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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 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 package org.chromium.chrome.browser.identity;
6
7 import android.content.Context;
8 import android.provider.Settings;
9
10 import com.google.common.annotations.VisibleForTesting;
11
12 import org.chromium.chrome.browser.util.HashUtil;
13
14 import javax.annotation.Nullable;
15
16 /**
17 * Unique identificator implementation that uses the Settings.Secure.ANDROID_ID field and MD5
18 * hashing.
19 */
20 public class SettingsSecureBasedIdentificationGenerator implements UniqueIdentif icationGenerator {
21 public static final String GENERATOR_ID = "SETTINGS_SECURE_ANDROID_ID";
22 private final Context mContext;
23
24 public SettingsSecureBasedIdentificationGenerator(Context context) {
25 // Since we do not know the lifetime of the given context, we get the ap plication context
26 // to ensure it is always possible to use it.
27 mContext = context.getApplicationContext();
28 }
29
30 @Override
31 public String getUniqueId(@Nullable String salt) {
32 String androidId = getAndroidId();
33 if (androidId == null) {
34 return "";
35 }
36
37 String md5Hash = HashUtil.getMd5Hash(
38 new HashUtil.Params(androidId).withSalt(salt));
39 return md5Hash == null ? "" : md5Hash;
40 }
41
42 @VisibleForTesting
43 String getAndroidId() {
44 return Settings.Secure.getString(mContext.getContentResolver(), Settings .Secure.ANDROID_ID);
45 }
46 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698