Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a96cbb43 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

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.
parent ba2a3a1b
Loading
Loading
Loading
Loading
+55 −23
Original line number Diff line number Diff line
@@ -870,17 +870,6 @@
 visibility="public"
>
</field>
<field name="SDCARD_WRITE"
 type="java.lang.String"
 transient="false"
 volatile="false"
 value="&quot;android.permission.SDCARD_WRITE&quot;"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="SEND_SMS"
 type="java.lang.String"
 transient="false"
@@ -1167,6 +1156,17 @@
 visibility="public"
>
</field>
<field name="WRITE_SDCARD"
 type="java.lang.String"
 transient="false"
 volatile="false"
 value="&quot;android.permission.WRITE_SDCARD&quot;"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="WRITE_SECURE_SETTINGS"
 type="java.lang.String"
 transient="false"
@@ -31824,6 +31824,16 @@
 visibility="public"
>
</field>
<field name="targetSdkVersion"
 type="int"
 transient="false"
 volatile="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="taskAffinity"
 type="java.lang.String"
 transient="false"
@@ -31999,22 +32009,11 @@
 visibility="public"
>
</field>
<field name="FLAG_TARGETS_SDK"
 type="int"
 transient="false"
 volatile="false"
 value="256"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="FLAG_TEST_ONLY"
 type="int"
 transient="false"
 volatile="false"
 value="512"
 value="256"
 static="true"
 final="true"
 deprecated="not deprecated"
@@ -86002,6 +86001,28 @@
 visibility="public"
>
</field>
<field name="CUR_DEVELOPMENT"
 type="int"
 transient="false"
 volatile="false"
 value="10000"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="DONUT"
 type="int"
 transient="false"
 volatile="false"
 value="10000"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
</class>
<class name="Bundle"
 extends="java.lang.Object"
@@ -139611,6 +139632,17 @@
<implements name="java.lang.annotation.Annotation">
</implements>
</class>
<class name="ViewDebug.FlagToString"
 extends="java.lang.Object"
 abstract="true"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<implements name="java.lang.annotation.Annotation">
</implements>
</class>
<class name="ViewDebug.HierarchyTraceType"
 extends="java.lang.Enum"
 abstract="false"
+16 −8
Original line number Diff line number Diff line
@@ -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;
    
@@ -181,6 +175,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();
+40 −8
Original line number Diff line number Diff line
@@ -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) {
+19 −0
Original line number Diff line number Diff line
@@ -86,6 +86,12 @@ public class Build {
     * increment monotonically with each official platform release.
     */
    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!
         */
@@ -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". */
+2 −2
Original line number Diff line number Diff line
@@ -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 -->
Loading