• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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.accessibility;
18 
19 import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
20 import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
21 
22 import android.content.Context;
23 import android.media.AudioManager;
24 import android.os.VibrationAttributes;
25 import android.os.Vibrator;
26 import android.provider.Settings;
27 
28 /** General configuration for ringtone vibration intensity settings. */
29 public class RingVibrationPreferenceConfig extends VibrationPreferenceConfig {
30     private final AudioManager mAudioManager;
31 
RingVibrationPreferenceConfig(Context context)32     public RingVibrationPreferenceConfig(Context context) {
33         super(context, Settings.System.RING_VIBRATION_INTENSITY,
34                 VibrationAttributes.USAGE_RINGTONE);
35         mAudioManager = context.getSystemService(AudioManager.class);
36     }
37 
38     @Override
isRestrictedByRingerModeSilent()39     public boolean isRestrictedByRingerModeSilent() {
40         // Incoming calls never vibrate when the phone is in silent mode.
41         return true;
42     }
43 
44     @Override
updateIntensity(int intensity)45     public boolean updateIntensity(int intensity) {
46         final boolean success = super.updateIntensity(intensity);
47 
48         // VIBRATE_WHEN_RINGING is deprecated but should still reflect the intensity setting.
49         // Ramping ringer is independent of the ring intensity and should not be affected.
50         Settings.System.putInt(mContentResolver, Settings.System.VIBRATE_WHEN_RINGING,
51                 (intensity == Vibrator.VIBRATION_INTENSITY_OFF) ? OFF : ON);
52 
53         return success;
54     }
55 }
56