summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRemi NGUYEN VAN <reminv@google.com>2020-06-01 11:49:29 +0000
committerRemi NGUYEN VAN <reminv@google.com>2020-06-02 00:13:03 +0000
commit3f5206b726944271f5a58759e8a348fe810c15cd (patch)
treea1485ce1821d66216d9f856de2cbf82eee8dc6a8 /src
parentd44616a143669a0c940c92a717da3c602ba54525 (diff)
Fix venue info notification not displaying
The venue info notification was never displayed, because querying the notification channel from UserHandle.ALL returns no channel. Channels must be handled from the NetworkStack (owner) user, not the ALL user that is used to send notifications. Bug: 157203874 Test: atest NetworkStackTests; manual: verified showing or disabling the notification as owner or alternate user. Original-Change: https://android-review.googlesource.com/1321357 Merged-In: I9ce908cebdef81bb524353219f7ee9ead2487056 Change-Id: I9ce908cebdef81bb524353219f7ee9ead2487056
Diffstat (limited to 'src')
-rw-r--r--src/com/android/networkstack/NetworkStackNotifier.java22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/com/android/networkstack/NetworkStackNotifier.java b/src/com/android/networkstack/NetworkStackNotifier.java
index a330c70..872834a 100644
--- a/src/com/android/networkstack/NetworkStackNotifier.java
+++ b/src/com/android/networkstack/NetworkStackNotifier.java
@@ -16,6 +16,8 @@
package com.android.networkstack;
+import static android.app.NotificationManager.IMPORTANCE_NONE;
+
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
@@ -142,7 +144,19 @@ public class NetworkStackNotifier {
resources.getString(title),
importance);
channel.setDescription(resources.getString(description));
- mNotificationManager.createNotificationChannel(channel);
+ getNotificationManagerForChannels().createNotificationChannel(channel);
+ }
+
+ /**
+ * Get the NotificationManager to use to query channels, as opposed to posting notifications.
+ *
+ * Although notifications are posted as USER_ALL, notification channels are always created
+ * based on the UID calling NotificationManager, regardless of the context UserHandle.
+ * When querying notification channels, using a USER_ALL context would return no channel: the
+ * default context (as UserHandle 0 for NetworkStack) must be used.
+ */
+ private NotificationManager getNotificationManagerForChannels() {
+ return mContext.getSystemService(NotificationManager.class);
}
/**
@@ -284,7 +298,11 @@ public class NetworkStackNotifier {
}
private boolean isVenueInfoNotificationEnabled() {
- return mNotificationManager.getNotificationChannel(CHANNEL_VENUE_INFO) != null;
+ final NotificationChannel channel = getNotificationManagerForChannels()
+ .getNotificationChannel(CHANNEL_VENUE_INFO);
+ if (channel == null) return false;
+
+ return channel.getImportance() != IMPORTANCE_NONE;
}
private static String getNotificationTag(@NonNull Network network) {