Merge "Better notification to user when DNS-over-TLS is broken" am: f42f3830ec am: 6a78c78996 am: e2bb0da748
am: d72606c43d
Change-Id: Iffbdc181d8249f26b3c370474583673aaa1c5032
This commit is contained in:
@@ -57,6 +57,9 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
private static final String TAG = "NetworkCapabilities";
|
private static final String TAG = "NetworkCapabilities";
|
||||||
private static final int INVALID_UID = -1;
|
private static final int INVALID_UID = -1;
|
||||||
|
|
||||||
|
// Set to true when private DNS is broken.
|
||||||
|
private boolean mPrivateDnsBroken;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@@ -86,6 +89,7 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
mUids = null;
|
mUids = null;
|
||||||
mEstablishingVpnAppUid = INVALID_UID;
|
mEstablishingVpnAppUid = INVALID_UID;
|
||||||
mSSID = null;
|
mSSID = null;
|
||||||
|
mPrivateDnsBroken = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -104,6 +108,7 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
mEstablishingVpnAppUid = nc.mEstablishingVpnAppUid;
|
mEstablishingVpnAppUid = nc.mEstablishingVpnAppUid;
|
||||||
mUnwantedNetworkCapabilities = nc.mUnwantedNetworkCapabilities;
|
mUnwantedNetworkCapabilities = nc.mUnwantedNetworkCapabilities;
|
||||||
mSSID = nc.mSSID;
|
mSSID = nc.mSSID;
|
||||||
|
mPrivateDnsBroken = nc.mPrivateDnsBroken;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -557,6 +562,9 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
}
|
}
|
||||||
if (mLinkUpBandwidthKbps != 0 || mLinkDownBandwidthKbps != 0) return "link bandwidth";
|
if (mLinkUpBandwidthKbps != 0 || mLinkDownBandwidthKbps != 0) return "link bandwidth";
|
||||||
if (hasSignalStrength()) return "signalStrength";
|
if (hasSignalStrength()) return "signalStrength";
|
||||||
|
if (isPrivateDnsBroken()) {
|
||||||
|
return "privateDnsBroken";
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1443,7 +1451,8 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
&& equalsSpecifier(that)
|
&& equalsSpecifier(that)
|
||||||
&& equalsTransportInfo(that)
|
&& equalsTransportInfo(that)
|
||||||
&& equalsUids(that)
|
&& equalsUids(that)
|
||||||
&& equalsSSID(that));
|
&& equalsSSID(that)
|
||||||
|
&& equalsPrivateDnsBroken(that));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1460,7 +1469,8 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
+ (mSignalStrength * 29)
|
+ (mSignalStrength * 29)
|
||||||
+ Objects.hashCode(mUids) * 31
|
+ Objects.hashCode(mUids) * 31
|
||||||
+ Objects.hashCode(mSSID) * 37
|
+ Objects.hashCode(mSSID) * 37
|
||||||
+ Objects.hashCode(mTransportInfo) * 41;
|
+ Objects.hashCode(mTransportInfo) * 41
|
||||||
|
+ Objects.hashCode(mPrivateDnsBroken) * 43;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1479,6 +1489,7 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
dest.writeInt(mSignalStrength);
|
dest.writeInt(mSignalStrength);
|
||||||
dest.writeArraySet(mUids);
|
dest.writeArraySet(mUids);
|
||||||
dest.writeString(mSSID);
|
dest.writeString(mSSID);
|
||||||
|
dest.writeBoolean(mPrivateDnsBroken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final @android.annotation.NonNull Creator<NetworkCapabilities> CREATOR =
|
public static final @android.annotation.NonNull Creator<NetworkCapabilities> CREATOR =
|
||||||
@@ -1498,6 +1509,7 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
netCap.mUids = (ArraySet<UidRange>) in.readArraySet(
|
netCap.mUids = (ArraySet<UidRange>) in.readArraySet(
|
||||||
null /* ClassLoader, null for default */);
|
null /* ClassLoader, null for default */);
|
||||||
netCap.mSSID = in.readString();
|
netCap.mSSID = in.readString();
|
||||||
|
netCap.mPrivateDnsBroken = in.readBoolean();
|
||||||
return netCap;
|
return netCap;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
@@ -1555,6 +1567,10 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
sb.append(" SSID: ").append(mSSID);
|
sb.append(" SSID: ").append(mSSID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mPrivateDnsBroken) {
|
||||||
|
sb.append(" Private DNS is broken");
|
||||||
|
}
|
||||||
|
|
||||||
sb.append("]");
|
sb.append("]");
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
@@ -1706,4 +1722,28 @@ public final class NetworkCapabilities implements Parcelable {
|
|||||||
public boolean isMetered() {
|
public boolean isMetered() {
|
||||||
return !hasCapability(NET_CAPABILITY_NOT_METERED);
|
return !hasCapability(NET_CAPABILITY_NOT_METERED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if private dns is broken.
|
||||||
|
*
|
||||||
|
* @return {@code true} if {@code mPrivateDnsBroken} is set when private DNS is broken.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public boolean isPrivateDnsBroken() {
|
||||||
|
return mPrivateDnsBroken;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set mPrivateDnsBroken to true when private dns is broken.
|
||||||
|
*
|
||||||
|
* @param broken the status of private DNS to be set.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public void setPrivateDnsBroken(boolean broken) {
|
||||||
|
mPrivateDnsBroken = broken;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean equalsPrivateDnsBroken(NetworkCapabilities nc) {
|
||||||
|
return mPrivateDnsBroken == nc.mPrivateDnsBroken;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,6 +77,12 @@ public class NetworkMisc implements Parcelable {
|
|||||||
*/
|
*/
|
||||||
public boolean skip464xlat;
|
public boolean skip464xlat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set to true if the PRIVATE_DNS_BROKEN notification has shown for this network.
|
||||||
|
* Reset this bit when private DNS mode is changed from strict mode to opportunistic/off mode.
|
||||||
|
*/
|
||||||
|
public boolean hasShownBroken;
|
||||||
|
|
||||||
public NetworkMisc() {
|
public NetworkMisc() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import static android.net.ConnectivityManager.TYPE_NONE;
|
|||||||
import static android.net.ConnectivityManager.TYPE_VPN;
|
import static android.net.ConnectivityManager.TYPE_VPN;
|
||||||
import static android.net.ConnectivityManager.getNetworkTypeName;
|
import static android.net.ConnectivityManager.getNetworkTypeName;
|
||||||
import static android.net.ConnectivityManager.isNetworkTypeValid;
|
import static android.net.ConnectivityManager.isNetworkTypeValid;
|
||||||
|
import static android.net.INetworkMonitor.NETWORK_VALIDATION_PROBE_PRIVDNS;
|
||||||
import static android.net.INetworkMonitor.NETWORK_VALIDATION_RESULT_PARTIAL;
|
import static android.net.INetworkMonitor.NETWORK_VALIDATION_RESULT_PARTIAL;
|
||||||
import static android.net.INetworkMonitor.NETWORK_VALIDATION_RESULT_VALID;
|
import static android.net.INetworkMonitor.NETWORK_VALIDATION_RESULT_VALID;
|
||||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_CAPTIVE_PORTAL;
|
import static android.net.NetworkCapabilities.NET_CAPABILITY_CAPTIVE_PORTAL;
|
||||||
@@ -527,6 +528,15 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
*/
|
*/
|
||||||
private static final int EVENT_SET_ACCEPT_PARTIAL_CONNECTIVITY = 45;
|
private static final int EVENT_SET_ACCEPT_PARTIAL_CONNECTIVITY = 45;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event for NetworkMonitor to inform ConnectivityService that the probe status has changed.
|
||||||
|
* Both of the arguments are bitmasks, and the value of bits come from
|
||||||
|
* INetworkMonitor.NETWORK_VALIDATION_PROBE_*.
|
||||||
|
* arg1 = A bitmask to describe which probes are completed.
|
||||||
|
* arg2 = A bitmask to describe which probes are successful.
|
||||||
|
*/
|
||||||
|
public static final int EVENT_PROBE_STATUS_CHANGED = 46;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Argument for {@link #EVENT_PROVISIONING_NOTIFICATION} to indicate that the notification
|
* Argument for {@link #EVENT_PROVISIONING_NOTIFICATION} to indicate that the notification
|
||||||
* should be shown.
|
* should be shown.
|
||||||
@@ -2663,6 +2673,41 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
switch (msg.what) {
|
switch (msg.what) {
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
case EVENT_PROBE_STATUS_CHANGED: {
|
||||||
|
final Integer netId = (Integer) msg.obj;
|
||||||
|
final NetworkAgentInfo nai = getNetworkAgentInfoForNetId(netId);
|
||||||
|
if (nai == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
final boolean probePrivateDnsCompleted =
|
||||||
|
((msg.arg1 & NETWORK_VALIDATION_PROBE_PRIVDNS) != 0);
|
||||||
|
final boolean privateDnsBroken =
|
||||||
|
((msg.arg2 & NETWORK_VALIDATION_PROBE_PRIVDNS) == 0);
|
||||||
|
if (probePrivateDnsCompleted) {
|
||||||
|
if (nai.networkCapabilities.isPrivateDnsBroken() != privateDnsBroken) {
|
||||||
|
nai.networkCapabilities.setPrivateDnsBroken(privateDnsBroken);
|
||||||
|
final int oldScore = nai.getCurrentScore();
|
||||||
|
updateCapabilities(oldScore, nai, nai.networkCapabilities);
|
||||||
|
}
|
||||||
|
// Only show the notification when the private DNS is broken and the
|
||||||
|
// PRIVATE_DNS_BROKEN notification hasn't shown since last valid.
|
||||||
|
if (privateDnsBroken && !nai.networkMisc.hasShownBroken) {
|
||||||
|
showNetworkNotification(nai, NotificationType.PRIVATE_DNS_BROKEN);
|
||||||
|
}
|
||||||
|
nai.networkMisc.hasShownBroken = privateDnsBroken;
|
||||||
|
} else if (nai.networkCapabilities.isPrivateDnsBroken()) {
|
||||||
|
// If probePrivateDnsCompleted is false but nai.networkCapabilities says
|
||||||
|
// private DNS is broken, it means this network is being reevaluated.
|
||||||
|
// Either probing private DNS is not necessary any more or it hasn't been
|
||||||
|
// done yet. In either case, the networkCapabilities should be updated to
|
||||||
|
// reflect the new status.
|
||||||
|
nai.networkCapabilities.setPrivateDnsBroken(false);
|
||||||
|
final int oldScore = nai.getCurrentScore();
|
||||||
|
updateCapabilities(oldScore, nai, nai.networkCapabilities);
|
||||||
|
nai.networkMisc.hasShownBroken = false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case EVENT_NETWORK_TESTED: {
|
case EVENT_NETWORK_TESTED: {
|
||||||
final NetworkAgentInfo nai = getNetworkAgentInfoForNetId(msg.arg2);
|
final NetworkAgentInfo nai = getNetworkAgentInfoForNetId(msg.arg2);
|
||||||
if (nai == null) break;
|
if (nai == null) break;
|
||||||
@@ -2705,14 +2750,20 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
if (oldScore != nai.getCurrentScore()) sendUpdatedScoreToFactories(nai);
|
if (oldScore != nai.getCurrentScore()) sendUpdatedScoreToFactories(nai);
|
||||||
if (valid) {
|
if (valid) {
|
||||||
handleFreshlyValidatedNetwork(nai);
|
handleFreshlyValidatedNetwork(nai);
|
||||||
// Clear NO_INTERNET, PARTIAL_CONNECTIVITY and LOST_INTERNET
|
// Clear NO_INTERNET, PRIVATE_DNS_BROKEN, PARTIAL_CONNECTIVITY and
|
||||||
// notifications if network becomes valid.
|
// LOST_INTERNET notifications if network becomes valid.
|
||||||
mNotifier.clearNotification(nai.network.netId,
|
mNotifier.clearNotification(nai.network.netId,
|
||||||
NotificationType.NO_INTERNET);
|
NotificationType.NO_INTERNET);
|
||||||
mNotifier.clearNotification(nai.network.netId,
|
mNotifier.clearNotification(nai.network.netId,
|
||||||
NotificationType.LOST_INTERNET);
|
NotificationType.LOST_INTERNET);
|
||||||
mNotifier.clearNotification(nai.network.netId,
|
mNotifier.clearNotification(nai.network.netId,
|
||||||
NotificationType.PARTIAL_CONNECTIVITY);
|
NotificationType.PARTIAL_CONNECTIVITY);
|
||||||
|
mNotifier.clearNotification(nai.network.netId,
|
||||||
|
NotificationType.PRIVATE_DNS_BROKEN);
|
||||||
|
// If network becomes valid, the hasShownBroken should be reset for
|
||||||
|
// that network so that the notification will be fired when the private
|
||||||
|
// DNS is broken again.
|
||||||
|
nai.networkMisc.hasShownBroken = false;
|
||||||
}
|
}
|
||||||
} else if (partialConnectivityChanged) {
|
} else if (partialConnectivityChanged) {
|
||||||
updateCapabilities(nai.getCurrentScore(), nai, nai.networkCapabilities);
|
updateCapabilities(nai.getCurrentScore(), nai, nai.networkCapabilities);
|
||||||
@@ -2862,6 +2913,13 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
0, mNetId, PrivateDnsConfig.fromParcel(config)));
|
0, mNetId, PrivateDnsConfig.fromParcel(config)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void notifyProbeStatusChanged(int probesCompleted, int probesSucceeded) {
|
||||||
|
mTrackerHandler.sendMessage(mTrackerHandler.obtainMessage(
|
||||||
|
EVENT_PROBE_STATUS_CHANGED,
|
||||||
|
probesCompleted, probesSucceeded, new Integer(mNetId)));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showProvisioningNotification(String action, String packageName) {
|
public void showProvisioningNotification(String action, String packageName) {
|
||||||
final Intent intent = new Intent(action);
|
final Intent intent = new Intent(action);
|
||||||
@@ -3679,6 +3737,11 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
// High priority because it is only displayed for explicitly selected networks.
|
// High priority because it is only displayed for explicitly selected networks.
|
||||||
highPriority = true;
|
highPriority = true;
|
||||||
break;
|
break;
|
||||||
|
case PRIVATE_DNS_BROKEN:
|
||||||
|
action = Settings.ACTION_WIRELESS_SETTINGS;
|
||||||
|
// High priority because we should let user know why there is no internet.
|
||||||
|
highPriority = true;
|
||||||
|
break;
|
||||||
case LOST_INTERNET:
|
case LOST_INTERNET:
|
||||||
action = ConnectivityManager.ACTION_PROMPT_LOST_VALIDATION;
|
action = ConnectivityManager.ACTION_PROMPT_LOST_VALIDATION;
|
||||||
// High priority because it could help the user avoid unexpected data usage.
|
// High priority because it could help the user avoid unexpected data usage.
|
||||||
@@ -3696,7 +3759,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
Intent intent = new Intent(action);
|
Intent intent = new Intent(action);
|
||||||
if (type != NotificationType.LOGGED_IN) {
|
if (type != NotificationType.LOGGED_IN && type != NotificationType.PRIVATE_DNS_BROKEN) {
|
||||||
intent.setData(Uri.fromParts("netId", Integer.toString(nai.network.netId), null));
|
intent.setData(Uri.fromParts("netId", Integer.toString(nai.network.netId), null));
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
intent.setClassName("com.android.settings",
|
intent.setClassName("com.android.settings",
|
||||||
@@ -5162,6 +5225,13 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
ns.assertValidFromUid(Binder.getCallingUid());
|
ns.assertValidFromUid(Binder.getCallingUid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ensureValid(NetworkCapabilities nc) {
|
||||||
|
ensureValidNetworkSpecifier(nc);
|
||||||
|
if (nc.isPrivateDnsBroken()) {
|
||||||
|
throw new IllegalArgumentException("Can't request broken private DNS");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NetworkRequest requestNetwork(NetworkCapabilities networkCapabilities,
|
public NetworkRequest requestNetwork(NetworkCapabilities networkCapabilities,
|
||||||
Messenger messenger, int timeoutMs, IBinder binder, int legacyType) {
|
Messenger messenger, int timeoutMs, IBinder binder, int legacyType) {
|
||||||
@@ -5195,7 +5265,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
if (timeoutMs < 0) {
|
if (timeoutMs < 0) {
|
||||||
throw new IllegalArgumentException("Bad timeout specified");
|
throw new IllegalArgumentException("Bad timeout specified");
|
||||||
}
|
}
|
||||||
ensureValidNetworkSpecifier(networkCapabilities);
|
ensureValid(networkCapabilities);
|
||||||
|
|
||||||
NetworkRequest networkRequest = new NetworkRequest(networkCapabilities, legacyType,
|
NetworkRequest networkRequest = new NetworkRequest(networkCapabilities, legacyType,
|
||||||
nextNetworkRequestId(), type);
|
nextNetworkRequestId(), type);
|
||||||
@@ -5337,7 +5407,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
// There is no need to do this for requests because an app without CHANGE_NETWORK_STATE
|
// There is no need to do this for requests because an app without CHANGE_NETWORK_STATE
|
||||||
// can't request networks.
|
// can't request networks.
|
||||||
restrictBackgroundRequestForCaller(nc);
|
restrictBackgroundRequestForCaller(nc);
|
||||||
ensureValidNetworkSpecifier(nc);
|
ensureValid(nc);
|
||||||
|
|
||||||
NetworkRequest networkRequest = new NetworkRequest(nc, TYPE_NONE, nextNetworkRequestId(),
|
NetworkRequest networkRequest = new NetworkRequest(nc, TYPE_NONE, nextNetworkRequestId(),
|
||||||
NetworkRequest.Type.LISTEN);
|
NetworkRequest.Type.LISTEN);
|
||||||
@@ -5355,7 +5425,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
if (!hasWifiNetworkListenPermission(networkCapabilities)) {
|
if (!hasWifiNetworkListenPermission(networkCapabilities)) {
|
||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
}
|
}
|
||||||
ensureValidNetworkSpecifier(networkCapabilities);
|
ensureValid(networkCapabilities);
|
||||||
ensureSufficientPermissionsForRequest(networkCapabilities,
|
ensureSufficientPermissionsForRequest(networkCapabilities,
|
||||||
Binder.getCallingPid(), Binder.getCallingUid());
|
Binder.getCallingPid(), Binder.getCallingUid());
|
||||||
|
|
||||||
@@ -5841,6 +5911,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
} else {
|
} else {
|
||||||
newNc.removeCapability(NET_CAPABILITY_PARTIAL_CONNECTIVITY);
|
newNc.removeCapability(NET_CAPABILITY_PARTIAL_CONNECTIVITY);
|
||||||
}
|
}
|
||||||
|
newNc.setPrivateDnsBroken(nai.networkCapabilities.isPrivateDnsBroken());
|
||||||
|
|
||||||
return newNc;
|
return newNc;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,8 @@ public class NetworkNotificationManager {
|
|||||||
NO_INTERNET(SystemMessage.NOTE_NETWORK_NO_INTERNET),
|
NO_INTERNET(SystemMessage.NOTE_NETWORK_NO_INTERNET),
|
||||||
LOGGED_IN(SystemMessage.NOTE_NETWORK_LOGGED_IN),
|
LOGGED_IN(SystemMessage.NOTE_NETWORK_LOGGED_IN),
|
||||||
PARTIAL_CONNECTIVITY(SystemMessage.NOTE_NETWORK_PARTIAL_CONNECTIVITY),
|
PARTIAL_CONNECTIVITY(SystemMessage.NOTE_NETWORK_PARTIAL_CONNECTIVITY),
|
||||||
SIGN_IN(SystemMessage.NOTE_NETWORK_SIGN_IN);
|
SIGN_IN(SystemMessage.NOTE_NETWORK_SIGN_IN),
|
||||||
|
PRIVATE_DNS_BROKEN(SystemMessage.NOTE_NETWORK_PRIVATE_DNS_BROKEN);
|
||||||
|
|
||||||
public final int eventId;
|
public final int eventId;
|
||||||
|
|
||||||
@@ -175,13 +176,23 @@ public class NetworkNotificationManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Resources r = Resources.getSystem();
|
Resources r = Resources.getSystem();
|
||||||
CharSequence title;
|
final CharSequence title;
|
||||||
CharSequence details;
|
final CharSequence details;
|
||||||
int icon = getIcon(transportType, notifyType);
|
int icon = getIcon(transportType, notifyType);
|
||||||
if (notifyType == NotificationType.NO_INTERNET && transportType == TRANSPORT_WIFI) {
|
if (notifyType == NotificationType.NO_INTERNET && transportType == TRANSPORT_WIFI) {
|
||||||
title = r.getString(R.string.wifi_no_internet,
|
title = r.getString(R.string.wifi_no_internet,
|
||||||
WifiInfo.removeDoubleQuotes(nai.networkCapabilities.getSSID()));
|
WifiInfo.removeDoubleQuotes(nai.networkCapabilities.getSSID()));
|
||||||
details = r.getString(R.string.wifi_no_internet_detailed);
|
details = r.getString(R.string.wifi_no_internet_detailed);
|
||||||
|
} else if (notifyType == NotificationType.PRIVATE_DNS_BROKEN) {
|
||||||
|
if (transportType == TRANSPORT_CELLULAR) {
|
||||||
|
title = r.getString(R.string.mobile_no_internet);
|
||||||
|
} else if (transportType == TRANSPORT_WIFI) {
|
||||||
|
title = r.getString(R.string.wifi_no_internet,
|
||||||
|
WifiInfo.removeDoubleQuotes(nai.networkCapabilities.getSSID()));
|
||||||
|
} else {
|
||||||
|
title = r.getString(R.string.other_networks_no_internet);
|
||||||
|
}
|
||||||
|
details = r.getString(R.string.private_dns_broken_detailed);
|
||||||
} else if (notifyType == NotificationType.PARTIAL_CONNECTIVITY
|
} else if (notifyType == NotificationType.PARTIAL_CONNECTIVITY
|
||||||
&& transportType == TRANSPORT_WIFI) {
|
&& transportType == TRANSPORT_WIFI) {
|
||||||
title = r.getString(R.string.network_partial_connectivity,
|
title = r.getString(R.string.network_partial_connectivity,
|
||||||
@@ -357,8 +368,10 @@ public class NetworkNotificationManager {
|
|||||||
}
|
}
|
||||||
switch (t) {
|
switch (t) {
|
||||||
case SIGN_IN:
|
case SIGN_IN:
|
||||||
return 5;
|
return 6;
|
||||||
case PARTIAL_CONNECTIVITY:
|
case PARTIAL_CONNECTIVITY:
|
||||||
|
return 5;
|
||||||
|
case PRIVATE_DNS_BROKEN:
|
||||||
return 4;
|
return 4;
|
||||||
case NO_INTERNET:
|
case NO_INTERNET:
|
||||||
return 3;
|
return 3;
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ public class NetworkCapabilitiesTest {
|
|||||||
.addCapability(NET_CAPABILITY_NOT_METERED);
|
.addCapability(NET_CAPABILITY_NOT_METERED);
|
||||||
assertParcelingIsLossless(netCap);
|
assertParcelingIsLossless(netCap);
|
||||||
netCap.setSSID(TEST_SSID);
|
netCap.setSSID(TEST_SSID);
|
||||||
assertParcelSane(netCap, 11);
|
assertParcelSane(netCap, 12);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import static android.net.INetworkMonitor.NETWORK_VALIDATION_PROBE_DNS;
|
|||||||
import static android.net.INetworkMonitor.NETWORK_VALIDATION_PROBE_FALLBACK;
|
import static android.net.INetworkMonitor.NETWORK_VALIDATION_PROBE_FALLBACK;
|
||||||
import static android.net.INetworkMonitor.NETWORK_VALIDATION_PROBE_HTTP;
|
import static android.net.INetworkMonitor.NETWORK_VALIDATION_PROBE_HTTP;
|
||||||
import static android.net.INetworkMonitor.NETWORK_VALIDATION_PROBE_HTTPS;
|
import static android.net.INetworkMonitor.NETWORK_VALIDATION_PROBE_HTTPS;
|
||||||
|
import static android.net.INetworkMonitor.NETWORK_VALIDATION_PROBE_PRIVDNS;
|
||||||
import static android.net.INetworkMonitor.NETWORK_VALIDATION_RESULT_PARTIAL;
|
import static android.net.INetworkMonitor.NETWORK_VALIDATION_RESULT_PARTIAL;
|
||||||
import static android.net.INetworkMonitor.NETWORK_VALIDATION_RESULT_VALID;
|
import static android.net.INetworkMonitor.NETWORK_VALIDATION_RESULT_VALID;
|
||||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_CAPTIVE_PORTAL;
|
import static android.net.NetworkCapabilities.NET_CAPABILITY_CAPTIVE_PORTAL;
|
||||||
@@ -492,6 +493,8 @@ public class ConnectivityServiceTest {
|
|||||||
private INetworkMonitor mNetworkMonitor;
|
private INetworkMonitor mNetworkMonitor;
|
||||||
private INetworkMonitorCallbacks mNmCallbacks;
|
private INetworkMonitorCallbacks mNmCallbacks;
|
||||||
private int mNmValidationResult = VALIDATION_RESULT_BASE;
|
private int mNmValidationResult = VALIDATION_RESULT_BASE;
|
||||||
|
private int mProbesCompleted;
|
||||||
|
private int mProbesSucceeded;
|
||||||
private String mNmValidationRedirectUrl = null;
|
private String mNmValidationRedirectUrl = null;
|
||||||
private boolean mNmProvNotificationRequested = false;
|
private boolean mNmProvNotificationRequested = false;
|
||||||
|
|
||||||
@@ -559,6 +562,7 @@ public class ConnectivityServiceTest {
|
|||||||
mNmProvNotificationRequested = false;
|
mNmProvNotificationRequested = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mNmCallbacks.notifyProbeStatusChanged(mProbesCompleted, mProbesSucceeded);
|
||||||
mNmCallbacks.notifyNetworkTested(
|
mNmCallbacks.notifyNetworkTested(
|
||||||
mNmValidationResult, mNmValidationRedirectUrl);
|
mNmValidationResult, mNmValidationRedirectUrl);
|
||||||
|
|
||||||
@@ -581,7 +585,7 @@ public class ConnectivityServiceTest {
|
|||||||
* @param validated Indicate if network should pretend to be validated.
|
* @param validated Indicate if network should pretend to be validated.
|
||||||
*/
|
*/
|
||||||
public void connect(boolean validated) {
|
public void connect(boolean validated) {
|
||||||
connect(validated, true);
|
connect(validated, true, false /* isStrictMode */);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -589,13 +593,13 @@ public class ConnectivityServiceTest {
|
|||||||
* @param validated Indicate if network should pretend to be validated.
|
* @param validated Indicate if network should pretend to be validated.
|
||||||
* @param hasInternet Indicate if network should pretend to have NET_CAPABILITY_INTERNET.
|
* @param hasInternet Indicate if network should pretend to have NET_CAPABILITY_INTERNET.
|
||||||
*/
|
*/
|
||||||
public void connect(boolean validated, boolean hasInternet) {
|
public void connect(boolean validated, boolean hasInternet, boolean isStrictMode) {
|
||||||
assertFalse(getNetworkCapabilities().hasCapability(NET_CAPABILITY_INTERNET));
|
assertFalse(getNetworkCapabilities().hasCapability(NET_CAPABILITY_INTERNET));
|
||||||
|
|
||||||
ConnectivityManager.NetworkCallback callback = null;
|
ConnectivityManager.NetworkCallback callback = null;
|
||||||
final ConditionVariable validatedCv = new ConditionVariable();
|
final ConditionVariable validatedCv = new ConditionVariable();
|
||||||
if (validated) {
|
if (validated) {
|
||||||
setNetworkValid();
|
setNetworkValid(isStrictMode);
|
||||||
NetworkRequest request = new NetworkRequest.Builder()
|
NetworkRequest request = new NetworkRequest.Builder()
|
||||||
.addTransportType(getNetworkCapabilities().getTransportTypes()[0])
|
.addTransportType(getNetworkCapabilities().getTransportTypes()[0])
|
||||||
.clearCapabilities()
|
.clearCapabilities()
|
||||||
@@ -620,15 +624,15 @@ public class ConnectivityServiceTest {
|
|||||||
if (validated) {
|
if (validated) {
|
||||||
// Wait for network to validate.
|
// Wait for network to validate.
|
||||||
waitFor(validatedCv);
|
waitFor(validatedCv);
|
||||||
setNetworkInvalid();
|
setNetworkInvalid(isStrictMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (callback != null) mCm.unregisterNetworkCallback(callback);
|
if (callback != null) mCm.unregisterNetworkCallback(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void connectWithCaptivePortal(String redirectUrl) {
|
public void connectWithCaptivePortal(String redirectUrl, boolean isStrictMode) {
|
||||||
setNetworkPortal(redirectUrl);
|
setNetworkPortal(redirectUrl, isStrictMode);
|
||||||
connect(false);
|
connect(false, true /* hasInternet */, isStrictMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void connectWithPartialConnectivity() {
|
public void connectWithPartialConnectivity() {
|
||||||
@@ -636,34 +640,75 @@ public class ConnectivityServiceTest {
|
|||||||
connect(false);
|
connect(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void connectWithPartialValidConnectivity() {
|
public void connectWithPartialValidConnectivity(boolean isStrictMode) {
|
||||||
setNetworkPartialValid();
|
setNetworkPartialValid(isStrictMode);
|
||||||
connect(false);
|
connect(false, true /* hasInternet */, isStrictMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setNetworkValid() {
|
void setNetworkValid(boolean isStrictMode) {
|
||||||
mNmValidationResult = VALIDATION_RESULT_VALID;
|
mNmValidationResult = VALIDATION_RESULT_VALID;
|
||||||
mNmValidationRedirectUrl = null;
|
mNmValidationRedirectUrl = null;
|
||||||
|
int probesSucceeded = VALIDATION_RESULT_BASE & ~NETWORK_VALIDATION_PROBE_HTTP;
|
||||||
|
if (isStrictMode) {
|
||||||
|
probesSucceeded |= NETWORK_VALIDATION_PROBE_PRIVDNS;
|
||||||
|
}
|
||||||
|
// The probesCompleted equals to probesSucceeded for the case of valid network, so put
|
||||||
|
// the same value into two different parameter of the method.
|
||||||
|
setProbesStatus(probesSucceeded, probesSucceeded);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setNetworkInvalid() {
|
void setNetworkInvalid(boolean isStrictMode) {
|
||||||
mNmValidationResult = VALIDATION_RESULT_INVALID;
|
mNmValidationResult = VALIDATION_RESULT_INVALID;
|
||||||
mNmValidationRedirectUrl = null;
|
mNmValidationRedirectUrl = null;
|
||||||
|
int probesCompleted = VALIDATION_RESULT_BASE;
|
||||||
|
int probesSucceeded = VALIDATION_RESULT_INVALID;
|
||||||
|
// If the isStrictMode is true, it means the network is invalid when NetworkMonitor
|
||||||
|
// tried to validate the private DNS but failed.
|
||||||
|
if (isStrictMode) {
|
||||||
|
probesCompleted &= ~NETWORK_VALIDATION_PROBE_HTTP;
|
||||||
|
probesSucceeded = probesCompleted;
|
||||||
|
probesCompleted |= NETWORK_VALIDATION_PROBE_PRIVDNS;
|
||||||
|
}
|
||||||
|
setProbesStatus(probesCompleted, probesSucceeded);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setNetworkPortal(String redirectUrl) {
|
void setNetworkPortal(String redirectUrl, boolean isStrictMode) {
|
||||||
setNetworkInvalid();
|
setNetworkInvalid(isStrictMode);
|
||||||
mNmValidationRedirectUrl = redirectUrl;
|
mNmValidationRedirectUrl = redirectUrl;
|
||||||
|
// Suppose the portal is found when NetworkMonitor probes NETWORK_VALIDATION_PROBE_HTTP
|
||||||
|
// in the beginning, so the NETWORK_VALIDATION_PROBE_HTTPS hasn't probed yet.
|
||||||
|
int probesCompleted = VALIDATION_RESULT_BASE & ~NETWORK_VALIDATION_PROBE_HTTPS;
|
||||||
|
int probesSucceeded = VALIDATION_RESULT_INVALID;
|
||||||
|
if (isStrictMode) {
|
||||||
|
probesCompleted |= NETWORK_VALIDATION_PROBE_PRIVDNS;
|
||||||
|
}
|
||||||
|
setProbesStatus(probesCompleted, probesSucceeded);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setNetworkPartial() {
|
void setNetworkPartial() {
|
||||||
mNmValidationResult = VALIDATION_RESULT_PARTIAL;
|
mNmValidationResult = VALIDATION_RESULT_PARTIAL;
|
||||||
mNmValidationRedirectUrl = null;
|
mNmValidationRedirectUrl = null;
|
||||||
|
int probesCompleted = VALIDATION_RESULT_BASE;
|
||||||
|
int probesSucceeded = VALIDATION_RESULT_BASE & ~NETWORK_VALIDATION_PROBE_HTTPS;
|
||||||
|
setProbesStatus(probesCompleted, probesSucceeded);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setNetworkPartialValid() {
|
void setNetworkPartialValid(boolean isStrictMode) {
|
||||||
mNmValidationResult = VALIDATION_RESULT_PARTIAL | VALIDATION_RESULT_VALID;
|
setNetworkPartial();
|
||||||
mNmValidationRedirectUrl = null;
|
mNmValidationResult |= VALIDATION_RESULT_VALID;
|
||||||
|
int probesCompleted = VALIDATION_RESULT_BASE;
|
||||||
|
int probesSucceeded = VALIDATION_RESULT_BASE & ~NETWORK_VALIDATION_PROBE_HTTPS;
|
||||||
|
// Suppose the partial network cannot pass the private DNS validation as well, so only
|
||||||
|
// add NETWORK_VALIDATION_PROBE_DNS in probesCompleted but not probesSucceeded.
|
||||||
|
if (isStrictMode) {
|
||||||
|
probesCompleted |= NETWORK_VALIDATION_PROBE_PRIVDNS;
|
||||||
|
}
|
||||||
|
setProbesStatus(probesCompleted, probesSucceeded);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setProbesStatus(int probesCompleted, int probesSucceeded) {
|
||||||
|
mProbesCompleted = probesCompleted;
|
||||||
|
mProbesSucceeded = probesSucceeded;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String waitForRedirectUrl() {
|
public String waitForRedirectUrl() {
|
||||||
@@ -2226,7 +2271,7 @@ public class ConnectivityServiceTest {
|
|||||||
|
|
||||||
// With HTTPS probe disabled, NetworkMonitor should pass the network validation with http
|
// With HTTPS probe disabled, NetworkMonitor should pass the network validation with http
|
||||||
// probe.
|
// probe.
|
||||||
mWiFiNetworkAgent.setNetworkPartialValid();
|
mWiFiNetworkAgent.setNetworkPartialValid(false /* isStrictMode */);
|
||||||
// If the user chooses yes to use this partial connectivity wifi, switch the default
|
// If the user chooses yes to use this partial connectivity wifi, switch the default
|
||||||
// network to wifi and check if wifi becomes valid or not.
|
// network to wifi and check if wifi becomes valid or not.
|
||||||
mCm.setAcceptPartialConnectivity(mWiFiNetworkAgent.getNetwork(), true /* accept */,
|
mCm.setAcceptPartialConnectivity(mWiFiNetworkAgent.getNetwork(), true /* accept */,
|
||||||
@@ -2299,7 +2344,7 @@ public class ConnectivityServiceTest {
|
|||||||
callback.expectCallback(CallbackEntry.LOSING, mCellNetworkAgent);
|
callback.expectCallback(CallbackEntry.LOSING, mCellNetworkAgent);
|
||||||
assertEquals(mWiFiNetworkAgent.getNetwork(), mCm.getActiveNetwork());
|
assertEquals(mWiFiNetworkAgent.getNetwork(), mCm.getActiveNetwork());
|
||||||
callback.expectCapabilitiesWith(NET_CAPABILITY_PARTIAL_CONNECTIVITY, mWiFiNetworkAgent);
|
callback.expectCapabilitiesWith(NET_CAPABILITY_PARTIAL_CONNECTIVITY, mWiFiNetworkAgent);
|
||||||
mWiFiNetworkAgent.setNetworkValid();
|
mWiFiNetworkAgent.setNetworkValid(false /* isStrictMode */);
|
||||||
|
|
||||||
// Need a trigger point to let NetworkMonitor tell ConnectivityService that network is
|
// Need a trigger point to let NetworkMonitor tell ConnectivityService that network is
|
||||||
// validated.
|
// validated.
|
||||||
@@ -2317,7 +2362,7 @@ public class ConnectivityServiceTest {
|
|||||||
// NetworkMonitor will immediately (once the HTTPS probe fails...) report the network as
|
// NetworkMonitor will immediately (once the HTTPS probe fails...) report the network as
|
||||||
// valid, because ConnectivityService calls setAcceptPartialConnectivity before it calls
|
// valid, because ConnectivityService calls setAcceptPartialConnectivity before it calls
|
||||||
// notifyNetworkConnected.
|
// notifyNetworkConnected.
|
||||||
mWiFiNetworkAgent.connectWithPartialValidConnectivity();
|
mWiFiNetworkAgent.connectWithPartialValidConnectivity(false /* isStrictMode */);
|
||||||
callback.expectAvailableCallbacksUnvalidated(mWiFiNetworkAgent);
|
callback.expectAvailableCallbacksUnvalidated(mWiFiNetworkAgent);
|
||||||
verify(mWiFiNetworkAgent.mNetworkMonitor, times(1)).setAcceptPartialConnectivity();
|
verify(mWiFiNetworkAgent.mNetworkMonitor, times(1)).setAcceptPartialConnectivity();
|
||||||
callback.expectCallback(CallbackEntry.LOSING, mCellNetworkAgent);
|
callback.expectCallback(CallbackEntry.LOSING, mCellNetworkAgent);
|
||||||
@@ -2343,7 +2388,7 @@ public class ConnectivityServiceTest {
|
|||||||
// Expect onAvailable callback of listen for NET_CAPABILITY_CAPTIVE_PORTAL.
|
// Expect onAvailable callback of listen for NET_CAPABILITY_CAPTIVE_PORTAL.
|
||||||
mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI);
|
mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI);
|
||||||
String redirectUrl = "http://android.com/path";
|
String redirectUrl = "http://android.com/path";
|
||||||
mWiFiNetworkAgent.connectWithCaptivePortal(redirectUrl);
|
mWiFiNetworkAgent.connectWithCaptivePortal(redirectUrl, false /* isStrictMode */);
|
||||||
captivePortalCallback.expectAvailableCallbacksUnvalidated(mWiFiNetworkAgent);
|
captivePortalCallback.expectAvailableCallbacksUnvalidated(mWiFiNetworkAgent);
|
||||||
assertEquals(mWiFiNetworkAgent.waitForRedirectUrl(), redirectUrl);
|
assertEquals(mWiFiNetworkAgent.waitForRedirectUrl(), redirectUrl);
|
||||||
|
|
||||||
@@ -2361,7 +2406,7 @@ public class ConnectivityServiceTest {
|
|||||||
mWiFiNetworkAgent);
|
mWiFiNetworkAgent);
|
||||||
|
|
||||||
// Report partial connectivity is accepted.
|
// Report partial connectivity is accepted.
|
||||||
mWiFiNetworkAgent.setNetworkPartialValid();
|
mWiFiNetworkAgent.setNetworkPartialValid(false /* isStrictMode */);
|
||||||
mCm.setAcceptPartialConnectivity(mWiFiNetworkAgent.getNetwork(), true /* accept */,
|
mCm.setAcceptPartialConnectivity(mWiFiNetworkAgent.getNetwork(), true /* accept */,
|
||||||
false /* always */);
|
false /* always */);
|
||||||
waitForIdle();
|
waitForIdle();
|
||||||
@@ -2392,7 +2437,7 @@ public class ConnectivityServiceTest {
|
|||||||
// Expect onAvailable callback of listen for NET_CAPABILITY_CAPTIVE_PORTAL.
|
// Expect onAvailable callback of listen for NET_CAPABILITY_CAPTIVE_PORTAL.
|
||||||
mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI);
|
mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI);
|
||||||
String firstRedirectUrl = "http://example.com/firstPath";
|
String firstRedirectUrl = "http://example.com/firstPath";
|
||||||
mWiFiNetworkAgent.connectWithCaptivePortal(firstRedirectUrl);
|
mWiFiNetworkAgent.connectWithCaptivePortal(firstRedirectUrl, false /* isStrictMode */);
|
||||||
captivePortalCallback.expectAvailableCallbacksUnvalidated(mWiFiNetworkAgent);
|
captivePortalCallback.expectAvailableCallbacksUnvalidated(mWiFiNetworkAgent);
|
||||||
assertEquals(mWiFiNetworkAgent.waitForRedirectUrl(), firstRedirectUrl);
|
assertEquals(mWiFiNetworkAgent.waitForRedirectUrl(), firstRedirectUrl);
|
||||||
|
|
||||||
@@ -2405,13 +2450,13 @@ public class ConnectivityServiceTest {
|
|||||||
// Expect onAvailable callback of listen for NET_CAPABILITY_CAPTIVE_PORTAL.
|
// Expect onAvailable callback of listen for NET_CAPABILITY_CAPTIVE_PORTAL.
|
||||||
mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI);
|
mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI);
|
||||||
String secondRedirectUrl = "http://example.com/secondPath";
|
String secondRedirectUrl = "http://example.com/secondPath";
|
||||||
mWiFiNetworkAgent.connectWithCaptivePortal(secondRedirectUrl);
|
mWiFiNetworkAgent.connectWithCaptivePortal(secondRedirectUrl, false /* isStrictMode */);
|
||||||
captivePortalCallback.expectAvailableCallbacksUnvalidated(mWiFiNetworkAgent);
|
captivePortalCallback.expectAvailableCallbacksUnvalidated(mWiFiNetworkAgent);
|
||||||
assertEquals(mWiFiNetworkAgent.waitForRedirectUrl(), secondRedirectUrl);
|
assertEquals(mWiFiNetworkAgent.waitForRedirectUrl(), secondRedirectUrl);
|
||||||
|
|
||||||
// Make captive portal disappear then revalidate.
|
// Make captive portal disappear then revalidate.
|
||||||
// Expect onLost callback because network no longer provides NET_CAPABILITY_CAPTIVE_PORTAL.
|
// Expect onLost callback because network no longer provides NET_CAPABILITY_CAPTIVE_PORTAL.
|
||||||
mWiFiNetworkAgent.setNetworkValid();
|
mWiFiNetworkAgent.setNetworkValid(false /* isStrictMode */);
|
||||||
mCm.reportNetworkConnectivity(mWiFiNetworkAgent.getNetwork(), true);
|
mCm.reportNetworkConnectivity(mWiFiNetworkAgent.getNetwork(), true);
|
||||||
captivePortalCallback.expectCallback(CallbackEntry.LOST, mWiFiNetworkAgent);
|
captivePortalCallback.expectCallback(CallbackEntry.LOST, mWiFiNetworkAgent);
|
||||||
|
|
||||||
@@ -2423,7 +2468,7 @@ public class ConnectivityServiceTest {
|
|||||||
|
|
||||||
// Break network connectivity.
|
// Break network connectivity.
|
||||||
// Expect NET_CAPABILITY_VALIDATED onLost callback.
|
// Expect NET_CAPABILITY_VALIDATED onLost callback.
|
||||||
mWiFiNetworkAgent.setNetworkInvalid();
|
mWiFiNetworkAgent.setNetworkInvalid(false /* isStrictMode */);
|
||||||
mCm.reportNetworkConnectivity(mWiFiNetworkAgent.getNetwork(), false);
|
mCm.reportNetworkConnectivity(mWiFiNetworkAgent.getNetwork(), false);
|
||||||
validatedCallback.expectCallback(CallbackEntry.LOST, mWiFiNetworkAgent);
|
validatedCallback.expectCallback(CallbackEntry.LOST, mWiFiNetworkAgent);
|
||||||
}
|
}
|
||||||
@@ -2454,7 +2499,7 @@ public class ConnectivityServiceTest {
|
|||||||
mServiceContext.expectNoStartActivityIntent(fastTimeoutMs);
|
mServiceContext.expectNoStartActivityIntent(fastTimeoutMs);
|
||||||
|
|
||||||
// Turn into a captive portal.
|
// Turn into a captive portal.
|
||||||
mWiFiNetworkAgent.setNetworkPortal("http://example.com");
|
mWiFiNetworkAgent.setNetworkPortal("http://example.com", false /* isStrictMode */);
|
||||||
mCm.reportNetworkConnectivity(wifiNetwork, false);
|
mCm.reportNetworkConnectivity(wifiNetwork, false);
|
||||||
captivePortalCallback.expectAvailableCallbacksUnvalidated(mWiFiNetworkAgent);
|
captivePortalCallback.expectAvailableCallbacksUnvalidated(mWiFiNetworkAgent);
|
||||||
validatedCallback.expectCallback(CallbackEntry.LOST, mWiFiNetworkAgent);
|
validatedCallback.expectCallback(CallbackEntry.LOST, mWiFiNetworkAgent);
|
||||||
@@ -2475,7 +2520,7 @@ public class ConnectivityServiceTest {
|
|||||||
assertEquals(testValue, signInIntent.getStringExtra(testKey));
|
assertEquals(testValue, signInIntent.getStringExtra(testKey));
|
||||||
|
|
||||||
// Report that the captive portal is dismissed, and check that callbacks are fired
|
// Report that the captive portal is dismissed, and check that callbacks are fired
|
||||||
mWiFiNetworkAgent.setNetworkValid();
|
mWiFiNetworkAgent.setNetworkValid(false /* isStrictMode */);
|
||||||
mWiFiNetworkAgent.mNetworkMonitor.forceReevaluation(Process.myUid());
|
mWiFiNetworkAgent.mNetworkMonitor.forceReevaluation(Process.myUid());
|
||||||
validatedCallback.expectAvailableCallbacksValidated(mWiFiNetworkAgent);
|
validatedCallback.expectAvailableCallbacksValidated(mWiFiNetworkAgent);
|
||||||
captivePortalCallback.expectCallback(CallbackEntry.LOST, mWiFiNetworkAgent);
|
captivePortalCallback.expectCallback(CallbackEntry.LOST, mWiFiNetworkAgent);
|
||||||
@@ -2504,7 +2549,7 @@ public class ConnectivityServiceTest {
|
|||||||
mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI);
|
mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI);
|
||||||
String firstRedirectUrl = "http://example.com/firstPath";
|
String firstRedirectUrl = "http://example.com/firstPath";
|
||||||
|
|
||||||
mWiFiNetworkAgent.connectWithCaptivePortal(firstRedirectUrl);
|
mWiFiNetworkAgent.connectWithCaptivePortal(firstRedirectUrl, false /* isStrictMode */);
|
||||||
mWiFiNetworkAgent.expectDisconnected();
|
mWiFiNetworkAgent.expectDisconnected();
|
||||||
mWiFiNetworkAgent.expectPreventReconnectReceived();
|
mWiFiNetworkAgent.expectPreventReconnectReceived();
|
||||||
|
|
||||||
@@ -3219,7 +3264,7 @@ public class ConnectivityServiceTest {
|
|||||||
Network wifiNetwork = mWiFiNetworkAgent.getNetwork();
|
Network wifiNetwork = mWiFiNetworkAgent.getNetwork();
|
||||||
|
|
||||||
// Fail validation on wifi.
|
// Fail validation on wifi.
|
||||||
mWiFiNetworkAgent.setNetworkInvalid();
|
mWiFiNetworkAgent.setNetworkInvalid(false /* isStrictMode */);
|
||||||
mCm.reportNetworkConnectivity(wifiNetwork, false);
|
mCm.reportNetworkConnectivity(wifiNetwork, false);
|
||||||
defaultCallback.expectCapabilitiesWithout(NET_CAPABILITY_VALIDATED, mWiFiNetworkAgent);
|
defaultCallback.expectCapabilitiesWithout(NET_CAPABILITY_VALIDATED, mWiFiNetworkAgent);
|
||||||
validatedWifiCallback.expectCallback(CallbackEntry.LOST, mWiFiNetworkAgent);
|
validatedWifiCallback.expectCallback(CallbackEntry.LOST, mWiFiNetworkAgent);
|
||||||
@@ -3263,7 +3308,7 @@ public class ConnectivityServiceTest {
|
|||||||
wifiNetwork = mWiFiNetworkAgent.getNetwork();
|
wifiNetwork = mWiFiNetworkAgent.getNetwork();
|
||||||
|
|
||||||
// Fail validation on wifi and expect the dialog to appear.
|
// Fail validation on wifi and expect the dialog to appear.
|
||||||
mWiFiNetworkAgent.setNetworkInvalid();
|
mWiFiNetworkAgent.setNetworkInvalid(false /* isStrictMode */);
|
||||||
mCm.reportNetworkConnectivity(wifiNetwork, false);
|
mCm.reportNetworkConnectivity(wifiNetwork, false);
|
||||||
defaultCallback.expectCapabilitiesWithout(NET_CAPABILITY_VALIDATED, mWiFiNetworkAgent);
|
defaultCallback.expectCapabilitiesWithout(NET_CAPABILITY_VALIDATED, mWiFiNetworkAgent);
|
||||||
validatedWifiCallback.expectCallback(CallbackEntry.LOST, mWiFiNetworkAgent);
|
validatedWifiCallback.expectCallback(CallbackEntry.LOST, mWiFiNetworkAgent);
|
||||||
@@ -4299,7 +4344,7 @@ public class ConnectivityServiceTest {
|
|||||||
mCm.registerNetworkCallback(request, callback);
|
mCm.registerNetworkCallback(request, callback);
|
||||||
|
|
||||||
// Bring up wifi aware network.
|
// Bring up wifi aware network.
|
||||||
wifiAware.connect(false, false);
|
wifiAware.connect(false, false, false /* isStrictMode */);
|
||||||
callback.expectAvailableCallbacksUnvalidated(wifiAware);
|
callback.expectAvailableCallbacksUnvalidated(wifiAware);
|
||||||
|
|
||||||
assertNull(mCm.getActiveNetworkInfo());
|
assertNull(mCm.getActiveNetworkInfo());
|
||||||
@@ -4536,6 +4581,44 @@ public class ConnectivityServiceTest {
|
|||||||
reset(mMockDnsResolver);
|
reset(mMockDnsResolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPrivateDnsNotification() throws Exception {
|
||||||
|
NetworkRequest request = new NetworkRequest.Builder()
|
||||||
|
.clearCapabilities().addCapability(NET_CAPABILITY_INTERNET)
|
||||||
|
.build();
|
||||||
|
TestNetworkCallback callback = new TestNetworkCallback();
|
||||||
|
mCm.registerNetworkCallback(request, callback);
|
||||||
|
// Bring up wifi.
|
||||||
|
mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI);
|
||||||
|
mWiFiNetworkAgent.connect(false);
|
||||||
|
callback.expectAvailableCallbacksUnvalidated(mWiFiNetworkAgent);
|
||||||
|
// Private DNS resolution failed, checking if the notification will be shown or not.
|
||||||
|
mWiFiNetworkAgent.setNetworkInvalid(true /* isStrictMode */);
|
||||||
|
mWiFiNetworkAgent.mNetworkMonitor.forceReevaluation(Process.myUid());
|
||||||
|
waitForIdle();
|
||||||
|
// If network validation failed, NetworkMonitor will re-evaluate the network.
|
||||||
|
// ConnectivityService should filter the redundant notification. This part is trying to
|
||||||
|
// simulate that situation and check if ConnectivityService could filter that case.
|
||||||
|
mWiFiNetworkAgent.mNetworkMonitor.forceReevaluation(Process.myUid());
|
||||||
|
waitForIdle();
|
||||||
|
verify(mNotificationManager, timeout(TIMEOUT_MS).times(1)).notifyAsUser(anyString(),
|
||||||
|
eq(NotificationType.PRIVATE_DNS_BROKEN.eventId), any(), eq(UserHandle.ALL));
|
||||||
|
// If private DNS resolution successful, the PRIVATE_DNS_BROKEN notification shouldn't be
|
||||||
|
// shown.
|
||||||
|
mWiFiNetworkAgent.setNetworkValid(true /* isStrictMode */);
|
||||||
|
mWiFiNetworkAgent.mNetworkMonitor.forceReevaluation(Process.myUid());
|
||||||
|
waitForIdle();
|
||||||
|
verify(mNotificationManager, timeout(TIMEOUT_MS).times(1)).cancelAsUser(anyString(),
|
||||||
|
eq(NotificationType.PRIVATE_DNS_BROKEN.eventId), eq(UserHandle.ALL));
|
||||||
|
// If private DNS resolution failed again, the PRIVATE_DNS_BROKEN notification should be
|
||||||
|
// shown again.
|
||||||
|
mWiFiNetworkAgent.setNetworkInvalid(true /* isStrictMode */);
|
||||||
|
mWiFiNetworkAgent.mNetworkMonitor.forceReevaluation(Process.myUid());
|
||||||
|
waitForIdle();
|
||||||
|
verify(mNotificationManager, timeout(TIMEOUT_MS).times(2)).notifyAsUser(anyString(),
|
||||||
|
eq(NotificationType.PRIVATE_DNS_BROKEN.eventId), any(), eq(UserHandle.ALL));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPrivateDnsSettingsChange() throws Exception {
|
public void testPrivateDnsSettingsChange() throws Exception {
|
||||||
// Clear any interactions that occur as a result of CS starting up.
|
// Clear any interactions that occur as a result of CS starting up.
|
||||||
@@ -4793,7 +4876,7 @@ public class ConnectivityServiceTest {
|
|||||||
// by NetworkMonitor
|
// by NetworkMonitor
|
||||||
assertFalse(NetworkMonitorUtils.isValidationRequired(
|
assertFalse(NetworkMonitorUtils.isValidationRequired(
|
||||||
vpnNetworkAgent.getNetworkCapabilities()));
|
vpnNetworkAgent.getNetworkCapabilities()));
|
||||||
vpnNetworkAgent.setNetworkValid();
|
vpnNetworkAgent.setNetworkValid(false /* isStrictMode */);
|
||||||
|
|
||||||
vpnNetworkAgent.connect(false);
|
vpnNetworkAgent.connect(false);
|
||||||
mMockVpn.connect();
|
mMockVpn.connect();
|
||||||
@@ -4882,7 +4965,8 @@ public class ConnectivityServiceTest {
|
|||||||
ranges.add(new UidRange(uid, uid));
|
ranges.add(new UidRange(uid, uid));
|
||||||
mMockVpn.setNetworkAgent(vpnNetworkAgent);
|
mMockVpn.setNetworkAgent(vpnNetworkAgent);
|
||||||
mMockVpn.setUids(ranges);
|
mMockVpn.setUids(ranges);
|
||||||
vpnNetworkAgent.connect(true /* validated */, false /* hasInternet */);
|
vpnNetworkAgent.connect(true /* validated */, false /* hasInternet */,
|
||||||
|
false /* isStrictMode */);
|
||||||
mMockVpn.connect();
|
mMockVpn.connect();
|
||||||
|
|
||||||
defaultCallback.assertNoCallback();
|
defaultCallback.assertNoCallback();
|
||||||
@@ -4913,7 +4997,8 @@ public class ConnectivityServiceTest {
|
|||||||
ranges.add(new UidRange(uid, uid));
|
ranges.add(new UidRange(uid, uid));
|
||||||
mMockVpn.setNetworkAgent(vpnNetworkAgent);
|
mMockVpn.setNetworkAgent(vpnNetworkAgent);
|
||||||
mMockVpn.setUids(ranges);
|
mMockVpn.setUids(ranges);
|
||||||
vpnNetworkAgent.connect(true /* validated */, true /* hasInternet */);
|
vpnNetworkAgent.connect(true /* validated */, true /* hasInternet */,
|
||||||
|
false /* isStrictMode */);
|
||||||
mMockVpn.connect();
|
mMockVpn.connect();
|
||||||
|
|
||||||
defaultCallback.expectAvailableThenValidatedCallbacks(vpnNetworkAgent);
|
defaultCallback.expectAvailableThenValidatedCallbacks(vpnNetworkAgent);
|
||||||
@@ -4945,7 +5030,8 @@ public class ConnectivityServiceTest {
|
|||||||
ranges.add(new UidRange(uid, uid));
|
ranges.add(new UidRange(uid, uid));
|
||||||
mMockVpn.setNetworkAgent(vpnNetworkAgent);
|
mMockVpn.setNetworkAgent(vpnNetworkAgent);
|
||||||
mMockVpn.setUids(ranges);
|
mMockVpn.setUids(ranges);
|
||||||
vpnNetworkAgent.connect(false /* validated */, true /* hasInternet */);
|
vpnNetworkAgent.connect(false /* validated */, true /* hasInternet */,
|
||||||
|
false /* isStrictMode */);
|
||||||
mMockVpn.connect();
|
mMockVpn.connect();
|
||||||
|
|
||||||
// Even though the VPN is unvalidated, it becomes the default network for our app.
|
// Even though the VPN is unvalidated, it becomes the default network for our app.
|
||||||
@@ -4968,7 +5054,7 @@ public class ConnectivityServiceTest {
|
|||||||
vpnNetworkAgent.getNetworkCapabilities()));
|
vpnNetworkAgent.getNetworkCapabilities()));
|
||||||
|
|
||||||
// Pretend that the VPN network validates.
|
// Pretend that the VPN network validates.
|
||||||
vpnNetworkAgent.setNetworkValid();
|
vpnNetworkAgent.setNetworkValid(false /* isStrictMode */);
|
||||||
vpnNetworkAgent.mNetworkMonitor.forceReevaluation(Process.myUid());
|
vpnNetworkAgent.mNetworkMonitor.forceReevaluation(Process.myUid());
|
||||||
// Expect to see the validated capability, but no other changes, because the VPN is already
|
// Expect to see the validated capability, but no other changes, because the VPN is already
|
||||||
// the default network for the app.
|
// the default network for the app.
|
||||||
@@ -5000,7 +5086,8 @@ public class ConnectivityServiceTest {
|
|||||||
mMockVpn.setNetworkAgent(vpnNetworkAgent);
|
mMockVpn.setNetworkAgent(vpnNetworkAgent);
|
||||||
mMockVpn.connect();
|
mMockVpn.connect();
|
||||||
mMockVpn.setUids(ranges);
|
mMockVpn.setUids(ranges);
|
||||||
vpnNetworkAgent.connect(true /* validated */, false /* hasInternet */);
|
vpnNetworkAgent.connect(true /* validated */, false /* hasInternet */,
|
||||||
|
false /* isStrictMode */);
|
||||||
|
|
||||||
vpnNetworkCallback.expectAvailableThenValidatedCallbacks(vpnNetworkAgent);
|
vpnNetworkCallback.expectAvailableThenValidatedCallbacks(vpnNetworkAgent);
|
||||||
nc = mCm.getNetworkCapabilities(vpnNetworkAgent.getNetwork());
|
nc = mCm.getNetworkCapabilities(vpnNetworkAgent.getNetwork());
|
||||||
@@ -5099,7 +5186,8 @@ public class ConnectivityServiceTest {
|
|||||||
mMockVpn.setNetworkAgent(vpnNetworkAgent);
|
mMockVpn.setNetworkAgent(vpnNetworkAgent);
|
||||||
mMockVpn.connect();
|
mMockVpn.connect();
|
||||||
mMockVpn.setUids(ranges);
|
mMockVpn.setUids(ranges);
|
||||||
vpnNetworkAgent.connect(true /* validated */, false /* hasInternet */);
|
vpnNetworkAgent.connect(true /* validated */, false /* hasInternet */,
|
||||||
|
false /* isStrictMode */);
|
||||||
|
|
||||||
vpnNetworkCallback.expectAvailableThenValidatedCallbacks(vpnNetworkAgent);
|
vpnNetworkCallback.expectAvailableThenValidatedCallbacks(vpnNetworkAgent);
|
||||||
nc = mCm.getNetworkCapabilities(vpnNetworkAgent.getNetwork());
|
nc = mCm.getNetworkCapabilities(vpnNetworkAgent.getNetwork());
|
||||||
|
|||||||
Reference in New Issue
Block a user