Loading core/java/android/app/ContextImpl.java +79 −73 Original line number Original line Diff line number Diff line Loading @@ -33,6 +33,7 @@ import android.content.IntentSender; import android.content.ReceiverCallNotAllowedException; import android.content.ReceiverCallNotAllowedException; import android.content.ServiceConnection; import android.content.ServiceConnection; import android.content.SharedPreferences; import android.content.SharedPreferences; import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo; import android.content.pm.IPackageManager; import android.content.pm.IPackageManager; import android.content.pm.PackageManager; import android.content.pm.PackageManager; Loading Loading @@ -159,7 +160,7 @@ class ContextImpl extends Context { private final String mOpPackageName; private final String mOpPackageName; private final @NonNull ResourcesManager mResourcesManager; private final @NonNull ResourcesManager mResourcesManager; private @NonNull Resources mResources; private final @NonNull Resources mResources; private @Nullable Display mDisplay; // may be null if default display private @Nullable Display mDisplay; // may be null if default display private final int mFlags; private final int mFlags; Loading Loading @@ -1834,19 +1835,6 @@ class ContextImpl extends Context { } } } } private static Resources createResources(IBinder activityToken, LoadedApk pi, int displayId, Configuration overrideConfig, CompatibilityInfo compatInfo) { return ResourcesManager.getInstance().getResources(activityToken, pi.getResDir(), pi.getSplitResDirs(), pi.getOverlayDirs(), pi.getApplicationInfo().sharedLibraryFiles, displayId, overrideConfig, compatInfo, pi.getClassLoader()); } @Override @Override public Context createApplicationContext(ApplicationInfo application, int flags) public Context createApplicationContext(ApplicationInfo application, int flags) throws NameNotFoundException { throws NameNotFoundException { Loading @@ -1854,13 +1842,8 @@ class ContextImpl extends Context { flags | CONTEXT_REGISTER_PACKAGE); flags | CONTEXT_REGISTER_PACKAGE); if (pi != null) { if (pi != null) { ContextImpl c = new ContextImpl(this, mMainThread, pi, mActivityToken, ContextImpl c = new ContextImpl(this, mMainThread, pi, mActivityToken, new UserHandle(UserHandle.getUserId(application.uid)), flags); new UserHandle(UserHandle.getUserId(application.uid)), flags, mDisplay, null, Display.INVALID_DISPLAY); final int displayId = mDisplay != null ? mDisplay.getDisplayId() : Display.DEFAULT_DISPLAY; c.mResources = createResources(mActivityToken, pi, displayId, null, getDisplayAdjustments(displayId).getCompatibilityInfo()); if (c.mResources != null) { if (c.mResources != null) { return c; return c; } } Loading @@ -1881,21 +1864,15 @@ class ContextImpl extends Context { public Context createPackageContextAsUser(String packageName, int flags, UserHandle user) public Context createPackageContextAsUser(String packageName, int flags, UserHandle user) throws NameNotFoundException { throws NameNotFoundException { if (packageName.equals("system") || packageName.equals("android")) { if (packageName.equals("system") || packageName.equals("android")) { // The system resources are loaded in every application, so we can safely copy return new ContextImpl(this, mMainThread, mPackageInfo, mActivityToken, // the context without reloading Resources. user, flags, mDisplay, null, Display.INVALID_DISPLAY); return new ContextImpl(this, mMainThread, mPackageInfo, mActivityToken, user, flags); } } LoadedApk pi = mMainThread.getPackageInfo(packageName, mResources.getCompatibilityInfo(), LoadedApk pi = mMainThread.getPackageInfo(packageName, mResources.getCompatibilityInfo(), flags | CONTEXT_REGISTER_PACKAGE, user.getIdentifier()); flags | CONTEXT_REGISTER_PACKAGE, user.getIdentifier()); if (pi != null) { if (pi != null) { ContextImpl c = new ContextImpl(this, mMainThread, pi, mActivityToken, user, flags); ContextImpl c = new ContextImpl(this, mMainThread, pi, mActivityToken, user, flags, mDisplay, null, Display.INVALID_DISPLAY); final int displayId = mDisplay != null ? mDisplay.getDisplayId() : Display.DEFAULT_DISPLAY; c.mResources = createResources(mActivityToken, pi, displayId, null, getDisplayAdjustments(displayId).getCompatibilityInfo()); if (c.mResources != null) { if (c.mResources != null) { return c; return c; } } Loading @@ -1912,14 +1889,8 @@ class ContextImpl extends Context { throw new IllegalArgumentException("overrideConfiguration must not be null"); throw new IllegalArgumentException("overrideConfiguration must not be null"); } } ContextImpl context = new ContextImpl(this, mMainThread, mPackageInfo, mActivityToken, return new ContextImpl(this, mMainThread, mPackageInfo, mActivityToken, mUser, mFlags); mUser, mFlags, mDisplay, overrideConfiguration, Display.INVALID_DISPLAY); final int displayId = mDisplay != null ? mDisplay.getDisplayId() : Display.DEFAULT_DISPLAY; context.mResources = createResources(mActivityToken, mPackageInfo, displayId, overrideConfiguration, getDisplayAdjustments(displayId).getCompatibilityInfo()); context.mDisplay = mDisplay; return context; } } @Override @Override Loading @@ -1928,28 +1899,24 @@ class ContextImpl extends Context { throw new IllegalArgumentException("display must not be null"); throw new IllegalArgumentException("display must not be null"); } } ContextImpl context = new ContextImpl(this, mMainThread, mPackageInfo, mActivityToken, return new ContextImpl(this, mMainThread, mPackageInfo, mActivityToken, mUser, mFlags); mUser, mFlags, display, null, Display.INVALID_DISPLAY); final int displayId = display.getDisplayId(); context.mResources = createResources(mActivityToken, mPackageInfo, displayId, null, getDisplayAdjustments(displayId).getCompatibilityInfo()); context.mDisplay = display; return context; } } @Override @Override public Context createDeviceProtectedStorageContext() { public Context createDeviceProtectedStorageContext() { final int flags = (mFlags & ~Context.CONTEXT_CREDENTIAL_PROTECTED_STORAGE) final int flags = (mFlags & ~Context.CONTEXT_CREDENTIAL_PROTECTED_STORAGE) | Context.CONTEXT_DEVICE_PROTECTED_STORAGE; | Context.CONTEXT_DEVICE_PROTECTED_STORAGE; return new ContextImplFlagContextWrapper(this, flags); return new ContextImpl(this, mMainThread, mPackageInfo, mActivityToken, mUser, flags, mDisplay, null, Display.INVALID_DISPLAY); } } @Override @Override public Context createCredentialProtectedStorageContext() { public Context createCredentialProtectedStorageContext() { final int flags = (mFlags & ~Context.CONTEXT_DEVICE_PROTECTED_STORAGE) final int flags = (mFlags & ~Context.CONTEXT_DEVICE_PROTECTED_STORAGE) | Context.CONTEXT_CREDENTIAL_PROTECTED_STORAGE; | Context.CONTEXT_CREDENTIAL_PROTECTED_STORAGE; return new ContextImplFlagContextWrapper(this, flags); return new ContextImpl(this, mMainThread, mPackageInfo, mActivityToken, mUser, flags, mDisplay, null, Display.INVALID_DISPLAY); } } @Override @Override Loading Loading @@ -2036,8 +2003,8 @@ class ContextImpl extends Context { static ContextImpl createSystemContext(ActivityThread mainThread) { static ContextImpl createSystemContext(ActivityThread mainThread) { LoadedApk packageInfo = new LoadedApk(mainThread); LoadedApk packageInfo = new LoadedApk(mainThread); ContextImpl context = new ContextImpl(null, mainThread, packageInfo, null, null, 0); ContextImpl context = new ContextImpl(null, mainThread, context.mResources = packageInfo.getResources(mainThread); packageInfo, null, null, 0, null, null, Display.INVALID_DISPLAY); context.mResources.updateConfiguration(context.mResourcesManager.getConfiguration(), context.mResources.updateConfiguration(context.mResourcesManager.getConfiguration(), context.mResourcesManager.getDisplayMetrics()); context.mResourcesManager.getDisplayMetrics()); return context; return context; Loading @@ -2045,35 +2012,21 @@ class ContextImpl extends Context { static ContextImpl createAppContext(ActivityThread mainThread, LoadedApk packageInfo) { static ContextImpl createAppContext(ActivityThread mainThread, LoadedApk packageInfo) { if (packageInfo == null) throw new IllegalArgumentException("packageInfo"); if (packageInfo == null) throw new IllegalArgumentException("packageInfo"); ContextImpl context = new ContextImpl(null, mainThread, packageInfo, null, null, 0); return new ContextImpl(null, mainThread, context.mResources = packageInfo.getResources(mainThread); packageInfo, null, null, 0, null, null, Display.INVALID_DISPLAY); return context; } } static ContextImpl createActivityContext(ActivityThread mainThread, static ContextImpl createActivityContext(ActivityThread mainThread, LoadedApk packageInfo, IBinder activityToken, int displayId, LoadedApk packageInfo, IBinder activityToken, int displayId, Configuration overrideConfiguration) { Configuration overrideConfiguration) { if (packageInfo == null) throw new IllegalArgumentException("packageInfo"); if (packageInfo == null) throw new IllegalArgumentException("packageInfo"); return new ContextImpl(null, mainThread, packageInfo, activityToken, null, 0, ContextImpl context = new ContextImpl(null, mainThread, packageInfo, activityToken, null, null, overrideConfiguration, displayId); 0); // Clamp display ID to DEFAULT_DISPLAY if it is INVALID_DISPLAY. displayId = (displayId != Display.INVALID_DISPLAY) ? displayId : Display.DEFAULT_DISPLAY; final CompatibilityInfo compatInfo = (displayId == Display.DEFAULT_DISPLAY) ? packageInfo.getCompatibilityInfo() : CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO; context.mResources = createResources(activityToken, packageInfo, displayId, overrideConfiguration, compatInfo); context.mDisplay = ResourcesManager.getInstance().getAdjustedDisplay(displayId, context.mResources.getDisplayAdjustments()); return context; } } private ContextImpl(ContextImpl container, ActivityThread mainThread, private ContextImpl(ContextImpl container, ActivityThread mainThread, LoadedApk packageInfo, IBinder activityToken, UserHandle user, int flags) { LoadedApk packageInfo, IBinder activityToken, UserHandle user, int flags, Display display, Configuration overrideConfiguration, int createDisplayWithId) { mOuterContext = this; mOuterContext = this; // If creator didn't specify which storage to use, use the default // If creator didn't specify which storage to use, use the default Loading @@ -2100,11 +2053,64 @@ class ContextImpl extends Context { mPackageInfo = packageInfo; mPackageInfo = packageInfo; mResourcesManager = ResourcesManager.getInstance(); mResourcesManager = ResourcesManager.getInstance(); final int displayId = (createDisplayWithId != Display.INVALID_DISPLAY) ? createDisplayWithId : (display != null) ? display.getDisplayId() : Display.DEFAULT_DISPLAY; CompatibilityInfo compatInfo = null; if (container != null) { compatInfo = container.getDisplayAdjustments(displayId).getCompatibilityInfo(); } if (compatInfo == null) { compatInfo = (displayId == Display.DEFAULT_DISPLAY) ? packageInfo.getCompatibilityInfo() : CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO; } Resources resources = packageInfo.getResources(mainThread); if (resources != null) { if (displayId != Display.DEFAULT_DISPLAY || overrideConfiguration != null || (compatInfo != null && compatInfo.applicationScale != resources.getCompatibilityInfo().applicationScale)) { if (container != null) { // This is a nested Context, so it can't be a base Activity context. // Just create a regular Resources object associated with the Activity. resources = mResourcesManager.getResources( activityToken, packageInfo.getResDir(), packageInfo.getSplitResDirs(), packageInfo.getOverlayDirs(), packageInfo.getApplicationInfo().sharedLibraryFiles, displayId, overrideConfiguration, compatInfo, packageInfo.getClassLoader()); } else { // This is not a nested Context, so it must be the root Activity context. // All other nested Contexts will inherit the configuration set here. resources = mResourcesManager.createBaseActivityResources( activityToken, packageInfo.getResDir(), packageInfo.getSplitResDirs(), packageInfo.getOverlayDirs(), packageInfo.getApplicationInfo().sharedLibraryFiles, displayId, overrideConfiguration, compatInfo, packageInfo.getClassLoader()); } } } mResources = resources; mDisplay = (createDisplayWithId == Display.INVALID_DISPLAY) ? display : mResourcesManager.getAdjustedDisplay(displayId, mResources.getDisplayAdjustments()); if (container != null) { if (container != null) { mBasePackageName = container.mBasePackageName; mBasePackageName = container.mBasePackageName; mOpPackageName = container.mOpPackageName; mOpPackageName = container.mOpPackageName; mResources = container.getResources(); mDisplay = container.getDisplay(); } else { } else { mBasePackageName = packageInfo.mPackageName; mBasePackageName = packageInfo.mPackageName; ApplicationInfo ainfo = packageInfo.getApplicationInfo(); ApplicationInfo ainfo = packageInfo.getApplicationInfo(); Loading core/java/android/app/ContextImplFlagContextWrapper.javadeleted 100644 → 0 +0 −43 Original line number Original line Diff line number Diff line /* * Copyright (C) 2016 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.app; import android.content.Context; import android.content.ContextWrapper; class ContextImplFlagContextWrapper extends ContextWrapper { private final int mFlags; public ContextImplFlagContextWrapper(Context base, int flags) { super(base); mFlags = flags; } @Override public boolean isRestricted() { return (mFlags & Context.CONTEXT_RESTRICTED) != 0; } @Override public boolean isDeviceProtectedStorage() { return (mFlags & Context.CONTEXT_DEVICE_PROTECTED_STORAGE) != 0; } @Override public boolean isCredentialProtectedStorage() { return (mFlags & Context.CONTEXT_CREDENTIAL_PROTECTED_STORAGE) != 0; } } Loading
core/java/android/app/ContextImpl.java +79 −73 Original line number Original line Diff line number Diff line Loading @@ -33,6 +33,7 @@ import android.content.IntentSender; import android.content.ReceiverCallNotAllowedException; import android.content.ReceiverCallNotAllowedException; import android.content.ServiceConnection; import android.content.ServiceConnection; import android.content.SharedPreferences; import android.content.SharedPreferences; import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo; import android.content.pm.IPackageManager; import android.content.pm.IPackageManager; import android.content.pm.PackageManager; import android.content.pm.PackageManager; Loading Loading @@ -159,7 +160,7 @@ class ContextImpl extends Context { private final String mOpPackageName; private final String mOpPackageName; private final @NonNull ResourcesManager mResourcesManager; private final @NonNull ResourcesManager mResourcesManager; private @NonNull Resources mResources; private final @NonNull Resources mResources; private @Nullable Display mDisplay; // may be null if default display private @Nullable Display mDisplay; // may be null if default display private final int mFlags; private final int mFlags; Loading Loading @@ -1834,19 +1835,6 @@ class ContextImpl extends Context { } } } } private static Resources createResources(IBinder activityToken, LoadedApk pi, int displayId, Configuration overrideConfig, CompatibilityInfo compatInfo) { return ResourcesManager.getInstance().getResources(activityToken, pi.getResDir(), pi.getSplitResDirs(), pi.getOverlayDirs(), pi.getApplicationInfo().sharedLibraryFiles, displayId, overrideConfig, compatInfo, pi.getClassLoader()); } @Override @Override public Context createApplicationContext(ApplicationInfo application, int flags) public Context createApplicationContext(ApplicationInfo application, int flags) throws NameNotFoundException { throws NameNotFoundException { Loading @@ -1854,13 +1842,8 @@ class ContextImpl extends Context { flags | CONTEXT_REGISTER_PACKAGE); flags | CONTEXT_REGISTER_PACKAGE); if (pi != null) { if (pi != null) { ContextImpl c = new ContextImpl(this, mMainThread, pi, mActivityToken, ContextImpl c = new ContextImpl(this, mMainThread, pi, mActivityToken, new UserHandle(UserHandle.getUserId(application.uid)), flags); new UserHandle(UserHandle.getUserId(application.uid)), flags, mDisplay, null, Display.INVALID_DISPLAY); final int displayId = mDisplay != null ? mDisplay.getDisplayId() : Display.DEFAULT_DISPLAY; c.mResources = createResources(mActivityToken, pi, displayId, null, getDisplayAdjustments(displayId).getCompatibilityInfo()); if (c.mResources != null) { if (c.mResources != null) { return c; return c; } } Loading @@ -1881,21 +1864,15 @@ class ContextImpl extends Context { public Context createPackageContextAsUser(String packageName, int flags, UserHandle user) public Context createPackageContextAsUser(String packageName, int flags, UserHandle user) throws NameNotFoundException { throws NameNotFoundException { if (packageName.equals("system") || packageName.equals("android")) { if (packageName.equals("system") || packageName.equals("android")) { // The system resources are loaded in every application, so we can safely copy return new ContextImpl(this, mMainThread, mPackageInfo, mActivityToken, // the context without reloading Resources. user, flags, mDisplay, null, Display.INVALID_DISPLAY); return new ContextImpl(this, mMainThread, mPackageInfo, mActivityToken, user, flags); } } LoadedApk pi = mMainThread.getPackageInfo(packageName, mResources.getCompatibilityInfo(), LoadedApk pi = mMainThread.getPackageInfo(packageName, mResources.getCompatibilityInfo(), flags | CONTEXT_REGISTER_PACKAGE, user.getIdentifier()); flags | CONTEXT_REGISTER_PACKAGE, user.getIdentifier()); if (pi != null) { if (pi != null) { ContextImpl c = new ContextImpl(this, mMainThread, pi, mActivityToken, user, flags); ContextImpl c = new ContextImpl(this, mMainThread, pi, mActivityToken, user, flags, mDisplay, null, Display.INVALID_DISPLAY); final int displayId = mDisplay != null ? mDisplay.getDisplayId() : Display.DEFAULT_DISPLAY; c.mResources = createResources(mActivityToken, pi, displayId, null, getDisplayAdjustments(displayId).getCompatibilityInfo()); if (c.mResources != null) { if (c.mResources != null) { return c; return c; } } Loading @@ -1912,14 +1889,8 @@ class ContextImpl extends Context { throw new IllegalArgumentException("overrideConfiguration must not be null"); throw new IllegalArgumentException("overrideConfiguration must not be null"); } } ContextImpl context = new ContextImpl(this, mMainThread, mPackageInfo, mActivityToken, return new ContextImpl(this, mMainThread, mPackageInfo, mActivityToken, mUser, mFlags); mUser, mFlags, mDisplay, overrideConfiguration, Display.INVALID_DISPLAY); final int displayId = mDisplay != null ? mDisplay.getDisplayId() : Display.DEFAULT_DISPLAY; context.mResources = createResources(mActivityToken, mPackageInfo, displayId, overrideConfiguration, getDisplayAdjustments(displayId).getCompatibilityInfo()); context.mDisplay = mDisplay; return context; } } @Override @Override Loading @@ -1928,28 +1899,24 @@ class ContextImpl extends Context { throw new IllegalArgumentException("display must not be null"); throw new IllegalArgumentException("display must not be null"); } } ContextImpl context = new ContextImpl(this, mMainThread, mPackageInfo, mActivityToken, return new ContextImpl(this, mMainThread, mPackageInfo, mActivityToken, mUser, mFlags); mUser, mFlags, display, null, Display.INVALID_DISPLAY); final int displayId = display.getDisplayId(); context.mResources = createResources(mActivityToken, mPackageInfo, displayId, null, getDisplayAdjustments(displayId).getCompatibilityInfo()); context.mDisplay = display; return context; } } @Override @Override public Context createDeviceProtectedStorageContext() { public Context createDeviceProtectedStorageContext() { final int flags = (mFlags & ~Context.CONTEXT_CREDENTIAL_PROTECTED_STORAGE) final int flags = (mFlags & ~Context.CONTEXT_CREDENTIAL_PROTECTED_STORAGE) | Context.CONTEXT_DEVICE_PROTECTED_STORAGE; | Context.CONTEXT_DEVICE_PROTECTED_STORAGE; return new ContextImplFlagContextWrapper(this, flags); return new ContextImpl(this, mMainThread, mPackageInfo, mActivityToken, mUser, flags, mDisplay, null, Display.INVALID_DISPLAY); } } @Override @Override public Context createCredentialProtectedStorageContext() { public Context createCredentialProtectedStorageContext() { final int flags = (mFlags & ~Context.CONTEXT_DEVICE_PROTECTED_STORAGE) final int flags = (mFlags & ~Context.CONTEXT_DEVICE_PROTECTED_STORAGE) | Context.CONTEXT_CREDENTIAL_PROTECTED_STORAGE; | Context.CONTEXT_CREDENTIAL_PROTECTED_STORAGE; return new ContextImplFlagContextWrapper(this, flags); return new ContextImpl(this, mMainThread, mPackageInfo, mActivityToken, mUser, flags, mDisplay, null, Display.INVALID_DISPLAY); } } @Override @Override Loading Loading @@ -2036,8 +2003,8 @@ class ContextImpl extends Context { static ContextImpl createSystemContext(ActivityThread mainThread) { static ContextImpl createSystemContext(ActivityThread mainThread) { LoadedApk packageInfo = new LoadedApk(mainThread); LoadedApk packageInfo = new LoadedApk(mainThread); ContextImpl context = new ContextImpl(null, mainThread, packageInfo, null, null, 0); ContextImpl context = new ContextImpl(null, mainThread, context.mResources = packageInfo.getResources(mainThread); packageInfo, null, null, 0, null, null, Display.INVALID_DISPLAY); context.mResources.updateConfiguration(context.mResourcesManager.getConfiguration(), context.mResources.updateConfiguration(context.mResourcesManager.getConfiguration(), context.mResourcesManager.getDisplayMetrics()); context.mResourcesManager.getDisplayMetrics()); return context; return context; Loading @@ -2045,35 +2012,21 @@ class ContextImpl extends Context { static ContextImpl createAppContext(ActivityThread mainThread, LoadedApk packageInfo) { static ContextImpl createAppContext(ActivityThread mainThread, LoadedApk packageInfo) { if (packageInfo == null) throw new IllegalArgumentException("packageInfo"); if (packageInfo == null) throw new IllegalArgumentException("packageInfo"); ContextImpl context = new ContextImpl(null, mainThread, packageInfo, null, null, 0); return new ContextImpl(null, mainThread, context.mResources = packageInfo.getResources(mainThread); packageInfo, null, null, 0, null, null, Display.INVALID_DISPLAY); return context; } } static ContextImpl createActivityContext(ActivityThread mainThread, static ContextImpl createActivityContext(ActivityThread mainThread, LoadedApk packageInfo, IBinder activityToken, int displayId, LoadedApk packageInfo, IBinder activityToken, int displayId, Configuration overrideConfiguration) { Configuration overrideConfiguration) { if (packageInfo == null) throw new IllegalArgumentException("packageInfo"); if (packageInfo == null) throw new IllegalArgumentException("packageInfo"); return new ContextImpl(null, mainThread, packageInfo, activityToken, null, 0, ContextImpl context = new ContextImpl(null, mainThread, packageInfo, activityToken, null, null, overrideConfiguration, displayId); 0); // Clamp display ID to DEFAULT_DISPLAY if it is INVALID_DISPLAY. displayId = (displayId != Display.INVALID_DISPLAY) ? displayId : Display.DEFAULT_DISPLAY; final CompatibilityInfo compatInfo = (displayId == Display.DEFAULT_DISPLAY) ? packageInfo.getCompatibilityInfo() : CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO; context.mResources = createResources(activityToken, packageInfo, displayId, overrideConfiguration, compatInfo); context.mDisplay = ResourcesManager.getInstance().getAdjustedDisplay(displayId, context.mResources.getDisplayAdjustments()); return context; } } private ContextImpl(ContextImpl container, ActivityThread mainThread, private ContextImpl(ContextImpl container, ActivityThread mainThread, LoadedApk packageInfo, IBinder activityToken, UserHandle user, int flags) { LoadedApk packageInfo, IBinder activityToken, UserHandle user, int flags, Display display, Configuration overrideConfiguration, int createDisplayWithId) { mOuterContext = this; mOuterContext = this; // If creator didn't specify which storage to use, use the default // If creator didn't specify which storage to use, use the default Loading @@ -2100,11 +2053,64 @@ class ContextImpl extends Context { mPackageInfo = packageInfo; mPackageInfo = packageInfo; mResourcesManager = ResourcesManager.getInstance(); mResourcesManager = ResourcesManager.getInstance(); final int displayId = (createDisplayWithId != Display.INVALID_DISPLAY) ? createDisplayWithId : (display != null) ? display.getDisplayId() : Display.DEFAULT_DISPLAY; CompatibilityInfo compatInfo = null; if (container != null) { compatInfo = container.getDisplayAdjustments(displayId).getCompatibilityInfo(); } if (compatInfo == null) { compatInfo = (displayId == Display.DEFAULT_DISPLAY) ? packageInfo.getCompatibilityInfo() : CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO; } Resources resources = packageInfo.getResources(mainThread); if (resources != null) { if (displayId != Display.DEFAULT_DISPLAY || overrideConfiguration != null || (compatInfo != null && compatInfo.applicationScale != resources.getCompatibilityInfo().applicationScale)) { if (container != null) { // This is a nested Context, so it can't be a base Activity context. // Just create a regular Resources object associated with the Activity. resources = mResourcesManager.getResources( activityToken, packageInfo.getResDir(), packageInfo.getSplitResDirs(), packageInfo.getOverlayDirs(), packageInfo.getApplicationInfo().sharedLibraryFiles, displayId, overrideConfiguration, compatInfo, packageInfo.getClassLoader()); } else { // This is not a nested Context, so it must be the root Activity context. // All other nested Contexts will inherit the configuration set here. resources = mResourcesManager.createBaseActivityResources( activityToken, packageInfo.getResDir(), packageInfo.getSplitResDirs(), packageInfo.getOverlayDirs(), packageInfo.getApplicationInfo().sharedLibraryFiles, displayId, overrideConfiguration, compatInfo, packageInfo.getClassLoader()); } } } mResources = resources; mDisplay = (createDisplayWithId == Display.INVALID_DISPLAY) ? display : mResourcesManager.getAdjustedDisplay(displayId, mResources.getDisplayAdjustments()); if (container != null) { if (container != null) { mBasePackageName = container.mBasePackageName; mBasePackageName = container.mBasePackageName; mOpPackageName = container.mOpPackageName; mOpPackageName = container.mOpPackageName; mResources = container.getResources(); mDisplay = container.getDisplay(); } else { } else { mBasePackageName = packageInfo.mPackageName; mBasePackageName = packageInfo.mPackageName; ApplicationInfo ainfo = packageInfo.getApplicationInfo(); ApplicationInfo ainfo = packageInfo.getApplicationInfo(); Loading
core/java/android/app/ContextImplFlagContextWrapper.javadeleted 100644 → 0 +0 −43 Original line number Original line Diff line number Diff line /* * Copyright (C) 2016 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.app; import android.content.Context; import android.content.ContextWrapper; class ContextImplFlagContextWrapper extends ContextWrapper { private final int mFlags; public ContextImplFlagContextWrapper(Context base, int flags) { super(base); mFlags = flags; } @Override public boolean isRestricted() { return (mFlags & Context.CONTEXT_RESTRICTED) != 0; } @Override public boolean isDeviceProtectedStorage() { return (mFlags & Context.CONTEXT_DEVICE_PROTECTED_STORAGE) != 0; } @Override public boolean isCredentialProtectedStorage() { return (mFlags & Context.CONTEXT_CREDENTIAL_PROTECTED_STORAGE) != 0; } }