react-native-notify-kit 9.1.21 → 9.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -2
- package/RNNotifee.podspec +1 -0
- package/android/build.gradle +67 -35
- package/android/proguard-rules.pro +14 -1
- package/android/schemas/app.notifee.core.database.NotifeeCoreDatabase/1.json +44 -0
- package/android/schemas/app.notifee.core.database.NotifeeCoreDatabase/2.json +51 -0
- package/android/src/androidTest/java/app/notifee/core/ExampleInstrumentedTest.java +25 -0
- package/android/src/androidTest/java/app/notifee/core/database/NotifeeCoreDatabaseTest.java +55 -0
- package/android/src/main/AndroidManifest.xml +71 -4
- package/android/src/main/java/app/notifee/core/AlarmPermissionBroadcastReceiver.java +25 -0
- package/android/src/main/java/app/notifee/core/BlockStateBroadcastReceiver.java +164 -0
- package/android/src/main/java/app/notifee/core/ChannelManager.java +350 -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 +347 -0
- package/android/src/main/java/app/notifee/core/InitProvider.java +93 -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 +570 -0
- package/android/src/main/java/app/notifee/core/NotifeeAlarmManager.java +352 -0
- package/android/src/main/java/app/notifee/core/NotificationAlarmReceiver.java +42 -0
- package/android/src/main/java/app/notifee/core/NotificationManager.java +939 -0
- package/android/src/main/java/app/notifee/core/NotificationPendingIntent.java +191 -0
- package/android/src/main/java/app/notifee/core/NotificationReceiverActivity.java +39 -0
- package/android/src/main/java/app/notifee/core/NotificationReceiverHandler.java +144 -0
- package/android/src/main/java/app/notifee/core/Preferences.java +79 -0
- package/android/src/main/java/app/notifee/core/RebootBroadcastReceiver.java +39 -0
- package/android/src/main/java/app/notifee/core/ReceiverService.java +281 -0
- package/android/src/main/java/app/notifee/core/Worker.java +87 -0
- package/android/src/main/java/app/notifee/core/database/NotifeeCoreDatabase.java +77 -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 +107 -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 +126 -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 +688 -0
- package/android/src/main/java/app/notifee/core/model/NotificationAndroidPressActionModel.java +150 -0
- package/android/src/main/java/app/notifee/core/model/NotificationAndroidStyleModel.java +336 -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 +206 -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 +146 -0
- package/android/src/main/java/app/notifee/core/utility/ObjectUtils.java +191 -0
- package/android/src/main/java/app/notifee/core/utility/PowerManagerUtils.java +338 -0
- package/android/src/main/java/app/notifee/core/utility/ResourceUtils.java +308 -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/android/src/test/java/app/notifee/core/model/NotificationAndroidPressActionModelTest.java +56 -0
- package/android/src/test/java/app/notifee/core/model/TimestampTriggerModelTest.java +44 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +2 -2
- package/src/version.ts +1 -1
- package/android/libs/app/notifee/core/202108261754/core-202108261754.aar +0 -0
- package/android/libs/app/notifee/core/202108261754/core-202108261754.aar.md5 +0 -1
- package/android/libs/app/notifee/core/202108261754/core-202108261754.aar.sha1 +0 -1
- package/android/libs/app/notifee/core/202108261754/core-202108261754.aar.sha256 +0 -1
- package/android/libs/app/notifee/core/202108261754/core-202108261754.aar.sha512 +0 -1
- package/android/libs/app/notifee/core/202108261754/core-202108261754.module +0 -146
- package/android/libs/app/notifee/core/202108261754/core-202108261754.module.md5 +0 -1
- package/android/libs/app/notifee/core/202108261754/core-202108261754.module.sha1 +0 -1
- package/android/libs/app/notifee/core/202108261754/core-202108261754.module.sha256 +0 -1
- package/android/libs/app/notifee/core/202108261754/core-202108261754.module.sha512 +0 -1
- package/android/libs/app/notifee/core/202108261754/core-202108261754.pom +0 -64
- package/android/libs/app/notifee/core/202108261754/core-202108261754.pom.md5 +0 -1
- package/android/libs/app/notifee/core/202108261754/core-202108261754.pom.sha1 +0 -1
- package/android/libs/app/notifee/core/202108261754/core-202108261754.pom.sha256 +0 -1
- package/android/libs/app/notifee/core/202108261754/core-202108261754.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,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
|
+
}
|
|
@@ -0,0 +1,350 @@
|
|
|
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 androidx.core.app.NotificationManagerCompat.IMPORTANCE_NONE;
|
|
21
|
+
|
|
22
|
+
import android.app.NotificationChannel;
|
|
23
|
+
import android.app.NotificationChannelGroup;
|
|
24
|
+
import android.media.AudioAttributes;
|
|
25
|
+
import android.net.Uri;
|
|
26
|
+
import android.os.Build;
|
|
27
|
+
import android.os.Bundle;
|
|
28
|
+
import androidx.annotation.NonNull;
|
|
29
|
+
import androidx.core.app.NotificationManagerCompat;
|
|
30
|
+
import app.notifee.core.model.ChannelGroupModel;
|
|
31
|
+
import app.notifee.core.model.ChannelModel;
|
|
32
|
+
import app.notifee.core.utility.ColorUtils;
|
|
33
|
+
import app.notifee.core.utility.ResourceUtils;
|
|
34
|
+
import com.google.common.util.concurrent.ListenableFuture;
|
|
35
|
+
import java.util.ArrayList;
|
|
36
|
+
import java.util.Collections;
|
|
37
|
+
import java.util.List;
|
|
38
|
+
|
|
39
|
+
public class ChannelManager {
|
|
40
|
+
|
|
41
|
+
private static String TAG = "ChannelManager";
|
|
42
|
+
|
|
43
|
+
static ListenableFuture<Void> createChannel(ChannelModel channelModel) {
|
|
44
|
+
return Notifee.getListeningExecutorService()
|
|
45
|
+
.submit(
|
|
46
|
+
() -> {
|
|
47
|
+
if (Build.VERSION.SDK_INT < 26) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
NotificationChannel channel =
|
|
52
|
+
new NotificationChannel(
|
|
53
|
+
channelModel.getId(), channelModel.getName(), channelModel.getImportance());
|
|
54
|
+
|
|
55
|
+
channel.setShowBadge(channelModel.getBadge());
|
|
56
|
+
channel.setBypassDnd(channelModel.getBypassDnd());
|
|
57
|
+
channel.setDescription(channelModel.getDescription());
|
|
58
|
+
channel.setGroup(channelModel.getGroupId());
|
|
59
|
+
channel.enableLights(channelModel.getLights());
|
|
60
|
+
|
|
61
|
+
if (channelModel.getLightColor() != null) {
|
|
62
|
+
channel.setLightColor(channelModel.getLightColor());
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
channel.setLockscreenVisibility(channelModel.getVisibility());
|
|
66
|
+
channel.enableVibration(channelModel.getVibration());
|
|
67
|
+
|
|
68
|
+
long[] vibrationPattern = channelModel.getVibrationPattern();
|
|
69
|
+
if (vibrationPattern.length > 0) {
|
|
70
|
+
channel.setVibrationPattern(vibrationPattern);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (channelModel.getSound() != null) {
|
|
74
|
+
Uri soundUri = ResourceUtils.getSoundUri(channelModel.getSound());
|
|
75
|
+
if (soundUri != null) {
|
|
76
|
+
AudioAttributes audioAttributes =
|
|
77
|
+
new AudioAttributes.Builder()
|
|
78
|
+
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
|
|
79
|
+
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
|
|
80
|
+
.build();
|
|
81
|
+
channel.setSound(soundUri, audioAttributes);
|
|
82
|
+
} else {
|
|
83
|
+
Logger.w(
|
|
84
|
+
TAG,
|
|
85
|
+
"Unable to retrieve sound for channel, sound was specified as: "
|
|
86
|
+
+ channel.getSound());
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
channel.setSound(null, null);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
NotificationManagerCompat.from(ContextHolder.getApplicationContext())
|
|
93
|
+
.createNotificationChannel(channel);
|
|
94
|
+
|
|
95
|
+
return null;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
static ListenableFuture<Void> createChannels(List<ChannelModel> channelModels) {
|
|
100
|
+
return Notifee.getListeningExecutorService()
|
|
101
|
+
.submit(
|
|
102
|
+
() -> {
|
|
103
|
+
for (ChannelModel channelModel : channelModels) {
|
|
104
|
+
createChannel(channelModel).get();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return null;
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
static ListenableFuture<Void> createChannelGroup(ChannelGroupModel channelGroupModel) {
|
|
112
|
+
return Notifee.getListeningExecutorService()
|
|
113
|
+
.submit(
|
|
114
|
+
() -> {
|
|
115
|
+
if (Build.VERSION.SDK_INT < 26) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
NotificationChannelGroup notificationChannelGroup =
|
|
120
|
+
new NotificationChannelGroup(
|
|
121
|
+
channelGroupModel.getId(), channelGroupModel.getName());
|
|
122
|
+
|
|
123
|
+
if (Build.VERSION.SDK_INT >= 28 && channelGroupModel.getDescription() != null) {
|
|
124
|
+
notificationChannelGroup.setDescription(channelGroupModel.getDescription());
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
NotificationManagerCompat.from(ContextHolder.getApplicationContext())
|
|
128
|
+
.createNotificationChannelGroup(notificationChannelGroup);
|
|
129
|
+
|
|
130
|
+
return null;
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
static ListenableFuture<Void> createChannelGroups(List<ChannelGroupModel> channelGroupModels) {
|
|
135
|
+
return Notifee.getListeningExecutorService()
|
|
136
|
+
.submit(
|
|
137
|
+
() -> {
|
|
138
|
+
if (Build.VERSION.SDK_INT < 26) {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
for (ChannelGroupModel channelGroupModel : channelGroupModels) {
|
|
143
|
+
createChannelGroup(channelGroupModel).get();
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return null;
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
static void deleteChannel(@NonNull String channelId) {
|
|
151
|
+
NotificationManagerCompat.from(ContextHolder.getApplicationContext())
|
|
152
|
+
.deleteNotificationChannel(channelId);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
static void deleteChannelGroup(@NonNull String channelGroupId) {
|
|
156
|
+
NotificationManagerCompat.from(ContextHolder.getApplicationContext())
|
|
157
|
+
.deleteNotificationChannelGroup(channelGroupId);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
static ListenableFuture<List<Bundle>> getChannels() {
|
|
161
|
+
return Notifee.getListeningExecutorService()
|
|
162
|
+
.submit(
|
|
163
|
+
() -> {
|
|
164
|
+
List<NotificationChannel> channels =
|
|
165
|
+
NotificationManagerCompat.from(ContextHolder.getApplicationContext())
|
|
166
|
+
.getNotificationChannels();
|
|
167
|
+
|
|
168
|
+
if (channels.size() == 0 || Build.VERSION.SDK_INT < 26) {
|
|
169
|
+
return Collections.emptyList();
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
ArrayList<Bundle> channelBundles = new ArrayList<>(channels.size());
|
|
173
|
+
for (NotificationChannel channel : channels) {
|
|
174
|
+
channelBundles.add(convertChannelToBundle(channel));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return channelBundles;
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
static ListenableFuture<Bundle> getChannel(String channelId) {
|
|
182
|
+
return Notifee.getListeningExecutorService()
|
|
183
|
+
.submit(
|
|
184
|
+
() -> {
|
|
185
|
+
NotificationChannel channel =
|
|
186
|
+
NotificationManagerCompat.from(ContextHolder.getApplicationContext())
|
|
187
|
+
.getNotificationChannel(channelId);
|
|
188
|
+
|
|
189
|
+
return convertChannelToBundle(channel);
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
static ListenableFuture<Boolean> isChannelBlocked(String channelId) {
|
|
194
|
+
return Notifee.getListeningExecutorService()
|
|
195
|
+
.submit(
|
|
196
|
+
() -> {
|
|
197
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return false;
|
|
198
|
+
|
|
199
|
+
NotificationChannel channel =
|
|
200
|
+
NotificationManagerCompat.from(ContextHolder.getApplicationContext())
|
|
201
|
+
.getNotificationChannel(channelId);
|
|
202
|
+
|
|
203
|
+
if (channel == null) {
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return IMPORTANCE_NONE == channel.getImportance();
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
static ListenableFuture<Boolean> isChannelCreated(String channelId) {
|
|
212
|
+
return Notifee.getListeningExecutorService()
|
|
213
|
+
.submit(
|
|
214
|
+
() -> {
|
|
215
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return false;
|
|
216
|
+
|
|
217
|
+
NotificationChannel channel =
|
|
218
|
+
NotificationManagerCompat.from(ContextHolder.getApplicationContext())
|
|
219
|
+
.getNotificationChannel(channelId);
|
|
220
|
+
|
|
221
|
+
return channel != null;
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
static ListenableFuture<List<Bundle>> getChannelGroups() {
|
|
226
|
+
return Notifee.getListeningExecutorService()
|
|
227
|
+
.submit(
|
|
228
|
+
() -> {
|
|
229
|
+
List<NotificationChannelGroup> channelGroups =
|
|
230
|
+
NotificationManagerCompat.from(ContextHolder.getApplicationContext())
|
|
231
|
+
.getNotificationChannelGroups();
|
|
232
|
+
|
|
233
|
+
if (channelGroups.size() == 0 || Build.VERSION.SDK_INT < 26) {
|
|
234
|
+
return Collections.emptyList();
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
ArrayList<Bundle> channelGroupBundles = new ArrayList<>(channelGroups.size());
|
|
238
|
+
for (NotificationChannelGroup channelGroup : channelGroups) {
|
|
239
|
+
channelGroupBundles.add(convertChannelGroupToBundle(channelGroup));
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return channelGroupBundles;
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
static ListenableFuture<Bundle> getChannelGroup(String channelGroupId) {
|
|
247
|
+
return Notifee.getListeningExecutorService()
|
|
248
|
+
.submit(
|
|
249
|
+
() -> {
|
|
250
|
+
NotificationChannelGroup channelGroup =
|
|
251
|
+
NotificationManagerCompat.from(ContextHolder.getApplicationContext())
|
|
252
|
+
.getNotificationChannelGroup(channelGroupId);
|
|
253
|
+
|
|
254
|
+
return convertChannelGroupToBundle(channelGroup);
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
private static Bundle convertChannelToBundle(NotificationChannel channel) {
|
|
259
|
+
if (channel == null || Build.VERSION.SDK_INT < 26) {
|
|
260
|
+
return null;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
Bundle channelBundle = new Bundle();
|
|
264
|
+
channelBundle.putString("id", channel.getId());
|
|
265
|
+
channelBundle.putString("name", channel.getName().toString());
|
|
266
|
+
channelBundle.putBoolean("badge", channel.canShowBadge());
|
|
267
|
+
channelBundle.putBoolean("bypassDnd", channel.canBypassDnd());
|
|
268
|
+
|
|
269
|
+
// can be null, don't include if null
|
|
270
|
+
if (channel.getDescription() != null) {
|
|
271
|
+
channelBundle.putString("description", channel.getDescription());
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// can be null, don't include if null
|
|
275
|
+
if (channel.getGroup() != null) {
|
|
276
|
+
channelBundle.putString("groupId", channel.getGroup());
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
channelBundle.putInt("importance", channel.getImportance());
|
|
280
|
+
channelBundle.putBoolean("lights", channel.shouldShowLights());
|
|
281
|
+
channelBundle.putBoolean("vibration", channel.shouldVibrate());
|
|
282
|
+
channelBundle.putBoolean("blocked", channel.getImportance() == IMPORTANCE_NONE);
|
|
283
|
+
|
|
284
|
+
// can be null, don't include if null
|
|
285
|
+
if (channel.getSound() != null) {
|
|
286
|
+
channelBundle.putString("soundURI", channel.getSound().toString());
|
|
287
|
+
// try to parse uri
|
|
288
|
+
String soundValue = ResourceUtils.getSoundName(channel.getSound());
|
|
289
|
+
if (soundValue != null) channelBundle.putString("sound", soundValue);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// optional, can be 0
|
|
293
|
+
if (channel.getLightColor() != 0) {
|
|
294
|
+
channelBundle.putString("lightColor", ColorUtils.getColorString(channel.getLightColor()));
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// getVibrationPattern can be null
|
|
298
|
+
long[] vibrationPattern = channel.getVibrationPattern();
|
|
299
|
+
|
|
300
|
+
if (vibrationPattern != null && vibrationPattern.length > 0) {
|
|
301
|
+
try {
|
|
302
|
+
int[] convertedVibrationPattern = new int[vibrationPattern.length];
|
|
303
|
+
// cast to int array
|
|
304
|
+
for (int i = 0; i < vibrationPattern.length; i++) {
|
|
305
|
+
convertedVibrationPattern[i] = (int) vibrationPattern[i];
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
channelBundle.putIntArray("vibrationPattern", convertedVibrationPattern);
|
|
309
|
+
} catch (Exception e) {
|
|
310
|
+
Logger.e(TAG, "Unable to convert Vibration Pattern to Channel Bundle", e);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// Unless the user manually changes this in app settings, it is always -1000.
|
|
315
|
+
int visibility = channel.getLockscreenVisibility();
|
|
316
|
+
if (visibility != -1000) { // -1000 = not set
|
|
317
|
+
channelBundle.putInt("visibility", visibility);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
return channelBundle;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
private static Bundle convertChannelGroupToBundle(NotificationChannelGroup channelGroup) {
|
|
324
|
+
if (channelGroup == null || Build.VERSION.SDK_INT < 26) {
|
|
325
|
+
return null;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
Bundle channelGroupBundle = new Bundle();
|
|
329
|
+
channelGroupBundle.putString("id", channelGroup.getId());
|
|
330
|
+
channelGroupBundle.putString("name", channelGroup.getName().toString());
|
|
331
|
+
|
|
332
|
+
List<NotificationChannel> notificationChannels = channelGroup.getChannels();
|
|
333
|
+
ArrayList<Bundle> channels = new ArrayList<>(notificationChannels.size());
|
|
334
|
+
|
|
335
|
+
for (NotificationChannel notificationChannel : notificationChannels) {
|
|
336
|
+
channels.add(convertChannelToBundle(notificationChannel));
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
channelGroupBundle.putParcelableArrayList("channels", channels);
|
|
340
|
+
|
|
341
|
+
if (Build.VERSION.SDK_INT >= 28) {
|
|
342
|
+
channelGroupBundle.putBoolean("blocked", channelGroup.isBlocked());
|
|
343
|
+
channelGroupBundle.putString("description", channelGroup.getDescription());
|
|
344
|
+
} else {
|
|
345
|
+
channelGroupBundle.putBoolean("blocked", false);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
return channelGroupBundle;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
|
|
22
|
+
public class ContextHolder {
|
|
23
|
+
private static Context applicationContext;
|
|
24
|
+
|
|
25
|
+
public static Context getApplicationContext() {
|
|
26
|
+
return applicationContext;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public static void setApplicationContext(Context applicationContext) {
|
|
30
|
+
Logger.d("context", "received application context");
|
|
31
|
+
ContextHolder.applicationContext = applicationContext;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
public class EventBus {
|
|
21
|
+
private static final EventBus instance = new EventBus();
|
|
22
|
+
private org.greenrobot.eventbus.EventBus eventBus;
|
|
23
|
+
|
|
24
|
+
private EventBus() {
|
|
25
|
+
eventBus = org.greenrobot.eventbus.EventBus.builder().build();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public static EventBus getInstance() {
|
|
29
|
+
return instance;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public static void register(Object subscriber) {
|
|
33
|
+
getInstance().getDefault().register(subscriber);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public static void unregister(Object subscriber) {
|
|
37
|
+
getInstance().getDefault().unregister(subscriber);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public static <T> T getStickyEvent(Class<T> eventType) {
|
|
41
|
+
return getInstance().getDefault().getStickyEvent(eventType);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public static <T> T removeStickEvent(Class<T> eventType) {
|
|
45
|
+
return getInstance().getDefault().removeStickyEvent(eventType);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public static void post(Object event) {
|
|
49
|
+
getInstance().getDefault().post(event);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
static void postSticky(Object event) {
|
|
53
|
+
getInstance().getDefault().postSticky(event);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static <T> T removeStickyEvent(Class<T> eventType) {
|
|
57
|
+
return getInstance().getDefault().removeStickyEvent(eventType);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private org.greenrobot.eventbus.EventBus getDefault() {
|
|
61
|
+
return eventBus;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
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 app.notifee.core.event.BlockStateEvent;
|
|
22
|
+
import app.notifee.core.event.ForegroundServiceEvent;
|
|
23
|
+
import app.notifee.core.event.LogEvent;
|
|
24
|
+
import app.notifee.core.event.NotificationEvent;
|
|
25
|
+
import app.notifee.core.interfaces.EventListener;
|
|
26
|
+
import java.util.HashSet;
|
|
27
|
+
import java.util.Set;
|
|
28
|
+
import org.greenrobot.eventbus.Subscribe;
|
|
29
|
+
import org.greenrobot.eventbus.ThreadMode;
|
|
30
|
+
|
|
31
|
+
@KeepForSdk
|
|
32
|
+
public class EventSubscriber {
|
|
33
|
+
private static final EventSubscriber mInstance = new EventSubscriber();
|
|
34
|
+
private final Set<EventListener> mListeners = new HashSet<>();
|
|
35
|
+
|
|
36
|
+
private EventSubscriber() {
|
|
37
|
+
EventBus.register(this);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@KeepForSdk
|
|
41
|
+
public static void register(EventListener listener) {
|
|
42
|
+
mInstance.mListeners.add(listener);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@KeepForSdk
|
|
46
|
+
public static void unregister(EventListener listener) {
|
|
47
|
+
mInstance.mListeners.remove(listener);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@KeepForSdk
|
|
51
|
+
public static Context getContext() {
|
|
52
|
+
return ContextHolder.getApplicationContext();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
56
|
+
public void onNotificationEvent(NotificationEvent notificationEvent) {
|
|
57
|
+
for (EventListener eventListener : mListeners) {
|
|
58
|
+
eventListener.onNotificationEvent(notificationEvent);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
63
|
+
public void onLogEvent(LogEvent logEvent) {
|
|
64
|
+
for (EventListener eventListener : mListeners) {
|
|
65
|
+
eventListener.onLogEvent(logEvent);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
70
|
+
public void onBlockStateEvent(BlockStateEvent blockStateEvent) {
|
|
71
|
+
for (EventListener eventListener : mListeners) {
|
|
72
|
+
eventListener.onBlockStateEvent(blockStateEvent);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
77
|
+
public void onForegroundServiceEvent(ForegroundServiceEvent foregroundServiceEvent) {
|
|
78
|
+
for (EventListener eventListener : mListeners) {
|
|
79
|
+
eventListener.onForegroundServiceEvent(foregroundServiceEvent);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|