Fix startActivity() for supporting API < 30
Call the older startActivityAsUser() instead of startActivityAsUserWithFeature() so that it also works on older Android versions. Fixes #4704 <https://github.com/Genymobile/scrcpy/issues/4704>
This commit is contained in:
parent
630adf829c
commit
abc64b46c4
@ -79,7 +79,7 @@ public final class AudioCapture {
|
|||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||||
intent.setComponent(new ComponentName(FakeContext.PACKAGE_NAME, "com.android.shell.HeapDumpActivity"));
|
intent.setComponent(new ComponentName(FakeContext.PACKAGE_NAME, "com.android.shell.HeapDumpActivity"));
|
||||||
ServiceManager.getActivityManager().startActivityAsUserWithFeature(intent);
|
ServiceManager.getActivityManager().startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void stopWorkaroundAndroid11() {
|
private static void stopWorkaroundAndroid11() {
|
||||||
|
@ -22,7 +22,7 @@ public final class ActivityManager {
|
|||||||
private Method getContentProviderExternalMethod;
|
private Method getContentProviderExternalMethod;
|
||||||
private boolean getContentProviderExternalMethodNewVersion = true;
|
private boolean getContentProviderExternalMethodNewVersion = true;
|
||||||
private Method removeContentProviderExternalMethod;
|
private Method removeContentProviderExternalMethod;
|
||||||
private Method startActivityAsUserWithFeatureMethod;
|
private Method startActivityAsUserMethod;
|
||||||
private Method forceStopPackageMethod;
|
private Method forceStopPackageMethod;
|
||||||
|
|
||||||
static ActivityManager create() {
|
static ActivityManager create() {
|
||||||
@ -107,26 +107,25 @@ public final class ActivityManager {
|
|||||||
return getContentProviderExternal("settings", new Binder());
|
return getContentProviderExternal("settings", new Binder());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Method getStartActivityAsUserWithFeatureMethod() throws NoSuchMethodException, ClassNotFoundException {
|
private Method getStartActivityAsUserMethod() throws NoSuchMethodException, ClassNotFoundException {
|
||||||
if (startActivityAsUserWithFeatureMethod == null) {
|
if (startActivityAsUserMethod == null) {
|
||||||
Class<?> iApplicationThreadClass = Class.forName("android.app.IApplicationThread");
|
Class<?> iApplicationThreadClass = Class.forName("android.app.IApplicationThread");
|
||||||
Class<?> profilerInfo = Class.forName("android.app.ProfilerInfo");
|
Class<?> profilerInfo = Class.forName("android.app.ProfilerInfo");
|
||||||
startActivityAsUserWithFeatureMethod = manager.getClass()
|
startActivityAsUserMethod = manager.getClass()
|
||||||
.getMethod("startActivityAsUserWithFeature", iApplicationThreadClass, String.class, String.class, Intent.class, String.class,
|
.getMethod("startActivityAsUser", iApplicationThreadClass, String.class, Intent.class, String.class, IBinder.class, String.class,
|
||||||
IBinder.class, String.class, int.class, int.class, profilerInfo, Bundle.class, int.class);
|
int.class, int.class, profilerInfo, Bundle.class, int.class);
|
||||||
}
|
}
|
||||||
return startActivityAsUserWithFeatureMethod;
|
return startActivityAsUserMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("ConstantConditions")
|
@SuppressWarnings("ConstantConditions")
|
||||||
public int startActivityAsUserWithFeature(Intent intent) {
|
public int startActivity(Intent intent) {
|
||||||
try {
|
try {
|
||||||
Method method = getStartActivityAsUserWithFeatureMethod();
|
Method method = getStartActivityAsUserMethod();
|
||||||
return (int) method.invoke(
|
return (int) method.invoke(
|
||||||
/* this */ manager,
|
/* this */ manager,
|
||||||
/* caller */ null,
|
/* caller */ null,
|
||||||
/* callingPackage */ FakeContext.PACKAGE_NAME,
|
/* callingPackage */ FakeContext.PACKAGE_NAME,
|
||||||
/* callingFeatureId */ null,
|
|
||||||
/* intent */ intent,
|
/* intent */ intent,
|
||||||
/* resolvedType */ null,
|
/* resolvedType */ null,
|
||||||
/* resultTo */ null,
|
/* resultTo */ null,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user