Vibrate as system instead of as an app am: aec7cbecdc
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13875192 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: I9c2f9061c91ffe54e3981535fc64049b58aff194
This commit is contained in:
@@ -7157,15 +7157,7 @@ public class NotificationManagerService extends SystemService {
|
||||
// so need to check the notification still valide for vibrate.
|
||||
synchronized (mNotificationLock) {
|
||||
if (mNotificationsByKey.get(record.getKey()) != null) {
|
||||
// Vibrator checks the appops for the op package, not the caller,
|
||||
// so we need to add the bypass dnd flag to be heard. it's ok to
|
||||
// always add this flag here because we've already checked that we can
|
||||
// bypass dnd
|
||||
AudioAttributes.Builder aab =
|
||||
new AudioAttributes.Builder(record.getAudioAttributes())
|
||||
.setFlags(FLAG_BYPASS_INTERRUPTION_POLICY);
|
||||
mVibrator.vibrate(record.getSbn().getUid(), record.getSbn().getOpPkg(),
|
||||
effect, "Notification (delayed)", aab.build());
|
||||
vibrate(record, effect, true);
|
||||
} else {
|
||||
Slog.e(TAG, "No vibration for canceled notification : "
|
||||
+ record.getKey());
|
||||
@@ -7173,8 +7165,7 @@ public class NotificationManagerService extends SystemService {
|
||||
}
|
||||
}).start();
|
||||
} else {
|
||||
mVibrator.vibrate(record.getSbn().getUid(), record.getSbn().getPackageName(),
|
||||
effect, "Notification", record.getAudioAttributes());
|
||||
vibrate(record, effect, false);
|
||||
}
|
||||
return true;
|
||||
} finally{
|
||||
@@ -7182,6 +7173,16 @@ public class NotificationManagerService extends SystemService {
|
||||
}
|
||||
}
|
||||
|
||||
private void vibrate(NotificationRecord record, VibrationEffect effect, boolean delayed) {
|
||||
// We need to vibrate as "android" so we can breakthrough DND. VibratorManagerService
|
||||
// doesn't have a concept of vibrating on an app's behalf, so add the app information
|
||||
// to the reason so we can still debug from bugreports
|
||||
String reason = "Notification (" + record.getSbn().getOpPkg() + " "
|
||||
+ record.getSbn().getUid() + ") " + (delayed ? "(Delayed)" : "");
|
||||
mVibrator.vibrate(Process.SYSTEM_UID, PackageManagerService.PLATFORM_PACKAGE_NAME,
|
||||
effect, reason, record.getAudioAttributes());
|
||||
}
|
||||
|
||||
private boolean isNotificationForCurrentUser(NotificationRecord record) {
|
||||
final int currentUser;
|
||||
final long token = Binder.clearCallingIdentity();
|
||||
|
||||
@@ -57,6 +57,7 @@ import android.media.AudioAttributes;
|
||||
import android.media.AudioManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.Process;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserHandle;
|
||||
import android.os.VibrationEffect;
|
||||
@@ -77,10 +78,12 @@ import com.android.internal.logging.InstanceIdSequenceFake;
|
||||
import com.android.internal.util.IntPair;
|
||||
import com.android.server.UiServiceTestCase;
|
||||
import com.android.server.lights.LogicalLight;
|
||||
import com.android.server.pm.PackageManagerService;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.ArgumentMatcher;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
@@ -407,12 +410,17 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase {
|
||||
}
|
||||
|
||||
private void verifyVibrate() {
|
||||
ArgumentCaptor<AudioAttributes> captor = ArgumentCaptor.forClass(AudioAttributes.class);
|
||||
verify(mVibrator, times(1)).vibrate(anyInt(), anyString(), argThat(mVibrateOnceMatcher),
|
||||
anyString(), any());
|
||||
anyString(), captor.capture());
|
||||
assertEquals(0, (captor.getValue().getAllFlags()
|
||||
& AudioAttributes.FLAG_BYPASS_INTERRUPTION_POLICY));
|
||||
}
|
||||
|
||||
private void verifyVibrate(int times) {
|
||||
verify(mVibrator, times(times)).vibrate(anyInt(), anyString(), any(), anyString(), any());
|
||||
verify(mVibrator, times(times)).vibrate(eq(Process.SYSTEM_UID),
|
||||
eq(PackageManagerService.PLATFORM_PACKAGE_NAME), any(), anyString(),
|
||||
any(AudioAttributes.class));
|
||||
}
|
||||
|
||||
private void verifyVibrateLooped() {
|
||||
|
||||
Reference in New Issue
Block a user