File tree Expand file tree Collapse file tree 2 files changed +36
-3
lines changed
telephony/java/com/android/internal/telephony/gsm Expand file tree Collapse file tree 2 files changed +36
-3
lines changed Original file line number Diff line number Diff line change @@ -250,4 +250,31 @@ public static String[] makeStrings(Collection<InetAddress> addrs) {
250250 }
251251 return result ;
252252 }
253+
254+ /**
255+ * Trim leading zeros from IPv4 address strings
256+ * Our base libraries will interpret that as octel..
257+ * Must leave non v4 addresses and host names alone.
258+ * For example, 192.168.000.010 -> 192.168.0.10
259+ * TODO - fix base libraries and remove this function
260+ * @param addr a string representing an ip addr
261+ * @return a string propertly trimmed
262+ */
263+ public static String trimV4AddrZeros (String addr ) {
264+ String [] octets = addr .split ("\\ ." );
265+ if (octets .length != 4 ) return addr ;
266+ StringBuilder builder = new StringBuilder (16 );
267+ String result = null ;
268+ for (int i = 0 ; i < 4 ; i ++) {
269+ try {
270+ if (octets [i ].length > 3 ) return addr ;
271+ builder .append (Integer .parseInt (octets [i ]));
272+ } catch (NumberFormatException e ) {
273+ return addr ;
274+ }
275+ if (i < 3 ) builder .append ('.' );
276+ }
277+ result = builder .toString ();
278+ return result ;
279+ }
253280}
Original file line number Diff line number Diff line change @@ -914,10 +914,16 @@ private ArrayList<ApnSetting> createApnList(Cursor cursor) {
914914 cursor .getString (cursor .getColumnIndexOrThrow (Telephony .Carriers .NUMERIC )),
915915 cursor .getString (cursor .getColumnIndexOrThrow (Telephony .Carriers .NAME )),
916916 cursor .getString (cursor .getColumnIndexOrThrow (Telephony .Carriers .APN )),
917- cursor .getString (cursor .getColumnIndexOrThrow (Telephony .Carriers .PROXY )),
917+ NetworkUtils .trimV4AddrZeros (
918+ cursor .getString (
919+ cursor .getColumnIndexOrThrow (Telephony .Carriers .PROXY ))),
918920 cursor .getString (cursor .getColumnIndexOrThrow (Telephony .Carriers .PORT )),
919- cursor .getString (cursor .getColumnIndexOrThrow (Telephony .Carriers .MMSC )),
920- cursor .getString (cursor .getColumnIndexOrThrow (Telephony .Carriers .MMSPROXY )),
921+ NetworkUtils .trimV4AddrZeros (
922+ cursor .getString (
923+ cursor .getColumnIndexOrThrow (Telephony .Carriers .MMSC ))),
924+ NetworkUtils .trimV4AddrZeros (
925+ cursor .getString (
926+ cursor .getColumnIndexOrThrow (Telephony .Carriers .MMSPROXY ))),
921927 cursor .getString (cursor .getColumnIndexOrThrow (Telephony .Carriers .MMSPORT )),
922928 cursor .getString (cursor .getColumnIndexOrThrow (Telephony .Carriers .USER )),
923929 cursor .getString (cursor .getColumnIndexOrThrow (Telephony .Carriers .PASSWORD )),
You can’t perform that action at this time.
0 commit comments