1 /* 2 * Copyright (C) 2020 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.settings.sound; 18 19 import android.content.Context; 20 import android.provider.DeviceConfig; 21 import android.provider.Settings; 22 23 import androidx.annotation.VisibleForTesting; 24 25 import com.android.settings.R; 26 import com.android.settings.Utils; 27 import com.android.settings.core.BasePreferenceController; 28 29 /** 30 * Controller for vibrate for calls settings. 31 */ 32 public class VibrateForCallsPreferenceController extends BasePreferenceController { 33 34 private static final int ON = 1; 35 private static final int OFF = 0; 36 @VisibleForTesting 37 static final String RAMPING_RINGER_ENABLED = "ramping_ringer_enabled"; 38 VibrateForCallsPreferenceController(Context context, String preferenceKey)39 public VibrateForCallsPreferenceController(Context context, String preferenceKey) { 40 super(context, preferenceKey); 41 } 42 43 @Override 44 @AvailabilityStatus getAvailabilityStatus()45 public int getAvailabilityStatus() { 46 return Utils.isVoiceCapable(mContext) && !DeviceConfig.getBoolean( 47 DeviceConfig.NAMESPACE_TELEPHONY, RAMPING_RINGER_ENABLED, false) 48 ? AVAILABLE 49 : UNSUPPORTED_ON_DEVICE; 50 } 51 52 @Override getSummary()53 public CharSequence getSummary() { 54 if (Settings.Global.getInt( 55 mContext.getContentResolver(), 56 Settings.Global.APPLY_RAMPING_RINGER, OFF) == ON) { 57 return mContext.getText(R.string.vibrate_when_ringing_option_ramping_ringer); 58 } else if (Settings.System.getInt( 59 mContext.getContentResolver(), 60 Settings.System.VIBRATE_WHEN_RINGING, OFF) == ON) { 61 return mContext.getText(R.string.vibrate_when_ringing_option_always_vibrate); 62 } else { 63 return mContext.getText(R.string.vibrate_when_ringing_option_never_vibrate); 64 } 65 } 66 } 67