Skip to content

Commit

Permalink
feat: set id
Browse files Browse the repository at this point in the history
  • Loading branch information
arifBurakDemiray committed Mar 21, 2024
1 parent 04894bf commit d7a513a
Show file tree
Hide file tree
Showing 2 changed files with 201 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,27 @@ 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 current type is 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
// else
// SDK generated ID
// we change device ID with merge so that data is combined
changeDeviceIdInternal(newDeviceID, DeviceIdType.DEVELOPER_SUPPLIED, !getTypeInternal().equals(DeviceIdType.DEVELOPER_SUPPLIED));
}

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

/**
* Sets current device id to the new one.
*
* @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 d7a513a

Please sign in to comment.