Loading services/core/java/com/android/server/devicestate/DeviceStateNotificationController.java +6 −3 Original line number Diff line number Diff line Loading @@ -109,6 +109,7 @@ class DeviceStateNotificationController extends BroadcastReceiver { .setPackage(mContext.getPackageName()); final PendingIntent pendingIntent = PendingIntent.getBroadcast( mContext, 0 /* requestCode */, intent, PendingIntent.FLAG_IMMUTABLE); showNotification( info.name, info.activeNotificationTitle, String.format(info.activeNotificationContent, requesterApplicationLabel), Loading Loading @@ -175,7 +176,7 @@ class DeviceStateNotificationController extends BroadcastReceiver { if (getNotificationInfos().get(state) == null) { return; } mNotificationManager.cancel(NOTIFICATION_TAG, NOTIFICATION_ID); mHandler.post(() -> mNotificationManager.cancel(NOTIFICATION_TAG, NOTIFICATION_ID)); } @Override Loading Loading @@ -219,8 +220,10 @@ class DeviceStateNotificationController extends BroadcastReceiver { builder.addAction(action); } mHandler.post(() -> { mNotificationManager.createNotificationChannel(channel); mNotificationManager.notify(NOTIFICATION_TAG, NOTIFICATION_ID, builder.build()); }); } private SparseArray<NotificationInfo> getNotificationInfos() { Loading services/tests/servicestests/src/com/android/server/devicestate/DeviceStateNotificationControllerTest.java +16 −1 Original line number Diff line number Diff line Loading @@ -33,6 +33,8 @@ import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.platform.test.annotations.Presubmit; import android.util.SparseArray; Loading Loading @@ -89,11 +91,12 @@ public class DeviceStateNotificationControllerTest { @Before public void setup() throws Exception { Context context = InstrumentationRegistry.getInstrumentation().getContext(); Handler handler = mock(Handler.class); PackageManager packageManager = mock(PackageManager.class); Runnable cancelStateRunnable = mock(Runnable.class); ApplicationInfo applicationInfo = mock(ApplicationInfo.class); Handler handler = new DeviceStateNotificationControllerTestHandler(Looper.getMainLooper()); final SparseArray<DeviceStateNotificationController.NotificationInfo> notificationInfos = new SparseArray<>(); notificationInfos.put(STATE_WITH_ACTIVE_NOTIFICATION, Loading Loading @@ -259,4 +262,16 @@ public class DeviceStateNotificationControllerTest { assertEquals(Locale.ITALY, mNotificationInfoProvider.getCachedLocale()); clearInvocations(mNotificationInfoProvider); } private static class DeviceStateNotificationControllerTestHandler extends Handler { DeviceStateNotificationControllerTestHandler(Looper looper) { super(looper); } @Override public boolean sendMessageAtTime(Message msg, long uptimeMillis) { msg.getCallback().run(); return true; } } } Loading
services/core/java/com/android/server/devicestate/DeviceStateNotificationController.java +6 −3 Original line number Diff line number Diff line Loading @@ -109,6 +109,7 @@ class DeviceStateNotificationController extends BroadcastReceiver { .setPackage(mContext.getPackageName()); final PendingIntent pendingIntent = PendingIntent.getBroadcast( mContext, 0 /* requestCode */, intent, PendingIntent.FLAG_IMMUTABLE); showNotification( info.name, info.activeNotificationTitle, String.format(info.activeNotificationContent, requesterApplicationLabel), Loading Loading @@ -175,7 +176,7 @@ class DeviceStateNotificationController extends BroadcastReceiver { if (getNotificationInfos().get(state) == null) { return; } mNotificationManager.cancel(NOTIFICATION_TAG, NOTIFICATION_ID); mHandler.post(() -> mNotificationManager.cancel(NOTIFICATION_TAG, NOTIFICATION_ID)); } @Override Loading Loading @@ -219,8 +220,10 @@ class DeviceStateNotificationController extends BroadcastReceiver { builder.addAction(action); } mHandler.post(() -> { mNotificationManager.createNotificationChannel(channel); mNotificationManager.notify(NOTIFICATION_TAG, NOTIFICATION_ID, builder.build()); }); } private SparseArray<NotificationInfo> getNotificationInfos() { Loading
services/tests/servicestests/src/com/android/server/devicestate/DeviceStateNotificationControllerTest.java +16 −1 Original line number Diff line number Diff line Loading @@ -33,6 +33,8 @@ import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.platform.test.annotations.Presubmit; import android.util.SparseArray; Loading Loading @@ -89,11 +91,12 @@ public class DeviceStateNotificationControllerTest { @Before public void setup() throws Exception { Context context = InstrumentationRegistry.getInstrumentation().getContext(); Handler handler = mock(Handler.class); PackageManager packageManager = mock(PackageManager.class); Runnable cancelStateRunnable = mock(Runnable.class); ApplicationInfo applicationInfo = mock(ApplicationInfo.class); Handler handler = new DeviceStateNotificationControllerTestHandler(Looper.getMainLooper()); final SparseArray<DeviceStateNotificationController.NotificationInfo> notificationInfos = new SparseArray<>(); notificationInfos.put(STATE_WITH_ACTIVE_NOTIFICATION, Loading Loading @@ -259,4 +262,16 @@ public class DeviceStateNotificationControllerTest { assertEquals(Locale.ITALY, mNotificationInfoProvider.getCachedLocale()); clearInvocations(mNotificationInfoProvider); } private static class DeviceStateNotificationControllerTestHandler extends Handler { DeviceStateNotificationControllerTestHandler(Looper looper) { super(looper); } @Override public boolean sendMessageAtTime(Message msg, long uptimeMillis) { msg.getCallback().run(); return true; } } }