OSDN Git Service

Merge "docs: Add documentation for equals() method" into qt-dev am: 732a127636
[android-x86/frameworks-base.git] / core / java / android / hardware / display / AmbientDisplayConfiguration.java
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 android.hardware.display;
18
19 import android.annotation.TestApi;
20 import android.content.Context;
21 import android.os.Build;
22 import android.os.SystemProperties;
23 import android.provider.Settings;
24 import android.text.TextUtils;
25
26 import com.android.internal.R;
27
28 /**
29  * AmbientDisplayConfiguration encapsulates reading access to the configuration of ambient display.
30  *
31  * {@hide}
32  */
33 @TestApi
34 public class AmbientDisplayConfiguration {
35
36     private final Context mContext;
37     private final boolean mAlwaysOnByDefault;
38
39     /** {@hide} */
40     @TestApi
41     public AmbientDisplayConfiguration(Context context) {
42         mContext = context;
43         mAlwaysOnByDefault = mContext.getResources().getBoolean(R.bool.config_dozeAlwaysOnEnabled);
44     }
45
46     /** {@hide} */
47     public boolean enabled(int user) {
48         return pulseOnNotificationEnabled(user)
49                 || pulseOnLongPressEnabled(user)
50                 || alwaysOnEnabled(user)
51                 || wakeLockScreenGestureEnabled(user)
52                 || wakeDisplayGestureEnabled(user)
53                 || pickupGestureEnabled(user)
54                 || tapGestureEnabled(user)
55                 || doubleTapGestureEnabled(user);
56     }
57
58     /** {@hide} */
59     public boolean pulseOnNotificationEnabled(int user) {
60         return boolSettingDefaultOn(Settings.Secure.DOZE_ENABLED, user)
61                 && pulseOnNotificationAvailable();
62     }
63
64     /** {@hide} */
65     public boolean pulseOnNotificationAvailable() {
66         return ambientDisplayAvailable();
67     }
68
69     /** {@hide} */
70     public boolean pickupGestureEnabled(int user) {
71         return boolSettingDefaultOn(Settings.Secure.DOZE_PICK_UP_GESTURE, user)
72                 && dozePickupSensorAvailable();
73     }
74
75     /** {@hide} */
76     public boolean dozePickupSensorAvailable() {
77         return mContext.getResources().getBoolean(R.bool.config_dozePulsePickup);
78     }
79
80     /** {@hide} */
81     public boolean tapGestureEnabled(int user) {
82         return boolSettingDefaultOn(Settings.Secure.DOZE_TAP_SCREEN_GESTURE, user)
83                 && tapSensorAvailable();
84     }
85
86     /** {@hide} */
87     public boolean tapSensorAvailable() {
88         return !TextUtils.isEmpty(tapSensorType());
89     }
90
91     /** {@hide} */
92     public boolean doubleTapGestureEnabled(int user) {
93         return boolSettingDefaultOn(Settings.Secure.DOZE_DOUBLE_TAP_GESTURE, user)
94                 && doubleTapSensorAvailable();
95     }
96
97     /** {@hide} */
98     public boolean doubleTapSensorAvailable() {
99         return !TextUtils.isEmpty(doubleTapSensorType());
100     }
101
102     /** {@hide} */
103     public boolean wakeScreenGestureAvailable() {
104         return mContext.getResources()
105                 .getBoolean(R.bool.config_dozeWakeLockScreenSensorAvailable);
106     }
107
108     /** {@hide} */
109     public boolean wakeLockScreenGestureEnabled(int user) {
110         return boolSettingDefaultOn(Settings.Secure.DOZE_WAKE_LOCK_SCREEN_GESTURE, user)
111                 && wakeScreenGestureAvailable();
112     }
113
114     /** {@hide} */
115     public boolean wakeDisplayGestureEnabled(int user) {
116         return boolSettingDefaultOn(Settings.Secure.DOZE_WAKE_DISPLAY_GESTURE, user)
117                 && wakeScreenGestureAvailable();
118     }
119
120     /** {@hide} */
121     public long getWakeLockScreenDebounce() {
122         return mContext.getResources().getInteger(R.integer.config_dozeWakeLockScreenDebounce);
123     }
124
125     /** {@hide} */
126     public String doubleTapSensorType() {
127         return mContext.getResources().getString(R.string.config_dozeDoubleTapSensorType);
128     }
129
130     /** {@hide} */
131     public String tapSensorType() {
132         return mContext.getResources().getString(R.string.config_dozeTapSensorType);
133     }
134
135     /** {@hide} */
136     public String longPressSensorType() {
137         return mContext.getResources().getString(R.string.config_dozeLongPressSensorType);
138     }
139
140     /** {@hide} */
141     public boolean pulseOnLongPressEnabled(int user) {
142         return pulseOnLongPressAvailable() && boolSettingDefaultOff(
143                 Settings.Secure.DOZE_PULSE_ON_LONG_PRESS, user);
144     }
145
146     private boolean pulseOnLongPressAvailable() {
147         return !TextUtils.isEmpty(longPressSensorType());
148     }
149
150     /**
151      * Returns if Always-on-Display functionality is enabled on the display for a specified user.
152      *
153      * {@hide}
154      */
155     @TestApi
156     public boolean alwaysOnEnabled(int user) {
157         return boolSetting(Settings.Secure.DOZE_ALWAYS_ON, user, mAlwaysOnByDefault ? 1 : 0)
158                 && alwaysOnAvailable() && !accessibilityInversionEnabled(user);
159     }
160
161     /**
162      * Returns if Always-on-Display functionality is available on the display.
163      *
164      * {@hide}
165      */
166     @TestApi
167     public boolean alwaysOnAvailable() {
168         return (alwaysOnDisplayDebuggingEnabled() || alwaysOnDisplayAvailable())
169                 && ambientDisplayAvailable();
170     }
171
172     /**
173      * Returns if Always-on-Display functionality is available on the display for a specified user.
174      *
175      *  {@hide}
176      */
177     @TestApi
178     public boolean alwaysOnAvailableForUser(int user) {
179         return alwaysOnAvailable() && !accessibilityInversionEnabled(user);
180     }
181
182     /** {@hide} */
183     public String ambientDisplayComponent() {
184         return mContext.getResources().getString(R.string.config_dozeComponent);
185     }
186
187     /** {@hide} */
188     public boolean accessibilityInversionEnabled(int user) {
189         return boolSettingDefaultOff(Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED, user);
190     }
191
192     /** {@hide} */
193     public boolean ambientDisplayAvailable() {
194         return !TextUtils.isEmpty(ambientDisplayComponent());
195     }
196
197     private boolean alwaysOnDisplayAvailable() {
198         return mContext.getResources().getBoolean(R.bool.config_dozeAlwaysOnDisplayAvailable);
199     }
200
201     private boolean alwaysOnDisplayDebuggingEnabled() {
202         return SystemProperties.getBoolean("debug.doze.aod", false) && Build.IS_DEBUGGABLE;
203     }
204
205     private boolean boolSettingDefaultOn(String name, int user) {
206         return boolSetting(name, user, 1);
207     }
208
209     private boolean boolSettingDefaultOff(String name, int user) {
210         return boolSetting(name, user, 0);
211     }
212
213     private boolean boolSetting(String name, int user, int def) {
214         return Settings.Secure.getIntForUser(mContext.getContentResolver(), name, def, user) != 0;
215     }
216 }