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,8 +1748,10 @@ public final class Compiler {
Set<String> infoSet = Sets.newHashSet();
for (int j = 0; j < infoArray.length(); ++j) {
String info = infoArray.getString(j);
if (!info.isEmpty()) {
infoSet.add(info);
}
}
if (!infoSet.isEmpty()) {
infoMap.put(type, infoSet);
......
......@@ -909,7 +909,7 @@ public abstract class ComponentProcessor extends AbstractProcessor {
UsesPermissions usesPermissions = element.getAnnotation(UsesPermissions.class);
if (usesPermissions != null) {
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 {
UsesLibraries usesLibraries = element.getAnnotation(UsesLibraries.class);
if (usesLibraries != null) {
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 {
UsesNativeLibraries usesNativeLibraries = element.getAnnotation(UsesNativeLibraries.class);
if (usesNativeLibraries != null) {
for (String nativeLibrary : usesNativeLibraries.libraries().split(",")) {
componentInfo.nativeLibraries.add(nativeLibrary.trim());
updateWithNonEmptyValue(componentInfo.nativeLibraries, nativeLibrary);
}
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 {
UsesAssets usesAssets = element.getAnnotation(UsesAssets.class);
if (usesAssets != null) {
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 {
if (usesActivities != null) {
try {
for (ActivityElement ae : usesActivities.activities()) {
componentInfo.activities.add(activityElementToString(ae));
updateWithNonEmptyValue(componentInfo.activities, activityElementToString(ae));
}
} catch (IllegalAccessException e) {
messager.printMessage(Diagnostic.Kind.ERROR, "IllegalAccessException when gathering " +
......@@ -963,7 +963,7 @@ public abstract class ComponentProcessor extends AbstractProcessor {
if (usesBroadcastReceivers != null) {
try {
for (ReceiverElement re : usesBroadcastReceivers.receivers()) {
componentInfo.broadcastReceivers.add(receiverElementToString(re));
updateWithNonEmptyValue(componentInfo.broadcastReceivers, receiverElementToString(re));
}
} catch (IllegalAccessException e) {
messager.printMessage(Diagnostic.Kind.ERROR, "IllegalAccessException when gathering " +
......@@ -1554,4 +1554,11 @@ public abstract class ComponentProcessor extends AbstractProcessor {
}, 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