am a4491eaf
: Fix the vpnsetting NPE crash.
* commit 'a4491eafd45c460b0317e7962e24d47e3c4206fb': Fix the vpnsetting NPE crash.
This commit is contained in:
@@ -3142,5 +3142,7 @@ found in the list of installed applications.</string>
|
||||
<string name="enter_password">Enter password to decrypt storage</string>
|
||||
<!-- This is displayed when the password is entered incorrectly -->
|
||||
<string name="try_again">Sorry, try again</string>
|
||||
<!-- This error message is displayed when the vpn profile is going to be saved but the vpn service is busy [CHAR LIMIT=NONE] -->
|
||||
<string name="service_busy">Service busy, try again</string>
|
||||
|
||||
</resources>
|
||||
|
@@ -28,6 +28,7 @@ import android.net.vpn.L2tpIpsecProfile;
|
||||
import android.net.vpn.L2tpIpsecPskProfile;
|
||||
import android.net.vpn.L2tpProfile;
|
||||
import android.net.vpn.PptpProfile;
|
||||
import android.net.vpn.VpnManager;
|
||||
import android.net.vpn.VpnProfile;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcel;
|
||||
@@ -37,6 +38,7 @@ import android.text.TextUtils;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.Toast;
|
||||
|
||||
/**
|
||||
* The activity class for editing a new or existing VPN profile.
|
||||
@@ -48,6 +50,7 @@ public class VpnEditor extends SettingsPreferenceFragment {
|
||||
private static final String KEY_PROFILE = "profile";
|
||||
private static final String KEY_ORIGINAL_PROFILE_NAME = "orig_profile_name";
|
||||
|
||||
private VpnManager mVpnManager;
|
||||
private VpnProfileEditor mProfileEditor;
|
||||
private boolean mAddingProfile;
|
||||
private byte[] mOriginalProfileData;
|
||||
@@ -63,6 +66,7 @@ public class VpnEditor extends SettingsPreferenceFragment {
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
mVpnManager = new VpnManager(getActivity());
|
||||
|
||||
VpnProfile p;
|
||||
if (savedInstanceState != null) {
|
||||
@@ -111,8 +115,15 @@ public class VpnEditor extends SettingsPreferenceFragment {
|
||||
case MENU_SAVE:
|
||||
Intent resultIntent = validateAndGetResult();
|
||||
if (resultIntent != null) {
|
||||
((PreferenceActivity) getActivity()).finishPreferencePanel(
|
||||
this, Activity.RESULT_OK, resultIntent);
|
||||
PreferenceActivity activity =
|
||||
(PreferenceActivity) getActivity();
|
||||
if (!mVpnManager.isIdle()) {
|
||||
Toast.makeText(activity, R.string.service_busy,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
activity.finishPreferencePanel(this,
|
||||
Activity.RESULT_OK, resultIntent);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
|
@@ -131,7 +131,7 @@ public class VpnSettings extends SettingsPreferenceFragment
|
||||
|
||||
private int mConnectingErrorCode = NO_ERROR;
|
||||
|
||||
private Dialog mShowingDialog;
|
||||
private Dialog mShowingDialog, mConnectDialog;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
@@ -182,7 +182,6 @@ public class VpnSettings extends SettingsPreferenceFragment
|
||||
// for long-press gesture on a profile preference
|
||||
registerForContextMenu(getListView());
|
||||
|
||||
|
||||
retrieveVpnListFromStorage();
|
||||
restoreInstanceState(savedInstanceState);
|
||||
}
|
||||
@@ -208,7 +207,13 @@ public class VpnSettings extends SettingsPreferenceFragment
|
||||
mUnlockAction = null;
|
||||
getActivity().runOnUiThread(action);
|
||||
}
|
||||
if (mConnectDialog == null || !mConnectDialog.isShowing()) {
|
||||
checkVpnConnectionStatus();
|
||||
} else {
|
||||
// Dismiss the connect dialog in case there is another instance
|
||||
// trying to operate a vpn connection.
|
||||
if (!mVpnManager.isIdle()) removeConnectDialog();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -237,7 +242,8 @@ public class VpnSettings extends SettingsPreferenceFragment
|
||||
public Dialog onCreateDialog (int id) {
|
||||
switch (id) {
|
||||
case DIALOG_CONNECT:
|
||||
return createConnectDialog();
|
||||
mConnectDialog = createConnectDialog();
|
||||
return mConnectDialog;
|
||||
|
||||
case DIALOG_SECRET_NOT_SET:
|
||||
return createSecretNotSetDialog();
|
||||
@@ -253,11 +259,19 @@ public class VpnSettings extends SettingsPreferenceFragment
|
||||
}
|
||||
}
|
||||
|
||||
private void removeConnectDialog() {
|
||||
if (mConnectDialog != null) {
|
||||
mConnectDialog.dismiss();
|
||||
mConnectDialog = null;
|
||||
checkVpnConnectionStatus();
|
||||
}
|
||||
}
|
||||
|
||||
private class ConnectDialog extends AlertDialog {
|
||||
public ConnectDialog(Context context) {
|
||||
super(context);
|
||||
setTitle(String.format(getString(R.string.vpn_connect_to),
|
||||
mActiveProfile.getName()));
|
||||
mConnectingActor.getProfile().getName()));
|
||||
setButton(DialogInterface.BUTTON_POSITIVE,
|
||||
getString(R.string.vpn_connect_button),
|
||||
VpnSettings.this);
|
||||
@@ -498,11 +512,11 @@ public class VpnSettings extends SettingsPreferenceFragment
|
||||
String error = mConnectingActor.validateInputs(d);
|
||||
if (error == null) {
|
||||
mConnectingActor.connect(d);
|
||||
removeDialog(DIALOG_CONNECT);
|
||||
removeConnectDialog();
|
||||
return;
|
||||
} else {
|
||||
// dismissDialog(DIALOG_CONNECT);
|
||||
removeDialog(DIALOG_CONNECT);
|
||||
removeConnectDialog();
|
||||
|
||||
final Activity activity = getActivity();
|
||||
// show error dialog
|
||||
@@ -522,8 +536,7 @@ public class VpnSettings extends SettingsPreferenceFragment
|
||||
mShowingDialog.show();
|
||||
}
|
||||
} else {
|
||||
removeDialog(DIALOG_CONNECT);
|
||||
changeState(mActiveProfile, VpnState.IDLE);
|
||||
removeConnectDialog();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user