Merge "Add receiver to user switch to VibrationSettings" into sc-dev
This commit is contained in:
@@ -19,7 +19,10 @@ package com.android.server.vibrator;
|
|||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.app.IUidObserver;
|
import android.app.IUidObserver;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.database.ContentObserver;
|
import android.database.ContentObserver;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
@@ -61,6 +64,9 @@ final class VibrationSettings {
|
|||||||
private final SettingsObserver mSettingObserver;
|
private final SettingsObserver mSettingObserver;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
final UidObserver mUidObserver;
|
final UidObserver mUidObserver;
|
||||||
|
@VisibleForTesting
|
||||||
|
final UserObserver mUserReceiver;
|
||||||
|
|
||||||
|
|
||||||
@GuardedBy("mLock")
|
@GuardedBy("mLock")
|
||||||
private final List<OnVibratorSettingsChanged> mListeners = new ArrayList<>();
|
private final List<OnVibratorSettingsChanged> mListeners = new ArrayList<>();
|
||||||
@@ -94,6 +100,7 @@ final class VibrationSettings {
|
|||||||
mContext = context;
|
mContext = context;
|
||||||
mSettingObserver = new SettingsObserver(handler);
|
mSettingObserver = new SettingsObserver(handler);
|
||||||
mUidObserver = new UidObserver();
|
mUidObserver = new UidObserver();
|
||||||
|
mUserReceiver = new UserObserver();
|
||||||
|
|
||||||
VibrationEffect clickEffect = createEffectFromResource(
|
VibrationEffect clickEffect = createEffectFromResource(
|
||||||
com.android.internal.R.array.config_virtualKeyVibePattern);
|
com.android.internal.R.array.config_virtualKeyVibePattern);
|
||||||
@@ -150,6 +157,7 @@ final class VibrationSettings {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
mContext.registerReceiver(mUserReceiver, new IntentFilter(Intent.ACTION_USER_SWITCHED));
|
||||||
registerSettingsObserver(Settings.System.getUriFor(Settings.System.VIBRATE_INPUT_DEVICES));
|
registerSettingsObserver(Settings.System.getUriFor(Settings.System.VIBRATE_INPUT_DEVICES));
|
||||||
registerSettingsObserver(Settings.System.getUriFor(Settings.System.VIBRATE_WHEN_RINGING));
|
registerSettingsObserver(Settings.System.getUriFor(Settings.System.VIBRATE_WHEN_RINGING));
|
||||||
registerSettingsObserver(Settings.Global.getUriFor(Settings.Global.APPLY_RAMPING_RINGER));
|
registerSettingsObserver(Settings.Global.getUriFor(Settings.Global.APPLY_RAMPING_RINGER));
|
||||||
@@ -457,6 +465,17 @@ final class VibrationSettings {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Implementation of {@link BroadcastReceiver} to update settings on current user change. */
|
||||||
|
@VisibleForTesting
|
||||||
|
final class UserObserver extends BroadcastReceiver {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
|
||||||
|
updateSettings();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Implementation of {@link ContentObserver} to be registered to a setting {@link Uri}. */
|
/** Implementation of {@link ContentObserver} to be registered to a setting {@link Uri}. */
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
final class UidObserver extends IUidObserver.Stub {
|
final class UidObserver extends IUidObserver.Stub {
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import android.app.ActivityManager;
|
|||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.ContextWrapper;
|
import android.content.ContextWrapper;
|
||||||
|
import android.content.Intent;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.PowerManagerInternal;
|
import android.os.PowerManagerInternal;
|
||||||
@@ -69,6 +70,7 @@ import org.mockito.junit.MockitoRule;
|
|||||||
public class VibrationSettingsTest {
|
public class VibrationSettingsTest {
|
||||||
|
|
||||||
private static final int UID = 1;
|
private static final int UID = 1;
|
||||||
|
private static final int USER_OPERATION_TIMEOUT_MILLIS = 60_000; // 1 min
|
||||||
private static final PowerSaveState NORMAL_POWER_STATE = new PowerSaveState.Builder().build();
|
private static final PowerSaveState NORMAL_POWER_STATE = new PowerSaveState.Builder().build();
|
||||||
private static final PowerSaveState LOW_POWER_STATE = new PowerSaveState.Builder()
|
private static final PowerSaveState LOW_POWER_STATE = new PowerSaveState.Builder()
|
||||||
.setBatterySaverEnabled(true).build();
|
.setBatterySaverEnabled(true).build();
|
||||||
@@ -407,6 +409,25 @@ public class VibrationSettingsTest {
|
|||||||
mVibrationSettings.getCurrentIntensity(VibrationAttributes.USAGE_RINGTONE));
|
mVibrationSettings.getCurrentIntensity(VibrationAttributes.USAGE_RINGTONE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getCurrentIntensity_updateTriggeredAfterUserSwitched() {
|
||||||
|
mFakeVibrator.setDefaultRingVibrationIntensity(Vibrator.VIBRATION_INTENSITY_OFF);
|
||||||
|
setUserSetting(Settings.System.RING_VIBRATION_INTENSITY,
|
||||||
|
Vibrator.VIBRATION_INTENSITY_HIGH);
|
||||||
|
assertEquals(Vibrator.VIBRATION_INTENSITY_HIGH,
|
||||||
|
mVibrationSettings.getCurrentIntensity(VibrationAttributes.USAGE_RINGTONE));
|
||||||
|
|
||||||
|
// Switching user is not working with FakeSettingsProvider.
|
||||||
|
// Testing the broadcast flow manually.
|
||||||
|
Settings.System.putIntForUser(mContextSpy.getContentResolver(),
|
||||||
|
Settings.System.RING_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_LOW,
|
||||||
|
UserHandle.USER_CURRENT);
|
||||||
|
mVibrationSettings.mUserReceiver.onReceive(mContextSpy,
|
||||||
|
new Intent(Intent.ACTION_USER_SWITCHED));
|
||||||
|
assertEquals(Vibrator.VIBRATION_INTENSITY_LOW,
|
||||||
|
mVibrationSettings.getCurrentIntensity(VibrationAttributes.USAGE_RINGTONE));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getFallbackEffect_returnsEffectsFromSettings() {
|
public void getFallbackEffect_returnsEffectsFromSettings() {
|
||||||
assertNotNull(mVibrationSettings.getFallbackEffect(VibrationEffect.EFFECT_TICK));
|
assertNotNull(mVibrationSettings.getFallbackEffect(VibrationEffect.EFFECT_TICK));
|
||||||
|
|||||||
Reference in New Issue
Block a user