Split ring and notification vibration settings

Synchronize settings between sound and accessibility menus

Bug: 116172311
Test: See accessibility vibration settings - ring and notification
settings sould be separate. Try changing vibration settings in sound and
accessibility menus - the settings should stay in sync.

Change-Id: I515a7188cdf5a26a229ac8f08c6fcfe98e2f91a0
This commit is contained in:
Alexey Kuzmin
2018-12-10 11:58:06 +00:00
parent e5d530348c
commit 3c51e824eb
13 changed files with 207 additions and 28 deletions

View File

@@ -810,15 +810,30 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
final Context context = getContext();
final Vibrator vibrator = context.getSystemService(Vibrator.class);
final int ringIntensity = Settings.System.getInt(context.getContentResolver(),
Settings.System.NOTIFICATION_VIBRATION_INTENSITY,
vibrator.getDefaultNotificationVibrationIntensity());
int ringIntensity = Settings.System.getInt(context.getContentResolver(),
Settings.System.RING_VIBRATION_INTENSITY,
vibrator.getDefaultRingVibrationIntensity());
if (Settings.System.getInt(context.getContentResolver(),
Settings.System.VIBRATE_WHEN_RINGING, 0) == 0) {
ringIntensity = Vibrator.VIBRATION_INTENSITY_OFF;
}
CharSequence ringIntensityString =
VibrationIntensityPreferenceController.getIntensityString(context, ringIntensity);
final int touchIntensity = Settings.System.getInt(context.getContentResolver(),
int notificationIntensity = Settings.System.getInt(context.getContentResolver(),
Settings.System.NOTIFICATION_VIBRATION_INTENSITY,
vibrator.getDefaultNotificationVibrationIntensity());
CharSequence notificationIntensityString =
VibrationIntensityPreferenceController.getIntensityString(context,
notificationIntensity);
int touchIntensity = Settings.System.getInt(context.getContentResolver(),
Settings.System.HAPTIC_FEEDBACK_INTENSITY,
vibrator.getDefaultHapticFeedbackIntensity());
if (Settings.System.getInt(context.getContentResolver(),
Settings.System.HAPTIC_FEEDBACK_ENABLED, 0) == 0) {
touchIntensity = Vibrator.VIBRATION_INTENSITY_OFF;
}
CharSequence touchIntensityString =
VibrationIntensityPreferenceController.getIntensityString(context, touchIntensity);
@@ -826,12 +841,14 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
mVibrationPreferenceScreen = findPreference(VIBRATION_PREFERENCE_SCREEN);
}
if (ringIntensity == touchIntensity) {
if (ringIntensity == touchIntensity && ringIntensity == notificationIntensity) {
mVibrationPreferenceScreen.setSummary(ringIntensityString);
} else {
mVibrationPreferenceScreen.setSummary(
getString(R.string.accessibility_vibration_summary,
ringIntensityString, touchIntensityString));
ringIntensityString,
notificationIntensityString,
touchIntensityString));
}
}

View File

@@ -28,7 +28,8 @@ public class HapticFeedbackIntensityPreferenceController
static final String PREF_KEY = "touch_vibration_preference_screen";
public HapticFeedbackIntensityPreferenceController(Context context) {
super(context, PREF_KEY, Settings.System.HAPTIC_FEEDBACK_INTENSITY);
super(context, PREF_KEY, Settings.System.HAPTIC_FEEDBACK_INTENSITY,
Settings.System.HAPTIC_FEEDBACK_ENABLED);
}
@Override

View File

@@ -28,7 +28,7 @@ public class NotificationVibrationIntensityPreferenceController
static final String PREF_KEY = "notification_vibration_preference_screen";
public NotificationVibrationIntensityPreferenceController(Context context) {
super(context, PREF_KEY, Settings.System.NOTIFICATION_VIBRATION_INTENSITY);
super(context, PREF_KEY, Settings.System.NOTIFICATION_VIBRATION_INTENSITY, "");
}
@Override

View File

