in ioXt/uraniborg/AndroidStudioProject/Hubble/app/src/main/java/com/uraniborg/hubble/PackageMetadata.java [87:146]
static public PackageMetadata parse(Context context, @NotNull PackageInfo packageInfo,
@NotNull PackageManager packageManager) {
PackageMetadata result = new PackageMetadata();
result.ref = packageInfo;
result.name = packageInfo.packageName;
if (packageInfo.applicationInfo != null) {
ApplicationInfo appInfo = packageInfo.applicationInfo;
result.installLocation = appInfo.sourceDir;
result.hash = Utilities.computeSHA256DigestOfFile(context, appInfo.sourceDir);
result.label = context.getPackageManager().getApplicationLabel(appInfo).toString();
result.isEnabled = appInfo.enabled;
result.hasCode = ((appInfo.flags & ApplicationInfo.FLAG_HAS_CODE) != 0);
result.isTestOnly = ((appInfo.flags & ApplicationInfo.FLAG_TEST_ONLY) != 0);
result.isFactoryTest = ((appInfo.flags & ApplicationInfo.FLAG_FACTORY_TEST) != 0);
result.isSuspended = ((appInfo.flags & ApplicationInfo.FLAG_SUSPENDED) != 0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
result.usesCleartextTraffic =
(appInfo.flags & ApplicationInfo.FLAG_USES_CLEARTEXT_TRAFFIC) != 0;
}
result.isHidden = (appInfo.flags & ApplicationInfo.FLAG_INSTALLED) == 0;
result.description = appInfo.loadDescription(packageManager);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
result.isApex = packageInfo.isApex;
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
result.versionCode = packageInfo.versionCode;
} else {
// versionCode and versionCodeMajor is combined together as a single long value. To extract
// only the versionCode, we need to get the lower 32 bits.
result.versionCode = (int) packageInfo.getLongVersionCode() & 0xFFFFFFFF;
}
result.versionName = packageInfo.versionName;
result.firstInstallTime = packageInfo.firstInstallTime;
result.sharedUserId = packageInfo.sharedUserId;
result.sharedUserLabel = packageInfo.sharedUserLabel;
result.splitNames = packageInfo.splitNames;
result.kernelGids = packageInfo.gids;
// compute package size
result.fileSizeInBytes = new File(result.installLocation).length();
// deal with permissions
result.parseDeclaredPermissions();
result.parseRequestedPermissions();
// deal with components
result.parseServices(packageManager);
result.parseActivityInfo(packageManager, false);
result.parseActivityInfo(packageManager, true);
result.parseProviders(packageManager);
return result;
}