Skip to content

Commit

Permalink
Fix Add/remove device dinamically problem
Browse files Browse the repository at this point in the history
  • Loading branch information
dim4o committed Nov 16, 2016
1 parent 9d1d475 commit 4639fdb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
14 changes: 9 additions & 5 deletions src/main/java/com/musala/atmosphere/agent/DeviceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,7 @@ String registerDevice(IDevice connectedDevice) {
return null;
}

Map<String, String> devicePropertiesMap = connectedDevice.getProperties();
String apiLevelString = devicePropertiesMap.get(DevicePropertyStringConstants.PROPERTY_API_LEVEL.toString());
String apiLevelString = connectedDevice.getProperty(IDevice.PROP_BUILD_API_LEVEL);
int deviceApiLevel = NO_AVAIBLE_API_LEVEL;
if (apiLevelString != null) {
deviceApiLevel = Integer.parseInt(apiLevelString);
Expand Down Expand Up @@ -392,9 +391,14 @@ private String unbindWrapperForDevice(IDevice device) throws RemoteException {
String rmiWrapperBindingId = getRmiWrapperBindingIdentifier(device);

try {
IWrapDevice deviceWrapper = getDeviceWrapper(rmiWrapperBindingId);
deviceWrapper.unbindWrapper();

// IWrapDevice deviceWrapper = getDeviceWrapper(rmiWrapperBindingId);
/*
* TODO: The method 'unbindWrapper()' fails because the physical device is missing
* (if is disconnected manually by removing the USB cable).
* Find an another solution for future work. Maybe is a good idea
* to stop the onDeviceComponents from the service.
*/
// deviceWrapper.unbindWrapper();
rmiRegistry.unbind(rmiWrapperBindingId);
} catch (NotBoundException e) {
// Wrapper for the device was never published, so we have nothing to unbind.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.musala.atmosphere.agent.devicewrapper.util;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

import com.android.ddmlib.AdbCommandRejectedException;
import com.android.ddmlib.IDevice;
Expand All @@ -11,9 +12,9 @@

/**
* A class that is used for running shell commands that do not return.
*
*
* @author georgi.gaydarov
*
*
*/
public class BackgroundShellCommandRunner implements Runnable {
private final String command;
Expand All @@ -25,7 +26,7 @@ public class BackgroundShellCommandRunner implements Runnable {
private final IDevice wrappedDevice;

/**
*
*
* @param command
* - shell command to be executed.
* @param wrappedDevice
Expand All @@ -41,26 +42,27 @@ public void run() {
executorThread = Thread.currentThread();
try {
NullOutputReceiver outputReceiver = new NullOutputReceiver();
wrappedDevice.executeShellCommand(command, outputReceiver, 0 /*
* this execution will never throw a
* ShellCommandUnresponsiveException
*/);
/*
* this execution will never throw a
* ShellCommandUnresponsiveException
*/
wrappedDevice.executeShellCommand(command, outputReceiver, 0, TimeUnit.MICROSECONDS);
} catch (TimeoutException | AdbCommandRejectedException | IOException | ShellCommandUnresponsiveException e) {
onExecutionException = new CommandFailedException("Shell command execution failed. See the enclosed exception for more information.",
e);
}
}

/**
*
*
* @return true if an exception was thrown when the passed shell command was executed, false otherwise.
*/
public boolean isExecutionExceptionThrown() {
return onExecutionException != null;
}

/**
*
*
* @return the exception which was thrown when the passed shell command was executed (null if no exception was
* thrown).
*/
Expand All @@ -69,7 +71,7 @@ public Exception getExecutionException() {
}

/**
*
*
* @return the {@link Thread} object that is responsible for the shell command execution.
*/
public Thread getExecutorThread() {
Expand Down

0 comments on commit 4639fdb

Please sign in to comment.