Skip to content

Commit c6db766

Browse files
feat: set id (#250)
* 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
1 parent 04894bf commit c6db766

File tree

3 files changed

+236
-24
lines changed

3 files changed

+236
-24
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## XX.XX.XX
2+
3+
* Added a new function "setID(newDeviceId)" for managing device id changes according to the device ID Type.
4+
15
## 24.1.0
26

37
* !! Major breaking change !! The following method and its functionality is deprecated from the "UserEditor" interface and will not function anymore:

sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleDeviceIdCore.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,29 @@ protected Config.DID acquireId() {
195195
return did;
196196
}
197197

198+
private void setIDInternal(String newDeviceID) {
199+
if (Utils.isEmptyOrNull(newDeviceID)) {
200+
L.w("[ModuleDeviceIdCore] setID, Empty id passed to setID method");
201+
return;
202+
}
203+
204+
if (getIDInternal().equals(newDeviceID)) {
205+
L.w("[ModuleDeviceIdCore] setID, Same id passed to setID method, ignoring");
206+
return;
207+
}
208+
209+
if (getTypeInternal().equals(DeviceIdType.DEVELOPER_SUPPLIED)) {
210+
// an ID was provided by the host app previously
211+
// we can assume that a device ID change with merge was executed previously
212+
// now we change it without merging
213+
changeDeviceIdInternal(newDeviceID, DeviceIdType.DEVELOPER_SUPPLIED, false);
214+
} else {
215+
// SDK generated ID
216+
// we change device ID with merge so that data is combined
217+
changeDeviceIdInternal(newDeviceID, DeviceIdType.DEVELOPER_SUPPLIED, true);
218+
}
219+
}
220+
198221
@Override
199222
public void stop(InternalConfig config, boolean clear) {
200223
if (tasks != null) {
@@ -225,6 +248,18 @@ public String getID() {
225248
}
226249
}
227250

251+
/**
252+
* Sets device ID according to the device ID Type.
253+
* If previous ID was Developer Supplied sets it without merge, otherwise with merge.
254+
*
255+
* @param newDeviceID device id to set
256+
*/
257+
public void setID(String newDeviceID) {
258+
synchronized (Countly.instance()) {
259+
setIDInternal(newDeviceID);
260+
}
261+
}
262+
228263
/**
229264
* Returns current device id type.
230265
*

0 commit comments

Comments
 (0)