Skip to content

Potentially dangerous cast inside Onesignal.Log method #5

@daisy1754

Description

@daisy1754

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions