Merge "Handle listing of private space apps in data usage settings" into main
diff --git a/src/com/android/settings/datausage/lib/AppDataUsageRepository.kt b/src/com/android/settings/datausage/lib/AppDataUsageRepository.kt
index 1844a7a..5abde31 100644
--- a/src/com/android/settings/datausage/lib/AppDataUsageRepository.kt
+++ b/src/com/android/settings/datausage/lib/AppDataUsageRepository.kt
@@ -18,10 +18,12 @@
import android.app.usage.NetworkStats
import android.content.Context
+import android.content.pm.UserProperties
import android.net.NetworkPolicyManager
import android.net.NetworkTemplate
import android.os.Process
import android.os.UserHandle
+import android.os.UserManager
import android.util.SparseArray
import android.util.SparseBooleanArray
import androidx.annotation.VisibleForTesting
@@ -50,7 +52,11 @@
val items = ArrayList<AppItem>()
val knownItems = SparseArray<AppItem>()
val profiles = context.userManager.userProfiles
- bindStats(buckets, profiles, knownItems, items)
+ val userManager : UserManager = context.getSystemService(Context.USER_SERVICE) as UserManager
+ val userIdToIsHiddenMap = profiles.associate { profile ->
+ profile.identifier to shouldSkipProfile(userManager, profile)
+ }
+ bindStats(buckets, userIdToIsHiddenMap, knownItems, items)
val restrictedUids = context.getSystemService(NetworkPolicyManager::class.java)!!
.getUidsWithPolicy(NetworkPolicyManager.POLICY_REJECT_METERED_BACKGROUND)
for (uid in restrictedUids) {
@@ -98,7 +104,7 @@
private fun bindStats(
buckets: List<Bucket>,
- profiles: List<UserHandle>,
+ userIdToIsHiddenMap: Map<Int, Boolean>,
knownItems: SparseArray<AppItem>,
items: ArrayList<AppItem>,
) {
@@ -108,8 +114,11 @@
val collapseKey: Int
val category: Int
val userId = UserHandle.getUserId(uid)
+ if(userIdToIsHiddenMap[userId] == true) {
+ continue
+ }
if (UserHandle.isApp(uid) || Process.isSdkSandboxUid(uid)) {
- if (profiles.contains(UserHandle(userId))) {
+ if (userIdToIsHiddenMap.keys.contains(userId)) {
if (userId != currentUserId) {
// Add to a managed user item.
accumulate(
@@ -153,6 +162,16 @@
}
}
+ private fun shouldSkipProfile(userManager : UserManager, userHandle: UserHandle): Boolean {
+ if (android.os.Flags.allowPrivateProfile()
+ && android.multiuser.Flags.handleInterleavedSettingsForPrivateSpace()) {
+ return (userManager.isQuietModeEnabled(userHandle)
+ && userManager.getUserProperties(userHandle).showInQuietMode
+ == UserProperties.SHOW_IN_QUIET_MODE_HIDDEN)
+ }
+ return false
+ }
+
/**
* Accumulate data usage of a network stats entry for the item mapped by the collapse key.
* Creates the item if needed.