diff options
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/app/ContextImpl.java | 9 | ||||
| -rw-r--r-- | core/java/android/content/Context.java | 20 | ||||
| -rw-r--r-- | core/java/android/content/ContextWrapper.java | 6 |
3 files changed, 34 insertions, 1 deletions
diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java index 9902f6aa0fe3..c2e413c9f39a 100644 --- a/core/java/android/app/ContextImpl.java +++ b/core/java/android/app/ContextImpl.java @@ -2224,6 +2224,15 @@ class ContextImpl extends Context { } @Override + public Context createContextAsUser(UserHandle user) { + try { + return createPackageContextAsUser(getPackageName(), mFlags, user); + } catch (NameNotFoundException e) { + throw new IllegalStateException("Own package not found: package=" + getPackageName()); + } + } + + @Override public Context createContextForSplit(String splitName) throws NameNotFoundException { if (!mPackageInfo.getApplicationInfo().requestsIsolatedSplitLoading()) { // All Splits are always loaded. diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java index aca8f5d8a4e2..bd678bb00de5 100644 --- a/core/java/android/content/Context.java +++ b/core/java/android/content/Context.java @@ -5264,8 +5264,9 @@ public abstract class Context { */ @SystemApi @TestApi + @NonNull public Context createPackageContextAsUser( - String packageName, @CreatePackageOptions int flags, UserHandle user) + @NonNull String packageName, @CreatePackageOptions int flags, @NonNull UserHandle user) throws PackageManager.NameNotFoundException { if (Build.IS_ENG) { throw new IllegalStateException("createPackageContextAsUser not overridden!"); @@ -5274,6 +5275,23 @@ public abstract class Context { } /** + * Similar to {@link #createPackageContext(String, int)}, but for the own package with a + * different {@link UserHandle}. For example, {@link #getContentResolver()} + * will open any {@link Uri} as the given user. + * + * @hide + */ + @SystemApi + @TestApi + @NonNull + public Context createContextAsUser(@NonNull UserHandle user) { + if (Build.IS_ENG) { + throw new IllegalStateException("createContextAsUser not overridden!"); + } + return this; + } + + /** * Creates a context given an {@link android.content.pm.ApplicationInfo}. * * @hide diff --git a/core/java/android/content/ContextWrapper.java b/core/java/android/content/ContextWrapper.java index 2b1b8eb183ab..f7a0eb84c925 100644 --- a/core/java/android/content/ContextWrapper.java +++ b/core/java/android/content/ContextWrapper.java @@ -898,6 +898,12 @@ public class ContextWrapper extends Context { /** @hide */ @Override + public Context createContextAsUser(UserHandle user) { + return mBase.createContextAsUser(user); + } + + /** @hide */ + @Override @UnsupportedAppUsage public Context createApplicationContext(ApplicationInfo application, int flags) throws PackageManager.NameNotFoundException { |
