Merge changes Iaa6f0d65,I68a16b64

* changes:
  Networking: Rename removeDoubleQuotes to sanitizeSsid
  Wifi: Rename removeDoubleQuotes to sanitizeSsid
This commit is contained in:
David Su
2020-01-30 22:42:16 +00:00
committed by Gerrit Code Review
5 changed files with 25 additions and 12 deletions

View File

@@ -5671,6 +5671,7 @@ package android.net.wifi {
public class WifiInfo implements android.os.Parcelable {
method public boolean isOsuAp();
method public boolean isPasspointAp();
method @Nullable public static String sanitizeSsid(@Nullable String);
}
public class WifiManager {

View File

@@ -367,12 +367,12 @@ public class NetworkPolicyManager {
}
public static String resolveNetworkId(WifiConfiguration config) {
return WifiInfo.removeDoubleQuotes(config.isPasspoint()
return WifiInfo.sanitizeSsid(config.isPasspoint()
? config.providerFriendlyName : config.SSID);
}
public static String resolveNetworkId(String ssid) {
return WifiInfo.removeDoubleQuotes(ssid);
return WifiInfo.sanitizeSsid(ssid);
}
/** {@hide} */

View File

@@ -32,7 +32,7 @@ import static android.net.NetworkStats.METERED_YES;
import static android.net.NetworkStats.ROAMING_ALL;
import static android.net.NetworkStats.ROAMING_NO;
import static android.net.NetworkStats.ROAMING_YES;
import static android.net.wifi.WifiInfo.removeDoubleQuotes;
import static android.net.wifi.WifiInfo.sanitizeSsid;
import android.compat.annotation.UnsupportedAppUsage;
import android.os.Parcel;
@@ -401,7 +401,7 @@ public class NetworkTemplate implements Parcelable {
switch (ident.mType) {
case TYPE_WIFI:
return Objects.equals(
removeDoubleQuotes(mNetworkId), removeDoubleQuotes(ident.mNetworkId));
sanitizeSsid(mNetworkId), sanitizeSsid(ident.mNetworkId));
default:
return false;
}

View File

@@ -188,14 +188,14 @@ public class NetworkNotificationManager {
int icon = getIcon(transportType, notifyType);
if (notifyType == NotificationType.NO_INTERNET && transportType == TRANSPORT_WIFI) {
title = r.getString(R.string.wifi_no_internet,
WifiInfo.removeDoubleQuotes(nai.networkCapabilities.getSSID()));
WifiInfo.sanitizeSsid(nai.networkCapabilities.getSSID()));
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()));
WifiInfo.sanitizeSsid(nai.networkCapabilities.getSSID()));
} else {
title = r.getString(R.string.other_networks_no_internet);
}
@@ -203,19 +203,19 @@ public class NetworkNotificationManager {
} else if (notifyType == NotificationType.PARTIAL_CONNECTIVITY
&& transportType == TRANSPORT_WIFI) {
title = r.getString(R.string.network_partial_connectivity,
WifiInfo.removeDoubleQuotes(nai.networkCapabilities.getSSID()));
WifiInfo.sanitizeSsid(nai.networkCapabilities.getSSID()));
details = r.getString(R.string.network_partial_connectivity_detailed);
} else if (notifyType == NotificationType.LOST_INTERNET &&
transportType == TRANSPORT_WIFI) {
title = r.getString(R.string.wifi_no_internet,
WifiInfo.removeDoubleQuotes(nai.networkCapabilities.getSSID()));
WifiInfo.sanitizeSsid(nai.networkCapabilities.getSSID()));
details = r.getString(R.string.wifi_no_internet_detailed);
} else if (notifyType == NotificationType.SIGN_IN) {
switch (transportType) {
case TRANSPORT_WIFI:
title = r.getString(R.string.wifi_available_sign_in, 0);
details = r.getString(R.string.network_available_sign_in_detailed,
WifiInfo.removeDoubleQuotes(nai.networkCapabilities.getSSID()));
WifiInfo.sanitizeSsid(nai.networkCapabilities.getSSID()));
break;
case TRANSPORT_CELLULAR:
title = r.getString(R.string.network_available_sign_in, 0);
@@ -236,7 +236,7 @@ public class NetworkNotificationManager {
break;
}
} else if (notifyType == NotificationType.LOGGED_IN) {
title = WifiInfo.removeDoubleQuotes(nai.networkCapabilities.getSSID());
title = WifiInfo.sanitizeSsid(nai.networkCapabilities.getSSID());
details = r.getString(R.string.captive_portal_logged_in_detailed);
} else if (notifyType == NotificationType.NETWORK_SWITCH) {
String fromTransport = getTransportName(transportType);

View File

@@ -658,9 +658,21 @@ public class WifiInfo implements Parcelable {
}
}
/** {@hide} */
/**
* Remove double quotes (") surrounding a SSID string, if present. Otherwise, return the
* string unmodified. Return null if the input string was null.
* @hide
*/
@Nullable
@SystemApi
public static String sanitizeSsid(@Nullable String string) {
return removeDoubleQuotes(string);
}
/** @hide */
@UnsupportedAppUsage
public static String removeDoubleQuotes(String string) {
@Nullable
public static String removeDoubleQuotes(@Nullable String string) {
if (string == null) return null;
final int length = string.length();
if ((length > 1) && (string.charAt(0) == '"') && (string.charAt(length - 1) == '"')) {