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.
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 @@
      * 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 @@
      * {@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 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 @@
         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 @@
         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 @@
         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 @@
         sharedLibraryFiles = source.readStringArray();
         dataDir = source.readString();
         uid = source.readInt();
+        targetSdkVersion = source.readInt();
         enabled = source.readInt() != 0;
         manageSpaceActivityName = source.readString();
         descriptionRes = source.readInt();