Fix the case where blocked reasons for dataSaver are not considered.
Fixes: 183267528 Test: atest ./tests/cts/hostside/src/com/android/cts/net/HostsideNetworkCallbackTests.java Change-Id: I3c90c3849261df4c289c398f22661f91f7cf4994
This commit is contained in:
@@ -326,6 +326,20 @@ public class NetworkPolicyManager {
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public static final int ALLOWED_METERED_REASON_USER_EXEMPTED = 1 << 16;
|
public static final int ALLOWED_METERED_REASON_USER_EXEMPTED = 1 << 16;
|
||||||
|
/**
|
||||||
|
* Flag to indicate that app is exempt from certain metered network restrictions because of it
|
||||||
|
* being a system component.
|
||||||
|
*
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final int ALLOWED_METERED_REASON_SYSTEM = 1 << 17;
|
||||||
|
/**
|
||||||
|
* Flag to indicate that app is exempt from certain metered network restrictions because of it
|
||||||
|
* being in the foreground.
|
||||||
|
*
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final int ALLOWED_METERED_REASON_FOREGROUND = 1 << 18;
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
public static final int ALLOWED_METERED_REASON_MASK = 0xffff0000;
|
public static final int ALLOWED_METERED_REASON_MASK = 0xffff0000;
|
||||||
|
|||||||
@@ -58,7 +58,9 @@ import static android.net.NetworkIdentity.OEM_NONE;
|
|||||||
import static android.net.NetworkPolicy.LIMIT_DISABLED;
|
import static android.net.NetworkPolicy.LIMIT_DISABLED;
|
||||||
import static android.net.NetworkPolicy.SNOOZE_NEVER;
|
import static android.net.NetworkPolicy.SNOOZE_NEVER;
|
||||||
import static android.net.NetworkPolicy.WARNING_DISABLED;
|
import static android.net.NetworkPolicy.WARNING_DISABLED;
|
||||||
|
import static android.net.NetworkPolicyManager.ALLOWED_METERED_REASON_FOREGROUND;
|
||||||
import static android.net.NetworkPolicyManager.ALLOWED_METERED_REASON_MASK;
|
import static android.net.NetworkPolicyManager.ALLOWED_METERED_REASON_MASK;
|
||||||
|
import static android.net.NetworkPolicyManager.ALLOWED_METERED_REASON_SYSTEM;
|
||||||
import static android.net.NetworkPolicyManager.ALLOWED_METERED_REASON_USER_EXEMPTED;
|
import static android.net.NetworkPolicyManager.ALLOWED_METERED_REASON_USER_EXEMPTED;
|
||||||
import static android.net.NetworkPolicyManager.ALLOWED_REASON_FOREGROUND;
|
import static android.net.NetworkPolicyManager.ALLOWED_REASON_FOREGROUND;
|
||||||
import static android.net.NetworkPolicyManager.ALLOWED_REASON_NONE;
|
import static android.net.NetworkPolicyManager.ALLOWED_REASON_NONE;
|
||||||
@@ -4634,8 +4636,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
newBlockedReasons |= (mRestrictBackground ? BLOCKED_METERED_REASON_DATA_SAVER : 0);
|
newBlockedReasons |= (mRestrictBackground ? BLOCKED_METERED_REASON_DATA_SAVER : 0);
|
||||||
newBlockedReasons |= (isDenied ? BLOCKED_METERED_REASON_USER_RESTRICTED : 0);
|
newBlockedReasons |= (isDenied ? BLOCKED_METERED_REASON_USER_RESTRICTED : 0);
|
||||||
|
|
||||||
newAllowedReasons |= (isSystem(uid) ? ALLOWED_REASON_SYSTEM : 0);
|
newAllowedReasons |= (isSystem(uid) ? ALLOWED_METERED_REASON_SYSTEM : 0);
|
||||||
newAllowedReasons |= (isForeground ? ALLOWED_REASON_FOREGROUND : 0);
|
newAllowedReasons |= (isForeground ? ALLOWED_METERED_REASON_FOREGROUND : 0);
|
||||||
newAllowedReasons |= (isAllowed ? ALLOWED_METERED_REASON_USER_EXEMPTED : 0);
|
newAllowedReasons |= (isAllowed ? ALLOWED_METERED_REASON_USER_EXEMPTED : 0);
|
||||||
|
|
||||||
if (LOGV) {
|
if (LOGV) {
|
||||||
@@ -4709,6 +4711,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
|
|
||||||
// Dispatch changed rule to existing listeners.
|
// Dispatch changed rule to existing listeners.
|
||||||
mHandler.obtainMessage(MSG_RULES_CHANGED, uid, newUidRules).sendToTarget();
|
mHandler.obtainMessage(MSG_RULES_CHANGED, uid, newUidRules).sendToTarget();
|
||||||
|
}
|
||||||
|
|
||||||
final int oldEffectiveBlockedReasons = uidBlockedState.effectiveBlockedReasons;
|
final int oldEffectiveBlockedReasons = uidBlockedState.effectiveBlockedReasons;
|
||||||
uidBlockedState.blockedReasons = (uidBlockedState.blockedReasons
|
uidBlockedState.blockedReasons = (uidBlockedState.blockedReasons
|
||||||
@@ -4722,7 +4725,6 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
.sendToTarget();
|
.sendToTarget();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the power-related part of the {@link #mUidRules} for a given map, and notify external
|
* Updates the power-related part of the {@link #mUidRules} for a given map, and notify external
|
||||||
@@ -5868,12 +5870,17 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((allowedReasons & ALLOWED_REASON_SYSTEM) != 0) {
|
if ((allowedReasons & ALLOWED_REASON_SYSTEM) != 0) {
|
||||||
effectiveBlockedReasons = BLOCKED_REASON_NONE;
|
effectiveBlockedReasons = (blockedReasons & ALLOWED_METERED_REASON_MASK);
|
||||||
|
}
|
||||||
|
if ((allowedReasons & ALLOWED_METERED_REASON_SYSTEM) != 0) {
|
||||||
|
effectiveBlockedReasons = (blockedReasons & ~ALLOWED_METERED_REASON_MASK);
|
||||||
}
|
}
|
||||||
if ((allowedReasons & ALLOWED_REASON_FOREGROUND) != 0) {
|
if ((allowedReasons & ALLOWED_REASON_FOREGROUND) != 0) {
|
||||||
effectiveBlockedReasons &= ~BLOCKED_REASON_BATTERY_SAVER;
|
effectiveBlockedReasons &= ~BLOCKED_REASON_BATTERY_SAVER;
|
||||||
effectiveBlockedReasons &= ~BLOCKED_REASON_DOZE;
|
effectiveBlockedReasons &= ~BLOCKED_REASON_DOZE;
|
||||||
effectiveBlockedReasons &= ~BLOCKED_REASON_APP_STANDBY;
|
effectiveBlockedReasons &= ~BLOCKED_REASON_APP_STANDBY;
|
||||||
|
}
|
||||||
|
if ((allowedReasons & ALLOWED_METERED_REASON_FOREGROUND) != 0) {
|
||||||
effectiveBlockedReasons &= ~BLOCKED_METERED_REASON_DATA_SAVER;
|
effectiveBlockedReasons &= ~BLOCKED_METERED_REASON_DATA_SAVER;
|
||||||
effectiveBlockedReasons &= ~BLOCKED_METERED_REASON_USER_RESTRICTED;
|
effectiveBlockedReasons &= ~BLOCKED_METERED_REASON_USER_RESTRICTED;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user