diff options
Diffstat (limited to 'packages/SettingsLib/src')
| -rw-r--r-- | packages/SettingsLib/src/com/android/settingslib/dream/DreamBackend.java | 39 |
1 files changed, 36 insertions, 3 deletions
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<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); } |