src/api-impl: misc stubbing

This commit is contained in:
Mis012
2022-12-27 17:21:21 +01:00
parent 696fa5a192
commit 2e4590c4d8
15 changed files with 226 additions and 52 deletions

View File

@@ -137,14 +137,6 @@ JNIEXPORT jint JNICALL Java_android_os_Process_getUidForName
JNIEXPORT jint JNICALL Java_android_os_Process_getGidForName JNIEXPORT jint JNICALL Java_android_os_Process_getGidForName
(JNIEnv *, jclass, jstring); (JNIEnv *, jclass, jstring);
/*
* Class: android_os_Process
* Method: setThreadPriority
* Signature: (II)V
*/
JNIEXPORT void JNICALL Java_android_os_Process_setThreadPriority
(JNIEnv *, jclass, jint, jint);
/* /*
* Class: android_os_Process * Class: android_os_Process
* Method: setCanSelfBackground * Method: setCanSelfBackground

View File

@@ -30,6 +30,7 @@ import android.media.AudioManager;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.hardware.usb.UsbManager; import android.hardware.usb.UsbManager;
import android.os.Vibrator; import android.os.Vibrator;
import android.hardware.display.DisplayManager;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@@ -38,6 +39,12 @@ import java.io.FileOutputStream;
public class Context extends Object { public class Context extends Object {
private final static String TAG = "Context"; private final static String TAG = "Context";
public static final int MODE_PRIVATE = 0;
public static final String LOCATION_SERVICE = "location";
public static final String AUDIO_SERVICE = "audio";
public static final String DISPLAY_SERVICE = "display";
public static final String MEDIA_ROUTER_SERVICE = "media_router";
static AssetManager assets; static AssetManager assets;
static DisplayMetrics dm; static DisplayMetrics dm;
static Configuration config; static Configuration config;
@@ -67,6 +74,10 @@ public class Context extends Object {
System.out.println("new Context! this one is: " + this); System.out.println("new Context! this one is: " + this);
} }
public int checkPermission (String permission, int pid, int uid) {
return getPackageManager().checkPermission(permission, "dummy");
}
public Resources.Theme getTheme() { public Resources.Theme getTheme() {
return r.newTheme(); return r.newTheme();
} }
@@ -109,6 +120,8 @@ public class Context extends Object {
return new Vibrator(); return new Vibrator();
case "power": case "power":
return new PowerManager(); return new PowerManager();
case "display":
return new DisplayManager();
default: default:
System.out.println("!!!!!!! getSystemService: case >"+name+"< is not implemented yet"); System.out.println("!!!!!!! getSystemService: case >"+name+"< is not implemented yet");
return null; return null;
@@ -191,6 +204,10 @@ public class Context extends Object {
return obb_dir; return obb_dir;
} }
public File[] getObbDirs() {
return new File[]{getObbDir()};
}
// FIXME: should be something like /tmp/cache, but may need to create that directory // FIXME: should be something like /tmp/cache, but may need to create that directory
public File getCacheDir() { public File getCacheDir() {
if (cache_dir == null) { if (cache_dir == null) {

View File

@@ -653,4 +653,6 @@ public class ApplicationInfo extends PackageItemInfo {
@Override protected ApplicationInfo getApplicationInfo() { @Override protected ApplicationInfo getApplicationInfo() {
return this; return this;
} }
public String[] splitPublicSourceDirs = new String[0];
} }

View File

@@ -1797,7 +1797,17 @@ public class PackageManager {
* @see #PERMISSION_DENIED * @see #PERMISSION_DENIED
*/ */
public int checkPermission(String permName, String pkgName) { public int checkPermission(String permName, String pkgName) {
return -1; switch(permName) {
// TODO: we shouldn't just automatically grant these once we have bubblewrap set up
// for now, the app can access anything it wants, so no point telling it otherwise
case "android.permission.WRITE_EXTERNAL_STORAGE":
return PERMISSION_GRANTED;
case "android.permission.READ_EXTERNAL_STORAGE":
return PERMISSION_GRANTED;
default:
System.out.println("PackageManager.checkPermission: >"+permName+"< not handled\n");
return PERMISSION_DENIED;
}
} }
/** /**

View File

@@ -3,56 +3,125 @@ package android.graphics;
public class Paint { public class Paint {
private int color = 0xFF000000; private int color = 0xFF000000;
public void setColor(int color) { public void setColor(int color) {
this.color = color; this.color = color;
} }
public int getColor() { public int getColor() {
return color; return color;
} }
public void setAntiAlias(boolean aa) {} public void setAntiAlias(boolean aa) {}
public void setStrokeWidth(float width) {} public void setStrokeWidth(float width) {}
public void setTextSize(float textSize) {} public void setTextSize(float textSize) {}
public Typeface setTypeface(Typeface typeface) { public Typeface setTypeface(Typeface typeface) {
return null; return new Typeface();
} }
public void getTextBounds(String text, int start, int end, Rect bounds) {} public void getTextBounds(String text, int start, int end, Rect bounds) {}
public void getTextBounds(char[] text, int index, int count, Rect bounds) {} public void getTextBounds(char[] text, int index, int count, Rect bounds) {}
public void setFlags(int flags) {} public void setFlags(int flags) {}
public void setFilterBitmap(boolean filter) {} public void setFilterBitmap(boolean filter) {}
public void setStyle(Style style) {} public void setStyle(Style style) {}
public float ascent() { return 0; } public float ascent() { return 0; }
public float measureText(char[] text, int index, int count) { return 10; } public float measureText(char[] text, int index, int count) { return 10; }
public float measureText(String text, int start, int end) { return 10; } public float measureText(String text, int start, int end) { return 10; }
public float measureText(String text) { return 10; } public float measureText(String text) { return 10; }
public float measureText(CharSequence text, int start, int end) { return 10; } public float measureText(CharSequence text, int start, int end) { return 10; }
public enum Style { public enum Style {
/** /**
* Geometry and text drawn with this style will be filled, ignoring all * Geometry and text drawn with this style will be filled, ignoring all
* stroke-related settings in the paint. * stroke-related settings in the paint.
*/ */
FILL (0), FILL (0),
/** /**
* Geometry and text drawn with this style will be stroked, respecting * Geometry and text drawn with this style will be stroked, respecting
* the stroke-related fields on the paint. * the stroke-related fields on the paint.
*/ */
STROKE (1), STROKE (1),
/** /**
* Geometry and text drawn with this style will be both filled and * Geometry and text drawn with this style will be both filled and
* stroked at the same time, respecting the stroke-related fields on * stroked at the same time, respecting the stroke-related fields on
* the paint. This mode can give unexpected results if the geometry * the paint. This mode can give unexpected results if the geometry
* is oriented counter-clockwise. This restriction does not apply to * is oriented counter-clockwise. This restriction does not apply to
* either FILL or STROKE. * either FILL or STROKE.
*/ */
FILL_AND_STROKE (2); FILL_AND_STROKE (2);
Style(int nativeInt) {
this.nativeInt = nativeInt;
}
final int nativeInt;
}
public static class FontMetrics {
/**
* The maximum distance above the baseline for the tallest glyph in
* the font at a given text size.
*/
public float top;
/**
* The recommended distance above the baseline for singled spaced text.
*/
public float ascent;
/**
* The recommended distance below the baseline for singled spaced text.
*/
public float descent;
/**
* The maximum distance below the baseline for the lowest glyph in
* the font at a given text size.
*/
public float bottom;
/**
* The recommended additional space to add between lines of text.
*/
public float leading;
}
public static class FontMetricsInt {
public int top;
public int ascent;
public int descent;
public int bottom;
public int leading;
@Override public String toString() {
return "FontMetricsInt: top=" + top + " ascent=" + ascent +
" descent=" + descent + " bottom=" + bottom +
" leading=" + leading;
}
}
public /*native*/ int getFlags() {return 0;}
public /*native*/ int getHinting() {return 0;}
public /*native*/ void setHinting(int mode) {}
public /*native*/ void setDither(boolean dither) {}
public /*native*/ void setLinearText(boolean linearText) {}
public /*native*/ void setSubpixelText(boolean subpixelText) {}
public /*native*/ void setUnderlineText(boolean underlineText) {}
public /*native*/ void setStrikeThruText(boolean strikeThruText) {}
public /*native*/ void setFakeBoldText(boolean fakeBoldText) {}
public /*native*/ int getAlpha() {return 0;}
public /*native*/ void setAlpha(int a) {}
public /*native*/ float getStrokeWidth() {return 0;}
public /*native*/ float getStrokeMiter() {return 0;}
public /*native*/ void setStrokeMiter(float miter) {}
public /*native*/ float getTextSize() {return 0;}
public /*native*/ float getTextScaleX() {return 0;}
public /*native*/ void setTextScaleX(float scaleX) {}
public /*native*/ float getTextSkewX() {return 0;}
public /*native*/ void setTextSkewX(float skewX) {}
public /*native*/ float descent() {return 0;}
public /*native*/ float getFontMetrics(FontMetrics metrics) {return 0;}
public /*native*/ int getFontMetricsInt(FontMetricsInt fmi) {return 0;}
Style(int nativeInt) {
this.nativeInt = nativeInt;
}
final int nativeInt;
}
} }

