Merge "Handle listing of private space apps in data usage settings" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
1922746789
@@ -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
|
||||
@@ -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) {
|
||||
@@ -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>,
|
||||
) {
|
||||
@@ -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(
|
||||
@@ -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.
|
||||
|
Reference in New Issue
Block a user