Fragmentize VpnSettings and relevant Activities.
Add startFragment() to SettingsFragmentPreference. Change-Id: Ifab93b2e68892d5f6da559f337c94d62629780c8
This commit is contained in:
@@ -197,10 +197,10 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity-alias>
|
</activity-alias>
|
||||||
|
|
||||||
<activity android:name=".vpn.VpnSettings"
|
<activity-alias android:name=".vpn.VpnSettings"
|
||||||
android:label="@string/vpn_settings_title"
|
|
||||||
android:configChanges="orientation|keyboardHidden"
|
android:configChanges="orientation|keyboardHidden"
|
||||||
android:clearTaskOnLaunch="true">
|
android:clearTaskOnLaunch="true"
|
||||||
|
android:targetActivity="Settings">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
<action android:name="android.net.vpn.SETTINGS" />
|
<action android:name="android.net.vpn.SETTINGS" />
|
||||||
@@ -208,14 +208,7 @@
|
|||||||
<category android:name="android.intent.category.VOICE_LAUNCH" />
|
<category android:name="android.intent.category.VOICE_LAUNCH" />
|
||||||
<category android:name="com.android.settings.SHORTCUT" />
|
<category android:name="com.android.settings.SHORTCUT" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity-alias>
|
||||||
|
|
||||||
<activity android:name=".vpn.VpnTypeSelection"
|
|
||||||
android:configChanges="orientation|keyboardHidden">
|
|
||||||
</activity>
|
|
||||||
<activity android:name=".vpn.VpnEditor"
|
|
||||||
android:configChanges="orientation|keyboardHidden">
|
|
||||||
</activity>
|
|
||||||
|
|
||||||
<activity-alias android:name="DateTimeSettings"
|
<activity-alias android:name="DateTimeSettings"
|
||||||
android:label="@string/date_and_time"
|
android:label="@string/date_and_time"
|
||||||
|
@@ -59,13 +59,10 @@
|
|||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|
||||||
<PreferenceScreen
|
<PreferenceScreen
|
||||||
|
android:fragment="com.android.settings.vpn.VpnSettings"
|
||||||
android:key="vpn_settings"
|
android:key="vpn_settings"
|
||||||
android:title="@string/vpn_settings_title"
|
android:title="@string/vpn_settings_title"
|
||||||
android:summary="@string/vpn_settings_summary" >
|
android:summary="@string/vpn_settings_summary" >
|
||||||
<intent
|
|
||||||
android:action="android.intent.action.MAIN"
|
|
||||||
android:targetPackage="com.android.settings"
|
|
||||||
android:targetClass="com.android.settings.vpn.VpnSettings" />
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|
||||||
<PreferenceScreen
|
<PreferenceScreen
|
||||||
|
@@ -41,7 +41,8 @@ import java.util.ArrayList;
|
|||||||
*/
|
*/
|
||||||
public class Settings extends Activity
|
public class Settings extends Activity
|
||||||
implements PreferenceFragment.OnPreferenceStartFragmentCallback,
|
implements PreferenceFragment.OnPreferenceStartFragmentCallback,
|
||||||
SettingsPreferenceFragment.OnStateListener {
|
SettingsPreferenceFragment.OnStateListener,
|
||||||
|
SettingsPreferenceFragment.FragmentStarter {
|
||||||
|
|
||||||
private static final boolean DBG = false;
|
private static final boolean DBG = false;
|
||||||
|
|
||||||
@@ -143,7 +144,9 @@ public class Settings extends Activity
|
|||||||
if (DBG) Log.d(TAG, "showFragment");
|
if (DBG) Log.d(TAG, "showFragment");
|
||||||
Fragment f = Fragment.instantiate(this, fragmentClass, extras);
|
Fragment f = Fragment.instantiate(this, fragmentClass, extras);
|
||||||
if (f instanceof SettingsPreferenceFragment) {
|
if (f instanceof SettingsPreferenceFragment) {
|
||||||
((SettingsPreferenceFragment) f).setOnStateListener(this);
|
SettingsPreferenceFragment spf = (SettingsPreferenceFragment) f;
|
||||||
|
spf.setOnStateListener(this);
|
||||||
|
spf.setFragmentStarter(this);
|
||||||
}
|
}
|
||||||
mBreadCrumbs.clear();
|
mBreadCrumbs.clear();
|
||||||
getFragmentManager().popBackStack(BACK_STACK_PREFS, POP_BACK_STACK_INCLUSIVE);
|
getFragmentManager().popBackStack(BACK_STACK_PREFS, POP_BACK_STACK_INCLUSIVE);
|
||||||
@@ -176,9 +179,17 @@ public class Settings extends Activity
|
|||||||
|
|
||||||
public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
|
public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
|
||||||
if (DBG) Log.d(TAG, "onPreferenceStartFragment");
|
if (DBG) Log.d(TAG, "onPreferenceStartFragment");
|
||||||
Fragment f = Fragment.instantiate(this, pref.getFragment(), pref.getExtras());
|
return startFragment(caller, pref.getFragment(), -1, pref.getExtras());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean startFragment(
|
||||||
|
Fragment caller, String fragmentClass, int requestCode, Bundle extras) {
|
||||||
|
Fragment f = Fragment.instantiate(this, fragmentClass, extras);
|
||||||
|
caller.setTargetFragment(f, requestCode);
|
||||||
if (f instanceof SettingsPreferenceFragment) {
|
if (f instanceof SettingsPreferenceFragment) {
|
||||||
((SettingsPreferenceFragment) f).setOnStateListener(this);
|
SettingsPreferenceFragment spf = (SettingsPreferenceFragment) f;
|
||||||
|
spf.setOnStateListener(this);
|
||||||
|
spf.setFragmentStarter(this);
|
||||||
}
|
}
|
||||||
getFragmentManager().openTransaction().replace(R.id.prefs, f)
|
getFragmentManager().openTransaction().replace(R.id.prefs, f)
|
||||||
.addToBackStack(BACK_STACK_PREFS).commit();
|
.addToBackStack(BACK_STACK_PREFS).commit();
|
||||||
|
@@ -19,6 +19,7 @@ package com.android.settings;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.app.DialogFragment;
|
import android.app.DialogFragment;
|
||||||
|
import android.app.Fragment;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
@@ -58,6 +59,10 @@ public class SettingsPreferenceFragment extends PreferenceFragment
|
|||||||
private SettingsDialogFragment mDialogFragment;
|
private SettingsDialogFragment mDialogFragment;
|
||||||
|
|
||||||
private OnStateListener mOnStateListener;
|
private OnStateListener mOnStateListener;
|
||||||
|
private FragmentStarter mFragmentStarter;
|
||||||
|
|
||||||
|
private int mResultCode = Activity.RESULT_CANCELED;
|
||||||
|
private Intent mResultData;
|
||||||
|
|
||||||
private Button mNextButton;
|
private Button mNextButton;
|
||||||
|
|
||||||
@@ -74,6 +79,43 @@ public class SettingsPreferenceFragment extends PreferenceFragment
|
|||||||
mOnStateListener = listener;
|
mOnStateListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Letting the class, assumed to be Fragment, start another Fragment object.
|
||||||
|
* The target Fragment object is stored in the caller Fragment using
|
||||||
|
* {@link Fragment#setTargetFragment(Fragment, int)}. The caller
|
||||||
|
* is able to obtain result code and result data via
|
||||||
|
* {@link SettingsPreferenceFragment#getResultCode()} and
|
||||||
|
* {@link SettingsPreferenceFragment#getResultData()} accordingly.
|
||||||
|
*/
|
||||||
|
interface FragmentStarter {
|
||||||
|
public boolean startFragment(
|
||||||
|
Fragment caller, String fragmentClass, int requestCode, Bundle extras);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFragmentStarter(FragmentStarter starter) {
|
||||||
|
mFragmentStarter = starter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
|
||||||
|
final Fragment f = getTargetFragment();
|
||||||
|
final int requestCode = getTargetRequestCode();
|
||||||
|
|
||||||
|
// TargetFragment becomes invalid when this object is resumed. Notify it to
|
||||||
|
// FragmentManager. Without this code, FragmentManager wrongly take the TargetFragment
|
||||||
|
// as live, and throws IllegalStateException.
|
||||||
|
setTargetFragment(null, -1);
|
||||||
|
|
||||||
|
if (f != null && (f instanceof SettingsPreferenceFragment)) {
|
||||||
|
final SettingsPreferenceFragment spf = (SettingsPreferenceFragment)f;
|
||||||
|
final int resultCode = spf.getResultCode();
|
||||||
|
final Intent resultData = spf.getResultData();
|
||||||
|
onActivityResult(requestCode, resultCode, resultData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
@@ -86,6 +128,32 @@ public class SettingsPreferenceFragment extends PreferenceFragment
|
|||||||
setupButtonBar();
|
setupButtonBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final void setResult(int resultCode) {
|
||||||
|
mResultCode = resultCode;
|
||||||
|
mResultData = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void setResult(int resultCode, Intent data) {
|
||||||
|
mResultCode = resultCode;
|
||||||
|
mResultData = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final int getResultCode() {
|
||||||
|
return mResultCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final Intent getResultData() {
|
||||||
|
return mResultData;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The name is intentionally made different from Activity#finish(), so that
|
||||||
|
* users won't misunderstand its meaning.
|
||||||
|
*/
|
||||||
|
public final void finishFragment() {
|
||||||
|
getActivity().onBackPressed();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
@@ -179,6 +247,16 @@ public class SettingsPreferenceFragment extends PreferenceFragment
|
|||||||
getActivity().onBackPressed();
|
getActivity().onBackPressed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean startFragment(
|
||||||
|
Fragment caller, String fragmentClass, int requestCode, Bundle extras) {
|
||||||
|
if (mFragmentStarter != null) {
|
||||||
|
return mFragmentStarter.startFragment(caller, fragmentClass, requestCode, extras);
|
||||||
|
} else {
|
||||||
|
Log.w(TAG, "FragmentStarter is not set.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets up Button Bar possibly required in the Fragment. Probably available only in
|
* Sets up Button Bar possibly required in the Fragment. Probably available only in
|
||||||
* phones.
|
* phones.
|
||||||
|
@@ -17,7 +17,9 @@
|
|||||||
package com.android.settings.vpn;
|
package com.android.settings.vpn;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
@@ -27,22 +29,19 @@ 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.VpnProfile;
|
import android.net.vpn.VpnProfile;
|
||||||
import android.net.vpn.VpnType;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.preference.PreferenceActivity;
|
|
||||||
import android.preference.PreferenceGroup;
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.KeyEvent;
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The activity class for editing a new or existing VPN profile.
|
* The activity class for editing a new or existing VPN profile.
|
||||||
*/
|
*/
|
||||||
public class VpnEditor extends PreferenceActivity {
|
public class VpnEditor extends SettingsPreferenceFragment {
|
||||||
private static final int MENU_SAVE = Menu.FIRST;
|
private static final int MENU_SAVE = Menu.FIRST;
|
||||||
private static final int MENU_CANCEL = Menu.FIRST + 1;
|
private static final int MENU_CANCEL = Menu.FIRST + 1;
|
||||||
private static final int CONFIRM_DIALOG_ID = 0;
|
private static final int CONFIRM_DIALOG_ID = 0;
|
||||||
@@ -56,59 +55,75 @@ public class VpnEditor extends PreferenceActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
VpnProfile p = (VpnProfile) ((savedInstanceState == null)
|
|
||||||
? getIntent().getParcelableExtra(VpnSettings.KEY_VPN_PROFILE)
|
|
||||||
: savedInstanceState.getParcelable(KEY_PROFILE));
|
|
||||||
mProfileEditor = getEditor(p);
|
|
||||||
mAddingProfile = TextUtils.isEmpty(p.getName());
|
|
||||||
|
|
||||||
// Loads the XML preferences file
|
// Loads the XML preferences file
|
||||||
addPreferencesFromResource(R.xml.vpn_edit);
|
addPreferencesFromResource(R.xml.vpn_edit);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
|
||||||
|
VpnProfile p;
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
p = (VpnProfile)savedInstanceState.getParcelable(KEY_PROFILE);
|
||||||
|
} else {
|
||||||
|
p = (VpnProfile)getArguments().getParcelable(VpnSettings.KEY_VPN_PROFILE);
|
||||||
|
if (p == null) {
|
||||||
|
p = getActivity().getIntent().getParcelableExtra(VpnSettings.KEY_VPN_PROFILE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mProfileEditor = getEditor(p);
|
||||||
|
mAddingProfile = TextUtils.isEmpty(p.getName());
|
||||||
|
|
||||||
initViewFor(p);
|
initViewFor(p);
|
||||||
|
|
||||||
Parcel parcel = Parcel.obtain();
|
Parcel parcel = Parcel.obtain();
|
||||||
p.writeToParcel(parcel, 0);
|
p.writeToParcel(parcel, 0);
|
||||||
mOriginalProfileData = parcel.marshall();
|
mOriginalProfileData = parcel.marshall();
|
||||||
|
|
||||||
|
registerForContextMenu(getListView());
|
||||||
|
setHasOptionsMenu(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected synchronized void onSaveInstanceState(Bundle outState) {
|
public synchronized void onSaveInstanceState(Bundle outState) {
|
||||||
if (mProfileEditor == null) return;
|
if (mProfileEditor == null) return;
|
||||||
|
|
||||||
outState.putParcelable(KEY_PROFILE, getProfile());
|
outState.putParcelable(KEY_PROFILE, getProfile());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
super.onCreateOptionsMenu(menu);
|
super.onCreateOptionsMenu(menu, inflater);
|
||||||
menu.add(0, MENU_SAVE, 0, R.string.vpn_menu_done)
|
menu.add(0, MENU_SAVE, 0, R.string.vpn_menu_done)
|
||||||
.setIcon(android.R.drawable.ic_menu_save);
|
.setIcon(android.R.drawable.ic_menu_save);
|
||||||
menu.add(0, MENU_CANCEL, 0,
|
menu.add(0, MENU_CANCEL, 0,
|
||||||
mAddingProfile ? R.string.vpn_menu_cancel
|
mAddingProfile ? R.string.vpn_menu_cancel
|
||||||
: R.string.vpn_menu_revert)
|
: R.string.vpn_menu_revert)
|
||||||
.setIcon(android.R.drawable.ic_menu_close_clear_cancel);
|
.setIcon(android.R.drawable.ic_menu_close_clear_cancel);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case MENU_SAVE:
|
case MENU_SAVE:
|
||||||
if (validateAndSetResult()) finish();
|
if (validateAndSetResult()) finishFragment();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case MENU_CANCEL:
|
case MENU_CANCEL:
|
||||||
if (profileChanged()) {
|
if (profileChanged()) {
|
||||||
showDialog(CONFIRM_DIALOG_ID);
|
showDialog(CONFIRM_DIALOG_ID);
|
||||||
} else {
|
} else {
|
||||||
finish();
|
finishFragment();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
@Override
|
@Override
|
||||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||||
switch (keyCode) {
|
switch (keyCode) {
|
||||||
@@ -117,7 +132,7 @@ public class VpnEditor extends PreferenceActivity {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return super.onKeyDown(keyCode, event);
|
return super.onKeyDown(keyCode, event);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
private void initViewFor(VpnProfile profile) {
|
private void initViewFor(VpnProfile profile) {
|
||||||
setTitle(profile);
|
setTitle(profile);
|
||||||
@@ -125,10 +140,11 @@ public class VpnEditor extends PreferenceActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setTitle(VpnProfile profile) {
|
private void setTitle(VpnProfile profile) {
|
||||||
|
final Activity activity = getActivity();
|
||||||
String formatString = mAddingProfile
|
String formatString = mAddingProfile
|
||||||
? getString(R.string.vpn_edit_title_add)
|
? activity.getString(R.string.vpn_edit_title_add)
|
||||||
: getString(R.string.vpn_edit_title_edit);
|
: activity.getString(R.string.vpn_edit_title_edit);
|
||||||
setTitle(String.format(formatString,
|
activity.setTitle(String.format(formatString,
|
||||||
profile.getType().getDisplayName()));
|
profile.getType().getDisplayName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +156,7 @@ public class VpnEditor extends PreferenceActivity {
|
|||||||
String errorMsg = mProfileEditor.validate();
|
String errorMsg = mProfileEditor.validate();
|
||||||
|
|
||||||
if (errorMsg != null) {
|
if (errorMsg != null) {
|
||||||
Util.showErrorMessage(this, errorMsg);
|
Util.showErrorMessage(getActivity(), errorMsg);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,9 +165,9 @@ public class VpnEditor extends PreferenceActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setResult(VpnProfile p) {
|
private void setResult(VpnProfile p) {
|
||||||
Intent intent = new Intent(this, VpnSettings.class);
|
Intent intent = new Intent(getActivity(), VpnSettings.class);
|
||||||
intent.putExtra(VpnSettings.KEY_VPN_PROFILE, (Parcelable) p);
|
intent.putExtra(VpnSettings.KEY_VPN_PROFILE, (Parcelable) p);
|
||||||
setResult(RESULT_OK, intent);
|
setResult(Activity.RESULT_OK, intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private VpnProfileEditor getEditor(VpnProfile p) {
|
private VpnProfileEditor getEditor(VpnProfile p) {
|
||||||
@@ -175,10 +191,9 @@ public class VpnEditor extends PreferenceActivity {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Dialog onCreateDialog(int id) {
|
public Dialog onCreateDialog(int id) {
|
||||||
|
|
||||||
if (id == CONFIRM_DIALOG_ID) {
|
if (id == CONFIRM_DIALOG_ID) {
|
||||||
return new AlertDialog.Builder(this)
|
return new AlertDialog.Builder(getActivity())
|
||||||
.setTitle(android.R.string.dialog_alert_title)
|
.setTitle(android.R.string.dialog_alert_title)
|
||||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||||
.setMessage(mAddingProfile
|
.setMessage(mAddingProfile
|
||||||
@@ -187,7 +202,7 @@ public class VpnEditor extends PreferenceActivity {
|
|||||||
.setPositiveButton(R.string.vpn_yes_button,
|
.setPositiveButton(R.string.vpn_yes_button,
|
||||||
new DialogInterface.OnClickListener() {
|
new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int w) {
|
public void onClick(DialogInterface dialog, int w) {
|
||||||
finish();
|
finishFragment();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.setNegativeButton(R.string.vpn_mistake_button, null)
|
.setNegativeButton(R.string.vpn_mistake_button, null)
|
||||||
@@ -197,8 +212,9 @@ public class VpnEditor extends PreferenceActivity {
|
|||||||
return super.onCreateDialog(id);
|
return super.onCreateDialog(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
@Override
|
@Override
|
||||||
protected void onPrepareDialog(int id, Dialog dialog) {
|
public void onPrepareDialog(int id, Dialog dialog) {
|
||||||
super.onPrepareDialog(id, dialog);
|
super.onPrepareDialog(id, dialog);
|
||||||
|
|
||||||
if (id == CONFIRM_DIALOG_ID) {
|
if (id == CONFIRM_DIALOG_ID) {
|
||||||
@@ -206,7 +222,7 @@ public class VpnEditor extends PreferenceActivity {
|
|||||||
? getString(R.string.vpn_confirm_add_profile_cancellation)
|
? getString(R.string.vpn_confirm_add_profile_cancellation)
|
||||||
: getString(R.string.vpn_confirm_edit_profile_cancellation));
|
: getString(R.string.vpn_confirm_edit_profile_cancellation));
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
private VpnProfile getProfile() {
|
private VpnProfile getProfile() {
|
||||||
return mProfileEditor.getProfile();
|
return mProfileEditor.getProfile();
|
||||||
|
@@ -17,11 +17,14 @@
|
|||||||
package com.android.settings.vpn;
|
package com.android.settings.vpn;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.ComponentName;
|
import android.app.Fragment;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -37,12 +40,10 @@ import android.net.vpn.VpnType;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.ConditionVariable;
|
import android.os.ConditionVariable;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.Parcelable;
|
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.PreferenceActivity;
|
import android.preference.Preference.OnPreferenceClickListener;
|
||||||
import android.preference.PreferenceCategory;
|
import android.preference.PreferenceCategory;
|
||||||
import android.preference.PreferenceScreen;
|
import android.preference.PreferenceScreen;
|
||||||
import android.preference.Preference.OnPreferenceClickListener;
|
|
||||||
import android.security.Credentials;
|
import android.security.Credentials;
|
||||||
import android.security.KeyStore;
|
import android.security.KeyStore;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@@ -69,8 +70,8 @@ import java.util.Map;
|
|||||||
/**
|
/**
|
||||||
* The preference activity for configuring VPN settings.
|
* The preference activity for configuring VPN settings.
|
||||||
*/
|
*/
|
||||||
public class VpnSettings extends PreferenceActivity implements
|
public class VpnSettings extends SettingsPreferenceFragment
|
||||||
DialogInterface.OnClickListener {
|
implements DialogInterface.OnClickListener {
|
||||||
// Key to the field exchanged for profile editing.
|
// Key to the field exchanged for profile editing.
|
||||||
static final String KEY_VPN_PROFILE = "vpn_profile";
|
static final String KEY_VPN_PROFILE = "vpn_profile";
|
||||||
|
|
||||||
@@ -122,7 +123,7 @@ public class VpnSettings extends PreferenceActivity implements
|
|||||||
|
|
||||||
private KeyStore mKeyStore = KeyStore.getInstance();
|
private KeyStore mKeyStore = KeyStore.getInstance();
|
||||||
|
|
||||||
private VpnManager mVpnManager = new VpnManager(this);
|
private VpnManager mVpnManager;
|
||||||
|
|
||||||
private ConnectivityReceiver mConnectivityReceiver =
|
private ConnectivityReceiver mConnectivityReceiver =
|
||||||
new ConnectivityReceiver();
|
new ConnectivityReceiver();
|
||||||
@@ -137,7 +138,13 @@ public class VpnSettings extends PreferenceActivity implements
|
|||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
addPreferencesFromResource(R.xml.vpn_settings);
|
addPreferencesFromResource(R.xml.vpn_settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
|
||||||
|
mVpnManager = new VpnManager(getActivity());
|
||||||
// restore VpnProfile list and construct VpnPreference map
|
// restore VpnProfile list and construct VpnPreference map
|
||||||
mVpnListContainer = (PreferenceCategory) findPreference(PREF_VPN_LIST);
|
mVpnListContainer = (PreferenceCategory) findPreference(PREF_VPN_LIST);
|
||||||
|
|
||||||
@@ -168,22 +175,24 @@ public class VpnSettings extends PreferenceActivity implements
|
|||||||
if ((mUnlockAction != null) && isKeyStoreUnlocked()) {
|
if ((mUnlockAction != null) && isKeyStoreUnlocked()) {
|
||||||
Runnable action = mUnlockAction;
|
Runnable action = mUnlockAction;
|
||||||
mUnlockAction = null;
|
mUnlockAction = null;
|
||||||
runOnUiThread(action);
|
getActivity().runOnUiThread(action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
public void onDestroyView() {
|
||||||
super.onDestroy();
|
|
||||||
unregisterForContextMenu(getListView());
|
unregisterForContextMenu(getListView());
|
||||||
mVpnManager.unregisterConnectivityReceiver(mConnectivityReceiver);
|
mVpnManager.unregisterConnectivityReceiver(mConnectivityReceiver);
|
||||||
if ((mShowingDialog != null) && mShowingDialog.isShowing()) {
|
if ((mShowingDialog != null) && mShowingDialog.isShowing()) {
|
||||||
mShowingDialog.dismiss();
|
mShowingDialog.dismiss();
|
||||||
}
|
}
|
||||||
|
// This should be called after the procedure above as ListView inside this Fragment
|
||||||
|
// will be deleted here.
|
||||||
|
super.onDestroyView();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Dialog onCreateDialog (int id) {
|
public Dialog onCreateDialog (int id) {
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case DIALOG_CONNECT:
|
case DIALOG_CONNECT:
|
||||||
return createConnectDialog();
|
return createConnectDialog();
|
||||||
@@ -203,13 +212,14 @@ public class VpnSettings extends PreferenceActivity implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Dialog createConnectDialog() {
|
private Dialog createConnectDialog() {
|
||||||
return new AlertDialog.Builder(this)
|
final Activity activity = getActivity();
|
||||||
|
return new AlertDialog.Builder(activity)
|
||||||
.setView(mConnectingActor.createConnectView())
|
.setView(mConnectingActor.createConnectView())
|
||||||
.setTitle(String.format(getString(R.string.vpn_connect_to),
|
.setTitle(String.format(activity.getString(R.string.vpn_connect_to),
|
||||||
mActiveProfile.getName()))
|
mActiveProfile.getName()))
|
||||||
.setPositiveButton(getString(R.string.vpn_connect_button),
|
.setPositiveButton(activity.getString(R.string.vpn_connect_button),
|
||||||
this)
|
this)
|
||||||
.setNegativeButton(getString(android.R.string.cancel),
|
.setNegativeButton(activity.getString(android.R.string.cancel),
|
||||||
this)
|
this)
|
||||||
.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||||
public void onCancel(DialogInterface dialog) {
|
public void onCancel(DialogInterface dialog) {
|
||||||
@@ -291,7 +301,7 @@ public class VpnSettings extends PreferenceActivity implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
private AlertDialog.Builder createCommonDialogBuilder() {
|
private AlertDialog.Builder createCommonDialogBuilder() {
|
||||||
return new AlertDialog.Builder(this)
|
return new AlertDialog.Builder(getActivity())
|
||||||
.setTitle(android.R.string.dialog_alert_title)
|
.setTitle(android.R.string.dialog_alert_title)
|
||||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||||
.setPositiveButton(R.string.vpn_yes_button,
|
.setPositiveButton(R.string.vpn_yes_button,
|
||||||
@@ -364,9 +374,9 @@ public class VpnSettings extends PreferenceActivity implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(final int requestCode, final int resultCode,
|
public void onActivityResult(final int requestCode, final int resultCode,
|
||||||
final Intent data) {
|
final Intent data) {
|
||||||
if ((resultCode == RESULT_CANCELED) || (data == null)) {
|
if ((resultCode == Activity.RESULT_CANCELED) || (data == null)) {
|
||||||
Log.d(TAG, "no result returned by editor");
|
Log.d(TAG, "no result returned by editor");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -381,11 +391,12 @@ public class VpnSettings extends PreferenceActivity implements
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Activity activity = getActivity();
|
||||||
int index = getProfileIndexFromId(p.getId());
|
int index = getProfileIndexFromId(p.getId());
|
||||||
if (checkDuplicateName(p, index)) {
|
if (checkDuplicateName(p, index)) {
|
||||||
final VpnProfile profile = p;
|
final VpnProfile profile = p;
|
||||||
Util.showErrorMessage(this, String.format(
|
Util.showErrorMessage(activity, String.format(
|
||||||
getString(R.string.vpn_error_duplicate_name),
|
activity.getString(R.string.vpn_error_duplicate_name),
|
||||||
p.getName()),
|
p.getName()),
|
||||||
new DialogInterface.OnClickListener() {
|
new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int w) {
|
public void onClick(DialogInterface dialog, int w) {
|
||||||
@@ -407,30 +418,32 @@ public class VpnSettings extends PreferenceActivity implements
|
|||||||
try {
|
try {
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
addProfile(p);
|
addProfile(p);
|
||||||
Util.showShortToastMessage(this, String.format(
|
Util.showShortToastMessage(activity, String.format(
|
||||||
getString(R.string.vpn_profile_added), p.getName()));
|
activity.getString(R.string.vpn_profile_added), p.getName()));
|
||||||
} else {
|
} else {
|
||||||
replaceProfile(index, p);
|
replaceProfile(index, p);
|
||||||
Util.showShortToastMessage(this, String.format(
|
Util.showShortToastMessage(activity, String.format(
|
||||||
getString(R.string.vpn_profile_replaced),
|
activity.getString(R.string.vpn_profile_replaced),
|
||||||
p.getName()));
|
p.getName()));
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
final VpnProfile profile = p;
|
final VpnProfile profile = p;
|
||||||
Util.showErrorMessage(this, e + ": " + e.getMessage(),
|
Util.showErrorMessage(activity, e + ": " + e.getMessage(),
|
||||||
new DialogInterface.OnClickListener() {
|
new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int w) {
|
public void onClick(DialogInterface dialog, int w) {
|
||||||
startVpnEditor(profile);
|
startVpnEditor(profile);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove cached VpnEditor as it is needless anymore.
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("unknown request code: " + requestCode);
|
throw new RuntimeException("unknown request code: " + requestCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called when the buttons on the connect dialog are clicked.
|
// Called when the buttons on the connect dialog are clicked.
|
||||||
//@Override
|
@Override
|
||||||
public synchronized void onClick(DialogInterface dialog, int which) {
|
public synchronized void onClick(DialogInterface dialog, int which) {
|
||||||
if (which == CONNECT_BUTTON) {
|
if (which == CONNECT_BUTTON) {
|
||||||
Dialog d = (Dialog) dialog;
|
Dialog d = (Dialog) dialog;
|
||||||
@@ -440,12 +453,15 @@ public class VpnSettings extends PreferenceActivity implements
|
|||||||
removeDialog(DIALOG_CONNECT);
|
removeDialog(DIALOG_CONNECT);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
dismissDialog(DIALOG_CONNECT);
|
// dismissDialog(DIALOG_CONNECT);
|
||||||
|
removeDialog(DIALOG_CONNECT);
|
||||||
|
|
||||||
|
final Activity activity = getActivity();
|
||||||
// show error dialog
|
// show error dialog
|
||||||
mShowingDialog = new AlertDialog.Builder(this)
|
mShowingDialog = new AlertDialog.Builder(activity)
|
||||||
.setTitle(android.R.string.dialog_alert_title)
|
.setTitle(android.R.string.dialog_alert_title)
|
||||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||||
.setMessage(String.format(getString(
|
.setMessage(String.format(activity.getString(
|
||||||
R.string.vpn_error_miss_entering), error))
|
R.string.vpn_error_miss_entering), error))
|
||||||
.setPositiveButton(R.string.vpn_back_button,
|
.setPositiveButton(R.string.vpn_back_button,
|
||||||
new DialogInterface.OnClickListener() {
|
new DialogInterface.OnClickListener() {
|
||||||
@@ -513,7 +529,7 @@ public class VpnSettings extends PreferenceActivity implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
mShowingDialog = new AlertDialog.Builder(this)
|
mShowingDialog = new AlertDialog.Builder(getActivity())
|
||||||
.setTitle(android.R.string.dialog_alert_title)
|
.setTitle(android.R.string.dialog_alert_title)
|
||||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||||
.setMessage(R.string.vpn_confirm_profile_deletion)
|
.setMessage(R.string.vpn_confirm_profile_deletion)
|
||||||
@@ -559,7 +575,7 @@ public class VpnSettings extends PreferenceActivity implements
|
|||||||
// Adds a preference in mVpnListContainer
|
// Adds a preference in mVpnListContainer
|
||||||
private VpnPreference addPreferenceFor(
|
private VpnPreference addPreferenceFor(
|
||||||
VpnProfile p, boolean addToContainer) {
|
VpnProfile p, boolean addToContainer) {
|
||||||
VpnPreference pref = new VpnPreference(this, p);
|
VpnPreference pref = new VpnPreference(getActivity(), p);
|
||||||
mVpnPreferenceMap.put(p.getName(), pref);
|
mVpnPreferenceMap.put(p.getName(), pref);
|
||||||
if (addToContainer) mVpnListContainer.addPreference(pref);
|
if (addToContainer) mVpnListContainer.addPreference(pref);
|
||||||
|
|
||||||
@@ -599,8 +615,8 @@ public class VpnSettings extends PreferenceActivity implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void startVpnTypeSelection() {
|
private void startVpnTypeSelection() {
|
||||||
Intent intent = new Intent(this, VpnTypeSelection.class);
|
startFragment(this, VpnTypeSelection.class.getCanonicalName(),
|
||||||
startActivityForResult(intent, REQUEST_SELECT_VPN_TYPE);
|
REQUEST_SELECT_VPN_TYPE, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isKeyStoreUnlocked() {
|
private boolean isKeyStoreUnlocked() {
|
||||||
@@ -614,16 +630,14 @@ public class VpnSettings extends PreferenceActivity implements
|
|||||||
L2tpIpsecPskProfile pskProfile = (L2tpIpsecPskProfile) p;
|
L2tpIpsecPskProfile pskProfile = (L2tpIpsecPskProfile) p;
|
||||||
String presharedKey = pskProfile.getPresharedKey();
|
String presharedKey = pskProfile.getPresharedKey();
|
||||||
if (!TextUtils.isEmpty(presharedKey)) return true;
|
if (!TextUtils.isEmpty(presharedKey)) return true;
|
||||||
// pass through
|
// $FALL-THROUGH$
|
||||||
|
|
||||||
case L2TP:
|
case L2TP:
|
||||||
L2tpProfile l2tpProfile = (L2tpProfile) p;
|
L2tpProfile l2tpProfile = (L2tpProfile) p;
|
||||||
if (l2tpProfile.isSecretEnabled() &&
|
if (l2tpProfile.isSecretEnabled() &&
|
||||||
!TextUtils.isEmpty(l2tpProfile.getSecretString())) {
|
!TextUtils.isEmpty(l2tpProfile.getSecretString())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// pass through
|
// $FALL-THROUGH$
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -648,14 +662,15 @@ public class VpnSettings extends PreferenceActivity implements
|
|||||||
private boolean unlockKeyStore(VpnProfile p, Runnable action) {
|
private boolean unlockKeyStore(VpnProfile p, Runnable action) {
|
||||||
if (isKeyStoreUnlocked()) return true;
|
if (isKeyStoreUnlocked()) return true;
|
||||||
mUnlockAction = action;
|
mUnlockAction = action;
|
||||||
Credentials.getInstance().unlock(this);
|
Credentials.getInstance().unlock(getActivity());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startVpnEditor(final VpnProfile profile) {
|
private void startVpnEditor(final VpnProfile profile) {
|
||||||
Intent intent = new Intent(this, VpnEditor.class);
|
Bundle args = new Bundle();
|
||||||
intent.putExtra(KEY_VPN_PROFILE, (Parcelable) profile);
|
args.putParcelable(KEY_VPN_PROFILE, profile);
|
||||||
startActivityForResult(intent, REQUEST_ADD_OR_EDIT_PROFILE);
|
startFragment(this, VpnEditor.class.getCanonicalName(),
|
||||||
|
REQUEST_ADD_OR_EDIT_PROFILE, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void connect(final VpnProfile p) {
|
private synchronized void connect(final VpnProfile p) {
|
||||||
@@ -714,7 +729,7 @@ public class VpnSettings extends PreferenceActivity implements
|
|||||||
|
|
||||||
case CONNECTING:
|
case CONNECTING:
|
||||||
mConnectingActor = getActor(p);
|
mConnectingActor = getActor(p);
|
||||||
// pass through
|
// $FALL-THROUGH$
|
||||||
case DISCONNECTING:
|
case DISCONNECTING:
|
||||||
mActiveProfile = p;
|
mActiveProfile = p;
|
||||||
disableProfilePreferencesIfOneActive();
|
disableProfilePreferencesIfOneActive();
|
||||||
@@ -810,11 +825,6 @@ public class VpnSettings extends PreferenceActivity implements
|
|||||||
public int compare(VpnProfile p1, VpnProfile p2) {
|
public int compare(VpnProfile p1, VpnProfile p2) {
|
||||||
return p1.getName().compareTo(p2.getName());
|
return p1.getName().compareTo(p2.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean equals(VpnProfile p) {
|
|
||||||
// not used
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
for (VpnProfile p : mVpnProfileList) {
|
for (VpnProfile p : mVpnProfileList) {
|
||||||
Preference pref = addPreferenceFor(p, false);
|
Preference pref = addPreferenceFor(p, false);
|
||||||
@@ -855,20 +865,21 @@ public class VpnSettings extends PreferenceActivity implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getProfileSummaryString(VpnProfile p) {
|
private String getProfileSummaryString(VpnProfile p) {
|
||||||
|
final Activity activity = getActivity();
|
||||||
switch (p.getState()) {
|
switch (p.getState()) {
|
||||||
case CONNECTING:
|
case CONNECTING:
|
||||||
return getString(R.string.vpn_connecting);
|
return activity.getString(R.string.vpn_connecting);
|
||||||
case DISCONNECTING:
|
case DISCONNECTING:
|
||||||
return getString(R.string.vpn_disconnecting);
|
return activity.getString(R.string.vpn_disconnecting);
|
||||||
case CONNECTED:
|
case CONNECTED:
|
||||||
return getString(R.string.vpn_connected);
|
return activity.getString(R.string.vpn_connected);
|
||||||
default:
|
default:
|
||||||
return getString(R.string.vpn_connect_hint);
|
return activity.getString(R.string.vpn_connect_hint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private VpnProfileActor getActor(VpnProfile p) {
|
private VpnProfileActor getActor(VpnProfile p) {
|
||||||
return new AuthenticationActor(this, p);
|
return new AuthenticationActor(getActivity(), p);
|
||||||
}
|
}
|
||||||
|
|
||||||
private VpnProfile createVpnProfile(String type) {
|
private VpnProfile createVpnProfile(String type) {
|
||||||
@@ -938,8 +949,7 @@ public class VpnSettings extends PreferenceActivity implements
|
|||||||
Log.e(TAG, "keystore write failed: key=" + key);
|
Log.e(TAG, "keystore write failed: key=" + key);
|
||||||
}
|
}
|
||||||
pskProfile.setPresharedKey(key);
|
pskProfile.setPresharedKey(key);
|
||||||
// pass through
|
// $FALL-THROUGH$
|
||||||
|
|
||||||
case L2TP_IPSEC:
|
case L2TP_IPSEC:
|
||||||
case L2TP:
|
case L2TP:
|
||||||
L2tpProfile l2tpProfile = (L2tpProfile) p;
|
L2tpProfile l2tpProfile = (L2tpProfile) p;
|
||||||
@@ -1007,8 +1017,6 @@ public class VpnSettings extends PreferenceActivity implements
|
|||||||
|
|
||||||
// managing status check in a background thread
|
// managing status check in a background thread
|
||||||
private class StatusChecker {
|
private class StatusChecker {
|
||||||
private List<VpnProfile> mList;
|
|
||||||
|
|
||||||
synchronized void check(final List<VpnProfile> list) {
|
synchronized void check(final List<VpnProfile> list) {
|
||||||
final ConditionVariable cv = new ConditionVariable();
|
final ConditionVariable cv = new ConditionVariable();
|
||||||
cv.close();
|
cv.close();
|
||||||
@@ -1027,7 +1035,7 @@ public class VpnSettings extends PreferenceActivity implements
|
|||||||
changeState(p, VpnState.IDLE);
|
changeState(p, VpnState.IDLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
VpnSettings.this.unbindService(this);
|
getActivity().unbindService(this);
|
||||||
showPreferences();
|
showPreferences();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1035,7 +1043,7 @@ public class VpnSettings extends PreferenceActivity implements
|
|||||||
cv.open();
|
cv.open();
|
||||||
|
|
||||||
setDefaultState(list);
|
setDefaultState(list);
|
||||||
VpnSettings.this.unbindService(this);
|
getActivity().unbindService(this);
|
||||||
showPreferences();
|
showPreferences();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -17,13 +17,14 @@
|
|||||||
package com.android.settings.vpn;
|
package com.android.settings.vpn;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.vpn.VpnManager;
|
import android.net.vpn.VpnManager;
|
||||||
import android.net.vpn.VpnType;
|
import android.net.vpn.VpnType;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.PreferenceActivity;
|
|
||||||
import android.preference.PreferenceScreen;
|
import android.preference.PreferenceScreen;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -32,7 +33,7 @@ import java.util.Map;
|
|||||||
/**
|
/**
|
||||||
* The activity to select a VPN type.
|
* The activity to select a VPN type.
|
||||||
*/
|
*/
|
||||||
public class VpnTypeSelection extends PreferenceActivity {
|
public class VpnTypeSelection extends SettingsPreferenceFragment {
|
||||||
private Map<String, VpnType> mTypeMap = new HashMap<String, VpnType>();
|
private Map<String, VpnType> mTypeMap = new HashMap<String, VpnType>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -46,19 +47,20 @@ public class VpnTypeSelection extends PreferenceActivity {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceTreeClick(PreferenceScreen ps, Preference pref) {
|
public boolean onPreferenceTreeClick(PreferenceScreen ps, Preference pref) {
|
||||||
setResult(mTypeMap.get(pref.getTitle().toString()));
|
setResult(mTypeMap.get(pref.getTitle().toString()));
|
||||||
finish();
|
finishFragment();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initTypeList() {
|
private void initTypeList() {
|
||||||
PreferenceScreen root = getPreferenceScreen();
|
PreferenceScreen root = getPreferenceScreen();
|
||||||
|
final Activity activity = getActivity();
|
||||||
for (VpnType t : VpnManager.getSupportedVpnTypes()) {
|
for (VpnType t : VpnManager.getSupportedVpnTypes()) {
|
||||||
String displayName = t.getDisplayName();
|
String displayName = t.getDisplayName();
|
||||||
String message = String.format(
|
String message = String.format(
|
||||||
getString(R.string.vpn_edit_title_add), displayName);
|
activity.getString(R.string.vpn_edit_title_add), displayName);
|
||||||
mTypeMap.put(message, t);
|
mTypeMap.put(message, t);
|
||||||
|
|
||||||
Preference pref = new Preference(this);
|
Preference pref = new Preference(activity);
|
||||||
pref.setTitle(message);
|
pref.setTitle(message);
|
||||||
pref.setSummary(t.getDescriptionId());
|
pref.setSummary(t.getDescriptionId());
|
||||||
root.addPreference(pref);
|
root.addPreference(pref);
|
||||||
@@ -66,8 +68,8 @@ public class VpnTypeSelection extends PreferenceActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setResult(VpnType type) {
|
private void setResult(VpnType type) {
|
||||||
Intent intent = new Intent(this, VpnSettings.class);
|
Intent intent = new Intent(getActivity(), VpnSettings.class);
|
||||||
intent.putExtra(VpnSettings.KEY_VPN_TYPE, type.toString());
|
intent.putExtra(VpnSettings.KEY_VPN_TYPE, type.toString());
|
||||||
setResult(RESULT_OK, intent);
|
setResult(Activity.RESULT_OK, intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user