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:
Chaohui Wang
2023-11-30 12:03:51 +08:00
parent f04ee0dfab
commit 0664d3cc45
29 changed files with 8 additions and 2774 deletions

View File

@@ -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*/);
}
};
}

View File

@@ -19,18 +19,15 @@ package com.android.settings;
import static android.provider.Settings.ACTION_PRIVACY_SETTINGS;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.ims.ImsRcsManager;
import android.text.TextUtils;
import android.util.FeatureFlagUtils;
import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.biometrics.face.FaceSettings;
import com.android.settings.communal.CommunalPreferenceController;
import com.android.settings.core.FeatureFlags;
import com.android.settings.enterprise.EnterprisePrivacySettings;
import com.android.settings.network.MobileNetworkIntentConverter;
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 CombinedBiometricSettingsActivity extends SettingsActivity { /* empty */ }
public static class CombinedBiometricProfileSettingsActivity extends SettingsActivity { /* empty */ }
public static class TetherSettingsActivity 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());
}
}
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 TetherSettingsActivity extends SettingsActivity { /* empty */ }
public static class WifiTetherSettingsActivity extends SettingsActivity { /* empty */ }
public static class VpnSettingsActivity extends SettingsActivity { /* empty */ }
/** Activity for Data saver settings. */

View File

@@ -16,7 +16,6 @@
package com.android.settings.core.gateway;
import com.android.settings.AllInOneTetherSettings;
import com.android.settings.DisplaySettings;
import com.android.settings.IccLockSettings;
import com.android.settings.MainClear;
@@ -205,7 +204,6 @@ public class SettingsGateway {
WifiNetworkDetailsFragment.class.getName(),
ConfigureWifiSettings.class.getName(),
SavedAccessPointsWifiSettings2.class.getName(),
AllInOneTetherSettings.class.getName(),
TetherSettings.class.getName(),
SmartAutoRotatePreferenceFragment.class.getName(),
WifiP2pSettings.class.getName(),

View File

@@ -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;
}
}
}
}
}

View File

@@ -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);
}
}
};
}

View File

@@ -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;
}
}

View File

@@ -18,7 +18,6 @@ package com.android.settings.network;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import androidx.lifecycle.LifecycleOwner;
@@ -60,13 +59,6 @@ public class NetworkDashboardFragment extends DashboardFragment implements
super.onAttach(context);
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

View File

@@ -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();
}

View File

@@ -20,7 +20,6 @@ import android.content.Context
import android.net.TetheringManager
import android.os.UserHandle
import android.os.UserManager
import android.util.FeatureFlagUtils
import androidx.annotation.StringRes
import androidx.annotation.VisibleForTesting
import androidx.lifecycle.Lifecycle
@@ -31,7 +30,6 @@ import androidx.preference.Preference
import androidx.preference.PreferenceScreen
import com.android.settings.R
import com.android.settings.core.BasePreferenceController
import com.android.settings.core.FeatureFlags
import com.android.settingslib.RestrictedLockUtilsInternal
import com.android.settingslib.TetherUtil
import com.android.settingslib.Utils
@@ -49,13 +47,7 @@ class TetherPreferenceController(context: Context, key: String) :
private var preference: Preference? = null
override fun getAvailabilityStatus() =
if (TetherUtil.isTetherAvailable(mContext)
&& !FeatureFlagUtils.isEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE)
) {
AVAILABLE
} else {
CONDITIONALLY_UNAVAILABLE
}
if (TetherUtil.isTetherAvailable(mContext)) AVAILABLE else CONDITIONALLY_UNAVAILABLE
override fun displayPreference(screen: PreferenceScreen) {
super.displayPreference(screen)

View File

@@ -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);
}
};
}

View File

@@ -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);
}
}

View File

