@Override
protected Void doInBackground() throws Exception {
AndroidDebugBridge bridge = AndroidDebugBridge.getBridge();
IDevice[] devices = bridge.getDevices();
IDevice selectedDevice = null;
String connectedDevice = mediator.getConnectedDevice();
final String absolutePath = file.getAbsolutePath();
final String fileName = file.getName();
mediator.setStatus("status.install.file", fileName);
if (file.exists() && file.isFile() && file.canRead()) {
for (IDevice iDevice : devices) {
if (StringUtils.equals(iDevice.toString(), connectedDevice)) {
selectedDevice = iDevice;
break;
}
}
if (selectedDevice != null) {
selectedDevice.installPackage(absolutePath, true);
} else {
logger.error("Cannot find device: {}", connectedDevice);
mediator.setStatus("status.error.install.device", connectedDevice);
}
mediator.setStatus("status.install");