.setSdkVersion(deviceSdkVersion) .addAllSupportedAbis(supportedAbis) .addAllSupportedLocales(deviceLocales) .setScreenDensity(deviceDensity) .addAllDeviceFeatures(deviceFeatures) .build(); } catch (TimeoutException e) { throw CommandExecutionException.builder()
DeviceSpecFromTargetingBuilder setSupportedAbis(AbiTargeting abiTargeting) { if (!abiTargeting.equals(AbiTargeting.getDefaultInstance())) { deviceSpec.addSupportedAbis( AbiName.fromProto(Iterables.getOnlyElement(abiTargeting.getValueList()).getAlias()) .getPlatformName()); } return this; }
DeviceSpecFromTargetingBuilder setSupportedLocales(LanguageTargeting languageTargeting) { if (!languageTargeting.equals(LanguageTargeting.getDefaultInstance())) { deviceSpec.addSupportedLocales(Iterables.getOnlyElement(languageTargeting.getValueList())); } return this; }
.setDeviceSpec( DeviceSpec.newBuilder() .setSdkVersion(21) .setScreenDensity(125) .addSupportedLocales("jp") .build()) .setDimensions( ImmutableSet.of(
.setApksArchivePath(apksArchiveFile) .setDeviceSpec( DeviceSpec.newBuilder().setScreenDensity(124).addSupportedAbis("x86").build()) .setDimensions(ImmutableSet.of(Dimension.ABI, Dimension.SCREEN_DENSITY)) .build()
.setGetSizeSubCommand(GetSizeSubcommand.TOTAL) .setApksArchivePath(apksArchiveFile) .setDeviceSpec(DeviceSpec.newBuilder().setSdkVersion(21).build()) .build() .getSizeTotalInternal();
@Test @Theory public void checkFlagsConstructionWithDeviceSpec( @FromDataPoints("deviceSpecs") String deviceSpecPath) throws Exception { DeviceSpec.Builder expectedDeviceSpecBuilder = DeviceSpec.newBuilder(); try (Reader reader = TestData.openReader(deviceSpecPath)) { JsonFormat.parser().merge(reader, expectedDeviceSpecBuilder); } DeviceSpec expectedDeviceSpec = expectedDeviceSpecBuilder.build(); BuildApksResult tableOfContentsProto = BuildApksResult.getDefaultInstance(); Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks")); Path deviceSpecFile = copyToTempDir(deviceSpecPath); GetSizeCommand command = GetSizeCommand.fromFlags( new FlagParser() .parse( "get-size", "total", "--device-spec=" + deviceSpecFile, "--apks=" + apksArchiveFile)); assertThat(command.getDeviceSpec()).isEqualTo(expectedDeviceSpec); }
@Test public void oneDevice_noDeviceId_works() throws Exception { DeviceSpec deviceSpec = mergeSpecs(sdkVersion(21), abis("x86_64", "x86"), locales("en-GB"), density(360)); Path outputPath = tmp.getRoot().toPath().resolve("device.json"); // We set up a fake ADB server because the real one won't work on Forge. GetDeviceSpecCommand command = GetDeviceSpecCommand.builder() .setAdbPath(adbPath) .setAdbServer(fakeServerOneDevice(deviceSpec)) .setOutputPath(outputPath) .build(); assertThat(command.execute()).isEqualTo(deviceSpec); try (Reader deviceSpecReader = BufferedIo.reader(outputPath)) { DeviceSpec.Builder writtenSpecBuilder = DeviceSpec.newBuilder(); JsonFormat.parser().merge(deviceSpecReader, writtenSpecBuilder); assertThat(writtenSpecBuilder.build()).isEqualTo(deviceSpec); } }
public static DeviceSpec density(int screenDpi) { return DeviceSpec.newBuilder().setScreenDensity(screenDpi).build(); }
public static DeviceSpec sdkVersion(int sdkVersion) { return DeviceSpec.newBuilder().setSdkVersion(sdkVersion).build(); }
public static DeviceSpec abis(String... abis) { return DeviceSpec.newBuilder().addAllSupportedAbis(Arrays.asList(abis)).build(); }
DeviceSpec build() { return deviceSpec.build(); } }
public static DeviceSpec locales(String... locales) { return DeviceSpec.newBuilder().addAllSupportedLocales(Arrays.asList(locales)).build(); }
@Test public void deviceSpecFromPbJson() throws Exception { DeviceSpec.Builder expectedDeviceSpecBuilder = DeviceSpec.newBuilder(); try (Reader reader = TestData.openReader("testdata/device/pixel2_spec.json")) { JsonFormat.parser().merge(reader, expectedDeviceSpecBuilder); } DeviceSpec expectedDeviceSpec = expectedDeviceSpecBuilder.build(); BuildApksResult tableOfContentsProto = BuildApksResult.getDefaultInstance(); Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks")); Path deviceSpecFile = copyToTempDir("testdata/device/pixel2_spec.json"); ExtractApksCommand command = ExtractApksCommand.fromFlags( new FlagParser().parse("--device-spec=" + deviceSpecFile, "--apks=" + apksArchiveFile)); assertThat(command.getDeviceSpec()).isEqualTo(expectedDeviceSpec); }
private static DeviceSpec parseDeviceSpecInternal(Reader deviceSpecReader, boolean canSkipFields) throws IOException { DeviceSpec.Builder builder = DeviceSpec.newBuilder(); JsonFormat.parser().merge(deviceSpecReader, builder); DeviceSpec deviceSpec = builder.build(); validateDeviceSpec(deviceSpec, canSkipFields); return deviceSpec; }
public static DeviceSpec deviceFeatures(String... features) { return DeviceSpec.newBuilder().addAllDeviceFeatures(Arrays.asList(features)).build(); }
DeviceSpecFromTargetingBuilder setSdkVersion(SdkVersionTargeting sdkVersionTargeting) { if (!sdkVersionTargeting.equals(SdkVersionTargeting.getDefaultInstance())) { deviceSpec.setSdkVersion( Iterables.getOnlyElement(sdkVersionTargeting.getValueList()).getMin().getValue()); } return this; }