Clean up AllInOneTetherSettings
This project is not on-going. Clean up to help improve latency. Bug: 311604902 Test: manual - on Network & internet page Test: robo test Change-Id: I6addb92e5587206661d1b64bdc56473a85ba9c9f
This commit is contained in:
@@ -2308,8 +2308,6 @@
|
|||||||
<string name="wifi_hotspot_name_title">Hotspot name</string>
|
<string name="wifi_hotspot_name_title">Hotspot name</string>
|
||||||
<!-- Label for Wifi hotspot password. -->
|
<!-- Label for Wifi hotspot password. -->
|
||||||
<string name="wifi_hotspot_password_title">Hotspot password</string>
|
<string name="wifi_hotspot_password_title">Hotspot password</string>
|
||||||
<!-- Label for Wifi hotspot AP Band. -->
|
|
||||||
<string name="wifi_hotspot_ap_band_title">AP Band</string>
|
|
||||||
|
|
||||||
<!-- Title for the toggle to turn off hotspot automatically [CHAR LIMIT=NONE]-->
|
<!-- Title for the toggle to turn off hotspot automatically [CHAR LIMIT=NONE]-->
|
||||||
<string name="wifi_hotspot_auto_off_title">Turn off hotspot automatically</string>
|
<string name="wifi_hotspot_auto_off_title">Turn off hotspot automatically</string>
|
||||||
@@ -3409,29 +3407,8 @@
|
|||||||
<!-- Tethering preference summary when hotspot and tethering are off [CHAR LIMIT=NONE]-->
|
<!-- Tethering preference summary when hotspot and tethering are off [CHAR LIMIT=NONE]-->
|
||||||
<string name="tether_preference_summary_off">Off</string>
|
<string name="tether_preference_summary_off">Off</string>
|
||||||
|
|
||||||
<!-- Tethering interface options [CHAR LIMIT=NONE]-->
|
|
||||||
<string name="tethering_interface_options">Tethering</string>
|
|
||||||
|
|
||||||
<!-- Disable Wifi Hotspot option-->
|
|
||||||
<!-- Don't use Wi-Fi hotspot title [CHAR LIMIT=NONE]-->
|
|
||||||
<string name="disable_wifi_hotspot_title">Don\u2019t use Wi\u2011Fi hotspot</string>
|
|
||||||
<!-- Don't use Wi-Fi hotspot summary when USB tethering is chosen [CHAR LIMIT=NONE]-->
|
|
||||||
<string name="disable_wifi_hotspot_when_usb_on">Only share internet via USB</string>
|
|
||||||
<!-- Don't use Wi-Fi hotspot summary when Bluetooth tethering is chosen [CHAR LIMIT=NONE]-->
|
|
||||||
<string name="disable_wifi_hotspot_when_bluetooth_on">Only share internet via Bluetooth</string>
|
|
||||||
<!-- Don't use Wi-Fi hotspot summary when Ethernet tethering is chosen [CHAR LIMIT=NONE]-->
|
|
||||||
<string name="disable_wifi_hotspot_when_ethernet_on">Only share internet via Ethernet</string>
|
|
||||||
<!-- Don't use Wi-Fi hotspot summary when USB tethering and Bluetooth tethering are chosen [CHAR LIMIT=NONE]-->
|
|
||||||
<string name="disable_wifi_hotspot_when_usb_and_bluetooth_on">Only share internet via USB and Bluetooth</string>
|
|
||||||
<!-- Don't use Wi-Fi hotspot summary when USB tethering and Ethernet tethering are chosen [CHAR LIMIT=NONE]-->
|
|
||||||
<string name="disable_wifi_hotspot_when_usb_and_ethernet_on">Only share internet via USB and Ethernet</string>
|
|
||||||
<!-- Don't use Wi-Fi hotspot summary when Bluetooth tethering and Ethernet tethering are chosen [CHAR LIMIT=NONE]-->
|
|
||||||
<string name="disable_wifi_hotspot_when_bluetooth_and_ethernet_on">Only share internet via Bluetooth and Ethernet</string>
|
|
||||||
<!-- Don't use Wi-Fi hotspot summary when USB, Bluetooth and Ethernet tethering are chosen [CHAR LIMIT=NONE]-->
|
|
||||||
<string name="disable_wifi_hotspot_when_usb_and_bluetooth_and_ethernet_on">Only share internet via USB, Bluetooth and Ethernet</string>
|
|
||||||
|
|
||||||
<!-- USB Tethering options -->
|
<!-- USB Tethering options -->
|
||||||
<string name="usb_title">USB</string>
|
<!-- Label for USB tethering switch [CHAR LIMIT=NONE]-->
|
||||||
<string name="usb_tethering_button_text">USB tethering</string>
|
<string name="usb_tethering_button_text">USB tethering</string>
|
||||||
|
|
||||||
<!-- Bluetooth Tethering settings-->
|
<!-- Bluetooth Tethering settings-->
|
||||||
|
|||||||
@@ -1,100 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!--
|
|
||||||
~ Copyright (C) 2020 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"
|
|
||||||
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
|
||||||
android:key="all_tether_prefs_screen"
|
|
||||||
android:title="@string/tether_settings_title_all"
|
|
||||||
settings:searchable="false">
|
|
||||||
|
|
||||||
<PreferenceCategory
|
|
||||||
android:key="wifi_tether_settings_group"
|
|
||||||
android:title="@string/wifi_hotspot_checkbox_text"
|
|
||||||
settings:searchable="false">
|
|
||||||
<com.android.settings.wifi.tether.WifiTetherSsidPreference
|
|
||||||
android:key="wifi_tether_network_name_2"
|
|
||||||
android:title="@string/wifi_hotspot_name_title"
|
|
||||||
android:summary="@string/summary_placeholder"/>
|
|
||||||
|
|
||||||
<com.android.settings.widget.ValidatedEditTextPreference
|
|
||||||
android:key="wifi_tether_network_password_2"
|
|
||||||
android:persistent="false"
|
|
||||||
android:title="@string/wifi_hotspot_password_title"/>
|
|
||||||
|
|
||||||
<SwitchPreferenceCompat
|
|
||||||
android:key="wifi_tether_auto_turn_off_2"
|
|
||||||
android:title="@string/wifi_hotspot_auto_off_title"
|
|
||||||
android:summary="@string/wifi_hotspot_auto_off_summary"/>
|
|
||||||
|
|
||||||
<ListPreference
|
|
||||||
android:key="wifi_tether_network_ap_band_2"
|
|
||||||
android:title="@string/wifi_hotspot_ap_band_title"/>
|
|
||||||
|
|
||||||
<ListPreference
|
|
||||||
android:key="wifi_tether_security_2"
|
|
||||||
android:title="@string/wifi_security"
|
|
||||||
android:summary="@string/summary_placeholder"
|
|
||||||
android:entries="@array/wifi_tether_security"
|
|
||||||
android:entryValues="@array/wifi_tether_security_values"/>
|
|
||||||
</PreferenceCategory>
|
|
||||||
|
|
||||||
<PreferenceCategory
|
|
||||||
android:key="tethering_options_group"
|
|
||||||
android:title="@string/tethering_interface_options"
|
|
||||||
settings:searchable="false">
|
|
||||||
<SwitchPreferenceCompat
|
|
||||||
android:key="enable_usb_tethering"
|
|
||||||
android:title="@string/usb_tethering_button_text"
|
|
||||||
android:summary="@string/usb_tethering_subtext"
|
|
||||||
settings:controller="com.android.settings.network.UsbTetherPreferenceController"
|
|
||||||
settings:keywords="@string/keywords_hotspot_tethering" />
|
|
||||||
|
|
||||||
<SwitchPreferenceCompat
|
|
||||||
android:key="enable_bluetooth_tethering_2"
|
|
||||||
android:title="@string/bluetooth_tether_checkbox_text"
|
|
||||||
android:summary="@string/bluetooth_tethering_subtext"
|
|
||||||
settings:controller="com.android.settings.network.BluetoothTetherPreferenceController"
|
|
||||||
settings:keywords="@string/keywords_hotspot_tethering" />
|
|
||||||
|
|
||||||
<SwitchPreferenceCompat
|
|
||||||
android:key="enable_ethernet_tethering_2"
|
|
||||||
android:title="@string/ethernet_tether_checkbox_text"
|
|
||||||
android:summary="@string/ethernet_tethering_subtext"
|
|
||||||
settings:controller="com.android.settings.network.EthernetTetherPreferenceController"
|
|
||||||
settings:keywords="@string/keywords_hotspot_tethering"/>
|
|
||||||
|
|
||||||
<SwitchPreferenceCompat
|
|
||||||
android:key="disable_wifi_tethering"
|
|
||||||
android:title="@string/disable_wifi_hotspot_title"
|
|
||||||
android:summary="@string/summary_placeholder"
|
|
||||||
settings:controller="com.android.settings.network.WifiTetherDisablePreferenceController"
|
|
||||||
settings:keywords="@string/keywords_hotspot_tethering" />
|
|
||||||
</PreferenceCategory>
|
|
||||||
|
|
||||||
<Preference
|
|
||||||
android:key="disabled_on_data_saver_2"
|
|
||||||
android:summary="@string/tether_settings_disabled_on_data_saver"
|
|
||||||
android:selectable="false"
|
|
||||||
settings:searchable="false"
|
|
||||||
settings:allowDividerAbove="true" />
|
|
||||||
|
|
||||||
<com.android.settingslib.widget.FooterPreference
|
|
||||||
android:key="tether_prefs_footer_2"
|
|
||||||
android:selectable="false"
|
|
||||||
settings:searchable="false"/>
|
|
||||||
</PreferenceScreen>
|
|
||||||
@@ -70,18 +70,6 @@
|
|||||||
settings:userRestriction="no_config_tethering"
|
settings:userRestriction="no_config_tethering"
|
||||||
settings:useAdminDisabledSummary="true" />
|
settings:useAdminDisabledSummary="true" />
|
||||||
|
|
||||||
<com.android.settingslib.PrimarySwitchPreference
|
|
||||||
android:fragment="com.android.settings.AllInOneTetherSettings"
|
|
||||||
android:key="all_tether_settings"
|
|
||||||
android:title="@string/tether_settings_title_all"
|
|
||||||
android:icon="@drawable/ic_wifi_tethering"
|
|
||||||
android:order="6"
|
|
||||||
android:summary="@string/summary_placeholder"
|
|
||||||
settings:controller="com.android.settings.network.AllInOneTetherPreferenceController"
|
|
||||||
settings:keywords="@string/keywords_hotspot_tethering"
|
|
||||||
settings:userRestriction="no_config_tethering"
|
|
||||||
settings:useAdminDisabledSummary="true" />
|
|
||||||
|
|
||||||
<com.android.settings.datausage.DataSaverPreference
|
<com.android.settings.datausage.DataSaverPreference
|
||||||
android:key="restrict_background_parent_entry"
|
android:key="restrict_background_parent_entry"
|
||||||
android:title="@string/data_saver_title"
|
android:title="@string/data_saver_title"
|
||||||
|
|||||||
@@ -1,444 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2020 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;
|
|
||||||
|
|
||||||
import static android.net.ConnectivityManager.TETHERING_WIFI;
|
|
||||||
import static android.net.TetheringManager.ACTION_TETHER_STATE_CHANGED;
|
|
||||||
import static android.net.wifi.WifiManager.WIFI_AP_STATE_CHANGED_ACTION;
|
|
||||||
|
|
||||||
import android.app.settings.SettingsEnums;
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
|
||||||
import android.bluetooth.BluetoothPan;
|
|
||||||
import android.bluetooth.BluetoothProfile;
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.IntentFilter;
|
|
||||||
import android.net.wifi.SoftApConfiguration;
|
|
||||||
import android.net.wifi.WifiManager;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.UserManager;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.FeatureFlagUtils;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
|
||||||
import androidx.preference.Preference;
|
|
||||||
import androidx.preference.PreferenceGroup;
|
|
||||||
|
|
||||||
import com.android.settings.core.FeatureFlags;
|
|
||||||
import com.android.settings.dashboard.RestrictedDashboardFragment;
|
|
||||||
import com.android.settings.datausage.DataSaverBackend;
|
|
||||||
import com.android.settings.network.BluetoothTetherPreferenceController;
|
|
||||||
import com.android.settings.network.EthernetTetherPreferenceController;
|
|
||||||
import com.android.settings.network.TetherEnabler;
|
|
||||||
import com.android.settings.network.UsbTetherPreferenceController;
|
|
||||||
import com.android.settings.network.WifiTetherDisablePreferenceController;
|
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
|
||||||
import com.android.settings.widget.MainSwitchBarController;
|
|
||||||
import com.android.settings.widget.SettingsMainSwitchBar;
|
|
||||||
import com.android.settings.wifi.tether.WifiTetherApBandPreferenceController;
|
|
||||||
import com.android.settings.wifi.tether.WifiTetherAutoOffPreferenceController;
|
|
||||||
import com.android.settings.wifi.tether.WifiTetherBasePreferenceController;
|
|
||||||
import com.android.settings.wifi.tether.WifiTetherFooterPreferenceController;
|
|
||||||
import com.android.settings.wifi.tether.WifiTetherPasswordPreferenceController;
|
|
||||||
import com.android.settings.wifi.tether.WifiTetherSSIDPreferenceController;
|
|
||||||
import com.android.settings.wifi.tether.WifiTetherSecurityPreferenceController;
|
|
||||||
import com.android.settingslib.TetherUtil;
|
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
|
||||||
import com.android.settingslib.search.SearchIndexable;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Displays preferences for all Tethering options.
|
|
||||||
*/
|
|
||||||
@SearchIndexable
|
|
||||||
public class AllInOneTetherSettings extends RestrictedDashboardFragment
|
|
||||||
implements DataSaverBackend.Listener,
|
|
||||||
WifiTetherBasePreferenceController.OnTetherConfigUpdateListener {
|
|
||||||
|
|
||||||
// TODO(b/148622133): Should clean up the postfix once this fragment replaced TetherSettings.
|
|
||||||
public static final String DEDUP_POSTFIX = "_2";
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
static final String KEY_WIFI_TETHER_NETWORK_NAME = "wifi_tether_network_name" + DEDUP_POSTFIX;
|
|
||||||
@VisibleForTesting
|
|
||||||
static final String KEY_WIFI_TETHER_NETWORK_PASSWORD =
|
|
||||||
"wifi_tether_network_password" + DEDUP_POSTFIX;
|
|
||||||
@VisibleForTesting
|
|
||||||
static final String KEY_WIFI_TETHER_AUTO_OFF = "wifi_tether_auto_turn_off" + DEDUP_POSTFIX;
|
|
||||||
@VisibleForTesting
|
|
||||||
static final String KEY_WIFI_TETHER_NETWORK_AP_BAND =
|
|
||||||
"wifi_tether_network_ap_band" + DEDUP_POSTFIX;
|
|
||||||
@VisibleForTesting
|
|
||||||
static final String KEY_WIFI_TETHER_SECURITY = "wifi_tether_security" + DEDUP_POSTFIX;
|
|
||||||
|
|
||||||
private static final String KEY_DATA_SAVER_FOOTER = "disabled_on_data_saver" + DEDUP_POSTFIX;
|
|
||||||
private static final String KEY_WIFI_TETHER_GROUP = "wifi_tether_settings_group";
|
|
||||||
public static final String WIFI_TETHER_DISABLE_KEY = "disable_wifi_tethering";
|
|
||||||
public static final String USB_TETHER_KEY = "enable_usb_tethering";
|
|
||||||
public static final String BLUETOOTH_TETHER_KEY = "enable_bluetooth_tethering" + DEDUP_POSTFIX;
|
|
||||||
public static final String ETHERNET_TETHER_KEY = "enable_ethernet_tethering" + DEDUP_POSTFIX;
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
static final int EXPANDED_CHILD_COUNT_DEFAULT = 4;
|
|
||||||
@VisibleForTesting
|
|
||||||
static final int EXPANDED_CHILD_COUNT_WITH_SECURITY_NON = 3;
|
|
||||||
@VisibleForTesting
|
|
||||||
static final int EXPANDED_CHILD_COUNT_MAX = Integer.MAX_VALUE;
|
|
||||||
private static final String TAG = "AllInOneTetherSettings";
|
|
||||||
|
|
||||||
private boolean mUnavailable;
|
|
||||||
|
|
||||||
private DataSaverBackend mDataSaverBackend;
|
|
||||||
private boolean mDataSaverEnabled;
|
|
||||||
private Preference mDataSaverFooter;
|
|
||||||
|
|
||||||
private WifiManager mWifiManager;
|
|
||||||
private boolean mRestartWifiApAfterConfigChange;
|
|
||||||
private final AtomicReference<BluetoothPan> mBluetoothPan = new AtomicReference<>();
|
|
||||||
|
|
||||||
private WifiTetherSSIDPreferenceController mSSIDPreferenceController;
|
|
||||||
private WifiTetherPasswordPreferenceController mPasswordPreferenceController;
|
|
||||||
private WifiTetherApBandPreferenceController mApBandPreferenceController;
|
|
||||||
private WifiTetherSecurityPreferenceController mSecurityPreferenceController;
|
|
||||||
private PreferenceGroup mWifiTetherGroup;
|
|
||||||
private boolean mShouldShowWifiConfig = true;
|
|
||||||
private boolean mHasShownAdvance;
|
|
||||||
private TetherEnabler mTetherEnabler;
|
|
||||||
@VisibleForTesting
|
|
||||||
final TetherEnabler.OnTetherStateUpdateListener mStateUpdateListener =
|
|
||||||
state -> {
|
|
||||||
mShouldShowWifiConfig = TetherEnabler.isTethering(state, TETHERING_WIFI)
|
|
||||||
|| state == TetherEnabler.TETHERING_OFF;
|
|
||||||
getPreferenceScreen().setInitialExpandedChildrenCount(
|
|
||||||
getInitialExpandedChildCount());
|
|
||||||
mWifiTetherGroup.setVisible(mShouldShowWifiConfig);
|
|
||||||
};
|
|
||||||
|
|
||||||
private final BroadcastReceiver mTetherChangeReceiver = new BroadcastReceiver() {
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context content, Intent intent) {
|
|
||||||
String action = intent.getAction();
|
|
||||||
if (Log.isLoggable(TAG, Log.DEBUG)) {
|
|
||||||
Log.d(TAG,
|
|
||||||
"updating display config due to receiving broadcast action " + action);
|
|
||||||
}
|
|
||||||
updateDisplayWithNewConfig();
|
|
||||||
if (TextUtils.equals(action, ACTION_TETHER_STATE_CHANGED)) {
|
|
||||||
restartWifiTetherIfNeed(mWifiManager.getWifiApState());
|
|
||||||
} else if (TextUtils.equals(action, WIFI_AP_STATE_CHANGED_ACTION)) {
|
|
||||||
restartWifiTetherIfNeed(intent.getIntExtra(WifiManager.EXTRA_WIFI_AP_STATE, 0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void restartWifiTetherIfNeed(int state) {
|
|
||||||
if (state == WifiManager.WIFI_AP_STATE_DISABLED
|
|
||||||
&& mRestartWifiApAfterConfigChange) {
|
|
||||||
mRestartWifiApAfterConfigChange = false;
|
|
||||||
mTetherEnabler.startTethering(TETHERING_WIFI);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private final BluetoothProfile.ServiceListener mProfileServiceListener =
|
|
||||||
new BluetoothProfile.ServiceListener() {
|
|
||||||
public void onServiceConnected(int profile, BluetoothProfile proxy) {
|
|
||||||
mBluetoothPan.set((BluetoothPan) proxy);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onServiceDisconnected(int profile) {
|
|
||||||
mBluetoothPan.set(null);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMetricsCategory() {
|
|
||||||
return SettingsEnums.TETHER;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AllInOneTetherSettings() {
|
|
||||||
super(UserManager.DISALLOW_CONFIG_TETHERING);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAttach(Context context) {
|
|
||||||
super.onAttach(context);
|
|
||||||
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
|
||||||
|
|
||||||
mSSIDPreferenceController = use(WifiTetherSSIDPreferenceController.class);
|
|
||||||
mSecurityPreferenceController = use(WifiTetherSecurityPreferenceController.class);
|
|
||||||
mPasswordPreferenceController = use(WifiTetherPasswordPreferenceController.class);
|
|
||||||
mApBandPreferenceController = use(WifiTetherApBandPreferenceController.class);
|
|
||||||
getSettingsLifecycle().addObserver(use(UsbTetherPreferenceController.class));
|
|
||||||
getSettingsLifecycle().addObserver(use(BluetoothTetherPreferenceController.class));
|
|
||||||
getSettingsLifecycle().addObserver(use(EthernetTetherPreferenceController.class));
|
|
||||||
getSettingsLifecycle().addObserver(use(WifiTetherDisablePreferenceController.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle icicle) {
|
|
||||||
super.onCreate(icicle);
|
|
||||||
mDataSaverBackend = new DataSaverBackend(getContext());
|
|
||||||
mDataSaverEnabled = mDataSaverBackend.isDataSaverEnabled();
|
|
||||||
mDataSaverFooter = findPreference(KEY_DATA_SAVER_FOOTER);
|
|
||||||
mWifiTetherGroup = findPreference(KEY_WIFI_TETHER_GROUP);
|
|
||||||
|
|
||||||
setIfOnlyAvailableForAdmins(true);
|
|
||||||
if (isUiRestricted()) {
|
|
||||||
mUnavailable = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
mDataSaverBackend.addListener(this);
|
|
||||||
|
|
||||||
// Set initial state based on Data Saver mode.
|
|
||||||
onDataSaverChanged(mDataSaverBackend.isDataSaverEnabled());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
|
||||||
super.onActivityCreated(savedInstanceState);
|
|
||||||
if (mUnavailable) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Assume we are in a SettingsActivity. This is only safe because we currently use
|
|
||||||
// SettingsActivity as base for all preference fragments.
|
|
||||||
final SettingsActivity activity = (SettingsActivity) getActivity();
|
|
||||||
final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
|
||||||
if (adapter != null) {
|
|
||||||
adapter.getProfileProxy(activity.getApplicationContext(), mProfileServiceListener,
|
|
||||||
BluetoothProfile.PAN);
|
|
||||||
}
|
|
||||||
final SettingsMainSwitchBar mainSwitch = activity.getSwitchBar();
|
|
||||||
mTetherEnabler = new TetherEnabler(activity,
|
|
||||||
new MainSwitchBarController(mainSwitch), mBluetoothPan);
|
|
||||||
getSettingsLifecycle().addObserver(mTetherEnabler);
|
|
||||||
use(UsbTetherPreferenceController.class).setTetherEnabler(mTetherEnabler);
|
|
||||||
use(BluetoothTetherPreferenceController.class).setTetherEnabler(mTetherEnabler);
|
|
||||||
use(EthernetTetherPreferenceController.class).setTetherEnabler(mTetherEnabler);
|
|
||||||
use(WifiTetherDisablePreferenceController.class).setTetherEnabler(mTetherEnabler);
|
|
||||||
mainSwitch.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStart() {
|
|
||||||
super.onStart();
|
|
||||||
|
|
||||||
if (mUnavailable) {
|
|
||||||
if (!isUiRestrictedByOnlyAdmin()) {
|
|
||||||
getEmptyTextView().setText(
|
|
||||||
com.android.settingslib.R.string.tethering_settings_not_available);
|
|
||||||
}
|
|
||||||
getPreferenceScreen().removeAll();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final Context context = getContext();
|
|
||||||
if (context != null) {
|
|
||||||
// The intent WIFI_AP_STATE_CHANGED_ACTION is not sticky intent after SC-V2
|
|
||||||
// But ACTION_TETHER_STATE_CHANGED is still sticky intent. So no need to handle
|
|
||||||
// initial state for WIFI_AP_STATE_CHANGED_ACTION
|
|
||||||
IntentFilter filter = new IntentFilter(ACTION_TETHER_STATE_CHANGED);
|
|
||||||
filter.addAction(WIFI_AP_STATE_CHANGED_ACTION);
|
|
||||||
context.registerReceiver(mTetherChangeReceiver, filter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
if (mUnavailable) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (mTetherEnabler != null) {
|
|
||||||
mTetherEnabler.addListener(mStateUpdateListener);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPause() {
|
|
||||||
super.onPause();
|
|
||||||
if (mUnavailable) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (mTetherEnabler != null) {
|
|
||||||
mTetherEnabler.removeListener(mStateUpdateListener);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStop() {
|
|
||||||
super.onStop();
|
|
||||||
if (mUnavailable) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final Context context = getContext();
|
|
||||||
if (context != null) {
|
|
||||||
context.unregisterReceiver(mTetherChangeReceiver);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroy() {
|
|
||||||
mDataSaverBackend.remListener(this);
|
|
||||||
super.onDestroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDataSaverChanged(boolean isDataSaving) {
|
|
||||||
mDataSaverEnabled = isDataSaving;
|
|
||||||
mDataSaverFooter.setVisible(mDataSaverEnabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAllowlistStatusChanged(int uid, boolean isAllowlisted) {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDenylistStatusChanged(int uid, boolean isDenylisted) {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
|
||||||
return buildPreferenceControllers(context, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
|
|
||||||
WifiTetherBasePreferenceController.OnTetherConfigUpdateListener listener) {
|
|
||||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
|
||||||
controllers.add(
|
|
||||||
new WifiTetherSSIDPreferenceController(context, listener));
|
|
||||||
controllers.add(
|
|
||||||
new WifiTetherPasswordPreferenceController(context, listener));
|
|
||||||
controllers.add(
|
|
||||||
new WifiTetherApBandPreferenceController(context, listener));
|
|
||||||
controllers.add(
|
|
||||||
new WifiTetherSecurityPreferenceController(context, listener));
|
|
||||||
controllers.add(
|
|
||||||
new WifiTetherAutoOffPreferenceController(context, KEY_WIFI_TETHER_AUTO_OFF));
|
|
||||||
controllers.add(
|
|
||||||
new WifiTetherFooterPreferenceController(context));
|
|
||||||
|
|
||||||
return controllers;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getPreferenceScreenResId() {
|
|
||||||
return R.xml.all_tether_prefs;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String getLogTag() {
|
|
||||||
return TAG;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getHelpResource() {
|
|
||||||
return R.string.help_url_tether;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTetherConfigUpdated(AbstractPreferenceController controller) {
|
|
||||||
final SoftApConfiguration config = buildNewConfig();
|
|
||||||
mPasswordPreferenceController.setSecurityType(config.getSecurityType());
|
|
||||||
mWifiManager.setSoftApConfiguration(config);
|
|
||||||
|
|
||||||
if (mWifiManager.getWifiApState() == WifiManager.WIFI_AP_STATE_ENABLED) {
|
|
||||||
if (Log.isLoggable(TAG, Log.DEBUG)) {
|
|
||||||
Log.d(TAG, "Wifi AP config changed while enabled, stop and restart");
|
|
||||||
}
|
|
||||||
mRestartWifiApAfterConfigChange = true;
|
|
||||||
mTetherEnabler.stopTethering(TETHERING_WIFI);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private SoftApConfiguration buildNewConfig() {
|
|
||||||
final SoftApConfiguration.Builder configBuilder = new SoftApConfiguration.Builder();
|
|
||||||
final int securityType = mSecurityPreferenceController.getSecurityType();
|
|
||||||
configBuilder.setSsid(mSSIDPreferenceController.getSSID());
|
|
||||||
if (securityType == SoftApConfiguration.SECURITY_TYPE_WPA2_PSK) {
|
|
||||||
configBuilder.setPassphrase(
|
|
||||||
mPasswordPreferenceController.getPasswordValidated(securityType),
|
|
||||||
SoftApConfiguration.SECURITY_TYPE_WPA2_PSK);
|
|
||||||
}
|
|
||||||
configBuilder.setBand(mApBandPreferenceController.getBandIndex());
|
|
||||||
return configBuilder.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateDisplayWithNewConfig() {
|
|
||||||
mSSIDPreferenceController.updateDisplay();
|
|
||||||
mSecurityPreferenceController.updateDisplay();
|
|
||||||
mPasswordPreferenceController.updateDisplay();
|
|
||||||
mApBandPreferenceController.updateDisplay();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getInitialExpandedChildCount() {
|
|
||||||
if (mHasShownAdvance || !mShouldShowWifiConfig) {
|
|
||||||
mHasShownAdvance = true;
|
|
||||||
return EXPANDED_CHILD_COUNT_MAX;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mSecurityPreferenceController == null) {
|
|
||||||
return EXPANDED_CHILD_COUNT_DEFAULT;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (mSecurityPreferenceController.getSecurityType()
|
|
||||||
== SoftApConfiguration.SECURITY_TYPE_OPEN)
|
|
||||||
? EXPANDED_CHILD_COUNT_WITH_SECURITY_NON : EXPANDED_CHILD_COUNT_DEFAULT;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onExpandButtonClick() {
|
|
||||||
super.onExpandButtonClick();
|
|
||||||
mHasShownAdvance = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
|
||||||
new BaseSearchIndexProvider(R.xml.all_tether_prefs) {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getNonIndexableKeys(Context context) {
|
|
||||||
final List<String> keys = super.getNonIndexableKeys(context);
|
|
||||||
|
|
||||||
if (!TetherUtil.isTetherAvailable(context)) {
|
|
||||||
keys.add(KEY_WIFI_TETHER_NETWORK_NAME);
|
|
||||||
keys.add(KEY_WIFI_TETHER_NETWORK_PASSWORD);
|
|
||||||
keys.add(KEY_WIFI_TETHER_AUTO_OFF);
|
|
||||||
keys.add(KEY_WIFI_TETHER_NETWORK_AP_BAND);
|
|
||||||
keys.add(KEY_WIFI_TETHER_SECURITY);
|
|
||||||
}
|
|
||||||
return keys;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean isPageSearchEnabled(Context context) {
|
|
||||||
return FeatureFlagUtils.isEnabled(context, FeatureFlags.TETHER_ALL_IN_ONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<AbstractPreferenceController> createPreferenceControllers(
|
|
||||||
Context context) {
|
|
||||||
return buildPreferenceControllers(context, null /*listener*/);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -19,18 +19,15 @@ package com.android.settings;
|
|||||||
import static android.provider.Settings.ACTION_PRIVACY_SETTINGS;
|
import static android.provider.Settings.ACTION_PRIVACY_SETTINGS;
|
||||||
|
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.telephony.ims.ImsRcsManager;
|
import android.telephony.ims.ImsRcsManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.FeatureFlagUtils;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.settings.biometrics.face.FaceSettings;
|
import com.android.settings.biometrics.face.FaceSettings;
|
||||||
import com.android.settings.communal.CommunalPreferenceController;
|
import com.android.settings.communal.CommunalPreferenceController;
|
||||||
import com.android.settings.core.FeatureFlags;
|
|
||||||
import com.android.settings.enterprise.EnterprisePrivacySettings;
|
import com.android.settings.enterprise.EnterprisePrivacySettings;
|
||||||
import com.android.settings.network.MobileNetworkIntentConverter;
|
import com.android.settings.network.MobileNetworkIntentConverter;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
@@ -58,42 +55,8 @@ public class Settings extends SettingsActivity {
|
|||||||
public static class FingerprintSettingsActivityV2 extends SettingsActivity { /* empty */ }
|
public static class FingerprintSettingsActivityV2 extends SettingsActivity { /* empty */ }
|
||||||
public static class CombinedBiometricSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class CombinedBiometricSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class CombinedBiometricProfileSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class CombinedBiometricProfileSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class TetherSettingsActivity extends SettingsActivity {
|
public static class TetherSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
// TODO(b/147675042): Clean the override up when we enable the new Fragment persistently.
|
public static class WifiTetherSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
@Override
|
|
||||||
public Intent getIntent() {
|
|
||||||
return wrapIntentWithAllInOneTetherSettingsIfNeeded(
|
|
||||||
getApplicationContext(), super.getIntent());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static class WifiTetherSettingsActivity extends SettingsActivity {
|
|
||||||
// TODO(b/147675042): Clean the override up when we enable the new Fragment persistently.
|
|
||||||
@Override
|
|
||||||
public Intent getIntent() {
|
|
||||||
return wrapIntentWithAllInOneTetherSettingsIfNeeded(
|
|
||||||
getApplicationContext(), super.getIntent());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Intent wrapIntentWithAllInOneTetherSettingsIfNeeded(
|
|
||||||
Context context, Intent superIntent) {
|
|
||||||
if (!FeatureFlagUtils.isEnabled(context, FeatureFlags.TETHER_ALL_IN_ONE)) {
|
|
||||||
return superIntent;
|
|
||||||
}
|
|
||||||
|
|
||||||
final Intent modIntent = new Intent(superIntent);
|
|
||||||
modIntent.putExtra(EXTRA_SHOW_FRAGMENT,
|
|
||||||
AllInOneTetherSettings.class.getCanonicalName());
|
|
||||||
Bundle args = superIntent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
|
|
||||||
if (args != null) {
|
|
||||||
args = new Bundle(args);
|
|
||||||
} else {
|
|
||||||
args = new Bundle();
|
|
||||||
}
|
|
||||||
args.putParcelable("intent", superIntent);
|
|
||||||
modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
|
|
||||||
return modIntent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class VpnSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class VpnSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
/** Activity for Data saver settings. */
|
/** Activity for Data saver settings. */
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.android.settings.core.gateway;
|
package com.android.settings.core.gateway;
|
||||||
|
|
||||||
import com.android.settings.AllInOneTetherSettings;
|
|
||||||
import com.android.settings.DisplaySettings;
|
import com.android.settings.DisplaySettings;
|
||||||
import com.android.settings.IccLockSettings;
|
import com.android.settings.IccLockSettings;
|
||||||
import com.android.settings.MainClear;
|
import com.android.settings.MainClear;
|
||||||
@@ -205,7 +204,6 @@ public class SettingsGateway {
|
|||||||
WifiNetworkDetailsFragment.class.getName(),
|
WifiNetworkDetailsFragment.class.getName(),
|
||||||
ConfigureWifiSettings.class.getName(),
|
ConfigureWifiSettings.class.getName(),
|
||||||
SavedAccessPointsWifiSettings2.class.getName(),
|
SavedAccessPointsWifiSettings2.class.getName(),
|
||||||
AllInOneTetherSettings.class.getName(),
|
|
||||||
TetherSettings.class.getName(),
|
TetherSettings.class.getName(),
|
||||||
SmartAutoRotatePreferenceFragment.class.getName(),
|
SmartAutoRotatePreferenceFragment.class.getName(),
|
||||||
WifiP2pSettings.class.getName(),
|
WifiP2pSettings.class.getName(),
|
||||||
|
|||||||
@@ -1,246 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2020 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.network;
|
|
||||||
|
|
||||||
import static android.os.UserManager.DISALLOW_CONFIG_TETHERING;
|
|
||||||
|
|
||||||
import static com.android.settings.network.TetherEnabler.TETHERING_BLUETOOTH_ON;
|
|
||||||
import static com.android.settings.network.TetherEnabler.TETHERING_ETHERNET_ON;
|
|
||||||
import static com.android.settings.network.TetherEnabler.TETHERING_OFF;
|
|
||||||
import static com.android.settings.network.TetherEnabler.TETHERING_USB_ON;
|
|
||||||
import static com.android.settings.network.TetherEnabler.TETHERING_WIFI_ON;
|
|
||||||
import static com.android.settingslib.RestrictedLockUtilsInternal.checkIfRestrictionEnforced;
|
|
||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
|
||||||
import android.bluetooth.BluetoothPan;
|
|
||||||
import android.bluetooth.BluetoothProfile;
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.IntentFilter;
|
|
||||||
import android.os.UserHandle;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.FeatureFlagUtils;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
|
||||||
import androidx.lifecycle.Lifecycle;
|
|
||||||
import androidx.lifecycle.Lifecycle.Event;
|
|
||||||
import androidx.lifecycle.LifecycleObserver;
|
|
||||||
import androidx.lifecycle.OnLifecycleEvent;
|
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.core.BasePreferenceController;
|
|
||||||
import com.android.settings.core.FeatureFlags;
|
|
||||||
import com.android.settings.widget.GenericSwitchController;
|
|
||||||
import com.android.settingslib.PrimarySwitchPreference;
|
|
||||||
import com.android.settingslib.TetherUtil;
|
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This controller helps to manage the switch state and visibility of "Hotspot & tethering" switch
|
|
||||||
* preference. It updates the preference summary text based on tethering state.
|
|
||||||
*/
|
|
||||||
public class AllInOneTetherPreferenceController extends BasePreferenceController implements
|
|
||||||
LifecycleObserver, TetherEnabler.OnTetherStateUpdateListener {
|
|
||||||
private static final String TAG = "AllInOneTetherPreferenceController";
|
|
||||||
|
|
||||||
private int mTetheringState;
|
|
||||||
|
|
||||||
private final boolean mAdminDisallowedTetherConfig;
|
|
||||||
private final AtomicReference<BluetoothPan> mBluetoothPan;
|
|
||||||
private final BluetoothAdapter mBluetoothAdapter;
|
|
||||||
@VisibleForTesting
|
|
||||||
final BluetoothProfile.ServiceListener mBtProfileServiceListener =
|
|
||||||
new BluetoothProfile.ServiceListener() {
|
|
||||||
@Override
|
|
||||||
public void onServiceConnected(int profile, BluetoothProfile proxy) {
|
|
||||||
if (mBluetoothPan.get() == null) {
|
|
||||||
mBluetoothPan.set((BluetoothPan) proxy);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onServiceDisconnected(int profile) { /* Do nothing */ }
|
|
||||||
};
|
|
||||||
|
|
||||||
private PrimarySwitchPreference mPreference;
|
|
||||||
private TetherEnabler mTetherEnabler;
|
|
||||||
private BroadcastReceiver mBluetoothStateReceiver;
|
|
||||||
|
|
||||||
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
|
|
||||||
AllInOneTetherPreferenceController() {
|
|
||||||
super(null /*context*/, "test");
|
|
||||||
mAdminDisallowedTetherConfig = false;
|
|
||||||
mBluetoothPan = new AtomicReference<>();
|
|
||||||
mBluetoothAdapter = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AllInOneTetherPreferenceController(Context context, String key) {
|
|
||||||
super(context, key);
|
|
||||||
mBluetoothPan = new AtomicReference<>();
|
|
||||||
mAdminDisallowedTetherConfig = checkIfRestrictionEnforced(
|
|
||||||
context, DISALLOW_CONFIG_TETHERING, UserHandle.myUserId()) != null;
|
|
||||||
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void displayPreference(PreferenceScreen screen) {
|
|
||||||
super.displayPreference(screen);
|
|
||||||
mPreference = screen.findPreference(mPreferenceKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getAvailabilityStatus() {
|
|
||||||
if (!TetherUtil.isTetherAvailable(mContext)
|
|
||||||
|| !FeatureFlagUtils.isEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE)) {
|
|
||||||
return CONDITIONALLY_UNAVAILABLE;
|
|
||||||
} else {
|
|
||||||
return AVAILABLE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CharSequence getSummary() {
|
|
||||||
switch (mTetheringState) {
|
|
||||||
case TETHERING_OFF:
|
|
||||||
return mContext.getString(R.string.tether_settings_summary_off);
|
|
||||||
case TETHERING_WIFI_ON:
|
|
||||||
return mContext.getString(R.string.tether_settings_summary_hotspot_only);
|
|
||||||
case TETHERING_USB_ON:
|
|
||||||
return mContext.getString(R.string.tether_settings_summary_usb_tethering_only);
|
|
||||||
case TETHERING_BLUETOOTH_ON:
|
|
||||||
return mContext.getString(
|
|
||||||
R.string.tether_settings_summary_bluetooth_tethering_only);
|
|
||||||
case TETHERING_ETHERNET_ON:
|
|
||||||
return mContext.getString(R.string.tether_settings_summary_ethernet_tethering_only);
|
|
||||||
case TETHERING_WIFI_ON | TETHERING_USB_ON:
|
|
||||||
return mContext.getString(R.string.tether_settings_summary_hotspot_and_usb);
|
|
||||||
case TETHERING_WIFI_ON | TETHERING_BLUETOOTH_ON:
|
|
||||||
return mContext.getString(R.string.tether_settings_summary_hotspot_and_bluetooth);
|
|
||||||
case TETHERING_WIFI_ON | TETHERING_ETHERNET_ON:
|
|
||||||
return mContext.getString(R.string.tether_settings_summary_hotspot_and_ethernet);
|
|
||||||
case TETHERING_USB_ON | TETHERING_BLUETOOTH_ON:
|
|
||||||
return mContext.getString(R.string.tether_settings_summary_usb_and_bluetooth);
|
|
||||||
case TETHERING_USB_ON | TETHERING_ETHERNET_ON:
|
|
||||||
return mContext.getString(R.string.tether_settings_summary_usb_and_ethernet);
|
|
||||||
case TETHERING_BLUETOOTH_ON | TETHERING_ETHERNET_ON:
|
|
||||||
return mContext.getString(R.string.tether_settings_summary_bluetooth_and_ethernet);
|
|
||||||
case TETHERING_WIFI_ON | TETHERING_USB_ON | TETHERING_BLUETOOTH_ON:
|
|
||||||
return mContext.getString(
|
|
||||||
R.string.tether_settings_summary_hotspot_and_usb_and_bluetooth);
|
|
||||||
case TETHERING_WIFI_ON | TETHERING_USB_ON | TETHERING_ETHERNET_ON:
|
|
||||||
return mContext.getString(
|
|
||||||
R.string.tether_settings_summary_hotspot_and_usb_and_ethernet);
|
|
||||||
case TETHERING_WIFI_ON | TETHERING_BLUETOOTH_ON | TETHERING_ETHERNET_ON:
|
|
||||||
return mContext.getString(
|
|
||||||
R.string.tether_settings_summary_hotspot_and_bluetooth_and_ethernet);
|
|
||||||
case TETHERING_USB_ON | TETHERING_BLUETOOTH_ON | TETHERING_ETHERNET_ON:
|
|
||||||
return mContext.getString(
|
|
||||||
R.string.tether_settings_summary_usb_and_bluetooth_and_ethernet);
|
|
||||||
case TETHERING_WIFI_ON | TETHERING_USB_ON | TETHERING_BLUETOOTH_ON
|
|
||||||
| TETHERING_ETHERNET_ON:
|
|
||||||
return mContext.getString(R.string.tether_settings_summary_all);
|
|
||||||
default:
|
|
||||||
Log.e(TAG, "Unknown tethering state");
|
|
||||||
return mContext.getString(R.string.summary_placeholder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnLifecycleEvent(Event.ON_CREATE)
|
|
||||||
public void onCreate() {
|
|
||||||
if (mBluetoothAdapter != null
|
|
||||||
&& mBluetoothAdapter.getState() == BluetoothAdapter.STATE_ON) {
|
|
||||||
mBluetoothAdapter.getProfileProxy(mContext, mBtProfileServiceListener,
|
|
||||||
BluetoothProfile.PAN);
|
|
||||||
}
|
|
||||||
if (mBluetoothStateReceiver == null) {
|
|
||||||
mBluetoothStateReceiver = new BluetoothStateReceiver();
|
|
||||||
mContext.registerReceiver(
|
|
||||||
mBluetoothStateReceiver,
|
|
||||||
new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnLifecycleEvent(Event.ON_RESUME)
|
|
||||||
public void onResume() {
|
|
||||||
if (mTetherEnabler != null) {
|
|
||||||
mTetherEnabler.addListener(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnLifecycleEvent(Event.ON_PAUSE)
|
|
||||||
public void onPause() {
|
|
||||||
if (mTetherEnabler != null) {
|
|
||||||
mTetherEnabler.removeListener(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnLifecycleEvent(Event.ON_DESTROY)
|
|
||||||
public void onDestroy() {
|
|
||||||
final BluetoothProfile profile = mBluetoothPan.getAndSet(null);
|
|
||||||
if (profile != null && mBluetoothAdapter != null) {
|
|
||||||
mBluetoothAdapter.closeProfileProxy(BluetoothProfile.PAN, profile);
|
|
||||||
}
|
|
||||||
if (mBluetoothStateReceiver != null) {
|
|
||||||
mContext.unregisterReceiver(mBluetoothStateReceiver);
|
|
||||||
mBluetoothStateReceiver = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void initEnabler(Lifecycle lifecycle) {
|
|
||||||
if (mPreference != null) {
|
|
||||||
mTetherEnabler = new TetherEnabler(
|
|
||||||
mContext, new GenericSwitchController(mPreference), mBluetoothPan);
|
|
||||||
if (lifecycle != null) {
|
|
||||||
lifecycle.addObserver(mTetherEnabler);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Log.e(TAG, "TetherEnabler is not initialized");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTetherStateUpdated(@TetherEnabler.TetheringState int state) {
|
|
||||||
mTetheringState = state;
|
|
||||||
updateState(mPreference);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class BluetoothStateReceiver extends BroadcastReceiver {
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
final String action = intent.getAction();
|
|
||||||
Log.i(TAG, "onReceive: action: " + action);
|
|
||||||
|
|
||||||
if (TextUtils.equals(action, BluetoothAdapter.ACTION_STATE_CHANGED)) {
|
|
||||||
final int state =
|
|
||||||
intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
|
|
||||||
Log.i(TAG, "onReceive: state: " + BluetoothAdapter.nameForState(state));
|
|
||||||
final BluetoothProfile profile = mBluetoothPan.get();
|
|
||||||
switch(state) {
|
|
||||||
case BluetoothAdapter.STATE_ON:
|
|
||||||
if (profile == null && mBluetoothAdapter != null) {
|
|
||||||
mBluetoothAdapter.getProfileProxy(mContext, mBtProfileServiceListener,
|
|
||||||
BluetoothProfile.PAN);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2019 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.network;
|
|
||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.IntentFilter;
|
|
||||||
import android.net.ConnectivityManager;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
|
|
||||||
import androidx.lifecycle.Lifecycle;
|
|
||||||
import androidx.lifecycle.OnLifecycleEvent;
|
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This controller helps to manage the switch state and visibility of bluetooth tether switch
|
|
||||||
* preference.
|
|
||||||
*/
|
|
||||||
public final class BluetoothTetherPreferenceController extends TetherBasePreferenceController {
|
|
||||||
private int mBluetoothState;
|
|
||||||
|
|
||||||
public BluetoothTetherPreferenceController(Context context, String preferenceKey) {
|
|
||||||
super(context, preferenceKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_START)
|
|
||||||
public void onStart() {
|
|
||||||
mBluetoothState = BluetoothAdapter.getDefaultAdapter().getState();
|
|
||||||
mContext.registerReceiver(mBluetoothChangeReceiver,
|
|
||||||
new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
|
|
||||||
public void onStop() {
|
|
||||||
mContext.unregisterReceiver(mBluetoothChangeReceiver);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean shouldEnable() {
|
|
||||||
switch (mBluetoothState) {
|
|
||||||
case BluetoothAdapter.STATE_ON:
|
|
||||||
case BluetoothAdapter.STATE_OFF:
|
|
||||||
// fall through.
|
|
||||||
case BluetoothAdapter.ERROR:
|
|
||||||
return true;
|
|
||||||
case BluetoothAdapter.STATE_TURNING_OFF:
|
|
||||||
case BluetoothAdapter.STATE_TURNING_ON:
|
|
||||||
// fall through.
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean shouldShow() {
|
|
||||||
final String[] bluetoothRegexs = mTm.getTetherableBluetoothRegexs();
|
|
||||||
return bluetoothRegexs != null && bluetoothRegexs.length != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getTetherType() {
|
|
||||||
return ConnectivityManager.TETHERING_BLUETOOTH;
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
final BroadcastReceiver mBluetoothChangeReceiver = new BroadcastReceiver() {
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
if (TextUtils.equals(BluetoothAdapter.ACTION_STATE_CHANGED, intent.getAction())) {
|
|
||||||
mBluetoothState =
|
|
||||||
intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
|
|
||||||
updateState(mPreference);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,99 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2020 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.network;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.net.EthernetManager;
|
|
||||||
import android.net.TetheringManager;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.Looper;
|
|
||||||
|
|
||||||
import androidx.lifecycle.Lifecycle;
|
|
||||||
import androidx.lifecycle.OnLifecycleEvent;
|
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
|
||||||
import com.android.settings.Utils;
|
|
||||||
import com.android.settingslib.utils.ThreadUtils;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This controller helps to manage the switch state and visibility of ethernet tether switch
|
|
||||||
* preference.
|
|
||||||
*/
|
|
||||||
public final class EthernetTetherPreferenceController extends TetherBasePreferenceController {
|
|
||||||
|
|
||||||
private final HashSet<String> mAvailableInterfaces = new HashSet<>();
|
|
||||||
private final EthernetManager mEthernetManager;
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
EthernetManager.InterfaceStateListener mEthernetListener;
|
|
||||||
|
|
||||||
public EthernetTetherPreferenceController(Context context, String preferenceKey) {
|
|
||||||
super(context, preferenceKey);
|
|
||||||
mEthernetManager = context.getSystemService(EthernetManager.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_START)
|
|
||||||
public void onStart() {
|
|
||||||
mEthernetListener = (iface, state, role, configuration) -> {
|
|
||||||
if (state != EthernetManager.STATE_ABSENT) {
|
|
||||||
mAvailableInterfaces.add(iface);
|
|
||||||
} else {
|
|
||||||
mAvailableInterfaces.remove(iface);
|
|
||||||
}
|
|
||||||
updateState(mPreference);
|
|
||||||
};
|
|
||||||
final Handler handler = new Handler(Looper.getMainLooper());
|
|
||||||
// Executor will execute to post the updateState event to a new handler which is created
|
|
||||||
// from the main looper when the {@link EthernetManager.Listener.onAvailabilityChanged}
|
|
||||||
// is triggerd.
|
|
||||||
if (mEthernetManager != null) {
|
|
||||||
mEthernetManager.addInterfaceStateListener(r -> handler.post(r), mEthernetListener);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
|
|
||||||
public void onStop() {
|
|
||||||
if (mEthernetManager != null) {
|
|
||||||
mEthernetManager.removeInterfaceStateListener(mEthernetListener);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean shouldEnable() {
|
|
||||||
ThreadUtils.ensureMainThread();
|
|
||||||
String[] available = mTm.getTetherableIfaces();
|
|
||||||
for (String s : available) {
|
|
||||||
if (mAvailableInterfaces.contains(s)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean shouldShow() {
|
|
||||||
return mEthernetManager != null && !Utils.isMonkeyRunning();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getTetherType() {
|
|
||||||
return TetheringManager.TETHERING_ETHERNET;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -18,7 +18,6 @@ package com.android.settings.network;
|
|||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
|
||||||
|
|
||||||
import androidx.lifecycle.LifecycleOwner;
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
|
|
||||||
@@ -60,13 +59,6 @@ public class NetworkDashboardFragment extends DashboardFragment implements
|
|||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
|
|
||||||
use(AirplaneModePreferenceController.class).setFragment(this);
|
use(AirplaneModePreferenceController.class).setFragment(this);
|
||||||
getSettingsLifecycle().addObserver(use(AllInOneTetherPreferenceController.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
|
||||||
super.onCreatePreferences(savedInstanceState, rootKey);
|
|
||||||
use(AllInOneTetherPreferenceController.class).initEnabler(getSettingsLifecycle());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,162 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2020 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.network;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.net.TetheringManager;
|
|
||||||
|
|
||||||
import androidx.lifecycle.Lifecycle;
|
|
||||||
import androidx.lifecycle.LifecycleObserver;
|
|
||||||
import androidx.lifecycle.OnLifecycleEvent;
|
|
||||||
import androidx.preference.Preference;
|
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.core.TogglePreferenceController;
|
|
||||||
import com.android.settings.datausage.DataSaverBackend;
|
|
||||||
|
|
||||||
public abstract class TetherBasePreferenceController extends TogglePreferenceController
|
|
||||||
implements LifecycleObserver, DataSaverBackend.Listener,
|
|
||||||
TetherEnabler.OnTetherStateUpdateListener {
|
|
||||||
|
|
||||||
private static final String TAG = "TetherBasePreferenceController";
|
|
||||||
final TetheringManager mTm;
|
|
||||||
private final DataSaverBackend mDataSaverBackend;
|
|
||||||
|
|
||||||
private TetherEnabler mTetherEnabler;
|
|
||||||
Preference mPreference;
|
|
||||||
private boolean mDataSaverEnabled;
|
|
||||||
int mTetheringState;
|
|
||||||
|
|
||||||
TetherBasePreferenceController(Context context, String preferenceKey) {
|
|
||||||
super(context, preferenceKey);
|
|
||||||
mTm = context.getSystemService(TetheringManager.class);
|
|
||||||
mDataSaverBackend = new DataSaverBackend(context);
|
|
||||||
mDataSaverEnabled = mDataSaverBackend.isDataSaverEnabled();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set TetherEnabler for the controller. Call this method to initialize the controller.
|
|
||||||
* @param tetherEnabler The tetherEnabler to set for the controller.
|
|
||||||
*/
|
|
||||||
public void setTetherEnabler(TetherEnabler tetherEnabler) {
|
|
||||||
mTetherEnabler = tetherEnabler;
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
|
||||||
public void onResume() {
|
|
||||||
// Must call setEnabler() before
|
|
||||||
if (mTetherEnabler != null) {
|
|
||||||
mTetherEnabler.addListener(this);
|
|
||||||
}
|
|
||||||
mDataSaverBackend.addListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
|
|
||||||
public void onPause() {
|
|
||||||
if (mTetherEnabler != null) {
|
|
||||||
mTetherEnabler.removeListener(this);
|
|
||||||
}
|
|
||||||
mDataSaverBackend.remListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isChecked() {
|
|
||||||
return TetherEnabler.isTethering(mTetheringState, getTetherType());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean setChecked(boolean isChecked) {
|
|
||||||
if (mTetherEnabler == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (isChecked) {
|
|
||||||
mTetherEnabler.startTethering(getTetherType());
|
|
||||||
} else {
|
|
||||||
mTetherEnabler.stopTethering(getTetherType());
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void displayPreference(PreferenceScreen screen) {
|
|
||||||
super.displayPreference(screen);
|
|
||||||
mPreference = screen.findPreference(mPreferenceKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateState(Preference preference) {
|
|
||||||
super.updateState(preference);
|
|
||||||
if (isAvailable()) {
|
|
||||||
preference.setEnabled(getAvailabilityStatus() != DISABLED_DEPENDENT_SETTING);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getAvailabilityStatus() {
|
|
||||||
if (!shouldShow()) {
|
|
||||||
return CONDITIONALLY_UNAVAILABLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mDataSaverEnabled || !shouldEnable()) {
|
|
||||||
return DISABLED_DEPENDENT_SETTING;
|
|
||||||
}
|
|
||||||
return AVAILABLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSliceHighlightMenuRes() {
|
|
||||||
return R.string.menu_key_network;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTetherStateUpdated(@TetherEnabler.TetheringState int state) {
|
|
||||||
mTetheringState = state;
|
|
||||||
updateState(mPreference);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDataSaverChanged(boolean isDataSaving) {
|
|
||||||
mDataSaverEnabled = isDataSaving;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAllowlistStatusChanged(int uid, boolean isAllowlisted) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDenylistStatusChanged(int uid, boolean isDenylisted) {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used to enable or disable the preference.
|
|
||||||
* @return true if the preference should be enabled; false otherwise.
|
|
||||||
*/
|
|
||||||
public abstract boolean shouldEnable();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used to determine visibility of the preference.
|
|
||||||
* @return true if the preference should be visible; false otherwise.
|
|
||||||
*/
|
|
||||||
public abstract boolean shouldShow();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the type of tether interface that is controlled by the preference.
|
|
||||||
* @return the tether interface, like {@link ConnectivityManager#TETHERING_WIFI}
|
|
||||||
*/
|
|
||||||
public abstract int getTetherType();
|
|
||||||
}
|
|
||||||
@@ -20,7 +20,6 @@ import android.content.Context
|
|||||||
import android.net.TetheringManager
|
import android.net.TetheringManager
|
||||||
import android.os.UserHandle
|
import android.os.UserHandle
|
||||||
import android.os.UserManager
|
import android.os.UserManager
|
||||||
import android.util.FeatureFlagUtils
|
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import androidx.annotation.VisibleForTesting
|
import androidx.annotation.VisibleForTesting
|
||||||
import androidx.lifecycle.Lifecycle
|
import androidx.lifecycle.Lifecycle
|
||||||
@@ -31,7 +30,6 @@ import androidx.preference.Preference
|
|||||||
import androidx.preference.PreferenceScreen
|
import androidx.preference.PreferenceScreen
|
||||||
import com.android.settings.R
|
import com.android.settings.R
|
||||||
import com.android.settings.core.BasePreferenceController
|
import com.android.settings.core.BasePreferenceController
|
||||||
import com.android.settings.core.FeatureFlags
|
|
||||||
import com.android.settingslib.RestrictedLockUtilsInternal
|
import com.android.settingslib.RestrictedLockUtilsInternal
|
||||||
import com.android.settingslib.TetherUtil
|
import com.android.settingslib.TetherUtil
|
||||||
import com.android.settingslib.Utils
|
import com.android.settingslib.Utils
|
||||||
@@ -49,13 +47,7 @@ class TetherPreferenceController(context: Context, key: String) :
|
|||||||
private var preference: Preference? = null
|
private var preference: Preference? = null
|
||||||
|
|
||||||
override fun getAvailabilityStatus() =
|
override fun getAvailabilityStatus() =
|
||||||
if (TetherUtil.isTetherAvailable(mContext)
|
if (TetherUtil.isTetherAvailable(mContext)) AVAILABLE else CONDITIONALLY_UNAVAILABLE
|
||||||
&& !FeatureFlagUtils.isEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE)
|
|
||||||
) {
|
|
||||||
AVAILABLE
|
|
||||||
} else {
|
|
||||||
CONDITIONALLY_UNAVAILABLE
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun displayPreference(screen: PreferenceScreen) {
|
override fun displayPreference(screen: PreferenceScreen) {
|
||||||
super.displayPreference(screen)
|
super.displayPreference(screen)
|
||||||
|
|||||||
@@ -1,95 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2019 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.network;
|
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.IntentFilter;
|
|
||||||
import android.hardware.usb.UsbManager;
|
|
||||||
import android.net.ConnectivityManager;
|
|
||||||
import android.os.Environment;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
|
||||||
import androidx.lifecycle.Lifecycle;
|
|
||||||
import androidx.lifecycle.OnLifecycleEvent;
|
|
||||||
|
|
||||||
import com.android.settings.Utils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This controller helps to manage the switch state and visibility of USB tether switch
|
|
||||||
* preference.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public final class UsbTetherPreferenceController extends TetherBasePreferenceController {
|
|
||||||
|
|
||||||
private static final String TAG = "UsbTetherPrefController";
|
|
||||||
|
|
||||||
private boolean mUsbConnected;
|
|
||||||
private boolean mMassStorageActive;
|
|
||||||
|
|
||||||
public UsbTetherPreferenceController(Context context, String prefKey) {
|
|
||||||
super(context, prefKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_START)
|
|
||||||
public void onStart() {
|
|
||||||
mMassStorageActive = Environment.MEDIA_SHARED.equals(Environment.getExternalStorageState());
|
|
||||||
IntentFilter filter = new IntentFilter(UsbManager.ACTION_USB_STATE);
|
|
||||||
filter.addAction(Intent.ACTION_MEDIA_SHARED);
|
|
||||||
filter.addAction(Intent.ACTION_MEDIA_UNSHARED);
|
|
||||||
mContext.registerReceiver(mUsbChangeReceiver, filter);
|
|
||||||
}
|
|
||||||
|
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
|
|
||||||
public void onStop() {
|
|
||||||
mContext.unregisterReceiver(mUsbChangeReceiver);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean shouldEnable() {
|
|
||||||
return mUsbConnected && !mMassStorageActive;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean shouldShow() {
|
|
||||||
String[] usbRegexs = mTm.getTetherableUsbRegexs();
|
|
||||||
return usbRegexs != null && usbRegexs.length != 0 && !Utils.isMonkeyRunning();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getTetherType() {
|
|
||||||
return ConnectivityManager.TETHERING_USB;
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
final BroadcastReceiver mUsbChangeReceiver = new BroadcastReceiver() {
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
String action = intent.getAction();
|
|
||||||
if (TextUtils.equals(Intent.ACTION_MEDIA_SHARED, action)) {
|
|
||||||
mMassStorageActive = true;
|
|
||||||
} else if (TextUtils.equals(Intent.ACTION_MEDIA_UNSHARED, action)) {
|
|
||||||
mMassStorageActive = false;
|
|
||||||
} else if (TextUtils.equals(UsbManager.ACTION_USB_STATE, action)) {
|
|
||||||
mUsbConnected = intent.getBooleanExtra(UsbManager.USB_CONNECTED, false);
|
|
||||||
}
|
|
||||||
updateState(mPreference);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,120 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2019 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.network;
|
|
||||||
|
|
||||||
import static com.android.settings.network.TetherEnabler.TETHERING_BLUETOOTH_ON;
|
|
||||||
import static com.android.settings.network.TetherEnabler.TETHERING_ETHERNET_ON;
|
|
||||||
import static com.android.settings.network.TetherEnabler.TETHERING_USB_ON;
|
|
||||||
import static com.android.settings.network.TetherEnabler.TETHERING_WIFI_ON;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.net.ConnectivityManager;
|
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.Utils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This controller helps to manage the switch state and visibility of wifi tether disable switch
|
|
||||||
* preference. When the preference checked, wifi tether will be disabled.
|
|
||||||
*
|
|
||||||
* @see BluetoothTetherPreferenceController
|
|
||||||
* @see UsbTetherPreferenceController
|
|
||||||
*/
|
|
||||||
public final class WifiTetherDisablePreferenceController extends TetherBasePreferenceController {
|
|
||||||
|
|
||||||
private static final String TAG = "WifiTetherDisablePreferenceController";
|
|
||||||
|
|
||||||
private PreferenceScreen mScreen;
|
|
||||||
|
|
||||||
public WifiTetherDisablePreferenceController(Context context, String prefKey) {
|
|
||||||
super(context, prefKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isChecked() {
|
|
||||||
return !super.isChecked();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean setChecked(boolean isChecked) {
|
|
||||||
return super.setChecked(!isChecked);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getTetheringStateOfOtherInterfaces() {
|
|
||||||
return mTetheringState & (~TETHERING_WIFI_ON);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean shouldEnable() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean shouldShow() {
|
|
||||||
final String[] wifiRegexs = mTm.getTetherableWifiRegexs();
|
|
||||||
return wifiRegexs != null && wifiRegexs.length != 0 && !Utils.isMonkeyRunning()
|
|
||||||
&& getTetheringStateOfOtherInterfaces() != TetherEnabler.TETHERING_OFF;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getTetherType() {
|
|
||||||
return ConnectivityManager.TETHERING_WIFI;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CharSequence getSummary() {
|
|
||||||
switch (getTetheringStateOfOtherInterfaces()) {
|
|
||||||
case TETHERING_USB_ON:
|
|
||||||
return mContext.getString(R.string.disable_wifi_hotspot_when_usb_on);
|
|
||||||
case TETHERING_BLUETOOTH_ON:
|
|
||||||
return mContext.getString(R.string.disable_wifi_hotspot_when_bluetooth_on);
|
|
||||||
case TETHERING_ETHERNET_ON:
|
|
||||||
return mContext.getString(R.string.disable_wifi_hotspot_when_ethernet_on);
|
|
||||||
case TETHERING_USB_ON | TETHERING_BLUETOOTH_ON:
|
|
||||||
return mContext.getString(R.string.disable_wifi_hotspot_when_usb_and_bluetooth_on);
|
|
||||||
case TETHERING_USB_ON | TETHERING_ETHERNET_ON:
|
|
||||||
return mContext.getString(R.string.disable_wifi_hotspot_when_usb_and_ethernet_on);
|
|
||||||
case TETHERING_BLUETOOTH_ON | TETHERING_ETHERNET_ON:
|
|
||||||
return mContext.getString(
|
|
||||||
R.string.disable_wifi_hotspot_when_bluetooth_and_ethernet_on);
|
|
||||||
case TETHERING_USB_ON | TETHERING_BLUETOOTH_ON | TETHERING_ETHERNET_ON:
|
|
||||||
return mContext.getString(
|
|
||||||
R.string.disable_wifi_hotspot_when_usb_and_bluetooth_and_ethernet_on);
|
|
||||||
default:
|
|
||||||
return mContext.getString(R.string.summary_placeholder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void displayPreference(PreferenceScreen screen) {
|
|
||||||
super.displayPreference(screen);
|
|
||||||
mScreen = screen;
|
|
||||||
if (mPreference != null) {
|
|
||||||
mPreference.setOnPreferenceChangeListener(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateState(Preference preference) {
|
|
||||||
super.updateState(preference);
|
|
||||||
preference.setVisible(isAvailable());
|
|
||||||
refreshSummary(preference);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -45,7 +45,6 @@ import android.os.UserHandle;
|
|||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.provider.SearchIndexableResource;
|
import android.provider.SearchIndexableResource;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.FeatureFlagUtils;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@@ -57,7 +56,6 @@ import androidx.preference.TwoStatePreference;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.RestrictedSettingsFragment;
|
import com.android.settings.RestrictedSettingsFragment;
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
import com.android.settings.core.FeatureFlags;
|
|
||||||
import com.android.settings.datausage.DataSaverBackend;
|
import com.android.settings.datausage.DataSaverBackend;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settings.wifi.tether.WifiTetherPreferenceController;
|
import com.android.settings.wifi.tether.WifiTetherPreferenceController;
|
||||||
@@ -629,11 +627,6 @@ public class TetherSettings extends RestrictedSettingsFragment
|
|||||||
return Arrays.asList(sir);
|
return Arrays.asList(sir);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean isPageSearchEnabled(Context context) {
|
|
||||||
return !FeatureFlagUtils.isEnabled(context, FeatureFlags.TETHER_ALL_IN_ONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getNonIndexableKeys(Context context) {
|
public List<String> getNonIndexableKeys(Context context) {
|
||||||
final List<String> keys = super.getNonIndexableKeys(context);
|
final List<String> keys = super.getNonIndexableKeys(context);
|
||||||
|
|||||||
@@ -1,139 +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.tether;
|
|
||||||
|
|
||||||
import static com.android.settings.AllInOneTetherSettings.DEDUP_POSTFIX;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.net.wifi.SoftApConfiguration;
|
|
||||||
import android.util.FeatureFlagUtils;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
|
||||||
import androidx.preference.ListPreference;
|
|
||||||
import androidx.preference.Preference;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.core.FeatureFlags;
|
|
||||||
|
|
||||||
public class WifiTetherApBandPreferenceController extends WifiTetherBasePreferenceController {
|
|
||||||
|
|
||||||
private static final String TAG = "WifiTetherApBandPref";
|
|
||||||
private static final String PREF_KEY = "wifi_tether_network_ap_band";
|
|
||||||
|
|
||||||
private String[] mBandEntries;
|
|
||||||
private String[] mBandSummaries;
|
|
||||||
private int mBandIndex;
|
|
||||||
|
|
||||||
public WifiTetherApBandPreferenceController(Context context,
|
|
||||||
OnTetherConfigUpdateListener listener) {
|
|
||||||
super(context, listener);
|
|
||||||
updatePreferenceEntries();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateDisplay() {
|
|
||||||
final SoftApConfiguration config = mWifiManager.getSoftApConfiguration();
|
|
||||||
if (config == null) {
|
|
||||||
mBandIndex = SoftApConfiguration.BAND_2GHZ;
|
|
||||||
Log.d(TAG, "Updating band index to BAND_2GHZ because no config");
|
|
||||||
} else if (is5GhzBandSupported()) {
|
|
||||||
mBandIndex = validateSelection(config.getBand());
|
|
||||||
Log.d(TAG, "Updating band index to " + mBandIndex);
|
|
||||||
} else {
|
|
||||||
mWifiManager.setSoftApConfiguration(
|
|
||||||
new SoftApConfiguration.Builder(config).setBand(SoftApConfiguration.BAND_2GHZ)
|
|
||||||
.build());
|
|
||||||
mBandIndex = SoftApConfiguration.BAND_2GHZ;
|
|
||||||
Log.d(TAG, "5Ghz not supported, updating band index to 2GHz");
|
|
||||||
}
|
|
||||||
ListPreference preference =
|
|
||||||
(ListPreference) mPreference;
|
|
||||||
preference.setEntries(mBandSummaries);
|
|
||||||
preference.setEntryValues(mBandEntries);
|
|
||||||
|
|
||||||
if (!is5GhzBandSupported()) {
|
|
||||||
preference.setEnabled(false);
|
|
||||||
preference.setSummary(R.string.wifi_ap_choose_2G);
|
|
||||||
} else {
|
|
||||||
preference.setValue(Integer.toString(config.getBand()));
|
|
||||||
preference.setSummary(getConfigSummary());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String getConfigSummary() {
|
|
||||||
switch (mBandIndex) {
|
|
||||||
case SoftApConfiguration.BAND_2GHZ:
|
|
||||||
return mBandSummaries[0];
|
|
||||||
case SoftApConfiguration.BAND_5GHZ:
|
|
||||||
return mBandSummaries[1];
|
|
||||||
default:
|
|
||||||
return mContext.getString(R.string.wifi_ap_prefer_5G);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPreferenceKey() {
|
|
||||||
return FeatureFlagUtils.isEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE)
|
|
||||||
? PREF_KEY + DEDUP_POSTFIX : PREF_KEY;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
||||||
mBandIndex = validateSelection(Integer.parseInt((String) newValue));
|
|
||||||
Log.d(TAG, "Band preference changed, updating band index to " + mBandIndex);
|
|
||||||
preference.setSummary(getConfigSummary());
|
|
||||||
mListener.onTetherConfigUpdated(this);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int validateSelection(int band) {
|
|
||||||
// unsupported states:
|
|
||||||
// 1: BAND_5GHZ only - include 2GHZ since some of countries doesn't support 5G hotspot
|
|
||||||
// 2: no 5 GHZ support means we can't have BAND_5GHZ - default to 2GHZ
|
|
||||||
if (SoftApConfiguration.BAND_5GHZ == band) {
|
|
||||||
if (!is5GhzBandSupported()) {
|
|
||||||
return SoftApConfiguration.BAND_2GHZ;
|
|
||||||
}
|
|
||||||
return SoftApConfiguration.BAND_5GHZ | SoftApConfiguration.BAND_2GHZ;
|
|
||||||
}
|
|
||||||
|
|
||||||
return band;
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
void updatePreferenceEntries() {
|
|
||||||
Resources res = mContext.getResources();
|
|
||||||
int entriesRes = R.array.wifi_ap_band;
|
|
||||||
int summariesRes = R.array.wifi_ap_band_summary;
|
|
||||||
mBandEntries = res.getStringArray(entriesRes);
|
|
||||||
mBandSummaries = res.getStringArray(summariesRes);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean is5GhzBandSupported() {
|
|
||||||
final String countryCode = mWifiManager.getCountryCode();
|
|
||||||
if (!mWifiManager.is5GHzBandSupported() || countryCode == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getBandIndex() {
|
|
||||||
return mBandIndex;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -16,20 +16,16 @@
|
|||||||
|
|
||||||
package com.android.settings.wifi.tether;
|
package com.android.settings.wifi.tether;
|
||||||
|
|
||||||
import static com.android.settings.AllInOneTetherSettings.DEDUP_POSTFIX;
|
|
||||||
|
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.wifi.SoftApConfiguration;
|
import android.net.wifi.SoftApConfiguration;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.FeatureFlagUtils;
|
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.preference.EditTextPreference;
|
import androidx.preference.EditTextPreference;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.FeatureFlags;
|
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.widget.ValidatedEditTextPreference;
|
import com.android.settings.widget.ValidatedEditTextPreference;
|
||||||
import com.android.settings.wifi.WifiUtils;
|
import com.android.settings.wifi.WifiUtils;
|
||||||
@@ -68,8 +64,7 @@ public class WifiTetherPasswordPreferenceController extends WifiTetherBasePrefer
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPreferenceKey() {
|
public String getPreferenceKey() {
|
||||||
return FeatureFlagUtils.isEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE)
|
return PREF_KEY;
|
||||||
? PREF_KEY + DEDUP_POSTFIX : PREF_KEY;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -16,21 +16,17 @@
|
|||||||
|
|
||||||
package com.android.settings.wifi.tether;
|
package com.android.settings.wifi.tether;
|
||||||
|
|
||||||
import static com.android.settings.AllInOneTetherSettings.DEDUP_POSTFIX;
|
|
||||||
|
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.wifi.SoftApConfiguration;
|
import android.net.wifi.SoftApConfiguration;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.FeatureFlagUtils;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.preference.EditTextPreference;
|
import androidx.preference.EditTextPreference;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.core.FeatureFlags;
|
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.widget.ValidatedEditTextPreference;
|
import com.android.settings.widget.ValidatedEditTextPreference;
|
||||||
import com.android.settings.wifi.dpp.WifiDppUtils;
|
import com.android.settings.wifi.dpp.WifiDppUtils;
|
||||||
@@ -68,8 +64,7 @@ public class WifiTetherSSIDPreferenceController extends WifiTetherBasePreference
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPreferenceKey() {
|
public String getPreferenceKey() {
|
||||||
return FeatureFlagUtils.isEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE)
|
return PREF_KEY;
|
||||||
? PREF_KEY + DEDUP_POSTFIX : PREF_KEY;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -16,14 +16,11 @@
|
|||||||
|
|
||||||
package com.android.settings.wifi.tether;
|
package com.android.settings.wifi.tether;
|
||||||
|
|
||||||
import static com.android.settings.AllInOneTetherSettings.DEDUP_POSTFIX;
|
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.wifi.SoftApCapability;
|
import android.net.wifi.SoftApCapability;
|
||||||
import android.net.wifi.SoftApConfiguration;
|
import android.net.wifi.SoftApConfiguration;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.util.FeatureFlagUtils;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
@@ -31,7 +28,6 @@ import androidx.preference.ListPreference;
|
|||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.FeatureFlags;
|
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
@@ -82,8 +78,7 @@ public class WifiTetherSecurityPreferenceController extends WifiTetherBasePrefer
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPreferenceKey() {
|
public String getPreferenceKey() {
|
||||||
return FeatureFlagUtils.isEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE)
|
return PREF_KEY;
|
||||||
? PREF_KEY + DEDUP_POSTFIX : PREF_KEY;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import android.content.IntentFilter;
|
|||||||
import android.net.wifi.SoftApConfiguration;
|
import android.net.wifi.SoftApConfiguration;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.util.FeatureFlagUtils;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
@@ -39,7 +38,6 @@ import androidx.preference.Preference;
|
|||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.SettingsActivity;
|
import com.android.settings.SettingsActivity;
|
||||||
import com.android.settings.core.FeatureFlags;
|
|
||||||
import com.android.settings.dashboard.RestrictedDashboardFragment;
|
import com.android.settings.dashboard.RestrictedDashboardFragment;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
@@ -387,10 +385,7 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
|
|||||||
if (userManager == null || !userManager.isAdminUser()) {
|
if (userManager == null || !userManager.isAdminUser()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!WifiUtils.canShowWifiHotspot(context)) {
|
return WifiUtils.canShowWifiHotspot(context);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return !FeatureFlagUtils.isEnabled(context, FeatureFlags.TETHER_ALL_IN_ONE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,240 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2020 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;
|
|
||||||
|
|
||||||
import static com.android.settings.AllInOneTetherSettings.BLUETOOTH_TETHER_KEY;
|
|
||||||
import static com.android.settings.AllInOneTetherSettings.ETHERNET_TETHER_KEY;
|
|
||||||
import static com.android.settings.AllInOneTetherSettings.EXPANDED_CHILD_COUNT_DEFAULT;
|
|
||||||
import static com.android.settings.AllInOneTetherSettings.EXPANDED_CHILD_COUNT_MAX;
|
|
||||||
import static com.android.settings.AllInOneTetherSettings.EXPANDED_CHILD_COUNT_WITH_SECURITY_NON;
|
|
||||||
import static com.android.settings.AllInOneTetherSettings.USB_TETHER_KEY;
|
|
||||||
import static com.android.settings.AllInOneTetherSettings.WIFI_TETHER_DISABLE_KEY;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import static org.mockito.Mockito.doReturn;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.spy;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.net.ConnectivityManager;
|
|
||||||
import android.net.EthernetManager;
|
|
||||||
import android.net.TetheringManager;
|
|
||||||
import android.net.wifi.SoftApConfiguration;
|
|
||||||
import android.net.wifi.WifiManager;
|
|
||||||
import android.os.UserHandle;
|
|
||||||
import android.os.UserManager;
|
|
||||||
import android.util.FeatureFlagUtils;
|
|
||||||
|
|
||||||
import androidx.preference.PreferenceGroup;
|
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
|
|
||||||
import com.android.settings.core.FeatureFlags;
|
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
|
||||||
import com.android.settings.wifi.repository.WifiHotspotRepository;
|
|
||||||
import com.android.settings.wifi.tether.WifiTetherAutoOffPreferenceController;
|
|
||||||
import com.android.settings.wifi.tether.WifiTetherSecurityPreferenceController;
|
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
import org.robolectric.RobolectricTestRunner;
|
|
||||||
import org.robolectric.RuntimeEnvironment;
|
|
||||||
import org.robolectric.util.ReflectionHelpers;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
|
||||||
public class AllInOneTetherSettingsTest {
|
|
||||||
private static final String[] WIFI_REGEXS = {"wifi_regexs"};
|
|
||||||
private static final String[] USB_REGEXS = {"usb_regexs"};
|
|
||||||
private static final String[] BT_REGEXS = {"bt_regexs"};
|
|
||||||
private static final String[] ETHERNET_REGEXS = {"ethernet_regexs"};
|
|
||||||
|
|
||||||
private Context mContext;
|
|
||||||
private AllInOneTetherSettings mAllInOneTetherSettings;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private WifiManager mWifiManager;
|
|
||||||
@Mock
|
|
||||||
private ConnectivityManager mConnectivityManager;
|
|
||||||
@Mock
|
|
||||||
private TetheringManager mTetheringManager;
|
|
||||||
@Mock
|
|
||||||
private UserManager mUserManager;
|
|
||||||
@Mock
|
|
||||||
private WifiTetherSecurityPreferenceController mSecurityPreferenceController;
|
|
||||||
@Mock
|
|
||||||
private PreferenceScreen mPreferenceScreen;
|
|
||||||
@Mock
|
|
||||||
private PreferenceGroup mWifiTetherGroup;
|
|
||||||
@Mock
|
|
||||||
private EthernetManager mEthernetManager;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
mContext = spy(RuntimeEnvironment.application);
|
|
||||||
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
when(FakeFeatureFactory.setupForTest().getWifiFeatureProvider().getWifiHotspotRepository())
|
|
||||||
.thenReturn(mock(WifiHotspotRepository.class));
|
|
||||||
doReturn(mWifiManager).when(mContext).getSystemService(WifiManager.class);
|
|
||||||
doReturn(mConnectivityManager)
|
|
||||||
.when(mContext).getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
||||||
doReturn(mTetheringManager)
|
|
||||||
.when(mContext).getSystemService(Context.TETHERING_SERVICE);
|
|
||||||
doReturn(mEthernetManager).when(mContext).getSystemService(EthernetManager.class);
|
|
||||||
doReturn(WIFI_REGEXS).when(mTetheringManager).getTetherableWifiRegexs();
|
|
||||||
doReturn(USB_REGEXS).when(mTetheringManager).getTetherableUsbRegexs();
|
|
||||||
doReturn(BT_REGEXS).when(mTetheringManager).getTetherableBluetoothRegexs();
|
|
||||||
doReturn(ETHERNET_REGEXS).when(mTetheringManager).getTetherableIfaces();
|
|
||||||
doReturn(mUserManager).when(mContext).getSystemService(Context.USER_SERVICE);
|
|
||||||
// Assume the feature is enabled for most test cases.
|
|
||||||
FeatureFlagUtils.setEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE, true);
|
|
||||||
mAllInOneTetherSettings = spy(new AllInOneTetherSettings());
|
|
||||||
doReturn(mPreferenceScreen).when(mAllInOneTetherSettings).getPreferenceScreen();
|
|
||||||
ReflectionHelpers.setField(mAllInOneTetherSettings, "mLifecycle", mock(Lifecycle.class));
|
|
||||||
ReflectionHelpers.setField(mAllInOneTetherSettings, "mSecurityPreferenceController",
|
|
||||||
mSecurityPreferenceController);
|
|
||||||
ReflectionHelpers.setField(mAllInOneTetherSettings, "mWifiTetherGroup", mWifiTetherGroup);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getNonIndexableKeys_tetherAvailable_featureEnabled_keysReturnedCorrectly() {
|
|
||||||
// To let TetherUtil.isTetherAvailable return true, select one of the combinations
|
|
||||||
setupIsTetherAvailable(true);
|
|
||||||
|
|
||||||
FeatureFlagUtils.setEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE, true);
|
|
||||||
final List<String> niks =
|
|
||||||
AllInOneTetherSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
|
|
||||||
|
|
||||||
assertThat(niks).doesNotContain(AllInOneTetherSettings.KEY_WIFI_TETHER_NETWORK_NAME);
|
|
||||||
assertThat(niks).doesNotContain(
|
|
||||||
AllInOneTetherSettings.KEY_WIFI_TETHER_NETWORK_PASSWORD);
|
|
||||||
assertThat(niks).doesNotContain(AllInOneTetherSettings.KEY_WIFI_TETHER_AUTO_OFF);
|
|
||||||
assertThat(niks).doesNotContain(AllInOneTetherSettings.KEY_WIFI_TETHER_NETWORK_AP_BAND);
|
|
||||||
assertThat(niks).doesNotContain(AllInOneTetherSettings.KEY_WIFI_TETHER_SECURITY);
|
|
||||||
assertThat(niks).doesNotContain(BLUETOOTH_TETHER_KEY);
|
|
||||||
assertThat(niks).doesNotContain(USB_TETHER_KEY);
|
|
||||||
assertThat(niks).doesNotContain(ETHERNET_TETHER_KEY);
|
|
||||||
|
|
||||||
// This key should be returned because it's not visible by default.
|
|
||||||
assertThat(niks).contains(WIFI_TETHER_DISABLE_KEY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getNonIndexableKeys_tetherAvailable_featureDisabled_keysReturned() {
|
|
||||||
setupIsTetherAvailable(true);
|
|
||||||
FeatureFlagUtils.setEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE, false);
|
|
||||||
|
|
||||||
final List<String> niks =
|
|
||||||
AllInOneTetherSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
|
|
||||||
|
|
||||||
assertThat(niks).contains(AllInOneTetherSettings.KEY_WIFI_TETHER_NETWORK_NAME);
|
|
||||||
assertThat(niks).contains(AllInOneTetherSettings.KEY_WIFI_TETHER_NETWORK_PASSWORD);
|
|
||||||
assertThat(niks).contains(AllInOneTetherSettings.KEY_WIFI_TETHER_AUTO_OFF);
|
|
||||||
assertThat(niks).contains(AllInOneTetherSettings.KEY_WIFI_TETHER_NETWORK_AP_BAND);
|
|
||||||
assertThat(niks).contains(AllInOneTetherSettings.KEY_WIFI_TETHER_SECURITY);
|
|
||||||
assertThat(niks).contains(WIFI_TETHER_DISABLE_KEY);
|
|
||||||
assertThat(niks).contains(BLUETOOTH_TETHER_KEY);
|
|
||||||
assertThat(niks).contains(USB_TETHER_KEY);
|
|
||||||
assertThat(niks).contains(ETHERNET_TETHER_KEY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getNonIndexableKeys_tetherNotAvailable_keysReturned() {
|
|
||||||
// To let TetherUtil.isTetherAvailable return false, select one of the combinations
|
|
||||||
setupIsTetherAvailable(false);
|
|
||||||
|
|
||||||
final List<String> niks =
|
|
||||||
AllInOneTetherSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
|
|
||||||
|
|
||||||
assertThat(niks).contains(AllInOneTetherSettings.KEY_WIFI_TETHER_NETWORK_NAME);
|
|
||||||
assertThat(niks).contains(AllInOneTetherSettings.KEY_WIFI_TETHER_NETWORK_PASSWORD);
|
|
||||||
assertThat(niks).contains(AllInOneTetherSettings.KEY_WIFI_TETHER_AUTO_OFF);
|
|
||||||
assertThat(niks).contains(AllInOneTetherSettings.KEY_WIFI_TETHER_NETWORK_AP_BAND);
|
|
||||||
assertThat(niks).contains(AllInOneTetherSettings.KEY_WIFI_TETHER_SECURITY);
|
|
||||||
assertThat(niks).contains(WIFI_TETHER_DISABLE_KEY);
|
|
||||||
assertThat(niks).doesNotContain(BLUETOOTH_TETHER_KEY);
|
|
||||||
assertThat(niks).doesNotContain(USB_TETHER_KEY);
|
|
||||||
assertThat(niks).doesNotContain(ETHERNET_TETHER_KEY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getPreferenceControllers_notEmpty() {
|
|
||||||
assertThat(AllInOneTetherSettings.SEARCH_INDEX_DATA_PROVIDER
|
|
||||||
.getPreferenceControllers(mContext)).isNotEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void createPreferenceControllers_hasAutoOffPreference() {
|
|
||||||
assertThat(mAllInOneTetherSettings.createPreferenceControllers(mContext)
|
|
||||||
.stream()
|
|
||||||
.filter(controller -> controller instanceof WifiTetherAutoOffPreferenceController)
|
|
||||||
.count())
|
|
||||||
.isEqualTo(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getInitialChildCount_withSecurity() {
|
|
||||||
when(mSecurityPreferenceController.getSecurityType())
|
|
||||||
.thenReturn(SoftApConfiguration.SECURITY_TYPE_WPA2_PSK);
|
|
||||||
assertThat(mAllInOneTetherSettings.getInitialExpandedChildCount()).isEqualTo(
|
|
||||||
EXPANDED_CHILD_COUNT_DEFAULT);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getInitialChildCount_withoutSecurity() {
|
|
||||||
when(mSecurityPreferenceController.getSecurityType())
|
|
||||||
.thenReturn(SoftApConfiguration.SECURITY_TYPE_OPEN);
|
|
||||||
assertThat(mAllInOneTetherSettings.getInitialExpandedChildCount()).isEqualTo(
|
|
||||||
EXPANDED_CHILD_COUNT_WITH_SECURITY_NON);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getInitialExpandedChildCount_expandAllChild() {
|
|
||||||
assertThat(mAllInOneTetherSettings.getInitialExpandedChildCount())
|
|
||||||
.isNotEqualTo(EXPANDED_CHILD_COUNT_MAX);
|
|
||||||
ReflectionHelpers.setField(mAllInOneTetherSettings, "mShouldShowWifiConfig", false);
|
|
||||||
assertThat(mAllInOneTetherSettings.getInitialExpandedChildCount())
|
|
||||||
.isEqualTo(EXPANDED_CHILD_COUNT_MAX);
|
|
||||||
ReflectionHelpers.setField(mAllInOneTetherSettings, "mShouldShowWifiConfig", true);
|
|
||||||
assertThat(mAllInOneTetherSettings.getInitialExpandedChildCount())
|
|
||||||
.isEqualTo(EXPANDED_CHILD_COUNT_MAX);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setupIsTetherAvailable(boolean returnValue) {
|
|
||||||
when(mConnectivityManager.isTetheringSupported()).thenReturn(true);
|
|
||||||
|
|
||||||
// For RestrictedLockUtils.checkIfRestrictionEnforced
|
|
||||||
final int userId = UserHandle.myUserId();
|
|
||||||
List<UserManager.EnforcingUser> enforcingUsers = new ArrayList<>();
|
|
||||||
when(mUserManager.getUserRestrictionSources(
|
|
||||||
UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.of(userId)))
|
|
||||||
.thenReturn(enforcingUsers);
|
|
||||||
|
|
||||||
// For RestrictedLockUtils.hasBaseUserRestriction
|
|
||||||
when(mUserManager.hasBaseUserRestriction(
|
|
||||||
UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.of(userId)))
|
|
||||||
.thenReturn(!returnValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,187 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2020 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.network;
|
|
||||||
|
|
||||||
import static com.android.settings.network.TetherEnabler.TETHERING_BLUETOOTH_ON;
|
|
||||||
import static com.android.settings.network.TetherEnabler.TETHERING_ETHERNET_ON;
|
|
||||||
import static com.android.settings.network.TetherEnabler.TETHERING_OFF;
|
|
||||||
import static com.android.settings.network.TetherEnabler.TETHERING_USB_ON;
|
|
||||||
import static com.android.settings.network.TetherEnabler.TETHERING_WIFI_ON;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import static org.mockito.Mockito.doReturn;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.spy;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
|
||||||
import android.bluetooth.BluetoothPan;
|
|
||||||
import android.bluetooth.BluetoothProfile;
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settingslib.PrimarySwitchPreference;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
import org.robolectric.ParameterizedRobolectricTestRunner;
|
|
||||||
import org.robolectric.util.ReflectionHelpers;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
|
|
||||||
@RunWith(ParameterizedRobolectricTestRunner.class)
|
|
||||||
public class AllInOneTetherPreferenceControllerTest {
|
|
||||||
|
|
||||||
@ParameterizedRobolectricTestRunner.Parameters(name = "TetherState: {0}")
|
|
||||||
public static List params() {
|
|
||||||
return Arrays.asList(new Object[][] {
|
|
||||||
{TETHERING_OFF, R.string.tether_settings_summary_off},
|
|
||||||
{TETHERING_WIFI_ON, R.string.tether_settings_summary_hotspot_only},
|
|
||||||
{TETHERING_USB_ON, R.string.tether_settings_summary_usb_tethering_only},
|
|
||||||
{TETHERING_BLUETOOTH_ON, R.string.tether_settings_summary_bluetooth_tethering_only},
|
|
||||||
{TETHERING_ETHERNET_ON, R.string.tether_settings_summary_ethernet_tethering_only},
|
|
||||||
{
|
|
||||||
TETHERING_WIFI_ON | TETHERING_USB_ON,
|
|
||||||
R.string.tether_settings_summary_hotspot_and_usb
|
|
||||||
},
|
|
||||||
{
|
|
||||||
TETHERING_WIFI_ON | TETHERING_BLUETOOTH_ON,
|
|
||||||
R.string.tether_settings_summary_hotspot_and_bluetooth
|
|
||||||
},
|
|
||||||
{
|
|
||||||
TETHERING_WIFI_ON | TETHERING_ETHERNET_ON,
|
|
||||||
R.string.tether_settings_summary_hotspot_and_ethernet
|
|
||||||
},
|
|
||||||
{
|
|
||||||
TETHERING_USB_ON | TETHERING_BLUETOOTH_ON,
|
|
||||||
R.string.tether_settings_summary_usb_and_bluetooth
|
|
||||||
},
|
|
||||||
{
|
|
||||||
TETHERING_USB_ON | TETHERING_ETHERNET_ON,
|
|
||||||
R.string.tether_settings_summary_usb_and_ethernet
|
|
||||||
},
|
|
||||||
{
|
|
||||||
TETHERING_BLUETOOTH_ON | TETHERING_ETHERNET_ON,
|
|
||||||
R.string.tether_settings_summary_bluetooth_and_ethernet
|
|
||||||
},
|
|
||||||
{
|
|
||||||
TETHERING_WIFI_ON | TETHERING_USB_ON | TETHERING_BLUETOOTH_ON,
|
|
||||||
R.string.tether_settings_summary_hotspot_and_usb_and_bluetooth
|
|
||||||
},
|
|
||||||
{
|
|
||||||
TETHERING_WIFI_ON | TETHERING_USB_ON | TETHERING_ETHERNET_ON,
|
|
||||||
R.string.tether_settings_summary_hotspot_and_usb_and_ethernet
|
|
||||||
},
|
|
||||||
{
|
|
||||||
TETHERING_WIFI_ON | TETHERING_BLUETOOTH_ON | TETHERING_ETHERNET_ON,
|
|
||||||
R.string.tether_settings_summary_hotspot_and_bluetooth_and_ethernet
|
|
||||||
},
|
|
||||||
{
|
|
||||||
TETHERING_USB_ON | TETHERING_BLUETOOTH_ON | TETHERING_ETHERNET_ON,
|
|
||||||
R.string.tether_settings_summary_usb_and_bluetooth_and_ethernet
|
|
||||||
},
|
|
||||||
{
|
|
||||||
TETHERING_WIFI_ON | TETHERING_USB_ON | TETHERING_BLUETOOTH_ON
|
|
||||||
| TETHERING_ETHERNET_ON,
|
|
||||||
R.string.tether_settings_summary_all
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private Context mContext;
|
|
||||||
@Mock
|
|
||||||
private BluetoothAdapter mBluetoothAdapter;
|
|
||||||
@Mock
|
|
||||||
private PrimarySwitchPreference mPreference;
|
|
||||||
|
|
||||||
private static final String PREF_KEY = "tether";
|
|
||||||
private AllInOneTetherPreferenceController mController;
|
|
||||||
private final int mTetherState;
|
|
||||||
private final int mSummaryResId;
|
|
||||||
|
|
||||||
public AllInOneTetherPreferenceControllerTest(int tetherState, int summaryResId) {
|
|
||||||
mTetherState = tetherState;
|
|
||||||
mSummaryResId = summaryResId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
doReturn(null).when(mContext)
|
|
||||||
.getSystemService(Context.DEVICE_POLICY_SERVICE);
|
|
||||||
mController = spy(new AllInOneTetherPreferenceController(mContext, /* key= */ "test"));
|
|
||||||
ReflectionHelpers.setField(mController, "mContext", mContext);
|
|
||||||
ReflectionHelpers.setField(mController, "mBluetoothAdapter", mBluetoothAdapter);
|
|
||||||
ReflectionHelpers.setField(mController, "mPreferenceKey", PREF_KEY);
|
|
||||||
PreferenceScreen screen = mock(PreferenceScreen.class);
|
|
||||||
when(screen.findPreference(PREF_KEY)).thenReturn(mPreference);
|
|
||||||
doReturn(mController.AVAILABLE).when(mController).getAvailabilityStatus();
|
|
||||||
mController.displayPreference(screen);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onCreate_shouldInitBluetoothPan() {
|
|
||||||
when(mBluetoothAdapter.getState()).thenReturn(BluetoothAdapter.STATE_ON);
|
|
||||||
mController.onCreate();
|
|
||||||
|
|
||||||
verify(mBluetoothAdapter).getState();
|
|
||||||
verify(mBluetoothAdapter).getProfileProxy(mContext, mController.mBtProfileServiceListener,
|
|
||||||
BluetoothProfile.PAN);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onCreate_shouldNotInitBluetoothPanWhenBluetoothOff() {
|
|
||||||
when(mBluetoothAdapter.getState()).thenReturn(BluetoothAdapter.STATE_OFF);
|
|
||||||
mController.onCreate();
|
|
||||||
|
|
||||||
verify(mBluetoothAdapter).getState();
|
|
||||||
verifyNoMoreInteractions(mBluetoothAdapter);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void goThroughLifecycle_shouldDestroyBluetoothProfile() {
|
|
||||||
final BluetoothPan pan = mock(BluetoothPan.class);
|
|
||||||
final AtomicReference<BluetoothPan> panRef =
|
|
||||||
ReflectionHelpers.getField(mController, "mBluetoothPan");
|
|
||||||
panRef.set(pan);
|
|
||||||
|
|
||||||
mController.onDestroy();
|
|
||||||
|
|
||||||
verify(mBluetoothAdapter).closeProfileProxy(BluetoothProfile.PAN, pan);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getSummary_afterTetherStateChanged() {
|
|
||||||
mController.onTetherStateUpdated(mTetherState);
|
|
||||||
assertThat(mController.getSummary()).isEqualTo(mContext.getString(mSummaryResId));
|
|
||||||
|
|
||||||
verify(mController).updateState(mPreference);
|
|
||||||
verify(mPreference).setSummary(mContext.getString(mSummaryResId));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,132 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2019 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.network;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
|
||||||
import static org.mockito.Mockito.spy;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.net.TetheringManager;
|
|
||||||
|
|
||||||
import androidx.preference.SwitchPreference;
|
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
import org.robolectric.RobolectricTestRunner;
|
|
||||||
import org.robolectric.util.ReflectionHelpers;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
|
||||||
public class BluetoothTetherPreferenceControllerTest {
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private TetheringManager mTetheringManager;
|
|
||||||
@Mock
|
|
||||||
private TetherEnabler mTetherEnabler;
|
|
||||||
|
|
||||||
private SwitchPreference mSwitchPreference;
|
|
||||||
private BluetoothTetherPreferenceController mController;
|
|
||||||
private Context mContext;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
|
|
||||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
|
||||||
mSwitchPreference = spy(SwitchPreference.class);
|
|
||||||
when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
|
|
||||||
when(mTetheringManager.getTetherableBluetoothRegexs()).thenReturn(new String[] {""});
|
|
||||||
mController = new BluetoothTetherPreferenceController(mContext, "BLUETOOTH");
|
|
||||||
mController.setTetherEnabler(mTetherEnabler);
|
|
||||||
ReflectionHelpers.setField(mController, "mPreference", mSwitchPreference);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void lifecycle_shouldRegisterReceiverOnStart() {
|
|
||||||
mController.onStart();
|
|
||||||
|
|
||||||
verify(mContext).registerReceiver(
|
|
||||||
eq(mController.mBluetoothChangeReceiver),
|
|
||||||
any());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void lifecycle_shouldAddListenerOnResume() {
|
|
||||||
mController.onResume();
|
|
||||||
verify(mTetherEnabler).addListener(mController);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void lifecycle_shouldRemoveListenrOnPause() {
|
|
||||||
mController.onPause();
|
|
||||||
verify(mTetherEnabler).removeListener(mController);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void lifecycle_shouldUnregisterReceiverOnStop() {
|
|
||||||
mController.onStart();
|
|
||||||
mController.onStop();
|
|
||||||
|
|
||||||
verify(mContext).unregisterReceiver(
|
|
||||||
eq(mController.mBluetoothChangeReceiver));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldShow_noBluetoothTetherable() {
|
|
||||||
when(mTetheringManager.getTetherableBluetoothRegexs()).thenReturn(new String[0]);
|
|
||||||
assertThat(mController.isAvailable()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldEnable_transientState() {
|
|
||||||
ReflectionHelpers.setField(mController, "mBluetoothState",
|
|
||||||
BluetoothAdapter.STATE_TURNING_OFF);
|
|
||||||
assertThat(mController.shouldEnable()).isFalse();
|
|
||||||
}
|
|
||||||
@Test
|
|
||||||
public void setChecked_shouldStartBluetoothTethering() {
|
|
||||||
mController.setChecked(true);
|
|
||||||
verify(mTetherEnabler).startTethering(TetheringManager.TETHERING_BLUETOOTH);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void setUnchecked_shouldStopBluetoothTethering() {
|
|
||||||
mController.setChecked(false);
|
|
||||||
verify(mTetherEnabler).stopTethering(TetheringManager.TETHERING_BLUETOOTH);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void switch_shouldCheckedWhenBluetoothTethering() {
|
|
||||||
mController.onTetherStateUpdated(TetherEnabler.TETHERING_BLUETOOTH_ON);
|
|
||||||
assertThat(mController.isChecked()).isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void switch_shouldUnCheckedWhenBluetoothNotTethering() {
|
|
||||||
mController.onTetherStateUpdated(TetherEnabler.TETHERING_OFF);
|
|
||||||
assertThat(mController.isChecked()).isFalse();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,143 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2020 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.network;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
|
||||||
import static org.mockito.Mockito.any;
|
|
||||||
import static org.mockito.Mockito.spy;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.net.EthernetManager;
|
|
||||||
import android.net.TetheringManager;
|
|
||||||
|
|
||||||
import androidx.preference.SwitchPreference;
|
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.junit.MockitoJUnit;
|
|
||||||
import org.mockito.junit.MockitoRule;
|
|
||||||
import org.robolectric.RobolectricTestRunner;
|
|
||||||
import org.robolectric.util.ReflectionHelpers;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
|
||||||
public class EthernetTetherPreferenceControllerTest {
|
|
||||||
|
|
||||||
@Rule
|
|
||||||
public MockitoRule mocks = MockitoJUnit.rule();
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private TetheringManager mTetheringManager;
|
|
||||||
@Mock
|
|
||||||
private EthernetManager mEthernetManager;
|
|
||||||
@Mock
|
|
||||||
private TetherEnabler mTetherEnabler;
|
|
||||||
|
|
||||||
private Context mContext;
|
|
||||||
private EthernetTetherPreferenceController mController;
|
|
||||||
private SwitchPreference mPreference;
|
|
||||||
private static final String ETHERNET_REGEX = "ethernet";
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
|
||||||
mPreference = spy(SwitchPreference.class);
|
|
||||||
when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
|
|
||||||
when(mTetheringManager.getTetherableIfaces()).thenReturn(new String[]{ETHERNET_REGEX});
|
|
||||||
when(mContext.getSystemService(EthernetManager.class)).thenReturn(mEthernetManager);
|
|
||||||
mController = new EthernetTetherPreferenceController(mContext, "ethernet");
|
|
||||||
mController.setTetherEnabler(mTetherEnabler);
|
|
||||||
ReflectionHelpers.setField(mController, "mPreference", mPreference);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Ignore
|
|
||||||
public void lifecycle_shouldRegisterReceiverOnStart() {
|
|
||||||
mController.onStart();
|
|
||||||
|
|
||||||
verify(mEthernetManager).addInterfaceStateListener(any(),
|
|
||||||
eq(mController.mEthernetListener));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void lifecycle_shouldAddListenerOnResume() {
|
|
||||||
mController.onResume();
|
|
||||||
verify(mTetherEnabler).addListener(mController);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void lifecycle_shouldRemoveListenerOnPause() {
|
|
||||||
mController.onPause();
|
|
||||||
verify(mTetherEnabler).removeListener(mController);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void lifecycle_shouldUnregisterReceiverOnStop() {
|
|
||||||
mController.onStart();
|
|
||||||
EthernetManager.InterfaceStateListener listener = mController.mEthernetListener;
|
|
||||||
mController.onStop();
|
|
||||||
|
|
||||||
verify(mEthernetManager).removeInterfaceStateListener(eq(listener));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldEnable_noTetherable() {
|
|
||||||
when(mTetheringManager.getTetherableIfaces()).thenReturn(new String[0]);
|
|
||||||
assertThat(mController.shouldEnable()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldShow_noEthernetInterface() {
|
|
||||||
when(mContext.getSystemService(EthernetManager.class)).thenReturn(null);
|
|
||||||
|
|
||||||
final EthernetTetherPreferenceController controller =
|
|
||||||
new EthernetTetherPreferenceController(mContext, "ethernet");
|
|
||||||
assertThat(controller.shouldShow()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void setChecked_shouldStartEthernetTethering() {
|
|
||||||
mController.setChecked(true);
|
|
||||||
verify(mTetherEnabler).startTethering(TetheringManager.TETHERING_ETHERNET);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void setUnchecked_shouldStopEthernetTethering() {
|
|
||||||
mController.setChecked(false);
|
|
||||||
verify(mTetherEnabler).stopTethering(TetheringManager.TETHERING_ETHERNET);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void switch_shouldCheckedWhenEthernetTethering() {
|
|
||||||
mController.onTetherStateUpdated(TetherEnabler.TETHERING_ETHERNET_ON);
|
|
||||||
assertThat(mController.isChecked()).isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void switch_shouldUnCheckedWhenEthernetNotTethering() {
|
|
||||||
mController.onTetherStateUpdated(TetherEnabler.TETHERING_OFF);
|
|
||||||
assertThat(mController.isChecked()).isFalse();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,128 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2019 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.network;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
|
||||||
import static org.mockito.Mockito.spy;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.net.TetheringManager;
|
|
||||||
|
|
||||||
import androidx.preference.SwitchPreference;
|
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
import org.robolectric.RobolectricTestRunner;
|
|
||||||
import org.robolectric.util.ReflectionHelpers;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
|
||||||
public class UsbTetherPreferenceControllerTest {
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private TetheringManager mTetheringManager;
|
|
||||||
@Mock
|
|
||||||
private TetherEnabler mTetherEnabler;
|
|
||||||
|
|
||||||
private Context mContext;
|
|
||||||
private UsbTetherPreferenceController mController;
|
|
||||||
private SwitchPreference mSwitchPreference;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
|
|
||||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
|
||||||
when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
|
|
||||||
when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(new String[]{""});
|
|
||||||
mController = new UsbTetherPreferenceController(mContext, "USB");
|
|
||||||
mController.setTetherEnabler(mTetherEnabler);
|
|
||||||
mSwitchPreference = spy(SwitchPreference.class);
|
|
||||||
ReflectionHelpers.setField(mController, "mPreference", mSwitchPreference);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void lifecycle_shouldRegisterReceiverOnStart() {
|
|
||||||
mController.onStart();
|
|
||||||
|
|
||||||
verify(mContext).registerReceiver(eq(mController.mUsbChangeReceiver), any());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void lifecycle_shouldAddListenerOnResume() {
|
|
||||||
mController.onResume();
|
|
||||||
verify(mTetherEnabler).addListener(mController);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void lifecycle_shouldRemoveListenrOnPause() {
|
|
||||||
mController.onPause();
|
|
||||||
verify(mTetherEnabler).removeListener(mController);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void lifecycle_shouldUnregisterReceiverOnStop() {
|
|
||||||
mController.onStart();
|
|
||||||
mController.onStop();
|
|
||||||
|
|
||||||
verify(mContext).unregisterReceiver(eq(mController.mUsbChangeReceiver));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldShow_noTetherableUsb() {
|
|
||||||
when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(new String[0]);
|
|
||||||
assertThat(mController.shouldShow()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldEnable_noUsbConnected() {
|
|
||||||
ReflectionHelpers.setField(mController, "mUsbConnected", false);
|
|
||||||
assertThat(mController.shouldEnable()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void setChecked_shouldStartUsbTethering() {
|
|
||||||
mController.setChecked(true);
|
|
||||||
verify(mTetherEnabler).startTethering(TetheringManager.TETHERING_USB);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void setUnchecked_shouldStopUsbTethering() {
|
|
||||||
mController.setChecked(false);
|
|
||||||
verify(mTetherEnabler).stopTethering(TetheringManager.TETHERING_USB);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void switch_shouldCheckedWhenUsbTethering() {
|
|
||||||
mController.onTetherStateUpdated(TetherEnabler.TETHERING_USB_ON);
|
|
||||||
assertThat(mController.isChecked()).isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void switch_shouldUnCheckedWhenUsbNotTethering() {
|
|
||||||
mController.onTetherStateUpdated(TetherEnabler.TETHERING_OFF);
|
|
||||||
assertThat(mController.isChecked()).isFalse();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,142 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2019 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.network;
|
|
||||||
|
|
||||||
import static com.android.settings.AllInOneTetherSettings.WIFI_TETHER_DISABLE_KEY;
|
|
||||||
import static com.android.settings.network.TetherEnabler.TETHERING_BLUETOOTH_ON;
|
|
||||||
import static com.android.settings.network.TetherEnabler.TETHERING_ETHERNET_ON;
|
|
||||||
import static com.android.settings.network.TetherEnabler.TETHERING_OFF;
|
|
||||||
import static com.android.settings.network.TetherEnabler.TETHERING_USB_ON;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import static org.mockito.Mockito.spy;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.net.TetheringManager;
|
|
||||||
|
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
import androidx.preference.SwitchPreference;
|
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
import org.robolectric.ParameterizedRobolectricTestRunner;
|
|
||||||
import org.robolectric.util.ReflectionHelpers;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RunWith(ParameterizedRobolectricTestRunner.class)
|
|
||||||
public class WifiTetherDisablePreferenceControllerTest {
|
|
||||||
|
|
||||||
@ParameterizedRobolectricTestRunner.Parameters(name = "TetherState: {0}")
|
|
||||||
public static List params() {
|
|
||||||
return Arrays.asList(new Object[][] {
|
|
||||||
{TETHERING_OFF, R.string.summary_placeholder},
|
|
||||||
{TETHERING_USB_ON, R.string.disable_wifi_hotspot_when_usb_on},
|
|
||||||
{TETHERING_BLUETOOTH_ON, R.string.disable_wifi_hotspot_when_bluetooth_on},
|
|
||||||
{TETHERING_ETHERNET_ON, R.string.disable_wifi_hotspot_when_ethernet_on},
|
|
||||||
{
|
|
||||||
TETHERING_USB_ON | TETHERING_BLUETOOTH_ON,
|
|
||||||
R.string.disable_wifi_hotspot_when_usb_and_bluetooth_on
|
|
||||||
},
|
|
||||||
{
|
|
||||||
TETHERING_USB_ON | TETHERING_ETHERNET_ON,
|
|
||||||
R.string.disable_wifi_hotspot_when_usb_and_ethernet_on
|
|
||||||
},
|
|
||||||
{
|
|
||||||
TETHERING_BLUETOOTH_ON | TETHERING_ETHERNET_ON,
|
|
||||||
R.string.disable_wifi_hotspot_when_bluetooth_and_ethernet_on
|
|
||||||
},
|
|
||||||
{
|
|
||||||
TETHERING_USB_ON | TETHERING_BLUETOOTH_ON | TETHERING_ETHERNET_ON,
|
|
||||||
R.string.disable_wifi_hotspot_when_usb_and_bluetooth_and_ethernet_on
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private TetheringManager mTetheringManager;
|
|
||||||
@Mock
|
|
||||||
private PreferenceScreen mPreferenceScreen;
|
|
||||||
@Mock
|
|
||||||
private TetherEnabler mTetherEnabler;
|
|
||||||
|
|
||||||
private SwitchPreference mPreference;
|
|
||||||
private Context mContext;
|
|
||||||
private WifiTetherDisablePreferenceController mController;
|
|
||||||
private final int mTetherState;
|
|
||||||
private final int mSummaryResId;
|
|
||||||
|
|
||||||
public WifiTetherDisablePreferenceControllerTest(int tetherState, int summaryResId) {
|
|
||||||
mTetherState = tetherState;
|
|
||||||
mSummaryResId = summaryResId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
|
|
||||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
|
||||||
mPreference = spy(SwitchPreference.class);
|
|
||||||
when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
|
|
||||||
when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{""});
|
|
||||||
mController = new WifiTetherDisablePreferenceController(mContext, WIFI_TETHER_DISABLE_KEY);
|
|
||||||
mController.setTetherEnabler(mTetherEnabler);
|
|
||||||
ReflectionHelpers.setField(mController, "mScreen", mPreferenceScreen);
|
|
||||||
ReflectionHelpers.setField(mController, "mPreference", mPreference);
|
|
||||||
when(mPreferenceScreen.findPreference(WIFI_TETHER_DISABLE_KEY)).thenReturn(mPreference);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldShow_noTetherableWifi() {
|
|
||||||
when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[0]);
|
|
||||||
assertThat(mController.shouldShow()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onTetherStateUpdated_visibilityChangeCorrectly() {
|
|
||||||
int state = TetherEnabler.TETHERING_BLUETOOTH_ON;
|
|
||||||
mController.onTetherStateUpdated(state);
|
|
||||||
assertThat(mController.shouldShow()).isTrue();
|
|
||||||
|
|
||||||
state |= TetherEnabler.TETHERING_USB_ON;
|
|
||||||
mController.onTetherStateUpdated(state);
|
|
||||||
assertThat(mController.shouldShow()).isTrue();
|
|
||||||
|
|
||||||
state = TetherEnabler.TETHERING_USB_ON;
|
|
||||||
mController.onTetherStateUpdated(state);
|
|
||||||
assertThat(mController.shouldShow()).isTrue();
|
|
||||||
|
|
||||||
state = TetherEnabler.TETHERING_OFF;
|
|
||||||
mController.onTetherStateUpdated(state);
|
|
||||||
assertThat(mController.shouldShow()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getSummary_onTetherStateUpdated() {
|
|
||||||
mController.onTetherStateUpdated(mTetherState);
|
|
||||||
assertThat(mController.getSummary()).isEqualTo(mContext.getString(mSummaryResId));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -48,7 +48,6 @@ import android.net.wifi.WifiManager;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.util.FeatureFlagUtils;
|
|
||||||
|
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
@@ -56,7 +55,6 @@ import androidx.preference.SwitchPreference;
|
|||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.RestrictedSettingsFragment;
|
import com.android.settings.RestrictedSettingsFragment;
|
||||||
import com.android.settings.core.FeatureFlags;
|
|
||||||
import com.android.settings.wifi.tether.WifiTetherPreferenceController;
|
import com.android.settings.wifi.tether.WifiTetherPreferenceController;
|
||||||
import com.android.settingslib.RestrictedSwitchPreference;
|
import com.android.settingslib.RestrictedSwitchPreference;
|
||||||
|
|
||||||
@@ -145,7 +143,6 @@ public class TetherSettingsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTetherNonIndexableKeys_tetherAvailable_keysNotReturned() {
|
public void testTetherNonIndexableKeys_tetherAvailable_keysNotReturned() {
|
||||||
FeatureFlagUtils.setEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE, false);
|
|
||||||
// To let TetherUtil.isTetherAvailable return true, select one of the combinations
|
// To let TetherUtil.isTetherAvailable return true, select one of the combinations
|
||||||
setupIsTetherAvailable(true);
|
setupIsTetherAvailable(true);
|
||||||
|
|
||||||
@@ -190,7 +187,6 @@ public class TetherSettingsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTetherNonIndexableKeys_usbAvailable_usbKeyNotReturned() {
|
public void testTetherNonIndexableKeys_usbAvailable_usbKeyNotReturned() {
|
||||||
FeatureFlagUtils.setEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE, false);
|
|
||||||
// We can ignore the condition of Utils.isMonkeyRunning()
|
// We can ignore the condition of Utils.isMonkeyRunning()
|
||||||
// In normal case, monkey and robotest should not execute at the same time
|
// In normal case, monkey and robotest should not execute at the same time
|
||||||
when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(new String[]{"fakeRegex"});
|
when(mTetheringManager.getTetherableUsbRegexs()).thenReturn(new String[]{"fakeRegex"});
|
||||||
@@ -213,7 +209,6 @@ public class TetherSettingsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTetherNonIndexableKeys_bluetoothAvailable_bluetoothKeyNotReturned() {
|
public void testTetherNonIndexableKeys_bluetoothAvailable_bluetoothKeyNotReturned() {
|
||||||
FeatureFlagUtils.setEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE, false);
|
|
||||||
when(mTetheringManager.getTetherableBluetoothRegexs())
|
when(mTetheringManager.getTetherableBluetoothRegexs())
|
||||||
.thenReturn(new String[]{"fakeRegex"});
|
.thenReturn(new String[]{"fakeRegex"});
|
||||||
|
|
||||||
|
|||||||
@@ -1,171 +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.tether;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
|
||||||
import static org.mockito.Mockito.spy;
|
|
||||||
import static org.mockito.Mockito.times;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.net.TetheringManager;
|
|
||||||
import android.net.wifi.SoftApConfiguration;
|
|
||||||
import android.net.wifi.WifiManager;
|
|
||||||
|
|
||||||
import androidx.preference.ListPreference;
|
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
import org.robolectric.RobolectricTestRunner;
|
|
||||||
import org.robolectric.RuntimeEnvironment;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
|
||||||
public class WifiTetherApBandPreferenceControllerTest {
|
|
||||||
|
|
||||||
private static final String ALL_BANDS = "5.0 GHz Band preferred";
|
|
||||||
private static final String TWO_GHZ_STRING = "2.4 GHz Band";
|
|
||||||
private static final String FIVE_GHZ_STRING = "5.0 GHz Band";
|
|
||||||
private static final String VAL_2GHZ_STR = "1";
|
|
||||||
private static final String VAL_5GHZ_STR = "2";
|
|
||||||
private static final String VAL_2_5_GHZ_STR = "3";
|
|
||||||
private static final int VAL_2GHZ_INT = 1;
|
|
||||||
private static final int VAL_5GHZ_INT = 2;
|
|
||||||
private static final int VAL_2_5_GHZ_INT = 3;
|
|
||||||
|
|
||||||
private Context mContext;
|
|
||||||
@Mock
|
|
||||||
private TetheringManager mTetheringManager;
|
|
||||||
@Mock
|
|
||||||
private WifiManager mWifiManager;
|
|
||||||
@Mock
|
|
||||||
private WifiTetherBasePreferenceController.OnTetherConfigUpdateListener mListener;
|
|
||||||
@Mock
|
|
||||||
private PreferenceScreen mScreen;
|
|
||||||
|
|
||||||
private WifiTetherApBandPreferenceController mController;
|
|
||||||
private ListPreference mPreference;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
mContext = spy(RuntimeEnvironment.application);
|
|
||||||
mPreference = new ListPreference(RuntimeEnvironment.application);
|
|
||||||
when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
|
|
||||||
when(mContext.getSystemService(Context.TETHERING_SERVICE)).thenReturn(mTetheringManager);
|
|
||||||
when(mTetheringManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"});
|
|
||||||
when(mContext.getResources()).thenReturn(RuntimeEnvironment.application.getResources());
|
|
||||||
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
|
|
||||||
when(mWifiManager.getSoftApConfiguration()).thenReturn(
|
|
||||||
new SoftApConfiguration.Builder().build());
|
|
||||||
|
|
||||||
mController = new WifiTetherApBandPreferenceController(mContext, mListener);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void display_5GhzSupported_shouldDisplayFullList() {
|
|
||||||
when(mWifiManager.getCountryCode()).thenReturn("US");
|
|
||||||
when(mWifiManager.is5GHzBandSupported()).thenReturn(true);
|
|
||||||
|
|
||||||
// Create a new instance
|
|
||||||
mController = new WifiTetherApBandPreferenceController(mContext, mListener);
|
|
||||||
|
|
||||||
mController.displayPreference(mScreen);
|
|
||||||
mController.onPreferenceChange(mPreference, VAL_2_5_GHZ_STR);
|
|
||||||
|
|
||||||
assertThat(mPreference.getSummary()).isEqualTo(ALL_BANDS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void display_noCountryCode_shouldDisable() {
|
|
||||||
when(mWifiManager.getCountryCode()).thenReturn(null);
|
|
||||||
when(mWifiManager.is5GHzBandSupported()).thenReturn(true);
|
|
||||||
|
|
||||||
mController.displayPreference(mScreen);
|
|
||||||
|
|
||||||
assertThat(mPreference.isEnabled()).isFalse();
|
|
||||||
assertThat(mPreference.getSummary())
|
|
||||||
.isEqualTo(RuntimeEnvironment.application.getString(R.string.wifi_ap_choose_2G));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void display_5GhzNotSupported_shouldDisable() {
|
|
||||||
when(mWifiManager.getCountryCode()).thenReturn("US");
|
|
||||||
when(mWifiManager.is5GHzBandSupported()).thenReturn(false);
|
|
||||||
|
|
||||||
mController.displayPreference(mScreen);
|
|
||||||
|
|
||||||
assertThat(mPreference.isEnabled()).isFalse();
|
|
||||||
assertThat(mPreference.getSummary())
|
|
||||||
.isEqualTo(RuntimeEnvironment.application.getString(R.string.wifi_ap_choose_2G));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void changePreference_With5G_shouldUpdateValue() {
|
|
||||||
when(mWifiManager.getCountryCode()).thenReturn("US");
|
|
||||||
when(mWifiManager.is5GHzBandSupported()).thenReturn(true);
|
|
||||||
|
|
||||||
// Create a new instance to pick the proper value of isDualModeSupported()
|
|
||||||
mController = new WifiTetherApBandPreferenceController(mContext, mListener);
|
|
||||||
|
|
||||||
mController.displayPreference(mScreen);
|
|
||||||
|
|
||||||
// 'Auto' option
|
|
||||||
mController.onPreferenceChange(mPreference, VAL_2_5_GHZ_STR);
|
|
||||||
assertThat(mController.getBandIndex()).isEqualTo(VAL_2_5_GHZ_INT);
|
|
||||||
assertThat(mPreference.getSummary()).isEqualTo(ALL_BANDS);
|
|
||||||
verify(mListener, times(1)).onTetherConfigUpdated(mController);
|
|
||||||
|
|
||||||
// should revert to the default for 5 Ghz only since this is not supported with this config
|
|
||||||
mController.onPreferenceChange(mPreference, VAL_5GHZ_STR);
|
|
||||||
assertThat(mController.getBandIndex()).isEqualTo(VAL_2_5_GHZ_INT);
|
|
||||||
assertThat(mPreference.getSummary()).isEqualTo(ALL_BANDS);
|
|
||||||
verify(mListener, times(2)).onTetherConfigUpdated(mController);
|
|
||||||
|
|
||||||
// set to 2 Ghz
|
|
||||||
mController.onPreferenceChange(mPreference, VAL_2GHZ_STR);
|
|
||||||
assertThat(mController.getBandIndex()).isEqualTo(VAL_2GHZ_INT);
|
|
||||||
assertThat(mPreference.getSummary()).isEqualTo(TWO_GHZ_STRING);
|
|
||||||
verify(mListener, times(3)).onTetherConfigUpdated(mController);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updateDisplay_shouldUpdateValue() {
|
|
||||||
when(mWifiManager.getCountryCode()).thenReturn("US");
|
|
||||||
when(mWifiManager.is5GHzBandSupported()).thenReturn(true);
|
|
||||||
|
|
||||||
// Set controller band index to 5GHz and verify is set.
|
|
||||||
mController.displayPreference(mScreen);
|
|
||||||
mController.onPreferenceChange(mPreference, VAL_5GHZ_STR);
|
|
||||||
assertThat(mController.getBandIndex()).isEqualTo(VAL_2_5_GHZ_INT);
|
|
||||||
|
|
||||||
// Disable 5Ghz band
|
|
||||||
when(mWifiManager.is5GHzBandSupported()).thenReturn(false);
|
|
||||||
|
|
||||||
// Call updateDisplay and verify it's changed.
|
|
||||||
mController.updateDisplay();
|
|
||||||
assertThat(mController.getBandIndex()).isEqualTo(VAL_2GHZ_INT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -49,7 +49,6 @@ import android.net.wifi.SoftApConfiguration;
|
|||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.util.FeatureFlagUtils;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
@@ -60,7 +59,6 @@ import androidx.preference.PreferenceScreen;
|
|||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.FeatureFlags;
|
|
||||||
import com.android.settings.dashboard.RestrictedDashboardFragment;
|
import com.android.settings.dashboard.RestrictedDashboardFragment;
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
import com.android.settings.testutils.shadow.ShadowFragment;
|
import com.android.settings.testutils.shadow.ShadowFragment;
|
||||||
@@ -144,7 +142,6 @@ public class WifiTetherSettingsTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
FeatureFlagUtils.setEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE, false);
|
|
||||||
setCanShowWifiHotspotCached(true);
|
setCanShowWifiHotspotCached(true);
|
||||||
doReturn(mWifiManager).when(mContext).getSystemService(WifiManager.class);
|
doReturn(mWifiManager).when(mContext).getSystemService(WifiManager.class);
|
||||||
doReturn(mConnectivityManager)
|
doReturn(mConnectivityManager)
|
||||||
|
|||||||
Reference in New Issue
Block a user