| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.notifications; | 5 package org.chromium.chrome.browser.notifications; |
| 6 | 6 |
| 7 import android.annotation.TargetApi; | 7 import android.annotation.TargetApi; |
| 8 import android.app.NotificationManager; | 8 import android.app.NotificationManager; |
| 9 import android.os.Build; | 9 import android.os.Build; |
| 10 import android.support.annotation.StringDef; | 10 import android.support.annotation.StringDef; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 */ | 26 */ |
| 27 public class ChannelDefinitions { | 27 public class ChannelDefinitions { |
| 28 public static final String CHANNEL_ID_BROWSER = "browser"; | 28 public static final String CHANNEL_ID_BROWSER = "browser"; |
| 29 public static final String CHANNEL_ID_DOWNLOADS = "downloads"; | 29 public static final String CHANNEL_ID_DOWNLOADS = "downloads"; |
| 30 public static final String CHANNEL_ID_INCOGNITO = "incognito"; | 30 public static final String CHANNEL_ID_INCOGNITO = "incognito"; |
| 31 public static final String CHANNEL_ID_MEDIA = "media"; | 31 public static final String CHANNEL_ID_MEDIA = "media"; |
| 32 public static final String CHANNEL_ID_SITES = "sites"; | 32 public static final String CHANNEL_ID_SITES = "sites"; |
| 33 static final String CHANNEL_GROUP_ID_GENERAL = "general"; | 33 static final String CHANNEL_GROUP_ID_GENERAL = "general"; |
| 34 /** | 34 /** |
| 35 * Version number identifying the current set of channels. This must be incr
emented whenever | 35 * Version number identifying the current set of channels. This must be incr
emented whenever |
| 36 * any channels are added or removed from the set of channels created in | 36 * the set of channels returned by {@link #getStartupChannelIds()} or |
| 37 * {@link ChannelsInitializer#initializeStartupChannels()}. | 37 * {@link #getLegacyChannelIds()} changes. |
| 38 */ | 38 */ |
| 39 static final int CHANNELS_VERSION = 0; | 39 static final int CHANNELS_VERSION = 0; |
| 40 | 40 |
| 41 // To define a new channel, add the channel ID to this StringDef and add a n
ew entry to | 41 /** |
| 42 // PredefinedChannels.MAP below with the appropriate channel parameters. | 42 * To define a new channel, add the channel ID to this StringDef and add a n
ew entry to |
| 43 * PredefinedChannels.MAP below with the appropriate channel parameters. |
| 44 * To remove an existing channel, remove the ID from this StringDef, remove
its entry from |
| 45 * Predefined Channels.MAP, and add the ID to the LEGACY_CHANNELS_ID array b
elow. |
| 46 */ |
| 43 @StringDef({CHANNEL_ID_BROWSER, CHANNEL_ID_DOWNLOADS, CHANNEL_ID_INCOGNITO,
CHANNEL_ID_MEDIA, | 47 @StringDef({CHANNEL_ID_BROWSER, CHANNEL_ID_DOWNLOADS, CHANNEL_ID_INCOGNITO,
CHANNEL_ID_MEDIA, |
| 44 CHANNEL_ID_SITES}) | 48 CHANNEL_ID_SITES}) |
| 45 @Retention(RetentionPolicy.SOURCE) | 49 @Retention(RetentionPolicy.SOURCE) |
| 46 public @interface ChannelId {} | 50 public @interface ChannelId {} |
| 47 | 51 |
| 48 @StringDef({CHANNEL_GROUP_ID_GENERAL}) | 52 @StringDef({CHANNEL_GROUP_ID_GENERAL}) |
| 49 @Retention(RetentionPolicy.SOURCE) | 53 @Retention(RetentionPolicy.SOURCE) |
| 50 @interface ChannelGroupId {} | 54 @interface ChannelGroupId {} |
| 51 | 55 |
| 52 // Map defined in static inner class so it's only initialized lazily. | 56 // Map defined in static inner class so it's only initialized lazily. |
| 53 @TargetApi(Build.VERSION_CODES.N) // for NotificationManager.IMPORTANCE_* co
nstants | 57 @TargetApi(Build.VERSION_CODES.N) // for NotificationManager.IMPORTANCE_* co
nstants |
| 54 private static class PredefinedChannels { | 58 private static class PredefinedChannels { |
| 55 /** | 59 /** |
| 56 * The set of predefined channels to be initialized on startup. CHANNELS
_VERSION must be | 60 * The set of predefined channels to be initialized on startup. CHANNELS
_VERSION must be |
| 57 * incremented every time an entry is modified, removed or added to this
map. | 61 * incremented every time an entry is modified, removed or added to this
map. |
| 62 * If an entry is removed from here then it must be added to the LEGACY_
CHANNEL_IDs array. |
| 58 */ | 63 */ |
| 59 static final Map<String, Channel> MAP; | 64 static final Map<String, Channel> MAP; |
| 60 static { | 65 static { |
| 61 Map<String, Channel> map = new HashMap<>(); | 66 Map<String, Channel> map = new HashMap<>(); |
| 62 map.put(CHANNEL_ID_BROWSER, | 67 map.put(CHANNEL_ID_BROWSER, |
| 63 new Channel(CHANNEL_ID_BROWSER, | 68 new Channel(CHANNEL_ID_BROWSER, |
| 64 org.chromium.chrome.R.string.notification_category_b
rowser, | 69 org.chromium.chrome.R.string.notification_category_b
rowser, |
| 65 NotificationManager.IMPORTANCE_LOW, CHANNEL_GROUP_ID
_GENERAL)); | 70 NotificationManager.IMPORTANCE_LOW, CHANNEL_GROUP_ID
_GENERAL)); |
| 66 map.put(CHANNEL_ID_DOWNLOADS, | 71 map.put(CHANNEL_ID_DOWNLOADS, |
| 67 new Channel(CHANNEL_ID_DOWNLOADS, | 72 new Channel(CHANNEL_ID_DOWNLOADS, |
| 68 org.chromium.chrome.R.string.notification_category_d
ownloads, | 73 org.chromium.chrome.R.string.notification_category_d
ownloads, |
| 69 NotificationManager.IMPORTANCE_LOW, CHANNEL_GROUP_ID
_GENERAL)); | 74 NotificationManager.IMPORTANCE_LOW, CHANNEL_GROUP_ID
_GENERAL)); |
| 70 map.put(CHANNEL_ID_INCOGNITO, | 75 map.put(CHANNEL_ID_INCOGNITO, |
| 71 new Channel(CHANNEL_ID_INCOGNITO, | 76 new Channel(CHANNEL_ID_INCOGNITO, |
| 72 org.chromium.chrome.R.string.notification_category_i
ncognito, | 77 org.chromium.chrome.R.string.notification_category_i
ncognito, |
| 73 NotificationManager.IMPORTANCE_LOW, CHANNEL_GROUP_ID
_GENERAL)); | 78 NotificationManager.IMPORTANCE_LOW, CHANNEL_GROUP_ID
_GENERAL)); |
| 74 map.put(CHANNEL_ID_MEDIA, | 79 map.put(CHANNEL_ID_MEDIA, |
| 75 new Channel(CHANNEL_ID_MEDIA, | 80 new Channel(CHANNEL_ID_MEDIA, |
| 76 org.chromium.chrome.R.string.notification_category_m
edia, | 81 org.chromium.chrome.R.string.notification_category_m
edia, |
| 77 NotificationManager.IMPORTANCE_LOW, CHANNEL_GROUP_ID
_GENERAL)); | 82 NotificationManager.IMPORTANCE_LOW, CHANNEL_GROUP_ID
_GENERAL)); |
| 78 map.put(CHANNEL_ID_SITES, | 83 map.put(CHANNEL_ID_SITES, |
| 79 new Channel(CHANNEL_ID_SITES, | 84 new Channel(CHANNEL_ID_SITES, |
| 80 org.chromium.chrome.R.string.notification_category_s
ites, | 85 org.chromium.chrome.R.string.notification_category_s
ites, |
| 81 NotificationManager.IMPORTANCE_DEFAULT, CHANNEL_GROU
P_ID_GENERAL)); | 86 NotificationManager.IMPORTANCE_DEFAULT, CHANNEL_GROU
P_ID_GENERAL)); |
| 82 MAP = Collections.unmodifiableMap(map); | 87 MAP = Collections.unmodifiableMap(map); |
| 83 } | 88 } |
| 84 } | 89 } |
| 85 | 90 |
| 91 /** |
| 92 * When channels become deprecated they should be removed from PredefinedCha
nnels and their ids |
| 93 * added to this array so they can be deleted on upgrade. |
| 94 * We also want to keep track of old channel ids so they aren't accidentally
reused. |
| 95 */ |
| 96 private static final String[] LEGACY_CHANNEL_IDS = {}; |
| 97 |
| 86 // Map defined in static inner class so it's only initialized lazily. | 98 // Map defined in static inner class so it's only initialized lazily. |
| 87 private static class PredefinedChannelGroups { | 99 private static class PredefinedChannelGroups { |
| 88 static final Map<String, ChannelGroup> MAP; | 100 static final Map<String, ChannelGroup> MAP; |
| 89 static { | 101 static { |
| 90 Map<String, ChannelGroup> map = new HashMap<>(); | 102 Map<String, ChannelGroup> map = new HashMap<>(); |
| 91 map.put(CHANNEL_GROUP_ID_GENERAL, | 103 map.put(CHANNEL_GROUP_ID_GENERAL, |
| 92 new ChannelGroup(CHANNEL_GROUP_ID_GENERAL, | 104 new ChannelGroup(CHANNEL_GROUP_ID_GENERAL, |
| 93 org.chromium.chrome.R.string.notification_category_g
roup_general)); | 105 org.chromium.chrome.R.string.notification_category_g
roup_general)); |
| 94 MAP = Collections.unmodifiableMap(map); | 106 MAP = Collections.unmodifiableMap(map); |
| 95 } | 107 } |
| 96 } | 108 } |
| 97 | 109 |
| 110 /** |
| 111 * @return A set of channel ids of channels that should be initialized on st
artup. |
| 112 */ |
| 98 Set<String> getStartupChannelIds() { | 113 Set<String> getStartupChannelIds() { |
| 99 // CHANNELS_VERSION must be incremented if the set of channels returned
here changes. | 114 // CHANNELS_VERSION must be incremented if the set of channels returned
here changes. |
| 100 return PredefinedChannels.MAP.keySet(); | 115 return PredefinedChannels.MAP.keySet(); |
| 101 } | 116 } |
| 102 | 117 |
| 118 /** |
| 119 * @return An array of old ChannelIds that may have been returned by |
| 120 * {@link #getStartupChannelIds} in the past, but are no longer in use. |
| 121 */ |
| 122 public String[] getLegacyChannelIds() { |
| 123 return LEGACY_CHANNEL_IDS; |
| 124 } |
| 125 |
| 103 ChannelGroup getChannelGroupFromId(Channel channel) { | 126 ChannelGroup getChannelGroupFromId(Channel channel) { |
| 104 return PredefinedChannelGroups.MAP.get(channel.mGroupId); | 127 return PredefinedChannelGroups.MAP.get(channel.mGroupId); |
| 105 } | 128 } |
| 106 | 129 |
| 107 Channel getChannelFromId(@ChannelId String channelId) { | 130 Channel getChannelFromId(@ChannelId String channelId) { |
| 108 return PredefinedChannels.MAP.get(channelId); | 131 return PredefinedChannels.MAP.get(channelId); |
| 109 } | 132 } |
| 110 | 133 |
| 111 /** | 134 /** |
| 112 * Helper class containing notification channel properties. | 135 * Helper class containing notification channel properties. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 135 @ChannelGroupId | 158 @ChannelGroupId |
| 136 final String mId; | 159 final String mId; |
| 137 final int mNameResId; | 160 final int mNameResId; |
| 138 | 161 |
| 139 ChannelGroup(@ChannelGroupId String id, int nameResId) { | 162 ChannelGroup(@ChannelGroupId String id, int nameResId) { |
| 140 this.mId = id; | 163 this.mId = id; |
| 141 this.mNameResId = nameResId; | 164 this.mNameResId = nameResId; |
| 142 } | 165 } |
| 143 } | 166 } |
| 144 } | 167 } |
| OLD | NEW |