Settings: SoftAp: Add Hidden SSID preference
[jhonboy121]: adapted to A13
Signed-off-by: cjybyjk <cjybyjk@zjnu.edu.cn>
Change-Id: I8a222a9a9ae8f005953b738368168d551a502491
Signed-off-by: jhonboy121 <alfredmathew05@gmail.com>
diff --git a/res/values/leaf_strings.xml b/res/values/leaf_strings.xml
index b0711cb..bc9d3e1 100644
--- a/res/values/leaf_strings.xml
+++ b/res/values/leaf_strings.xml
@@ -97,4 +97,8 @@
<!-- fingerprint lockout -->
<string name="fingerprint_lockout_title">Disable fingerprint lockout</string>
<string name="fingerprint_lockout_summary">Deactivates 30 second timeout as well as permanent lockout after multiple failed fingerprint unlock attempts</string>
+
+ <!-- Hotspot -->
+ <string name="wifi_hotspot_hidden_ssid_title">Hidden network</string>
+ <string name="wifi_hotspot_hidden_ssid_summary">Your mobile hotspot\'s name won\'t appear in the list of available WLAN networks.</string>
</resources>
diff --git a/res/xml/wifi_tether_settings.xml b/res/xml/wifi_tether_settings.xml
index 4924bf9..a40480e 100644
--- a/res/xml/wifi_tether_settings.xml
+++ b/res/xml/wifi_tether_settings.xml
@@ -65,4 +65,9 @@
android:title="@string/wifi_hotspot_instant_title"
android:summary="@string/summary_placeholder"
settings:isPreferenceVisible="false"/>
+
+ <SwitchPreference
+ android:key="wifi_tether_hidden_ssid"
+ android:title="@string/wifi_hotspot_hidden_ssid_title"
+ android:summary="@string/wifi_hotspot_hidden_ssid_summary"/>
</PreferenceScreen>
diff --git a/src/com/android/settings/wifi/tether/WifiTetherSettings.java b/src/com/android/settings/wifi/tether/WifiTetherSettings.java
index bad29eb..5264ce0 100644
--- a/src/com/android/settings/wifi/tether/WifiTetherSettings.java
+++ b/src/com/android/settings/wifi/tether/WifiTetherSettings.java
@@ -48,6 +48,8 @@
import com.android.settingslib.search.SearchIndexable;
import com.android.settingslib.wifi.WifiEnterpriseRestrictionUtils;
+import ink.kscope.settings.wifi.tether.WifiTetherHiddenSsidPreferenceController;
+
import java.util.ArrayList;
import java.util.List;
@@ -76,6 +78,9 @@
static final String KEY_WIFI_HOTSPOT_SPEED = "wifi_hotspot_speed";
@VisibleForTesting
static final String KEY_INSTANT_HOTSPOT = "wifi_hotspot_instant";
+ @VisibleForTesting
+ static final String KEY_WIFI_TETHER_HIDDEN_SSID =
+ WifiTetherHiddenSsidPreferenceController.PREF_KEY;
@VisibleForTesting
SettingsMainSwitchBar mMainSwitchBar;
@@ -90,6 +95,8 @@
WifiTetherMaximizeCompatibilityPreferenceController mMaxCompatibilityPrefController;
@VisibleForTesting
WifiTetherAutoOffPreferenceController mWifiTetherAutoOffPreferenceController;
+ @VisibleForTesting
+ WifiTetherHiddenSsidPreferenceController mHiddenSsidPrefController;
@VisibleForTesting
boolean mUnavailable;
@@ -199,6 +206,7 @@
mMaxCompatibilityPrefController =
use(WifiTetherMaximizeCompatibilityPreferenceController.class);
mWifiTetherAutoOffPreferenceController = use(WifiTetherAutoOffPreferenceController.class);
+ mHiddenSsidPrefController = use(WifiTetherHiddenSsidPreferenceController.class);
}
@Override
@@ -283,6 +291,7 @@
controllers.add(
new WifiTetherAutoOffPreferenceController(context, KEY_WIFI_TETHER_AUTO_OFF));
controllers.add(new WifiTetherMaximizeCompatibilityPreferenceController(context, listener));
+ controllers.add(new WifiTetherHiddenSsidPreferenceController(context, listener));
return controllers;
}
@@ -329,6 +338,7 @@
}
configBuilder.setAutoShutdownEnabled(
mWifiTetherAutoOffPreferenceController.isEnabled());
+ configBuilder.setHiddenSsid(mHiddenSsidPrefController.isHiddenSsidEnabled());
return configBuilder.build();
}
@@ -337,6 +347,7 @@
use(WifiTetherSecurityPreferenceController.class).updateDisplay();
use(WifiTetherPasswordPreferenceController.class).updateDisplay();
use(WifiTetherMaximizeCompatibilityPreferenceController.class).updateDisplay();
+ use(WifiTetherHiddenSsidPreferenceController.class).updateDisplay();
}
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
@@ -369,6 +380,7 @@
keys.add(KEY_WIFI_TETHER_NETWORK_PASSWORD);
keys.add(KEY_WIFI_TETHER_AUTO_OFF);
keys.add(KEY_WIFI_TETHER_MAXIMIZE_COMPATIBILITY);
+ keys.add(KEY_WIFI_TETHER_HIDDEN_SSID);
}
// Remove duplicate
diff --git a/src/ink/kscope/settings/wifi/tether/WifiTetherHiddenSsidPreferenceController.java b/src/ink/kscope/settings/wifi/tether/WifiTetherHiddenSsidPreferenceController.java
new file mode 100644
index 0000000..2460877
--- /dev/null
+++ b/src/ink/kscope/settings/wifi/tether/WifiTetherHiddenSsidPreferenceController.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2022 Project Kaleidoscope
+ *
+ * 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 ink.kscope.settings.wifi.tether;
+
+import android.content.Context;
+import android.net.wifi.SoftApConfiguration;
+import android.util.FeatureFlagUtils;
+
+import androidx.preference.Preference;
+import androidx.preference.SwitchPreference;
+
+import com.android.settings.R;
+import com.android.settings.core.FeatureFlags;
+import com.android.settings.wifi.tether.WifiTetherBasePreferenceController;
+
+/**
+ * This controller helps to manage the state of hide SSID switch preference.
+ */
+public class WifiTetherHiddenSsidPreferenceController extends
+ WifiTetherBasePreferenceController {
+
+ public static final String DEDUP_POSTFIX = "_2";
+ public static final String PREF_KEY = "wifi_tether_hidden_ssid";
+
+ private boolean mHiddenSsid;
+
+ public WifiTetherHiddenSsidPreferenceController(Context context,
+ WifiTetherBasePreferenceController.OnTetherConfigUpdateListener listener) {
+ super(context, listener);
+
+ if (mWifiManager != null) {
+ final SoftApConfiguration config = mWifiManager.getSoftApConfiguration();
+ if (config != null) {
+ mHiddenSsid = config.isHiddenSsid();
+ }
+ }
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return FeatureFlagUtils.isEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE)
+ ? PREF_KEY + DEDUP_POSTFIX : PREF_KEY;
+ }
+
+ @Override
+ public void updateDisplay() {
+ if (mPreference == null) {
+ return;
+ }
+ ((SwitchPreference) mPreference).setChecked(mHiddenSsid);
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ mHiddenSsid = (Boolean) newValue;
+ if (mListener != null) {
+ mListener.onTetherConfigUpdated(this);
+ }
+ return true;
+ }
+
+ public boolean isHiddenSsidEnabled() {
+ return mHiddenSsid;
+ }
+}