Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 74dc6408 authored by Lucas Silva's avatar Lucas Silva Committed by Automerger Merge Worker
Browse files

Merge "Add screensaver home control setting" into tm-qpr-dev am: 9b98c8e9 am: 8762e2b7

parents 6f2a456d 8762e2b7
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -9541,6 +9541,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.
+36 −3
Original line number Diff line number Diff line
@@ -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);
    }
+54 −3
Original line number Diff line number Diff line
@@ -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);
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -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,
+1 −0
Original line number Diff line number Diff line
@@ -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(
Loading