Loading core/java/android/app/ApplicationPackageManager.java +22 −2 Original line number Diff line number Diff line Loading @@ -200,6 +200,8 @@ public class ApplicationPackageManager extends PackageManager { @GuardedBy("mPackageMonitorCallbacks") private final ArraySet<IRemoteCallback> mPackageMonitorCallbacks = new ArraySet<>(); private final boolean mUseSystemFeaturesCache; UserManager getUserManager() { if (mUserManager == null) { mUserManager = UserManager.get(mContext); Loading Loading @@ -824,8 +826,7 @@ public class ApplicationPackageManager extends PackageManager { if (maybeHasSystemFeature != null) { return maybeHasSystemFeature; } if (com.android.internal.os.Flags.applicationSharedMemoryEnabled() && android.content.pm.Flags.cacheSdkSystemFeatures()) { if (mUseSystemFeaturesCache) { maybeHasSystemFeature = SystemFeaturesCache.getInstance().maybeHasFeature(name, version); if (maybeHasSystemFeature != null) { Loading Loading @@ -2221,6 +2222,25 @@ public class ApplicationPackageManager extends PackageManager { protected ApplicationPackageManager(ContextImpl context, IPackageManager pm) { mContext = context; mPM = pm; mUseSystemFeaturesCache = isSystemFeaturesCacheEnabledAndAvailable(); } private static boolean isSystemFeaturesCacheEnabledAndAvailable() { if (!android.content.pm.Flags.cacheSdkSystemFeatures()) { return false; } if (!com.android.internal.os.Flags.applicationSharedMemoryEnabled()) { return false; } if (ActivityThread.isSystem() && !SystemFeaturesCache.hasInstance()) { // There are a handful of utility "system" processes that are neither system_server nor // bound as applications. For these processes, we don't have access to application // shared memory or the dependent system features cache. // TODO(b/400713460): Revisit this exception after deprecating these command-like // system processes. return false; } return true; } /** Loading core/java/android/content/pm/SystemFeaturesCache.java +5 −0 Original line number Diff line number Diff line Loading @@ -74,6 +74,11 @@ public final class SystemFeaturesCache { return instance; } /** Checks for existence of the process-global instance. */ public static boolean hasInstance() { return sInstance != null; } /** Clears the process-global cache instance for testing. */ @VisibleForTesting public static void clearInstance() { Loading core/tests/coretests/src/android/content/pm/SystemFeaturesCacheTest.java +3 −0 Original line number Diff line number Diff line Loading @@ -136,9 +136,11 @@ public class SystemFeaturesCacheTest { SystemFeaturesCache cache = new SystemFeaturesCache(features); SystemFeaturesCache.clearInstance(); assertThat(SystemFeaturesCache.hasInstance()).isFalse(); assertThrows(IllegalStateException.class, () -> SystemFeaturesCache.getInstance()); SystemFeaturesCache.setInstance(cache); assertThat(SystemFeaturesCache.hasInstance()).isTrue(); assertThat(SystemFeaturesCache.getInstance()).isEqualTo(cache); assertThrows( Loading @@ -149,6 +151,7 @@ public class SystemFeaturesCacheTest { @Test public void testSingletonAutomaticallySetWithFeatureEnabled() { assumeTrue(android.content.pm.Flags.cacheSdkSystemFeatures()); assertThat(SystemFeaturesCache.hasInstance()).isTrue(); assertThat(SystemFeaturesCache.getInstance()).isNotNull(); } Loading Loading
core/java/android/app/ApplicationPackageManager.java +22 −2 Original line number Diff line number Diff line Loading @@ -200,6 +200,8 @@ public class ApplicationPackageManager extends PackageManager { @GuardedBy("mPackageMonitorCallbacks") private final ArraySet<IRemoteCallback> mPackageMonitorCallbacks = new ArraySet<>(); private final boolean mUseSystemFeaturesCache; UserManager getUserManager() { if (mUserManager == null) { mUserManager = UserManager.get(mContext); Loading Loading @@ -824,8 +826,7 @@ public class ApplicationPackageManager extends PackageManager { if (maybeHasSystemFeature != null) { return maybeHasSystemFeature; } if (com.android.internal.os.Flags.applicationSharedMemoryEnabled() && android.content.pm.Flags.cacheSdkSystemFeatures()) { if (mUseSystemFeaturesCache) { maybeHasSystemFeature = SystemFeaturesCache.getInstance().maybeHasFeature(name, version); if (maybeHasSystemFeature != null) { Loading Loading @@ -2221,6 +2222,25 @@ public class ApplicationPackageManager extends PackageManager { protected ApplicationPackageManager(ContextImpl context, IPackageManager pm) { mContext = context; mPM = pm; mUseSystemFeaturesCache = isSystemFeaturesCacheEnabledAndAvailable(); } private static boolean isSystemFeaturesCacheEnabledAndAvailable() { if (!android.content.pm.Flags.cacheSdkSystemFeatures()) { return false; } if (!com.android.internal.os.Flags.applicationSharedMemoryEnabled()) { return false; } if (ActivityThread.isSystem() && !SystemFeaturesCache.hasInstance()) { // There are a handful of utility "system" processes that are neither system_server nor // bound as applications. For these processes, we don't have access to application // shared memory or the dependent system features cache. // TODO(b/400713460): Revisit this exception after deprecating these command-like // system processes. return false; } return true; } /** Loading
core/java/android/content/pm/SystemFeaturesCache.java +5 −0 Original line number Diff line number Diff line Loading @@ -74,6 +74,11 @@ public final class SystemFeaturesCache { return instance; } /** Checks for existence of the process-global instance. */ public static boolean hasInstance() { return sInstance != null; } /** Clears the process-global cache instance for testing. */ @VisibleForTesting public static void clearInstance() { Loading
core/tests/coretests/src/android/content/pm/SystemFeaturesCacheTest.java +3 −0 Original line number Diff line number Diff line Loading @@ -136,9 +136,11 @@ public class SystemFeaturesCacheTest { SystemFeaturesCache cache = new SystemFeaturesCache(features); SystemFeaturesCache.clearInstance(); assertThat(SystemFeaturesCache.hasInstance()).isFalse(); assertThrows(IllegalStateException.class, () -> SystemFeaturesCache.getInstance()); SystemFeaturesCache.setInstance(cache); assertThat(SystemFeaturesCache.hasInstance()).isTrue(); assertThat(SystemFeaturesCache.getInstance()).isEqualTo(cache); assertThrows( Loading @@ -149,6 +151,7 @@ public class SystemFeaturesCacheTest { @Test public void testSingletonAutomaticallySetWithFeatureEnabled() { assumeTrue(android.content.pm.Flags.cacheSdkSystemFeatures()); assertThat(SystemFeaturesCache.hasInstance()).isTrue(); assertThat(SystemFeaturesCache.getInstance()).isNotNull(); } Loading