Home | History | Annotate | Download | only in hardware
      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;
     22 import android.os.Build;
     23 import android.os.SystemProperties;
     24 import android.provider.Settings;
     25 import android.text.TextUtils;
     26 
     27 public class AmbientDisplayConfiguration {
     28 
     29     private final Context mContext;
     30 
     31     public AmbientDisplayConfiguration(Context context) {
     32         mContext = context;
     33     }
     34 
     35     public boolean enabled(int user) {
     36         return pulseOnNotificationEnabled(user)
     37                 || pulseOnPickupEnabled(user)
     38                 || pulseOnDoubleTapEnabled(user)
     39                 || pulseOnLongPressEnabled(user)
     40                 || alwaysOnEnabled(user);
     41     }
     42 
     43     public boolean available() {
     44         return pulseOnNotificationAvailable() || pulseOnPickupAvailable()
     45                 || pulseOnDoubleTapAvailable();
     46     }
     47 
     48     public boolean pulseOnNotificationEnabled(int user) {
     49         return boolSettingDefaultOn(Settings.Secure.DOZE_ENABLED, user) && pulseOnNotificationAvailable();
     50     }
     51 
     52     public boolean pulseOnNotificationAvailable() {
     53         return ambientDisplayAvailable();
     54     }
     55 
     56     public boolean pulseOnPickupEnabled(int user) {
     57         boolean settingEnabled = boolSettingDefaultOn(Settings.Secure.DOZE_PULSE_ON_PICK_UP, user);
     58         return (settingEnabled || alwaysOnEnabled(user)) && pulseOnPickupAvailable();
     59     }
     60 
     61     public boolean pulseOnPickupAvailable() {
     62         return dozePulsePickupSensorAvailable() && ambientDisplayAvailable();
     63     }
     64 
     65     public boolean dozePulsePickupSensorAvailable() {
     66         return mContext.getResources().getBoolean(R.bool.config_dozePulsePickup);
     67     }
     68 
     69     public boolean pulseOnPickupCanBeModified(int user) {
     70         return !alwaysOnEnabled(user);
     71     }
     72 
     73     public boolean pulseOnDoubleTapEnabled(int user) {
     74         return boolSettingDefaultOn(Settings.Secure.DOZE_PULSE_ON_DOUBLE_TAP, user)
     75                 && pulseOnDoubleTapAvailable();
     76     }
     77 
     78     public boolean pulseOnDoubleTapAvailable() {
     79         return doubleTapSensorAvailable() && ambientDisplayAvailable();
     80     }
     81 
     82     public boolean doubleTapSensorAvailable() {
     83         return !TextUtils.isEmpty(doubleTapSensorType());
     84     }
     85 
     86     public String doubleTapSensorType() {
     87         return mContext.getResources().getString(R.string.config_dozeDoubleTapSensorType);
     88     }
     89 
     90     public String longPressSensorType() {
     91         return mContext.getResources().getString(R.string.config_dozeLongPressSensorType);
     92     }
     93 
     94     public boolean pulseOnLongPressEnabled(int user) {
     95         return pulseOnLongPressAvailable() && boolSettingDefaultOff(
     96                 Settings.Secure.DOZE_PULSE_ON_LONG_PRESS, user);
     97     }
     98 
     99     private boolean pulseOnLongPressAvailable() {
    100         return !TextUtils.isEmpty(longPressSensorType());
    101     }
    102 
    103     public boolean alwaysOnEnabled(int user) {
    104         return boolSettingDefaultOn(Settings.Secure.DOZE_ALWAYS_ON, user) && alwaysOnAvailable()
    105                 && !accessibilityInversionEnabled(user);
    106     }
    107 
    108     public boolean alwaysOnAvailable() {
    109         return (alwaysOnDisplayDebuggingEnabled() || alwaysOnDisplayAvailable())
    110                 && ambientDisplayAvailable();
    111     }
    112 
    113     public boolean alwaysOnAvailableForUser(int user) {
    114         return alwaysOnAvailable() && !accessibilityInversionEnabled(user);
    115     }
    116 
    117     public String ambientDisplayComponent() {
    118         return mContext.getResources().getString(R.string.config_dozeComponent);
    119     }
    120 
    121     public boolean accessibilityInversionEnabled(int user) {
    122         return boolSettingDefaultOff(Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED, user);
    123     }
    124 
    125     public boolean ambientDisplayAvailable() {
    126         return !TextUtils.isEmpty(ambientDisplayComponent());
    127     }
    128 
    129     private boolean alwaysOnDisplayAvailable() {
    130         return mContext.getResources().getBoolean(R.bool.config_dozeAlwaysOnDisplayAvailable);
    131     }
    132 
    133     private boolean alwaysOnDisplayDebuggingEnabled() {
    134         return SystemProperties.getBoolean("debug.doze.aod", false) && Build.IS_DEBUGGABLE;
    135     }
    136 
    137 
    138     private boolean boolSettingDefaultOn(String name, int user) {
    139         return boolSetting(name, user, 1);
    140     }
    141 
    142     private boolean boolSettingDefaultOff(String name, int user) {
    143         return boolSetting(name, user, 0);
    144     }
    145 
    146     private boolean boolSetting(String name, int user, int def) {
    147         return Settings.Secure.getIntForUser(mContext.getContentResolver(), name, def, user) != 0;
    148     }
    149 }
    150