Fix issue with migration from v4 to v5 when obfuscation is used by the app #1901
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
One Line Summary
Fix issue with migration from v4 to v5 when obfuscation is used by the app
Details
The v5 SDK will read/write to a preference store called "OneSignal", it is defined as a string so it is always expected a file at /data/data/<app_id>/shared_prefs/OneSignal.xml . The v4 SDK however will read/write to a preference store defined as OneSignal.class.getSimpleName(); (see here).
When an app is using ProGuard (or similar) the OneSignal class name can be renamed, as a result the underlying preference store for v4 can be named anything. So when going from v4 -> v5 (or even different builds of v4 to v4), on startup the SDK does not find the preference store and believes it is starting "fresh", resulting in a new subscription for the device.
Since we don't know what name was used, the underlying fix is to scan the existing preference stores to find the correct one and rename it to "OneSignal.xml", which is the static name as of v5.
Motivation
Desire to only have 1 subscription per device across app builds.
Scope
This fix is a startup/initialization fix targeting devices that have a new app install migrating from SDK v4 to SDK v5.
Testing
Manual testing
OneSignal.initWithContext
is called the preference file should be appropriately renamed, and the subscriber created from the v4 SDK version is used by the v5 SDK.Affected code checklist
Checklist
Overview
Testing
Final pass
This change is