@@ -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