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

V4 to v5 upgrade will migrate app ID for wrapper SDKs #2244

Merged
merged 1 commit into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ object PreferencePlayerPurchasesKeys {
object PreferenceOneSignalKeys {
// Legacy

/**
* (String) The legacy app ID from SDKs prior to 5.
*/
const val PREFS_LEGACY_APP_ID = "GT_APP_ID"

/**
* (String) The legacy player ID from SDKs prior to 5.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,23 @@ internal class OneSignalImp : IOneSignal, IServiceProvider {
sessionModel = services.getService<SessionModelStore>().model
operationRepo = services.getService<IOperationRepo>()

// initWithContext is called by our internal services/receivers/activites but they do not provide
var forceCreateUser = false

// initWithContext is called by our internal services/receivers/activities but they do not provide
// an appId (they don't know it). If the app has never called the external initWithContext
// prior to our services/receivers/activities we will blow up, as no appId has been established.
if (appId == null && !configModel!!.hasProperty(ConfigModel::appId.name)) {
Logging.warn("initWithContext called without providing appId, and no appId has been established!")
return false
val legacyAppId = getLegacyAppId()
if (legacyAppId == null) {
Logging.warn("initWithContext called without providing appId, and no appId has been established!")
return false
} else {
Logging.debug("initWithContext: using cached legacy appId $legacyAppId")
forceCreateUser = true
configModel!!.appId = legacyAppId
}
}

var forceCreateUser = false
// if the app id was specified as input, update the config model with it
if (appId != null) {
if (!configModel!!.hasProperty(ConfigModel::appId.name) || configModel!!.appId != appId) {
Expand Down Expand Up @@ -418,6 +426,16 @@ internal class OneSignalImp : IOneSignal, IServiceProvider {
}
}

/**
* Returns the cached app ID from v4 of the SDK, if available.
*/
private fun getLegacyAppId(): String? {
return preferencesService.getString(
PreferenceStores.ONESIGNAL,
PreferenceOneSignalKeys.PREFS_LEGACY_APP_ID,
)
}

private fun createAndSwitchToNewUser(
suppressBackendOperation: Boolean = false,
modify: (
Expand Down
Loading