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

@@ -8,6 +8,7 @@ import android.content.ContextWrapper;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.net.Uri;
import android.os.Bundle;
@@ -22,10 +23,7 @@ import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.WindowManagerImpl;
import com.reandroid.arsc.chunk.xml.AndroidManifestBlock;
import com.reandroid.arsc.chunk.xml.ResXmlAttribute;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
@@ -51,16 +49,27 @@ public class Activity extends ContextWrapper implements Window.Callback {
*
* @param className class name of activity or null
* @return instance of main activity class
* @throws Exception
*/
private static Activity createMainActivity(String className, long native_window) throws ClassNotFoundException, NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, IOException {
private static Activity createMainActivity(String className, long native_window) throws Exception {
if (className == null) {
InputStream inStream = ClassLoader.getSystemClassLoader().getResourceAsStream("AndroidManifest.xml");
AndroidManifestBlock block = AndroidManifestBlock.load(inStream);
className = block.getMainActivity().searchAttributeByResourceId(AndroidManifestBlock.ID_name).getValueAsString();
XmlResourceParser parser = Context.this_application.getAssets().openXmlResourceParser("AndroidManifest.xml");
for (; parser.getEventType() != XmlResourceParser.END_DOCUMENT; parser.next()) {
if (parser.getEventType() == XmlResourceParser.START_TAG && "activity".equals(parser.getName())) {
className = parser.getAttributeValue("http://schemas.android.com/apk/res/android", "name");
}
// check if it is the main activity
if (parser.getEventType() == XmlResourceParser.START_TAG && "action".equals(parser.getName())) {
if ("android.intent.action.MAIN".equals(parser.getAttributeValue("http://schemas.android.com/apk/res/android", "name"))) {
break;
}
}
}
parser.close();
if(className.indexOf('.') == -1)
className = "." + className;
if (className.startsWith("."))
className = block.getPackageName() + className;
className = Context.this_application.getPackageName() + className;
} else {
className = className.replace('/', '.');
}
@@ -76,13 +85,30 @@ public class Activity extends ContextWrapper implements Window.Callback {
layout_inflater = new LayoutInflater();
intent = new Intent();
ResXmlAttribute label;
if((label = manifest.getActivityByName(getClass().getName()).searchAttributeByResourceId(AndroidManifestBlock.ID_label)) != null
|| (label = manifest.getApplicationElement().searchAttributeByResourceId(AndroidManifestBlock.ID_label)) != null) {
if(label.getValueType() == com.reandroid.arsc.value.ValueType.STRING)
setTitle(label.getValueAsString());
else
setTitle(getString(label.getData()));
CharSequence label = null;
CharSequence app_label = null;
try (XmlResourceParser parser = getAssets().openXmlResourceParser("AndroidManifest.xml")) {
for (; parser.getEventType() != XmlResourceParser.END_DOCUMENT; parser.next()) {
if (parser.getEventType() == XmlResourceParser.START_TAG && "application".equals(parser.getName())) {
TypedArray a = obtainStyledAttributes(parser, R.styleable.AndroidManifestApplication);
app_label = a.getText(R.styleable.AndroidManifestApplication_label);
a.recycle();
} else if (parser.getEventType() == XmlResourceParser.START_TAG && "activity".equals(parser.getName())) {
if (getClass().getName().equals(parser.getAttributeValue("http://schemas.android.com/apk/res/android", "name"))) {
TypedArray a = obtainStyledAttributes(parser, R.styleable.AndroidManifestActivity);
label = a.getText(R.styleable.AndroidManifestActivity_label);
a.recycle();
break;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
if (label != null) {
setTitle(label);
} else if (app_label != null) {
setTitle(app_label);
}
}

View File

@@ -2,18 +2,15 @@ package android.app;
import android.os.Bundle;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import com.reandroid.apk.AndroidFrameworks;
import com.reandroid.arsc.chunk.xml.AndroidManifestBlock;
import java.io.InputStream;
import java.io.IOException;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.R;
import android.content.Context;
import android.content.ContextWrapper;
public class Application extends ContextWrapper {
private String app_icon_path = null;
private String app_label = null;
public long native_window;
private String get_app_icon_path() {
@@ -21,8 +18,7 @@ public class Application extends ContextWrapper {
}
private String get_app_label() {
int app_label_resid = manifest.getApplicationElement().searchAttributeByResourceId(AndroidManifestBlock.ID_label).getData();
return getResources().getString(app_label_resid);
return app_label;
}
public interface ActivityLifecycleCallbacks {
@@ -52,12 +48,16 @@ public class Application extends ContextWrapper {
public Application() {
super(new Context());
/* TODO: is this the right place to put this? */
InputStream inStream = ClassLoader.getSystemClassLoader().getResourceAsStream("AndroidManifest.xml");
try {
AndroidManifestBlock manifest = AndroidManifestBlock.load(inStream);
int app_icon_resid = manifest.getIconResourceId();
app_icon_path = r.getString(app_icon_resid);
} catch (IOException e) {
try (XmlResourceParser parser = getAssets().openXmlResourceParser("AndroidManifest.xml")) {
for (; parser.getEventType() != XmlResourceParser.END_DOCUMENT; parser.next()) {
if (parser.getEventType() == XmlResourceParser.START_TAG && "application".equals(parser.getName())) {
TypedArray a = getResources().obtainAttributes(parser, R.styleable.AndroidManifestApplication);
app_icon_path = a.getString(R.styleable.AndroidManifestApplication_icon);
app_label = a.getString(R.styleable.AndroidManifestApplication_label);
a.recycle();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}

View File

@@ -21,6 +21,7 @@ import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.content.res.XmlResourceParser;
// import android.graphics.PixelFormat;
import android.os.Build;
import android.os.Bundle;
@@ -34,13 +35,8 @@ import android.view.SurfaceView;
import android.view.View;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.WindowManager;
import com.reandroid.arsc.chunk.xml.AndroidManifestBlock;
import com.reandroid.arsc.chunk.xml.ResXmlAttribute;
import com.reandroid.arsc.chunk.xml.ResXmlElement;
// import android.view.inputmethod.InputMethodManager;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
/**
* Convenience for implementing an activity that will be implemented
@@ -166,26 +162,28 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback,
}*/
// parse AndroidManifest.xml to get name and entry of native lib
try (InputStream inStream = ClassLoader.getSystemClassLoader().getResourceAsStream("AndroidManifest.xml")) {
for (ResXmlElement activity : AndroidManifestBlock.load(inStream).listActivities()) {
if (!getClass().getName().equals(activity.searchAttributeByResourceId(AndroidManifestBlock.ID_name).getValueAsString())) {
continue;
}
for (ResXmlElement metaData : activity.listElements(AndroidManifestBlock.TAG_meta_data)) {
ResXmlAttribute name = metaData.searchAttributeByResourceId(AndroidManifestBlock.ID_name);
ResXmlAttribute value = metaData.searchAttributeByResourceId(AndroidManifestBlock.ID_value);
if (name == null || value == null) {
try (XmlResourceParser parser = getAssets().openXmlResourceParser("AndroidManifest.xml")) {
for (; parser.getEventType() != XmlResourceParser.END_DOCUMENT; parser.next()) {
if (parser.getEventType() == XmlResourceParser.START_TAG && "activity".equals(parser.getName())) {
if (!getClass().getName().equals(parser.getAttributeValue("http://schemas.android.com/apk/res/android", "name"))) {
continue;
}
if (META_DATA_LIB_NAME.equals(name.getValueAsString())) {
libname = value.getValueAsString();
}
if (META_DATA_FUNC_NAME.equals(name.getValueAsString())) {
funcname = value.getValueAsString();
for (; !(parser.getEventType() == XmlResourceParser.END_TAG && "activity".equals(parser.getName())); parser.next()) {
if (parser.getEventType() == XmlResourceParser.START_TAG && "meta-data".equals(parser.getName())) {
String name = parser.getAttributeValue("http://schemas.android.com/apk/res/android", "name");
String value = parser.getAttributeValue("http://schemas.android.com/apk/res/android", "value");
if (META_DATA_LIB_NAME.equals(name)) {
libname = value;
}
if (META_DATA_FUNC_NAME.equals(name)) {
funcname = value;
}
}
}
break;
}
}
} catch (IOException e) {
} catch (Exception e) {
e.printStackTrace();
}