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:
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.ContentObserver;
|
||||
import android.media.AudioManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.VibrationAttributes;
|
||||
import android.os.Vibrator;
|
||||
import android.provider.DeviceConfig;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
/**
|
||||
* Preference controller for the ramping ringer setting key, controlled via {@link AudioManager}.
|
||||
*
|
||||
* <p>This preference depends on the {@link Settings.System#RING_VIBRATION_INTENSITY}, and it will
|
||||
* be disabled and display the unchecked state when the ring intensity is set to OFF. The actual
|
||||
* ramping ringer setting will not be overwritten when the ring intensity is turned off, so the
|
||||
* user original value will be naturally restored when the ring intensity is enabled again.
|
||||
*/
|
||||
public class VibrationRampingRingerTogglePreferenceController
|
||||
extends TogglePreferenceController implements LifecycleObserver, OnStart, OnStop {
|
||||
|
||||
@VisibleForTesting
|
||||
static final String DEVICE_CONFIG_KEY = "ramping_ringer_enabled";
|
||||
|
||||
private final ContentObserver mSettingObserver;
|
||||
private final Vibrator mVibrator;
|
||||
private final AudioManager mAudioManager;
|
||||
|
||||
private Preference mPreference;
|
||||
|
||||
public VibrationRampingRingerTogglePreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mVibrator = context.getSystemService(Vibrator.class);
|
||||
mAudioManager = context.getSystemService(AudioManager.class);
|
||||
mSettingObserver = new ContentObserver(new Handler(Looper.getMainLooper())) {
|
||||
@Override
|
||||
public void onChange(boolean selfChange, Uri uri) {
|
||||
updateState(mPreference);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
final boolean rampingRingerEnabledOnTelephonyConfig =
|
||||
DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_TELEPHONY, DEVICE_CONFIG_KEY, false);
|
||||
return (Utils.isVoiceCapable(mContext) && !rampingRingerEnabledOnTelephonyConfig)
|
||||
? AVAILABLE
|
||||
: UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
mContext.getContentResolver().registerContentObserver(
|
||||
Settings.System.getUriFor(Settings.System.APPLY_RAMPING_RINGER),
|
||||
/* notifyForDescendants= */ false,
|
||||
mSettingObserver);
|
||||
mContext.getContentResolver().registerContentObserver(
|
||||
Settings.System.getUriFor(Settings.System.RING_VIBRATION_INTENSITY),
|
||||
/* notifyForDescendants= */ false,
|
||||
mSettingObserver);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
mContext.getContentResolver().unregisterContentObserver(mSettingObserver);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = screen.findPreference(getPreferenceKey());
|
||||
mPreference.setEnabled(isRingVibrationEnabled());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return isRingVibrationEnabled() && mAudioManager.isRampingRingerEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
if (isRingVibrationEnabled()) {
|
||||
// Don't update ramping ringer setting value if ring vibration is disabled.
|
||||
mAudioManager.setRampingRingerEnabled(isChecked);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSliceHighlightMenuRes() {
|
||||
return R.string.menu_key_accessibility;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
if (preference != null) {
|
||||
preference.setEnabled(isRingVibrationEnabled());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isRingVibrationEnabled() {
|
||||
final int ringIntensity = Settings.System.getInt(mContext.getContentResolver(),
|
||||
Settings.System.RING_VIBRATION_INTENSITY,
|
||||
mVibrator.getDefaultVibrationIntensity(VibrationAttributes.USAGE_RINGTONE));
|
||||
return ringIntensity != Vibrator.VIBRATION_INTENSITY_OFF;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user