[WifiSettings] Add Wi-Fi dialog activity
Add a Wi-Fi dialog activity that can be started by setup wizard to connect to a Wi-Fi access point. Also refactored mEdit and mModify in WifiConfigController into an int-enum mMode, with modes view, connect and modify. This is how the new modes maps to the old flags: MODE_VIEW -- mEdit = false, mModify = * MODE_CONNECT -- mEdit = true, mModify = false MODE_MODIFY -- mEdit = true, mModify = true Bug: 23426311 Change-Id: I8e2221fd3c42577068e07686dab245dd5888e0ae
This commit is contained in:
@@ -2500,6 +2500,16 @@
|
||||
android:excludeFromRecents="true">
|
||||
</activity>
|
||||
|
||||
<activity android:name=".wifi.WifiDialogActivity"
|
||||
android:theme="@style/Transparent"
|
||||
android:excludeFromRecents="true"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="com.android.settings.WIFI_DIALOG" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name=".sim.SimDialogActivity"
|
||||
android:theme="@android:style/Theme.Material.Light.Dialog.NoActionBar"
|
||||
android:label="@string/sim_settings_title"
|
||||
|
@@ -239,6 +239,7 @@
|
||||
</style>
|
||||
|
||||
<style name="Transparent">
|
||||
<item name="android:alertDialogTheme">@style/Theme.AlertDialog</item>
|
||||
<item name="android:windowBackground">@android:color/transparent</item>
|
||||
<item name="android:windowNoTitle">true</item>
|
||||
<item name="android:windowIsFloating">true</item>
|
||||
|
@@ -146,7 +146,7 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
|
||||
final boolean hideForgetButton = WifiSettings.isEditabilityLockedDown(getActivity(),
|
||||
mDlgAccessPoint.getConfig());
|
||||
mDialog = new WifiDialog(getActivity(), this, mDlgAccessPoint,
|
||||
false /* not editting */, false, true /* hide the submit button */,
|
||||
WifiConfigUiBase.MODE_VIEW, true /* hide the submit button */,
|
||||
hideForgetButton);
|
||||
return mDialog;
|
||||
|
||||
|
@@ -144,23 +144,20 @@ public class WifiConfigController implements TextWatcher,
|
||||
private StaticIpConfiguration mStaticIpConfiguration = null;
|
||||
|
||||
private String[] mLevels;
|
||||
private boolean mEdit;
|
||||
private boolean mModify;
|
||||
private int mMode;
|
||||
private TextView mSsidView;
|
||||
|
||||
private Context mContext;
|
||||
|
||||
public WifiConfigController(
|
||||
WifiConfigUiBase parent, View view, AccessPoint accessPoint, boolean edit,
|
||||
boolean modify) {
|
||||
public WifiConfigController(WifiConfigUiBase parent, View view, AccessPoint accessPoint,
|
||||
int mode) {
|
||||
mConfigUi = parent;
|
||||
|
||||
mView = view;
|
||||
mAccessPoint = accessPoint;
|
||||
mAccessPointSecurity = (accessPoint == null) ? AccessPoint.SECURITY_NONE :
|
||||
accessPoint.getSecurity();
|
||||
mEdit = edit;
|
||||
mModify = modify;
|
||||
mMode = mode;
|
||||
|
||||
mTextViewChangedHandler = new Handler();
|
||||
mContext = mConfigUi.getContext();
|
||||
@@ -238,7 +235,7 @@ public class WifiConfigController implements TextWatcher,
|
||||
}
|
||||
|
||||
if ((!mAccessPoint.isSaved() && !mAccessPoint.isActive())
|
||||
|| mEdit) {
|
||||
|| mMode != WifiConfigUiBase.MODE_VIEW) {
|
||||
showSecurityFields();
|
||||
showIpConfigFields();
|
||||
showProxyFields();
|
||||
@@ -251,8 +248,10 @@ public class WifiConfigController implements TextWatcher,
|
||||
}
|
||||
}
|
||||
|
||||
if (mModify) {
|
||||
if (mMode == WifiConfigUiBase.MODE_MODIFY) {
|
||||
mConfigUi.setSubmitButton(res.getString(R.string.wifi_save));
|
||||
} else if (mMode == WifiConfigUiBase.MODE_CONNECT) {
|
||||
mConfigUi.setSubmitButton(res.getString(R.string.wifi_connect));
|
||||
} else {
|
||||
final DetailedState state = mAccessPoint.getDetailedState();
|
||||
final String signalLevel = getSignalString();
|
||||
@@ -376,7 +375,7 @@ public class WifiConfigController implements TextWatcher,
|
||||
}
|
||||
|
||||
/* package */ WifiConfiguration getConfig() {
|
||||
if (!mEdit) {
|
||||
if (mMode == WifiConfigUiBase.MODE_VIEW) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -966,12 +965,8 @@ public class WifiConfigController implements TextWatcher,
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEdit() {
|
||||
return mEdit;
|
||||
}
|
||||
|
||||
public boolean isModify() {
|
||||
return mModify;
|
||||
public int getMode() {
|
||||
return mMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1066,4 +1061,8 @@ public class WifiConfigController implements TextWatcher,
|
||||
InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD :
|
||||
InputType.TYPE_TEXT_VARIATION_PASSWORD));
|
||||
}
|
||||
|
||||
public AccessPoint getAccessPoint() {
|
||||
return mAccessPoint;
|
||||
}
|
||||
}
|
||||
|
@@ -24,10 +24,26 @@ import android.widget.Button;
|
||||
* Foundation interface glues between Activities and UIs like {@link WifiDialog}.
|
||||
*/
|
||||
public interface WifiConfigUiBase {
|
||||
|
||||
/**
|
||||
* Viewing mode for a Wi-Fi access point. Data is displayed in non-editable mode.
|
||||
*/
|
||||
int MODE_VIEW = 0;
|
||||
/**
|
||||
* Connect mode. Data is displayed in editable mode, and a connect button will be shown.
|
||||
*/
|
||||
int MODE_CONNECT = 1;
|
||||
/**
|
||||
* Modify mode. All data is displayed in editable fields, and a "save" button is shown instead
|
||||
* of "connect". Clients are expected to only save but not connect to the access point in this
|
||||
* mode.
|
||||
*/
|
||||
int MODE_MODIFY = 2;
|
||||
|
||||
public Context getContext();
|
||||
public WifiConfigController getController();
|
||||
public LayoutInflater getLayoutInflater();
|
||||
public boolean isEdit();
|
||||
public int getMode();
|
||||
|
||||
public void dispatchSubmit();
|
||||
|
||||
|
@@ -24,6 +24,7 @@ import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Button;
|
||||
|
||||
class WifiDialog extends AlertDialog implements WifiConfigUiBase, DialogInterface.OnClickListener {
|
||||
@@ -36,8 +37,7 @@ class WifiDialog extends AlertDialog implements WifiConfigUiBase, DialogInterfac
|
||||
private static final int BUTTON_SUBMIT = DialogInterface.BUTTON_POSITIVE;
|
||||
private static final int BUTTON_FORGET = DialogInterface.BUTTON_NEUTRAL;
|
||||
|
||||
private final boolean mEdit;
|
||||
private final boolean mModify;
|
||||
private final int mMode;
|
||||
private final WifiDialogListener mListener;
|
||||
private final AccessPoint mAccessPoint;
|
||||
|
||||
@@ -46,19 +46,17 @@ class WifiDialog extends AlertDialog implements WifiConfigUiBase, DialogInterfac
|
||||
private boolean mHideSubmitButton;
|
||||
private boolean mHideForgetButton;
|
||||
|
||||
public WifiDialog(Context context, WifiDialogListener listener,
|
||||
AccessPoint accessPoint, boolean edit, boolean modify,
|
||||
boolean hideSubmitButton, boolean hideForgetButton) {
|
||||
this(context, listener, accessPoint, edit, modify);
|
||||
public WifiDialog(Context context, WifiDialogListener listener, AccessPoint accessPoint,
|
||||
int mode, boolean hideSubmitButton, boolean hideForgetButton) {
|
||||
this(context, listener, accessPoint, mode);
|
||||
mHideSubmitButton = hideSubmitButton;
|
||||
mHideForgetButton = hideForgetButton;
|
||||
}
|
||||
|
||||
public WifiDialog(Context context, WifiDialogListener listener,
|
||||
AccessPoint accessPoint, boolean edit, boolean modify) {
|
||||
public WifiDialog(Context context, WifiDialogListener listener, AccessPoint accessPoint,
|
||||
int mode) {
|
||||
super(context);
|
||||
mEdit = edit;
|
||||
mModify = modify;
|
||||
mMode = mode;
|
||||
mListener = listener;
|
||||
mAccessPoint = accessPoint;
|
||||
mHideSubmitButton = false;
|
||||
@@ -75,7 +73,7 @@ class WifiDialog extends AlertDialog implements WifiConfigUiBase, DialogInterfac
|
||||
mView = getLayoutInflater().inflate(R.layout.wifi_dialog, null);
|
||||
setView(mView);
|
||||
setInverseBackgroundForced(true);
|
||||
mController = new WifiConfigController(this, mView, mAccessPoint, mEdit, mModify);
|
||||
mController = new WifiConfigController(this, mView, mAccessPoint, mMode);
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (mHideSubmitButton) {
|
||||
@@ -119,8 +117,8 @@ class WifiDialog extends AlertDialog implements WifiConfigUiBase, DialogInterfac
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEdit() {
|
||||
return mEdit;
|
||||
public int getMode() {
|
||||
return mMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
118
src/com/android/settings/wifi/WifiDialogActivity.java
Normal file
118
src/com/android/settings/wifi/WifiDialogActivity.java
Normal file
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.wifi;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settingslib.wifi.AccessPoint;
|
||||
|
||||
public class WifiDialogActivity extends Activity implements WifiDialog.WifiDialogListener,
|
||||
DialogInterface.OnDismissListener {
|
||||
|
||||
private static final String TAG = "WifiDialogActivity";
|
||||
|
||||
private static final int RESULT_CONNECTED = RESULT_FIRST_USER;
|
||||
private static final int RESULT_FORGET = RESULT_FIRST_USER + 1;
|
||||
|
||||
private static final String KEY_ACCESS_POINT_STATE = "access_point_state";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
final Intent intent = getIntent();
|
||||
final Bundle accessPointState = intent.getBundleExtra(KEY_ACCESS_POINT_STATE);
|
||||
final AccessPoint accessPoint = new AccessPoint(this, accessPointState);
|
||||
|
||||
WifiDialog dialog = new WifiDialog(this, this, accessPoint, WifiConfigUiBase.MODE_CONNECT);
|
||||
dialog.show();
|
||||
dialog.setOnDismissListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onForget(WifiDialog dialog) {
|
||||
final WifiManager wifiManager = getSystemService(WifiManager.class);
|
||||
final AccessPoint accessPoint = dialog.getController().getAccessPoint();
|
||||
if (accessPoint != null) {
|
||||
if (!accessPoint.isSaved()) {
|
||||
if (accessPoint.getNetworkInfo() != null &&
|
||||
accessPoint.getNetworkInfo().getState() != NetworkInfo.State.DISCONNECTED) {
|
||||
// Network is active but has no network ID - must be ephemeral.
|
||||
wifiManager.disableEphemeralNetwork(
|
||||
AccessPoint.convertToQuotedString(accessPoint.getSsidStr()));
|
||||
} else {
|
||||
// Should not happen, but a monkey seems to trigger it
|
||||
Log.e(TAG, "Failed to forget invalid network " + accessPoint.getConfig());
|
||||
}
|
||||
} else {
|
||||
wifiManager.forget(accessPoint.getConfig().networkId, null /* listener */);
|
||||
}
|
||||
}
|
||||
|
||||
Intent resultData = new Intent();
|
||||
if (accessPoint != null) {
|
||||
Bundle accessPointState = new Bundle();
|
||||
accessPoint.saveWifiState(accessPointState);
|
||||
resultData.putExtra(KEY_ACCESS_POINT_STATE, accessPointState);
|
||||
}
|
||||
setResult(RESULT_FORGET);
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubmit(WifiDialog dialog) {
|
||||
final WifiConfiguration config = dialog.getController().getConfig();
|
||||
final AccessPoint accessPoint = dialog.getController().getAccessPoint();
|
||||
final WifiManager wifiManager = getSystemService(WifiManager.class);
|
||||
|
||||
if (config == null) {
|
||||
if (accessPoint != null && accessPoint.isSaved()) {
|
||||
wifiManager.connect(accessPoint.getConfig(), null /* listener */);
|
||||
}
|
||||
} else {
|
||||
wifiManager.save(config, null /* listener */);
|
||||
if (accessPoint != null) {
|
||||
// accessPoint is null for "Add network"
|
||||
NetworkInfo networkInfo = accessPoint.getNetworkInfo();
|
||||
if (networkInfo == null || !networkInfo.isConnected()) {
|
||||
wifiManager.connect(config, null /* listener */);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Intent resultData = new Intent();
|
||||
if (accessPoint != null) {
|
||||
Bundle accessPointState = new Bundle();
|
||||
accessPoint.saveWifiState(accessPointState);
|
||||
resultData.putExtra(KEY_ACCESS_POINT_STATE, accessPointState);
|
||||
}
|
||||
setResult(RESULT_CONNECTED, resultData);
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialogInterface) {
|
||||
finish();
|
||||
}
|
||||
}
|
@@ -112,8 +112,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
private static final int WRITE_NFC_DIALOG_ID = 6;
|
||||
|
||||
// Instance state keys
|
||||
private static final String SAVE_DIALOG_EDIT_MODE = "edit_mode";
|
||||
private static final String SAVE_DIALOG_MODIFY_MODE = "modify_mode";
|
||||
private static final String SAVE_DIALOG_MODE = "dialog_mode";
|
||||
private static final String SAVE_DIALOG_ACCESS_POINT_STATE = "wifi_ap_state";
|
||||
private static final String SAVED_WIFI_NFC_DIALOG_STATE = "wifi_nfc_dlg_state";
|
||||
|
||||
@@ -145,8 +144,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
private boolean mEnableNextOnConnection;
|
||||
|
||||
// Save the dialog details
|
||||
private boolean mDlgModify;
|
||||
private boolean mDlgEdit;
|
||||
private int mDialogMode;
|
||||
private AccessPoint mDlgAccessPoint;
|
||||
private Bundle mAccessPointSavedState;
|
||||
private Bundle mWifiNfcDialogSavedState;
|
||||
@@ -243,8 +241,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
};
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
mDlgEdit = savedInstanceState.getBoolean(SAVE_DIALOG_EDIT_MODE);
|
||||
mDlgModify = savedInstanceState.getBoolean(SAVE_DIALOG_MODIFY_MODE);
|
||||
mDialogMode = savedInstanceState.getInt(SAVE_DIALOG_MODE);
|
||||
if (savedInstanceState.containsKey(SAVE_DIALOG_ACCESS_POINT_STATE)) {
|
||||
mAccessPointSavedState =
|
||||
savedInstanceState.getBundle(SAVE_DIALOG_ACCESS_POINT_STATE);
|
||||
@@ -375,8 +372,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
|
||||
// If the dialog is showing, save its state.
|
||||
if (mDialog != null && mDialog.isShowing()) {
|
||||
outState.putBoolean(SAVE_DIALOG_EDIT_MODE, mDlgEdit);
|
||||
outState.putBoolean(SAVE_DIALOG_MODIFY_MODE, mDlgModify);
|
||||
outState.putInt(SAVE_DIALOG_MODE, mDialogMode);
|
||||
if (mDlgAccessPoint != null) {
|
||||
mAccessPointSavedState = new Bundle();
|
||||
mDlgAccessPoint.saveWifiState(mAccessPointSavedState);
|
||||
@@ -504,8 +500,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
mSelectedAccessPoint.generateOpenNetworkConfig();
|
||||
connect(mSelectedAccessPoint.getConfig());
|
||||
} else {
|
||||
mDlgModify = false;
|
||||
showDialog(mSelectedAccessPoint, true);
|
||||
showDialog(mSelectedAccessPoint, WifiConfigUiBase.MODE_CONNECT);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -514,8 +509,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
return true;
|
||||
}
|
||||
case MENU_ID_MODIFY: {
|
||||
mDlgModify = true;
|
||||
showDialog(mSelectedAccessPoint, true);
|
||||
showDialog(mSelectedAccessPoint, WifiConfigUiBase.MODE_MODIFY);
|
||||
return true;
|
||||
}
|
||||
case MENU_ID_WRITE_NFC:
|
||||
@@ -540,11 +534,9 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
}
|
||||
connect(mSelectedAccessPoint.getConfig());
|
||||
} else if (mSelectedAccessPoint.isSaved()){
|
||||
mDlgModify = false;
|
||||
showDialog(mSelectedAccessPoint, false);
|
||||
showDialog(mSelectedAccessPoint, WifiConfigUiBase.MODE_VIEW);
|
||||
} else {
|
||||
mDlgModify = false;
|
||||
showDialog(mSelectedAccessPoint, true);
|
||||
showDialog(mSelectedAccessPoint, WifiConfigUiBase.MODE_CONNECT);
|
||||
}
|
||||
} else {
|
||||
return super.onPreferenceTreeClick(screen, preference);
|
||||
@@ -552,7 +544,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
return true;
|
||||
}
|
||||
|
||||
private void showDialog(AccessPoint accessPoint, boolean edit) {
|
||||
private void showDialog(AccessPoint accessPoint, int dialogMode) {
|
||||
if (accessPoint != null) {
|
||||
WifiConfiguration config = accessPoint.getConfig();
|
||||
if (isEditabilityLockedDown(getActivity(), config) && accessPoint.isActive()) {
|
||||
@@ -587,7 +579,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
|
||||
// Save the access point and edit mode
|
||||
mDlgAccessPoint = accessPoint;
|
||||
mDlgEdit = edit;
|
||||
mDialogMode = dialogMode;
|
||||
|
||||
showDialog(WIFI_DIALOG_ID);
|
||||
}
|
||||
@@ -610,8 +602,8 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
mSelectedAccessPoint = ap;
|
||||
final boolean hideForget = (ap == null || isEditabilityLockedDown(getActivity(),
|
||||
ap.getConfig()));
|
||||
mDialog = new WifiDialog(getActivity(), this, ap, mDlgEdit,
|
||||
mDlgModify, /* no hide submit/connect */ false,
|
||||
mDialog = new WifiDialog(getActivity(), this, ap, mDialogMode,
|
||||
/* no hide submit/connect */ false,
|
||||
/* hide forget if config locked down */ hideForget);
|
||||
return mDialog;
|
||||
case WPS_PBC_DIALOG_ID:
|
||||
@@ -830,7 +822,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
&& mSelectedAccessPoint.isSaved()) {
|
||||
connect(mSelectedAccessPoint.getConfig());
|
||||
}
|
||||
} else if (configController.isModify()) {
|
||||
} else if (configController.getMode() == WifiConfigUiBase.MODE_MODIFY) {
|
||||
mWifiManager.save(config, mSaveListener);
|
||||
} else {
|
||||
mWifiManager.save(config, mSaveListener);
|
||||
@@ -891,7 +883,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
MetricsLogger.action(getActivity(), MetricsLogger.ACTION_WIFI_ADD_NETWORK);
|
||||
// No exact access point is selected.
|
||||
mSelectedAccessPoint = null;
|
||||
showDialog(null, true);
|
||||
showDialog(null, WifiConfigUiBase.MODE_CONNECT);
|
||||
}
|
||||
|
||||
/* package */ int getAccessPointsCount() {
|
||||
|
Reference in New Issue
Block a user