1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.server.usage; 17 18 import android.annotation.NonNull; 19 import android.annotation.SystemApi; 20 import android.content.pm.PackageStats; 21 import android.os.UserHandle; 22 23 /** 24 * StorageStatsManager local system service interface. 25 * 26 * @hide Only for use within the system server. 27 */ 28 @SystemApi(client = SystemApi.Client.SYSTEM_SERVER) 29 public interface StorageStatsManagerLocal { 30 /** 31 * Class used to augment {@link PackageStats} with the data stored by the system on 32 * behalf of apps in system specific directories 33 * ({@link android.os.Environment#getDataSystemDirectory}, 34 * {@link android.os.Environment#getDataSystemCeDirectory}, etc). 35 */ 36 interface StorageStatsAugmenter { 37 /** 38 * Augments {@link PackageStats} with data stored by the system for the given package. 39 * 40 * @param stats Structure to modify with usage data 41 * @param packageName Package name of the app whose data is stored by the 42 * system and needs to be added to {@code stats}. 43 * @param userHandle Device user for which usage stats are being requested. 44 * @param canCallerAccessAllStats Whether the caller who is requesting the storage stats 45 * can query stats for packages other than itself. For 46 * example, holding the PACKAGE_USAGE_STATS permission is one 47 * way to accomplish this. 48 */ augmentStatsForPackageForUser( @onNull PackageStats stats, @NonNull String packageName, @NonNull UserHandle userHandle, boolean canCallerAccessAllStats)49 void augmentStatsForPackageForUser( 50 @NonNull PackageStats stats, 51 @NonNull String packageName, 52 @NonNull UserHandle userHandle, 53 boolean canCallerAccessAllStats); 54 55 /** 56 * Augments {@link PackageStats} with data stored by the system for the given uid. 57 * 58 * @param stats Structure to modify with usage data 59 * @param uid Unique app ID for the app instance whose stats are being 60 * requested. 61 * @param canCallerAccessAllStats Whether the caller who is requesting the storage stats 62 * can query stats for packages other than itself. For 63 * example, holding the PACKAGE_USAGE_STATS permission is one 64 * way to accomplish this. 65 */ augmentStatsForUid( @onNull PackageStats stats, int uid, boolean canCallerAccessAllStats)66 void augmentStatsForUid( 67 @NonNull PackageStats stats, int uid, boolean canCallerAccessAllStats); 68 69 /** 70 * Augments {@link PackageStats} with data stored by the system for the given device user. 71 * 72 * @param stats Structure to modify with usage data 73 * @param userHandle Device user whose data is stored by the system and needs to be added to 74 * {@code stats}. 75 */ augmentStatsForUser(@onNull PackageStats stats, @NonNull UserHandle userHandle)76 void augmentStatsForUser(@NonNull PackageStats stats, @NonNull UserHandle userHandle); 77 } 78 79 /** 80 * Register a {@link StorageStatsAugmenter}. 81 * 82 * @param augmenter the {@link StorageStatsAugmenter} object to be registered. 83 * @param tag the identifier to be used for debugging in logs/trace. 84 */ registerStorageStatsAugmenter( @onNull StorageStatsAugmenter augmenter, @NonNull String tag)85 void registerStorageStatsAugmenter( 86 @NonNull StorageStatsAugmenter augmenter, @NonNull String tag); 87 } 88