diff options
Diffstat (limited to 'src')
2 files changed, 37 insertions, 11 deletions
diff --git a/src/tools/android/java/com/google/devtools/build/android/DensitySpecificManifestProcessor.java b/src/tools/android/java/com/google/devtools/build/android/DensitySpecificManifestProcessor.java index 4226a45bf7..13938dff32 100644 --- a/src/tools/android/java/com/google/devtools/build/android/DensitySpecificManifestProcessor.java +++ b/src/tools/android/java/com/google/devtools/build/android/DensitySpecificManifestProcessor.java @@ -48,7 +48,7 @@ public class DensitySpecificManifestProcessor { static final ImmutableList<String> SCREEN_SIZES = ImmutableList.of( "small", "normal", "large", "xlarge"); - static final ImmutableBiMap<String, String> SCREEN_DENSITIES = + static final ImmutableBiMap<String, String> PLAY_STORE_SUPPORTED_DENSITIES = ImmutableBiMap.<String, String>builder() .put("ldpi", "ldpi") .put("mdpi", "mdpi") @@ -124,7 +124,7 @@ public class DensitySpecificManifestProcessor { NodeList screenElements = doc.getElementsByTagName("screen"); for (int i = 0; i < screenElements.getLength(); i++) { Node screen = screenElements.item(i); - existingDensities.add(SCREEN_DENSITIES.inverse().get( + existingDensities.add(PLAY_STORE_SUPPORTED_DENSITIES.inverse().get( screen.getAttributes().getNamedItem("android:screenDensity").getNodeValue())); } if (existingDensities.containsAll(densities)) { @@ -137,15 +137,32 @@ public class DensitySpecificManifestProcessor { compatibleScreensElement.getParentNode().removeChild(compatibleScreensElement); } - Node compatibleScreens = doc.createElement("compatible-screens"); - manifestElement.appendChild(compatibleScreens); - + // If the list of densities provided in the android_binary build rule contains a density not + // supported by the Play Store, omit the <compatible-screens> declaration from the manifest to + // indicate that this APK supports all densities. This is a temporary fix to support new + // density buckets until the Play Store introduces a new density targeting mechanism. + boolean omitCompatibleScreens = false; for (String density : densities) { - for (String screenSize : SCREEN_SIZES) { - Element screen = doc.createElement("screen"); - screen.setAttribute("android:screenSize", screenSize); - screen.setAttribute("android:screenDensity", SCREEN_DENSITIES.get(density)); - compatibleScreens.appendChild(screen); + if (!PLAY_STORE_SUPPORTED_DENSITIES.containsKey(density)) { + omitCompatibleScreens = true; + System.out.println(density + " is not an accepted Play Store density."); + System.out.println("Omitting <compatible-screens> declaration from output manifest."); + break; + } + } + + if (!omitCompatibleScreens) { + Node compatibleScreens = doc.createElement("compatible-screens"); + manifestElement.appendChild(compatibleScreens); + + for (String density : densities) { + for (String screenSize : SCREEN_SIZES) { + Element screen = doc.createElement("screen"); + screen.setAttribute("android:screenSize", screenSize); + screen.setAttribute("android:screenDensity", + PLAY_STORE_SUPPORTED_DENSITIES.get(density)); + compatibleScreens.appendChild(screen); + } } } diff --git a/src/tools/android/java/com/google/devtools/build/android/DensitySpecificResourceFilter.java b/src/tools/android/java/com/google/devtools/build/android/DensitySpecificResourceFilter.java index c5f7d45b44..e003a7df9d 100644 --- a/src/tools/android/java/com/google/devtools/build/android/DensitySpecificResourceFilter.java +++ b/src/tools/android/java/com/google/devtools/build/android/DensitySpecificResourceFilter.java @@ -13,6 +13,7 @@ // limitations under the License. package com.google.devtools.build.android; +import com.android.ide.common.res2.MergingException; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; import com.google.common.base.Joiner; @@ -118,6 +119,7 @@ public class DensitySpecificResourceFilter { .put("hdpi", 240) .put("280dpi", 280) .put("xhdpi", 320) + .put("340dpi", 340) .put("400dpi", 400) .put("420dpi", 420) .put("xxhdpi", 480) @@ -154,10 +156,17 @@ public class DensitySpecificResourceFilter { * @param out The path to use for name spacing the final resource directory. * @param working The path of the working directory for the filtering */ - public DensitySpecificResourceFilter(List<String> densities, Path out, Path working) { + public DensitySpecificResourceFilter(List<String> densities, Path out, Path working) + throws MergingException { this.densities = densities; this.out = out; this.working = working; + + for (String density : densities) { + if (!DENSITY_MAP.containsKey(density)) { + throw new MergingException(density + " is not a known density qualifier."); + } + } } @VisibleForTesting |