summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apex/sdkextensions/derive_sdk/derive_sdk.cpp2
-rw-r--r--apex/sdkextensions/framework/java/android/os/ext/SdkExtensions.java2
-rw-r--r--api/current.txt1
-rw-r--r--core/java/android/app/INotificationManager.aidl3
-rw-r--r--core/java/android/provider/Settings.java11
-rw-r--r--core/java/android/service/notification/ConversationChannelWrapper.aidl19
-rw-r--r--core/java/android/service/notification/ConversationChannelWrapper.java122
-rw-r--r--core/proto/android/app/settings_enums.proto4
-rwxr-xr-xservices/core/java/com/android/server/notification/NotificationManagerService.java27
-rw-r--r--services/core/java/com/android/server/notification/PreferencesHelper.java38
-rwxr-xr-xservices/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java59
-rw-r--r--services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java97
12 files changed, 380 insertions, 5 deletions
diff --git a/apex/sdkextensions/derive_sdk/derive_sdk.cpp b/apex/sdkextensions/derive_sdk/derive_sdk.cpp
index 6fb7ef43416e..900193a6bd0d 100644
--- a/apex/sdkextensions/derive_sdk/derive_sdk.cpp
+++ b/apex/sdkextensions/derive_sdk/derive_sdk.cpp
@@ -69,7 +69,7 @@ int main(int, char**) {
auto itr = std::min_element(versions.begin(), versions.end());
std::string prop_value = itr == versions.end() ? "0" : std::to_string(*itr);
- if (!android::base::SetProperty("ro.build.version.extensions.r", prop_value)) {
+ if (!android::base::SetProperty("build.version.extensions.r", prop_value)) {
LOG(ERROR) << "failed to set sdk_info prop";
return EXIT_FAILURE;
}
diff --git a/apex/sdkextensions/framework/java/android/os/ext/SdkExtensions.java b/apex/sdkextensions/framework/java/android/os/ext/SdkExtensions.java
index a8a7effa9b6c..103b53e81db5 100644
--- a/apex/sdkextensions/framework/java/android/os/ext/SdkExtensions.java
+++ b/apex/sdkextensions/framework/java/android/os/ext/SdkExtensions.java
@@ -38,7 +38,7 @@ public class SdkExtensions {
private static final int R_EXTENSION_INT;
static {
- R_EXTENSION_INT = SystemProperties.getInt("ro.build.version.extensions.r", 0);
+ R_EXTENSION_INT = SystemProperties.getInt("build.version.extensions.r", 0);
}
/**
diff --git a/api/current.txt b/api/current.txt
index 977dcde6a072..826d409b0a2d 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -40417,6 +40417,7 @@ package android.provider {
field public static final String EXTRA_BATTERY_SAVER_MODE_ENABLED = "android.settings.extra.battery_saver_mode_enabled";
field public static final String EXTRA_BIOMETRIC_MINIMUM_STRENGTH_REQUIRED = "android.provider.extra.BIOMETRIC_MINIMUM_STRENGTH_REQUIRED";
field public static final String EXTRA_CHANNEL_ID = "android.provider.extra.CHANNEL_ID";
+ field public static final String EXTRA_CONVERSATION_ID = "android.provider.extra.CONVERSATION_ID";
field public static final String EXTRA_DO_NOT_DISTURB_MODE_ENABLED = "android.settings.extra.do_not_disturb_mode_enabled";
field public static final String EXTRA_DO_NOT_DISTURB_MODE_MINUTES = "android.settings.extra.do_not_disturb_mode_minutes";
field public static final String EXTRA_EASY_CONNECT_ATTEMPTED_SSID = "android.provider.extra.EASY_CONNECT_ATTEMPTED_SSID";
diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl
index 19397ed3ebaa..1d4a1acde434 100644
--- a/core/java/android/app/INotificationManager.aidl
+++ b/core/java/android/app/INotificationManager.aidl
@@ -88,6 +88,7 @@ interface INotificationManager
void createNotificationChannelGroups(String pkg, in ParceledListSlice channelGroupList);
void createNotificationChannels(String pkg, in ParceledListSlice channelsList);
void createNotificationChannelsForPackage(String pkg, int uid, in ParceledListSlice channelsList);
+ ParceledListSlice getConversationsForPackage(String pkg, int uid);
ParceledListSlice getNotificationChannelGroupsForPackage(String pkg, int uid, boolean includeDeleted);
NotificationChannelGroup getNotificationChannelGroupForPackage(String groupId, String pkg, int uid);
NotificationChannelGroup getPopulatedNotificationChannelGroupForPackage(String pkg, int uid, String groupId, boolean includeDeleted);
@@ -96,7 +97,7 @@ interface INotificationManager
NotificationChannel getNotificationChannel(String callingPkg, int userId, String pkg, String channelId);
NotificationChannel getConversationNotificationChannel(String callingPkg, int userId, String pkg, String channelId, boolean returnParentIfNoConversationChannel, String conversationId);
void createConversationNotificationChannelForPackage(String pkg, int uid, String triggeringKey, in NotificationChannel parentChannel, String conversationId);
- NotificationChannel getNotificationChannelForPackage(String pkg, int uid, String channelId, boolean includeDeleted);
+ NotificationChannel getNotificationChannelForPackage(String pkg, int uid, String channelId, String conversationId, boolean includeDeleted);
void deleteNotificationChannel(String pkg, String channelId);
void deleteConversationNotificationChannels(String pkg, int uid, String conversationId);
ParceledListSlice getNotificationChannels(String callingPkg, String targetPkg, int userId);
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 30e4eee08e8d..b9207e5a12d5 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -1830,6 +1830,17 @@ public final class Settings {
public static final String EXTRA_CHANNEL_ID = "android.provider.extra.CHANNEL_ID";
/**
+ * Activity Extra: The {@link NotificationChannel#getConversationId()} of the notification
+ * conversation settings to display.
+ * <p>
+ * This is an optional extra field to the {@link #ACTION_CHANNEL_NOTIFICATION_SETTINGS}. If
+ * included the system will first look up notification settings by channel and conversation id,
+ * and will fall back to channel id if a specialized channel for this conversation doesn't
+ * exist, similar to {@link NotificationManager#getNotificationChannel(String, String)}.
+ */
+ public static final String EXTRA_CONVERSATION_ID = "android.provider.extra.CONVERSATION_ID";
+
+ /**
* Activity Action: Show notification redaction settings.
*
* @hide
diff --git a/core/java/android/service/notification/ConversationChannelWrapper.aidl b/core/java/android/service/notification/ConversationChannelWrapper.aidl
new file mode 100644
index 000000000000..f3241586e252
--- /dev/null
+++ b/core/java/android/service/notification/ConversationChannelWrapper.aidl
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2020, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.service.notification;
+
+parcelable ConversationChannelWrapper; \ No newline at end of file
diff --git a/core/java/android/service/notification/ConversationChannelWrapper.java b/core/java/android/service/notification/ConversationChannelWrapper.java
new file mode 100644
index 000000000000..9847695ca5ee
--- /dev/null
+++ b/core/java/android/service/notification/ConversationChannelWrapper.java
@@ -0,0 +1,122 @@
+/**
+ * Copyright (c) 2020, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.service.notification;
+
+import android.app.NotificationChannel;
+import android.content.pm.ShortcutInfo;
+import android.graphics.drawable.Drawable;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import java.util.Objects;
+
+/**
+ * @hide
+ */
+public final class ConversationChannelWrapper implements Parcelable {
+
+ private NotificationChannel mNotificationChannel;
+ private CharSequence mGroupLabel;
+ private CharSequence mParentChannelLabel;
+ private ShortcutInfo mShortcutInfo;
+
+ public ConversationChannelWrapper() {}
+
+ protected ConversationChannelWrapper(Parcel in) {
+ mNotificationChannel = in.readParcelable(NotificationChannel.class.getClassLoader());
+ mGroupLabel = in.readCharSequence();
+ mParentChannelLabel = in.readCharSequence();
+ mShortcutInfo = in.readParcelable(ShortcutInfo.class.getClassLoader());
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeParcelable(mNotificationChannel, flags);
+ dest.writeCharSequence(mGroupLabel);
+ dest.writeCharSequence(mParentChannelLabel);
+ dest.writeParcelable(mShortcutInfo, flags);
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ public static final Creator<ConversationChannelWrapper> CREATOR =
+ new Creator<ConversationChannelWrapper>() {
+ @Override
+ public ConversationChannelWrapper createFromParcel(Parcel in) {
+ return new ConversationChannelWrapper(in);
+ }
+
+ @Override
+ public ConversationChannelWrapper[] newArray(int size) {
+ return new ConversationChannelWrapper[size];
+ }
+ };
+
+
+ public NotificationChannel getNotificationChannel() {
+ return mNotificationChannel;
+ }
+
+ public void setNotificationChannel(
+ NotificationChannel notificationChannel) {
+ mNotificationChannel = notificationChannel;
+ }
+
+ public CharSequence getGroupLabel() {
+ return mGroupLabel;
+ }
+
+ public void setGroupLabel(CharSequence groupLabel) {
+ mGroupLabel = groupLabel;
+ }
+
+ public CharSequence getParentChannelLabel() {
+ return mParentChannelLabel;
+ }
+
+ public void setParentChannelLabel(CharSequence parentChannelLabel) {
+ mParentChannelLabel = parentChannelLabel;
+ }
+
+ public ShortcutInfo getShortcutInfo() {
+ return mShortcutInfo;
+ }
+
+ public void setShortcutInfo(ShortcutInfo shortcutInfo) {
+ mShortcutInfo = shortcutInfo;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ ConversationChannelWrapper that = (ConversationChannelWrapper) o;
+ return Objects.equals(getNotificationChannel(), that.getNotificationChannel()) &&
+ Objects.equals(getGroupLabel(), that.getGroupLabel()) &&
+ Objects.equals(getParentChannelLabel(), that.getParentChannelLabel()) &&
+ Objects.equals(getShortcutInfo(), that.getShortcutInfo());
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(getNotificationChannel(), getGroupLabel(), getParentChannelLabel(),
+ getShortcutInfo());
+ }
+}
diff --git a/core/proto/android/app/settings_enums.proto b/core/proto/android/app/settings_enums.proto
index cc257973b860..4625418c1581 100644
--- a/core/proto/android/app/settings_enums.proto
+++ b/core/proto/android/app/settings_enums.proto
@@ -2587,4 +2587,8 @@ enum PageId {
// OPEN: Settings -> Apps & Notifications -> Special App Access
INTERACT_ACROSS_PROFILES = 1829;
+
+ // OPEN: Settings > Notifications > (app or conversations) > conversation
+ NOTIFICATION_CONVERSATION_SETTINGS = 1830;
+
}
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index f8777d618776..ea77c36c1498 100755
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -193,6 +193,7 @@ import android.provider.DeviceConfig;
import android.provider.Settings;
import android.service.notification.Adjustment;
import android.service.notification.Condition;
+import android.service.notification.ConversationChannelWrapper;
import android.service.notification.IConditionProvider;
import android.service.notification.INotificationListener;
import android.service.notification.IStatusBarNotificationHolder;
@@ -3221,9 +3222,10 @@ public class NotificationManagerService extends SystemService {
@Override
public NotificationChannel getNotificationChannelForPackage(String pkg, int uid,
- String channelId, boolean includeDeleted) {
+ String channelId, String conversationId, boolean includeDeleted) {
checkCallerIsSystem();
- return mPreferencesHelper.getNotificationChannel(pkg, uid, channelId, includeDeleted);
+ return mPreferencesHelper.getConversationNotificationChannel(
+ pkg, uid, channelId, conversationId, true, includeDeleted);
}
@Override
@@ -3360,6 +3362,27 @@ public class NotificationManagerService extends SystemService {
}
@Override
+ public ParceledListSlice<ConversationChannelWrapper> getConversationsForPackage(String pkg,
+ int uid) {
+ enforceSystemOrSystemUI("getConversationsForPackage");
+ ArrayList<ConversationChannelWrapper> conversations =
+ mPreferencesHelper.getConversations(pkg, uid);
+ for (ConversationChannelWrapper conversation : conversations) {
+ LauncherApps.ShortcutQuery query = new LauncherApps.ShortcutQuery()
+ .setPackage(pkg)
+ .setQueryFlags(FLAG_MATCH_DYNAMIC | FLAG_MATCH_PINNED)
+ .setShortcutIds(Arrays.asList(
+ conversation.getNotificationChannel().getConversationId()));
+ List<ShortcutInfo> shortcuts = mLauncherAppsService.getShortcuts(
+ query, UserHandle.of(UserHandle.getUserId(uid)));
+ if (shortcuts != null && !shortcuts.isEmpty()) {
+ conversation.setShortcutInfo(shortcuts.get(0));
+ }
+ }
+ return new ParceledListSlice<>(conversations);
+ }
+
+ @Override
public NotificationChannelGroup getPopulatedNotificationChannelGroupForPackage(
String pkg, int uid, String groupId, boolean includeDeleted) {
enforceSystemOrSystemUI("getPopulatedNotificationChannelGroupForPackage");
diff --git a/services/core/java/com/android/server/notification/PreferencesHelper.java b/services/core/java/com/android/server/notification/PreferencesHelper.java
index fe39322edb42..a244c48fab6a 100644
--- a/services/core/java/com/android/server/notification/PreferencesHelper.java
+++ b/services/core/java/com/android/server/notification/PreferencesHelper.java
@@ -36,6 +36,7 @@ import android.metrics.LogMaker;
import android.os.Build;
import android.os.UserHandle;
import android.provider.Settings;
+import android.service.notification.ConversationChannelWrapper;
import android.service.notification.NotificationListenerService;
import android.service.notification.RankingHelperProto;
import android.text.TextUtils;
@@ -1176,6 +1177,43 @@ public class PreferencesHelper implements RankingConfig {
return groups;
}
+ public ArrayList<ConversationChannelWrapper> getConversations(String pkg, int uid) {
+ Objects.requireNonNull(pkg);
+ synchronized (mPackagePreferences) {
+ PackagePreferences r = getPackagePreferencesLocked(pkg, uid);
+ if (r == null) {
+ return new ArrayList<>();
+ }
+ ArrayList<ConversationChannelWrapper> conversations = new ArrayList<>();
+ int N = r.channels.size();
+ for (int i = 0; i < N; i++) {
+ final NotificationChannel nc = r.channels.valueAt(i);
+ if (!TextUtils.isEmpty(nc.getConversationId()) && !nc.isDeleted()) {
+ ConversationChannelWrapper conversation = new ConversationChannelWrapper();
+ conversation.setNotificationChannel(nc);
+ conversation.setParentChannelLabel(
+ r.channels.get(nc.getParentChannelId()).getName());
+ boolean blockedByGroup = false;
+ if (nc.getGroup() != null) {
+ NotificationChannelGroup group = r.groups.get(nc.getGroup());
+ if (group != null) {
+ if (group.isBlocked()) {
+ blockedByGroup = true;
+ } else {
+ conversation.setGroupLabel(group.getName());
+ }
+ }
+ }
+ if (!blockedByGroup) {
+ conversations.add(conversation);
+ }
+ }
+ }
+
+ return conversations;
+ }
+ }
+
@Override
public ParceledListSlice<NotificationChannel> getNotificationChannels(String pkg, int uid,
boolean includeDeleted) {
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
index e0ee3ce3aa57..9ec339d88b23 100755
--- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
@@ -42,6 +42,8 @@ import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_SCREEN_OFF;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_SCREEN_ON;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_STATUS_BAR;
+import static android.content.pm.LauncherApps.ShortcutQuery.FLAG_MATCH_DYNAMIC;
+import static android.content.pm.LauncherApps.ShortcutQuery.FLAG_MATCH_PINNED;
import static android.content.pm.PackageManager.FEATURE_WATCH;
import static android.content.pm.PackageManager.PERMISSION_DENIED;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
@@ -128,6 +130,7 @@ import android.provider.DeviceConfig;
import android.provider.MediaStore;
import android.provider.Settings;
import android.service.notification.Adjustment;
+import android.service.notification.ConversationChannelWrapper;
import android.service.notification.NotificationListenerService;
import android.service.notification.NotificationStats;
import android.service.notification.StatusBarNotification;
@@ -6273,4 +6276,60 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
assertEquals(PRIORITY_CATEGORY_CALLS, actual);
}
+
+ @Test
+ public void testGetConversationsForPackage_hasShortcut() throws Exception {
+ mService.setPreferencesHelper(mPreferencesHelper);
+ ArrayList<ConversationChannelWrapper> convos = new ArrayList<>();
+ ConversationChannelWrapper convo1 = new ConversationChannelWrapper();
+ NotificationChannel channel1 = new NotificationChannel("a", "a", 1);
+ channel1.setConversationId("parent1", "convo 1");
+ convo1.setNotificationChannel(channel1);
+ convos.add(convo1);
+
+ ConversationChannelWrapper convo2 = new ConversationChannelWrapper();
+ NotificationChannel channel2 = new NotificationChannel("b", "b", 1);
+ channel2.setConversationId("parent1", "convo 2");
+ convo2.setNotificationChannel(channel2);
+ convos.add(convo2);
+ when(mPreferencesHelper.getConversations(anyString(), anyInt())).thenReturn(convos);
+
+ // only one valid shortcut
+ LauncherApps.ShortcutQuery query = new LauncherApps.ShortcutQuery()
+ .setPackage(PKG_P)
+ .setQueryFlags(FLAG_MATCH_DYNAMIC | FLAG_MATCH_PINNED)
+ .setShortcutIds(Arrays.asList(channel1.getConversationId()));
+ ShortcutInfo si = mock(ShortcutInfo.class);
+ when(si.getShortLabel()).thenReturn("Hello");
+ when(mLauncherApps.getShortcuts(any(), any())).thenReturn(Arrays.asList(si));
+
+ List<ConversationChannelWrapper> conversations =
+ mBinderService.getConversationsForPackage(PKG_P, mUid).getList();
+ assertEquals(si, conversations.get(0).getShortcutInfo());
+ assertEquals(si, conversations.get(1).getShortcutInfo());
+
+ }
+
+ @Test
+ public void testGetConversationsForPackage_doesNotHaveShortcut() throws Exception {
+ mService.setPreferencesHelper(mPreferencesHelper);
+ ArrayList<ConversationChannelWrapper> convos = new ArrayList<>();
+ ConversationChannelWrapper convo1 = new ConversationChannelWrapper();
+ NotificationChannel channel1 = new NotificationChannel("a", "a", 1);
+ channel1.setConversationId("parent1", "convo 1");
+ convo1.setNotificationChannel(channel1);
+ convos.add(convo1);
+
+ ConversationChannelWrapper convo2 = new ConversationChannelWrapper();
+ NotificationChannel channel2 = new NotificationChannel("b", "b", 1);
+ channel2.setConversationId("parent1", "convo 2");
+ convo2.setNotificationChannel(channel2);
+ convos.add(convo2);
+ when(mPreferencesHelper.getConversations(anyString(), anyInt())).thenReturn(convos);
+
+ List<ConversationChannelWrapper> conversations =
+ mBinderService.getConversationsForPackage(PKG_P, mUid).getList();
+ assertNull(conversations.get(0).getShortcutInfo());
+ assertNull(conversations.get(1).getShortcutInfo());
+ }
}
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java b/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java
index bb84b04361ea..3f690b105d8b 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java
@@ -26,6 +26,8 @@ import static android.util.FeatureFlagUtils.NOTIF_CONVO_BYPASS_SHORTCUT_REQ;
import static com.android.server.notification.PreferencesHelper.NOTIFICATION_CHANNEL_COUNT_LIMIT;
+import static com.google.common.truth.Truth.assertThat;
+
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.fail;
@@ -64,6 +66,7 @@ import android.os.UserHandle;
import android.provider.Settings;
import android.provider.Settings.Global;
import android.provider.Settings.Secure;
+import android.service.notification.ConversationChannelWrapper;
import android.test.suitebuilder.annotation.SmallTest;
import android.testing.TestableContentResolver;
import android.util.ArrayMap;
@@ -91,6 +94,7 @@ import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@@ -2939,4 +2943,97 @@ public class PreferencesHelperTest extends UiServiceTestCase {
assertNotNull(mHelper.getNotificationChannel(PKG_O, UID_O, "id", true));
}
+
+ @Test
+ public void testGetConversations_invalidPkg() {
+ assertThat(mHelper.getConversations("bad", 1)).isEmpty();
+ }
+
+ @Test
+ public void testGetConversations_noConversations() {
+ NotificationChannel channel =
+ new NotificationChannel("not_convo", "not_convo", IMPORTANCE_DEFAULT);
+ mHelper.createNotificationChannel(PKG_O, UID_O, channel, true, false);
+
+ assertThat(mHelper.getConversations(PKG_O, UID_O)).isEmpty();
+ }
+
+ @Test
+ public void testGetConversations_noDisabledGroups() {
+ NotificationChannelGroup group = new NotificationChannelGroup("a", "a");
+ group.setBlocked(true);
+ mHelper.createNotificationChannelGroup(PKG_O, UID_O, group, true);
+ NotificationChannel parent = new NotificationChannel("parent", "p", 1);
+ mHelper.createNotificationChannel(PKG_O, UID_O, parent, true, false);
+
+ NotificationChannel channel =
+ new NotificationChannel("convo", "convo", IMPORTANCE_DEFAULT);
+ channel.setConversationId("parent", "convo");
+ channel.setGroup(group.getId());
+ mHelper.createNotificationChannel(PKG_O, UID_O, channel, true, false);
+
+ assertThat(mHelper.getConversations(PKG_O, UID_O)).isEmpty();
+ }
+
+ @Test
+ public void testGetConversations_noDeleted() {
+ NotificationChannel parent = new NotificationChannel("parent", "p", 1);
+ mHelper.createNotificationChannel(PKG_O, UID_O, parent, true, false);
+ NotificationChannel channel =
+ new NotificationChannel("convo", "convo", IMPORTANCE_DEFAULT);
+ channel.setConversationId("parent", "convo");
+ mHelper.createNotificationChannel(PKG_O, UID_O, channel, true, false);
+ mHelper.deleteNotificationChannel(PKG_O, UID_O, channel.getId());
+
+ assertThat(mHelper.getConversations(PKG_O, UID_O)).isEmpty();
+ }
+
+ @Test
+ public void testGetConversations() {
+ NotificationChannelGroup group = new NotificationChannelGroup("acct", "account_name");
+ mHelper.createNotificationChannelGroup(PKG_O, UID_O, group, true);
+
+ NotificationChannel messages =
+ new NotificationChannel("messages", "Messages", IMPORTANCE_DEFAULT);
+ messages.setGroup(group.getId());
+ mHelper.createNotificationChannel(PKG_O, UID_O, messages, true, false);
+ NotificationChannel calls =
+ new NotificationChannel("calls", "Calls", IMPORTANCE_HIGH);
+ mHelper.createNotificationChannel(PKG_O, UID_O, calls, true, false);
+
+ NotificationChannel channel =
+ new NotificationChannel("A person", "A lovely person", IMPORTANCE_DEFAULT);
+ channel.setGroup(group.getId());
+ channel.setConversationId(messages.getId(), channel.getName().toString());
+ mHelper.createNotificationChannel(PKG_O, UID_O, channel, true, false);
+
+ NotificationChannel channel2 =
+ new NotificationChannel("B person", "B fabulous person", IMPORTANCE_DEFAULT);
+ channel2.setConversationId(calls.getId(), channel.getName().toString());
+ mHelper.createNotificationChannel(PKG_O, UID_O, channel2, true, false);
+
+ Map<String, NotificationChannel> expected = new HashMap<>();
+ expected.put(channel.getId(), channel);
+ expected.put(channel2.getId(), channel2);
+
+ Map<String, CharSequence> expectedGroup = new HashMap<>();
+ expectedGroup.put(channel.getId(), group.getName());
+ expectedGroup.put(channel2.getId(), null);
+
+ Map<String, CharSequence> expectedParentLabel= new HashMap<>();
+ expectedParentLabel.put(channel.getId(), messages.getName());
+ expectedParentLabel.put(channel2.getId(), calls.getName());
+
+ ArrayList<ConversationChannelWrapper> convos = mHelper.getConversations(PKG_O, UID_O);
+ assertThat(convos).hasSize(2);
+
+ for (ConversationChannelWrapper convo : convos) {
+ assertThat(convo.getNotificationChannel())
+ .isEqualTo(expected.get(convo.getNotificationChannel().getId()));
+ assertThat(convo.getParentChannelLabel())
+ .isEqualTo(expectedParentLabel.get(convo.getNotificationChannel().getId()));
+ assertThat(convo.getGroupLabel())
+ .isEqualTo(expectedGroup.get(convo.getNotificationChannel().getId()));
+ }
+ }
}