Merge "Add screensaver home control setting" into tm-qpr-dev

This commit is contained in:
Lucas Silva
2023-03-14 21:47:02 +00:00
committed by Android (Google) Code Review
7 changed files with 112 additions and 19 deletions

View File

@@ -9209,6 +9209,14 @@ public final class Settings {
public static final String SCREENSAVER_COMPLICATIONS_ENABLED =
"screensaver_complications_enabled";
/**
* Whether home controls are enabled to be shown over the screensaver by the user.
*
* @hide
*/
public static final String SCREENSAVER_HOME_CONTROLS_ENABLED =
"screensaver_home_controls_enabled";
/**
* Default, indicates that the user has not yet started the dock setup flow.

View File

@@ -31,13 +31,15 @@ import android.os.ServiceManager;
import android.provider.Settings;
import android.service.dreams.DreamService;
import android.service.dreams.IDreamManager;
import android.util.ArraySet;
import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
@@ -116,7 +118,7 @@ public class DreamBackend {
private final boolean mDreamsActivatedOnSleepByDefault;
private final boolean mDreamsActivatedOnDockByDefault;
private final Set<ComponentName> mDisabledDreams;
private final Set<Integer> mSupportedComplications;
private Set<Integer> mSupportedComplications;
private static DreamBackend sInstance;
public static DreamBackend getInstance(Context context) {
@@ -281,7 +283,18 @@ public class DreamBackend {
/** Gets all complications which have been enabled by the user. */
public Set<Integer> getEnabledComplications() {
return getComplicationsEnabled() ? mSupportedComplications : Collections.emptySet();
final Set<Integer> enabledComplications =
getComplicationsEnabled()
? new ArraySet<>(mSupportedComplications) : new ArraySet<>();
if (!getHomeControlsEnabled()) {
enabledComplications.remove(COMPLICATION_TYPE_HOME_CONTROLS);
} else if (mSupportedComplications.contains(COMPLICATION_TYPE_HOME_CONTROLS)) {
// Add home control type to list of enabled complications, even if other complications
// have been disabled.
enabledComplications.add(COMPLICATION_TYPE_HOME_CONTROLS);
}
return enabledComplications;
}
/** Sets complication enabled state. */
@@ -290,6 +303,18 @@ public class DreamBackend {
Settings.Secure.SCREENSAVER_COMPLICATIONS_ENABLED, enabled ? 1 : 0);
}
/** Sets whether home controls are enabled by the user on the dream */
public void setHomeControlsEnabled(boolean enabled) {
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.SCREENSAVER_HOME_CONTROLS_ENABLED, enabled ? 1 : 0);
}
/** Gets whether home controls button is enabled on the dream */
private boolean getHomeControlsEnabled() {
return Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.SCREENSAVER_HOME_CONTROLS_ENABLED, 1) == 1;
}
/**
* Gets whether complications are enabled on this device
*/
@@ -304,6 +329,14 @@ public class DreamBackend {
return mSupportedComplications;
}
/**
* Sets the list of supported complications. Should only be used in tests.
*/
@VisibleForTesting
public void setSupportedComplications(Set<Integer> complications) {
mSupportedComplications = complications;
}
public boolean isEnabled() {
return getBoolean(Settings.Secure.SCREENSAVER_ENABLED, mDreamsEnabledByDefault);
}

View File

@@ -16,6 +16,10 @@
package com.android.settingslib.dream;
import static com.android.settingslib.dream.DreamBackend.COMPLICATION_TYPE_DATE;
import static com.android.settingslib.dream.DreamBackend.COMPLICATION_TYPE_HOME_CONTROLS;
import static com.android.settingslib.dream.DreamBackend.COMPLICATION_TYPE_TIME;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
@@ -36,13 +40,16 @@ import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowSettings;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = {ShadowSettings.ShadowSecure.class})
public final class DreamBackendTest {
private static final int[] SUPPORTED_DREAM_COMPLICATIONS = {1, 2, 3};
private static final int[] SUPPORTED_DREAM_COMPLICATIONS =
{COMPLICATION_TYPE_HOME_CONTROLS, COMPLICATION_TYPE_DATE,
COMPLICATION_TYPE_TIME};
private static final List<Integer> SUPPORTED_DREAM_COMPLICATIONS_LIST = Arrays.stream(
SUPPORTED_DREAM_COMPLICATIONS).boxed().collect(
Collectors.toList());
@@ -93,8 +100,52 @@ public final class DreamBackendTest {
@Test
public void testDisableComplications() {
mBackend.setComplicationsEnabled(false);
assertThat(mBackend.getEnabledComplications()).isEmpty();
assertThat(mBackend.getEnabledComplications())
.containsExactly(COMPLICATION_TYPE_HOME_CONTROLS);
assertThat(mBackend.getComplicationsEnabled()).isFalse();
}
}
@Test
public void testHomeControlsDisabled_ComplicationsEnabled() {
mBackend.setComplicationsEnabled(true);
mBackend.setHomeControlsEnabled(false);
// Home controls should not be enabled, only date and time.
final List<Integer> enabledComplications =
Arrays.asList(COMPLICATION_TYPE_DATE, COMPLICATION_TYPE_TIME);
assertThat(mBackend.getEnabledComplications())
.containsExactlyElementsIn(enabledComplications);
}
@Test
public void testHomeControlsDisabled_ComplicationsDisabled() {
mBackend.setComplicationsEnabled(false);
mBackend.setHomeControlsEnabled(false);
assertThat(mBackend.getEnabledComplications()).isEmpty();
}
@Test
public void testHomeControlsEnabled_ComplicationsDisabled() {
mBackend.setComplicationsEnabled(false);
mBackend.setHomeControlsEnabled(true);
// Home controls should not be enabled, only date and time.
final List<Integer> enabledComplications =
Collections.singletonList(COMPLICATION_TYPE_HOME_CONTROLS);
assertThat(mBackend.getEnabledComplications())
.containsExactlyElementsIn(enabledComplications);
}
@Test
public void testHomeControlsEnabled_ComplicationsEnabled() {
mBackend.setComplicationsEnabled(true);
mBackend.setHomeControlsEnabled(true);
// Home controls should not be enabled, only date and time.
final List<Integer> enabledComplications =
Arrays.asList(
COMPLICATION_TYPE_HOME_CONTROLS,
COMPLICATION_TYPE_DATE,
COMPLICATION_TYPE_TIME
);
assertThat(mBackend.getEnabledComplications())
.containsExactlyElementsIn(enabledComplications);
}
}

