remove remaining dependencies on ARSClib

This commit is contained in:
Julian Winkler
2024-05-22 23:38:54 +02:00
parent 64b3a505b6
commit 778d19f268
11 changed files with 225 additions and 223 deletions

View File

@@ -22,10 +22,6 @@ import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import com.reandroid.arsc.chunk.xml.ResXmlDocument;
import com.reandroid.arsc.chunk.xml.ResXmlPullParser;
import com.reandroid.arsc.value.ValueItem;
import java.io.FileDescriptor;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -34,6 +30,7 @@ import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
@@ -112,10 +109,17 @@ public final class AssetManager {
// ensureSystemAssets()
try {
Enumeration<URL> resources = ClassLoader.getSystemClassLoader().getResources("resources.arsc");
ArrayList<String> paths = new ArrayList<String>();
paths.add(null); // reserve first slot for framework-res.apk
while (resources.hasMoreElements()) {
URL resource = resources.nextElement();
String path = resource.getPath();
if (!path.contains("com.google.android.gms")) { // ignore MicroG .apk
String path = resources.nextElement().getPath();
if (path.contains("framework-res.apk")) // needs to be first, so it can be overridden
paths.set(0, path);
else if (!path.contains("com.google.android.gms")) // microg resources can not be merged
paths.add(path);
}
for (String path : paths) {
if (path != null) {
path = path.substring(path.indexOf("file:") + 5, path.indexOf("!/resources.arsc"));
addAssetPath(path);
}
@@ -759,18 +763,7 @@ public final class AssetManager {
if (defStyleRes == 0 && theme != 0 && loadThemeAttributeValue(theme, defStyleAttr, value, true) >= 0)
defStyleRes = value.data;
if (defStyleRes == 0 && set != null) {
if (parser instanceof ResXmlPullParser) {
ValueItem valueItem = ((ResXmlPullParser)parser).getAttribute(null, "style");
if (valueItem != null) {
value.type = valueItem.getType();
value.data = valueItem.getData();
if (theme != 0 && (value.type == TypedValue.TYPE_ATTRIBUTE))
loadThemeAttributeValue(theme, value.data, value, true);
defStyleRes = value.data;
}
} else {
defStyleRes = parser.getStyleAttribute();
}
defStyleRes = parser.getStyleAttribute();
}
outIndices[0] = 0;
@@ -798,14 +791,8 @@ public final class AssetManager {
value.assetCookie = -1;
found = true;
} else if (xmlCache.containsKey(resId)) {
if (parser instanceof ResXmlPullParser) {
ValueItem valueItem = ((ResXmlPullParser)parser).getResXmlAttributeAt(xmlCache.get(resId));
value.type = valueItem.getType();
value.data = valueItem.getData();
} else {
value.type = XmlBlock.nativeGetAttributeDataType(((XmlBlock.Parser)parser).mParseState, xmlCache.get(resId));
value.data = XmlBlock.nativeGetAttributeData(((XmlBlock.Parser)parser).mParseState, xmlCache.get(resId));
}
value.type = XmlBlock.nativeGetAttributeDataType(((XmlBlock.Parser)parser).mParseState, xmlCache.get(resId));
value.data = XmlBlock.nativeGetAttributeData(((XmlBlock.Parser)parser).mParseState, xmlCache.get(resId));
value.resourceId = 0;
value.assetCookie = -1;
if (value.type != TypedValue.TYPE_ATTRIBUTE)

View File

@@ -34,8 +34,6 @@ import android.util.LongSparseArray;
import android.util.Slog;
import android.util.TypedValue;
import com.android.internal.util.XmlUtils;
import com.reandroid.arsc.chunk.xml.ResXmlPullParser;
import com.reandroid.arsc.value.ValueItem;
// import android.view.DisplayAdjustments;
import java.io.IOException;
import java.io.InputStream;

View File

@@ -16,15 +16,12 @@
package android.content.res;
import android.content.pm.ActivityInfo;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import com.android.internal.util.XmlUtils;
import com.reandroid.arsc.chunk.xml.ResXmlPullParser;
import com.reandroid.arsc.item.ResXmlString;
import java.util.Arrays;
@@ -156,12 +153,9 @@ public class TypedArray {
if (type == TypedValue.TYPE_STRING) {
final int cookie = data[index + AssetManager.STYLE_ASSET_COOKIE];
if (cookie < 0) {
if (mXml instanceof ResXmlPullParser)
return ((ResXmlPullParser )mXml).getResXmlDocument().getStringPool().get(data[index + AssetManager.STYLE_DATA]).get();
else {
Thread.dumpStack();
System.exit(-1);
}
CharSequence string = ((XmlBlock.Parser)mXml).getPooledString(data[index + AssetManager.STYLE_DATA]);
if (string != null)
return string.toString();
}
}
return null;
@@ -700,15 +694,9 @@ public class TypedArray {
final int cookie = data[index + AssetManager.STYLE_ASSET_COOKIE];
if (cookie < 0) {
if (mXml != null) {
if (mXml instanceof ResXmlPullParser) {
ResXmlString xmlString = ((ResXmlPullParser)mXml).getResXmlDocument().getStringPool().get(data[index + AssetManager.STYLE_DATA]);
if (xmlString != null)
return xmlString.get();
} else {
CharSequence string = ((XmlBlock.Parser)mXml).getPooledString(data[index + AssetManager.STYLE_DATA]);
if (string != null)
return string;
}
CharSequence string = ((XmlBlock.Parser)mXml).getPooledString(data[index + AssetManager.STYLE_DATA]);
if (string != null)
return string;
}
if (data[index + AssetManager.STYLE_RESOURCE_ID] != 0) {
return mResources.mAssets.getResourceText(data[index + AssetManager.STYLE_RESOURCE_ID]);