Search in sources :

Example 26 with DeviceSpec

use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.

the class ApkMatcherTest method apkMatch_withModuleTypeFiltering_splitApks_installTimeModules.

@Test
public void apkMatch_withModuleTypeFiltering_splitApks_installTimeModules() {
    DeviceSpec device = deviceWithSdk(21);
    ZipPath baseApk = ZipPath.create("master-base.apk");
    ZipPath onDemandFeatureApk = ZipPath.create("master-feature1.apk");
    ZipPath installTimeFeatureApk = ZipPath.create("master-feature2.apk");
    ZipPath fastFollowFeatureApk = ZipPath.create("master-feature3.apk");
    BuildApksResult buildApksResult = buildApksResult(createVariant(VariantTargeting.getDefaultInstance(), splitApkSet(/* moduleName= */
    "base", splitApkDescription(ApkTargeting.getDefaultInstance(), baseApk)), splitApkSet(/* moduleName= */
    "onDemandFeature", DeliveryType.ON_DEMAND, /* moduleDependencies= */
    ImmutableList.of(), splitApkDescription(ApkTargeting.getDefaultInstance(), onDemandFeatureApk)), splitApkSet(/* moduleName= */
    "installTimeFeature", INSTALL_TIME, /* moduleDependencies= */
    ImmutableList.of(), splitApkDescription(ApkTargeting.getDefaultInstance(), installTimeFeatureApk)), splitApkSet(/* moduleName= */
    "fastFollowFeature", /* deliveryType= */
    DeliveryType.FAST_FOLLOW, /* moduleDependencies= */
    ImmutableList.of(), splitApkDescription(ApkTargeting.getDefaultInstance(), fastFollowFeatureApk))));
    // By default only install-time module are matched.
    Optional<ImmutableSet<String>> allModules = Optional.empty();
    assertThat(createMatcher(device, allModules).getMatchingApks(buildApksResult)).containsExactly(matchedApk(baseApk, /* moduleName=*/
    "base", INSTALL_TIME), matchedApk(installTimeFeatureApk, /* moduleName=*/
    "installTimeFeature", INSTALL_TIME));
    Optional<ImmutableSet<String>> baseModuleOnly = Optional.of(ImmutableSet.of("base"));
    assertThat(createMatcher(device, baseModuleOnly).getMatchingApks(buildApksResult)).containsExactly(matchedApk(baseApk, /* moduleName=*/
    "base", INSTALL_TIME), matchedApk(installTimeFeatureApk, /* moduleName=*/
    "installTimeFeature", INSTALL_TIME));
    Optional<ImmutableSet<String>> installTimeModuleOnly = Optional.of(ImmutableSet.of("installTimeFeature"));
    assertThat(createMatcher(device, installTimeModuleOnly).getMatchingApks(buildApksResult)).containsExactly(matchedApk(baseApk, /* moduleName=*/
    "base", INSTALL_TIME), matchedApk(installTimeFeatureApk, /* moduleName=*/
    "installTimeFeature", INSTALL_TIME));
    Optional<ImmutableSet<String>> onDemandModuleOnly = Optional.of(ImmutableSet.of("onDemandFeature"));
    assertThat(createMatcher(device, onDemandModuleOnly).getMatchingApks(buildApksResult)).containsExactly(matchedApk(baseApk, /* moduleName=*/
    "base", INSTALL_TIME), matchedApk(onDemandFeatureApk, /* moduleName=*/
    "onDemandFeature", ON_DEMAND), matchedApk(installTimeFeatureApk, /* moduleName=*/
    "installTimeFeature", INSTALL_TIME));
    Optional<ImmutableSet<String>> fastFollowModuleOnly = Optional.of(ImmutableSet.of("fastFollowFeature"));
    assertThat(createMatcher(device, fastFollowModuleOnly).getMatchingApks(buildApksResult)).containsExactly(matchedApk(baseApk, /* moduleName=*/
    "base", INSTALL_TIME), matchedApk(fastFollowFeatureApk, /* moduleName=*/
    "fastFollowFeature", FAST_FOLLOW), matchedApk(installTimeFeatureApk, /* moduleName=*/
    "installTimeFeature", INSTALL_TIME));
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) ImmutableSet(com.google.common.collect.ImmutableSet) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Test(org.junit.Test)

