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
Before Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 2.5 KiB |
Before Width: | Height: | Size: 2.5 KiB |
Before Width: | Height: | Size: 2.8 KiB |
Before Width: | Height: | Size: 2.8 KiB |
@@ -1,66 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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.
|
||||
-->
|
||||
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="300sp"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="8dip"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/wps_dialog_txt"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dip" />
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="8dip"
|
||||
android:src="?attr/ic_wps" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/wps_timeout_bar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dip"
|
||||
style="?android:attr/progressBarStyleHorizontal" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/wps_progress_bar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dip"
|
||||
style="?android:attr/progressBarStyle" />
|
||||
|
||||
<RelativeLayout
|
||||
android:gravity="center"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<Button
|
||||
android:id="@+id/wps_dialog_btn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/cancel" />
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
@@ -1845,12 +1845,8 @@
|
||||
<string name="wifi_configure_settings_preference_summary_wakeup_off">Wi\u2011Fi doesn\u0027t turn back on automatically</string>
|
||||
<!-- Header for the list of wifi networks-->
|
||||
<string name="wifi_access_points">Wi\u2011Fi networks</string>
|
||||
<!-- Menu option to do WPS Push Button [CHAR LIMIT=25]-->
|
||||
<string name="wifi_menu_wps_pbc">WPS Push Button</string>
|
||||
<!-- Content description for menu button in Wifi setup. Not shown on the screen. [CHAR LIMIT=NONE] -->
|
||||
<string name="wifi_menu_more_options">More options</string>
|
||||
<!-- Menu option to do WPS Pin Entry [CHAR LIMIT=25]-->
|
||||
<string name="wifi_menu_wps_pin">WPS Pin Entry</string>
|
||||
<!-- Menu option to launch Wi-Fi Direct settings [CHAR LIMIT=20]-->
|
||||
<string name="wifi_menu_p2p">Wi\u2011Fi Direct</string>
|
||||
<!-- Menu option to scan Wi-Fi networks -->
|
||||
@@ -1887,32 +1883,6 @@
|
||||
<string name="wifi_advanced_toggle_description_expanded">Drop down list Advanced Options. Double-tap to collapse.</string>
|
||||
<!-- Message for talkback to say when Advanced Options is collapsed [CHAR LIMIT=NONE] -->
|
||||
<string name="wifi_advanced_toggle_description_collapsed">Drop down list Advanced Options. Double-tap to expand.</string>
|
||||
<!-- Title for the WPS setup dialog [CHAR LIMIT=50] -->
|
||||
<string name="wifi_wps_setup_title">Wi\u2011Fi Protected Setup</string>
|
||||
<!-- Message in WPS dialog at start up [CHAR LIMIT=150] -->
|
||||
<string name="wifi_wps_setup_msg">Starting WPS\u2026</string>
|
||||
<!-- Message in WPS dialog for PBC after start up [CHAR LIMIT=150] -->
|
||||
<string name="wifi_wps_onstart_pbc">Press the Wi\u2011Fi Protected Setup button on your router. It may be called \u201cWPS\u201d or marked with this symbol:</string>
|
||||
<!-- Message in WPS dialog for PIN after start up [CHAR LIMIT=150] -->
|
||||
<string name="wifi_wps_onstart_pin">Enter pin <xliff:g id="number">%1$s</xliff:g> on your Wi\u2011Fi router. The setup can take up to two minutes to complete.</string>
|
||||
<!-- Text displayed when WPS succeeds [CHAR LIMIT=150] -->
|
||||
<string name="wifi_wps_complete">WPS succeeded. Connecting to the network\u2026</string>
|
||||
<!-- Text displayed when Wi-Fi is connected through WPS [CHAR LIMIT=150] -->
|
||||
<string name="wifi_wps_connected">Connected to Wi\u2011Fi network <xliff:g id="network_name">%s</xliff:g></string>
|
||||
<!-- Text displayed when WPS setup is in progress [CHAR LIMIT=150] -->
|
||||
<string name="wifi_wps_in_progress">WPS is already in progress and can take up to two minutes to complete</string>
|
||||
<!-- Text displayed when WPS fails to start [CHAR LIMIT=150] -->
|
||||
<string name="wifi_wps_failed_generic">WPS failed. Please try again in a few minutes.</string>
|
||||
<!-- Text displayed when WPS fails due to WEP [CHAR LIMIT=150] -->
|
||||
<string name="wifi_wps_failed_wep">The wireless router security setting (WEP) is not supported</string>
|
||||
<!-- Text displayed when WPS fails to TKIP [CHAR LIMIT=150] -->
|
||||
<string name="wifi_wps_failed_tkip">The wireless router security setting (TKIP) is not supported</string>
|
||||
<!-- Text displayed when WPS fails due to authentication issues [CHAR LIMIT=150] -->
|
||||
<string name="wifi_wps_failed_auth">Authentication failure. Please try again.</string>
|
||||
<!-- Text displayed when WPS fails due to another session [CHAR LIMIT=150] -->
|
||||
<string name="wifi_wps_failed_overlap">Another WPS session was detected. Please try again in a few minutes.</string>
|
||||
<!-- Text displayed when WPS fails due to wifi disconnected [CHAR LIMIT=150] -->
|
||||
<string name="wifi_wps_failed_wifi_disconnected">Wi\u2011Fi disconnected. WPS setup canceled.</string>
|
||||
<!-- Label for the SSID of the network -->
|
||||
<string name="wifi_ssid">Network name</string>
|
||||
<!-- Hint for a text field to enter the SSID of a hidden wifi network. [CHAR LIMIT=35] -->
|
||||
|
@@ -17,7 +17,6 @@
|
||||
<resources>
|
||||
<attr name="fingerprint_layout_theme" format="reference" />
|
||||
<attr name="ic_menu_moreoverflow" format="reference" />
|
||||
<attr name="ic_wps" format="reference" />
|
||||
<attr name="side_margin" format="reference|dimension" />
|
||||
<attr name="wifi_signal_color" format="reference" />
|
||||
|
||||
@@ -28,7 +27,6 @@
|
||||
<item name="*android:preferencePanelStyle">@*android:style/PreferencePanel.Dialog</item>
|
||||
<item name="fingerprint_layout_theme">@style/FingerprintLayoutTheme</item>
|
||||
<item name="ic_menu_moreoverflow">@*android:drawable/ic_menu_moreoverflow_material</item>
|
||||
<item name="ic_wps">@drawable/ic_wps_dark</item>
|
||||
<item name="side_margin">0dip</item>
|
||||
<item name="wifi_signal_color">@color/setup_wizard_wifi_color_dark</item>
|
||||
<item name="wifi_signal">@drawable/wifi_signal</item>
|
||||
@@ -47,7 +45,6 @@
|
||||
<item name="*android:preferencePanelStyle">@*android:style/PreferencePanel.Dialog</item>
|
||||
<item name="fingerprint_layout_theme">@style/FingerprintLayoutTheme</item>
|
||||
<item name="ic_menu_moreoverflow">@*android:drawable/ic_menu_moreoverflow_material</item>
|
||||
<item name="ic_wps">@drawable/ic_wps_light</item>
|
||||
<item name="side_margin">0dip</item>
|
||||
<item name="wifi_signal_color">@color/setup_wizard_wifi_color_light</item>
|
||||
<item name="wifi_signal">@drawable/wifi_signal</item>
|
||||
@@ -65,7 +62,6 @@
|
||||
<item name="*android:preferencePanelStyle">@*android:style/PreferencePanel.Dialog</item>
|
||||
<item name="fingerprint_layout_theme">@style/FingerprintLayoutTheme</item>
|
||||
<item name="ic_menu_moreoverflow">@*android:drawable/ic_menu_moreoverflow_material</item>
|
||||
<item name="ic_wps">@drawable/ic_wps_dark</item>
|
||||
<item name="side_margin">0dip</item>
|
||||
<item name="wifi_signal_color">@color/setup_wizard_wifi_color_dark</item>
|
||||
<item name="wifi_signal">@drawable/wifi_signal</item>
|
||||
@@ -84,7 +80,6 @@
|
||||
<item name="*android:preferencePanelStyle">@*android:style/PreferencePanel.Dialog</item>
|
||||
<item name="fingerprint_layout_theme">@style/FingerprintLayoutTheme</item>
|
||||
<item name="ic_menu_moreoverflow">@*android:drawable/ic_menu_moreoverflow_material</item>
|
||||
<item name="ic_wps">@drawable/ic_wps_light</item>
|
||||
<item name="side_margin">0dip</item>
|
||||
<item name="wifi_signal_color">@color/setup_wizard_wifi_color_light</item>
|
||||
<item name="wifi_signal">@drawable/wifi_signal</item>
|
||||
@@ -102,7 +97,6 @@
|
||||
<item name="*android:preferencePanelStyle">@*android:style/PreferencePanel.Dialog</item>
|
||||
<item name="fingerprint_layout_theme">@style/FingerprintLayoutTheme</item>
|
||||
<item name="ic_menu_moreoverflow">@*android:drawable/ic_menu_moreoverflow_material</item>
|
||||
<item name="ic_wps">@drawable/ic_wps_dark</item>
|
||||
<item name="side_margin">0dip</item>
|
||||
<item name="wifi_signal_color">@color/setup_wizard_wifi_color_dark</item>
|
||||
<item name="wifi_signal">@drawable/wifi_signal</item>
|
||||
@@ -121,7 +115,6 @@
|
||||
<item name="*android:preferencePanelStyle">@*android:style/PreferencePanel.Dialog</item>
|
||||
<item name="fingerprint_layout_theme">@style/FingerprintLayoutTheme</item>
|
||||
<item name="ic_menu_moreoverflow">@*android:drawable/ic_menu_moreoverflow_material</item>
|
||||
<item name="ic_wps">@drawable/ic_wps_light</item>
|
||||
<item name="side_margin">0dip</item>
|
||||
<item name="wifi_signal_color">@color/setup_wizard_wifi_color_light</item>
|
||||
<item name="wifi_signal">@drawable/wifi_signal</item>
|
||||
@@ -221,7 +214,6 @@
|
||||
|
||||
<item name="fingerprint_layout_theme">@style/FingerprintLayoutTheme</item>
|
||||
<item name="ic_menu_moreoverflow">@*android:drawable/ic_menu_moreoverflow_holo_dark</item>
|
||||
<item name="ic_wps">@drawable/ic_wps_light</item>
|
||||
<item name="wifi_signal">@drawable/wifi_signal</item>
|
||||
<item name="wifi_signal_color">?android:attr/colorAccent</item>
|
||||
<item name="wifi_friction">@drawable/wifi_friction</item>
|
||||
|
@@ -63,14 +63,6 @@
|
||||
android:title="@string/wifi_menu_p2p"
|
||||
android:fragment="com.android.settings.wifi.p2p.WifiP2pSettings"/>
|
||||
|
||||
<Preference
|
||||
android:key="wps_push_button"
|
||||
android:title="@string/wifi_menu_wps_pbc" />
|
||||
|
||||
<Preference
|
||||
android:key="wps_pin_entry"
|
||||
android:title="@string/wifi_menu_wps_pin" />
|
||||
|
||||
<Preference
|
||||
android:key="mac_address"
|
||||
android:title="@string/wifi_advanced_mac_address_title"/>
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,140 +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 static android.arch.lifecycle.Lifecycle.Event.ON_PAUSE;
|
||||
import static android.arch.lifecycle.Lifecycle.Event.ON_RESUME;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.FragmentManager;
|
||||
import android.arch.lifecycle.LifecycleOwner;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class WpsPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private Context mContext;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private WifiManager mWifiManager;
|
||||
@Mock
|
||||
private FragmentManager mFragmentManager;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private Preference mWpsPushPref;
|
||||
@Mock
|
||||
private Preference mWpsPinPref;
|
||||
|
||||
private Lifecycle mLifecycle;
|
||||
private LifecycleOwner mLifecycleOwner;
|
||||
private WpsPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mLifecycleOwner = () -> mLifecycle;
|
||||
mLifecycle = new Lifecycle(mLifecycleOwner);
|
||||
when(mContext.getSystemService(WifiManager.class))
|
||||
.thenReturn(mWifiManager);
|
||||
when(mScreen.findPreference(anyString()))
|
||||
.thenReturn(mWpsPushPref)
|
||||
.thenReturn(mWpsPinPref);
|
||||
mController = new WpsPreferenceController(
|
||||
mContext, mLifecycle, mWifiManager, mFragmentManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAvailable_shouldAlwaysReturnTrue() {
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnResume_shouldRegisterListener() {
|
||||
mLifecycle.handleLifecycleEvent(ON_RESUME);
|
||||
verify(mContext).registerReceiver(any(BroadcastReceiver.class), any(IntentFilter.class));
|
||||
}
|
||||
@Test
|
||||
public void testOnPause_shouldUnregisterListener() {
|
||||
mLifecycle.handleLifecycleEvent(ON_RESUME);
|
||||
mLifecycle.handleLifecycleEvent(ON_PAUSE);
|
||||
verify(mContext).unregisterReceiver(any(BroadcastReceiver.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWifiStateChange_shouldToggleEnabledState() {
|
||||
when(mWifiManager.isWifiEnabled()).thenReturn(true);
|
||||
|
||||
//Sets the preferences.
|
||||
mController.displayPreference(mScreen);
|
||||
verify(mWpsPushPref).setEnabled(true);
|
||||
verify(mWpsPinPref).setEnabled(true);
|
||||
|
||||
Intent dummyIntent = new Intent();
|
||||
mController.mReceiver.onReceive(mContext, dummyIntent);
|
||||
verify(mWpsPushPref, times(2)).setEnabled(true);
|
||||
verify(mWpsPinPref, times(2)).setEnabled(true);
|
||||
|
||||
when(mWifiManager.isWifiEnabled()).thenReturn(false);
|
||||
mController.mReceiver.onReceive(mContext, dummyIntent);
|
||||
verify(mWpsPushPref).setEnabled(false);
|
||||
verify(mWpsPinPref).setEnabled(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisplayPreference_shouldSetPreferenceClickListenerAndToggleEnabledState() {
|
||||
when(mWifiManager.isWifiEnabled()).thenReturn(true);
|
||||
mController.displayPreference(mScreen);
|
||||
verify(mWpsPushPref).setOnPreferenceClickListener(any());
|
||||
verify(mWpsPinPref).setOnPreferenceClickListener(any());
|
||||
verify(mWpsPushPref).setEnabled(true);
|
||||
verify(mWpsPinPref).setEnabled(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisplayPreference_shouldDisablePreferenceWhenWifiDisabled() {
|
||||
when(mWifiManager.isWifiEnabled()).thenReturn(false);
|
||||
mController.displayPreference(mScreen);
|
||||
verify(mWpsPushPref).setEnabled(false);
|
||||
verify(mWpsPinPref).setEnabled(false);
|
||||
}
|
||||
}
|