@@ -44,6 +44,11 @@ public class NotificationVibrationPreferenceFragment extends VibrationPreference
return Settings.System.NOTIFICATION_VIBRATION_INTENSITY;
}
@Override
protected String getVibrationEnabledSetting() {
return "";
}
@Override
protected int getPreviewVibrationAudioAttributesUsage() {
return AudioAttributes.USAGE_NOTIFICATION;

View File

@@ -0,0 +1,44 @@
/*
* Copyright (C) 2018 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.provider.Settings;
import androidx.annotation.VisibleForTesting;
public class RingVibrationIntensityPreferenceController
extends VibrationIntensityPreferenceController {
@VisibleForTesting
static final String PREF_KEY = "ring_vibration_preference_screen";
public RingVibrationIntensityPreferenceController(Context context) {
super(context, PREF_KEY, Settings.System.RING_VIBRATION_INTENSITY,
Settings.System.VIBRATE_WHEN_RINGING);
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE;
}
@Override
protected int getDefaultIntensity() {
return mVibrator.getDefaultRingVibrationIntensity();
}
}

View File

@@ -0,0 +1,62 @@
/*
* Copyright (C) 2018 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.media.AudioAttributes;
import android.os.Vibrator;
import android.provider.Settings;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
/**
* Fragment for picking accessibility shortcut service
*/
public class RingVibrationPreferenceFragment extends VibrationPreferenceFragment {
@Override
public int getMetricsCategory() {
return MetricsEvent.ACCESSIBILITY_VIBRATION_RING;
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.accessibility_ring_vibration_settings;
}
/**
* Get the setting string of the vibration intensity setting this preference is dealing with.
*/
@Override
protected String getVibrationIntensitySetting() {
return Settings.System.RING_VIBRATION_INTENSITY;
}
@Override
protected String getVibrationEnabledSetting() {
return Settings.System.VIBRATE_WHEN_RINGING;
}
@Override
protected int getPreviewVibrationAudioAttributesUsage() {
return AudioAttributes.USAGE_NOTIFICATION;
}
@Override
protected int getDefaultVibrationIntensity() {
Vibrator vibrator = getContext().getSystemService(Vibrator.class);
return vibrator.getDefaultRingVibrationIntensity();
}
}

View File

@@ -44,6 +44,11 @@ public class TouchVibrationPreferenceFragment extends VibrationPreferenceFragmen
return Settings.System.HAPTIC_FEEDBACK_INTENSITY;
}
@Override
protected String getVibrationEnabledSetting() {
return Settings.System.HAPTIC_FEEDBACK_ENABLED;
}
@Override
protected int getDefaultVibrationIntensity() {
Vibrator vibrator = getContext().getSystemService(Vibrator.class);
@@ -54,13 +59,4 @@ public class TouchVibrationPreferenceFragment extends VibrationPreferenceFragmen
protected int getPreviewVibrationAudioAttributesUsage() {
return AudioAttributes.USAGE_ASSISTANCE_SONIFICATION;
}
@Override
public void onVibrationIntensitySelected(int intensity) {
// We want to keep HAPTIC_FEEDBACK_ENABLED consistent with this setting since some
// applications check it directly before triggering their own haptic feedback.
final boolean hapticFeedbackEnabled = !(intensity == Vibrator.VIBRATION_INTENSITY_OFF);
Settings.System.putInt(getContext().getContentResolver(),
Settings.System.HAPTIC_FEEDBACK_ENABLED, hapticFeedbackEnabled ? 1 : 0);
}
}

View File

@@ -39,14 +39,16 @@ public abstract class VibrationIntensityPreferenceController extends BasePrefere
protected final Vibrator mVibrator;
private final SettingObserver mSettingsContentObserver;
private final String mSettingKey;
private final String mEnabledKey;
private Preference mPreference;
public VibrationIntensityPreferenceController(Context context, String prefkey,
String settingKey) {
String settingKey, String enabledKey) {
super(context, prefkey);
mVibrator = mContext.getSystemService(Vibrator.class);
mSettingKey = settingKey;
mEnabledKey = enabledKey;
mSettingsContentObserver = new SettingObserver(settingKey) {
@Override
public void onChange(boolean selfChange, Uri uri) {
@@ -78,7 +80,9 @@ public abstract class VibrationIntensityPreferenceController extends BasePrefere
public CharSequence getSummary() {
final int intensity = Settings.System.getInt(mContext.getContentResolver(),
mSettingKey, getDefaultIntensity());
return getIntensityString(mContext, intensity);
final boolean enabled = Settings.System.getInt(mContext.getContentResolver(),
mEnabledKey, 1) == 1;
return getIntensityString(mContext, enabled ? intensity : Vibrator.VIBRATION_INTENSITY_OFF);
}
public static CharSequence getIntensityString(Context context, int intensity) {

View File

@@ -26,6 +26,7 @@ import android.os.Handler;
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.Log;
@@ -116,6 +117,11 @@ public abstract class VibrationPreferenceFragment extends RadioButtonPickerFragm
*/
protected abstract String getVibrationIntensitySetting();
/**
* Get the setting string of the vibration enabledness setting this preference is dealing with.
*/
protected abstract String getVibrationEnabledSetting();
/**
* Get the default intensity for the desired setting.
*/
@@ -154,8 +160,13 @@ public abstract class VibrationPreferenceFragment extends RadioButtonPickerFragm
@Override
protected String getDefaultKey() {
final int vibrationIntensity = Settings.System.getInt(getContext().getContentResolver(),
int vibrationIntensity = Settings.System.getInt(getContext().getContentResolver(),
getVibrationIntensitySetting(), getDefaultVibrationIntensity());
final boolean vibrationEnabled = Settings.System.getInt(getContext().getContentResolver(),
getVibrationEnabledSetting(), 1) == 1;
if (!vibrationEnabled) {
vibrationIntensity = Vibrator.VIBRATION_INTENSITY_OFF;
}
for (VibrationIntensityCandidateInfo candidate : mCandidates.values()) {
final boolean matchesIntensity = candidate.getIntensity() == vibrationIntensity;
final boolean matchesOn = candidate.getKey().equals(KEY_INTENSITY_ON)
@@ -174,8 +185,11 @@ public abstract class VibrationPreferenceFragment extends RadioButtonPickerFragm
Log.e(TAG, "Tried to set unknown intensity (key=" + key + ")!");
return false;
}
Settings.System.putInt(getContext().getContentResolver(),
getVibrationIntensitySetting(), candidate.getIntensity());
if (candidate.getIntensity() != Vibrator.VIBRATION_INTENSITY_OFF ||
TextUtils.isEmpty(getVibrationEnabledSetting())) {
Settings.System.putInt(getContext().getContentResolver(),
getVibrationIntensitySetting(), candidate.getIntensity());
}
onVibrationIntensitySelected(candidate.getIntensity());
return true;
}