@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.
Files changed (79) hide show
  1. package/android/build.gradle +36 -18
  2. package/android/schemas/app.notifee.core.database.NotifeeCoreDatabase/1.json +46 -0
  3. package/android/schemas/app.notifee.core.database.NotifeeCoreDatabase/2.json +53 -0
  4. package/android/src/main/java/app/notifee/core/AlarmPermissionBroadcastReceiver.java +19 -0
  5. package/android/src/main/java/app/notifee/core/BlockStateBroadcastReceiver.java +164 -0
  6. package/android/src/main/java/app/notifee/core/ChannelManager.java +351 -0
  7. package/android/src/main/java/app/notifee/core/ContextHolder.java +33 -0
  8. package/android/src/main/java/app/notifee/core/EventBus.java +63 -0
  9. package/android/src/main/java/app/notifee/core/EventSubscriber.java +82 -0
  10. package/android/src/main/java/app/notifee/core/ForegroundService.java +125 -0
  11. package/android/src/main/java/app/notifee/core/InitProvider.java +92 -0
  12. package/android/src/main/java/app/notifee/core/KeepForSdk.java +26 -0
  13. package/android/src/main/java/app/notifee/core/Logger.java +68 -0
  14. package/android/src/main/java/app/notifee/core/Notifee.java +533 -0
  15. package/android/src/main/java/app/notifee/core/NotifeeAlarmManager.java +256 -0
  16. package/android/src/main/java/app/notifee/core/NotificationAlarmReceiver.java +32 -0
  17. package/android/src/main/java/app/notifee/core/NotificationManager.java +903 -0
  18. package/android/src/main/java/app/notifee/core/NotificationPendingIntent.java +189 -0
  19. package/android/src/main/java/app/notifee/core/NotificationReceiverActivity.java +38 -0
  20. package/android/src/main/java/app/notifee/core/NotificationReceiverHandler.java +140 -0
  21. package/android/src/main/java/app/notifee/core/Preferences.java +79 -0
  22. package/android/src/main/java/app/notifee/core/RebootBroadcastReceiver.java +38 -0
  23. package/android/src/main/java/app/notifee/core/ReceiverService.java +268 -0
  24. package/android/src/main/java/app/notifee/core/Worker.java +87 -0
  25. package/android/src/main/java/app/notifee/core/database/NotifeeCoreDatabase.java +76 -0
  26. package/android/src/main/java/app/notifee/core/database/WorkDataDao.java +52 -0
  27. package/android/src/main/java/app/notifee/core/database/WorkDataEntity.java +68 -0
  28. package/android/src/main/java/app/notifee/core/database/WorkDataRepository.java +107 -0
  29. package/android/src/main/java/app/notifee/core/event/BlockStateEvent.java +102 -0
  30. package/android/src/main/java/app/notifee/core/event/ForegroundServiceEvent.java +48 -0
  31. package/android/src/main/java/app/notifee/core/event/InitialNotificationEvent.java +50 -0
  32. package/android/src/main/java/app/notifee/core/event/LogEvent.java +74 -0
  33. package/android/src/main/java/app/notifee/core/event/MainComponentEvent.java +33 -0
  34. package/android/src/main/java/app/notifee/core/event/NotificationEvent.java +97 -0
  35. package/android/src/main/java/app/notifee/core/interfaces/EventListener.java +39 -0
  36. package/android/src/main/java/app/notifee/core/interfaces/MethodCallResult.java +27 -0
  37. package/android/src/main/java/app/notifee/core/model/ChannelGroupModel.java +48 -0
  38. package/android/src/main/java/app/notifee/core/model/ChannelModel.java +123 -0
  39. package/android/src/main/java/app/notifee/core/model/IntervalTriggerModel.java +63 -0
  40. package/android/src/main/java/app/notifee/core/model/NotificationAndroidActionModel.java +125 -0
  41. package/android/src/main/java/app/notifee/core/model/NotificationAndroidModel.java +654 -0
  42. package/android/src/main/java/app/notifee/core/model/NotificationAndroidPressActionModel.java +146 -0
  43. package/android/src/main/java/app/notifee/core/model/NotificationAndroidStyleModel.java +341 -0
  44. package/android/src/main/java/app/notifee/core/model/NotificationModel.java +72 -0
  45. package/android/src/main/java/app/notifee/core/model/TimestampTriggerModel.java +163 -0
  46. package/android/src/main/java/app/notifee/core/model/package-info.java +4 -0
  47. package/android/src/main/java/app/notifee/core/utility/AlarmUtils.java +52 -0
  48. package/android/src/main/java/app/notifee/core/utility/Callbackable.java +12 -0
  49. package/android/src/main/java/app/notifee/core/utility/ColorUtils.java +62 -0
  50. package/android/src/main/java/app/notifee/core/utility/ExtendedListenableFuture.java +84 -0
  51. package/android/src/main/java/app/notifee/core/utility/IntentUtils.java +136 -0
  52. package/android/src/main/java/app/notifee/core/utility/ObjectUtils.java +187 -0
  53. package/android/src/main/java/app/notifee/core/utility/PowerManagerUtils.java +334 -0
  54. package/android/src/main/java/app/notifee/core/utility/ResourceUtils.java +309 -0
  55. package/android/src/main/java/app/notifee/core/utility/TextUtils.java +28 -0
  56. package/android/src/main/java/app/notifee/core/utility/package-info.java +4 -0
  57. package/dist/types/Notification.d.ts +8 -1
  58. package/dist/types/Notification.js +6 -0
  59. package/dist/types/Notification.js.map +1 -1
  60. package/dist/version.d.ts +1 -1
  61. package/jest-mock.js +7 -4
  62. package/package.json +1 -3
  63. package/src/types/Notification.ts +8 -0
  64. package/src/version.ts +1 -1
  65. package/android/libs/app/notifee/core/202108261756/core-202108261756.aar +0 -0
  66. package/android/libs/app/notifee/core/202108261756/core-202108261756.aar.md5 +0 -1
  67. package/android/libs/app/notifee/core/202108261756/core-202108261756.aar.sha1 +0 -1
  68. package/android/libs/app/notifee/core/202108261756/core-202108261756.aar.sha256 +0 -1
  69. package/android/libs/app/notifee/core/202108261756/core-202108261756.aar.sha512 +0 -1
  70. package/android/libs/app/notifee/core/202108261756/core-202108261756.pom +0 -9
  71. package/android/libs/app/notifee/core/202108261756/core-202108261756.pom.md5 +0 -1
  72. package/android/libs/app/notifee/core/202108261756/core-202108261756.pom.sha1 +0 -1
  73. package/android/libs/app/notifee/core/202108261756/core-202108261756.pom.sha256 +0 -1
  74. package/android/libs/app/notifee/core/202108261756/core-202108261756.pom.sha512 +0 -1
  75. package/android/libs/app/notifee/core/maven-metadata.xml +0 -13
  76. package/android/libs/app/notifee/core/maven-metadata.xml.md5 +0 -1
  77. package/android/libs/app/notifee/core/maven-metadata.xml.sha1 +0 -1
  78. package/android/libs/app/notifee/core/maven-metadata.xml.sha256 +0 -1
  79. package/android/libs/app/notifee/core/maven-metadata.xml.sha512 +0 -1
