Skip to content

Commit

Permalink
fix: SQDSDK-5597 - Get ad id in background thread (#463)
Browse files Browse the repository at this point in the history
* fix: only delete branch if all succeeds

* Get ad id in background thread

* Removing unused import

---------

Co-authored-by: Sam Dozor <[email protected]>
  • Loading branch information
markvdouw and Sam Dozor authored Jan 29, 2024
1 parent c7287b6 commit 679d987
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class UpdateAdIdIdentityTest : BaseCleanInstallEachTest() {
)

// execute CheckAdIdRunnable without a current user
AppStateManager.CheckAdIdRunnable("newAdId", "oldAdId").run()
MParticle.getInstance()!!.Internal().configManager
AppStateManager.CheckAdIdRunnable(MParticle.getInstance()!!.Internal().configManager).run()
assertNull(MParticle.getInstance()!!.Identity().currentUser)

// set a current user
Expand All @@ -44,8 +45,7 @@ class UpdateAdIdIdentityTest : BaseCleanInstallEachTest() {
request.asIdentityRequest().body.identity_changes.let {
it.size == 1 &&
it[0].let { identityChange ->
identityChange["new_value"] == "newAdId" &&
identityChange["old_value"] == "oldAdId"
identityChange["new_value"] == "someId"
}
}
}.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,7 @@ public void onActivityResumed(Activity activity) {
initialize(mCurrentActivityName, previousSessionUri, previousSessionParameters, previousSessionPackage);
} else if (isBackgrounded() && mLastStoppedTime.get() > 0) {
isBackToForeground = true;
MPUtility.AdIdInfo adIdInfo = MPUtility.getAdIdInfo(mContext);
String currentGoogleAdId = (adIdInfo == null ? null : (adIdInfo.isLimitAdTrackingEnabled ? null : adIdInfo.id));
mMessageManager.postToMessageThread(new CheckAdIdRunnable(currentGoogleAdId, mConfigManager.getPreviousAdId()));
mMessageManager.postToMessageThread(new CheckAdIdRunnable(mConfigManager));
logStateTransition(Constants.StateTransitionType.STATE_TRANS_FORE,
mCurrentActivityName,
mLastStoppedTime.get() - mLastForegroundTime,
Expand Down Expand Up @@ -446,16 +444,17 @@ public WeakReference<Activity> getCurrentActivity() {
}

static class CheckAdIdRunnable implements Runnable {
String currentAdId;
String previousAdId;
ConfigManager configManager;

CheckAdIdRunnable(@Nullable String currentAdId, @Nullable String previousAdId) {
this.currentAdId = currentAdId;
this.previousAdId = previousAdId;
CheckAdIdRunnable(@Nullable ConfigManager configManager) {
this.configManager = configManager;
}

@Override
public void run() {
MPUtility.AdIdInfo adIdInfo = MPUtility.getAdIdInfo(MParticle.getInstance().Internal().getAppStateManager().mContext);
String currentAdId = (adIdInfo == null ? null : (adIdInfo.isLimitAdTrackingEnabled ? null : adIdInfo.id));
String previousAdId = configManager.getPreviousAdId();
if (currentAdId != null && !currentAdId.equals(previousAdId)) {
MParticle instance = MParticle.getInstance();
if (instance != null) {
Expand Down

0 comments on commit 679d987

Please sign in to comment.