Skip to content
This repository has been archived by the owner on Sep 21, 2020. It is now read-only.

Commit

Permalink
deal with system and development permission level
Browse files Browse the repository at this point in the history
  • Loading branch information
Dong Liu committed Dec 18, 2014
1 parent eba56f6 commit 9335b71
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
6 changes: 5 additions & 1 deletion src/main/java/net/dongliu/apk/parser/ApkParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public ApkParser(File apkFile) throws IOException {
this.apkMetaMap = new HashMap<Locale, ApkMeta>();
}

public ApkParser(String filePath) throws IOException {
this(new File(filePath));
}

/**
* return decoded AndroidManifest.xml
*
Expand Down Expand Up @@ -333,7 +337,7 @@ private void parsePermission(ApkMeta apkMeta, Node node) {
permission.setDescription(XmlUtils.getAttribute(attributes, "android:description"));
String protectionLevel = XmlUtils.getAttribute(attributes, "android:protectionLevel");
if (protectionLevel != null) {
permission.setProtectionLevel(Constants.ProtectionLevel.valueOf(protectionLevel));
permission.setProtectionLevel(protectionLevel);
}
apkMeta.addPermission(permission);
}
Expand Down
18 changes: 14 additions & 4 deletions src/main/java/net/dongliu/apk/parser/bean/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,30 @@ public static List<WindowSoftInputMode> valuesOf(int value) {

//http://developer.android.com/reference/android/content/pm/PermissionInfo.html
public enum ProtectionLevel {
normal(0), dangerous(1), signature(2), signatureOrSystem(3);
normal(0), dangerous(1), signature(2), signatureOrSystem(3),
system(0x10), development(0x20);
private int value;

ProtectionLevel(int value) {
this.value = value;
}

public static ProtectionLevel valueOf(int value) {
public static List<ProtectionLevel> valueOf(int value) {
List<ProtectionLevel> list = new ArrayList<ProtectionLevel>();
if ((value & system.value) != 0) {
value = value ^ system.value;
list.add(system);
}
if ((value & development.value) != 0) {
value = value ^ development.value;
list.add(development);
}
for (ProtectionLevel protectionLevel : ProtectionLevel.values()) {
if (protectionLevel.value == value) {
return protectionLevel;
list.add(protectionLevel);
}
}
return null;
return list;
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/dongliu/apk/parser/bean/Permission.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Permission {
private String icon;
private String description;
private String group;
private Constants.ProtectionLevel protectionLevel;
private String protectionLevel;

public String getName() {
return name;
Expand Down Expand Up @@ -53,11 +53,11 @@ public void setGroup(String group) {
this.group = group;
}

public Constants.ProtectionLevel getProtectionLevel() {
public String getProtectionLevel() {
return protectionLevel;
}

public void setProtectionLevel(Constants.ProtectionLevel protectionLevel) {
public void setProtectionLevel(String protectionLevel) {
this.protectionLevel = protectionLevel;
}
}
11 changes: 8 additions & 3 deletions src/main/java/net/dongliu/apk/parser/parser/XmlTranslator.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,14 @@ private String getAttributeValueAsString(String attributeName, String value) {
realValue = installLocation.name();
}
} else if (attributeName.equals("protectionLevel")) {
ProtectionLevel protectionLevel = ProtectionLevel.valueOf(intValue);
if (protectionLevel != null) {
realValue = protectionLevel.name();
List<ProtectionLevel> list = ProtectionLevel.valueOf(intValue);
StringBuilder sb = new StringBuilder();
if (list != null) {
for (ProtectionLevel protectionLevel : list) {
sb.append(protectionLevel.name()).append('|');
}
sb.deleteCharAt(sb.length() - 1);
realValue = sb.toString();
}
}
return realValue;
Expand Down

0 comments on commit 9335b71

Please sign in to comment.