api-impl: misc stubs/additions

This commit is contained in:
Mis012 2024-11-30 18:49:11 +01:00
parent 39504d1437
commit 0803848c6d
18 changed files with 206 additions and 39 deletions

View file

@ -159,7 +159,6 @@ void activity_start(JNIEnv *env, jobject activity_object)
activity_backlog = g_list_prepend(activity_backlog, _REF(activity_object));
activity_update_current(env);
}
JNIEXPORT void JNICALL Java_android_app_Activity_nativeFinish(JNIEnv *env, jobject this, jlong window)

View file

@ -9,6 +9,10 @@ extern "C" {
#endif
#undef android_app_Activity_MODE_PRIVATE
#define android_app_Activity_MODE_PRIVATE 0L
#undef android_app_Activity_RESULT_CANCELED
#define android_app_Activity_RESULT_CANCELED 0L
#undef android_app_Activity_RESULT_OK
#define android_app_Activity_RESULT_OK -1L
/*
* Class: android_app_Activity
* Method: nativeFinish

View file

@ -14,6 +14,7 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Slog;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.Menu;
@ -34,6 +35,11 @@ import java.util.List;
import java.util.Map;
public class Activity extends ContextThemeWrapper implements Window.Callback {
private final static String TAG = "Activity";
public static final int RESULT_CANCELED = 0;
public static final int RESULT_OK = -1;
LayoutInflater layout_inflater;
Window window = new Window(this, this);
int requested_orientation = -1 /*ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED*/; // dummy
@ -57,6 +63,7 @@ public class Activity extends ContextThemeWrapper implements Window.Callback {
if (className == null) {
for (PackageParser.Activity activity: pkg.activities) {
for (PackageParser.IntentInfo intent: activity.intents) {
Slog.i(TAG, intent.toString());
if ((uri == null && intent.hasCategory("android.intent.category.LAUNCHER")) ||
(uri != null && intent.hasDataScheme(uri.getScheme()))) {
className = activity.className;
@ -149,7 +156,7 @@ public class Activity extends ContextThemeWrapper implements Window.Callback {
public final void setVolumeControlStream(int streamType) {}
protected void onCreate(Bundle savedInstanceState) {
System.out.println("- onCreate - yay!");
Slog.i(TAG, "- onCreate - yay!");
new ViewGroup(this).setId(R.id.content);
for (Fragment fragment : fragments) {
@ -160,12 +167,12 @@ public class Activity extends ContextThemeWrapper implements Window.Callback {
}
protected void onPostCreate(Bundle savedInstanceState) {
System.out.println("- onPostCreate - yay!");
Slog.i(TAG, "- onPostCreate - yay!");
return;
}
protected void onStart() {
System.out.println("- onStart - yay!");
Slog.i(TAG, "- onStart - yay!");
if (window.contentView != null)
window.setContentView(window.contentView);
window.setTitle(title);
@ -184,13 +191,13 @@ public class Activity extends ContextThemeWrapper implements Window.Callback {
}
protected void onRestart() {
System.out.println("- onRestart - yay!");
Slog.i(TAG, "- onRestart - yay!");
return;
}
protected void onResume() {
System.out.println("- onResume - yay!");
Slog.i(TAG, "- onResume - yay!");
for (Fragment fragment : fragments) {
fragment.onResume();
@ -201,12 +208,12 @@ public class Activity extends ContextThemeWrapper implements Window.Callback {
}
protected void onPostResume() {
System.out.println("- onPostResume - yay!");
Slog.i(TAG, "- onPostResume - yay!");
return;
}
protected void onPause() {
System.out.println("- onPause - yay!");
Slog.i(TAG, "- onPause - yay!");
for (Fragment fragment : fragments) {
fragment.onPause();
@ -217,7 +224,7 @@ public class Activity extends ContextThemeWrapper implements Window.Callback {
}
protected void onStop() {
System.out.println("- onStop - yay!");
Slog.i(TAG, "- onStop - yay!");
for (Fragment fragment : fragments) {
fragment.onStop();
@ -227,7 +234,7 @@ public class Activity extends ContextThemeWrapper implements Window.Callback {
}
protected void onDestroy() {
System.out.println("- onDestroy - yay!");
Slog.i(TAG, "- onDestroy - yay!");
for (Fragment fragment : fragments) {
fragment.onDestroy();
@ -238,7 +245,7 @@ public class Activity extends ContextThemeWrapper implements Window.Callback {
}
public void onWindowFocusChanged(boolean hasFocus) {
System.out.println("- onWindowFocusChanged - yay! (hasFocus: " + hasFocus + ")");
Slog.i(TAG, "- onWindowFocusChanged - yay! (hasFocus: " + hasFocus + ")");
return;
}
@ -255,12 +262,12 @@ public class Activity extends ContextThemeWrapper implements Window.Callback {
/* --- */
public void setContentView(int layoutResID) throws Exception {
System.out.println("- setContentView - yay!");
Slog.i(TAG, "- setContentView - yay!");
root_view = layout_inflater.inflate(layoutResID, null, false);
System.out.println("~~~~~~~~~~~");
System.out.println(root_view);
System.out.println(root_view.toString());
System.out.printf("%x\n", root_view.id);
System.out.println("~~~~~~~~~~~");
@ -277,17 +284,17 @@ public class Activity extends ContextThemeWrapper implements Window.Callback {
}
public <T extends android.view.View> T findViewById(int id) {
System.out.printf("- findViewById - asked for view with id: %x\n", id);
System.out.printf(TAG, "- findViewById - asked for view with id: %x\n", id);
View view = null;
if (window.contentView != null)
view = window.contentView.findViewById(id);
System.out.println("- findViewById - found this: " + view);
Slog.i(TAG, "- findViewById - found this: " + view);
return (T)view;
}
public void invalidateOptionsMenu() {
System.out.println("invalidateOptionsMenu() called, should we do something?");
Slog.i(TAG, "invalidateOptionsMenu() called, should we do something?");
}
public Window getWindow() {
@ -317,7 +324,7 @@ public class Activity extends ContextThemeWrapper implements Window.Callback {
}
public void startActivityForResult(Intent intent, int requestCode, Bundle options) {
System.out.println("startActivityForResult(" + intent + ", " + requestCode + ") called");
Slog.i(TAG, "startActivityForResult(" + intent + ", " + requestCode + "," + options + ") called");
if (intent.getComponent() != null) {
try {
Class<? extends Activity> cls = Class.forName(intent.getComponent().getClassName()).asSubclass(Activity.class);
@ -338,9 +345,8 @@ public class Activity extends ContextThemeWrapper implements Window.Callback {
}
} else if (FILE_CHOOSER_ACTIONS.contains(intent.getAction())) {
nativeFileChooser(FILE_CHOOSER_ACTIONS.indexOf(intent.getAction()), intent.getType(), intent.getStringExtra("android.intent.extra.TITLE"), requestCode);
}
else {
System.out.println("startActivityForResult: intent was not handled. Calling onActivityResult(RESULT_CANCELED).");
} else {
Slog.i(TAG, "startActivityForResult: intent was not handled. Calling onActivityResult(RESULT_CANCELED).");
onActivityResult(requestCode, 0 /*RESULT_CANCELED*/, new Intent());
}
}
@ -359,18 +365,18 @@ public class Activity extends ContextThemeWrapper implements Window.Callback {
}
protected Dialog onCreateDialog(int id) {
System.out.println("Activity.onCreateDialog(" + id + ") called");
Slog.i(TAG, "Activity.onCreateDialog(" + id + ") called");
return null;
}
protected void onPrepareDialog(int id, Dialog dialog) {
System.out.println("Activity.onPrepareDialog(" + id + ") called");
Slog.i(TAG, "Activity.onPrepareDialog(" + id + ") called");
}
private Map<Integer, Dialog> dialogs = new HashMap<Integer, Dialog>();
public final void showDialog(int id) {
System.out.println("Activity.showDialog(" + id + ") called");
Slog.i(TAG, "Activity.showDialog(" + id + ") called");
Dialog dialog = dialogs.get(id);
if (dialog == null)
dialogs.put(id, dialog = onCreateDialog(id));
@ -416,7 +422,7 @@ public class Activity extends ContextThemeWrapper implements Window.Callback {
@Override
public void onContentChanged() {
System.out.println("- onContentChanged - yay!");
Slog.i(TAG, "- onContentChanged - yay!");
}
public boolean onCreateOptionsMenu(Menu menu) {
@ -502,7 +508,7 @@ public class Activity extends ContextThemeWrapper implements Window.Callback {
@Override
public boolean onMenuOpened(int featureId, Menu menu) {
System.out.println("onMenuOpened(" + featureId + ", " + menu + ") called");
Slog.i(TAG, "onMenuOpened(" + featureId + ", " + menu + ") called");
return false;
}
@ -513,11 +519,11 @@ public class Activity extends ContextThemeWrapper implements Window.Callback {
Constructor<? extends Activity> constructor = cls.getConstructor();
Activity activity = constructor.newInstance();
activity.getWindow().native_window = getWindow().native_window;
System.out.println("activity.getWindow().native_window >"+activity.getWindow().native_window+"<");
Slog.i(TAG, "activity.getWindow().native_window >"+activity.getWindow().native_window+"<");
nativeFinish(0);
nativeStartActivity(activity);
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
System.out.println("exception in Activity.recreate, this is kinda sus");
Slog.i(TAG, "exception in Activity.recreate, this is kinda sus");
e.printStackTrace();
}
}

View file

@ -1,8 +1,10 @@
package android.app;
import android.app.Application;
import android.content.pm.ConfigurationInfo;
import android.content.Context;
import android.content.pm.ConfigurationInfo;
import android.content.res.Configuration;
import java.util.List;
public class ActivityThread {
@ -18,4 +20,8 @@ public class ActivityThread {
public Application getApplication() {
return Context.this_application;
}
public Configuration getConfiguration() {
return Context.this_application.getResources().getConfiguration();
}
}

View file

@ -7,7 +7,7 @@ public class FragmentManager {
public FragmentManager(Activity activity) {
this.activity = activity;
}
public Fragment findFragmentByTag(String tag) {
return null;
}

View file

@ -7,7 +7,7 @@ public class FragmentTransaction {
public FragmentTransaction(Activity activity) {
this.activity = activity;
}
public FragmentTransaction add(Fragment fragment, String string) {
fragment.activity = activity;
activity.fragments.add(fragment);

View file

@ -14,6 +14,18 @@ public class ProgressDialog extends AlertDialog {
public void setIndeterminate(boolean indeterminate) {}
public static ProgressDialog show(Context context, CharSequence title, CharSequence message) {
return show(context, title, message, false);
}
public static ProgressDialog show(Context context, CharSequence title, CharSequence message, boolean indeterminate) {
return show(context, title, message, indeterminate, false, null);
}
public static ProgressDialog show(Context context, CharSequence title, CharSequence message, boolean indeterminate, boolean cancelable) {
return show(context, title, message, indeterminate, cancelable, null);
}
public static ProgressDialog show(Context context, CharSequence title, CharSequence message, boolean indeterminate, boolean cancelable, OnCancelListener cancelListener) {
return new ProgressDialog(context);
}

View file

@ -3,13 +3,17 @@ package android.content;
import java.io.File;
import java.io.FileNotFoundException;
import android.accounts.Account;
import android.database.ContentObserver;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.CancellationSignal;
import android.os.ParcelFileDescriptor;
public class ContentResolver {
public static final String SYNC_EXTRAS_IGNORE_SETTINGS = "ignore_settings";
public final void registerContentObserver(Uri uri, boolean notifyForDescendants, ContentObserver observer) {
}
public final void unregisterContentObserver(ContentObserver observer) {
@ -77,4 +81,17 @@ public class ContentResolver {
else
return 0;
}
public static void requestSync(Account account, String authority, Bundle extras) {
}
public static void cancelSync(Account account, String authority) {
}
public static void setMasterSyncAutomatically(boolean sync) {
}
public static boolean isSyncActive(Account account, String authority) {
return false;
}
}

View file

@ -358,6 +358,10 @@ public class Context extends Object {
return getCacheDir();
}
public File[] getExternalCacheDirs() {
return new File[] {getCacheDir()};
}
public File getNoBackupFilesDir() {
if (nobackup_dir == null) {
nobackup_dir = new File(getDataDirFile(), "no_backup/" + getPackageName());

View file

@ -7,6 +7,9 @@ import java.io.Serializable;
import java.util.ArrayList;
public class Intent implements Parcelable {
public static final String ACTION_MAIN = "android.intent.action.MAIN";
public static final int FLAG_ACTIVITY_NEW_TASK = 0x10000000;
private ComponentName component;
private Bundle extras = new Bundle();
private String action;

View file

@ -2,11 +2,10 @@ package android.os;
public final class Debug {
public static class MemoryInfo {
}
/**
* Wait until a debugger attaches. As soon as the debugger attaches,
* this returns, so you will need to place a breakpoint after the
* waitForDebugger() call if you want to start tracing immediately.
*/
public static void waitForDebugger() {
}
public static class InstructionCount {
public InstructionCount() {
}

View file

@ -4,6 +4,10 @@ import java.util.ArrayList;
import java.util.List;
public class TelephonyManager {
public static TelephonyManager getDefault() {
return new TelephonyManager();
}
// FIXME: can we return null instead of ""?
public String getNetworkOperator() {
return "";
@ -17,6 +21,10 @@ public class TelephonyManager {
return "";
}
public String getSubscriberId() {
return "";
}
public int getPhoneType() {
return 0; // PHONE_TYPE_NONE
}

View file

@ -0,0 +1,40 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.util;
/**
* An implementation of {@link android.util.Property} to be used specifically with fields of type
* <code>float</code>. This type-specific subclass enables performance benefit by allowing
* calls to a {@link #setValue(Object, float) setValue()} function that takes the primitive
* <code>float</code> type and avoids autoboxing and other overhead associated with the
* <code>Float</code> class.
*
* @param <T> The class on which the Property is declared.
*/
public abstract class FloatProperty<T> extends Property<T, Float> {
public FloatProperty(String name) {
super(Float.class, name);
}
/**
* A type-specific variant of {@link #set(Object, Float)} that is faster when dealing
* with fields of type <code>float</code>.
*/
public abstract void setValue(T object, float value);
@Override
final public void set(T object, Float value) {
setValue(object, value);
}
}

View file

@ -21,6 +21,7 @@ import android.os.Parcelable;
import android.os.SystemClock;
import android.os.Vibrator;
import android.util.AttributeSet;
import android.util.FloatProperty;
import android.util.LayoutDirection;
import android.util.Property;
import android.util.Slog;
@ -580,6 +581,28 @@ public class View implements Drawable.Callback {
public static final int TEXT_DIRECTION_RTL = 4; // 0x4
public static final Property<View, Float> SCALE_X = new FloatProperty<View>("scaleX") {
@Override
public void setValue(View object, float value) {
object.setScaleX(value);
}
@Override
public Float get(View object) {
return object.getScaleX();
}
};
public static final Property<View, Float> SCALE_Y = new FloatProperty<View>("scaleY") {
@Override
public void setValue(View object, float value) {
object.setScaleY(value);
}
@Override
public Float get(View object) {
return object.getScaleY();
}
};
// --- end of constants from android source
// --- interfaces from android source
@ -613,8 +636,7 @@ public class View implements Drawable.Callback {
}
public static interface OnKeyListener {
// TODO
// boolean onKey(View v, int keyCode, KeyEvent event);
boolean onKey(View v, int keyCode, KeyEvent event);
}
public interface OnLongClickListener {
@ -1580,6 +1602,16 @@ public class View implements Drawable.Callback {
native_queueAllocate(widget);
}
public void setX(float x) {
setTranslationX(x - left);
}
public void setY(float y) {
setTranslationY(y - top);
}
public void setAlpha(float alpha) {
native_setVisibility(widget, visibility, alpha);
this.alpha = alpha;
@ -1721,6 +1753,9 @@ public class View implements Drawable.Callback {
public void setHorizontalScrollBarEnabled(boolean enabled) {}
public void setVerticalScrollBarEnabled(boolean enabled) {}
public void postInvalidateOnAnimation() {
postInvalidate();
}

View file

@ -18,6 +18,8 @@ package android.view;
import android.graphics.Rect;
import android.graphics.Region;
import android.os.Handler;
import android.os.Looper;
import java.util.ArrayList;
import java.util.concurrent.CopyOnWriteArrayList;
@ -494,9 +496,16 @@ public final class ViewTreeObserver {
}
mOnGlobalLayoutListeners.add(listener);
// hack: many Applications wait for the global layout before doing anything
// so we dispatch the event immediately
listener.onGlobalLayout();
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
listener.onGlobalLayout();
}
});
}
/**

View file

@ -1,7 +1,10 @@
package android.widget;
import java.util.ArrayList;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
public class GridView extends AbsListView {
public GridView(Context context) {
@ -11,4 +14,19 @@ public class GridView extends AbsListView {
public GridView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
}
public GridView(Context context, AttributeSet attributeSet, int defStyleAttr) {
super(context, attributeSet, defStyleAttr);
}
@Override
public View getSelectedView() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getSelectedView'");
}
@Override
public void setSelection(int position) {
setSelection(position, false);
}
}

View file

@ -220,7 +220,7 @@ public class TextView extends View {
public void setAllCaps(boolean allCaps) {
String[] classesToRemove = {"ATL-text-uppercase"};
native_removeClasses(widget, classesToRemove);
if(allCaps){
native_addClass(widget, "ATL-text-uppercase");
}
@ -351,4 +351,8 @@ public class TextView extends View {
public int getPaintFlags() {return 0;}
public void setPaintFlags(int flags) {}
public int getLineHeight() {
return 10; // FIXME
}
}

View file

@ -400,6 +400,7 @@ hax_jar = jar('hax', [
'android/util/DecompiledXmlResourceParser.java',
'android/util/DisplayMetrics.java',
'android/util/FloatMath.java',
'android/util/FloatProperty.java',
'android/util/JsonReader.java',
'android/util/JsonScope.java',
'android/util/JsonToken.java',
@ -516,6 +517,7 @@ hax_jar = jar('hax', [
'android/widget/FilterQueryProvider.java',
'android/widget/FrameLayout.java',
'android/widget/Gallery.java',
'android/widget/GridView.java',
'android/widget/HeaderViewListAdapter.java',
'android/widget/HorizontalScrollView.java',
'android/widget/ImageButton.java',
@ -588,5 +590,6 @@ hax_jar = jar('hax', [
'-bootclasspath', bootclasspath,
'-source', '1.8', '-target', '1.8',
'-encoding', 'UTF-8',
'-Xlint:-deprecation', # we implement deprecated APIs
'-h', join_paths(dir_base, 'src/api-impl-jni/generated_headers')
])