use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class ApkMatcherTest method assetModuleMatch.
@Test
public void assetModuleMatch() {
String installTimeModule1 = "installtime_assetmodule1";
String installTimeModule2 = "installtime_assetmodule2";
String onDemandModule = "ondemand_assetmodule";
ZipPath installTimeMasterApk1 = ZipPath.create(installTimeModule1 + "-master.apk");
ZipPath installTimeEnApk1 = ZipPath.create(installTimeModule1 + "-en.apk");
ZipPath installTimeMasterApk2 = ZipPath.create(installTimeModule2 + "-master.apk");
ZipPath installTimeEnApk2 = ZipPath.create(installTimeModule2 + "-en.apk");
ZipPath onDemandMasterApk = ZipPath.create(onDemandModule + "-master.apk");
ZipPath baseApk = ZipPath.create("base-master.apk");
BuildApksResult buildApksResult = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(oneApkSplitApkVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(sdkVersionFrom(1))), ApkTargeting.getDefaultInstance(), baseApk)).addAssetSliceSet(AssetSliceSet.newBuilder().setAssetModuleMetadata(AssetModuleMetadata.newBuilder().setName(installTimeModule1).setDeliveryType(INSTALL_TIME)).addApkDescription(splitApkDescription(ApkTargeting.getDefaultInstance(), installTimeMasterApk1)).addApkDescription(splitApkDescription(apkLanguageTargeting("en"), installTimeEnApk1))).addAssetSliceSet(AssetSliceSet.newBuilder().setAssetModuleMetadata(AssetModuleMetadata.newBuilder().setName(installTimeModule2).setDeliveryType(INSTALL_TIME)).addApkDescription(splitApkDescription(ApkTargeting.getDefaultInstance(), installTimeMasterApk2)).addApkDescription(splitApkDescription(apkLanguageTargeting("en"), installTimeEnApk2))).addAssetSliceSet(AssetSliceSet.newBuilder().setAssetModuleMetadata(AssetModuleMetadata.newBuilder().setName(onDemandModule).setDeliveryType(DeliveryType.ON_DEMAND)).addApkDescription(splitApkDescription(ApkTargeting.getDefaultInstance(), onDemandMasterApk))).build();
DeviceSpec enDevice = lDeviceWithLocales("en");
assertThat(new ApkMatcher(enDevice).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(baseApk), matchedApk(installTimeMasterApk1, installTimeModule1, INSTALL_TIME), matchedApk(installTimeEnApk1, installTimeModule1, INSTALL_TIME), matchedApk(installTimeMasterApk2, installTimeModule2, INSTALL_TIME), matchedApk(installTimeEnApk2, installTimeModule2, INSTALL_TIME));
DeviceSpec esDevice = lDeviceWithLocales("fr");
assertThat(new ApkMatcher(esDevice).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(baseApk), matchedApk(installTimeMasterApk1, installTimeModule1, INSTALL_TIME), matchedApk(installTimeMasterApk2, installTimeModule2, INSTALL_TIME));
assertThat(createMatcher(enDevice, Optional.of(ImmutableSet.of(installTimeModule1, onDemandModule))).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(baseApk), matchedApk(installTimeMasterApk1, installTimeModule1, INSTALL_TIME), matchedApk(installTimeEnApk1, installTimeModule1, INSTALL_TIME), matchedApk(onDemandMasterApk, onDemandModule, ON_DEMAND));
}
use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class ApkMatcherTest method apkMatch_withModuleNameFiltering_instantApks_checksModuleName_exists.
@Test
public void apkMatch_withModuleNameFiltering_instantApks_checksModuleName_exists() {
DeviceSpec device = deviceWithSdk(21);
ZipPath apk = ZipPath.create("master-de-fr.apk");
BuildApksResult buildApksResult = buildApksResult(createVariant(VariantTargeting.getDefaultInstance(), splitApkSet(/* moduleName= */
"base", instantApkDescription(ApkTargeting.getDefaultInstance(), apk))));
Optional<ImmutableSet<String>> allModules = Optional.empty();
assertThat(createInstantMatcher(device, allModules).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(apk));
Optional<ImmutableSet<String>> baseModuleOnly = Optional.of(ImmutableSet.of("base"));
assertThat(createInstantMatcher(device, baseModuleOnly).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(apk));
Optional<ImmutableSet<String>> unknownModuleOnly = Optional.of(ImmutableSet.of("unknown_module"));
InvalidCommandException exception = assertThrows(InvalidCommandException.class, () -> createInstantMatcher(device, unknownModuleOnly).getMatchingApks(buildApksResult));
assertThat(exception).hasMessageThat().contains("The APK Set archive does not contain the following modules: [unknown_module]");
}
use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class ApkMatcherTest method splitApk_conditionalModule_deviceEligible.
@Test
public void splitApk_conditionalModule_deviceEligible() {
DeviceSpec device = mergeSpecs(deviceWithSdk(24), deviceFeatures("android.hardware.camera.ar", "reqGlEsVersion=0x30002"), deviceGroups("highRam"));
ZipPath baseApk = ZipPath.create("base-master.apk");
ZipPath feature1Apk = ZipPath.create("ar-master.apk");
ZipPath feature2Apk = ZipPath.create("opengl-master.apk");
ZipPath feature3Apk = ZipPath.create("high_end-master.apk");
BuildApksResult buildApksResult = buildApksResult(createVariant(variantSdkTargeting(21), splitApkSet(/* moduleName= */
"base", splitApkDescription(ApkTargeting.getDefaultInstance(), baseApk)), createConditionalApkSet(/* moduleName= */
"ar", mergeModuleTargeting(moduleFeatureTargeting("android.hardware.camera.ar"), moduleMinSdkVersionTargeting(24)), splitApkDescription(ApkTargeting.getDefaultInstance(), feature1Apk)), createConditionalApkSet(/* moduleName= */
"opengl", mergeModuleTargeting(moduleFeatureTargeting("android.hardware.opengles.version", 0x30001), moduleMinSdkVersionTargeting(21)), splitApkDescription(ApkTargeting.getDefaultInstance(), feature2Apk)), createConditionalApkSet(/* moduleName= */
"high_end", mergeModuleTargeting(moduleDeviceGroupsTargeting("highRam"), moduleMinSdkVersionTargeting(21)), splitApkDescription(ApkTargeting.getDefaultInstance(), feature3Apk))));
assertThat(new ApkMatcher(device).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(baseApk), matchedApk(feature1Apk, /* moduleName= */
"ar", INSTALL_TIME), matchedApk(feature2Apk, /* moduleName= */
"opengl", INSTALL_TIME), matchedApk(feature3Apk, /* moduleName= */
"high_end", INSTALL_TIME));
}
use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class ApkMatcherTest method apkMatch_withModuleTypeFiltering_splitApks_installTimeModules_deprecatedOnDemand.
@Test
public void apkMatch_withModuleTypeFiltering_splitApks_installTimeModules_deprecatedOnDemand() {
DeviceSpec device = deviceWithSdk(21);
ZipPath baseApk = ZipPath.create("master-base.apk");
ZipPath onDemandFeatureApk = ZipPath.create("master-feature1.apk");
ApkSet onDemandFeature = splitApkSet(/* moduleName= */
"onDemandFeature", DeliveryType.ON_DEMAND, /* moduleDependencies= */
ImmutableList.of(), splitApkDescription(ApkTargeting.getDefaultInstance(), onDemandFeatureApk));
ApkSet onDemandFeatureWithDeprecatedField = onDemandFeature.toBuilder().setModuleMetadata(onDemandFeature.getModuleMetadata().toBuilder().setOnDemandDeprecated(true)).build();
BuildApksResult buildApksResult = buildApksResult(/* bundletoolVersion= */
"0.10.0", createVariant(VariantTargeting.getDefaultInstance(), splitApkSet(/* moduleName= */
"base", splitApkDescription(ApkTargeting.getDefaultInstance(), baseApk)), onDemandFeatureWithDeprecatedField));
// By default only install-time module are matched.
Optional<ImmutableSet<String>> allModules = Optional.empty();
assertThat(createMatcher(device, allModules).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(baseApk));
}
use of com.android.bundle.Devices.DeviceSpec 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");
}
Aggregations