react-native-notify-kit 9.1.22 → 9.2.0

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.
Files changed (88) hide show
  1. package/README.md +5 -2
  2. package/android/build.gradle +67 -35
  3. package/android/proguard-rules.pro +14 -1
  4. package/android/schemas/app.notifee.core.database.NotifeeCoreDatabase/1.json +44 -0
  5. package/android/schemas/app.notifee.core.database.NotifeeCoreDatabase/2.json +51 -0
  6. package/android/src/androidTest/java/app/notifee/core/ExampleInstrumentedTest.java +25 -0
  7. package/android/src/androidTest/java/app/notifee/core/database/NotifeeCoreDatabaseTest.java +55 -0
  8. package/android/src/main/AndroidManifest.xml +71 -4
  9. package/android/src/main/java/app/notifee/core/AlarmPermissionBroadcastReceiver.java +25 -0
  10. package/android/src/main/java/app/notifee/core/BlockStateBroadcastReceiver.java +164 -0
  11. package/android/src/main/java/app/notifee/core/ChannelManager.java +350 -0
  12. package/android/src/main/java/app/notifee/core/ContextHolder.java +33 -0
  13. package/android/src/main/java/app/notifee/core/EventBus.java +63 -0
  14. package/android/src/main/java/app/notifee/core/EventSubscriber.java +82 -0
  15. package/android/src/main/java/app/notifee/core/ForegroundService.java +347 -0
  16. package/android/src/main/java/app/notifee/core/InitProvider.java +93 -0
  17. package/android/src/main/java/app/notifee/core/KeepForSdk.java +26 -0
  18. package/android/src/main/java/app/notifee/core/Logger.java +68 -0
  19. package/android/src/main/java/app/notifee/core/Notifee.java +570 -0
  20. package/android/src/main/java/app/notifee/core/NotifeeAlarmManager.java +352 -0
  21. package/android/src/main/java/app/notifee/core/NotificationAlarmReceiver.java +42 -0
  22. package/android/src/main/java/app/notifee/core/NotificationManager.java +939 -0
  23. package/android/src/main/java/app/notifee/core/NotificationPendingIntent.java +191 -0
  24. package/android/src/main/java/app/notifee/core/NotificationReceiverActivity.java +39 -0
  25. package/android/src/main/java/app/notifee/core/NotificationReceiverHandler.java +144 -0
  26. package/android/src/main/java/app/notifee/core/Preferences.java +79 -0
  27. package/android/src/main/java/app/notifee/core/RebootBroadcastReceiver.java +39 -0
  28. package/android/src/main/java/app/notifee/core/ReceiverService.java +281 -0
  29. package/android/src/main/java/app/notifee/core/Worker.java +87 -0
  30. package/android/src/main/java/app/notifee/core/database/NotifeeCoreDatabase.java +77 -0
  31. package/android/src/main/java/app/notifee/core/database/WorkDataDao.java +52 -0
  32. package/android/src/main/java/app/notifee/core/database/WorkDataEntity.java +68 -0
  33. package/android/src/main/java/app/notifee/core/database/WorkDataRepository.java +107 -0
  34. package/android/src/main/java/app/notifee/core/event/BlockStateEvent.java +102 -0
  35. package/android/src/main/java/app/notifee/core/event/ForegroundServiceEvent.java +48 -0
  36. package/android/src/main/java/app/notifee/core/event/InitialNotificationEvent.java +50 -0
  37. package/android/src/main/java/app/notifee/core/event/LogEvent.java +74 -0
  38. package/android/src/main/java/app/notifee/core/event/MainComponentEvent.java +33 -0
  39. package/android/src/main/java/app/notifee/core/event/NotificationEvent.java +107 -0
  40. package/android/src/main/java/app/notifee/core/interfaces/EventListener.java +39 -0
  41. package/android/src/main/java/app/notifee/core/interfaces/MethodCallResult.java +27 -0
  42. package/android/src/main/java/app/notifee/core/model/ChannelGroupModel.java +48 -0
  43. package/android/src/main/java/app/notifee/core/model/ChannelModel.java +126 -0
  44. package/android/src/main/java/app/notifee/core/model/IntervalTriggerModel.java +63 -0
  45. package/android/src/main/java/app/notifee/core/model/NotificationAndroidActionModel.java +125 -0
  46. package/android/src/main/java/app/notifee/core/model/NotificationAndroidModel.java +688 -0
  47. package/android/src/main/java/app/notifee/core/model/NotificationAndroidPressActionModel.java +150 -0
  48. package/android/src/main/java/app/notifee/core/model/NotificationAndroidStyleModel.java +336 -0
  49. package/android/src/main/java/app/notifee/core/model/NotificationModel.java +72 -0
  50. package/android/src/main/java/app/notifee/core/model/TimestampTriggerModel.java +206 -0
  51. package/android/src/main/java/app/notifee/core/model/package-info.java +4 -0
  52. package/android/src/main/java/app/notifee/core/utility/AlarmUtils.java +52 -0
  53. package/android/src/main/java/app/notifee/core/utility/Callbackable.java +12 -0
  54. package/android/src/main/java/app/notifee/core/utility/ColorUtils.java +62 -0
  55. package/android/src/main/java/app/notifee/core/utility/ExtendedListenableFuture.java +84 -0
  56. package/android/src/main/java/app/notifee/core/utility/IntentUtils.java +146 -0
  57. package/android/src/main/java/app/notifee/core/utility/ObjectUtils.java +191 -0
  58. package/android/src/main/java/app/notifee/core/utility/PowerManagerUtils.java +338 -0
  59. package/android/src/main/java/app/notifee/core/utility/ResourceUtils.java +308 -0
  60. package/android/src/main/java/app/notifee/core/utility/TextUtils.java +28 -0
  61. package/android/src/main/java/app/notifee/core/utility/package-info.java +4 -0
  62. package/android/src/test/java/app/notifee/core/model/NotificationAndroidPressActionModelTest.java +56 -0
  63. package/android/src/test/java/app/notifee/core/model/TimestampTriggerModelTest.java +44 -0
  64. package/dist/version.d.ts +1 -1
  65. package/dist/version.js +1 -1
  66. package/dist/version.js.map +1 -1
  67. package/package.json +2 -2
  68. package/src/version.ts +1 -1
  69. package/android/libs/app/notifee/core/202108261754/core-202108261754.aar +0 -0
  70. package/android/libs/app/notifee/core/202108261754/core-202108261754.aar.md5 +0 -1
  71. package/android/libs/app/notifee/core/202108261754/core-202108261754.aar.sha1 +0 -1
  72. package/android/libs/app/notifee/core/202108261754/core-202108261754.aar.sha256 +0 -1
  73. package/android/libs/app/notifee/core/202108261754/core-202108261754.aar.sha512 +0 -1
  74. package/android/libs/app/notifee/core/202108261754/core-202108261754.module +0 -146
  75. package/android/libs/app/notifee/core/202108261754/core-202108261754.module.md5 +0 -1
  76. package/android/libs/app/notifee/core/202108261754/core-202108261754.module.sha1 +0 -1
  77. package/android/libs/app/notifee/core/202108261754/core-202108261754.module.sha256 +0 -1
  78. package/android/libs/app/notifee/core/202108261754/core-202108261754.module.sha512 +0 -1
  79. package/android/libs/app/notifee/core/202108261754/core-202108261754.pom +0 -64
  80. package/android/libs/app/notifee/core/202108261754/core-202108261754.pom.md5 +0 -1
  81. package/android/libs/app/notifee/core/202108261754/core-202108261754.pom.sha1 +0 -1
  82. package/android/libs/app/notifee/core/202108261754/core-202108261754.pom.sha256 +0 -1
  83. package/android/libs/app/notifee/core/202108261754/core-202108261754.pom.sha512 +0 -1
  84. package/android/libs/app/notifee/core/maven-metadata.xml +0 -13
  85. package/android/libs/app/notifee/core/maven-metadata.xml.md5 +0 -1
  86. package/android/libs/app/notifee/core/maven-metadata.xml.sha1 +0 -1
  87. package/android/libs/app/notifee/core/maven-metadata.xml.sha256 +0 -1
  88. package/android/libs/app/notifee/core/maven-metadata.xml.sha512 +0 -1
