@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
package/android/build.gradle
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import java.nio.file.Paths
|
|
2
|
+
import org.gradle.internal.jvm.Jvm
|
|
3
|
+
|
|
2
4
|
|
|
3
5
|
buildscript {
|
|
4
6
|
// The Android Gradle plugin is only required when opening the android folder stand-alone.
|
|
@@ -20,6 +22,8 @@ plugins {
|
|
|
20
22
|
id "io.invertase.gradle.build" version "1.5"
|
|
21
23
|
}
|
|
22
24
|
|
|
25
|
+
apply plugin: 'com.android.library'
|
|
26
|
+
|
|
23
27
|
// https://github.com/facebook/react-native/blob/a70354df12ef71aec08583cca4f1fed5fb77d874/ReactAndroid/build.gradle#L168-L201
|
|
24
28
|
def findNodeModulePath(baseDir, packageName) {
|
|
25
29
|
def basePath = baseDir.toPath().normalize()
|
|
@@ -35,7 +39,7 @@ def findNodeModulePath(baseDir, packageName) {
|
|
|
35
39
|
return null
|
|
36
40
|
}
|
|
37
41
|
|
|
38
|
-
def notifeeDir = findNodeModulePath(projectDir, "@
|
|
42
|
+
def notifeeDir = findNodeModulePath(projectDir, "@ammarahm-ed/notifee-react-native") ?: "$rootDir/../node_modules/@ammarahm-ed/notifee-react-native"
|
|
39
43
|
println ":${project.name} @notifee/react-native found at $notifeeDir"
|
|
40
44
|
|
|
41
45
|
if (project.hasProperty('reactNativeProjects')) {
|
|
@@ -64,7 +68,15 @@ project.ext {
|
|
|
64
68
|
android {
|
|
65
69
|
defaultConfig {
|
|
66
70
|
multiDexEnabled true
|
|
71
|
+
javaCompileOptions {
|
|
72
|
+
annotationProcessorOptions {
|
|
73
|
+
arguments = ["room.schemaLocation":
|
|
74
|
+
"$projectDir/schemas".toString(),
|
|
75
|
+
eventBusIndex: 'app.notifee.core.EventBusIndex']
|
|
76
|
+
}
|
|
77
|
+
}
|
|
67
78
|
}
|
|
79
|
+
|
|
68
80
|
lintOptions {
|
|
69
81
|
disable 'GradleCompatible'
|
|
70
82
|
abortOnError false
|
|
@@ -88,29 +100,35 @@ repositories {
|
|
|
88
100
|
}
|
|
89
101
|
|
|
90
102
|
dependencies {
|
|
91
|
-
if (findProject(':notifee_core')) {
|
|
92
|
-
implementation findProject(':notifee_core')
|
|
93
|
-
} else {
|
|
94
|
-
implementation(group: 'app.notifee', name:'core', version: '+')
|
|
95
|
-
}
|
|
96
|
-
implementation 'androidx.concurrent:concurrent-futures:1.1.0' // https://developer.android.com/jetpack/androidx/releases/concurrent
|
|
97
|
-
implementation 'com.google.android.gms:play-services-tasks:18.0.1' // https://developers.google.com/android/guides/releases
|
|
98
|
-
implementation 'androidx.work:work-runtime:2.7.1' // https://developer.android.com/jetpack/androidx/releases/work
|
|
99
|
-
implementation 'org.greenrobot:eventbus:3.2.0' // https://github.com/greenrobot/EventBus/releases
|
|
100
|
-
|
|
101
103
|
// needed to enforce version and avoid clashes
|
|
102
104
|
// https://github.com/square/okhttp/blob/master/docs/changelog_3x.md
|
|
103
105
|
implementation 'com.squareup.okhttp3:okhttp:3.12.13' // okhttp must stay on 3.12.x to support minSdkVersion < 21
|
|
106
|
+
|
|
107
|
+
implementation 'androidx.annotation:annotation:1.3.0' // https://developer.android.com/jetpack/androidx/releases/annotation
|
|
108
|
+
implementation "com.squareup.okhttp3:okhttp:3.12.12" // okhttp must stay on 3.12.x to support minSdkVersion < 21
|
|
109
|
+
implementation 'androidx.concurrent:concurrent-futures:1.1.0' // https://developer.android.com/jetpack/androidx/releases/concurrent
|
|
110
|
+
implementation 'androidx.work:work-runtime:2.7.1' // https://developer.android.com/jetpack/androidx/releases/work
|
|
111
|
+
implementation 'com.facebook.fresco:fresco:2.6.0' // https://github.com/facebook/fresco/releases
|
|
112
|
+
|
|
113
|
+
implementation("com.google.guava:guava:31.1-android") // https://github.com/google/guava
|
|
114
|
+
implementation 'androidx.core:core:1.6.0'
|
|
115
|
+
|
|
116
|
+
def room_version = '2.4.3' // https://developer.android.com/jetpack/androidx/releases/room
|
|
117
|
+
implementation "androidx.room:room-runtime:$room_version"
|
|
118
|
+
annotationProcessor "androidx.room:room-compiler:$room_version"
|
|
119
|
+
|
|
120
|
+
def eventbus_version = '3.2.0' // https://github.com/greenrobot/EventBus/releases
|
|
121
|
+
api "org.greenrobot:eventbus:$eventbus_version"
|
|
122
|
+
annotationProcessor "org.greenrobot:eventbus-annotation-processor:$eventbus_version"
|
|
123
|
+
|
|
124
|
+
testImplementation 'junit:junit:4.13.2' // https://github.com/junit-team/junit4/releases
|
|
125
|
+
androidTestImplementation 'androidx.test.ext:junit:1.1.3' // https://developer.android.com/jetpack/androidx/releases/test
|
|
126
|
+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' // see above
|
|
127
|
+
androidTestImplementation "androidx.room:room-testing:$room_version"
|
|
128
|
+
androidTestImplementation "androidx.test:monitor:1.4.0"
|
|
104
129
|
}
|
|
105
130
|
|
|
106
131
|
ReactNative.shared.applyPackageVersion()
|
|
107
132
|
ReactNative.shared.applyDefaultExcludes()
|
|
108
133
|
ReactNative.module.applyAndroidVersions()
|
|
109
134
|
ReactNative.module.applyReactNativeDependency("api")
|
|
110
|
-
rootProject.allprojects {
|
|
111
|
-
repositories {
|
|
112
|
-
maven {
|
|
113
|
-
url "$notifeeDir/android/libs"
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"formatVersion": 1,
|
|
3
|
+
"database": {
|
|
4
|
+
"version": 1,
|
|
5
|
+
"identityHash": "f3fdf2a542ef241fa353c4b3be121211",
|
|
6
|
+
"entities": [
|
|
7
|
+
{
|
|
8
|
+
"tableName": "work_data",
|
|
9
|
+
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `notification` BLOB, `trigger` BLOB, PRIMARY KEY(`id`))",
|
|
10
|
+
"fields": [
|
|
11
|
+
{
|
|
12
|
+
"fieldPath": "id",
|
|
13
|
+
"columnName": "id",
|
|
14
|
+
"affinity": "TEXT",
|
|
15
|
+
"notNull": true
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"fieldPath": "notification",
|
|
19
|
+
"columnName": "notification",
|
|
20
|
+
"affinity": "BLOB",
|
|
21
|
+
"notNull": false
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"fieldPath": "trigger",
|
|
25
|
+
"columnName": "trigger",
|
|
26
|
+
"affinity": "BLOB",
|
|
27
|
+
"notNull": false
|
|
28
|
+
}
|
|
29
|
+
],
|
|
30
|
+
"primaryKey": {
|
|
31
|
+
"columnNames": [
|
|
32
|
+
"id"
|
|
33
|
+
],
|
|
34
|
+
"autoGenerate": false
|
|
35
|
+
},
|
|
36
|
+
"indices": [],
|
|
37
|
+
"foreignKeys": []
|
|
38
|
+
}
|
|
39
|
+
],
|
|
40
|
+
"views": [],
|
|
41
|
+
"setupQueries": [
|
|
42
|
+
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
|
43
|
+
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'f3fdf2a542ef241fa353c4b3be121211')"
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"formatVersion": 1,
|
|
3
|
+
"database": {
|
|
4
|
+
"version": 2,
|
|
5
|
+
"identityHash": "24b2477514809255df232947ce7928c4",
|
|
6
|
+
"entities": [
|
|
7
|
+
{
|
|
8
|
+
"tableName": "work_data",
|
|
9
|
+
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `notification` BLOB, `trigger` BLOB, `with_alarm_manager` INTEGER NOT NULL DEFAULT 0, PRIMARY KEY(`id`))",
|
|
10
|
+
"fields": [
|
|
11
|
+
{
|
|
12
|
+
"fieldPath": "id",
|
|
13
|
+
"columnName": "id",
|
|
14
|
+
"affinity": "TEXT",
|
|
15
|
+
"notNull": true
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"fieldPath": "notification",
|
|
19
|
+
"columnName": "notification",
|
|
20
|
+
"affinity": "BLOB",
|
|
21
|
+
"notNull": false
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"fieldPath": "trigger",
|
|
25
|
+
"columnName": "trigger",
|
|
26
|
+
"affinity": "BLOB",
|
|
27
|
+
"notNull": false
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"fieldPath": "withAlarmManager",
|
|
31
|
+
"columnName": "with_alarm_manager",
|
|
32
|
+
"affinity": "INTEGER",
|
|
33
|
+
"notNull": true,
|
|
34
|
+
"defaultValue": "0"
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
"primaryKey": {
|
|
38
|
+
"columnNames": [
|
|
39
|
+
"id"
|
|
40
|
+
],
|
|
41
|
+
"autoGenerate": false
|
|
42
|
+
},
|
|
43
|
+
"indices": [],
|
|
44
|
+
"foreignKeys": []
|
|
45
|
+
}
|
|
46
|
+
],
|
|
47
|
+
"views": [],
|
|
48
|
+
"setupQueries": [
|
|
49
|
+
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
|
50
|
+
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '24b2477514809255df232947ce7928c4')"
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
package app.notifee.core;
|
|
2
|
+
|
|
3
|
+
import static android.app.AlarmManager.ACTION_SCHEDULE_EXACT_ALARM_PERMISSION_STATE_CHANGED;
|
|
4
|
+
|
|
5
|
+
import android.content.BroadcastReceiver;
|
|
6
|
+
import android.content.Context;
|
|
7
|
+
import android.content.Intent;
|
|
8
|
+
import android.util.Log;
|
|
9
|
+
|
|
10
|
+
public class AlarmPermissionBroadcastReceiver extends BroadcastReceiver {
|
|
11
|
+
@Override
|
|
12
|
+
public void onReceive(Context context, Intent intent) {
|
|
13
|
+
|
|
14
|
+
if (intent.getAction().equals(ACTION_SCHEDULE_EXACT_ALARM_PERMISSION_STATE_CHANGED)) {
|
|
15
|
+
Log.i("AlarmPermissionReceiver", "Received alarm permission state changed event");
|
|
16
|
+
new NotifeeAlarmManager().rescheduleNotifications();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
package app.notifee.core;
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this library except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import android.app.NotificationManager;
|
|
21
|
+
import android.content.BroadcastReceiver;
|
|
22
|
+
import android.content.Context;
|
|
23
|
+
import android.content.Intent;
|
|
24
|
+
import android.os.Build;
|
|
25
|
+
import android.os.Bundle;
|
|
26
|
+
import androidx.annotation.Keep;
|
|
27
|
+
import androidx.concurrent.futures.CallbackToFutureAdapter;
|
|
28
|
+
import androidx.work.Data;
|
|
29
|
+
import androidx.work.ExistingWorkPolicy;
|
|
30
|
+
import androidx.work.ListenableWorker.Result;
|
|
31
|
+
import androidx.work.OneTimeWorkRequest;
|
|
32
|
+
import androidx.work.WorkManager;
|
|
33
|
+
import app.notifee.core.event.BlockStateEvent;
|
|
34
|
+
import app.notifee.core.interfaces.MethodCallResult;
|
|
35
|
+
import app.notifee.core.utility.ObjectUtils;
|
|
36
|
+
import java.util.concurrent.TimeUnit;
|
|
37
|
+
|
|
38
|
+
public class BlockStateBroadcastReceiver extends BroadcastReceiver {
|
|
39
|
+
private static final String TAG = "BlockState";
|
|
40
|
+
private static final String KEY_TYPE = "type";
|
|
41
|
+
private static final String KEY_BLOCKED = "blocked";
|
|
42
|
+
private static final String KEY_CHANNEL_GROUP = "channelOrGroupId";
|
|
43
|
+
|
|
44
|
+
@Keep
|
|
45
|
+
public BlockStateBroadcastReceiver() {}
|
|
46
|
+
|
|
47
|
+
static void doWork(Data workData, CallbackToFutureAdapter.Completer<Result> completer) {
|
|
48
|
+
Logger.v(TAG, "starting background work");
|
|
49
|
+
|
|
50
|
+
final boolean blocked = workData.getBoolean(KEY_BLOCKED, false);
|
|
51
|
+
final int type = workData.getInt(KEY_TYPE, BlockStateEvent.TYPE_APP_BLOCKED);
|
|
52
|
+
final ObjectUtils.TypedCallback<Bundle> sendEventCallback =
|
|
53
|
+
bundle -> {
|
|
54
|
+
final MethodCallResult<Void> methodCallResult =
|
|
55
|
+
(e, aVoid) -> {
|
|
56
|
+
if (e != null) {
|
|
57
|
+
Logger.e(TAG, "background work failed with error: ", e);
|
|
58
|
+
completer.set(Result.failure());
|
|
59
|
+
} else {
|
|
60
|
+
Logger.v(TAG, "background work completed successfully");
|
|
61
|
+
completer.set(Result.success());
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
BlockStateEvent blockStateEvent =
|
|
66
|
+
new BlockStateEvent(type, bundle, blocked, methodCallResult);
|
|
67
|
+
|
|
68
|
+
EventBus.post(blockStateEvent);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
if (type == BlockStateEvent.TYPE_APP_BLOCKED) {
|
|
72
|
+
sendEventCallback.call(null);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
MethodCallResult<Bundle> methodCallResult =
|
|
77
|
+
(e, aBundle) -> {
|
|
78
|
+
if (e != null) {
|
|
79
|
+
Logger.e(TAG, "Failed getting channel or channel group bundle, received error: ", e);
|
|
80
|
+
completer.set(Result.success());
|
|
81
|
+
} else {
|
|
82
|
+
sendEventCallback.call(aBundle);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
String channelOrGroupId = workData.getString(KEY_CHANNEL_GROUP);
|
|
87
|
+
if (type == BlockStateEvent.TYPE_CHANNEL_BLOCKED) {
|
|
88
|
+
Notifee.getInstance().getChannel(channelOrGroupId, methodCallResult);
|
|
89
|
+
} else if (type == BlockStateEvent.TYPE_CHANNEL_GROUP_BLOCKED) {
|
|
90
|
+
Notifee.getInstance().getChannelGroup(channelOrGroupId, methodCallResult);
|
|
91
|
+
} else {
|
|
92
|
+
Logger.e(TAG, "unknown block state work type");
|
|
93
|
+
completer.set(Result.success());
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@Override
|
|
98
|
+
public void onReceive(Context context, Intent intent) {
|
|
99
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
String action = intent.getAction();
|
|
104
|
+
if (action == null) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// To prevent a race condition
|
|
109
|
+
// See https://github.com/notifee/react-native-notifee/issues/237
|
|
110
|
+
if (ContextHolder.getApplicationContext() == null) {
|
|
111
|
+
ContextHolder.setApplicationContext(context.getApplicationContext());
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
String uniqueWorkId = action;
|
|
115
|
+
Data.Builder workDataBuilder = new Data.Builder();
|
|
116
|
+
workDataBuilder.putString(Worker.KEY_WORK_TYPE, Worker.WORK_TYPE_BLOCK_STATE_RECEIVER);
|
|
117
|
+
|
|
118
|
+
switch (action) {
|
|
119
|
+
case NotificationManager.ACTION_APP_BLOCK_STATE_CHANGED:
|
|
120
|
+
workDataBuilder.putInt(KEY_TYPE, BlockStateEvent.TYPE_APP_BLOCKED);
|
|
121
|
+
break;
|
|
122
|
+
case NotificationManager.ACTION_NOTIFICATION_CHANNEL_BLOCK_STATE_CHANGED:
|
|
123
|
+
workDataBuilder.putInt(KEY_TYPE, BlockStateEvent.TYPE_CHANNEL_BLOCKED);
|
|
124
|
+
String channelId = intent.getStringExtra(NotificationManager.EXTRA_NOTIFICATION_CHANNEL_ID);
|
|
125
|
+
workDataBuilder.putString(KEY_CHANNEL_GROUP, channelId);
|
|
126
|
+
uniqueWorkId += "." + channelId;
|
|
127
|
+
break;
|
|
128
|
+
case NotificationManager.ACTION_NOTIFICATION_CHANNEL_GROUP_BLOCK_STATE_CHANGED:
|
|
129
|
+
workDataBuilder.putInt(KEY_TYPE, BlockStateEvent.TYPE_CHANNEL_GROUP_BLOCKED);
|
|
130
|
+
String channelGroupId =
|
|
131
|
+
intent.getStringExtra(NotificationManager.EXTRA_NOTIFICATION_CHANNEL_GROUP_ID);
|
|
132
|
+
workDataBuilder.putString(KEY_CHANNEL_GROUP, channelGroupId);
|
|
133
|
+
uniqueWorkId += "." + channelGroupId;
|
|
134
|
+
break;
|
|
135
|
+
default:
|
|
136
|
+
Logger.d(TAG, "unknown intent action received, ignoring.");
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
workDataBuilder.putBoolean(
|
|
141
|
+
KEY_BLOCKED, intent.getBooleanExtra(NotificationManager.EXTRA_BLOCKED_STATE, false));
|
|
142
|
+
|
|
143
|
+
// a second delay to debounce events coming from a user spam toggling block states
|
|
144
|
+
OneTimeWorkRequest.Builder builder =
|
|
145
|
+
new OneTimeWorkRequest.Builder(Worker.class)
|
|
146
|
+
.setInitialDelay(1, TimeUnit.SECONDS)
|
|
147
|
+
.setInputData(workDataBuilder.build());
|
|
148
|
+
|
|
149
|
+
// On-going issue with WorkManager.getInstance(context)
|
|
150
|
+
// https://issuetracker.google.com/issues/135858602
|
|
151
|
+
try {
|
|
152
|
+
WorkManager.getInstance(ContextHolder.getApplicationContext())
|
|
153
|
+
.enqueueUniqueWork(uniqueWorkId, ExistingWorkPolicy.REPLACE, builder.build());
|
|
154
|
+
} catch (IllegalStateException e) {
|
|
155
|
+
Logger.e(TAG, "Error while calling WorkManager.getInstance", e);
|
|
156
|
+
|
|
157
|
+
if (ContextHolder.getApplicationContext() == null) {
|
|
158
|
+
Logger.e(TAG, "Application Context is null");
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
Logger.v(TAG, "scheduled new background work with id " + uniqueWorkId);
|
|
163
|
+
}
|
|
164
|
+
}
|