Browse Source

Merge pull request #1410 from nonlinear-chaos-order-etc/openssl

android various fixes and improvements
pull/1413/head
orignal 5 years ago committed by GitHub
parent
commit
478d7b4a83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      android/res/values-ru/strings.xml
  2. 1
      android/res/values/strings.xml
  3. 67
      android/src/org/purplei2p/i2pd/I2PDActivity.java

1
android/res/values-ru/strings.xml

@ -24,4 +24,5 @@
<string name="battery_optimizations_enabled_dialog" >Ваша операционная система осуществляет оптимизации расхода аккумулятора, которые могут приводить к выгрузке I2PD из памяти и прекращению его работы с целью сэкономить заряд аккумулятора.\n\nВам сейчас будет предложено разрешить отключение этих оптимизаций.</string> <string name="battery_optimizations_enabled_dialog" >Ваша операционная система осуществляет оптимизации расхода аккумулятора, которые могут приводить к выгрузке I2PD из памяти и прекращению его работы с целью сэкономить заряд аккумулятора.\n\nВам сейчас будет предложено разрешить отключение этих оптимизаций.</string>
<string name="continue_str">Продолжить</string> <string name="continue_str">Продолжить</string>
<string name="os_version_does_not_support_battery_optimizations_show_os_dialog_api">Ваша версия Андроид не поддерживает показ диалога об оптимизациях аккумулятора для приложений.</string> <string name="os_version_does_not_support_battery_optimizations_show_os_dialog_api">Ваша версия Андроид не поддерживает показ диалога об оптимизациях аккумулятора для приложений.</string>
<string name="shutdown_canceled">Плановая остановка отменена</string>
</resources> </resources>

1
android/res/values/strings.xml

@ -24,4 +24,5 @@
<string name="device_does_not_support_disabling_battery_optimizations">Your Android version does not support opting out of battery optimizations</string> <string name="device_does_not_support_disabling_battery_optimizations">Your Android version does not support opting out of battery optimizations</string>
<string name="menu_item_battery_optimizations_str">Battery Optimizations</string> <string name="menu_item_battery_optimizations_str">Battery Optimizations</string>
<string name="os_version_does_not_support_battery_optimizations_show_os_dialog_api">Your Android OS version does not support showing the dialog for battery optimizations for applications.</string> <string name="os_version_does_not_support_battery_optimizations_show_os_dialog_api">Your Android OS version does not support showing the dialog for battery optimizations for applications.</string>
<string name="shutdown_canceled">Planned shutdown canceled</string>
</resources> </resources>

67
android/src/org/purplei2p/i2pd/I2PDActivity.java

