diff --git a/packages/SystemUI/res/values/config.xml b/packages/SystemUI/res/values/config.xml
index 9188ce091a3bd..d1a46c9b58c21 100644
--- a/packages/SystemUI/res/values/config.xml
+++ b/packages/SystemUI/res/values/config.xml
@@ -771,4 +771,8 @@
- @color/dream_overlay_aqi_very_unhealthy
- @color/dream_overlay_aqi_hazardous
+
+
+ true
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/HotspotControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/HotspotControllerImpl.java
index bd2123a251c35..69b55c81f48b4 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/HotspotControllerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/HotspotControllerImpl.java
@@ -33,6 +33,7 @@ import android.util.Log;
import androidx.annotation.NonNull;
import com.android.internal.util.ConcurrentUtils;
+import com.android.systemui.R;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.qualifiers.Background;
import com.android.systemui.dagger.qualifiers.Main;
@@ -63,6 +64,7 @@ public class HotspotControllerImpl implements HotspotController, WifiManager.Sof
private volatile int mNumConnectedDevices;
// Assume tethering is available until told otherwise
private volatile boolean mIsTetheringSupported = true;
+ private final boolean mIsTetheringSupportedConfig;
private volatile boolean mHasTetherableWifiRegexs = true;
private boolean mWaitingForTerminalState;
@@ -100,23 +102,29 @@ public class HotspotControllerImpl implements HotspotController, WifiManager.Sof
mTetheringManager = context.getSystemService(TetheringManager.class);
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
mMainHandler = mainHandler;
- mTetheringManager.registerTetheringEventCallback(
- new HandlerExecutor(backgroundHandler), mTetheringCallback);
+ mIsTetheringSupportedConfig = context.getResources()
+ .getBoolean(R.bool.config_show_wifi_tethering);
+ if (mIsTetheringSupportedConfig) {
+ mTetheringManager.registerTetheringEventCallback(
+ new HandlerExecutor(backgroundHandler), mTetheringCallback);
+ }
dumpManager.registerDumpable(getClass().getSimpleName(), this);
}
/**
* Whether hotspot is currently supported.
*
- * This will return {@code true} immediately on creation of the controller, but may be updated
- * later. Callbacks from this controllers will notify if the state changes.
+ * This may return {@code true} immediately on creation of the controller, but may be updated
+ * later as capabilities are collected from System Server.
+ *
+ * Callbacks from this controllers will notify if the state changes.
*
* @return {@code true} if hotspot is supported (or we haven't been told it's not)
* @see #addCallback
*/
@Override
public boolean isHotspotSupported() {
- return mIsTetheringSupported && mHasTetherableWifiRegexs
+ return mIsTetheringSupportedConfig && mIsTetheringSupported && mHasTetherableWifiRegexs
&& UserManager.get(mContext).isUserAdmin(ActivityManager.getCurrentUser());
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/HotspotControllerImplTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/HotspotControllerImplTest.java
index 4f1fb02ecdcd4..26df03f31b9ac 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/HotspotControllerImplTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/HotspotControllerImplTest.java
@@ -16,6 +16,7 @@
package com.android.systemui.statusbar.policy;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
@@ -25,6 +26,7 @@ import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import android.net.TetheringManager;
@@ -36,6 +38,7 @@ import android.testing.TestableLooper;
import androidx.test.filters.SmallTest;
+import com.android.systemui.R;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.dump.DumpManager;
@@ -96,6 +99,9 @@ public class HotspotControllerImplTest extends SysuiTestCase {
}).when(mWifiManager).registerSoftApCallback(any(Executor.class),
any(WifiManager.SoftApCallback.class));
+ mContext.getOrCreateTestableResources()
+ .addOverride(R.bool.config_show_wifi_tethering, true);
+
Handler handler = new Handler(mLooper.getLooper());
mController = new HotspotControllerImpl(mContext, handler, handler, mDumpManager);
@@ -176,4 +182,18 @@ public class HotspotControllerImplTest extends SysuiTestCase {
verify(mCallback1).onHotspotAvailabilityChanged(false);
}
+
+ @Test
+ public void testHotspotSupported_resource_false() {
+ mContext.getOrCreateTestableResources()
+ .addOverride(R.bool.config_show_wifi_tethering, false);
+
+ Handler handler = new Handler(mLooper.getLooper());
+
+ HotspotController controller =
+ new HotspotControllerImpl(mContext, handler, handler, mDumpManager);
+
+ verifyNoMoreInteractions(mTetheringManager);
+ assertFalse(controller.isHotspotSupported());
+ }
}