api-impl: misc stubs and fixes for Spotify

This commit is contained in:
Daniel Panero 2024-11-01 14:21:15 +01:00 committed by Mis012
parent 6dfd0d1d4b
commit e541d87fc2
14 changed files with 229 additions and 95 deletions

View file

@ -97,6 +97,7 @@ public class Activity extends ContextThemeWrapper implements Window.Callback {
break;
}
}
app_label = r.getText(pkg.applicationInfo.labelRes);
if (label != null) {
setTitle(label);
@ -568,4 +569,6 @@ public class Activity extends ContextThemeWrapper implements Window.Callback {
public static native void nativeOpenURI(String uri);
public native void nativeFileChooser(int action, String type, String title, int requestCode);
public void reportFullyDrawn() {}
public void setVisible(boolean visible) {}
public Uri getReferrer() { return null; }
}

View file

@ -2,7 +2,11 @@ package android.app;
import android.content.pm.ConfigurationInfo;
import android.graphics.Bitmap;
import android.os.IBinder;
import android.os.Parcel;
import android.os.Parcelable;
import java.util.ArrayList;
import java.util.List;
public class ActivityManager {
@ -46,4 +50,32 @@ public class ActivityManager {
public static void getMyMemoryState(RunningAppProcessInfo outInfo) {}
public boolean clearApplicationUserData() {return false;}
public static class AppTask {}
public List<ActivityManager.AppTask> getAppTasks() {
return new ArrayList<>();
}
public static class RunningServiceInfo implements Parcelable {
public RunningServiceInfo() {
}
public int describeContents() {
return 0;
}
public void writeToParcel(Parcel dest, int flags) {
return;
}
public void readFromParcel(Parcel source) {
return;
}
}
public List<RunningServiceInfo> getRunningServices(int maxNum)
throws SecurityException {
return new ArrayList<>();
}
}

View file

@ -1,4 +1,7 @@
package android.bluetooth;
public class BluetoothManager {
public BluetoothAdapter getAdapter(){
return new BluetoothAdapter();
}
}

View file

@ -10,6 +10,7 @@ import android.app.NotificationManager;
import android.app.Service;
import android.app.SharedPreferencesImpl;
import android.app.UiModeManager;
import android.bluetooth.BluetoothManager;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageParser;
@ -104,7 +105,13 @@ public class Context extends Object {
application_info = new ApplicationInfo();
try (XmlResourceParser parser = assets.openXmlResourceParser("AndroidManifest.xml")) {
PackageParser packageParser = new PackageParser(native_get_apk_path());
pkg = packageParser.parsePackage(r, parser, 0, new String[1]);
String[] parseError = new String[1];
pkg = packageParser.parsePackage(r, parser, 0, parseError);
if (parseError[0] != null) {
Slog.e(TAG, parseError[0]);
System.exit(1);
}
packageParser.collectCertificates(pkg, 0);
application_info = pkg.applicationInfo;
} catch (Exception e) {
@ -212,12 +219,18 @@ public class Context extends Object {
return new LayoutInflater(getApplicationContext());
case "wifi":
return new WifiManager();
case "bluetooth":
return new BluetoothManager();
default:
Slog.e(TAG, "!!!!!!! getSystemService: case >" + name + "< is not implemented yet");
return null;
}
}
public final <T> T getSystemService(Class<T> serviceClass) {
return null;
}
public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {
receiverMap.put(filter, receiver);
return new Intent();

View file

@ -342,4 +342,9 @@ public class Intent implements Parcelable {
return new ShortcutIconResource();
}
}
public void setExtrasClassLoader(ClassLoader loader) {}
public Intent setClassName(Context packageContext, String className) {
return this;
}
}

View file

@ -28,6 +28,11 @@ public class PackageInfo {
*/
public String packageName = "com.example.app"; // FIXME
/**
* The names of any installed split APKs for this package.
*/
public String[] splitNames;
/**
* The version number of this package, as specified by the &lt;manifest&gt;
* tag's {@link android.R.styleable#AndroidManifest_versionCode versionCode}

View file

@ -831,6 +831,11 @@ public class Resources {
return csl.getDefaultColor();
}
public int getColor(int id, Theme theme) throws NotFoundException {
// TODO fix it
return 0;
}
/**
* Return a color state list associated with a particular resource ID. The
* resource may contain either a single raw color value, or a complex
@ -1594,7 +1599,7 @@ public class Resources {
mConfiguration.smallestScreenWidthDp,
mConfiguration.screenWidthDp, mConfiguration.screenHeightDp,
mConfiguration.screenLayout, mConfiguration.uiMode,
24);
25);
if (DEBUG_CONFIG) {
Slog.i(TAG, "**** Updating config of " + this + ": final config is " + mConfiguration + " final compat is " + mCompatibilityInfo);
@ -2310,50 +2315,50 @@ public class Resources {
throw new RuntimeException(e);
}
/* if (id != 0) {
try {
// These may be compiled...
synchronized (mCachedXmlBlockIds) {
// First see if this block is in our cache.
final int num = mCachedXmlBlockIds.length;
for (int i=0; i<num; i++) {
if (mCachedXmlBlockIds[i] == id) {
//System.out.println("**** REUSING XML BLOCK! id="
// + id + ", index=" + i);
return mCachedXmlBlocks[i].newParser();
}
}
try {
// These may be compiled...
synchronized (mCachedXmlBlockIds) {
// First see if this block is in our cache.
final int num = mCachedXmlBlockIds.length;
for (int i=0; i<num; i++) {
if (mCachedXmlBlockIds[i] == id) {
//System.out.println("**** REUSING XML BLOCK! id="
// + id + ", index=" + i);
return mCachedXmlBlocks[i].newParser();
}
}
// Not in the cache, create a new block and put it at
// the next slot in the cache.
XmlBlock block = mAssets.openXmlBlockAsset(
assetCookie, file);
if (block != null) {
int pos = mLastCachedXmlBlockIndex+1;
if (pos >= num) pos = 0;
mLastCachedXmlBlockIndex = pos;
XmlBlock oldBlock = mCachedXmlBlocks[pos];
if (oldBlock != null) {
oldBlock.close();
}
mCachedXmlBlockIds[pos] = id;
mCachedXmlBlocks[pos] = block;
//System.out.println("**** CACHING NEW XML BLOCK! id="
// + id + ", index=" + pos);
return block.newParser();
}
}
} catch (Exception e) {
NotFoundException rnf = new NotFoundException(
"File " + file + " from xml type " + type + " resource ID #0x"
+ Integer.toHexString(id));
rnf.initCause(e);
throw rnf;
}
}
// Not in the cache, create a new block and put it at
// the next slot in the cache.
XmlBlock block = mAssets.openXmlBlockAsset(
assetCookie, file);
if (block != null) {
int pos = mLastCachedXmlBlockIndex+1;
if (pos >= num) pos = 0;
mLastCachedXmlBlockIndex = pos;
XmlBlock oldBlock = mCachedXmlBlocks[pos];
if (oldBlock != null) {
oldBlock.close();
}
mCachedXmlBlockIds[pos] = id;
mCachedXmlBlocks[pos] = block;
//System.out.println("**** CACHING NEW XML BLOCK! id="
// + id + ", index=" + pos);
return block.newParser();
}
}
} catch (Exception e) {
NotFoundException rnf = new NotFoundException(
"File " + file + " from xml type " + type + " resource ID #0x"
+ Integer.toHexString(id));
rnf.initCause(e);
throw rnf;
}
}
throw new NotFoundException(
"File " + file + " from xml type " + type + " resource ID #0x"
+ Integer.toHexString(id));
throw new NotFoundException(
"File " + file + " from xml type " + type + " resource ID #0x"
+ Integer.toHexString(id));
*/ }
private TypedArray getCachedStyledAttributes(int len) {

View file

@ -3,4 +3,6 @@ package android.graphics;
public class LinearGradient extends Shader {
public LinearGradient(float x0, float y0, float x1, float y1, int[] colors, float[] positions, TileMode mode) {}
public LinearGradient(float x0, float y0, float x1, float y1, long[] colors, float[] positions, TileMode tile) {}
public LinearGradient(float x0, float y0, float x1, float y1, int color0, int color1, TileMode tile) {}
}

View file

@ -68,6 +68,10 @@ public class Paint {
}
public void getTextBounds(String text, int start, int end, Rect bounds) {}
public void getTextBounds(char[] text, int index, int count, Rect bounds) {}
public int getTextWidths(String text, int start, int end, float[] widths) {
// TODO fix it
return 0;
}
public void setFilterBitmap(boolean filter) {}
public void setFlags(int flags) {

View file

@ -50,6 +50,10 @@ public class Typeface {
return typeface;
}
public static Typeface createFromFile(String path) {
return DEFAULT;
}
private static native long native_create(CharSequence family_name, int style);
public int getStyle() {

View file

@ -7,6 +7,7 @@ import android.util.Log;
public class BaseBundle {
protected static final String TAG = "Bundle";
static final boolean DEBUG = false;
// Invariant - exactly one of mMap / mParcelledData will be null
// (except inside a call to unparcel)
@ -198,6 +199,57 @@ public class BaseBundle {
return mMap.size();
}
/**
* Returns the value associated with the given key, or defaultValue if
* no mapping of the desired type exists for the given key.
*
* @param key a String
* @param defaultValue Value to return if key does not exist
* @return a boolean value
*/
public boolean getBoolean(String key, boolean defaultValue) {
Object o = mMap.get(key);
System.out.println("bundle.getBoolean(" + key + ", " + defaultValue + ") called");
/* the default for this is very scummy */
if(key.equals("com.facebook.sdk.AutoLogAppEventsEnabled")) {
return false;
}
if (o == null) {
return defaultValue;
}
try {
return (Boolean)o;
} catch (ClassCastException e) {
typeWarning(key, o, "Boolean", defaultValue, e);
return defaultValue;
}
}
/**
* Returns the value associated with the given key, or false if
* no mapping of the desired type exists for the given key.
*
* @param key a String
* @return a boolean value
*/
public boolean getBoolean(String key) {
if (DEBUG)
Log.d(TAG, "Getting boolean in " + Integer.toHexString(System.identityHashCode(this)));
return getBoolean(key, false);
}
/**
* Inserts a Boolean value into the mapping of this Bundle, replacing
* any existing value for the given key. Either key or value may be null.
*
* @param key a String, or null
* @param value a Boolean, or null
*/
public void putBoolean(String key, boolean value) {
mMap.put(key, value);
}
/**
* Returns the value associated with the given key, or defaultValue if
* no mapping of the desired type exists for the given key.

View file

@ -262,17 +262,6 @@ public final class Bundle extends BaseBundle implements Cloneable, Parcelable {
return false;
}
/**
* Inserts a Boolean value into the mapping of this Bundle, replacing
* any existing value for the given key. Either key or value may be null.
*
* @param key a String, or null
* @param value a Boolean, or null
*/
public void putBoolean(String key, boolean value) {
mMap.put(key, value);
}
/**
* Inserts a byte value into the mapping of this Bundle, replacing
* any existing value for the given key.
@ -587,45 +576,6 @@ public final class Bundle extends BaseBundle implements Cloneable, Parcelable {
mMap.put(key, value);
}
/**
* Returns the value associated with the given key, or false if
* no mapping of the desired type exists for the given key.
*
* @param key a String
* @return a boolean value
*/
public boolean getBoolean(String key) {
if (DEBUG)
Log.d(TAG, "Getting boolean in " + Integer.toHexString(System.identityHashCode(this)));
return getBoolean(key, false);
}
/**
* Returns the value associated with the given key, or defaultValue if
* no mapping of the desired type exists for the given key.
*
* @param key a String
* @param defaultValue Value to return if key does not exist
* @return a boolean value
*/
public boolean getBoolean(String key, boolean defaultValue) {
Object o = mMap.get(key);
System.out.println("bundle.getBoolean(" + key + ", " + defaultValue + ") called");
/* the default for this is very scummy */
if(key.equals("com.facebook.sdk.AutoLogAppEventsEnabled")) {
return false;
}
if (o == null) {
return defaultValue;
}
try {
return (Boolean)o;
} catch (ClassCastException e) {
typeWarning(key, o, "Boolean", defaultValue, e);
return defaultValue;
}
}
/**
* Returns the value associated with the given key, or (byte) 0 if
* no mapping of the desired type exists for the given key.

View file

@ -1,5 +1,7 @@
package android.os;
import java.util.concurrent.Executor;
public final class StrictMode {
public static void setThreadPolicy(final ThreadPolicy policy) {}
public static void setVmPolicy(final VmPolicy policy) {}
@ -9,9 +11,50 @@ public final class StrictMode {
public static ThreadPolicy allowThreadDiskReads() {
return new ThreadPolicy();
}
public static ThreadPolicy getThreadPolicy() {
return new ThreadPolicy();
}
public interface OnThreadViolationListener {
}
public static final class ThreadPolicy {
final int mask;
final OnThreadViolationListener listener;
final Executor callbackExecutor;
private ThreadPolicy(int mask, OnThreadViolationListener listener, Executor executor) {
this.mask = mask;
this.listener = listener;
this.callbackExecutor = executor;
}
private ThreadPolicy() {
this.mask = 0;
this.listener = new OnThreadViolationListener() {};
this.callbackExecutor = new Executor() {
@Override
public void execute(Runnable command) {}
};
}
public static final class Builder {
private int mask = 0;
private OnThreadViolationListener listener;
private Executor executor;
public Builder() {
mask = 0;
}
public Builder(ThreadPolicy policy) {
if(policy != null) {
mask = policy.mask;
listener = policy.listener;
executor = policy.callbackExecutor;
}
}
public Builder detectAll() {
return this;
}
@ -24,11 +67,14 @@ public final class StrictMode {
public Builder permitDiskWrites() {
return this;
}
public Builder detectResourceMismatches() {
return this;
}
public Builder penaltyLog() {
return this;
}
public ThreadPolicy build() {
return new ThreadPolicy();
return new ThreadPolicy(mask, listener, executor);
}
}
}

View file

@ -1,5 +1,7 @@
package android.text;
import org.xml.sax.XMLReader;
import android.graphics.drawable.Drawable;
public class Html {
@ -29,4 +31,12 @@ public class Html {
}
return out.toString();
}
public static interface TagHandler {
/**
* This method will be called whenn the HTML parser encounters
* a tag that it does not know how to interpret.
*/
public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader);
}
}