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

Commit 83620602 authored by Dario Freni's avatar Dario Freni
Browse files

Disable APEX install on unsupported devices.

If the device ships with "flattened" APEXs, this will not be treated as
packages and therefore will not be updatable.

This CL also ensure that APEX files are only scheduled to be installed
as part of a staged session.

Fix: 124644545
Test: install succeeds on taimen (supported). Install fails on marlin
with following error.
$ adb install com.android.media.apex
Performing Streamed Install
adb: failed to install com.android.media.apex:
Exception occurred while executing:
java.lang.IllegalStateException: This device doesn't support the installation of APEX files
        at com.android.server.pm.PackageInstallerService.createSessionInternal(PackageInstallerService.java:497)
        at com.android.server.pm.PackageInstallerService.createSession(PackageInstallerService.java:450)
        at com.android.server.pm.PackageManagerShellCommand.doCreateSession(PackageManagerShellCommand.java:2587)
        at com.android.server.pm.PackageManagerShellCommand.runInstall(PackageManagerShellCommand.java:1011)
        at com.android.server.pm.PackageManagerShellCommand.onCommand(PackageManagerShellCommand.java:164)
        at android.os.ShellCommand.exec(ShellCommand.java:103)
        at com.android.server.pm.PackageManagerService.onShellCommand(PackageManagerService.java:20664)
        at android.os.Binder.shellCommand(Binder.java:887)
        at android.os.Binder.onTransact(Binder.java:771)
        at android.content.pm.IPackageManager$Stub.onTransact(IPackageManager.java:4689)
        at com.android.server.pm.PackageManagerService.onTransact(PackageManagerService.java:3698)
        at android.os.Binder.execTransactInternal(Binder.java:1026)
        at android.os.Binder.execTransact(Binder.java:999)

Change-Id: I6cc0c1d4cb143197cf4cc88a86dc6b758c6c70b2
parent 3deb23fe
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -187,6 +187,18 @@ class ApexManager {
        }
    }

    /**
     * Whether the current device supports the management of APEX packages.
     *
     * @return true if APEX packages can be managed on this device, false otherwise.
     */
    boolean isApexSupported() {
        // There is no system-wide property available to check if APEX are flattened and hence can't
        // be updated. In absence of such property, we assume that if we didn't index APEX packages
        // since they were flattened, no APEX management should be possible.
        return !mActivePackagesCache.isEmpty();
    }

    /**
     * Dumps various state information to the provided {@link PrintWriter} object.
     *
+13 −0
Original line number Diff line number Diff line
@@ -130,6 +130,7 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements

    private final Context mContext;
    private final PackageManagerService mPm;
    private final ApexManager mApexManager;
    private final StagingManager mStagingManager;
    private final PermissionManagerServiceInternal mPermissionManager;

@@ -204,6 +205,7 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
        mSessionsDir = new File(Environment.getDataSystemDirectory(), "install_sessions");
        mSessionsDir.mkdirs();

        mApexManager = am;
        mStagingManager = new StagingManager(pm, this, am);
    }

@@ -485,6 +487,17 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
            mContext.enforceCallingOrSelfPermission(Manifest.permission.INSTALL_PACKAGES, TAG);
        }

        if ((params.installFlags & PackageManager.INSTALL_APEX) != 0) {
            if (!mApexManager.isApexSupported()) {
                throw new IllegalArgumentException(
                    "This device doesn't support the installation of APEX files");
            }
            if (!params.isStaged) {
                throw new IllegalArgumentException(
                    "APEX files can only be installed as part of a staged session.");
            }
        }

        if (!params.isMultiPackage) {
            // Only system components can circumvent runtime permissions when installing.
            if ((params.installFlags & PackageManager.INSTALL_GRANT_RUNTIME_PERMISSIONS) != 0