From 73702413f83353785ef109be1bd5c73befdcc148 Mon Sep 17 00:00:00 2001 From: Matt Pietal Date: Mon, 19 Apr 2021 12:48:37 -0400 Subject: [PATCH] Remove "Device Controls" from Settings Both device controls and wallet have moved to new areas outside of the power menu. In step 1, we are deprecating the device controls settings, as the user can now fully control availability within the new Quick Settings device controls tile. Bug: 185597511 Test: atest ControlsControllerImplTest ControlsComponentTest DeviceControlsTileTest ControlsRequestDialogTest Change-Id: Ifdbb83dfd35263d62c9fd3dc67699769f9c9f408 --- core/java/android/provider/Settings.java | 3 + .../controls/controller/ControlsController.kt | 5 -- .../controller/ControlsControllerImpl.kt | 32 ++-------- .../controls/dagger/ControlsComponent.kt | 2 +- .../management/ControlsRequestDialog.kt | 5 +- .../controls/ui/ControlsUiController.kt | 2 - .../controls/ui/ControlsUiControllerImpl.kt | 3 - .../statusbar/phone/AutoTileManager.java | 7 ++- .../policy/DeviceControlsController.kt | 2 +- .../policy/DeviceControlsControllerImpl.kt | 34 ++++++----- .../controller/ControlsControllerImplTest.kt | 59 ------------------- .../controls/dagger/ControlsComponentTest.kt | 4 -- .../management/ControlsRequestDialogTest.kt | 3 +- .../qs/tiles/DeviceControlsTileTest.kt | 9 --- .../DeviceControlsControllerImplTest.kt | 29 +++++++-- 15 files changed, 62 insertions(+), 137 deletions(-) diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index 2616a6676db11..2179f3c333a58 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -9428,9 +9428,12 @@ public final class Settings { * 0 indicates disabled and 1 indicates enabled. A non existent value should be treated as * enabled. * + * @deprecated Controls are migrated to Quick Settings, rendering this unnecessary and will + * be removed in a future release. * @hide */ @Readable + @Deprecated public static final String CONTROLS_ENABLED = "controls_enabled"; /** diff --git a/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsController.kt b/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsController.kt index 496741b1cd6ff..ea1ade41dca8c 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsController.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsController.kt @@ -40,11 +40,6 @@ import java.util.function.Consumer */ interface ControlsController : UserAwareController { - /** - * Whether the controls system is available for the current user. - */ - val available: Boolean - // SERVICE COMMUNICATION /** diff --git a/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsControllerImpl.kt b/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsControllerImpl.kt index 8c3ef68f0bde4..5d0127a714fbc 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsControllerImpl.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsControllerImpl.kt @@ -28,7 +28,6 @@ import android.database.ContentObserver import android.net.Uri import android.os.Environment import android.os.UserHandle -import android.provider.Settings import android.service.controls.Control import android.service.controls.actions.ControlAction import android.util.ArrayMap @@ -70,15 +69,10 @@ class ControlsControllerImpl @Inject constructor ( companion object { private const val TAG = "ControlsControllerImpl" - internal const val CONTROLS_AVAILABLE = Settings.Secure.CONTROLS_ENABLED - internal val URI = Settings.Secure.getUriFor(CONTROLS_AVAILABLE) private const val USER_CHANGE_RETRY_DELAY = 500L // ms private const val DEFAULT_ENABLED = 1 private const val PERMISSION_SELF = "com.android.systemui.permission.SELF" const val SUGGESTED_CONTROLS_PER_STRUCTURE = 6 - - private fun isAvailable(userId: Int, cr: ContentResolver) = Settings.Secure.getIntForUser( - cr, CONTROLS_AVAILABLE, DEFAULT_ENABLED, userId) != 0 } private var userChanging: Boolean = true @@ -93,8 +87,6 @@ class ControlsControllerImpl @Inject constructor ( private val contentResolver: ContentResolver get() = context.contentResolver - override var available = isAvailable(currentUserId, contentResolver) - private set private val persistenceWrapper: ControlsFavoritePersistenceWrapper @VisibleForTesting @@ -126,8 +118,7 @@ class ControlsControllerImpl @Inject constructor ( BackupManager(userStructure.userContext) ) auxiliaryPersistenceWrapper.changeFile(userStructure.auxiliaryFile) - available = isAvailable(newUser.identifier, contentResolver) - resetFavorites(available) + resetFavorites() bindingController.changeUser(newUser) listingController.changeUser(newUser) userChanging = false @@ -157,7 +148,7 @@ class ControlsControllerImpl @Inject constructor ( Log.d(TAG, "Restore finished, storing auxiliary favorites") auxiliaryPersistenceWrapper.initialize() persistenceWrapper.storeFavorites(auxiliaryPersistenceWrapper.favorites) - resetFavorites(available) + resetFavorites() } } } @@ -176,8 +167,7 @@ class ControlsControllerImpl @Inject constructor ( if (userChanging || userId != currentUserId) { return } - available = isAvailable(currentUserId, contentResolver) - resetFavorites(available) + resetFavorites() } } @@ -242,7 +232,7 @@ class ControlsControllerImpl @Inject constructor ( init { dumpManager.registerDumpable(javaClass.name, this) - resetFavorites(available) + resetFavorites() userChanging = false broadcastDispatcher.registerReceiver( userSwitchReceiver, @@ -256,23 +246,18 @@ class ControlsControllerImpl @Inject constructor ( PERMISSION_SELF, null ) - contentResolver.registerContentObserver(URI, false, settingObserver, UserHandle.USER_ALL) listingController.addCallback(listingCallback) } fun destroy() { broadcastDispatcher.unregisterReceiver(userSwitchReceiver) context.unregisterReceiver(restoreFinishedReceiver) - contentResolver.unregisterContentObserver(settingObserver) listingController.removeCallback(listingCallback) } - private fun resetFavorites(shouldLoad: Boolean) { + private fun resetFavorites() { Favorites.clear() - - if (shouldLoad) { - Favorites.load(persistenceWrapper.readFavorites()) - } + Favorites.load(persistenceWrapper.readFavorites()) } private fun confirmAvailability(): Boolean { @@ -280,10 +265,6 @@ class ControlsControllerImpl @Inject constructor ( Log.w(TAG, "Controls not available while user is changing") return false } - if (!available) { - Log.d(TAG, "Controls not available") - return false - } return true } @@ -577,7 +558,6 @@ class ControlsControllerImpl @Inject constructor ( override fun dump(fd: FileDescriptor, pw: PrintWriter, args: Array) { pw.println("ControlsController state:") - pw.println(" Available: $available") pw.println(" Changing users: $userChanging") pw.println(" Current user: ${currentUser.identifier}") pw.println(" Favorites:") diff --git a/packages/SystemUI/src/com/android/systemui/controls/dagger/ControlsComponent.kt b/packages/SystemUI/src/com/android/systemui/controls/dagger/ControlsComponent.kt index 6b7a1ac8cb7e2..5557c86725961 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/dagger/ControlsComponent.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/dagger/ControlsComponent.kt @@ -93,7 +93,7 @@ class ControlsComponent @Inject constructor( /** * @return true if controls are feature-enabled and the user has the setting enabled */ - fun isEnabled() = featureEnabled && lazyControlsController.get().available + fun isEnabled() = featureEnabled /** * Returns one of 3 states: diff --git a/packages/SystemUI/src/com/android/systemui/controls/management/ControlsRequestDialog.kt b/packages/SystemUI/src/com/android/systemui/controls/management/ControlsRequestDialog.kt index 4ed6106750937..f9e7f0e921f32 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/management/ControlsRequestDialog.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/management/ControlsRequestDialog.kt @@ -71,10 +71,7 @@ open class ControlsRequestDialog @Inject constructor( override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - if (!controller.available) { - Log.w(TAG, "Quick Controls not available for this user ") - finish() - } + currentUserTracker.startTracking() controlsListingController.addCallback(callback) diff --git a/packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiController.kt b/packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiController.kt index ac13aadeeb409..2bbd3cbbc220e 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiController.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiController.kt @@ -23,8 +23,6 @@ import android.service.controls.actions.ControlAction import android.view.ViewGroup interface ControlsUiController { - val available: Boolean - companion object { public const val TAG = "ControlsUiController" public const val EXTRA_ANIMATE = "extra_animate" diff --git a/packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiControllerImpl.kt b/packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiControllerImpl.kt index 954bfb3ff891e..26be98743eed9 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiControllerImpl.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiControllerImpl.kt @@ -128,9 +128,6 @@ class ControlsUiControllerImpl @Inject constructor ( reload(parent) } - override val available: Boolean - get() = controlsController.get().available - private lateinit var activityContext: Context private lateinit var listingCallback: ControlsListingController.ControlsListingCallback diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoTileManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoTileManager.java index 3dd4a3b9300ee..fa326203b1829 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoTileManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/AutoTileManager.java @@ -16,6 +16,7 @@ package com.android.systemui.statusbar.phone; import static com.android.systemui.qs.dagger.QSFlagsModule.RBC_AVAILABLE; +import android.annotation.Nullable; import android.content.Context; import android.content.res.Resources; import android.hardware.display.ColorDisplayManager; @@ -294,9 +295,11 @@ public class AutoTileManager implements UserAwareController { private final DeviceControlsController.Callback mDeviceControlsCallback = new DeviceControlsController.Callback() { @Override - public void onControlsAvailable(int position) { + public void onControlsUpdate(@Nullable Integer position) { if (mAutoTracker.isAdded(DEVICE_CONTROLS)) return; - mHost.addTile(DEVICE_CONTROLS, position); + if (position != null) { + mHost.addTile(DEVICE_CONTROLS, position); + } mAutoTracker.setTileAdded(DEVICE_CONTROLS); mHandler.post(() -> mDeviceControlsController.removeCallback()); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/DeviceControlsController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/policy/DeviceControlsController.kt index b21189802c191..e2bebbe22554c 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/DeviceControlsController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/DeviceControlsController.kt @@ -24,7 +24,7 @@ interface DeviceControlsController { /** * If controls become available, initiate this callback with the desired position */ - fun onControlsAvailable(position: Int) + fun onControlsUpdate(position: Int?) } /** Add callback, supporting only a single callback at once */ diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/DeviceControlsControllerImpl.kt b/packages/SystemUI/src/com/android/systemui/statusbar/policy/DeviceControlsControllerImpl.kt index a4fd647ee643b..7563b3082ed8f 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/DeviceControlsControllerImpl.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/DeviceControlsControllerImpl.kt @@ -19,6 +19,7 @@ package com.android.systemui.statusbar.policy import android.content.ComponentName import android.content.Context import android.content.SharedPreferences +import android.provider.Settings import android.util.Log import com.android.systemui.R @@ -29,6 +30,7 @@ import com.android.systemui.dagger.SysUISingleton import com.android.systemui.qs.QSTileHost.POSITION_AT_END import com.android.systemui.settings.UserContextProvider import com.android.systemui.statusbar.policy.DeviceControlsController.Callback +import com.android.systemui.util.settings.SecureSettings import javax.inject.Inject @@ -45,7 +47,8 @@ import javax.inject.Inject public class DeviceControlsControllerImpl @Inject constructor( private val context: Context, private val controlsComponent: ControlsComponent, - private val userContextProvider: UserContextProvider + private val userContextProvider: UserContextProvider, + private val secureSettings: SecureSettings ) : DeviceControlsController { private var callback: Callback? = null @@ -73,6 +76,7 @@ public class DeviceControlsControllerImpl @Inject constructor( controlsComponent.getControlsController().ifPresent { if (!it.getFavorites().isEmpty()) { position = QS_PRIORITY_POSITION + fireControlsUpdate() } } } @@ -80,20 +84,22 @@ public class DeviceControlsControllerImpl @Inject constructor( /** * This migration logic assumes that something like [AutoTileManager] is tracking state * externally, and won't call this method after receiving a response via - * [Callback#onControlsAvailable], once per user. Otherwise the calculated position may be + * [Callback#onControlsUpdate], once per user. Otherwise the calculated position may be * incorrect. */ override fun setCallback(callback: Callback) { // Treat any additional call as a reset before recalculating removeCallback() - - checkMigrationToQs() - controlsComponent.getControlsListingController().ifPresent { - it.addCallback(listingCallback) - } - this.callback = callback - fireControlsAvailable() + + if (secureSettings.getInt(Settings.Secure.CONTROLS_ENABLED, 1) == 0) { + fireControlsUpdate() + } else { + checkMigrationToQs() + controlsComponent.getControlsListingController().ifPresent { + it.addCallback(listingCallback) + } + } } override fun removeCallback() { @@ -104,11 +110,9 @@ public class DeviceControlsControllerImpl @Inject constructor( } } - private fun fireControlsAvailable() { - position?.let { - Log.i(TAG, "Setting DeviceControlsTile position: $it") - callback?.onControlsAvailable(it) - } + private fun fireControlsUpdate() { + Log.i(TAG, "Setting DeviceControlsTile position: $position") + callback?.onControlsUpdate(position) } /** @@ -155,7 +159,7 @@ public class DeviceControlsControllerImpl @Inject constructor( if (position == null) { position = QS_DEFAULT_POSITION } - fireControlsAvailable() + fireControlsUpdate() controlsComponent.getControlsListingController().ifPresent { it.removeCallback(listingCallback) diff --git a/packages/SystemUI/tests/src/com/android/systemui/controls/controller/ControlsControllerImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/controls/controller/ControlsControllerImplTest.kt index f6c836a24f21d..a80fbbeb318dc 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/controls/controller/ControlsControllerImplTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/controls/controller/ControlsControllerImplTest.kt @@ -24,7 +24,6 @@ import android.content.ContextWrapper import android.content.Intent import android.content.pm.ServiceInfo import android.os.UserHandle -import android.provider.Settings import android.service.controls.Control import android.service.controls.DeviceTypes import android.service.controls.actions.ControlAction @@ -141,11 +140,6 @@ class ControlsControllerImplTest : SysuiTestCase() { fun setUp() { MockitoAnnotations.initMocks(this) - Settings.Secure.putInt(mContext.contentResolver, - ControlsControllerImpl.CONTROLS_AVAILABLE, 1) - Settings.Secure.putIntForUser(mContext.contentResolver, - ControlsControllerImpl.CONTROLS_AVAILABLE, 1, otherUser) - `when`(userTracker.userHandle).thenReturn(UserHandle.of(user)) delayableExecutor = FakeExecutor(FakeSystemClock()) @@ -172,7 +166,6 @@ class ControlsControllerImplTest : SysuiTestCase() { ) controller.auxiliaryPersistenceWrapper = auxiliaryPersistenceWrapper - assertTrue(controller.available) verify(broadcastDispatcher).registerReceiver( capture(broadcastReceiverCaptor), any(), any(), eq(UserHandle.ALL)) @@ -527,58 +520,6 @@ class ControlsControllerImplTest : SysuiTestCase() { verify(listingController).changeUser(UserHandle.of(otherUser)) assertTrue(controller.getFavorites().isEmpty()) assertEquals(otherUser, controller.currentUserId) - assertTrue(controller.available) - } - - @Test - fun testDisableFeature_notAvailable() { - Settings.Secure.putIntForUser(mContext.contentResolver, - ControlsControllerImpl.CONTROLS_AVAILABLE, 0, user) - controller.settingObserver.onChange(false, listOf(ControlsControllerImpl.URI), 0, 0) - assertFalse(controller.available) - } - - @Test - fun testDisableFeature_clearFavorites() { - controller.replaceFavoritesForStructure(TEST_STRUCTURE_INFO) - delayableExecutor.runAllReady() - - assertFalse(controller.getFavorites().isEmpty()) - - Settings.Secure.putIntForUser(mContext.contentResolver, - ControlsControllerImpl.CONTROLS_AVAILABLE, 0, user) - controller.settingObserver.onChange(false, listOf(ControlsControllerImpl.URI), 0, user) - assertTrue(controller.getFavorites().isEmpty()) - } - - @Test - fun testDisableFeature_noChangeForNotCurrentUser() { - controller.replaceFavoritesForStructure(TEST_STRUCTURE_INFO) - delayableExecutor.runAllReady() - - Settings.Secure.putIntForUser(mContext.contentResolver, - ControlsControllerImpl.CONTROLS_AVAILABLE, 0, otherUser) - controller.settingObserver.onChange(false, listOf(ControlsControllerImpl.URI), 0, otherUser) - - assertTrue(controller.available) - assertFalse(controller.getFavorites().isEmpty()) - } - - @Test - fun testCorrectUserSettingOnUserChange() { - Settings.Secure.putIntForUser(mContext.contentResolver, - ControlsControllerImpl.CONTROLS_AVAILABLE, 0, otherUser) - - val intent = Intent(Intent.ACTION_USER_SWITCHED).apply { - putExtra(Intent.EXTRA_USER_HANDLE, otherUser) - } - val pendingResult = mock(BroadcastReceiver.PendingResult::class.java) - `when`(pendingResult.sendingUserId).thenReturn(otherUser) - broadcastReceiverCaptor.value.pendingResult = pendingResult - - broadcastReceiverCaptor.value.onReceive(mContext, intent) - - assertFalse(controller.available) } @Test diff --git a/packages/SystemUI/tests/src/com/android/systemui/controls/dagger/ControlsComponentTest.kt b/packages/SystemUI/tests/src/com/android/systemui/controls/dagger/ControlsComponentTest.kt index b8f91b8d47193..c678f46c0c7e7 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/controls/dagger/ControlsComponentTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/controls/dagger/ControlsComponentTest.kt @@ -103,7 +103,6 @@ class ControlsComponentTest : SysuiTestCase() { @Test fun testFeatureEnabledAfterBootVisibility() { - `when`(controller.available).thenReturn(true) `when`(lockPatternUtils.getStrongAuthForUser(anyInt())) .thenReturn(STRONG_AUTH_REQUIRED_AFTER_BOOT) val component = setupComponent(true) @@ -113,7 +112,6 @@ class ControlsComponentTest : SysuiTestCase() { @Test fun testFeatureEnabledAndCannotShowOnLockScreenVisibility() { - `when`(controller.available).thenReturn(true) `when`(lockPatternUtils.getStrongAuthForUser(anyInt())) .thenReturn(STRONG_AUTH_NOT_REQUIRED) `when`(keyguardStateController.isUnlocked()).thenReturn(false) @@ -126,7 +124,6 @@ class ControlsComponentTest : SysuiTestCase() { @Test fun testFeatureEnabledAndCanShowOnLockScreenVisibility() { - `when`(controller.available).thenReturn(true) `when`(lockPatternUtils.getStrongAuthForUser(anyInt())) .thenReturn(STRONG_AUTH_NOT_REQUIRED) `when`(keyguardStateController.isUnlocked()).thenReturn(false) @@ -141,7 +138,6 @@ class ControlsComponentTest : SysuiTestCase() { fun testFeatureEnabledAndCanShowWhileUnlockedVisibility() { `when`(secureSettings.getInt(eq(Settings.Secure.POWER_MENU_LOCKED_SHOW_CONTENT), anyInt())) .thenReturn(0) - `when`(controller.available).thenReturn(true) `when`(lockPatternUtils.getStrongAuthForUser(anyInt())) .thenReturn(STRONG_AUTH_NOT_REQUIRED) `when`(keyguardStateController.isUnlocked()).thenReturn(true) diff --git a/packages/SystemUI/tests/src/com/android/systemui/controls/management/ControlsRequestDialogTest.kt b/packages/SystemUI/tests/src/com/android/systemui/controls/management/ControlsRequestDialogTest.kt index 0122db6c4965e..a328d9e06a742 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/controls/management/ControlsRequestDialogTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/controls/management/ControlsRequestDialogTest.kt @@ -110,7 +110,6 @@ class ControlsRequestDialogTest : SysuiTestCase() { intent.putExtra(ControlsProviderService.EXTRA_CONTROL, control) `when`(controller.currentUserId).thenReturn(USER_ID) - `when`(controller.available).thenReturn(true) `when`(listingController.getAppLabel(CONTROL_COMPONENT)).thenReturn(LABEL) `when`(controller.getFavoritesForComponent(CONTROL_COMPONENT)).thenReturn(emptyList()) @@ -142,4 +141,4 @@ class ControlsRequestDialogTest : SysuiTestCase() { assertEquals(control.deviceType, it.deviceType) } } -} \ No newline at end of file +} diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/DeviceControlsTileTest.kt b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/DeviceControlsTileTest.kt index a59f45d535970..aa766515cc13f 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/DeviceControlsTileTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/DeviceControlsTileTest.kt @@ -105,7 +105,6 @@ class DeviceControlsTileTest : SysuiTestCase() { doNothing().`when`(spiedContext).startActivity(any(Intent::class.java)) `when`(qsHost.context).thenReturn(spiedContext) `when`(qsHost.uiEventLogger).thenReturn(uiEventLogger) - `when`(controlsController.available).thenReturn(true) `when`(controlsComponent.isEnabled()).thenReturn(true) secureSettings.putInt(Settings.Secure.POWER_MENU_LOCKED_SHOW_CONTENT, 1) @@ -153,14 +152,6 @@ class DeviceControlsTileTest : SysuiTestCase() { assertThat(tile.isAvailable).isFalse() } - @Test - fun testAvailableControlsSettingOff() { - `when`(controlsController.available).thenReturn(false) - - tile = createTile() - assertThat(tile.isAvailable).isTrue() - } - @Test fun testObservingCallback() { verify(controlsListingController).observe( diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/DeviceControlsControllerImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/DeviceControlsControllerImplTest.kt index 95a363ee110ea..e9d16a6738ca3 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/DeviceControlsControllerImplTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/DeviceControlsControllerImplTest.kt @@ -19,6 +19,7 @@ package com.android.systemui.statusbar.policy import android.content.ComponentName import android.content.Context import android.content.pm.ServiceInfo +import android.provider.Settings import android.testing.AndroidTestingRunner import androidx.test.filters.SmallTest @@ -37,6 +38,7 @@ import com.android.systemui.statusbar.policy.DeviceControlsControllerImpl.Compan import com.android.systemui.statusbar.policy.DeviceControlsControllerImpl.Companion.PREFS_CONTROLS_SEEDING_COMPLETED import com.android.systemui.statusbar.policy.DeviceControlsControllerImpl.Companion.QS_DEFAULT_POSITION import com.android.systemui.statusbar.policy.DeviceControlsControllerImpl.Companion.QS_PRIORITY_POSITION +import com.android.systemui.util.settings.SecureSettings import java.util.Optional import java.util.function.Consumer @@ -55,6 +57,7 @@ import org.mockito.Mockito.times import org.mockito.Mockito.verify import org.mockito.Mockito.`when` import org.mockito.ArgumentMatchers.anyInt +import org.mockito.ArgumentMatchers.anyObject @SmallTest @RunWith(AndroidTestingRunner::class) @@ -76,6 +79,8 @@ class DeviceControlsControllerImplTest : SysuiTestCase() { private lateinit var serviceInfo: ServiceInfo @Mock private lateinit var userContextProvider: UserContextProvider + @Mock + private lateinit var secureSettings: SecureSettings @Captor private lateinit var seedCallback: ArgumentCaptor> @@ -98,7 +103,14 @@ class DeviceControlsControllerImplTest : SysuiTestCase() { `when`(controlsComponent.getControlsListingController()) .thenReturn(Optional.of(controlsListingController)) - controller = DeviceControlsControllerImpl(mContext, controlsComponent, userContextProvider) + controller = DeviceControlsControllerImpl( + mContext, + controlsComponent, + userContextProvider, + secureSettings + ) + + `when`(secureSettings.getInt(Settings.Secure.CONTROLS_ENABLED, 1)).thenReturn(1) `when`(serviceInfo.componentName).thenReturn(TEST_COMPONENT) controlsServiceInfo = ControlsServiceInfo(mContext, serviceInfo) @@ -116,7 +128,16 @@ class DeviceControlsControllerImplTest : SysuiTestCase() { verify(controlsListingController).addCallback(capture(listingCallbackCaptor)) listingCallbackCaptor.value.onServicesUpdated(emptyList()) - verify(callback, never()).onControlsAvailable(anyInt()) + verify(callback, never()).onControlsUpdate(anyInt()) + } + + @Test + fun testCallbackWithNullValueWhenSettingIsDisabled() { + `when`(secureSettings.getInt(Settings.Secure.CONTROLS_ENABLED, 1)).thenReturn(0) + controller.setCallback(callback) + + verify(controlsListingController, never()).addCallback(anyObject()) + verify(callback).onControlsUpdate(null) } @Test @@ -126,7 +147,7 @@ class DeviceControlsControllerImplTest : SysuiTestCase() { verify(controlsListingController).addCallback(capture(listingCallbackCaptor)) listingCallbackCaptor.value.onServicesUpdated(listOf(controlsServiceInfo)) - verify(callback).onControlsAvailable(QS_PRIORITY_POSITION) + verify(callback).onControlsUpdate(QS_PRIORITY_POSITION) } @Test @@ -146,6 +167,6 @@ class DeviceControlsControllerImplTest : SysuiTestCase() { capture(seedCallback) ) seedCallback.value.accept(SeedResponse(TEST_PKG, true)) - verify(callback).onControlsAvailable(QS_DEFAULT_POSITION) + verify(callback).onControlsUpdate(QS_DEFAULT_POSITION) } }