Commit 8a363032 authored by Evan W. Patton's avatar Evan W. Patton Committed by Jeffrey Schiller

Handle empty strings in component annotations

When a string such as "permission," is used with @UsesPermission, it
results in an empty string appearing in the permission list, and in
the <uses-permission> annotation in AndroidManifest.xml. Google Play
Store will reject such apps. This commit filters out empty strings
during component processing and during compilation to fix this issue.

Fixes #1108

Change-Id: Icafe2fa658f83f046dacfec98d3f0cb8f8b90755
parent 3bc2f321
...@@ -1748,7 +1748,9 @@ public final class Compiler { ...@@ -1748,7 +1748,9 @@ public final class Compiler {
Set<String> infoSet = Sets.newHashSet(); Set<String> infoSet = Sets.newHashSet();
for (int j = 0; j < infoArray.length(); ++j) { for (int j = 0; j < infoArray.length(); ++j) {
String info = infoArray.getString(j); String info = infoArray.getString(j);
infoSet.add(info); if (!info.isEmpty()) {
infoSet.add(info);
}
} }
if (!infoSet.isEmpty()) { if (!infoSet.isEmpty()) {
......
...@@ -909,7 +909,7 @@ public abstract class ComponentProcessor extends AbstractProcessor { ...@@ -909,7 +909,7 @@ public abstract class ComponentProcessor extends AbstractProcessor {
UsesPermissions usesPermissions = element.getAnnotation(UsesPermissions.class); UsesPermissions usesPermissions = element.getAnnotation(UsesPermissions.class);
if (usesPermissions != null) { if (usesPermissions != null) {
for (String permission : usesPermissions.permissionNames().split(",")) { for (String permission : usesPermissions.permissionNames().split(",")) {
componentInfo.permissions.add(permission.trim()); updateWithNonEmptyValue(componentInfo.permissions, permission);
} }
} }
...@@ -917,7 +917,7 @@ public abstract class ComponentProcessor extends AbstractProcessor { ...@@ -917,7 +917,7 @@ public abstract class ComponentProcessor extends AbstractProcessor {
UsesLibraries usesLibraries = element.getAnnotation(UsesLibraries.class); UsesLibraries usesLibraries = element.getAnnotation(UsesLibraries.class);
if (usesLibraries != null) { if (usesLibraries != null) {
for (String library : usesLibraries.libraries().split(",")) { for (String library : usesLibraries.libraries().split(",")) {
componentInfo.libraries.add(library.trim()); updateWithNonEmptyValue(componentInfo.libraries, library);
} }
} }
...@@ -925,10 +925,10 @@ public abstract class ComponentProcessor extends AbstractProcessor { ...@@ -925,10 +925,10 @@ public abstract class ComponentProcessor extends AbstractProcessor {
UsesNativeLibraries usesNativeLibraries = element.getAnnotation(UsesNativeLibraries.class); UsesNativeLibraries usesNativeLibraries = element.getAnnotation(UsesNativeLibraries.class);
if (usesNativeLibraries != null) { if (usesNativeLibraries != null) {
for (String nativeLibrary : usesNativeLibraries.libraries().split(",")) { for (String nativeLibrary : usesNativeLibraries.libraries().split(",")) {
componentInfo.nativeLibraries.add(nativeLibrary.trim()); updateWithNonEmptyValue(componentInfo.nativeLibraries, nativeLibrary);
} }
for (String v7aLibrary : usesNativeLibraries.v7aLibraries().split(",")) { for (String v7aLibrary : usesNativeLibraries.v7aLibraries().split(",")) {
componentInfo.nativeLibraries.add(v7aLibrary.trim() + ARMEABI_V7A_SUFFIX); updateWithNonEmptyValue(componentInfo.nativeLibraries, v7aLibrary.trim() + ARMEABI_V7A_SUFFIX);
} }
} }
...@@ -936,7 +936,7 @@ public abstract class ComponentProcessor extends AbstractProcessor { ...@@ -936,7 +936,7 @@ public abstract class ComponentProcessor extends AbstractProcessor {
UsesAssets usesAssets = element.getAnnotation(UsesAssets.class); UsesAssets usesAssets = element.getAnnotation(UsesAssets.class);
if (usesAssets != null) { if (usesAssets != null) {
for (String file : usesAssets.fileNames().split(",")) { for (String file : usesAssets.fileNames().split(",")) {
componentInfo.assets.add(file.trim()); updateWithNonEmptyValue(componentInfo.assets, file);
} }
} }
...@@ -945,7 +945,7 @@ public abstract class ComponentProcessor extends AbstractProcessor { ...@@ -945,7 +945,7 @@ public abstract class ComponentProcessor extends AbstractProcessor {
if (usesActivities != null) { if (usesActivities != null) {
try { try {
for (ActivityElement ae : usesActivities.activities()) { for (ActivityElement ae : usesActivities.activities()) {
componentInfo.activities.add(activityElementToString(ae)); updateWithNonEmptyValue(componentInfo.activities, activityElementToString(ae));
} }
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
messager.printMessage(Diagnostic.Kind.ERROR, "IllegalAccessException when gathering " + messager.printMessage(Diagnostic.Kind.ERROR, "IllegalAccessException when gathering " +
...@@ -963,7 +963,7 @@ public abstract class ComponentProcessor extends AbstractProcessor { ...@@ -963,7 +963,7 @@ public abstract class ComponentProcessor extends AbstractProcessor {
if (usesBroadcastReceivers != null) { if (usesBroadcastReceivers != null) {
try { try {
for (ReceiverElement re : usesBroadcastReceivers.receivers()) { for (ReceiverElement re : usesBroadcastReceivers.receivers()) {
componentInfo.broadcastReceivers.add(receiverElementToString(re)); updateWithNonEmptyValue(componentInfo.broadcastReceivers, receiverElementToString(re));
} }
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
messager.printMessage(Diagnostic.Kind.ERROR, "IllegalAccessException when gathering " + messager.printMessage(Diagnostic.Kind.ERROR, "IllegalAccessException when gathering " +
...@@ -1554,4 +1554,11 @@ public abstract class ComponentProcessor extends AbstractProcessor { ...@@ -1554,4 +1554,11 @@ public abstract class ComponentProcessor extends AbstractProcessor {
}, visitedTypes); }, visitedTypes);
} }
} }
private void updateWithNonEmptyValue(Set<String> collection, String value) {
String trimmedValue = value.trim();
if (!trimmedValue.isEmpty()) {
collection.add(trimmedValue);
}
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment