Merge "Add Context.createContextAsUser()" am: 63d5e4a0b9

am: 056b8f00b7

Change-Id: I703b0234c75f91ad548a0c431277d684212e0586
This commit is contained in:
Makoto Onuki
2019-11-20 14:11:19 -08:00
committed by android-build-merger
6 changed files with 44 additions and 3 deletions

View File

@@ -2223,6 +2223,15 @@ class ContextImpl extends Context {
"Application package " + packageName + " not found");
}
@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()) {

View File

@@ -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!");
@@ -5273,6 +5274,23 @@ public abstract class Context {
return this;
}
/**
* 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}.
*

View File

@@ -896,6 +896,12 @@ public class ContextWrapper extends Context {
return mBase.createPackageContextAsUser(packageName, flags, user);
}
/** @hide */
@Override
public Context createContextAsUser(UserHandle user) {
return mBase.createContextAsUser(user);
}
/** @hide */
@Override
@UnsupportedAppUsage