Skip to content

Conversation

@nan-li
Copy link
Contributor

@nan-li nan-li commented May 7, 2025

Description

One Line Summary

Obey log level set by developers and also fixes NPE crash when some malformed logs were actually invoked.

Details

Motivation

Scope

Logging only
The bug was some usages of android.util.Log had arguments conflated with our OneSignal Logging. OneSignalLog's 2nd parameter is a nullable throwable, but android.util.Log's 1st argument is a string TAG to represent your collection, and the 2nd parameter is the actual print statement.

Testing

Unit testing

Manual testing

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
  • I have reviewed this PR myself, ensuring it meets each checklist item

This change is Reviewable

@nan-li nan-li changed the title Fix: Android use OneSignalLog, don't use android.util.Log, fix log crash Fix: Android use OneSignalLog, don't use android.util.Log, also fixes crash May 7, 2025
@nan-li nan-li force-pushed the fix/android_logging branch 2 times, most recently from ee6df90 to d6dda9c Compare May 7, 2025 21:42
@nan-li nan-li changed the base branch from main to ci-update-ubuntu May 7, 2025 22:41
* Obey log level set by developers and don't use android.util.Log to log information.
* Also some usages of android.util.Log were incorrect (by not setting TAG) and would get a NPE
private void removeHandlers() {
if(!oneSignalInitDone) {
Log.i("OneSignal", "OneSignal React-Native SDK not initialized yet. Could not remove handlers.");
Logging.debug("OneSignal React-Native SDK not initialized yet. Could not remove handlers.", null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, no need to pass in null as the 2nd parameter to our OneSignal Logging functions, it as optional parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are calling this Kotlin-defined method from Java, we have to pass the 2nd parameter.

@nan-li nan-li changed the base branch from ci-update-ubuntu to main May 8, 2025 17:00
@nan-li nan-li merged commit cee22e6 into main May 8, 2025
2 checks passed
This was referenced May 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants