2 * Copyright (C) 2016 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package android.hardware.display;
19 import android.annotation.TestApi;
20 import android.content.Context;
21 import android.os.Build;
22 import android.os.SystemProperties;
23 import android.provider.Settings;
24 import android.text.TextUtils;
26 import com.android.internal.R;
29 * AmbientDisplayConfiguration encapsulates reading access to the configuration of ambient display.
34 public class AmbientDisplayConfiguration {
36 private final Context mContext;
37 private final boolean mAlwaysOnByDefault;
41 public AmbientDisplayConfiguration(Context context) {
43 mAlwaysOnByDefault = mContext.getResources().getBoolean(R.bool.config_dozeAlwaysOnEnabled);
47 public boolean enabled(int user) {
48 return pulseOnNotificationEnabled(user)
49 || pulseOnLongPressEnabled(user)
50 || alwaysOnEnabled(user)
51 || wakeLockScreenGestureEnabled(user)
52 || wakeDisplayGestureEnabled(user)
53 || pickupGestureEnabled(user)
54 || tapGestureEnabled(user)
55 || doubleTapGestureEnabled(user);
59 public boolean pulseOnNotificationEnabled(int user) {
60 return boolSettingDefaultOn(Settings.Secure.DOZE_ENABLED, user)
61 && pulseOnNotificationAvailable();
65 public boolean pulseOnNotificationAvailable() {
66 return ambientDisplayAvailable();
70 public boolean pickupGestureEnabled(int user) {
71 return boolSettingDefaultOn(Settings.Secure.DOZE_PICK_UP_GESTURE, user)
72 && dozePickupSensorAvailable();
76 public boolean dozePickupSensorAvailable() {
77 return mContext.getResources().getBoolean(R.bool.config_dozePulsePickup);
81 public boolean tapGestureEnabled(int user) {
82 return boolSettingDefaultOn(Settings.Secure.DOZE_TAP_SCREEN_GESTURE, user)
83 && tapSensorAvailable();
87 public boolean tapSensorAvailable() {
88 return !TextUtils.isEmpty(tapSensorType());
92 public boolean doubleTapGestureEnabled(int user) {
93 return boolSettingDefaultOn(Settings.Secure.DOZE_DOUBLE_TAP_GESTURE, user)
94 && doubleTapSensorAvailable();
98 public boolean doubleTapSensorAvailable() {
99 return !TextUtils.isEmpty(doubleTapSensorType());
103 public boolean wakeScreenGestureAvailable() {
104 return mContext.getResources()
105 .getBoolean(R.bool.config_dozeWakeLockScreenSensorAvailable);
109 public boolean wakeLockScreenGestureEnabled(int user) {
110 return boolSettingDefaultOn(Settings.Secure.DOZE_WAKE_LOCK_SCREEN_GESTURE, user)
111 && wakeScreenGestureAvailable();
115 public boolean wakeDisplayGestureEnabled(int user) {
116 return boolSettingDefaultOn(Settings.Secure.DOZE_WAKE_DISPLAY_GESTURE, user)
117 && wakeScreenGestureAvailable();
121 public long getWakeLockScreenDebounce() {
122 return mContext.getResources().getInteger(R.integer.config_dozeWakeLockScreenDebounce);
126 public String doubleTapSensorType() {
127 return mContext.getResources().getString(R.string.config_dozeDoubleTapSensorType);
131 public String tapSensorType() {
132 return mContext.getResources().getString(R.string.config_dozeTapSensorType);
136 public String longPressSensorType() {
137 return mContext.getResources().getString(R.string.config_dozeLongPressSensorType);
141 public boolean pulseOnLongPressEnabled(int user) {
142 return pulseOnLongPressAvailable() && boolSettingDefaultOff(
143 Settings.Secure.DOZE_PULSE_ON_LONG_PRESS, user);
146 private boolean pulseOnLongPressAvailable() {
147 return !TextUtils.isEmpty(longPressSensorType());
151 * Returns if Always-on-Display functionality is enabled on the display for a specified user.
156 public boolean alwaysOnEnabled(int user) {
157 return boolSetting(Settings.Secure.DOZE_ALWAYS_ON, user, mAlwaysOnByDefault ? 1 : 0)
158 && alwaysOnAvailable() && !accessibilityInversionEnabled(user);
162 * Returns if Always-on-Display functionality is available on the display.
167 public boolean alwaysOnAvailable() {
168 return (alwaysOnDisplayDebuggingEnabled() || alwaysOnDisplayAvailable())
169 && ambientDisplayAvailable();
173 * Returns if Always-on-Display functionality is available on the display for a specified user.
178 public boolean alwaysOnAvailableForUser(int user) {
179 return alwaysOnAvailable() && !accessibilityInversionEnabled(user);
183 public String ambientDisplayComponent() {
184 return mContext.getResources().getString(R.string.config_dozeComponent);
188 public boolean accessibilityInversionEnabled(int user) {
189 return boolSettingDefaultOff(Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED, user);
193 public boolean ambientDisplayAvailable() {
194 return !TextUtils.isEmpty(ambientDisplayComponent());
197 private boolean alwaysOnDisplayAvailable() {
198 return mContext.getResources().getBoolean(R.bool.config_dozeAlwaysOnDisplayAvailable);
201 private boolean alwaysOnDisplayDebuggingEnabled() {
202 return SystemProperties.getBoolean("debug.doze.aod", false) && Build.IS_DEBUGGABLE;
205 private boolean boolSettingDefaultOn(String name, int user) {
206 return boolSetting(name, user, 1);
209 private boolean boolSettingDefaultOff(String name, int user) {
210 return boolSetting(name, user, 0);
213 private boolean boolSetting(String name, int user, int def) {
214 return Settings.Secure.getIntForUser(mContext.getContentResolver(), name, def, user) != 0;