diff options
| author | Chris Li <lihongyu@google.com> | 2020-04-16 17:48:59 -0700 |
|---|---|---|
| committer | Chris Li <lihongyu@google.com> | 2020-04-27 11:35:31 -0700 |
| commit | e7f4f30698c3e460bbb41797079a686c30f5f9ff (patch) | |
| tree | 722f615b45a899cb34900b1e751078be0f108a9d /core/java | |
| parent | 16ee6e725f0d7e4dbb6bea8684036c1c6ae35bbc (diff) | |
Cache isSystemOrSystemUI on ContextImpl creation
When creating Context without a container Context, cache the value of #isSystemOrSystemUI().
Fix: 154161051
Test: atest FrameworksCoreTests:ContextTest
Change-Id: I1d16173c7da06a73d1338e3d6e75f5b56fcdbe23
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/app/ContextImpl.java | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java index bb64c3492c4f..a4256a9d8ab3 100644 --- a/core/java/android/app/ContextImpl.java +++ b/core/java/android/app/ContextImpl.java @@ -250,6 +250,10 @@ class ContextImpl extends Context { private final Object mSync = new Object(); + /** + * Whether this is created from {@link #createSystemContext(ActivityThread)} or + * {@link #createSystemUiContext(ContextImpl, int)} or any {@link Context} that system UI uses. + */ private boolean mIsSystemOrSystemUiContext; private boolean mIsUiContext; private boolean mIsAssociatedWithDisplay; @@ -1922,16 +1926,18 @@ class ContextImpl extends Context { /** @hide */ @Override public boolean isUiContext() { - return mIsSystemOrSystemUiContext || mIsUiContext || isSystemOrSystemUI(); + return mIsSystemOrSystemUiContext || mIsUiContext; } /** * Temporary workaround to permit incorrect usages of Context by SystemUI. - * TODO(b/149790106): Fix usages and remove. + * TODO(b/147647877): Fix usages and remove. */ - private boolean isSystemOrSystemUI() { - return ActivityThread.isSystem() || checkPermission("android.permission.STATUS_BAR_SERVICE", - Binder.getCallingPid(), Binder.getCallingUid()) == PERMISSION_GRANTED; + private static boolean isSystemOrSystemUI(Context context) { + return ActivityThread.isSystem() || context.checkPermission( + "android.permission.STATUS_BAR_SERVICE", + Binder.getCallingPid(), + Binder.getCallingUid()) == PERMISSION_GRANTED; } private static boolean isUiComponent(String name) { @@ -2467,7 +2473,7 @@ class ContextImpl extends Context { @Override public Display getDisplay() { - if (!mIsSystemOrSystemUiContext && !mIsAssociatedWithDisplay && !isSystemOrSystemUI()) { + if (!mIsSystemOrSystemUiContext && !mIsAssociatedWithDisplay) { throw new UnsupportedOperationException("Tried to obtain display from a Context not " + "associated with one. Only visual Contexts (such as Activity or one created " + "with Context#createWindowContext) or ones created with " @@ -2643,6 +2649,7 @@ class ContextImpl extends Context { ContextImpl context = new ContextImpl(null, mainThread, packageInfo, null, null, null, null, 0, null, opPackageName); context.setResources(packageInfo.getResources()); + context.mIsSystemOrSystemUiContext = isSystemOrSystemUI(context); return context; } @@ -2672,6 +2679,7 @@ class ContextImpl extends Context { activityInfo.splitName, activityToken, null, 0, classLoader, null); context.mIsUiContext = true; context.mIsAssociatedWithDisplay = true; + context.mIsSystemOrSystemUiContext = isSystemOrSystemUI(context); // Clamp display ID to DEFAULT_DISPLAY if it is INVALID_DISPLAY. displayId = (displayId != Display.INVALID_DISPLAY) ? displayId : Display.DEFAULT_DISPLAY; |
