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

Commit ab223112 authored by Przemyslaw Szczepaniak's avatar Przemyslaw Szczepaniak
Browse files

Reject apks targeting deprecated sdk

As part of deprecation policy enforcement for android apps, minimum
supported targetSdkVersion will be 17. Apks targeting values lower that
one set in PLATFORM_MIN_SUPPORTED_TARGET_SDK_VERSION will fail to install.

PLATFORM_MIN_SUPPORTED_TARGET_SDK_VERSION is currently set to 0 and
will be set to 17 in a following cl.

Installation of deprecated apks can be forced using adb install
--force-sdk flag.

More details in http://go/android-platform-deprecation-policy.

Test: tests are in complementary Cts cl.
Bug: 63926630
Change-Id: I8e55bdebf1fb2cfd951e2c6703ccc87b8d4e9a09
parent 73b6bc86
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.content.Context;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Environment;
import android.os.Parcel;
import android.os.Parcelable;
@@ -1582,6 +1583,11 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
        return (privateFlags & ApplicationInfo.PRIVATE_FLAG_VENDOR) != 0;
    }

    /** @hide */
    public boolean isTargetingDeprecatedSdkVersion() {
        return targetSdkVersion < Build.VERSION.MIN_SUPPORTED_TARGET_SDK_INT;
    }

    /**
     * Returns whether or not this application was installed as a virtual preload.
     */
+11 −0
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import static android.content.pm.PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
import static android.content.pm.PackageManager.INSTALL_FAILED_INVALID_APK;
import static android.content.pm.PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION;
import static android.content.pm.PackageManager.INSTALL_FAILED_MISSING_SHARED_LIBRARY;
import static android.content.pm.PackageManager.INSTALL_FAILED_NEWER_SDK;
import static android.content.pm.PackageManager.INSTALL_FAILED_PACKAGE_CHANGED;
import static android.content.pm.PackageManager.INSTALL_FAILED_REPLACE_COULDNT_DELETE;
import static android.content.pm.PackageManager.INSTALL_FAILED_SANDBOX_VERSION_DOWNGRADE;
@@ -16283,6 +16284,16 @@ public class PackageManagerService extends IPackageManager.Stub
            Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
        }
        // App targetSdkVersion is below min supported version
        if (!forceSdk && pkg.applicationInfo.isTargetingDeprecatedSdkVersion()) {
            Slog.w(TAG, "App " + pkg.packageName + " targets deprecated sdk");
            res.setError(INSTALL_FAILED_NEWER_SDK,
                    "App is targeting deprecated sdk (targetSdkVersion should be at least "
                    + Build.VERSION.MIN_SUPPORTED_TARGET_SDK_INT + ").");
            return;
        }
        // Instant apps must have target SDK >= O and have targetSanboxVersion >= 2
        if (instantApp && pkg.applicationInfo.targetSdkVersion <= Build.VERSION_CODES.N_MR1) {
            Slog.w(TAG, "Instant app package " + pkg.packageName + " does not target O");