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