Adapt call() on ContentProvider for Android 11
This commit in AOSP framework_base added a parameter "attributionTag" to
the call() method:
12ac3f406f
%5E%21/#F17
As a consequence, the method did not exist, so scrcpy used the legacy
call() method (using the authority "unknown") as a fallback, which fails
for security reasons.
Fixes #1468 <https://github.com/Genymobile/scrcpy/issues/1468>
This commit is contained in:
parent
bd9f656933
commit
ae758f99d6
1 changed files with 23 additions and 9 deletions
|
@ -35,7 +35,7 @@ public class ContentProvider implements Closeable {
|
||||||
private final IBinder token;
|
private final IBinder token;
|
||||||
|
|
||||||
private Method callMethod;
|
private Method callMethod;
|
||||||
private boolean callMethodLegacy;
|
private int callMethodVersion;
|
||||||
|
|
||||||
ContentProvider(ActivityManager manager, Object provider, String name, IBinder token) {
|
ContentProvider(ActivityManager manager, Object provider, String name, IBinder token) {
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
|
@ -46,12 +46,20 @@ public class ContentProvider implements Closeable {
|
||||||
|
|
||||||
private Method getCallMethod() throws NoSuchMethodException {
|
private Method getCallMethod() throws NoSuchMethodException {
|
||||||
if (callMethod == null) {
|
if (callMethod == null) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
callMethod = provider.getClass()
|
||||||
|
.getMethod("call", String.class, String.class, String.class, String.class, String.class, Bundle.class);
|
||||||
|
callMethodVersion = 0;
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
// old versions
|
||||||
try {
|
try {
|
||||||
callMethod = provider.getClass().getMethod("call", String.class, String.class, String.class, String.class, Bundle.class);
|
callMethod = provider.getClass().getMethod("call", String.class, String.class, String.class, String.class, Bundle.class);
|
||||||
} catch (NoSuchMethodException e) {
|
callMethodVersion = 1;
|
||||||
// old version
|
} catch (NoSuchMethodException e2) {
|
||||||
callMethod = provider.getClass().getMethod("call", String.class, String.class, String.class, Bundle.class);
|
callMethod = provider.getClass().getMethod("call", String.class, String.class, String.class, Bundle.class);
|
||||||
callMethodLegacy = true;
|
callMethodVersion = 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return callMethod;
|
return callMethod;
|
||||||
|
@ -61,10 +69,16 @@ public class ContentProvider implements Closeable {
|
||||||
try {
|
try {
|
||||||
Method method = getCallMethod();
|
Method method = getCallMethod();
|
||||||
Object[] args;
|
Object[] args;
|
||||||
if (!callMethodLegacy) {
|
switch (callMethodVersion) {
|
||||||
|
case 0:
|
||||||
|
args = new Object[]{ServiceManager.PACKAGE_NAME, null, "settings", callMethod, arg, extras};
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
args = new Object[]{ServiceManager.PACKAGE_NAME, "settings", callMethod, arg, extras};
|
args = new Object[]{ServiceManager.PACKAGE_NAME, "settings", callMethod, arg, extras};
|
||||||
} else {
|
break;
|
||||||
|
default:
|
||||||
args = new Object[]{ServiceManager.PACKAGE_NAME, callMethod, arg, extras};
|
args = new Object[]{ServiceManager.PACKAGE_NAME, callMethod, arg, extras};
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return (Bundle) method.invoke(provider, args);
|
return (Bundle) method.invoke(provider, args);
|
||||||
} catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
|
} catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
|
||||||
|
|
Loading…
Reference in a new issue