Move AdvancedWifiSettings into ConfigureWifiSettings.
Bug:34719854 Test: make -j40 RunSettingsRoboTests clicked on preferences and made sure functionality did not change. Change-Id: Ia5f0c7f5ea0f88d1322008ab58ca79028cc1a2bb
This commit is contained in:
@@ -299,27 +299,6 @@
|
|||||||
android:value="true" />
|
android:value="true" />
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity android:name="Settings$AdvancedWifiSettingsActivity"
|
|
||||||
android:taskAffinity="com.android.settings"
|
|
||||||
android:label="@string/wifi_advanced_settings_label"
|
|
||||||
android:icon="@drawable/ic_settings_wireless"
|
|
||||||
android:configChanges="orientation|keyboardHidden|screenSize"
|
|
||||||
android:parentActivityName="Settings$WifiSettingsActivity">
|
|
||||||
<intent-filter android:priority="1">
|
|
||||||
<action android:name="android.settings.WIFI_IP_SETTINGS" />
|
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
|
||||||
</intent-filter>
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.MAIN" />
|
|
||||||
<category android:name="android.intent.category.VOICE_LAUNCH" />
|
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
|
||||||
</intent-filter>
|
|
||||||
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
|
||||||
android:value="com.android.settings.wifi.AdvancedWifiSettings" />
|
|
||||||
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
|
|
||||||
android:value="true" />
|
|
||||||
</activity>
|
|
||||||
|
|
||||||
<activity android:name="Settings$SavedAccessPointsSettingsActivity"
|
<activity android:name="Settings$SavedAccessPointsSettingsActivity"
|
||||||
android:taskAffinity="com.android.settings"
|
android:taskAffinity="com.android.settings"
|
||||||
android:label="@string/wifi_saved_access_points_label"
|
android:label="@string/wifi_saved_access_points_label"
|
||||||
|
@@ -1,40 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!-- Copyright (C) 2008 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:title="@string/wifi_advanced_titlebar">
|
|
||||||
|
|
||||||
<Preference
|
|
||||||
android:key="install_credentials"
|
|
||||||
android:title="@string/wifi_install_credentials"
|
|
||||||
android:persistent="false" />
|
|
||||||
|
|
||||||
<Preference
|
|
||||||
android:key="wifi_direct"
|
|
||||||
android:title="@string/wifi_menu_p2p"
|
|
||||||
android:persistent="false" />
|
|
||||||
|
|
||||||
<Preference
|
|
||||||
android:key="wps_push_button"
|
|
||||||
android:title="@string/wifi_menu_wps_pbc"
|
|
||||||
android:persistent="false" />
|
|
||||||
|
|
||||||
<Preference
|
|
||||||
android:key="wps_pin_entry"
|
|
||||||
android:title="@string/wifi_menu_wps_pin"
|
|
||||||
android:persistent="false" />
|
|
||||||
|
|
||||||
</PreferenceScreen>
|
|
@@ -52,4 +52,29 @@
|
|||||||
android:key="current_ip_address"
|
android:key="current_ip_address"
|
||||||
android:title="@string/wifi_advanced_ip_address_title"/>
|
android:title="@string/wifi_advanced_ip_address_title"/>
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="install_credentials"
|
||||||
|
android:title="@string/wifi_install_credentials">
|
||||||
|
<intent android:action="android.credentials.INSTALL_AS_USER"
|
||||||
|
android:targetPackage="com.android.certinstaller"
|
||||||
|
android:targetClass="com.android.certinstaller.CertInstallerMain">
|
||||||
|
<extra android:name="install_as_uid" android:value="1010"/>
|
||||||
|
</intent>
|
||||||
|
</Preference>
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="wifi_direct"
|
||||||
|
android:title="@string/wifi_menu_p2p">
|
||||||
|
<intent android:targetPackage="com.android.settings"
|
||||||
|
android:targetClass="com.android.settings.Settings$WifiP2pSettingsActivity"/>
|
||||||
|
</Preference>
|
||||||
|
|
||||||
|
<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" />
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
@@ -95,7 +95,6 @@ public class Settings extends SettingsActivity {
|
|||||||
public static class DeviceAdminSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class DeviceAdminSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class DataUsageSummaryActivity extends SettingsActivity { /* empty */ }
|
public static class DataUsageSummaryActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class ConfigureWifiSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class ConfigureWifiSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class AdvancedWifiSettingsActivity extends SettingsActivity { /* empty */ }
|
|
||||||
public static class SavedAccessPointsSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class SavedAccessPointsSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class TextToSpeechSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class TextToSpeechSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class AndroidBeamSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class AndroidBeamSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
|
@@ -122,7 +122,6 @@ import com.android.settings.tts.TextToSpeechSettings;
|
|||||||
import com.android.settings.users.UserSettings;
|
import com.android.settings.users.UserSettings;
|
||||||
import com.android.settings.vpn2.VpnSettings;
|
import com.android.settings.vpn2.VpnSettings;
|
||||||
import com.android.settings.wfd.WifiDisplaySettings;
|
import com.android.settings.wfd.WifiDisplaySettings;
|
||||||
import com.android.settings.wifi.AdvancedWifiSettings;
|
|
||||||
import com.android.settings.wifi.ConfigureWifiSettings;
|
import com.android.settings.wifi.ConfigureWifiSettings;
|
||||||
import com.android.settings.wifi.SavedAccessPointsWifiSettings;
|
import com.android.settings.wifi.SavedAccessPointsWifiSettings;
|
||||||
import com.android.settings.wifi.WifiAPITest;
|
import com.android.settings.wifi.WifiAPITest;
|
||||||
@@ -140,7 +139,6 @@ public class SettingsGateway {
|
|||||||
WirelessSettings.class.getName(),
|
WirelessSettings.class.getName(),
|
||||||
WifiSettings.class.getName(),
|
WifiSettings.class.getName(),
|
||||||
ConfigureWifiSettings.class.getName(),
|
ConfigureWifiSettings.class.getName(),
|
||||||
AdvancedWifiSettings.class.getName(),
|
|
||||||
SavedAccessPointsWifiSettings.class.getName(),
|
SavedAccessPointsWifiSettings.class.getName(),
|
||||||
BluetoothSettings.class.getName(),
|
BluetoothSettings.class.getName(),
|
||||||
SimSettings.class.getName(),
|
SimSettings.class.getName(),
|
||||||
|
@@ -56,7 +56,6 @@ import com.android.settings.print.PrintSettingsFragment;
|
|||||||
import com.android.settings.sim.SimSettings;
|
import com.android.settings.sim.SimSettings;
|
||||||
import com.android.settings.system.SystemDashboardFragment;
|
import com.android.settings.system.SystemDashboardFragment;
|
||||||
import com.android.settings.users.UserSettings;
|
import com.android.settings.users.UserSettings;
|
||||||
import com.android.settings.wifi.AdvancedWifiSettings;
|
|
||||||
import com.android.settings.wifi.ConfigureWifiSettings;
|
import com.android.settings.wifi.ConfigureWifiSettings;
|
||||||
import com.android.settings.wifi.SavedAccessPointsWifiSettings;
|
import com.android.settings.wifi.SavedAccessPointsWifiSettings;
|
||||||
import com.android.settings.wifi.WifiSettings;
|
import com.android.settings.wifi.WifiSettings;
|
||||||
@@ -106,7 +105,6 @@ public final class Ranking {
|
|||||||
// Wi-Fi
|
// Wi-Fi
|
||||||
sRankMap.put(WifiSettings.class.getName(), RANK_WIFI);
|
sRankMap.put(WifiSettings.class.getName(), RANK_WIFI);
|
||||||
sRankMap.put(ConfigureWifiSettings.class.getName(), RANK_WIFI);
|
sRankMap.put(ConfigureWifiSettings.class.getName(), RANK_WIFI);
|
||||||
sRankMap.put(AdvancedWifiSettings.class.getName(), RANK_WIFI);
|
|
||||||
sRankMap.put(SavedAccessPointsWifiSettings.class.getName(), RANK_WIFI);
|
sRankMap.put(SavedAccessPointsWifiSettings.class.getName(), RANK_WIFI);
|
||||||
|
|
||||||
// BT
|
// BT
|
||||||
|
@@ -76,7 +76,6 @@ import com.android.settings.system.SystemDashboardFragment;
|
|||||||
import com.android.settings.tts.TtsEnginePreferenceFragment;
|
import com.android.settings.tts.TtsEnginePreferenceFragment;
|
||||||
import com.android.settings.tts.TtsSlidersFragment;
|
import com.android.settings.tts.TtsSlidersFragment;
|
||||||
import com.android.settings.users.UserSettings;
|
import com.android.settings.users.UserSettings;
|
||||||
import com.android.settings.wifi.AdvancedWifiSettings;
|
|
||||||
import com.android.settings.wifi.ConfigureWifiSettings;
|
import com.android.settings.wifi.ConfigureWifiSettings;
|
||||||
import com.android.settings.wifi.SavedAccessPointsWifiSettings;
|
import com.android.settings.wifi.SavedAccessPointsWifiSettings;
|
||||||
import com.android.settings.wifi.WifiSettings;
|
import com.android.settings.wifi.WifiSettings;
|
||||||
@@ -103,7 +102,6 @@ public final class SearchIndexableResources {
|
|||||||
static {
|
static {
|
||||||
addIndex(WifiSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_wireless);
|
addIndex(WifiSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_wireless);
|
||||||
addIndex(NetworkDashboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_wireless);
|
addIndex(NetworkDashboardFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_wireless);
|
||||||
addIndex(AdvancedWifiSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_wireless);
|
|
||||||
addIndex(ConfigureWifiSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_wireless);
|
addIndex(ConfigureWifiSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_wireless);
|
||||||
addIndex(SavedAccessPointsWifiSettings.class, NO_DATA_RES_ID,
|
addIndex(SavedAccessPointsWifiSettings.class, NO_DATA_RES_ID,
|
||||||
R.drawable.ic_settings_wireless);
|
R.drawable.ic_settings_wireless);
|
||||||
|
@@ -1,184 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011 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.DialogFragment;
|
|
||||||
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.os.UserManager;
|
|
||||||
import android.provider.SearchIndexableResource;
|
|
||||||
import android.security.Credentials;
|
|
||||||
import android.support.v7.preference.Preference;
|
|
||||||
import android.support.v7.preference.Preference.OnPreferenceClickListener;
|
|
||||||
import android.support.v7.preference.PreferenceScreen;
|
|
||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.RestrictedSettingsFragment;
|
|
||||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
|
||||||
import com.android.settings.search.Indexable;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class AdvancedWifiSettings extends RestrictedSettingsFragment {
|
|
||||||
private static final String TAG = "AdvancedWifiSettings";
|
|
||||||
|
|
||||||
private static final String KEY_INSTALL_CREDENTIALS = "install_credentials";
|
|
||||||
private static final String KEY_WIFI_DIRECT = "wifi_direct";
|
|
||||||
private static final String KEY_WPS_PUSH = "wps_push_button";
|
|
||||||
private static final String KEY_WPS_PIN = "wps_pin_entry";
|
|
||||||
|
|
||||||
private boolean mUnavailable;
|
|
||||||
|
|
||||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
initPreferences();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public AdvancedWifiSettings() {
|
|
||||||
super(UserManager.DISALLOW_CONFIG_WIFI);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMetricsCategory() {
|
|
||||||
return MetricsEvent.WIFI_ADVANCED;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
if (isUiRestricted()) {
|
|
||||||
mUnavailable = true;
|
|
||||||
setPreferenceScreen(new PreferenceScreen(getPrefContext(), null));
|
|
||||||
} else {
|
|
||||||
addPreferencesFromResource(R.xml.wifi_advanced_settings);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
|
||||||
super.onActivityCreated(savedInstanceState);
|
|
||||||
getEmptyTextView().setText(R.string.wifi_advanced_not_available);
|
|
||||||
if (mUnavailable) {
|
|
||||||
getPreferenceScreen().removeAll();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStart() {
|
|
||||||
super.onStart();
|
|
||||||
if (!mUnavailable) {
|
|
||||||
getActivity().registerReceiver(mReceiver,
|
|
||||||
new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION));
|
|
||||||
initPreferences();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStop() {
|
|
||||||
super.onStop();
|
|
||||||
if (!mUnavailable) {
|
|
||||||
getActivity().unregisterReceiver(mReceiver);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initPreferences() {
|
|
||||||
final Context context = getActivity();
|
|
||||||
Intent intent = new Intent(Credentials.INSTALL_AS_USER_ACTION);
|
|
||||||
intent.setClassName("com.android.certinstaller",
|
|
||||||
"com.android.certinstaller.CertInstallerMain");
|
|
||||||
intent.putExtra(Credentials.EXTRA_INSTALL_AS_UID, android.os.Process.WIFI_UID);
|
|
||||||
Preference pref = findPreference(KEY_INSTALL_CREDENTIALS);
|
|
||||||
pref.setIntent(intent);
|
|
||||||
|
|
||||||
final WifiManager wifiManager =
|
|
||||||
(WifiManager)getActivity().getSystemService(Context.WIFI_SERVICE);
|
|
||||||
Intent wifiDirectIntent = new Intent(context,
|
|
||||||
com.android.settings.Settings.WifiP2pSettingsActivity.class);
|
|
||||||
Preference wifiDirectPref = findPreference(KEY_WIFI_DIRECT);
|
|
||||||
wifiDirectPref.setIntent(wifiDirectIntent);
|
|
||||||
wifiDirectPref.setEnabled(wifiManager.isWifiEnabled());
|
|
||||||
|
|
||||||
// WpsDialog: Create the dialog like WifiSettings does.
|
|
||||||
Preference wpsPushPref = findPreference(KEY_WPS_PUSH);
|
|
||||||
wpsPushPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
|
||||||
public boolean onPreferenceClick(Preference arg0) {
|
|
||||||
WpsFragment wpsFragment = new WpsFragment(WpsInfo.PBC);
|
|
||||||
wpsFragment.show(getFragmentManager(), KEY_WPS_PUSH);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
wpsPushPref.setEnabled(wifiManager.isWifiEnabled());
|
|
||||||
|
|
||||||
// WpsDialog: Create the dialog like WifiSettings does.
|
|
||||||
Preference wpsPinPref = findPreference(KEY_WPS_PIN);
|
|
||||||
wpsPinPref.setOnPreferenceClickListener(new OnPreferenceClickListener(){
|
|
||||||
public boolean onPreferenceClick(Preference arg0) {
|
|
||||||
WpsFragment wpsFragment = new WpsFragment(WpsInfo.DISPLAY);
|
|
||||||
wpsFragment.show(getFragmentManager(), KEY_WPS_PIN);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
wpsPinPref.setEnabled(wifiManager.isWifiEnabled());
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wrapper class for the WPS dialog to properly handle life cycle events like rotation. */
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
|
||||||
new BaseSearchIndexProvider() {
|
|
||||||
@Override
|
|
||||||
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
|
|
||||||
boolean enabled) {
|
|
||||||
final SearchIndexableResource sir = new SearchIndexableResource(context);
|
|
||||||
sir.xmlResId = R.xml.wifi_advanced_settings;
|
|
||||||
return Arrays.asList(sir);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
@@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.settings.wifi;
|
package com.android.settings.wifi;
|
||||||
|
|
||||||
|
import static android.content.Context.WIFI_SERVICE;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.provider.SearchIndexableResource;
|
import android.provider.SearchIndexableResource;
|
||||||
@@ -25,13 +27,12 @@ import com.android.settings.core.PreferenceController;
|
|||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settings.search.Indexable;
|
import com.android.settings.search.Indexable;
|
||||||
|
import com.android.settings.wifi.p2p.WifiP2pPreferenceController;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static android.content.Context.WIFI_SERVICE;
|
|
||||||
|
|
||||||
public class ConfigureWifiSettings extends DashboardFragment {
|
public class ConfigureWifiSettings extends DashboardFragment {
|
||||||
|
|
||||||
private static final String TAG = "ConfigureWifiSettings";
|
private static final String TAG = "ConfigureWifiSettings";
|
||||||
@@ -63,6 +64,9 @@ public class ConfigureWifiSettings extends DashboardFragment {
|
|||||||
controllers.add(new NotifyOpenNetworksPreferenceController(context, getLifecycle()));
|
controllers.add(new NotifyOpenNetworksPreferenceController(context, getLifecycle()));
|
||||||
controllers.add(new WifiWakeupPreferenceController(context, getLifecycle()));
|
controllers.add(new WifiWakeupPreferenceController(context, getLifecycle()));
|
||||||
controllers.add(new WifiSleepPolicyPreferenceController(context));
|
controllers.add(new WifiSleepPolicyPreferenceController(context));
|
||||||
|
controllers.add(new WifiP2pPreferenceController(context, getLifecycle(), mWifiManager));
|
||||||
|
controllers.add(new WpsPreferenceController(
|
||||||
|
context, getLifecycle(), mWifiManager, getFragmentManager()));
|
||||||
return controllers;
|
return controllers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -39,8 +39,9 @@ public class WifiPickerActivity extends SettingsActivity implements ButtonBarHan
|
|||||||
protected boolean isValidFragment(String fragmentName) {
|
protected boolean isValidFragment(String fragmentName) {
|
||||||
if (WifiSettings.class.getName().equals(fragmentName)
|
if (WifiSettings.class.getName().equals(fragmentName)
|
||||||
|| WifiP2pSettings.class.getName().equals(fragmentName)
|
|| WifiP2pSettings.class.getName().equals(fragmentName)
|
||||||
|| SavedAccessPointsWifiSettings.class.getName().equals(fragmentName)
|
|| SavedAccessPointsWifiSettings.class.getName().equals(fragmentName)) {
|
||||||
|| AdvancedWifiSettings.class.getName().equals(fragmentName)) return true;
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -93,7 +93,6 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
|
|
||||||
/* package */ static final int MENU_ID_WPS_PBC = Menu.FIRST;
|
/* 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_WPS_PIN = Menu.FIRST + 1;
|
||||||
private static final int MENU_ID_ADVANCED = Menu.FIRST + 4;
|
|
||||||
private static final int MENU_ID_SCAN = Menu.FIRST + 5;
|
private static final int MENU_ID_SCAN = Menu.FIRST + 5;
|
||||||
private static final int MENU_ID_CONNECT = Menu.FIRST + 6;
|
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_FORGET = Menu.FIRST + 7;
|
||||||
@@ -113,6 +112,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
private static final String PREF_KEY_EMPTY_WIFI_LIST = "wifi_empty_list";
|
private static final String PREF_KEY_EMPTY_WIFI_LIST = "wifi_empty_list";
|
||||||
private static final String PREF_KEY_ACCESS_POINTS = "access_points";
|
private static final String PREF_KEY_ACCESS_POINTS = "access_points";
|
||||||
private static final String PREF_KEY_ADDITIONAL_SETTINGS = "additional_settings";
|
private static final String PREF_KEY_ADDITIONAL_SETTINGS = "additional_settings";
|
||||||
|
private static final String PREF_KEY_CONFIGURE_WIFI_SETTINGS = "configure_settings";
|
||||||
private static final String PREF_KEY_SAVED_NETWORKS = "saved_networks";
|
private static final String PREF_KEY_SAVED_NETWORKS = "saved_networks";
|
||||||
|
|
||||||
protected WifiManager mWifiManager;
|
protected WifiManager mWifiManager;
|
||||||
@@ -155,6 +155,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
private PreferenceCategory mAccessPointsPreferenceCategory;
|
private PreferenceCategory mAccessPointsPreferenceCategory;
|
||||||
private PreferenceCategory mAdditionalSettingsPreferenceCategory;
|
private PreferenceCategory mAdditionalSettingsPreferenceCategory;
|
||||||
private Preference mAddPreference;
|
private Preference mAddPreference;
|
||||||
|
private Preference mConfigureWifiSettingsPreference;
|
||||||
private Preference mSavedNetworksPreference;
|
private Preference mSavedNetworksPreference;
|
||||||
private LinkablePreference mStatusMessagePreference;
|
private LinkablePreference mStatusMessagePreference;
|
||||||
|
|
||||||
@@ -186,6 +187,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
(PreferenceCategory) findPreference(PREF_KEY_ACCESS_POINTS);
|
(PreferenceCategory) findPreference(PREF_KEY_ACCESS_POINTS);
|
||||||
mAdditionalSettingsPreferenceCategory =
|
mAdditionalSettingsPreferenceCategory =
|
||||||
(PreferenceCategory) findPreference(PREF_KEY_ADDITIONAL_SETTINGS);
|
(PreferenceCategory) findPreference(PREF_KEY_ADDITIONAL_SETTINGS);
|
||||||
|
mConfigureWifiSettingsPreference = findPreference(PREF_KEY_CONFIGURE_WIFI_SETTINGS);
|
||||||
mSavedNetworksPreference = findPreference(PREF_KEY_SAVED_NETWORKS);
|
mSavedNetworksPreference = findPreference(PREF_KEY_SAVED_NETWORKS);
|
||||||
|
|
||||||
Context prefContext = getPrefContext();
|
Context prefContext = getPrefContext();
|
||||||
@@ -359,9 +361,6 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
* @param menu
|
* @param menu
|
||||||
*/
|
*/
|
||||||
void addOptionsMenuItems(Menu menu) {
|
void addOptionsMenuItems(Menu menu) {
|
||||||
menu.add(Menu.NONE, MENU_ID_ADVANCED, 0, R.string.wifi_menu_advanced)
|
|
||||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
|
|
||||||
|
|
||||||
final boolean wifiIsEnabled = mWifiTracker.isWifiEnabled();
|
final boolean wifiIsEnabled = mWifiTracker.isWifiEnabled();
|
||||||
mScanMenuItem = menu.add(Menu.NONE, MENU_ID_SCAN, 0, R.string.menu_stats_refresh)
|
mScanMenuItem = menu.add(Menu.NONE, MENU_ID_SCAN, 0, R.string.menu_stats_refresh)
|
||||||
.setIcon(com.android.internal.R.drawable.ic_menu_refresh);
|
.setIcon(com.android.internal.R.drawable.ic_menu_refresh);
|
||||||
@@ -425,17 +424,6 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
mMetricsFeatureProvider.action(getActivity(), MetricsEvent.ACTION_WIFI_FORCE_SCAN);
|
mMetricsFeatureProvider.action(getActivity(), MetricsEvent.ACTION_WIFI_FORCE_SCAN);
|
||||||
mWifiTracker.forceScan();
|
mWifiTracker.forceScan();
|
||||||
return true;
|
return true;
|
||||||
case MENU_ID_ADVANCED:
|
|
||||||
if (getActivity() instanceof SettingsActivity) {
|
|
||||||
((SettingsActivity) getActivity()).startPreferencePanel(
|
|
||||||
AdvancedWifiSettings.class.getCanonicalName(), null,
|
|
||||||
R.string.wifi_advanced_titlebar, null, this, 0);
|
|
||||||
} else {
|
|
||||||
startFragment(this, AdvancedWifiSettings.class.getCanonicalName(),
|
|
||||||
R.string.wifi_advanced_titlebar, -1 /* Do not request a results */,
|
|
||||||
null);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
@@ -689,11 +677,11 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
mAccessPointsPreferenceCategory.addPreference(pref);
|
mAccessPointsPreferenceCategory.addPreference(pref);
|
||||||
mAddPreference.setOrder(index++);
|
mAddPreference.setOrder(index++);
|
||||||
mAccessPointsPreferenceCategory.addPreference(mAddPreference);
|
mAccessPointsPreferenceCategory.addPreference(mAddPreference);
|
||||||
setSavedNetworkPreferenceVisibility();
|
setConfigureWifiSettingsVisibility();
|
||||||
} else {
|
} else {
|
||||||
mAddPreference.setOrder(index++);
|
mAddPreference.setOrder(index++);
|
||||||
mAccessPointsPreferenceCategory.addPreference(mAddPreference);
|
mAccessPointsPreferenceCategory.addPreference(mAddPreference);
|
||||||
setSavedNetworkPreferenceVisibility();
|
setConfigureWifiSettingsVisibility();
|
||||||
setProgressBarVisible(false);
|
setProgressBarVisible(false);
|
||||||
}
|
}
|
||||||
if (mScanMenuItem != null) {
|
if (mScanMenuItem != null) {
|
||||||
@@ -713,7 +701,7 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
|
|
||||||
case WifiManager.WIFI_STATE_DISABLED:
|
case WifiManager.WIFI_STATE_DISABLED:
|
||||||
setOffMessage();
|
setOffMessage();
|
||||||
setSavedNetworkPreferenceVisibility();
|
setConfigureWifiSettingsVisibility();
|
||||||
setProgressBarVisible(false);
|
setProgressBarVisible(false);
|
||||||
if (mScanMenuItem != null) {
|
if (mScanMenuItem != null) {
|
||||||
mScanMenuItem.setEnabled(false);
|
mScanMenuItem.setEnabled(false);
|
||||||
@@ -722,7 +710,12 @@ public class WifiSettings extends RestrictedSettingsFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setSavedNetworkPreferenceVisibility() {
|
private void setConfigureWifiSettingsVisibility() {
|
||||||
|
if (isUiRestricted()) {
|
||||||
|
mAdditionalSettingsPreferenceCategory.removeAll();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mAdditionalSettingsPreferenceCategory.addPreference(mConfigureWifiSettingsPreference);
|
||||||
if (mWifiTracker.doSavedNetworksExist()) {
|
if (mWifiTracker.doSavedNetworksExist()) {
|
||||||
mAdditionalSettingsPreferenceCategory.addPreference(mSavedNetworksPreference);
|
mAdditionalSettingsPreferenceCategory.addPreference(mSavedNetworksPreference);
|
||||||
} else {
|
} else {
|
||||||
|
154
src/com/android/settings/wifi/WpsPreferenceController.java
Normal file
154
src/com/android/settings/wifi/WpsPreferenceController.java
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
/*
|
||||||
|
* 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.PreferenceController;
|
||||||
|
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||||
|
import com.android.settings.core.lifecycle.Lifecycle;
|
||||||
|
import com.android.settings.core.lifecycle.LifecycleObserver;
|
||||||
|
import com.android.settings.core.lifecycle.events.OnPause;
|
||||||
|
import com.android.settings.core.lifecycle.events.OnResume;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link PreferenceController} that shows Dialog for WPS progress. Disabled when Wi-Fi is off.
|
||||||
|
*/
|
||||||
|
public class WpsPreferenceController extends PreferenceController implements
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* 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.p2p;
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
|
import android.net.wifi.WifiManager;
|
||||||
|
import android.support.annotation.VisibleForTesting;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.settings.core.PreferenceController;
|
||||||
|
import com.android.settings.core.lifecycle.Lifecycle;
|
||||||
|
import com.android.settings.core.lifecycle.LifecycleObserver;
|
||||||
|
import com.android.settings.core.lifecycle.events.OnPause;
|
||||||
|
import com.android.settings.core.lifecycle.events.OnResume;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link PreferenceController} to toggle Wifi Direct preference on Wi-Fi state.
|
||||||
|
*/
|
||||||
|
public class WifiP2pPreferenceController extends PreferenceController implements
|
||||||
|
LifecycleObserver, OnPause, OnResume {
|
||||||
|
|
||||||
|
private static final String KEY_WIFI_DIRECT = "wifi_direct";
|
||||||
|
|
||||||
|
private final WifiManager mWifiManager;
|
||||||
|
@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 mWifiDirectPref;
|
||||||
|
|
||||||
|
public WifiP2pPreferenceController(
|
||||||
|
Context context, Lifecycle lifecycle, WifiManager wifiManager) {
|
||||||
|
super(context);
|
||||||
|
mWifiManager = wifiManager;
|
||||||
|
lifecycle.addObserver(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
|
super.displayPreference(screen);
|
||||||
|
mWifiDirectPref = screen.findPreference(KEY_WIFI_DIRECT);
|
||||||
|
togglePreferences();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
mContext.registerReceiver(mReceiver, mFilter);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
mContext.unregisterReceiver(mReceiver);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAvailable() {
|
||||||
|
// Always show preference.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String getPreferenceKey() {
|
||||||
|
return KEY_WIFI_DIRECT;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void togglePreferences() {
|
||||||
|
if (mWifiDirectPref != null) {
|
||||||
|
mWifiDirectPref.setEnabled(mWifiManager.isWifiEnabled());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -81,7 +81,6 @@ com.android.settings.notification.ZenAccessSettings
|
|||||||
com.android.settings.accessibility.ToggleFontSizePreferenceFragment
|
com.android.settings.accessibility.ToggleFontSizePreferenceFragment
|
||||||
com.android.settings.accessibility.ToggleGlobalGesturePreferenceFragment
|
com.android.settings.accessibility.ToggleGlobalGesturePreferenceFragment
|
||||||
com.android.settings.wifi.ConfigureWifiSettings
|
com.android.settings.wifi.ConfigureWifiSettings
|
||||||
com.android.settings.wifi.AdvancedWifiSettings
|
|
||||||
com.android.settings.applications.PremiumSmsAccess
|
com.android.settings.applications.PremiumSmsAccess
|
||||||
com.android.settings.applications.UsageAccessDetails
|
com.android.settings.applications.UsageAccessDetails
|
||||||
com.android.settings.applications.AppStorageSettings
|
com.android.settings.applications.AppStorageSettings
|
||||||
|
@@ -0,0 +1,132 @@
|
|||||||
|
/*
|
||||||
|
* 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 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.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.SettingsRobolectricTestRunner;
|
||||||
|
import com.android.settings.TestConfig;
|
||||||
|
import com.android.settings.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 WpsPreferenceController mController;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
mLifecycle = new Lifecycle();
|
||||||
|
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.onResume();
|
||||||
|
verify(mContext).registerReceiver(any(BroadcastReceiver.class), any(IntentFilter.class));
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void testOnPause_shouldUnregisterListener() {
|
||||||
|
mLifecycle.onPause();
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,116 @@
|
|||||||
|
/*
|
||||||
|
* 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.p2p;
|
||||||
|
|
||||||
|
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.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.SettingsRobolectricTestRunner;
|
||||||
|
import com.android.settings.TestConfig;
|
||||||
|
import com.android.settings.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 WifiP2PPreferenceControllerTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private Context mContext;
|
||||||
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
|
private WifiManager mWifiManager;
|
||||||
|
@Mock
|
||||||
|
private PreferenceScreen mScreen;
|
||||||
|
@Mock
|
||||||
|
private Preference mWifiDirectPreference;
|
||||||
|
|
||||||
|
private Lifecycle mLifecycle;
|
||||||
|
private WifiP2pPreferenceController mController;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
mLifecycle = new Lifecycle();
|
||||||
|
when(mContext.getSystemService(WifiManager.class))
|
||||||
|
.thenReturn(mWifiManager);
|
||||||
|
when(mScreen.findPreference(anyString()))
|
||||||
|
.thenReturn(mWifiDirectPreference);
|
||||||
|
mController = new WifiP2pPreferenceController(mContext, mLifecycle, mWifiManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIsAvailable_shouldAlwaysReturnTrue() {
|
||||||
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOnResume_shouldRegisterListener() {
|
||||||
|
mLifecycle.onResume();
|
||||||
|
verify(mContext).registerReceiver(any(BroadcastReceiver.class), any(IntentFilter.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOnPause_shouldUnregisterListener() {
|
||||||
|
mLifecycle.onPause();
|
||||||
|
verify(mContext).unregisterReceiver(any(BroadcastReceiver.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWifiStateChange_shouldToggleEnabledState() {
|
||||||
|
when(mWifiManager.isWifiEnabled()).thenReturn(true);
|
||||||
|
|
||||||
|
//Sets the preferences.
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
verify(mWifiDirectPreference).setEnabled(true);
|
||||||
|
|
||||||
|
Intent dummyIntent = new Intent();
|
||||||
|
mController.mReceiver.onReceive(mContext, dummyIntent);
|
||||||
|
verify(mWifiDirectPreference, times(2)).setEnabled(true);
|
||||||
|
|
||||||
|
when(mWifiManager.isWifiEnabled()).thenReturn(false);
|
||||||
|
mController.mReceiver.onReceive(mContext, dummyIntent);
|
||||||
|
verify(mWifiDirectPreference).setEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDisplayPreference_shouldToggleEnabledState() {
|
||||||
|
when(mWifiManager.isWifiEnabled()).thenReturn(true);
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
verify(mWifiDirectPreference).setEnabled(true);
|
||||||
|
|
||||||
|
when(mWifiManager.isWifiEnabled()).thenReturn(false);
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
verify(mWifiDirectPreference).setEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user