Merge "Fix title of PRIVATE_DNS_BROKEN notification when connecting VPN"
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