ConnectSDK / Connect-SDK-Android-Core

Core source code for the Android Connect SDK project
Apache License 2.0
115 stars 80 forks source link

MouseControl continuously requesting pointer input socket. #65

Open alexey-odintsov opened 9 years ago

alexey-odintsov commented 9 years ago

I'm working with Android app that translates Gyroscope data to TV cursor movements. You can find test source code at https://github.com/alexey-odintsov/MouseSocketTest (it's short).

Currently I'm migrating project from ConnectSDK 1.4 to 1.5 Lite and encountered a problem: Every time gyroscope data comes my code checks MouseControl availability and invokes move method:

public class App extends Application {
    public static ConnectableDevice tv;

    // return MouseControl
    public static MouseControl getMouse() {
        if (tv != null && tv.isConnected()) {
            return tv.getCapability(MouseControl.class);
        } else {
            return null;
        }
    }
    ...
}

class MySensorsListener implements SensorEventListener {
    // this method is invoked continuously every N millisecond
    public void onSensorChanged(SensorEvent event) {
        ...
        if (App.getMouse() != null) {
            App.getMouse().move(dx, dy);
        }
    }
}

public class MainActivity extends AppCompatActivity {
    ...
    // connected to device
    public void onDeviceReady(ConnectableDevice device) {
        if (App.getMouse() != null) {
            App.getMouse().connectMouse();
        }
    }
}

With ConnectSDK 1.4.2 this code works great, but with ConnectSDK 1.5 mouse movements sometimes don't work.

It seems that mouseSocket is not ready and it's created every time move method invoked.

Normal working socket logs are:

webOS Socket [IN] : {"type":"hello","payload":{...}}
webOS Socket [OUT] : {"type":"register","id":3,"payload":{...}}
webOS Socket [IN] : {"type":"registered","id":3,"payload":{...}}
webOS Socket [OUT] : {"type":"subscribe","id":"1","uri":"ssap:\/\/com.webos.service.ime\/registerRemoteKeyboard"}
webOS Socket [IN] : {"type":"response","id":"1","payload":{"subscribed":true}}
webOS Socket [OUT] : {"type":"request","id":"4","uri":"ssap:\/\/com.webos.service.networkinput\/getPointerInputSocket"}
webOS Socket [IN] : {"type":"response","id":"4","payload":{"socketPath":"wss://192.168.0..../netinput.pointer.sock","returnValue":true}}

Socket logs when mouse is not working:

webOS Socket [IN] : {"type":"hello","payload":{...}}
webOS Socket [OUT] : {"type":"register","id":3,"payload":{...}}
webOS Socket [IN] : {"type":"registered","id":3,"payload":{...}}
webOS Socket [OUT] : {"type":"subscribe","id":"1","uri":"ssap:\/\/com.webos.service.ime\/registerRemoteKeyboard"}
webOS Socket [IN] : {"type":"response","id":"1","payload":{"subscribed":true}}
webOS Socket [OUT] : {"type":"request","id":"4","uri":"ssap:\/\/com.webos.service.networkinput\/getPointerInputSocket"}
webOS Socket [OUT] : {"type":"request","id":"5","uri":"ssap:\/\/com.webos.service.networkinput\/getPointerInputSocket"}
webOS Socket [OUT] : {"type":"request","id":"6","uri":"ssap:\/\/com.webos.service.networkinput\/getPointerInputSocket"}
webOS Socket [OUT] : {"type":"request","id":"7","uri":"ssap:\/\/com.webos.service.networkinput\/getPointerInputSocket"}
webOS Socket [OUT] : {"type":"request","id":"8","uri":"ssap:\/\/com.webos.service.networkinput\/getPointerInputSocket"}
webOS Socket [OUT] : {"type":"request","id":"9","uri":"ssap:\/\/com.webos.service.networkinput\/getPointerInputSocket"}
webOS Socket [OUT] : {"type":"request","id":"10","uri":"ssap:\/\/com.webos.service.networkinput\/getPointerInputSocket"}
webOS Socket [OUT] : {"type":"request","id":"11","uri":"ssap:\/\/com.webos.service.networkinput\/getPointerInputSocket"}
...
webOS Socket [OUT] : {"type":"request","id":"50","uri":"ssap:\/\/com.webos.service.networkinput\/getPointerInputSocket"}

I've found a workaround by exposing isMouseConnected API inside WebOSTVService class and updating MouseControl interface method signature:

public boolean isMouseConnected() {
        return mouseSocket != null && mouseSocket.isConnected();
}

And by adding checking to my code:

if (App.getMouse() != null && App.getMouse().isMouseConnected()) {
    App.getMouse().move(dx, dy);
}

But I believe there is something must be done with MouseControl socket creation logic.

xuanhieu147 commented 2 years ago

did you find a way to solve it?