|
|
@ -107,7 +107,7 @@ public class I2PDActivity extends Activity { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onCreate(Bundle savedInstanceState) { |
|
|
|
public void onCreate(Bundle savedInstanceState) { |
|
|
|
Log.i(TAG, "onCreate"); |
|
|
|
Log.d(TAG, "onCreate"); |
|
|
|
super.onCreate(savedInstanceState); |
|
|
|
super.onCreate(savedInstanceState); |
|
|
|
setContentView(R.layout.activity_main); |
|
|
|
setContentView(R.layout.activity_main); |
|
|
|
|
|
|
|
|
|
|
@ -173,11 +173,10 @@ public class I2PDActivity extends Activity { |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (requestCode == MY_PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE) { |
|
|
|
if (requestCode == MY_PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE) { |
|
|
|
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) |
|
|
|
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) |
|
|
|
Log.e(TAG, "WR_EXT_STORAGE perm granted"); |
|
|
|
Log.w(TAG, "WR_EXT_STORAGE perm granted"); |
|
|
|
else { |
|
|
|
else { |
|
|
|
Log.e(TAG, "WR_EXT_STORAGE perm declined, stopping i2pd"); |
|
|
|
Log.e(TAG, "WR_EXT_STORAGE perm declined, stopping i2pd"); |
|
|
|
i2pdStop(); |
|
|
|
i2pdStop(); |
|
|
|
//TODO must work w/o this perm, ask orignal
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -318,14 +317,14 @@ public class I2PDActivity extends Activity { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void onReloadTunnelsConfig() { |
|
|
|
private void onReloadTunnelsConfig() { |
|
|
|
Log.d(TAG, "reloading tunnels"); |
|
|
|
Log.i(TAG, "reloading tunnels"); |
|
|
|
daemon.reloadTunnelsConfigs(); |
|
|
|
daemon.reloadTunnelsConfigs(); |
|
|
|
Toast.makeText(this, R.string.tunnels_reloading, Toast.LENGTH_SHORT).show(); |
|
|
|
Toast.makeText(this, R.string.tunnels_reloading, Toast.LENGTH_SHORT).show(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void i2pdStop() { |
|
|
|
private void i2pdStop() { |
|
|
|
cancelGracefulStop0(); |
|
|
|
cancelGracefulStop0(); |
|
|
|
Log.d(TAG, "stopping"); |
|
|
|
Log.i(TAG, "stopping"); |
|
|
|
textView.setText(getText(R.string.stopping)); |
|
|
|
textView.setText(getText(R.string.stopping)); |
|
|
|
new Thread(() -> { |
|
|
|
new Thread(() -> { |
|
|
|
try { |
|
|
|
try { |
|
|
@ -351,7 +350,7 @@ public class I2PDActivity extends Activity { |
|
|
|
Toast.makeText(this, R.string.graceful_stop_is_in_progress, Toast.LENGTH_SHORT).show(); |
|
|
|
Toast.makeText(this, R.string.graceful_stop_is_in_progress, Toast.LENGTH_SHORT).show(); |
|
|
|
new Thread(() -> { |
|
|
|
new Thread(() -> { |
|
|
|
try { |
|
|
|
try { |
|
|
|
Log.d(TAG, "graceful stopping"); |
|
|
|
Log.i(TAG, "graceful stopping"); |
|
|
|
if (daemon.isStartedOkay()) { |
|
|
|
if (daemon.isStartedOkay()) { |
|
|
|
daemon.stopAcceptingTunnels(); |
|
|
|
daemon.stopAcceptingTunnels(); |
|
|
|
long gracefulStopAtMillis; |
|
|
|
long gracefulStopAtMillis; |
|
|
@ -373,7 +372,7 @@ public class I2PDActivity extends Activity { |
|
|
|
cancelGracefulStop0(); |
|
|
|
cancelGracefulStop0(); |
|
|
|
new Thread(() -> { |
|
|
|
new Thread(() -> { |
|
|
|
try { |
|
|
|
try { |
|
|
|
Log.d(TAG, "canceling graceful stop"); |
|
|
|
Log.i(TAG, "canceling graceful stop"); |
|
|
|
if (daemon.isStartedOkay()) { |
|
|
|
if (daemon.isStartedOkay()) { |
|
|
|
daemon.startAcceptingTunnels(); |
|
|
|
daemon.startAcceptingTunnels(); |
|
|
|
runOnUiThread(() -> Toast.makeText(this, R.string.shutdown_canceled, Toast.LENGTH_SHORT).show()); |
|
|
|
runOnUiThread(() -> Toast.makeText(this, R.string.shutdown_canceled, Toast.LENGTH_SHORT).show()); |
|
|
@ -390,7 +389,7 @@ public class I2PDActivity extends Activity { |
|
|
|
gracefulQuitTimerOld.cancel(); |
|
|
|
gracefulQuitTimerOld.cancel(); |
|
|
|
|
|
|
|
|
|
|
|
if (daemon.getTransitTunnelsCount() <= 0) { // no tunnels left
|
|
|
|
if (daemon.getTransitTunnelsCount() <= 0) { // no tunnels left
|
|
|
|
Log.d(TAG, "no transit tunnels left, stopping"); |
|
|
|
Log.i(TAG, "no transit tunnels left, stopping"); |
|
|
|
i2pdStop(); |
|
|
|
i2pdStop(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -436,7 +435,7 @@ public class I2PDActivity extends Activity { |
|
|
|
@SuppressLint("BatteryLife") |
|
|
|
@SuppressLint("BatteryLife") |
|
|
|
private void openBatteryOptimizationDialogIfNeeded() { |
|
|
|
private void openBatteryOptimizationDialogIfNeeded() { |
|
|
|
boolean questionEnabled = getPreferences().getBoolean(getBatteryOptimizationPreferenceKey(), true); |
|
|
|
boolean questionEnabled = getPreferences().getBoolean(getBatteryOptimizationPreferenceKey(), true); |
|
|
|
Log.i(TAG, "BATT_OPTIM_questionEnabled==" + questionEnabled); |
|
|
|
Log.d(TAG, "BATT_OPTIM_questionEnabled==" + questionEnabled); |
|
|
|
if (!isKnownIgnoringBatteryOptimizations() |
|
|
|
if (!isKnownIgnoringBatteryOptimizations() |
|
|
|
&& android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M |
|
|
|
&& android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M |
|
|
|
&& questionEnabled) { |
|
|
|
&& questionEnabled) { |
|
|
@ -466,14 +465,14 @@ public class I2PDActivity extends Activity { |
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |
|
|
|
final PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); |
|
|
|
final PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); |
|
|
|
if (pm == null) { |
|
|
|
if (pm == null) { |
|
|
|
Log.i(TAG, "BATT_OPTIM: POWER_SERVICE==null"); |
|
|
|
Log.d(TAG, "BATT_OPTIM: POWER_SERVICE==null"); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
boolean ignoring = pm.isIgnoringBatteryOptimizations(getPackageName()); |
|
|
|
boolean ignoring = pm.isIgnoringBatteryOptimizations(getPackageName()); |
|
|
|
Log.i(TAG, "BATT_OPTIM: ignoring==" + ignoring); |
|
|
|
Log.d(TAG, "BATT_OPTIM: ignoring==" + ignoring); |
|
|
|
return ignoring; |
|
|
|
return ignoring; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
Log.i(TAG, "BATT_OPTIM: old SDK version==" + Build.VERSION.SDK_INT); |
|
|
|
Log.d(TAG, "BATT_OPTIM: old SDK version==" + Build.VERSION.SDK_INT); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|