Inform user that changing uPnP setting will require a router restart
This commit is contained in:
@ -9,6 +9,7 @@ import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceCategory;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.widget.Toast;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.android.router.service.StatSummarizer;
|
||||
@ -160,6 +161,8 @@ public class SettingsActivity extends PreferenceActivity {
|
||||
Properties props = lProps.get(0);
|
||||
Properties logSettings = lProps.get(1);
|
||||
|
||||
boolean restartRequired = Util.checkAndCorrectRouterConfig(this, props);
|
||||
|
||||
// Apply new config if we are running.
|
||||
RouterContext rCtx = Util.getRouterContext();
|
||||
if (rCtx != null) {
|
||||
@ -177,6 +180,9 @@ public class SettingsActivity extends PreferenceActivity {
|
||||
|
||||
// Store the settings in Android
|
||||
super.onPause();
|
||||
|
||||
if (restartRequired)
|
||||
Toast.makeText(this, R.string.settings_router_restart_required, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
private void saveLoggingChanges(I2PAppContext ctx, Properties logSettings) {
|
||||
|
@ -10,6 +10,7 @@ import android.preference.PreferenceManager;
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.router.RouterContext;
|
||||
import net.i2p.router.transport.TransportManager;
|
||||
import net.i2p.util.OrderedProperties;
|
||||
|
||||
import java.io.File;
|
||||
@ -179,6 +180,37 @@ public abstract class Util {
|
||||
return pList;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function performs two tasks:
|
||||
* <ul><li>
|
||||
* The Properties object is modified to ensure that all options are valid
|
||||
* for the current state of the Android device (e.g. what type of network
|
||||
* the device is connected to).
|
||||
* </li><li>
|
||||
* The Properties object is checked to determine whether any options have
|
||||
* changed that will require a router restart.
|
||||
* </li></ul>
|
||||
*
|
||||
* @param props a Properties object containing the router.config
|
||||
* @return true if the router needs to be restarted.
|
||||
*/
|
||||
public static boolean checkAndCorrectRouterConfig(Context context, Properties props) {
|
||||
// Disable UPnP on mobile networks, ignoring user's configuration
|
||||
boolean upnpEnabled = Boolean.parseBoolean(props.getProperty(TransportManager.PROP_ENABLE_UPNP, Boolean.toString(true)));
|
||||
if (Connectivity.isConnectedMobile(context)) {
|
||||
upnpEnabled = false;
|
||||
props.setProperty(TransportManager.PROP_ENABLE_UPNP, Boolean.toString(upnpEnabled));
|
||||
}
|
||||
|
||||
// Now check if a restart is required
|
||||
boolean restartRequired = false;
|
||||
RouterContext rCtx = getRouterContext();
|
||||
if (rCtx != null) {
|
||||
restartRequired = upnpEnabled != rCtx.getBooleanPropertyDefaultTrue(TransportManager.PROP_ENABLE_UPNP);
|
||||
}
|
||||
return restartRequired;
|
||||
}
|
||||
|
||||
public static String getFileDir(Context context) {
|
||||
// This needs to be changed so that we can have an alternative place
|
||||
return context.getFilesDir().getAbsolutePath();
|
||||
|
@ -116,6 +116,8 @@
|
||||
<string name="settings_summ_expl_backupQuantity">%s tunnels</string>
|
||||
<string name="settings_desc_expl_backupQuantity">How many tunnel backups</string>
|
||||
|
||||
<string name="settings_router_restart_required">Please restart I2P to apply the changes</string>
|
||||
|
||||
<string name="menu_about">About</string>
|
||||
<string name="about_version">Version:</string>
|
||||
<string name="about_project">Project Home:</string>
|
||||
|
Reference in New Issue
Block a user