@@ -0,0 +1,570 @@
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 android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
21
+
22
+ import android.app.Activity;
23
+ import android.content.Context;
24
+ import android.content.Intent;
25
+ import android.os.Build;
26
+ import android.os.Bundle;
27
+ import android.provider.Settings;
28
+ import androidx.annotation.NonNull;
29
+ import androidx.annotation.Nullable;
30
+ import androidx.core.app.NotificationManagerCompat;
31
+ import app.notifee.core.event.InitialNotificationEvent;
32
+ import app.notifee.core.event.MainComponentEvent;
33
+ import app.notifee.core.interfaces.EventListener;
34
+ import app.notifee.core.interfaces.MethodCallResult;
35
+ import app.notifee.core.model.ChannelGroupModel;
36
+ import app.notifee.core.model.ChannelModel;
37
+ import app.notifee.core.model.NotificationModel;
38
+ import app.notifee.core.utility.AlarmUtils;
39
+ import app.notifee.core.utility.PowerManagerUtils;
40
+ import com.google.common.util.concurrent.FutureCallback;
41
+ import com.google.common.util.concurrent.Futures;
42
+ import com.google.common.util.concurrent.ListeningExecutorService;
43
+ import com.google.common.util.concurrent.MoreExecutors;
44
+ import java.util.ArrayList;
45
+ import java.util.List;
46
+ import java.util.concurrent.ExecutorService;
47
+ import java.util.concurrent.Executors;
48
+
49
+ @KeepForSdk
50
+ public class Notifee {
51
+ private static final String TAG = "API";
52
+ private static Notifee mNotifee = null;
53
+ private static boolean mIsnitialized = false;
54
+
55
+ private static final ExecutorService executorService = Executors.newCachedThreadPool();
56
+ private static final ListeningExecutorService lExecutorService =
57
+ MoreExecutors.listeningDecorator(executorService);
58
+
59
+ @KeepForSdk public static final int REQUEST_CODE_NOTIFICATION_PERMISSION = 11111;
60
+
61
+ @KeepForSdk
62
+ public static ListeningExecutorService getListeningExecutorService() {
63
+ return lExecutorService;
64
+ }
65
+
66
+ @KeepForSdk
67
+ public static Notifee getInstance() {
68
+ if (!mIsnitialized) {
69
+ Logger.w(TAG, "getInstance() accessed before event listener is initialized");
70
+ mNotifee = new Notifee();
71
+ }
72
+
73
+ return mNotifee;
74
+ }
75
+
76
+ @KeepForSdk
77
+ public static @Nullable Context getContext() {
78
+ return ContextHolder.getApplicationContext();
79
+ }
80
+
81
+ @KeepForSdk
82
+ public static void initialize(@Nullable EventListener eventListener) {
83
+ synchronized (Notifee.class) {
84
+ if (mIsnitialized) {
85
+ return;
86
+ }
87
+
88
+ if (mNotifee == null) {
89
+ mNotifee = new Notifee();
90
+ }
91
+
92
+ if (eventListener != null) {
93
+ EventSubscriber.register(eventListener);
94
+ }
95
+
96
+ mIsnitialized = true;
97
+ }
98
+ }
99
+
100
+ @KeepForSdk
101
+ public @NonNull String getMainComponent(@NonNull String defaultComponent) {
102
+ MainComponentEvent event = EventBus.removeStickEvent(MainComponentEvent.class);
103
+
104
+ if (event == null) {
105
+ return defaultComponent;
106
+ }
107
+
108
+ return event.getMainComponent();
109
+ }
110
+
111
+ /**
112
+ * NOTE: Allow cancelling notifications even if the license is invalid.
113
+ *
114
+ * @param result
115
+ */
116
+ @KeepForSdk
117
+ public void cancelAllNotifications(int notificationType, MethodCallResult<Void> result) {
118
+ Futures.addCallback(
119
+ NotificationManager.cancelAllNotifications(notificationType),
120
+ new FutureCallback<Void>() {
121
+ @Override
122
+ public void onSuccess(Void taskResult) {
123
+ result.onComplete(null, taskResult);
124
+ }
125
+
126
+ @Override
127
+ public void onFailure(Throwable t) {
128
+ result.onComplete(new Exception(t), null);
129
+ }
130
+ },
131
+ getListeningExecutorService());
132
+ }
133
+
134
+ @KeepForSdk
135
+ public void cancelAllNotificationsWithIds(
136
+ int type, List<String> ids, String tag, MethodCallResult<Void> result) {
137
+ Futures.addCallback(
138
+ NotificationManager.cancelAllNotificationsWithIds(type, ids, tag),
139
+ new FutureCallback<Void>() {
140
+ @Override
141
+ public void onSuccess(Void taskResult) {
142
+ result.onComplete(null, taskResult);
143
+ }
144
+
145
+ @Override
146
+ public void onFailure(Throwable t) {
147
+ result.onComplete(new Exception(t), null);
148
+ }
149
+ },
150
+ getListeningExecutorService());
151
+ }
152
+
153
+ @KeepForSdk
154
+ public void openAlarmPermissionSettings(Activity activity, MethodCallResult<Void> result) {
155
+ AlarmUtils.openAlarmPermissionSettings(activity);
156
+ result.onComplete(null, null);
157
+ }
158
+
159
+ @KeepForSdk
160
+ public void createChannel(Bundle channelMap, MethodCallResult<Void> result) {
161
+ ChannelModel channelModel = ChannelModel.fromBundle(channelMap);
162
+ Futures.addCallback(
163
+ ChannelManager.createChannel(channelModel),
164
+ new FutureCallback<Void>() {
165
+ @Override
166
+ public void onSuccess(Void taskResult) {
167
+ result.onComplete(null, taskResult);
168
+ }
169
+
170
+ @Override
171
+ public void onFailure(Throwable t) {
172
+ result.onComplete(new Exception(t), null);
173
+ }
174
+ },
175
+ getListeningExecutorService());
176
+ }
177
+
178
+ @KeepForSdk
179
+ public void createChannels(List<Bundle> channelsList, MethodCallResult<Void> result) {
180
+ ArrayList<ChannelModel> channelModels = new ArrayList<>(channelsList.size());
181
+ for (Bundle bundle : channelsList) {
182
+ channelModels.add(ChannelModel.fromBundle(bundle));
183
+ }
184
+ Futures.addCallback(
185
+ ChannelManager.createChannels(channelModels),
186
+ new FutureCallback<Void>() {
187
+ @Override
188
+ public void onSuccess(Void taskResult) {
189
+ result.onComplete(null, taskResult);
190
+ }
191
+
192
+ @Override
193
+ public void onFailure(Throwable t) {
194
+ result.onComplete(new Exception(t), null);
195
+ }
196
+ },
197
+ getListeningExecutorService());
198
+ }
199
+
200
+ @KeepForSdk
201
+ public void createChannelGroup(Bundle channelGroupMap, MethodCallResult<Void> result) {
202
+ ChannelGroupModel channelGroupModel = ChannelGroupModel.fromBundle(channelGroupMap);
203
+ Futures.addCallback(
204
+ ChannelManager.createChannelGroup(channelGroupModel),
205
+ new FutureCallback<Void>() {
206
+ @Override
207
+ public void onSuccess(Void taskResult) {
208
+ result.onComplete(null, taskResult);
209
+ }
210
+
211
+ @Override
212
+ public void onFailure(Throwable t) {
213
+ result.onComplete(new Exception(t), null);
214
+ }
215
+ },
216
+ getListeningExecutorService());
217
+ }
218
+
219
+ @KeepForSdk
220
+ public void createChannelGroups(List<Bundle> channelGroupsList, MethodCallResult<Void> result) {
221
+ ArrayList<ChannelGroupModel> channelGroupModels = new ArrayList<>(channelGroupsList.size());
222
+ for (Bundle bundle : channelGroupsList) {
223
+ channelGroupModels.add(ChannelGroupModel.fromBundle(bundle));
224
+ }
225
+ Futures.addCallback(
226
+ ChannelManager.createChannelGroups(channelGroupModels),
227
+ new FutureCallback<Void>() {
228
+ @Override
229
+ public void onSuccess(Void taskResult) {
230
+ result.onComplete(null, taskResult);
231
+ }
232
+
233
+ @Override
234
+ public void onFailure(Throwable t) {
235
+ result.onComplete(new Exception(t), null);
236
+ }
237
+ },
238
+ getListeningExecutorService());
239
+ }
240
+
241
+ @KeepForSdk
242
+ public void deleteChannel(String channelId, MethodCallResult<Void> result) {
243
+ ChannelManager.deleteChannel(channelId);
244
+ result.onComplete(null, null);
245
+ }
246
+
247
+ @KeepForSdk
248
+ public void deleteChannelGroup(String channelGroupId, MethodCallResult<Void> result) {
249
+ ChannelManager.deleteChannelGroup(channelGroupId);
250
+ result.onComplete(null, null);
251
+ }
252
+
253
+ @KeepForSdk
254
+ public void displayNotification(Bundle notificationMap, MethodCallResult<Void> result) {
255
+ NotificationModel notificationModel = NotificationModel.fromBundle(notificationMap);
256
+ Futures.addCallback(
257
+ NotificationManager.displayNotification(notificationModel, null),
258
+ new FutureCallback<Void>() {
259
+ @Override
260
+ public void onSuccess(Void taskResult) {
261
+ result.onComplete(null, taskResult);
262
+ }
263
+
264
+ @Override
265
+ public void onFailure(Throwable t) {
266
+ Exception e = new Exception(t);
267
+ Logger.e(TAG, "displayNotification", e);
268
+ result.onComplete(e, null);
269
+ }
270
+ },
271
+ getListeningExecutorService());
272
+ }
273
+
274
+ @KeepForSdk
275
+ public void createTriggerNotification(
276
+ Bundle notificationMap, Bundle triggerMap, MethodCallResult<Void> result) {
277
+ NotificationModel notificationModel = NotificationModel.fromBundle(notificationMap);
278
+ Futures.addCallback(
279
+ NotificationManager.createTriggerNotification(notificationModel, triggerMap),
280
+ new FutureCallback<Void>() {
281
+ @Override
282
+ public void onSuccess(Void taskResult) {
283
+ result.onComplete(null, taskResult);
284
+ }
285
+
286
+ @Override
287
+ public void onFailure(Throwable t) {
288
+ Exception e = new Exception(t);
289
+ Logger.e(TAG, "createTriggerNotification", e);
290
+ result.onComplete(e, null);
291
+ }
292
+ },
293
+ getListeningExecutorService());
294
+ }
295
+
296
+ @KeepForSdk
297
+ public void getTriggerNotificationIds(MethodCallResult<List<String>> result) {
298
+ NotificationManager.getTriggerNotificationIds(result);
299
+ }
300
+
301
+ @KeepForSdk
302
+ public void getDisplayedNotifications(MethodCallResult<List<Bundle>> result) {
303
+ Futures.addCallback(
304
+ NotificationManager.getDisplayedNotifications(),
305
+ new FutureCallback<List<Bundle>>() {
306
+ @Override
307
+ public void onSuccess(List<Bundle> taskResult) {
308
+ result.onComplete(null, taskResult);
309
+ }
310
+
311
+ @Override
312
+ public void onFailure(Throwable t) {
313
+ result.onComplete(new Exception(t), null);
314
+ }
315
+ },
316
+ getListeningExecutorService());
317
+ }
318
+
319
+ @KeepForSdk
320
+ public void getTriggerNotifications(MethodCallResult<List<Bundle>> result) {
321
+ NotificationManager.getTriggerNotifications(result);
322
+ }
323
+
324
+ @KeepForSdk
325
+ public void getChannels(MethodCallResult<List<Bundle>> result) {
326
+ Futures.addCallback(
327
+ ChannelManager.getChannels(),
328
+ new FutureCallback<List<Bundle>>() {
329
+ @Override
330
+ public void onSuccess(List<Bundle> taskResult) {
331
+ result.onComplete(null, taskResult);
332
+ }
333
+
334
+ @Override
335
+ public void onFailure(Throwable t) {
336
+ result.onComplete(new Exception(t), null);
337
+ }
338
+ },
339
+ getListeningExecutorService());
340
+ }
341
+
342
+ @KeepForSdk
343
+ public void getChannel(String channelId, MethodCallResult<Bundle> result) {
344
+ Futures.addCallback(
345
+ ChannelManager.getChannel(channelId),
346
+ new FutureCallback<Bundle>() {
347
+ @Override
348
+ public void onSuccess(Bundle taskResult) {
349
+ result.onComplete(null, taskResult);
350
+ }
351
+
352
+ @Override
353
+ public void onFailure(Throwable t) {
354
+ result.onComplete(new Exception(t), null);
355
+ }
356
+ },
357
+ getListeningExecutorService());
358
+ }
359
+
360
+ @KeepForSdk
361
+ public void getChannelGroups(MethodCallResult<List<Bundle>> result) {
362
+ Futures.addCallback(
363
+ ChannelManager.getChannelGroups(),
364
+ new FutureCallback<List<Bundle>>() {
365
+ @Override
366
+ public void onSuccess(List<Bundle> taskResult) {
367
+ result.onComplete(null, taskResult);
368
+ }
369
+
370
+ @Override
371
+ public void onFailure(Throwable t) {
372
+ result.onComplete(new Exception(t), null);
373
+ }
374
+ },
375
+ getListeningExecutorService());
376
+ }
377
+
378
+ @KeepForSdk
379
+ public void getChannelGroup(String channelGroupId, MethodCallResult<Bundle> result) {
380
+ Futures.addCallback(
381
+ ChannelManager.getChannelGroup(channelGroupId),
382
+ new FutureCallback<Bundle>() {
383
+ @Override
384
+ public void onSuccess(Bundle taskResult) {
385
+ result.onComplete(null, taskResult);
386
+ }
387
+
388
+ @Override
389
+ public void onFailure(Throwable t) {
390
+ result.onComplete(new Exception(t), null);
391
+ }
392
+ },
393
+ getListeningExecutorService());
394
+ }
395
+
396
+ @KeepForSdk
397
+ public void isChannelCreated(String channelId, MethodCallResult<Boolean> result) {
398
+ Futures.addCallback(
399
+ ChannelManager.isChannelCreated(channelId),
400
+ new FutureCallback<Boolean>() {
401
+ @Override
402
+ public void onSuccess(Boolean taskResult) {
403
+ result.onComplete(null, taskResult);
404
+ }
405
+
406
+ @Override
407
+ public void onFailure(Throwable t) {
408
+ result.onComplete(new Exception(t), null);
409
+ }
410
+ },
411
+ getListeningExecutorService());
412
+ }
413
+
414
+ @KeepForSdk
415
+ public void isChannelBlocked(String channelId, MethodCallResult<Boolean> result) {
416
+ Futures.addCallback(
417
+ ChannelManager.isChannelBlocked(channelId),
418
+ new FutureCallback<Boolean>() {
419
+ @Override
420
+ public void onSuccess(Boolean taskResult) {
421
+ result.onComplete(null, taskResult);
422
+ }
423
+
424
+ @Override
425
+ public void onFailure(Throwable t) {
426
+ result.onComplete(new Exception(t), null);
427
+ }
428
+ },
429
+ getListeningExecutorService());
430
+ }
431
+
432
+ @KeepForSdk
433
+ public void getInitialNotification(Activity activity, MethodCallResult<Bundle> result) {
434
+ InitialNotificationEvent event = EventBus.removeStickEvent(InitialNotificationEvent.class);
435
+ Bundle initialNotificationBundle = new Bundle();
436
+
437
+ if (event != null) {
438
+ initialNotificationBundle.putAll(event.getExtras());
439
+ initialNotificationBundle.putBundle("notification", event.getNotificationModel().toBundle());
440
+ result.onComplete(null, initialNotificationBundle);
441
+ return;
442
+ } else if (activity != null) {
443
+ try {
444
+ // get intent from current activity
445
+ Intent intent = activity.getIntent();
446
+ if (intent != null && intent.getExtras() != null && intent.hasExtra("notification")) {
447
+ initialNotificationBundle.putBundle(
448
+ "notification", intent.getBundleExtra("notification"));
449
+ result.onComplete(null, initialNotificationBundle);
450
+ return;
451
+ }
452
+ } catch (Exception e) {
453
+ Logger.e(TAG, "getInitialNotification", e);
454
+ }
455
+ }
456
+
457
+ // If no initial notification, return
458
+ result.onComplete(null, null);
459
+ }
460
+
461
+ @KeepForSdk
462
+ public void isBatteryOptimizationEnabled(MethodCallResult<Boolean> result) {
463
+ Boolean isBatteryOptimizationEnabled =
464
+ PowerManagerUtils.isBatteryOptimizationEnabled(ContextHolder.getApplicationContext());
465
+ result.onComplete(null, isBatteryOptimizationEnabled);
466
+ }
467
+
468
+ @KeepForSdk
469
+ public void openBatteryOptimizationSettings(Activity activity, MethodCallResult<Void> result) {
470
+ PowerManagerUtils.openBatteryOptimizationSettings(activity);
471
+ result.onComplete(null, null);
472
+ }
473
+
474
+ @KeepForSdk
475
+ public void getPowerManagerInfo(MethodCallResult<Bundle> result) {
476
+ PowerManagerUtils.PowerManagerInfo info = PowerManagerUtils.getPowerManagerInfo();
477
+ result.onComplete(null, info.toBundle());
478
+ }
479
+
480
+ @KeepForSdk
481
+ public void openPowerManagerSettings(Activity activity, MethodCallResult<Void> result) {
482
+ PowerManagerUtils.openPowerManagerSettings(activity);
483
+ result.onComplete(null, null);
484
+ }
485
+
486
+ @KeepForSdk
487
+ public void getNotificationSettings(MethodCallResult<Bundle> result) {
488
+ boolean areNotificationsEnabled =
489
+ NotificationManagerCompat.from(ContextHolder.getApplicationContext())
490
+ .areNotificationsEnabled();
491
+
492
+ Bundle notificationSettingsBundle = new Bundle();
493
+ if (areNotificationsEnabled) {
494
+ notificationSettingsBundle.putInt("authorizationStatus", 1); // AUTHORIZED
495
+ } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
496
+ && !Preferences.getSharedInstance().getBooleanValue("permission_requested", false)) {
497
+ notificationSettingsBundle.putInt("authorizationStatus", -1); // NOT_DETERMINED
498
+ } else {
499
+ notificationSettingsBundle.putInt("authorizationStatus", 0); // DENIED
500
+ }
501
+
502
+ boolean canScheduleExactAlarms = AlarmUtils.canScheduleExactAlarms();
503
+ Bundle androidSettingsBundle = new Bundle();
504
+
505
+ if (canScheduleExactAlarms) {
506
+ androidSettingsBundle.putInt("alarm", 1);
507
+ } else {
508
+ androidSettingsBundle.putInt("alarm", 0);
509
+ }
510
+
511
+ notificationSettingsBundle.putBundle("android", androidSettingsBundle);
512
+ result.onComplete(null, notificationSettingsBundle);
513
+ }
514
+
515
+ @Nullable private MethodCallResult<Bundle> requestPermissionCallResult;
516
+
517
+ @KeepForSdk
518
+ public void setRequestPermissionCallback(MethodCallResult<Bundle> result) {
519
+ requestPermissionCallResult = result;
520
+ }
521
+
522
+ @KeepForSdk
523
+ public boolean onRequestPermissionsResult(
524
+ int requestCode, String[] permissions, int[] grantResults) {
525
+ if (requestCode == REQUEST_CODE_NOTIFICATION_PERMISSION) {
526
+ Preferences.getSharedInstance().setBooleanValue("permission_requested", true);
527
+ if (requestPermissionCallResult != null) {
528
+ getNotificationSettings(requestPermissionCallResult);
529
+ return true;
530
+ }
531
+ }
532
+ return false;
533
+ }
534
+
535
+ @KeepForSdk
536
+ public void openNotificationSettings(
537
+ @Nullable String channelId, Activity activity, MethodCallResult<Void> result) {
538
+ if (getContext() == null || activity == null) {
539
+ Logger.d(
540
+ "openNotificationSettings",
541
+ "attempted to start activity but no current activity or context was available.");
542
+ result.onComplete(null, null);
543
+ return;
544
+ }
545
+
546
+ Intent intent;
547
+ if (Build.VERSION.SDK_INT >= 26) {
548
+ if (channelId != null) {
549
+ intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
550
+ intent.putExtra(Settings.EXTRA_CHANNEL_ID, channelId);
551
+ } else {
552
+ intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS);
553
+ }
554
+ intent.putExtra(Settings.EXTRA_APP_PACKAGE, getContext().getPackageName());
555
+ } else {
556
+ intent = new Intent(Settings.ACTION_APPLICATION_SETTINGS);
557
+ }
558
+
559
+ intent.setFlags(FLAG_ACTIVITY_NEW_TASK);
560
+
561
+ activity.runOnUiThread(() -> getContext().startActivity(intent));
562
+ result.onComplete(null, null);
563
+ }
564
+
565
+ @KeepForSdk
566
+ public void stopForegroundService(MethodCallResult<Void> result) {
567
+ ForegroundService.stop();
568
+ result.onComplete(null, null);
569
+ }
570
+ }