Delete WPS settings.
Removes the WPS PIN and Push button settings, all of the strings, and related code. Change-Id: I1c7a35ffc8491c57e07accba9b1b5f5407b01831 Fixes: 72421239 Test: deletes code, robotests
This commit is contained in:
@@ -92,8 +92,6 @@ public class ConfigureWifiSettings extends DashboardFragment {
|
||||
controllers.add(new WifiInfoPreferenceController(context, getLifecycle(), wifiManager));
|
||||
controllers.add(new CellularFallbackPreferenceController(context));
|
||||
controllers.add(new WifiP2pPreferenceController(context, getLifecycle(), wifiManager));
|
||||
controllers.add(new WpsPreferenceController(
|
||||
context, getLifecycle(), wifiManager, getFragmentManager()));
|
||||
return controllers;
|
||||
}
|
||||
|
||||
|
@@ -85,16 +85,12 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
|
||||
private static final String TAG = "WifiSettings";
|
||||
|
||||
/* package */ static final int MENU_ID_WPS_PBC = Menu.FIRST;
|
||||
private static final int MENU_ID_WPS_PIN = Menu.FIRST + 1;
|
||||
private static final int MENU_ID_CONNECT = Menu.FIRST + 6;
|
||||
private static final int MENU_ID_FORGET = Menu.FIRST + 7;
|
||||
private static final int MENU_ID_MODIFY = Menu.FIRST + 8;
|
||||
private static final int MENU_ID_WRITE_NFC = Menu.FIRST + 9;
|
||||
|
||||
public static final int WIFI_DIALOG_ID = 1;
|
||||
/* package */ static final int WPS_PBC_DIALOG_ID = 2;
|
||||
private static final int WPS_PIN_DIALOG_ID = 3;
|
||||
private static final int WRITE_NFC_DIALOG_ID = 6;
|
||||
|
||||
// Instance state keys
|
||||
@@ -459,24 +455,6 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// If the user is not allowed to configure wifi, do not handle menu selections.
|
||||
if (mIsRestricted) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case MENU_ID_WPS_PBC:
|
||||
showDialog(WPS_PBC_DIALOG_ID);
|
||||
return true;
|
||||
case MENU_ID_WPS_PIN:
|
||||
showDialog(WPS_PIN_DIALOG_ID);
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo info) {
|
||||
Preference preference = (Preference) view.getTag();
|
||||
@@ -635,10 +613,6 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
|
||||
mSelectedAccessPoint = mDlgAccessPoint;
|
||||
return mDialog;
|
||||
case WPS_PBC_DIALOG_ID:
|
||||
return new WpsDialog(getActivity(), WpsInfo.PBC);
|
||||
case WPS_PIN_DIALOG_ID:
|
||||
return new WpsDialog(getActivity(), WpsInfo.DISPLAY);
|
||||
case WRITE_NFC_DIALOG_ID:
|
||||
if (mSelectedAccessPoint != null) {
|
||||
mWifiToNfcDialog = new WriteWifiConfigToNfcDialog(
|
||||
@@ -660,10 +634,6 @@ public class WifiSettings extends RestrictedSettingsFragment
|
||||
switch (dialogId) {
|
||||
case WIFI_DIALOG_ID:
|
||||
return MetricsEvent.DIALOG_WIFI_AP_EDIT;
|
||||
case WPS_PBC_DIALOG_ID:
|
||||
return MetricsEvent.DIALOG_WIFI_PBC;
|
||||
case WPS_PIN_DIALOG_ID:
|
||||
return MetricsEvent.DIALOG_WIFI_PIN;
|
||||
case WRITE_NFC_DIALOG_ID:
|
||||
return MetricsEvent.DIALOG_WIFI_WRITE_NFC;
|
||||
default:
|
||||
|
@@ -1,297 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2012 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.AlertDialog;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.NetworkInfo.DetailedState;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.net.wifi.WpsInfo;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
|
||||
/**
|
||||
* Dialog to show WPS progress.
|
||||
*/
|
||||
public class WpsDialog extends AlertDialog {
|
||||
|
||||
private final static String TAG = "WpsDialog";
|
||||
private static final String DIALOG_STATE = "android:dialogState";
|
||||
private static final String DIALOG_MSG_STRING = "android:dialogMsg";
|
||||
|
||||
private View mView;
|
||||
private TextView mTextView;
|
||||
private ProgressBar mTimeoutBar;
|
||||
private ProgressBar mProgressBar;
|
||||
private Button mButton;
|
||||
private Timer mTimer;
|
||||
|
||||
private static final int WPS_TIMEOUT_S = 120;
|
||||
|
||||
private WifiManager mWifiManager;
|
||||
private WifiManager.WpsCallback mWpsListener;
|
||||
private int mWpsSetup;
|
||||
|
||||
private final IntentFilter mFilter;
|
||||
private BroadcastReceiver mReceiver;
|
||||
|
||||
private Context mContext;
|
||||
private Handler mHandler = new Handler();
|
||||
private String mMsgString = "";
|
||||
|
||||
private enum DialogState {
|
||||
WPS_INIT,
|
||||
WPS_START,
|
||||
WPS_COMPLETE,
|
||||
CONNECTED, //WPS + IP config is done
|
||||
WPS_FAILED
|
||||
}
|
||||
DialogState mDialogState = DialogState.WPS_INIT;
|
||||
|
||||
public WpsDialog(Context context, int wpsSetup) {
|
||||
super(context);
|
||||
mContext = context;
|
||||
mWpsSetup = wpsSetup;
|
||||
|
||||
class WpsListener extends WifiManager.WpsCallback {
|
||||
|
||||
public void onStarted(String pin) {
|
||||
if (pin != null) {
|
||||
updateDialog(DialogState.WPS_START, String.format(
|
||||
mContext.getString(R.string.wifi_wps_onstart_pin), pin));
|
||||
} else {
|
||||
updateDialog(DialogState.WPS_START, mContext.getString(
|
||||
R.string.wifi_wps_onstart_pbc));
|
||||
}
|
||||
}
|
||||
|
||||
public void onSucceeded() {
|
||||
updateDialog(DialogState.WPS_COMPLETE,
|
||||
mContext.getString(R.string.wifi_wps_complete));
|
||||
}
|
||||
|
||||
public void onFailed(int reason) {
|
||||
String msg;
|
||||
switch (reason) {
|
||||
case WifiManager.WPS_OVERLAP_ERROR:
|
||||
msg = mContext.getString(R.string.wifi_wps_failed_overlap);
|
||||
break;
|
||||
case WifiManager.WPS_WEP_PROHIBITED:
|
||||
msg = mContext.getString(R.string.wifi_wps_failed_wep);
|
||||
break;
|
||||
case WifiManager.WPS_TKIP_ONLY_PROHIBITED:
|
||||
msg = mContext.getString(R.string.wifi_wps_failed_tkip);
|
||||
break;
|
||||
case WifiManager.IN_PROGRESS:
|
||||
msg = mContext.getString(R.string.wifi_wps_in_progress);
|
||||
break;
|
||||
default:
|
||||
msg = mContext.getString(R.string.wifi_wps_failed_generic);
|
||||
break;
|
||||
}
|
||||
updateDialog(DialogState.WPS_FAILED, msg);
|
||||
}
|
||||
}
|
||||
|
||||
mWpsListener = new WpsListener();
|
||||
|
||||
|
||||
mFilter = new IntentFilter();
|
||||
mFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
|
||||
mFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
||||
mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
handleEvent(context, intent);
|
||||
}
|
||||
};
|
||||
setCanceledOnTouchOutside(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bundle onSaveInstanceState () {
|
||||
Bundle bundle = super.onSaveInstanceState();
|
||||
bundle.putString(DIALOG_STATE, mDialogState.toString());
|
||||
bundle.putString(DIALOG_MSG_STRING, mMsgString.toString());
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRestoreInstanceState(Bundle savedInstanceState) {
|
||||
if (savedInstanceState != null) {
|
||||
super.onRestoreInstanceState(savedInstanceState);
|
||||
DialogState dialogState = mDialogState.valueOf(savedInstanceState.getString(DIALOG_STATE));
|
||||
String msg = savedInstanceState.getString(DIALOG_MSG_STRING);
|
||||
updateDialog(dialogState, msg);
|
||||
if (dialogState == DialogState.WPS_START) {
|
||||
startWps();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
mView = getLayoutInflater().inflate(R.layout.wifi_wps_dialog, null);
|
||||
|
||||
mTextView = (TextView) mView.findViewById(R.id.wps_dialog_txt);
|
||||
mTextView.setText(R.string.wifi_wps_setup_msg);
|
||||
|
||||
mTimeoutBar = ((ProgressBar) mView.findViewById(R.id.wps_timeout_bar));
|
||||
mTimeoutBar.setMax(WPS_TIMEOUT_S);
|
||||
mTimeoutBar.setProgress(0);
|
||||
|
||||
mProgressBar = ((ProgressBar) mView.findViewById(R.id.wps_progress_bar));
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
|
||||
mButton = ((Button) mView.findViewById(R.id.wps_dialog_btn));
|
||||
mButton.setText(R.string.wifi_cancel);
|
||||
mButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
|
||||
|
||||
setView(mView);
|
||||
if (savedInstanceState == null) {
|
||||
startWps();
|
||||
}
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
/*
|
||||
* increment timeout bar per second.
|
||||
*/
|
||||
mTimer = new Timer(false);
|
||||
mTimer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
mHandler.post(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
mTimeoutBar.incrementProgressBy(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, 1000, 1000);
|
||||
|
||||
mContext.registerReceiver(mReceiver, mFilter);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
if (mDialogState != DialogState.WPS_COMPLETE) {
|
||||
mWifiManager.cancelWps(null);
|
||||
}
|
||||
|
||||
if (mReceiver != null) {
|
||||
mContext.unregisterReceiver(mReceiver);
|
||||
mReceiver = null;
|
||||
}
|
||||
|
||||
if (mTimer != null) {
|
||||
mTimer.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateDialog(final DialogState state, final String msg) {
|
||||
if (mDialogState.ordinal() >= state.ordinal()) {
|
||||
//ignore.
|
||||
return;
|
||||
}
|
||||
mDialogState = state;
|
||||
mMsgString = msg;
|
||||
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
switch(state) {
|
||||
case WPS_COMPLETE:
|
||||
mTimeoutBar.setVisibility(View.GONE);
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
case CONNECTED:
|
||||
case WPS_FAILED:
|
||||
mButton.setText(mContext.getString(R.string.dlg_ok));
|
||||
mTimeoutBar.setVisibility(View.GONE);
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
if (mReceiver != null) {
|
||||
mContext.unregisterReceiver(mReceiver);
|
||||
mReceiver = null;
|
||||
}
|
||||
break;
|
||||
}
|
||||
mTextView.setText(msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void handleEvent(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) {
|
||||
final int state = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,
|
||||
WifiManager.WIFI_STATE_UNKNOWN);
|
||||
if (state == WifiManager.WIFI_STATE_DISABLED) {
|
||||
if (mTimer != null) {
|
||||
mTimer.cancel();
|
||||
mTimer = null;
|
||||
}
|
||||
String msg = mContext.getString(R.string.wifi_wps_failed_wifi_disconnected);
|
||||
updateDialog(DialogState.WPS_FAILED, msg);
|
||||
}
|
||||
} else if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) {
|
||||
NetworkInfo info = (NetworkInfo) intent.getParcelableExtra(
|
||||
WifiManager.EXTRA_NETWORK_INFO);
|
||||
final NetworkInfo.DetailedState state = info.getDetailedState();
|
||||
if (state == DetailedState.CONNECTED &&
|
||||
mDialogState == DialogState.WPS_COMPLETE) {
|
||||
WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
|
||||
if (wifiInfo != null) {
|
||||
String msg = String.format(mContext.getString(
|
||||
R.string.wifi_wps_connected), wifiInfo.getSSID());
|
||||
updateDialog(DialogState.CONNECTED, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void startWps() {
|
||||
WpsInfo wpsConfig = new WpsInfo();
|
||||
wpsConfig.setup = mWpsSetup;
|
||||
mWifiManager.startWps(wpsConfig, mWpsListener);
|
||||
}
|
||||
}
|
@@ -1,155 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.Dialog;
|
||||
import android.app.FragmentManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.net.wifi.WpsInfo;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnPause;
|
||||
import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||
|
||||
/**
|
||||
* {@link PreferenceControllerMixin} that shows Dialog for WPS progress. Disabled when Wi-Fi is off.
|
||||
*/
|
||||
public class WpsPreferenceController extends AbstractPreferenceController
|
||||
implements PreferenceControllerMixin, LifecycleObserver, OnPause, OnResume {
|
||||
|
||||
private static final String KEY_WPS_PUSH = "wps_push_button";
|
||||
private static final String KEY_WPS_PIN = "wps_pin_entry";
|
||||
|
||||
private final WifiManager mWifiManager;
|
||||
private final FragmentManager mFragmentManager;
|
||||
@VisibleForTesting
|
||||
final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
togglePreferences();
|
||||
}
|
||||
};
|
||||
private final IntentFilter mFilter = new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION);
|
||||
|
||||
private Preference mWpsPushPref;
|
||||
private Preference mWpsPinPref;
|
||||
|
||||
public WpsPreferenceController(
|
||||
Context context,
|
||||
Lifecycle lifecycle,
|
||||
WifiManager wifiManager,
|
||||
FragmentManager fragmentManager) {
|
||||
super(context);
|
||||
mWifiManager = wifiManager;
|
||||
mFragmentManager = fragmentManager;
|
||||
lifecycle.addObserver(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
// Always show preference.
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
// Returns null because this controller contains more than 1 preference.
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mWpsPushPref = screen.findPreference(KEY_WPS_PUSH);
|
||||
mWpsPinPref = screen.findPreference(KEY_WPS_PIN);
|
||||
if (mWpsPushPref == null || mWpsPinPref == null) {
|
||||
return;
|
||||
}
|
||||
// WpsDialog: Create the dialog like WifiSettings does.
|
||||
mWpsPushPref.setOnPreferenceClickListener((arg) -> {
|
||||
WpsFragment wpsFragment = new WpsFragment(WpsInfo.PBC);
|
||||
wpsFragment.show(mFragmentManager, KEY_WPS_PUSH);
|
||||
return true;
|
||||
}
|
||||
);
|
||||
|
||||
// WpsDialog: Create the dialog like WifiSettings does.
|
||||
mWpsPinPref.setOnPreferenceClickListener((arg) -> {
|
||||
WpsFragment wpsFragment = new WpsFragment(WpsInfo.DISPLAY);
|
||||
wpsFragment.show(mFragmentManager, KEY_WPS_PIN);
|
||||
return true;
|
||||
});
|
||||
togglePreferences();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
mContext.registerReceiver(mReceiver, mFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
mContext.unregisterReceiver(mReceiver);
|
||||
}
|
||||
|
||||
private void togglePreferences() {
|
||||
if (mWpsPushPref != null && mWpsPinPref != null) {
|
||||
boolean enabled = mWifiManager.isWifiEnabled();
|
||||
mWpsPushPref.setEnabled(enabled);
|
||||
mWpsPinPref.setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fragment for Dialog to show WPS progress.
|
||||
*/
|
||||
public static class WpsFragment extends InstrumentedDialogFragment {
|
||||
private static int mWpsSetup;
|
||||
|
||||
// Public default constructor is required for rotation.
|
||||
public WpsFragment() {
|
||||
super();
|
||||
}
|
||||
|
||||
public WpsFragment(int wpsSetup) {
|
||||
super();
|
||||
mWpsSetup = wpsSetup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.DIALOG_WPS_SETUP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
return new WpsDialog(getActivity(), mWpsSetup);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user