1 /* 2 * Copyright (C) 2011 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 17 package android.net; 18 19 import android.net.DataUsageRequest; 20 import android.net.INetworkStatsSession; 21 import android.net.Network; 22 import android.net.NetworkStateSnapshot; 23 import android.net.NetworkStats; 24 import android.net.NetworkTemplate; 25 import android.net.UnderlyingNetworkInfo; 26 import android.net.netstats.IUsageCallback; 27 import android.net.netstats.StatsResult; 28 import android.net.netstats.TrafficStatsRateLimitCacheConfig; 29 import android.net.netstats.provider.INetworkStatsProvider; 30 import android.net.netstats.provider.INetworkStatsProviderCallback; 31 import android.os.IBinder; 32 import android.os.Messenger; 33 34 /** {@hide} */ 35 interface INetworkStatsService { 36 37 /** Start a statistics query session. */ 38 @UnsupportedAppUsage openSession()39 INetworkStatsSession openSession(); 40 41 /** Start a statistics query session. If calling package is profile or device owner then it is 42 * granted automatic access if apiLevel is NetworkStatsManager.API_LEVEL_DPC_ALLOWED. If 43 * apiLevel is at least NetworkStatsManager.API_LEVEL_REQUIRES_PACKAGE_USAGE_STATS then 44 * PACKAGE_USAGE_STATS permission is always checked. If PACKAGE_USAGE_STATS is not granted 45 * READ_NETWORK_USAGE_STATS is checked for. 46 */ 47 @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553) openSessionForUsageStats(int flags, String callingPackage)48 INetworkStatsSession openSessionForUsageStats(int flags, String callingPackage); 49 50 /** Return data layer snapshot of UID network usage. */ 51 @UnsupportedAppUsage getDataLayerSnapshotForUid(int uid)52 NetworkStats getDataLayerSnapshotForUid(int uid); 53 54 /** Get the transport NetworkStats for all UIDs since boot. */ getUidStatsForTransport(int transport)55 NetworkStats getUidStatsForTransport(int transport); 56 57 /** Return set of any ifaces associated with mobile networks since boot. */ 58 @UnsupportedAppUsage getMobileIfaces()59 String[] getMobileIfaces(); 60 61 /** Increment data layer count of operations performed for UID and tag. */ incrementOperationCount(int uid, int tag, int operationCount)62 void incrementOperationCount(int uid, int tag, int operationCount); 63 64 /** Notify {@code NetworkStatsService} about network status changed. */ notifyNetworkStatus( in Network[] defaultNetworks, in NetworkStateSnapshot[] snapshots, in String activeIface, in UnderlyingNetworkInfo[] underlyingNetworkInfos)65 void notifyNetworkStatus( 66 in Network[] defaultNetworks, 67 in NetworkStateSnapshot[] snapshots, 68 in String activeIface, 69 in UnderlyingNetworkInfo[] underlyingNetworkInfos); 70 /** Force update of statistics. */ 71 @UnsupportedAppUsage forceUpdate()72 void forceUpdate(); 73 74 /** Registers a callback on data usage. */ registerUsageCallback(String callingPackage, in DataUsageRequest request, in IUsageCallback callback)75 DataUsageRequest registerUsageCallback(String callingPackage, 76 in DataUsageRequest request, in IUsageCallback callback); 77 78 /** Unregisters a callback on data usage. */ unregisterUsageRequest(in DataUsageRequest request)79 void unregisterUsageRequest(in DataUsageRequest request); 80 81 /** Get the uid stats information since boot */ getUidStats(int uid)82 StatsResult getUidStats(int uid); 83 84 /** Get the iface stats information since boot */ getIfaceStats(String iface)85 StatsResult getIfaceStats(String iface); 86 87 /** Get the total network stats information since boot */ getTotalStats()88 StatsResult getTotalStats(); 89 90 /** Registers a network stats provider */ registerNetworkStatsProvider(String tag, in INetworkStatsProvider provider)91 INetworkStatsProviderCallback registerNetworkStatsProvider(String tag, 92 in INetworkStatsProvider provider); 93 94 /** Mark given UID as being in foreground for stats purposes. */ noteUidForeground(int uid, boolean uidForeground)95 void noteUidForeground(int uid, boolean uidForeground); 96 97 /** Advise persistence threshold; may be overridden internally. */ advisePersistThreshold(long thresholdBytes)98 void advisePersistThreshold(long thresholdBytes); 99 100 /** 101 * Set the warning and limit to all registered custom network stats providers. 102 * Note that invocation of any interface will be sent to all providers. 103 */ setStatsProviderWarningAndLimitAsync(String iface, long warning, long limit)104 void setStatsProviderWarningAndLimitAsync(String iface, long warning, long limit); 105 106 /** Clear TrafficStats rate-limit caches. */ clearTrafficStatsRateLimitCaches()107 void clearTrafficStatsRateLimitCaches(); 108 109 /** Get rate-limit cache config. */ getRateLimitCacheConfig()110 TrafficStatsRateLimitCacheConfig getRateLimitCacheConfig(); 111 } 112