Example 27 with DeviceSpec

use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.

the class DeviceAnalyzerTest method deviceId_multipleConnectedDevices_match.

@Test
public void deviceId_multipleConnectedDevices_match() {
    FakeAdbServer fakeAdbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, /* devices= */
    ImmutableList.of(createUsbEnabledDevice("a"), createUsbEnabledDevice("b", /* sdkVersion= */
    23, /* locale= */
    "pt-BR")));
    fakeAdbServer.init(Paths.get("path/to/adb"));
    DeviceSpec spec = new DeviceAnalyzer(fakeAdbServer).getDeviceSpec(Optional.of("b"));
    assertThat(spec.getScreenDensity()).isEqualTo(480);
    assertThat(spec.getSupportedAbisList()).containsExactly("armeabi");
    assertThat(spec.getSdkVersion()).isEqualTo(23);
    assertThat(spec.getSupportedLocalesList()).containsExactly("pt-BR");
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Test(org.junit.Test)

Example 28 with DeviceSpec

use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.

the class DeviceAnalyzerTest method extractsGlExtensions.

@Test
public void extractsGlExtensions() {
    FakeDevice fakeDevice = FakeDevice.fromDeviceSpec("id1", DeviceState.ONLINE, mergeSpecs(density(240), locales("en-US"), abis("x86"), sdkVersion(21), glExtensions("GL_EXT_extension1", "GL_EXT_extension2")));
    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.getGlExtensionsList()).containsExactly("GL_EXT_extension1", "GL_EXT_extension2");
}
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 29 with DeviceSpec

use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.

the class DeviceAnalyzerTest method noDeviceId_oneConnectedDevice_sdk21_fine.

@Test
public void noDeviceId_oneConnectedDevice_sdk21_fine() {
    FakeAdbServer fakeAdbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, /* devices= */
    ImmutableList.of(createUsbEnabledDevice("a", /* sdkVersion= */
    21, "fr-CA")));
    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(21);
    assertThat(spec.getSupportedLocalesList()).containsExactly("fr-CA");
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Test(org.junit.Test)

Example 30 with DeviceSpec

use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.

the class DeviceAnalyzerTest method noDeviceId_oneConnectedDevice_sdk19_fallBack.

@Test
public void noDeviceId_oneConnectedDevice_sdk19_fallBack() {
    FakeAdbServer fakeAdbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, /* devices= */
    ImmutableList.of(createDeviceWithNoProperties("a", /* sdkVersion= */
    19, /* locale= */
    "de-DE")));
    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(19);
    // 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) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Test(org.junit.Test)

Aggregations

DeviceSpec (com.android.bundle.Devices.DeviceSpec)124 Test (org.junit.Test)113 Path (java.nio.file.Path)71 BuildApksResult (com.android.bundle.Commands.BuildApksResult)68 ZipPath (com.android.tools.build.bundletool.model.ZipPath)64 FakeAdbServer (com.android.tools.build.bundletool.testing.FakeAdbServer)19 FlagParser (com.android.tools.build.bundletool.flags.FlagParser)18 AdbServer (com.android.tools.build.bundletool.device.AdbServer)15 ImmutableSet (com.google.common.collect.ImmutableSet)14 Theory (org.junit.experimental.theories.Theory)13 IncompatibleDeviceException (com.android.tools.build.bundletool.model.exceptions.IncompatibleDeviceException)12 Variant (com.android.bundle.Commands.Variant)11 InvalidCommandException (com.android.tools.build.bundletool.model.exceptions.InvalidCommandException)11 ZipFile (java.util.zip.ZipFile)11 ApkSet (com.android.bundle.Commands.ApkSet)10 ImmutableList (com.google.common.collect.ImmutableList)9 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)9 ImmutableMap (com.google.common.collect.ImmutableMap)8 SystemEnvironmentProvider (com.android.tools.build.bundletool.model.utils.SystemEnvironmentProvider)7 PrintStream (java.io.PrintStream)7