import soot.jimple.infoflow.android.axml.AXmlNode; //导入方法依赖的package包/类
/**
* Get the name of the main activity in the AndroidManifest.xml file
* @param apkFileLocation
* @return
*/
public static String getMainActivityName(String apkFileLocation) {
String mainActivityName = null;
try {
ProcessManifest pm = new ProcessManifest(apkFileLocation);
AXmlHandler axmlh = pm.getAXml();
// Find main activity and remove main intent-filter
List anodes = axmlh.getNodesWithTag("activity");
for (AXmlNode an: anodes) {
boolean hasMain = false;
boolean hasLauncher = false;
AXmlNode filter = null;
AXmlAttribute aname = an.getAttribute("name");
String aval = (String)aname.getValue();
System.out.println("activity: "+ aval);
for (AXmlNode ch : an.getChildren()) {
System.out.println("children: "+ ch);
}
List fnodes = an.getChildrenWithTag("intent-filter");
for (AXmlNode fn: fnodes) {
hasMain = false;
hasLauncher = false;
// check action
List acnodes = fn.getChildrenWithTag("action");
for (AXmlNode acn: acnodes) {
AXmlAttribute acname = acn.getAttribute("name");
String acval = (String)acname.getValue();
System.out.println("action: "+ acval);
if (acval.equals("android.intent.action.MAIN")) {
hasMain = true;
}
}
// check category
List catnodes = fn.getChildrenWithTag("category");
for (AXmlNode catn: catnodes) {
AXmlAttribute catname = catn.getAttribute("name");
String catval = (String)catname.getValue();
System.out.println("category: "+ catval);
if (catval.equals("android.intent.category.LAUNCHER")) {
hasLauncher = true;
filter = fn;
}
}
if (hasLauncher && hasMain) {
break;
}
}
if (hasLauncher && hasMain) {
// replace name with the activity waiting for the connection to the PDP
System.out.println("main activity is: "+ aval);
System.out.println("excluding filter: "+ filter);
filter.exclude();
mainActivityName = aval;
break;
}
}
} catch (IOException | XmlPullParserException ex) {
System.err.println("Could not read Android manifest file: " + ex.getMessage());
throw new RuntimeException(ex);
}
return mainActivityName;
}