Loading ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuntimeEnvironmentController.java +16 −19 Original line number Diff line number Diff line Loading @@ -16,12 +16,11 @@ package android.platform.test.ravenwood; import static com.android.ravenwood.common.RavenwoodCommonUtils.RAVENWOOD_INST_RESOURCE_APK; import static com.android.ravenwood.common.RavenwoodCommonUtils.RAVENWOOD_RESOURCE_APK; import static com.android.ravenwood.common.RavenwoodCommonUtils.RAVENWOOD_VERBOSE_LOGGING; import static com.android.ravenwood.common.RavenwoodCommonUtils.RAVENWOOD_VERSION_JAVA_SYSPROP; import static org.junit.Assert.fail; import android.app.ActivityManager; import android.app.Instrumentation; import android.app.ResourcesManager; Loading Loading @@ -211,23 +210,21 @@ public class RavenwoodRuntimeEnvironmentController { var file = new File(RAVENWOOD_RESOURCE_APK); return config.mState.loadResources(file.exists() ? file : null); }; // Set up test context's resources. // Set up test context's (== instrumentation context's) resources. // If the target package name == test package name, then we use the main resources. // Otherwise, we don't simulate loading resources from the test APK yet. // (we need to add `test_resource_apk` to `android_ravenwood_test`) final Supplier<Resources> testResourcesLoader; final Supplier<Resources> instResourcesLoader; if (isSelfInstrumenting) { testResourcesLoader = targetResourcesLoader; instResourcesLoader = targetResourcesLoader; } else { testResourcesLoader = () -> { fail("Cannot load resources from the test context (yet)." + " Use target context's resources instead."); return null; // unreachable. instResourcesLoader = () -> { var file = new File(RAVENWOOD_INST_RESOURCE_APK); return config.mState.loadResources(file.exists() ? file : null); }; } var testContext = new RavenwoodContext( config.mTestPackageName, main, testResourcesLoader); var instContext = new RavenwoodContext( config.mTestPackageName, main, instResourcesLoader); var targetContext = new RavenwoodContext( config.mTargetPackageName, main, targetResourcesLoader); Loading @@ -236,18 +233,18 @@ public class RavenwoodRuntimeEnvironmentController { config.mTargetPackageName, main, targetResourcesLoader); appContext.setApplicationContext(appContext); if (isSelfInstrumenting) { testContext.setApplicationContext(appContext); instContext.setApplicationContext(appContext); targetContext.setApplicationContext(appContext); } else { // When instrumenting into another APK, the test context doesn't have an app context. targetContext.setApplicationContext(appContext); } config.mTestContext = testContext; config.mInstContext = instContext; config.mTargetContext = targetContext; // Prepare other fields. config.mInstrumentation = new Instrumentation(); config.mInstrumentation.basicInit(config.mTestContext, config.mTargetContext); config.mInstrumentation.basicInit(config.mInstContext, config.mTargetContext); InstrumentationRegistry.registerInstance(config.mInstrumentation, Bundle.EMPTY); RavenwoodSystemServer.init(config); Loading Loading @@ -284,13 +281,13 @@ public class RavenwoodRuntimeEnvironmentController { InstrumentationRegistry.registerInstance(null, Bundle.EMPTY); config.mInstrumentation = null; if (config.mTestContext != null) { ((RavenwoodContext) config.mTestContext).cleanUp(); if (config.mInstContext != null) { ((RavenwoodContext) config.mInstContext).cleanUp(); } if (config.mTargetContext != null) { ((RavenwoodContext) config.mTargetContext).cleanUp(); } config.mTestContext = null; config.mInstContext = null; config.mTargetContext = null; if (config.mProvideMainThread) { Loading ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodSystemServer.java +1 −1 Original line number Diff line number Diff line Loading @@ -67,7 +67,7 @@ public class RavenwoodSystemServer { sStartedServices = new ArraySet<>(); sTimings = new TimingsTraceAndSlog(); sServiceManager = new SystemServiceManager(config.mTestContext); sServiceManager = new SystemServiceManager(config.mInstContext); sServiceManager.setStartInfo(false, SystemClock.elapsedRealtime(), SystemClock.uptimeMillis()); Loading ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodConfig.java +1 −1 Original line number Diff line number Diff line Loading @@ -74,7 +74,7 @@ public final class RavenwoodConfig { final List<Class<?>> mServicesRequired = new ArrayList<>(); volatile Context mTestContext; volatile Context mInstContext; volatile Context mTargetContext; volatile Instrumentation mInstrumentation; Loading ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodRule.java +1 −1 Original line number Diff line number Diff line Loading @@ -216,7 +216,7 @@ public final class RavenwoodRule implements TestRule { */ @Deprecated public Context getContext() { return Objects.requireNonNull(mConfiguration.mTestContext, return Objects.requireNonNull(mConfiguration.mInstContext, "Context is only available during @Test execution"); } Loading ravenwood/runtime-common-src/com/android/ravenwood/common/RavenwoodCommonUtils.java +2 −0 Original line number Diff line number Diff line Loading @@ -63,6 +63,8 @@ public class RavenwoodCommonUtils { public static final String RAVENWOOD_SYSPROP = "ro.is_on_ravenwood"; public static final String RAVENWOOD_RESOURCE_APK = "ravenwood-res-apks/ravenwood-res.apk"; public static final String RAVENWOOD_INST_RESOURCE_APK = "ravenwood-res-apks/ravenwood-inst-res.apk"; public static final String RAVENWOOD_EMPTY_RESOURCES_APK = RAVENWOOD_RUNTIME_PATH + "ravenwood-data/ravenwood-empty-res.apk"; Loading Loading
ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuntimeEnvironmentController.java +16 −19 Original line number Diff line number Diff line Loading @@ -16,12 +16,11 @@ package android.platform.test.ravenwood; import static com.android.ravenwood.common.RavenwoodCommonUtils.RAVENWOOD_INST_RESOURCE_APK; import static com.android.ravenwood.common.RavenwoodCommonUtils.RAVENWOOD_RESOURCE_APK; import static com.android.ravenwood.common.RavenwoodCommonUtils.RAVENWOOD_VERBOSE_LOGGING; import static com.android.ravenwood.common.RavenwoodCommonUtils.RAVENWOOD_VERSION_JAVA_SYSPROP; import static org.junit.Assert.fail; import android.app.ActivityManager; import android.app.Instrumentation; import android.app.ResourcesManager; Loading Loading @@ -211,23 +210,21 @@ public class RavenwoodRuntimeEnvironmentController { var file = new File(RAVENWOOD_RESOURCE_APK); return config.mState.loadResources(file.exists() ? file : null); }; // Set up test context's resources. // Set up test context's (== instrumentation context's) resources. // If the target package name == test package name, then we use the main resources. // Otherwise, we don't simulate loading resources from the test APK yet. // (we need to add `test_resource_apk` to `android_ravenwood_test`) final Supplier<Resources> testResourcesLoader; final Supplier<Resources> instResourcesLoader; if (isSelfInstrumenting) { testResourcesLoader = targetResourcesLoader; instResourcesLoader = targetResourcesLoader; } else { testResourcesLoader = () -> { fail("Cannot load resources from the test context (yet)." + " Use target context's resources instead."); return null; // unreachable. instResourcesLoader = () -> { var file = new File(RAVENWOOD_INST_RESOURCE_APK); return config.mState.loadResources(file.exists() ? file : null); }; } var testContext = new RavenwoodContext( config.mTestPackageName, main, testResourcesLoader); var instContext = new RavenwoodContext( config.mTestPackageName, main, instResourcesLoader); var targetContext = new RavenwoodContext( config.mTargetPackageName, main, targetResourcesLoader); Loading @@ -236,18 +233,18 @@ public class RavenwoodRuntimeEnvironmentController { config.mTargetPackageName, main, targetResourcesLoader); appContext.setApplicationContext(appContext); if (isSelfInstrumenting) { testContext.setApplicationContext(appContext); instContext.setApplicationContext(appContext); targetContext.setApplicationContext(appContext); } else { // When instrumenting into another APK, the test context doesn't have an app context. targetContext.setApplicationContext(appContext); } config.mTestContext = testContext; config.mInstContext = instContext; config.mTargetContext = targetContext; // Prepare other fields. config.mInstrumentation = new Instrumentation(); config.mInstrumentation.basicInit(config.mTestContext, config.mTargetContext); config.mInstrumentation.basicInit(config.mInstContext, config.mTargetContext); InstrumentationRegistry.registerInstance(config.mInstrumentation, Bundle.EMPTY); RavenwoodSystemServer.init(config); Loading Loading @@ -284,13 +281,13 @@ public class RavenwoodRuntimeEnvironmentController { InstrumentationRegistry.registerInstance(null, Bundle.EMPTY); config.mInstrumentation = null; if (config.mTestContext != null) { ((RavenwoodContext) config.mTestContext).cleanUp(); if (config.mInstContext != null) { ((RavenwoodContext) config.mInstContext).cleanUp(); } if (config.mTargetContext != null) { ((RavenwoodContext) config.mTargetContext).cleanUp(); } config.mTestContext = null; config.mInstContext = null; config.mTargetContext = null; if (config.mProvideMainThread) { Loading
ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodSystemServer.java +1 −1 Original line number Diff line number Diff line Loading @@ -67,7 +67,7 @@ public class RavenwoodSystemServer { sStartedServices = new ArraySet<>(); sTimings = new TimingsTraceAndSlog(); sServiceManager = new SystemServiceManager(config.mTestContext); sServiceManager = new SystemServiceManager(config.mInstContext); sServiceManager.setStartInfo(false, SystemClock.elapsedRealtime(), SystemClock.uptimeMillis()); Loading
ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodConfig.java +1 −1 Original line number Diff line number Diff line Loading @@ -74,7 +74,7 @@ public final class RavenwoodConfig { final List<Class<?>> mServicesRequired = new ArrayList<>(); volatile Context mTestContext; volatile Context mInstContext; volatile Context mTargetContext; volatile Instrumentation mInstrumentation; Loading
ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodRule.java +1 −1 Original line number Diff line number Diff line Loading @@ -216,7 +216,7 @@ public final class RavenwoodRule implements TestRule { */ @Deprecated public Context getContext() { return Objects.requireNonNull(mConfiguration.mTestContext, return Objects.requireNonNull(mConfiguration.mInstContext, "Context is only available during @Test execution"); } Loading
ravenwood/runtime-common-src/com/android/ravenwood/common/RavenwoodCommonUtils.java +2 −0 Original line number Diff line number Diff line Loading @@ -63,6 +63,8 @@ public class RavenwoodCommonUtils { public static final String RAVENWOOD_SYSPROP = "ro.is_on_ravenwood"; public static final String RAVENWOOD_RESOURCE_APK = "ravenwood-res-apks/ravenwood-res.apk"; public static final String RAVENWOOD_INST_RESOURCE_APK = "ravenwood-res-apks/ravenwood-inst-res.apk"; public static final String RAVENWOOD_EMPTY_RESOURCES_APK = RAVENWOOD_RUNTIME_PATH + "ravenwood-data/ravenwood-empty-res.apk"; Loading