Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 1 | /* |
| 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 Suzuki | ca19e6e | 2019-02-26 12:39:11 +0100 | [diff] [blame] | 14 | * limitations under the License. |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
Issei Suzuki | ca19e6e | 2019-02-26 12:39:11 +0100 | [diff] [blame] | 17 | package android.hardware.display; |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 18 | |
Issei Suzuki | ca19e6e | 2019-02-26 12:39:11 +0100 | [diff] [blame] | 19 | import android.annotation.TestApi; |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 20 | import android.content.Context; |
Adrian Roos | 0261fb2 | 2017-03-07 20:20:35 +0000 | [diff] [blame] | 21 | import android.os.Build; |
Michael Wright | 8036799 | 2017-05-10 19:49:06 +0100 | [diff] [blame] | 22 | import android.os.SystemProperties; |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 23 | import android.provider.Settings; |
| 24 | import android.text.TextUtils; |
| 25 | |
Lucas Dupin | 70bda67 | 2018-12-27 15:43:40 -0800 | [diff] [blame] | 26 | import com.android.internal.R; |
| 27 | |
Issei Suzuki | ca19e6e | 2019-02-26 12:39:11 +0100 | [diff] [blame] | 28 | /** |
| 29 | * AmbientDisplayConfiguration encapsulates reading access to the configuration of ambient display. |
| 30 | * |
| 31 | * {@hide} |
| 32 | */ |
| 33 | @TestApi |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 34 | public class AmbientDisplayConfiguration { |
| 35 | |
| 36 | private final Context mContext; |
Lucas Dupin | 1e02f34 | 2018-06-13 12:54:29 -0700 | [diff] [blame] | 37 | private final boolean mAlwaysOnByDefault; |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 38 | |
Issei Suzuki | ca19e6e | 2019-02-26 12:39:11 +0100 | [diff] [blame] | 39 | /** {@hide} */ |
| 40 | @TestApi |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 41 | public AmbientDisplayConfiguration(Context context) { |
| 42 | mContext = context; |
Lucas Dupin | 1e02f34 | 2018-06-13 12:54:29 -0700 | [diff] [blame] | 43 | mAlwaysOnByDefault = mContext.getResources().getBoolean(R.bool.config_dozeAlwaysOnEnabled); |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 44 | } |
Adrian Roos | 22a905e | 2017-03-07 12:05:57 -0800 | [diff] [blame] | 45 | |
Issei Suzuki | ca19e6e | 2019-02-26 12:39:11 +0100 | [diff] [blame] | 46 | /** {@hide} */ |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 47 | public boolean enabled(int user) { |
| 48 | return pulseOnNotificationEnabled(user) |
Adrian Roos | d0963a0 | 2017-05-15 14:33:37 -0700 | [diff] [blame] | 49 | || pulseOnLongPressEnabled(user) |
Lucas Dupin | 70bda67 | 2018-12-27 15:43:40 -0800 | [diff] [blame] | 50 | || alwaysOnEnabled(user) |
Lucas Dupin | 62206cc | 2019-03-25 16:27:51 -0700 | [diff] [blame] | 51 | || wakeScreenGestureEnabled(user) |
| 52 | || pickupGestureEnabled(user) |
| 53 | || tapGestureEnabled(user) |
| 54 | || doubleTapGestureEnabled(user); |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 55 | } |
Adrian Roos | 22a905e | 2017-03-07 12:05:57 -0800 | [diff] [blame] | 56 | |
Issei Suzuki | ca19e6e | 2019-02-26 12:39:11 +0100 | [diff] [blame] | 57 | /** {@hide} */ |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 58 | public boolean pulseOnNotificationEnabled(int user) { |
Issei Suzuki | ca19e6e | 2019-02-26 12:39:11 +0100 | [diff] [blame] | 59 | return boolSettingDefaultOn(Settings.Secure.DOZE_ENABLED, user) |
| 60 | && pulseOnNotificationAvailable(); |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Issei Suzuki | ca19e6e | 2019-02-26 12:39:11 +0100 | [diff] [blame] | 63 | /** {@hide} */ |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 64 | public boolean pulseOnNotificationAvailable() { |
| 65 | return ambientDisplayAvailable(); |
| 66 | } |
| 67 | |
Issei Suzuki | ca19e6e | 2019-02-26 12:39:11 +0100 | [diff] [blame] | 68 | /** {@hide} */ |
Lucas Dupin | 4359b55 | 2018-08-09 15:07:54 -0700 | [diff] [blame] | 69 | public boolean pickupGestureEnabled(int user) { |
| 70 | return boolSettingDefaultOn(Settings.Secure.DOZE_PICK_UP_GESTURE, user) |
| 71 | && dozePickupSensorAvailable(); |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 72 | } |
Adrian Roos | 22a905e | 2017-03-07 12:05:57 -0800 | [diff] [blame] | 73 | |
Issei Suzuki | ca19e6e | 2019-02-26 12:39:11 +0100 | [diff] [blame] | 74 | /** {@hide} */ |
Lucas Dupin | 4359b55 | 2018-08-09 15:07:54 -0700 | [diff] [blame] | 75 | public boolean dozePickupSensorAvailable() { |
Matthew Fritze | 3461bb4 | 2018-05-21 13:12:36 -0700 | [diff] [blame] | 76 | return mContext.getResources().getBoolean(R.bool.config_dozePulsePickup); |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 77 | } |
Adrian Roos | 22a905e | 2017-03-07 12:05:57 -0800 | [diff] [blame] | 78 | |
Issei Suzuki | ca19e6e | 2019-02-26 12:39:11 +0100 | [diff] [blame] | 79 | /** {@hide} */ |
Lucas Dupin | d43bf70 | 2019-01-15 13:40:42 -0800 | [diff] [blame] | 80 | public boolean tapGestureEnabled(int user) { |
| 81 | return boolSettingDefaultOn(Settings.Secure.DOZE_TAP_SCREEN_GESTURE, user) |
| 82 | && tapSensorAvailable(); |
| 83 | } |
| 84 | |
Issei Suzuki | ca19e6e | 2019-02-26 12:39:11 +0100 | [diff] [blame] | 85 | /** {@hide} */ |
Lucas Dupin | d43bf70 | 2019-01-15 13:40:42 -0800 | [diff] [blame] | 86 | public boolean tapSensorAvailable() { |
| 87 | return !TextUtils.isEmpty(tapSensorType()); |
| 88 | } |
| 89 | |
Issei Suzuki | ca19e6e | 2019-02-26 12:39:11 +0100 | [diff] [blame] | 90 | /** {@hide} */ |
Lucas Dupin | 4359b55 | 2018-08-09 15:07:54 -0700 | [diff] [blame] | 91 | public boolean doubleTapGestureEnabled(int user) { |
| 92 | return boolSettingDefaultOn(Settings.Secure.DOZE_DOUBLE_TAP_GESTURE, user) |
| 93 | && doubleTapSensorAvailable(); |
Matthew Fritze | 3461bb4 | 2018-05-21 13:12:36 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Issei Suzuki | ca19e6e | 2019-02-26 12:39:11 +0100 | [diff] [blame] | 96 | /** {@hide} */ |
Matthew Fritze | 3461bb4 | 2018-05-21 13:12:36 -0700 | [diff] [blame] | 97 | public boolean doubleTapSensorAvailable() { |
| 98 | return !TextUtils.isEmpty(doubleTapSensorType()); |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Issei Suzuki | ca19e6e | 2019-02-26 12:39:11 +0100 | [diff] [blame] | 101 | /** {@hide} */ |
Lucas Dupin | de64ee0 | 2018-12-21 14:45:12 -0800 | [diff] [blame] | 102 | public boolean wakeScreenGestureAvailable() { |
Lucas Dupin | 3d95175 | 2018-10-10 12:00:40 -0700 | [diff] [blame] | 103 | return mContext.getResources() |
| 104 | .getBoolean(R.bool.config_dozeWakeLockScreenSensorAvailable); |
Lucas Dupin | c81702e | 2018-08-09 15:41:55 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Issei Suzuki | ca19e6e | 2019-02-26 12:39:11 +0100 | [diff] [blame] | 107 | /** {@hide} */ |
Lucas Dupin | 323f9ff | 2018-08-27 16:55:56 -0700 | [diff] [blame] | 108 | public boolean wakeScreenGestureEnabled(int user) { |
| 109 | return boolSettingDefaultOn(Settings.Secure.DOZE_WAKE_SCREEN_GESTURE, user) |
| 110 | && wakeScreenGestureAvailable(); |
| 111 | } |
| 112 | |
Issei Suzuki | ca19e6e | 2019-02-26 12:39:11 +0100 | [diff] [blame] | 113 | /** {@hide} */ |
Lucas Dupin | 8a13aa7 | 2019-02-22 12:45:21 -0800 | [diff] [blame] | 114 | public long getWakeLockScreenDebounce() { |
| 115 | return mContext.getResources().getInteger(R.integer.config_dozeWakeLockScreenDebounce); |
| 116 | } |
| 117 | |
Issei Suzuki | ca19e6e | 2019-02-26 12:39:11 +0100 | [diff] [blame] | 118 | /** {@hide} */ |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 119 | public String doubleTapSensorType() { |
| 120 | return mContext.getResources().getString(R.string.config_dozeDoubleTapSensorType); |
| 121 | } |
| 122 | |
Issei Suzuki | ca19e6e | 2019-02-26 12:39:11 +0100 | [diff] [blame] | 123 | /** {@hide} */ |
Lucas Dupin | d43bf70 | 2019-01-15 13:40:42 -0800 | [diff] [blame] | 124 | public String tapSensorType() { |
| 125 | return mContext.getResources().getString(R.string.config_dozeTapSensorType); |
| 126 | } |
| 127 | |
Issei Suzuki | ca19e6e | 2019-02-26 12:39:11 +0100 | [diff] [blame] | 128 | /** {@hide} */ |
Adrian Roos | d0963a0 | 2017-05-15 14:33:37 -0700 | [diff] [blame] | 129 | public String longPressSensorType() { |
| 130 | return mContext.getResources().getString(R.string.config_dozeLongPressSensorType); |
| 131 | } |
| 132 | |
Issei Suzuki | ca19e6e | 2019-02-26 12:39:11 +0100 | [diff] [blame] | 133 | /** {@hide} */ |
Adrian Roos | d0963a0 | 2017-05-15 14:33:37 -0700 | [diff] [blame] | 134 | 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 Suzuki | ca19e6e | 2019-02-26 12:39:11 +0100 | [diff] [blame] | 143 | /** |
| 144 | * Returns if Always-on-Display functionality is enabled on the display for a specified user. |
| 145 | * |
| 146 | * {@hide} |
| 147 | */ |
| 148 | @TestApi |
Adrian Roos | 0261fb2 | 2017-03-07 20:20:35 +0000 | [diff] [blame] | 149 | public boolean alwaysOnEnabled(int user) { |
Lucas Dupin | 1e02f34 | 2018-06-13 12:54:29 -0700 | [diff] [blame] | 150 | return boolSetting(Settings.Secure.DOZE_ALWAYS_ON, user, mAlwaysOnByDefault ? 1 : 0) |
| 151 | && alwaysOnAvailable() && !accessibilityInversionEnabled(user); |
Adrian Roos | 0261fb2 | 2017-03-07 20:20:35 +0000 | [diff] [blame] | 152 | } |
| 153 | |
Issei Suzuki | ca19e6e | 2019-02-26 12:39:11 +0100 | [diff] [blame] | 154 | /** |
| 155 | * Returns if Always-on-Display functionality is available on the display. |
| 156 | * |
| 157 | * {@hide} |
| 158 | */ |
| 159 | @TestApi |
Adrian Roos | 0261fb2 | 2017-03-07 20:20:35 +0000 | [diff] [blame] | 160 | public boolean alwaysOnAvailable() { |
Michael Wright | 8036799 | 2017-05-10 19:49:06 +0100 | [diff] [blame] | 161 | return (alwaysOnDisplayDebuggingEnabled() || alwaysOnDisplayAvailable()) |
| 162 | && ambientDisplayAvailable(); |
Adrian Roos | 0261fb2 | 2017-03-07 20:20:35 +0000 | [diff] [blame] | 163 | } |
| 164 | |
Issei Suzuki | ca19e6e | 2019-02-26 12:39:11 +0100 | [diff] [blame] | 165 | /** |
| 166 | * Returns if Always-on-Display functionality is available on the display for a specified user. |
| 167 | * |
| 168 | * {@hide} |
| 169 | */ |
| 170 | @TestApi |
Geoffrey Pitsch | 3ba2623 | 2017-07-28 15:07:39 -0400 | [diff] [blame] | 171 | public boolean alwaysOnAvailableForUser(int user) { |
| 172 | return alwaysOnAvailable() && !accessibilityInversionEnabled(user); |
| 173 | } |
| 174 | |
Issei Suzuki | ca19e6e | 2019-02-26 12:39:11 +0100 | [diff] [blame] | 175 | /** {@hide} */ |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 176 | public String ambientDisplayComponent() { |
| 177 | return mContext.getResources().getString(R.string.config_dozeComponent); |
| 178 | } |
| 179 | |
Issei Suzuki | ca19e6e | 2019-02-26 12:39:11 +0100 | [diff] [blame] | 180 | /** {@hide} */ |
Andrew Sapperstein | 5a71a0f | 2017-08-07 19:09:41 -0700 | [diff] [blame] | 181 | public boolean accessibilityInversionEnabled(int user) { |
Geoffrey Pitsch | 3ba2623 | 2017-07-28 15:07:39 -0400 | [diff] [blame] | 182 | return boolSettingDefaultOff(Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED, user); |
| 183 | } |
| 184 | |
Issei Suzuki | ca19e6e | 2019-02-26 12:39:11 +0100 | [diff] [blame] | 185 | /** {@hide} */ |
Matthew Fritze | 3461bb4 | 2018-05-21 13:12:36 -0700 | [diff] [blame] | 186 | public boolean ambientDisplayAvailable() { |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 187 | return !TextUtils.isEmpty(ambientDisplayComponent()); |
| 188 | } |
| 189 | |
Michael Wright | 8036799 | 2017-05-10 19:49:06 +0100 | [diff] [blame] | 190 | 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 Roos | 22a905e | 2017-03-07 12:05:57 -0800 | [diff] [blame] | 198 | private boolean boolSettingDefaultOn(String name, int user) { |
| 199 | return boolSetting(name, user, 1); |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Adrian Roos | 22a905e | 2017-03-07 12:05:57 -0800 | [diff] [blame] | 202 | 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 Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 209 | } |