Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrachytski <siarhei.rachytski@gmail.com>2012-04-17 18:13:40 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:37:28 +0300
commit465184b9d8317d4829ed4060fb0b1d4698ada053 (patch)
tree94aa802cffc0e5be5d94b20cf74bfe4de3a2c52b /android/jni/com/mapswithme/platform/Platform.cpp
parent7964b599dd0728adc682bd79de147ca5272b728a (diff)
[android] implemented UniqueClientId
Diffstat (limited to 'android/jni/com/mapswithme/platform/Platform.cpp')
-rw-r--r--android/jni/com/mapswithme/platform/Platform.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/android/jni/com/mapswithme/platform/Platform.cpp b/android/jni/com/mapswithme/platform/Platform.cpp
index abec4e52d4..b93524de67 100644
--- a/android/jni/com/mapswithme/platform/Platform.cpp
+++ b/android/jni/com/mapswithme/platform/Platform.cpp
@@ -2,6 +2,7 @@
#include "../core/jni_helper.hpp"
+#include "../../../../../platform/settings.hpp"
#include "../../../../../base/logging.hpp"
#include "../../../../../std/algorithm.hpp"
@@ -83,6 +84,53 @@ int Platform::PreCachingDepth() const
return m_impl->m_preCachingDepth;
}
+string Platform::UniqueClientId() const
+{
+ string res;
+ if (!Settings::Get("UniqueClientID", res))
+ {
+ JNIEnv * env = jni::GetEnv();
+ if (!env)
+ {
+ LOG(LWARNING, ("Can't get JNIEnv"));
+ return "";
+ }
+
+ jclass uuidClass = env->FindClass("java/util/UUID");
+ ASSERT(uuidClass, ("Can't find java class java/util/UUID"));
+
+ jmethodID randomUUIDId = env->GetStaticMethodID(uuidClass, "randomUUID", "()Ljava/util/UUID;");
+ ASSERT(randomUUIDId, ("Can't find static java/util/UUID.randomUUIDId() method"));
+
+ jobject uuidInstance = env->CallStaticObjectMethod(uuidClass, randomUUIDId);
+ ASSERT(uuidInstance, ("UUID.randomUUID() returned NULL"));
+
+ jmethodID toStringId = env->GetMethodID(uuidClass, "toString", "()Ljava/lang/String;");
+ ASSERT(toStringId, ("Can't find java/util/UUID.toString() method"));
+
+ jstring uuidString = (jstring)env->CallObjectMethod(uuidInstance, toStringId);
+ ASSERT(uuidString, ("UUID.toString() returned NULL"));
+
+ char const * uuidUtf8 = env->GetStringUTFChars(uuidString, 0);
+
+ string result("en");
+
+ if (uuidUtf8 != 0)
+ {
+ result = uuidUtf8;
+ env->ReleaseStringUTFChars(uuidString, uuidUtf8);
+ }
+
+ result = HashUniqueID(result);
+
+ Settings::Set("UniqueClientID", result);
+ }
+
+ Settings::Get("UniqueClientID", res);
+
+ return res;
+}
+
namespace android
{
Platform::~Platform()