Loading packages/SystemUI/src/com/android/systemui/statusbar/policy/HotspotControllerImpl.java +12 −2 Original line number Original line Diff line number Diff line Loading @@ -56,8 +56,9 @@ public class HotspotControllerImpl implements HotspotController, WifiManager.Sof private int mHotspotState; private int mHotspotState; private volatile int mNumConnectedDevices; private volatile int mNumConnectedDevices; private volatile boolean mIsTetheringSupported; // Assume tethering is available until told otherwise private volatile boolean mHasTetherableWifiRegexs; private volatile boolean mIsTetheringSupported = true; private volatile boolean mHasTetherableWifiRegexs = true; private boolean mWaitingForTerminalState; private boolean mWaitingForTerminalState; private TetheringManager.TetheringEventCallback mTetheringCallback = private TetheringManager.TetheringEventCallback mTetheringCallback = Loading Loading @@ -97,6 +98,15 @@ public class HotspotControllerImpl implements HotspotController, WifiManager.Sof new HandlerExecutor(backgroundHandler), mTetheringCallback); new HandlerExecutor(backgroundHandler), mTetheringCallback); } } /** * 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. * * @return {@code true} if hotspot is supported (or we haven't been told it's not) * @see #addCallback */ @Override @Override public boolean isHotspotSupported() { public boolean isHotspotSupported() { return mIsTetheringSupported && mHasTetherableWifiRegexs return mIsTetheringSupported && mHasTetherableWifiRegexs Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/HotspotControllerImplTest.java +17 −7 Original line number Original line Diff line number Diff line Loading @@ -16,7 +16,6 @@ package com.android.systemui.statusbar.policy; package com.android.systemui.statusbar.policy; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt; Loading Loading @@ -140,13 +139,16 @@ public class HotspotControllerImplTest extends SysuiTestCase { } } @Test @Test public void testDefault_hotspotNotSupported() { public void testHotspotSupported_default() { assertFalse(mController.isHotspotSupported()); assertTrue(mController.isHotspotSupported()); } } @Test @Test public void testHotspotSupported_rightConditions() { public void testHotspotSupported_rightConditions() { mTetheringCallbackCaptor.getValue().onTetheringSupported(true); mTetheringCallbackCaptor.getValue().onTetheringSupported(true); assertTrue(mController.isHotspotSupported()); mTetheringCallbackCaptor.getValue() mTetheringCallbackCaptor.getValue() .onTetherableInterfaceRegexpsChanged(mTetheringInterfaceRegexps); .onTetherableInterfaceRegexpsChanged(mTetheringInterfaceRegexps); Loading @@ -154,13 +156,21 @@ public class HotspotControllerImplTest extends SysuiTestCase { } } @Test @Test public void testHotspotSupported_callbackCalledOnChange() { public void testHotspotSupported_callbackCalledOnChange_tetheringSupported() { mController.addCallback(mCallback1); mTetheringCallbackCaptor.getValue().onTetheringSupported(false); verify(mCallback1).onHotspotAvailabilityChanged(false); } @Test public void testHotspotSupported_callbackCalledOnChange_tetherableInterfaces() { when(mTetheringInterfaceRegexps.getTetherableWifiRegexs()) .thenReturn(Collections.emptyList()); mController.addCallback(mCallback1); mController.addCallback(mCallback1); mTetheringCallbackCaptor.getValue().onTetheringSupported(true); mTetheringCallbackCaptor.getValue() mTetheringCallbackCaptor.getValue() .onTetherableInterfaceRegexpsChanged(mTetheringInterfaceRegexps); .onTetherableInterfaceRegexpsChanged(mTetheringInterfaceRegexps); verify(mCallback1).onHotspotAvailabilityChanged(true); verify(mCallback1).onHotspotAvailabilityChanged(false); } } } } Loading
packages/SystemUI/src/com/android/systemui/statusbar/policy/HotspotControllerImpl.java +12 −2 Original line number Original line Diff line number Diff line Loading @@ -56,8 +56,9 @@ public class HotspotControllerImpl implements HotspotController, WifiManager.Sof private int mHotspotState; private int mHotspotState; private volatile int mNumConnectedDevices; private volatile int mNumConnectedDevices; private volatile boolean mIsTetheringSupported; // Assume tethering is available until told otherwise private volatile boolean mHasTetherableWifiRegexs; private volatile boolean mIsTetheringSupported = true; private volatile boolean mHasTetherableWifiRegexs = true; private boolean mWaitingForTerminalState; private boolean mWaitingForTerminalState; private TetheringManager.TetheringEventCallback mTetheringCallback = private TetheringManager.TetheringEventCallback mTetheringCallback = Loading Loading @@ -97,6 +98,15 @@ public class HotspotControllerImpl implements HotspotController, WifiManager.Sof new HandlerExecutor(backgroundHandler), mTetheringCallback); new HandlerExecutor(backgroundHandler), mTetheringCallback); } } /** * 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. * * @return {@code true} if hotspot is supported (or we haven't been told it's not) * @see #addCallback */ @Override @Override public boolean isHotspotSupported() { public boolean isHotspotSupported() { return mIsTetheringSupported && mHasTetherableWifiRegexs return mIsTetheringSupported && mHasTetherableWifiRegexs Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/HotspotControllerImplTest.java +17 −7 Original line number Original line Diff line number Diff line Loading @@ -16,7 +16,6 @@ package com.android.systemui.statusbar.policy; package com.android.systemui.statusbar.policy; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt; Loading Loading @@ -140,13 +139,16 @@ public class HotspotControllerImplTest extends SysuiTestCase { } } @Test @Test public void testDefault_hotspotNotSupported() { public void testHotspotSupported_default() { assertFalse(mController.isHotspotSupported()); assertTrue(mController.isHotspotSupported()); } } @Test @Test public void testHotspotSupported_rightConditions() { public void testHotspotSupported_rightConditions() { mTetheringCallbackCaptor.getValue().onTetheringSupported(true); mTetheringCallbackCaptor.getValue().onTetheringSupported(true); assertTrue(mController.isHotspotSupported()); mTetheringCallbackCaptor.getValue() mTetheringCallbackCaptor.getValue() .onTetherableInterfaceRegexpsChanged(mTetheringInterfaceRegexps); .onTetherableInterfaceRegexpsChanged(mTetheringInterfaceRegexps); Loading @@ -154,13 +156,21 @@ public class HotspotControllerImplTest extends SysuiTestCase { } } @Test @Test public void testHotspotSupported_callbackCalledOnChange() { public void testHotspotSupported_callbackCalledOnChange_tetheringSupported() { mController.addCallback(mCallback1); mTetheringCallbackCaptor.getValue().onTetheringSupported(false); verify(mCallback1).onHotspotAvailabilityChanged(false); } @Test public void testHotspotSupported_callbackCalledOnChange_tetherableInterfaces() { when(mTetheringInterfaceRegexps.getTetherableWifiRegexs()) .thenReturn(Collections.emptyList()); mController.addCallback(mCallback1); mController.addCallback(mCallback1); mTetheringCallbackCaptor.getValue().onTetheringSupported(true); mTetheringCallbackCaptor.getValue() mTetheringCallbackCaptor.getValue() .onTetherableInterfaceRegexpsChanged(mTetheringInterfaceRegexps); .onTetherableInterfaceRegexpsChanged(mTetheringInterfaceRegexps); verify(mCallback1).onHotspotAvailabilityChanged(true); verify(mCallback1).onHotspotAvailabilityChanged(false); } } } }