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 ringer ramping time in milliseconds. */ 34 private static final String RAMPING_RINGER_DURATION_MILLIS = "ramping_ringer_duration"; 35 36 /** Flag for vibration time in milliseconds before ramping ringer starts. */ 37 private static final String RAMPING_RINGER_VIBRATION_DURATION = 38 "ramping_ringer_vibration_duration"; 39 40 /** Flag for whether or not to apply ramping ringer on incoming phone calls. */ 41 private static final String RAMPING_RINGER_ENABLED = "ramping_ringer_enabled"; 42 43 /** Flag for whether or not to support audio coupled haptics in ramping ringer. */ 44 private static final String RAMPING_RINGER_AUDIO_COUPLED_VIBRATION_ENABLED = 45 "ramping_ringer_audio_coupled_vibration_enabled"; 46 isTheaterModeOn(Context context)47 public boolean isTheaterModeOn(Context context) { 48 return Settings.Global.getInt(context.getContentResolver(), Settings.Global.THEATER_MODE_ON, 49 0) == 1; 50 } 51 canVibrateWhenRinging(Context context)52 public boolean canVibrateWhenRinging(Context context) { 53 return Settings.System.getInt(context.getContentResolver(), 54 Settings.System.VIBRATE_WHEN_RINGING, 0) != 0; 55 } 56 isEnhancedCallBlockingEnabled(Context context)57 public boolean isEnhancedCallBlockingEnabled(Context context) { 58 return Settings.System.getInt(context.getContentResolver(), 59 Settings.System.DEBUG_ENABLE_ENHANCED_CALL_BLOCKING, 0) != 0; 60 } 61 setEnhancedCallBlockingEnabled(Context context, boolean enabled)62 public boolean setEnhancedCallBlockingEnabled(Context context, boolean enabled) { 63 return Settings.System.putInt(context.getContentResolver(), 64 Settings.System.DEBUG_ENABLE_ENHANCED_CALL_BLOCKING, enabled ? 1 : 0); 65 } 66 applyRampingRinger(Context context)67 public boolean applyRampingRinger(Context context) { 68 return Settings.Global.getInt(context.getContentResolver(), 69 Settings.Global.APPLY_RAMPING_RINGER, 0) == 1; 70 } 71 enableRampingRingerFromDeviceConfig()72 public boolean enableRampingRingerFromDeviceConfig() { 73 return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_TELEPHONY, RAMPING_RINGER_ENABLED, 74 false); 75 } 76 enableAudioCoupledVibrationForRampingRinger()77 public boolean enableAudioCoupledVibrationForRampingRinger() { 78 return DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_TELEPHONY, 79 RAMPING_RINGER_AUDIO_COUPLED_VIBRATION_ENABLED, false); 80 } 81 getRampingRingerDuration()82 public int getRampingRingerDuration() { 83 return DeviceConfig.getInt(DeviceConfig.NAMESPACE_TELEPHONY, 84 RAMPING_RINGER_DURATION_MILLIS, -1); 85 } 86 getRampingRingerVibrationDuration()87 public int getRampingRingerVibrationDuration() { 88 return DeviceConfig.getInt(DeviceConfig.NAMESPACE_TELEPHONY, 89 RAMPING_RINGER_VIBRATION_DURATION, 0); 90 } 91 isHapticPlaybackSupported(Context context)92 public boolean isHapticPlaybackSupported(Context context) { 93 return context.getSystemService(AudioManager.class).isHapticPlaybackSupported(); 94 } 95 } 96 97