Log app versionCode in anomaly detection

Change-Id: Ie760a4156b14b739279aa398bd1d2b8485449e91
Fixes: 77919142
Test: RunSettingsRoboTests
This commit is contained in:
Lei Yu
2018-04-11 19:53:53 -07:00
parent 7d09e2ea68
commit 63795b2f5c
3 changed files with 32 additions and 5 deletions

View File

@@ -20,6 +20,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.BatteryStats;
@@ -595,5 +596,21 @@ public class BatteryUtils {
return false;
}
/**
* Return version number of an app represented by {@code packageName}, and return -1 if not
* found.
*/
public long getAppLongVersionCode(String packageName) {
try {
final PackageInfo packageInfo = mPackageManager.getPackageInfo(packageName,
0 /* flags */);
return packageInfo.getLongVersionCode();
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "Cannot find package: " + packageName, e);
}
return -1L;
}
}