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 static com.android.server.net.NetworkPolicyManagerService.UidBlockedState.getAllowedReasonsForProcState; 20 import static com.android.server.net.NetworkPolicyManagerService.UidBlockedState.getEffectiveBlockedReasons; 21 22 import android.annotation.Nullable; 23 import android.net.Network; 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 public static final int QUOTA_TYPE_JOBS = 1; 60 public static final int QUOTA_TYPE_MULTIPATH = 2; 61 62 /** 63 * Return the daily quota (in bytes) that can be opportunistically used on 64 * the given network to improve the end user experience. It's called 65 * "opportunistic" because it's traffic that would typically not use the 66 * given network. 67 */ getSubscriptionOpportunisticQuota(Network network, int quotaType)68 public abstract long getSubscriptionOpportunisticQuota(Network network, int quotaType); 69 70 /** 71 * Informs that admin data is loaded and available. 72 */ onAdminDataAvailable()73 public abstract void onAdminDataAvailable(); 74 75 /** 76 * Control if a UID should be allowlisted even if it's in app idle mode. Other restrictions may 77 * still be in effect. 78 */ setAppIdleWhitelist(int uid, boolean shouldWhitelist)79 public abstract void setAppIdleWhitelist(int uid, boolean shouldWhitelist); 80 81 /** 82 * Sets a list of packages which are restricted by admin from accessing metered data. 83 * 84 * @param packageNames the list of restricted packages. 85 * @param userId the userId in which {@param packagesNames} are restricted. 86 */ setMeteredRestrictedPackages( Set<String> packageNames, int userId)87 public abstract void setMeteredRestrictedPackages( 88 Set<String> packageNames, int userId); 89 90 /** 91 * Similar to {@link #setMeteredRestrictedPackages(Set, int)} but updates the restricted 92 * packages list asynchronously. 93 */ setMeteredRestrictedPackagesAsync( Set<String> packageNames, int userId)94 public abstract void setMeteredRestrictedPackagesAsync( 95 Set<String> packageNames, int userId); 96 97 /** Informs that Low Power Standby has become active */ setLowPowerStandbyActive(boolean active)98 public abstract void setLowPowerStandbyActive(boolean active); 99 100 /** Informs that the Low Power Standby allowlist has changed */ setLowPowerStandbyAllowlist(int[] uids)101 public abstract void setLowPowerStandbyAllowlist(int[] uids); 102 103 /** Update the {@code blockedReasons} taking into account the {@code procState} of the uid */ updateBlockedReasonsWithProcState(int blockedReasons, int procState)104 public static int updateBlockedReasonsWithProcState(int blockedReasons, int procState) { 105 final int allowedReasons = getAllowedReasonsForProcState(procState); 106 return getEffectiveBlockedReasons(blockedReasons, allowedReasons); 107 } 108 } 109