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.
5 package org.chromium.chrome.browser.identity;
7 import android.content.Context;
8 import android.provider.Settings;
10 import com.google.common.annotations.VisibleForTesting;
12 import org.chromium.chrome.browser.util.HashUtil;
14 import javax.annotation.Nullable;
17 * Unique identificator implementation that uses the Settings.Secure.ANDROID_ID field and MD5
20 public class SettingsSecureBasedIdentificationGenerator implements UniqueIdentificationGenerator {
21 public static final String GENERATOR_ID = "SETTINGS_SECURE_ANDROID_ID";
22 private final Context mContext;
24 public SettingsSecureBasedIdentificationGenerator(Context context) {
25 // Since we do not know the lifetime of the given context, we get the application context
26 // to ensure it is always possible to use it.
27 mContext = context.getApplicationContext();
31 public String getUniqueId(@Nullable String salt) {
32 String androidId = getAndroidId();
33 if (androidId == null) {
37 String md5Hash = HashUtil.getMd5Hash(
38 new HashUtil.Params(androidId).withSalt(salt));
39 return md5Hash == null ? "" : md5Hash;
43 String getAndroidId() {
44 return Settings.Secure.getString(mContext.getContentResolver(), Settings.Secure.ANDROID_ID);