@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,533 @@
|
|
|
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 java.util.ArrayList;
|
|
43
|
+
import java.util.List;
|
|
44
|
+
|
|
45
|
+
@KeepForSdk
|
|
46
|
+
public class Notifee {
|
|
47
|
+
private static final String TAG = "API";
|
|
48
|
+
private static Notifee mNotifee = null;
|
|
49
|
+
private static boolean mIsnitialized = false;
|
|
50
|
+
|
|
51
|
+
@KeepForSdk public static final int REQUEST_CODE_NOTIFICATION_PERMISSION = 11111;
|
|
52
|
+
|
|
53
|
+
@KeepForSdk
|
|
54
|
+
public static Notifee getInstance() {
|
|
55
|
+
if (!mIsnitialized) {
|
|
56
|
+
Logger.w(TAG, "getInstance() accessed before event listener is initialized");
|
|
57
|
+
mNotifee = new Notifee();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return mNotifee;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@KeepForSdk
|
|
64
|
+
public static @Nullable Context getContext() {
|
|
65
|
+
return ContextHolder.getApplicationContext();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@KeepForSdk
|
|
69
|
+
public static void initialize(@Nullable EventListener eventListener) {
|
|
70
|
+
synchronized (Notifee.class) {
|
|
71
|
+
if (mIsnitialized) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (mNotifee == null) {
|
|
76
|
+
mNotifee = new Notifee();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (eventListener != null) {
|
|
80
|
+
EventSubscriber.register(eventListener);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
mIsnitialized = true;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
@KeepForSdk
|
|
88
|
+
public @NonNull String getMainComponent(@NonNull String defaultComponent) {
|
|
89
|
+
MainComponentEvent event = EventBus.removeStickEvent(MainComponentEvent.class);
|
|
90
|
+
|
|
91
|
+
if (event == null) {
|
|
92
|
+
return defaultComponent;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return event.getMainComponent();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* NOTE: Allow cancelling notifications even if the license is invalid.
|
|
100
|
+
*
|
|
101
|
+
* @param result
|
|
102
|
+
*/
|
|
103
|
+
@KeepForSdk
|
|
104
|
+
public void cancelAllNotifications(int notificationType,
|
|
105
|
+
MethodCallResult<Void> result) {
|
|
106
|
+
Futures.addCallback(
|
|
107
|
+
NotificationManager.cancelAllNotifications(notificationType),
|
|
108
|
+
new FutureCallback<Void>() {
|
|
109
|
+
@Override
|
|
110
|
+
public void onSuccess(Void taskResult) {
|
|
111
|
+
result.onComplete(null, taskResult);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
@Override
|
|
115
|
+
public void onFailure(Throwable t) {
|
|
116
|
+
result.onComplete(new Exception(t), null);
|
|
117
|
+
}
|
|
118
|
+
}, ChannelManager.getListeningExecutorService());
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
@KeepForSdk
|
|
122
|
+
public void cancelAllNotificationsWithIds(
|
|
123
|
+
int type, List<String> ids, String tag, MethodCallResult<Void> result) {
|
|
124
|
+
Futures.addCallback(
|
|
125
|
+
NotificationManager.cancelAllNotificationsWithIds(type, ids, tag),
|
|
126
|
+
new FutureCallback<Void>() {
|
|
127
|
+
@Override
|
|
128
|
+
public void onSuccess(Void taskResult) {
|
|
129
|
+
result.onComplete(null, taskResult);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
@Override
|
|
133
|
+
public void onFailure(Throwable t) {
|
|
134
|
+
result.onComplete(new Exception(t), null);
|
|
135
|
+
}
|
|
136
|
+
}, ChannelManager.getListeningExecutorService());
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
@KeepForSdk
|
|
140
|
+
public void openAlarmPermissionSettings(Activity activity, MethodCallResult<Void> result) {
|
|
141
|
+
AlarmUtils.openAlarmPermissionSettings(activity);
|
|
142
|
+
result.onComplete(null, null);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
@KeepForSdk
|
|
146
|
+
public void createChannel(Bundle channelMap, MethodCallResult<Void> result) {
|
|
147
|
+
ChannelModel channelModel = ChannelModel.fromBundle(channelMap);
|
|
148
|
+
Futures.addCallback(ChannelManager.createChannel(channelModel),
|
|
149
|
+
new FutureCallback<Void>() {
|
|
150
|
+
@Override
|
|
151
|
+
public void onSuccess(Void taskResult) {
|
|
152
|
+
result.onComplete(null, taskResult);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
@Override
|
|
156
|
+
public void onFailure(Throwable t) {
|
|
157
|
+
result.onComplete(new Exception(t), null);
|
|
158
|
+
}
|
|
159
|
+
}, ChannelManager.getListeningExecutorService());
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
@KeepForSdk
|
|
163
|
+
public void createChannels(List<Bundle> channelsList, MethodCallResult<Void> result) {
|
|
164
|
+
ArrayList<ChannelModel> channelModels = new ArrayList<>(channelsList.size());
|
|
165
|
+
for (Bundle bundle : channelsList) {
|
|
166
|
+
channelModels.add(ChannelModel.fromBundle(bundle));
|
|
167
|
+
}
|
|
168
|
+
Futures.addCallback(ChannelManager.createChannels(channelModels),
|
|
169
|
+
new FutureCallback<Void>() {
|
|
170
|
+
@Override
|
|
171
|
+
public void onSuccess(Void taskResult) {
|
|
172
|
+
result.onComplete(null, taskResult);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
@Override
|
|
176
|
+
public void onFailure(Throwable t) {
|
|
177
|
+
result.onComplete(new Exception(t), null);
|
|
178
|
+
}
|
|
179
|
+
}, ChannelManager.getListeningExecutorService());
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
@KeepForSdk
|
|
183
|
+
public void createChannelGroup(Bundle channelGroupMap, MethodCallResult<Void> result) {
|
|
184
|
+
ChannelGroupModel channelGroupModel = ChannelGroupModel.fromBundle(channelGroupMap);
|
|
185
|
+
Futures.addCallback(ChannelManager.createChannelGroup(channelGroupModel),
|
|
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
|
+
}, ChannelManager.getListeningExecutorService());
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
@KeepForSdk
|
|
200
|
+
public void createChannelGroups(List<Bundle> channelGroupsList, MethodCallResult<Void> result) {
|
|
201
|
+
ArrayList<ChannelGroupModel> channelGroupModels = new ArrayList<>(channelGroupsList.size());
|
|
202
|
+
for (Bundle bundle : channelGroupsList) {
|
|
203
|
+
channelGroupModels.add(ChannelGroupModel.fromBundle(bundle));
|
|
204
|
+
}
|
|
205
|
+
Futures.addCallback(ChannelManager.createChannelGroups(channelGroupModels),
|
|
206
|
+
new FutureCallback<Void>() {
|
|
207
|
+
@Override
|
|
208
|
+
public void onSuccess(Void taskResult) {
|
|
209
|
+
result.onComplete(null, taskResult);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
@Override
|
|
213
|
+
public void onFailure(Throwable t) {
|
|
214
|
+
result.onComplete(new Exception(t), null);
|
|
215
|
+
}
|
|
216
|
+
}, ChannelManager.getListeningExecutorService());
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
@KeepForSdk
|
|
220
|
+
public void deleteChannel(String channelId, MethodCallResult<Void> result) {
|
|
221
|
+
ChannelManager.deleteChannel(channelId);
|
|
222
|
+
result.onComplete(null, null);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
@KeepForSdk
|
|
226
|
+
public void deleteChannelGroup(String channelGroupId, MethodCallResult<Void> result) {
|
|
227
|
+
ChannelManager.deleteChannelGroup(channelGroupId);
|
|
228
|
+
result.onComplete(null, null);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
@KeepForSdk
|
|
232
|
+
public void displayNotification(Bundle notificationMap,
|
|
233
|
+
MethodCallResult<Void> result) {
|
|
234
|
+
NotificationModel notificationModel = NotificationModel.fromBundle(
|
|
235
|
+
notificationMap);
|
|
236
|
+
Futures.addCallback(
|
|
237
|
+
NotificationManager.displayNotification(notificationModel, null),
|
|
238
|
+
new FutureCallback<Void>() {
|
|
239
|
+
@Override
|
|
240
|
+
public void onSuccess(Void taskResult) {
|
|
241
|
+
result.onComplete(null, taskResult);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
@Override
|
|
245
|
+
public void onFailure(Throwable t) {
|
|
246
|
+
Exception e = new Exception(t);
|
|
247
|
+
Logger.e(TAG, "displayNotification", e);
|
|
248
|
+
result.onComplete(e, null);
|
|
249
|
+
}
|
|
250
|
+
}, ChannelManager.getListeningExecutorService());
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
@KeepForSdk
|
|
254
|
+
public void createTriggerNotification(
|
|
255
|
+
Bundle notificationMap, Bundle triggerMap, MethodCallResult<Void> result) {
|
|
256
|
+
NotificationModel notificationModel = NotificationModel.fromBundle(notificationMap);
|
|
257
|
+
Futures.addCallback(
|
|
258
|
+
NotificationManager.createTriggerNotification(notificationModel,
|
|
259
|
+
triggerMap), new FutureCallback<Void>() {
|
|
260
|
+
@Override
|
|
261
|
+
public void onSuccess(Void taskResult) {
|
|
262
|
+
result.onComplete(null, taskResult);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
@Override
|
|
266
|
+
public void onFailure(Throwable t) {
|
|
267
|
+
Exception e = new Exception(t);
|
|
268
|
+
Logger.e(TAG, "createTriggerNotification", e);
|
|
269
|
+
result.onComplete(e, null);
|
|
270
|
+
}
|
|
271
|
+
}, ChannelManager.getListeningExecutorService());
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
@KeepForSdk
|
|
275
|
+
public void getTriggerNotificationIds(MethodCallResult<List<String>> result) {
|
|
276
|
+
NotificationManager.getTriggerNotificationIds(result);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
@KeepForSdk
|
|
280
|
+
public void getDisplayedNotifications(MethodCallResult<List<Bundle>> result) {
|
|
281
|
+
Futures.addCallback(NotificationManager.getDisplayedNotifications(),
|
|
282
|
+
new FutureCallback<List<Bundle>>() {
|
|
283
|
+
@Override
|
|
284
|
+
public void onSuccess(List<Bundle> taskResult) {
|
|
285
|
+
result.onComplete(null, taskResult);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
@Override
|
|
289
|
+
public void onFailure(Throwable t) {
|
|
290
|
+
result.onComplete(new Exception(t), null);
|
|
291
|
+
}
|
|
292
|
+
}, ChannelManager.getListeningExecutorService());
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
@KeepForSdk
|
|
296
|
+
public void getTriggerNotifications(MethodCallResult<List<Bundle>> result) {
|
|
297
|
+
NotificationManager.getTriggerNotifications(result);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
@KeepForSdk
|
|
301
|
+
public void getChannels(MethodCallResult<List<Bundle>> result) {
|
|
302
|
+
Futures.addCallback(ChannelManager.getChannels(),
|
|
303
|
+
new FutureCallback<List<Bundle>>() {
|
|
304
|
+
@Override
|
|
305
|
+
public void onSuccess(List<Bundle> taskResult) {
|
|
306
|
+
result.onComplete(null, taskResult);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
@Override
|
|
310
|
+
public void onFailure(Throwable t) {
|
|
311
|
+
result.onComplete(new Exception(t), null);
|
|
312
|
+
}
|
|
313
|
+
}, ChannelManager.getListeningExecutorService());
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
@KeepForSdk
|
|
317
|
+
public void getChannel(String channelId, MethodCallResult<Bundle> result) {
|
|
318
|
+
Futures.addCallback(ChannelManager.getChannel(channelId),
|
|
319
|
+
new FutureCallback<Bundle>() {
|
|
320
|
+
@Override
|
|
321
|
+
public void onSuccess(Bundle taskResult) {
|
|
322
|
+
result.onComplete(null, taskResult);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
@Override
|
|
326
|
+
public void onFailure(Throwable t) {
|
|
327
|
+
result.onComplete(new Exception(t), null);
|
|
328
|
+
}
|
|
329
|
+
}, ChannelManager.getListeningExecutorService());
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
@KeepForSdk
|
|
333
|
+
public void getChannelGroups(MethodCallResult<List<Bundle>> result) {
|
|
334
|
+
Futures.addCallback(ChannelManager.getChannelGroups(),
|
|
335
|
+
new FutureCallback<List<Bundle>>() {
|
|
336
|
+
@Override
|
|
337
|
+
public void onSuccess(List<Bundle> taskResult) {
|
|
338
|
+
result.onComplete(null, taskResult);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
@Override
|
|
342
|
+
public void onFailure(Throwable t) {
|
|
343
|
+
result.onComplete(new Exception(t), null);
|
|
344
|
+
}
|
|
345
|
+
}, ChannelManager.getListeningExecutorService());
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
@KeepForSdk
|
|
349
|
+
public void getChannelGroup(String channelGroupId,
|
|
350
|
+
MethodCallResult<Bundle> result) {
|
|
351
|
+
Futures.addCallback(ChannelManager.getChannelGroup(channelGroupId),
|
|
352
|
+
new FutureCallback<Bundle>() {
|
|
353
|
+
@Override
|
|
354
|
+
public void onSuccess(Bundle taskResult) {
|
|
355
|
+
result.onComplete(null, taskResult);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
@Override
|
|
359
|
+
public void onFailure(Throwable t) {
|
|
360
|
+
result.onComplete(new Exception(t), null);
|
|
361
|
+
}
|
|
362
|
+
}, ChannelManager.getListeningExecutorService());
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
@KeepForSdk
|
|
366
|
+
public void isChannelCreated(String channelId,
|
|
367
|
+
MethodCallResult<Boolean> result) {
|
|
368
|
+
Futures.addCallback(ChannelManager.isChannelCreated(channelId),
|
|
369
|
+
new FutureCallback<Boolean>() {
|
|
370
|
+
@Override
|
|
371
|
+
public void onSuccess(Boolean taskResult) {
|
|
372
|
+
result.onComplete(null, taskResult);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
@Override
|
|
376
|
+
public void onFailure(Throwable t) {
|
|
377
|
+
result.onComplete(new Exception(t), null);
|
|
378
|
+
}
|
|
379
|
+
}, ChannelManager.getListeningExecutorService());
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
@KeepForSdk
|
|
383
|
+
public void isChannelBlocked(String channelId,
|
|
384
|
+
MethodCallResult<Boolean> result) {
|
|
385
|
+
Futures.addCallback(ChannelManager.isChannelBlocked(channelId),
|
|
386
|
+
new FutureCallback<Boolean>() {
|
|
387
|
+
@Override
|
|
388
|
+
public void onSuccess(Boolean taskResult) {
|
|
389
|
+
result.onComplete(null, taskResult);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
@Override
|
|
393
|
+
public void onFailure(Throwable t) {
|
|
394
|
+
result.onComplete(new Exception(t), null);
|
|
395
|
+
}
|
|
396
|
+
}, ChannelManager.getListeningExecutorService());
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
@KeepForSdk
|
|
400
|
+
public void getInitialNotification(Activity activity, MethodCallResult<Bundle> result) {
|
|
401
|
+
InitialNotificationEvent event = EventBus.removeStickEvent(InitialNotificationEvent.class);
|
|
402
|
+
Bundle initialNotificationBundle = new Bundle();
|
|
403
|
+
|
|
404
|
+
if (event != null) {
|
|
405
|
+
initialNotificationBundle.putAll(event.getExtras());
|
|
406
|
+
initialNotificationBundle.putBundle("notification", event.getNotificationModel().toBundle());
|
|
407
|
+
result.onComplete(null, initialNotificationBundle);
|
|
408
|
+
return;
|
|
409
|
+
} else if (activity != null) {
|
|
410
|
+
try {
|
|
411
|
+
// get intent from current activity
|
|
412
|
+
Intent intent = activity.getIntent();
|
|
413
|
+
if (intent != null && intent.getExtras() != null && intent.hasExtra("notification")) {
|
|
414
|
+
initialNotificationBundle.putBundle(
|
|
415
|
+
"notification", intent.getBundleExtra("notification"));
|
|
416
|
+
result.onComplete(null, initialNotificationBundle);
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
} catch (Exception e) {
|
|
420
|
+
Logger.e(TAG, "getInitialNotification", e);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// If no initial notification, return
|
|
425
|
+
result.onComplete(null, null);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
@KeepForSdk
|
|
429
|
+
public void isBatteryOptimizationEnabled(MethodCallResult<Boolean> result) {
|
|
430
|
+
Boolean isBatteryOptimizationEnabled =
|
|
431
|
+
PowerManagerUtils.isBatteryOptimizationEnabled(ContextHolder.getApplicationContext());
|
|
432
|
+
result.onComplete(null, isBatteryOptimizationEnabled);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
@KeepForSdk
|
|
436
|
+
public void openBatteryOptimizationSettings(Activity activity, MethodCallResult<Void> result) {
|
|
437
|
+
PowerManagerUtils.openBatteryOptimizationSettings(activity);
|
|
438
|
+
result.onComplete(null, null);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
@KeepForSdk
|
|
442
|
+
public void getPowerManagerInfo(MethodCallResult<Bundle> result) {
|
|
443
|
+
PowerManagerUtils.PowerManagerInfo info = PowerManagerUtils.getPowerManagerInfo();
|
|
444
|
+
result.onComplete(null, info.toBundle());
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
@KeepForSdk
|
|
448
|
+
public void openPowerManagerSettings(Activity activity, MethodCallResult<Void> result) {
|
|
449
|
+
PowerManagerUtils.openPowerManagerSettings(activity);
|
|
450
|
+
result.onComplete(null, null);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
@KeepForSdk
|
|
454
|
+
public void getNotificationSettings(MethodCallResult<Bundle> result) {
|
|
455
|
+
boolean areNotificationsEnabled =
|
|
456
|
+
NotificationManagerCompat.from(ContextHolder.getApplicationContext())
|
|
457
|
+
.areNotificationsEnabled();
|
|
458
|
+
|
|
459
|
+
Bundle notificationSettingsBundle = new Bundle();
|
|
460
|
+
if (areNotificationsEnabled) {
|
|
461
|
+
notificationSettingsBundle.putInt("authorizationStatus", 1);
|
|
462
|
+
} else {
|
|
463
|
+
notificationSettingsBundle.putInt("authorizationStatus", 0);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
boolean canScheduleExactAlarms = AlarmUtils.canScheduleExactAlarms();
|
|
467
|
+
Bundle androidSettingsBundle = new Bundle();
|
|
468
|
+
|
|
469
|
+
if (canScheduleExactAlarms) {
|
|
470
|
+
androidSettingsBundle.putInt("alarm", 1);
|
|
471
|
+
} else {
|
|
472
|
+
androidSettingsBundle.putInt("alarm", 0);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
notificationSettingsBundle.putBundle("android", androidSettingsBundle);
|
|
476
|
+
result.onComplete(null, notificationSettingsBundle);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
@Nullable private MethodCallResult<Bundle> requestPermissionCallResult;
|
|
480
|
+
|
|
481
|
+
@KeepForSdk
|
|
482
|
+
public void setRequestPermissionCallback(MethodCallResult<Bundle> result) {
|
|
483
|
+
requestPermissionCallResult = result;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
@KeepForSdk
|
|
487
|
+
public boolean onRequestPermissionsResult(
|
|
488
|
+
int requestCode, String[] permissions, int[] grantResults) {
|
|
489
|
+
if (requestCode == REQUEST_CODE_NOTIFICATION_PERMISSION) {
|
|
490
|
+
if (requestPermissionCallResult != null) {
|
|
491
|
+
getNotificationSettings(requestPermissionCallResult);
|
|
492
|
+
return true;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
return false;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
@KeepForSdk
|
|
499
|
+
public void openNotificationSettings(
|
|
500
|
+
@Nullable String channelId, Activity activity, MethodCallResult<Void> result) {
|
|
501
|
+
if (getContext() == null || activity == null) {
|
|
502
|
+
Logger.d(
|
|
503
|
+
"openNotificationSettings",
|
|
504
|
+
"attempted to start activity but no current activity or context was available.");
|
|
505
|
+
result.onComplete(null, null);
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
Intent intent;
|
|
510
|
+
if (Build.VERSION.SDK_INT >= 26) {
|
|
511
|
+
if (channelId != null) {
|
|
512
|
+
intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
|
|
513
|
+
intent.putExtra(Settings.EXTRA_CHANNEL_ID, channelId);
|
|
514
|
+
} else {
|
|
515
|
+
intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS);
|
|
516
|
+
}
|
|
517
|
+
intent.putExtra(Settings.EXTRA_APP_PACKAGE, getContext().getPackageName());
|
|
518
|
+
} else {
|
|
519
|
+
intent = new Intent(Settings.ACTION_APPLICATION_SETTINGS);
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
intent.setFlags(FLAG_ACTIVITY_NEW_TASK);
|
|
523
|
+
|
|
524
|
+
activity.runOnUiThread(() -> getContext().startActivity(intent));
|
|
525
|
+
result.onComplete(null, null);
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
@KeepForSdk
|
|
529
|
+
public void stopForegroundService(MethodCallResult<Void> result) {
|
|
530
|
+
ForegroundService.stop();
|
|
531
|
+
result.onComplete(null, null);
|
|
532
|
+
}
|
|
533
|
+
}
|