Add version code retrieval in PackageUtil
bug: 139022526
Test: none
Change-Id: I9689a1d858e20d4189fcb4277925b018cbb26167
diff --git a/common/device-side/util-axt/src/com/android/compatibility/common/util/PackageUtil.java b/common/device-side/util-axt/src/com/android/compatibility/common/util/PackageUtil.java
index 9df0bf1..28d8f0d 100644
--- a/common/device-side/util-axt/src/com/android/compatibility/common/util/PackageUtil.java
+++ b/common/device-side/util-axt/src/com/android/compatibility/common/util/PackageUtil.java
@@ -97,6 +97,18 @@
}
}
+ /** Returns the version code for the package name, or null if the package can't be found */
+ public static Long getLongVersionCode(String packageName) {
+ try {
+ PackageInfo info = getPackageManager().getPackageInfo(packageName,
+ PackageManager.GET_META_DATA);
+ return info.getLongVersionCode();
+ } catch (PackageManager.NameNotFoundException | NullPointerException e) {
+ Log.w(TAG, "Could not find version string for package " + packageName);
+ return null;
+ }
+ }
+
/**
* Compute the signature SHA digest for a package.
* @param package the name of the package for which the signature SHA digest is requested