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 org.chromium.base.VisibleForTesting;
11 import org.chromium.chrome.browser.util.HashUtil;
13 import javax.annotation.Nullable;
16 * Unique identificator implementation that uses the Settings.Secure.ANDROID_ID field and MD5
19 public class SettingsSecureBasedIdentificationGenerator implements UniqueIdentificationGenerator {
20 public static final String GENERATOR_ID = "SETTINGS_SECURE_ANDROID_ID";
21 private final Context mContext;
23 public SettingsSecureBasedIdentificationGenerator(Context context) {
24 // Since we do not know the lifetime of the given context, we get the application context
25 // to ensure it is always possible to use it.
26 mContext = context.getApplicationContext();
30 public String getUniqueId(@Nullable String salt) {
31 String androidId = getAndroidId();
32 if (androidId == null) {
36 String md5Hash = HashUtil.getMd5Hash(
37 new HashUtil.Params(androidId).withSalt(salt));
38 return md5Hash == null ? "" : md5Hash;
42 String getAndroidId() {
43 return Settings.Secure.getString(mContext.getContentResolver(), Settings.Secure.ANDROID_ID);