1 // Copyright 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.
5 package org.chromium.base;
7 import android.content.Context;
8 import android.content.pm.ApplicationInfo;
9 import android.content.pm.PackageInfo;
10 import android.content.pm.PackageManager;
11 import android.content.pm.PackageManager.NameNotFoundException;
12 import android.os.Build;
13 import android.util.Log;
16 * BuildInfo is a utility class providing easy access to {@link PackageInfo}
17 * information. This is primarly of use for accessesing package information
20 public class BuildInfo {
21 private static final String TAG = "BuildInfo";
22 private static final int MAX_FINGERPRINT_LENGTH = 128;
25 * BuildInfo is a static utility class and therefore shouldn't be
32 public static String getDevice() {
37 public static String getBrand() {
42 public static String getAndroidBuildId() {
47 * @return The build fingerprint for the current Android install. The value is truncated to a
48 * 128 characters as this is used for crash and UMA reporting, which should avoid huge
52 public static String getAndroidBuildFingerprint() {
53 return Build.FINGERPRINT.substring(
54 0, Math.min(Build.FINGERPRINT.length(), MAX_FINGERPRINT_LENGTH));
58 public static String getDeviceModel() {
63 public static String getPackageVersionCode(Context context) {
64 String msg = "versionCode not available.";
66 PackageManager pm = context.getPackageManager();
67 PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
69 if (pi.versionCode > 0) {
70 msg = Integer.toString(pi.versionCode);
72 } catch (NameNotFoundException e) {
80 public static String getPackageVersionName(Context context) {
81 String msg = "versionName not available";
83 PackageManager pm = context.getPackageManager();
84 PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
86 } catch (NameNotFoundException e) {
93 public static String getPackageLabel(Context context) {
95 PackageManager packageManager = context.getPackageManager();
96 ApplicationInfo appInfo = packageManager.getApplicationInfo(context.getPackageName(),
97 PackageManager.GET_META_DATA);
98 CharSequence label = packageManager.getApplicationLabel(appInfo);
99 return label != null ? label.toString() : "";
100 } catch (NameNotFoundException e) {
106 public static String getPackageName(Context context) {
107 String packageName = context != null ? context.getPackageName() : null;
108 return packageName != null ? packageName : "";
112 public static String getBuildType() {
117 public static int getSdkInt() {
118 return Build.VERSION.SDK_INT;