You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
add lots of java APIs needed for Whatsapp
This commit is contained in:
@@ -17,7 +17,7 @@ public class ContentProvider {
|
||||
public boolean onCreate() {return false;}
|
||||
|
||||
public Context getContext() {
|
||||
return Context.this_application;
|
||||
return new Context();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ import android.telephony.TelephonyManager;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Slog;
|
||||
import android.view.Display;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.WindowManagerImpl;
|
||||
import android.view.accessibility.AccessibilityManager;
|
||||
@@ -128,6 +129,7 @@ public class Context extends Object {
|
||||
application.setTheme(pkg.applicationInfo.theme);
|
||||
application.native_window = native_window;
|
||||
this_application = application;
|
||||
application.attachBaseContext(new Context());
|
||||
return application;
|
||||
}
|
||||
|
||||
@@ -199,7 +201,7 @@ public class Context extends Object {
|
||||
case "accessibility":
|
||||
return new AccessibilityManager();
|
||||
case "layout_inflater":
|
||||
return new LayoutInflater();
|
||||
return new LayoutInflater(getApplicationContext());
|
||||
case "wifi":
|
||||
return new WifiManager();
|
||||
default:
|
||||
@@ -214,14 +216,7 @@ public class Context extends Object {
|
||||
}
|
||||
|
||||
public Looper getMainLooper() {
|
||||
/* TODO: this is not what AOSP does, which could be a problem */
|
||||
Looper looper = Looper.myLooper();
|
||||
if(looper == null) {
|
||||
Looper.prepare();
|
||||
looper = Looper.myLooper();
|
||||
}
|
||||
|
||||
return looper;
|
||||
return Looper.getMainLooper();
|
||||
}
|
||||
|
||||
public String getPackageName() {
|
||||
@@ -452,7 +447,7 @@ public class Context extends Object {
|
||||
return false;
|
||||
}
|
||||
|
||||
new Handler().post(new Runnable() { // run this asynchron so the caller can finish its setup before onServiceConnected is called
|
||||
new Handler(Looper.getMainLooper()).post(new Runnable() { // run this asynchron so the caller can finish its setup before onServiceConnected is called
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@@ -490,15 +485,26 @@ public class Context extends Object {
|
||||
}
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Class<? extends Activity> cls = Class.forName(intent.getComponent().getClassName()).asSubclass(Activity.class);
|
||||
Constructor<? extends Activity> constructor = cls.getConstructor();
|
||||
Activity activity = constructor.newInstance();
|
||||
activity.intent = intent;
|
||||
activity.getWindow().native_window = this_application.native_window;
|
||||
Activity.nativeStartActivity(activity);
|
||||
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
final Intent intent_ = intent;
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Class<? extends Activity> cls = Class.forName(intent_.getComponent().getClassName()).asSubclass(Activity.class);
|
||||
Constructor<? extends Activity> constructor = cls.getConstructor();
|
||||
Activity activity = constructor.newInstance();
|
||||
activity.intent = intent_;
|
||||
activity.getWindow().native_window = this_application.native_window;
|
||||
Activity.nativeStartActivity(activity);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
};
|
||||
if (Looper.myLooper() == Looper.getMainLooper()) {
|
||||
runnable.run();
|
||||
} else {
|
||||
new Handler(Looper.getMainLooper()).post(runnable);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -576,6 +582,18 @@ public class Context extends Object {
|
||||
}
|
||||
|
||||
public Context createConfigurationContext(Configuration configuration) {
|
||||
return this;
|
||||
return new Context();
|
||||
}
|
||||
|
||||
public void sendOrderedBroadcast(Intent intent, String receiverPermission, BroadcastReceiver resultReceiver, Handler handler, int flags, String extra, Bundle options) {
|
||||
System.out.println("sendOrderedBroadcast(" + intent + ", " + receiverPermission + ", " + resultReceiver + ", " + handler + ", " + flags + ", " + extra + ", " + options + ") called");
|
||||
}
|
||||
|
||||
public Context createDisplayContext(Display display) {
|
||||
return new Context();
|
||||
}
|
||||
|
||||
public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter, String broadcastPermission, Handler scheduler) {
|
||||
return registerReceiver(receiver, filter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,4 +10,9 @@ public class ContextWrapper extends Context {
|
||||
public Context getBaseContext() {
|
||||
return baseContext;
|
||||
}
|
||||
|
||||
protected void attachBaseContext(Context baseContext) {
|
||||
this.baseContext = baseContext;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ public interface DialogInterface {
|
||||
void onClick(DialogInterface dialog, int which);
|
||||
}
|
||||
public interface OnShowListener {
|
||||
void onShow(DialogInterface dialog);
|
||||
}
|
||||
public interface OnCancelListener {
|
||||
}
|
||||
|
||||
@@ -314,4 +314,8 @@ public class Intent {
|
||||
public ArrayList<Parcelable> getParcelableArrayListExtra(String name) {
|
||||
return extras.getParcelableArrayList(name);
|
||||
}
|
||||
|
||||
public String getPackage() {
|
||||
return component.getPackageName();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package android.content;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class IntentFilter {
|
||||
|
||||
private Set<String> actions = new HashSet<>();
|
||||
private List<String> actions = new ArrayList<>();
|
||||
private Set<String> categories = new HashSet<>();
|
||||
|
||||
public IntentFilter() {}
|
||||
public IntentFilter(String action) {
|
||||
@@ -22,4 +25,19 @@ public class IntentFilter {
|
||||
public final boolean matchAction(String action) {
|
||||
return actions.contains(action);
|
||||
}
|
||||
|
||||
public void addCategory(String category) {
|
||||
categories.add(category);
|
||||
}
|
||||
public int countCategories() {
|
||||
return categories.size();
|
||||
}
|
||||
|
||||
public final boolean hasCategory(String category) {
|
||||
return categories.contains(category);
|
||||
}
|
||||
|
||||
public String getAction(int index) {
|
||||
return actions.get(index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -472,6 +472,8 @@ public class ApplicationInfo extends PackageItemInfo {
|
||||
*/
|
||||
public int installLocation = PackageInfo.INSTALL_LOCATION_UNSPECIFIED;
|
||||
|
||||
public String[] splitSourceDirs;
|
||||
|
||||
public void dump(Printer pw, String prefix) {
|
||||
super.dumpFront(pw, prefix);
|
||||
if (className != null) {
|
||||
|
||||
@@ -1670,7 +1670,12 @@ public class PackageManager {
|
||||
*/
|
||||
public ServiceInfo getServiceInfo(ComponentName component,
|
||||
int flags) throws NameNotFoundException {
|
||||
return null;
|
||||
for (PackageParser.Service s : Context.pkg.services) {
|
||||
if (s.className.equals(component.getClassName())) {
|
||||
return s.info;
|
||||
}
|
||||
}
|
||||
return new ServiceInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2245,6 +2245,7 @@ public class PackageParser {
|
||||
return false;
|
||||
}
|
||||
XmlUtils.skipCurrentTag(parser);
|
||||
outInfo.addCategory(value);
|
||||
} else if (nodeName.equals("data")) {
|
||||
XmlUtils.skipCurrentTag(parser);
|
||||
} else if (!RIGID_PARSER) {
|
||||
|
||||
@@ -103,7 +103,7 @@ public class Resources {
|
||||
/*package*/ final Object mAccessLock = new Object();
|
||||
/*package*/ final Configuration mTmpConfig = new Configuration();
|
||||
/*package*/ TypedValue mTmpValue = new TypedValue();
|
||||
/*package*/ final LongSparseArray<WeakReference<Drawable.ConstantState>> mDrawableCache = new LongSparseArray<WeakReference<Drawable.ConstantState>>(0);
|
||||
/*package*/ final Map<Long,WeakReference<Drawable.ConstantState>> mDrawableCache = new HashMap<Long,WeakReference<Drawable.ConstantState>>(0);
|
||||
/*package*/ final LongSparseArray<WeakReference<ColorStateList>> mColorStateListCache = new LongSparseArray<WeakReference<ColorStateList>>(0);
|
||||
/*package*/ final LongSparseArray<WeakReference<Drawable.ConstantState>> mColorDrawableCache = new LongSparseArray<WeakReference<Drawable.ConstantState>>(0);
|
||||
/*package*/ boolean mPreloading;
|
||||
|
||||
Reference in New Issue
Block a user