diff options
| author | 2018-04-10 15:18:12 -0600 | |
|---|---|---|
| committer | 2018-04-10 15:18:15 -0600 | |
| commit | aa1a911d9a0f797748b001c41bd8df2f517b318c (patch) | |
| tree | 8e7f65a3c08c5217fda0e4d8e308437534ab2fc4 | |
| parent | 964631d1a78842f4297d875012b0ebe1c08cd06d (diff) | |
Fix broken target SDK checks.
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
10 files changed, 15 insertions, 15 deletions
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 50a439897ed6..82c3383dc16a 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -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); } diff --git a/core/java/android/app/WallpaperManager.java b/core/java/android/app/WallpaperManager.java index 17bc6eab8012..6c2fb2dfebe5 100644 --- a/core/java/android/app/WallpaperManager.java +++ b/core/java/android/app/WallpaperManager.java @@ -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; diff --git a/core/java/android/content/pm/ApplicationInfo.java b/core/java/android/content/pm/ApplicationInfo.java index c5a39f4c4502..d65e051b70b4 100644 --- a/core/java/android/content/pm/ApplicationInfo.java +++ b/core/java/android/content/pm/ApplicationInfo.java @@ -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); } diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java index 3e0db609c47e..f0af6045943f 100644 --- a/core/java/android/content/pm/PackageParser.java +++ b/core/java/android/content/pm/PackageParser.java @@ -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; diff --git a/core/java/android/content/pm/PackageSharedLibraryUpdater.java b/core/java/android/content/pm/PackageSharedLibraryUpdater.java index fa894320b7d0..b14b321a2481 100644 --- a/core/java/android/content/pm/PackageSharedLibraryUpdater.java +++ b/core/java/android/content/pm/PackageSharedLibraryUpdater.java @@ -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; } /** diff --git a/core/java/android/text/method/LinkMovementMethod.java b/core/java/android/text/method/LinkMovementMethod.java index f33235889388..e60377b46e7d 100644 --- a/core/java/android/text/method/LinkMovementMethod.java +++ b/core/java/android/text/method/LinkMovementMethod.java @@ -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); diff --git a/core/java/android/widget/SelectionActionModeHelper.java b/core/java/android/widget/SelectionActionModeHelper.java index 468abdcb2c00..1f2b90a11616 100644 --- a/core/java/android/widget/SelectionActionModeHelper.java +++ b/core/java/android/widget/SelectionActionModeHelper.java @@ -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) diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 04d54e1dcb8d..e508ef0d1d8f 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -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 diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 7e04d3337e68..c5fb274211ff 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -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; diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java index 5b45cbe1f658..e86a0663aec2 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -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( |