Genymobile / scrcpy

Display and control your Android device
Apache License 2.0
110.64k stars 10.6k forks source link

can not using DisplayManager API . it using SurfaceControl API. Exception is null receiver. #5319

Closed shudingcai closed 3 weeks ago

shudingcai commented 3 weeks ago

private Method getCreateVirtualDisplayMethod() throws NoSuchMethodException { if (createVirtualDisplayMethod == null) { createVirtualDisplayMethod = android.hardware.display.DisplayManager.class .getMethod("createVirtualDisplay", String.class, int.class, int.class, int.class, Surface.class); } return createVirtualDisplayMethod; } public VirtualDisplay createVirtualDisplay(String name, int width, int height, int displayIdToMirror, Surface surface) throws Exception { Method method = getCreateVirtualDisplayMethod(); return (VirtualDisplay) method.invoke(null, name, width, height, displayIdToMirror, surface); }

public VirtualDisplay createVirtualDisplay(@NonNull String name, @IntRange(from = 1) int width, @IntRange(from = 1) int height, @IntRange(from = 1) int densityDpi, @Nullable Surface surface, @VirtualDisplayFlag int flags) { return createVirtualDisplay(name, width, height, densityDpi, surface, flags, null, null); }

in createVirtualDisplay function first param is null,but i find source code fuction createVirtualDisplay in DisplayManager .java is not a static function.

shudingcai commented 3 weeks ago

method.invoke(null, name, width, height, displayIdToMirror, surface); invoke is fail ,the first param is null,but in fuction createVirtualDisplay in DisplayManager .java(android framework) is not a static function.so Exception "null receiver"

rom1v commented 3 weeks ago

Which scrcpy version?

Please post the full console output (use ``` to format your code on github).

Please post your framework.jar:

adb pull /system/framework/framework.jar
shudingcai commented 3 weeks ago

(c) Microsoft Corporation。保留所有权利。

D:\Android study\scrcpy-win64-v2.4\scrcpy-win64-v2.4>scrcpy
scrcpy 2.4 <https://github.com/Genymobile/scrcpy>
INFO: ADB device found:
INFO:     -->   (usb)  050da80e828fb7d3                device  MEK_MX8Q
D:\Android study\scrcpy-win64-v2.4\scrcpy-win64-v2.4\scrcp...1 file pushed, 0 skipped. 2.5 MB/s (96973 bytes in 0.038s)
[server] INFO: Device: [nxp] Android MEK-MX8Q (Android 13)
[server] INFO: Screen id is :0
[server] WARN: Screen id is :0
[server] INFO: start------
[server] INFO: displayManagerException: java.lang.NullPointerException: null receiver
[server] INFO: Display: using SurfaceControl API
INFO: Renderer: direct3d
INFO: Texture: 1920x1080
rom1v commented 3 weeks ago

scrcpy 2.4 https://github.com/Genymobile/scrcpy

Can you test with the latest version? (post the full console output with scrcpy 2.7)

[server] INFO: Screen id is :0 [server] WARN: Screen id is :0 [server] INFO: start------

It is a modified version, correct?

shudingcai commented 3 weeks ago

scrcpy 2.4 https://github.com/Genymobile/scrcpy

Can you test with the latest version? (post the full console output with scrcpy 2.7)

[server] INFO: Screen id is :0 [server] WARN: Screen id is :0 [server] INFO: start------

It is a modified version, correct?

only add some log. '''@Override public void start(Surface surface) { Ln.i("start------"); ScreenInfo screenInfo = device.getScreenInfo(); Rect contentRect = screenInfo.getContentRect();

    // does not include the locked video orientation
    Rect unlockedVideoRect = screenInfo.getUnlockedVideoSize().toRect();
    int videoRotation = screenInfo.getVideoRotation();
    int layerStack = device.getLayerStack();

    if (display != null) {
        Ln.i("destroyDisplay------");
        SurfaceControl.destroyDisplay(display);
        display = null;
    }
    if (virtualDisplay != null) {
        Ln.i("destroyDisplay release------");
        virtualDisplay.release();
        virtualDisplay = null;
    }
    try {
        Rect videoRect = screenInfo.getVideoSize().toRect();
        virtualDisplay = ServiceManager.getDisplayManager()
                .createVirtualDisplay("scrcpy", videoRect.width(), videoRect.height(), device.getDisplayId(), surface,DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC);
        Ln.i("Display: using DisplayManager API");
    } catch (Exception displayManagerException) {
        Ln.i("displayManagerException: "+displayManagerException.toString());
        try {
            display = createDisplay();
            setDisplaySurface(display, surface, videoRotation, contentRect, unlockedVideoRect, layerStack);
            Ln.i("Display: using SurfaceControl API");
        } catch (Exception surfaceControlException) {
            Ln.e("Could not create display using DisplayManager", displayManagerException);
            Ln.e("Could not create display using SurfaceControl", surfaceControlException);
            throw new AssertionError("Could not create display");
        }
    }
shudingcai commented 3 weeks ago

adb pull /system/framework/framework.jar adb pull as follow. framework.zip

shudingcai commented 3 weeks ago

Scrcpy 2.7 Display: using SurfaceControl API not using DisplayManager API

Microsoft Windows [版本 10.0.19045.4894]
(c) Microsoft Corporation。保留所有权利。

D:\Android study\scrcpy-win64-v2.7>scrcpy
scrcpy 2.7 <https://github.com/Genymobile/scrcpy>
INFO: ADB device found:
INFO:     -->   (usb)  050da80e828fb7d3                device  MEK_MX8Q
D:\Android study\scrcpy-win64-v2.7\scrcpy-server: 1 file pushed, 0 skipped. 4.9 MB/s (131746 bytes in 0.025s)
[server] INFO: Device: [nxp] Android MEK-MX8Q (Android 13)
INFO: Renderer: direct3d
INFO: Texture: 1920x1080
[server] INFO: Display: using SurfaceControl API 
rom1v commented 3 weeks ago

[server] INFO: Device: [nxp] Android MEK-MX8Q (Android 13)

Display: using SurfaceControl API not using DisplayManager API

That's expected on Android 13.

DisplayManager can be used since this commit introduced in Android 14.

shudingcai commented 3 weeks ago

[server] INFO: Device: [nxp] Android MEK-MX8Q (Android 13)

Display: using SurfaceControl API not using DisplayManager API

That's expected on Android 13.

DisplayManager can be used since this commit introduced in Android 14.

source code(android 14.0.0-r2) fuction createVirtualDisplay in DisplayManager .java is not a static function(as follow picture) why? user need to pull the commit ?

image

rom1v commented 3 weeks ago

There are still the non-static versions, but since Android 14 there is also the static version. Check the commit I linked.

shudingcai commented 3 weeks ago

There are still the non-static versions, but since Android 14 there is also the static version. Check the commit I linked.

thanks