Skip to content

Commit

Permalink
Handle empty strings in component annotations
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ewpatton authored and jisqyv committed Jan 8, 2018
1 parent 3bc2f32 commit 8a36303
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
Expand Up @@ -1748,7 +1748,9 @@ private void loadJsonInfo(ConcurrentMap<String, Set<String>> infoMap, String tar
Set<String> infoSet = Sets.newHashSet();
for (int j = 0; j < infoArray.length(); ++j) {
String info = infoArray.getString(j);
infoSet.add(info);
if (!info.isEmpty()) {
infoSet.add(info);
}
}

if (!infoSet.isEmpty()) {
Expand Down
Expand Up @@ -909,34 +909,34 @@ private void processComponent(Element element) {
UsesPermissions usesPermissions = element.getAnnotation(UsesPermissions.class);
if (usesPermissions != null) {
for (String permission : usesPermissions.permissionNames().split(",")) {
componentInfo.permissions.add(permission.trim());
updateWithNonEmptyValue(componentInfo.permissions, permission);
}
}

// Gather library names.
UsesLibraries usesLibraries = element.getAnnotation(UsesLibraries.class);
if (usesLibraries != null) {
for (String library : usesLibraries.libraries().split(",")) {
componentInfo.libraries.add(library.trim());
updateWithNonEmptyValue(componentInfo.libraries, library);
}
}

// Gather native library names.
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);
}
}

// Gather required files.
UsesAssets usesAssets = element.getAnnotation(UsesAssets.class);
if (usesAssets != null) {
for (String file : usesAssets.fileNames().split(",")) {
componentInfo.assets.add(file.trim());
updateWithNonEmptyValue(componentInfo.assets, file);
}
}

Expand All @@ -945,7 +945,7 @@ private void processComponent(Element element) {
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 " +
Expand All @@ -963,7 +963,7 @@ private void processComponent(Element element) {
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 " +
Expand Down Expand Up @@ -1554,4 +1554,11 @@ public Boolean visitDeclared(DeclaredType t, Set<String> types) {
}, visitedTypes);
}
}

private void updateWithNonEmptyValue(Set<String> collection, String value) {
String trimmedValue = value.trim();
if (!trimmedValue.isEmpty()) {
collection.add(trimmedValue);
}
}
}

0 comments on commit 8a36303

Please sign in to comment.