From 1c06bb330fad4d7f3244d7fbca2cf60646e5761c Mon Sep 17 00:00:00 2001 From: Mikhail Suendukov Date: Thu, 5 Oct 2023 16:50:29 +0200 Subject: [PATCH] implement client unique id using uuid for Android --- .../microsoft/codepush/react/CodePushConstants.java | 1 + .../microsoft/codepush/react/CodePushNativeModule.java | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/android/app/src/main/java/com/microsoft/codepush/react/CodePushConstants.java b/android/app/src/main/java/com/microsoft/codepush/react/CodePushConstants.java index aecccd65c..90d432636 100644 --- a/android/app/src/main/java/com/microsoft/codepush/react/CodePushConstants.java +++ b/android/app/src/main/java/com/microsoft/codepush/react/CodePushConstants.java @@ -31,4 +31,5 @@ public class CodePushConstants { public static final String LATEST_ROLLBACK_PACKAGE_HASH_KEY = "packageHash"; public static final String LATEST_ROLLBACK_TIME_KEY = "time"; public static final String LATEST_ROLLBACK_COUNT_KEY = "count"; + public static final String CLIENT_UNIQUE_ID_KEY = "clientUniqueId"; } diff --git a/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java b/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java index 1db25328f..e996486d6 100644 --- a/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java +++ b/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java @@ -1,6 +1,7 @@ package com.microsoft.codepush.react; import android.app.Activity; +import android.content.SharedPreferences; import android.os.AsyncTask; import android.os.Handler; import android.os.Looper; @@ -34,6 +35,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.UUID; public class CodePushNativeModule extends ReactContextBaseJavaModule { private String mBinaryContentsHash = null; @@ -60,7 +62,13 @@ public CodePushNativeModule(ReactApplicationContext reactContext, CodePush codeP // Initialize module state while we have a reference to the current context. mBinaryContentsHash = CodePushUpdateUtils.getHashForBinaryContents(reactContext, mCodePush.isDebugMode()); - mClientUniqueId = Settings.Secure.getString(reactContext.getContentResolver(), Settings.Secure.ANDROID_ID); + + SharedPreferences preferences = codePush.getContext().getSharedPreferences(CodePushConstants.CODE_PUSH_PREFERENCES, 0); + mClientUniqueId = preferences.getString(CodePushConstants.CLIENT_UNIQUE_ID_KEY, null); + if (mClientUniqueId == null) { + mClientUniqueId = UUID.randomUUID().toString(); + preferences.edit().putString(CodePushConstants.CLIENT_UNIQUE_ID_KEY, mClientUniqueId).apply(); + } } @Override