AssetManager.java: iterate tableBlocks instead of merging

The merging process is too slow
This commit is contained in:
Julian Winkler
2023-08-22 16:14:18 +02:00
committed by Mis012
parent 6547e66d4f
commit 2b97e3bd57

View File

@@ -32,6 +32,7 @@ import com.reandroid.arsc.group.EntryGroup;
import com.reandroid.arsc.item.StringItem; import com.reandroid.arsc.item.StringItem;
import com.reandroid.arsc.value.Entry; import com.reandroid.arsc.value.Entry;
import com.reandroid.arsc.value.EntryHeaderMap; import com.reandroid.arsc.value.EntryHeaderMap;
import com.reandroid.arsc.item.TableString;
import com.reandroid.arsc.value.ResValue; import com.reandroid.arsc.value.ResValue;
import com.reandroid.arsc.value.ResValueMap; import com.reandroid.arsc.value.ResValueMap;
import com.reandroid.arsc.value.ValueItem; import com.reandroid.arsc.value.ValueItem;
@@ -49,6 +50,7 @@ import java.util.ArrayList;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.List;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
@@ -106,7 +108,7 @@ public final class AssetManager {
private boolean mOpen = true; private boolean mOpen = true;
private HashMap<Integer, RuntimeException> mRefStacks; private HashMap<Integer, RuntimeException> mRefStacks;
private TableBlock tableBlock; private List<TableBlock> tableBlocks;
/** /**
* Create a new AssetManager containing only the basic system assets. * Create a new AssetManager containing only the basic system assets.
@@ -117,12 +119,12 @@ public final class AssetManager {
*/ */
public AssetManager() { public AssetManager() {
try { try {
tableBlock = new TableBlock(); tableBlocks = new ArrayList<>();
Enumeration<URL> resources = ClassLoader.getSystemClassLoader().getResources("resources.arsc"); Enumeration<URL> resources = ClassLoader.getSystemClassLoader().getResources("resources.arsc");
while (resources.hasMoreElements()) { while (resources.hasMoreElements()) {
URL resource = resources.nextElement(); URL resource = resources.nextElement();
if (!resource.getFile().contains("com.google.android.gms")) { // ignore MicroG .apk if (!resource.getFile().contains("com.google.android.gms")) { // ignore MicroG .apk
tableBlock.merge(TableBlock.load(resource.openStream())); tableBlocks.add(TableBlock.load(resource.openStream()));
} }
} }
} catch (IOException e) { } catch (IOException e) {
@@ -142,6 +144,16 @@ public final class AssetManager {
} }
} }
private EntryGroup tableBlockSearch(int resId) {
EntryGroup ret = null;
for (TableBlock tableBlock : tableBlocks) {
ret = tableBlock.search(resId);
if (ret != null)
break;
}
return ret;
}
private static void ensureSystemAssets() { private static void ensureSystemAssets() {
synchronized (sSync) { synchronized (sSync) {
if (sSystem == null) { if (sSystem == null) {
@@ -195,7 +207,7 @@ public final class AssetManager {
/*package*/ final CharSequence getResourceText(int id) { /*package*/ final CharSequence getResourceText(int id) {
if (id == 0) if (id == 0)
return ""; return "";
ResValue resValue = tableBlock.search(id).pickOne().getResValue(); ResValue resValue = tableBlockSearch(id).pickOne().getResValue();
if (resValue.getValueType() == ValueType.REFERENCE) { if (resValue.getValueType() == ValueType.REFERENCE) {
return getResourceText(resValue.getData()); return getResourceText(resValue.getData());
} }
@@ -227,7 +239,7 @@ public final class AssetManager {
*/ */
/*package*/ final String[] getResourceStringArray(final int id) { /*package*/ final String[] getResourceStringArray(final int id) {
ArrayList<String> values = new ArrayList<String>(); ArrayList<String> values = new ArrayList<String>();
for (ResValueMap map : tableBlock.search(id).pickOne().getResValueMapArray().getChildes()) { for (ResValueMap map : tableBlockSearch(id).pickOne().getResValueMapArray().getChildes()) {
values.add(map.getValueAsString()); values.add(map.getValueAsString());
} }
return values.toArray(new String[0]); return values.toArray(new String[0]);
@@ -245,7 +257,7 @@ public final class AssetManager {
outValue.string = mStringBlocks[block].get(outValue.data); outValue.string = mStringBlocks[block].get(outValue.data);
return true; return true;
}*/ }*/
EntryGroup entryGroup = tableBlock.search(ident); EntryGroup entryGroup = tableBlockSearch(ident);
if (entryGroup == null) if (entryGroup == null)
return false; // not found return false; // not found
ResValue resValue = entryGroup.pickOne().getResValue(); ResValue resValue = entryGroup.pickOne().getResValue();
@@ -794,9 +806,11 @@ public final class AssetManager {
*/ */
/*package*/ /*native*/ final int getResourceIdentifier(String name, String type, String defPackage) { /*package*/ /*native*/ final int getResourceIdentifier(String name, String type, String defPackage) {
System.out.println("getResourceIdentifier(" + name + "," + type + "," + defPackage + ") called"); System.out.println("getResourceIdentifier(" + name + "," + type + "," + defPackage + ") called");
for (PackageBlock packageBlock : tableBlock.listPackages()) { for (TableBlock tableBlock : tableBlocks) {
if (packageBlock.getName().equals(defPackage)) { for (PackageBlock packageBlock : tableBlock.listPackages()) {
return packageBlock.getEntry("", type, name).getResourceId(); if (packageBlock.getName().equals(defPackage)) {
return packageBlock.getEntry("", type, name).getResourceId();
}
} }
} }
@@ -966,7 +980,7 @@ public final class AssetManager {
private native final String[] getArrayStringResource(int arrayRes); private native final String[] getArrayStringResource(int arrayRes);
private native final int[] getArrayStringInfo(int arrayRes); private native final int[] getArrayStringInfo(int arrayRes);
/*package*/ final int[] getArrayIntResource(int arrayRes) { /*package*/ final int[] getArrayIntResource(int arrayRes) {
ResValueMap children[] = tableBlock.search(arrayRes).pickOne().getResValueMapArray().getChildes(); ResValueMap children[] = tableBlockSearch(arrayRes).pickOne().getResValueMapArray().getChildes();
int values[] = new int[children.length]; int values[] = new int[children.length];
for (int i = 0; i < children.length; i++) { for (int i = 0; i < children.length; i++) {
values[i] = children[i].getData(); values[i] = children[i].getData();