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

COVERAGE SUMMARY FOR SOURCE FILE [BuildInfo.java]

nameclass, %method, %block, %line, %
BuildInfo.java100% (1/1)91%  (10/11)79%  (84/107)73%  (24.7/34)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BuildInfo100% (1/1)91%  (10/11)79%  (84/107)73%  (24.7/34)
BuildInfo (): void 0%   (0/1)0%   (0/3)0%   (0/2)
getPackageVersionCode (Context): String 100% (1/1)68%  (19/28)70%  (7/10)
getPackageVersionName (Context): String 100% (1/1)77%  (17/22)75%  (6/8)
getPackageLabel (Context): String 100% (1/1)83%  (19/23)66%  (4/6)
getPackageName (Context): String 100% (1/1)85%  (11/13)86%  (1.7/2)
getAndroidBuildFingerprint (): String 100% (1/1)100% (8/8)100% (1/1)
getAndroidBuildId (): String 100% (1/1)100% (2/2)100% (1/1)
getBrand (): String 100% (1/1)100% (2/2)100% (1/1)
getDevice (): String 100% (1/1)100% (2/2)100% (1/1)
getDeviceModel (): String 100% (1/1)100% (2/2)100% (1/1)
getSdkInt (): int 100% (1/1)100% (2/2)100% (1/1)

1// Copyright (c) 2012 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.base;
6 
7import android.content.Context;
8import android.content.pm.ApplicationInfo;
9import android.content.pm.PackageInfo;
10import android.content.pm.PackageManager;
11import android.content.pm.PackageManager.NameNotFoundException;
12import android.os.Build;
13import android.util.Log;
14 
15import org.chromium.base.CalledByNative;
16 
17/**
18 * BuildInfo is a utility class providing easy access to {@link PackageInfo}
19 * information. This is primarly of use for accessesing package information
20 * from native code.
21 */
22public class BuildInfo {
23    private static final String TAG = "BuildInfo";
24    private static final int MAX_FINGERPRINT_LENGTH = 128;
25 
26    /**
27     * BuildInfo is a static utility class and therefore shouldn't be
28     * instantiated.
29     */
30    private BuildInfo() {
31    }
32 
33    @CalledByNative
34    public static String getDevice() {
35        return Build.DEVICE;
36    }
37 
38    @CalledByNative
39    public static String getBrand() {
40        return Build.BRAND;
41    }
42 
43    @CalledByNative
44    public static String getAndroidBuildId() {
45        return Build.ID;
46    }
47 
48    /**
49     * @return The build fingerprint for the current Android install.  The value is truncated to a
50     *         128 characters as this is used for crash and UMA reporting, which should avoid huge
51     *         strings.
52     */
53    @CalledByNative
54    public static String getAndroidBuildFingerprint() {
55        return Build.FINGERPRINT.substring(
56                0, Math.min(Build.FINGERPRINT.length(), MAX_FINGERPRINT_LENGTH));
57    }
58 
59    @CalledByNative
60    public static String getDeviceModel() {
61        return Build.MODEL;
62    }
63 
64    @CalledByNative
65    public static String getPackageVersionCode(Context context) {
66        String msg = "versionCode not available.";
67        try {
68            PackageManager pm = context.getPackageManager();
69            PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
70            msg = "";
71            if (pi.versionCode > 0) {
72                msg = Integer.toString(pi.versionCode);
73            }
74        } catch (NameNotFoundException e) {
75            Log.d(TAG, msg);
76        }
77        return msg;
78 
79    }
80 
81    @CalledByNative
82    public static String getPackageVersionName(Context context) {
83        String msg = "versionName not available";
84        try {
85            PackageManager pm = context.getPackageManager();
86            PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
87            msg = pi.versionName;
88        } catch (NameNotFoundException e) {
89            Log.d(TAG, msg);
90        }
91        return msg;
92    }
93 
94    @CalledByNative
95    public static String getPackageLabel(Context context) {
96        try {
97            PackageManager packageManager = context.getPackageManager();
98            ApplicationInfo appInfo = packageManager.getApplicationInfo(context.getPackageName(),
99                    PackageManager.GET_META_DATA);
100            CharSequence label = packageManager.getApplicationLabel(appInfo);
101            return  label != null ? label.toString() : "";
102        } catch (NameNotFoundException e) {
103            return "";
104        }
105    }
106 
107    @CalledByNative
108    public static String getPackageName(Context context) {
109        String packageName = context != null ? context.getPackageName() : null;
110        return packageName != null ? packageName : "";
111    }
112 
113    @CalledByNative
114    public static int getSdkInt() {
115        return Build.VERSION.SDK_INT;
116    }
117}

[all classes][org.chromium.base]
EMMA 2.0.5312 (C) Vladimir Roubtsov