Create UhidManager only on first use
There is no need to create a UhidManager instance (with its thread) if no UHID is used.
This commit is contained in:
parent
4f74b9210d
commit
ba6c295501
@ -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,7 +52,13 @@ public class Controller implements AsyncProcessor {
|
||||
this.powerOn = powerOn;
|
||||
initPointers();
|
||||
sender = new DeviceMessageSender(controlChannel);
|
||||
uhidManager = new UhidManager(sender);
|
||||
}
|
||||
|
||||
private UhidManager getUhidManager() {
|
||||
if (uhidManager == null) {
|
||||
uhidManager = new UhidManager(sender);
|
||||
}
|
||||
return uhidManager;
|
||||
}
|
||||
|
||||
private void initPointers() {
|
||||
@ -98,7 +104,9 @@ public class Controller implements AsyncProcessor {
|
||||
// this is expected on close
|
||||
} finally {
|
||||
Ln.d("Controller stopped");
|
||||
uhidManager.closeAll();
|
||||
if (uhidManager != null) {
|
||||
uhidManager.closeAll();
|
||||
}
|
||||
listener.onTerminated(true);
|
||||
}
|
||||
}, "control-recv");
|
||||
@ -187,10 +195,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.write(msg.getId(), msg.getData());
|
||||
getUhidManager().write(msg.getId(), msg.getData());
|
||||
break;
|
||||
default:
|
||||
// do nothing
|
||||
|
Loading…
x
Reference in New Issue
Block a user