Update Settings to use intensity settings as main preference keys
Updating the Settings app to allow setting the value off for key HAPTIC_FEEDBACK_INTENSITY. This setting state is also copied onto HAPTIC_FEEDBACK_ENABLED setting, so both should be in sync after this change. Similar logic is applied between RING_VIBRATION_INTENSITY and VIBRATE_WHEN_RINGING. This will not disable the hardware feedback since that one is controlled by a separate setting key now. The "vibrate for calls" was also removed and the single toggle for "vibrate first then ring gradually" was moved into the "Vibration & haptics" page. Bug: 185351540 Test: [HapticFeedback|NotificationVibration|RingVibration][Intensity|Toggle]PreferenceControllerTest and manual testing of the AOSP settings app Change-Id: I9c94cef331a1500a1272a601ba32667ca995ddab
This commit is contained in:
@@ -16,30 +16,63 @@
|
||||
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
|
||||
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
|
||||
|
||||
import android.content.Context;
|
||||
import android.media.AudioManager;
|
||||
import android.os.VibrationAttributes;
|
||||
import android.os.Vibrator;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
/** Preference controller for ringtone vibration intensity */
|
||||
public class RingVibrationIntensityPreferenceController
|
||||
extends VibrationIntensityPreferenceController {
|
||||
|
||||
@VisibleForTesting
|
||||
static final String PREF_KEY = "ring_vibration_preference_screen";
|
||||
/** General configuration for ringtone vibration intensity settings. */
|
||||
public static final class RingVibrationPreferenceConfig extends VibrationPreferenceConfig {
|
||||
private final AudioManager mAudioManager;
|
||||
|
||||
public RingVibrationIntensityPreferenceController(Context context) {
|
||||
super(context, PREF_KEY, Settings.System.RING_VIBRATION_INTENSITY,
|
||||
Settings.System.VIBRATE_WHEN_RINGING, /* supportRampingRinger= */ true);
|
||||
public RingVibrationPreferenceConfig(Context context) {
|
||||
super(context, Settings.System.RING_VIBRATION_INTENSITY,
|
||||
VibrationAttributes.USAGE_RINGTONE);
|
||||
mAudioManager = context.getSystemService(AudioManager.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readIntensity() {
|
||||
final int vibrateWhenRinging = Settings.System.getInt(mContentResolver,
|
||||
Settings.System.VIBRATE_WHEN_RINGING, ON);
|
||||
|
||||
if ((vibrateWhenRinging == OFF)
|
||||
&& !mAudioManager.isRampingRingerEnabled()) {
|
||||
// VIBRATE_WHEN_RINGING is deprecated but should still be applied if the user has
|
||||
// turned it off and has not enabled the ramping ringer (old three-state setting).
|
||||
return Vibrator.VIBRATION_INTENSITY_OFF;
|
||||
}
|
||||
|
||||
return super.readIntensity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateIntensity(int intensity) {
|
||||
final boolean success = super.updateIntensity(intensity);
|
||||
|
||||
// VIBRATE_WHEN_RINGING is deprecated but should still reflect the intensity setting.
|
||||
// Ramping ringer is independent of the ring intensity and should not be affected.
|
||||
Settings.System.putInt(mContentResolver, Settings.System.VIBRATE_WHEN_RINGING,
|
||||
(intensity == Vibrator.VIBRATION_INTENSITY_OFF) ? OFF : ON);
|
||||
|
||||
return success;
|
||||
}
|
||||
}
|
||||
|
||||
public RingVibrationIntensityPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey, new RingVibrationPreferenceConfig(context));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getDefaultIntensity() {
|
||||
return mVibrator.getDefaultVibrationIntensity(VibrationAttributes.USAGE_RINGTONE);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user