Fields Summary |
---|
static final String | PUSH_INTERRUPT_DIALOG_TITLEInterrupt dialog title for push. |
protected static final String | PUSH_INTERRUPT_QUESTIONInterrupt question for push. |
protected static final String | ALARM_INTERRUPT_QUESTIONInterrupt question for alarms. |
private static com.sun.midp.security.SecurityToken | classSecurityTokenThis class has a different security domain than the application. |
private JadProperties | bufferedJadPropsBuffered properties from the application descriptor. |
private ManifestProperties | bufferedJarPropsBuffered properties from the JAR manifest. |
private com.sun.midp.security.SecurityToken | securityTokenSecurity token for this suite. |
private byte[] | permissionsPermissions for this suite. |
private int | pushInterruptSettingCan this MIDlet suite interrupt other suites. |
private String | storageRootThe storage path of this suite. |
private String | storageNameThe storage name of this suite. |
private String | caThe CA that authorized this suite. |
private boolean | trustedIndicates if this suite is trusted. |
private String | initialMIDletClassNameInitial midlet class name. |
private int | numberOfMidletsNumber of midlets in this suite. less than 0 mean they need to
counted. |
Methods Summary |
---|
public void | addProperty(java.lang.String key, java.lang.String value)Adds a property to the suite.
MIDletSuite current = Scheduler.getScheduler().getMIDletSuite();
if (current != null) {
current.checkIfPermissionAllowed(Permissions.MIDP);
}
if (bufferedJadProps != null) {
bufferedJadProps.addProperty(key, value);
return;
}
bufferedJarProps.addProperty(key, value);
|
public void | checkForPermission(int permission, java.lang.String resource)Checks for permission and throw an exception if not allowed.
May block to ask the user a question.
checkForPermission(permission,
getProperty(Installer.SUITE_NAME_PROP), resource);
|
protected void | checkForPermission(int permission, java.lang.String name, java.lang.String resource)Checks for permission and throw an exception if not allowed.
May block to ask the user a question.
String protocolName = null;
try {
int colon = resource.indexOf(':");
if (colon != -1) {
protocolName = resource.substring(0, colon);
}
} catch (Exception e) {
// ignore
}
securityToken.checkForPermission(permission,
Permissions.getTitle(permission),
Permissions.getQuestion(permission),
name, resource, protocolName);
|
public void | checkIfPermissionAllowed(int permission)Checks to see the suite has the ALLOW level for specific permission.
This is used for by internal APIs that only provide access to
trusted system applications.
securityToken.checkIfPermissionAllowed(permission);
|
public int | checkPermission(java.lang.String permission)Gets the status of the specified permission.
If no API on the device defines the specific permission
requested then it must be reported as denied.
If the status of the permission is not known because it might
require a user interaction then it should be reported as unknown.
return securityToken.checkPermission(permission);
|
protected byte[][] | copyPermissions(byte[][] permissions)Makes a copy of a list of permissions.
if (permissions == null) {
return null;
}
byte[][] copy = new byte[2][];
for (int i = 0; i < 2; i++) {
copy[i] = new byte[permissions[i].length];
System.arraycopy(permissions[i], 0, copy[i], 0,
permissions[i].length);
}
return copy;
|
protected int | countMIDlets()Counts the number of MIDlets from its properties.
int i;
for (i = 1; getProperty("MIDlet-" + i) != null; i++);
return i - 1;
|
protected java.lang.String | getAlarmInterruptQuestion()Gets the Alarm interrupt question the should be used when
interrupting this suite.
The question will have %2 where this suite name should be and
a %1 where the current suite name should be.
return ALARM_INTERRUPT_QUESTION;
|
public java.lang.String | getCA()Gets the name of CA that authorized this suite.
return ca;
|
public java.lang.String | getDownloadUrl()Gets the URL that the suite was downloaded from.
String url = getJadUrl();
if (url != null) {
return url;
}
return getJarUrl();
|
public java.lang.String | getInitialMIDletClassname()Gets the classname of the initial MIDlet to run.
if (initialMIDletClassName != null) {
return initialMIDletClassName;
}
if (getNumberOfMIDlets() == 1) {
return new MIDletInfo(getProperty("MIDlet-1")).classname;
}
// Have the user select a MIDlet.
return "com.sun.midp.midlet.Selector";
|
public java.lang.String | getJadUrl()Gets the JAD URL of the suite. This is only for the installer.
RandomAccessStream storage =
new RandomAccessStream(classSecurityToken);
DataInputStream storageStream;
try {
storage.connect(getStorageRoot() + Installer.JAD_URL_FILENAME,
Connector.READ);
// convert the JAD URL to UTF8 and write it to storage
storageStream = storage.openDataInputStream();
return storageStream.readUTF();
} catch (Exception e) {
// ignore, not all suite have JAD URLs
return null;
} finally {
try {
storage.disconnect();
} catch (IOException e) {
// ignore
}
}
|
public java.lang.String | getJarUrl()Gets the JAR URL of the suite. This is only for the installer.
RandomAccessStream storage =
new RandomAccessStream(classSecurityToken);
DataInputStream storageStream;
try {
storage.connect(getStorageRoot() + Installer.JAR_URL_FILENAME,
Connector.READ);
// convert the JAR URL to UTF8 and write it to storage
storageStream = storage.openDataInputStream();
return storageStream.readUTF();
} catch (Exception e) {
// old installations did not have JAR URL's
return "unknown";
} finally {
try {
storage.disconnect();
} catch (IOException e) {
// ignore
}
}
|
protected java.lang.String | getMIDletClassName(java.lang.String midletName)Retrieves the classname for a given MIDlet name.
String midlet;
MIDletInfo midletInfo;
for (int i = 1; ; i++) {
midlet = getProperty("MIDlet-" + i);
if (midlet == null) {
/*
* If the name was a class name use it.
* (Temporary implemention - overloading the
* name as MIDlet name or class name could be in
* conflict. Longer term solution would expand
* Installer.execute() semantics to allow a class
* name to run, rather than just the indirection
* via MIDlet info.)
*/
try {
Class.forName(midletName);
return midletName;
} catch (Exception e) {}
return null; // We went past the last MIDlet
}
midletInfo = new MIDletInfo(midlet);
if (midletInfo.name.equals(midletName)) {
return midletInfo.classname;
}
}
|
public int | getNumberOfMIDlets()Provides the number of of MIDlets in this suite.
if (numberOfMidlets <= 0) {
numberOfMidlets = countMIDlets();
}
return numberOfMidlets;
|
public byte[][] | getPermissions()Gets list of permissions for this suite.
return copyPermissions(permissions);
|
private void | getPropertiesFromStorage()Gets properites from a symbolically named installed package.
The properties are the attributes in the application descriptor
and JAR Manifest.
RandomAccessStream myStorage;
int size;
byte[] buffer;
InputStream is;
DataInputStream dis;
String jadEncoding = null;
myStorage = new RandomAccessStream(classSecurityToken);
// Get the JAD encoding, if the server provided one
try {
myStorage.connect(storageRoot +
Installer.JAD_ENCODING_FILENAME,
Connector.READ);
try {
// convert the JAD encoding to UTF8 and write it to storage
dis = myStorage.openDataInputStream();
try {
jadEncoding = dis.readUTF();
} finally {
dis.close();
}
} finally {
myStorage.disconnect();
}
} catch (IOException e) {
// servers can choose the default encoding by not providing one
}
// Load .jad file
bufferedJadProps = new JadProperties();
try {
myStorage.connect(storageRoot + Installer.JAD_FILENAME,
Connector.READ);
try {
size = myStorage.getSizeOf();
buffer = new byte[size];
dis = myStorage.openDataInputStream();
try {
dis.readFully(buffer);
is = new ByteArrayInputStream(buffer);
bufferedJadProps.load(is, jadEncoding);
buffer = null;
is = null;
} finally {
dis.close();
}
} finally {
myStorage.disconnect();
}
} catch (IOException e) {
// Jar only install
}
try {
// Get Manifest file so we can buffer it
myStorage.connect(storageRoot + Installer.MANIFEST_FILENAME,
Connector.READ);
try {
size = myStorage.getSizeOf();
buffer = new byte[size];
dis = myStorage.openDataInputStream();
try {
dis.readFully(buffer);
is = new ByteArrayInputStream(buffer);
bufferedJarProps = new ManifestProperties();
bufferedJarProps.load(is);
buffer = null;
is = null;
} finally {
dis.close();
}
} finally {
myStorage.disconnect();
}
} catch (IOException e) {
// ignore
}
|
public java.lang.String | getProperty(java.lang.String key)Gets a property of the suite. A property is an attribute from
either the application descriptor or JAR Manifest.
String prop;
if (bufferedJadProps == null) {
getPropertiesFromStorage();
if (bufferedJadProps == null) {
return null;
}
}
// check the JAD first
prop = bufferedJadProps.getProperty(key);
if (prop != null) {
return prop;
}
if (bufferedJarProps == null) {
return null;
}
return bufferedJarProps.getProperty(key);
|
protected java.lang.String | getPushInterruptQuestion()Gets the Push interrupt question the should be used when
interrupting this suite.
The question will have %2 where this suite name should be and
a %1 where the current suite name should be.
return PUSH_INTERRUPT_QUESTION;
|
public int | getPushInterruptSetting()Gets push setting for interrupting other MIDlets.
Reuses the Permissions.
return pushInterruptSetting;
|
public byte[] | getResource(java.lang.String name)Get a named resource out of the JAR of this MIDlet suite.
if (name.charAt(0) == '/") {
// the jar reader does not remove the leading '/'
name = name.substring(1, name.length());
}
try {
return JarReader.readJarEntry(classSecurityToken,
getStorageRoot() +
Installer.JAR_FILENAME,
name);
} catch (IOException e) {
return null;
}
|
public java.lang.String | getStorageName()Gets the unique name of vendor and suite.
return storageName;
|
public java.lang.String | getStorageRoot()Gets the path root of any file this suite.
Has any needed file separators appended.
return storageRoot;
|
public int | getStorageUsed()Gets the amount of storage on the device that this suite is using.
This includes the JAD, JAR, management data, and RMS.
File file = new File(classSecurityToken);
RandomAccessStream stream =
new RandomAccessStream(classSecurityToken);
Vector files;
int storageUsed = 0;
files = file.filenamesThatStartWith(getStorageRoot());
for (int i = 0; i < files.size(); i++) {
try {
stream.connect((String)files.elementAt(i), Connector.READ);
try {
storageUsed += stream.getSizeOf();
} finally {
stream.disconnect();
}
} catch (IOException ioe) {
// just move on to the next file
}
}
return storageUsed;
|
protected java.lang.String | getSuiteNameForInterrupt()Gets the suite name for interruption purposes.
return getProperty(Installer.SUITE_NAME_PROP);
|
static 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) {
return;
}
classSecurityToken = token;
|
public boolean | isRegistered(java.lang.String midletName)Indicates if the named MIDlet is registered in the suite
with MIDlet-<n> record in the manifest or
application descriptor.
String midlet;
MIDletInfo midletInfo;
for (int i = 1; ; i++) {
midlet = getProperty("MIDlet-" + i);
if (midlet == null) {
return false; // We went past the last MIDlet
}
/* Check if the names match. */
midletInfo = new MIDletInfo(midlet);
if (midletInfo.classname.equals(midletName)) {
return true;
}
}
|
public boolean | isTrusted()Indicates if this suite is trusted.
(not to be confused with a domain named "trusted",
this is used to determine if a trusted symbol should be displayed
to the user and not used for permissions)
return trusted;
|
public boolean | permissionToInterrupt(java.lang.String connection)Asks the user want to interrupt the current MIDlet with
a new MIDlet that has received network data.
String name;
MIDletSuite current;
String question;
String currentName;
if (pushInterruptSetting == Permissions.USER_DENIED ||
pushInterruptSetting == Permissions.NEVER) {
return false;
}
// treat SESSION level the same as ONE_SHOT
switch (pushInterruptSetting) {
case Permissions.ALLOW:
case Permissions.BLANKET_GRANTED:
return true;
}
name = getSuiteNameForInterrupt();
// The currently running suite controls what question to ask.
current = Scheduler.getScheduler().getMIDletSuite();
if (current instanceof MIDletSuiteImpl) {
MIDletSuiteImpl temp = (MIDletSuiteImpl)current;
if (connection == null) {
question = temp.getAlarmInterruptQuestion();
} else {
question = temp.getPushInterruptQuestion();
}
currentName = temp.getSuiteNameForInterrupt();
} else {
// use the questions of this suite
if (connection == null) {
question = getAlarmInterruptQuestion();
} else {
question = getPushInterruptQuestion();
}
currentName = Resource.getString("The current application");
}
try {
switch (SecurityToken.askUserForPermission(classSecurityToken,
"Can %1 Interrupt?", question, name, currentName, null,
Permissions.BLANKET, pushInterruptSetting)) {
case Permissions.BLANKET:
pushInterruptSetting = Permissions.BLANKET_GRANTED;
return true;
case Permissions.SESSION:
case Permissions.ONE_SHOT:
// treat one shot as session
pushInterruptSetting = Permissions.SESSION;
return true;
case Permissions.DENY:
pushInterruptSetting = Permissions.USER_DENIED;
return false;
}
} catch (InterruptedException ie) {
return false;
}
// default, is cancel, ask again next time
pushInterruptSetting = Permissions.DENY_SESSION;
return false;
|
private void | readSettings()Reads the suite settings from storage.
byte[] maximums = Permissions.getEmptySet();
byte[] currentLevels = Permissions.getEmptySet();
RandomAccessStream storage =
new RandomAccessStream(classSecurityToken);
DataInputStream storageStream;
int version;
int count;
permissions = new byte[2][];
permissions[Permissions.MAX_LEVELS] = maximums;
permissions[Permissions.CUR_LEVELS] = currentLevels;
try {
storage.connect(getStorageRoot() + Installer.SETTINGS_FILENAME,
Connector.READ);
try {
storageStream = storage.openDataInputStream();
version = storageStream.readByte();
/*
* only version 1 are handled by the method
* 0 means that this is a beta version that are not handled
* by the method. Note that version number only has to
* increase if data has been removed, not if new data has been
* added to the end of the file.
*/
if (version != 1) {
System.out.println("Corrupt application settings file.");
return;
}
trusted = storageStream.readBoolean();
pushInterruptSetting = storageStream.readByte();
count = storageStream.readByte();
storageStream.readFully(currentLevels, 0, count);
count = storageStream.readByte();
storageStream.readFully(maximums, 0, count);
} finally {
storage.disconnect();
}
} catch (IOException e) {
// ignore, old settings files are shorter
}
|
public void | saveSettings()Saves any the settings (security or others) that the user may have
changed. Normally called by the scheduler after
the last running MIDlet in the suite is destoryed.
However it could be called during a suspend of the VM so
that persisent settings of the suite can be perserved or
by the graphical manager application settings MIDlet.
try {
Installer.saveSuiteSettings(classSecurityToken, storageRoot,
(byte)pushInterruptSetting, permissions, trusted);
} catch (IOException e) {
// ignore
}
|