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 Thread thread;
|
||||||
|
|
||||||
private final UhidManager uhidManager;
|
private UhidManager uhidManager;
|
||||||
|
|
||||||
private final Device device;
|
private final Device device;
|
||||||
private final ControlChannel controlChannel;
|
private final ControlChannel controlChannel;
|
||||||
@ -52,7 +52,13 @@ public class Controller implements AsyncProcessor {
|
|||||||
this.powerOn = powerOn;
|
this.powerOn = powerOn;
|
||||||
initPointers();
|
initPointers();
|
||||||
sender = new DeviceMessageSender(controlChannel);
|
sender = new DeviceMessageSender(controlChannel);
|
||||||
uhidManager = new UhidManager(sender);
|
}
|
||||||
|
|
||||||
|
private UhidManager getUhidManager() {
|
||||||
|
if (uhidManager == null) {
|
||||||
|
uhidManager = new UhidManager(sender);
|
||||||
|
}
|
||||||
|
return uhidManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initPointers() {
|
private void initPointers() {
|
||||||
@ -98,7 +104,9 @@ public class Controller implements AsyncProcessor {
|
|||||||
// this is expected on close
|
// this is expected on close
|
||||||
} finally {
|
} finally {
|
||||||
Ln.d("Controller stopped");
|
Ln.d("Controller stopped");
|
||||||
uhidManager.closeAll();
|
if (uhidManager != null) {
|
||||||
|
uhidManager.closeAll();
|
||||||
|
}
|
||||||
listener.onTerminated(true);
|
listener.onTerminated(true);
|
||||||
}
|
}
|
||||||
}, "control-recv");
|
}, "control-recv");
|
||||||
@ -187,10 +195,10 @@ public class Controller implements AsyncProcessor {
|
|||||||
Device.rotateDevice();
|
Device.rotateDevice();
|
||||||
break;
|
break;
|
||||||
case ControlMessage.TYPE_UHID_CREATE:
|
case ControlMessage.TYPE_UHID_CREATE:
|
||||||
uhidManager.open(msg.getId(), msg.getData());
|
getUhidManager().open(msg.getId(), msg.getData());
|
||||||
break;
|
break;
|
||||||
case ControlMessage.TYPE_UHID_INPUT:
|
case ControlMessage.TYPE_UHID_INPUT:
|
||||||
uhidManager.write(msg.getId(), msg.getData());
|
getUhidManager().write(msg.getId(), msg.getData());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// do nothing
|
// do nothing
|
||||||
|
Loading…
x
Reference in New Issue
Block a user