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: set id #250

Merged
merged 8 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## XX.XX.XX
* Added a new function "setID(newDeviceId)" for managing device id changes.
arifBurakDemiray marked this conversation as resolved.
Show resolved Hide resolved

## 24.1.0

* !! Major breaking change !! The following method and its functionality is deprecated from the "UserEditor" interface and will not function anymore:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,29 @@ protected Config.DID acquireId() {
return did;
}

private void setIDInternal(String newDeviceID) {
if (Utils.isEmptyOrNull(newDeviceID)) {
L.w("[ModuleDeviceIdCore] setID, Empty id passed to setID method");
return;
}

if (getIDInternal().equals(newDeviceID)) {
L.w("[ModuleDeviceIdCore] setID, Same id passed to setID method, ignoring");
return;
}

if (getTypeInternal().equals(DeviceIdType.DEVELOPER_SUPPLIED)) {
// an ID was provided by the host app previously
// we can assume that a device ID change with merge was executed previously
// now we change it without merging
changeDeviceIdInternal(newDeviceID, DeviceIdType.DEVELOPER_SUPPLIED, false);
} else {
// SDK generated ID
// we change device ID with merge so that data is combined
changeDeviceIdInternal(newDeviceID, DeviceIdType.DEVELOPER_SUPPLIED, true);
}
}

@Override
public void stop(InternalConfig config, boolean clear) {
if (tasks != null) {
Expand Down Expand Up @@ -225,6 +248,17 @@ public String getID() {
}
}

/**
* Sets current device id to the new one.
arifBurakDemiray marked this conversation as resolved.
Show resolved Hide resolved
*
* @param newDeviceID device id to set
*/
public void setID(String newDeviceID) {
synchronized (Countly.instance()) {
setIDInternal(newDeviceID);
}
}

/**
* Returns current device id type.
*
Expand Down
Loading
Loading