@ammarahmed/notifee-react-native 7.3.0 → 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 +35 -17
- 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,268 @@
|
|
|
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.event.NotificationEvent.TYPE_ACTION_PRESS;
|
|
21
|
+
import static app.notifee.core.event.NotificationEvent.TYPE_DISMISSED;
|
|
22
|
+
import static app.notifee.core.event.NotificationEvent.TYPE_PRESS;
|
|
23
|
+
|
|
24
|
+
import android.app.PendingIntent;
|
|
25
|
+
import android.app.Service;
|
|
26
|
+
import android.content.Context;
|
|
27
|
+
import android.content.Intent;
|
|
28
|
+
import android.os.Build;
|
|
29
|
+
import android.os.Bundle;
|
|
30
|
+
import android.os.IBinder;
|
|
31
|
+
import androidx.annotation.Nullable;
|
|
32
|
+
import androidx.core.app.NotificationManagerCompat;
|
|
33
|
+
import androidx.core.app.RemoteInput;
|
|
34
|
+
import app.notifee.core.event.InitialNotificationEvent;
|
|
35
|
+
import app.notifee.core.event.MainComponentEvent;
|
|
36
|
+
import app.notifee.core.event.NotificationEvent;
|
|
37
|
+
import app.notifee.core.model.NotificationAndroidModel;
|
|
38
|
+
import app.notifee.core.model.NotificationAndroidPressActionModel;
|
|
39
|
+
import app.notifee.core.model.NotificationModel;
|
|
40
|
+
import app.notifee.core.utility.IntentUtils;
|
|
41
|
+
import java.util.concurrent.atomic.AtomicInteger;
|
|
42
|
+
|
|
43
|
+
public class ReceiverService extends Service {
|
|
44
|
+
private static final String TAG = "ReceiverService";
|
|
45
|
+
public static final String REMOTE_INPUT_RECEIVER_KEY =
|
|
46
|
+
"app.notifee.core.ReceiverService.REMOTE_INPUT_RECEIVER_KEY";
|
|
47
|
+
|
|
48
|
+
private static final AtomicInteger uniqueIds = new AtomicInteger(0);
|
|
49
|
+
|
|
50
|
+
static final String DELETE_INTENT = "app.notifee.core.ReceiverService.DELETE_INTENT";
|
|
51
|
+
static final String PRESS_INTENT = "app.notifee.core.ReceiverService.PRESS_INTENT";
|
|
52
|
+
static final String ACTION_PRESS_INTENT = "app.notifee.core.ReceiverService.ACTION_PRESS_INTENT";
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Creates a PendingIntent, which when sent triggers this class.
|
|
56
|
+
*
|
|
57
|
+
* @param action An Action - matches up with the JS EventType Enum.
|
|
58
|
+
* @param extraKeys Array of strings
|
|
59
|
+
* @param extraBundles One or more bundles
|
|
60
|
+
*/
|
|
61
|
+
public static PendingIntent createIntent(
|
|
62
|
+
String action, String[] extraKeys, Bundle... extraBundles) {
|
|
63
|
+
Context context = ContextHolder.getApplicationContext();
|
|
64
|
+
Intent intent = new Intent(context, ReceiverService.class);
|
|
65
|
+
intent.setAction(action);
|
|
66
|
+
|
|
67
|
+
for (int i = 0; i < extraKeys.length; i++) {
|
|
68
|
+
String key = extraKeys[i];
|
|
69
|
+
|
|
70
|
+
if (i <= extraBundles.length - 1) {
|
|
71
|
+
Bundle bundle = extraBundles[i];
|
|
72
|
+
intent.putExtra(key, bundle);
|
|
73
|
+
} else {
|
|
74
|
+
intent.putExtra(key, (String) null);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
int uniqueInt = uniqueIds.getAndIncrement();
|
|
79
|
+
return PendingIntent.getService(
|
|
80
|
+
context, uniqueInt, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
@Nullable
|
|
84
|
+
@Override
|
|
85
|
+
public IBinder onBind(Intent intent) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@Override
|
|
90
|
+
public int onStartCommand(Intent intent, int flags, int startId) {
|
|
91
|
+
String action = intent.getAction();
|
|
92
|
+
|
|
93
|
+
if (action == null) {
|
|
94
|
+
return START_NOT_STICKY;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
switch (action) {
|
|
98
|
+
case DELETE_INTENT:
|
|
99
|
+
onDeleteIntent(intent);
|
|
100
|
+
break;
|
|
101
|
+
case PRESS_INTENT:
|
|
102
|
+
onPressIntent(intent);
|
|
103
|
+
break;
|
|
104
|
+
case ACTION_PRESS_INTENT:
|
|
105
|
+
onActionPressIntent(intent);
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return START_NOT_STICKY;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Handle users delete/dismiss intents */
|
|
113
|
+
private void onDeleteIntent(Intent intent) {
|
|
114
|
+
Bundle notification = intent.getBundleExtra("notification");
|
|
115
|
+
|
|
116
|
+
if (notification == null) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
NotificationModel notificationModel = NotificationModel.fromBundle(notification);
|
|
121
|
+
EventBus.post(new NotificationEvent(TYPE_DISMISSED, notificationModel));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Handle user notification press */
|
|
125
|
+
private void onPressIntent(Intent intent) {
|
|
126
|
+
Bundle notification = intent.getBundleExtra("notification");
|
|
127
|
+
|
|
128
|
+
if (notification == null) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
NotificationModel notificationModel = NotificationModel.fromBundle(notification);
|
|
133
|
+
|
|
134
|
+
Bundle pressAction = intent.getBundleExtra("pressAction");
|
|
135
|
+
NotificationAndroidPressActionModel pressActionBundle = null;
|
|
136
|
+
|
|
137
|
+
Bundle extras = new Bundle();
|
|
138
|
+
|
|
139
|
+
if (pressAction != null) {
|
|
140
|
+
pressActionBundle = NotificationAndroidPressActionModel.fromBundle(pressAction);
|
|
141
|
+
extras.putBundle("pressAction", pressActionBundle.toBundle());
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
EventBus.post(new NotificationEvent(TYPE_PRESS, notificationModel, extras));
|
|
145
|
+
|
|
146
|
+
if (pressActionBundle == null) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
String launchActivity = pressActionBundle.getLaunchActivity();
|
|
151
|
+
String mainComponent = pressActionBundle.getMainComponent();
|
|
152
|
+
|
|
153
|
+
if (launchActivity != null || mainComponent != null) {
|
|
154
|
+
InitialNotificationEvent initialNotificationEvent =
|
|
155
|
+
new InitialNotificationEvent(notificationModel, extras);
|
|
156
|
+
launchPendingIntentActivity(
|
|
157
|
+
initialNotificationEvent,
|
|
158
|
+
launchActivity,
|
|
159
|
+
mainComponent,
|
|
160
|
+
pressActionBundle.getLaunchActivityFlags());
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Handle action intents */
|
|
165
|
+
private void onActionPressIntent(Intent intent) {
|
|
166
|
+
Bundle notification = intent.getBundleExtra("notification");
|
|
167
|
+
Bundle pressAction = intent.getBundleExtra("pressAction");
|
|
168
|
+
|
|
169
|
+
if (notification == null || pressAction == null) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
NotificationModel notificationModel = NotificationModel.fromBundle(notification);
|
|
174
|
+
NotificationAndroidModel notificationAndroidModel = notificationModel.getAndroid();
|
|
175
|
+
NotificationAndroidPressActionModel pressActionBundle =
|
|
176
|
+
NotificationAndroidPressActionModel.fromBundle(pressAction);
|
|
177
|
+
|
|
178
|
+
Bundle extras = new Bundle();
|
|
179
|
+
extras.putBundle("pressAction", pressActionBundle.toBundle());
|
|
180
|
+
|
|
181
|
+
Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
|
|
182
|
+
if (remoteInput != null) {
|
|
183
|
+
CharSequence input = remoteInput.getCharSequence(REMOTE_INPUT_RECEIVER_KEY);
|
|
184
|
+
if (input != null) {
|
|
185
|
+
extras.putString("input", input.toString());
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
EventBus.post(new NotificationEvent(TYPE_ACTION_PRESS, notificationModel, extras));
|
|
190
|
+
|
|
191
|
+
if (notificationModel.getAndroid().getAutoCancel()) {
|
|
192
|
+
NotificationManagerCompat notificationManagerCompat =
|
|
193
|
+
NotificationManagerCompat.from(getApplicationContext());
|
|
194
|
+
|
|
195
|
+
notificationManagerCompat.cancel(
|
|
196
|
+
notificationAndroidModel.getTag(), notificationModel.getId().hashCode());
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
String launchActivity = pressActionBundle.getLaunchActivity();
|
|
200
|
+
String mainComponent = pressActionBundle.getMainComponent();
|
|
201
|
+
|
|
202
|
+
if (launchActivity != null || mainComponent != null) {
|
|
203
|
+
InitialNotificationEvent initialNotificationEvent =
|
|
204
|
+
new InitialNotificationEvent(notificationModel, extras);
|
|
205
|
+
launchPendingIntentActivity(
|
|
206
|
+
initialNotificationEvent,
|
|
207
|
+
launchActivity,
|
|
208
|
+
mainComponent,
|
|
209
|
+
pressActionBundle.getLaunchActivityFlags());
|
|
210
|
+
|
|
211
|
+
int targetSdkVersion =
|
|
212
|
+
ContextHolder.getApplicationContext().getApplicationInfo().targetSdkVersion;
|
|
213
|
+
|
|
214
|
+
// Close notification drawer if application SDK is Android 11 and lower
|
|
215
|
+
// See
|
|
216
|
+
// https://developer.android.com/about/versions/12/behavior-changes-all#close-system-dialogs
|
|
217
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
|
|
218
|
+
ContextHolder.getApplicationContext()
|
|
219
|
+
.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
private void launchPendingIntentActivity(
|
|
225
|
+
InitialNotificationEvent initialNotificationEvent,
|
|
226
|
+
@Nullable String launchActivity,
|
|
227
|
+
@Nullable String mainComponent,
|
|
228
|
+
int launchActivityFlags) {
|
|
229
|
+
Class<?> launchActivityClass = IntentUtils.getLaunchActivity(launchActivity);
|
|
230
|
+
if (launchActivityClass == null) {
|
|
231
|
+
Logger.e(TAG, "Failed to get launch activity");
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
Intent launchIntent = new Intent(getApplicationContext(), launchActivityClass);
|
|
236
|
+
|
|
237
|
+
if (launchActivityFlags != -1) {
|
|
238
|
+
launchIntent.addFlags(launchActivityFlags);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (mainComponent != null) {
|
|
242
|
+
launchIntent.putExtra("mainComponent", mainComponent);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
PendingIntent pendingContentIntent =
|
|
246
|
+
PendingIntent.getActivity(
|
|
247
|
+
getApplicationContext(),
|
|
248
|
+
initialNotificationEvent.getNotificationModel().getHashCode(),
|
|
249
|
+
launchIntent,
|
|
250
|
+
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE);
|
|
251
|
+
|
|
252
|
+
try {
|
|
253
|
+
pendingContentIntent.send();
|
|
254
|
+
EventBus.postSticky(initialNotificationEvent);
|
|
255
|
+
|
|
256
|
+
// Send sticky event to save the mainComponent
|
|
257
|
+
if (mainComponent != null) {
|
|
258
|
+
EventBus.postSticky(new MainComponentEvent(mainComponent));
|
|
259
|
+
}
|
|
260
|
+
} catch (Exception e) {
|
|
261
|
+
Logger.e(
|
|
262
|
+
"ReceiverService",
|
|
263
|
+
"Failed to send PendingIntent from launchPendingIntentActivity for notification "
|
|
264
|
+
+ initialNotificationEvent.getNotificationModel().getId(),
|
|
265
|
+
e);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
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 androidx.annotation.Keep;
|
|
22
|
+
import androidx.annotation.NonNull;
|
|
23
|
+
import androidx.concurrent.futures.CallbackToFutureAdapter;
|
|
24
|
+
import androidx.work.ListenableWorker;
|
|
25
|
+
import androidx.work.WorkerParameters;
|
|
26
|
+
import com.google.common.util.concurrent.ListenableFuture;
|
|
27
|
+
|
|
28
|
+
public class Worker extends ListenableWorker {
|
|
29
|
+
static final String KEY_WORK_TYPE = "workType";
|
|
30
|
+
static final String KEY_IS_PRIMARY = "isPrimaryKey";
|
|
31
|
+
static final String WORK_TYPE_BLOCK_STATE_RECEIVER =
|
|
32
|
+
"app.notifee.core.BlockStateBroadcastReceiver.WORKER";
|
|
33
|
+
static final String WORK_TYPE_NOTIFICATION_TRIGGER =
|
|
34
|
+
"app.notifee.core.NotificationManager.TRIGGER";
|
|
35
|
+
static final String WORK_REQUEST_ONE_TIME = "OneTime";
|
|
36
|
+
static final String WORK_REQUEST_PERIODIC = "Periodic";
|
|
37
|
+
static final String KEY_WORK_REQUEST = "workRequestType";
|
|
38
|
+
private static final String TAG = "Worker";
|
|
39
|
+
|
|
40
|
+
private CallbackToFutureAdapter.Completer<Result> mCompleter;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @param appContext The application {@link Context}
|
|
44
|
+
* @param workerParams Parameters to setup the internal state of this worker
|
|
45
|
+
*/
|
|
46
|
+
@Keep
|
|
47
|
+
public Worker(@NonNull Context appContext, @NonNull WorkerParameters workerParams) {
|
|
48
|
+
super(appContext, workerParams);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@Override
|
|
52
|
+
public void onStopped() {
|
|
53
|
+
if (mCompleter != null) mCompleter.set(Result.failure());
|
|
54
|
+
mCompleter = null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@NonNull
|
|
58
|
+
@Override
|
|
59
|
+
public ListenableFuture<Result> startWork() {
|
|
60
|
+
return CallbackToFutureAdapter.getFuture(
|
|
61
|
+
completer -> {
|
|
62
|
+
mCompleter = completer;
|
|
63
|
+
String workType = getInputData().getString(KEY_WORK_TYPE);
|
|
64
|
+
if (workType == null) {
|
|
65
|
+
Logger.d(TAG, "received task with no input key type.");
|
|
66
|
+
completer.set(Result.success());
|
|
67
|
+
return "Worker.startWork operation cancelled - no input.";
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
switch (workType) {
|
|
71
|
+
case WORK_TYPE_BLOCK_STATE_RECEIVER:
|
|
72
|
+
Logger.d(TAG, "received task with type " + workType);
|
|
73
|
+
BlockStateBroadcastReceiver.doWork(getInputData(), completer);
|
|
74
|
+
break;
|
|
75
|
+
case WORK_TYPE_NOTIFICATION_TRIGGER:
|
|
76
|
+
NotificationManager.doScheduledWork(getInputData(), completer);
|
|
77
|
+
break;
|
|
78
|
+
default:
|
|
79
|
+
Logger.d(TAG, "unknown work type received: " + workType);
|
|
80
|
+
completer.set(Result.success());
|
|
81
|
+
return "Worker.startWork operation cancelled - unknown work type.";
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return "Worker.startWork operation created successfully.";
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
package app.notifee.core.database;
|
|
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 androidx.annotation.VisibleForTesting;
|
|
22
|
+
import androidx.room.Database;
|
|
23
|
+
import androidx.room.Room;
|
|
24
|
+
import androidx.room.RoomDatabase;
|
|
25
|
+
import androidx.room.migration.Migration;
|
|
26
|
+
import androidx.sqlite.db.SupportSQLiteDatabase;
|
|
27
|
+
import com.google.common.util.concurrent.ListeningExecutorService;
|
|
28
|
+
import com.google.common.util.concurrent.MoreExecutors;
|
|
29
|
+
import java.util.concurrent.ExecutorService;
|
|
30
|
+
import java.util.concurrent.Executors;
|
|
31
|
+
|
|
32
|
+
@Database(
|
|
33
|
+
entities = {WorkDataEntity.class},
|
|
34
|
+
version = 2,
|
|
35
|
+
exportSchema = true)
|
|
36
|
+
public abstract class NotifeeCoreDatabase extends RoomDatabase {
|
|
37
|
+
|
|
38
|
+
public abstract WorkDataDao workDao();
|
|
39
|
+
|
|
40
|
+
private static volatile NotifeeCoreDatabase INSTANCE;
|
|
41
|
+
|
|
42
|
+
static final ExecutorService databaseWriteExecutor = Executors.newCachedThreadPool();
|
|
43
|
+
static final ListeningExecutorService databaseWriteListeningExecutor = MoreExecutors.listeningDecorator(databaseWriteExecutor);
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Migrate from: version 1 to version 2 - where the {@link WorkDataEntity} has an extra field:
|
|
47
|
+
* alert
|
|
48
|
+
*/
|
|
49
|
+
@VisibleForTesting
|
|
50
|
+
static final Migration MIGRATION_1_2 =
|
|
51
|
+
new Migration(1, 2) {
|
|
52
|
+
@Override
|
|
53
|
+
public void migrate(SupportSQLiteDatabase database) {
|
|
54
|
+
database.execSQL(
|
|
55
|
+
"ALTER TABLE work_data"
|
|
56
|
+
+ " ADD COLUMN with_alarm_manager INTEGER NOT NULL DEFAULT 0");
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
static NotifeeCoreDatabase getDatabase(final Context context) {
|
|
61
|
+
if (INSTANCE == null) {
|
|
62
|
+
synchronized (NotifeeCoreDatabase.class) {
|
|
63
|
+
if (INSTANCE == null) {
|
|
64
|
+
INSTANCE =
|
|
65
|
+
Room.databaseBuilder(
|
|
66
|
+
context.getApplicationContext(),
|
|
67
|
+
NotifeeCoreDatabase.class,
|
|
68
|
+
"notifee_core_database")
|
|
69
|
+
.addMigrations(MIGRATION_1_2)
|
|
70
|
+
.build();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return INSTANCE;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
package app.notifee.core.database;
|
|
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 androidx.room.Dao;
|
|
21
|
+
import androidx.room.Insert;
|
|
22
|
+
import androidx.room.OnConflictStrategy;
|
|
23
|
+
import androidx.room.Query;
|
|
24
|
+
import androidx.room.Update;
|
|
25
|
+
import java.util.List;
|
|
26
|
+
|
|
27
|
+
@Dao
|
|
28
|
+
public interface WorkDataDao {
|
|
29
|
+
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
|
30
|
+
void insert(WorkDataEntity workDataEntity);
|
|
31
|
+
|
|
32
|
+
@Update(onConflict = OnConflictStrategy.REPLACE)
|
|
33
|
+
void update(WorkDataEntity workDataEntity);
|
|
34
|
+
|
|
35
|
+
@Query("DELETE FROM work_data")
|
|
36
|
+
void deleteAll();
|
|
37
|
+
|
|
38
|
+
@Query("DELETE FROM work_data WHERE id = :id")
|
|
39
|
+
void deleteById(String id);
|
|
40
|
+
|
|
41
|
+
@Query("DELETE FROM work_data WHERE id in (:ids)")
|
|
42
|
+
void deleteByIds(List<String> ids);
|
|
43
|
+
|
|
44
|
+
@Query("SELECT * from work_data WHERE id = :id")
|
|
45
|
+
WorkDataEntity getWorkDataById(String id);
|
|
46
|
+
|
|
47
|
+
@Query("SELECT * FROM work_data WHERE with_alarm_manager = :withAlarmManager")
|
|
48
|
+
List<WorkDataEntity> getAllWithAlarmManager(Boolean withAlarmManager);
|
|
49
|
+
|
|
50
|
+
@Query("SELECT * FROM work_data")
|
|
51
|
+
List<WorkDataEntity> getAll();
|
|
52
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
package app.notifee.core.database;
|
|
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 androidx.annotation.NonNull;
|
|
21
|
+
import androidx.room.ColumnInfo;
|
|
22
|
+
import androidx.room.Entity;
|
|
23
|
+
import androidx.room.PrimaryKey;
|
|
24
|
+
|
|
25
|
+
@Entity(tableName = "work_data")
|
|
26
|
+
public class WorkDataEntity {
|
|
27
|
+
|
|
28
|
+
@PrimaryKey(autoGenerate = false)
|
|
29
|
+
@NonNull
|
|
30
|
+
private String id;
|
|
31
|
+
|
|
32
|
+
@ColumnInfo(name = "notification", typeAffinity = ColumnInfo.BLOB)
|
|
33
|
+
private byte[] notification;
|
|
34
|
+
|
|
35
|
+
@ColumnInfo(name = "trigger", typeAffinity = ColumnInfo.BLOB)
|
|
36
|
+
private byte[] trigger;
|
|
37
|
+
|
|
38
|
+
@ColumnInfo(name = "with_alarm_manager", defaultValue = "0")
|
|
39
|
+
@NonNull
|
|
40
|
+
private Boolean withAlarmManager;
|
|
41
|
+
|
|
42
|
+
public WorkDataEntity(String id, byte[] notification, byte[] trigger, Boolean withAlarmManager) {
|
|
43
|
+
this.id = id;
|
|
44
|
+
this.notification = notification;
|
|
45
|
+
this.trigger = trigger;
|
|
46
|
+
this.withAlarmManager = withAlarmManager;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public String getId() {
|
|
50
|
+
return this.id;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public byte[] getNotification() {
|
|
54
|
+
return this.notification;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public byte[] getTrigger() {
|
|
58
|
+
return this.trigger;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public Boolean getWithAlarmManager() {
|
|
62
|
+
return this.withAlarmManager;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public void setTrigger(byte[] trigger) {
|
|
66
|
+
this.trigger = trigger;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
package app.notifee.core.database;
|
|
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 android.os.Bundle;
|
|
22
|
+
import androidx.annotation.NonNull;
|
|
23
|
+
import app.notifee.core.model.NotificationModel;
|
|
24
|
+
import app.notifee.core.utility.ObjectUtils;
|
|
25
|
+
import com.google.common.util.concurrent.ListenableFuture;
|
|
26
|
+
import java.util.List;
|
|
27
|
+
|
|
28
|
+
public class WorkDataRepository {
|
|
29
|
+
private WorkDataDao mWorkDataDao;
|
|
30
|
+
private static WorkDataRepository mInstance;
|
|
31
|
+
|
|
32
|
+
public static @NonNull WorkDataRepository getInstance(@NonNull Context context) {
|
|
33
|
+
synchronized (WorkDataRepository.class) {
|
|
34
|
+
if (mInstance == null) {
|
|
35
|
+
mInstance = new WorkDataRepository(context);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return mInstance;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public WorkDataRepository(Context context) {
|
|
43
|
+
NotifeeCoreDatabase db = NotifeeCoreDatabase.getDatabase(context);
|
|
44
|
+
mWorkDataDao = db.workDao();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public void insert(WorkDataEntity workData) {
|
|
48
|
+
NotifeeCoreDatabase.databaseWriteListeningExecutor.execute(
|
|
49
|
+
() -> {
|
|
50
|
+
mWorkDataDao.insert(workData);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public ListenableFuture<WorkDataEntity> getWorkDataById(String id) {
|
|
55
|
+
return NotifeeCoreDatabase.databaseWriteListeningExecutor.submit(() -> mWorkDataDao.getWorkDataById(id));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public ListenableFuture<List<WorkDataEntity>> getAllWithAlarmManager(Boolean withAlarmManager) {
|
|
59
|
+
return
|
|
60
|
+
NotifeeCoreDatabase.databaseWriteListeningExecutor.submit(
|
|
61
|
+
() -> mWorkDataDao.getAllWithAlarmManager(withAlarmManager));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public ListenableFuture<List<WorkDataEntity>> getAll() {
|
|
65
|
+
return NotifeeCoreDatabase.databaseWriteListeningExecutor.submit( () -> mWorkDataDao.getAll());
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public void deleteById(String id) {
|
|
69
|
+
NotifeeCoreDatabase.databaseWriteListeningExecutor.execute(
|
|
70
|
+
() -> {
|
|
71
|
+
mWorkDataDao.deleteById(id);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public void deleteByIds(List<String> ids) {
|
|
76
|
+
NotifeeCoreDatabase.databaseWriteListeningExecutor.execute(
|
|
77
|
+
() -> {
|
|
78
|
+
mWorkDataDao.deleteByIds(ids);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public void deleteAll() {
|
|
83
|
+
NotifeeCoreDatabase.databaseWriteListeningExecutor.execute(
|
|
84
|
+
() -> {
|
|
85
|
+
mWorkDataDao.deleteAll();
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public static void insertTriggerNotification(
|
|
90
|
+
NotificationModel notificationModel, Bundle triggerBundle, Boolean withAlarmManager) {
|
|
91
|
+
WorkDataEntity workData =
|
|
92
|
+
new WorkDataEntity(
|
|
93
|
+
notificationModel.getId(),
|
|
94
|
+
ObjectUtils.bundleToBytes(notificationModel.toBundle()),
|
|
95
|
+
ObjectUtils.bundleToBytes(triggerBundle),
|
|
96
|
+
withAlarmManager);
|
|
97
|
+
|
|
98
|
+
mInstance.insert(workData);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
public void update(WorkDataEntity workData) {
|
|
102
|
+
NotifeeCoreDatabase.databaseWriteListeningExecutor.execute(
|
|
103
|
+
() -> {
|
|
104
|
+
mWorkDataDao.update(workData);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|