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,3 +17,10 @@ JNIEXPORT jlong JNICALL Java_android_os_SystemClock_uptimeMillis(JNIEnv *env, jc
|
||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
return now.tv_sec * 1000 + lround(now.tv_nsec / 1e6);
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_android_os_SystemClock_elapsedRealtimeNanos(JNIEnv *env, jclass this)
|
||||
{
|
||||
struct timespec t;
|
||||
clock_gettime(CLOCK_BOOTTIME, &t);
|
||||
return t.tv_sec * 1000000000 + t.tv_nsec;
|
||||
}
|
||||
|
||||
@@ -273,14 +273,6 @@ JNIEXPORT void JNICALL Java_android_os_Process_readProcLines
|
||||
JNIEXPORT jintArray JNICALL Java_android_os_Process_getPids
|
||||
(JNIEnv *, jclass, jstring, jintArray);
|
||||
|
||||
/*
|
||||
* Class: android_os_Process
|
||||
* Method: readProcFile
|
||||
* Signature: (Ljava/lang/String;[I[Ljava/lang/String;[J[F)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_android_os_Process_readProcFile
|
||||
(JNIEnv *, jclass, jstring, jintArray, jobjectArray, jlongArray, jfloatArray);
|
||||
|
||||
/*
|
||||
* Class: android_os_Process
|
||||
* Method: parseProcLine
|
||||
|
||||
@@ -27,4 +27,6 @@ public class Animator {
|
||||
|
||||
public Animator setDuration(long duration) { return this; }
|
||||
|
||||
public void setInterpolator(TimeInterpolator i) {}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,4 +4,8 @@ public class PropertyValuesHolder{
|
||||
public static PropertyValuesHolder ofFloat(String propertyName, float... values) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static PropertyValuesHolder ofObject(String propertyName, TypeEvaluator evaluator, Object... values) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package android.app;
|
||||
import android.R;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContextWrapper;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageParser;
|
||||
@@ -12,6 +12,7 @@ import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
@@ -28,7 +29,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Activity extends ContextWrapper implements Window.Callback {
|
||||
public class Activity extends ContextThemeWrapper implements Window.Callback {
|
||||
LayoutInflater layout_inflater;
|
||||
Window window = new Window(this);
|
||||
int requested_orientation = -1 /*ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED*/; // dummy
|
||||
@@ -54,7 +55,7 @@ public class Activity extends ContextWrapper implements Window.Callback {
|
||||
if (className == null) {
|
||||
for (PackageParser.Activity activity: pkg.activities) {
|
||||
for (PackageParser.IntentInfo intent: activity.intents) {
|
||||
if (intent.matchAction("android.intent.action.MAIN")) {
|
||||
if (intent.hasCategory("android.intent.category.LAUNCHER")) {
|
||||
className = activity.className;
|
||||
break;
|
||||
}
|
||||
@@ -74,23 +75,27 @@ public class Activity extends ContextWrapper implements Window.Callback {
|
||||
|
||||
public Activity() {
|
||||
super(null);
|
||||
layout_inflater = new LayoutInflater();
|
||||
layout_inflater = new LayoutInflater(this);
|
||||
intent = new Intent();
|
||||
|
||||
CharSequence label = null;
|
||||
CharSequence app_label = null;
|
||||
int themeResId = 0;
|
||||
for (PackageParser.Activity activity: pkg.activities) {
|
||||
if (getClass().getName().equals(activity.className)) {
|
||||
label = getText(activity.info.labelRes);
|
||||
label = r.getText(activity.info.labelRes);
|
||||
themeResId = activity.info.getThemeResource();
|
||||
break;
|
||||
}
|
||||
}
|
||||
app_label = getText(pkg.applicationInfo.labelRes);
|
||||
app_label = r.getText(pkg.applicationInfo.labelRes);
|
||||
if (label != null) {
|
||||
setTitle(label);
|
||||
} else if (app_label != null) {
|
||||
setTitle(app_label);
|
||||
}
|
||||
attachBaseContext(new Context());
|
||||
setTheme(themeResId);
|
||||
}
|
||||
|
||||
public View root_view;
|
||||
@@ -422,6 +427,10 @@ public class Activity extends ContextWrapper implements Window.Callback {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public void setTitle(int titleId) {
|
||||
this.title = getText(titleId);
|
||||
}
|
||||
|
||||
public CharSequence getTitle() {
|
||||
return title;
|
||||
}
|
||||
@@ -488,6 +497,10 @@ public class Activity extends ContextWrapper implements Window.Callback {
|
||||
return destroyed;
|
||||
}
|
||||
|
||||
public void finishAffinity() {
|
||||
finish();
|
||||
}
|
||||
|
||||
private native void nativeFinish(long native_window);
|
||||
public static native void nativeRecreateActivity(Activity activity);
|
||||
public static native void nativeStartActivity(Activity activity);
|
||||
|
||||
@@ -5,7 +5,9 @@ import java.util.List;
|
||||
|
||||
public class ActivityManager {
|
||||
|
||||
public static class RunningAppProcessInfo{}
|
||||
public static class RunningAppProcessInfo{
|
||||
public int importance;
|
||||
}
|
||||
|
||||
public List<RunningAppProcessInfo> getRunningAppProcesses() {
|
||||
return null;
|
||||
@@ -16,6 +18,8 @@ public class ActivityManager {
|
||||
public static class MemoryInfo {
|
||||
/* For now, just always report there's 10GB free RAM */
|
||||
public long availMem = 10000;
|
||||
|
||||
public long totalMem = 10000;
|
||||
}
|
||||
|
||||
public void getMemoryInfo(MemoryInfo outInfo)
|
||||
@@ -26,4 +30,8 @@ public class ActivityManager {
|
||||
public ConfigurationInfo getDeviceConfigurationInfo() {
|
||||
return new ConfigurationInfo();
|
||||
}
|
||||
|
||||
public int getMemoryClass() {return 20;} // suggested heap size in MB
|
||||
|
||||
public static void getMyMemoryState(RunningAppProcessInfo outInfo) {}
|
||||
}
|
||||
|
||||
@@ -2,4 +2,8 @@ package android.app;
|
||||
|
||||
public class AlarmManager {
|
||||
public void cancel(PendingIntent operation) {}
|
||||
|
||||
public void setInexactRepeating(int type, long triggerTime, long interval, PendingIntent operation) {}
|
||||
|
||||
public void setExact(int type, long triggerTime, PendingIntent operation) {}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class Application extends ContextWrapper {
|
||||
}
|
||||
|
||||
public Application() {
|
||||
super(new Context());
|
||||
super(null);
|
||||
}
|
||||
/**
|
||||
* Called when the application is starting, before any activity, service,
|
||||
|
||||
@@ -22,6 +22,7 @@ public class Dialog implements Window.Callback, DialogInterface {
|
||||
private Context context;
|
||||
private Window window;
|
||||
private OnDismissListener onDismissListener;
|
||||
private OnShowListener onShowListener;
|
||||
|
||||
public Dialog(Context context, int themeResId) {
|
||||
this.context = context;
|
||||
@@ -75,6 +76,8 @@ public class Dialog implements Window.Callback, DialogInterface {
|
||||
public void run() {
|
||||
onCreate(null);
|
||||
nativeShow(nativePtr);
|
||||
if (onShowListener != null)
|
||||
onShowListener.onShow(Dialog.this);
|
||||
}
|
||||
};
|
||||
if(Looper.myLooper() == Looper.getMainLooper()) {
|
||||
@@ -160,4 +163,8 @@ public class Dialog implements Window.Callback, DialogInterface {
|
||||
public void cancel() {
|
||||
dismiss();
|
||||
}
|
||||
|
||||
public void setOnShowListener(OnShowListener onShowListener) {
|
||||
this.onShowListener = onShowListener;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,4 +4,8 @@ public class KeyguardManager {
|
||||
public boolean inKeyguardRestrictedInputMode() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isKeyguardLocked() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
public class NotificationManager {
|
||||
public void cancelAll() {}
|
||||
@@ -40,7 +41,7 @@ public class NotificationManager {
|
||||
public void cancel(String tag, final int id) {
|
||||
// remove_notification doesn't work reliably when sent directly after add_notification in GNOME session.
|
||||
// So we give some extra delay here.
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
nativeCancel(id);
|
||||
|
||||
@@ -25,4 +25,12 @@ public abstract class Service extends Context {
|
||||
public Application getApplication() {
|
||||
return this_application;
|
||||
}
|
||||
|
||||
public void stopSelf(int startId) {
|
||||
System.out.println("Service.stopSelf(" + startId + ") called");
|
||||
}
|
||||
|
||||
public void stopSelf() {
|
||||
System.out.println("Service.stopSelf() called");
|
||||
}
|
||||
}
|
||||
|
||||
8
src/api-impl/android/bluetooth/BluetoothAdapter.java
Normal file
8
src/api-impl/android/bluetooth/BluetoothAdapter.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package android.bluetooth;
|
||||
|
||||
public class BluetoothAdapter {
|
||||
|
||||
public static BluetoothAdapter getDefaultAdapter() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
6
src/api-impl/android/bluetooth/BluetoothProfile.java
Normal file
6
src/api-impl/android/bluetooth/BluetoothProfile.java
Normal file
@@ -0,0 +1,6 @@
|
||||
package android.bluetooth;
|
||||
|
||||
public class BluetoothProfile {
|
||||
|
||||
public interface ServiceListener {}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user