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
diff --git a/services/core/java/com/android/server/pm/ApexManager.java b/services/core/java/com/android/server/pm/ApexManager.java
index e12d1dc..a0304f2 100644
--- a/services/core/java/com/android/server/pm/ApexManager.java
+++ b/services/core/java/com/android/server/pm/ApexManager.java
@@ -188,6 +188,18 @@
     }
 
     /**
+     * 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.
      *
      * @param pw the {@link PrintWriter} object to send information to.