blob: c45b8ed52187907f966a48a05b5ca4f898f0f8c8 [file] [log] [blame]
Adrian Roosb7e4e102016-10-14 13:03:45 -07001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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
Issei Suzukica19e6e2019-02-26 12:39:11 +010014 * limitations under the License.
Adrian Roosb7e4e102016-10-14 13:03:45 -070015 */
16
Issei Suzukica19e6e2019-02-26 12:39:11 +010017package android.hardware.display;
Adrian Roosb7e4e102016-10-14 13:03:45 -070018
Issei Suzukica19e6e2019-02-26 12:39:11 +010019import android.annotation.TestApi;
Adrian Roosb7e4e102016-10-14 13:03:45 -070020import android.content.Context;
Adrian Roos0261fb22017-03-07 20:20:35 +000021import android.os.Build;
Michael Wright80367992017-05-10 19:49:06 +010022import android.os.SystemProperties;
Adrian Roosb7e4e102016-10-14 13:03:45 -070023import android.provider.Settings;
24import android.text.TextUtils;
25
Lucas Dupin70bda672018-12-27 15:43:40 -080026import com.android.internal.R;
27
Issei Suzukica19e6e2019-02-26 12:39:11 +010028/**
29 * AmbientDisplayConfiguration encapsulates reading access to the configuration of ambient display.
30 *
31 * {@hide}
32 */
33@TestApi
Adrian Roosb7e4e102016-10-14 13:03:45 -070034public class AmbientDisplayConfiguration {
35
36 private final Context mContext;
Lucas Dupin1e02f342018-06-13 12:54:29 -070037 private final boolean mAlwaysOnByDefault;
Adrian Roosb7e4e102016-10-14 13:03:45 -070038
Issei Suzukica19e6e2019-02-26 12:39:11 +010039 /** {@hide} */
40 @TestApi
Adrian Roosb7e4e102016-10-14 13:03:45 -070041 public AmbientDisplayConfiguration(Context context) {
42 mContext = context;
Lucas Dupin1e02f342018-06-13 12:54:29 -070043 mAlwaysOnByDefault = mContext.getResources().getBoolean(R.bool.config_dozeAlwaysOnEnabled);
Adrian Roosb7e4e102016-10-14 13:03:45 -070044 }
Adrian Roos22a905e2017-03-07 12:05:57 -080045
Issei Suzukica19e6e2019-02-26 12:39:11 +010046 /** {@hide} */
Adrian Roosb7e4e102016-10-14 13:03:45 -070047 public boolean enabled(int user) {
48 return pulseOnNotificationEnabled(user)
Adrian Roosd0963a02017-05-15 14:33:37 -070049 || pulseOnLongPressEnabled(user)
Lucas Dupin70bda672018-12-27 15:43:40 -080050 || alwaysOnEnabled(user)
Lucas Dupin62206cc2019-03-25 16:27:51 -070051 || wakeScreenGestureEnabled(user)
52 || pickupGestureEnabled(user)
53 || tapGestureEnabled(user)
54 || doubleTapGestureEnabled(user);
Adrian Roosb7e4e102016-10-14 13:03:45 -070055 }
Adrian Roos22a905e2017-03-07 12:05:57 -080056
Issei Suzukica19e6e2019-02-26 12:39:11 +010057 /** {@hide} */
Adrian Roosb7e4e102016-10-14 13:03:45 -070058 public boolean pulseOnNotificationEnabled(int user) {
Issei Suzukica19e6e2019-02-26 12:39:11 +010059 return boolSettingDefaultOn(Settings.Secure.DOZE_ENABLED, user)
60 && pulseOnNotificationAvailable();
Adrian Roosb7e4e102016-10-14 13:03:45 -070061 }
62
Issei Suzukica19e6e2019-02-26 12:39:11 +010063 /** {@hide} */
Adrian Roosb7e4e102016-10-14 13:03:45 -070064 public boolean pulseOnNotificationAvailable() {
65 return ambientDisplayAvailable();
66 }
67
Issei Suzukica19e6e2019-02-26 12:39:11 +010068 /** {@hide} */
Lucas Dupin4359b552018-08-09 15:07:54 -070069 public boolean pickupGestureEnabled(int user) {
70 return boolSettingDefaultOn(Settings.Secure.DOZE_PICK_UP_GESTURE, user)
71 && dozePickupSensorAvailable();
Adrian Roosb7e4e102016-10-14 13:03:45 -070072 }
Adrian Roos22a905e2017-03-07 12:05:57 -080073
Issei Suzukica19e6e2019-02-26 12:39:11 +010074 /** {@hide} */
Lucas Dupin4359b552018-08-09 15:07:54 -070075 public boolean dozePickupSensorAvailable() {
Matthew Fritze3461bb42018-05-21 13:12:36 -070076 return mContext.getResources().getBoolean(R.bool.config_dozePulsePickup);
Adrian Roosb7e4e102016-10-14 13:03:45 -070077 }
Adrian Roos22a905e2017-03-07 12:05:57 -080078
Issei Suzukica19e6e2019-02-26 12:39:11 +010079 /** {@hide} */
Lucas Dupind43bf702019-01-15 13:40:42 -080080 public boolean tapGestureEnabled(int user) {
81 return boolSettingDefaultOn(Settings.Secure.DOZE_TAP_SCREEN_GESTURE, user)
82 && tapSensorAvailable();
83 }
84
Issei Suzukica19e6e2019-02-26 12:39:11 +010085 /** {@hide} */
Lucas Dupind43bf702019-01-15 13:40:42 -080086 public boolean tapSensorAvailable() {
87 return !TextUtils.isEmpty(tapSensorType());
88 }
89
Issei Suzukica19e6e2019-02-26 12:39:11 +010090 /** {@hide} */
Lucas Dupin4359b552018-08-09 15:07:54 -070091 public boolean doubleTapGestureEnabled(int user) {
92 return boolSettingDefaultOn(Settings.Secure.DOZE_DOUBLE_TAP_GESTURE, user)
93 && doubleTapSensorAvailable();
Matthew Fritze3461bb42018-05-21 13:12:36 -070094 }
95
Issei Suzukica19e6e2019-02-26 12:39:11 +010096 /** {@hide} */
Matthew Fritze3461bb42018-05-21 13:12:36 -070097 public boolean doubleTapSensorAvailable() {
98 return !TextUtils.isEmpty(doubleTapSensorType());
Adrian Roosb7e4e102016-10-14 13:03:45 -070099 }
100
Issei Suzukica19e6e2019-02-26 12:39:11 +0100101 /** {@hide} */
Lucas Dupinde64ee02018-12-21 14:45:12 -0800102 public boolean wakeScreenGestureAvailable() {
Lucas Dupin3d951752018-10-10 12:00:40 -0700103 return mContext.getResources()
104 .getBoolean(R.bool.config_dozeWakeLockScreenSensorAvailable);
Lucas Dupinc81702e2018-08-09 15:41:55 -0700105 }
106
Issei Suzukica19e6e2019-02-26 12:39:11 +0100107 /** {@hide} */
Lucas Dupin323f9ff2018-08-27 16:55:56 -0700108 public boolean wakeScreenGestureEnabled(int user) {
109 return boolSettingDefaultOn(Settings.Secure.DOZE_WAKE_SCREEN_GESTURE, user)
110 && wakeScreenGestureAvailable();
111 }
112
Issei Suzukica19e6e2019-02-26 12:39:11 +0100113 /** {@hide} */
Lucas Dupin8a13aa72019-02-22 12:45:21 -0800114 public long getWakeLockScreenDebounce() {
115 return mContext.getResources().getInteger(R.integer.config_dozeWakeLockScreenDebounce);
116 }
117
Issei Suzukica19e6e2019-02-26 12:39:11 +0100118 /** {@hide} */
Adrian Roosb7e4e102016-10-14 13:03:45 -0700119 public String doubleTapSensorType() {
120 return mContext.getResources().getString(R.string.config_dozeDoubleTapSensorType);
121 }
122
Issei Suzukica19e6e2019-02-26 12:39:11 +0100123 /** {@hide} */
Lucas Dupind43bf702019-01-15 13:40:42 -0800124 public String tapSensorType() {
125 return mContext.getResources().getString(R.string.config_dozeTapSensorType);
126 }
127
Issei Suzukica19e6e2019-02-26 12:39:11 +0100128 /** {@hide} */
Adrian Roosd0963a02017-05-15 14:33:37 -0700129 public String longPressSensorType() {
130 return mContext.getResources().getString(R.string.config_dozeLongPressSensorType);
131 }
132
Issei Suzukica19e6e2019-02-26 12:39:11 +0100133 /** {@hide} */
Adrian Roosd0963a02017-05-15 14:33:37 -0700134 public boolean pulseOnLongPressEnabled(int user) {
135 return pulseOnLongPressAvailable() && boolSettingDefaultOff(
136 Settings.Secure.DOZE_PULSE_ON_LONG_PRESS, user);
137 }
138
139 private boolean pulseOnLongPressAvailable() {
140 return !TextUtils.isEmpty(longPressSensorType());
141 }
142
Issei Suzukica19e6e2019-02-26 12:39:11 +0100143 /**
144 * Returns if Always-on-Display functionality is enabled on the display for a specified user.
145 *
146 * {@hide}
147 */
148 @TestApi
Adrian Roos0261fb22017-03-07 20:20:35 +0000149 public boolean alwaysOnEnabled(int user) {
Lucas Dupin1e02f342018-06-13 12:54:29 -0700150 return boolSetting(Settings.Secure.DOZE_ALWAYS_ON, user, mAlwaysOnByDefault ? 1 : 0)
151 && alwaysOnAvailable() && !accessibilityInversionEnabled(user);
Adrian Roos0261fb22017-03-07 20:20:35 +0000152 }
153
Issei Suzukica19e6e2019-02-26 12:39:11 +0100154 /**
155 * Returns if Always-on-Display functionality is available on the display.
156 *
157 * {@hide}
158 */
159 @TestApi
Adrian Roos0261fb22017-03-07 20:20:35 +0000160 public boolean alwaysOnAvailable() {
Michael Wright80367992017-05-10 19:49:06 +0100161 return (alwaysOnDisplayDebuggingEnabled() || alwaysOnDisplayAvailable())
162 && ambientDisplayAvailable();
Adrian Roos0261fb22017-03-07 20:20:35 +0000163 }
164
Issei Suzukica19e6e2019-02-26 12:39:11 +0100165 /**
166 * Returns if Always-on-Display functionality is available on the display for a specified user.
167 *
168 * {@hide}
169 */
170 @TestApi
Geoffrey Pitsch3ba26232017-07-28 15:07:39 -0400171 public boolean alwaysOnAvailableForUser(int user) {
172 return alwaysOnAvailable() && !accessibilityInversionEnabled(user);
173 }
174
Issei Suzukica19e6e2019-02-26 12:39:11 +0100175 /** {@hide} */
Adrian Roosb7e4e102016-10-14 13:03:45 -0700176 public String ambientDisplayComponent() {
177 return mContext.getResources().getString(R.string.config_dozeComponent);
178 }
179
Issei Suzukica19e6e2019-02-26 12:39:11 +0100180 /** {@hide} */
Andrew Sapperstein5a71a0f2017-08-07 19:09:41 -0700181 public boolean accessibilityInversionEnabled(int user) {
Geoffrey Pitsch3ba26232017-07-28 15:07:39 -0400182 return boolSettingDefaultOff(Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED, user);
183 }
184
Issei Suzukica19e6e2019-02-26 12:39:11 +0100185 /** {@hide} */
Matthew Fritze3461bb42018-05-21 13:12:36 -0700186 public boolean ambientDisplayAvailable() {
Adrian Roosb7e4e102016-10-14 13:03:45 -0700187 return !TextUtils.isEmpty(ambientDisplayComponent());
188 }
189
Michael Wright80367992017-05-10 19:49:06 +0100190 private boolean alwaysOnDisplayAvailable() {
191 return mContext.getResources().getBoolean(R.bool.config_dozeAlwaysOnDisplayAvailable);
192 }
193
194 private boolean alwaysOnDisplayDebuggingEnabled() {
195 return SystemProperties.getBoolean("debug.doze.aod", false) && Build.IS_DEBUGGABLE;
196 }
197
Adrian Roos22a905e2017-03-07 12:05:57 -0800198 private boolean boolSettingDefaultOn(String name, int user) {
199 return boolSetting(name, user, 1);
Adrian Roosb7e4e102016-10-14 13:03:45 -0700200 }
201
Adrian Roos22a905e2017-03-07 12:05:57 -0800202 private boolean boolSettingDefaultOff(String name, int user) {
203 return boolSetting(name, user, 0);
204 }
205
206 private boolean boolSetting(String name, int user, int def) {
207 return Settings.Secure.getIntForUser(mContext.getContentResolver(), name, def, user) != 0;
208 }
Adrian Roosb7e4e102016-10-14 13:03:45 -0700209}