Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1554)

Unified Diff: services/notifications/src/org/chromium/mojo/notifications/NotificationServiceImpl.java

Issue 1513553003: Fix notifications selection when there is not task. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/notifications/src/org/chromium/mojo/notifications/NotificationServiceImpl.java
diff --git a/services/notifications/src/org/chromium/mojo/notifications/NotificationServiceImpl.java b/services/notifications/src/org/chromium/mojo/notifications/NotificationServiceImpl.java
index d756d3178b91e02b180d1a2d34fa022c9750020d..9cd335b135c7ee867de8244a7656855ecc91034a 100644
--- a/services/notifications/src/org/chromium/mojo/notifications/NotificationServiceImpl.java
+++ b/services/notifications/src/org/chromium/mojo/notifications/NotificationServiceImpl.java
@@ -38,8 +38,10 @@ class NotificationServiceImpl implements NotificationService,
private final String mNotificationManagerTag;
private final NotificationBuilder mNotificationBuilder;
- private final ActivityManager.AppTask mAppTask;
+ private final ActivityManager mActivityManager;
+
private int mNextNotificationId;
+ private ActivityManager.AppTask mAppTask;
NotificationServiceImpl(
Context context, Core core, Shell shell, int notificationIconResourceId) {
@@ -52,9 +54,8 @@ class NotificationServiceImpl implements NotificationService,
core, shell, "mojo:intent_receiver", IntentReceiverManager.MANAGER);
mNotificationBuilder = new NotificationBuilder(
context, intentReceiverManager, notificationIconResourceId, this, this);
- ActivityManager activityManager =
- (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
- List<ActivityManager.AppTask> tasks = activityManager.getAppTasks();
+ mActivityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
+ List<ActivityManager.AppTask> tasks = mActivityManager.getAppTasks();
// Associate the service instance with the current top task of the shell
// application. All notifications created by this instance will be associated with
// this task too, and the task will be foregrounded when any of the notifications
@@ -86,7 +87,15 @@ class NotificationServiceImpl implements NotificationService,
public void onNotificationSelected(int notificationId) {
NotificationClient client = mNotificationClientMap.get(notificationId);
if (client != null) {
- mAppTask.moveToFront();
+ // If the selected task is not active anymore, choose the most recent one and associate
+ // this service with it.
+ if (mAppTask == null || mAppTask.getTaskInfo().id == -1) {
+ List<ActivityManager.AppTask> tasks = mActivityManager.getAppTasks();
+ mAppTask = tasks.isEmpty() ? null : tasks.get(0);
+ }
+ if (mAppTask != null) {
+ mAppTask.moveToFront();
+ }
client.onSelected();
}
// Since autoCancel is set to true (@see NotificationBuilder#build(int, NotificationData)),
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698