1 /*
2  * Copyright (C) 2015 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.server.telecom;
18 
19 import android.content.Context;
20 import android.media.AudioManager;
21 import android.provider.DeviceConfig;
22 import android.provider.Settings;
23 import android.telecom.Log;
24 
25 import com.android.internal.annotations.VisibleForTesting;
26 
27 /**
28  * Accesses the Global System settings for more control during testing.
29  */
30 @VisibleForTesting
31 public class SystemSettingsUtil {
32 
33     /** Flag for whether or not to support audio coupled haptics in ramping ringer. */
34     private static final String RAMPING_RINGER_AUDIO_COUPLED_VIBRATION_ENABLED =
35             "ramping_ringer_audio_coupled_vibration_enabled";
36 
isTheaterModeOn(Context context)37     public boolean isTheaterModeOn(Context context) {
38         return Settings.Global.getInt(context.getContentResolver(), Settings.Global.THEATER_MODE_ON,
39                 0) == 1;
40     }
41 
canVibrateWhenRinging(Context context)42     public boolean canVibrateWhenRinging(Context context) {
43         return Settings.System.getInt(context.getContentResolver(),
44                 Settings.System.VIBRATE_WHEN_RINGING, 0) != 0;
45     }
46 
isEnhancedCallBlockingEnabled(Context context)47     public boolean isEnhancedCallBlockingEnabled(Context context) {
48         return Settings.System.getInt(context.getContentResolver(),
49                 Settings.System.DEBUG_ENABLE_ENHANCED_CALL_BLOCKING, 0) != 0;
50     }
51 
setEnhancedCallBlockingEnabled(Context context, boolean enabled)52     public boolean setEnhancedCallBlockingEnabled(Context context, boolean enabled) {
53         return Settings.System.putInt(context.getContentResolver(),
54                 Settings.System.DEBUG_ENABLE_ENHANCED_CALL_BLOCKING, enabled ? 1 : 0);
55     }
56 
applyRampingRinger(Context context)57     public boolean applyRampingRinger(Context context) {
58         return Settings.Global.getInt(context.getContentResolver(),
59                 Settings.Global.APPLY_RAMPING_RINGER, 0) == 1;
60     }
61 
enableAudioCoupledVibrationForRampingRinger()62     public boolean enableAudioCoupledVibrationForRampingRinger() {
63         return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_TELEPHONY,
64                 RAMPING_RINGER_AUDIO_COUPLED_VIBRATION_ENABLED, false);
65     }
66 
isHapticPlaybackSupported(Context context)67     public boolean isHapticPlaybackSupported(Context context) {
68         return context.getSystemService(AudioManager.class).isHapticPlaybackSupported();
69     }
70 }
71 
72