OSDN Git Service

[STOPSHIP] PackageManager: Add package setting flag for N upgrade
authorAndreas Gampe <agampe@google.com>
Sat, 26 Mar 2016 03:03:51 +0000 (20:03 -0700)
committerAndreas Gampe <agampe@google.com>
Mon, 28 Mar 2016 15:32:09 +0000 (08:32 -0700)
First upgrade to N level needs to compile apps with the first-boot
reason, as profiles are missing. The SDK level check does not work
for the preview, as the version is not incremented, yet.

Add a flag to the package settings to track the status.

Note: STOPSHIP, this will be reverted before release.

Bug: 27689078
Bug: 27872764
Change-Id: Ifd460d5235348f041ef64c9b61068af47113ddcb

services/core/java/com/android/server/pm/PackageManagerService.java
services/core/java/com/android/server/pm/Settings.java

index f8108cb..d2fd762 100644 (file)
@@ -2225,9 +2225,10 @@ public class PackageManagerService extends IPackageManager.Stub {
                 }
             }
 
-            // When upgrading form pre-N, we need to handle package extraction like first boot,
+            // When upgrading from pre-N, we need to handle package extraction like first boot,
             // as there is no profiling data available.
-            mIsPreNUpgrade = ver.sdkVersion <= Build.VERSION_CODES.M;
+            mIsPreNUpgrade = !mSettings.isNWorkDone();
+            mSettings.setNWorkDone();
 
             // Collect vendor overlay packages.
             // (Do this before scanning any apps.)
index fa0eb46..3c3c576 100644 (file)
@@ -190,6 +190,7 @@ final class Settings {
             "all-intent-filter-verifications";
     private static final String TAG_DEFAULT_BROWSER = "default-browser";
     private static final String TAG_VERSION = "version";
+    private static final String TAG_N_WORK = "n-work";
 
     private static final String ATTR_NAME = "name";
     private static final String ATTR_USER = "user";
@@ -214,6 +215,7 @@ final class Settings {
     private static final String ATTR_VOLUME_UUID = "volumeUuid";
     private static final String ATTR_SDK_VERSION = "sdkVersion";
     private static final String ATTR_DATABASE_VERSION = "databaseVersion";
+    private static final String ATTR_DONE = "done";
 
     // Bookkeeping for restored permission grants
     private static final String TAG_RESTORED_RUNTIME_PERMISSIONS = "restored-perms";
@@ -386,6 +388,17 @@ final class Settings {
 
     public final KeySetManagerService mKeySetManagerService = new KeySetManagerService(mPackages);
 
+    /**
+     * Used to track whether N+ work has been done. This is similar to the file-system level
+     * and denotes that first-boot or upgrade-to-N work has been done.
+     *
+     * Note: the flag has been added to a) allow tracking while an API level check is impossible
+     *       and b) to merge upgrade as well as first boot (because the flag is false, by default).
+     *
+     * STOPSHIP: b/27872764
+     */
+    private boolean mIsNWorkDone = false;
+
     Settings(Object lock) {
         this(Environment.getDataDirectory(), lock);
     }
@@ -2327,6 +2340,10 @@ final class Settings {
 
             mKeySetManagerService.writeKeySetManagerServiceLPr(serializer);
 
+            serializer.startTag(null, TAG_N_WORK);
+            serializer.attribute(null, ATTR_DONE, Boolean.toString(mIsNWorkDone));
+            serializer.endTag(null, TAG_N_WORK);
+
             serializer.endTag(null, "packages");
 
             serializer.endDocument();
@@ -2860,7 +2877,8 @@ final class Settings {
                     ver.sdkVersion = XmlUtils.readIntAttribute(parser, ATTR_SDK_VERSION);
                     ver.databaseVersion = XmlUtils.readIntAttribute(parser, ATTR_SDK_VERSION);
                     ver.fingerprint = XmlUtils.readStringAttribute(parser, ATTR_FINGERPRINT);
-
+                } else if (TAG_N_WORK.equals(tagName)) {
+                    mIsNWorkDone = XmlUtils.readBooleanAttribute(parser, ATTR_DONE, false);
                 } else {
                     Slog.w(PackageManagerService.TAG, "Unknown element under <packages>: "
                             + parser.getName());
@@ -4140,6 +4158,14 @@ final class Settings {
         return res;
     }
 
+    public boolean isNWorkDone() {
+        return mIsNWorkDone;
+    }
+
+    void setNWorkDone() {
+        mIsNWorkDone = true;
+    }
+
     static void printFlags(PrintWriter pw, int val, Object[] spec) {
         pw.print("[ ");
         for (int i=0; i<spec.length; i+=2) {