@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,334 @@
|
|
|
1
|
+
package app.notifee.core.utility;
|
|
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.Activity;
|
|
21
|
+
import android.content.ComponentName;
|
|
22
|
+
import android.content.Context;
|
|
23
|
+
import android.content.Intent;
|
|
24
|
+
import android.net.Uri;
|
|
25
|
+
import android.os.Build;
|
|
26
|
+
import android.os.Bundle;
|
|
27
|
+
import android.os.PowerManager;
|
|
28
|
+
import android.provider.Settings;
|
|
29
|
+
import app.notifee.core.ContextHolder;
|
|
30
|
+
import app.notifee.core.Logger;
|
|
31
|
+
import java.util.ArrayList;
|
|
32
|
+
import java.util.Arrays;
|
|
33
|
+
import java.util.List;
|
|
34
|
+
import java.util.Locale;
|
|
35
|
+
|
|
36
|
+
public class PowerManagerUtils {
|
|
37
|
+
private static final String TAG = "PowerManagerUtils";
|
|
38
|
+
private static volatile Intent sPowerManagerIntentCache;
|
|
39
|
+
|
|
40
|
+
public static void setPowerManagerIntentCache(Intent intent) {
|
|
41
|
+
synchronized (PowerManagerUtils.class) {
|
|
42
|
+
sPowerManagerIntentCache = intent;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public static Intent getPowerManagerIntent() {
|
|
47
|
+
synchronized (PowerManagerUtils.class) {
|
|
48
|
+
return sPowerManagerIntentCache;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Attempts to open the device's battery optimization settings
|
|
54
|
+
*
|
|
55
|
+
* @param activity
|
|
56
|
+
*/
|
|
57
|
+
public static void openBatteryOptimizationSettings(Activity activity) {
|
|
58
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
Intent intent = new Intent();
|
|
64
|
+
intent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
|
|
65
|
+
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
66
|
+
|
|
67
|
+
if (activity != null) {
|
|
68
|
+
Boolean isAvailableOnDevice =
|
|
69
|
+
IntentUtils.isAvailableOnDevice(ContextHolder.getApplicationContext(), intent);
|
|
70
|
+
|
|
71
|
+
if (!isAvailableOnDevice) {
|
|
72
|
+
Logger.d(TAG, "battery optimization settings is not available on device");
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
IntentUtils.startActivityOnUiThread(activity, intent);
|
|
77
|
+
}
|
|
78
|
+
} catch (Exception e) {
|
|
79
|
+
Logger.e(TAG, "An error occurred whilst trying to open battery optimization settings", e);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Returns true if the app has battery optimization enabled
|
|
85
|
+
*
|
|
86
|
+
* @param context
|
|
87
|
+
*/
|
|
88
|
+
public static Boolean isBatteryOptimizationEnabled(Context context) {
|
|
89
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
|
93
|
+
return !pm.isIgnoringBatteryOptimizations(context.getPackageName());
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Lights up the screen if it is not already lit
|
|
98
|
+
*
|
|
99
|
+
* @param context
|
|
100
|
+
*/
|
|
101
|
+
public static void lightUpScreenIfNeeded(Context context) {
|
|
102
|
+
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
|
103
|
+
Boolean isInteractive = pm.isInteractive();
|
|
104
|
+
|
|
105
|
+
if (isInteractive == false) {
|
|
106
|
+
PowerManager.WakeLock wl =
|
|
107
|
+
pm.newWakeLock(
|
|
108
|
+
PowerManager.FULL_WAKE_LOCK
|
|
109
|
+
| PowerManager.ACQUIRE_CAUSES_WAKEUP
|
|
110
|
+
| PowerManager.ON_AFTER_RELEASE,
|
|
111
|
+
"Notifee:lock");
|
|
112
|
+
wl.acquire();
|
|
113
|
+
|
|
114
|
+
PowerManager.WakeLock wl_cpu =
|
|
115
|
+
pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Notifee:cpuLock");
|
|
116
|
+
wl_cpu.acquire();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Retrieves information about the device and its Power Manager Settings
|
|
122
|
+
*
|
|
123
|
+
* @return PowerManagerInfo
|
|
124
|
+
*/
|
|
125
|
+
public static PowerManagerInfo getPowerManagerInfo() {
|
|
126
|
+
String activityName;
|
|
127
|
+
|
|
128
|
+
Intent intent = findPowerManagerIntent(ContextHolder.getApplicationContext());
|
|
129
|
+
activityName = IntentUtils.getActivityName(intent);
|
|
130
|
+
|
|
131
|
+
PowerManagerInfo result =
|
|
132
|
+
new PowerManagerInfo(Build.MANUFACTURER, Build.MODEL, Build.VERSION.RELEASE, activityName);
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Attempts to open the device's Power Manager settings
|
|
138
|
+
*
|
|
139
|
+
* @param activity
|
|
140
|
+
*/
|
|
141
|
+
public static void openPowerManagerSettings(Activity activity) {
|
|
142
|
+
Intent intent = getPowerManagerIntent();
|
|
143
|
+
if (intent == null) {
|
|
144
|
+
intent = findPowerManagerIntent(ContextHolder.getApplicationContext());
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (intent != null) {
|
|
148
|
+
try {
|
|
149
|
+
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
150
|
+
IntentUtils.startActivityOnUiThread(activity, intent);
|
|
151
|
+
} catch (Exception exception) {
|
|
152
|
+
Logger.e(
|
|
153
|
+
TAG, "Unable to start activity: " + IntentUtils.getActivityName(intent), exception);
|
|
154
|
+
}
|
|
155
|
+
} else {
|
|
156
|
+
Logger.w(TAG, "Unable to find an activity to open the device's power manager");
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private static Intent findPowerManagerIntent(Context context) {
|
|
161
|
+
String manufacturerName = Build.BRAND.toLowerCase(Locale.US);
|
|
162
|
+
List<Intent> possibleIntents = getManufacturerPowerManagerIntents(manufacturerName);
|
|
163
|
+
|
|
164
|
+
for (int i = 0; i < possibleIntents.size(); i++) {
|
|
165
|
+
Intent possibleIntent = possibleIntents.get(i);
|
|
166
|
+
Boolean isAvailableOnDevice = IntentUtils.isAvailableOnDevice(context, possibleIntent);
|
|
167
|
+
if (isAvailableOnDevice) {
|
|
168
|
+
setPowerManagerIntentCache(possibleIntent);
|
|
169
|
+
return possibleIntent;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
private static List<Intent> getManufacturerPowerManagerIntents(String manufacturerName) {
|
|
176
|
+
List<Intent> possibleIntents = new ArrayList<>();
|
|
177
|
+
switch (manufacturerName) {
|
|
178
|
+
case "asus":
|
|
179
|
+
possibleIntents =
|
|
180
|
+
Arrays.asList(
|
|
181
|
+
createIntent(
|
|
182
|
+
"com.asus.mobilemanager",
|
|
183
|
+
"com.asus.mobilemanager.powersaver.PowerSaverSettings"),
|
|
184
|
+
createIntent(
|
|
185
|
+
"com.asus.mobilemanager", "com.asus.mobilemanager.autostart.AutoStartActivity"),
|
|
186
|
+
createIntent(
|
|
187
|
+
"com.asus.mobilemanager", "com.asus.mobilemanager.entry.FunctionActivity")
|
|
188
|
+
.setData(Uri.parse("mobilemanager://function/entry/AutoStart")));
|
|
189
|
+
break;
|
|
190
|
+
case "samsung":
|
|
191
|
+
possibleIntents =
|
|
192
|
+
Arrays.asList(
|
|
193
|
+
createIntent(
|
|
194
|
+
"com.samsung.android.lool",
|
|
195
|
+
"com.samsung.android.sm.ui.battery.BatteryActivity"),
|
|
196
|
+
createIntent(
|
|
197
|
+
"com.samsung.android.sm", "com.samsung.android.sm.ui.battery.BatteryActivity"),
|
|
198
|
+
createIntent(
|
|
199
|
+
"com.samsung.android.lool",
|
|
200
|
+
"com.samsung.android.sm.battery.ui.BatteryActivity"));
|
|
201
|
+
break;
|
|
202
|
+
case "huawei":
|
|
203
|
+
possibleIntents =
|
|
204
|
+
Arrays.asList(
|
|
205
|
+
createIntent(
|
|
206
|
+
"com.huawei.systemmanager",
|
|
207
|
+
"com.huawei.systemmanager.optimize.process.ProtectActivity"),
|
|
208
|
+
createIntent(
|
|
209
|
+
"com.huawei.systemmanager",
|
|
210
|
+
"com.huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity"),
|
|
211
|
+
createIntent(
|
|
212
|
+
"com.huawei.systemmanager",
|
|
213
|
+
"com.huawei.systemmanager.appcontrol.activity.StartupAppControlActivity"));
|
|
214
|
+
break;
|
|
215
|
+
case "redmi":
|
|
216
|
+
case "xiaomi":
|
|
217
|
+
possibleIntents =
|
|
218
|
+
Arrays.asList(
|
|
219
|
+
createIntent(
|
|
220
|
+
"com.miui.securitycenter",
|
|
221
|
+
"com.miui.permcenter.autostart.AutoStartManagementActivity"));
|
|
222
|
+
break;
|
|
223
|
+
case "letv":
|
|
224
|
+
possibleIntents =
|
|
225
|
+
Arrays.asList(
|
|
226
|
+
createIntent(
|
|
227
|
+
"com.letv.android.letvsafe",
|
|
228
|
+
"com.letv.android.letvsafe.AutobootManageActivity")
|
|
229
|
+
.setData(Uri.parse("mobilemanager://function/entry/AutoStart")));
|
|
230
|
+
break;
|
|
231
|
+
case "honor":
|
|
232
|
+
possibleIntents =
|
|
233
|
+
Arrays.asList(
|
|
234
|
+
createIntent(
|
|
235
|
+
"com.huawei.systemmanager",
|
|
236
|
+
"com.huawei.systemmanager.optimize.process.ProtectActivity"));
|
|
237
|
+
break;
|
|
238
|
+
case "coloros":
|
|
239
|
+
case "oppo":
|
|
240
|
+
possibleIntents =
|
|
241
|
+
Arrays.asList(
|
|
242
|
+
createIntent(
|
|
243
|
+
"com.coloros.safecenter",
|
|
244
|
+
"com.coloros.safecenter.permission.startup.StartupAppListActivity"),
|
|
245
|
+
createIntent(
|
|
246
|
+
"com.oppo.safe", "com.oppo.safe.permission.startup.StartupAppListActivity"),
|
|
247
|
+
createIntent(
|
|
248
|
+
"com.coloros.safecenter",
|
|
249
|
+
"com.coloros.safecenter.startupapp.StartupAppListActivity")
|
|
250
|
+
.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS),
|
|
251
|
+
createIntent(
|
|
252
|
+
"com.coloros.oppoguardelf",
|
|
253
|
+
"com.coloros.powermanager.fuelgaue.PowerUsageModelActivity"),
|
|
254
|
+
createIntent(
|
|
255
|
+
"com.coloros.oppoguardelf",
|
|
256
|
+
"com.coloros.powermanager.fuelgaue.PowerSaverModeActivity"),
|
|
257
|
+
createIntent(
|
|
258
|
+
"com.coloros.oppoguardelf",
|
|
259
|
+
"com.coloros.powermanager.fuelgaue.PowerConsumptionActivity"));
|
|
260
|
+
break;
|
|
261
|
+
case "vivo":
|
|
262
|
+
possibleIntents =
|
|
263
|
+
Arrays.asList(
|
|
264
|
+
createIntent(
|
|
265
|
+
"com.iqoo.secure", "com.iqoo.secure.ui.phoneoptimize.AddWhiteListActivity"),
|
|
266
|
+
createIntent(
|
|
267
|
+
"com.vivo.permissionmanager",
|
|
268
|
+
"com.vivo.permissionmanager.activity.BgStartUpManagerActivity"),
|
|
269
|
+
createIntent(
|
|
270
|
+
"com.iqoo.secure", "com.iqoo.secure.ui.phoneoptimize.BgStartUpManager"));
|
|
271
|
+
break;
|
|
272
|
+
case "nokia":
|
|
273
|
+
possibleIntents =
|
|
274
|
+
Arrays.asList(
|
|
275
|
+
createIntent(
|
|
276
|
+
"com.evenwell.powersaving.g3",
|
|
277
|
+
"com.evenwell.powersaving.g3.exception.PowerSaverExceptionActivity"));
|
|
278
|
+
break;
|
|
279
|
+
case "oneplus":
|
|
280
|
+
possibleIntents =
|
|
281
|
+
Arrays.asList(
|
|
282
|
+
createIntent(
|
|
283
|
+
"com.oneplus.security",
|
|
284
|
+
"com.oneplus.security.chainlaunch.view.ChainLaunchAppListActivity"));
|
|
285
|
+
break;
|
|
286
|
+
case "meizu":
|
|
287
|
+
possibleIntents =
|
|
288
|
+
Arrays.asList(
|
|
289
|
+
createIntent("com.meizu.safe", "com.meizu.safe.security.SHOW_APPSEC")
|
|
290
|
+
.addCategory(Intent.CATEGORY_DEFAULT));
|
|
291
|
+
break;
|
|
292
|
+
case "htc":
|
|
293
|
+
possibleIntents =
|
|
294
|
+
Arrays.asList(
|
|
295
|
+
createIntent(
|
|
296
|
+
"com.htc.pitroad", "com.htc.pitroad.landingpage.activity.LandingPageActivity"));
|
|
297
|
+
break;
|
|
298
|
+
default:
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
return possibleIntents;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
private static Intent createIntent(String pkg, String cls) {
|
|
306
|
+
Intent intent = new Intent();
|
|
307
|
+
intent.setComponent(new ComponentName(pkg, cls));
|
|
308
|
+
return intent;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
public static class PowerManagerInfo {
|
|
312
|
+
String manufacturer;
|
|
313
|
+
String model;
|
|
314
|
+
String version;
|
|
315
|
+
String activity;
|
|
316
|
+
|
|
317
|
+
public PowerManagerInfo(String manufacturer, String model, String version, String activity) {
|
|
318
|
+
this.manufacturer = manufacturer;
|
|
319
|
+
this.model = model;
|
|
320
|
+
this.version = version;
|
|
321
|
+
this.activity = activity;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
public Bundle toBundle() {
|
|
325
|
+
Bundle bundle = new Bundle();
|
|
326
|
+
bundle.putString("manufacturer", this.manufacturer);
|
|
327
|
+
bundle.putString("model", this.model);
|
|
328
|
+
bundle.putString("version", this.version);
|
|
329
|
+
bundle.putString("activity", this.activity);
|
|
330
|
+
|
|
331
|
+
return bundle;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
package app.notifee.core.utility;
|
|
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.graphics.Bitmap;
|
|
22
|
+
import android.graphics.Canvas;
|
|
23
|
+
import android.graphics.Color;
|
|
24
|
+
import android.graphics.Paint;
|
|
25
|
+
import android.graphics.PorterDuff;
|
|
26
|
+
import android.graphics.PorterDuffXfermode;
|
|
27
|
+
import android.graphics.Rect;
|
|
28
|
+
import android.media.RingtoneManager;
|
|
29
|
+
import android.net.Uri;
|
|
30
|
+
import android.util.TypedValue;
|
|
31
|
+
import androidx.annotation.NonNull;
|
|
32
|
+
import androidx.annotation.Nullable;
|
|
33
|
+
import app.notifee.core.ContextHolder;
|
|
34
|
+
import app.notifee.core.Logger;
|
|
35
|
+
import com.facebook.common.executors.CallerThreadExecutor;
|
|
36
|
+
import com.facebook.common.references.CloseableReference;
|
|
37
|
+
import com.facebook.datasource.DataSource;
|
|
38
|
+
import com.facebook.drawee.backends.pipeline.Fresco;
|
|
39
|
+
import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber;
|
|
40
|
+
import com.facebook.imagepipeline.image.CloseableImage;
|
|
41
|
+
import com.facebook.imagepipeline.request.ImageRequest;
|
|
42
|
+
import com.facebook.imagepipeline.request.ImageRequestBuilder;
|
|
43
|
+
import com.google.common.util.concurrent.ListenableFuture;
|
|
44
|
+
import com.google.common.util.concurrent.SettableFuture;
|
|
45
|
+
import java.util.HashMap;
|
|
46
|
+
import java.util.Map;
|
|
47
|
+
|
|
48
|
+
public class ResourceUtils {
|
|
49
|
+
private static final String TAG = "ResourceUtils";
|
|
50
|
+
private static final String LOCAL_RESOURCE_SCHEME = "res";
|
|
51
|
+
private static volatile Map<String, Integer> sResourceIdCache;
|
|
52
|
+
|
|
53
|
+
public static Map<String, Integer> getResourceIdCache() {
|
|
54
|
+
if (sResourceIdCache == null) {
|
|
55
|
+
synchronized (ResourceUtils.class) {
|
|
56
|
+
if (sResourceIdCache == null) {
|
|
57
|
+
sResourceIdCache = new HashMap<>();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return sResourceIdCache;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public static Uri getImageSourceUri(String source) {
|
|
65
|
+
try {
|
|
66
|
+
Uri uri = Uri.parse(source);
|
|
67
|
+
// verify a scheme is set,
|
|
68
|
+
// so that relative uri (used by static resources) are not handled
|
|
69
|
+
if (uri.getScheme() == null) {
|
|
70
|
+
return getResourceDrawableUri(source);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return uri;
|
|
74
|
+
} catch (Exception e) {
|
|
75
|
+
return getResourceDrawableUri(source);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public static Uri getResourceDrawableUri(@Nullable String name) {
|
|
80
|
+
int resId = getResourceIdByName(name, "drawable");
|
|
81
|
+
return resId > 0
|
|
82
|
+
? new Uri.Builder().scheme(LOCAL_RESOURCE_SCHEME).path(String.valueOf(resId)).build()
|
|
83
|
+
: Uri.EMPTY;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Returns a circular Bitmap from another bitmap. The original bitmap can be any shape.
|
|
88
|
+
*
|
|
89
|
+
* @param bitmap
|
|
90
|
+
* @return Bitmap
|
|
91
|
+
*/
|
|
92
|
+
public static Bitmap getCircularBitmap(Bitmap bitmap) {
|
|
93
|
+
Bitmap output;
|
|
94
|
+
Rect srcRect, dstRect;
|
|
95
|
+
float r;
|
|
96
|
+
final int width = bitmap.getWidth();
|
|
97
|
+
final int height = bitmap.getHeight();
|
|
98
|
+
|
|
99
|
+
if (width > height) {
|
|
100
|
+
output = Bitmap.createBitmap(height, height, Bitmap.Config.ARGB_8888);
|
|
101
|
+
int left = (width - height) / 2;
|
|
102
|
+
int right = left + height;
|
|
103
|
+
srcRect = new Rect(left, 0, right, height);
|
|
104
|
+
dstRect = new Rect(0, 0, height, height);
|
|
105
|
+
r = height / 2;
|
|
106
|
+
} else {
|
|
107
|
+
output = Bitmap.createBitmap(width, width, Bitmap.Config.ARGB_8888);
|
|
108
|
+
int top = (height - width) / 2;
|
|
109
|
+
int bottom = top + width;
|
|
110
|
+
srcRect = new Rect(0, top, width, bottom);
|
|
111
|
+
dstRect = new Rect(0, 0, width, width);
|
|
112
|
+
r = width / 2;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
final Canvas canvas = new Canvas(output);
|
|
116
|
+
|
|
117
|
+
final int color = Color.RED;
|
|
118
|
+
final Paint paint = new Paint();
|
|
119
|
+
|
|
120
|
+
paint.setAntiAlias(true);
|
|
121
|
+
canvas.drawARGB(0, 0, 0, 0);
|
|
122
|
+
paint.setColor(color);
|
|
123
|
+
canvas.drawCircle(r, r, r, paint);
|
|
124
|
+
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
|
|
125
|
+
canvas.drawBitmap(bitmap, srcRect, dstRect, paint);
|
|
126
|
+
|
|
127
|
+
return output;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Returns a Bitmap from any given HTTP image URL, or local resource.
|
|
132
|
+
*
|
|
133
|
+
* @param imageUrl
|
|
134
|
+
* @return Bitmap or null if the image failed to load
|
|
135
|
+
*/
|
|
136
|
+
public static ListenableFuture<Bitmap> getImageBitmapFromUrl(
|
|
137
|
+
String imageUrl) {
|
|
138
|
+
Uri imageUri;
|
|
139
|
+
final SettableFuture<Bitmap> bitmapTCS = SettableFuture.create();
|
|
140
|
+
|
|
141
|
+
if (!imageUrl.contains("/")) {
|
|
142
|
+
String imageResourceUrl = getImageResourceUrl(imageUrl);
|
|
143
|
+
if (imageResourceUrl == null) {
|
|
144
|
+
bitmapTCS.set(null);
|
|
145
|
+
return bitmapTCS;
|
|
146
|
+
}
|
|
147
|
+
imageUri = getImageSourceUri(imageResourceUrl);
|
|
148
|
+
} else {
|
|
149
|
+
imageUri = getImageSourceUri(imageUrl);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(imageUri).build();
|
|
153
|
+
|
|
154
|
+
// TODO(helenaford): handle destroying of fresco after use in background state
|
|
155
|
+
// Needed when the app is killed, and the Fresco hasn't yet been initialized by React Native
|
|
156
|
+
if (!Fresco.hasBeenInitialized()) {
|
|
157
|
+
Logger.w(TAG, "Fresco initializing natively by Notifee");
|
|
158
|
+
|
|
159
|
+
// TODO(helenaford): expand on this to initialize with a custom imagePipelineConfig
|
|
160
|
+
Fresco.initialize(ContextHolder.getApplicationContext());
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
DataSource<CloseableReference<CloseableImage>> dataSource =
|
|
164
|
+
Fresco.getImagePipeline()
|
|
165
|
+
.fetchDecodedImage(imageRequest, ContextHolder.getApplicationContext());
|
|
166
|
+
|
|
167
|
+
dataSource.subscribe(
|
|
168
|
+
new BaseBitmapDataSubscriber() {
|
|
169
|
+
@Override
|
|
170
|
+
protected void onNewResultImpl(@Nullable Bitmap bitmap) {
|
|
171
|
+
bitmapTCS.set(bitmap);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
@Override
|
|
175
|
+
protected void onFailureImpl(
|
|
176
|
+
@NonNull DataSource<CloseableReference<CloseableImage>> dataSource) {
|
|
177
|
+
Logger.e(TAG, "Failed to load an image: " + imageUrl, dataSource.getFailureCause());
|
|
178
|
+
bitmapTCS.set(null);
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
CallerThreadExecutor.getInstance());
|
|
182
|
+
|
|
183
|
+
return bitmapTCS;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Returns a resource path for a local resource
|
|
188
|
+
*
|
|
189
|
+
* @param icon
|
|
190
|
+
* @return
|
|
191
|
+
*/
|
|
192
|
+
private static String getImageResourceUrl(String icon) {
|
|
193
|
+
int resourceId = getResourceIdByName(icon, "mipmap");
|
|
194
|
+
|
|
195
|
+
if (resourceId == 0) {
|
|
196
|
+
resourceId = getResourceIdByName(icon, "drawable");
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (resourceId == 0) {
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return resourceId > 0
|
|
204
|
+
? new Uri.Builder()
|
|
205
|
+
.scheme(LOCAL_RESOURCE_SCHEME)
|
|
206
|
+
.path(String.valueOf(resourceId))
|
|
207
|
+
.build()
|
|
208
|
+
.toString()
|
|
209
|
+
: Uri.EMPTY.toString();
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Gets a resource ID by name.
|
|
214
|
+
*
|
|
215
|
+
* @param resourceName
|
|
216
|
+
* @return integer or 0 if not found
|
|
217
|
+
*/
|
|
218
|
+
public static int getImageResourceId(String resourceName) {
|
|
219
|
+
int resourceId = getResourceIdByName(resourceName, "mipmap");
|
|
220
|
+
if (resourceId == 0) {
|
|
221
|
+
resourceId = getResourceIdByName(resourceName, "drawable");
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return resourceId;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** Attempts to find a resource id by name and type */
|
|
228
|
+
private static int getResourceIdByName(String name, String type) {
|
|
229
|
+
if (name == null || name.isEmpty()) {
|
|
230
|
+
return 0;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
name = name.toLowerCase().replace("-", "_");
|
|
234
|
+
|
|
235
|
+
String key = name + "_" + type;
|
|
236
|
+
|
|
237
|
+
synchronized (ResourceUtils.class) {
|
|
238
|
+
if (getResourceIdCache().containsKey(key)) {
|
|
239
|
+
// noinspection ConstantConditions
|
|
240
|
+
return getResourceIdCache().get(key);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
Context context = ContextHolder.getApplicationContext();
|
|
244
|
+
String packageName = context.getPackageName();
|
|
245
|
+
|
|
246
|
+
int id = context.getResources().getIdentifier(name, type, packageName);
|
|
247
|
+
getResourceIdCache().put(key, id);
|
|
248
|
+
return id;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
public static @Nullable String getSoundName(Uri sound) {
|
|
253
|
+
if (sound == null) return null;
|
|
254
|
+
if (sound.toString().contains("android.resource")) {
|
|
255
|
+
String soundFile = sound.getLastPathSegment();
|
|
256
|
+
try {
|
|
257
|
+
int resourceId = Integer.valueOf(soundFile);
|
|
258
|
+
Logger.e(
|
|
259
|
+
TAG,
|
|
260
|
+
"Loaded sound by resource id. New app builds will fail to play sound. Create a new"
|
|
261
|
+
+ " channel to resolve. Issue #341");
|
|
262
|
+
if (resourceId != 0) {
|
|
263
|
+
TypedValue value = new TypedValue();
|
|
264
|
+
Context context = ContextHolder.getApplicationContext();
|
|
265
|
+
context.getResources().getValue(resourceId, value, true);
|
|
266
|
+
|
|
267
|
+
CharSequence soundString = value.string;
|
|
268
|
+
if (soundString != null || soundString.length() > 0) {
|
|
269
|
+
return soundString.toString().replace("res/raw/", "");
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
} catch (NumberFormatException nfe) {
|
|
273
|
+
// This implies the sound URI last path segment was by file name, not resourceId
|
|
274
|
+
// They were by resourceId prior to issue #341 where we learned that leads to unstable URIs
|
|
275
|
+
// Now we verify the file exists but use the file name from the raw directory
|
|
276
|
+
// We still attempt to resolve by resourceId above to gracefully handle URIs created via our
|
|
277
|
+
// previous behavior
|
|
278
|
+
return soundFile;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// TODO parse system sounds
|
|
283
|
+
return null;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
public static @Nullable Uri getSoundUri(String sound) {
|
|
287
|
+
Context context = ContextHolder.getApplicationContext();
|
|
288
|
+
if (sound == null) {
|
|
289
|
+
return null;
|
|
290
|
+
} else if (sound.contains("://")) {
|
|
291
|
+
return Uri.parse(sound);
|
|
292
|
+
} else if (sound.equalsIgnoreCase("default")) {
|
|
293
|
+
return RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
|
|
294
|
+
} else {
|
|
295
|
+
// The API user is attempting to set a sound by file name, verify it exists
|
|
296
|
+
int soundResourceId = getResourceIdByName(sound, "raw");
|
|
297
|
+
if (soundResourceId == 0 && sound.contains(".")) {
|
|
298
|
+
soundResourceId = getResourceIdByName(sound.substring(0, sound.lastIndexOf('.')), "raw");
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if (soundResourceId == 0) {
|
|
302
|
+
return null;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// Use the actual sound name vs the resource ID, to obtain a stable URI, Issue #341
|
|
306
|
+
return Uri.parse("android.resource://" + context.getPackageName() + "/raw/" + sound);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
package app.notifee.core.utility;
|
|
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.text.Spanned;
|
|
21
|
+
import androidx.core.text.HtmlCompat;
|
|
22
|
+
|
|
23
|
+
public class TextUtils {
|
|
24
|
+
|
|
25
|
+
public static Spanned fromHtml(String text) {
|
|
26
|
+
return HtmlCompat.fromHtml(text, HtmlCompat.FROM_HTML_MODE_LEGACY);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -325,7 +325,13 @@ export declare enum EventType {
|
|
|
325
325
|
/**
|
|
326
326
|
* Event type is sent when a notification trigger is created.
|
|
327
327
|
*/
|
|
328
|
-
TRIGGER_NOTIFICATION_CREATED = 7
|
|
328
|
+
TRIGGER_NOTIFICATION_CREATED = 7,
|
|
329
|
+
/**
|
|
330
|
+
* **ANDROID ONLY**
|
|
331
|
+
*
|
|
332
|
+
* Event type is sent when a notification wants to start a foreground service but a foreground service is already started.
|
|
333
|
+
*/
|
|
334
|
+
FG_ALREADY_EXIST = 8
|
|
329
335
|
}
|
|
330
336
|
/**
|
|
331
337
|
* An interface representing the different detail values which can be provided with a notification event.
|
|
@@ -343,6 +349,7 @@ export interface EventDetail {
|
|
|
343
349
|
* - [`EventType.ACTION_PRESS`](/react-native/reference/eventtype#action_press)
|
|
344
350
|
* - [`EventType.DELIVERED`](/react-native/reference/eventtype#delivered)
|
|
345
351
|
* - [`EventType.TRIGGER_NOTIFICATION_CREATED`](/react-native/reference/eventtype#trigger_notification_created)
|
|
352
|
+
* - [`EventType.FG_ALREADY_EXIST`](/react-native/reference/eventtype#fg_already_exist)
|
|
346
353
|
*/
|
|
347
354
|
notification?: Notification;
|
|
348
355
|
/**
|