Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f668b384 authored by josephpv's avatar josephpv Committed by Joseph Vincent
Browse files

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
parent 3454f304
Loading
Loading
Loading
Loading
+22 −3
Original line number Diff line number Diff line
@@ -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.