Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config parser: add support for Android 15+ stubs #204

Merged
merged 5 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config-holder/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ android {
buildToolsVersion = "35.0.0"

defaultConfig {
minSdk = 35
minSdk = 32
targetSdk = 35
versionCode = 142
versionName = versionCode.toString()
Expand Down
18 changes: 9 additions & 9 deletions gmscompat_config
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,21 @@ getName nullString
getAddress String 02:00:00:00:00:00
listenUsingInsecureL2capChannel throw java.io.IOException
getProfileProxy false
registerBluetoothConnectionCallback void
unregisterBluetoothConnectionCallback void
registerBluetoothConnectionCallback default
unregisterBluetoothConnectionCallback default

[android.bluetooth.BluetoothDevice]
getIdentityAddress nullString
getMetadata nullArray
setMetadata false
setPairingConfirmation false
setSilenceMode false
getIdentityAddress default
getMetadata default
setMetadata default
setPairingConfirmation default
setSilenceMode default

[android.bluetooth.BluetoothManager]
openGattServer void
openGattServer default

[android.bluetooth.le.BluetoothLeAdvertiser]
startAdvertisingSet void
startAdvertisingSet default

[android.content.ContentResolver]
registerContentObserver void
Expand Down
94 changes: 3 additions & 91 deletions src/app/grapheneos/gmscompat/GmsCompatConfigParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
public class GmsCompatConfigParser {
private static final String TAG = "GmsCompatConfigParser";

private final boolean strict = false;
private final boolean strict = Build.isDebuggable() && Build.VERSION.SDK_INT >= 33;
private boolean invalid;

private GmsCompatConfigParser() {}
Expand Down Expand Up @@ -158,6 +158,7 @@ private void parse(ArrayList<String> lines, GmsCompatConfig res) {
section2Type = SECTION_FLAGS;
break;
case "stubs":
case "stubs_15+":
section2Type = SECTION_STUBS;
break;
case "versionMap":
Expand Down Expand Up @@ -590,98 +591,9 @@ static void checkStubDef(String className, String methodName, @Nullable StubDef

String signature = className + '#' + methodName;

if (methods.size() == 0) {
if (methods.isEmpty()) {
throw new InvalidObjectException(signature + " not found");
}

Class returnType = methods.get(0).getReturnType();

if (methods.size() > 1) {
for (Method m : methods) {
if (m.getReturnType() != returnType) {
throw new InvalidObjectException("overloads of method " + signature
+ " have different return types");
}
}
}

switch (stubDef.type) {
case StubDef.VOID:
stubCheck(signature, returnType == Void.TYPE);
break;
case StubDef.NULL:
// only for types that implement Parcelable
stubCheck(signature, Parcelable.class.isAssignableFrom(returnType));
break;
case StubDef.NULL_STRING:
case StubDef.EMPTY_STRING:
case StubDef.STRING:
stubCheck(signature, returnType == String.class);
break;
case StubDef.NULL_ARRAY:
stubCheck(signature, returnType.isArray()
&& (
Parcelable.class.isAssignableFrom(returnType.getComponentType())
|| returnType.getComponentType() == String.class
|| returnType.getComponentType().isPrimitive()
)
);
break;
case StubDef.EMPTY_BYTE_ARRAY:
stubCheck(signature, returnType == byte[].class);
break;
case StubDef.EMPTY_INT_ARRAY:
stubCheck(signature, returnType == int[].class);
break;
case StubDef.EMPTY_LONG_ARRAY:
stubCheck(signature, returnType == long[].class);
break;
case StubDef.EMPTY_LIST:
stubCheck(signature, returnType == List.class);
break;
case StubDef.EMPTY_MAP:
stubCheck(signature, returnType == Map.class);
break;
case StubDef.BOOLEAN:
stubCheck(signature, returnType == boolean.class);
break;
case StubDef.BYTE:
stubCheck(signature, returnType == byte.class);
break;
case StubDef.INT:
stubCheck(signature, returnType == int.class);
break;
case StubDef.LONG:
stubCheck(signature, returnType == long.class);
break;
case StubDef.FLOAT:
stubCheck(signature, returnType == float.class);
break;
case StubDef.DOUBLE:
stubCheck(signature, returnType == double.class);
break;
case StubDef.THROW: {
Class c = Class.forName(stubDef.stringVal);
stubCheck(signature,
Throwable.class.isAssignableFrom(c)
&&
Modifier.isPublic(c.getConstructor().getModifiers())
);
break;
}
case StubDef.DEFAULT:
// unknown return type
break;
default:
stubCheck(signature, false);
break;
}
}

private static void stubCheck(String sig, boolean v) throws InvalidObjectException {
if (!v) {
throw new InvalidObjectException("invalid stub for " + sig);
}
}

private void checkRegex(String regex) {
Expand Down