Fix title of PRIVATE_DNS_BROKEN notification when connecting VPN
NetworkNotificationManager will only get the first transport
type from the NetworkCapabilities of network, and if the device
connects to a VPN and its underlying network is wifi, then the
first finding transport type will be TRANSPORT_WIFI. So, if the
private DNS is broken when device connected to VPN,
NetworkNotificationManager will try to get the SSID for the
title of notification but failed. For this kind of case, the
title of PRIVATE_DNS_BROKEN notification will show
"null has no internet access".
Bug: 143340533
Test: 1. Build pass.
2. Connect to VPN and let private DNS to be broken, check
title of PRIVATE_DNS_BROKEN notification.
3. atest FrameworksNetTests
Change-Id: I1ed018cc8774d4fce4b94854f8e8703a28818463
This commit is contained in:
@@ -18,6 +18,7 @@ package com.android.server.connectivity;
|
||||
|
||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET;
|
||||
import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
|
||||
import static android.net.NetworkCapabilities.TRANSPORT_VPN;
|
||||
import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
|
||||
|
||||
import android.app.Notification;
|
||||
@@ -89,14 +90,22 @@ public class NetworkNotificationManager {
|
||||
mNotificationTypeMap = new SparseIntArray();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected static int approximateTransportType(NetworkAgentInfo nai) {
|
||||
return nai.isVPN() ? TRANSPORT_VPN : getFirstTransportType(nai);
|
||||
}
|
||||
|
||||
// TODO: deal more gracefully with multi-transport networks.
|
||||
private static int getFirstTransportType(NetworkAgentInfo nai) {
|
||||
// TODO: The range is wrong, the safer and correct way is to change the range from
|
||||
// MIN_TRANSPORT to MAX_TRANSPORT.
|
||||
for (int i = 0; i < 64; i++) {
|
||||
if (nai.networkCapabilities.hasTransport(i)) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// TODO: Remove @TransportType or change it to @Transport.
|
||||
private static String getTransportName(@TransportType int transportType) {
|
||||
Resources r = Resources.getSystem();
|
||||
String[] networkTypes = r.getStringArray(R.array.network_switch_type_name);
|
||||
@@ -146,7 +155,7 @@ public class NetworkNotificationManager {
|
||||
final int transportType;
|
||||
final String name;
|
||||
if (nai != null) {
|
||||
transportType = getFirstTransportType(nai);
|
||||
transportType = approximateTransportType(nai);
|
||||
final String extraInfo = nai.networkInfo.getExtraInfo();
|
||||
name = TextUtils.isEmpty(extraInfo) ? nai.networkCapabilities.getSSID() : extraInfo;
|
||||
// Only notify for Internet-capable networks.
|
||||
@@ -175,7 +184,7 @@ public class NetworkNotificationManager {
|
||||
tag, nameOf(eventId), getTransportName(transportType), name, highPriority));
|
||||
}
|
||||
|
||||
Resources r = Resources.getSystem();
|
||||
Resources r = mContext.getResources();
|
||||
final CharSequence title;
|
||||
final CharSequence details;
|
||||
int icon = getIcon(transportType, notifyType);
|
||||
@@ -239,7 +248,7 @@ public class NetworkNotificationManager {
|
||||
details = r.getString(R.string.captive_portal_logged_in_detailed);
|
||||
} else if (notifyType == NotificationType.NETWORK_SWITCH) {
|
||||
String fromTransport = getTransportName(transportType);
|
||||
String toTransport = getTransportName(getFirstTransportType(switchToNai));
|
||||
String toTransport = getTransportName(approximateTransportType(switchToNai));
|
||||
title = r.getString(R.string.network_switch_metered, toTransport);
|
||||
details = r.getString(R.string.network_switch_metered_detail, toTransport,
|
||||
fromTransport);
|
||||
@@ -340,8 +349,8 @@ public class NetworkNotificationManager {
|
||||
}
|
||||
|
||||
public void showToast(NetworkAgentInfo fromNai, NetworkAgentInfo toNai) {
|
||||
String fromTransport = getTransportName(getFirstTransportType(fromNai));
|
||||
String toTransport = getTransportName(getFirstTransportType(toNai));
|
||||
String fromTransport = getTransportName(approximateTransportType(fromNai));
|
||||
String toTransport = getTransportName(approximateTransportType(toNai));
|
||||
String text = mContext.getResources().getString(
|
||||
R.string.network_switch_metered_toast, fromTransport, toTransport);
|
||||
Toast.makeText(mContext, text, Toast.LENGTH_LONG).show();
|
||||
|
||||
Reference in New Issue
Block a user