Merge "Modify instr and app context for sdk-in-sandbox instrumented tests"

This commit is contained in:
Sandro Montanari
2023-03-30 07:33:09 +00:00
committed by Android (Google) Code Review
5 changed files with 46 additions and 17 deletions

View File

@@ -888,6 +888,7 @@ public final class ActivityThread extends ClientTransactionHandler
ApplicationInfo appInfo;
String sdkSandboxClientAppVolumeUuid;
String sdkSandboxClientAppPackage;
boolean isSdkInSandbox;
@UnsupportedAppUsage
List<ProviderInfo> providers;
ComponentName instrumentationName;
@@ -1169,19 +1170,34 @@ public final class ActivityThread extends ClientTransactionHandler
}
@Override
public final void bindApplication(String processName, ApplicationInfo appInfo,
String sdkSandboxClientAppVolumeUuid, String sdkSandboxClientAppPackage,
ProviderInfoList providerList, ComponentName instrumentationName,
ProfilerInfo profilerInfo, Bundle instrumentationArgs,
public final void bindApplication(
String processName,
ApplicationInfo appInfo,
String sdkSandboxClientAppVolumeUuid,
String sdkSandboxClientAppPackage,
boolean isSdkInSandbox,
ProviderInfoList providerList,
ComponentName instrumentationName,
ProfilerInfo profilerInfo,
Bundle instrumentationArgs,
IInstrumentationWatcher instrumentationWatcher,
IUiAutomationConnection instrumentationUiConnection, int debugMode,
boolean enableBinderTracking, boolean trackAllocation,
boolean isRestrictedBackupMode, boolean persistent, Configuration config,
CompatibilityInfo compatInfo, Map services, Bundle coreSettings,
String buildSerial, AutofillOptions autofillOptions,
ContentCaptureOptions contentCaptureOptions, long[] disabledCompatChanges,
IUiAutomationConnection instrumentationUiConnection,
int debugMode,
boolean enableBinderTracking,
boolean trackAllocation,
boolean isRestrictedBackupMode,
boolean persistent,
Configuration config,
CompatibilityInfo compatInfo,
Map services,
Bundle coreSettings,
String buildSerial,
AutofillOptions autofillOptions,
ContentCaptureOptions contentCaptureOptions,
long[] disabledCompatChanges,
SharedMemory serializedSystemFontMap,
long startRequestedElapsedTime, long startRequestedUptime) {
long startRequestedElapsedTime,
long startRequestedUptime) {
if (services != null) {
if (false) {
// Test code to make sure the app could see the passed-in services.
@@ -1215,6 +1231,7 @@ public final class ActivityThread extends ClientTransactionHandler
data.appInfo = appInfo;
data.sdkSandboxClientAppVolumeUuid = sdkSandboxClientAppVolumeUuid;
data.sdkSandboxClientAppPackage = sdkSandboxClientAppPackage;
data.isSdkInSandbox = isSdkInSandbox;
data.providers = providerList.getList();
data.instrumentationName = instrumentationName;
data.instrumentationArgs = instrumentationArgs;
@@ -7213,8 +7230,14 @@ public final class ActivityThread extends ClientTransactionHandler
// The test context's op package name == the target app's op package name, because
// the app ops manager checks the op package name against the real calling UID,
// which is what the target package name is associated with.
final ContextImpl instrContext = ContextImpl.createAppContext(this, pi,
appContext.getOpPackageName());
// In the case of instrumenting an sdk running in the sdk sandbox, appContext refers
// to the context of the sdk running in the sandbox. Since the sandbox does not have
// access to data outside the sandbox, we require the instrContext to point to the
// sdk in the sandbox as well, and not to the test context.
final ContextImpl instrContext =
(data.isSdkInSandbox)
? appContext
: ContextImpl.createAppContext(this, pi, appContext.getOpPackageName());
try {
final ClassLoader cl = instrContext.getClassLoader();

View File

@@ -78,6 +78,7 @@ oneway interface IApplicationThread {
void scheduleStopService(IBinder token);
void bindApplication(in String packageName, in ApplicationInfo info,
in String sdkSandboxClientAppVolumeUuid, in String sdkSandboxClientAppPackage,
in boolean isSdkInSandbox,
in ProviderInfoList providerList, in ComponentName testName,
in ProfilerInfo profilerInfo, in Bundle testArguments,
IInstrumentationWatcher testWatcher, IUiAutomationConnection uiAutomationConnection,

View File

@@ -40,6 +40,9 @@ class ActiveInstrumentation {
// The application being instrumented
ApplicationInfo mTargetInfo;
// Whether the application is instrumented as an sdk running in the sdk_sandbox.
boolean mIsSdkInSandbox;
// Where to save profiling
String mProfileFile;

View File

@@ -4655,6 +4655,7 @@ public class ActivityManagerService extends IActivityManager.Stub
} else if (instr2 != null) {
thread.bindApplication(processName, appInfo,
app.sdkSandboxClientAppVolumeUuid, app.sdkSandboxClientAppPackage,
instr2.mIsSdkInSandbox,
providerList,
instr2.mClass,
profilerInfo, instr2.mArguments,
@@ -4671,6 +4672,7 @@ public class ActivityManagerService extends IActivityManager.Stub
} else {
thread.bindApplication(processName, appInfo,
app.sdkSandboxClientAppVolumeUuid, app.sdkSandboxClientAppPackage,
/* isSdkInSandbox= */ false,
providerList, null, profilerInfo, null, null, null, testMode,
mBinderTransactionTrackingEnabled, enableTrackAllocation,
isRestrictedBackupMode || !normalMode, app.isPersistent(),
@@ -15436,6 +15438,7 @@ public class ActivityManagerService extends IActivityManager.Stub
activeInstr.mClass = className;
activeInstr.mTargetProcesses = new String[]{sdkSandboxInfo.processName};
activeInstr.mTargetInfo = sdkSandboxInfo;
activeInstr.mIsSdkInSandbox = isSdkInSandbox;
activeInstr.mProfileFile = profileFile;
activeInstr.mArguments = arguments;
activeInstr.mWatcher = watcher;
@@ -15452,7 +15455,6 @@ public class ActivityManagerService extends IActivityManager.Stub
sandboxManagerLocal.notifyInstrumentationStarted(
sdkSandboxClientAppInfo.packageName, sdkSandboxClientAppInfo.uid);
synchronized (mProcLock) {
int sdkSandboxUid = Process.toSdkSandboxUid(sdkSandboxClientAppInfo.uid);
// Kill the package sdk sandbox process belong to. At this point sdk sandbox is
// already killed.
forceStopPackageLocked(
@@ -15471,7 +15473,7 @@ public class ActivityManagerService extends IActivityManager.Stub
sdkSandboxInfo.processName,
/* isolated= */ false,
/* isSdkSandbox= */ true,
sdkSandboxUid,
sdkSandboxInfo.uid,
sdkSandboxClientAppInfo.packageName,
disableHiddenApiChecks,
disableTestApiChecks,

View File

@@ -200,7 +200,7 @@ public class AsyncProcessStartTest {
return null;
}).when(thread).bindApplication(
any(), any(),
any(), any(),
any(), any(), anyBoolean(),
any(), any(),
any(), any(),
any(),
@@ -260,7 +260,7 @@ public class AsyncProcessStartTest {
/* expectedStartSeq */ 0, /* procAttached */ false);
app.getThread().bindApplication(PACKAGE, appInfo,
null, null,
null, null, false,
null,
null,
null, null,