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())));
putUsesFramework(meta);
putSdkInfo(meta);
putPackageInfo(meta);
}
mAndrolib.writeMetaFile(mOutDir, meta);
@ -257,7 +258,14 @@ public class ApkDecoder {
if (info.size() > 0) {
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;

View File

@ -190,6 +190,12 @@ final public class AndrolibResources {
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,
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(mMaxSdkVersion);
}
if (mPackageRenamed != null) {
cmd.add("--rename-manifest-package");
cmd.add(mPackageRenamed);
}
cmd.add("-F");
cmd.add(apkFile.getAbsolutePath());
@ -581,5 +592,7 @@ final public class AndrolibResources {
private String mMinSdkVersion = null;
private String mMaxSdkVersion = null;
private String mTargetSdkVersion = null;
private String mPackageRenamed = null;
}

View File

@ -40,6 +40,7 @@ public class ResTable {
private String mFrameTag;
private Map<String, String> mSdkInfo = new LinkedHashMap<String, String>();
private Map<String, String> mPackageInfo = new LinkedHashMap<String, String>();
public ResTable() {
mAndRes = null;
@ -134,4 +135,12 @@ public class ResTable {
public void clearSdkInfo() {
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){
boolean hideSdkInfo = false;
boolean hidePackageInfo = false;
@Override
public void event(XmlPullParser pp) throws XmlPullParserException, IOException {
int type = pp.getEventType();
if (type == XmlPullParser.START_TAG) {
if ("packages".equalsIgnoreCase(pp.getName())) {
if ("manifest".equalsIgnoreCase(pp.getName())) {
try {
boolean test = parseAttr(pp);
hidePackageInfo = parseManifest(pp);
if (hidePackageInfo) {
return;
}
} catch (AndrolibException e) {}
}
if ("uses-sdk".equalsIgnoreCase(pp.getName())) {
@ -69,11 +73,18 @@ public class XmlPullStreamDecoder implements ResStreamDecoder {
super.event(pp);
}
private boolean parseManifest(XmlPullParser pp) throws AndrolibException {
// @todo read <manifest> for package:
return false;
}
private boolean parseAttr(XmlPullParser pp) throws AndrolibException {
ResTable restable = resTable;
for (int i = 0; i < pp.getAttributeCount(); i++) {
final String a_ns = "http://schemas.android.com/apk/res/android";
String ns = pp.getAttributeNamespace (i);
if (a_ns.equalsIgnoreCase(ns)) {
String name = pp.getAttributeName (i);
String value = pp.getAttributeValue (i);
@ -89,7 +100,10 @@ public class XmlPullStreamDecoder implements ResStreamDecoder {
}
} else {
resTable.clearSdkInfo();
return false;//Found unknown flags
if (i >= pp.getAttributeCount()) {
return false;//Found unknown flags
}
}
}
return true;