Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(409)

Side by Side Diff: sync/util/session_utils_android.cc

Issue 11414013: Depend on stored sync session GUID for Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Simplified implementation Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sync/util/session_utils_android.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <jni.h>
6 #include <sys/system_properties.h>
7
8 #include "sync/util/session_utils_android.h"
9
10 #include "base/android/jni_android.h"
11 #include "base/android/jni_string.h"
12 #include "base/android/scoped_java_ref.h"
13 #include "base/logging.h"
14
15 using base::android::AttachCurrentThread;
16 using base::android::CheckException;
17 using base::android::ConvertUTF8ToJavaString;
18 using base::android::GetApplicationContext;
19 using base::android::GetClass;
20 using base::android::JavaRef;
21 using base::android::MethodID;
22 using base::android::ScopedJavaLocalRef;
23
24 namespace {
25
26 ScopedJavaLocalRef<jstring> GetAndroidIdJNI(
27 JNIEnv* env, const JavaRef<jobject>& content_resolver) {
28 ScopedJavaLocalRef<jclass> clazz(
29 GetClass(env, "android/provider/Settings$Secure"));
30 jmethodID j_get_string = MethodID::Get<MethodID::TYPE_STATIC>(
31 env, clazz.obj(), "getString",
32 "(Landroid/content/ContentResolver;Ljava/lang/String;)"
33 "Ljava/lang/String;");
34 ScopedJavaLocalRef<jstring> j_android_id =
35 ConvertUTF8ToJavaString(env, "android_id");
36 jstring android_id = static_cast<jstring>(
37 env->CallStaticObjectMethod(
38 clazz.obj(), j_get_string, content_resolver.obj(),
39 j_android_id.obj()));
40 CheckException(env);
41 return ScopedJavaLocalRef<jstring>(env, android_id);
42 }
43
44 ScopedJavaLocalRef<jobject> GetContentResolver(JNIEnv* env) {
45 ScopedJavaLocalRef<jclass> clazz(GetClass(env, "android/content/Context"));
46 jmethodID j_get_content_resolver_method = MethodID::Get<
47 MethodID::TYPE_INSTANCE>(
48 env, clazz.obj(), "getContentResolver",
49 "()Landroid/content/ContentResolver;");
50 jobject content_resolver = env->CallObjectMethod(
51 GetApplicationContext(), j_get_content_resolver_method);
52 CheckException(env);
53 return ScopedJavaLocalRef<jobject>(env, content_resolver);
54 }
55
56 }
57
58 namespace syncer {
59 namespace internal {
60
61 std::string GetAndroidId() {
62 JNIEnv* env = AttachCurrentThread();
63 ScopedJavaLocalRef<jstring> android_id =
64 GetAndroidIdJNI(env, GetContentResolver(env));
65 return ConvertJavaStringToUTF8(android_id);
66 }
67
68 std::string GetModel() {
69 char model[PROP_VALUE_MAX];
70 __system_property_get("ro.product.model", model);
71 return model;
72 }
73
74 } // namespace internal
75 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/util/session_utils_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698