import org.tizen.sdblib.SyncService.SyncResult;
-
-
/**
* A Device. It can be a physical device or an emulator.
*/
final class Device implements IDevice {
-
- private final static int INSTALL_TIMEOUT = 2*60*1000; //2min
+
+ private final static int INSTALL_TIMEOUT = 2 * 60 * 1000; // 2min
final static String COMMAND_ARCHITECTURE_INFO = "uname -m";
final static String EMULATOR = "emulator";
private DeviceMonitor mMonitor;
private static final String LOG_TAG = "Device";
-
+
private SdbShellProcess sdbShellProcess = null;
public String getSerialNumber() {
return mState == DeviceState.OFFLINE;
}
- public SyncService getSyncService()
- throws TimeoutException, SdbCommandRejectedException, IOException {
+ public SyncService getSyncService() throws TimeoutException, SdbCommandRejectedException, IOException {
SyncService syncService = new SyncService(SmartDevelopmentBridge.getSocketAddress(), this);
if (syncService.openSync()) {
return syncService;
- }
+ }
return null;
}
public FileListingService getFileListingService() {
return new FileListingService(this);
}
-
+
public SdbShellProcess executeShellCommand(String command) throws IOException {
- SmartDevelopmentBridge sdb = SmartDevelopmentBridge.getBridge();
- if (sdb == null)
- return null;
- String sdbPath = sdb.getSdbOsLocation();
- if (sdbPath == null)
- return null;
- if (mSerialNumber == null)
- return null;
-
- String sdbShellCmd = sdbPath + " -s " + mSerialNumber + " shell";
- Process pSdb = Runtime.getRuntime().exec(sdbShellCmd);
- sdbShellProcess = new SdbShellProcess(pSdb, command);
- return sdbShellProcess;
+ SmartDevelopmentBridge sdb = SmartDevelopmentBridge.getBridge();
+ if (sdb == null)
+ return null;
+ String sdbPath = sdb.getSdbOsLocation();
+ if (sdbPath == null)
+ return null;
+ if (mSerialNumber == null)
+ return null;
+
+ String sdbShellCmd = sdbPath + " -s " + mSerialNumber + " shell";
+ Process pSdb = Runtime.getRuntime().exec(sdbShellCmd);
+ sdbShellProcess = new SdbShellProcess(pSdb, command);
+ return sdbShellProcess;
}
-
- public void executeShellCommand(String command, IShellOutputReceiver receiver)
- throws TimeoutException, SdbCommandRejectedException, ShellCommandUnresponsiveException,
- IOException {
- SdbHelper.executeRemoteCommand(SmartDevelopmentBridge.getSocketAddress(), command, this,
- receiver, SdbPreferences.getTimeOut());
+
+ public void executeShellCommand(String command, IShellOutputReceiver receiver) throws TimeoutException,
+ SdbCommandRejectedException, ShellCommandUnresponsiveException, IOException {
+ SdbHelper.executeRemoteCommand(SmartDevelopmentBridge.getSocketAddress(), command, this, receiver,
+ SdbPreferences.getTimeOut());
}
- public void executeShellCommand(String command, IShellOutputReceiver receiver,
- int maxTimeToOutputResponse)
- throws TimeoutException, SdbCommandRejectedException, ShellCommandUnresponsiveException,
- IOException {
- SdbHelper.executeRemoteCommand(SmartDevelopmentBridge.getSocketAddress(), command, this,
- receiver, maxTimeToOutputResponse);
+ public void executeShellCommand(String command, IShellOutputReceiver receiver, int maxTimeToOutputResponse)
+ throws TimeoutException, SdbCommandRejectedException, ShellCommandUnresponsiveException, IOException {
+ SdbHelper.executeRemoteCommand(SmartDevelopmentBridge.getSocketAddress(), command, this, receiver,
+ maxTimeToOutputResponse);
}
- public void runEventLogService(LogReceiver receiver)
- throws TimeoutException, SdbCommandRejectedException, IOException {
+ public void runEventLogService(LogReceiver receiver) throws TimeoutException, SdbCommandRejectedException, IOException {
SdbHelper.runEventLogService(SmartDevelopmentBridge.getSocketAddress(), this, receiver);
}
- public void runLogService(String logname, LogReceiver receiver)
- throws TimeoutException, SdbCommandRejectedException, IOException {
+ public void runLogService(String logname, LogReceiver receiver) throws TimeoutException, SdbCommandRejectedException,
+ IOException {
SdbHelper.runLogService(SmartDevelopmentBridge.getSocketAddress(), this, logname, receiver);
}
- public void createForward(int localPort, int remotePort)
- throws TimeoutException, SdbCommandRejectedException, IOException {
+ public void createForward(int localPort, int remotePort) throws TimeoutException, SdbCommandRejectedException, IOException {
SdbHelper.createForward(SmartDevelopmentBridge.getSocketAddress(), this, localPort, remotePort);
}
- public void removeForward(int localPort, int remotePort)
- throws TimeoutException, SdbCommandRejectedException, IOException {
+ public void removeForward(int localPort, int remotePort) throws TimeoutException, SdbCommandRejectedException, IOException {
SdbHelper.removeForward(SmartDevelopmentBridge.getSocketAddress(), this, localPort, remotePort);
}
return mMonitor;
}
+ /**
+ * Update device state value.
+ *
+ * @param changeMask
+ */
void update(int changeMask) {
mMonitor.getServer().deviceChanged(this, changeMask);
}
- public String syncPackageToDevice(String localFilePath)
- throws IOException, SdbCommandRejectedException, TimeoutException {
+ /**
+ * Update device state and name value.
+ *
+ * @param changeMask
+ * @param name
+ */
+ void update(int changeMask, String name) {
+ mDeviceName = name;
+ update(changeMask);
+ }
+
+ public String syncPackageToDevice(String localFilePath) throws IOException, SdbCommandRejectedException, TimeoutException {
try {
String packageFileName = getFileName(localFilePath);
String remoteFilePath = String.format("/opt/apps/tmp/%1$s", packageFileName); //$NON-NLS-1$
- Log.d(packageFileName, String.format("Uploading %1$s onto device '%2$s'",
- packageFileName, getSerialNumber()));
+ Log.d(packageFileName, String.format("Uploading %1$s onto device '%2$s'", packageFileName, getSerialNumber()));
SyncService sync = getSyncService();
if (sync != null) {
- String message = String.format("Uploading file onto device '%1$s'",
- getSerialNumber());
+ String message = String.format("Uploading file onto device '%1$s'", getSerialNumber());
Log.d(LOG_TAG, message);
- SyncResult result = sync.pushFile(localFilePath, remoteFilePath,
- SyncService.getNullProgressMonitor());
+ SyncResult result = sync.pushFile(localFilePath, remoteFilePath, SyncService.getNullProgressMonitor());
if (result.getCode() != SyncService.RESULT_OK) {
- throw new IOException(String.format("Unable to upload file: %1$s",
- result.getMessage()));
+ throw new IOException(String.format("Unable to upload file: %1$s", result.getMessage()));
}
} else {
throw new IOException("Unable to open sync connection!");
Log.e(LOG_TAG, "Unable to open sync connection! Timeout.");
throw e;
} catch (IOException e) {
- Log.e(LOG_TAG, String.format("Unable to open sync connection! reason: %1$s",
- e.getMessage()));
+ Log.e(LOG_TAG, String.format("Unable to open sync connection! reason: %1$s", e.getMessage()));
throw e;
}
}
/**
* Helper method to retrieve the file name given a local file path
- * @param filePath full directory path to file
+ *
+ * @param filePath
+ * full directory path to file
* @return {@link String} file name
*/
private String getFileName(String filePath) {
/**
* {@inheritDoc}
*/
- public void removeRemotePackage(String remoteFilePath)
- throws TimeoutException, SdbCommandRejectedException, ShellCommandUnresponsiveException,
- IOException {
+ public void removeRemotePackage(String remoteFilePath) throws TimeoutException, SdbCommandRejectedException,
+ ShellCommandUnresponsiveException, IOException {
// now we delete the app we sync'ed
try {
executeShellCommand("rm " + remoteFilePath, new NullOutputReceiver(), INSTALL_TIMEOUT);
} catch (IOException e) {
- Log.e(LOG_TAG, String.format("Failed to delete temporary package: %1$s",
- e.getMessage()));
+ Log.e(LOG_TAG, String.format("Failed to delete temporary package: %1$s", e.getMessage()));
throw e;
}
}
- public Arch getArch()
- {
+ public Arch getArch() {
return mArch;
}
- public void checkArchitecture()
- {
- try
- {
+ public void checkArchitecture() {
+ try {
executeShellCommand(COMMAND_ARCHITECTURE_INFO, new ArchInfoReceiver());
- } catch (Exception e)
- {
- Log.e("sdb", "execute " + COMMAND_ARCHITECTURE_INFO + " failed:" + e);
+ } catch (Exception e) {
+ Log.e("sdb", "execute " + COMMAND_ARCHITECTURE_INFO + " failed:" + e);
}
}
-
- public void checkDeviceType()
- {
- try
- {
+
+ public void checkDeviceType() {
+ try {
executeShellCommand(COMMAND_DEVICE_TYPE, new DeviceTypeReceiver());
- } catch (Exception e)
- {
- Log.e("sdb", "execute " + COMMAND_DEVICE_TYPE + " failed:" + e);
+ } catch (Exception e) {
+ Log.e("sdb", "execute " + COMMAND_DEVICE_TYPE + " failed:" + e);
}
}
- class ArchInfoReceiver extends MultiLineReceiver
- {
+ class ArchInfoReceiver extends MultiLineReceiver {
@Override
- public void processNewLines(String[] lines)
- {
- if(lines[0] != null && !lines[0].contains(Arch.ARM.getArch()))
- {
+ public void processNewLines(String[] lines) {
+ if (lines[0] != null && !lines[0].contains(Arch.ARM.getArch())) {
mArch = Arch.X86;
}
}
}
- class DeviceTypeReceiver extends MultiLineReceiver
- {
+ class DeviceTypeReceiver extends MultiLineReceiver {
@Override
- public void processNewLines(String[] lines)
- {
- if(EMULATOR.equals(lines[0]))
- {
+ public void processNewLines(String[] lines) {
+ if (EMULATOR.equals(lines[0])) {
mIsEmulator = true;
}
}
import org.tizen.sdblib.IDevice.DeviceState;
import org.tizen.sdblib.SdbHelper.SdbResponse;
-
/**
* A Device monitor. This connects to the Smart Development Bridge and get device.
*/
private final ArrayList<Device> mDevices = new ArrayList<Device>();
/**
- * Creates a new {@link DeviceMonitor} object and links it to the running
- * {@link SmartDevelopmentBridge} object.
- * @param server the running {@link SmartDevelopmentBridge}.
+ * Creates a new {@link DeviceMonitor} object and links it to the running {@link SmartDevelopmentBridge} object.
+ *
+ * @param server
+ * the running {@link SmartDevelopmentBridge}.
*/
DeviceMonitor(SmartDevelopmentBridge server) {
mServer = server;
}
}
-
-
/**
* Returns if the monitor is currently connected to the debug bridge server.
+ *
* @return
*/
boolean isMonitoring() {
Log.d("DeviceMonitor", "start sdb");
if (mServer.startSdb() == false) {
mRestartAttemptCount++;
- Log.e("DeviceMonitor",
- "sdb restart attempts: " + mRestartAttemptCount);
+ Log.e("DeviceMonitor", "sdb restart attempts: " + mRestartAttemptCount);
}
waitABit();
} else {
// read the incoming message
processIncomingDeviceData(length);
- // flag the fact that we have build the list at least once.
+ // flag the fact that we have build the list at least
+ // once.
mInitialDeviceListDone = true;
}
}
/**
* Attempts to connect to the debug bridge server.
+ *
* @return a connect socket if success, null otherwise
*/
private SocketChannel openSdbConnection() {
}
/**
- *
+ *
* @return
* @throws IOException
*/
try {
SdbHelper.write(mMainSdbConnection, request);
- SdbResponse resp = SdbHelper.readSdbResponse(mMainSdbConnection,
- false /* readDiagString */);
+ SdbResponse resp = SdbHelper.readSdbResponse(mMainSdbConnection, false /* readDiagString */);
if (resp.okay == false) {
// request was refused by sdb!
/**
* Processes an incoming device message from the socket
+ *
* @param socket
* @param length
* @throws IOException
String[] param = d.split("\t"); // $NON-NLS-1$
if (param.length == 3) {
// new sdb uses only serial numbers to identify devices
- Device device = new Device(this, param[0].trim() /*serialnumber*/,
- DeviceState.getState(param[1].trim()),
- param[2].trim() /*device name*/);
+ Device device = new Device(this, param[0].trim() /* serialnumber */, DeviceState.getState(param[1].trim()),
+ param[2].trim() /* device name */);
- //add the device to the list
+ // add the device to the list
list.add(device);
Log.d("DeviceMonitor", "deviceData: " + device.getSerialNumber() + " added to list");
}
}
/**
- * Updates the device list with the new items received from the monitoring service.
+ * Updates the device list with the new items received from the monitoring service.
*/
private void updateDevices(ArrayList<Device> newList) {
// because we are going to call mServer.deviceDisconnected which will acquire this lock
synchronized (mDevices) {
// For each device in the current list, we look for a matching the new list.
// * if we find it, we update the current object with whatever new information
- // there is
- // (mostly state change, if the device becomes ready, we query for build info).
- // We also remove the device from the new list to mark it as "processed"
+ // there is (mostly state change, if the device becomes ready, we query for build info).
+ // We also remove the device from the new list to mark it as "processed"
// * if we do not find it, we remove it from the current list.
// Once this is done, the new list contains device we aren't monitoring yet, so we
// add them to the list, and start monitoring them.
- for (int d = 0 ; d < mDevices.size() ;) {
+ for (int d = 0; d < mDevices.size();) {
Device device = mDevices.get(d);
// look for a similar device in the new list.
int count = newList.size();
boolean foundMatch = false;
- for (int dd = 0 ; dd < count ; dd++) {
+ for (int dd = 0; dd < count; dd++) {
Device newDevice = newList.get(dd);
// see if it matches in id and serial number.
if (newDevice.getSerialNumber().equals(device.getSerialNumber())) {
if (device.getState() != newDevice.getState()) {
device.setState(newDevice.getState());
- //should to check architecture if device is an emulator and state changed from "off-lined" to "on-lined"
- if(device.getState() == DeviceState.ONLINE)
- {
+ // should to check architecture if device is an
+ // emulator and state changed from "off-lined" to "on-lined"
+ if (device.getState() == DeviceState.ONLINE) {
device.checkArchitecture();
device.checkDeviceType();
Log.d("DeviceMonitor", "updateDevices: " + device.getSerialNumber() + " onlined");
- device.update(Device.CHANGE_STATE);
+ device.update(Device.CHANGE_STATE, newDevice.getDeviceName());
}
}
// remove the new device from the list since it's been used
}
if (foundMatch == false) {
- // the device is gone, we need to remove it, and keep current index
- // to process the next one.
+ // the device is gone, we need to remove it, and keep current index to process the next one.
removeDevice(device);
mServer.deviceDisconnected(device);
Log.d("DeviceMonitor", "updateDevices: " + device.getSerialNumber() + " off-lined");
}
}
- // at this point we should still have some new devices in newList, so we
- // process them.
+ // at this point we should still have some new devices in newList, so we process them.
for (Device newDevice : newList) {
- //should to check architecture if new device is an emulator on-lined
- if(newDevice.isOnline())
- {
+ // should to check architecture if new device is an emulator on-lined
+ if (newDevice.isOnline()) {
newDevice.checkArchitecture();
newDevice.checkDeviceType();
}
mDevices.remove(device);
}
-
/**
* Reads the length of the next message from a socket.
- * @param socket The {@link SocketChannel} to read from.
+ *
+ * @param socket
+ * The {@link SocketChannel} to read from.
* @return the length, or 0 (zero) if no data is available from the socket.
- * @throws IOException if the connection failed.
+ * @throws IOException
+ * if the connection failed.
*/
private int readLength(SocketChannel socket, byte[] buffer) throws IOException {
String msg = read(socket, buffer);
// we'll throw an exception below.
Log.e("sdb", "parse integer failed:" + nfe);
}
- }
+ }
// we receive something we can't read. It's better to reset the connection at this point.
throw new IOException("Unable to read length");
/**
* Fills a buffer from a socket.
+ *
* @param socket
* @param buffer
* @return the content of the buffer as a string, or null if it failed to convert the buffer.