OSDN Git Service

Fix broken target SDK checks.
authorJeff Sharkey <jsharkey@android.com>
Tue, 10 Apr 2018 21:18:12 +0000 (15:18 -0600)
committerJeff Sharkey <jsharkey@android.com>
Tue, 10 Apr 2018 21:18:15 +0000 (15:18 -0600)
Consider an app targeting the final API 28, but running on an older
build where "P" is still API 10000.  Those apps need to be treated as
legacy apps.

In general, the logical pattern that should be used when enforcing
target SDK behaviors is below.

For applying behavior to legacy apps:
    // BROKEN
    if (targetSdkVersion <= Build.VERSION_CODES.N_MR1) {
    // CORRECT
    if (targetSdkVersion < Build.VERSION_CODES.O) {

For applying behavior to new apps:
    // BROKEN
    if (targetSdkVersion > Build.VERSION_CODES.N_MR1) {
    // CORRECT
    if (targetSdkVersion >= Build.VERSION_CODES.O) {

Bug: 77865751
Test: builds, boots
Change-Id: Ia83bd446a940751d51a6542c7a5b9cca174c5296

core/java/android/app/ActivityThread.java
core/java/android/app/WallpaperManager.java
core/java/android/content/pm/ApplicationInfo.java
core/java/android/content/pm/PackageParser.java
core/java/android/content/pm/PackageSharedLibraryUpdater.java
core/java/android/text/method/LinkMovementMethod.java
core/java/android/widget/SelectionActionModeHelper.java
services/core/java/com/android/server/am/ActivityManagerService.java
services/core/java/com/android/server/notification/NotificationManagerService.java
services/core/java/com/android/server/pm/PackageManagerService.java

index 50a4398..82c3383 100644 (file)
@@ -5873,7 +5873,7 @@ public final class ActivityThread extends ClientTransactionHandler {
         } finally {
             // If the app targets < O-MR1, or doesn't change the thread policy
             // during startup, clobber the policy to maintain behavior of b/36951662
-            if (data.appInfo.targetSdkVersion <= Build.VERSION_CODES.O
+            if (data.appInfo.targetSdkVersion < Build.VERSION_CODES.O_MR1
                     || StrictMode.getThreadPolicy().equals(writesAllowedPolicy)) {
                 StrictMode.setThreadPolicy(savedPolicy);
             }
index 17bc6ea..6c2fb2d 100644 (file)
@@ -413,7 +413,7 @@ public class WallpaperManager {
                 } catch (OutOfMemoryError e) {
                     Log.w(TAG, "Out of memory loading the current wallpaper: " + e);
                 } catch (SecurityException e) {
-                    if (context.getApplicationInfo().targetSdkVersion <= Build.VERSION_CODES.O) {
+                    if (context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.O_MR1) {
                         Log.w(TAG, "No permission to access wallpaper, suppressing"
                                 + " exception to avoid crashing legacy app.");
                     } else {
@@ -977,7 +977,7 @@ public class WallpaperManager {
             } catch (RemoteException e) {
                 throw e.rethrowFromSystemServer();
             } catch (SecurityException e) {
-                if (mContext.getApplicationInfo().targetSdkVersion <= Build.VERSION_CODES.O) {
+                if (mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.O_MR1) {
                     Log.w(TAG, "No permission to access wallpaper, suppressing"
                             + " exception to avoid crashing legacy app.");
                     return null;
index c5a39f4..d65e051 100644 (file)
@@ -1694,7 +1694,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
         if (mHiddenApiPolicy != HIDDEN_API_ENFORCEMENT_DEFAULT) {
             return mHiddenApiPolicy;
         }
-        if (targetSdkVersion <= Build.VERSION_CODES.O_MR1) {
+        if (targetSdkVersion < Build.VERSION_CODES.P) {
             return HIDDEN_API_ENFORCEMENT_BLACK;
         } else {
             return HIDDEN_API_ENFORCEMENT_DARK_GREY_AND_BLACK;
@@ -1728,9 +1728,9 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
         if (isPackageWhitelistedForHiddenApis()) {
             return;
         }
-        if (targetSdkVersion <= Build.VERSION_CODES.O_MR1) {
+        if (targetSdkVersion < Build.VERSION_CODES.P) {
             setHiddenApiEnforcementPolicy(policyPreP);
-        } else if (targetSdkVersion > Build.VERSION_CODES.O_MR1) {
+        } else if (targetSdkVersion >= Build.VERSION_CODES.P) {
             setHiddenApiEnforcementPolicy(policyP);
         }
 
index 3e0db60..f0af604 100644 (file)
@@ -2726,7 +2726,7 @@ public class PackageParser {
 
         // Fot apps targeting O-MR1 we require explicit enumeration of all certs.
         String[] additionalCertSha256Digests = EmptyArray.STRING;
-        if (pkg.applicationInfo.targetSdkVersion > Build.VERSION_CODES.O) {
+        if (pkg.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.O_MR1) {
             additionalCertSha256Digests = parseAdditionalCertificates(res, parser, outError);
             if (additionalCertSha256Digests == null) {
                 return false;
index fa89432..b14b321 100644 (file)
@@ -62,7 +62,7 @@ public abstract class PackageSharedLibraryUpdater {
 
     static boolean apkTargetsApiLevelLessThanOrEqualToOMR1(PackageParser.Package pkg) {
         int targetSdkVersion = pkg.applicationInfo.targetSdkVersion;
-        return targetSdkVersion <= Build.VERSION_CODES.O_MR1;
+        return targetSdkVersion < Build.VERSION_CODES.P;
     }
 
     /**
index f332358..e60377b 100644 (file)
@@ -219,7 +219,7 @@ public class LinkMovementMethod extends ScrollingMovementMethod {
                     links[0].onClick(widget);
                 } else if (action == MotionEvent.ACTION_DOWN) {
                     if (widget.getContext().getApplicationInfo().targetSdkVersion
-                            > Build.VERSION_CODES.O_MR1) {
+                            >= Build.VERSION_CODES.P) {
                         // Selection change will reposition the toolbar. Hide it for a few ms for a
                         // smoother transition.
                         widget.hideFloatingToolbar(HIDE_FLOATING_TOOLBAR_DELAY_MS);
index 468abdc..1f2b90a 100644 (file)
@@ -969,7 +969,7 @@ public final class SelectionActionModeHelper {
             mHot = true;
             trimText();
             final TextSelection selection;
-            if (mContext.getApplicationInfo().targetSdkVersion > Build.VERSION_CODES.O_MR1) {
+            if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.P) {
                 final TextSelection.Request request = new TextSelection.Request.Builder(
                         mTrimmedText, mRelativeStart, mRelativeEnd)
                         .setDefaultLocales(mDefaultLocales)
@@ -1023,7 +1023,7 @@ public final class SelectionActionModeHelper {
 
                 trimText();
                 final TextClassification classification;
-                if (mContext.getApplicationInfo().targetSdkVersion > Build.VERSION_CODES.O_MR1) {
+                if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.P) {
                     final TextClassification.Request request =
                             new TextClassification.Request.Builder(
                                     mTrimmedText, mRelativeStart, mRelativeEnd)
index 04d54e1..e508ef0 100644 (file)
@@ -7684,7 +7684,7 @@ public class ActivityManagerService extends IActivityManager.Stub
             // target APIs higher than O MR1. Since access to the serial
             // is now behind a permission we push down the value.
             final String buildSerial = (appInfo.targetSandboxVersion < 2
-                    && appInfo.targetSdkVersion <= Build.VERSION_CODES.O_MR1)
+                    && appInfo.targetSdkVersion < Build.VERSION_CODES.P)
                             ? sTheRealBuildSerial : Build.UNKNOWN;
 
             // Check if this is a secondary process that should be incorporated into some
index 7e04d33..c5fb274 100644 (file)
@@ -1831,7 +1831,7 @@ public class NotificationManagerService extends SystemService {
         };
 
         int newSuppressedVisualEffects = incomingPolicy.suppressedVisualEffects;
-        if (targetSdkVersion <= Build.VERSION_CODES.O_MR1) {
+        if (targetSdkVersion < Build.VERSION_CODES.P) {
             // unset higher order bits introduced in P, maintain the user's higher order bits
             for (int i = 0; i < effectsIntroducedInP.length ; i++) {
                 newSuppressedVisualEffects &= ~effectsIntroducedInP[i];
@@ -3188,7 +3188,7 @@ public class NotificationManagerService extends SystemService {
                         0, UserHandle.getUserId(MY_UID));
                 Policy currPolicy = mZenModeHelper.getNotificationPolicy();
 
-                if (applicationInfo.targetSdkVersion <= Build.VERSION_CODES.O_MR1) {
+                if (applicationInfo.targetSdkVersion < Build.VERSION_CODES.P) {
                     int priorityCategories = policy.priorityCategories;
                     // ignore alarm and media values from new policy
                     priorityCategories &= ~Policy.PRIORITY_CATEGORY_ALARMS;
index 5b45cbe..e86a066 100644 (file)
@@ -9707,7 +9707,7 @@ public class PackageManagerService extends IPackageManager.Stub
                     if (expectedCertDigests.length > 1) {
 
                         // For apps targeting O MR1 we require explicit enumeration of all certs.
-                        final String[] libCertDigests = (targetSdk > Build.VERSION_CODES.O)
+                        final String[] libCertDigests = (targetSdk >= Build.VERSION_CODES.O_MR1)
                                 ? PackageUtils.computeSignaturesSha256Digests(
                                 libPkg.mSigningDetails.signatures)
                                 : PackageUtils.computeSignaturesSha256Digests(