Fix tunnel details IAE, expose errors to user

This commit is contained in:
str4d
2017-08-18 21:30:53 +00:00
parent 4f5b0bd21a
commit b140158b24
2 changed files with 15 additions and 2 deletions

View File

@ -5,11 +5,13 @@ import android.os.Bundle;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceGroup;
import android.support.v7.preference.PreferenceScreen;
import android.widget.Toast;
import net.i2p.I2PAppContext;
import net.i2p.android.i2ptunnel.util.TunnelUtil;
import net.i2p.android.preferences.util.CustomPreferenceFragment;
import net.i2p.android.router.R;
import net.i2p.android.router.util.Util;
import net.i2p.i2ptunnel.TunnelControllerGroup;
import net.i2p.i2ptunnel.ui.TunnelConfig;
@ -31,10 +33,20 @@ public abstract class BaseTunnelPreferenceFragment extends CustomPreferenceFragm
}
if (mGroup == null) {
// TODO Show error
Toast.makeText(getActivity().getApplicationContext(),
error, Toast.LENGTH_LONG).show();
getActivity().finish();
} else if (getArguments().containsKey(ARG_TUNNEL_ID)) {
mTunnelId = getArguments().getInt(ARG_TUNNEL_ID, 0);
TunnelUtil.writeTunnelToPreferences(getActivity(), mGroup, mTunnelId);
try {
TunnelUtil.writeTunnelToPreferences(getActivity(), mGroup, mTunnelId);
} catch (IllegalArgumentException e) {
// Tunnel doesn't exist, or the tunnel config file could not be read
Util.e("Could not load tunnel details", e);
Toast.makeText(getActivity().getApplicationContext(),
R.string.i2ptunnel_no_tunnel_details, Toast.LENGTH_LONG).show();
getActivity().finish();
}
// https://stackoverflow.com/questions/17880437/which-settings-file-does-preferencefragment-read-write
getPreferenceManager().setSharedPreferencesName(TunnelUtil.getPreferencesFilename(mTunnelId));
loadPreferences();

View File

@ -259,6 +259,7 @@
<string name="i2ptunnel_msg_tunnel_stopping">Stopping tunnel</string>
<string name="i2ptunnel_delete_confirm_message">Delete tunnel?</string>
<string name="i2ptunnel_delete_confirm_button">Delete tunnel</string>
<string name="i2ptunnel_no_tunnel_details">Could not load tunnel details</string>
<string name="i2ptunnel_wizard_k_client_server">Client or Server</string>
<string name="i2ptunnel_wizard_v_client">Client tunnel</string>