Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

Commit

Permalink
SettingsLib: show which user recently updated/installed app on App In…
Browse files Browse the repository at this point in the history
…fo screen
  • Loading branch information
quh4gko8 committed Aug 6, 2024
1 parent af40b52 commit 2cd6812
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/SettingsLib/SpaPrivileged/res/values/strings_ext.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="app_info_install_time">Installed: %1$s</string>
<string name="app_info_update_time">Updated: %1$s</string>

<string name="app_info_installed_or_updated_by_primary_user">Installed/Updated by: %1$s</string>
<string name="app_info_installed_or_updated_by_secondary_user">Installed/Updated by: %1$s (Secondary user)</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
}
}
Expand Down

0 comments on commit 2cd6812

Please sign in to comment.