@@ -0,0 +1,163 @@
1
+ package app.notifee.core.model;
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.os.Bundle;
21
+ import androidx.annotation.NonNull;
22
+ import app.notifee.core.utility.ObjectUtils;
23
+ import java.util.concurrent.TimeUnit;
24
+
25
+ public class TimestampTriggerModel {
26
+ private Bundle mTimeTriggerBundle;
27
+ private int mInterval = -1;
28
+ private TimeUnit mTimeUnit = null;
29
+ private Boolean mWithAlarmManager = false;
30
+ private Boolean mAllowWhileIdle = false;
31
+ private String mRepeatFrequency = null;
32
+ private Long mTimestamp = null;
33
+
34
+ public static final String HOURLY = "HOURLY";
35
+ public static final String DAILY = "DAILY";
36
+ public static final String WEEKLY = "WEEKLY";
37
+
38
+ private static final int MINUTES_IN_MS = 60 * 1000;
39
+ private static final long HOUR_IN_MS = 60 * MINUTES_IN_MS;
40
+ private static final long DAY_IN_MS = 24 * HOUR_IN_MS;
41
+
42
+ private static final String TAG = "TimeTriggerModel";
43
+
44
+ private TimestampTriggerModel(Bundle bundle) {
45
+ mTimeTriggerBundle = bundle;
46
+
47
+ // set initial values
48
+ TimeUnit timeUnit = null;
49
+ if (mTimeTriggerBundle.containsKey("repeatFrequency")) {
50
+ int repeatFrequency = ObjectUtils.getInt(mTimeTriggerBundle.get("repeatFrequency"));
51
+ mTimestamp = ObjectUtils.getLong(mTimeTriggerBundle.get("timestamp"));
52
+
53
+ switch (repeatFrequency) {
54
+ case -1:
55
+ // default value for one-time trigger
56
+ break;
57
+ case 0:
58
+ mInterval = 1;
59
+ mTimeUnit = TimeUnit.HOURS;
60
+ mRepeatFrequency = HOURLY;
61
+ break;
62
+ case 1:
63
+ mInterval = 1;
64
+ mTimeUnit = TimeUnit.DAYS;
65
+ mRepeatFrequency = DAILY;
66
+ break;
67
+ case 2:
68
+ // weekly, 7 days
69
+ mInterval = 7;
70
+ mTimeUnit = TimeUnit.DAYS;
71
+ mRepeatFrequency = WEEKLY;
72
+ break;
73
+ }
74
+ }
75
+
76
+ if (mTimeTriggerBundle.containsKey("alarmManager")) {
77
+ mWithAlarmManager = true;
78
+
79
+ Bundle alarmManagerBundle = mTimeTriggerBundle.getBundle("alarmManager");
80
+
81
+ if (alarmManagerBundle.containsKey("allowWhileIdle")) {
82
+ mAllowWhileIdle = alarmManagerBundle.getBoolean("allowWhileIdle");
83
+ }
84
+ } else if (mTimeTriggerBundle.containsKey("allowWhileIdle")) {
85
+ mWithAlarmManager = true;
86
+ mAllowWhileIdle = mTimeTriggerBundle.getBoolean("allowWhileIdle");
87
+ }
88
+ }
89
+
90
+ public static TimestampTriggerModel fromBundle(@NonNull Bundle bundle) {
91
+ return new TimestampTriggerModel(bundle);
92
+ }
93
+
94
+ public long getTimestamp() {
95
+ return mTimestamp;
96
+ }
97
+
98
+ public long getDelay() {
99
+ long delay = 0;
100
+
101
+ if (mTimeTriggerBundle.containsKey("timestamp")) {
102
+ long timestamp = ObjectUtils.getLong(mTimeTriggerBundle.get("timestamp"));
103
+ if (timestamp > 0) {
104
+ delay = Math.round((timestamp - System.currentTimeMillis()) / 1000);
105
+ }
106
+ }
107
+
108
+ return delay;
109
+ }
110
+
111
+ public void setNextTimestamp() {
112
+ // Skip for non-repeating triggers
113
+ if (mRepeatFrequency == null) {
114
+ return;
115
+ }
116
+
117
+ long timestamp = getTimestamp();
118
+ long interval = 0;
119
+
120
+ switch (mRepeatFrequency) {
121
+ case TimestampTriggerModel.WEEKLY:
122
+ interval = 7 * DAY_IN_MS;
123
+ break;
124
+ case TimestampTriggerModel.DAILY:
125
+ interval = DAY_IN_MS;
126
+ break;
127
+ case TimestampTriggerModel.HOURLY:
128
+ interval = HOUR_IN_MS;
129
+ break;
130
+ }
131
+
132
+ // prevent alarm manager notification firing straight away
133
+ while (timestamp < System.currentTimeMillis()) {
134
+ timestamp += interval;
135
+ }
136
+
137
+ this.mTimestamp = timestamp;
138
+ }
139
+
140
+ public int getInterval() {
141
+ return mInterval;
142
+ }
143
+
144
+ public TimeUnit getTimeUnit() {
145
+ return mTimeUnit;
146
+ }
147
+
148
+ public Boolean getWithAlarmManager() {
149
+ return mWithAlarmManager;
150
+ }
151
+
152
+ public Boolean getAllowWhileIdle() {
153
+ return mAllowWhileIdle;
154
+ }
155
+
156
+ public String getRepeatFrequency() {
157
+ return mRepeatFrequency;
158
+ }
159
+
160
+ public Bundle toBundle() {
161
+ return (Bundle) mTimeTriggerBundle.clone();
162
+ }
163
+ }
@@ -0,0 +1,4 @@
1
+ @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX)
2
+ package app.notifee.core.model;
3
+
4
+ import androidx.annotation.RestrictTo;
@@ -0,0 +1,52 @@
1
+ package app.notifee.core.utility;
2
+
3
+ import static app.notifee.core.ContextHolder.getApplicationContext;
4
+
5
+ import android.app.Activity;
6
+ import android.app.AlarmManager;
7
+ import android.content.Context;
8
+ import android.content.Intent;
9
+ import android.net.Uri;
10
+ import android.os.Build;
11
+ import android.provider.Settings;
12
+ import app.notifee.core.ContextHolder;
13
+ import app.notifee.core.Logger;
14
+
15
+ public class AlarmUtils {
16
+ private static final String TAG = "AlarmUtils";
17
+
18
+ public static AlarmManager getAlarmManager() {
19
+ return (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
20
+ }
21
+
22
+ /**
23
+ * Attempts to open the device's alarm special access settings
24
+ *
25
+ * @param activity
26
+ */
27
+ public static void openAlarmPermissionSettings(Activity activity) {
28
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
29
+ return;
30
+ }
31
+
32
+ try {
33
+ Intent intent = new Intent();
34
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
35
+ intent.setAction(Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM);
36
+ Context context = ContextHolder.getApplicationContext();
37
+ String packageName = context.getPackageName();
38
+ intent.setData(Uri.parse("package:" + packageName));
39
+
40
+ IntentUtils.startActivityOnUiThread(activity, intent);
41
+ } catch (Exception e) {
42
+ Logger.e(TAG, "An error occurred whilst trying to open alarm permission settings", e);
43
+ }
44
+ }
45
+
46
+ public static boolean canScheduleExactAlarms() {
47
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
48
+ return getAlarmManager().canScheduleExactAlarms();
49
+ }
50
+ return true;
51
+ }
52
+ }
@@ -0,0 +1,12 @@
1
+ package app.notifee.core.utility;
2
+
3
+ import androidx.annotation.Nullable;
4
+
5
+ /**
6
+ * Since lambda functions are not supported prior to SDK 24, and this project's SDK min. is 20,
7
+ * This interface was created to pass a function to another object.
8
+ */
9
+ public interface Callbackable<T> {
10
+
11
+ void call(@Nullable Exception e,@Nullable T result);
12
+ }
@@ -0,0 +1,62 @@
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.graphics.Color;
21
+ import androidx.annotation.Nullable;
22
+ import java.util.HashMap;
23
+
24
+ public class ColorUtils {
25
+ public static @Nullable String getColorString(int color) {
26
+ String colorString = iColorNameMap.get(color);
27
+ if (colorString != null) {
28
+ return colorString;
29
+ } else {
30
+ return "#" + Integer.toHexString(color).substring(2);
31
+ }
32
+ }
33
+
34
+ private static final HashMap<Integer, String> iColorNameMap;
35
+
36
+ static {
37
+ iColorNameMap = new HashMap<>();
38
+ iColorNameMap.put(Color.BLACK, "black");
39
+ iColorNameMap.put(Color.DKGRAY, "darkgray");
40
+ iColorNameMap.put(Color.GRAY, "gray");
41
+ iColorNameMap.put(Color.LTGRAY, "lightgray");
42
+ iColorNameMap.put(Color.WHITE, "white");
43
+ iColorNameMap.put(Color.RED, "red");
44
+ iColorNameMap.put(Color.GREEN, "green");
45
+ iColorNameMap.put(Color.BLUE, "blue");
46
+ iColorNameMap.put(Color.YELLOW, "yellow");
47
+ iColorNameMap.put(Color.CYAN, "cyan");
48
+ iColorNameMap.put(Color.MAGENTA, "magenta");
49
+ iColorNameMap.put(0xFF00FFFF, "aqua");
50
+ iColorNameMap.put(0xFFFF00FF, "fuchsia");
51
+ iColorNameMap.put(Color.DKGRAY, "darkgrey");
52
+ iColorNameMap.put(Color.GRAY, "grey");
53
+ iColorNameMap.put(Color.LTGRAY, "lightgrey");
54
+ iColorNameMap.put(0xFF00FF00, "lime");
55
+ iColorNameMap.put(0xFF800000, "maroon");
56
+ iColorNameMap.put(0xFF000080, "navy");
57
+ iColorNameMap.put(0xFF808000, "olive");
58
+ iColorNameMap.put(0xFF800080, "purple");
59
+ iColorNameMap.put(0xFFC0C0C0, "silver");
60
+ iColorNameMap.put(0xFF008080, "teal");
61
+ }
62
+ }
@@ -0,0 +1,84 @@
1
+ package app.notifee.core.utility;
2
+
3
+ import com.google.common.util.concurrent.AsyncFunction;
4
+ import com.google.common.util.concurrent.FutureCallback;
5
+ import com.google.common.util.concurrent.Futures;
6
+ import com.google.common.util.concurrent.ListenableFuture;
7
+ import java.util.concurrent.ExecutionException;
8
+ import java.util.concurrent.Executor;
9
+ import java.util.concurrent.TimeUnit;
10
+ import java.util.concurrent.TimeoutException;
11
+ import org.checkerframework.checker.nullness.qual.Nullable;
12
+
13
+ /**
14
+ * A simple wrapper around {@link ListenableFuture} that provides additional
15
+ * methods that makes chaining {@link ListenableFuture}s easier and more readable.
16
+ */
17
+ public class ExtendedListenableFuture<T> implements ListenableFuture<T> {
18
+
19
+ private final ListenableFuture<T> future;
20
+
21
+ public ExtendedListenableFuture(ListenableFuture<T> future) {
22
+ this.future = future;
23
+ }
24
+
25
+ /**
26
+ * A wrapper around {@link Futures#transformAsync} that uses the
27
+ * Future It's called on as first parameter by default.
28
+ * This allows easier chaining.
29
+ */
30
+ public <O extends @Nullable Object> ExtendedListenableFuture<O> continueWith(
31
+ AsyncFunction<T, O> asyncFunction, Executor lExecutor) {
32
+ ListenableFuture<O> future = Futures.transformAsync(this, asyncFunction,
33
+ lExecutor);
34
+ return new ExtendedListenableFuture<>(future);
35
+ }
36
+
37
+ public ExtendedListenableFuture<T> addOnCompleteListener(Callbackable<T> callbackable,
38
+ Executor executor) {
39
+ Futures.addCallback(this, new FutureCallback<T>() {
40
+ @Override
41
+ public void onSuccess(T result) {
42
+ callbackable.call(null, result);
43
+ }
44
+
45
+ @Override
46
+ public void onFailure(Throwable t) {
47
+ callbackable.call(new Exception(t), null);
48
+ }
49
+ }, executor);
50
+ return this;
51
+ }
52
+
53
+ @Override
54
+ public void addListener(Runnable listener, Executor executor) {
55
+ future.addListener(listener, executor);
56
+ }
57
+
58
+ @Override
59
+ public boolean cancel(boolean mayInterruptIfRunning) {
60
+ return future.cancel(mayInterruptIfRunning);
61
+ }
62
+
63
+ @Override
64
+ public boolean isCancelled() {
65
+ return future.isCancelled();
66
+ }
67
+
68
+ @Override
69
+ public boolean isDone() {
70
+ return future.isDone();
71
+ }
72
+
73
+ @Override
74
+ public T get() throws ExecutionException, InterruptedException {
75
+ return future.get();
76
+ }
77
+
78
+ @Override
79
+ public T get(long timeout, TimeUnit unit)
80
+ throws ExecutionException, InterruptedException, TimeoutException {
81
+ return future.get(timeout, unit);
82
+ }
83
+
84
+ }
@@ -0,0 +1,136 @@
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 static app.notifee.core.ContextHolder.getApplicationContext;
21
+
22
+ import android.app.Activity;
23
+ import android.content.Context;
24
+ import android.content.Intent;
25
+ import android.content.pm.PackageManager;
26
+ import android.content.pm.ResolveInfo;
27
+ import androidx.annotation.Nullable;
28
+ import app.notifee.core.Logger;
29
+ import java.util.List;
30
+
31
+ public class IntentUtils {
32
+ private static final String TAG = "IntentUtils";
33
+
34
+ public static boolean isAvailableOnDevice(Context ctx, Intent intent) {
35
+ try {
36
+ if (ctx == null || intent == null) {
37
+ return false;
38
+ }
39
+
40
+ final PackageManager mgr = ctx.getPackageManager();
41
+ List<ResolveInfo> list = mgr.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
42
+ return list.size() > 0;
43
+ } catch (Exception e) {
44
+ Logger.e(TAG, "An error occurred whilst trying to check if intent is available on device", e);
45
+
46
+ return false;
47
+ }
48
+ }
49
+
50
+ public static String getActivityName(Intent intent) {
51
+ if (intent == null) {
52
+ return null;
53
+ }
54
+
55
+ try {
56
+ String className = intent.getComponent().getClassName();
57
+ int index = className.lastIndexOf(".");
58
+
59
+ if (index != -1) {
60
+ return className.substring(index + 1);
61
+ }
62
+
63
+ } catch (Exception e) {
64
+ // noop
65
+ }
66
+
67
+ return null;
68
+ }
69
+
70
+ public static void startActivityOnUiThread(Activity activity, Intent intent) {
71
+ if (activity == null || intent == null) {
72
+ Logger.w(TAG, "Activity or intent is null when calling startActivityOnUiThread()");
73
+ return;
74
+ }
75
+
76
+ Context ctx = getApplicationContext();
77
+ if (ctx == null) {
78
+ Logger.w(TAG, "Unable to get application context when calling startActivityOnUiThread()");
79
+ }
80
+
81
+ activity.runOnUiThread(
82
+ () -> {
83
+ try {
84
+ ctx.startActivity(intent);
85
+ } catch (Exception e) {
86
+ Logger.e(TAG, "An error occurred whilst trying to start activity on Ui Thread", e);
87
+ }
88
+ });
89
+ }
90
+
91
+ public static Class<?> getLaunchActivity(@Nullable String launchActivity) {
92
+ String activity;
93
+
94
+ if (launchActivity != null && !launchActivity.equals("default")) {
95
+ activity = launchActivity;
96
+ } else {
97
+ activity = getMainActivityClassName();
98
+ }
99
+
100
+ if (activity == null) {
101
+ Logger.e("ReceiverService", "Launch Activity for notification could not be found.");
102
+ return null;
103
+ }
104
+
105
+ Class<?> launchActivityClass = getClassForName(activity);
106
+
107
+ if (launchActivityClass == null) {
108
+ Logger.e(
109
+ "ReceiverService",
110
+ String.format("Launch Activity for notification does not exist ('%s').", launchActivity));
111
+ return null;
112
+ }
113
+
114
+ return launchActivityClass;
115
+ }
116
+
117
+ private @Nullable static Class<?> getClassForName(String className) {
118
+ try {
119
+ return Class.forName(className);
120
+ } catch (ClassNotFoundException e) {
121
+ return null;
122
+ }
123
+ }
124
+
125
+ private @Nullable static String getMainActivityClassName() {
126
+ String packageName = getApplicationContext().getPackageName();
127
+ Intent launchIntent =
128
+ getApplicationContext().getPackageManager().getLaunchIntentForPackage(packageName);
129
+
130
+ if (launchIntent == null || launchIntent.getComponent() == null) {
131
+ return null;
132
+ }
133
+
134
+ return launchIntent.getComponent().getClassName();
135
+ }
136
+ }
@@ -0,0 +1,187 @@
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.os.Bundle;
21
+ import android.os.Parcel;
22
+ import androidx.annotation.NonNull;
23
+ import androidx.annotation.Nullable;
24
+ import java.lang.reflect.Field;
25
+ import java.lang.reflect.InvocationTargetException;
26
+ import java.util.ArrayList;
27
+ import java.util.HashMap;
28
+ import java.util.List;
29
+ import java.util.Map;
30
+ import java.util.Objects;
31
+
32
+ public class ObjectUtils {
33
+
34
+ public static @Nullable Class getClassForName(String className) {
35
+ try {
36
+ return Class.forName(className);
37
+ } catch (ClassNotFoundException e) {
38
+ return null;
39
+ }
40
+ }
41
+
42
+ public static @Nullable Object getClassInstanceFromDefaultConstructor(@Nullable Class clazz) {
43
+ Object classInstance = null;
44
+ if (clazz == null) return null;
45
+ try {
46
+ classInstance = clazz.getConstructors()[0].newInstance();
47
+ } catch (IllegalAccessException e) {
48
+ // noop
49
+ } catch (InstantiationException e) {
50
+ // noop
51
+ } catch (InvocationTargetException e) {
52
+ // noop
53
+ }
54
+ return classInstance;
55
+ }
56
+
57
+ public static Map<String, Object> getClassProperties(Class clazz) {
58
+ Map<String, Object> properties = new HashMap<>();
59
+ try {
60
+ for (Field field : clazz.getDeclaredFields()) {
61
+ field.setAccessible(true);
62
+ Object value = field.get(clazz);
63
+ if (value != null) {
64
+ properties.put(field.getName(), value);
65
+ }
66
+ }
67
+ } catch (IllegalAccessException exception) {
68
+ return null;
69
+ }
70
+ return properties;
71
+ }
72
+
73
+ public static int getInt(Object value) {
74
+ if (value instanceof Double) {
75
+ return (int) ((Double) value).doubleValue();
76
+ }
77
+
78
+ return (int) value;
79
+ }
80
+
81
+ public static long getLong(Object value) {
82
+ if (value instanceof Double) {
83
+ return (long) ((Double) value).doubleValue();
84
+ }
85
+
86
+ return (long) value;
87
+ }
88
+
89
+ public static byte[] bundleToBytes(@NonNull Bundle bundle) {
90
+ Parcel parcel = Parcel.obtain();
91
+ parcel.writeBundle(bundle);
92
+ byte[] bytes = parcel.marshall();
93
+ parcel.recycle();
94
+ return bytes;
95
+ }
96
+
97
+ @NonNull
98
+ public static Bundle bytesToBundle(byte[] bytes) {
99
+ Parcel parcel = Parcel.obtain();
100
+ parcel.unmarshall(bytes, 0, bytes.length);
101
+ parcel.setDataPosition(0);
102
+ Bundle bundle = parcel.readBundle(ObjectUtils.class.getClassLoader());
103
+ parcel.recycle();
104
+ return Objects.requireNonNull(bundle);
105
+ }
106
+
107
+ public static Map<String, Object> bundleToMap(Bundle bundle) throws IllegalArgumentException {
108
+ Map<String, Object> map = new HashMap<>();
109
+ for (String key : bundle.keySet()) {
110
+ Object value = bundle.get(key);
111
+ if (value == null) {
112
+ map.put(key, null);
113
+ } else if (value.getClass().isArray()) {
114
+ map.put(key, arrayToMap(value));
115
+ } else if (value instanceof Bundle) {
116
+ map.put(key, bundleToMap((Bundle) value));
117
+ } else if (value instanceof List) {
118
+ map.put(key, listToMap((List) value));
119
+ } else {
120
+ map.put(key, value);
121
+ }
122
+ }
123
+ return map;
124
+ }
125
+
126
+ public static ArrayList arrayToMap(Object array) throws IllegalArgumentException {
127
+ ArrayList catalystArray = new ArrayList();
128
+ if (array instanceof String[]) {
129
+ for (String v : (String[]) array) {
130
+ catalystArray.add(v);
131
+ }
132
+ } else if (array instanceof Bundle[]) {
133
+ for (Bundle v : (Bundle[]) array) {
134
+ catalystArray.add(ObjectUtils.bundleToMap(v));
135
+ }
136
+ } else if (array instanceof int[]) {
137
+ for (int v : (int[]) array) {
138
+ catalystArray.add(v);
139
+ }
140
+ } else if (array instanceof float[]) {
141
+ for (float v : (float[]) array) {
142
+ catalystArray.add(v);
143
+ }
144
+ } else if (array instanceof double[]) {
145
+ for (double v : (double[]) array) {
146
+ catalystArray.add(v);
147
+ }
148
+ } else if (array instanceof boolean[]) {
149
+ for (boolean v : (boolean[]) array) {
150
+ catalystArray.add(v);
151
+ }
152
+ } else {
153
+ throw new IllegalArgumentException("Unknown array type " + array.getClass());
154
+ }
155
+ return catalystArray;
156
+ }
157
+
158
+ public static ArrayList listToMap(List list) throws IllegalArgumentException {
159
+ ArrayList catalystArray = new ArrayList();
160
+ for (Object obj : list) {
161
+ if (obj == null) {
162
+ catalystArray.add(null);
163
+ } else if (obj.getClass().isArray()) {
164
+ catalystArray.add(arrayToMap(obj));
165
+ } else if (obj instanceof Bundle) {
166
+ catalystArray.add(ObjectUtils.bundleToMap((Bundle) obj));
167
+ } else if (obj instanceof List) {
168
+ catalystArray.add(listToMap((List) obj));
169
+ } else if (obj instanceof String) {
170
+ catalystArray.add((String) obj);
171
+ } else if (obj instanceof Integer) {
172
+ catalystArray.add((Integer) obj);
173
+ } else if (obj instanceof Number) {
174
+ catalystArray.add(((Number) obj).doubleValue());
175
+ } else if (obj instanceof Boolean) {
176
+ catalystArray.add((Boolean) obj);
177
+ } else {
178
+ throw new IllegalArgumentException("Unknown value type " + obj.getClass());
179
+ }
180
+ }
181
+ return catalystArray;
182
+ }
183
+
184
+ public interface TypedCallback<T> {
185
+ void call(T t);
186
+ }
187
+ }