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
} 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);
}
} 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 {
} 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;
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;
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);
}
// 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;
static boolean apkTargetsApiLevelLessThanOrEqualToOMR1(PackageParser.Package pkg) {
int targetSdkVersion = pkg.applicationInfo.targetSdkVersion;
- return targetSdkVersion <= Build.VERSION_CODES.O_MR1;
+ return targetSdkVersion < Build.VERSION_CODES.P;
}
/**
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);
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)
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)
// 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
};
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];
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;
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(