Merge "Replace NetworkPolicyManagerInternal#isUidRestrictedOnMeteredNetworks()" am: ce1b5d00d9
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1534910 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: I0f8833a502cfa4674190509300eb378c4072efcc
This commit is contained in:
@@ -81,4 +81,5 @@ interface INetworkPolicyManager {
|
||||
void factoryReset(String subscriber);
|
||||
|
||||
boolean isUidNetworkingBlocked(int uid, boolean meteredNetwork);
|
||||
boolean isUidRestrictedOnMeteredNetworks(int uid);
|
||||
}
|
||||
|
||||
@@ -459,6 +459,22 @@ public class NetworkPolicyManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the given uid is restricted from doing networking on metered networks.
|
||||
*
|
||||
* @param uid The target uid.
|
||||
* @return true if the given uid is restricted from doing networking on metered networks.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public boolean isUidRestrictedOnMeteredNetworks(int uid) {
|
||||
try {
|
||||
return mService.isUidRestrictedOnMeteredNetworks(uid);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get multipath preference for the given network.
|
||||
*/
|
||||
|
||||
@@ -5714,9 +5714,14 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
// Policy already enforced.
|
||||
return;
|
||||
}
|
||||
if (mPolicyManagerInternal.isUidRestrictedOnMeteredNetworks(uid)) {
|
||||
// If UID is restricted, don't allow them to bring up metered APNs.
|
||||
networkCapabilities.addCapability(NET_CAPABILITY_NOT_METERED);
|
||||
final long ident = Binder.clearCallingIdentity();
|
||||
try {
|
||||
if (mPolicyManager.isUidRestrictedOnMeteredNetworks(uid)) {
|
||||
// If UID is restricted, don't allow them to bring up metered APNs.
|
||||
networkCapabilities.addCapability(NET_CAPABILITY_NOT_METERED);
|
||||
}
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(ident);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,11 +38,6 @@ public abstract class NetworkPolicyManagerInternal {
|
||||
*/
|
||||
public abstract void resetUserState(int userId);
|
||||
|
||||
/**
|
||||
* @return true if the given uid is restricted from doing networking on metered networks.
|
||||
*/
|
||||
public abstract boolean isUidRestrictedOnMeteredNetworks(int uid);
|
||||
|
||||
/**
|
||||
* Figure out if networking is blocked for a given set of conditions.
|
||||
*
|
||||
|
||||
@@ -5361,7 +5361,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
public boolean isUidNetworkingBlocked(int uid, boolean isNetworkMetered) {
|
||||
final long startTime = mStatLogger.getTime();
|
||||
|
||||
enforceAnyPermissionOf(OBSERVE_NETWORK_POLICY, PERMISSION_MAINLINE_NETWORK_STACK);
|
||||
mContext.enforceCallingOrSelfPermission(OBSERVE_NETWORK_POLICY, TAG);
|
||||
final int uidRules;
|
||||
final boolean isBackgroundRestricted;
|
||||
synchronized (mUidRulesFirstLock) {
|
||||
@@ -5376,6 +5376,23 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUidRestrictedOnMeteredNetworks(int uid) {
|
||||
mContext.enforceCallingOrSelfPermission(OBSERVE_NETWORK_POLICY, TAG);
|
||||
final int uidRules;
|
||||
final boolean isBackgroundRestricted;
|
||||
synchronized (mUidRulesFirstLock) {
|
||||
uidRules = mUidRules.get(uid, RULE_ALLOW_ALL);
|
||||
isBackgroundRestricted = mRestrictBackground;
|
||||
}
|
||||
//TODO(b/177490332): The logic here might not be correct because it doesn't consider
|
||||
// RULE_REJECT_METERED condition. And it could be replaced by
|
||||
// isUidNetworkingBlockedInternal().
|
||||
return isBackgroundRestricted
|
||||
&& !hasRule(uidRules, RULE_ALLOW_METERED)
|
||||
&& !hasRule(uidRules, RULE_TEMPORARY_ALLOW_METERED);
|
||||
}
|
||||
|
||||
private static boolean isSystem(int uid) {
|
||||
return uid < Process.FIRST_APPLICATION_UID;
|
||||
}
|
||||
@@ -5444,22 +5461,6 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the given uid is restricted from doing networking on metered networks.
|
||||
*/
|
||||
@Override
|
||||
public boolean isUidRestrictedOnMeteredNetworks(int uid) {
|
||||
final int uidRules;
|
||||
final boolean isBackgroundRestricted;
|
||||
synchronized (mUidRulesFirstLock) {
|
||||
uidRules = mUidRules.get(uid, RULE_ALLOW_ALL);
|
||||
isBackgroundRestricted = mRestrictBackground;
|
||||
}
|
||||
return isBackgroundRestricted
|
||||
&& !hasRule(uidRules, RULE_ALLOW_METERED)
|
||||
&& !hasRule(uidRules, RULE_TEMPORARY_ALLOW_METERED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTempPowerSaveWhitelistChange(int appId, boolean added) {
|
||||
synchronized (mUidRulesFirstLock) {
|
||||
|
||||
Reference in New Issue
Block a user