Skip to content
Snippets Groups Projects
Commit adf801d3 authored by Kenneth Ford's avatar Kenneth Ford Committed by Automerger Merge Worker
Browse files

Merge "Posts DeviceStateManager notifications to a handler" into udc-qpr-dev am: e6139fcd

parents 2c0ccc08 e6139fcd
No related branches found
No related tags found
No related merge requests found
......@@ -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),
......@@ -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
......@@ -219,8 +220,10 @@ class DeviceStateNotificationController extends BroadcastReceiver {
builder.addAction(action);
}
mNotificationManager.createNotificationChannel(channel);
mNotificationManager.notify(NOTIFICATION_TAG, NOTIFICATION_ID, builder.build());
mHandler.post(() -> {
mNotificationManager.createNotificationChannel(channel);
mNotificationManager.notify(NOTIFICATION_TAG, NOTIFICATION_ID, builder.build());
});
}
private SparseArray<NotificationInfo> getNotificationInfos() {
......
......@@ -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;
......@@ -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,
......@@ -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;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment