Skip to content

Commit a6b5a3b

Browse files
[Sdk 518] Print warning on random UUID and deprecate additional device id methods (#25)
* - Login and logout deprecated - utils 'isEmpty' method rename to 'isEmptyorNull' * - changelog updated - added warning when sdk generate a random uuid * Update ModuleDeviceIdCore.java * Update CHANGELOG.md Co-authored-by: Zahid Zafar <> Co-authored-by: ArtursKadikis <[email protected]>
1 parent f968acf commit a6b5a3b

File tree

9 files changed

+26
-27
lines changed

9 files changed

+26
-27
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
22.06.0
2+
* The "resetDeviceId", "login", and "logout" have been deprecated.
23
* ! Minor breaking change ! The following methods and their functionality is removed from the "Config" class: "enableTestMode", "disableTestMode" and "isTestModeEnabled". The "TestMode" functionality is being removed from the SDK.
34

45
20.11.5

sdk-java/src/main/java/ly/count/sdk/java/Config.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ public Config setDeviceIdStrategy(DeviceIdStrategy strategy) {
647647
* @return {@code this} instance for method chaining
648648
*/
649649
public Config setCustomDeviceId(String customDeviceId) {
650-
if (Utils.isEmpty(customDeviceId)) {
650+
if (Utils.isEmptyOrNull(customDeviceId)) {
651651
System.out.print("[ConfigCore] DeviceIdStrategy.CUSTOM_ID strategy cannot be used without device id specified");
652652
} else {
653653
this.customDeviceId = customDeviceId;
@@ -716,7 +716,7 @@ public Config setRequestQueueMaxSize(int requestQueueMaxSize) {
716716
* @return {@code this} instance for method chaining
717717
*/
718718
public Config enableParameterTamperingProtection(String salt) {
719-
if (Utils.isEmpty(salt)) {
719+
if (Utils.isEmptyOrNull(salt)) {
720720
System.out.print("[ConfigCore] Salt cannot be empty in enableParameterTamperingProtection");
721721
} else {
722722
this.salt = salt;
@@ -854,7 +854,7 @@ public Config setSessionCooldownPeriod(int sessionCooldownPeriod) {
854854
* @return {@code this} instance for method chaining
855855
*/
856856
public Config setSdkName(String sdkName) {
857-
if (Utils.isEmpty(sdkName)) {
857+
if (Utils.isEmptyOrNull(sdkName)) {
858858
System.out.print("[ConfigCore] sdkName cannot be empty");
859859
} else {
860860
this.sdkName = sdkName;
@@ -869,7 +869,7 @@ public Config setSdkName(String sdkName) {
869869
* @return {@code this} instance for method chaining
870870
*/
871871
public Config setSdkVersion(String sdkVersion) {
872-
if (Utils.isEmpty(sdkVersion)) {
872+
if (Utils.isEmptyOrNull(sdkVersion)) {
873873
System.out.print("[ConfigCore] sdkVersion cannot be empty");
874874
} else {
875875
this.sdkVersion = sdkVersion;
@@ -884,7 +884,7 @@ public Config setSdkVersion(String sdkVersion) {
884884
* @return {@code this} instance for method chaining
885885
*/
886886
public Config setApplicationName(String name) {
887-
if (Utils.isEmpty(name)) {
887+
if (Utils.isEmptyOrNull(name)) {
888888
System.out.print("[ConfigCore] name cannot be empty");
889889
} else {
890890
this.applicationName = name;
@@ -899,7 +899,7 @@ public Config setApplicationName(String name) {
899899
* @return {@code this} instance for method chaining
900900
*/
901901
public Config setApplicationVersion(String version) {
902-
if (Utils.isEmpty(version)) {
902+
if (Utils.isEmptyOrNull(version)) {
903903
System.out.print("[ConfigCore] version cannot be empty");
904904
} else {
905905
this.applicationVersion = version;
@@ -989,7 +989,7 @@ public Config setNetworkImportantRequestCooldown(int milliseconds) {
989989
* @return {@code this} instance for method chaining
990990
*/
991991
public Config addPublicKeyPin(String pemEncodedPublicKey) {
992-
if (Utils.isEmpty(pemEncodedPublicKey)) {
992+
if (Utils.isEmptyOrNull(pemEncodedPublicKey)) {
993993
System.out.print("[ConfigCore] pemEncodedPublicKey cannot be empty");
994994
} else {
995995
if (publicKeyPins == null) {
@@ -1021,7 +1021,7 @@ public Config addPublicKeyPin(String pemEncodedPublicKey) {
10211021
* @return {@code this} instance for method chaining
10221022
*/
10231023
public Config addCertificatePin(String pemEncodedCertificate) {
1024-
if (Utils.isEmpty(pemEncodedCertificate)) {
1024+
if (Utils.isEmptyOrNull(pemEncodedCertificate)) {
10251025
System.out.print("[ConfigCore] pemEncodedCertificate cannot be empty");
10261026
} else {
10271027
if (certificatePins == null) {

sdk-java/src/main/java/ly/count/sdk/java/Usage.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public interface Usage {
111111
View view(String name);
112112

113113
/**
114+
* @deprecated
114115
* Login function to set device (user) id on Countly server to the string specified here.
115116
* Closes current session, then starts new one automatically if {@link Config#autoSessionsTracking} is on, acquires device id.
116117
*
@@ -119,6 +120,7 @@ public interface Usage {
119120
Usage login(String id);
120121

121122
/**
123+
* @deprecated
122124
* Logout function to make current user anonymous (that is with random id according to
123125
* {@link Config#deviceIdStrategy} and such). Obviously makes sense only after a call to {@link #login(String)},
124126
* so it throws error or does nothing (depending on {@link Config#testMode}) if current id wasn't set using {@link #login(String)}.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public Map<String, String> getSegments() {
165165
public List<String> getLogs() {
166166
try {
167167
String logs = this.data.getString("_logs");
168-
return Utils.isEmpty(logs) ? null : Arrays.asList(logs.split("\n"));
168+
return Utils.isEmptyOrNull(logs) ? null : Arrays.asList(logs.split("\n"));
169169
} catch (JSONException e) {
170170
return null;
171171
}
@@ -230,7 +230,7 @@ public static String getStoragePrefix() {
230230
public CrashImplCore putMetricsCore(CtxCore ctx, Long runningTime) {
231231
String version = ctx.getConfig().getApplicationVersion();
232232
return add("_os", DeviceCore.dev.getOS())
233-
.add("_app_version", Utils.isEmpty(version) ? "0.0" : version)
233+
.add("_app_version", Utils.isEmptyOrNull(version) ? "0.0" : version)
234234
.add("_os_version", DeviceCore.dev.getOSVersion())
235235
.add("_ram_current", DeviceCore.dev.getRAMAvailable())
236236
.add("_ram_total", DeviceCore.dev.getRAMTotal())

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ public void onContextAcquired(final CtxCore ctx) {
120120
@Override
121121
public void call(Config.DID id) throws Exception {
122122
if (id != null) {
123+
if(id.strategy == Config.DID.STRATEGY_UUID) {
124+
L.i("During init, custom device id was not provided. SDK has generated a random device id.");
125+
}
123126
L.d("[ModuleDeviceIdCore] Got device id: " + id);
124127
SDKCore.instance.onDeviceId(ctx, id, null);
125128
} else {
@@ -254,7 +257,7 @@ private void sendDIDSignal(CtxCore ctx, Config.DID id, Config.DID old) {
254257
* @param id device id to change to
255258
*/
256259
public void login(CtxCore ctx, String id) {
257-
if (Utils.isEmpty(id)) {
260+
if (Utils.isEmptyOrNull(id)) {
258261
L.e("[ModuleDeviceIdCore] Empty id passed to login method");
259262
} else {
260263
final Config.DID old = ctx.getConfig().getDeviceId();
@@ -303,7 +306,7 @@ public void call(Config.DID id) throws Exception {
303306
* @param id new user id
304307
*/
305308
public void changeDeviceId(CtxCore ctx, String id, boolean withMerge) {
306-
if (Utils.isEmpty(id)) {
309+
if (Utils.isEmptyOrNull(id)) {
307310
L.e("[ModuleDeviceIdCore] Empty id passed to resetId method");
308311
} else {
309312
final Config.DID old = ctx.getConfig().getDeviceId();

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@
1313
import java.util.List;
1414
import java.util.Map;
1515

16-
import ly.count.sdk.java.internal.Log;
17-
import ly.count.sdk.java.internal.Storable;
18-
import ly.count.sdk.java.internal.Storage;
19-
import ly.count.sdk.java.internal.Utils;
20-
2116
abstract class SDKStorage extends SDKLifecycle {
2217
private static final String FILE_NAME_PREFIX = "[CLY]";
2318
private static final String FILE_NAME_SEPARATOR = "_";
@@ -41,7 +36,7 @@ private static String getName(Storable storable) {
4136
}
4237

4338
private static String getName(String ...names) {
44-
if (names == null || names.length == 0 || Utils.isEmpty(names[0])) {
39+
if (names == null || names.length == 0 || Utils.isEmptyOrNull(names[0])) {
4540
return FILE_NAME_PREFIX;
4641
} else {
4742
StringBuilder prefix = new StringBuilder(FILE_NAME_PREFIX);
@@ -246,7 +241,7 @@ private String[] getFileList(ly.count.sdk.java.internal.CtxCore context){
246241

247242
@Override
248243
public List<Long> storableList(ly.count.sdk.java.internal.CtxCore context, String prefix, int slice) {
249-
if (Utils.isEmpty(prefix)) {
244+
if (Utils.isEmptyOrNull(prefix)) {
250245
L.e("[SDKStorage] Cannot get list of ids without prefix");
251246
}
252247
prefix = prefix + FILE_NAME_SEPARATOR;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ HttpURLConnection connection(final Request request, final User user) throws IOEx
141141

142142
String path = config.getServerURL().toString() + endpoint;
143143
String picture = request.params.remove(UserEditorImpl.PICTURE_PATH);
144-
boolean usingGET = !config.isUsePOST() && request.isGettable(config.getServerURL()) && Utils.isEmpty(picture);
144+
boolean usingGET = !config.isUsePOST() && request.isGettable(config.getServerURL()) && Utils.isEmptyOrNull(picture);
145145

146146
if (usingGET && config.getParameterTamperingProtectionSalt() != null) {
147147
request.params.add(CHECKSUM, Utils.digestHex(PARAMETER_TAMPERING_DIGEST, request.params.toString() + config.getParameterTamperingProtectionSalt()));

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public static Field findField(Class cls, String name) throws NoSuchFieldExceptio
105105
* @param str string to check
106106
* @return true if null or empty string, false otherwise
107107
*/
108-
public static boolean isEmpty(String str) {
108+
public static boolean isEmptyOrNull(String str) {
109109
return str == null || "".equals(str);
110110
}
111111

@@ -116,7 +116,7 @@ public static boolean isEmpty(String str) {
116116
* @return false if null or empty string, true otherwise
117117
*/
118118
public static boolean isNotEmpty(String str) {
119-
return !isEmpty(str);
119+
return !isEmptyOrNull(str);
120120
}
121121

122122
public static boolean isNotEqual(Object a, Object b) {

sdk-java/src/test/java/ly/count/sdk/java/internal/UtilsTests.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
import java.util.ArrayList;
1111
import java.util.Collection;
1212

13-
import ly.count.sdk.java.internal.Utils;
14-
1513
@RunWith(JUnit4.class)
1614
public class UtilsTests {
1715
@Before
@@ -192,9 +190,9 @@ public boolean equals(Object obj) {
192190

193191
@Test
194192
public void isEmpty() {
195-
junit.framework.Assert.assertFalse(Utils.isEmpty("notthatempty"));
196-
junit.framework.Assert.assertTrue(Utils.isEmpty(""));
197-
junit.framework.Assert.assertTrue(Utils.isEmpty(null));
193+
junit.framework.Assert.assertFalse(Utils.isEmptyOrNull("notthatempty"));
194+
junit.framework.Assert.assertTrue(Utils.isEmptyOrNull(""));
195+
junit.framework.Assert.assertTrue(Utils.isEmptyOrNull(null));
198196
}
199197

200198
@Test

0 commit comments

Comments
 (0)