diff options
| author | 2020-02-25 11:26:20 -0500 | |
|---|---|---|
| committer | 2020-02-25 12:10:49 -0500 | |
| commit | 17623bfa8f42c8399698f88d5a8cf745c65301d4 (patch) | |
| tree | da54aa89296a1a8b1e9dace69bed732d6bdb86f2 | |
| parent | 7b27da1d8fc439bc238507ffb9b54d7032e561a1 (diff) | |
Prevent early destroying HotspotTile
Due to the switch to Async HotspotControllerImpl, if the controller is
created with the tile it will think that tethering is not available
(because it hasn't received callbacks saying otherwise yet) and the tile
will be preemptively destroyed. This was observable on OTAs (or when
doing a full flash).
With this change, HotspotControllerImpl will assume that tethering is
available by default and will signal callbacks if it learns that it's
not.
There are currently no other consumers of
HotspotControllerImpl#isHotspotSupported.
Fixes: 149492796
Test: atest HotspotControllerImplTest
Test: manual full flash
Change-Id: Id1461b7fbe973b732bc69c7ad77a30e0f66247d8
2 files changed, 29 insertions, 9 deletions
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 d0904049d85a..7d532a88caac 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/HotspotControllerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/HotspotControllerImpl.java @@ -56,8 +56,9 @@ public class HotspotControllerImpl implements HotspotController, WifiManager.Sof private int mHotspotState; private volatile int mNumConnectedDevices; - private volatile boolean mIsTetheringSupported; - private volatile boolean mHasTetherableWifiRegexs; + // Assume tethering is available until told otherwise + private volatile boolean mIsTetheringSupported = true; + private volatile boolean mHasTetherableWifiRegexs = true; private boolean mWaitingForTerminalState; private TetheringManager.TetheringEventCallback mTetheringCallback = @@ -97,6 +98,15 @@ public class HotspotControllerImpl implements HotspotController, WifiManager.Sof 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 public boolean isHotspotSupported() { return mIsTetheringSupported && mHasTetherableWifiRegexs 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 cd91f22bb753..57714722aea4 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,7 +16,6 @@ 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; @@ -140,13 +139,16 @@ public class HotspotControllerImplTest extends SysuiTestCase { } @Test - public void testDefault_hotspotNotSupported() { - assertFalse(mController.isHotspotSupported()); + public void testHotspotSupported_default() { + assertTrue(mController.isHotspotSupported()); } @Test public void testHotspotSupported_rightConditions() { mTetheringCallbackCaptor.getValue().onTetheringSupported(true); + + assertTrue(mController.isHotspotSupported()); + mTetheringCallbackCaptor.getValue() .onTetherableInterfaceRegexpsChanged(mTetheringInterfaceRegexps); @@ -154,13 +156,21 @@ public class HotspotControllerImplTest extends SysuiTestCase { } @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); - mTetheringCallbackCaptor.getValue().onTetheringSupported(true); mTetheringCallbackCaptor.getValue() .onTetherableInterfaceRegexpsChanged(mTetheringInterfaceRegexps); - verify(mCallback1).onHotspotAvailabilityChanged(true); + verify(mCallback1).onHotspotAvailabilityChanged(false); } - } |