Show restricted message in Wi-Fi hotspot settings
- Remove Wi-Fi hotspot preferences in settings search if Wi-Fi hotspot is disallowed - See the result screenshot in b/203168953#comment12 Bug: 203168953 Test: manual test make RunSettingsRoboTests ROBOTEST_FILTER=WifiTetherSettingsTest Change-Id: Id4416fd0659b596e4e6f31890a139198219f4552
This commit is contained in:
@@ -30,6 +30,7 @@ import android.os.UserManager;
|
||||
import android.util.FeatureFlagUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settings.R;
|
||||
@@ -41,6 +42,7 @@ import com.android.settings.widget.SettingsMainSwitchBar;
|
||||
import com.android.settingslib.TetherUtil;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
import com.android.settingslib.wifi.WifiEnterpriseRestrictionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -56,6 +58,8 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
|
||||
@VisibleForTesting
|
||||
static final String KEY_WIFI_TETHER_NETWORK_NAME = "wifi_tether_network_name";
|
||||
@VisibleForTesting
|
||||
static final String KEY_WIFI_TETHER_SECURITY = "wifi_tether_security";
|
||||
@VisibleForTesting
|
||||
static final String KEY_WIFI_TETHER_NETWORK_PASSWORD = "wifi_tether_network_password";
|
||||
@VisibleForTesting
|
||||
static final String KEY_WIFI_TETHER_AUTO_OFF = "wifi_tether_auto_turn_off";
|
||||
@@ -72,7 +76,7 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
|
||||
private WifiManager mWifiManager;
|
||||
private boolean mRestartWifiApAfterConfigChange;
|
||||
private boolean mUnavailable;
|
||||
|
||||
private WifiRestriction mWifiRestriction;
|
||||
@VisibleForTesting
|
||||
TetherChangeReceiver mTetherChangeReceiver;
|
||||
|
||||
@@ -82,6 +86,12 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
|
||||
|
||||
public WifiTetherSettings() {
|
||||
super(UserManager.DISALLOW_CONFIG_TETHERING);
|
||||
mWifiRestriction = new WifiRestriction();
|
||||
}
|
||||
|
||||
public WifiTetherSettings(WifiRestriction wifiRestriction) {
|
||||
super(UserManager.DISALLOW_CONFIG_TETHERING);
|
||||
mWifiRestriction = wifiRestriction;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -98,9 +108,7 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
setIfOnlyAvailableForAdmins(true);
|
||||
if (isUiRestricted()) {
|
||||
mUnavailable = true;
|
||||
}
|
||||
mUnavailable = isUiRestricted() || !mWifiRestriction.isHotspotAvailable(getContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -135,6 +143,11 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
if (!mWifiRestriction.isHotspotAvailable(getContext())) {
|
||||
getEmptyTextView().setText(R.string.not_allowed_by_ent);
|
||||
getPreferenceScreen().removeAll();
|
||||
return;
|
||||
}
|
||||
if (mUnavailable) {
|
||||
if (!isUiRestrictedByOnlyAdmin()) {
|
||||
getEmptyTextView().setText(R.string.tethering_settings_not_available);
|
||||
@@ -228,36 +241,67 @@ public class WifiTetherSettings extends RestrictedDashboardFragment
|
||||
use(WifiTetherMaximizeCompatibilityPreferenceController.class).updateDisplay();
|
||||
}
|
||||
|
||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider(R.xml.wifi_tether_settings) {
|
||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new SearchIndexProvider(R.xml.wifi_tether_settings);
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
final List<String> keys = super.getNonIndexableKeys(context);
|
||||
@VisibleForTesting
|
||||
static class SearchIndexProvider extends BaseSearchIndexProvider {
|
||||
|
||||
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_MAXIMIZE_COMPATIBILITY);
|
||||
}
|
||||
private final WifiRestriction mWifiRestriction;
|
||||
|
||||
// Remove duplicate
|
||||
keys.add(KEY_WIFI_TETHER_SCREEN);
|
||||
return keys;
|
||||
}
|
||||
SearchIndexProvider(int xmlRes) {
|
||||
super(xmlRes);
|
||||
mWifiRestriction = new WifiRestriction();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isPageSearchEnabled(Context context) {
|
||||
return !FeatureFlagUtils.isEnabled(context, FeatureFlags.TETHER_ALL_IN_ONE);
|
||||
}
|
||||
@VisibleForTesting
|
||||
SearchIndexProvider(int xmlRes, WifiRestriction wifiRestriction) {
|
||||
super(xmlRes);
|
||||
mWifiRestriction = wifiRestriction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AbstractPreferenceController> createPreferenceControllers(
|
||||
Context context) {
|
||||
return buildPreferenceControllers(context, null /* listener */);
|
||||
}
|
||||
};
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
final List<String> keys = super.getNonIndexableKeys(context);
|
||||
|
||||
if (!mWifiRestriction.isTetherAvailable(context)
|
||||
|| !mWifiRestriction.isHotspotAvailable(context)) {
|
||||
keys.add(KEY_WIFI_TETHER_NETWORK_NAME);
|
||||
keys.add(KEY_WIFI_TETHER_SECURITY);
|
||||
keys.add(KEY_WIFI_TETHER_NETWORK_PASSWORD);
|
||||
keys.add(KEY_WIFI_TETHER_AUTO_OFF);
|
||||
keys.add(KEY_WIFI_TETHER_MAXIMIZE_COMPATIBILITY);
|
||||
}
|
||||
|
||||
// Remove duplicate
|
||||
keys.add(KEY_WIFI_TETHER_SCREEN);
|
||||
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 */);
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static class WifiRestriction {
|
||||
public boolean isTetherAvailable(@Nullable Context context) {
|
||||
if (context == null) return true;
|
||||
return TetherUtil.isTetherAvailable(context);
|
||||
}
|
||||
|
||||
public boolean isHotspotAvailable(@Nullable Context context) {
|
||||
if (context == null) return true;
|
||||
return WifiEnterpriseRestrictionUtils.isWifiTetheringAllowed(context);
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
class TetherChangeReceiver extends BroadcastReceiver {
|
||||
|
Reference in New Issue
Block a user