Methods Summary |
---|
private static native int | add0(byte[] connection)Native connection registry add connection function.
|
private static native long | addAlarm0(byte[] midlet, long time)Native connection registry add alarm function.
|
private static native int | checkInByName0(byte[] connection)Native connection registry check in connection function.
|
public static boolean | checkInConnectionInternal(com.sun.midp.security.SecurityToken token, java.lang.String connection)Check in a push connection into AMS so the owning MIDlet can get
launched next time data is pushed. This method is used when a MIDlet
will not be able to get the connection and close (check in) the
connection for some reason. (normally because the user denied a
permission)
For datagram connections this function will discard the cached message.
For server socket connections this function will close the
accepted connection.
int ret;
token.checkIfPermissionAllowed(Permissions.MIDP);
/* Verify that the connection requested is valid. */
if (connection == null || connection.length() == 0) {
throw new IllegalArgumentException("Connection missing");
}
byte[] asciiRegistration = Util.toCString(connection);
return checkInByName0(asciiRegistration) != -1;
|
static void | checkRegistration(java.lang.String connection, java.lang.String midlet, java.lang.String filter)Check the registration arguments.
/* Verify the MIDlet is in the current classpath. */
if (midlet == null || midlet.length() == 0) {
throw new ClassNotFoundException("MIDlet missing");
}
/* Verify that the connection requested is valid. */
if (connection == null || connection.length() == 0) {
throw new IllegalArgumentException("Connection missing");
}
/* Verify that the filter requested is valid. */
if (filter == null || filter.length() == 0) {
throw new IllegalArgumentException("Filter missing");
}
int len = filter.length();
for (int i = 0; i < len; i++) {
char c = filter.charAt(i);
if (!(c == '?" || c == '*" || c == '." ||
('0" <= c && c <= '9"))) {
throw new IllegalArgumentException("Filter invalid");
}
}
|
private static native int | del0(byte[] connection, byte[] storage)Native connection registry del connection function.
|
private static native void | delAllForSuite0(byte[] storageName)Native connection registry delete a suite's connections function.
|
public static void | enablePushLaunch(com.sun.midp.security.SecurityToken token, boolean enable)Sets the flag which enables push launches to take place.
token.checkIfPermissionAllowed(Permissions.MIDP);
pushEnabled = enable;
|
private static native int | getEntry0(byte[] connection, byte[] regentry, int entrysz)Native connection registry lookup registry entry from a
specific connection.
|
public static java.lang.String | getFilter(java.lang.String connection)Retrieve the registered filter for a requested connection.
/* Verify that the connection requested is valid. */
if (connection == null || connection.length() == 0) {
return null;
}
String filter = null;
byte[] asciiConn = Util.toCString(connection);
byte[] registryEntry = new byte[512];
if (getEntry0(asciiConn, registryEntry, 512) == 0) {
String name = Util.toJavaString(registryEntry);
try {
int comma1 = name.indexOf(',", 0);
int comma2 = name.indexOf(',", comma1 + 1);
int comma3 = name.indexOf(',", comma2 + 1);
filter = name.substring(comma2+1, comma3).trim();
} catch (Exception e) {
e.printStackTrace();
}
}
return filter;
|
public static java.lang.String | getMIDlet(java.lang.String connection)Retrieve the registered MIDlet for a requested connection.
/* Verify that the connection requested is valid. */
if (connection == null || connection.length() == 0) {
return null;
}
String midlet = null;
byte[] asciiConn = Util.toCString(connection);
byte[] registryEntry = new byte[512];
if (getEntry0(asciiConn, registryEntry, 512) == 0) {
String name = Util.toJavaString(registryEntry);
try {
int comma1 = name.indexOf(',", 0);
int comma2 = name.indexOf(',", comma1 + 1);
midlet = name.substring(comma1+1, comma2).trim();
} catch (Exception e) {
e.printStackTrace();
}
}
return midlet;
|
private static native int | getMIDlet0(long handle, byte[] regentry, int entrysz)Native connection registry lookup for MIDlet name from file
descriptor.
|
public void | initSecurityToken(com.sun.midp.security.SecurityToken token)Initializes the security token for this class, so it can
perform actions that a normal MIDlet Suite cannot.
if (classSecurityToken == null) {
classSecurityToken = token;
}
|
protected void | launchEntry(java.lang.String name)Parse the registration entry and launch the associtated
MIDlet .
String conn;
String midlet;
String filter;
String storage;
/*
* Parse the comma separated values -
* " connection, midlet, filter, storagename"
* " midlet, wakeup, storagename"
*/
int comma1 = name.indexOf(',", 0);
int comma2 = name.indexOf(',", comma1 + 1);
int comma3 = name.indexOf(',", comma2 + 1);
if (comma3 == -1) {
/* Alarm was triggered */
conn = null;
midlet = name.substring(0, comma1).trim();
storage = name.substring(comma2+1).trim();
} else {
conn = name.substring(0, comma1).trim();
midlet = name.substring(comma1+1, comma2).trim();
filter = name.substring(comma2+1, comma3).trim();
storage = name.substring(comma3+1).trim();
}
try {
boolean okToInterrupt = true;
/*
* Check to see if the MIDlet is already scheduled.
*/
Installer installer = Installer.getInstaller(classSecurityToken);
Scheduler scheduler = Scheduler.getScheduler();
MIDletSuite current = scheduler.getMIDletSuite();
String root = null;
if (current != null) {
root = current.getStorageName();
}
if ((root != null) && root.equals(storage)) {
/*
* The storage name matches the current running
* MIDlet do not start it.
*/
if (scheduler.isScheduled(midlet)) {
return;
}
if (!current.permissionToInterrupt(conn)) {
// user does not want the interruption
if (conn != null) {
checkInConnectionInternal(classSecurityToken, conn);
}
return;
}
current.saveSettings();
} else {
MIDletSuite next = installer.getMIDletSuite(storage);
if (next == null) {
return;
}
okToInterrupt = next.permissionToInterrupt(conn);
next.saveSettings();
if (!okToInterrupt) {
// user does not want the interruption
if (conn != null) {
checkInConnectionInternal(classSecurityToken, conn);
}
return;
}
}
/*
* Inform the Installer about the MIDlet to run next.
* Need to restart the VM to load the next suite.
*/
installer.execute(storage, midlet);
/*
* Shutdown all running applications.
* NYI, ask the user before doing a forced take down.
*/
Scheduler.getScheduler().shutdown();
} catch (Exception e) {
// Could not launch requested push entry
if (conn != null) {
checkInConnectionInternal(classSecurityToken, conn);
}
e.printStackTrace();
}
|
private static native int | list0(byte[] midlet, boolean available, byte[] connectionlist, int listsz)Native connection registry list connection function.
|
public static java.lang.String | listConnections(java.lang.String storageName, boolean available)Return a list of registered connections for given
MIDlet suite.
return listConnections(null, storageName, available);
|
public static java.lang.String | listConnections(com.sun.midp.security.SecurityToken token, java.lang.String storageName, boolean available)Return a list of registered connections for given
MIDlet suite. Root permissions are required.
byte[] nativeStorageName;
String connections = null;
byte[] connlist;
if (token == null) {
MIDletSuite current = Scheduler.getScheduler().getMIDletSuite();
if (current != null) {
current.checkIfPermissionAllowed(Permissions.MIDP);
}
} else {
token.checkIfPermissionAllowed(Permissions.MIDP);
}
nativeStorageName = Util.toCString(storageName);
connlist = new byte[512];
if (list0(nativeStorageName, available, connlist, 512) == 0) {
connections = Util.toJavaString(connlist);
}
return connections;
|
public static java.lang.String | listConnections(boolean available)Return a list of registered connections for the current
MIDlet suite.
MIDletSuite current = Scheduler.getScheduler().getMIDletSuite();
if (current == null) {
return null;
}
return listConnections(classSecurityToken, current.getStorageName(),
available);
|
private native long | poll0(long time)Native function to test registered inbound connections
for new connection notification.
|
public static long | registerAlarm(java.lang.String midlet, long time)Register a time to launch the specified application. The
PushRegistry supports one outstanding wake up
time per MIDlet in the current suite. An application
is expected to use a TimerTask for notification
of time based events while the application is running.
If a wakeup time is already registered, the previous value will
be returned, otherwise a zero is returned the first time the
alarm is registered.
Scheduler scheduler = Scheduler.getScheduler();
MIDletSuite midletSuite = scheduler.getMIDletSuite();
/* There is no suite running when installing from the command line. */
if (midletSuite != null) {
try {
midletSuite.checkForPermission(Permissions.PUSH, null);
} catch (InterruptedException ie) {
throw new RuntimeException(
"Interrupted while trying to ask the user permission");
}
}
/* Verify the MIDlet is in the current classpath. */
if (midlet == null || midlet.length() == 0) {
throw new ClassNotFoundException("MIDlet missing");
}
/* Check if an appropriate MIDlet-<n> record exists. */
if (!midletSuite.isRegistered(midlet)) {
throw new ClassNotFoundException("No MIDLet-<n> registration");
}
Class c = Class.forName(midlet);
Class m = Class.forName("javax.microedition.midlet.MIDlet");
if (!m.isAssignableFrom(c)) {
throw new ClassNotFoundException("Not a MIDlet");
}
/*
* Add the alarm for the specified MIDlet int the current
* MIDlet suite.
*/
MIDletSuite current = Scheduler.getScheduler().getMIDletSuite();
if (current != null) {
String root = current.getStorageName();
byte[] asciiName = Util.toCString(midlet + ","
+ time + ","
+ root);
return addAlarm0(asciiName, time);
}
return 0;
|
public static void | registerConnection(java.lang.String connection, java.lang.String midlet, java.lang.String filter)Register a dynamic connection with the
application management software. Once registered,
the dynamic connection acts just like a
connection preallocated from the descriptor file.
The internal implementation includes the storage name
that uniquely identifies the MIDlet .
Scheduler scheduler = Scheduler.getScheduler();
MIDletSuite midletSuite = scheduler.getMIDletSuite();
/* This method should only be called by scheduled MIDlets. */
if (midletSuite == null) {
throw new IllegalStateException("Not in a MIDlet context");
}
/* Verify the MIDlet is in the current classpath. */
if (midlet == null || midlet.length() == 0) {
throw new ClassNotFoundException("MIDlet missing");
}
Class cl = Class.forName(midlet);
Class m = Class.forName("javax.microedition.midlet.MIDlet");
if (!m.isAssignableFrom(cl)) {
throw new ClassNotFoundException("Not a MIDlet");
}
/* Perform the rest of the checks in the internal registry. */
registerConnectionInternal(classSecurityToken, midletSuite,
connection, midlet, filter, false);
|
public static void | registerConnectionInternal(com.sun.midp.security.SecurityToken token, com.sun.midp.midlet.MIDletSuite midletSuite, java.lang.String connection, java.lang.String midlet, java.lang.String filter, boolean bypassChecks)Register a dynamic connection with the
application management software. Once registered,
the dynamic connection acts just like a
connection preallocated from the descriptor file.
The internal implementation includes the storage name
that uniquely identifies the MIDlet .
This method bypasses the class loader specific checks
needed by the Installer .
HttpUrl url;
String storageName;
token.checkIfPermissionAllowed(Permissions.MIDP);
if (!bypassChecks) {
try {
midletSuite.checkForPermission(Permissions.PUSH, null);
/* Check the registration arguments. */
checkRegistration(connection, midlet, filter);
/* Check if an appropriate MIDlet-<n> record exists. */
if (!midletSuite.isRegistered(midlet)) {
throw new
ClassNotFoundException("No MIDLet-<n> registration");
}
/*
* Only socket and datagram connections are supported by
* the MIDP 2.0 reference implementation.
*/
url = new HttpUrl(connection);
// Server connections do not have a host
if (url.host != null) {
throw new ConnectionNotFoundException(
"Connection not supported");
}
/*
* Attempt to open the connection to perform security check
* int the context of the current MIDlet suite.
*/
if (connection.startsWith("socket://")) {
if (url.port == -1) {
new IllegalArgumentException("Port missing");
}
midletSuite.checkForPermission(Permissions.TCP_SERVER,
connection);
} else if (connection.startsWith("datagram://")) {
/*
* Check the suite permission for the connection
* and close the connection immediately.
*/
midletSuite.checkForPermission(Permissions.UDP_SERVER,
connection);
} else {
throw new ConnectionNotFoundException(
"Connection not supported");
}
} catch (InterruptedException ie) {
throw new InterruptedIOException(
"Interrupted while trying to ask the user permission");
}
}
storageName = midletSuite.getStorageName();
byte[] asciiRegistration = Util.toCString(connection
+ "," + midlet
+ "," + filter
+ "," + storageName);
if (add0(asciiRegistration) == -1) {
throw new IOException("Connection already registered");
}
|
public void | run()Run the polling loop to check for inbound connections.
long fd = -1;
int ret = 0;
while (true) {
try {
if (pushEnabled
&& (fd = poll0(System.currentTimeMillis())) != -1) {
if (fd != -1) {
byte[] registryEntry = new byte[512];
if ((ret = getMIDlet0(fd, registryEntry, 512)) == 0) {
String name = Util.toJavaString(registryEntry);
launchEntry(name);
} else {
// NYI - can't find entry after successful poll
}
}
}
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
}
}
|
public static boolean | unregisterConnection(java.lang.String connection)Remove a dynamic connection registration.
/* Verify the connection string before using it. */
if (connection == null || connection.length() == 0) {
return false;
}
Scheduler scheduler = Scheduler.getScheduler();
MIDletSuite current = scheduler.getMIDletSuite();
String root = current.getStorageName();
byte[] asciiRegistration = Util.toCString(connection);
byte[] asciiStorage = Util.toCString(root);
int ret = del0(asciiRegistration, asciiStorage);
if (ret == -2) {
throw new SecurityException("wrong suite");
}
return ret != -1;
|
public static void | unregisterConnections(com.sun.midp.security.SecurityToken token, java.lang.String storageName)Unregister all the connections for a MIDlet suite.
token.checkIfPermissionAllowed(Permissions.MIDP);
delAllForSuite0(Util.toCString(storageName));
|