@@ -45,7 +45,6 @@ import android.os.UserHandle;
import android.os.UserManager;
import android.provider.SearchIndexableResource;
import android.text.TextUtils;
import android.util.FeatureFlagUtils;
import android.util.Log;
import androidx.annotation.NonNull;
@@ -57,7 +56,6 @@ import androidx.preference.TwoStatePreference;
import com.android.settings.R;
import com.android.settings.RestrictedSettingsFragment;
import com.android.settings.Utils;
import com.android.settings.core.FeatureFlags;
import com.android.settings.datausage.DataSaverBackend;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.wifi.tether.WifiTetherPreferenceController;
@@ -629,11 +627,6 @@ public class TetherSettings extends RestrictedSettingsFragment
return Arrays.asList(sir);
}
@Override
protected boolean isPageSearchEnabled(Context context) {
return !FeatureFlagUtils.isEnabled(context, FeatureFlags.TETHER_ALL_IN_ONE);
}
@Override
public List<String> getNonIndexableKeys(Context context) {
final List<String> keys = super.getNonIndexableKeys(context);

View File

@@ -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;
}
}

View File

@@ -16,20 +16,16 @@
package com.android.settings.wifi.tether;
import static com.android.settings.AllInOneTetherSettings.DEDUP_POSTFIX;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.net.wifi.SoftApConfiguration;
import android.text.TextUtils;
import android.util.FeatureFlagUtils;
import androidx.annotation.VisibleForTesting;
import androidx.preference.EditTextPreference;
import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.core.FeatureFlags;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.widget.ValidatedEditTextPreference;
import com.android.settings.wifi.WifiUtils;
@@ -68,8 +64,7 @@ public class WifiTetherPasswordPreferenceController extends WifiTetherBasePrefer
@Override
public String getPreferenceKey() {
return FeatureFlagUtils.isEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE)
? PREF_KEY + DEDUP_POSTFIX : PREF_KEY;
return PREF_KEY;
}
@Override

View File

@@ -16,21 +16,17 @@
package com.android.settings.wifi.tether;
import static com.android.settings.AllInOneTetherSettings.DEDUP_POSTFIX;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.Intent;
import android.net.wifi.SoftApConfiguration;
import android.text.TextUtils;
import android.util.FeatureFlagUtils;
import android.util.Log;
import androidx.annotation.VisibleForTesting;
import androidx.preference.EditTextPreference;
import androidx.preference.Preference;
import com.android.settings.core.FeatureFlags;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.widget.ValidatedEditTextPreference;
import com.android.settings.wifi.dpp.WifiDppUtils;
@@ -68,8 +64,7 @@ public class WifiTetherSSIDPreferenceController extends WifiTetherBasePreference
@Override
public String getPreferenceKey() {
return FeatureFlagUtils.isEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE)
? PREF_KEY + DEDUP_POSTFIX : PREF_KEY;
return PREF_KEY;
}
@Override

View File

@@ -16,14 +16,11 @@
package com.android.settings.wifi.tether;
import static com.android.settings.AllInOneTetherSettings.DEDUP_POSTFIX;
import android.annotation.NonNull;
import android.content.Context;
import android.net.wifi.SoftApCapability;
import android.net.wifi.SoftApConfiguration;
import android.net.wifi.WifiManager;
import android.util.FeatureFlagUtils;
import android.util.Log;
import androidx.annotation.VisibleForTesting;
@@ -31,7 +28,6 @@ import androidx.preference.ListPreference;
import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.core.FeatureFlags;
import com.android.settings.overlay.FeatureFactory;
import java.util.LinkedHashMap;
@@ -82,8 +78,7 @@ public class WifiTetherSecurityPreferenceController extends WifiTetherBasePrefer
@Override
public String getPreferenceKey() {
return FeatureFlagUtils.isEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE)
? PREF_KEY + DEDUP_POSTFIX : PREF_KEY;
return PREF_KEY;
}
@Override

View File

@@ -30,7 +30,6 @@ import android.content.IntentFilter;
import android.net.wifi.SoftApConfiguration;
import android.os.Bundle;
import android.os.UserManager;
import android.util.FeatureFlagUtils;
import android.util.Log;
import androidx.annotation.Nullable;
@@ -39,7 +38,6 @@ import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.core.FeatureFlags;
import com.android.settings.dashboard.RestrictedDashboardFragment;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
@@ -387,10 +385,7 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
if (userManager == null || !userManager.isAdminUser()) {
return false;
}
if (!WifiUtils.canShowWifiHotspot(context)) {
return false;
}
return !FeatureFlagUtils.isEnabled(context, FeatureFlags.TETHER_ALL_IN_ONE);
return WifiUtils.canShowWifiHotspot(context);
}
@Override