Search in sources :

Example 46 with FakeAdbServer

use of com.android.tools.build.bundletool.testing.FakeAdbServer 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 47 with FakeAdbServer

use of com.android.tools.build.bundletool.testing.FakeAdbServer 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 48 with FakeAdbServer

use of com.android.tools.build.bundletool.testing.FakeAdbServer 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)

Example 49 with FakeAdbServer

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

the class DeviceAnalyzerTest method noDeviceId_multipleConnectedDevices_throws.

@Test
public void noDeviceId_multipleConnectedDevices_throws() {
    FakeAdbServer fakeAdbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, /* devices= */
    ImmutableList.of(createUsbEnabledDevice("a"), createUsbEnabledDevice("b")));
    fakeAdbServer.init(Paths.get("path/to/adb"));
    DeviceAnalyzer analyzer = new DeviceAnalyzer(fakeAdbServer);
    Throwable exception = assertThrows(CommandExecutionException.class, () -> analyzer.getDeviceSpec(Optional.empty()));
    assertThat(exception).hasMessageThat().contains("More than one device connected, please provide --device-id.");
}
Also used : FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Test(org.junit.Test)

Example 50 with FakeAdbServer

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

the class DeviceAnalyzerTest method activityManagerFails_propertiesFallback.

@Test
public void activityManagerFails_propertiesFallback() {
    FakeDevice fakeDevice = FakeDevice.fromDeviceSpec("id1", DeviceState.ONLINE, mergeSpecs(sdkVersion(26), locales("de-DE"), density(480), abis("armeabi")));
    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);
    assertThat(spec.getSupportedLocalesList()).containsExactly("de-DE");
}
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

FakeAdbServer (com.android.tools.build.bundletool.testing.FakeAdbServer)57 Test (org.junit.Test)57 FakeDevice (com.android.tools.build.bundletool.testing.FakeDevice)30 Path (java.nio.file.Path)27 AdbServer (com.android.tools.build.bundletool.device.AdbServer)23 BuildApksResult (com.android.bundle.Commands.BuildApksResult)19 ZipPath (com.android.tools.build.bundletool.model.ZipPath)16 DeviceSpec (com.android.bundle.Devices.DeviceSpec)14 ArrayList (java.util.ArrayList)10 Theory (org.junit.experimental.theories.Theory)9 ApkSet (com.android.bundle.Commands.ApkSet)7 Variant (com.android.bundle.Commands.Variant)7 DeviceState (com.android.ddmlib.IDevice.DeviceState)7 CommandExecutionException (com.android.tools.build.bundletool.model.exceptions.CommandExecutionException)7 ImmutableList (com.google.common.collect.ImmutableList)7 Truth.assertThat (com.google.common.truth.Truth.assertThat)7 Files (java.nio.file.Files)7 ZipFile (java.util.zip.ZipFile)7 Before (org.junit.Before)7 Rule (org.junit.Rule)7