Add "When to start" definitions to DreamBackend
Eases the logic of talking to DreamBackend from settings in that you can
now ask it for a constant describing when the screen saver will turn on.
Test: none
Bug: 35031991
Change-Id: I4a35620b9baf1830998fd4b3e6ebcfe663d5c8ad
diff --git a/packages/SettingsLib/src/com/android/settingslib/dream/DreamBackend.java b/packages/SettingsLib/src/com/android/settingslib/dream/DreamBackend.java
index e5cdc85..988060e 100644
--- a/packages/SettingsLib/src/com/android/settingslib/dream/DreamBackend.java
+++ b/packages/SettingsLib/src/com/android/settingslib/dream/DreamBackend.java
@@ -16,6 +16,7 @@
package com.android.settingslib.dream;
+import android.annotation.IntDef;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -35,6 +36,8 @@
import android.util.Log;
import android.util.Xml;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -68,6 +71,15 @@
}
}
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef({WHILE_CHARGING, WHILE_DOCKED, EITHER, NEVER})
+ public @interface WhenToDream{}
+
+ public static final int WHILE_CHARGING = 0;
+ public static final int WHILE_DOCKED = 1;
+ public static final int EITHER = 2;
+ public static final int NEVER = 3;
+
private final Context mContext;
private final IDreamManager mDreamManager;
private final DreamInfoComparator mComparator;
@@ -75,6 +87,15 @@
private final boolean mDreamsActivatedOnSleepByDefault;
private final boolean mDreamsActivatedOnDockByDefault;
+ private static DreamBackend sInstance;
+
+ public static DreamBackend getInstance(Context context) {
+ if (sInstance == null) {
+ sInstance = new DreamBackend(context);
+ }
+ return sInstance;
+ }
+
public DreamBackend(Context context) {
mContext = context;
mDreamManager = IDreamManager.Stub.asInterface(
@@ -138,6 +159,42 @@
return null;
}
+ public @WhenToDream int getWhenToDreamSetting() {
+ if (!isEnabled()) {
+ return NEVER;
+ }
+ return isActivatedOnDock() && isActivatedOnSleep() ? EITHER
+ : isActivatedOnDock() ? WHILE_DOCKED
+ : isActivatedOnSleep() ? WHILE_CHARGING
+ : NEVER;
+ }
+
+ public void setWhenToDream(@WhenToDream int whenToDream) {
+ setEnabled(whenToDream != NEVER);
+
+ switch (whenToDream) {
+ case WHILE_CHARGING:
+ setActivatedOnDock(false);
+ setActivatedOnSleep(true);
+ break;
+
+ case WHILE_DOCKED:
+ setActivatedOnDock(true);
+ setActivatedOnSleep(false);
+ break;
+
+ case EITHER:
+ setActivatedOnDock(true);
+ setActivatedOnSleep(true);
+ break;
+
+ case NEVER:
+ default:
+ break;
+ }
+
+ }
+
public boolean isEnabled() {
return getBoolean(Settings.Secure.SCREENSAVER_ENABLED, mDreamsEnabledByDefault);
}