Starting work on Bug #252

This commit is contained in:
Connor Tumbleson 2012-12-01 12:36:51 -06:00
parent 60f3ef49c9
commit da68943022
4 changed files with 48 additions and 4 deletions

View File

@ -222,6 +222,7 @@ public class ApkDecoder {
Boolean.valueOf(mAndrolib.isFrameworkApk(getResTable()))); Boolean.valueOf(mAndrolib.isFrameworkApk(getResTable())));
putUsesFramework(meta); putUsesFramework(meta);
putSdkInfo(meta); putSdkInfo(meta);
putPackageInfo(meta);
} }
mAndrolib.writeMetaFile(mOutDir, meta); mAndrolib.writeMetaFile(mOutDir, meta);
@ -257,7 +258,14 @@ public class ApkDecoder {
if (info.size() > 0) { if (info.size() > 0) {
meta.put("sdkInfo", info); meta.put("sdkInfo", info);
} }
}
private void putPackageInfo(Map<String, Object> meta)
throws AndrolibException {
Map<String, String> info = getResTable().getPackageInfo();
if (info.size() > 0) {
meta.put("packageInfo", info);
}
} }
private final Androlib mAndrolib; private final Androlib mAndrolib;

View File

@ -190,6 +190,12 @@ final public class AndrolibResources {
mMaxSdkVersion = map.get("maxSdkVersion"); mMaxSdkVersion = map.get("maxSdkVersion");
} }
} }
public void setPackageInfo(Map<String, String> map) {
if (map != null) {
mPackageRenamed = map.get("package");
}
}
public void aaptPackage(File apkFile, File manifest, File resDir, public void aaptPackage(File apkFile, File manifest, File resDir,
File rawDir, File assetDir, File[] include, HashMap<String, Boolean> flags) File rawDir, File assetDir, File[] include, HashMap<String, Boolean> flags)
@ -221,6 +227,11 @@ final public class AndrolibResources {
cmd.add("--max-sdk-version"); cmd.add("--max-sdk-version");
cmd.add(mMaxSdkVersion); cmd.add(mMaxSdkVersion);
} }
if (mPackageRenamed != null) {
cmd.add("--rename-manifest-package");
cmd.add(mPackageRenamed);
}
cmd.add("-F"); cmd.add("-F");
cmd.add(apkFile.getAbsolutePath()); cmd.add(apkFile.getAbsolutePath());
@ -581,5 +592,7 @@ final public class AndrolibResources {
private String mMinSdkVersion = null; private String mMinSdkVersion = null;
private String mMaxSdkVersion = null; private String mMaxSdkVersion = null;
private String mTargetSdkVersion = null; private String mTargetSdkVersion = null;
private String mPackageRenamed = null;
} }

View File

@ -40,6 +40,7 @@ public class ResTable {
private String mFrameTag; private String mFrameTag;
private Map<String, String> mSdkInfo = new LinkedHashMap<String, String>(); private Map<String, String> mSdkInfo = new LinkedHashMap<String, String>();
private Map<String, String> mPackageInfo = new LinkedHashMap<String, String>();
public ResTable() { public ResTable() {
mAndRes = null; mAndRes = null;
@ -134,4 +135,12 @@ public class ResTable {
public void clearSdkInfo() { public void clearSdkInfo() {
mSdkInfo.clear(); mSdkInfo.clear();
} }
public void addPackageInfo(String key, String value) {
mPackageInfo.put(key, value);
}
public Map<String, String> getPackageInfo() {
return mPackageInfo;
}
} }

View File

@ -44,14 +44,18 @@ public class XmlPullStreamDecoder implements ResStreamDecoder {
XmlSerializerWrapper ser = new StaticXmlSerializerWrapper(mSerial, factory){ XmlSerializerWrapper ser = new StaticXmlSerializerWrapper(mSerial, factory){
boolean hideSdkInfo = false; boolean hideSdkInfo = false;
boolean hidePackageInfo = false;
@Override @Override
public void event(XmlPullParser pp) throws XmlPullParserException, IOException { public void event(XmlPullParser pp) throws XmlPullParserException, IOException {
int type = pp.getEventType(); int type = pp.getEventType();
if (type == XmlPullParser.START_TAG) { if (type == XmlPullParser.START_TAG) {
if ("packages".equalsIgnoreCase(pp.getName())) { if ("manifest".equalsIgnoreCase(pp.getName())) {
try { try {
boolean test = parseAttr(pp); hidePackageInfo = parseManifest(pp);
if (hidePackageInfo) {
return;
}
} catch (AndrolibException e) {} } catch (AndrolibException e) {}
} }
if ("uses-sdk".equalsIgnoreCase(pp.getName())) { if ("uses-sdk".equalsIgnoreCase(pp.getName())) {
@ -69,11 +73,18 @@ public class XmlPullStreamDecoder implements ResStreamDecoder {
super.event(pp); super.event(pp);
} }
private boolean parseManifest(XmlPullParser pp) throws AndrolibException {
// @todo read <manifest> for package:
return false;
}
private boolean parseAttr(XmlPullParser pp) throws AndrolibException { private boolean parseAttr(XmlPullParser pp) throws AndrolibException {
ResTable restable = resTable; ResTable restable = resTable;
for (int i = 0; i < pp.getAttributeCount(); i++) { for (int i = 0; i < pp.getAttributeCount(); i++) {
final String a_ns = "http://schemas.android.com/apk/res/android"; final String a_ns = "http://schemas.android.com/apk/res/android";
String ns = pp.getAttributeNamespace (i); String ns = pp.getAttributeNamespace (i);
if (a_ns.equalsIgnoreCase(ns)) { if (a_ns.equalsIgnoreCase(ns)) {
String name = pp.getAttributeName (i); String name = pp.getAttributeName (i);
String value = pp.getAttributeValue (i); String value = pp.getAttributeValue (i);
@ -89,7 +100,10 @@ public class XmlPullStreamDecoder implements ResStreamDecoder {
} }
} else { } else {
resTable.clearSdkInfo(); resTable.clearSdkInfo();
return false;//Found unknown flags
if (i >= pp.getAttributeCount()) {
return false;//Found unknown flags
}
} }
} }
return true; return true;