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 |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
| 17 | package com.android.internal.hardware; |
| 18 | |
| 19 | import com.android.internal.R; |
| 20 | |
| 21 | import android.content.Context; |
Adrian Roos | 0261fb2 | 2017-03-07 20:20:35 +0000 | [diff] [blame] | 22 | import android.os.Build; |
Michael Wright | 8036799 | 2017-05-10 19:49:06 +0100 | [diff] [blame] | 23 | import android.os.SystemProperties; |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 24 | import android.provider.Settings; |
| 25 | import android.text.TextUtils; |
| 26 | |
| 27 | public class AmbientDisplayConfiguration { |
| 28 | |
| 29 | private final Context mContext; |
Lucas Dupin | 1e02f34 | 2018-06-13 12:54:29 -0700 | [diff] [blame] | 30 | private final boolean mAlwaysOnByDefault; |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 31 | |
| 32 | public AmbientDisplayConfiguration(Context context) { |
| 33 | mContext = context; |
Lucas Dupin | 1e02f34 | 2018-06-13 12:54:29 -0700 | [diff] [blame] | 34 | mAlwaysOnByDefault = mContext.getResources().getBoolean(R.bool.config_dozeAlwaysOnEnabled); |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 35 | } |
Adrian Roos | 22a905e | 2017-03-07 12:05:57 -0800 | [diff] [blame] | 36 | |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 37 | public boolean enabled(int user) { |
| 38 | return pulseOnNotificationEnabled(user) |
| 39 | || pulseOnPickupEnabled(user) |
Adrian Roos | 0261fb2 | 2017-03-07 20:20:35 +0000 | [diff] [blame] | 40 | || pulseOnDoubleTapEnabled(user) |
Adrian Roos | d0963a0 | 2017-05-15 14:33:37 -0700 | [diff] [blame] | 41 | || pulseOnLongPressEnabled(user) |
Adrian Roos | 0261fb2 | 2017-03-07 20:20:35 +0000 | [diff] [blame] | 42 | || alwaysOnEnabled(user); |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 43 | } |
Adrian Roos | 22a905e | 2017-03-07 12:05:57 -0800 | [diff] [blame] | 44 | |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 45 | public boolean available() { |
| 46 | return pulseOnNotificationAvailable() || pulseOnPickupAvailable() |
| 47 | || pulseOnDoubleTapAvailable(); |
| 48 | } |
Adrian Roos | 22a905e | 2017-03-07 12:05:57 -0800 | [diff] [blame] | 49 | |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 50 | public boolean pulseOnNotificationEnabled(int user) { |
Adrian Roos | 22a905e | 2017-03-07 12:05:57 -0800 | [diff] [blame] | 51 | return boolSettingDefaultOn(Settings.Secure.DOZE_ENABLED, user) && pulseOnNotificationAvailable(); |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | public boolean pulseOnNotificationAvailable() { |
| 55 | return ambientDisplayAvailable(); |
| 56 | } |
| 57 | |
| 58 | public boolean pulseOnPickupEnabled(int user) { |
Geoffrey Pitsch | 7075308 | 2017-07-10 10:36:25 -0400 | [diff] [blame] | 59 | boolean settingEnabled = boolSettingDefaultOn(Settings.Secure.DOZE_PULSE_ON_PICK_UP, user); |
| 60 | return (settingEnabled || alwaysOnEnabled(user)) && pulseOnPickupAvailable(); |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 61 | } |
Adrian Roos | 22a905e | 2017-03-07 12:05:57 -0800 | [diff] [blame] | 62 | |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 63 | public boolean pulseOnPickupAvailable() { |
Matthew Fritze | 3461bb4 | 2018-05-21 13:12:36 -0700 | [diff] [blame] | 64 | return dozePulsePickupSensorAvailable() && ambientDisplayAvailable(); |
| 65 | } |
| 66 | |
| 67 | public boolean dozePulsePickupSensorAvailable() { |
| 68 | return mContext.getResources().getBoolean(R.bool.config_dozePulsePickup); |
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 | |
Geoffrey Pitsch | 7075308 | 2017-07-10 10:36:25 -0400 | [diff] [blame] | 71 | public boolean pulseOnPickupCanBeModified(int user) { |
| 72 | return !alwaysOnEnabled(user); |
| 73 | } |
| 74 | |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 75 | public boolean pulseOnDoubleTapEnabled(int user) { |
Adrian Roos | 22a905e | 2017-03-07 12:05:57 -0800 | [diff] [blame] | 76 | return boolSettingDefaultOn(Settings.Secure.DOZE_PULSE_ON_DOUBLE_TAP, user) |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 77 | && pulseOnDoubleTapAvailable(); |
| 78 | } |
| 79 | |
| 80 | public boolean pulseOnDoubleTapAvailable() { |
Matthew Fritze | 3461bb4 | 2018-05-21 13:12:36 -0700 | [diff] [blame] | 81 | return doubleTapSensorAvailable() && ambientDisplayAvailable(); |
| 82 | } |
| 83 | |
| 84 | public boolean doubleTapSensorAvailable() { |
| 85 | return !TextUtils.isEmpty(doubleTapSensorType()); |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | public String doubleTapSensorType() { |
| 89 | return mContext.getResources().getString(R.string.config_dozeDoubleTapSensorType); |
| 90 | } |
| 91 | |
Adrian Roos | d0963a0 | 2017-05-15 14:33:37 -0700 | [diff] [blame] | 92 | public String longPressSensorType() { |
| 93 | return mContext.getResources().getString(R.string.config_dozeLongPressSensorType); |
| 94 | } |
| 95 | |
| 96 | public boolean pulseOnLongPressEnabled(int user) { |
| 97 | return pulseOnLongPressAvailable() && boolSettingDefaultOff( |
| 98 | Settings.Secure.DOZE_PULSE_ON_LONG_PRESS, user); |
| 99 | } |
| 100 | |
| 101 | private boolean pulseOnLongPressAvailable() { |
| 102 | return !TextUtils.isEmpty(longPressSensorType()); |
| 103 | } |
| 104 | |
Adrian Roos | 0261fb2 | 2017-03-07 20:20:35 +0000 | [diff] [blame] | 105 | public boolean alwaysOnEnabled(int user) { |
Lucas Dupin | 1e02f34 | 2018-06-13 12:54:29 -0700 | [diff] [blame] | 106 | return boolSetting(Settings.Secure.DOZE_ALWAYS_ON, user, mAlwaysOnByDefault ? 1 : 0) |
| 107 | && alwaysOnAvailable() && !accessibilityInversionEnabled(user); |
Adrian Roos | 0261fb2 | 2017-03-07 20:20:35 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | public boolean alwaysOnAvailable() { |
Michael Wright | 8036799 | 2017-05-10 19:49:06 +0100 | [diff] [blame] | 111 | return (alwaysOnDisplayDebuggingEnabled() || alwaysOnDisplayAvailable()) |
| 112 | && ambientDisplayAvailable(); |
Adrian Roos | 0261fb2 | 2017-03-07 20:20:35 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Geoffrey Pitsch | 3ba2623 | 2017-07-28 15:07:39 -0400 | [diff] [blame] | 115 | public boolean alwaysOnAvailableForUser(int user) { |
| 116 | return alwaysOnAvailable() && !accessibilityInversionEnabled(user); |
| 117 | } |
| 118 | |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 119 | public String ambientDisplayComponent() { |
| 120 | return mContext.getResources().getString(R.string.config_dozeComponent); |
| 121 | } |
| 122 | |
Andrew Sapperstein | 5a71a0f | 2017-08-07 19:09:41 -0700 | [diff] [blame] | 123 | public boolean accessibilityInversionEnabled(int user) { |
Geoffrey Pitsch | 3ba2623 | 2017-07-28 15:07:39 -0400 | [diff] [blame] | 124 | return boolSettingDefaultOff(Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED, user); |
| 125 | } |
| 126 | |
Matthew Fritze | 3461bb4 | 2018-05-21 13:12:36 -0700 | [diff] [blame] | 127 | public boolean ambientDisplayAvailable() { |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 128 | return !TextUtils.isEmpty(ambientDisplayComponent()); |
| 129 | } |
| 130 | |
Michael Wright | 8036799 | 2017-05-10 19:49:06 +0100 | [diff] [blame] | 131 | private boolean alwaysOnDisplayAvailable() { |
| 132 | return mContext.getResources().getBoolean(R.bool.config_dozeAlwaysOnDisplayAvailable); |
| 133 | } |
| 134 | |
| 135 | private boolean alwaysOnDisplayDebuggingEnabled() { |
| 136 | return SystemProperties.getBoolean("debug.doze.aod", false) && Build.IS_DEBUGGABLE; |
| 137 | } |
| 138 | |
| 139 | |
Adrian Roos | 22a905e | 2017-03-07 12:05:57 -0800 | [diff] [blame] | 140 | private boolean boolSettingDefaultOn(String name, int user) { |
| 141 | return boolSetting(name, user, 1); |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Adrian Roos | 22a905e | 2017-03-07 12:05:57 -0800 | [diff] [blame] | 144 | private boolean boolSettingDefaultOff(String name, int user) { |
| 145 | return boolSetting(name, user, 0); |
| 146 | } |
| 147 | |
| 148 | private boolean boolSetting(String name, int user, int def) { |
| 149 | return Settings.Secure.getIntForUser(mContext.getContentResolver(), name, def, user) != 0; |
| 150 | } |
Adrian Roos | b7e4e10 | 2016-10-14 13:03:45 -0700 | [diff] [blame] | 151 | } |