diff options
author | Dianne Hackborn <hackbod@google.com> | 2009-05-13 15:06:13 -0700 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2009-05-15 18:02:47 -0700 |
commit | a96cbb435d7b2197ab2b61fd98d14cbd6e0c5c3d (patch) | |
tree | 75e0804e6628f9bb818c5f6f918315640c721d4b /core | |
parent | ba2a3a1b32e242eea4e97c927d886e8987fde3d4 (diff) | |
download | frameworks_base-a96cbb435d7b2197ab2b61fd98d14cbd6e0c5c3d.zip frameworks_base-a96cbb435d7b2197ab2b61fd98d14cbd6e0c5c3d.tar.gz frameworks_base-a96cbb435d7b2197ab2b61fd98d14cbd6e0c5c3d.tar.bz2 |
Implement compatibility support for WRITE_SDCARD permission.
Now old applications will automatically be granted it. Also renamed it from
SDCARD_WRITE to WRITE_SDCARD to be consistent with our other permissions,
and re-arranged how we do targetSdkVersion to actually be usuable for this
kind of stuff.
Note that right now this results in basically all apps being given the
WRITE_SDCARD permission, because their targetSdkVersion is not set. I will
be dealing with that in a future change.
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/content/pm/ApplicationInfo.java | 24 | ||||
-rw-r--r-- | core/java/android/content/pm/PackageParser.java | 48 | ||||
-rw-r--r-- | core/java/android/os/Build.java | 19 | ||||
-rw-r--r-- | core/res/AndroidManifest.xml | 4 | ||||
-rw-r--r-- | core/res/res/values/strings.xml | 2 |
5 files changed, 78 insertions, 19 deletions
diff --git a/core/java/android/content/pm/ApplicationInfo.java b/core/java/android/content/pm/ApplicationInfo.java index 88ac04c..ad022e7 100644 --- a/core/java/android/content/pm/ApplicationInfo.java +++ b/core/java/android/content/pm/ApplicationInfo.java @@ -123,13 +123,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { * Value for {@link #flags}: this is set of the application has set * its android:targetSdkVersion to something >= the current SDK version. */ - public static final int FLAG_TARGETS_SDK = 1<<8; - - /** - * Value for {@link #flags}: this is set of the application has set - * its android:targetSdkVersion to something >= the current SDK version. - */ - public static final int FLAG_TEST_ONLY = 1<<9; + public static final int FLAG_TEST_ONLY = 1<<8; /** * Flags associated with the application. Any combination of @@ -137,7 +131,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { * {@link #FLAG_PERSISTENT}, {@link #FLAG_FACTORY_TEST}, and * {@link #FLAG_ALLOW_TASK_REPARENTING} * {@link #FLAG_ALLOW_CLEAR_USER_DATA}, {@link #FLAG_UPDATED_SYSTEM_APP}, - * {@link #FLAG_TARGETS_SDK}. + * {@link #FLAG_TEST_ONLY}. */ public int flags = 0; @@ -182,6 +176,16 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { public int[] supportsDensities; /** + * The minimum SDK version this application targets. It may run on earilier + * versions, but it knows how to work with any new behavior added at this + * version. Will be {@link android.os.Build.VERSION_CODES#CUR_DEVELOPMENT} + * if this is a development build and the app is targeting that. You should + * compare that this number is >= the SDK version number at which your + * behavior was introduced. + */ + public int targetSdkVersion; + + /** * When false, indicates that all components within this application are * considered disabled, regardless of their individually set enabled status. */ @@ -200,6 +204,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { pw.println(prefix + "publicSourceDir=" + publicSourceDir); pw.println(prefix + "sharedLibraryFiles=" + sharedLibraryFiles); pw.println(prefix + "dataDir=" + dataDir); + pw.println(prefix + "targetSdkVersion=" + targetSdkVersion); pw.println(prefix + "enabled=" + enabled); pw.println(prefix + "manageSpaceActivityName="+manageSpaceActivityName); pw.println(prefix + "description=0x"+Integer.toHexString(descriptionRes)); @@ -246,6 +251,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { sharedLibraryFiles = orig.sharedLibraryFiles; dataDir = orig.dataDir; uid = orig.uid; + targetSdkVersion = orig.targetSdkVersion; enabled = orig.enabled; manageSpaceActivityName = orig.manageSpaceActivityName; descriptionRes = orig.descriptionRes; @@ -276,6 +282,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { dest.writeStringArray(sharedLibraryFiles); dest.writeString(dataDir); dest.writeInt(uid); + dest.writeInt(targetSdkVersion); dest.writeInt(enabled ? 1 : 0); dest.writeString(manageSpaceActivityName); dest.writeInt(descriptionRes); @@ -305,6 +312,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { sharedLibraryFiles = source.readStringArray(); dataDir = source.readString(); uid = source.readInt(); + targetSdkVersion = source.readInt(); enabled = source.readInt() != 0; manageSpaceActivityName = source.readString(); descriptionRes = source.readInt(); diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java index 88907c1..78462f1 100644 --- a/core/java/android/content/pm/PackageParser.java +++ b/core/java/android/content/pm/PackageParser.java @@ -55,6 +55,30 @@ import java.util.jar.JarFile; * {@hide} */ public class PackageParser { + /** @hide */ + public static class NewPermissionInfo { + public final String name; + public final int sdkVersion; + public final int fileVersion; + + public NewPermissionInfo(String name, int sdkVersion, int fileVersion) { + this.name = name; + this.sdkVersion = sdkVersion; + this.fileVersion = fileVersion; + } + } + + /** + * List of new permissions that have been added since 1.0. + * NOTE: These must be declared in SDK version order, with permissions + * added to older SDKs appearing before those added to newer SDKs. + * @hide + */ + public static final PackageParser.NewPermissionInfo NEW_PERMISSIONS[] = new PackageParser.NewPermissionInfo[] { + new PackageParser.NewPermissionInfo(android.Manifest.permission.WRITE_SDCARD, + android.os.Build.VERSION_CODES.DONUT, + 0) + }; private String mArchiveSourcePath; private String[] mSeparateProcesses; @@ -616,7 +640,6 @@ public class PackageParser { final Package pkg = new Package(pkgName); boolean foundApp = false; - boolean targetsSdk = false; TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifest); @@ -774,11 +797,10 @@ public class PackageParser { return null; } // If the code matches, it definitely targets this SDK. - targetsSdk = true; - } else if (targetVers >= mSdkVersion) { - // If they have explicitly targeted our current version - // or something after it, then note this. - targetsSdk = true; + pkg.applicationInfo.targetSdkVersion + = android.os.Build.VERSION_CODES.CUR_DEVELOPMENT; + } else { + pkg.applicationInfo.targetSdkVersion = targetVers; } if (minVers > mSdkVersion) { @@ -824,8 +846,18 @@ public class PackageParser { mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY; } - if (targetsSdk) { - pkg.applicationInfo.flags |= ApplicationInfo.FLAG_TARGETS_SDK; + final int NP = PackageParser.NEW_PERMISSIONS.length; + for (int ip=0; ip<NP; ip++) { + final PackageParser.NewPermissionInfo npi + = PackageParser.NEW_PERMISSIONS[ip]; + if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) { + break; + } + if (!pkg.requestedPermissions.contains(npi.name)) { + Log.i(TAG, "Impliciting adding " + npi.name + " to old pkg " + + pkg.packageName); + pkg.requestedPermissions.add(npi.name); + } } if (pkg.usesLibraries.size() > 0) { diff --git a/core/java/android/os/Build.java b/core/java/android/os/Build.java index 5487c54..4a4285e 100644 --- a/core/java/android/os/Build.java +++ b/core/java/android/os/Build.java @@ -87,6 +87,12 @@ public class Build { */ public static class VERSION_CODES { /** + * Magic version number for a current development build, which has + * not yet turned into an official release. + */ + public static final int CUR_DEVELOPMENT = 10000; + + /** * October 2008: The original, first, version of Android. Yay! */ public static final int BASE = 1; @@ -98,6 +104,19 @@ public class Build { * May 2009: Android 1.5. */ public static final int CUPCAKE = 3; + /** + * Current work on "Donut" development branch. + * + * <p>Applications targeting this or a later release will get these + * new changes in behavior:</p> + * <ul> + * <li> They must explicitly request the + * {@link android.Manifest.permission#WRITE_SDCARD} permission to be + * able to modify the contents of the SD card. (Apps targeting + * earlier versions will always request the permission.) + * </ul> + */ + public static final int DONUT = CUR_DEVELOPMENT; } /** The type of build, like "user" or "eng". */ diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index bff6b9d..59b26a0 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -389,11 +389,11 @@ android:description="@string/permgroupdesc_storage" /> <!-- Allows an application to write to the SD card --> - <permission android:name="android.permission.SDCARD_WRITE" + <permission android:name="android.permission.WRITE_SDCARD" android:permissionGroup="android.permission-group.STORAGE" android:label="@string/permlab_sdcardWrite" android:description="@string/permdesc_sdcardWrite" - android:protectionLevel="normal" /> + android:protectionLevel="dangerous" /> <!-- ============================================ --> <!-- Permissions for low-level system interaction --> diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml index 2860292..8ad8a84 100644 --- a/core/res/res/values/strings.xml +++ b/core/res/res/values/strings.xml @@ -1069,7 +1069,7 @@ user dictionary.</string> <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. --> - <string name="permlab_sdcardWrite">write to SD card</string> + <string name="permlab_sdcardWrite">modify/delete SD card contents</string> <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. --> <string name="permdesc_sdcardWrite">Allows an application to write to the SD card.</string> |