Add config for Wi-Fi Hotspot Settings hidden
- Add config_show_wifi_hotspot_settings for Settings customization
- Hide Wi-Fi Hotspot preference in Hotspot & tethering Settings
- Don't launch Wi-Fi Hotspot Settings (e.g long press on Hotspot in QS-tile)
Bug: 213426762
Test: manual test
atest -c com.android.settings.wifi.WifiUtilsTest
make RunSettingsRoboTests ROBOTEST_FILTER=WifiTetherPreferenceControllerTest
make RunSettingsRoboTests ROBOTEST_FILTER=WifiTetherSettingsTest
Merged-In: I11f88d0d15d6d5c2766b64b5847ac31ed0f34c25
Change-Id: I11f88d0d15d6d5c2766b64b5847ac31ed0f34c25
(cherry picked from commit 160b5078ed
)
This commit is contained in:
@@ -22,14 +22,20 @@ import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.TetheringManager;
|
||||
import android.net.wifi.ScanResult;
|
||||
import android.net.wifi.SoftApConfiguration;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.wifitrackerlib.WifiEntry;
|
||||
|
||||
@@ -38,12 +44,16 @@ import java.nio.charset.StandardCharsets;
|
||||
/** A utility class for Wi-Fi functions. */
|
||||
public class WifiUtils extends com.android.settingslib.wifi.WifiUtils {
|
||||
|
||||
static final String TAG = "WifiUtils";
|
||||
|
||||
private static final int SSID_ASCII_MIN_LENGTH = 1;
|
||||
private static final int SSID_ASCII_MAX_LENGTH = 32;
|
||||
|
||||
private static final int PSK_PASSPHRASE_ASCII_MIN_LENGTH = 8;
|
||||
private static final int PSK_PASSPHRASE_ASCII_MAX_LENGTH = 63;
|
||||
|
||||
private static Boolean sCanShowWifiHotspotCached;
|
||||
|
||||
public static boolean isSSIDTooLong(String ssid) {
|
||||
if (TextUtils.isEmpty(ssid)) {
|
||||
return false;
|
||||
@@ -240,4 +250,62 @@ public class WifiUtils extends com.android.settingslib.wifi.WifiUtils {
|
||||
|
||||
return WifiEntry.SECURITY_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Wi-Fi hotspot settings can be displayed.
|
||||
*
|
||||
* @param context Context of caller
|
||||
* @return true if Wi-Fi hotspot settings can be displayed
|
||||
*/
|
||||
public static boolean checkShowWifiHotspot(Context context) {
|
||||
if (context == null) return false;
|
||||
|
||||
boolean showWifiHotspotSettings =
|
||||
context.getResources().getBoolean(R.bool.config_show_wifi_hotspot_settings);
|
||||
if (!showWifiHotspotSettings) {
|
||||
Log.w(TAG, "config_show_wifi_hotspot_settings:false");
|
||||
return false;
|
||||
}
|
||||
|
||||
WifiManager wifiManager = context.getSystemService(WifiManager.class);
|
||||
if (wifiManager == null) {
|
||||
Log.e(TAG, "WifiManager is null");
|
||||
return false;
|
||||
}
|
||||
|
||||
TetheringManager tetheringManager = context.getSystemService(TetheringManager.class);
|
||||
if (tetheringManager == null) {
|
||||
Log.e(TAG, "TetheringManager is null");
|
||||
return false;
|
||||
}
|
||||
String[] wifiRegexs = tetheringManager.getTetherableWifiRegexs();
|
||||
if (wifiRegexs == null || wifiRegexs.length == 0) {
|
||||
Log.w(TAG, "TetherableWifiRegexs is empty");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the cached result to see if Wi-Fi hotspot settings can be displayed.
|
||||
*
|
||||
* @param context Context of caller
|
||||
* @return true if Wi-Fi hotspot settings can be displayed
|
||||
*/
|
||||
public static boolean canShowWifiHotspot(Context context) {
|
||||
if (sCanShowWifiHotspotCached == null) {
|
||||
sCanShowWifiHotspotCached = checkShowWifiHotspot(context);
|
||||
}
|
||||
return sCanShowWifiHotspotCached;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sCanShowWifiHotspotCached for testing purposes.
|
||||
*
|
||||
* @param cached Cached value for #canShowWifiHotspot()
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public static void setCanShowWifiHotspotCached(Boolean cached) {
|
||||
sCanShowWifiHotspotCached = cached;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user