diff options
author | Pradeep Panigrahi <pradeepp@codeaurora.org> | 2014-02-21 11:43:03 +0530 |
---|---|---|
committer | Steve Kondik <shade@chemlab.org> | 2014-06-05 12:29:05 -0700 |
commit | 358663a8fd015ed51dc69a0decd3869b4a5fba70 (patch) | |
tree | 1e676abcafb06177aca5cfdb453f677cb61d43ae | |
parent | 3a12aa10dcccf7d7454a254c9e9d23e7059944c4 (diff) | |
download | android_packages_apps_Bluetooth-358663a8fd015ed51dc69a0decd3869b4a5fba70.tar.gz android_packages_apps_Bluetooth-358663a8fd015ed51dc69a0decd3869b4a5fba70.tar.bz2 android_packages_apps_Bluetooth-358663a8fd015ed51dc69a0decd3869b4a5fba70.zip |
Bluetooth: Map: Bug fixes on Map Code.
Add bug fixes on MAP code to avoid null deferences in erroneous
scenario.
Avoid null dereference during a case when emailBody is null and getMessage
operation is performed for that email handle.
CRs-fixed: 620282
Change-Id: I4066daf88251452a21b97292817d49232c70dd76
4 files changed, 41 insertions, 29 deletions
diff --git a/src/com/android/bluetooth/map/BluetoothMapContent.java b/src/com/android/bluetooth/map/BluetoothMapContent.java index d30512af9..341889443 100644 --- a/src/com/android/bluetooth/map/BluetoothMapContent.java +++ b/src/com/android/bluetooth/map/BluetoothMapContent.java @@ -265,7 +265,7 @@ public class BluetoothMapContent { selection, null, null); - if (c.moveToFirst()) { + if (c !=null && c.moveToFirst()) { do { String add = c.getString(c.getColumnIndex("address")); Integer type = c.getInt(c.getColumnIndex("type")); @@ -314,7 +314,7 @@ public class BluetoothMapContent { null, null); if (D) Log.d(TAG, " parts:"); - if (c.moveToFirst()) { + if (c !=null && c.moveToFirst()) { do { Long partid = c.getLong(c.getColumnIndex(BaseColumns._ID)); String ct = c.getString(c.getColumnIndex("ct")); @@ -358,9 +358,9 @@ public class BluetoothMapContent { printMmsAddr(id); printMmsParts(id); } + c.close(); } else { Log.d(TAG, "query failed"); - c.close(); } } @@ -375,9 +375,9 @@ public class BluetoothMapContent { while (c.moveToNext()) { printSms(c); } + c.close(); } else { Log.d(TAG, "query failed"); - c.close(); } } @@ -722,7 +722,7 @@ public class BluetoothMapContent { } else { int toIndex = c.getColumnIndex(MessageColumns.TO_LIST); address = c.getString(toIndex); - if (address.contains("")) { + if (address != null && address.contains("")) { String[] recepientAddrStr = address.split(""); if (recepientAddrStr !=null && recepientAddrStr.length > 0) { if (V){ @@ -1043,7 +1043,9 @@ public class BluetoothMapContent { name = c.getString(c.getColumnIndex(Contacts.DISPLAY_NAME)); } - c.close(); + if (c != null) { + c.close(); + } return name; } @@ -1458,9 +1460,13 @@ public class BluetoothMapContent { if (!c.isLast()) { where += " OR "; } - p.close(); + if (p != null) { + p.close(); + } + } + if (c != null) { + c.close(); } - c.close(); if (str != null && str.length() > 0) { if (where.length() > 0) { @@ -2305,7 +2311,8 @@ public class BluetoothMapContent { contactId = p.getString(p.getColumnIndex(Contacts._ID)); contactName = p.getString(p.getColumnIndex(Contacts.DISPLAY_NAME)); } - p.close(); + if (p != null) + p.close(); // The phone number we got is the one we will use phoneNumbers = new String[1]; @@ -2404,7 +2411,7 @@ public class BluetoothMapContent { selection, null, null); /* TODO: Change the setVCard...() to return the vCard, and use the name in message.addXxx() */ - if (c.moveToFirst()) { + if (c != null && c.moveToFirst()) { do { String address = c.getString(c.getColumnIndex("address")); Integer type = c.getInt(c.getColumnIndex("type")); @@ -2485,7 +2492,7 @@ public class BluetoothMapContent { selection, null, null); - if (c.moveToFirst()) { + if (c != null && c.moveToFirst()) { do { Long partId = c.getLong(c.getColumnIndex(BaseColumns._ID)); String contentType = c.getString(c.getColumnIndex("ct")); diff --git a/src/com/android/bluetooth/map/BluetoothMapContentObserver.java b/src/com/android/bluetooth/map/BluetoothMapContentObserver.java index 12203a13f..c66a03dbe 100644 --- a/src/com/android/bluetooth/map/BluetoothMapContentObserver.java +++ b/src/com/android/bluetooth/map/BluetoothMapContentObserver.java @@ -1198,7 +1198,7 @@ public class BluetoothMapContentObserver { Cursor cursor = mResolver.query(msgInfo.uri, ID_PROJECTION, null, null, null); try { - if (cursor.moveToFirst()) { + if (cursor != null && cursor.moveToFirst()) { int messageId = cursor.getInt(0); Uri updateUri = ContentUris.withAppendedId(UPDATE_STATUS_URI, messageId); @@ -1216,7 +1216,8 @@ public class BluetoothMapContentObserver { Log.d(TAG, "Can't find message for status update: " + messageUri); } } finally { - cursor.close(); + if (cursor != null) + cursor.close(); } if (status == 0) { diff --git a/src/com/android/bluetooth/map/BluetoothMapService.java b/src/com/android/bluetooth/map/BluetoothMapService.java index e94af3d30..262ab70f4 100644 --- a/src/com/android/bluetooth/map/BluetoothMapService.java +++ b/src/com/android/bluetooth/map/BluetoothMapService.java @@ -273,17 +273,19 @@ public class BluetoothMapService extends ProfileService { Set<BluetoothDevice> bondedDevices = mAdapter.getBondedDevices(); int connectionState; synchronized (this) { - for (BluetoothDevice device : bondedDevices) { - ParcelUuid[] featureUuids = device.getUuids(); - if (!BluetoothUuid.containsAnyUuid(featureUuids, MAP_UUIDS)) { - continue; - } - connectionState = getConnectionState(device); - for(int i = 0; i < states.length; i++) { - if (connectionState == states[i]) { - deviceList.add(device); - } - } + if (bondedDevices != null) { + for (BluetoothDevice device : bondedDevices) { + ParcelUuid[] featureUuids = device.getUuids(); + if (!BluetoothUuid.containsAnyUuid(featureUuids, MAP_UUIDS)) { + continue; + } + connectionState = getConnectionState(device); + for(int i = 0; i < states.length; i++) { + if (connectionState == states[i]) { + deviceList.add(device); + } + } + } } } return deviceList; diff --git a/src/com/android/bluetooth/map/BluetoothMapbMessageMmsEmail.java b/src/com/android/bluetooth/map/BluetoothMapbMessageMmsEmail.java index 84f9c511e..7cd72fa50 100644 --- a/src/com/android/bluetooth/map/BluetoothMapbMessageMmsEmail.java +++ b/src/com/android/bluetooth/map/BluetoothMapbMessageMmsEmail.java @@ -87,11 +87,13 @@ public class BluetoothMapbMessageMmsEmail extends BluetoothMapbMessage { public void encodePlainText(StringBuilder sb) throws UnsupportedEncodingException { if(contentType != null && contentType.toUpperCase().contains("TEXT")) { - sb.append(contentType).append("\r\n"); - sb.append("Content-Transfer-Encoding: 8bit").append("\r\n"); - sb.append("Content-Disposition:inline").append("\r\n") - .append("\r\n"); - sb.append(new String(data,"UTF-8")).append("\r\n"); + if(data != null) { + sb.append(contentType).append("\r\n"); + sb.append("Content-Transfer-Encoding: 8bit").append("\r\n"); + sb.append("Content-Disposition:inline").append("\r\n") + .append("\r\n"); + sb.append(new String(data,"UTF-8")).append("\r\n"); + } } else if(contentType != null && contentType.toUpperCase().contains("/SMIL")) { /* Skip the smil.xml, as no-one knows what it is. */ } else { |