View File

@@ -4,8 +4,28 @@ import android.content.res.AssetManager;
public class Typeface { public class Typeface {
/** The default NORMAL typeface object */
public static final Typeface DEFAULT = new Typeface();
/**
* The default BOLD typeface object. Note: this may be not actually be
* bold, depending on what fonts are installed. Call getStyle() to know
* for sure.
*/
public static final Typeface DEFAULT_BOLD = new Typeface();
/** The NORMAL style of the default sans serif typeface. */
public static final Typeface SANS_SERIF = new Typeface();
/** The NORMAL style of the default serif typeface. */
public static final Typeface SERIF = new Typeface();
/** The NORMAL style of the default monospace typeface. */
public static final Typeface MONOSPACE = new Typeface();
// Style
public static final int NORMAL = 0;
public static final int BOLD = 1;
public static final int ITALIC = 2;
public static final int BOLD_ITALIC = 3;
public static Typeface createFromAsset(AssetManager mgr, String path) { public static Typeface createFromAsset(AssetManager mgr, String path) {
return null; return null;
} }
} }

View File

@@ -1,5 +1,15 @@
package android.hardware.display; package android.hardware.display;
import android.os.Handler;
import android.view.Display;
public final class DisplayManager { public final class DisplayManager {
public static interface DisplayListener {} public static interface DisplayListener {}
public Display getDisplay(int dummy) {
return new Display();
}
public void registerDisplayListener(DisplayListener listener, Handler handler) {
}
} }

