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

[Android 14 Beta3] Can't control the device screen #4074

Closed
2 tasks done
DerekWuYD opened this issue Jun 9, 2023 · 14 comments
Closed
2 tasks done

[Android 14 Beta3] Can't control the device screen #4074

DerekWuYD opened this issue Jun 9, 2023 · 14 comments

Comments

@DerekWuYD
Copy link
Contributor

  • I have read the FAQ.
  • I have searched in existing issues.

Environment

  • OS: debian
  • scrcpy version: v2.0
  • installation method: manual built
  • device model: Pixel 7 Pro
  • Android version: Android 14 Beta 3

Describe the bug
In Android 14 beta 3, mouse and keyboard input events are no longer valid.
Screencasting is working, but remote control has failed.

Start arguments : --force-adb-forward --no-audio

scrcpy 2.0 <https://github.com/Genymobile/scrcpy>
x/server/scrcpy-server: 1 file pushed, 0 skipped. 74.6 MB/s (52911 bytes in 0.001s)
[server] INFO: Device: Google Pixel 7 Pro (Android 14)
[server] ERROR: Could not invoke method
java.lang.NoSuchMethodException: android.content.IClipboard$Stub$Proxy.addPrimaryClipChangedListener [interface android.content.IOnPrimaryClipChangedListener, class java.lang.String, class java.lang.String, int]
	at java.lang.Class.getMethod(Class.java:2937)
	at java.lang.Class.getMethod(Class.java:2449)
	at com.genymobile.scrcpy.wrappers.ClipboardManager.getAddPrimaryClipChangedListener(ClipboardManager.java:129)
	at com.genymobile.scrcpy.wrappers.ClipboardManager.addPrimaryClipChangedListener(ClipboardManager.java:139)
	at com.genymobile.scrcpy.Device.<init>(Device.java:100)
	at com.genymobile.scrcpy.Server.scrcpy(Server.java:64)
	at com.genymobile.scrcpy.Server.main(Server.java:381)
	at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
	at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:359)
[server] ERROR: Exception on thread Thread[Thread-2,5,main]
java.lang.AssertionError: java.lang.reflect.InvocationTargetException
	at com.genymobile.scrcpy.wrappers.ServiceManager.getInputManager(ServiceManager.java:72)
	at com.genymobile.scrcpy.Device.injectEvent(Device.java:192)
	at com.genymobile.scrcpy.Device.injectKeyEvent(Device.java:203)
	at com.genymobile.scrcpy.Device.pressReleaseKeycode(Device.java:211)
	at com.genymobile.scrcpy.Device.pressReleaseKeycode(Device.java:216)
	at com.genymobile.scrcpy.Controller.control(Controller.java:70)
	at com.genymobile.scrcpy.Controller.lambda$start$0$com-genymobile-scrcpy-Controller(Controller.java:90)
	at com.genymobile.scrcpy.Controller$$ExternalSyntheticLambda0.run(Unknown Source:2)
	at java.lang.Thread.run(Thread.java:1012)
Caused by: java.lang.reflect.InvocationTargetException
	at java.lang.reflect.Method.invoke(Native Method)
	at com.genymobile.scrcpy.wrappers.ServiceManager.getInputManager(ServiceManager.java:69)
	... 8 more
Caused by: java.lang.NullPointerException
	at java.util.Objects.requireNonNull(Objects.java:207)
	at android.hardware.input.InputManager.getInstance(InputManager.java:271)
	... 10 more
@DerekWuYD
Copy link
Contributor Author

This method works both on Android 14 Beta3 and pervious version.

Test result :

scrcpy 2.0 <https://github.com/Genymobile/scrcpy>
x/server/scrcpy-server: 1 file pushed, 0 skipped. 133.6 MB/s (53187 bytes in 0.000s)
[server] INFO: Device: Google Pixel 7 Pro (Android 14)
[server] INFO: Using the InputManagerGlobal API
INFO: Renderer: opengl
INFO: OpenGL version: 4.5 (Compatibility Profile) Mesa 22.3.3
...

rom1v pushed a commit that referenced this issue Jun 9, 2023
Parts of the InputManager class have been moved to a new
InputManagerGlobal class in Android 14 preview.

Fixes #4074 <#4074>
PR #4075 <#4075>

Signed-off-by: Romain Vimont <rom@rom1v.com>
@rom1v
Copy link
Collaborator

rom1v commented Jun 10, 2023

Thank you again for the fix.

However, I don't really understand the stacktrace:

Caused by: java.lang.reflect.InvocationTargetException
	at java.lang.reflect.Method.invoke(Native Method)
	at com.genymobile.scrcpy.wrappers.ServiceManager.getInputManager(ServiceManager.java:69)
	... 8 more
Caused by: java.lang.NullPointerException
	at java.util.Objects.requireNonNull(Objects.java:207)
	at android.hardware.input.InputManager.getInstance(InputManager.java:271)
	... 10 more

Since you get an InvocationTargetException, the invocation fails (getInstanceMethod.invoke(null);), so getInstanceMethod != null, so the method InputManager.getInstance() still exists (?), but does not accept a null target (so it is not static anymore?).

Could you please post your framework.jar so that I can understand?

adb pull /system/framework/framework.jar

@forforksake
Copy link

forforksake commented Jun 11, 2023

Could you please post your framework.jar so that I can understand?

adb pull /system/framework/framework.jar

Thanks to you both!

I was having the exact same issue on Android 14 beta 3, on Pixel 6 Pro via Kubuntu 23.04

framework.jar from my device =
framework.tar.gz

@forforksake
Copy link

This method works both on Android 14 Beta3 and pervious version.

Test result :

