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.os.VibrationAttributes;
22 import android.os.Vibrator;
23 import android.provider.DeviceConfig;
24 import android.provider.Settings;
25 
26 import com.android.internal.annotations.VisibleForTesting;
27 
28 /**
29  * Accesses the Global System settings for more control during testing.
30  */
31 @VisibleForTesting
32 public class SystemSettingsUtil {
33 
34     /** Flag for whether or not to support audio coupled haptics in ramping ringer. */
35     private static final String RAMPING_RINGER_AUDIO_COUPLED_VIBRATION_ENABLED =
36             "ramping_ringer_audio_coupled_vibration_enabled";
37 
isTheaterModeOn(Context context)38     public boolean isTheaterModeOn(Context context) {
39         return Settings.Global.getInt(context.getContentResolver(), Settings.Global.THEATER_MODE_ON,
40                 0) == 1;
41     }
42 
isRingVibrationEnabled(Context context)43     public boolean isRingVibrationEnabled(Context context) {
44         // VIBRATE_WHEN_RINGING setting was deprecated, only RING_VIBRATION_INTENSITY controls the
45         // ringtone vibrations on/off state now. Ramping ringer should only be applied when ring
46         // vibration intensity is ON, otherwise the ringtone sound should not be delayed as there
47         // will be no ring vibration.
48         return Settings.System.getIntForUser(context.getContentResolver(),
49                 Settings.System.RING_VIBRATION_INTENSITY,
50                 context.getSystemService(Vibrator.class).getDefaultVibrationIntensity(
51                         VibrationAttributes.USAGE_RINGTONE),
52                 context.getUserId()) != Vibrator.VIBRATION_INTENSITY_OFF;
53     }
54 
isEnhancedCallBlockingEnabled(Context context)55     public boolean isEnhancedCallBlockingEnabled(Context context) {
56         return Settings.System.getIntForUser(context.getContentResolver(),
57                 Settings.System.DEBUG_ENABLE_ENHANCED_CALL_BLOCKING, 0, context.getUserId()) != 0;
58     }
59 
setEnhancedCallBlockingEnabled(Context context, boolean enabled)60     public boolean setEnhancedCallBlockingEnabled(Context context, boolean enabled) {
61         return Settings.System.putIntForUser(context.getContentResolver(),
62                 Settings.System.DEBUG_ENABLE_ENHANCED_CALL_BLOCKING, enabled ? 1 : 0,
63                 context.getUserId());
64     }
65 
isRampingRingerEnabled(Context context)66     public boolean isRampingRingerEnabled(Context context) {
67         return context.getSystemService(AudioManager.class).isRampingRingerEnabled();
68     }
69 
isAudioCoupledVibrationForRampingRingerEnabled()70     public boolean isAudioCoupledVibrationForRampingRingerEnabled() {
71         return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_TELEPHONY,
72                 RAMPING_RINGER_AUDIO_COUPLED_VIBRATION_ENABLED, false);
73     }
74 
isHapticPlaybackSupported(Context context)75     public boolean isHapticPlaybackSupported(Context context) {
76         return context.getSystemService(AudioManager.class).isHapticPlaybackSupported();
77     }
78 }
79 
80