View File

@@ -139,6 +139,7 @@ public class SecureSettings {
Settings.Secure.SCREENSAVER_COMPONENTS,
Settings.Secure.SCREENSAVER_ACTIVATE_ON_DOCK,
Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP,
Settings.Secure.SCREENSAVER_HOME_CONTROLS_ENABLED,
Settings.Secure.SHOW_FIRST_CRASH_DIALOG_DEV_OPTION,
Settings.Secure.VOLUME_HUSH_GESTURE,
Settings.Secure.MANUAL_RINGER_TOGGLE_COUNT,

View File

@@ -206,6 +206,7 @@ public class SecureSettingsValidators {
VALIDATORS.put(Secure.SCREENSAVER_COMPONENTS, COMMA_SEPARATED_COMPONENT_LIST_VALIDATOR);
VALIDATORS.put(Secure.SCREENSAVER_ACTIVATE_ON_DOCK, BOOLEAN_VALIDATOR);
VALIDATORS.put(Secure.SCREENSAVER_ACTIVATE_ON_SLEEP, BOOLEAN_VALIDATOR);
VALIDATORS.put(Secure.SCREENSAVER_HOME_CONTROLS_ENABLED, BOOLEAN_VALIDATOR);
VALIDATORS.put(Secure.SHOW_FIRST_CRASH_DIALOG_DEV_OPTION, BOOLEAN_VALIDATOR);
VALIDATORS.put(Secure.VOLUME_HUSH_GESTURE, NON_NEGATIVE_INTEGER_VALIDATOR);
VALIDATORS.put(

View File

@@ -75,6 +75,10 @@ public class ComplicationTypesUpdater extends ConditionalCoreStartable {
Settings.Secure.SCREENSAVER_COMPLICATIONS_ENABLED,
settingsObserver,
UserHandle.myUserId());
mSecureSettings.registerContentObserverForUser(
Settings.Secure.SCREENSAVER_HOME_CONTROLS_ENABLED,
settingsObserver,
UserHandle.myUserId());
settingsObserver.onChange(false);
}

View File

@@ -17,7 +17,6 @@
package com.android.systemui.dreams.complication;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -36,7 +35,7 @@ import com.android.systemui.condition.SelfExecutingMonitor;
import com.android.systemui.dreams.DreamOverlayStateController;
import com.android.systemui.shared.condition.Monitor;
import com.android.systemui.util.concurrency.FakeExecutor;
import com.android.systemui.util.settings.SecureSettings;
import com.android.systemui.util.settings.FakeSettings;
import com.android.systemui.util.time.FakeSystemClock;
import org.junit.Before;
@@ -57,8 +56,7 @@ public class ComplicationTypesUpdaterTest extends SysuiTestCase {
private Context mContext;
@Mock
private DreamBackend mDreamBackend;
@Mock
private SecureSettings mSecureSettings;
private FakeSettings mSecureSettings;
@Mock
private DreamOverlayStateController mDreamOverlayStateController;
@Captor
@@ -74,6 +72,7 @@ public class ComplicationTypesUpdaterTest extends SysuiTestCase {
public void setUp() {
MockitoAnnotations.initMocks(this);
when(mDreamBackend.getEnabledComplications()).thenReturn(new HashSet<>());
mSecureSettings = new FakeSettings();
mMonitor = SelfExecutingMonitor.createInstance();
mController = new ComplicationTypesUpdater(mDreamBackend, mExecutor,
@@ -100,19 +99,15 @@ public class ComplicationTypesUpdaterTest extends SysuiTestCase {
when(mDreamBackend.getEnabledComplications()).thenReturn(new HashSet<>(Arrays.asList(
DreamBackend.COMPLICATION_TYPE_TIME, DreamBackend.COMPLICATION_TYPE_WEATHER,
DreamBackend.COMPLICATION_TYPE_AIR_QUALITY)));
final ContentObserver settingsObserver = captureSettingsObserver();
settingsObserver.onChange(false);
// Update the setting to trigger any content observers
mSecureSettings.putBoolForUser(
Settings.Secure.SCREENSAVER_COMPLICATIONS_ENABLED, true,
UserHandle.myUserId());
mExecutor.runAllReady();
verify(mDreamOverlayStateController).setAvailableComplicationTypes(
Complication.COMPLICATION_TYPE_TIME | Complication.COMPLICATION_TYPE_WEATHER
| Complication.COMPLICATION_TYPE_AIR_QUALITY);
}
private ContentObserver captureSettingsObserver() {
verify(mSecureSettings).registerContentObserverForUser(
eq(Settings.Secure.SCREENSAVER_COMPLICATIONS_ENABLED),
mSettingsObserverCaptor.capture(), eq(UserHandle.myUserId()));
return mSettingsObserverCaptor.getValue();
}
}