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