api-impl: add stubs / simple stuff for OsmAnd

without native libs present, launches and renders white square
in map view; with native libs present, segfaults in bundled skia
This commit is contained in:
Mis012
2024-04-12 18:32:30 +02:00
parent fefd2f108b
commit 2802aaa28d
42 changed files with 2171 additions and 77 deletions

View File

@@ -217,10 +217,10 @@ JNIEXPORT void JNICALL Java_android_widget_ProgressBar_native_1setProgress
/*
* Class: android_widget_ProgressBar
* Method: setIndeterminate
* Method: native_setIndeterminate
* Signature: (Z)V
*/
JNIEXPORT void JNICALL Java_android_widget_ProgressBar_setIndeterminate
JNIEXPORT void JNICALL Java_android_widget_ProgressBar_native_1setIndeterminate
(JNIEnv *, jobject, jboolean);
#ifdef __cplusplus

View File

@@ -29,7 +29,7 @@ JNIEXPORT void JNICALL Java_android_widget_ProgressBar_native_1setProgress(JNIEn
gtk_progress_bar_set_fraction(progress_bar, progress);
}
JNIEXPORT void JNICALL Java_android_widget_ProgressBar_setIndeterminate(JNIEnv *env, jobject this, jboolean indeterminate)
JNIEXPORT void JNICALL Java_android_widget_ProgressBar_native_1setIndeterminate(JNIEnv *env, jobject this, jboolean indeterminate)
{
GtkWidget *box = GTK_WIDGET(_PTR(_GET_LONG_FIELD(this, "widget")));
GtkProgressBar *progress_bar = GTK_PROGRESS_BAR(gtk_widget_get_first_child(box));

View File

@@ -1,5 +1,6 @@
package android.animation;
import android.graphics.Path;
import android.util.Property;
public class ObjectAnimator extends ValueAnimator {
@@ -8,7 +9,11 @@ public class ObjectAnimator extends ValueAnimator {
return null;
}
public static ObjectAnimator ofFloat(Object target, String propertyName, float... values) {
public static ObjectAnimator ofFloat(Object target, String xPropertyName, String yPropertyName, Path path) {
return new ObjectAnimator();
}
public static <T> ObjectAnimator ofFloat(T target, Property<T, Float> xProperty, Property<T, Float> yProperty, Path path) {
return new ObjectAnimator();
}
@@ -16,6 +21,10 @@ public class ObjectAnimator extends ValueAnimator {
return new ObjectAnimator();
}
public static ObjectAnimator ofFloat(Object target, String propertyName, float... values) {
return new ObjectAnimator();
}
public static <T> ObjectAnimator ofInt(T target, String propertyName, int... values) {
return new ObjectAnimator();
}

View File

@@ -6,6 +6,7 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.XmlResourceParser;
import android.net.Uri;
@@ -451,6 +452,20 @@ public class Activity extends ContextWrapper implements Window.Callback {
}
}
public String getLocalClassName() {
final String pkg = getPackageName();
final String cls = this.getClass().getName();
int packageLen = pkg.length();
if (!cls.startsWith(pkg) || cls.length() <= packageLen || cls.charAt(packageLen) != '.') {
return cls;
}
return cls.substring(packageLen+1);
}
public SharedPreferences getPreferences(int mode) {
return getSharedPreferences(getLocalClassName(), mode);
}
private native void nativeFinish(long native_window);
public static native void nativeRecreateActivity(Activity activity);
public static native void nativeStartActivity(Activity activity);

View File

@@ -9,6 +9,7 @@ import com.reandroid.arsc.chunk.xml.AndroidManifestBlock;
import java.io.InputStream;
import java.io.IOException;
import android.content.Context;
import android.content.ContextWrapper;
public class Application extends ContextWrapper {
@@ -44,13 +45,13 @@ public class Application extends ContextWrapper {
}
public Application() {
super(null);
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 = this.getResources().getString(app_icon_resid);
app_icon_path = r.getString(app_icon_resid);
} catch (IOException e) {
e.printStackTrace();
}

View File

@@ -0,0 +1,5 @@
package android.bluetooth.le;
public abstract class ScanCallback {
}

View File

@@ -15,6 +15,8 @@ import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.database.DatabaseErrorHandler;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.drawable.Drawable;
import android.hardware.input.InputManager;
import android.hardware.SensorManager;
@@ -71,7 +73,7 @@ public class Context extends Object {
static AssetManager assets;
static DisplayMetrics dm;
static Resources r;
protected static Resources r;
static ApplicationInfo application_info;
static Resources.Theme theme;
private static Map<Class<? extends Service>,Service> runningServices = new HashMap<>();
@@ -85,6 +87,7 @@ public class Context extends Object {
File files_dir = null;
File obb_dir = null;
File cache_dir = null;
File nobackup_dir = null;
private static Map<IntentFilter, BroadcastReceiver> receiverMap = new HashMap<IntentFilter, BroadcastReceiver>();
@@ -231,6 +234,10 @@ public class Context extends Object {
return apk_path;
}
public int getColor(int resId) {
return r.getColor(resId);
}
public final String getString(int resId) {
return r.getString(resId);
}
@@ -324,6 +331,23 @@ public class Context extends Object {
return getCacheDir();
}
public File getNoBackupFilesDir() {
if (nobackup_dir == null) {
nobackup_dir = new File(getDataDirFile(), "no_backup/" + getPackageName());
}
if (!nobackup_dir.exists()) {
if (!nobackup_dir.mkdirs()) {
if (nobackup_dir.exists()) {
// spurious failure; probably racing with another process for this app
return nobackup_dir;
}
Slog.w(TAG, "Unable to create obb directory >" + nobackup_dir.getPath() + "<");
return null;
}
}
return nobackup_dir;
}
private File getPreferencesDir() {
if (prefs_dir == null) {
prefs_dir = new File(getDataDirFile(), "shared_prefs");
@@ -331,6 +355,10 @@ public class Context extends Object {
return prefs_dir;
}
public File getFileStreamPath(String name) {
return makeFilename(getFilesDir(), name);
}
public File getSharedPrefsFile(String name) {
return makeFilename(getPreferencesDir(), name + ".xml");
}
@@ -503,4 +531,21 @@ public class Context extends Object {
public void grantUriPermission(String dummy, Uri dummy2, int dummy3) {
System.out.println("grantUriPermission(" + dummy + ", " + dummy2 + ", " + dummy3 + ") called");
}
public SQLiteDatabase openOrCreateDatabase(String name, int mode, SQLiteDatabase.CursorFactory factory) {
return openOrCreateDatabase(name, mode, factory, null);
}
public SQLiteDatabase openOrCreateDatabase(String filename, int mode, SQLiteDatabase.CursorFactory factory, DatabaseErrorHandler errorHandler) {
int flags = SQLiteDatabase.CREATE_IF_NECESSARY;
if ((mode & (1 <<3) /*MODE_ENABLE_WRITE_AHEAD_LOGGING*/) != 0) {
flags |= SQLiteDatabase.ENABLE_WRITE_AHEAD_LOGGING;
}
SQLiteDatabase db = SQLiteDatabase.openDatabase(filename, factory, flags, errorHandler);
return db;
}
public Context createConfigurationContext(Configuration configuration) {
return this;
}
}

View File

@@ -178,23 +178,33 @@ public class Intent {
return this;
}
public Intent putExtras (Intent src) {
public Intent putExtras(Intent src) {
// FIXME HACK
this.extras = src.getExtras();
return this;
}
public Intent putExtras (Bundle extras) {
public Intent putExtras(Bundle extras) {
// FIXME HACK
this.extras = extras;
return this;
}
public Intent replaceExtras(Bundle extras) {
this.extras = extras;
return this;
}
public Intent setClass(Context packageContext, Class<?> cls) {
setComponent(new ComponentName(packageContext, cls));
return this;
}
public Intent setClassName(String packageName, String className) {
setComponent(new ComponentName(packageName, className));
return this;
}
public String getStringExtra(String name) {
return (String)extras.get(name);
}

View File

@@ -851,23 +851,28 @@ public class Resources {
* solid color or multiple colors that can be selected based on a state.
*/
public ColorStateList getColorStateList(int id) throws NotFoundException {
TypedValue value;
synchronized (mAccessLock) {
value = mTmpValue;
if (value == null) {
value = new TypedValue();
} else {
mTmpValue = null;
}
getValue(id, value, true);
}
ColorStateList res = loadColorStateList(value, id);
synchronized (mAccessLock) {
if (mTmpValue == null) {
mTmpValue = value;
}
}
return res;
return getColorStateList(id, null);
}
/* FIXME use the theme */
public ColorStateList getColorStateList(int id, Theme theme) throws NotFoundException {
TypedValue value;
synchronized (mAccessLock) {
value = mTmpValue;
if (value == null) {
value = new TypedValue();
} else {
mTmpValue = null;
}
getValue(id, value, true);
}
ColorStateList res = loadColorStateList(value, id);
synchronized (mAccessLock) {
if (mTmpValue == null) {
mTmpValue = value;
}
}
return res;
}
/**

View File

@@ -257,6 +257,9 @@ public class Canvas {
if (dst == null) {
throw new NullPointerException();
}
if(src == null) {
src = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
}
native_drawBitmap(skia_canvas, widget, bitmap.pixbuf, src.left, src.top, src.right, src.bottom,
dst.left, dst.top, dst.right, dst.bottom,
(paint != null) ? paint.skia_paint : 0);
@@ -416,6 +419,16 @@ public class Canvas {
return false;
}
public int getWidth() {
return 10; //FIXME
}
public int getHeight() {
return 10; //FIXME
}
public void drawColor(int dummy) {}
private static native long native_canvas_from_bitmap(long pixbuf);
private static native void native_save(long skia_canvas, long widget);

View File

@@ -37,6 +37,10 @@ public class Color {
return (alpha << 24) | (red << 16) | (green << 8) | (blue << 0);
}
public static int rgb(int red, int green, int blue) {
return argb(0xff, red, green, blue);
}
/**
* Return the alpha component of a color int. This is the same as saying
* color >>> 24

View File

@@ -0,0 +1,256 @@
/*
* Copyright (C) 2007 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.graphics;
import android.util.FloatMath;
/**
* 5x4 matrix for transforming the color+alpha components of a Bitmap.
* The matrix is stored in a single array, and its treated as follows:
* [ a, b, c, d, e,
* f, g, h, i, j,
* k, l, m, n, o,
* p, q, r, s, t ]
*
* When applied to a color [r, g, b, a], the resulting color is computed as
* (after clamping)
* R' = a*R + b*G + c*B + d*A + e;
* G' = f*R + g*G + h*B + i*A + j;
* B' = k*R + l*G + m*B + n*A + o;
* A' = p*R + q*G + r*B + s*A + t;
*/
public class ColorMatrix {
private final float[] mArray = new float[20];
/**
* Create a new colormatrix initialized to identity (as if reset() had
* been called).
*/
public ColorMatrix() {
reset();
}
/**
* Create a new colormatrix initialized with the specified array of values.
*/
public ColorMatrix(float[] src) {
System.arraycopy(src, 0, mArray, 0, 20);
}
/**
* Create a new colormatrix initialized with the specified colormatrix.
*/
public ColorMatrix(ColorMatrix src) {
System.arraycopy(src.mArray, 0, mArray, 0, 20);
}
/**
* Return the array of floats representing this colormatrix.
*/
public final float[] getArray() { return mArray; }
/**
* Set this colormatrix to identity:
* [ 1 0 0 0 0 - red vector
* 0 1 0 0 0 - green vector
* 0 0 1 0 0 - blue vector
* 0 0 0 1 0 ] - alpha vector
*/
public void reset() {
final float[] a = mArray;
for (int i = 19; i > 0; --i) {
a[i] = 0;
}
a[0] = a[6] = a[12] = a[18] = 1;
}
/**
* Assign the src colormatrix into this matrix, copying all of its values.
*/
public void set(ColorMatrix src) {
System.arraycopy(src.mArray, 0, mArray, 0, 20);
}
/**
* Assign the array of floats into this matrix, copying all of its values.
*/
public void set(float[] src) {
System.arraycopy(src, 0, mArray, 0, 20);
}
/**
* Set this colormatrix to scale by the specified values.
*/
public void setScale(float rScale, float gScale, float bScale,
float aScale) {
final float[] a = mArray;
for (int i = 19; i > 0; --i) {
a[i] = 0;
}
a[0] = rScale;
a[6] = gScale;
a[12] = bScale;
a[18] = aScale;
}
/**
* Set the rotation on a color axis by the specified values.
* axis=0 correspond to a rotation around the RED color
* axis=1 correspond to a rotation around the GREEN color
* axis=2 correspond to a rotation around the BLUE color
*/
public void setRotate(int axis, float degrees) {
reset();
float radians = degrees * (float)Math.PI / 180;
float cosine = FloatMath.cos(radians);
float sine = FloatMath.sin(radians);
switch (axis) {
// Rotation around the red color
case 0:
mArray[6] = mArray[12] = cosine;
mArray[7] = sine;
mArray[11] = -sine;
break;
// Rotation around the green color
case 1:
mArray[0] = mArray[12] = cosine;
mArray[2] = -sine;
mArray[10] = sine;
break;
// Rotation around the blue color
case 2:
mArray[0] = mArray[6] = cosine;
mArray[1] = sine;
mArray[5] = -sine;
break;
default:
throw new RuntimeException();
}
}
/**
* Set this colormatrix to the concatenation of the two specified
* colormatrices, such that the resulting colormatrix has the same effect
* as applying matB and then applying matA. It is legal for either matA or
* matB to be the same colormatrix as this.
*/
public void setConcat(ColorMatrix matA, ColorMatrix matB) {
float[] tmp = null;
if (matA == this || matB == this) {
tmp = new float[20];
} else {
tmp = mArray;
}
final float[] a = matA.mArray;
final float[] b = matB.mArray;
int index = 0;
for (int j = 0; j < 20; j += 5) {
for (int i = 0; i < 4; i++) {
tmp[index++] = a[j + 0] * b[i + 0] + a[j + 1] * b[i + 5] +
a[j + 2] * b[i + 10] + a[j + 3] * b[i + 15];
}
tmp[index++] = a[j + 0] * b[4] + a[j + 1] * b[9] +
a[j + 2] * b[14] + a[j + 3] * b[19] +
a[j + 4];
}
if (tmp != mArray) {
System.arraycopy(tmp, 0, mArray, 0, 20);
}
}
/**
* Concat this colormatrix with the specified prematrix. This is logically
* the same as calling setConcat(this, prematrix);
*/
public void preConcat(ColorMatrix prematrix) {
setConcat(this, prematrix);
}
/**
* Concat this colormatrix with the specified postmatrix. This is logically
* the same as calling setConcat(postmatrix, this);
*/
public void postConcat(ColorMatrix postmatrix) {
setConcat(postmatrix, this);
}
///////////////////////////////////////////////////////////////////////////
/**
* Set the matrix to affect the saturation of colors. A value of 0 maps the
* color to gray-scale. 1 is identity.
*/
public void setSaturation(float sat) {
reset();
float[] m = mArray;
final float invSat = 1 - sat;
final float R = 0.213f * invSat;
final float G = 0.715f * invSat;
final float B = 0.072f * invSat;
m[0] = R + sat;
m[1] = G;
m[2] = B;
m[5] = R;
m[6] = G + sat;
m[7] = B;
m[10] = R;
m[11] = G;
m[12] = B + sat;
}
/**
* Set the matrix to convert RGB to YUV
*/
public void setRGB2YUV() {
reset();
float[] m = mArray;
// these coefficients match those in libjpeg
m[0] = 0.299f;
m[1] = 0.587f;
m[2] = 0.114f;
m[5] = -0.16874f;
m[6] = -0.33126f;
m[7] = 0.5f;
m[10] = 0.5f;
m[11] = -0.41869f;
m[12] = -0.08131f;
}
/**
* Set the matrix to convert from YUV to RGB
*/
public void setYUV2RGB() {
reset();
float[] m = mArray;
// these coefficients match those in libjpeg
m[2] = 1.402f;
m[5] = 1;
m[6] = -0.34414f;
m[7] = -0.71414f;
m[10] = 1;
m[11] = 1.772f;
m[12] = 0;
}
}

View File

@@ -0,0 +1,11 @@
package android.graphics;
public class ColorMatrixColorFilter extends ColorFilter {
public ColorMatrixColorFilter(ColorMatrix matrix) {
super();
}
public ColorMatrixColorFilter(float[] array) {
super();
}
}

View File

@@ -0,0 +1,7 @@
package android.graphics;
public class CornerPathEffect extends PathEffect {
public CornerPathEffect(float radius) {
super();
}
}

View File

@@ -0,0 +1,6 @@
package android.graphics;
public class DashPathEffect extends PathEffect {
public DashPathEffect(float[] dummy, float dummy2) {
}
}

View File

@@ -256,6 +256,16 @@ public class Paint {
return new Shader();
}
public PathEffect setPathEffect(PathEffect effect) {
return effect;
}
public int breakText(char[] text, int index, int count, float maxWidth, float[] measuredWidth) { return 10; }
public int breakText(String text, boolean measureForwards, float maxWidth, float[] measuredWidth) { return 10; }
public int breakText(CharSequence text, int start, int end, boolean measureForwards, float maxWidth, float[] measuredWidth) { return 10; }
public void clearShadowLayer() {}
private native long native_constructor();
private native void native_set_antialias(long skia_paint, boolean aa);
private native void native_set_color(long skia_paint, int color);

View File

@@ -0,0 +1,5 @@
package android.graphics;
public class PathEffect {
}

View File

@@ -0,0 +1,6 @@
package android.graphics;
public class PathMeasure {
public PathMeasure(Path path, boolean dummy) {
}
}

View File

@@ -52,7 +52,7 @@ public class Drawable {
return null;
}
public abstract class ConstantState {
public static abstract class ConstantState {
public abstract Drawable newDrawable(Resources res);
@@ -88,6 +88,10 @@ public class Drawable {
this.callback = callback;
}
public Callback getCallback() {
return this.callback;
}
public void invalidateSelf() {
native_invalidate(paintable);
@@ -172,10 +176,16 @@ public class Drawable {
VectorDrawable drawable = new VectorDrawable();
drawable.inflate(resources, parser, parser, null);
return drawable;
} else if ("layer-list".equals(parser.getName())) {
return new LayerDrawable();
}
return null;
}
public static Drawable createFromXmlInner(Resources resources, XmlPullParser parser, AttributeSet attrs) {
return createFromXmlInner(resources, parser, attrs, null);
}
public static Drawable createFromXmlInner(Resources resources, XmlPullParser parser, AttributeSet attrs, Theme theme) {
return null;
}
@@ -211,6 +221,13 @@ public class Drawable {
bounds.set(mBounds);
}
public int getMinimumWidth() {
return 10; // FIXME
}
public int getMinimumHeight() {
return 10; // FIXME
}
protected void onBoundsChange(Rect bounds) {}
protected static native long native_paintable_from_path(String path);

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More