Skip to content

Commit

Permalink
When wifi wants ASCII lowercasing, it needs to ask for it.
Browse files Browse the repository at this point in the history
http://elliotth.blogspot.com/2012/01/beware-convenience-methods.html

Bug: https://code.google.com/p/android/issues/detail?id=58359
Change-Id: Ibf25d0bbc76015cf8353ec01ab2b743cbc2bde67

Conflicts:

	wifi/java/android/net/wifi/WifiStateMachine.java

If frameworks wants ASCII casing, it should explicity ask for it.

http://elliotth.blogspot.com/2012/01/beware-convenience-methods.html

Bug: https://code.google.com/p/android/issues/detail?id=58359
Change-Id: Iaab02e718a7be7bda22e626dca05d79bfd2a8fc4

If graphics wants ASCII lowercasing, it needs to ask for it.

http://elliotth.blogspot.com/2012/01/beware-convenience-methods.html

Bug: https://code.google.com/p/android/issues/detail?id=58359
Change-Id: I13c106985302335dbb15bb9176d35ec6b4546d4e

If media wants ASCII lowercasing, it needs to ask for it.

http://elliotth.blogspot.com/2012/01/beware-convenience-methods.html

Use toLowerCase(Locale.ROOT) if you want ASCII for machine consumption,
and use toLowerCase(Locale.getDefault()) if you want the user's locale's
casing rules for human consumption.

Bug: https://code.google.com/p/android/issues/detail?id=58359
Change-Id: Id9005a17e34217a81bef3b40031b9e2e6272f45d
  • Loading branch information
enh-google authored and elektroschmock committed Aug 27, 2013
1 parent 767d2ac commit 9b829a9
Show file tree
Hide file tree
Showing 25 changed files with 53 additions and 33 deletions.
2 changes: 1 addition & 1 deletion core/java/android/content/Intent.java
Original file line number Diff line number Diff line change
Expand Up @@ -7046,7 +7046,7 @@ public static String normalizeMimeType(String type) {
return null;
}

type = type.trim().toLowerCase(Locale.US);
type = type.trim().toLowerCase(Locale.ROOT);

