https://github.com/one-signal/OneSignal-Android-SDK/blob/b05676b9f4844bac4658bab5021ed0b94dd997f1/OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java#L378
Since context here is Context type, (Activity)context can raise RuntimeException if caller passes non-Activity context as argument. OneSignal.Log method is public, so anyone can call it.
I believe right approach here is implement own runOnUiThread method, rather than relying on Activity's method. Following is part of platform code, and as you can see runOnUiThread method can be implemented with a few lines of code.
public final void runOnUiThread(Runnable action) {
if (Thread.currentThread() != mUiThread) {
mHandler.post(action);
} else {
action.run();
}
}
Another separate but related issue is that, OneSignal.init method requires Activity as argument. I feel like this should be Context as you don't really need Activity here especially after you fix this bug.
https://github.com/one-signal/OneSignal-Android-SDK/blob/b05676b9f4844bac4658bab5021ed0b94dd997f1/OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java#L378
Since context here is Context type,
(Activity)contextcan raise RuntimeException if caller passes non-Activity context as argument. OneSignal.Log method is public, so anyone can call it.I believe right approach here is implement own runOnUiThread method, rather than relying on Activity's method. Following is part of platform code, and as you can see runOnUiThread method can be implemented with a few lines of code.
Another separate but related issue is that, OneSignal.init method requires
Activityas argument. I feel like this should beContextas you don't really needActivityhere especially after you fix this bug.