Skip to content

Commit

Permalink
feat: set id (#250)
Browse files Browse the repository at this point in the history
* feat: set id

* feat: changelog

* doc: comments

* refactor: spread out

* feat: pr changes

* feat: combine tests

* feat: add comment to test setId

* Update ModuleDeviceIdTests.java
  • Loading branch information
arifBurakDemiray authored Apr 8, 2024
1 parent 04894bf commit c6db766
Show file tree
Hide file tree
Showing 3 changed files with 236 additions and 24 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## XX.XX.XX

* Added a new function "setID(newDeviceId)" for managing device id changes according to the device ID Type.

## 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,18 @@ public String getID() {
}
}

/**
* Sets device ID according to the device ID Type.
* If previous ID was Developer Supplied sets it without merge, otherwise with merge.
*
* @param newDeviceID device id to set
*/
public void setID(String newDeviceID) {
synchronized (Countly.instance()) {
setIDInternal(newDeviceID);
}
}

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

0 comments on commit c6db766

Please sign in to comment.