final int semicolonIndex = type.indexOf(';');
if (semicolonIndex != -1) {
Expand Down
2 changes: 1 addition & 1 deletion core/java/android/database/DatabaseUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,7 @@ public static int getSqlStatementType(String sql) {
if (sql.length() < 3) {
return STATEMENT_OTHER;
}
String prefixSql = sql.substring(0, 3).toUpperCase(Locale.US);
String prefixSql = sql.substring(0, 3).toUpperCase(Locale.ROOT);
if (prefixSql.equals("SEL")) {
return STATEMENT_SELECT;
} else if (prefixSql.equals("INS") ||
Expand Down
3 changes: 2 additions & 1 deletion core/java/android/net/MailTo.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package android.net;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -84,7 +85,7 @@ public static MailTo parse(String url) throws ParseException {
}
// insert the headers with the name in lowercase so that
// we can easily find common headers
m.mHeaders.put(Uri.decode(nameval[0]).toLowerCase(),
m.mHeaders.put(Uri.decode(nameval[0]).toLowerCase(Locale.ROOT),
nameval.length > 1 ? Uri.decode(nameval[1]) : null);
}
}
Expand Down
3 changes: 2 additions & 1 deletion core/java/android/net/NetworkConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package android.net;

import android.util.Log;
import java.util.Locale;

/**
* Describes the buildtime configuration of a network.
Expand Down Expand Up @@ -63,7 +64,7 @@ public class NetworkConfig {
*/
public NetworkConfig(String init) {
String fragments[] = init.split(",");
name = fragments[0].trim().toLowerCase();
name = fragments[0].trim().toLowerCase(Locale.ROOT);
type = Integer.parseInt(fragments[1]);
radio = Integer.parseInt(fragments[2]);
priority = Integer.parseInt(fragments[3]);
Expand Down
3 changes: 2 additions & 1 deletion core/java/android/net/ProxyProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.Locale;

/**
* A container class for the http proxy info
Expand Down Expand Up @@ -87,7 +88,7 @@ private void setExclusionList(String exclusionList) {
if (mExclusionList == null) {
mParsedExclusionList = new String[0];
} else {
String splitExclusionList[] = exclusionList.toLowerCase().split(",");
String splitExclusionList[] = exclusionList.toLowerCase(Locale.ROOT).split(",");
mParsedExclusionList = new String[splitExclusionList.length * 2];
for (int i = 0; i < splitExclusionList.length; i++) {
String s = splitExclusionList[i].trim();
Expand Down
4 changes: 2 additions & 2 deletions core/java/android/net/Uri.java
Original file line number Diff line number Diff line change
Expand Up @@ -1717,7 +1717,7 @@ public boolean getBooleanQueryParameter(String key, boolean defaultValue) {
if (flag == null) {
return defaultValue;
}
flag = flag.toLowerCase();
flag = flag.toLowerCase(Locale.ROOT);
return (!"false".equals(flag) && !"0".equals(flag));
}

Expand Down Expand Up @@ -1745,7 +1745,7 @@ public boolean getBooleanQueryParameter(String key, boolean defaultValue) {
public Uri normalizeScheme() {
String scheme = getScheme();
if (scheme == null) return this; // give up
String lowerScheme = scheme.toLowerCase(Locale.US);
String lowerScheme = scheme.toLowerCase(Locale.ROOT);
if (scheme.equals(lowerScheme)) return this; // no change

return buildUpon().scheme(lowerScheme).build();
Expand Down
3 changes: 2 additions & 1 deletion core/java/android/net/UrlQuerySanitizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.StringTokenizer;

Expand Down Expand Up @@ -305,7 +306,7 @@ public String sanitize(String value) {
int length = value.length();
if ((mFlags & SCRIPT_URL_OK) != 0) {
if (length >= MIN_SCRIPT_PREFIX_LENGTH) {
String asLower = value.toLowerCase();
String asLower = value.toLowerCase(Locale.ROOT);
if (asLower.startsWith(JAVASCRIPT_PREFIX) ||
asLower.startsWith(VBSCRIPT_PREFIX)) {
return "";
Expand Down
3 changes: 2 additions & 1 deletion core/java/android/net/WebAddress.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static android.util.Patterns.GOOD_IRI_CHAR;

import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -77,7 +78,7 @@ public WebAddress(String address) throws ParseException {
String t;
if (m.matches()) {
t = m.group(MATCH_GROUP_SCHEME);
if (t != null) mScheme = t.toLowerCase();
if (t != null) mScheme = t.toLowerCase(Locale.ROOT);
t = m.group(MATCH_GROUP_AUTHORITY);
if (t != null) mAuthInfo = t;
t = m.group(MATCH_GROUP_HOST);
Expand Down
6 changes: 4 additions & 2 deletions core/java/android/net/http/HttpAuthHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package android.net.http;

import java.util.Locale;

/**
* HttpAuthHeader: a class to store HTTP authentication-header parameters.
* For more information, see: RFC 2617: HTTP Authentication.
Expand Down Expand Up @@ -380,12 +382,12 @@ private void parseParameter(String token, String value) {
}

if (token.equalsIgnoreCase(QOP_TOKEN)) {
mQop = value.toLowerCase();
mQop = value.toLowerCase(Locale.ROOT);
return;
}

if (token.equalsIgnoreCase(ALGORITHM_TOKEN)) {
mAlgorithm = value.toLowerCase();
mAlgorithm = value.toLowerCase(Locale.ROOT);
return;
}
}
Expand Down
3 changes: 2 additions & 1 deletion core/java/android/net/http/HttpsConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.net.Socket;
import java.security.KeyManagementException;
import java.security.cert.X509Certificate;
import java.util.Locale;

/**
* A Connection connecting to a secure http server or tunneling through
Expand Down Expand Up @@ -209,7 +210,7 @@ AndroidHttpClientConnection openConnection(Request req) throws IOException {
// to add 'host' header unless we want proxy to answer us with a
// 400 Bad Request
for (Header h : req.mHttpRequest.getAllHeaders()) {
String headerName = h.getName().toLowerCase();
String headerName = h.getName().toLowerCase(Locale.ROOT);
if (headerName.startsWith("proxy") || headerName.equals("keep-alive")
|| headerName.equals("host")) {
proxyReq.addHeader(h);
Expand Down
4 changes: 2 additions & 2 deletions core/java/android/nfc/NdefRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,8 @@ public static NdefRecord createExternal(String domain, String type, byte[] data)
if (domain == null) throw new NullPointerException("domain is null");
if (type == null) throw new NullPointerException("type is null");

domain = domain.trim().toLowerCase(Locale.US);
type = type.trim().toLowerCase(Locale.US);
domain = domain.trim().toLowerCase(Locale.ROOT);
type = type.trim().toLowerCase(Locale.ROOT);

if (domain.length() == 0) throw new IllegalArgumentException("domain is empty");
if (type.length() == 0) throw new IllegalArgumentException("type is empty");
Expand Down
7 changes: 4 additions & 3 deletions core/java/android/provider/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;

/**
* The Settings provider contains global system-level device preferences.
Expand Down Expand Up @@ -6401,23 +6402,23 @@ public static final class Global extends NameValueTable {
* @hide
*/
public static final String getBluetoothHeadsetPriorityKey(String address) {
return BLUETOOTH_HEADSET_PRIORITY_PREFIX + address.toUpperCase();
return BLUETOOTH_HEADSET_PRIORITY_PREFIX + address.toUpperCase(Locale.ROOT);
}

/**
* Get the key that retrieves a bluetooth a2dp sink's priority.
* @hide
*/
public static final String getBluetoothA2dpSinkPriorityKey(String address) {
return BLUETOOTH_A2DP_SINK_PRIORITY_PREFIX + address.toUpperCase();
return BLUETOOTH_A2DP_SINK_PRIORITY_PREFIX + address.toUpperCase(Locale.ROOT);
}

/**
* Get the key that retrieves a bluetooth Input Device's priority.
* @hide
*/
public static final String getBluetoothInputDevicePriorityKey(String address) {
return BLUETOOTH_INPUT_DEVICE_PRIORITY_PREFIX + address.toUpperCase();
return BLUETOOTH_INPUT_DEVICE_PRIORITY_PREFIX + address.toUpperCase(Locale.ROOT);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion core/java/android/speech/srec/Recognizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public final class Recognizer {
public static String getConfigDir(Locale locale) {
if (locale == null) locale = Locale.US;
String dir = "/system/usr/srec/config/" +
locale.toString().replace('_', '.').toLowerCase();
locale.toString().replace('_', '.').toLowerCase(Locale.ROOT);
if ((new File(dir)).isDirectory()) return dir;
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion core/java/android/text/util/Linkify.java
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ public static final boolean addLinks(Spannable s, Pattern p,
String scheme, MatchFilter matchFilter,
TransformFilter transformFilter) {
boolean hasMatches = false;
String prefix = (scheme == null) ? "" : scheme.toLowerCase();
String prefix = (scheme == null) ? "" : scheme.toLowerCase(Locale.ROOT);
Matcher m = p.matcher(s);

while (m.find()) {
Expand Down
3 changes: 2 additions & 1 deletion core/java/android/util/DebugUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
import java.util.Locale;

/**
* <p>Various utilities for debugging and logging.</p>
Expand Down Expand Up @@ -78,7 +79,7 @@ public static boolean isObjectSelected(Object object) {
Class<?> parent = klass;
do {
declaredMethod = parent.getDeclaredMethod("get" +
pair[0].substring(0, 1).toUpperCase() +
pair[0].substring(0, 1).toUpperCase(Locale.ROOT) +
pair[0].substring(1),
(Class[]) null);
} while ((parent = klass.getSuperclass()) != null &&
Expand Down
3 changes: 2 additions & 1 deletion core/java/android/webkit/URLUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package android.webkit;

import java.io.UnsupportedEncodingException;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -348,7 +349,7 @@ public static final String guessFileName(
}
}
if (extension == null) {
if (mimeType != null && mimeType.toLowerCase().startsWith("text/")) {
if (mimeType != null && mimeType.toLowerCase(Locale.ROOT).startsWith("text/")) {
if (mimeType.equalsIgnoreCase("text/html")) {
extension = ".html";
} else {
Expand Down
4 changes: 2 additions & 2 deletions graphics/java/android/graphics/Color.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public static int parseColor(String colorString) {
}
return (int)color;
} else {
Integer color = sColorNameMap.get(colorString.toLowerCase(Locale.US));
Integer color = sColorNameMap.get(colorString.toLowerCase(Locale.ROOT));
if (color != null) {
return color;
}
Expand Down Expand Up @@ -379,7 +379,7 @@ public static int HSVToColor(int alpha, float hsv[]) {
* @hide
*/
public static int getHtmlColor(String color) {
Integer i = sColorNameMap.get(color.toLowerCase());
Integer i = sColorNameMap.get(color.toLowerCase(Locale.ROOT));
if (i != null) {
return i;
} else {
Expand Down
7 changes: 4 additions & 3 deletions media/java/android/media/MediaFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;

/**
* MediaScanner helper class.
Expand Down Expand Up @@ -297,10 +298,10 @@ public static boolean isDrmFileType(int fileType) {
}

public static MediaFileType getFileType(String path) {
int lastDot = path.lastIndexOf(".");
int lastDot = path.lastIndexOf('.');
if (lastDot < 0)
return null;
return sFileTypeMap.get(path.substring(lastDot + 1).toUpperCase());
return sFileTypeMap.get(path.substring(lastDot + 1).toUpperCase(Locale.ROOT));
}

public static boolean isMimeTypeMedia(String mimeType) {
Expand Down Expand Up @@ -346,7 +347,7 @@ public static int getFormatCode(String fileName, String mimeType) {
}
int lastDot = fileName.lastIndexOf('.');
if (lastDot > 0) {
String extension = fileName.substring(lastDot + 1).toUpperCase();
String extension = fileName.substring(lastDot + 1).toUpperCase(Locale.ROOT);
Integer value = sFileTypeToFormatMap.get(extension);
if (value != null) {
return value.intValue();
Expand Down
2 changes: 1 addition & 1 deletion media/java/android/media/MediaScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ public Uri doScanFile(String path, String mimeType, long lastModified,
if (noMedia) {
result = endFile(entry, false, false, false, false, false);
} else {
String lowpath = path.toLowerCase();
String lowpath = path.toLowerCase(Locale.ROOT);
boolean ringtones = (lowpath.indexOf(RINGTONES_DIR) > 0);
boolean notifications = (lowpath.indexOf(NOTIFICATIONS_DIR) > 0);
boolean alarms = (lowpath.indexOf(ALARMS_DIR) > 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import android.filterfw.core.FrameFormat;
import android.filterfw.format.ObjectFormat;

import java.util.Locale;

/**
* @hide
*/
Expand All @@ -47,7 +49,7 @@ public void process(FilterContext env) {
String inputString = (String)input.getObjectValue();

Frame output = env.getFrameManager().newFrame(mOutputFormat);
output.setObjectValue(inputString.toUpperCase());
output.setObjectValue(inputString.toUpperCase(Locale.getDefault()));

pushOutput("uppercase", output);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

import java.io.File;
import java.util.Date;
import java.util.Locale;

/**
* A view to display the properties of an object.
Expand Down Expand Up @@ -120,7 +121,7 @@ protected void onResume() {
mFileName = info.getName();
view.setText(mFileName);
view = (TextView)findViewById(R.id.format);
view.setText(Integer.toHexString(info.getFormat()).toUpperCase());
view.setText(Integer.toHexString(info.getFormat()).toUpperCase(Locale.ROOT));
view = (TextView)findViewById(R.id.size);
view.setText(Long.toString(info.getCompressedSize()));
view = (TextView)findViewById(R.id.thumb_width);
Expand Down
3 changes: 2 additions & 1 deletion wifi/java/android/net/wifi/WifiInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.net.Inet4Address;
import java.net.UnknownHostException;
import java.util.EnumMap;
import java.util.Locale;

/**
* Describes the state of any Wifi connection that is active or
Expand Down Expand Up @@ -275,7 +276,7 @@ static SupplicantState valueOf(String stateName) {
return SupplicantState.FOUR_WAY_HANDSHAKE;
else {
try {
return SupplicantState.valueOf(stateName.toUpperCase());
return SupplicantState.valueOf(stateName.toUpperCase(Locale.ROOT));
} catch (IllegalArgumentException e) {
return SupplicantState.INVALID;
}
Expand Down
3 changes: 2 additions & 1 deletion wifi/java/android/net/wifi/WifiStateMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.Iterator;
Expand Down Expand Up @@ -2551,7 +2552,7 @@ public boolean processMessage(Message message) {
break;
case CMD_SET_COUNTRY_CODE:
String country = (String) message.obj;
String countryCode = country != null ? country.toUpperCase() : null;
String countryCode = country != null ? country.toUpperCase(Locale.ROOT) : null;
if (DBG) log("set country code " + countryCode);
if (mWifiNative.setCountryCode(countryCode)) {
mCountryCode = countryCode;
Expand Down
Loading

0 comments on commit 9b829a9

Please sign in to comment.