From 1a31b9dffcda34543e11a45fe688b3e0f2cf7588 Mon Sep 17 00:00:00 2001 From: Adnan Begovic Date: Tue, 31 Jan 2023 20:33:11 +0000 Subject: [PATCH] sysui: Observe weather enabled for lockscreen. Bug: 261757708 Test: manually, unit Change-Id: I7a7830cb8875d74a447b3ee07105899418a084c4 Merged-In: I7a7830cb8875d74a447b3ee07105899418a084c4 --- core/java/android/provider/Settings.java | 7 ++++++ core/res/res/values/config.xml | 3 +++ core/res/res/values/symbols.xml | 3 +++ .../settings/backup/SecureSettings.java | 3 ++- .../validators/SecureSettingsValidators.java | 1 + .../KeyguardClockSwitchController.java | 22 +++++++++++++++++++ .../LockscreenSmartspaceController.kt | 12 ++++++++++ .../KeyguardClockSwitchControllerTest.java | 21 ++++++++++++++++-- 8 files changed, 69 insertions(+), 3 deletions(-) diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index de0f8ef99f59d..36b366384ce14 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -11046,6 +11046,13 @@ public final class Settings { public static final String EXTRA_AUTOMATIC_POWER_SAVE_MODE = "extra_automatic_power_save_mode"; + /** + * Whether lockscreen weather is enabled. + * + * @hide + */ + public static final String LOCK_SCREEN_WEATHER_ENABLED = "lockscreen_weather_enabled"; + /** * These entries are considered common between the personal and the managed profile, * since the managed profile doesn't get to change them. diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 8f2272886f2cf..65dd86e63fcc3 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -6037,4 +6037,7 @@ + + + false diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index a02a1eb4726c8..88a398bf255da 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -4917,4 +4917,7 @@ + + + diff --git a/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java b/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java index c537d96b41937..2afcf71731710 100644 --- a/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java +++ b/packages/SettingsProvider/src/android/provider/settings/backup/SecureSettings.java @@ -219,6 +219,7 @@ public class SecureSettings { Settings.Secure.ASSIST_LONG_PRESS_HOME_ENABLED, Settings.Secure.BLUETOOTH_LE_BROADCAST_PROGRAM_INFO, Settings.Secure.BLUETOOTH_LE_BROADCAST_CODE, - Settings.Secure.BLUETOOTH_LE_BROADCAST_APP_SOURCE_NAME + Settings.Secure.BLUETOOTH_LE_BROADCAST_APP_SOURCE_NAME, + Settings.Secure.LOCK_SCREEN_WEATHER_ENABLED }; } diff --git a/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java b/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java index 8a67a0d816779..53ae9268f49ef 100644 --- a/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java +++ b/packages/SettingsProvider/src/android/provider/settings/validators/SecureSettingsValidators.java @@ -352,5 +352,6 @@ public class SecureSettingsValidators { VALIDATORS.put(Secure.BLUETOOTH_LE_BROADCAST_PROGRAM_INFO, ANY_STRING_VALIDATOR); VALIDATORS.put(Secure.BLUETOOTH_LE_BROADCAST_CODE, ANY_STRING_VALIDATOR); VALIDATORS.put(Secure.BLUETOOTH_LE_BROADCAST_APP_SOURCE_NAME, ANY_STRING_VALIDATOR); + VALIDATORS.put(Secure.LOCK_SCREEN_WEATHER_ENABLED, BOOLEAN_VALIDATOR); } } diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java index a148aa10024a1..879a95c4df5dc 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardClockSwitchController.java @@ -106,6 +106,12 @@ public class KeyguardClockSwitchController extends ViewController mWeatherView.setVisibility( + mSmartspaceController.isWeatherEnabled() ? View.VISIBLE : View.GONE)); + } + } + /** * Sets the clipChildren property on relevant views, to allow the smartspace to draw out of * bounds during the unlock transition. diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt index 5440fcc913d4a..aed132476c589 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt @@ -31,6 +31,7 @@ import android.os.Handler import android.os.UserHandle import android.provider.Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS import android.provider.Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS +import android.provider.Settings.Secure.LOCK_SCREEN_WEATHER_ENABLED import android.util.Log import android.view.ContextThemeWrapper import android.view.View @@ -244,6 +245,17 @@ constructor( datePlugin != null && weatherPlugin != null } + fun isWeatherEnabled(): Boolean { + execution.assertIsMainThread() + val defaultValue = context.getResources().getBoolean( + com.android.internal.R.bool.config_lockscreenWeatherEnabledByDefault) + val showWeather = secureSettings.getIntForUser( + LOCK_SCREEN_WEATHER_ENABLED, + if (defaultValue) 1 else 0, + userTracker.userId) == 1 + return showWeather + } + private fun updateBypassEnabled() { val bypassEnabled = bypassController.bypassEnabled smartspaceViews.forEach { it.setKeyguardBypassEnabled(bypassEnabled) } diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchControllerTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchControllerTest.java index 36b3f897190d4..ccc4e4af4ac8e 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardClockSwitchControllerTest.java @@ -300,8 +300,9 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase { ArgumentCaptor observerCaptor = ArgumentCaptor.forClass(ContentObserver.class); mController.init(); - verify(mSecureSettings).registerContentObserverForUser(any(String.class), - anyBoolean(), observerCaptor.capture(), eq(UserHandle.USER_ALL)); + verify(mSecureSettings).registerContentObserverForUser( + eq(Settings.Secure.LOCKSCREEN_USE_DOUBLE_LINE_CLOCK), + anyBoolean(), observerCaptor.capture(), eq(UserHandle.USER_ALL)); ContentObserver observer = observerCaptor.getValue(); mExecutor.runAllReady(); @@ -347,6 +348,22 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase { assertEquals(0, mController.getClockBottom(10)); } + @Test + public void testChangeLockscreenWeatherEnabledSetsWeatherViewVisible() { + when(mSmartspaceController.isWeatherEnabled()).thenReturn(true); + ArgumentCaptor observerCaptor = + ArgumentCaptor.forClass(ContentObserver.class); + mController.init(); + verify(mSecureSettings).registerContentObserverForUser( + eq(Settings.Secure.LOCK_SCREEN_WEATHER_ENABLED), anyBoolean(), + observerCaptor.capture(), eq(UserHandle.USER_ALL)); + ContentObserver observer = observerCaptor.getValue(); + mExecutor.runAllReady(); + // When a settings change has occurred, check that view is visible. + observer.onChange(true); + mExecutor.runAllReady(); + assertEquals(View.VISIBLE, mFakeWeatherView.getVisibility()); + } private void verifyAttachment(VerificationMode times) { verify(mClockRegistry, times).registerClockChangeListener(