From 171a801caa42bc1e87ef2a9a55a514eec4b4dadd Mon Sep 17 00:00:00 2001 From: Lucas Silva Date: Thu, 9 Mar 2023 14:59:21 -0500 Subject: Add screensaver home control setting This setting controls whether home controls are visible on the screensaver Bug: 271330583 Test: verified setting correctly disables/enables button Test: make -j64 RunSettingsLibRoboTests ROBOTEST_FILTER="com.android.settingslib.dream.DreamBackendTest" Test: atest ComplicationTypesUpdaterTest Change-Id: I44e0e8c4f81984604f4b47489b91f07285c75e15 --- .../android/settingslib/dream/DreamBackend.java | 39 ++++++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'packages/SettingsLib/src') diff --git a/packages/SettingsLib/src/com/android/settingslib/dream/DreamBackend.java b/packages/SettingsLib/src/com/android/settingslib/dream/DreamBackend.java index 688fc720d058..c4f09cecfa1f 100644 --- a/packages/SettingsLib/src/com/android/settingslib/dream/DreamBackend.java +++ b/packages/SettingsLib/src/com/android/settingslib/dream/DreamBackend.java @@ -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 mDisabledDreams; - private final Set mSupportedComplications; + private Set 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 getEnabledComplications() { - return getComplicationsEnabled() ? mSupportedComplications : Collections.emptySet(); + final Set 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 complications) { + mSupportedComplications = complications; + } + public boolean isEnabled() { return getBoolean(Settings.Secure.SCREENSAVER_ENABLED, mDreamsEnabledByDefault); } -- cgit v1.2.3-59-g8ed1b