| Index: chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationManagerProxyImpl.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationManagerProxyImpl.java b/chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationManagerProxyImpl.java
|
| index 46d2a103ce07b3e821cd369ceaa0366c47709b0d..f7092994130e4b2fd3b0c231cbb89be10f68be90 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationManagerProxyImpl.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationManagerProxyImpl.java
|
| @@ -14,6 +14,8 @@ import org.chromium.base.Log;
|
| import java.lang.reflect.Constructor;
|
| import java.lang.reflect.InvocationTargetException;
|
| import java.lang.reflect.Method;
|
| +import java.util.ArrayList;
|
| +import java.util.List;
|
|
|
| /**
|
| * Default implementation of the NotificationManagerProxy, which passes through all calls to the
|
| @@ -112,6 +114,52 @@ public class NotificationManagerProxyImpl implements NotificationManagerProxy {
|
| }
|
|
|
| @Override
|
| + public List<String> getNotificationChannelIds() {
|
| + assert BuildInfo.isAtLeastO();
|
| + List<String> channelIds = new ArrayList<>();
|
| + /*
|
| + The code in the try-block uses reflection in order to compile as it calls APIs newer than
|
| + our compileSdkVersion of Android. The equivalent code without reflection looks like this:
|
| +
|
| + List<NotificationChannel> list = mNotificationManager.getNotificationChannels();
|
| + for (NotificationChannel channel : list) {
|
| + channelIds.add(channel.getId());
|
| + }
|
| + */
|
| + // TODO(crbug.com/707804) Stop using reflection once compileSdkVersion is high enough.
|
| + try {
|
| + Method method = mNotificationManager.getClass().getMethod("getNotificationChannels");
|
| + List channelsList = (List) method.invoke(mNotificationManager);
|
| + for (Object o : channelsList) {
|
| + Method getId = o.getClass().getMethod("getId");
|
| + channelIds.add((String) getId.invoke(o));
|
| + }
|
| + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
| + Log.e(TAG, "Error getting notification channels:", e);
|
| + }
|
| + return channelIds;
|
| + }
|
| +
|
| + @Override
|
| + public void deleteNotificationChannel(@ChannelsInitializer.ChannelId String id) {
|
| + assert BuildInfo.isAtLeastO();
|
| + /*
|
| + The code in the try-block uses reflection in order to compile as it calls APIs newer than
|
| + our compileSdkVersion of Android. The equivalent code without reflection looks like this:
|
| +
|
| + mNotificationManager.deleteNotificationChannel(id);
|
| + */
|
| + // TODO(crbug.com/707804) Stop using reflection once compileSdkVersion is high enough.
|
| + try {
|
| + Method method = mNotificationManager.getClass().getMethod(
|
| + "deleteNotificationChannel", String.class);
|
| + method.invoke(mNotificationManager, id);
|
| + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
| + Log.e(TAG, "Error deleting notification channel:", e);
|
| + }
|
| + }
|
| +
|
| + @Override
|
| public void notify(int id, Notification notification) {
|
| mNotificationManager.notify(id, notification);
|
| }
|
|
|