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 getDeviceManufacturer() {
59 return Build.MANUFACTURER;
63 public static String getDeviceModel() {
68 public static String getPackageVersionCode(Context context) {
69 String msg = "versionCode not available.";
71 PackageManager pm = context.getPackageManager();
72 PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
74 if (pi.versionCode > 0) {
75 msg = Integer.toString(pi.versionCode);
77 } catch (NameNotFoundException e) {
85 public static String getPackageVersionName(Context context) {
86 String msg = "versionName not available";
88 PackageManager pm = context.getPackageManager();
89 PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
91 } catch (NameNotFoundException e) {
98 public static String getPackageLabel(Context context) {
100 PackageManager packageManager = context.getPackageManager();
101 ApplicationInfo appInfo = packageManager.getApplicationInfo(context.getPackageName(),
102 PackageManager.GET_META_DATA);
103 CharSequence label = packageManager.getApplicationLabel(appInfo);
104 return label != null ? label.toString() : "";
105 } catch (NameNotFoundException e) {
111 public static String getPackageName(Context context) {
112 String packageName = context != null ? context.getPackageName() : null;
113 return packageName != null ? packageName : "";
117 public static String getBuildType() {
122 public static int getSdkInt() {
123 return Build.VERSION.SDK_INT;