api-impl/android/content: implement metadata bundle in PackageInfo

This commit is contained in:
Mis012
2023-10-08 22:33:14 +02:00
parent 2bb61d98be
commit 1b33acb658
3 changed files with 36 additions and 6 deletions

View File

@@ -17,6 +17,8 @@
package android.content.pm;
import com.reandroid.arsc.chunk.xml.AndroidManifestBlock;
import com.reandroid.arsc.chunk.xml.ResXmlAttribute;
import com.reandroid.arsc.chunk.xml.ResXmlElement;
import java.io.InputStream;
import java.io.IOException;
@@ -249,6 +251,23 @@ public class PackageInfo {
packageName = manifest.getPackageName();
versionCode = manifest.getVersionCode();
versionName = manifest.getVersionName();
System.out.println("PackageInfo()");
applicationInfo = new ApplicationInfo();
ResXmlElement application = manifest.getApplicationElement();
for (ResXmlElement metaData : application.listElements(AndroidManifestBlock.TAG_meta_data)) {
ResXmlAttribute name = metaData.searchAttributeByResourceId(AndroidManifestBlock.ID_name);
ResXmlAttribute value = metaData.searchAttributeByResourceId(AndroidManifestBlock.ID_value);
if (name == null || value == null) {
continue;
}
System.out.println("PackageInfo(): applicationInfo.metaData.putString("+name.getValueAsString()+", "+value.getValueAsString()+")");
applicationInfo.metaData.putString(name.getValueAsString(), value.getValueAsString());
}
System.out.println("PackageInfo(): packageName: >"+packageName+"<, versionCode: >"+versionCode+"<, versionName: >"+versionName+"<");
}

View File

@@ -1330,6 +1330,8 @@ public class PackageManager {
*/
public static final String ACTION_REQUEST_PERMISSION = "android.content.pm.action.REQUEST_PERMISSION";
PackageInfo package_info;
/**
* Extra field name for the list of permissions, which the user must approve.
*
@@ -1365,6 +1367,11 @@ public class PackageManager {
"SaTYb9dr5sB4WLNglk7zxDtM80H518VvihTcP7FHL+Gn6g4j5fkI98+S\n" +
"-----END CERTIFICATE-----\n").getBytes();
public PackageManager() {
package_info = new PackageInfo();
}
/**
* Retrieve overall information about an application package that is
* installed on the system.
@@ -1400,11 +1407,10 @@ public class PackageManager {
* @see #GET_UNINSTALLED_PACKAGES
*/
public PackageInfo getPackageInfo(String packageName, int flags) throws NameNotFoundException {
PackageInfo packageInfo = new PackageInfo();
if ((flags & GET_SIGNATURES) == GET_SIGNATURES) {
packageInfo.signatures = new Signature[]{new Signature(X509_DUMMY)};
package_info.signatures = new Signature[]{new Signature(X509_DUMMY)};
}
return packageInfo;
return package_info;
}
/**
@@ -1586,7 +1592,7 @@ public class PackageManager {
*/
public ApplicationInfo getApplicationInfo(String packageName,
int flags) throws NameNotFoundException {
return new ApplicationInfo();
return package_info.applicationInfo;
}
/**
@@ -1723,7 +1729,7 @@ public class PackageManager {
*/
public List<PackageInfo> getInstalledPackages(int flags) {
List<PackageInfo> ret = new ArrayList<PackageInfo>();
ret.add(new PackageInfo());
ret.add(package_info);
return ret;
}

View File

@@ -834,7 +834,12 @@ public final class AssetManager {
for (TableBlock tableBlock : tableBlocks) {
for (PackageBlock packageBlock : tableBlock.listPackages()) {
if (packageBlock.getName().equals(defPackage)) {
return packageBlock.getEntry("", type, name).getResourceId();
Entry entry = packageBlock.getEntry("", type, name);
if(entry != null) {
return entry.getResourceId();
} else {
return -1; // TODO: investigate
}
}
}
}