OSDN Git Service

Update vibrator on/off status from accessibility settings menu
authorAlexey Kuzmin <alexeykuzmin@google.com>
Wed, 23 Jan 2019 18:23:45 +0000 (18:23 +0000)
committerwilsonshih <wilsonshih@google.com>
Tue, 26 Feb 2019 04:51:49 +0000 (12:51 +0800)
Fix ringing and touch vibration cannot be turned off from accessibility
settings menu.

Bug: 116172311
Fix: 125618621
Test: Open Settings=>Accessibility=>Vibration, change every sub-item and
verify the change can synced with main page, also check the settings can
synced with Sounds.
Test: m -j RunSettingsRoboTests

Change-Id: I7a10bcda17323bce612e199bdf067363b8f9a332

src/com/android/settings/accessibility/VibrationPreferenceFragment.java

index 648acad..5261daa 100644 (file)
@@ -106,6 +106,31 @@ public abstract class VibrationPreferenceFragment extends RadioButtonPickerFragm
         }
     }
 
+    private boolean hasVibrationEnabledSetting() {
+        return !TextUtils.isEmpty(getVibrationEnabledSetting());
+    }
+
+    private void updateSettings(VibrationIntensityCandidateInfo candidate) {
+        boolean vibrationEnabled = candidate.getIntensity() != Vibrator.VIBRATION_INTENSITY_OFF;
+        if (hasVibrationEnabledSetting()) {
+            // Update vibration enabled setting
+            boolean wasEnabled = Settings.System.getInt(getContext().getContentResolver(),
+                    getVibrationEnabledSetting(), 1) == 1;
+            if (vibrationEnabled != wasEnabled) {
+                Settings.System.putInt(getContext().getContentResolver(),
+                    getVibrationEnabledSetting(), vibrationEnabled ? 1 : 0);
+            }
+        }
+        // There are two conditions that need to change the intensity.
+        // First: Vibration is enabled and we are changing its strength.
+        // Second: There is no setting to enable this vibration, change the intensity directly.
+        if (vibrationEnabled || !hasVibrationEnabledSetting()) {
+            // Update vibration intensity setting
+            Settings.System.putInt(getContext().getContentResolver(),
+                    getVibrationIntensitySetting(), candidate.getIntensity());
+        }
+    }
+
     @Override
     public void onDetach() {
         super.onDetach();
@@ -185,11 +210,7 @@ public abstract class VibrationPreferenceFragment extends RadioButtonPickerFragm
             Log.e(TAG, "Tried to set unknown intensity (key=" + key + ")!");
             return false;
         }
-        if (candidate.getIntensity() != Vibrator.VIBRATION_INTENSITY_OFF ||
-                TextUtils.isEmpty(getVibrationEnabledSetting())) {
-            Settings.System.putInt(getContext().getContentResolver(),
-                    getVibrationIntensitySetting(), candidate.getIntensity());
-        }
+        updateSettings(candidate);
         onVibrationIntensitySelected(candidate.getIntensity());
         return true;
     }