Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit aa1a911d authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

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
parent 964631d1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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);
            }
+2 −2
Original line number Diff line number Diff line
@@ -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;
+3 −3
Original line number Diff line number Diff line
@@ -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);
        }

+1 −1
Original line number Diff line number Diff line
@@ -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;
+1 −1
Original line number Diff line number Diff line
@@ -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;
    }

    /**
Loading