blob: 07bb4533c4e0b6b0727407fd8969185312797087 [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
14 * limitations under the License
15 */
16
17package com.android.internal.hardware;
18
19import com.android.internal.R;
20
21import android.content.Context;
Adrian Roos0261fb22017-03-07 20:20:35 +000022import android.os.Build;
Michael Wright80367992017-05-10 19:49:06 +010023import android.os.SystemProperties;
Adrian Roosb7e4e102016-10-14 13:03:45 -070024import android.provider.Settings;
25import android.text.TextUtils;
26
27public class AmbientDisplayConfiguration {
28
29 private final Context mContext;
Lucas Dupin1e02f342018-06-13 12:54:29 -070030 private final boolean mAlwaysOnByDefault;
Adrian Roosb7e4e102016-10-14 13:03:45 -070031
32 public AmbientDisplayConfiguration(Context context) {
33 mContext = context;
Lucas Dupin1e02f342018-06-13 12:54:29 -070034 mAlwaysOnByDefault = mContext.getResources().getBoolean(R.bool.config_dozeAlwaysOnEnabled);
Adrian Roosb7e4e102016-10-14 13:03:45 -070035 }
Adrian Roos22a905e2017-03-07 12:05:57 -080036
Adrian Roosb7e4e102016-10-14 13:03:45 -070037 public boolean enabled(int user) {
38 return pulseOnNotificationEnabled(user)
39 || pulseOnPickupEnabled(user)
Adrian Roos0261fb22017-03-07 20:20:35 +000040 || pulseOnDoubleTapEnabled(user)
Adrian Roosd0963a02017-05-15 14:33:37 -070041 || pulseOnLongPressEnabled(user)
Adrian Roos0261fb22017-03-07 20:20:35 +000042 || alwaysOnEnabled(user);
Adrian Roosb7e4e102016-10-14 13:03:45 -070043 }
Adrian Roos22a905e2017-03-07 12:05:57 -080044
Adrian Roosb7e4e102016-10-14 13:03:45 -070045 public boolean available() {
46 return pulseOnNotificationAvailable() || pulseOnPickupAvailable()
47 || pulseOnDoubleTapAvailable();
48 }
Adrian Roos22a905e2017-03-07 12:05:57 -080049
Adrian Roosb7e4e102016-10-14 13:03:45 -070050 public boolean pulseOnNotificationEnabled(int user) {
Adrian Roos22a905e2017-03-07 12:05:57 -080051 return boolSettingDefaultOn(Settings.Secure.DOZE_ENABLED, user) && pulseOnNotificationAvailable();
Adrian Roosb7e4e102016-10-14 13:03:45 -070052 }
53
54 public boolean pulseOnNotificationAvailable() {
55 return ambientDisplayAvailable();
56 }
57
58 public boolean pulseOnPickupEnabled(int user) {
Geoffrey Pitsch70753082017-07-10 10:36:25 -040059 boolean settingEnabled = boolSettingDefaultOn(Settings.Secure.DOZE_PULSE_ON_PICK_UP, user);
60 return (settingEnabled || alwaysOnEnabled(user)) && pulseOnPickupAvailable();
Adrian Roosb7e4e102016-10-14 13:03:45 -070061 }
Adrian Roos22a905e2017-03-07 12:05:57 -080062
Adrian Roosb7e4e102016-10-14 13:03:45 -070063 public boolean pulseOnPickupAvailable() {
Matthew Fritze3461bb42018-05-21 13:12:36 -070064 return dozePulsePickupSensorAvailable() && ambientDisplayAvailable();
65 }
66
67 public boolean dozePulsePickupSensorAvailable() {
68 return mContext.getResources().getBoolean(R.bool.config_dozePulsePickup);
Adrian Roosb7e4e102016-10-14 13:03:45 -070069 }
Adrian Roos22a905e2017-03-07 12:05:57 -080070
Geoffrey Pitsch70753082017-07-10 10:36:25 -040071 public boolean pulseOnPickupCanBeModified(int user) {
72 return !alwaysOnEnabled(user);
73 }
74
Adrian Roosb7e4e102016-10-14 13:03:45 -070075 public boolean pulseOnDoubleTapEnabled(int user) {
Adrian Roos22a905e2017-03-07 12:05:57 -080076 return boolSettingDefaultOn(Settings.Secure.DOZE_PULSE_ON_DOUBLE_TAP, user)
Adrian Roosb7e4e102016-10-14 13:03:45 -070077 && pulseOnDoubleTapAvailable();
78 }
79
80 public boolean pulseOnDoubleTapAvailable() {
Matthew Fritze3461bb42018-05-21 13:12:36 -070081 return doubleTapSensorAvailable() && ambientDisplayAvailable();
82 }
83
84 public boolean doubleTapSensorAvailable() {
85 return !TextUtils.isEmpty(doubleTapSensorType());
Adrian Roosb7e4e102016-10-14 13:03:45 -070086 }
87
88 public String doubleTapSensorType() {
89 return mContext.getResources().getString(R.string.config_dozeDoubleTapSensorType);
90 }
91
Adrian Roosd0963a02017-05-15 14:33:37 -070092 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 Roos0261fb22017-03-07 20:20:35 +0000105 public boolean alwaysOnEnabled(int user) {
Lucas Dupin1e02f342018-06-13 12:54:29 -0700106 return boolSetting(Settings.Secure.DOZE_ALWAYS_ON, user, mAlwaysOnByDefault ? 1 : 0)
107 && alwaysOnAvailable() && !accessibilityInversionEnabled(user);
Adrian Roos0261fb22017-03-07 20:20:35 +0000108 }
109
110 public boolean alwaysOnAvailable() {
Michael Wright80367992017-05-10 19:49:06 +0100111 return (alwaysOnDisplayDebuggingEnabled() || alwaysOnDisplayAvailable())
112 && ambientDisplayAvailable();
Adrian Roos0261fb22017-03-07 20:20:35 +0000113 }
114
Geoffrey Pitsch3ba26232017-07-28 15:07:39 -0400115 public boolean alwaysOnAvailableForUser(int user) {
116 return alwaysOnAvailable() && !accessibilityInversionEnabled(user);
117 }
118
Adrian Roosb7e4e102016-10-14 13:03:45 -0700119 public String ambientDisplayComponent() {
120 return mContext.getResources().getString(R.string.config_dozeComponent);
121 }
122
Andrew Sapperstein5a71a0f2017-08-07 19:09:41 -0700123 public boolean accessibilityInversionEnabled(int user) {
Geoffrey Pitsch3ba26232017-07-28 15:07:39 -0400124 return boolSettingDefaultOff(Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED, user);
125 }
126
Matthew Fritze3461bb42018-05-21 13:12:36 -0700127 public boolean ambientDisplayAvailable() {
Adrian Roosb7e4e102016-10-14 13:03:45 -0700128 return !TextUtils.isEmpty(ambientDisplayComponent());
129 }
130
Michael Wright80367992017-05-10 19:49:06 +0100131 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 Roos22a905e2017-03-07 12:05:57 -0800140 private boolean boolSettingDefaultOn(String name, int user) {
141 return boolSetting(name, user, 1);
Adrian Roosb7e4e102016-10-14 13:03:45 -0700142 }
143
Adrian Roos22a905e2017-03-07 12:05:57 -0800144 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 Roosb7e4e102016-10-14 13:03:45 -0700151}