mirror of https://github.com/Genymobile/scrcpy
Create UhidManager only on first use
There is no need to create a UhidManager instance (with its thread) if no UHID is used. PR #4473 <https://github.com/Genymobile/scrcpy/pull/4473>
This commit is contained in:
parent
87da68ee0d
commit
f557188dc8
|
@ -26,7 +26,7 @@ public class Controller implements AsyncProcessor {
|
|||
|
||||
private Thread thread;
|
||||
|
||||
private final UhidManager uhidManager;
|
||||
private UhidManager uhidManager;
|
||||
|
||||
private final Device device;
|
||||
private final ControlChannel controlChannel;
|
||||
|
@ -52,8 +52,14 @@ public class Controller implements AsyncProcessor {
|
|||
this.powerOn = powerOn;
|
||||
initPointers();
|
||||
sender = new DeviceMessageSender(controlChannel);
|
||||
}
|
||||
|
||||
private UhidManager getUhidManager() {
|
||||
if (uhidManager == null) {
|
||||
uhidManager = new UhidManager(sender);
|
||||
}
|
||||
return uhidManager;
|
||||
}
|
||||
|
||||
private void initPointers() {
|
||||
for (int i = 0; i < PointersState.MAX_POINTERS; ++i) {
|
||||
|
@ -99,7 +105,9 @@ public class Controller implements AsyncProcessor {
|
|||
Ln.e("Controller error", e);
|
||||
} finally {
|
||||
Ln.d("Controller stopped");
|
||||
if (uhidManager != null) {
|
||||
uhidManager.closeAll();
|
||||
}
|
||||
listener.onTerminated(true);
|
||||
}
|
||||
}, "control-recv");
|
||||
|
@ -195,10 +203,10 @@ public class Controller implements AsyncProcessor {
|
|||
device.rotateDevice();
|
||||
break;
|
||||
case ControlMessage.TYPE_UHID_CREATE:
|
||||
uhidManager.open(msg.getId(), msg.getData());
|
||||
getUhidManager().open(msg.getId(), msg.getData());
|
||||
break;
|
||||
case ControlMessage.TYPE_UHID_INPUT:
|
||||
uhidManager.writeInput(msg.getId(), msg.getData());
|
||||
getUhidManager().writeInput(msg.getId(), msg.getData());
|
||||
break;
|
||||
default:
|
||||
// do nothing
|
||||
|
|
Loading…
Reference in New Issue