Handle listing of private space apps in data usage settings
Settings->Network & Internet->Internet->Non-carrier data usage Settings->Newtork & Internet->SIMs->App datat usage Screen recording link: https://drive.google.com/file/d/1vQPunoza_eB0hiqJ-Mu_ylDOz2IbKjYQ/view?usp=drive_link Bug: 324844478 Test: Manual Change-Id: I020e6bd2a62a342570f2d33765c75b882be3569d
This commit is contained in:
@@ -18,10 +18,12 @@ package com.android.settings.datausage.lib
|
|||||||
|
|
||||||
import android.app.usage.NetworkStats
|
import android.app.usage.NetworkStats
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.pm.UserProperties
|
||||||
import android.net.NetworkPolicyManager
|
import android.net.NetworkPolicyManager
|
||||||
import android.net.NetworkTemplate
|
import android.net.NetworkTemplate
|
||||||
import android.os.Process
|
import android.os.Process
|
||||||
import android.os.UserHandle
|
import android.os.UserHandle
|
||||||
|
import android.os.UserManager
|
||||||
import android.util.SparseArray
|
import android.util.SparseArray
|
||||||
import android.util.SparseBooleanArray
|
import android.util.SparseBooleanArray
|
||||||
import androidx.annotation.VisibleForTesting
|
import androidx.annotation.VisibleForTesting
|
||||||
@@ -50,7 +52,11 @@ class AppDataUsageRepository(
|
|||||||
val items = ArrayList<AppItem>()
|
val items = ArrayList<AppItem>()
|
||||||
val knownItems = SparseArray<AppItem>()
|
val knownItems = SparseArray<AppItem>()
|
||||||
val profiles = context.userManager.userProfiles
|
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)!!
|
val restrictedUids = context.getSystemService(NetworkPolicyManager::class.java)!!
|
||||||
.getUidsWithPolicy(NetworkPolicyManager.POLICY_REJECT_METERED_BACKGROUND)
|
.getUidsWithPolicy(NetworkPolicyManager.POLICY_REJECT_METERED_BACKGROUND)
|
||||||
for (uid in restrictedUids) {
|
for (uid in restrictedUids) {
|
||||||
@@ -98,7 +104,7 @@ class AppDataUsageRepository(
|
|||||||
|
|
||||||
private fun bindStats(
|
private fun bindStats(
|
||||||
buckets: List<Bucket>,
|
buckets: List<Bucket>,
|
||||||
profiles: List<UserHandle>,
|
userIdToIsHiddenMap: Map<Int, Boolean>,
|
||||||
knownItems: SparseArray<AppItem>,
|
knownItems: SparseArray<AppItem>,
|
||||||
items: ArrayList<AppItem>,
|
items: ArrayList<AppItem>,
|
||||||
) {
|
) {
|
||||||
@@ -108,8 +114,11 @@ class AppDataUsageRepository(
|
|||||||
val collapseKey: Int
|
val collapseKey: Int
|
||||||
val category: Int
|
val category: Int
|
||||||
val userId = UserHandle.getUserId(uid)
|
val userId = UserHandle.getUserId(uid)
|
||||||
|
if(userIdToIsHiddenMap[userId] == true) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if (UserHandle.isApp(uid) || Process.isSdkSandboxUid(uid)) {
|
if (UserHandle.isApp(uid) || Process.isSdkSandboxUid(uid)) {
|
||||||
if (profiles.contains(UserHandle(userId))) {
|
if (userIdToIsHiddenMap.keys.contains(userId)) {
|
||||||
if (userId != currentUserId) {
|
if (userId != currentUserId) {
|
||||||
// Add to a managed user item.
|
// Add to a managed user item.
|
||||||
accumulate(
|
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.
|
* Accumulate data usage of a network stats entry for the item mapped by the collapse key.
|
||||||
* Creates the item if needed.
|
* Creates the item if needed.
|
||||||
|
|||||||
Reference in New Issue
Block a user