Fix keyboard vibration settings delay
The default settings observer delay is 10s for background service. It cause the apps get the settings update delay and lead a unsync behavior. Update the settings change without delay. Bug: 327094397 Test: Manual test with bug steps Test: atest KeyboardVibrationTogglePreferenceControllerTest (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:f2174611b8be192815f16e0ebc42eebfe3bfca0d) Merged-In: Ib1c23ec9e1442e8397c7a36ffa157594ac64a9b3 Change-Id: Ib1c23ec9e1442e8397c7a36ffa157594ac64a9b3
This commit is contained in:
committed by
Android Build Coastguard Worker
parent
9d0f23c862
commit
2ffd023d17
@@ -22,6 +22,7 @@ import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
|
|||||||
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
|
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
|
||||||
|
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.ContentObserver;
|
import android.database.ContentObserver;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
@@ -159,8 +160,11 @@ public class KeyboardVibrationTogglePreferenceController extends TogglePreferenc
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean updateKeyboardVibrationSetting(boolean enable) {
|
private boolean updateKeyboardVibrationSetting(boolean enable) {
|
||||||
final boolean success = Settings.System.putInt(mContext.getContentResolver(),
|
final ContentResolver contentResolver = mContext.getContentResolver();
|
||||||
|
final boolean success = Settings.System.putInt(contentResolver,
|
||||||
KEYBOARD_VIBRATION_ENABLED, enable ? ON : OFF);
|
KEYBOARD_VIBRATION_ENABLED, enable ? ON : OFF);
|
||||||
|
contentResolver.notifyChange(Settings.System.getUriFor(KEYBOARD_VIBRATION_ENABLED),
|
||||||
|
null /* observer */, ContentResolver.NOTIFY_NO_DELAY);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
Log.w(TAG, "Update settings database error!");
|
Log.w(TAG, "Update settings database error!");
|
||||||
}
|
}
|
||||||
|
@@ -30,6 +30,7 @@ import static org.mockito.Mockito.when;
|
|||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.os.vibrator.Flags;
|
import android.os.vibrator.Flags;
|
||||||
@@ -60,6 +61,9 @@ public class KeyboardVibrationTogglePreferenceControllerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private PreferenceScreen mPreferenceScreen;
|
private PreferenceScreen mPreferenceScreen;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private ContentResolver mContentResolver;
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private Resources mResources;
|
private Resources mResources;
|
||||||
private KeyboardVibrationTogglePreferenceController mController;
|
private KeyboardVibrationTogglePreferenceController mController;
|
||||||
@@ -72,6 +76,7 @@ public class KeyboardVibrationTogglePreferenceControllerTest {
|
|||||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||||
mResources = spy(mContext.getResources());
|
mResources = spy(mContext.getResources());
|
||||||
when(mContext.getResources()).thenReturn(mResources);
|
when(mContext.getResources()).thenReturn(mResources);
|
||||||
|
when(mContext.getContentResolver()).thenReturn(mContentResolver);
|
||||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||||
mController = new KeyboardVibrationTogglePreferenceController(mContext, "preferenceKey");
|
mController = new KeyboardVibrationTogglePreferenceController(mContext, "preferenceKey");
|
||||||
mPreference = new SwitchPreference(mContext);
|
mPreference = new SwitchPreference(mContext);
|
||||||
|
Reference in New Issue
Block a user