scrcpy 2.0 <https://github.com/Genymobile/scrcpy>
x/server/scrcpy-server: 1 file pushed, 0 skipped. 133.6 MB/s (53187 bytes in 0.000s)
[server] INFO: Device: Google Pixel 7 Pro (Android 14)
[server] INFO: Using the InputManagerGlobal API
INFO: Renderer: opengl
INFO: OpenGL version: 4.5 (Compatibility Profile) Mesa 22.3.3
...

Works perfectly - saved my life man, just smashed my screen and to my horror when I loaded scrcpy for the first time on A14 - disaster! Thanks both

@DerekWuYD
Copy link
Contributor Author

#4074 (comment)

Actually android.hardware.input.InputManager.getInstance still exist, but there's some changes in the function body.
Let's figure out the best solution when Android 14 source code release on AOSP : )

@rom1v
Copy link
Collaborator

rom1v commented Jun 12, 2023

framework.jar from my device =
framework.tar.gz

Thank you 👍

So in Android 13 (current AOSP master), here is the implementation of InputManager.getInstance():

    @UnsupportedAppUsage
    public static InputManager getInstance() {
        synchronized (InputManager.class) {
            if (sInstance == null) {
                try {
                    sInstance = new InputManager(IInputManager.Stub
                            .asInterface(ServiceManager.getServiceOrThrow(Context.INPUT_SERVICE)));
                } catch (ServiceNotFoundException e) {
                    throw new IllegalStateException(e);
                }
            }
            return sInstance;
        }
    }

In Android 14 (the version from your framework.jar), the new InputManager.getInstance() implementation is:

    @Deprecated
    public static InputManager getInstance() {
        return (InputManager) ((Application) Objects.requireNonNull(ActivityThread.currentApplication())).getSystemService(InputManager.class);
    }

And InputManagerGlobal.getInstance():

    public static InputManagerGlobal getInstance() {
        InputManagerGlobal inputManagerGlobal;
        IBinder b;
        synchronized (InputManagerGlobal.class) {
            if (sInstance == null && (b = ServiceManager.getService("input")) != null) {
                sInstance = new InputManagerGlobal(IInputManager.Stub.asInterface(b));
            }
            inputManagerGlobal = sInstance;
        }
        return inputManagerGlobal;
    }

rom1v pushed a commit that referenced this issue Jun 12, 2023
Parts of the InputManager class have been moved to a new
InputManagerGlobal class in Android 14 preview.

Fixes #4074 <#4074>
PR #4075 <#4075>

Signed-off-by: Romain Vimont <rom@rom1v.com>
@icantremember
Copy link

icantremember commented Jun 13, 2023

Works perfectly - saved my life man, just smashed my screen and to my horror when I loaded scrcpy for the first time on A14 - disaster! Thanks both

Sorry if I'm not following, but what "Works perfectly"? Am I just not seeing a command line switch that has options allowing this to work?

Thanks.

@rom1v
Copy link
Collaborator

rom1v commented Jun 13, 2023

@icantremember #4075

@icantremember
Copy link

Thanks for the reply, but I think I'm in a bit over my head. That commit would only help me if I were to build from source on my own, right? There's no (pre)release that has it yet, right?

@rom1v
Copy link
Collaborator

rom1v commented Jun 13, 2023

That commit would only help me if I were to build from source on my own, right? There's no (pre)release that has it yet, right?

That's correct.

But I plan to release a new version soon (v2.1, maybe next week), which is basically what is on dev branch, currently on commit 5bd7514 (+ the future SDL 2.28 not released yet). So if you beta-test it and report regressions/problems, I can provide a build 😄

Here it is:

(check git log for new features and command line options)

@icantremember
Copy link

But I plan to release a new version soon (v2.1, maybe next week), which is basically what is on dev branch, currently on commit 5bd7514 (+ the future SDL 2.28 not released yet). So if you beta-test it and report regressions/problems, I can provide a build 😄

Awesome. Can confirm that mouse/keyboard control is working well in this version. Anything else specific you need tested?

@Yaoojq
Copy link

Yaoojq commented Jun 28, 2023

I can see the screen on my computer, but I can't control the phone from the computer

[server] INFO: Device: Xiaomi 22011211C (Android 13)
[server] ERROR: Could not invoke method
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.genymobile.scrcpy.wrappers.InputManager.injectInputEvent(InputManager.java:37)
at com.genymobile.scrcpy.Device.injectEvent(Device.java:192)
at com.genymobile.scrcpy.Device.injectKeyEvent(Device.java:203)
at com.genymobile.scrcpy.Device.pressReleaseKeycode(Device.java:211)
at com.genymobile.scrcpy.Device.pressReleaseKeycode(Device.java:216)
at com.genymobile.scrcpy.Controller.control(Controller.java:70)
at com.genymobile.scrcpy.Controller.lambda$start$0$com-genymobile-scrcpy-Controller(Controller.java:90)
at com.genymobile.scrcpy.Controller$$ExternalSyntheticLambda0.run(Unknown Source:2)
at java.lang.Thread.run(Thread.java:1012)
Caused by: java.lang.SecurityException: Injecting input events requires the caller (or the source of the instrumentation, if any) to have the INJECT_EVENTS permission.
at android.os.Parcel.createExceptionOrNull(Parcel.java:3011)
at android.os.Parcel.createException(Parcel.java:2995)
at android.os.Parcel.readException(Parcel.java:2978)
at android.os.Parcel.readException(Parcel.java:2920)
at android.hardware.input.IInputManager$Stub$Proxy.injectInputEventToTarget(IInputManager.java:1294)
at android.hardware.input.InputManager.injectInputEvent(InputManager.java:1153)
at android.hardware.input.InputManager.injectInputEvent(InputM

@DerekWuYD
Copy link
Contributor Author

@Yaoojq
Copy link

Yaoojq commented Jun 28, 2023

It is normal after the device is restarted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants