AvdWizardUtils { @VisibleForTesting static void convertWebpSkinToPng(@NotNull FileOp fop, @NotNull File dest, @NotNull File resourcePath) throws IOException { File[] files = fop.listFiles(resourcePath); Map<String,String> renameMap = Maps.newHashMap(); File skinFile = null; for (File src : files) { String name = src.getName(); if (name.equals(FN_SKIN_LAYOUT)) { skinFile = src; continue; } if (name.endsWith(DOT_WEBP)) { try (InputStream inputStream = new BufferedInputStream(fop.newFileInputStream(src))) { BufferedImage icon = ImageIO.read(inputStream); if (icon != null) { File target = new File(dest, name.substring(0, name.length() - DOT_WEBP.length()) + DOT_PNG); try (BufferedOutputStream outputStream = new BufferedOutputStream(fop.newFileOutputStream(target))) { ImageIO.write(icon, "PNG", outputStream); renameMap.put(name, target.getName()); continue; } } } } File target = new File(dest, name); if (fop.isFile(src) && !fop.exists(target)) { fop.copyFile(src, target); } } if (skinFile != null) { try (InputStream inputStream = new BufferedInputStream(fop.newFileInputStream(skinFile))) { File target = new File(dest, skinFile.getName()); try (BufferedOutputStream outputStream = new BufferedOutputStream(fop.newFileOutputStream(target))) { byte[] bytes = ByteStreams.toByteArray(inputStream); String layout = new String(bytes, Charsets.UTF_8); for (Map.Entry<String, String> entry : renameMap.entrySet()) { layout = layout.replace(entry.getKey(), entry.getValue()); } outputStream.write(layout.getBytes(Charsets.UTF_8)); } } } }  @NotNull static Storage getDefaultRam(@NotNull Hardware hardware); @NotNull static Storage getMaxPossibleRam(); static int getMaxCpuCores(); @Nullable static String getHardwarePropertyDefaultValue(String name, @Nullable AndroidSdkHandler sdkHandler); static String cleanAvdName(@NotNull AvdManagerConnection connection, @NotNull String candidateBase, boolean uniquify); @Nullable static File pathToUpdatedSkins(@Nullable File deviceFile, @Nullable SystemImageDescription image, @NotNull FileOp fop); @VisibleForTesting @Nullable static File ensureSkinsAreCurrent(@Nullable File resourcePath,
                                           @Nullable File skinDestination,
                                           @Nullable File deviceName,
                                           boolean emulatorCanDecodeWebp,
                                           @NotNull FileOp fop); static ModelWizardDialog createAvdWizard(@Nullable Component parent,
                                                  @Nullable Project project); static ModelWizardDialog createAvdWizard(@Nullable Component parent,
                                                  @Nullable Project project,
                                                  @Nullable AvdInfo avdInfo); static ModelWizardDialog createAvdWizard(@Nullable Component parent,
                                                  @Nullable Project project,
                                                  @NotNull AvdOptionsModel model); static ModelWizardDialog createAvdWizardForDuplication(@Nullable Component parent,
                                                                @Nullable Project project,
                                                                @NotNull  AvdInfo avdInfo); static final String WIZARD_ONLY; static final String DEVICE_DEFINITION_KEY; static final String SYSTEM_IMAGE_KEY; static final String RAM_STORAGE_KEY; static final String VM_HEAP_STORAGE_KEY; static final String INTERNAL_STORAGE_KEY; static final String SD_CARD_STORAGE_KEY; static final String EXISTING_SD_LOCATION; static final String DISPLAY_SD_SIZE_KEY; static final String DISPLAY_SD_LOCATION_KEY; static final String DISPLAY_USE_EXTERNAL_SD_KEY; static final String DEFAULT_ORIENTATION_KEY; static final String AVD_INI_NETWORK_SPEED; static final String NETWORK_SPEED_KEY; static final String AVD_INI_NETWORK_LATENCY; static final String NETWORK_LATENCY_KEY; static final String FRONT_CAMERA_KEY; static final String BACK_CAMERA_KEY; static final String USE_HOST_GPU_KEY; static final String HOST_GPU_MODE_KEY; static final String USE_COLD_BOOT; static final String USE_FAST_BOOT; static final String USE_CHOSEN_SNAPSHOT_BOOT; static final String CHOSEN_SNAPSHOT_FILE; static final String COLD_BOOT_ONCE_VALUE; static final String IS_IN_EDIT_MODE_KEY; static final String CUSTOM_SKIN_FILE_KEY; static final String BACKUP_SKIN_FILE_KEY; static final String DEVICE_FRAME_KEY; static final String DISPLAY_NAME_KEY; static final String AVD_ID_KEY; static final String CPU_CORES_KEY; static final String HAS_HARDWARE_KEYBOARD_KEY; static final Font STANDARD_FONT; static final Font FIGURE_FONT; static final Font TITLE_FONT; static final List<IdDisplay> ALL_DEVICE_TAGS; static final List<IdDisplay> TAGS_WITH_GOOGLE_API; static final String CREATE_SKIN_HELP_LINK; static final File NO_SKIN; }
