Merge "Revert "Add an API to listen for changes in network blocked status of an uid.""
This commit is contained in:
@@ -72,8 +72,8 @@ import static android.net.NetworkCapabilities.NET_CAPABILITY_VALIDATED;
|
||||
import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
|
||||
import static android.net.NetworkCapabilities.TRANSPORT_TEST;
|
||||
import static android.net.NetworkCapabilities.TRANSPORT_VPN;
|
||||
import static android.net.NetworkPolicyManager.BLOCKED_REASON_NONE;
|
||||
import static android.net.NetworkPolicyManager.blockedReasonsToString;
|
||||
import static android.net.NetworkPolicyManager.RULE_NONE;
|
||||
import static android.net.NetworkPolicyManager.uidRulesToString;
|
||||
import static android.net.NetworkRequest.Type.LISTEN_FOR_BEST;
|
||||
import static android.net.shared.NetworkMonitorUtils.isPrivateDnsValidationRequired;
|
||||
import static android.os.Process.INVALID_UID;
|
||||
@@ -117,6 +117,7 @@ import android.net.INetd;
|
||||
import android.net.INetworkActivityListener;
|
||||
import android.net.INetworkMonitor;
|
||||
import android.net.INetworkMonitorCallbacks;
|
||||
import android.net.INetworkPolicyListener;
|
||||
import android.net.IOnCompleteListener;
|
||||
import android.net.IQosCallback;
|
||||
import android.net.ISocketKeepaliveCallback;
|
||||
@@ -134,7 +135,6 @@ import android.net.NetworkInfo;
|
||||
import android.net.NetworkInfo.DetailedState;
|
||||
import android.net.NetworkMonitorManager;
|
||||
import android.net.NetworkPolicyManager;
|
||||
import android.net.NetworkPolicyManager.NetworkPolicyCallback;
|
||||
import android.net.NetworkProvider;
|
||||
import android.net.NetworkRequest;
|
||||
import android.net.NetworkScore;
|
||||
@@ -331,10 +331,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
private volatile boolean mLockdownEnabled;
|
||||
|
||||
/**
|
||||
* Stale copy of uid blocked reasons provided by NPMS. As long as they are accessed only in
|
||||
* internal handler thread, they don't need a lock.
|
||||
* Stale copy of uid rules provided by NPMS. As long as they are accessed only in internal
|
||||
* handler thread, they don't need a lock.
|
||||
*/
|
||||
private SparseIntArray mUidBlockedReasons = new SparseIntArray();
|
||||
private SparseIntArray mUidRules = new SparseIntArray();
|
||||
/** Flag indicating if background data is restricted. */
|
||||
private boolean mRestrictBackground;
|
||||
|
||||
private final Context mContext;
|
||||
private final ConnectivityResources mResources;
|
||||
@@ -508,6 +510,16 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
// Handle private DNS validation status updates.
|
||||
private static final int EVENT_PRIVATE_DNS_VALIDATION_UPDATE = 38;
|
||||
|
||||
/**
|
||||
* Used to handle onUidRulesChanged event from NetworkPolicyManagerService.
|
||||
*/
|
||||
private static final int EVENT_UID_RULES_CHANGED = 39;
|
||||
|
||||
/**
|
||||
* Used to handle onRestrictBackgroundChanged event from NetworkPolicyManagerService.
|
||||
*/
|
||||
private static final int EVENT_DATA_SAVER_CHANGED = 40;
|
||||
|
||||
/**
|
||||
* Event for NetworkMonitor/NetworkAgentInfo to inform ConnectivityService that the network has
|
||||
* been tested.
|
||||
@@ -583,13 +595,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
*/
|
||||
private static final int EVENT_SET_PROFILE_NETWORK_PREFERENCE = 50;
|
||||
|
||||
/**
|
||||
* Event to specify that reasons for why an uid is blocked changed.
|
||||
* arg1 = uid
|
||||
* arg2 = blockedReasons
|
||||
*/
|
||||
private static final int EVENT_UID_BLOCKED_REASON_CHANGED = 51;
|
||||
|
||||
/**
|
||||
* Argument for {@link #EVENT_PROVISIONING_NOTIFICATION} to indicate that the notification
|
||||
* should be shown.
|
||||
@@ -1248,10 +1253,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
|
||||
mLocationPermissionChecker = new LocationPermissionChecker(mContext);
|
||||
|
||||
// To ensure uid state is synchronized with Network Policy, register for
|
||||
// To ensure uid rules are synchronized with Network Policy, register for
|
||||
// NetworkPolicyManagerService events must happen prior to NetworkPolicyManagerService
|
||||
// reading existing policy from disk.
|
||||
mPolicyManager.registerNetworkPolicyCallback(null, mPolicyCallback);
|
||||
mPolicyManager.registerListener(mPolicyListener);
|
||||
|
||||
final PowerManager powerManager = (PowerManager) context.getSystemService(
|
||||
Context.POWER_SERVICE);
|
||||
@@ -2232,17 +2237,53 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
}
|
||||
}
|
||||
|
||||
private final NetworkPolicyCallback mPolicyCallback = new NetworkPolicyCallback() {
|
||||
private final INetworkPolicyListener mPolicyListener = new NetworkPolicyManager.Listener() {
|
||||
@Override
|
||||
public void onUidBlockedReasonChanged(int uid, int blockedReasons) {
|
||||
mHandler.sendMessage(mHandler.obtainMessage(EVENT_UID_BLOCKED_REASON_CHANGED,
|
||||
uid, blockedReasons));
|
||||
public void onUidRulesChanged(int uid, int uidRules) {
|
||||
mHandler.sendMessage(mHandler.obtainMessage(EVENT_UID_RULES_CHANGED, uid, uidRules));
|
||||
}
|
||||
@Override
|
||||
public void onRestrictBackgroundChanged(boolean restrictBackground) {
|
||||
// caller is NPMS, since we only register with them
|
||||
if (LOGD_BLOCKED_NETWORKINFO) {
|
||||
log("onRestrictBackgroundChanged(restrictBackground=" + restrictBackground + ")");
|
||||
}
|
||||
mHandler.sendMessage(mHandler.obtainMessage(
|
||||
EVENT_DATA_SAVER_CHANGED, restrictBackground ? 1 : 0, 0));
|
||||
}
|
||||
};
|
||||
|
||||
void handleUidBlockedReasonChanged(int uid, int blockedReasons) {
|
||||
maybeNotifyNetworkBlockedForNewState(uid, blockedReasons);
|
||||
mUidBlockedReasons.put(uid, blockedReasons);
|
||||
void handleUidRulesChanged(int uid, int newRules) {
|
||||
// skip update when we've already applied rules
|
||||
final int oldRules = mUidRules.get(uid, RULE_NONE);
|
||||
if (oldRules == newRules) return;
|
||||
|
||||
maybeNotifyNetworkBlockedForNewUidRules(uid, newRules);
|
||||
|
||||
if (newRules == RULE_NONE) {
|
||||
mUidRules.delete(uid);
|
||||
} else {
|
||||
mUidRules.put(uid, newRules);
|
||||
}
|
||||
}
|
||||
|
||||
void handleRestrictBackgroundChanged(boolean restrictBackground) {
|
||||
if (mRestrictBackground == restrictBackground) return;
|
||||
|
||||
final List<UidRange> blockedRanges = mVpnBlockedUidRanges;
|
||||
for (final NetworkAgentInfo nai : mNetworkAgentInfos) {
|
||||
final boolean curMetered = nai.networkCapabilities.isMetered();
|
||||
maybeNotifyNetworkBlocked(nai, curMetered, curMetered, mRestrictBackground,
|
||||
restrictBackground, blockedRanges, blockedRanges);
|
||||
}
|
||||
|
||||
mRestrictBackground = restrictBackground;
|
||||
}
|
||||
|
||||
private boolean isUidBlockedByRules(int uid, int uidRules, boolean isNetworkMetered,
|
||||
boolean isBackgroundRestricted) {
|
||||
return mPolicyManager.checkUidNetworkingBlocked(uid, uidRules, isNetworkMetered,
|
||||
isBackgroundRestricted);
|
||||
}
|
||||
|
||||
private boolean checkAnyPermissionOf(String... permissions) {
|
||||
@@ -2716,16 +2757,19 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
pw.decreaseIndent();
|
||||
pw.println();
|
||||
|
||||
pw.print("Restrict background: ");
|
||||
pw.println(mRestrictBackground);
|
||||
pw.println();
|
||||
|
||||
pw.println("Status for known UIDs:");
|
||||
pw.increaseIndent();
|
||||
final int size = mUidBlockedReasons.size();
|
||||
final int size = mUidRules.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
// Don't crash if the array is modified while dumping in bugreports.
|
||||
try {
|
||||
final int uid = mUidBlockedReasons.keyAt(i);
|
||||
final int blockedReasons = mUidBlockedReasons.valueAt(i);
|
||||
pw.println("UID=" + uid + " blockedReasons="
|
||||
+ blockedReasonsToString(blockedReasons));
|
||||
final int uid = mUidRules.keyAt(i);
|
||||
final int uidRules = mUidRules.get(uid, RULE_NONE);
|
||||
pw.println("UID=" + uid + " rules=" + uidRulesToString(uidRules));
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
pw.println(" ArrayIndexOutOfBoundsException");
|
||||
} catch (ConcurrentModificationException e) {
|
||||
@@ -4522,8 +4566,11 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
handlePrivateDnsValidationUpdate(
|
||||
(PrivateDnsValidationUpdate) msg.obj);
|
||||
break;
|
||||
case EVENT_UID_BLOCKED_REASON_CHANGED:
|
||||
handleUidBlockedReasonChanged(msg.arg1, msg.arg2);
|
||||
case EVENT_UID_RULES_CHANGED:
|
||||
handleUidRulesChanged(msg.arg1, msg.arg2);
|
||||
break;
|
||||
case EVENT_DATA_SAVER_CHANGED:
|
||||
handleRestrictBackgroundChanged(toBool(msg.arg1));
|
||||
break;
|
||||
case EVENT_SET_REQUIRE_VPN_FOR_UIDS:
|
||||
handleSetRequireVpnForUids(toBool(msg.arg1), (UidRange[]) msg.obj);
|
||||
@@ -4996,8 +5043,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
|
||||
for (final NetworkAgentInfo nai : mNetworkAgentInfos) {
|
||||
final boolean curMetered = nai.networkCapabilities.isMetered();
|
||||
maybeNotifyNetworkBlocked(nai, curMetered, curMetered,
|
||||
mVpnBlockedUidRanges, newVpnBlockedUidRanges);
|
||||
maybeNotifyNetworkBlocked(nai, curMetered, curMetered, mRestrictBackground,
|
||||
mRestrictBackground, mVpnBlockedUidRanges, newVpnBlockedUidRanges);
|
||||
}
|
||||
|
||||
mVpnBlockedUidRanges = newVpnBlockedUidRanges;
|
||||
@@ -6780,8 +6827,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
final boolean meteredChanged = oldMetered != newMetered;
|
||||
|
||||
if (meteredChanged) {
|
||||
maybeNotifyNetworkBlocked(nai, oldMetered, newMetered,
|
||||
mVpnBlockedUidRanges, mVpnBlockedUidRanges);
|
||||
maybeNotifyNetworkBlocked(nai, oldMetered, newMetered, mRestrictBackground,
|
||||
mRestrictBackground, mVpnBlockedUidRanges, mVpnBlockedUidRanges);
|
||||
}
|
||||
|
||||
final boolean roamingChanged = prevNc.hasCapability(NET_CAPABILITY_NOT_ROAMING)
|
||||
@@ -7904,8 +7951,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
final boolean metered = nai.networkCapabilities.isMetered();
|
||||
boolean blocked;
|
||||
blocked = isUidBlockedByVpn(nri.mUid, mVpnBlockedUidRanges);
|
||||
blocked |= NetworkPolicyManager.isUidBlocked(
|
||||
mUidBlockedReasons.get(nri.mUid, BLOCKED_REASON_NONE), metered);
|
||||
blocked |= isUidBlockedByRules(nri.mUid, mUidRules.get(nri.mUid),
|
||||
metered, mRestrictBackground);
|
||||
callCallbackForRequest(nri, nai, ConnectivityManager.CALLBACK_AVAILABLE, blocked ? 1 : 0);
|
||||
}
|
||||
|
||||
@@ -7923,14 +7970,16 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
*
|
||||
* @param nai The target NetworkAgentInfo.
|
||||
* @param oldMetered True if the previous network capabilities is metered.
|
||||
* @param newRestrictBackground True if data saver is enabled.
|
||||
*/
|
||||
private void maybeNotifyNetworkBlocked(NetworkAgentInfo nai, boolean oldMetered,
|
||||
boolean newMetered, List<UidRange> oldBlockedUidRanges,
|
||||
List<UidRange> newBlockedUidRanges) {
|
||||
boolean newMetered, boolean oldRestrictBackground, boolean newRestrictBackground,
|
||||
List<UidRange> oldBlockedUidRanges, List<UidRange> newBlockedUidRanges) {
|
||||
|
||||
for (int i = 0; i < nai.numNetworkRequests(); i++) {
|
||||
NetworkRequest nr = nai.requestAt(i);
|
||||
NetworkRequestInfo nri = mNetworkRequests.get(nr);
|
||||
final int uidRules = mUidRules.get(nri.mUid);
|
||||
final boolean oldBlocked, newBlocked, oldVpnBlocked, newVpnBlocked;
|
||||
|
||||
oldVpnBlocked = isUidBlockedByVpn(nri.mUid, oldBlockedUidRanges);
|
||||
@@ -7938,11 +7987,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
? isUidBlockedByVpn(nri.mUid, newBlockedUidRanges)
|
||||
: oldVpnBlocked;
|
||||
|
||||
final int blockedReasons = mUidBlockedReasons.get(nri.mUid, BLOCKED_REASON_NONE);
|
||||
oldBlocked = oldVpnBlocked || NetworkPolicyManager.isUidBlocked(
|
||||
blockedReasons, oldMetered);
|
||||
newBlocked = newVpnBlocked || NetworkPolicyManager.isUidBlocked(
|
||||
blockedReasons, newMetered);
|
||||
oldBlocked = oldVpnBlocked || isUidBlockedByRules(nri.mUid, uidRules, oldMetered,
|
||||
oldRestrictBackground);
|
||||
newBlocked = newVpnBlocked || isUidBlockedByRules(nri.mUid, uidRules, newMetered,
|
||||
newRestrictBackground);
|
||||
|
||||
if (oldBlocked != newBlocked) {
|
||||
callCallbackForRequest(nri, nai, ConnectivityManager.CALLBACK_BLK_CHANGED,
|
||||
@@ -7952,20 +8000,19 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify apps with a given UID of the new blocked state according to new uid state.
|
||||
* Notify apps with a given UID of the new blocked state according to new uid rules.
|
||||
* @param uid The uid for which the rules changed.
|
||||
* @param blockedReasons The reasons for why an uid is blocked.
|
||||
* @param newRules The new rules to apply.
|
||||
*/
|
||||
private void maybeNotifyNetworkBlockedForNewState(int uid, int blockedReasons) {
|
||||
private void maybeNotifyNetworkBlockedForNewUidRules(int uid, int newRules) {
|
||||
for (final NetworkAgentInfo nai : mNetworkAgentInfos) {
|
||||
final boolean metered = nai.networkCapabilities.isMetered();
|
||||
final boolean vpnBlocked = isUidBlockedByVpn(uid, mVpnBlockedUidRanges);
|
||||
final boolean oldBlocked, newBlocked;
|
||||
|
||||
oldBlocked = vpnBlocked || NetworkPolicyManager.isUidBlocked(
|
||||
mUidBlockedReasons.get(uid, BLOCKED_REASON_NONE), metered);
|
||||
newBlocked = vpnBlocked || NetworkPolicyManager.isUidBlocked(
|
||||
blockedReasons, metered);
|
||||
oldBlocked = vpnBlocked || isUidBlockedByRules(
|
||||
uid, mUidRules.get(uid), metered, mRestrictBackground);
|
||||
newBlocked = vpnBlocked || isUidBlockedByRules(
|
||||
uid, newRules, metered, mRestrictBackground);
|
||||
if (oldBlocked == newBlocked) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -87,10 +87,10 @@ import static android.net.NetworkCapabilities.TRANSPORT_ETHERNET;
|
||||
import static android.net.NetworkCapabilities.TRANSPORT_VPN;
|
||||
import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
|
||||
import static android.net.NetworkCapabilities.TRANSPORT_WIFI_AWARE;
|
||||
import static android.net.NetworkPolicyManager.BLOCKED_METERED_REASON_DATA_SAVER;
|
||||
import static android.net.NetworkPolicyManager.BLOCKED_METERED_REASON_USER_RESTRICTED;
|
||||
import static android.net.NetworkPolicyManager.BLOCKED_REASON_BATTERY_SAVER;
|
||||
import static android.net.NetworkPolicyManager.BLOCKED_REASON_NONE;
|
||||
import static android.net.NetworkPolicyManager.RULE_ALLOW_METERED;
|
||||
import static android.net.NetworkPolicyManager.RULE_NONE;
|
||||
import static android.net.NetworkPolicyManager.RULE_REJECT_ALL;
|
||||
import static android.net.NetworkPolicyManager.RULE_REJECT_METERED;
|
||||
import static android.net.OemNetworkPreferences.OEM_NETWORK_PREFERENCE_OEM_PAID;
|
||||
import static android.net.OemNetworkPreferences.OEM_NETWORK_PREFERENCE_OEM_PAID_NO_FALLBACK;
|
||||
import static android.net.OemNetworkPreferences.OEM_NETWORK_PREFERENCE_OEM_PAID_ONLY;
|
||||
@@ -188,6 +188,7 @@ import android.net.IDnsResolver;
|
||||
import android.net.INetd;
|
||||
import android.net.INetworkMonitor;
|
||||
import android.net.INetworkMonitorCallbacks;
|
||||
import android.net.INetworkPolicyListener;
|
||||
import android.net.IOnCompleteListener;
|
||||
import android.net.IQosCallback;
|
||||
import android.net.InetAddresses;
|
||||
@@ -206,7 +207,6 @@ import android.net.NetworkFactory;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.NetworkInfo.DetailedState;
|
||||
import android.net.NetworkPolicyManager;
|
||||
import android.net.NetworkPolicyManager.NetworkPolicyCallback;
|
||||
import android.net.NetworkRequest;
|
||||
import android.net.NetworkScore;
|
||||
import android.net.NetworkSpecifier;
|
||||
@@ -423,7 +423,7 @@ public class ConnectivityServiceTest {
|
||||
private TestNetworkAgentWrapper mEthernetNetworkAgent;
|
||||
private MockVpn mMockVpn;
|
||||
private Context mContext;
|
||||
private NetworkPolicyCallback mPolicyCallback;
|
||||
private INetworkPolicyListener mPolicyListener;
|
||||
private WrappedMultinetworkPolicyTracker mPolicyTracker;
|
||||
private HandlerThread mAlarmManagerThread;
|
||||
private TestNetIdManager mNetIdManager;
|
||||
@@ -435,7 +435,8 @@ public class ConnectivityServiceTest {
|
||||
private TestNetworkCallback mProfileDefaultNetworkCallback;
|
||||
|
||||
// State variables required to emulate NetworkPolicyManagerService behaviour.
|
||||
private int mBlockedReasons = BLOCKED_REASON_NONE;
|
||||
private int mUidRules = RULE_NONE;
|
||||
private boolean mRestrictBackground = false;
|
||||
|
||||
@Mock DeviceIdleInternal mDeviceIdleInternal;
|
||||
@Mock INetworkManagementService mNetworkManagementService;
|
||||
@@ -1374,13 +1375,28 @@ public class ConnectivityServiceTest {
|
||||
}
|
||||
|
||||
private void mockUidNetworkingBlocked() {
|
||||
doAnswer(i -> NetworkPolicyManager.isUidBlocked(mBlockedReasons, i.getArgument(1))
|
||||
doAnswer(i -> mContext.getSystemService(NetworkPolicyManager.class)
|
||||
.checkUidNetworkingBlocked(i.getArgument(0) /* uid */, mUidRules,
|
||||
i.getArgument(1) /* metered */, mRestrictBackground)
|
||||
).when(mNetworkPolicyManager).isUidNetworkingBlocked(anyInt(), anyBoolean());
|
||||
|
||||
doAnswer(inv -> mContext.getSystemService(NetworkPolicyManager.class)
|
||||
.checkUidNetworkingBlocked(inv.getArgument(0) /* uid */,
|
||||
inv.getArgument(1) /* uidRules */,
|
||||
inv.getArgument(2) /* isNetworkMetered */,
|
||||
inv.getArgument(3) /* isBackgroundRestricted */)
|
||||
).when(mNetworkPolicyManager).checkUidNetworkingBlocked(
|
||||
anyInt(), anyInt(), anyBoolean(), anyBoolean());
|
||||
}
|
||||
|
||||
private void setBlockedReasonChanged(int blockedReasons) {
|
||||
mBlockedReasons = blockedReasons;
|
||||
mPolicyCallback.onUidBlockedReasonChanged(Process.myUid(), blockedReasons);
|
||||
private void setUidRulesChanged(int uidRules) throws RemoteException {
|
||||
mUidRules = uidRules;
|
||||
mPolicyListener.onUidRulesChanged(Process.myUid(), mUidRules);
|
||||
}
|
||||
|
||||
private void setRestrictBackgroundChanged(boolean restrictBackground) throws RemoteException {
|
||||
mRestrictBackground = restrictBackground;
|
||||
mPolicyListener.onRestrictBackgroundChanged(mRestrictBackground);
|
||||
}
|
||||
|
||||
private Nat464Xlat getNat464Xlat(NetworkAgentWrapper mna) {
|
||||
@@ -1522,11 +1538,10 @@ public class ConnectivityServiceTest {
|
||||
mService.mNascentDelayMs = TEST_NASCENT_DELAY_MS;
|
||||
verify(mDeps).makeMultinetworkPolicyTracker(any(), any(), any());
|
||||
|
||||
final ArgumentCaptor<NetworkPolicyCallback> policyCallbackCaptor =
|
||||
ArgumentCaptor.forClass(NetworkPolicyCallback.class);
|
||||
verify(mNetworkPolicyManager).registerNetworkPolicyCallback(any(),
|
||||
policyCallbackCaptor.capture());
|
||||
mPolicyCallback = policyCallbackCaptor.getValue();
|
||||
final ArgumentCaptor<INetworkPolicyListener> policyListenerCaptor =
|
||||
ArgumentCaptor.forClass(INetworkPolicyListener.class);
|
||||
verify(mNetworkPolicyManager).registerListener(policyListenerCaptor.capture());
|
||||
mPolicyListener = policyListenerCaptor.getValue();
|
||||
|
||||
// Create local CM before sending system ready so that we can answer
|
||||
// getSystemService() correctly.
|
||||
@@ -7250,7 +7265,7 @@ public class ConnectivityServiceTest {
|
||||
assertNetworkInfo(TYPE_MOBILE, DetailedState.CONNECTED);
|
||||
assertExtraInfoFromCmPresent(mCellNetworkAgent);
|
||||
|
||||
setBlockedReasonChanged(BLOCKED_REASON_BATTERY_SAVER);
|
||||
setUidRulesChanged(RULE_REJECT_ALL);
|
||||
cellNetworkCallback.expectBlockedStatusCallback(true, mCellNetworkAgent);
|
||||
assertNull(mCm.getActiveNetwork());
|
||||
assertActiveNetworkInfo(TYPE_MOBILE, DetailedState.BLOCKED);
|
||||
@@ -7258,17 +7273,17 @@ public class ConnectivityServiceTest {
|
||||
assertExtraInfoFromCmBlocked(mCellNetworkAgent);
|
||||
|
||||
// ConnectivityService should cache it not to invoke the callback again.
|
||||
setBlockedReasonChanged(BLOCKED_METERED_REASON_USER_RESTRICTED);
|
||||
setUidRulesChanged(RULE_REJECT_METERED);
|
||||
cellNetworkCallback.assertNoCallback();
|
||||
|
||||
setBlockedReasonChanged(BLOCKED_REASON_NONE);
|
||||
setUidRulesChanged(RULE_NONE);
|
||||
cellNetworkCallback.expectBlockedStatusCallback(false, mCellNetworkAgent);
|
||||
assertEquals(mCellNetworkAgent.getNetwork(), mCm.getActiveNetwork());
|
||||
assertActiveNetworkInfo(TYPE_MOBILE, DetailedState.CONNECTED);
|
||||
assertNetworkInfo(TYPE_MOBILE, DetailedState.CONNECTED);
|
||||
assertExtraInfoFromCmPresent(mCellNetworkAgent);
|
||||
|
||||
setBlockedReasonChanged(BLOCKED_METERED_REASON_DATA_SAVER);
|
||||
setUidRulesChanged(RULE_REJECT_METERED);
|
||||
cellNetworkCallback.expectBlockedStatusCallback(true, mCellNetworkAgent);
|
||||
assertNull(mCm.getActiveNetwork());
|
||||
assertActiveNetworkInfo(TYPE_MOBILE, DetailedState.BLOCKED);
|
||||
@@ -7293,33 +7308,33 @@ public class ConnectivityServiceTest {
|
||||
assertNetworkInfo(TYPE_MOBILE, DetailedState.BLOCKED);
|
||||
assertExtraInfoFromCmBlocked(mCellNetworkAgent);
|
||||
|
||||
setBlockedReasonChanged(BLOCKED_REASON_NONE);
|
||||
setUidRulesChanged(RULE_ALLOW_METERED);
|
||||
cellNetworkCallback.expectBlockedStatusCallback(false, mCellNetworkAgent);
|
||||
assertEquals(mCellNetworkAgent.getNetwork(), mCm.getActiveNetwork());
|
||||
assertActiveNetworkInfo(TYPE_MOBILE, DetailedState.CONNECTED);
|
||||
assertNetworkInfo(TYPE_MOBILE, DetailedState.CONNECTED);
|
||||
assertExtraInfoFromCmPresent(mCellNetworkAgent);
|
||||
|
||||
setBlockedReasonChanged(BLOCKED_REASON_NONE);
|
||||
setUidRulesChanged(RULE_NONE);
|
||||
cellNetworkCallback.assertNoCallback();
|
||||
|
||||
// Restrict background data. Networking is not blocked because the network is unmetered.
|
||||
setBlockedReasonChanged(BLOCKED_METERED_REASON_DATA_SAVER);
|
||||
setRestrictBackgroundChanged(true);
|
||||
cellNetworkCallback.expectBlockedStatusCallback(true, mCellNetworkAgent);
|
||||
assertNull(mCm.getActiveNetwork());
|
||||
assertActiveNetworkInfo(TYPE_MOBILE, DetailedState.BLOCKED);
|
||||
assertNetworkInfo(TYPE_MOBILE, DetailedState.BLOCKED);
|
||||
assertExtraInfoFromCmBlocked(mCellNetworkAgent);
|
||||
setBlockedReasonChanged(BLOCKED_METERED_REASON_DATA_SAVER);
|
||||
setRestrictBackgroundChanged(true);
|
||||
cellNetworkCallback.assertNoCallback();
|
||||
|
||||
setBlockedReasonChanged(BLOCKED_REASON_NONE);
|
||||
setUidRulesChanged(RULE_ALLOW_METERED);
|
||||
cellNetworkCallback.expectBlockedStatusCallback(false, mCellNetworkAgent);
|
||||
assertActiveNetworkInfo(TYPE_MOBILE, DetailedState.CONNECTED);
|
||||
assertNetworkInfo(TYPE_MOBILE, DetailedState.CONNECTED);
|
||||
assertExtraInfoFromCmPresent(mCellNetworkAgent);
|
||||
|
||||
setBlockedReasonChanged(BLOCKED_REASON_NONE);
|
||||
setRestrictBackgroundChanged(false);
|
||||
cellNetworkCallback.assertNoCallback();
|
||||
assertEquals(mCellNetworkAgent.getNetwork(), mCm.getActiveNetwork());
|
||||
assertActiveNetworkInfo(TYPE_MOBILE, DetailedState.CONNECTED);
|
||||
@@ -7336,9 +7351,9 @@ public class ConnectivityServiceTest {
|
||||
mockUidNetworkingBlocked();
|
||||
|
||||
// No Networkcallbacks invoked before any network is active.
|
||||
setBlockedReasonChanged(BLOCKED_REASON_BATTERY_SAVER);
|
||||
setBlockedReasonChanged(BLOCKED_REASON_NONE);
|
||||
setBlockedReasonChanged(BLOCKED_METERED_REASON_DATA_SAVER);
|
||||
setUidRulesChanged(RULE_REJECT_ALL);
|
||||
setUidRulesChanged(RULE_NONE);
|
||||
setUidRulesChanged(RULE_REJECT_METERED);
|
||||
defaultCallback.assertNoCallback();
|
||||
|
||||
mCellNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_CELLULAR);
|
||||
@@ -7363,8 +7378,8 @@ public class ConnectivityServiceTest {
|
||||
defaultCallback.expectBlockedStatusCallback(false, mCellNetworkAgent);
|
||||
|
||||
// Verify there's no Networkcallbacks invoked after data saver on/off.
|
||||
setBlockedReasonChanged(BLOCKED_METERED_REASON_DATA_SAVER);
|
||||
setBlockedReasonChanged(BLOCKED_REASON_NONE);
|
||||
setRestrictBackgroundChanged(true);
|
||||
setRestrictBackgroundChanged(false);
|
||||
defaultCallback.assertNoCallback();
|
||||
|
||||
mCellNetworkAgent.disconnect();
|
||||
|
||||
Reference in New Issue
Block a user