Added "Speed and Compatibility" Settings page
- Show each band option individually in single-band devices
- Show "2.4 and 5GHz" combined option in dual-band devices
- Disable 5 GHz option if the device is in the restricted country
- Disable 6 GHz option if the device is in the restricted country
- Hide 6 GHz option if the old device does not support 6 GHz band.
Bug: 245258763
Test: manual test
atest -c WifiHotspotSpeedSettingsTest
atest -c WifiHotspotSpeedViewModelTest \
WifiHotspotRepositoryTest
Change-Id: I358d4ff8d62df72fd5080e55f40d588c238d01fb
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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.wifi.repository.WifiHotspotRepository.SPEED_2GHZ;
|
||||
import static com.android.settings.wifi.repository.WifiHotspotRepository.SPEED_2GHZ_5GHZ;
|
||||
import static com.android.settings.wifi.repository.WifiHotspotRepository.SPEED_5GHZ;
|
||||
import static com.android.settings.wifi.repository.WifiHotspotRepository.SPEED_6GHZ;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.widget.SelectorWithWidgetPreference;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Wi-Fi Hotspot Speed & compatibility Settings
|
||||
*/
|
||||
public class WifiHotspotSpeedSettings extends DashboardFragment implements
|
||||
SelectorWithWidgetPreference.OnClickListener {
|
||||
|
||||
private static final String TAG = "WifiHotspotSpeedSettings";
|
||||
|
||||
protected static final String KEY_SPEED_2GHZ = "wifi_hotspot_speed_2g";
|
||||
protected static final String KEY_SPEED_5GHZ = "wifi_hotspot_speed_5g";
|
||||
protected static final String KEY_SPEED_2GHZ_5GHZ = "wifi_hotspot_speed_2g_5g";
|
||||
protected static final String KEY_SPEED_6GHZ = "wifi_hotspot_speed_6g";
|
||||
protected static Map<String, Integer> sSpeedKeyMap = new HashMap<>();
|
||||
|
||||
static {
|
||||
sSpeedKeyMap.put(KEY_SPEED_2GHZ, SPEED_2GHZ);
|
||||
sSpeedKeyMap.put(KEY_SPEED_5GHZ, SPEED_5GHZ);
|
||||
sSpeedKeyMap.put(KEY_SPEED_2GHZ_5GHZ, SPEED_2GHZ_5GHZ);
|
||||
sSpeedKeyMap.put(KEY_SPEED_6GHZ, SPEED_6GHZ);
|
||||
}
|
||||
|
||||
protected WifiHotspotSpeedViewModel mWifiHotspotSpeedViewModel;
|
||||
protected Map<Integer, SelectorWithWidgetPreference> mSpeedPreferenceMap = new HashMap<>();
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.wifi_hotspot_speed;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLogTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return SettingsEnums.WIFI_TETHER_SETTINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
loadPreferences();
|
||||
mWifiHotspotSpeedViewModel = FeatureFactory.getFactory(getContext())
|
||||
.getWifiFeatureProvider().getWifiHotspotSpeedViewModel(this);
|
||||
onSpeedInfoMapDataChanged(mWifiHotspotSpeedViewModel.getSpeedInfoMapData().getValue());
|
||||
mWifiHotspotSpeedViewModel.getSpeedInfoMapData()
|
||||
.observe(this, this::onSpeedInfoMapDataChanged);
|
||||
}
|
||||
|
||||
protected void loadPreferences() {
|
||||
for (Map.Entry<String, Integer> entry : sSpeedKeyMap.entrySet()) {
|
||||
SelectorWithWidgetPreference preference = findPreference(entry.getKey());
|
||||
if (preference != null) {
|
||||
preference.setOnClickListener(this);
|
||||
mSpeedPreferenceMap.put(entry.getValue(), preference);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void onSpeedInfoMapDataChanged(
|
||||
Map<Integer, WifiHotspotSpeedViewModel.SpeedInfo> speedInfoMap) {
|
||||
log("onSpeedViewDataChanged(), speedInfoMap:" + speedInfoMap);
|
||||
for (Map.Entry<Integer, SelectorWithWidgetPreference> entry :
|
||||
mSpeedPreferenceMap.entrySet()) {
|
||||
WifiHotspotSpeedViewModel.SpeedInfo speedInfo = speedInfoMap.get(entry.getKey());
|
||||
if (speedInfo == null) {
|
||||
continue;
|
||||
}
|
||||
SelectorWithWidgetPreference radioButton = entry.getValue();
|
||||
if (radioButton == null) {
|
||||
continue;
|
||||
}
|
||||
if (radioButton.isChecked() != speedInfo.mIsChecked) {
|
||||
radioButton.setChecked(speedInfo.mIsChecked);
|
||||
}
|
||||
if (radioButton.isEnabled() != speedInfo.mIsEnabled) {
|
||||
radioButton.setEnabled(speedInfo.mIsEnabled);
|
||||
}
|
||||
if (radioButton.isVisible() != speedInfo.mIsVisible) {
|
||||
radioButton.setVisible(speedInfo.mIsVisible);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRadioButtonClicked(SelectorWithWidgetPreference emiter) {
|
||||
String key = emiter.getKey();
|
||||
log("onRadioButtonClicked(), key:" + key);
|
||||
if (sSpeedKeyMap.containsKey(key)) {
|
||||
mWifiHotspotSpeedViewModel.setSpeedType(sSpeedKeyMap.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
private void log(String msg) {
|
||||
FeatureFactory.getFactory(getContext()).getWifiFeatureProvider().verboseLog(TAG, msg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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.wifi.repository.WifiHotspotRepository.SPEED_2GHZ;
|
||||
import static com.android.settings.wifi.repository.WifiHotspotRepository.SPEED_2GHZ_5GHZ;
|
||||
import static com.android.settings.wifi.repository.WifiHotspotRepository.SPEED_5GHZ;
|
||||
import static com.android.settings.wifi.repository.WifiHotspotRepository.SPEED_6GHZ;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.Observer;
|
||||
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.wifi.repository.WifiHotspotRepository;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Wi-Fi Hotspot Speed View Model
|
||||
*/
|
||||
public class WifiHotspotSpeedViewModel extends AndroidViewModel {
|
||||
private static final String TAG = "WifiHotspotSpeedViewModel";
|
||||
|
||||
protected final WifiHotspotRepository mWifiHotspotRepository;
|
||||
protected Map<Integer, SpeedInfo> mSpeedInfoMap = new HashMap<>();
|
||||
protected MutableLiveData<Map<Integer, SpeedInfo>> mSpeedInfoMapData;
|
||||
protected SpeedInfo mSpeedInfo2g = new SpeedInfo(false, true, false);
|
||||
protected SpeedInfo mSpeedInfo5g = new SpeedInfo(false, true, false);
|
||||
protected SpeedInfo mSpeedInfo2g5g = new SpeedInfo(false, true, true);
|
||||
protected SpeedInfo mSpeedInfo6g = new SpeedInfo(false, true, true);
|
||||
|
||||
protected final Observer<Boolean> m6gAvailableObserver = a -> on6gAvailableChanged(a);
|
||||
protected final Observer<Boolean> m5gAvailableObserver = a -> on5gAvailableChanged(a);
|
||||
protected final Observer<Integer> mSpeedTypeObserver = st -> onSpeedTypeChanged(st);
|
||||
|
||||
public WifiHotspotSpeedViewModel(@NotNull Application application) {
|
||||
super(application);
|
||||
mWifiHotspotRepository = FeatureFactory.getFactory(application).getWifiFeatureProvider()
|
||||
.getWifiHotspotRepository();
|
||||
mWifiHotspotRepository.get6gAvailable().observeForever(m6gAvailableObserver);
|
||||
mWifiHotspotRepository.get5gAvailable().observeForever(m5gAvailableObserver);
|
||||
mWifiHotspotRepository.getSpeedType().observeForever(mSpeedTypeObserver);
|
||||
mWifiHotspotRepository.setAutoRefresh(true);
|
||||
|
||||
// The visibility of the 6 GHz speed option will not change on a Pixel device.
|
||||
mSpeedInfo6g.mIsVisible = mWifiHotspotRepository.is6GHzBandSupported();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCleared() {
|
||||
mWifiHotspotRepository.get6gAvailable().removeObserver(m6gAvailableObserver);
|
||||
mWifiHotspotRepository.get5gAvailable().removeObserver(m5gAvailableObserver);
|
||||
mWifiHotspotRepository.getSpeedType().removeObserver(mSpeedTypeObserver);
|
||||
}
|
||||
|
||||
protected void on6gAvailableChanged(Boolean available) {
|
||||
log("on6gAvailableChanged(), available:" + available);
|
||||
mSpeedInfo6g.mIsEnabled = available;
|
||||
updateSpeedInfoMapData();
|
||||
}
|
||||
|
||||
protected void on5gAvailableChanged(Boolean available) {
|
||||
log("on5gAvailableChanged(), available:" + available);
|
||||
mSpeedInfo5g.mIsEnabled = available;
|
||||
|
||||
boolean showDualBand = mWifiHotspotRepository.isDualBand() && available;
|
||||
log("on5gAvailableChanged(), showDualBand:" + showDualBand);
|
||||
mSpeedInfo2g5g.mIsVisible = showDualBand;
|
||||
mSpeedInfo2g.mIsVisible = !showDualBand;
|
||||
mSpeedInfo5g.mIsVisible = !showDualBand;
|
||||
updateSpeedInfoMapData();
|
||||
}
|
||||
|
||||
protected void onSpeedTypeChanged(Integer speedType) {
|
||||
log("onSpeedTypeChanged(), speedType:" + speedType);
|
||||
mSpeedInfo2g.mIsChecked = speedType.equals(SPEED_2GHZ);
|
||||
mSpeedInfo5g.mIsChecked = speedType.equals(SPEED_5GHZ);
|
||||
mSpeedInfo2g5g.mIsChecked = speedType.equals(SPEED_2GHZ_5GHZ);
|
||||
mSpeedInfo6g.mIsChecked = speedType.equals(SPEED_6GHZ);
|
||||
updateSpeedInfoMapData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets SpeedType
|
||||
*/
|
||||
public void setSpeedType(Integer speedType) {
|
||||
mWifiHotspotRepository.setSpeedType(speedType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets Speed Information LiveData
|
||||
*/
|
||||
public LiveData<Map<Integer, SpeedInfo>> getSpeedInfoMapData() {
|
||||
if (mSpeedInfoMapData == null) {
|
||||
mSpeedInfoMapData = new MutableLiveData<>();
|
||||
mSpeedInfoMapData.setValue(mSpeedInfoMap);
|
||||
log("getSpeedViewData(), mSpeedInfoMap:" + mSpeedInfoMapData.getValue());
|
||||
}
|
||||
return mSpeedInfoMapData;
|
||||
}
|
||||
|
||||
protected void updateSpeedInfoMapData() {
|
||||
mSpeedInfoMap.put(SPEED_2GHZ, mSpeedInfo2g);
|
||||
mSpeedInfoMap.put(SPEED_5GHZ, mSpeedInfo5g);
|
||||
mSpeedInfoMap.put(SPEED_2GHZ_5GHZ, mSpeedInfo2g5g);
|
||||
mSpeedInfoMap.put(SPEED_6GHZ, mSpeedInfo6g);
|
||||
if (mSpeedInfoMapData != null) {
|
||||
mSpeedInfoMapData.setValue(mSpeedInfoMap);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wi-Fi Hotspot Speed Information
|
||||
*/
|
||||
public static final class SpeedInfo {
|
||||
Boolean mIsChecked;
|
||||
boolean mIsEnabled;
|
||||
boolean mIsVisible;
|
||||
|
||||
public SpeedInfo(boolean isChecked, boolean isEnabled, boolean isVisible) {
|
||||
this.mIsChecked = isChecked;
|
||||
this.mIsEnabled = isEnabled;
|
||||
this.mIsVisible = isVisible;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringBuilder("SpeedInfo{")
|
||||
.append("isChecked:").append(mIsChecked)
|
||||
.append(",isEnabled:").append(mIsEnabled)
|
||||
.append(",isVisible:").append(mIsVisible)
|
||||
.append('}').toString();
|
||||
}
|
||||
}
|
||||
|
||||
private void log(String msg) {
|
||||
FeatureFactory.getFactory(getApplication()).getWifiFeatureProvider().verboseLog(TAG, msg);
|
||||
}
|
||||
}
|
||||
@@ -46,13 +46,12 @@ public class WifiTetherViewModel extends AndroidViewModel {
|
||||
private static final String TAG = "WifiTetherViewModel";
|
||||
|
||||
protected static Map<Integer, Integer> sSpeedSummaryResMap = new HashMap<>();
|
||||
|
||||
static {
|
||||
sSpeedSummaryResMap.put(SPEED_UNKNOWN, R.string.summary_placeholder);
|
||||
sSpeedSummaryResMap.put(SPEED_2GHZ, R.string.wifi_hotspot_speed_2g_summary);
|
||||
sSpeedSummaryResMap.put(SPEED_5GHZ, R.string.wifi_hotspot_speed_5g_summary);
|
||||
sSpeedSummaryResMap.put(SPEED_6GHZ, R.string.wifi_hotspot_speed_6g_summary);
|
||||
sSpeedSummaryResMap.put(SPEED_2GHZ_5GHZ, R.string.wifi_hotspot_speed_2g_and_5g_summary);
|
||||
sSpeedSummaryResMap.put(SPEED_2GHZ, R.string.wifi_hotspot_speed_summary_2g);
|
||||
sSpeedSummaryResMap.put(SPEED_5GHZ, R.string.wifi_hotspot_speed_summary_5g);
|
||||
sSpeedSummaryResMap.put(SPEED_6GHZ, R.string.wifi_hotspot_speed_summary_6g);
|
||||
sSpeedSummaryResMap.put(SPEED_2GHZ_5GHZ, R.string.wifi_hotspot_speed_summary_2g_and_5g);
|
||||
}
|
||||
|
||||
protected final WifiHotspotRepository mWifiHotspotRepository;
|
||||
|
||||
Reference in New Issue
Block a user