Search in sources :

Example 26 with FakeDevice

use of com.android.tools.build.bundletool.testing.FakeDevice in project bundletool by google.

the class InstallApksCommandTest method moduleDependencies_diamondGraph.

@Test
@Theory
public void moduleDependencies_diamondGraph(@FromDataPoints("apksInDirectory") boolean apksInDirectory) throws Exception {
    BuildApksResult tableOfContent = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(VariantTargeting.getDefaultInstance(), createSplitApkSet(/* moduleName= */
    "base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-master.apk"))), createSplitApkSet(/* moduleName= */
    "feature1", DeliveryType.ON_DEMAND, /* moduleDependencies= */
    ImmutableList.of(), createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("feature1-master.apk"))), createSplitApkSet(/* moduleName= */
    "feature2", DeliveryType.ON_DEMAND, /* moduleDependencies= */
    ImmutableList.of("feature1"), createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("feature2-master.apk"))), createSplitApkSet(/* moduleName= */
    "feature3", DeliveryType.ON_DEMAND, /* moduleDependencies= */
    ImmutableList.of("feature1"), createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("feature3-master.apk"))), createSplitApkSet(/* moduleName= */
    "feature4", DeliveryType.ON_DEMAND, /* moduleDependencies= */
    ImmutableList.of("feature2", "feature3"), createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("feature4-master.apk"))))).build();
    Path apksFile = createApks(tableOfContent, apksInDirectory);
    List<Path> installedApks = new ArrayList<>();
    FakeDevice fakeDevice = FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, lDeviceWithLocales("en-US"));
    AdbServer adbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, ImmutableList.of(fakeDevice));
    fakeDevice.setInstallApksSideEffect((apks, installOptions) -> installedApks.addAll(apks));
    InstallApksCommand.builder().setApksArchivePath(apksFile).setAdbPath(adbPath).setAdbServer(adbServer).setModules(ImmutableSet.of("feature4")).build().execute();
    assertThat(getFileNames(installedApks)).containsExactly("base-master.apk", "feature1-master.apk", "feature2-master.apk", "feature3-master.apk", "feature4-master.apk");
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ArrayList(java.util.ArrayList) FakeDevice(com.android.tools.build.bundletool.testing.FakeDevice) AdbServer(com.android.tools.build.bundletool.device.AdbServer) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Test(org.junit.Test) Theory(org.junit.experimental.theories.Theory)

Example 27 with FakeDevice

use of com.android.tools.build.bundletool.testing.FakeDevice in project bundletool by google.

the class InstallMultiApksCommandTest method execute_timeout_androidS_success.

@Test
public void execute_timeout_androidS_success() throws Exception {
    FakeDevice sDevice = FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, mergeSpecs(qDeviceWithLocales("en-US"), sdkVersion(ANDROID_S_API_VERSION)));
    // GIVEN a fake .apks file with an .apex file.
    BuildApksResult toc = fakeTableOfContents(PKG_NAME_1);
    Path apksPath = createApksArchiveFile(toc, tmpDir.resolve("package1.apks"));
    // GIVEN an install command with the --staged flag...
    InstallMultiApksCommand command = InstallMultiApksCommand.builder().setAdbServer(fakeServerOneDevice(sDevice)).setDeviceId(DEVICE_ID).setAdbPath(adbPath).setTimeout(Duration.ofSeconds(20)).setApksArchivePaths(ImmutableList.of(apksPath)).setAapt2Command(createFakeAapt2Command(ImmutableMap.of(PKG_NAME_1, 1L))).setAdbCommand(// EXPECT the --staged flag to be included.
    createFakeAdbCommand(expectedInstallApks(PKG_NAME_1, toc), /* expectedStaged= */
    false, /* expectedEnableRollback= */
    false, /* expectedTimeout= */
    Optional.of(Duration.ofSeconds(20)), Optional.of(DEVICE_ID))).build();
    givenEmptyListPackages(sDevice);
    command.execute();
    assertAdbCommandExecuted();
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) BuildApksResult(com.android.bundle.Commands.BuildApksResult) FakeDevice(com.android.tools.build.bundletool.testing.FakeDevice) Test(org.junit.Test)

Example 28 with FakeDevice

use of com.android.tools.build.bundletool.testing.FakeDevice in project bundletool by google.

the class ActivityManagerRunnerTest method pixelDevice_detectsFeatures.

@Test
public void pixelDevice_detectsFeatures() {
    FakeDevice device = FakeDevice.fromDeviceSpec(SERIAL_NUMBER, DeviceState.ONLINE, mergeSpecs(sdkVersion(27), locales("en-US"), density(560), abis("armv64-v8a")));
    device.injectShellCommandOutput("am get-config", () -> Joiner.on('\n').join(ImmutableList.of("abi: arm64-v8a,armeabi-v7a,armeabi", "config: mcc234-mnc15-en-rGB,in-rID,pl-rPL-ldltr-sw411dp-w411dp-h746dp-" + "normal-long-notround-lowdr-widecg-port-notnight-560dpi-finger-" + "keysexposed-nokeys-navhidden-nonav-v27")));
    ActivityManagerRunner runner = new ActivityManagerRunner(device);
    assertThat(runner.getDeviceLocales()).containsExactly("en-GB", "in-ID", "pl-PL").inOrder();
    assertThat(runner.getDeviceAbis()).containsExactly("arm64-v8a", "armeabi-v7a", "armeabi").inOrder();
}
Also used : FakeDevice(com.android.tools.build.bundletool.testing.FakeDevice) Test(org.junit.Test)

