Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] Add HTTP header OneSignal-Install-Id #2072

Merged
merged 4 commits into from
May 6, 2024

Conversation

jkasten2
Copy link
Member

@jkasten2 jkasten2 commented May 2, 2024

Description

One Line Summary

Add HTTP header OneSignal-Install-Id, a persistent id. Allows OneSignal's backend to know where traffic is coming from.

Details

OneSignal-Install-Id is a UUIDv4 locally generated on the device and added to as an HTTP Header to all calls made to OneSignal's backend.

State for the new installId is encapsulated in a new InstallIdService class, where it handles generating the id and persisting it. Tests were also added to ensure the persisting behavior works as expected.

Motivation

Allows the OneSignal's backend know where traffic is coming from, no matter if the SubscriptionId or OneSignalId changes or isn't available yet.

Scope

  • A new OneSignal-Install-Id HTTP header added to all network calls.
  • Added HTTP header and general improvements to logcat logging for both send and received.

Testing

Unit testing

Added InstallIdServiceTest to test the new InstallIdService class.

Manual testing

Tested on an Android 6 device, ensuring the new OneSignal-Install-Id header is sent. Restarted app to ensure the value stays the same as well.

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
    • If it is hard to explain how any codes changes are related to each other then it most likely needs to be more than one PR
  • 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.
    • Simplify with less code, followed by splitting up code into well named functions and variables, followed by adding comments to the code.
  • I have reviewed this PR myself, ensuring it meets each checklist item
    • WIP (Work In Progress) is ok, but explain what is still in progress and what you would like feedback on. Start the PR title with "WIP" to indicate this.

This change is Reviewable

@jkasten2 jkasten2 changed the title WIP [Feat] Add HTTP header OneSignal-Install-Id [Feat] Add HTTP header OneSignal-Install-Id May 2, 2024
OneSignal-Install-Id is a UUIDv4 locally generated on the device and
added to as an HTTP Header to all calls made to OneSignal's backend.
This allows the OneSignal's backend know where traffic is coming
from, no matter if the SubscriptionId or OneSignalId changes or isn't
available yet.

State for the new installId is encapsulated in a new InstallIdService
class, where it handles generating the id and persisting it. Tests
were also added to ensure the persisting behavior works as expected.
The motivation for this was we recently added a new HTTP header,
OneSignal-Install-Id, and wanted to confirm it is being sent,
however this will help if we need to debug any other headers.

This also makes a small improvement to separate out the debug
logic from production logic.
@jkasten2 jkasten2 force-pushed the feat/add-install-id-http-header branch from a942c88 to 6ed8b4d Compare May 3, 2024 00:05
Added "Got Response =" to the beginning of each line were we got a
response. This exact wording was picked since it is the same number of
characters as "Request Sent = ", this way it lines up in the logs,
making them easier to read.
@jkasten2 jkasten2 force-pushed the feat/add-install-id-http-header branch from 6ed8b4d to 37487e0 Compare May 3, 2024 20:23
Copy link
Contributor

@jinliu9508 jinliu9508 left a comment

Choose a reason for hiding this comment

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

LGTM!

I did a few tests and the install ID is included in the http request header correctly.
image

@jkasten2 jkasten2 merged commit 18a388c into main May 6, 2024
2 checks passed
@jkasten2 jkasten2 deleted the feat/add-install-id-http-header branch May 6, 2024 22:40
@jinliu9508 jinliu9508 mentioned this pull request May 7, 2024
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.

None yet

2 participants