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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/identity/SettingsSecureBasedIdentificationGenerator.java

Issue 12313075: [sync] Upstream the Android ProfileSyncService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 7 years, 9 months 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/identity/SettingsSecureBasedIdentificationGenerator.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/identity/SettingsSecureBasedIdentificationGenerator.java b/chrome/android/java/src/org/chromium/chrome/browser/identity/SettingsSecureBasedIdentificationGenerator.java
new file mode 100644
index 0000000000000000000000000000000000000000..e5d9b543d9e570f0e8ae73c17e2c3b93ddc7b914
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/identity/SettingsSecureBasedIdentificationGenerator.java
@@ -0,0 +1,46 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.identity;
+
+import android.content.Context;
+import android.provider.Settings;
+
+import com.google.common.annotations.VisibleForTesting;
+
+import org.chromium.chrome.browser.util.HashUtil;
+
+import javax.annotation.Nullable;
+
+/**
+ * Unique identificator implementation that uses the Settings.Secure.ANDROID_ID field and MD5
+ * hashing.
+ */
+public class SettingsSecureBasedIdentificationGenerator implements UniqueIdentificationGenerator {
+ public static final String GENERATOR_ID = "SETTINGS_SECURE_ANDROID_ID";
+ private final Context mContext;
+
+ public SettingsSecureBasedIdentificationGenerator(Context context) {
+ // Since we do not know the lifetime of the given context, we get the application context
+ // to ensure it is always possible to use it.
+ mContext = context.getApplicationContext();
+ }
+
+ @Override
+ public String getUniqueId(@Nullable String salt) {
+ String androidId = getAndroidId();
+ if (androidId == null) {
+ return "";
+ }
+
+ String md5Hash = HashUtil.getMd5Hash(
+ new HashUtil.Params(androidId).withSalt(salt));
+ return md5Hash == null ? "" : md5Hash;
+ }
+
+ @VisibleForTesting
+ String getAndroidId() {
+ return Settings.Secure.getString(mContext.getContentResolver(), Settings.Secure.ANDROID_ID);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698