View File

@@ -1,6 +1,27 @@
package android.media; package android.media;
public class AudioManager { public class AudioManager {
public static final String PROPERTY_OUTPUT_FRAMES_PER_BUFFER = "android.media.property.OUTPUT_FRAMES_PER_BUFFER";
public static final String PROPERTY_OUTPUT_SAMPLE_RATE = "android.media.property.OUTPUT_SAMPLE_RATE";
public static final int STREAM_MUSIC = 0x3;
public boolean isBluetoothA2dpOn() {
return false;
}
public String getProperty(String name) {
switch(name) {
case PROPERTY_OUTPUT_FRAMES_PER_BUFFER:
return "256"; // FIXME arbitrary
case PROPERTY_OUTPUT_SAMPLE_RATE:
return "44100"; // FIXME arbitrary
default:
System.out.println("AudioManager.getProperty: >"+name+"< not handled");
return "";
}
}
public interface OnAudioFocusChangeListener { public interface OnAudioFocusChangeListener {
} }

View File

@@ -622,8 +622,8 @@ public class Environment {
* {@link #MEDIA_BAD_REMOVAL}, or {@link #MEDIA_UNMOUNTABLE}. * {@link #MEDIA_BAD_REMOVAL}, or {@link #MEDIA_UNMOUNTABLE}.
*/ */
public static String getExternalStorageState() { public static String getExternalStorageState() {
final File externalDir = sCurrentUser.getExternalDirsForApp()[0]; // we don't do stupid stuff like having this on a separate partition, so it should always be "mounted"
return getStorageState(externalDir); return MEDIA_MOUNTED;
} }
/** /**

View File

@@ -505,8 +505,10 @@ public class Process {
* not have permission to modify the given thread, or to use the given * not have permission to modify the given thread, or to use the given
* priority. * priority.
*/ */
public static final native void setThreadPriority(int tid, int priority) public static final /*native*/ void setThreadPriority(int tid, int priority)
throws IllegalArgumentException, SecurityException; throws IllegalArgumentException, SecurityException {
// TODO - this is clearly not critical
}
/** /**
* Call with 'false' to cause future calls to {@link #setThreadPriority(int)} to * Call with 'false' to cause future calls to {@link #setThreadPriority(int)} to

View File

@@ -41,6 +41,8 @@ public class Settings {
switch(key) { switch(key) {
case "accelerometer_rotation": case "accelerometer_rotation":
return 0; // degrees? no clue return 0; // degrees? no clue
case "always_finish_activities":
return 0; // we certainly don't aggressively kill activities :P
default: default:
java.lang.System.out.println("!!!! Settings$System.getInt: unknown key: >"+key+"<"); java.lang.System.out.println("!!!! Settings$System.getInt: unknown key: >"+key+"<");
return 0; // TODO: should be -1 probably? return 0; // TODO: should be -1 probably?

View File

@@ -0,0 +1,7 @@
package android.support.v7.app;
import android.app.Activity;
public class AppCompatActivity extends Activity {
}

View File

@@ -14,6 +14,14 @@ public final class Display {
outMetrics.heightPixels = this.window_height; outMetrics.heightPixels = this.window_height;
} }
public int getWidth() {
return window_width;
}
public int getHeight() {
return window_height;
}
public int getRotation() { public int getRotation() {
return 0/*ROTATION_0*/; return 0/*ROTATION_0*/;
} }
@@ -21,4 +29,16 @@ public final class Display {
public float getRefreshRate() { public float getRefreshRate() {
return 60; // FIXME return 60; // FIXME
} }
public long getAppVsyncOffsetNanos() {
return 0; // what else would we return here?
}
public int getDisplayId() {
return 0;
}
public long getPresentationDeadlineNanos() {
return 0; // what else...
}
} }

View File

@@ -4,5 +4,6 @@ public interface WindowManager {
public android.view.Display getDefaultDisplay(); public android.view.Display getDefaultDisplay();
public class LayoutParams { public class LayoutParams {
public static final int FLAG_KEEP_SCREEN_ON = 0;
} }
} }

View File

@@ -131,6 +131,7 @@ hax_jar = jar('hax', [
'android/R.java', 'android/R.java',
'android/support/multidex/MultiDexApplication.java', 'android/support/multidex/MultiDexApplication.java',
'android/support/v4/app/FragmentActivity.java', 'android/support/v4/app/FragmentActivity.java',
'android/support/v7/app/AppCompatActivity.java',
'android/telephony/PhoneStateListener.java', 'android/telephony/PhoneStateListener.java',
'android/telephony/TelephonyManager.java', 'android/telephony/TelephonyManager.java',
'android/text/ClipboardManager.java', 'android/text/ClipboardManager.java',