Loading packages/SystemUI/res/values/config.xml +4 −0 Original line number Diff line number Diff line Loading @@ -783,4 +783,8 @@ <item>@color/dream_overlay_aqi_very_unhealthy</item> <item>@color/dream_overlay_aqi_hazardous</item> </integer-array> <!-- Whether the device should display hotspot UI. If true, UI will display only when tethering is available. If false, UI will never show regardless of tethering availability" --> <bool name="config_show_wifi_tethering">true</bool> </resources> packages/SystemUI/src/com/android/systemui/statusbar/policy/HotspotControllerImpl.java +13 −5 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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; 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()); } Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/HotspotControllerImplTest.java +20 −0 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading @@ -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; Loading Loading @@ -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); Loading Loading @@ -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()); } } Loading
packages/SystemUI/res/values/config.xml +4 −0 Original line number Diff line number Diff line Loading @@ -783,4 +783,8 @@ <item>@color/dream_overlay_aqi_very_unhealthy</item> <item>@color/dream_overlay_aqi_hazardous</item> </integer-array> <!-- Whether the device should display hotspot UI. If true, UI will display only when tethering is available. If false, UI will never show regardless of tethering availability" --> <bool name="config_show_wifi_tethering">true</bool> </resources>
packages/SystemUI/src/com/android/systemui/statusbar/policy/HotspotControllerImpl.java +13 −5 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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; 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()); } Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/HotspotControllerImplTest.java +20 −0 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading @@ -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; Loading Loading @@ -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); Loading Loading @@ -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()); } }