EMMA Coverage Report (generated Fri Aug 23 16:39:17 PDT 2013)
[all classes][org.chromium.chrome.browser.identity]

COVERAGE SUMMARY FOR SOURCE FILE [SettingsSecureBasedIdentificationGenerator.java]

nameclass, %method, %block, %line, %
SettingsSecureBasedIdentificationGenerator.java100% (1/1)67%  (2/3)76%  (26/34)87%  (7.8/9)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SettingsSecureBasedIdentificationGenerator100% (1/1)67%  (2/3)76%  (26/34)87%  (7.8/9)
getAndroidId (): String 0%   (0/1)0%   (0/6)0%   (0/1)
getUniqueId (String): String 100% (1/1)90%  (19/21)97%  (4.8/5)
SettingsSecureBasedIdentificationGenerator (Context): void 100% (1/1)100% (7/7)100% (3/3)

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 
5package org.chromium.chrome.browser.identity;
6 
7import android.content.Context;
8import android.provider.Settings;
9 
10import com.google.common.annotations.VisibleForTesting;
11 
12import org.chromium.chrome.browser.util.HashUtil;
13 
14import javax.annotation.Nullable;
15 
16/**
17 * Unique identificator implementation that uses the Settings.Secure.ANDROID_ID field and MD5
18 * hashing.
19 */
20public class SettingsSecureBasedIdentificationGenerator implements UniqueIdentificationGenerator {
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 application 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}

[all classes][org.chromium.chrome.browser.identity]
EMMA 2.0.5312 (C) Vladimir Roubtsov