Loading src/com/android/settings/datausage/lib/AppDataUsageRepository.kt +22 −3 Original line number Diff line number Diff line Loading @@ -18,10 +18,12 @@ package com.android.settings.datausage.lib 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 Loading Loading @@ -50,7 +52,11 @@ class AppDataUsageRepository( 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) { Loading Loading @@ -98,7 +104,7 @@ class AppDataUsageRepository( private fun bindStats( buckets: List<Bucket>, profiles: List<UserHandle>, userIdToIsHiddenMap: Map<Int, Boolean>, knownItems: SparseArray<AppItem>, items: ArrayList<AppItem>, ) { Loading @@ -108,8 +114,11 @@ class AppDataUsageRepository( 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( Loading Loading @@ -153,6 +162,16 @@ class AppDataUsageRepository( } } 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. Loading Loading
src/com/android/settings/datausage/lib/AppDataUsageRepository.kt +22 −3 Original line number Diff line number Diff line Loading @@ -18,10 +18,12 @@ package com.android.settings.datausage.lib 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 Loading Loading @@ -50,7 +52,11 @@ class AppDataUsageRepository( 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) { Loading Loading @@ -98,7 +104,7 @@ class AppDataUsageRepository( private fun bindStats( buckets: List<Bucket>, profiles: List<UserHandle>, userIdToIsHiddenMap: Map<Int, Boolean>, knownItems: SparseArray<AppItem>, items: ArrayList<AppItem>, ) { Loading @@ -108,8 +114,11 @@ class AppDataUsageRepository( 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( Loading Loading @@ -153,6 +162,16 @@ class AppDataUsageRepository( } } 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. Loading