1 /*
2  * Copyright (C) 2016 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 com.android.server.net;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.net.Network;
22 import android.net.NetworkTemplate;
23 import android.net.netstats.provider.NetworkStatsProvider;
24 import android.os.PowerExemptionManager.ReasonCode;
25 import android.telephony.SubscriptionPlan;
26 
27 import java.util.Set;
28 
29 /**
30  * Network Policy Manager local system service interface.
31  *
32  * @hide Only for use within the system server.
33  */
34 public abstract class NetworkPolicyManagerInternal {
35 
36     /**
37      * Resets all policies associated with a given user.
38      */
resetUserState(int userId)39     public abstract void resetUserState(int userId);
40 
41     /**
42      * Informs that an appId has been added or removed from the temp-powersave-allowlist so that
43      * that network rules for that appId can be updated.
44      *
45      * @param appId The appId which has been updated in the allowlist.
46      * @param added Denotes whether the {@code appId} has been added or removed from the allowlist.
47      * @param reasonCode one of {@link ReasonCode} indicating the reason for the change.
48      *                   Only valid when {@code added} is {@code true}.
49      * @param reason an optional human-readable reason explaining why the app is temp allow-listed.
50      */
onTempPowerSaveWhitelistChange(int appId, boolean added, @ReasonCode int reasonCode, @Nullable String reason)51     public abstract void onTempPowerSaveWhitelistChange(int appId, boolean added,
52             @ReasonCode int reasonCode, @Nullable String reason);
53 
54     /**
55      * Return the active {@link SubscriptionPlan} for the given network.
56      */
getSubscriptionPlan(Network network)57     public abstract SubscriptionPlan getSubscriptionPlan(Network network);
58 
59     /**
60      * Return the active {@link SubscriptionPlan} for the given template.
61      */
getSubscriptionPlan(NetworkTemplate template)62     public abstract SubscriptionPlan getSubscriptionPlan(NetworkTemplate template);
63 
64     public static final int QUOTA_TYPE_JOBS = 1;
65     public static final int QUOTA_TYPE_MULTIPATH = 2;
66 
67     /**
68      * Return the daily quota (in bytes) that can be opportunistically used on
69      * the given network to improve the end user experience. It's called
70      * "opportunistic" because it's traffic that would typically not use the
71      * given network.
72      */
getSubscriptionOpportunisticQuota(Network network, int quotaType)73     public abstract long getSubscriptionOpportunisticQuota(Network network, int quotaType);
74 
75     /**
76      * Informs that admin data is loaded and available.
77      */
onAdminDataAvailable()78     public abstract void onAdminDataAvailable();
79 
80     /**
81      * Control if a UID should be allowlisted even if it's in app idle mode. Other restrictions may
82      * still be in effect.
83      */
setAppIdleWhitelist(int uid, boolean shouldWhitelist)84     public abstract void setAppIdleWhitelist(int uid, boolean shouldWhitelist);
85 
86     /**
87      * Sets a list of packages which are restricted by admin from accessing metered data.
88      *
89      * @param packageNames the list of restricted packages.
90      * @param userId the userId in which {@param packagesNames} are restricted.
91      */
setMeteredRestrictedPackages( Set<String> packageNames, int userId)92     public abstract void setMeteredRestrictedPackages(
93             Set<String> packageNames, int userId);
94 
95 
96     /**
97      * Similar to {@link #setMeteredRestrictedPackages(Set, int)} but updates the restricted
98      * packages list asynchronously.
99      */
setMeteredRestrictedPackagesAsync( Set<String> packageNames, int userId)100     public abstract void setMeteredRestrictedPackagesAsync(
101             Set<String> packageNames, int userId);
102 
103     /**
104      *  Notifies that the specified {@link NetworkStatsProvider} has reached its quota
105      *  which was set through {@link NetworkStatsProvider#onSetLimit(String, long)} or
106      *  {@link NetworkStatsProvider#onSetWarningAndLimit(String, long, long)}.
107      *
108      * @param tag the human readable identifier of the custom network stats provider.
109      */
onStatsProviderWarningOrLimitReached(@onNull String tag)110     public abstract void onStatsProviderWarningOrLimitReached(@NonNull String tag);
111 }
112