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

1
android/res/values/strings.xml

@ -24,4 +24,5 @@ @@ -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="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="shutdown_canceled">Planned shutdown canceled</string>
</resources>

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

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

Loading…
Cancel
Save