@Test public void testConvertWebpSkinToPng() throws IOException { WebpMetadata.ensureWebpRegistered(); if (!WebpNativeLibHelper.loadNativeLibraryIfNeeded()) { System.out.println("Can't run skin conversion test without native webp library"); return; } DeviceArtDescriptor pixel = null; List<DeviceArtDescriptor> specs = DeviceArtDescriptor.getDescriptors(null); for (DeviceArtDescriptor spec : specs) { if ("pixel".equals(spec.getId())) { pixel = spec; break; } } assertThat(pixel).isNotNull(); File source = pixel.getBaseFolder(); FileOp fileOp = FileOpUtils.create(); assertThat(fileOp.exists(new File(source, "port_back.webp"))).isTrue(); assertThat(fileOp.exists(new File(source, "port_back.png"))).isFalse(); assertThat(fileOp.toString(new File(source, "layout"), Charsets.UTF_8)).contains(".webp"); assertThat(fileOp.toString(new File(source, "layout"), Charsets.UTF_8)).doesNotContain(".png"); File dest = myFolder.getRoot(); AvdWizardUtils.convertWebpSkinToPng(fileOp, dest, source); assertThat(fileOp.exists(new File(dest, "port_back.webp"))).isFalse(); assertThat(fileOp.exists(new File(dest, "port_back.png"))).isTrue(); assertThat(fileOp.exists(new File(dest, "layout"))).isTrue(); assertThat(fileOp.toString(new File(dest, "layout"), Charsets.UTF_8)).contains(".png"); assertThat(fileOp.toString(new File(dest, "layout"), Charsets.UTF_8)).doesNotContain(".webp"); }
@Test public void testConvertWebpSkinToPngFallthrough() throws IOException { WebpMetadata.ensureWebpRegistered(); if (!WebpNativeLibHelper.loadNativeLibraryIfNeeded()) { System.out.println("Can't run skin conversion test without native webp library"); return; } DeviceArtDescriptor wearSquare = null; List<DeviceArtDescriptor> specs = DeviceArtDescriptor.getDescriptors(null); for (DeviceArtDescriptor spec : specs) { if ("wear_square".equals(spec.getId())) { wearSquare = spec; break; } } assertThat(wearSquare).isNotNull(); File source = wearSquare.getBaseFolder(); FileOp fileOp = FileOpUtils.create(); assertThat(fileOp.exists(new File(source, "back.png"))).isTrue(); assertThat(fileOp.exists(new File(source, "back.webp"))).isFalse(); assertThat(fileOp.toString(new File(source, "layout"), Charsets.UTF_8)).contains(".png"); assertThat(fileOp.toString(new File(source, "layout"), Charsets.UTF_8)).doesNotContain(".webp"); File dest = myFolder.getRoot(); AvdWizardUtils.convertWebpSkinToPng(fileOp, dest, source); assertThat(fileOp.exists(new File(dest, "back.webp"))).isFalse(); assertThat(fileOp.exists(new File(dest, "back.png"))).isTrue(); assertThat(fileOp.exists(new File(dest, "layout"))).isTrue(); assertThat(fileOp.toString(new File(dest, "layout"), Charsets.UTF_8)).contains(".png"); assertThat(fileOp.toString(new File(dest, "layout"), Charsets.UTF_8)).doesNotContain(".webp"); }