|
|
@ -23,9 +23,9 @@ public class I2PDActivity extends Activity { |
|
|
|
|
|
|
|
|
|
|
|
private TextView textView; |
|
|
|
private TextView textView; |
|
|
|
|
|
|
|
|
|
|
|
private final DaemonSingleton daemon = DaemonSingleton.getInstance(); |
|
|
|
private static final DaemonSingleton daemon = DaemonSingleton.getInstance(); |
|
|
|
|
|
|
|
|
|
|
|
private DaemonSingleton.StateUpdateListener daemonStateUpdatedListener = |
|
|
|
private final DaemonSingleton.StateUpdateListener daemonStateUpdatedListener = |
|
|
|
new DaemonSingleton.StateUpdateListener() { |
|
|
|
new DaemonSingleton.StateUpdateListener() { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -58,7 +58,7 @@ public class I2PDActivity extends Activity { |
|
|
|
|
|
|
|
|
|
|
|
textView = new TextView(this); |
|
|
|
textView = new TextView(this); |
|
|
|
setContentView(textView); |
|
|
|
setContentView(textView); |
|
|
|
DaemonSingleton.getInstance().addStateChangeListener(daemonStateUpdatedListener); |
|
|
|
daemon.addStateChangeListener(daemonStateUpdatedListener); |
|
|
|
daemonStateUpdatedListener.daemonStateUpdate(); |
|
|
|
daemonStateUpdatedListener.daemonStateUpdate(); |
|
|
|
|
|
|
|
|
|
|
|
//set the app be foreground
|
|
|
|
//set the app be foreground
|
|
|
@ -68,22 +68,18 @@ public class I2PDActivity extends Activity { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void onDestroy() { |
|
|
|
protected void onDestroy() { |
|
|
|
super.onDestroy(); |
|
|
|
super.onDestroy(); |
|
|
|
localDestroy(); |
|
|
|
textView = null; |
|
|
|
} |
|
|
|
daemon.removeStateChangeListener(daemonStateUpdatedListener); |
|
|
|
|
|
|
|
Timer gracefulQuitTimer = getGracefulQuitTimer(); |
|
|
|
private void localDestroy() { |
|
|
|
if(gracefulQuitTimer!=null) { |
|
|
|
textView = null; |
|
|
|
gracefulQuitTimer.cancel(); |
|
|
|
DaemonSingleton.getInstance().removeStateChangeListener(daemonStateUpdatedListener); |
|
|
|
setGracefulQuitTimer(null); |
|
|
|
Timer gracefulQuitTimer = getGracefulQuitTimer(); |
|
|
|
} |
|
|
|
if(gracefulQuitTimer!=null) { |
|
|
|
try{ |
|
|
|
gracefulQuitTimer.cancel(); |
|
|
|
doUnbindService(); |
|
|
|
setGracefulQuitTimer(null); |
|
|
|
}catch(Throwable tr){ |
|
|
|
|
|
|
|
Log.e(TAG, "", tr); |
|
|
|
} |
|
|
|
} |
|
|
|
// try{
|
|
|
|
|
|
|
|
// doUnbindService();
|
|
|
|
|
|
|
|
// }catch(Throwable tr){
|
|
|
|
|
|
|
|
// Log.e(TAG, "", tr);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private CharSequence throwableToString(Throwable tr) { |
|
|
|
private CharSequence throwableToString(Throwable tr) { |
|
|
@ -122,24 +118,27 @@ public class I2PDActivity extends Activity { |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean mIsBound; |
|
|
|
private static volatile boolean mIsBound; |
|
|
|
|
|
|
|
|
|
|
|
private synchronized void doBindService() { |
|
|
|
private void doBindService() { |
|
|
|
if(mIsBound)return; |
|
|
|
synchronized (I2PDActivity.class) { |
|
|
|
// Establish a connection with the service. We use an explicit
|
|
|
|
if (mIsBound) return; |
|
|
|
// class name because we want a specific service implementation that
|
|
|
|
// Establish a connection with the service. We use an explicit
|
|
|
|
// we know will be running in our own process (and thus won't be
|
|
|
|
// class name because we want a specific service implementation that
|
|
|
|
// supporting component replacement by other applications).
|
|
|
|
// we know will be running in our own process (and thus won't be
|
|
|
|
bindService(new Intent(this, |
|
|
|
// supporting component replacement by other applications).
|
|
|
|
ForegroundService.class), mConnection, Context.BIND_AUTO_CREATE); |
|
|
|
bindService(new Intent(this, ForegroundService.class), mConnection, Context.BIND_AUTO_CREATE); |
|
|
|
mIsBound = true; |
|
|
|
mIsBound = true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void doUnbindService() { |
|
|
|
private void doUnbindService() { |
|
|
|
if (mIsBound) { |
|
|
|
synchronized (I2PDActivity.class) { |
|
|
|
// Detach our existing connection.
|
|
|
|
if (mIsBound) { |
|
|
|
unbindService(mConnection); |
|
|
|
// Detach our existing connection.
|
|
|
|
mIsBound = false; |
|
|
|
unbindService(mConnection); |
|
|
|
|
|
|
|
mIsBound = false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -177,9 +176,9 @@ public class I2PDActivity extends Activity { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Timer gracefulQuitTimer; |
|
|
|
private volatile Timer gracefulQuitTimer; |
|
|
|
private final Object gracefulQuitTimerLock = new Object(); |
|
|
|
|
|
|
|
private synchronized void i2pdGracefulStop() { |
|
|
|
private void i2pdGracefulStop() { |
|
|
|
if(daemon.getState()==DaemonSingleton.State.stopped){ |
|
|
|
if(daemon.getState()==DaemonSingleton.State.stopped){ |
|
|
|
Toast.makeText(this, R.string.already_stopped, |
|
|
|
Toast.makeText(this, R.string.already_stopped, |
|
|
|
Toast.LENGTH_SHORT).show(); |
|
|
|
Toast.LENGTH_SHORT).show(); |
|
|
@ -218,18 +217,14 @@ public class I2PDActivity extends Activity { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
},"gracQuitInit").start(); |
|
|
|
},"gracInit").start(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Timer getGracefulQuitTimer() { |
|
|
|
private Timer getGracefulQuitTimer() { |
|
|
|
synchronized (gracefulQuitTimerLock) { |
|
|
|
return gracefulQuitTimer; |
|
|
|
return gracefulQuitTimer; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void setGracefulQuitTimer(Timer gracefulQuitTimer) { |
|
|
|
private void setGracefulQuitTimer(Timer gracefulQuitTimer) { |
|
|
|
synchronized (gracefulQuitTimerLock) { |
|
|
|
this.gracefulQuitTimer = gracefulQuitTimer; |
|
|
|
this.gracefulQuitTimer = gracefulQuitTimer; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|