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.provider.Settings;
     23 import android.text.TextUtils;
     24 
     25 public class AmbientDisplayConfiguration {
     26 
     27     private final Context mContext;
     28 
     29     public AmbientDisplayConfiguration(Context context) {
     30         mContext = context;
     31     }
     32 
     33     public boolean enabled(int user) {
     34         return pulseOnNotificationEnabled(user)
     35                 || pulseOnPickupEnabled(user)
     36                 || pulseOnDoubleTapEnabled(user);
     37     }
     38 
     39     public boolean available() {
     40         return pulseOnNotificationAvailable() || pulseOnPickupAvailable()
     41                 || pulseOnDoubleTapAvailable();
     42     }
     43 
     44     public boolean pulseOnNotificationEnabled(int user) {
     45         return boolSetting(Settings.Secure.DOZE_ENABLED, user) && pulseOnNotificationAvailable();
     46     }
     47 
     48     public boolean pulseOnNotificationAvailable() {
     49         return ambientDisplayAvailable();
     50     }
     51 
     52     public boolean pulseOnPickupEnabled(int user) {
     53         return boolSetting(Settings.Secure.DOZE_PULSE_ON_PICK_UP, user)
     54                 && pulseOnPickupAvailable();
     55     }
     56 
     57     public boolean pulseOnPickupAvailable() {
     58         return mContext.getResources().getBoolean(R.bool.config_dozePulsePickup)
     59                 && ambientDisplayAvailable();
     60     }
     61 
     62     public boolean pulseOnDoubleTapEnabled(int user) {
     63         return boolSetting(Settings.Secure.DOZE_PULSE_ON_DOUBLE_TAP, user)
     64                 && pulseOnDoubleTapAvailable();
     65     }
     66 
     67     public boolean pulseOnDoubleTapAvailable() {
     68         return !TextUtils.isEmpty(doubleTapSensorType()) && ambientDisplayAvailable();
     69     }
     70 
     71     public String doubleTapSensorType() {
     72         return mContext.getResources().getString(R.string.config_dozeDoubleTapSensorType);
     73     }
     74 
     75     public String ambientDisplayComponent() {
     76         return mContext.getResources().getString(R.string.config_dozeComponent);
     77     }
     78 
     79     private boolean ambientDisplayAvailable() {
     80         return !TextUtils.isEmpty(ambientDisplayComponent());
     81     }
     82 
     83     private boolean boolSetting(String name, int user) {
     84         return Settings.Secure.getIntForUser(mContext.getContentResolver(), name, 1, user) != 0;
     85     }
     86 
     87 }
     88