blob: b122f199bc6ff5288254a6199b09bd3f4fbedeb4 [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 Dupine3218c12019-01-18 16:48:41 -080051 || wakeScreenGestureEnabled(user);
Adrian Roosb7e4e102016-10-14 13:03:45 -070052 }
Adrian Roos22a905e2017-03-07 12:05:57 -080053
Issei Suzukica19e6e2019-02-26 12:39:11 +010054 /** {@hide} */
Adrian Roosb7e4e102016-10-14 13:03:45 -070055 public boolean pulseOnNotificationEnabled(int user) {
Issei Suzukica19e6e2019-02-26 12:39:11 +010056 return boolSettingDefaultOn(Settings.Secure.DOZE_ENABLED, user)
57 && pulseOnNotificationAvailable();
Adrian Roosb7e4e102016-10-14 13:03:45 -070058 }
59
Issei Suzukica19e6e2019-02-26 12:39:11 +010060 /** {@hide} */
Adrian Roosb7e4e102016-10-14 13:03:45 -070061 public boolean pulseOnNotificationAvailable() {
62 return ambientDisplayAvailable();
63 }
64
Issei Suzukica19e6e2019-02-26 12:39:11 +010065 /** {@hide} */
Lucas Dupin4359b552018-08-09 15:07:54 -070066 public boolean pickupGestureEnabled(int user) {
67 return boolSettingDefaultOn(Settings.Secure.DOZE_PICK_UP_GESTURE, user)
68 && dozePickupSensorAvailable();
Adrian Roosb7e4e102016-10-14 13:03:45 -070069 }
Adrian Roos22a905e2017-03-07 12:05:57 -080070
Issei Suzukica19e6e2019-02-26 12:39:11 +010071 /** {@hide} */
Lucas Dupin4359b552018-08-09 15:07:54 -070072 public boolean dozePickupSensorAvailable() {
Matthew Fritze3461bb42018-05-21 13:12:36 -070073 return mContext.getResources().getBoolean(R.bool.config_dozePulsePickup);
Adrian Roosb7e4e102016-10-14 13:03:45 -070074 }
Adrian Roos22a905e2017-03-07 12:05:57 -080075
Issei Suzukica19e6e2019-02-26 12:39:11 +010076 /** {@hide} */
Lucas Dupind43bf702019-01-15 13:40:42 -080077 public boolean tapGestureEnabled(int user) {
78 return boolSettingDefaultOn(Settings.Secure.DOZE_TAP_SCREEN_GESTURE, user)
79 && tapSensorAvailable();
80 }
81
Issei Suzukica19e6e2019-02-26 12:39:11 +010082 /** {@hide} */
Lucas Dupind43bf702019-01-15 13:40:42 -080083 public boolean tapSensorAvailable() {
84 return !TextUtils.isEmpty(tapSensorType());
85 }
86
Issei Suzukica19e6e2019-02-26 12:39:11 +010087 /** {@hide} */
Lucas Dupin4359b552018-08-09 15:07:54 -070088 public boolean doubleTapGestureEnabled(int user) {
89 return boolSettingDefaultOn(Settings.Secure.DOZE_DOUBLE_TAP_GESTURE, user)
90 && doubleTapSensorAvailable();
Matthew Fritze3461bb42018-05-21 13:12:36 -070091 }
92
Issei Suzukica19e6e2019-02-26 12:39:11 +010093 /** {@hide} */
Matthew Fritze3461bb42018-05-21 13:12:36 -070094 public boolean doubleTapSensorAvailable() {
95 return !TextUtils.isEmpty(doubleTapSensorType());
Adrian Roosb7e4e102016-10-14 13:03:45 -070096 }
97
Issei Suzukica19e6e2019-02-26 12:39:11 +010098 /** {@hide} */
Lucas Dupinde64ee02018-12-21 14:45:12 -080099 public boolean wakeScreenGestureAvailable() {
Lucas Dupin3d951752018-10-10 12:00:40 -0700100 return mContext.getResources()
101 .getBoolean(R.bool.config_dozeWakeLockScreenSensorAvailable);
Lucas Dupinc81702e2018-08-09 15:41:55 -0700102 }
103
Issei Suzukica19e6e2019-02-26 12:39:11 +0100104 /** {@hide} */
Lucas Dupin323f9ff2018-08-27 16:55:56 -0700105 public boolean wakeScreenGestureEnabled(int user) {
106 return boolSettingDefaultOn(Settings.Secure.DOZE_WAKE_SCREEN_GESTURE, user)
107 && wakeScreenGestureAvailable();
108 }
109
Issei Suzukica19e6e2019-02-26 12:39:11 +0100110 /** {@hide} */
Lucas Dupin8a13aa72019-02-22 12:45:21 -0800111 public long getWakeLockScreenDebounce() {
112 return mContext.getResources().getInteger(R.integer.config_dozeWakeLockScreenDebounce);
113 }
114
Issei Suzukica19e6e2019-02-26 12:39:11 +0100115 /** {@hide} */
Adrian Roosb7e4e102016-10-14 13:03:45 -0700116 public String doubleTapSensorType() {
117 return mContext.getResources().getString(R.string.config_dozeDoubleTapSensorType);
118 }
119
Issei Suzukica19e6e2019-02-26 12:39:11 +0100120 /** {@hide} */
Lucas Dupind43bf702019-01-15 13:40:42 -0800121 public String tapSensorType() {
122 return mContext.getResources().getString(R.string.config_dozeTapSensorType);
123 }
124
Issei Suzukica19e6e2019-02-26 12:39:11 +0100125 /** {@hide} */
Adrian Roosd0963a02017-05-15 14:33:37 -0700126 public String longPressSensorType() {
127 return mContext.getResources().getString(R.string.config_dozeLongPressSensorType);
128 }
129
Issei Suzukica19e6e2019-02-26 12:39:11 +0100130 /** {@hide} */
Adrian Roosd0963a02017-05-15 14:33:37 -0700131 public boolean pulseOnLongPressEnabled(int user) {
132 return pulseOnLongPressAvailable() && boolSettingDefaultOff(
133 Settings.Secure.DOZE_PULSE_ON_LONG_PRESS, user);
134 }
135
136 private boolean pulseOnLongPressAvailable() {
137 return !TextUtils.isEmpty(longPressSensorType());
138 }
139
Issei Suzukica19e6e2019-02-26 12:39:11 +0100140 /**
141 * Returns if Always-on-Display functionality is enabled on the display for a specified user.
142 *
143 * {@hide}
144 */
145 @TestApi
Adrian Roos0261fb22017-03-07 20:20:35 +0000146 public boolean alwaysOnEnabled(int user) {
Lucas Dupin1e02f342018-06-13 12:54:29 -0700147 return boolSetting(Settings.Secure.DOZE_ALWAYS_ON, user, mAlwaysOnByDefault ? 1 : 0)
148 && alwaysOnAvailable() && !accessibilityInversionEnabled(user);
Adrian Roos0261fb22017-03-07 20:20:35 +0000149 }
150
Issei Suzukica19e6e2019-02-26 12:39:11 +0100151 /**
152 * Returns if Always-on-Display functionality is available on the display.
153 *
154 * {@hide}
155 */
156 @TestApi
Adrian Roos0261fb22017-03-07 20:20:35 +0000157 public boolean alwaysOnAvailable() {
Michael Wright80367992017-05-10 19:49:06 +0100158 return (alwaysOnDisplayDebuggingEnabled() || alwaysOnDisplayAvailable())
159 && ambientDisplayAvailable();
Adrian Roos0261fb22017-03-07 20:20:35 +0000160 }
161
Issei Suzukica19e6e2019-02-26 12:39:11 +0100162 /**
163 * Returns if Always-on-Display functionality is available on the display for a specified user.
164 *
165 * {@hide}
166 */
167 @TestApi
Geoffrey Pitsch3ba26232017-07-28 15:07:39 -0400168 public boolean alwaysOnAvailableForUser(int user) {
169 return alwaysOnAvailable() && !accessibilityInversionEnabled(user);
170 }
171
Issei Suzukica19e6e2019-02-26 12:39:11 +0100172 /** {@hide} */
Adrian Roosb7e4e102016-10-14 13:03:45 -0700173 public String ambientDisplayComponent() {
174 return mContext.getResources().getString(R.string.config_dozeComponent);
175 }
176
Issei Suzukica19e6e2019-02-26 12:39:11 +0100177 /** {@hide} */
Andrew Sapperstein5a71a0f2017-08-07 19:09:41 -0700178 public boolean accessibilityInversionEnabled(int user) {
Geoffrey Pitsch3ba26232017-07-28 15:07:39 -0400179 return boolSettingDefaultOff(Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED, user);
180 }
181
Issei Suzukica19e6e2019-02-26 12:39:11 +0100182 /** {@hide} */
Matthew Fritze3461bb42018-05-21 13:12:36 -0700183 public boolean ambientDisplayAvailable() {
Adrian Roosb7e4e102016-10-14 13:03:45 -0700184 return !TextUtils.isEmpty(ambientDisplayComponent());
185 }
186
Michael Wright80367992017-05-10 19:49:06 +0100187 private boolean alwaysOnDisplayAvailable() {
188 return mContext.getResources().getBoolean(R.bool.config_dozeAlwaysOnDisplayAvailable);
189 }
190
191 private boolean alwaysOnDisplayDebuggingEnabled() {
192 return SystemProperties.getBoolean("debug.doze.aod", false) && Build.IS_DEBUGGABLE;
193 }
194
Adrian Roos22a905e2017-03-07 12:05:57 -0800195 private boolean boolSettingDefaultOn(String name, int user) {
196 return boolSetting(name, user, 1);
Adrian Roosb7e4e102016-10-14 13:03:45 -0700197 }
198
Adrian Roos22a905e2017-03-07 12:05:57 -0800199 private boolean boolSettingDefaultOff(String name, int user) {
200 return boolSetting(name, user, 0);
201 }
202
203 private boolean boolSetting(String name, int user, int def) {
204 return Settings.Secure.getIntForUser(mContext.getContentResolver(), name, def, user) != 0;
205 }
Adrian Roosb7e4e102016-10-14 13:03:45 -0700206}