Remove hander on ruffy unbind.
This commit is contained in:
parent
5e845e37f7
commit
d672f3c653
2 changed files with 23 additions and 1 deletions
|
@ -48,16 +48,36 @@ public class RuffyScripter {
|
||||||
private volatile boolean connected = false;
|
private volatile boolean connected = false;
|
||||||
private volatile long lastDisconnected = 0;
|
private volatile long lastDisconnected = 0;
|
||||||
|
|
||||||
|
private boolean started = false;
|
||||||
|
|
||||||
public RuffyScripter(final IRuffyService ruffyService) {
|
public RuffyScripter(final IRuffyService ruffyService) {
|
||||||
this.ruffyService = ruffyService;
|
this.ruffyService = ruffyService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start() {
|
||||||
try {
|
try {
|
||||||
ruffyService.addHandler(mHandler);
|
ruffyService.addHandler(mHandler);
|
||||||
idleDisconnectMonitorThread.start();
|
idleDisconnectMonitorThread.start();
|
||||||
|
started = true;
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void stop() {
|
||||||
|
if (started) {
|
||||||
|
try {
|
||||||
|
ruffyService.removeHandler(mHandler);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
log.warn("Removing IRTHandler from Ruffy service failed, ignoring", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isRunning() {
|
||||||
|
return started;
|
||||||
|
}
|
||||||
|
|
||||||
private Thread idleDisconnectMonitorThread = new Thread(new Runnable() {
|
private Thread idleDisconnectMonitorThread = new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
|
@ -16,7 +16,6 @@ import android.support.v4.app.NotificationCompat;
|
||||||
|
|
||||||
import com.squareup.otto.Subscribe;
|
import com.squareup.otto.Subscribe;
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.monkey.d.ruffy.ruffy.driver.IRuffyService;
|
import org.monkey.d.ruffy.ruffy.driver.IRuffyService;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -189,11 +188,14 @@ public class ComboPlugin implements PluginBase, PumpInterface {
|
||||||
@Override
|
@Override
|
||||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||||
ruffyScripter = new RuffyScripter(IRuffyService.Stub.asInterface(service));
|
ruffyScripter = new RuffyScripter(IRuffyService.Stub.asInterface(service));
|
||||||
|
ruffyScripter.start();
|
||||||
log.debug("ruffy serivce connected");
|
log.debug("ruffy serivce connected");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onServiceDisconnected(ComponentName name) {
|
public void onServiceDisconnected(ComponentName name) {
|
||||||
|
ruffyScripter.stop();
|
||||||
|
ruffyScripter = null;
|
||||||
log.debug("ruffy service disconnected");
|
log.debug("ruffy service disconnected");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue