Display and control your Android device
Catch generic ReflectiveOperationException
Romain Vimontf7b4a18b4398
diff --git a/server/src/main/java/com/genymobile/scrcpy/wrappers/ActivityManager.java b/server/src/main/java/com/genymobile/scrcpy/wrappers/ActivityManager.javaindex fd0a7798..367ea2e7 100644--- a/server/src/main/java/com/genymobile/scrcpy/wrappers/ActivityManager.java+++ b/server/src/main/java/com/genymobile/scrcpy/wrappers/ActivityManager.java@@ -13,7 +13,6 @@ import android.os.IBinder;import android.os.IInterface;import java.lang.reflect.Field;-import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;@SuppressLint("PrivateApi,DiscouragedPrivateApi")@@ -34,7 +33,7 @@ public final class ActivityManager {Method getDefaultMethod = cls.getDeclaredMethod("getDefault");IInterface am = (IInterface) getDefaultMethod.invoke(null);return new ActivityManager(am);- } catch (Exception e) {+ } catch (ReflectiveOperationException e) {throw new AssertionError(e);}}@@ -89,7 +88,7 @@ public final class ActivityManager {return null;}return new ContentProvider(this, provider, name, token);- } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException | NoSuchFieldException e) {+ } catch (ReflectiveOperationException e) {Ln.e("Could not invoke method", e);return null;}@@ -99,7 +98,7 @@ public final class ActivityManager {try {Method method = getRemoveContentProviderExternalMethod();method.invoke(manager, name, token);- } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {+ } catch (ReflectiveOperationException e) {Ln.e("Could not invoke method", e);}}diff --git a/server/src/main/java/com/genymobile/scrcpy/wrappers/ClipboardManager.java b/server/src/main/java/com/genymobile/scrcpy/wrappers/ClipboardManager.javaindex 2a09b200..2c8d9907 100644--- a/server/src/main/java/com/genymobile/scrcpy/wrappers/ClipboardManager.java+++ b/server/src/main/java/com/genymobile/scrcpy/wrappers/ClipboardManager.java@@ -8,7 +8,6 @@ import android.content.IOnPrimaryClipChangedListener;import android.os.Build;import android.os.IInterface;-import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;public final class ClipboardManager {@@ -98,8 +97,7 @@ public final class ClipboardManager {return setPrimaryClipMethod;}- private static ClipData getPrimaryClip(Method method, int methodVersion, IInterface manager)- throws InvocationTargetException, IllegalAccessException {+ private static ClipData getPrimaryClip(Method method, int methodVersion, IInterface manager) throws ReflectiveOperationException {if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {return (ClipData) method.invoke(manager, FakeContext.PACKAGE_NAME);}@@ -121,8 +119,7 @@ public final class ClipboardManager {}}- private static void setPrimaryClip(Method method, int methodVersion, IInterface manager, ClipData clipData)- throws InvocationTargetException, IllegalAccessException {+ private static void setPrimaryClip(Method method, int methodVersion, IInterface manager, ClipData clipData) throws ReflectiveOperationException {if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {method.invoke(manager, clipData, FakeContext.PACKAGE_NAME);return;@@ -149,7 +146,7 @@ public final class ClipboardManager {return null;}return clipData.getItemAt(0).getText();- } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {+ } catch (ReflectiveOperationException e) {Ln.e("Could not invoke method", e);return null;}@@ -161,14 +158,14 @@ public final class ClipboardManager {ClipData clipData = ClipData.newPlainText(null, text);setPrimaryClip(method, setMethodVersion, manager, clipData);return true;- } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {+ } catch (ReflectiveOperationException e) {Ln.e("Could not invoke method", e);return false;}}private static void addPrimaryClipChangedListener(Method method, int methodVersion, IInterface manager, IOnPrimaryClipChangedListener listener)- throws InvocationTargetException, IllegalAccessException {+ throws ReflectiveOperationException {if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {method.invoke(manager, listener, FakeContext.PACKAGE_NAME);return;@@ -220,7 +217,7 @@ public final class ClipboardManager {Method method = getAddPrimaryClipChangedListener();addPrimaryClipChangedListener(method, addListenerMethodVersion, manager, listener);return true;- } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {+ } catch (ReflectiveOperationException e) {Ln.e("Could not invoke method", e);return false;}diff --git a/server/src/main/java/com/genymobile/scrcpy/wrappers/ContentProvider.java b/server/src/main/java/com/genymobile/scrcpy/wrappers/ContentProvider.javaindex 89c1d0e2..a03f824e 100644--- a/server/src/main/java/com/genymobile/scrcpy/wrappers/ContentProvider.java+++ b/server/src/main/java/com/genymobile/scrcpy/wrappers/ContentProvider.java@@ -11,7 +11,6 @@ import android.os.Bundle;import android.os.IBinder;import java.io.Closeable;-import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;public final class ContentProvider implements Closeable {@@ -75,8 +74,7 @@ public final class ContentProvider implements Closeable {return callMethod;}- private Bundle call(String callMethod, String arg, Bundle extras)- throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {+ private Bundle call(String callMethod, String arg, Bundle extras) throws ReflectiveOperationException {try {Method method = getCallMethod();Object[] args;@@ -97,7 +95,7 @@ public final class ContentProvider implements Closeable {}}return (Bundle) method.invoke(provider, args);- } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {+ } catch (ReflectiveOperationException e) {Ln.e("Could not invoke method", e);throw e;}diff --git a/server/src/main/java/com/genymobile/scrcpy/wrappers/DisplayControl.java b/server/src/main/java/com/genymobile/scrcpy/wrappers/DisplayControl.javaindex 4e19beb9..ba3e9ee0 100644--- a/server/src/main/java/com/genymobile/scrcpy/wrappers/DisplayControl.java+++ b/server/src/main/java/com/genymobile/scrcpy/wrappers/DisplayControl.java@@ -7,7 +7,6 @@ import android.annotation.TargetApi;import android.os.Build;import android.os.IBinder;-import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;@SuppressLint({"PrivateApi", "SoonBlockedPrivateApi", "BlockedPrivateApi"})@@ -55,7 +54,7 @@ public final class DisplayControl {try {Method method = getGetPhysicalDisplayTokenMethod();return (IBinder) method.invoke(null, physicalDisplayId);- } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {+ } catch (ReflectiveOperationException e) {Ln.e("Could not invoke method", e);return null;}@@ -72,7 +71,7 @@ public final class DisplayControl {try {Method method = getGetPhysicalDisplayIdsMethod();return (long[]) method.invoke(null);- } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {+ } catch (ReflectiveOperationException e) {Ln.e("Could not invoke method", e);return null;}diff --git a/server/src/main/java/com/genymobile/scrcpy/wrappers/DisplayManager.java b/server/src/main/java/com/genymobile/scrcpy/wrappers/DisplayManager.javaindex 80785a9f..33a061ba 100644--- a/server/src/main/java/com/genymobile/scrcpy/wrappers/DisplayManager.java+++ b/server/src/main/java/com/genymobile/scrcpy/wrappers/DisplayManager.java@@ -9,7 +9,6 @@ import android.annotation.SuppressLint;import android.view.Display;import java.lang.reflect.Field;-import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;import java.util.regex.Matcher;import java.util.regex.Pattern;@@ -24,7 +23,7 @@ public final class DisplayManager {Method getInstanceMethod = clazz.getDeclaredMethod("getInstance");Object dmg = getInstanceMethod.invoke(null);return new DisplayManager(dmg);- } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {+ } catch (ReflectiveOperationException e) {throw new AssertionError(e);}}@@ -75,7 +74,7 @@ public final class DisplayManager {try {Field filed = Display.class.getDeclaredField(flagString);flags |= filed.getInt(null);- } catch (NoSuchFieldException | IllegalAccessException e) {+ } catch (ReflectiveOperationException e) {// Silently ignore, some flags reported by "dumpsys display" are @TestApi}}@@ -97,7 +96,7 @@ public final class DisplayManager {int layerStack = cls.getDeclaredField("layerStack").getInt(displayInfo);int flags = cls.getDeclaredField("flags").getInt(displayInfo);return new DisplayInfo(displayId, new Size(width, height), rotation, layerStack, flags);- } catch (Exception e) {+ } catch (ReflectiveOperationException e) {throw new AssertionError(e);}}@@ -105,7 +104,7 @@ public final class DisplayManager {public int[] getDisplayIds() {try {return (int[]) manager.getClass().getMethod("getDisplayIds").invoke(manager);- } catch (Exception e) {+ } catch (ReflectiveOperationException e) {throw new AssertionError(e);}}diff --git a/server/src/main/java/com/genymobile/scrcpy/wrappers/InputManager.java b/server/src/main/java/com/genymobile/scrcpy/wrappers/InputManager.javaindex c7c72dc9..16ecb09f 100644--- a/server/src/main/java/com/genymobile/scrcpy/wrappers/InputManager.java+++ b/server/src/main/java/com/genymobile/scrcpy/wrappers/InputManager.java@@ -6,7 +6,6 @@ import android.annotation.SuppressLint;import android.view.InputEvent;import android.view.MotionEvent;-import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;@SuppressLint("PrivateApi,DiscouragedPrivateApi")@@ -28,7 +27,7 @@ public final class InputManager {Method getInstanceMethod = inputManagerClass.getDeclaredMethod("getInstance");Object im = getInstanceMethod.invoke(null);return new InputManager(im);- } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {+ } catch (ReflectiveOperationException e) {throw new AssertionError(e);}}@@ -57,7 +56,7 @@ public final class InputManager {try {Method method = getInjectInputEventMethod();return (boolean) method.invoke(manager, inputEvent, mode);- } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {+ } catch (ReflectiveOperationException e) {Ln.e("Could not invoke method", e);return false;}@@ -75,7 +74,7 @@ public final class InputManager {Method method = getSetDisplayIdMethod();method.invoke(inputEvent, displayId);return true;- } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {+ } catch (ReflectiveOperationException e) {Ln.e("Cannot associate a display id to the input event", e);return false;}@@ -93,7 +92,7 @@ public final class InputManager {Method method = getSetActionButtonMethod();method.invoke(motionEvent, actionButton);return true;- } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {+ } catch (ReflectiveOperationException e) {Ln.e("Cannot set action button on MotionEvent", e);return false;}diff --git a/server/src/main/java/com/genymobile/scrcpy/wrappers/PowerManager.java b/server/src/main/java/com/genymobile/scrcpy/wrappers/PowerManager.javaindex 942a5880..36d5f1ac 100644--- a/server/src/main/java/com/genymobile/scrcpy/wrappers/PowerManager.java+++ b/server/src/main/java/com/genymobile/scrcpy/wrappers/PowerManager.java@@ -6,7 +6,6 @@ import android.annotation.SuppressLint;import android.os.Build;import android.os.IInterface;-import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;public final class PowerManager {@@ -35,7 +34,7 @@ public final class PowerManager {try {Method method = getIsScreenOnMethod();return (boolean) method.invoke(manager);- } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {+ } catch (ReflectiveOperationException e) {Ln.e("Could not invoke method", e);return false;}diff --git a/server/src/main/java/com/genymobile/scrcpy/wrappers/StatusBarManager.java b/server/src/main/java/com/genymobile/scrcpy/wrappers/StatusBarManager.javaindex e65cef5c..af217da2 100644--- a/server/src/main/java/com/genymobile/scrcpy/wrappers/StatusBarManager.java+++ b/server/src/main/java/com/genymobile/scrcpy/wrappers/StatusBarManager.java@@ -4,7 +4,6 @@ import com.genymobile.scrcpy.Ln;import android.os.IInterface;-import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;public final class StatusBarManager {@@ -67,7 +66,7 @@ public final class StatusBarManager {} else {method.invoke(manager);}- } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {+ } catch (ReflectiveOperationException e) {Ln.e("Could not invoke method", e);}}@@ -82,7 +81,7 @@ public final class StatusBarManager {// old versionmethod.invoke(manager);}- } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {+ } catch (ReflectiveOperationException e) {Ln.e("Could not invoke method", e);}}@@ -91,7 +90,7 @@ public final class StatusBarManager {try {Method method = getCollapsePanelsMethod();method.invoke(manager);- } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {+ } catch (ReflectiveOperationException e) {Ln.e("Could not invoke method", e);}}diff --git a/server/src/main/java/com/genymobile/scrcpy/wrappers/SurfaceControl.java b/server/src/main/java/com/genymobile/scrcpy/wrappers/SurfaceControl.javaindex 98259e7f..4a3d0bfe 100644--- a/server/src/main/java/com/genymobile/scrcpy/wrappers/SurfaceControl.java+++ b/server/src/main/java/com/genymobile/scrcpy/wrappers/SurfaceControl.java@@ -8,7 +8,6 @@ import android.os.Build;import android.os.IBinder;import android.view.Surface;-import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;@SuppressLint("PrivateApi")@@ -109,7 +108,7 @@ public final class SurfaceControl {// call getInternalDisplayToken()return (IBinder) method.invoke(null);- } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {+ } catch (ReflectiveOperationException e) {Ln.e("Could not invoke method", e);return null;}@@ -126,7 +125,7 @@ public final class SurfaceControl {try {Method method = getGetPhysicalDisplayTokenMethod();return (IBinder) method.invoke(null, physicalDisplayId);- } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {+ } catch (ReflectiveOperationException e) {Ln.e("Could not invoke method", e);return null;}@@ -152,7 +151,7 @@ public final class SurfaceControl {try {Method method = getGetPhysicalDisplayIdsMethod();return (long[]) method.invoke(null);- } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {+ } catch (ReflectiveOperationException e) {Ln.e("Could not invoke method", e);return null;}@@ -170,7 +169,7 @@ public final class SurfaceControl {Method method = getSetDisplayPowerModeMethod();method.invoke(null, displayToken, mode);return true;- } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {+ } catch (ReflectiveOperationException e) {Ln.e("Could not invoke method", e);return false;}diff --git a/server/src/main/java/com/genymobile/scrcpy/wrappers/WindowManager.java b/server/src/main/java/com/genymobile/scrcpy/wrappers/WindowManager.javaindex 99b9148f..b19dace9 100644--- a/server/src/main/java/com/genymobile/scrcpy/wrappers/WindowManager.java+++ b/server/src/main/java/com/genymobile/scrcpy/wrappers/WindowManager.java@@ -7,7 +7,6 @@ import android.os.IInterface;import android.view.IDisplayFoldListener;import android.view.IRotationWatcher;-import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;public final class WindowManager {@@ -66,7 +65,7 @@ public final class WindowManager {try {Method method = getGetRotationMethod();return (int) method.invoke(manager);- } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {+ } catch (ReflectiveOperationException e) {Ln.e("Could not invoke method", e);return 0;}@@ -76,7 +75,7 @@ public final class WindowManager {try {Method method = getFreezeRotationMethod();method.invoke(manager, rotation);- } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {+ } catch (ReflectiveOperationException e) {Ln.e("Could not invoke method", e);}}@@ -85,7 +84,7 @@ public final class WindowManager {try {Method method = getIsRotationFrozenMethod();return (boolean) method.invoke(manager);- } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {+ } catch (ReflectiveOperationException e) {Ln.e("Could not invoke method", e);return false;}@@ -95,7 +94,7 @@ public final class WindowManager {try {Method method = getThawRotationMethod();method.invoke(manager);- } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {+ } catch (ReflectiveOperationException e) {Ln.e("Could not invoke method", e);}}