From 2cd6812113bc24ba350eb366b0246162246e7ced Mon Sep 17 00:00:00 2001 From: quh4gko8 <88831734+quh4gko8@users.noreply.github.com> Date: Thu, 25 Jul 2024 14:42:05 +0000 Subject: [PATCH] SettingsLib: show which user recently updated/installed app on App Info screen --- .../SpaPrivileged/res/values/strings_ext.xml | 3 ++ .../spaprivileged/template/app/AppInfo.kt | 34 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/packages/SettingsLib/SpaPrivileged/res/values/strings_ext.xml b/packages/SettingsLib/SpaPrivileged/res/values/strings_ext.xml index 4a867c5a1c20..b4014a4caf7a 100644 --- a/packages/SettingsLib/SpaPrivileged/res/values/strings_ext.xml +++ b/packages/SettingsLib/SpaPrivileged/res/values/strings_ext.xml @@ -2,4 +2,7 @@ Installed: %1$s Updated: %1$s + + Installed/Updated by: %1$s + Installed/Updated by: %1$s (Secondary user) diff --git a/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/app/AppInfo.kt b/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/app/AppInfo.kt index 49f2a511dfd4..0ecdbd8a57aa 100644 --- a/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/app/AppInfo.kt +++ b/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/app/AppInfo.kt @@ -18,6 +18,7 @@ package com.android.settingslib.spaprivileged.template.app import android.content.pm.ApplicationInfo import android.content.pm.PackageInfo +import android.os.UserHandle import android.text.BidiFormatter import androidx.compose.foundation.Image import androidx.compose.foundation.layout.Box @@ -162,6 +163,39 @@ class AppInfoProvider(private val packageInfo: PackageInfo) { lines.add(stringResource(R.string.app_info_update_time, s)) } + val installerUserId = if (appInfo == null) { + UserHandle.USER_NULL + } else { + val installerUid = ctx.packageManager.getInstallerOfRecordUid( + appInfo.packageName, UserHandle.getUserId(appInfo.uid) + ) + if (installerUid == android.os.Process.INVALID_UID) { + UserHandle.USER_NULL + } else { + UserHandle.getUserId(installerUid) + } + } + + if (installerUserId != UserHandle.USER_NULL) { + val userMgr: android.os.UserManager? = + ctx.getSystemService(android.os.UserManager::class.java) + userMgr?.getUserInfo(installerUserId)?.name?.let { userName -> + lines.add( + if (installerUserId == UserHandle.USER_SYSTEM) { + stringResource( + R.string.app_info_installed_or_updated_by_primary_user, + userName, + ) + } else { + stringResource( + R.string.app_info_installed_or_updated_by_secondary_user, + userName, + ) + } + ) + } + } + return lines.joinToString(separator = System.lineSeparator()) } }