Example 29 with FakeDevice

use of com.android.tools.build.bundletool.testing.FakeDevice in project bundletool by google.

the class DeviceAnalyzerTest method activityManagerFails_noProperties_defaultLocaleFallback.

@Test
public void activityManagerFails_noProperties_defaultLocaleFallback() {
    // It creates no properties, hence locale fetch via properties should also fall back.
    FakeDevice fakeDevice = createDeviceWithNoProperties("a", /* sdkVersion= */
    26, /* locale= */
    "de-DE");
    fakeDevice.injectShellCommandOutput("am get-config", () -> "error");
    FakeAdbServer fakeAdbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, /* devices= */
    ImmutableList.of(fakeDevice));
    fakeAdbServer.init(Paths.get("path/to/adb"));
    DeviceSpec spec = new DeviceAnalyzer(fakeAdbServer).getDeviceSpec(Optional.empty());
    assertThat(spec.getScreenDensity()).isEqualTo(480);
    assertThat(spec.getSupportedAbisList()).containsExactly("armeabi");
    assertThat(spec.getSdkVersion()).isEqualTo(26);
    // We couldn't detect locale so we expect to fallback to en-US.
    assertThat(spec.getSupportedLocalesList()).containsExactly("en-US");
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) FakeDevice(com.android.tools.build.bundletool.testing.FakeDevice) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Test(org.junit.Test)

Example 30 with FakeDevice

use of com.android.tools.build.bundletool.testing.FakeDevice in project bundletool by google.

the class DeviceAnalyzerTest method prefersAbisLocalesViaActivityManager.

@Test
public void prefersAbisLocalesViaActivityManager() {
    FakeDevice fakeDevice = FakeDevice.fromDeviceSpec("id1", DeviceState.ONLINE, mergeSpecs(sdkVersion(27), locales("en-US"), density(560), abis("armv64-v8a")));
    fakeDevice.injectShellCommandOutput("am get-config", () -> Joiner.on('\n').join(ImmutableList.of("abi: arm64-v8a,armeabi-v7a,armeabi", "config: mcc234-mnc15-en-rGB,in-rID,pl-rPL-ldltr-sw411dp-w411dp-h746dp-" + "normal-long-notround-lowdr-widecg-port-notnight-560dpi-finger-" + "keysexposed-nokeys-navhidden-nonav-v27")));
    FakeAdbServer fakeAdbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, /* devices= */
    ImmutableList.of(fakeDevice));
    fakeAdbServer.init(Paths.get("path/to/adb"));
    DeviceAnalyzer analyzer = new DeviceAnalyzer(fakeAdbServer);
    DeviceSpec deviceSpec = analyzer.getDeviceSpec(Optional.empty());
    assertThat(deviceSpec.getSupportedAbisList()).containsExactly("arm64-v8a", "armeabi-v7a", "armeabi").inOrder();
    assertThat(deviceSpec.getSupportedLocalesList()).containsExactly("en-GB", "in-ID", "pl-PL").inOrder();
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) FakeDevice(com.android.tools.build.bundletool.testing.FakeDevice) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Test(org.junit.Test)

Aggregations

FakeDevice (com.android.tools.build.bundletool.testing.FakeDevice)32 Test (org.junit.Test)32 FakeAdbServer (com.android.tools.build.bundletool.testing.FakeAdbServer)24 AdbServer (com.android.tools.build.bundletool.device.AdbServer)17 Path (java.nio.file.Path)17 ZipPath (com.android.tools.build.bundletool.model.ZipPath)16 BuildApksResult (com.android.bundle.Commands.BuildApksResult)13 DeviceSpec (com.android.bundle.Devices.DeviceSpec)10 ArrayList (java.util.ArrayList)10 Theory (org.junit.experimental.theories.Theory)9 Duration (java.time.Duration)2 AdbCommandRejectedException (com.android.ddmlib.AdbCommandRejectedException)1 DeviceState (com.android.ddmlib.IDevice.DeviceState)1 ShellCommandUnresponsiveException (com.android.ddmlib.ShellCommandUnresponsiveException)1 TimeoutException (com.android.ddmlib.TimeoutException)1 InstallOptions (com.android.tools.build.bundletool.device.Device.InstallOptions)1 CommandExecutionException (com.android.tools.build.bundletool.model.exceptions.CommandExecutionException)1 DeviceFactory.lDeviceWithLocales (com.android.tools.build.bundletool.testing.DeviceFactory.lDeviceWithLocales)1 ImmutableList (com.google.common.collect.ImmutableList)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1