Skip to content

Commit b8ceb31

Browse files
committed
Create OSBackgroundManager
* Make OSNotificationDataController extend OSBackgroundManager * OSBackgroundManager will be responsible of runRunnableOnThread method
1 parent e881741 commit b8ceb31

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.onesignal
2+
3+
open class OSBackgroundManager {
4+
5+
fun runRunnableOnThread(runnable: Runnable, threadName: String) {
6+
// DB access is a heavy task, dispatch to a thread if running on main thread
7+
if (OSUtils.isRunningOnMainThread()) Thread(runnable, threadName).start() else runnable.run()
8+
}
9+
}

OneSignalSDK/onesignal/src/main/java/com/onesignal/OSNotificationDataController.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import java.lang.ref.WeakReference;
1414

15-
class OSNotificationDataController {
15+
class OSNotificationDataController extends OSBackgroundManager {
1616

1717
private final static long NOTIFICATION_CACHE_DATA_LIFETIME = 604_800L; // 7 days in second
1818

@@ -58,7 +58,7 @@ public void run() {
5858
}
5959
};
6060

61-
runRunnableOnThread(notificationCacheCleaner);
61+
runRunnableOnThread(notificationCacheCleaner, OS_NOTIFICATIONS_THREAD);
6262
}
6363

6464
void clearOneSignalNotifications(final WeakReference<Context> weakReference) {
@@ -105,7 +105,7 @@ public void run() {
105105
}
106106
};
107107

108-
runRunnableOnThread(runClearOneSignalNotifications);
108+
runRunnableOnThread(runClearOneSignalNotifications, OS_NOTIFICATIONS_THREAD);
109109
}
110110

111111
void removeGroupedNotifications(final String group, final WeakReference<Context> weakReference) {
@@ -154,7 +154,7 @@ public void run() {
154154
}
155155
};
156156

157-
runRunnableOnThread(runCancelGroupedNotifications);
157+
runRunnableOnThread(runCancelGroupedNotifications, OS_NOTIFICATIONS_THREAD);
158158
}
159159

160160
void removeNotification(final int id, final WeakReference<Context> weakReference) {
@@ -185,7 +185,7 @@ public void run() {
185185
}
186186
};
187187

188-
runRunnableOnThread(runCancelNotification);
188+
runRunnableOnThread(runCancelNotification, OS_NOTIFICATIONS_THREAD);
189189
}
190190

191191
void notValidOrDuplicated(JSONObject jsonPayload, final InvalidOrDuplicateNotificationCallback callback) {
@@ -240,15 +240,7 @@ public void run() {
240240
}
241241
};
242242

243-
runRunnableOnThread(runCancelNotification);
244-
}
245-
246-
private void runRunnableOnThread(Runnable runnable) {
247-
// DB access is a heavy task, dispatch to a thread if running on main thread
248-
if (OSUtils.isRunningOnMainThread())
249-
new Thread(runnable, OS_NOTIFICATIONS_THREAD).start();
250-
else
251-
runnable.run();
243+
runRunnableOnThread(runCancelNotification, OS_NOTIFICATIONS_THREAD);
252244
}
253245

254246
interface InvalidOrDuplicateNotificationCallback {

0 commit comments

Comments
 (0)