| Index: base/android/java/src/org/chromium/base/BuildInfo.java
|
| diff --git a/base/android/java/src/org/chromium/base/BuildInfo.java b/base/android/java/src/org/chromium/base/BuildInfo.java
|
| index b7341af24bf70ffef6d9a4d8df408bc34cec6ca1..4f1355f077f43fa52f6429dad1dcd0ca8b4ada0e 100644
|
| --- a/base/android/java/src/org/chromium/base/BuildInfo.java
|
| +++ b/base/android/java/src/org/chromium/base/BuildInfo.java
|
| @@ -5,12 +5,10 @@
|
| package org.chromium.base;
|
|
|
| import android.content.Context;
|
| -import android.content.pm.ApplicationInfo;
|
| import android.content.pm.PackageInfo;
|
| import android.content.pm.PackageManager;
|
| import android.content.pm.PackageManager.NameNotFoundException;
|
| import android.os.Build;
|
| -import android.os.StrictMode;
|
|
|
| import org.chromium.base.annotations.CalledByNative;
|
|
|
| @@ -28,18 +26,32 @@ public class BuildInfo {
|
| private BuildInfo() {}
|
|
|
| @CalledByNative
|
| - public static String getDevice() {
|
| - return Build.DEVICE;
|
| - }
|
| + private static String[] getAll() {
|
| + try {
|
| + String packageName = ContextUtils.getApplicationContext().getPackageName();
|
| + PackageManager pm = ContextUtils.getApplicationContext().getPackageManager();
|
| + PackageInfo pi = pm.getPackageInfo(packageName, 0);
|
| + String versionCode = pi.versionCode <= 0 ? "" : Integer.toString(pi.versionCode);
|
| + String versionName = pi.versionName == null ? "" : pi.versionName;
|
|
|
| - @CalledByNative
|
| - public static String getBrand() {
|
| - return Build.BRAND;
|
| - }
|
| + CharSequence label = pm.getApplicationLabel(pi.applicationInfo);
|
| + String packageLabel = label == null ? "" : label.toString();
|
|
|
| - @CalledByNative
|
| - public static String getAndroidBuildId() {
|
| - return Build.ID;
|
| + // Use lastUpdateTime when developing locally, since versionCode does not normally
|
| + // change in this case.
|
| + long version = pi.versionCode > 10 ? pi.versionCode : pi.lastUpdateTime;
|
| + String extractedFileSuffix = String.format("@%s", Long.toHexString(version));
|
| +
|
| + // Do not alter this list without updating callers of it.
|
| + return new String[] {
|
| + Build.BRAND, Build.DEVICE, Build.ID, Build.MANUFACTURER, Build.MODEL,
|
| + String.valueOf(Build.VERSION.SDK_INT), Build.TYPE, packageLabel, packageName,
|
| + versionCode, versionName, getAndroidBuildFingerprint(), getGMSVersionCode(pm),
|
| + extractedFileSuffix,
|
| + };
|
| + } catch (NameNotFoundException e) {
|
| + throw new RuntimeException(e);
|
| + }
|
| }
|
|
|
| /**
|
| @@ -47,28 +59,14 @@ public class BuildInfo {
|
| * 128 characters as this is used for crash and UMA reporting, which should avoid huge
|
| * strings.
|
| */
|
| - @CalledByNative
|
| - public static String getAndroidBuildFingerprint() {
|
| + private static String getAndroidBuildFingerprint() {
|
| return Build.FINGERPRINT.substring(
|
| 0, Math.min(Build.FINGERPRINT.length(), MAX_FINGERPRINT_LENGTH));
|
| }
|
|
|
| - @CalledByNative
|
| - public static String getDeviceManufacturer() {
|
| - return Build.MANUFACTURER;
|
| - }
|
| -
|
| - @CalledByNative
|
| - public static String getDeviceModel() {
|
| - return Build.MODEL;
|
| - }
|
| -
|
| - @CalledByNative
|
| - public static String getGMSVersionCode() {
|
| + private static String getGMSVersionCode(PackageManager packageManager) {
|
| String msg = "gms versionCode not available.";
|
| try {
|
| - PackageManager packageManager =
|
| - ContextUtils.getApplicationContext().getPackageManager();
|
| PackageInfo packageInfo = packageManager.getPackageInfo("com.google.android.gms", 0);
|
| msg = Integer.toString(packageInfo.versionCode);
|
| } catch (NameNotFoundException e) {
|
| @@ -77,85 +75,23 @@ public class BuildInfo {
|
| return msg;
|
| }
|
|
|
| - @CalledByNative
|
| - public static String getPackageVersionCode() {
|
| - String msg = "versionCode not available.";
|
| - try {
|
| - PackageManager pm = ContextUtils.getApplicationContext().getPackageManager();
|
| - PackageInfo pi = pm.getPackageInfo(getPackageName(), 0);
|
| - msg = "";
|
| - if (pi.versionCode > 0) {
|
| - msg = Integer.toString(pi.versionCode);
|
| - }
|
| - } catch (NameNotFoundException e) {
|
| - Log.d(TAG, msg);
|
| - }
|
| - return msg;
|
| - }
|
| -
|
| - @CalledByNative
|
| public static String getPackageVersionName() {
|
| - String msg = "versionName not available";
|
| - try {
|
| - PackageManager pm = ContextUtils.getApplicationContext().getPackageManager();
|
| - PackageInfo pi = pm.getPackageInfo(getPackageName(), 0);
|
| - msg = "";
|
| - if (pi.versionName != null) {
|
| - msg = pi.versionName;
|
| - }
|
| - } catch (NameNotFoundException e) {
|
| - Log.d(TAG, msg);
|
| - }
|
| - return msg;
|
| + return getAll()[10];
|
| }
|
|
|
| /** Returns a string that is different each time the apk changes. */
|
| - @CalledByNative
|
| public static String getExtractedFileSuffix() {
|
| - PackageManager pm = ContextUtils.getApplicationContext().getPackageManager();
|
| - try {
|
| - PackageInfo pi =
|
| - pm.getPackageInfo(ContextUtils.getApplicationContext().getPackageName(), 0);
|
| - // Use lastUpdateTime when developing locally, since versionCode does not normally
|
| - // change in this case.
|
| - long version = pi.versionCode > 10 ? pi.versionCode : pi.lastUpdateTime;
|
| - return "@" + Long.toHexString(version);
|
| - } catch (PackageManager.NameNotFoundException e) {
|
| - throw new RuntimeException(e);
|
| - }
|
| + return getAll()[13];
|
| }
|
|
|
| - @CalledByNative
|
| public static String getPackageLabel() {
|
| - // Third-party code does disk read on the getApplicationInfo call. http://crbug.com/614343
|
| - StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
|
| - try {
|
| - PackageManager packageManager =
|
| - ContextUtils.getApplicationContext().getPackageManager();
|
| - ApplicationInfo appInfo = packageManager.getApplicationInfo(
|
| - getPackageName(), PackageManager.GET_META_DATA);
|
| - CharSequence label = packageManager.getApplicationLabel(appInfo);
|
| - return label != null ? label.toString() : "";
|
| - } catch (NameNotFoundException e) {
|
| - return "";
|
| - } finally {
|
| - StrictMode.setThreadPolicy(oldPolicy);
|
| - }
|
| + return getAll()[7];
|
| }
|
|
|
| - @CalledByNative
|
| public static String getPackageName() {
|
| - if (ContextUtils.getApplicationContext() == null) {
|
| - return "";
|
| - }
|
| return ContextUtils.getApplicationContext().getPackageName();
|
| }
|
|
|
| - @CalledByNative
|
| - public static String getBuildType() {
|
| - return Build.TYPE;
|
| - }
|
| -
|
| /**
|
| * Check if this is a debuggable build of Android. Use this to enable developer-only features.
|
| */
|
| @@ -163,11 +99,6 @@ public class BuildInfo {
|
| return "eng".equals(Build.TYPE) || "userdebug".equals(Build.TYPE);
|
| }
|
|
|
| - @CalledByNative
|
| - public static int getSdkInt() {
|
| - return Build.VERSION.SDK_INT;
|
| - }
|
| -
|
| /**
|
| * @return Whether the current device is running Android O release or newer.
|
| */
|
|
|