John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.statusbar.phone; |
| 18 | |
| 19 | import android.content.Context; |
Issei Suzuki | ca19e6e | 2019-02-26 12:39:11 +0100 | [diff] [blame] | 20 | import android.hardware.display.AmbientDisplayConfiguration; |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 21 | import android.os.PowerManager; |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 22 | import android.os.SystemProperties; |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 23 | import android.os.UserHandle; |
Adrian Roos | ebea7a7 | 2016-10-26 12:51:26 -0700 | [diff] [blame] | 24 | import android.provider.Settings; |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 25 | import android.util.MathUtils; |
| 26 | |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 27 | import com.android.internal.annotations.VisibleForTesting; |
Lucas Dupin | dff8cdf | 2018-01-09 13:01:01 -0800 | [diff] [blame] | 28 | import com.android.systemui.Dependency; |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 29 | import com.android.systemui.R; |
Lucas Dupin | 82aa163 | 2017-12-13 00:13:57 -0800 | [diff] [blame] | 30 | import com.android.systemui.doze.AlwaysOnDisplayPolicy; |
Lucas Dupin | cbe0596 | 2018-04-26 16:44:05 -0700 | [diff] [blame] | 31 | import com.android.systemui.doze.DozeScreenState; |
Lucas Dupin | dff8cdf | 2018-01-09 13:01:01 -0800 | [diff] [blame] | 32 | import com.android.systemui.tuner.TunerService; |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 33 | |
| 34 | import java.io.PrintWriter; |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 35 | |
Beverly | 1488f69 | 2019-06-07 09:32:46 -0400 | [diff] [blame] | 36 | /** |
| 37 | * Retrieve doze information |
| 38 | */ |
| 39 | public class DozeParameters implements TunerService.Tunable, |
| 40 | com.android.systemui.plugins.statusbar.DozeParameters { |
Selim Cinek | bb998c9 | 2015-09-22 10:05:29 +0200 | [diff] [blame] | 41 | private static final int MAX_DURATION = 60 * 1000; |
Selim Cinek | 0dd5a6b | 2018-05-15 13:15:42 -0700 | [diff] [blame] | 42 | public static final boolean FORCE_NO_BLANKING = |
| 43 | SystemProperties.getBoolean("debug.force_no_blanking", false); |
Lucas Dupin | ee63c37 | 2018-08-03 11:58:24 -0700 | [diff] [blame] | 44 | public static final boolean FORCE_BLANKING = |
| 45 | SystemProperties.getBoolean("debug.force_blanking", false); |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 46 | |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 47 | private static DozeParameters sInstance; |
| 48 | |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 49 | private final Context mContext; |
Adrian Roos | 0261fb2 | 2017-03-07 20:20:35 +0000 | [diff] [blame] | 50 | private final AmbientDisplayConfiguration mAmbientDisplayConfiguration; |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 51 | private final PowerManager mPowerManager; |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 52 | |
Lucas Dupin | 82aa163 | 2017-12-13 00:13:57 -0800 | [diff] [blame] | 53 | private final AlwaysOnDisplayPolicy mAlwaysOnPolicy; |
Adrian Roos | 5753f05 | 2016-07-13 10:30:37 -0700 | [diff] [blame] | 54 | |
Lucas Dupin | dff8cdf | 2018-01-09 13:01:01 -0800 | [diff] [blame] | 55 | private boolean mDozeAlwaysOn; |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 56 | private boolean mControlScreenOffAnimation; |
Lucas Dupin | dff8cdf | 2018-01-09 13:01:01 -0800 | [diff] [blame] | 57 | |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 58 | public static DozeParameters getInstance(Context context) { |
| 59 | if (sInstance == null) { |
| 60 | sInstance = new DozeParameters(context); |
| 61 | } |
| 62 | return sInstance; |
| 63 | } |
| 64 | |
| 65 | @VisibleForTesting |
| 66 | protected DozeParameters(Context context) { |
Adrian Roos | 2f5a385 | 2018-04-23 17:48:08 +0200 | [diff] [blame] | 67 | mContext = context.getApplicationContext(); |
Adrian Roos | 0261fb2 | 2017-03-07 20:20:35 +0000 | [diff] [blame] | 68 | mAmbientDisplayConfiguration = new AmbientDisplayConfiguration(mContext); |
Adrian Roos | 2f5a385 | 2018-04-23 17:48:08 +0200 | [diff] [blame] | 69 | mAlwaysOnPolicy = new AlwaysOnDisplayPolicy(mContext); |
Lucas Dupin | dff8cdf | 2018-01-09 13:01:01 -0800 | [diff] [blame] | 70 | |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 71 | mControlScreenOffAnimation = !getDisplayNeedsBlanking(); |
| 72 | mPowerManager = mContext.getSystemService(PowerManager.class); |
| 73 | mPowerManager.setDozeAfterScreenOff(!mControlScreenOffAnimation); |
| 74 | |
Lucas Dupin | dff8cdf | 2018-01-09 13:01:01 -0800 | [diff] [blame] | 75 | Dependency.get(TunerService.class).addTunable(this, Settings.Secure.DOZE_ALWAYS_ON, |
| 76 | Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED); |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | public void dump(PrintWriter pw) { |
| 80 | pw.println(" DozeParameters:"); |
John Spurlock | 190d026 | 2014-09-14 15:39:13 -0400 | [diff] [blame] | 81 | pw.print(" getDisplayStateSupported(): "); pw.println(getDisplayStateSupported()); |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 82 | pw.print(" getPulseDuration(): "); pw.println(getPulseDuration()); |
| 83 | pw.print(" getPulseInDuration(): "); pw.println(getPulseInDuration()); |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 84 | pw.print(" getPulseInVisibleDuration(): "); pw.println(getPulseVisibleDuration()); |
| 85 | pw.print(" getPulseOutDuration(): "); pw.println(getPulseOutDuration()); |
John Spurlock | 190d026 | 2014-09-14 15:39:13 -0400 | [diff] [blame] | 86 | pw.print(" getPulseOnSigMotion(): "); pw.println(getPulseOnSigMotion()); |
| 87 | pw.print(" getVibrateOnSigMotion(): "); pw.println(getVibrateOnSigMotion()); |
John Spurlock | 190d026 | 2014-09-14 15:39:13 -0400 | [diff] [blame] | 88 | pw.print(" getVibrateOnPickup(): "); pw.println(getVibrateOnPickup()); |
John Spurlock | 686e4d5 | 2014-11-20 21:48:09 -0500 | [diff] [blame] | 89 | pw.print(" getProxCheckBeforePulse(): "); pw.println(getProxCheckBeforePulse()); |
John Spurlock | 50a8ea6 | 2014-09-16 09:12:03 -0400 | [diff] [blame] | 90 | pw.print(" getPickupVibrationThreshold(): "); pw.println(getPickupVibrationThreshold()); |
John Spurlock | 190d026 | 2014-09-14 15:39:13 -0400 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | public boolean getDisplayStateSupported() { |
| 94 | return getBoolean("doze.display.supported", R.bool.doze_display_state_supported); |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 95 | } |
| 96 | |
Adrian Roos | a1e6b31 | 2017-03-28 16:20:34 -0700 | [diff] [blame] | 97 | public boolean getDozeSuspendDisplayStateSupported() { |
| 98 | return mContext.getResources().getBoolean(R.bool.doze_suspend_display_state_supported); |
| 99 | } |
| 100 | |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 101 | public int getPulseDuration() { |
| 102 | return getPulseInDuration() + getPulseVisibleDuration() + getPulseOutDuration(); |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 103 | } |
| 104 | |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 105 | public float getScreenBrightnessDoze() { |
| 106 | return mContext.getResources().getInteger( |
| 107 | com.android.internal.R.integer.config_screenBrightnessDoze) / 255f; |
| 108 | } |
| 109 | |
Lucas Dupin | 9e3fa10 | 2017-11-08 17:16:55 -0800 | [diff] [blame] | 110 | public int getPulseInDuration() { |
| 111 | return getInt("doze.pulse.duration.in", R.integer.doze_pulse_duration_in); |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | public int getPulseVisibleDuration() { |
| 115 | return getInt("doze.pulse.duration.visible", R.integer.doze_pulse_duration_visible); |
| 116 | } |
| 117 | |
| 118 | public int getPulseOutDuration() { |
| 119 | return getInt("doze.pulse.duration.out", R.integer.doze_pulse_duration_out); |
| 120 | } |
| 121 | |
John Spurlock | 190d026 | 2014-09-14 15:39:13 -0400 | [diff] [blame] | 122 | public boolean getPulseOnSigMotion() { |
| 123 | return getBoolean("doze.pulse.sigmotion", R.bool.doze_pulse_on_significant_motion); |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 124 | } |
| 125 | |
John Spurlock | 190d026 | 2014-09-14 15:39:13 -0400 | [diff] [blame] | 126 | public boolean getVibrateOnSigMotion() { |
| 127 | return SystemProperties.getBoolean("doze.vibrate.sigmotion", false); |
| 128 | } |
| 129 | |
John Spurlock | 190d026 | 2014-09-14 15:39:13 -0400 | [diff] [blame] | 130 | public boolean getVibrateOnPickup() { |
| 131 | return SystemProperties.getBoolean("doze.vibrate.pickup", false); |
| 132 | } |
| 133 | |
John Spurlock | 686e4d5 | 2014-11-20 21:48:09 -0500 | [diff] [blame] | 134 | public boolean getProxCheckBeforePulse() { |
| 135 | return getBoolean("doze.pulse.proxcheck", R.bool.doze_proximity_check_before_pulse); |
| 136 | } |
| 137 | |
John Spurlock | 50a8ea6 | 2014-09-16 09:12:03 -0400 | [diff] [blame] | 138 | public int getPickupVibrationThreshold() { |
| 139 | return getInt("doze.pickup.vibration.threshold", R.integer.doze_pickup_vibration_threshold); |
| 140 | } |
| 141 | |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 142 | /** |
Lucas Dupin | 82aa163 | 2017-12-13 00:13:57 -0800 | [diff] [blame] | 143 | * For how long a wallpaper can be visible in AoD before it fades aways. |
| 144 | * @return duration in millis. |
| 145 | */ |
| 146 | public long getWallpaperAodDuration() { |
Lucas Dupin | 00be88f | 2019-01-03 17:50:52 -0800 | [diff] [blame] | 147 | if (shouldControlScreenOff()) { |
Lucas Dupin | de64ee0 | 2018-12-21 14:45:12 -0800 | [diff] [blame] | 148 | return DozeScreenState.ENTER_DOZE_HIDE_WALLPAPER_DELAY; |
| 149 | } |
| 150 | return mAlwaysOnPolicy.wallpaperVisibilityDuration; |
Lucas Dupin | 82aa163 | 2017-12-13 00:13:57 -0800 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | /** |
| 154 | * How long it takes for the wallpaper fade away (Animation duration.) |
| 155 | * @return duration in millis. |
| 156 | */ |
| 157 | public long getWallpaperFadeOutDuration() { |
| 158 | return mAlwaysOnPolicy.wallpaperFadeOutDuration; |
| 159 | } |
| 160 | |
| 161 | /** |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 162 | * Checks if always on is available and enabled for the current user. |
| 163 | * @return {@code true} if enabled and available. |
| 164 | */ |
Adrian Roos | ebea7a7 | 2016-10-26 12:51:26 -0700 | [diff] [blame] | 165 | public boolean getAlwaysOn() { |
Lucas Dupin | dff8cdf | 2018-01-09 13:01:01 -0800 | [diff] [blame] | 166 | return mDozeAlwaysOn; |
Adrian Roos | ebea7a7 | 2016-10-26 12:51:26 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Lucas Dupin | 43d0d73 | 2017-11-16 11:23:49 -0800 | [diff] [blame] | 169 | /** |
| 170 | * Some screens need to be completely black before changing the display power mode, |
| 171 | * unexpected behavior might happen if this parameter isn't respected. |
| 172 | * |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 173 | * @return {@code true} if screen needs to be completely black before a power transition. |
Lucas Dupin | 43d0d73 | 2017-11-16 11:23:49 -0800 | [diff] [blame] | 174 | */ |
| 175 | public boolean getDisplayNeedsBlanking() { |
Lucas Dupin | ee63c37 | 2018-08-03 11:58:24 -0700 | [diff] [blame] | 176 | return FORCE_BLANKING || !FORCE_NO_BLANKING && mContext.getResources().getBoolean( |
Lucas Dupin | 43d0d73 | 2017-11-16 11:23:49 -0800 | [diff] [blame] | 177 | com.android.internal.R.bool.config_displayBlanksAfterDoze); |
| 178 | } |
| 179 | |
Lucas Dupin | 16cfe45 | 2018-02-08 13:14:50 -0800 | [diff] [blame] | 180 | public boolean shouldControlScreenOff() { |
| 181 | return mControlScreenOffAnimation; |
| 182 | } |
| 183 | |
| 184 | public void setControlScreenOffAnimation(boolean controlScreenOffAnimation) { |
| 185 | if (mControlScreenOffAnimation == controlScreenOffAnimation) { |
| 186 | return; |
| 187 | } |
| 188 | mControlScreenOffAnimation = controlScreenOffAnimation; |
| 189 | getPowerManager().setDozeAfterScreenOff(!controlScreenOffAnimation); |
| 190 | } |
| 191 | |
| 192 | @VisibleForTesting |
| 193 | protected PowerManager getPowerManager() { |
| 194 | return mPowerManager; |
Lucas Dupin | 43d0d73 | 2017-11-16 11:23:49 -0800 | [diff] [blame] | 195 | } |
| 196 | |
John Spurlock | 190d026 | 2014-09-14 15:39:13 -0400 | [diff] [blame] | 197 | private boolean getBoolean(String propName, int resId) { |
| 198 | return SystemProperties.getBoolean(propName, mContext.getResources().getBoolean(resId)); |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | private int getInt(String propName, int resId) { |
| 202 | int value = SystemProperties.getInt(propName, mContext.getResources().getInteger(resId)); |
| 203 | return MathUtils.constrain(value, 0, MAX_DURATION); |
| 204 | } |
| 205 | |
| 206 | private String getString(String propName, int resId) { |
| 207 | return SystemProperties.get(propName, mContext.getString(resId)); |
| 208 | } |
| 209 | |
Lucas Dupin | fac2e8e | 2019-06-27 16:10:19 -0700 | [diff] [blame] | 210 | public boolean getPickupPerformsProxCheck() { |
| 211 | return mContext.getResources().getBoolean(R.bool.doze_pickup_performs_proximity_check); |
Adrian Roos | 5753f05 | 2016-07-13 10:30:37 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Adrian Roos | 67cca74 | 2017-04-13 16:52:51 -0700 | [diff] [blame] | 214 | public int getPulseVisibleDurationExtended() { |
| 215 | return 2 * getPulseVisibleDuration(); |
| 216 | } |
| 217 | |
Adrian Roos | 44198f5 | 2017-06-02 12:50:38 -0700 | [diff] [blame] | 218 | public boolean doubleTapReportsTouchCoordinates() { |
| 219 | return mContext.getResources().getBoolean(R.bool.doze_double_tap_reports_touch_coordinates); |
| 220 | } |
| 221 | |
Lucas Dupin | dff8cdf | 2018-01-09 13:01:01 -0800 | [diff] [blame] | 222 | @Override |
| 223 | public void onTuningChanged(String key, String newValue) { |
| 224 | mDozeAlwaysOn = mAmbientDisplayConfiguration.alwaysOnEnabled(UserHandle.USER_CURRENT); |
| 225 | } |
Adrian Roos | 5753f05 | 2016-07-13 10:30:37 -0700 | [diff] [blame] | 226 | |
Adrian Roos | 2f5a385 | 2018-04-23 17:48:08 +0200 | [diff] [blame] | 227 | public AlwaysOnDisplayPolicy getPolicy() { |
| 228 | return mAlwaysOnPolicy; |
| 229 | } |
John Spurlock | d06aa57 | 2014-09-10 10:40:49 -0400 | [diff] [blame] | 230 | } |