Merge "Add an API to create customized context for Sdk in Sandbox"
This commit is contained in:
@@ -82,6 +82,7 @@ package android.content {
|
||||
}
|
||||
|
||||
public abstract class Context {
|
||||
method @NonNull public android.content.Context createContextForSdkInSandbox(@NonNull android.content.pm.ApplicationInfo, int) throws android.content.pm.PackageManager.NameNotFoundException;
|
||||
method @NonNull public android.os.IBinder getIApplicationThreadBinder();
|
||||
method @NonNull public android.os.UserHandle getUser();
|
||||
field public static final String PAC_PROXY_SERVICE = "pac_proxy";
|
||||
|
||||
@@ -2640,7 +2640,7 @@ public final class ActivityThread extends ClientTransactionHandler
|
||||
ClassLoader baseLoader, boolean securityViolation, boolean includeCode,
|
||||
boolean registerPackage) {
|
||||
return getPackageInfo(aInfo, compatInfo, baseLoader, securityViolation, includeCode,
|
||||
registerPackage, /*isSdkSandbox=*/false);
|
||||
registerPackage, Process.isSdkSandbox());
|
||||
}
|
||||
|
||||
private LoadedApk getPackageInfo(ApplicationInfo aInfo, CompatibilityInfo compatInfo,
|
||||
|
||||
@@ -2581,6 +2581,22 @@ class ContextImpl extends Context {
|
||||
"Application package " + application.packageName + " not found");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context createContextForSdkInSandbox(ApplicationInfo sdkInfo, int flags)
|
||||
throws NameNotFoundException {
|
||||
if (!Process.isSdkSandbox()) {
|
||||
throw new SecurityException("API can only be called from SdkSandbox process");
|
||||
}
|
||||
|
||||
ContextImpl ctx = (ContextImpl) createApplicationContext(sdkInfo, flags);
|
||||
|
||||
// Set sandbox app's context as the application context for sdk context
|
||||
ctx.mPackageInfo.makeApplicationInner(/*forceDefaultAppClass=*/false,
|
||||
/*instrumentation=*/null);
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context createPackageContext(String packageName, int flags)
|
||||
throws NameNotFoundException {
|
||||
|
||||
@@ -6858,6 +6858,26 @@ public abstract class Context {
|
||||
public abstract Context createApplicationContext(ApplicationInfo application,
|
||||
@CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
|
||||
|
||||
/**
|
||||
* Creates a context given an {@link android.content.pm.ApplicationInfo}.
|
||||
*
|
||||
* Context created is for an sdk library that is being loaded in sdk sandbox.
|
||||
*
|
||||
* @param sdkInfo information regarding the sdk library being loaded.
|
||||
*
|
||||
* @throws PackageManager.NameNotFoundException if there is no application with
|
||||
* the given package name.
|
||||
* @throws SecurityException if caller is not a SdkSandbox process.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
|
||||
@NonNull
|
||||
public Context createContextForSdkInSandbox(@NonNull ApplicationInfo sdkInfo,
|
||||
@CreatePackageOptions int flags) throws PackageManager.NameNotFoundException {
|
||||
throw new RuntimeException("Not implemented. Must override in a subclass.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a new Context object for the given split name. The new Context has a ClassLoader and
|
||||
* Resources object that can access the split's and all of its dependencies' code/resources.
|
||||
|
||||
@@ -1071,6 +1071,15 @@ public class ContextWrapper extends Context {
|
||||
return mBase.createApplicationContext(application, flags);
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
@Override
|
||||
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
|
||||
@NonNull
|
||||
public Context createContextForSdkInSandbox(@NonNull ApplicationInfo sdkInfo, int flags)
|
||||
throws PackageManager.NameNotFoundException {
|
||||
return mBase.createContextForSdkInSandbox(sdkInfo, flags);
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
@Override
|
||||
public Context createContextForSplit(String splitName)
|
||||
|
||||
Reference in New Issue
Block a user