am a4491eaf: Fix the vpnsetting NPE crash.

* commit 'a4491eafd45c460b0317e7962e24d47e3c4206fb':
  Fix the vpnsetting NPE crash.
This commit is contained in:
Chung-yih Wang
2011-01-20 02:40:42 -08:00
committed by Android Git Automerger
3 changed files with 37 additions and 11 deletions

View File

@@ -3142,5 +3142,7 @@ found in the list of installed applications.</string>
<string name="enter_password">Enter password to decrypt storage</string> <string name="enter_password">Enter password to decrypt storage</string>
<!-- This is displayed when the password is entered incorrectly --> <!-- This is displayed when the password is entered incorrectly -->
<string name="try_again">Sorry, try again</string> <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> </resources>

View File

@@ -28,6 +28,7 @@ import android.net.vpn.L2tpIpsecProfile;
import android.net.vpn.L2tpIpsecPskProfile; import android.net.vpn.L2tpIpsecPskProfile;
import android.net.vpn.L2tpProfile; import android.net.vpn.L2tpProfile;
import android.net.vpn.PptpProfile; import android.net.vpn.PptpProfile;
import android.net.vpn.VpnManager;
import android.net.vpn.VpnProfile; import android.net.vpn.VpnProfile;
import android.os.Bundle; import android.os.Bundle;
import android.os.Parcel; import android.os.Parcel;
@@ -37,6 +38,7 @@ import android.text.TextUtils;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.widget.Toast;
/** /**
* The activity class for editing a new or existing VPN profile. * 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_PROFILE = "profile";
private static final String KEY_ORIGINAL_PROFILE_NAME = "orig_profile_name"; private static final String KEY_ORIGINAL_PROFILE_NAME = "orig_profile_name";
private VpnManager mVpnManager;
private VpnProfileEditor mProfileEditor; private VpnProfileEditor mProfileEditor;
private boolean mAddingProfile; private boolean mAddingProfile;
private byte[] mOriginalProfileData; private byte[] mOriginalProfileData;
@@ -63,6 +66,7 @@ public class VpnEditor extends SettingsPreferenceFragment {
@Override @Override
public void onActivityCreated(Bundle savedInstanceState) { public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
mVpnManager = new VpnManager(getActivity());
VpnProfile p; VpnProfile p;
if (savedInstanceState != null) { if (savedInstanceState != null) {
@@ -111,8 +115,15 @@ public class VpnEditor extends SettingsPreferenceFragment {
case MENU_SAVE: case MENU_SAVE:
Intent resultIntent = validateAndGetResult(); Intent resultIntent = validateAndGetResult();
if (resultIntent != null) { if (resultIntent != null) {
((PreferenceActivity) getActivity()).finishPreferencePanel( PreferenceActivity activity =
this, Activity.RESULT_OK, resultIntent); (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; return true;

View File

@@ -131,7 +131,7 @@ public class VpnSettings extends SettingsPreferenceFragment
private int mConnectingErrorCode = NO_ERROR; private int mConnectingErrorCode = NO_ERROR;
private Dialog mShowingDialog; private Dialog mShowingDialog, mConnectDialog;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@@ -182,7 +182,6 @@ public class VpnSettings extends SettingsPreferenceFragment
// for long-press gesture on a profile preference // for long-press gesture on a profile preference
registerForContextMenu(getListView()); registerForContextMenu(getListView());
retrieveVpnListFromStorage(); retrieveVpnListFromStorage();
restoreInstanceState(savedInstanceState); restoreInstanceState(savedInstanceState);
} }
@@ -208,7 +207,13 @@ public class VpnSettings extends SettingsPreferenceFragment
mUnlockAction = null; mUnlockAction = null;
getActivity().runOnUiThread(action); getActivity().runOnUiThread(action);
} }
checkVpnConnectionStatus(); 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 @Override
@@ -237,7 +242,8 @@ public class VpnSettings extends SettingsPreferenceFragment
public Dialog onCreateDialog (int id) { public Dialog onCreateDialog (int id) {
switch (id) { switch (id) {
case DIALOG_CONNECT: case DIALOG_CONNECT:
return createConnectDialog(); mConnectDialog = createConnectDialog();
return mConnectDialog;
case DIALOG_SECRET_NOT_SET: case DIALOG_SECRET_NOT_SET:
return createSecretNotSetDialog(); 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 { private class ConnectDialog extends AlertDialog {
public ConnectDialog(Context context) { public ConnectDialog(Context context) {
super(context); super(context);
setTitle(String.format(getString(R.string.vpn_connect_to), setTitle(String.format(getString(R.string.vpn_connect_to),
mActiveProfile.getName())); mConnectingActor.getProfile().getName()));
setButton(DialogInterface.BUTTON_POSITIVE, setButton(DialogInterface.BUTTON_POSITIVE,
getString(R.string.vpn_connect_button), getString(R.string.vpn_connect_button),
VpnSettings.this); VpnSettings.this);
@@ -498,11 +512,11 @@ public class VpnSettings extends SettingsPreferenceFragment
String error = mConnectingActor.validateInputs(d); String error = mConnectingActor.validateInputs(d);
if (error == null) { if (error == null) {
mConnectingActor.connect(d); mConnectingActor.connect(d);
removeDialog(DIALOG_CONNECT); removeConnectDialog();
return; return;
} else { } else {
// dismissDialog(DIALOG_CONNECT); // dismissDialog(DIALOG_CONNECT);
removeDialog(DIALOG_CONNECT); removeConnectDialog();
final Activity activity = getActivity(); final Activity activity = getActivity();
// show error dialog // show error dialog
@@ -522,8 +536,7 @@ public class VpnSettings extends SettingsPreferenceFragment
mShowingDialog.show(); mShowingDialog.show();
} }
} else { } else {
removeDialog(DIALOG_CONNECT); removeConnectDialog();
changeState(mActiveProfile, VpnState.IDLE);
} }
} }