summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGaurav Asati <gasati@codeaurora.org>2014-10-08 12:01:06 +0530
committerrakesh reddy <ramare@codeaurora.org>2014-11-12 17:18:06 +0530
commit637282364053a9477490cb0732532ea806504768 (patch)
tree6d314f2f7e8100f483ede871cd291efc65276090
parent5475aebf79c70a9967206aec7bd44177faf460da (diff)
downloadandroid_packages_apps_Bluetooth-637282364053a9477490cb0732532ea806504768.tar.gz
android_packages_apps_Bluetooth-637282364053a9477490cb0732532ea806504768.tar.bz2
android_packages_apps_Bluetooth-637282364053a9477490cb0732532ea806504768.zip
Bluetooth: NPE and Memory leaks.
Fix NPE and Memory leak identified by static analysis. CRs-Fixed: 747566 Change-Id: If73882341f7dfb2aaa2756be6ebbbb96fb779085
-rw-r--r--src/com/android/bluetooth/avrcp/Avrcp.java132
-rw-r--r--src/com/android/bluetooth/hfp/HeadsetStateMachine.java51
2 files changed, 123 insertions, 60 deletions
diff --git a/src/com/android/bluetooth/avrcp/Avrcp.java b/src/com/android/bluetooth/avrcp/Avrcp.java
index b734a89f3..98f6ca537 100644
--- a/src/com/android/bluetooth/avrcp/Avrcp.java
+++ b/src/com/android/bluetooth/avrcp/Avrcp.java
@@ -1318,13 +1318,15 @@ public final class Avrcp {
cursor, attr);
attIds[(7 * index) + attIndex] = attr;
}
- cursor.close();
}
} catch(Exception e) {
Log.i(TAG, "Exception e"+ e);
- cursor.close();
getFolderItemsRspNative((byte)INTERNAL_ERROR, numItems, itemType,
uid, type, playable, displayName, numAtt, attValues, attIds);
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
}
}
numItems = index;
@@ -1617,11 +1619,13 @@ public final class Avrcp {
status = NOT_A_DIRECTORY;
else
status = DOES_NOT_EXIST;
- cursor.close();
} catch (Exception e) {
Log.e(TAG, "Exception " + e);
- cursor.close();
changePathRspNative(INTERNAL_ERROR, numberOfItems);
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
}
break;
default:
@@ -1656,12 +1660,14 @@ public final class Avrcp {
} else{
numberOfItems = cursor.getCount();
mCurrentPathUid = String.valueOf(folderUid);
- cursor.close();
}
} catch (Exception e) {
Log.e(TAG, "Exception " + e);
- cursor.close();
changePathRspNative(INTERNAL_ERROR, numberOfItems);
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
}
} else { // Path @ Individual Album id
Cursor cursor = null;
@@ -1677,11 +1683,13 @@ public final class Avrcp {
status = NOT_A_DIRECTORY;
else
status = DOES_NOT_EXIST;
- cursor.close();
} catch (Exception e) {
Log.e(TAG, "Exception " + e);
- cursor.close();
changePathRspNative(INTERNAL_ERROR, numberOfItems);
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
}
}
break;
@@ -1718,12 +1726,14 @@ public final class Avrcp {
numberOfItems = cursor.getCount();
mCurrentPathUid = String.valueOf(folderUid);
mCurrentPath = PATH_ARTISTS;
- cursor.close();
}
} catch (Exception e) {
Log.e(TAG, "Exception " + e);
- cursor.close();
changePathRspNative(INTERNAL_ERROR, numberOfItems);
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
}
} else {
Cursor cursor = null;
@@ -1737,11 +1747,13 @@ public final class Avrcp {
status = NOT_A_DIRECTORY;
else
status = DOES_NOT_EXIST;
- cursor.close();
} catch (Exception e) {
Log.e(TAG, "Exception " + e);
- cursor.close();
changePathRspNative(INTERNAL_ERROR, numberOfItems);
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
}
}
break;
@@ -1784,12 +1796,14 @@ public final class Avrcp {
numberOfItems = cursor.getCount();
mCurrentPathUid = String.valueOf(folderUid);
mCurrentPath = PATH_PLAYLISTS;
- cursor.close();
}
} catch (Exception e) {
Log.e(TAG, "Exception " + e);
- cursor.close();
changePathRspNative(INTERNAL_ERROR, numberOfItems);
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
}
} else {
numberOfItems = 0;
@@ -1824,13 +1838,15 @@ public final class Avrcp {
return 0;
} else {
long count = cursor.getCount();
- cursor.close();
return count;
}
} catch (Exception e) {
Log.e(TAG, "Exception " + e);
- cursor.close();
return 0;
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
}
}
@@ -1848,7 +1864,6 @@ public final class Avrcp {
return 0;
} else if (path.equals(PATH_TITLES)) {
long count = cursor.getCount();
- cursor.close();
return count;
} else if (path.equals(PATH_ALBUMS) || path.equals(PATH_ARTISTS)){
long elemCount = 0;
@@ -1867,12 +1882,14 @@ public final class Avrcp {
count--;
}
Log.i(TAG, "element Count is "+ elemCount);
- cursor.close();
return elemCount;
}
} catch (Exception e) {
Log.e(TAG, "Exception " + e);
- cursor.close();
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
}
return 0;
}
@@ -1919,13 +1936,15 @@ public final class Avrcp {
playItemRspNative(DOES_NOT_EXIST);
} else {
Log.i(TAG, "Play uid:" + uid);
- cursor.close();
mRemoteController.setRemoteControlClientPlayItem(uid, scope);
}
} catch (Exception e) {
Log.e(TAG, "Exception " + e);
- cursor.close();
playItemRspNative(INTERNAL_ERROR);
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
}
} else if (mCurrentPath.equals(PATH_ALBUMS)) {
if (mCurrentPathUid == null) {
@@ -1944,13 +1963,15 @@ public final class Avrcp {
playItemRspNative(DOES_NOT_EXIST);
} else {
Log.i(TAG, "Play uid:" + uid);
- cursor.close();
mRemoteController.setRemoteControlClientPlayItem(uid, scope);
}
} catch (Exception e) {
Log.e(TAG, "Exception " + e);
- cursor.close();
playItemRspNative(INTERNAL_ERROR);
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
}
}
} else if (mCurrentPath.equals(PATH_ARTISTS)) {
@@ -1970,13 +1991,15 @@ public final class Avrcp {
playItemRspNative(DOES_NOT_EXIST);
} else {
Log.i(TAG, "Play uid:" + uid);
- cursor.close();
mRemoteController.setRemoteControlClientPlayItem(uid, scope);
}
} catch (Exception e) {
Log.e(TAG, "Exception " + e);
- cursor.close();
playItemRspNative(INTERNAL_ERROR);
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
}
}
} else if (mCurrentPath.equals(PATH_PLAYLISTS)) {
@@ -2009,13 +2032,15 @@ public final class Avrcp {
playItemRspNative(DOES_NOT_EXIST);
} else {
Log.i(TAG, "Play uid:" + uid);
- cursor.close();
mRemoteController.setRemoteControlClientPlayItem(uid, scope);
}
} catch (Exception e) {
Log.e(TAG, "Exception " + e);
- cursor.close();
playItemRspNative(INTERNAL_ERROR);
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
}
}
} else {
@@ -2083,11 +2108,14 @@ public final class Avrcp {
textArray[i] = getAttributeStringFromCursor(cursor, attrs[i]);
}
getItemAttrRspNative(numAttr, attrs, textArray);
- cursor.close();
}
} catch (Exception e) {
- Log.e(TAG, "Exception " + e); cursor.close();
+ Log.e(TAG, "Exception " + e);
getItemAttrRspNative((byte)0, attrs, textArray);
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
}
} else {
Log.i(TAG, "Invalid scope");
@@ -2345,7 +2373,6 @@ public final class Avrcp {
getFolderItemsRspNative((byte)RANGE_OUT_OF_BOUNDS, numItems,
itemType, uid, type, playable, displayName, numAtt, attValues,
attIds);
- cursor.close();
return;
}
cursor.moveToFirst();
@@ -2388,12 +2415,14 @@ public final class Avrcp {
numItems = index;
getFolderItemsRspNative((byte)OPERATION_SUCCESSFUL, numItems, itemType, uid,
type, playable, displayName, numAtt, attValues, attIds);
- cursor.close();
} catch(Exception e) {
Log.i(TAG, "Exception e" + e);
- cursor.close();
getFolderItemsRspNative((byte)INTERNAL_ERROR, numItems, itemType, uid, type,
playable, displayName, numAtt, attValues, attIds);
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
}
} else if (mCurrentPath.equals(PATH_ALBUMS)) {
if (mCurrentPathUid == null) {
@@ -2472,12 +2501,14 @@ public final class Avrcp {
itemType, uid, type, playable, displayName, numAtt, attValues,
attIds);
}
- cursor.close();
} catch(Exception e) {
Log.i(TAG, "Exception e" + e);
- cursor.close();
getFolderItemsRspNative((byte)INTERNAL_ERROR, numItems, itemType, uid, type,
playable, displayName, numAtt, attValues, attIds);
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
}
} else {
long folderUid = Long.valueOf(mCurrentPathUid);
@@ -2497,7 +2528,6 @@ public final class Avrcp {
getFolderItemsRspNative((byte)RANGE_OUT_OF_BOUNDS, numItems,
itemType, uid, type, playable, displayName, numAtt,
attValues, attIds);
- cursor.close();
return;
}
cursor.moveToFirst();
@@ -2542,12 +2572,14 @@ public final class Avrcp {
numItems = index;
getFolderItemsRspNative((byte)OPERATION_SUCCESSFUL, numItems, itemType, uid,
type, playable, displayName, numAtt, attValues, attIds);
- cursor.close();
} catch(Exception e) {
Log.i(TAG, "Exception e" + e);
- cursor.close();
getFolderItemsRspNative((byte)INTERNAL_ERROR, numItems, itemType, uid, type,
playable, displayName, numAtt, attValues, attIds);
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
}
}
} else if (mCurrentPath.equals(PATH_ARTISTS)) {
@@ -2625,12 +2657,14 @@ public final class Avrcp {
getFolderItemsRspNative((byte)RANGE_OUT_OF_BOUNDS, numItems, itemType,
uid, type, playable, displayName, numAtt, attValues, attIds);
}
- cursor.close();
} catch(Exception e) {
Log.i(TAG, "Exception e" + e);
- cursor.close();
getFolderItemsRspNative((byte)INTERNAL_ERROR, numItems, itemType, uid, type,
playable, displayName, numAtt, attValues, attIds);
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
}
} else {
long folderUid = Long.valueOf(mCurrentPathUid);
@@ -2650,7 +2684,6 @@ public final class Avrcp {
getFolderItemsRspNative((byte)RANGE_OUT_OF_BOUNDS, numItems,
itemType, uid, type, playable, displayName, numAtt, attValues,
attIds);
- cursor.close();
return;
}
cursor.moveToFirst();
@@ -2694,12 +2727,14 @@ public final class Avrcp {
numItems = index;
getFolderItemsRspNative((byte)OPERATION_SUCCESSFUL, numItems, itemType,
uid, type, playable, displayName, numAtt, attValues, attIds);
- cursor.close();
} catch(Exception e) {
Log.i(TAG, "Exception e" + e);
- cursor.close();
getFolderItemsRspNative((byte)INTERNAL_ERROR, numItems, itemType, uid,
type, playable, displayName, numAtt, attValues, attIds);
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
}
}
} else if (mCurrentPath.equals(PATH_PLAYLISTS)) {
@@ -2771,12 +2806,14 @@ public final class Avrcp {
itemType, uid, type, playable, displayName, numAtt,
attValues, attIds);
}
- cursor.close();
} catch(Exception e) {
Log.i(TAG, "Exception e" + e);
- cursor.close();
getFolderItemsRspNative((byte)INTERNAL_ERROR, numItems, itemType,
uid, type, playable, displayName, numAtt, attValues, attIds);
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
}
} else {
long folderUid = Long.valueOf(mCurrentPathUid);
@@ -2811,7 +2848,6 @@ public final class Avrcp {
getFolderItemsRspNative((byte)RANGE_OUT_OF_BOUNDS, numItems,
itemType, uid, type, playable, displayName, numAtt,
attValues, attIds);
- cursor.close();
return;
}
cursor.moveToFirst();
@@ -2856,12 +2892,14 @@ public final class Avrcp {
numItems = index;
getFolderItemsRspNative((byte)OPERATION_SUCCESSFUL, numItems, itemType, uid,
type, playable, displayName, numAtt, attValues, attIds);
- cursor.close();
} catch(Exception e) {
Log.e(TAG, "Exception e" + e);
- cursor.close();
getFolderItemsRspNative((byte)INTERNAL_ERROR, numItems, itemType, uid, type,
playable, displayName, numAtt, attValues, attIds);
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
}
}
} else {
diff --git a/src/com/android/bluetooth/hfp/HeadsetStateMachine.java b/src/com/android/bluetooth/hfp/HeadsetStateMachine.java
index 276948152..f3bcea996 100644
--- a/src/com/android/bluetooth/hfp/HeadsetStateMachine.java
+++ b/src/com/android/bluetooth/hfp/HeadsetStateMachine.java
@@ -2407,10 +2407,16 @@ final class HeadsetStateMachine extends StateMachine {
}
public boolean isBluetoothVoiceDialingEnabled( BluetoothDevice device) {
- int RemoteBrsf = mHeadsetBrsf.get(device);
- Log.d(TAG, "isBluetoothVoiceDialingEnabled mRemoteBrsf: " + RemoteBrsf +
- "supported: " + (RemoteBrsf & BRSF_HF_VOICE_REG_ACT));
- return ((RemoteBrsf & BRSF_HF_VOICE_REG_ACT) != 0x0) ? true : false;
+ int remoteBrsf = 0;
+ if (mHeadsetBrsf != null && !mHeadsetBrsf.isEmpty()) {
+ remoteBrsf = mHeadsetBrsf.get(device);
+ } else {
+ Log.e(TAG,"remote device supported features not found");
+ return false;
+ }
+ Log.d(TAG, "isBluetoothVoiceDialingEnabled mRemoteBrsf: " + remoteBrsf +
+ "supported: " + (remoteBrsf & BRSF_HF_VOICE_REG_ACT));
+ return ((remoteBrsf & BRSF_HF_VOICE_REG_ACT) != 0x0) ? true : false;
}
int getAudioState(BluetoothDevice device) {
@@ -2512,7 +2518,11 @@ final class HeadsetStateMachine extends StateMachine {
// Whereas for VoiceDial we want to activate the SCO connection but we are still
// in MODE_NORMAL and hence the need to explicitly suspend the A2DP stream
mAudioManager.setParameters("A2dpSuspended=true");
- connectAudioNative(getByteAddress(device));
+ if (device != null) {
+ connectAudioNative(getByteAddress(device));
+ } else {
+ Log.e(TAG, "device not found for VR");
+ }
}
if (mStartVoiceRecognitionWakeLock.isHeld()) {
@@ -2680,9 +2690,15 @@ final class HeadsetStateMachine extends StateMachine {
{
// 1. update nrec value
// 2. update headset name
+ int mCodec = 0;
+ int mNrec = 0;
HashMap<String, Integer> AudioParam = mHeadsetAudioParam.get(device);
- int mCodec = AudioParam.get("codec");
- int mNrec = AudioParam.get("NREC");
+ if (AudioParam != null && !AudioParam.isEmpty()) {
+ mCodec = AudioParam.get("codec");
+ mNrec = AudioParam.get("NREC");
+ } else {
+ Log.e(TAG,"setAudioParameters: AudioParam not found");
+ }
if (mCodec != WBS_CODEC) {
Log.d(TAG, "Use NBS PCM samples:" + device);
mAudioManager.setParameters(HEADSET_WBS + "=off");
@@ -3104,18 +3120,27 @@ final class HeadsetStateMachine extends StateMachine {
// 0 disable noice reduction
private void processNoiceReductionEvent(int enable, BluetoothDevice device) {
HashMap<String, Integer> AudioParamNrec = mHeadsetAudioParam.get(device);
- if (enable == 1)
- AudioParamNrec.put("NREC", 1);
- else
- AudioParamNrec.put("NREC", 0);
- log("NREC value for device :" + device + " is: " + AudioParamNrec.get("NREC"));
+ if (AudioParamNrec != null && !AudioParamNrec.isEmpty()) {
+ if (enable == 1)
+ AudioParamNrec.put("NREC", 1);
+ else
+ AudioParamNrec.put("NREC", 0);
+ log("NREC value for device :" + device + " is: " +
+ AudioParamNrec.get("NREC"));
+ } else {
+ Log.e(TAG,"processNoiceReductionEvent: AudioParamNrec is null ");
+ }
}
// 2 - WBS on
// 1 - NBS on
private void processWBSEvent(int enable, BluetoothDevice device) {
HashMap<String, Integer> AudioParamCodec = mHeadsetAudioParam.get(device);
- AudioParamCodec.put("codec", enable);
+ if (AudioParamCodec != null && !AudioParamCodec.isEmpty()) {
+ AudioParamCodec.put("codec", enable);
+ } else {
+ Log.e(TAG,"processWBSEvent: AudioParamNrec is null ");
+ }
if (enable == 2) {
Log.d(TAG, "AudioManager.setParameters bt_wbs=on for " +
device.getName() + " - " + device.getAddress());