@ -44,7 +44,6 @@ import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
// For future package update checking // For future package update checking
import org.purplei2p.i2pd.BuildConfig;
import static android.provider.Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS; import static android.provider.Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS;
@ -86,6 +85,7 @@ public class I2PDActivity extends Activity {
}; };
private static volatile long graceStartedMillis; private static volatile long graceStartedMillis;
private static final Object graceStartedMillis_LOCK=new Object(); private static final Object graceStartedMillis_LOCK=new Object();
private Menu optionsMenu;
private static String formatGraceTimeRemaining() { private static String formatGraceTimeRemaining() {
long remainingSeconds; long remainingSeconds;
@ -138,7 +138,7 @@ public class I2PDActivity extends Activity {
super.onDestroy(); super.onDestroy();
textView = null; textView = null;
daemon.removeStateChangeListener(daemonStateUpdatedListener); daemon.removeStateChangeListener(daemonStateUpdatedListener);
//cancelGracefulStop(); //cancelGracefulStop0();
try{ try{
doUnbindService(); doUnbindService();
}catch(Throwable tr){ }catch(Throwable tr){
@ -160,7 +160,7 @@ public class I2PDActivity extends Activity {
} }
} }
private static void cancelGracefulStop() { private void cancelGracefulStop0() {
Timer gracefulQuitTimer = getGracefulQuitTimer(); Timer gracefulQuitTimer = getGracefulQuitTimer();
if(gracefulQuitTimer!=null) { if(gracefulQuitTimer!=null) {
gracefulQuitTimer.cancel(); gracefulQuitTimer.cancel();
@ -232,6 +232,7 @@ public class I2PDActivity extends Activity {
// Inflate the menu; this adds items to the action bar if it is present. // Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.options_main, menu); getMenuInflater().inflate(R.menu.options_main, menu);
menu.findItem(R.id.action_battery_otimizations).setVisible(isBatteryOptimizationsOpenOsDialogApiAvailable()); menu.findItem(R.id.action_battery_otimizations).setVisible(isBatteryOptimizationsOpenOsDialogApiAvailable());
this.optionsMenu = menu;
return true; return true;
} }
@ -251,14 +252,10 @@ public class I2PDActivity extends Activity {
i2pdStop(); i2pdStop();
return true; return true;
case R.id.action_graceful_stop: case R.id.action_graceful_stop:
synchronized (graceStartedMillis_LOCK) {
if (getGracefulQuitTimer() != null) if (getGracefulQuitTimer() != null)
{ cancelGracefulStop();
item.setTitle(R.string.action_graceful_stop);
i2pdCancelGracefulStop ();
}
else else
{
item.setTitle(R.string.action_cancel_graceful_stop);
i2pdGracefulStop(); i2pdGracefulStop();
} }
return true; return true;
@ -282,7 +279,7 @@ public class I2PDActivity extends Activity {
} }
private void i2pdStop() { private void i2pdStop() {
cancelGracefulStop(); cancelGracefulStop0();
new Thread(() -> { new Thread(() -> {
Log.d(TAG, "stopping"); Log.d(TAG, "stopping");
try { try {
@ -329,16 +326,17 @@ public class I2PDActivity extends Activity {
},"gracInit").start(); },"gracInit").start();
} }
private void i2pdCancelGracefulStop() private void cancelGracefulStop()
{ {
cancelGracefulStop(); cancelGracefulStop0();
Toast.makeText(this, R.string.startedOkay, Toast.LENGTH_SHORT).show();
new Thread(() -> { new Thread(() -> {
try try
{ {
Log.d(TAG, "grac stopping cancel"); Log.d(TAG, "canceling grac stop");
if(daemon.isStartedOkay()) if(daemon.isStartedOkay()) {
daemon.startAcceptingTunnels(); daemon.startAcceptingTunnels();
runOnUiThread(() -> Toast.makeText(this, R.string.shutdown_canceled, Toast.LENGTH_SHORT).show());
}
else else
i2pdStop(); i2pdStop();
} }
@ -374,8 +372,19 @@ public class I2PDActivity extends Activity {
return gracefulQuitTimer; return gracefulQuitTimer;
} }
private static void setGracefulQuitTimer(Timer gracefulQuitTimer) { private void setGracefulQuitTimer(Timer gracefulQuitTimer) {
I2PDActivity.gracefulQuitTimer = gracefulQuitTimer; I2PDActivity.gracefulQuitTimer = gracefulQuitTimer;
runOnUiThread(()-> {
Menu menu = optionsMenu;
if (menu != null) {
MenuItem item = menu.findItem(R.id.action_graceful_stop);
if (item != null) {
synchronized (graceStartedMillis_LOCK) {
item.setTitle(getGracefulQuitTimer() != null ? R.string.action_cancel_graceful_stop : R.string.action_graceful_stop);
}
}
}
});
} }
/** /**
@ -398,20 +407,22 @@ public class I2PDActivity extends Activity {
// to a file. That doesn't appear to be the case. If the returned array is // to a file. That doesn't appear to be the case. If the returned array is
// null or has 0 length, we assume the path is to a file. This means empty // null or has 0 length, we assume the path is to a file. This means empty
// directories will get turned into files. // directories will get turned into files.
if (contents == null || contents.length == 0) if (contents == null || contents.length == 0) {
throw new IOException(); copyFileAsset(path);
return;
}
// Make the directory. // Make the directory.
File dir = new File(i2pdpath, path); File dir = new File(i2pdpath, path);
Log.d(TAG, "dir.mkdirs() returned "+dir.mkdirs()); boolean result = dir.mkdirs();
Log.d(TAG, "dir.mkdirs() returned " + result);
// Recurse on the contents. // Recurse on the contents.
for (String entry : contents) { for (String entry : contents) {
copyAsset(path + "/" + entry); copyAsset(path + '/' + entry);
} }
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG,"ex ignored", e); Log.e(TAG, "ex ignored for path='" + path + "'", e);
copyFileAsset(path);
} }
} }
@ -424,21 +435,23 @@ public class I2PDActivity extends Activity {
*/ */
private void copyFileAsset(String path) { private void copyFileAsset(String path) {
File file = new File(i2pdpath, path); File file = new File(i2pdpath, path);
if(!file.exists()) try { if(!file.exists()) {
InputStream in = getAssets().open(path); try {
OutputStream out = new FileOutputStream(file); try (InputStream in = getAssets().open(path) ) {
try (OutputStream out = new FileOutputStream(file)) {
byte[] buffer = new byte[1024]; byte[] buffer = new byte[1024];
int read = in.read(buffer); int read = in.read(buffer);
while (read != -1) { while (read != -1) {
out.write(buffer, 0, read); out.write(buffer, 0, read);
read = in.read(buffer); read = in.read(buffer);
} }
out.close(); }
in.close(); }
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "", e); Log.e(TAG, "", e);
} }
} }
}
private void deleteRecursive(File fileOrDirectory) { private void deleteRecursive(File fileOrDirectory) {
if (fileOrDirectory.isDirectory()) { if (fileOrDirectory.isDirectory()) {

Loading…
Cancel
Save