Merge "sysui: Observe weather enabled for lockscreen."

This commit is contained in:
Adnan Begovic
2023-02-03 22:39:16 +00:00
committed by Android (Google) Code Review
8 changed files with 69 additions and 3 deletions

View File

@@ -11467,6 +11467,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.

View File

@@ -6276,4 +6276,7 @@
"stopped" during initial boot of a device, or after an OTA update. Stopped state of
an app is not changed during subsequent reboots. -->
<bool name="config_stopSystemPackagesByDefault">false</bool>
<!-- Whether to show weather on the lock screen by default. -->
<bool name="config_lockscreenWeatherEnabledByDefault">false</bool>
</resources>

View File

@@ -4926,4 +4926,7 @@
<java-symbol type="array" name="config_displayShapeArray" />
<java-symbol type="bool" name="config_stopSystemPackagesByDefault"/>
<!-- Whether to show weather on the lockscreen by default. -->
<java-symbol type="bool" name="config_lockscreenWeatherEnabledByDefault" />
</resources>

View File

@@ -228,6 +228,7 @@ public class SecureSettings {
Settings.Secure.BLUETOOTH_LE_BROADCAST_CODE,
Settings.Secure.BLUETOOTH_LE_BROADCAST_APP_SOURCE_NAME,
Settings.Secure.CUSTOM_BUGREPORT_HANDLER_APP,
Settings.Secure.CUSTOM_BUGREPORT_HANDLER_USER
Settings.Secure.CUSTOM_BUGREPORT_HANDLER_USER,
Settings.Secure.LOCK_SCREEN_WEATHER_ENABLED
};
}

View File

@@ -361,5 +361,6 @@ public class SecureSettingsValidators {
VALIDATORS.put(Secure.BLUETOOTH_LE_BROADCAST_APP_SOURCE_NAME, ANY_STRING_VALIDATOR);
VALIDATORS.put(Secure.CUSTOM_BUGREPORT_HANDLER_APP, ANY_STRING_VALIDATOR);
VALIDATORS.put(Secure.CUSTOM_BUGREPORT_HANDLER_USER, ANY_INTEGER_VALIDATOR);
VALIDATORS.put(Secure.LOCK_SCREEN_WEATHER_ENABLED, BOOLEAN_VALIDATOR);
}
}

View File

@@ -106,6 +106,12 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
updateDoubleLineClock();
}
};
private final ContentObserver mShowWeatherObserver = new ContentObserver(null) {
@Override
public void onChange(boolean change) {
setWeatherVisibility();
}
};
private final KeyguardUnlockAnimationController.KeyguardUnlockAnimationListener
mKeyguardUnlockAnimationListener =
@@ -216,7 +222,15 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
UserHandle.USER_ALL
);
mSecureSettings.registerContentObserverForUser(
Settings.Secure.LOCK_SCREEN_WEATHER_ENABLED,
false, /* notifyForDescendants */
mShowWeatherObserver,
UserHandle.USER_ALL
);
updateDoubleLineClock();
setWeatherVisibility();
mKeyguardUnlockAnimationController.addKeyguardUnlockAnimationListener(
mKeyguardUnlockAnimationListener);
@@ -449,6 +463,14 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
}
}
private void setWeatherVisibility() {
if (mWeatherView != null) {
mUiExecutor.execute(
() -> 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.

View File

@@ -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
@@ -245,6 +246,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) }

View File

@@ -300,8 +300,9 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase {
ArgumentCaptor<ContentObserver> 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<ContentObserver> 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(