@ammarahmed/notifee-react-native 7.3.1 → 7.4.2
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,256 @@
|
|
|
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 app.notifee.core.ContextHolder.getApplicationContext;
|
|
21
|
+
|
|
22
|
+
import android.app.AlarmManager;
|
|
23
|
+
import android.app.PendingIntent;
|
|
24
|
+
import android.content.Context;
|
|
25
|
+
import android.content.Intent;
|
|
26
|
+
import android.os.Build;
|
|
27
|
+
import android.os.Bundle;
|
|
28
|
+
import androidx.core.app.AlarmManagerCompat;
|
|
29
|
+
|
|
30
|
+
import app.notifee.core.database.WorkDataEntity;
|
|
31
|
+
import app.notifee.core.database.WorkDataRepository;
|
|
32
|
+
import app.notifee.core.model.NotificationModel;
|
|
33
|
+
import app.notifee.core.model.TimestampTriggerModel;
|
|
34
|
+
import app.notifee.core.utility.AlarmUtils;
|
|
35
|
+
import app.notifee.core.utility.ExtendedListenableFuture;
|
|
36
|
+
import app.notifee.core.utility.ObjectUtils;
|
|
37
|
+
import com.google.common.util.concurrent.FutureCallback;
|
|
38
|
+
import com.google.common.util.concurrent.Futures;
|
|
39
|
+
import com.google.common.util.concurrent.ListenableFuture;
|
|
40
|
+
import com.google.common.util.concurrent.ListeningExecutorService;
|
|
41
|
+
import com.google.common.util.concurrent.MoreExecutors;
|
|
42
|
+
import java.util.List;
|
|
43
|
+
import java.util.concurrent.ExecutorService;
|
|
44
|
+
import java.util.concurrent.Executors;
|
|
45
|
+
|
|
46
|
+
class NotifeeAlarmManager {
|
|
47
|
+
private static final String TAG = "NotifeeAlarmManager";
|
|
48
|
+
private static final String NOTIFICATION_ID_INTENT_KEY = "notificationId";
|
|
49
|
+
private static final ExecutorService alarmManagerExecutor = Executors.newCachedThreadPool();
|
|
50
|
+
private static final ListeningExecutorService alarmManagerListeningExecutor = MoreExecutors.listeningDecorator(
|
|
51
|
+
alarmManagerExecutor);
|
|
52
|
+
|
|
53
|
+
static void displayScheduledNotification(Bundle alarmManagerNotification) {
|
|
54
|
+
if (alarmManagerNotification == null) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
String id = alarmManagerNotification.getString(NOTIFICATION_ID_INTENT_KEY);
|
|
58
|
+
|
|
59
|
+
if (id == null) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
WorkDataRepository workDataRepository = new WorkDataRepository(getApplicationContext());
|
|
64
|
+
|
|
65
|
+
ListenableFuture<?> displayFuture = new ExtendedListenableFuture<>(workDataRepository.getWorkDataById(id)).continueWith(workDataEntity -> {
|
|
66
|
+
Bundle notificationBundle;
|
|
67
|
+
|
|
68
|
+
Bundle triggerBundle;
|
|
69
|
+
|
|
70
|
+
if (workDataEntity == null
|
|
71
|
+
|| workDataEntity.getNotification() == null
|
|
72
|
+
|| workDataEntity.getTrigger() == null) {
|
|
73
|
+
// check if notification bundle is stored with Work Manager
|
|
74
|
+
Logger.w(
|
|
75
|
+
TAG, "Attempted to handle doScheduledWork but no notification data was found.");
|
|
76
|
+
return Futures.immediateFuture(null);
|
|
77
|
+
} else {
|
|
78
|
+
triggerBundle = ObjectUtils.bytesToBundle(workDataEntity.getTrigger());
|
|
79
|
+
notificationBundle = ObjectUtils.bytesToBundle(workDataEntity.getNotification());
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
NotificationModel notificationModel = NotificationModel.fromBundle(notificationBundle);
|
|
83
|
+
|
|
84
|
+
return new ExtendedListenableFuture<>(
|
|
85
|
+
NotificationManager.displayNotification(notificationModel, triggerBundle)
|
|
86
|
+
).continueWith(voidDisplayedNotification -> {
|
|
87
|
+
if (triggerBundle.containsKey("repeatFrequency")
|
|
88
|
+
&& ObjectUtils.getInt(triggerBundle.get("repeatFrequency")) != -1) {
|
|
89
|
+
TimestampTriggerModel trigger =
|
|
90
|
+
TimestampTriggerModel.fromBundle(triggerBundle);
|
|
91
|
+
// Ensure trigger is in the future and the latest timestamp is updated in
|
|
92
|
+
// the database
|
|
93
|
+
trigger.setNextTimestamp();
|
|
94
|
+
scheduleTimestampTriggerNotification(notificationModel, trigger);
|
|
95
|
+
WorkDataRepository.getInstance(getApplicationContext())
|
|
96
|
+
.update(
|
|
97
|
+
new WorkDataEntity(
|
|
98
|
+
id,
|
|
99
|
+
workDataEntity.getNotification(),
|
|
100
|
+
ObjectUtils.bundleToBytes(triggerBundle),
|
|
101
|
+
true));
|
|
102
|
+
} else {
|
|
103
|
+
// not repeating, delete database entry if work is a one-time request
|
|
104
|
+
WorkDataRepository.getInstance(getApplicationContext()).deleteById(id);
|
|
105
|
+
}
|
|
106
|
+
return Futures.immediateFuture(null);
|
|
107
|
+
}, alarmManagerExecutor);
|
|
108
|
+
}, alarmManagerExecutor)
|
|
109
|
+
.addOnCompleteListener(
|
|
110
|
+
(e, result) -> {
|
|
111
|
+
if (e != null) {
|
|
112
|
+
Logger.e(TAG, "Failed to display notification", e);
|
|
113
|
+
}
|
|
114
|
+
}, alarmManagerExecutor);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
public static PendingIntent getAlarmManagerIntentForNotification(String notificationId) {
|
|
118
|
+
try {
|
|
119
|
+
Context context = getApplicationContext();
|
|
120
|
+
Intent notificationIntent = new Intent(context, NotificationAlarmReceiver.class);
|
|
121
|
+
notificationIntent.putExtra(NOTIFICATION_ID_INTENT_KEY, notificationId);
|
|
122
|
+
return PendingIntent.getBroadcast(
|
|
123
|
+
context,
|
|
124
|
+
notificationId.hashCode(),
|
|
125
|
+
notificationIntent,
|
|
126
|
+
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE);
|
|
127
|
+
|
|
128
|
+
} catch (Exception e) {
|
|
129
|
+
Logger.e(TAG, "Unable to create AlarmManager intent", e);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
static void scheduleTimestampTriggerNotification(
|
|
136
|
+
NotificationModel notificationModel, TimestampTriggerModel timestampTrigger) {
|
|
137
|
+
|
|
138
|
+
PendingIntent pendingIntent = getAlarmManagerIntentForNotification(notificationModel.getId());
|
|
139
|
+
|
|
140
|
+
AlarmManager alarmManager = AlarmUtils.getAlarmManager();
|
|
141
|
+
|
|
142
|
+
// Verify we can call setExact APIs to avoid a crash, but it requires an Android S+ symbol
|
|
143
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
144
|
+
if (!alarmManager.canScheduleExactAlarms()) {
|
|
145
|
+
System.err.println(
|
|
146
|
+
"Missing SCHEDULE_EXACT_ALARM permission. Trigger not scheduled. See:"
|
|
147
|
+
+ " https://notifee.app/react-native/docs/triggers#android-12-limitations");
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Ensure timestamp is always in the future when scheduling the alarm
|
|
153
|
+
timestampTrigger.setNextTimestamp();
|
|
154
|
+
|
|
155
|
+
if (timestampTrigger.getAllowWhileIdle()) {
|
|
156
|
+
int mutabilityFlag = PendingIntent.FLAG_UPDATE_CURRENT;
|
|
157
|
+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
|
|
158
|
+
mutabilityFlag = PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
Context context = getApplicationContext();
|
|
162
|
+
Intent launchActivityIntent =
|
|
163
|
+
context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
|
|
164
|
+
|
|
165
|
+
PendingIntent pendingLaunchIntent =
|
|
166
|
+
PendingIntent.getActivity(
|
|
167
|
+
context,
|
|
168
|
+
0,
|
|
169
|
+
launchActivityIntent,
|
|
170
|
+
mutabilityFlag);
|
|
171
|
+
AlarmManagerCompat.setAlarmClock(
|
|
172
|
+
alarmManager, timestampTrigger.getTimestamp(), pendingLaunchIntent, pendingIntent);
|
|
173
|
+
} else {
|
|
174
|
+
AlarmManagerCompat.setExact(
|
|
175
|
+
alarmManager, AlarmManager.RTC_WAKEUP, timestampTrigger.getTimestamp(), pendingIntent);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
ListenableFuture<List<WorkDataEntity>> getScheduledNotifications() {
|
|
180
|
+
WorkDataRepository workDataRepository = new WorkDataRepository(getApplicationContext());
|
|
181
|
+
return workDataRepository.getAllWithAlarmManager(true);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
public static void cancelNotification(String notificationId) {
|
|
185
|
+
PendingIntent pendingIntent = getAlarmManagerIntentForNotification(notificationId);
|
|
186
|
+
AlarmManager alarmManager = AlarmUtils.getAlarmManager();
|
|
187
|
+
if (pendingIntent != null) {
|
|
188
|
+
alarmManager.cancel(pendingIntent);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
public static ListenableFuture<Void> cancelAllNotifications() {
|
|
193
|
+
WorkDataRepository workDataRepository =
|
|
194
|
+
WorkDataRepository.getInstance(getApplicationContext());
|
|
195
|
+
|
|
196
|
+
return new ExtendedListenableFuture<>(workDataRepository
|
|
197
|
+
.getAllWithAlarmManager(true))
|
|
198
|
+
.continueWith(
|
|
199
|
+
workDataEntities -> {
|
|
200
|
+
if (workDataEntities != null) {
|
|
201
|
+
for (WorkDataEntity workDataEntity : workDataEntities) {
|
|
202
|
+
NotifeeAlarmManager.cancelNotification(workDataEntity.getId());
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return Futures.immediateFuture(null);
|
|
206
|
+
}, alarmManagerListeningExecutor);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/* On reboot, reschedule trigger notifications created via alarm manager */
|
|
210
|
+
void rescheduleNotification(WorkDataEntity workDataEntity) {
|
|
211
|
+
if (workDataEntity.getNotification() == null || workDataEntity.getTrigger() == null) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
byte[] notificationBytes = workDataEntity.getNotification();
|
|
216
|
+
byte[] triggerBytes = workDataEntity.getTrigger();
|
|
217
|
+
Bundle triggerBundle = ObjectUtils.bytesToBundle(triggerBytes);
|
|
218
|
+
|
|
219
|
+
NotificationModel notificationModel =
|
|
220
|
+
NotificationModel.fromBundle(ObjectUtils.bytesToBundle(notificationBytes));
|
|
221
|
+
|
|
222
|
+
int triggerType = ObjectUtils.getInt(triggerBundle.get("type"));
|
|
223
|
+
|
|
224
|
+
switch (triggerType) {
|
|
225
|
+
case 0:
|
|
226
|
+
TimestampTriggerModel trigger = TimestampTriggerModel.fromBundle(triggerBundle);
|
|
227
|
+
if (!trigger.getWithAlarmManager()) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
scheduleTimestampTriggerNotification(notificationModel, trigger);
|
|
232
|
+
break;
|
|
233
|
+
case 1:
|
|
234
|
+
// TODO: support interval triggers with alarm manager
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
void rescheduleNotifications() {
|
|
240
|
+
Logger.d(TAG, "Reschedule Notifications on reboot");
|
|
241
|
+
Futures.addCallback(getScheduledNotifications(),
|
|
242
|
+
new FutureCallback<List<WorkDataEntity>>() {
|
|
243
|
+
@Override
|
|
244
|
+
public void onSuccess(List<WorkDataEntity> workDataEntities) {
|
|
245
|
+
for (WorkDataEntity workDataEntity : workDataEntities) {
|
|
246
|
+
rescheduleNotification(workDataEntity);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
@Override
|
|
251
|
+
public void onFailure(Throwable t) {
|
|
252
|
+
// silently fail
|
|
253
|
+
}
|
|
254
|
+
}, alarmManagerListeningExecutor);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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.BroadcastReceiver;
|
|
21
|
+
import android.content.Context;
|
|
22
|
+
import android.content.Intent;
|
|
23
|
+
|
|
24
|
+
/*
|
|
25
|
+
* This is invoked by the Alarm Manager when it is time to display a scheduled notification.
|
|
26
|
+
*/
|
|
27
|
+
public class NotificationAlarmReceiver extends BroadcastReceiver {
|
|
28
|
+
@Override
|
|
29
|
+
public void onReceive(Context context, Intent intent) {
|
|
30
|
+
new NotifeeAlarmManager().displayScheduledNotification(intent.getExtras());
|
|
31
|
+
}
|
|
32
|
+
}
|