Chromium Code Reviews| 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 141b62b9e41f43be6c1404fd7b6cab7742231707..277f05ee11a943b3fc02f4901c9d44f869ca8177 100644 |
| --- a/base/android/java/src/org/chromium/base/BuildInfo.java |
| +++ b/base/android/java/src/org/chromium/base/BuildInfo.java |
| @@ -44,8 +44,8 @@ public class BuildInfo { |
| /** |
| * @return The build fingerprint for the current Android install. The value is truncated to a |
| - * 128 characters as this is used for crash and UMA reporting, which should avoid huge |
| - * strings. |
| + * 128 characters as this is used for crash and UMA reporting, which should avoid huge |
| + * strings. |
| */ |
| @CalledByNative |
| public static String getAndroidBuildFingerprint() { |
| @@ -64,10 +64,11 @@ public class BuildInfo { |
| } |
| @CalledByNative |
| - public static String getGMSVersionCode(Context context) { |
| + public static String getGMSVersionCode() { |
| String msg = "gms versionCode not available."; |
| try { |
| - PackageManager packageManager = context.getPackageManager(); |
| + PackageManager packageManager = |
| + ContextUtils.getApplicationContext().getPackageManager(); |
| PackageInfo packageInfo = packageManager.getPackageInfo("com.google.android.gms", 0); |
| msg = Integer.toString(packageInfo.versionCode); |
| } catch (NameNotFoundException e) { |
| @@ -77,11 +78,12 @@ public class BuildInfo { |
| } |
| @CalledByNative |
| - public static String getPackageVersionCode(Context context) { |
| + public static String getPackageVersionCode() { |
| String msg = "versionCode not available."; |
| try { |
| - PackageManager pm = context.getPackageManager(); |
| - PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0); |
| + PackageManager pm = ContextUtils.getApplicationContext().getPackageManager(); |
|
estevenson
2017/03/27 21:00:54
optional nit: might be a little nicer to store con
Peter Wen
2017/03/27 22:31:06
Modified it a little bit by calling getPackageName
|
| + PackageInfo pi = |
| + pm.getPackageInfo(ContextUtils.getApplicationContext().getPackageName(), 0); |
| msg = ""; |
| if (pi.versionCode > 0) { |
| msg = Integer.toString(pi.versionCode); |
| @@ -93,11 +95,12 @@ public class BuildInfo { |
| } |
| @CalledByNative |
| - public static String getPackageVersionName(Context context) { |
| + public static String getPackageVersionName() { |
| String msg = "versionName not available"; |
| try { |
| - PackageManager pm = context.getPackageManager(); |
| - PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0); |
| + PackageManager pm = ContextUtils.getApplicationContext().getPackageManager(); |
| + PackageInfo pi = |
| + pm.getPackageInfo(ContextUtils.getApplicationContext().getPackageName(), 0); |
| msg = ""; |
| if (pi.versionName != null) { |
| msg = pi.versionName; |
| @@ -109,15 +112,17 @@ public class BuildInfo { |
| } |
| @CalledByNative |
| - public static String getPackageLabel(Context context) { |
| + 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 = context.getPackageManager(); |
| - ApplicationInfo appInfo = packageManager.getApplicationInfo(context.getPackageName(), |
| + PackageManager packageManager = |
| + ContextUtils.getApplicationContext().getPackageManager(); |
| + ApplicationInfo appInfo = packageManager.getApplicationInfo( |
| + ContextUtils.getApplicationContext().getPackageName(), |
| PackageManager.GET_META_DATA); |
| CharSequence label = packageManager.getApplicationLabel(appInfo); |
| - return label != null ? label.toString() : ""; |
| + return label != null ? label.toString() : ""; |
| } catch (NameNotFoundException e) { |
| return ""; |
| } finally { |
| @@ -126,9 +131,11 @@ public class BuildInfo { |
| } |
| @CalledByNative |
| - public static String getPackageName(Context context) { |
| - String packageName = context != null ? context.getPackageName() : null; |
| - return packageName != null ? packageName : ""; |
| + public static String getPackageName() { |
| + if (ContextUtils.getApplicationContext() == null) { |
| + return ""; |
| + } |
| + return ContextUtils.getApplicationContext().getPackageName(); |
| } |
| @CalledByNative |