|
|
@ -5,11 +5,13 @@ import java.io.StringWriter; |
|
|
|
import java.util.Timer; |
|
|
|
import java.util.Timer; |
|
|
|
import java.util.TimerTask; |
|
|
|
import java.util.TimerTask; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint; |
|
|
|
import android.app.Activity; |
|
|
|
import android.app.Activity; |
|
|
|
import android.content.ComponentName; |
|
|
|
import android.content.ComponentName; |
|
|
|
import android.content.Context; |
|
|
|
import android.content.Context; |
|
|
|
import android.content.Intent; |
|
|
|
import android.content.Intent; |
|
|
|
import android.content.ServiceConnection; |
|
|
|
import android.content.ServiceConnection; |
|
|
|
|
|
|
|
import android.os.Build; |
|
|
|
import android.os.Bundle; |
|
|
|
import android.os.Bundle; |
|
|
|
import android.os.IBinder; |
|
|
|
import android.os.IBinder; |
|
|
|
import android.util.Log; |
|
|
|
import android.util.Log; |
|
|
@ -18,7 +20,7 @@ import android.view.MenuItem; |
|
|
|
import android.widget.TextView; |
|
|
|
import android.widget.TextView; |
|
|
|
import android.widget.Toast; |
|
|
|
import android.widget.Toast; |
|
|
|
|
|
|
|
|
|
|
|
public class I2PDActivity extends Activity { |
|
|
|
public class I2PD extends Activity { |
|
|
|
private static final String TAG = "i2pd"; |
|
|
|
private static final String TAG = "i2pd"; |
|
|
|
|
|
|
|
|
|
|
|
private TextView textView; |
|
|
|
private TextView textView; |
|
|
@ -79,11 +81,11 @@ public class I2PDActivity extends Activity { |
|
|
|
gracefulQuitTimer.cancel(); |
|
|
|
gracefulQuitTimer.cancel(); |
|
|
|
setGracefulQuitTimer(null); |
|
|
|
setGracefulQuitTimer(null); |
|
|
|
} |
|
|
|
} |
|
|
|
// try{
|
|
|
|
try{ |
|
|
|
// doUnbindService();
|
|
|
|
doUnbindService(); |
|
|
|
// }catch(Throwable tr){
|
|
|
|
}catch(Throwable tr){ |
|
|
|
// Log.e(TAG, "", tr);
|
|
|
|
Log.e(TAG, "", tr); |
|
|
|
// }
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private CharSequence throwableToString(Throwable tr) { |
|
|
|
private CharSequence throwableToString(Throwable tr) { |
|
|
@ -124,8 +126,7 @@ public class I2PDActivity extends Activity { |
|
|
|
|
|
|
|
|
|
|
|
private boolean mIsBound; |
|
|
|
private boolean mIsBound; |
|
|
|
|
|
|
|
|
|
|
|
private synchronized void doBindService() { |
|
|
|
private void doBindService() { |
|
|
|
if(mIsBound)return; |
|
|
|
|
|
|
|
// Establish a connection with the service. We use an explicit
|
|
|
|
// Establish a connection with the service. We use an explicit
|
|
|
|
// class name because we want a specific service implementation that
|
|
|
|
// class name because we want a specific service implementation that
|
|
|
|
// we know will be running in our own process (and thus won't be
|
|
|
|
// we know will be running in our own process (and thus won't be
|
|
|
@ -158,39 +159,48 @@ public class I2PDActivity extends Activity { |
|
|
|
int id = item.getItemId(); |
|
|
|
int id = item.getItemId(); |
|
|
|
|
|
|
|
|
|
|
|
switch(id){ |
|
|
|
switch(id){ |
|
|
|
case R.id.action_stop: |
|
|
|
case R.id.action_quit: |
|
|
|
i2pdStop(); |
|
|
|
quit(); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
case R.id.action_graceful_stop: |
|
|
|
case R.id.action_graceful_quit: |
|
|
|
i2pdGracefulStop(); |
|
|
|
gracefulQuit(); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return super.onOptionsItemSelected(item); |
|
|
|
return super.onOptionsItemSelected(item); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void i2pdStop() { |
|
|
|
@SuppressLint("NewApi") |
|
|
|
|
|
|
|
private void quit() { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { |
|
|
|
|
|
|
|
finishAndRemoveTask(); |
|
|
|
|
|
|
|
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { |
|
|
|
|
|
|
|
finishAffinity(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
//moveTaskToBack(true);
|
|
|
|
|
|
|
|
finish(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}catch (Throwable tr) { |
|
|
|
|
|
|
|
Log.e(TAG, "", tr); |
|
|
|
|
|
|
|
} |
|
|
|
try{ |
|
|
|
try{ |
|
|
|
daemon.stopDaemon(); |
|
|
|
daemon.stopDaemon(); |
|
|
|
}catch (Throwable tr) { |
|
|
|
}catch (Throwable tr) { |
|
|
|
Log.e(TAG, "", tr); |
|
|
|
Log.e(TAG, "", tr); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
System.exit(0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Timer gracefulQuitTimer; |
|
|
|
private Timer gracefulQuitTimer; |
|
|
|
private final Object gracefulQuitTimerLock = new Object(); |
|
|
|
private final Object gracefulQuitTimerLock = new Object(); |
|
|
|
private synchronized void i2pdGracefulStop() { |
|
|
|
private void gracefulQuit() { |
|
|
|
if(daemon.getState()==DaemonSingleton.State.stopped){ |
|
|
|
|
|
|
|
Toast.makeText(this, R.string.already_stopped, |
|
|
|
|
|
|
|
Toast.LENGTH_SHORT).show(); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(getGracefulQuitTimer()!=null){ |
|
|
|
if(getGracefulQuitTimer()!=null){ |
|
|
|
Toast.makeText(this, R.string.graceful_stop_is_already_in_progress, |
|
|
|
Toast.makeText(this, R.string.graceful_quit_is_already_in_progress, |
|
|
|
Toast.LENGTH_SHORT).show(); |
|
|
|
Toast.LENGTH_SHORT).show(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
Toast.makeText(this, R.string.graceful_stop_is_in_progress, |
|
|
|
Toast.makeText(this, R.string.graceful_quit_is_in_progress, |
|
|
|
Toast.LENGTH_SHORT).show(); |
|
|
|
Toast.LENGTH_SHORT).show(); |
|
|
|
new Thread(new Runnable(){ |
|
|
|
new Thread(new Runnable(){ |
|
|
|
|
|
|
|
|
|
|
@ -206,12 +216,12 @@ public class I2PDActivity extends Activity { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void run() { |
|
|
|
public void run() { |
|
|
|
i2pdStop(); |
|
|
|
quit(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}, 10*60*1000/*milliseconds*/); |
|
|
|
}, 10*60*1000/*milliseconds*/); |
|
|
|
}else{ |
|
|
|
}else{ |
|
|
|
i2pdStop(); |
|
|
|
quit(); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch(Throwable tr) { |
|
|
|
} catch(Throwable tr) { |
|
|
|
Log.e(TAG,"",tr); |
|
|
|
Log.e(TAG,"",tr); |