@ammarahmed/notifee-react-native 7.3.1 → 7.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/build.gradle +36 -18
- package/android/schemas/app.notifee.core.database.NotifeeCoreDatabase/1.json +46 -0
- package/android/schemas/app.notifee.core.database.NotifeeCoreDatabase/2.json +53 -0
- package/android/src/main/java/app/notifee/core/AlarmPermissionBroadcastReceiver.java +19 -0
- package/android/src/main/java/app/notifee/core/BlockStateBroadcastReceiver.java +164 -0
- package/android/src/main/java/app/notifee/core/ChannelManager.java +351 -0
- package/android/src/main/java/app/notifee/core/ContextHolder.java +33 -0
- package/android/src/main/java/app/notifee/core/EventBus.java +63 -0
- package/android/src/main/java/app/notifee/core/EventSubscriber.java +82 -0
- package/android/src/main/java/app/notifee/core/ForegroundService.java +125 -0
- package/android/src/main/java/app/notifee/core/InitProvider.java +92 -0
- package/android/src/main/java/app/notifee/core/KeepForSdk.java +26 -0
- package/android/src/main/java/app/notifee/core/Logger.java +68 -0
- package/android/src/main/java/app/notifee/core/Notifee.java +533 -0
- package/android/src/main/java/app/notifee/core/NotifeeAlarmManager.java +256 -0
- package/android/src/main/java/app/notifee/core/NotificationAlarmReceiver.java +32 -0
- package/android/src/main/java/app/notifee/core/NotificationManager.java +903 -0
- package/android/src/main/java/app/notifee/core/NotificationPendingIntent.java +189 -0
- package/android/src/main/java/app/notifee/core/NotificationReceiverActivity.java +38 -0
- package/android/src/main/java/app/notifee/core/NotificationReceiverHandler.java +140 -0
- package/android/src/main/java/app/notifee/core/Preferences.java +79 -0
- package/android/src/main/java/app/notifee/core/RebootBroadcastReceiver.java +38 -0
- package/android/src/main/java/app/notifee/core/ReceiverService.java +268 -0
- package/android/src/main/java/app/notifee/core/Worker.java +87 -0
- package/android/src/main/java/app/notifee/core/database/NotifeeCoreDatabase.java +76 -0
- package/android/src/main/java/app/notifee/core/database/WorkDataDao.java +52 -0
- package/android/src/main/java/app/notifee/core/database/WorkDataEntity.java +68 -0
- package/android/src/main/java/app/notifee/core/database/WorkDataRepository.java +107 -0
- package/android/src/main/java/app/notifee/core/event/BlockStateEvent.java +102 -0
- package/android/src/main/java/app/notifee/core/event/ForegroundServiceEvent.java +48 -0
- package/android/src/main/java/app/notifee/core/event/InitialNotificationEvent.java +50 -0
- package/android/src/main/java/app/notifee/core/event/LogEvent.java +74 -0
- package/android/src/main/java/app/notifee/core/event/MainComponentEvent.java +33 -0
- package/android/src/main/java/app/notifee/core/event/NotificationEvent.java +97 -0
- package/android/src/main/java/app/notifee/core/interfaces/EventListener.java +39 -0
- package/android/src/main/java/app/notifee/core/interfaces/MethodCallResult.java +27 -0
- package/android/src/main/java/app/notifee/core/model/ChannelGroupModel.java +48 -0
- package/android/src/main/java/app/notifee/core/model/ChannelModel.java +123 -0
- package/android/src/main/java/app/notifee/core/model/IntervalTriggerModel.java +63 -0
- package/android/src/main/java/app/notifee/core/model/NotificationAndroidActionModel.java +125 -0
- package/android/src/main/java/app/notifee/core/model/NotificationAndroidModel.java +654 -0
- package/android/src/main/java/app/notifee/core/model/NotificationAndroidPressActionModel.java +146 -0
- package/android/src/main/java/app/notifee/core/model/NotificationAndroidStyleModel.java +341 -0
- package/android/src/main/java/app/notifee/core/model/NotificationModel.java +72 -0
- package/android/src/main/java/app/notifee/core/model/TimestampTriggerModel.java +163 -0
- package/android/src/main/java/app/notifee/core/model/package-info.java +4 -0
- package/android/src/main/java/app/notifee/core/utility/AlarmUtils.java +52 -0
- package/android/src/main/java/app/notifee/core/utility/Callbackable.java +12 -0
- package/android/src/main/java/app/notifee/core/utility/ColorUtils.java +62 -0
- package/android/src/main/java/app/notifee/core/utility/ExtendedListenableFuture.java +84 -0
- package/android/src/main/java/app/notifee/core/utility/IntentUtils.java +136 -0
- package/android/src/main/java/app/notifee/core/utility/ObjectUtils.java +187 -0
- package/android/src/main/java/app/notifee/core/utility/PowerManagerUtils.java +334 -0
- package/android/src/main/java/app/notifee/core/utility/ResourceUtils.java +309 -0
- package/android/src/main/java/app/notifee/core/utility/TextUtils.java +28 -0
- package/android/src/main/java/app/notifee/core/utility/package-info.java +4 -0
- package/dist/types/Notification.d.ts +8 -1
- package/dist/types/Notification.js +6 -0
- package/dist/types/Notification.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/jest-mock.js +7 -4
- package/package.json +1 -3
- package/src/types/Notification.ts +8 -0
- package/src/version.ts +1 -1
- package/android/libs/app/notifee/core/202108261756/core-202108261756.aar +0 -0
- package/android/libs/app/notifee/core/202108261756/core-202108261756.aar.md5 +0 -1
- package/android/libs/app/notifee/core/202108261756/core-202108261756.aar.sha1 +0 -1
- package/android/libs/app/notifee/core/202108261756/core-202108261756.aar.sha256 +0 -1
- package/android/libs/app/notifee/core/202108261756/core-202108261756.aar.sha512 +0 -1
- package/android/libs/app/notifee/core/202108261756/core-202108261756.pom +0 -9
- package/android/libs/app/notifee/core/202108261756/core-202108261756.pom.md5 +0 -1
- package/android/libs/app/notifee/core/202108261756/core-202108261756.pom.sha1 +0 -1
- package/android/libs/app/notifee/core/202108261756/core-202108261756.pom.sha256 +0 -1
- package/android/libs/app/notifee/core/202108261756/core-202108261756.pom.sha512 +0 -1
- package/android/libs/app/notifee/core/maven-metadata.xml +0 -13
- package/android/libs/app/notifee/core/maven-metadata.xml.md5 +0 -1
- package/android/libs/app/notifee/core/maven-metadata.xml.sha1 +0 -1
- package/android/libs/app/notifee/core/maven-metadata.xml.sha256 +0 -1
- package/android/libs/app/notifee/core/maven-metadata.xml.sha512 +0 -1
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
package app.notifee.core;
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this library except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import static androidx.core.app.NotificationManagerCompat.IMPORTANCE_NONE;
|
|
21
|
+
|
|
22
|
+
import android.app.NotificationChannel;
|
|
23
|
+
import android.app.NotificationChannelGroup;
|
|
24
|
+
import android.media.AudioAttributes;
|
|
25
|
+
import android.net.Uri;
|
|
26
|
+
import android.os.Build;
|
|
27
|
+
import android.os.Bundle;
|
|
28
|
+
import androidx.annotation.NonNull;
|
|
29
|
+
import androidx.core.app.NotificationManagerCompat;
|
|
30
|
+
import app.notifee.core.model.ChannelGroupModel;
|
|
31
|
+
import app.notifee.core.model.ChannelModel;
|
|
32
|
+
import app.notifee.core.utility.ColorUtils;
|
|
33
|
+
import app.notifee.core.utility.ResourceUtils;
|
|
34
|
+
import com.google.common.util.concurrent.ListenableFuture;
|
|
35
|
+
import com.google.common.util.concurrent.ListeningExecutorService;
|
|
36
|
+
import com.google.common.util.concurrent.MoreExecutors;
|
|
37
|
+
import java.util.ArrayList;
|
|
38
|
+
import java.util.Collections;
|
|
39
|
+
import java.util.List;
|
|
40
|
+
import java.util.concurrent.ExecutorService;
|
|
41
|
+
import java.util.concurrent.Executors;
|
|
42
|
+
|
|
43
|
+
public class ChannelManager {
|
|
44
|
+
|
|
45
|
+
private static String TAG = "ChannelManager";
|
|
46
|
+
private static ExecutorService executorService = Executors.newCachedThreadPool();
|
|
47
|
+
private static ListeningExecutorService lExecutorService = MoreExecutors.listeningDecorator(
|
|
48
|
+
executorService);
|
|
49
|
+
|
|
50
|
+
static ListenableFuture<Void> createChannel(ChannelModel channelModel) {
|
|
51
|
+
return lExecutorService.submit(
|
|
52
|
+
() -> {
|
|
53
|
+
if (Build.VERSION.SDK_INT < 26) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
NotificationChannel channel =
|
|
58
|
+
new NotificationChannel(
|
|
59
|
+
channelModel.getId(), channelModel.getName(), channelModel.getImportance());
|
|
60
|
+
|
|
61
|
+
channel.setShowBadge(channelModel.getBadge());
|
|
62
|
+
channel.setBypassDnd(channelModel.getBypassDnd());
|
|
63
|
+
channel.setDescription(channelModel.getDescription());
|
|
64
|
+
channel.setGroup(channelModel.getGroupId());
|
|
65
|
+
channel.enableLights(channelModel.getLights());
|
|
66
|
+
|
|
67
|
+
if (channelModel.getLightColor() != null) {
|
|
68
|
+
channel.setLightColor(channelModel.getLightColor());
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
channel.setLockscreenVisibility(channelModel.getVisibility());
|
|
72
|
+
channel.enableVibration(channelModel.getVibration());
|
|
73
|
+
|
|
74
|
+
long[] vibrationPattern = channelModel.getVibrationPattern();
|
|
75
|
+
if (vibrationPattern.length > 0) {
|
|
76
|
+
channel.setVibrationPattern(vibrationPattern);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (channelModel.getSound() != null) {
|
|
80
|
+
Uri soundUri = ResourceUtils.getSoundUri(channelModel.getSound());
|
|
81
|
+
if (soundUri != null) {
|
|
82
|
+
AudioAttributes audioAttributes =
|
|
83
|
+
new AudioAttributes.Builder()
|
|
84
|
+
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
|
|
85
|
+
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
|
|
86
|
+
.build();
|
|
87
|
+
channel.setSound(soundUri, audioAttributes);
|
|
88
|
+
} else {
|
|
89
|
+
Logger.w(
|
|
90
|
+
TAG,
|
|
91
|
+
"Unable to retrieve sound for channel, sound was specified as: "
|
|
92
|
+
+ channel.getSound());
|
|
93
|
+
}
|
|
94
|
+
} else {
|
|
95
|
+
channel.setSound(null, null);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
NotificationManagerCompat.from(ContextHolder.getApplicationContext())
|
|
99
|
+
.createNotificationChannel(channel);
|
|
100
|
+
|
|
101
|
+
return null;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
static ListenableFuture<Void> createChannels(List<ChannelModel> channelModels) {
|
|
106
|
+
return lExecutorService.submit(
|
|
107
|
+
() -> {
|
|
108
|
+
for (ChannelModel channelModel : channelModels) {
|
|
109
|
+
createChannel(channelModel).get();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return null;
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
static ListenableFuture<Void> createChannelGroup(ChannelGroupModel channelGroupModel) {
|
|
117
|
+
return lExecutorService.submit(
|
|
118
|
+
() -> {
|
|
119
|
+
if (Build.VERSION.SDK_INT < 26) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
NotificationChannelGroup notificationChannelGroup =
|
|
124
|
+
new NotificationChannelGroup(channelGroupModel.getId(), channelGroupModel.getName());
|
|
125
|
+
|
|
126
|
+
if (Build.VERSION.SDK_INT >= 28 && channelGroupModel.getDescription() != null) {
|
|
127
|
+
notificationChannelGroup.setDescription(channelGroupModel.getDescription());
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
NotificationManagerCompat.from(ContextHolder.getApplicationContext())
|
|
131
|
+
.createNotificationChannelGroup(notificationChannelGroup);
|
|
132
|
+
|
|
133
|
+
return null;
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
static ListenableFuture<Void> createChannelGroups(
|
|
138
|
+
List<ChannelGroupModel> channelGroupModels) {
|
|
139
|
+
return lExecutorService.submit(
|
|
140
|
+
() -> {
|
|
141
|
+
if (Build.VERSION.SDK_INT < 26) {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
for (ChannelGroupModel channelGroupModel : channelGroupModels) {
|
|
146
|
+
createChannelGroup(channelGroupModel).get();
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return null;
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
static void deleteChannel(@NonNull String channelId) {
|
|
154
|
+
NotificationManagerCompat.from(ContextHolder.getApplicationContext())
|
|
155
|
+
.deleteNotificationChannel(channelId);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
static void deleteChannelGroup(@NonNull String channelGroupId) {
|
|
159
|
+
NotificationManagerCompat.from(ContextHolder.getApplicationContext())
|
|
160
|
+
.deleteNotificationChannelGroup(channelGroupId);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
static ListenableFuture<List<Bundle>> getChannels() {
|
|
164
|
+
return lExecutorService.submit(
|
|
165
|
+
() -> {
|
|
166
|
+
List<NotificationChannel> channels =
|
|
167
|
+
NotificationManagerCompat.from(ContextHolder.getApplicationContext())
|
|
168
|
+
.getNotificationChannels();
|
|
169
|
+
|
|
170
|
+
if (channels.size() == 0 || Build.VERSION.SDK_INT < 26) {
|
|
171
|
+
return Collections.emptyList();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
ArrayList<Bundle> channelBundles = new ArrayList<>(channels.size());
|
|
175
|
+
for (NotificationChannel channel : channels) {
|
|
176
|
+
channelBundles.add(convertChannelToBundle(channel));
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return channelBundles;
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
static ListenableFuture<Bundle> getChannel(String channelId) {
|
|
184
|
+
return lExecutorService.submit(
|
|
185
|
+
() -> {
|
|
186
|
+
NotificationChannel channel =
|
|
187
|
+
NotificationManagerCompat.from(ContextHolder.getApplicationContext())
|
|
188
|
+
.getNotificationChannel(channelId);
|
|
189
|
+
|
|
190
|
+
return convertChannelToBundle(channel);
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
static ListenableFuture<Boolean> isChannelBlocked(String channelId) {
|
|
195
|
+
return lExecutorService.submit(
|
|
196
|
+
() -> {
|
|
197
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return false;
|
|
198
|
+
|
|
199
|
+
NotificationChannel channel =
|
|
200
|
+
NotificationManagerCompat.from(ContextHolder.getApplicationContext())
|
|
201
|
+
.getNotificationChannel(channelId);
|
|
202
|
+
|
|
203
|
+
if (channel == null) {
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return IMPORTANCE_NONE == channel.getImportance();
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
static ListenableFuture<Boolean> isChannelCreated(String channelId) {
|
|
212
|
+
return lExecutorService.submit(
|
|
213
|
+
() -> {
|
|
214
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return false;
|
|
215
|
+
|
|
216
|
+
NotificationChannel channel =
|
|
217
|
+
NotificationManagerCompat.from(ContextHolder.getApplicationContext())
|
|
218
|
+
.getNotificationChannel(channelId);
|
|
219
|
+
|
|
220
|
+
return channel != null;
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
static ListenableFuture<List<Bundle>> getChannelGroups() {
|
|
225
|
+
return lExecutorService.submit(
|
|
226
|
+
() -> {
|
|
227
|
+
List<NotificationChannelGroup> channelGroups =
|
|
228
|
+
NotificationManagerCompat.from(ContextHolder.getApplicationContext())
|
|
229
|
+
.getNotificationChannelGroups();
|
|
230
|
+
|
|
231
|
+
if (channelGroups.size() == 0 || Build.VERSION.SDK_INT < 26) {
|
|
232
|
+
return Collections.emptyList();
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
ArrayList<Bundle> channelGroupBundles = new ArrayList<>(channelGroups.size());
|
|
236
|
+
for (NotificationChannelGroup channelGroup : channelGroups) {
|
|
237
|
+
channelGroupBundles.add(convertChannelGroupToBundle(channelGroup));
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return channelGroupBundles;
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
static ListenableFuture<Bundle> getChannelGroup(String channelGroupId) {
|
|
245
|
+
return lExecutorService.submit(
|
|
246
|
+
() -> {
|
|
247
|
+
NotificationChannelGroup channelGroup =
|
|
248
|
+
NotificationManagerCompat.from(ContextHolder.getApplicationContext())
|
|
249
|
+
.getNotificationChannelGroup(channelGroupId);
|
|
250
|
+
|
|
251
|
+
return convertChannelGroupToBundle(channelGroup);
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
private static Bundle convertChannelToBundle(NotificationChannel channel) {
|
|
256
|
+
if (channel == null || Build.VERSION.SDK_INT < 26) {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
Bundle channelBundle = new Bundle();
|
|
261
|
+
channelBundle.putString("id", channel.getId());
|
|
262
|
+
channelBundle.putString("name", channel.getName().toString());
|
|
263
|
+
channelBundle.putBoolean("badge", channel.canShowBadge());
|
|
264
|
+
channelBundle.putBoolean("bypassDnd", channel.canBypassDnd());
|
|
265
|
+
|
|
266
|
+
// can be null, don't include if null
|
|
267
|
+
if (channel.getDescription() != null) {
|
|
268
|
+
channelBundle.putString("description", channel.getDescription());
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// can be null, don't include if null
|
|
272
|
+
if (channel.getGroup() != null) {
|
|
273
|
+
channelBundle.putString("groupId", channel.getGroup());
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
channelBundle.putInt("importance", channel.getImportance());
|
|
277
|
+
channelBundle.putBoolean("lights", channel.shouldShowLights());
|
|
278
|
+
channelBundle.putBoolean("vibration", channel.shouldVibrate());
|
|
279
|
+
channelBundle.putBoolean("blocked", channel.getImportance() == IMPORTANCE_NONE);
|
|
280
|
+
|
|
281
|
+
// can be null, don't include if null
|
|
282
|
+
if (channel.getSound() != null) {
|
|
283
|
+
channelBundle.putString("soundURI", channel.getSound().toString());
|
|
284
|
+
// try to parse uri
|
|
285
|
+
String soundValue = ResourceUtils.getSoundName(channel.getSound());
|
|
286
|
+
if (soundValue != null) channelBundle.putString("sound", soundValue);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// optional, can be 0
|
|
290
|
+
if (channel.getLightColor() != 0) {
|
|
291
|
+
channelBundle.putString("lightColor", ColorUtils.getColorString(channel.getLightColor()));
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// getVibrationPattern can be null
|
|
295
|
+
long[] vibrationPattern = channel.getVibrationPattern();
|
|
296
|
+
|
|
297
|
+
if (vibrationPattern != null && vibrationPattern.length > 0) {
|
|
298
|
+
try {
|
|
299
|
+
int[] convertedVibrationPattern = new int[vibrationPattern.length];
|
|
300
|
+
// cast to int array
|
|
301
|
+
for (int i = 0; i < vibrationPattern.length; i++) {
|
|
302
|
+
convertedVibrationPattern[i] = (int) vibrationPattern[i];
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
channelBundle.putIntArray("vibrationPattern", convertedVibrationPattern);
|
|
306
|
+
} catch (Exception e) {
|
|
307
|
+
Logger.e(TAG, "Unable to convert Vibration Pattern to Channel Bundle", e);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// Unless the user manually changes this in app settings, it is always -1000.
|
|
312
|
+
int visibility = channel.getLockscreenVisibility();
|
|
313
|
+
if (visibility != -1000) { // -1000 = not set
|
|
314
|
+
channelBundle.putInt("visibility", visibility);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
return channelBundle;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
private static Bundle convertChannelGroupToBundle(NotificationChannelGroup channelGroup) {
|
|
321
|
+
if (channelGroup == null || Build.VERSION.SDK_INT < 26) {
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
Bundle channelGroupBundle = new Bundle();
|
|
326
|
+
channelGroupBundle.putString("id", channelGroup.getId());
|
|
327
|
+
channelGroupBundle.putString("name", channelGroup.getName().toString());
|
|
328
|
+
|
|
329
|
+
List<NotificationChannel> notificationChannels = channelGroup.getChannels();
|
|
330
|
+
ArrayList<Bundle> channels = new ArrayList<>(notificationChannels.size());
|
|
331
|
+
|
|
332
|
+
for (NotificationChannel notificationChannel : notificationChannels) {
|
|
333
|
+
channels.add(convertChannelToBundle(notificationChannel));
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
channelGroupBundle.putParcelableArrayList("channels", channels);
|
|
337
|
+
|
|
338
|
+
if (Build.VERSION.SDK_INT >= 28) {
|
|
339
|
+
channelGroupBundle.putBoolean("blocked", channelGroup.isBlocked());
|
|
340
|
+
channelGroupBundle.putString("description", channelGroup.getDescription());
|
|
341
|
+
} else {
|
|
342
|
+
channelGroupBundle.putBoolean("blocked", false);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
return channelGroupBundle;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
public static ListeningExecutorService getListeningExecutorService() {
|
|
349
|
+
return lExecutorService;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
package app.notifee.core;
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this library except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import android.content.Context;
|
|
21
|
+
|
|
22
|
+
public class ContextHolder {
|
|
23
|
+
private static Context applicationContext;
|
|
24
|
+
|
|
25
|
+
public static Context getApplicationContext() {
|
|
26
|
+
return applicationContext;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public static void setApplicationContext(Context applicationContext) {
|
|
30
|
+
Logger.d("context", "received application context");
|
|
31
|
+
ContextHolder.applicationContext = applicationContext;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
package app.notifee.core;
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this library except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
public class EventBus {
|
|
21
|
+
private static final EventBus instance = new EventBus();
|
|
22
|
+
private org.greenrobot.eventbus.EventBus eventBus;
|
|
23
|
+
|
|
24
|
+
private EventBus() {
|
|
25
|
+
eventBus = org.greenrobot.eventbus.EventBus.builder().build();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public static EventBus getInstance() {
|
|
29
|
+
return instance;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public static void register(Object subscriber) {
|
|
33
|
+
getInstance().getDefault().register(subscriber);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public static void unregister(Object subscriber) {
|
|
37
|
+
getInstance().getDefault().unregister(subscriber);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public static <T> T getStickyEvent(Class<T> eventType) {
|
|
41
|
+
return getInstance().getDefault().getStickyEvent(eventType);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public static <T> T removeStickEvent(Class<T> eventType) {
|
|
45
|
+
return getInstance().getDefault().removeStickyEvent(eventType);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public static void post(Object event) {
|
|
49
|
+
getInstance().getDefault().post(event);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
static void postSticky(Object event) {
|
|
53
|
+
getInstance().getDefault().postSticky(event);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static <T> T removeStickyEvent(Class<T> eventType) {
|
|
57
|
+
return getInstance().getDefault().removeStickyEvent(eventType);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private org.greenrobot.eventbus.EventBus getDefault() {
|
|
61
|
+
return eventBus;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
package app.notifee.core;
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this library except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import android.content.Context;
|
|
21
|
+
import app.notifee.core.event.BlockStateEvent;
|
|
22
|
+
import app.notifee.core.event.ForegroundServiceEvent;
|
|
23
|
+
import app.notifee.core.event.LogEvent;
|
|
24
|
+
import app.notifee.core.event.NotificationEvent;
|
|
25
|
+
import app.notifee.core.interfaces.EventListener;
|
|
26
|
+
import java.util.HashSet;
|
|
27
|
+
import java.util.Set;
|
|
28
|
+
import org.greenrobot.eventbus.Subscribe;
|
|
29
|
+
import org.greenrobot.eventbus.ThreadMode;
|
|
30
|
+
|
|
31
|
+
@KeepForSdk
|
|
32
|
+
public class EventSubscriber {
|
|
33
|
+
private static final EventSubscriber mInstance = new EventSubscriber();
|
|
34
|
+
private final Set<EventListener> mListeners = new HashSet<>();
|
|
35
|
+
|
|
36
|
+
private EventSubscriber() {
|
|
37
|
+
EventBus.register(this);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@KeepForSdk
|
|
41
|
+
public static void register(EventListener listener) {
|
|
42
|
+
mInstance.mListeners.add(listener);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@KeepForSdk
|
|
46
|
+
public static void unregister(EventListener listener) {
|
|
47
|
+
mInstance.mListeners.remove(listener);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@KeepForSdk
|
|
51
|
+
public static Context getContext() {
|
|
52
|
+
return ContextHolder.getApplicationContext();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
56
|
+
public void onNotificationEvent(NotificationEvent notificationEvent) {
|
|
57
|
+
for (EventListener eventListener : mListeners) {
|
|
58
|
+
eventListener.onNotificationEvent(notificationEvent);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
63
|
+
public void onLogEvent(LogEvent logEvent) {
|
|
64
|
+
for (EventListener eventListener : mListeners) {
|
|
65
|
+
eventListener.onLogEvent(logEvent);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
70
|
+
public void onBlockStateEvent(BlockStateEvent blockStateEvent) {
|
|
71
|
+
for (EventListener eventListener : mListeners) {
|
|
72
|
+
eventListener.onBlockStateEvent(blockStateEvent);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
77
|
+
public void onForegroundServiceEvent(ForegroundServiceEvent foregroundServiceEvent) {
|
|
78
|
+
for (EventListener eventListener : mListeners) {
|
|
79
|
+
eventListener.onForegroundServiceEvent(foregroundServiceEvent);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
package app.notifee.core;
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this library except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import android.app.Notification;
|
|
21
|
+
import android.app.Service;
|
|
22
|
+
import android.content.Intent;
|
|
23
|
+
import android.os.Build;
|
|
24
|
+
import android.os.Bundle;
|
|
25
|
+
import android.os.IBinder;
|
|
26
|
+
import androidx.annotation.Nullable;
|
|
27
|
+
import androidx.core.app.NotificationManagerCompat;
|
|
28
|
+
import app.notifee.core.event.ForegroundServiceEvent;
|
|
29
|
+
import app.notifee.core.event.NotificationEvent;
|
|
30
|
+
import app.notifee.core.interfaces.MethodCallResult;
|
|
31
|
+
import app.notifee.core.model.NotificationModel;
|
|
32
|
+
|
|
33
|
+
public class ForegroundService extends Service {
|
|
34
|
+
private static final String TAG = "ForegroundService";
|
|
35
|
+
public static final String START_FOREGROUND_SERVICE_ACTION =
|
|
36
|
+
"app.notifee.core.ForegroundService.START";
|
|
37
|
+
public static final String STOP_FOREGROUND_SERVICE_ACTION =
|
|
38
|
+
"app.notifee.core.ForegroundService.STOP";
|
|
39
|
+
|
|
40
|
+
public static String mCurrentNotificationId = null;
|
|
41
|
+
|
|
42
|
+
static void start(int hashCode, Notification notification, Bundle notificationBundle) {
|
|
43
|
+
Intent intent = new Intent(ContextHolder.getApplicationContext(), ForegroundService.class);
|
|
44
|
+
intent.setAction(START_FOREGROUND_SERVICE_ACTION);
|
|
45
|
+
intent.putExtra("hashCode", hashCode);
|
|
46
|
+
intent.putExtra("notification", notification);
|
|
47
|
+
intent.putExtra("notificationBundle", notificationBundle);
|
|
48
|
+
|
|
49
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
50
|
+
ContextHolder.getApplicationContext().startForegroundService(intent);
|
|
51
|
+
} else {
|
|
52
|
+
// TODO test this on older device
|
|
53
|
+
ContextHolder.getApplicationContext().startService(intent);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static void stop() {
|
|
58
|
+
Intent intent = new Intent(ContextHolder.getApplicationContext(), ForegroundService.class);
|
|
59
|
+
intent.setAction(STOP_FOREGROUND_SERVICE_ACTION);
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
// Call start service first with stop action
|
|
63
|
+
ContextHolder.getApplicationContext().startService(intent);
|
|
64
|
+
} catch (IllegalStateException illegalStateException) {
|
|
65
|
+
// try to stop with stopService command
|
|
66
|
+
ContextHolder.getApplicationContext().stopService(intent);
|
|
67
|
+
} catch (Exception exception) {
|
|
68
|
+
Logger.e(TAG, "Unable to stop foreground service", exception);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@Override
|
|
73
|
+
public int onStartCommand(Intent intent, int flags, int startId) {
|
|
74
|
+
// Check if action is to stop the foreground service
|
|
75
|
+
if (intent == null || STOP_FOREGROUND_SERVICE_ACTION.equals(intent.getAction())) {
|
|
76
|
+
stopSelf();
|
|
77
|
+
mCurrentNotificationId = null;
|
|
78
|
+
return 0;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
Bundle extras = intent.getExtras();
|
|
82
|
+
|
|
83
|
+
if (extras != null) {
|
|
84
|
+
// Hash code is sent to service to ensure it is kept the same
|
|
85
|
+
int hashCode = extras.getInt("hashCode");
|
|
86
|
+
Notification notification = extras.getParcelable("notification");
|
|
87
|
+
Bundle bundle = extras.getBundle("notificationBundle");
|
|
88
|
+
|
|
89
|
+
if (notification != null & bundle != null) {
|
|
90
|
+
NotificationModel notificationModel = NotificationModel.fromBundle(bundle);
|
|
91
|
+
|
|
92
|
+
if (mCurrentNotificationId == null) {
|
|
93
|
+
mCurrentNotificationId = notificationModel.getId();
|
|
94
|
+
startForeground(hashCode, notification);
|
|
95
|
+
|
|
96
|
+
// On headless task complete
|
|
97
|
+
final MethodCallResult<Void> methodCallResult =
|
|
98
|
+
(e, aVoid) -> {
|
|
99
|
+
stopForeground(true);
|
|
100
|
+
mCurrentNotificationId = null;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
ForegroundServiceEvent foregroundServiceEvent =
|
|
104
|
+
new ForegroundServiceEvent(notificationModel, methodCallResult);
|
|
105
|
+
|
|
106
|
+
EventBus.post(foregroundServiceEvent);
|
|
107
|
+
} else if (mCurrentNotificationId.equals(notificationModel.getId())) {
|
|
108
|
+
NotificationManagerCompat.from(ContextHolder.getApplicationContext())
|
|
109
|
+
.notify(hashCode, notification);
|
|
110
|
+
} else {
|
|
111
|
+
EventBus.post(
|
|
112
|
+
new NotificationEvent(NotificationEvent.TYPE_FG_ALREADY_EXIST, notificationModel));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return START_NOT_STICKY;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
@Nullable
|
|
121
|
+
@Override
|
|
122
|
+
public IBinder onBind(Intent intent) {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
}
|