OSDN Git Service

Move vibration preview invokation to the correct place
authorAlexey Kuzmin <alexeykuzmin@google.com>
Tue, 4 Jun 2019 14:59:32 +0000 (15:59 +0100)
committerAlexey Kuzmin <alexeykuzmin@google.com>
Tue, 4 Jun 2019 15:44:43 +0000 (15:44 +0000)
Bug: 133711461
Bug: 130332550
Test: Open Settings > Accessibility > Vibration. Switch between the
vibration settings several times. The preview should be played, and it
should be in line with the selected setting

Change-Id: I65fcd679c4c61afa4cce9cee652987d81572096c

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

index 480041a..1803a8b 100644 (file)
@@ -128,6 +128,20 @@ public abstract class VibrationPreferenceFragment extends RadioButtonPickerFragm
                     Settings.System.putInt(getContext().getContentResolver(),
                             vibrationEnabledSetting, vibrationEnabled ? 1 : 0);
                 }
+
+                int previousIntensity = Settings.System.getInt(getContext().getContentResolver(),
+                        getVibrationIntensitySetting(), 0);
+                if (vibrationEnabled && previousIntensity == candidate.getIntensity()) {
+                    // We can't play preview effect here for all cases because that causes a data
+                    // race (VibratorService may access intensity settings before these settings
+                    // are updated). But we can't just play it in intensity settings update
+                    // observer, because the intensity settings are not changed if we turn the
+                    // vibration off, then on.
+                    //
+                    // In this case we sould play the preview here.
+                    // To be refactored in b/132952771
+                    playVibrationPreview();
+                }
             }
         }
         // There are two conditions that need to change the intensity.
@@ -137,15 +151,6 @@ public abstract class VibrationPreferenceFragment extends RadioButtonPickerFragm
             // Update vibration intensity setting
             Settings.System.putInt(getContext().getContentResolver(),
                     getVibrationIntensitySetting(), candidate.getIntensity());
-        } else {
-            // We can't play preview effect here for all cases because that causes a data race
-            // (VibratorService may access intensity settings before these settings are updated).
-            // But we can't just play it in intensity settings update observer, because the
-            // intensity settings are not changed if we turn the vibration off, then on.
-            //
-            // In this case we sould play the preview here.
-            // To be refactored in b/132952771
-            playVibrationPreview();
         }
     }