summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSwami Dhyan Anurag <dhyananurag@codeaurora.org>2014-11-12 17:29:43 -0800
committerGerrit - the friendly Code Review server <code-review@localhost>2014-11-14 07:40:27 -0800
commitb1bafb1f78d1ae743f039614e1913da15c64d796 (patch)
tree3a4c89b3908f20da936c5f3438cbd449e88b43c8
parentec1ee663663a1b8cec0a2a03da3124295dc5578c (diff)
downloadandroid_packages_apps_Bluetooth-b1bafb1f78d1ae743f039614e1913da15c64d796.tar.gz
android_packages_apps_Bluetooth-b1bafb1f78d1ae743f039614e1913da15c64d796.tar.bz2
android_packages_apps_Bluetooth-b1bafb1f78d1ae743f039614e1913da15c64d796.zip
Bluetooth: Fix Klocwork issues for gatt
Code changes fix the klocwork issue in gatt. Change-Id: If9e5a1bcddf3aa50220d11a3be6940ae60facdff
-rw-r--r--src/com/android/bluetooth/gatt/AdvertiseManager.java16
-rw-r--r--src/com/android/bluetooth/gatt/GattService.java70
-rw-r--r--src/com/android/bluetooth/gatt/ScanManager.java55
3 files changed, 96 insertions, 45 deletions
diff --git a/src/com/android/bluetooth/gatt/AdvertiseManager.java b/src/com/android/bluetooth/gatt/AdvertiseManager.java
index 6222fb534..22b20dd6b 100644
--- a/src/com/android/bluetooth/gatt/AdvertiseManager.java
+++ b/src/com/android/bluetooth/gatt/AdvertiseManager.java
@@ -229,12 +229,16 @@ class AdvertiseManager {
// Returns maximum advertise instances supported by controller.
private int maxAdvertiseInstances() {
- AdapterService adapter = AdapterService.getAdapterService();
- int numOfAdvtInstances = adapter.getNumOfAdvertisementInstancesSupported();
- // Note numOfAdvtInstances includes the standard advertising instance.
- // TODO: remove - 1 once the stack is able to include standard instance for multiple
- // advertising.
- return numOfAdvtInstances - 1;
+ AdapterService adapter;
+ int numOfAdvtInstances = 0;
+ if (null != (adapter = AdapterService.getAdapterService())){
+ numOfAdvtInstances = adapter.getNumOfAdvertisementInstancesSupported();
+ // Note numOfAdvtInstances includes the standard advertising instance.
+ // TODO: remove - 1 once the stack is able to include standard instance for multiple
+ // advertising.
+ return numOfAdvtInstances - 1;
+ }
+ return numOfAdvtInstances;
}
}
diff --git a/src/com/android/bluetooth/gatt/GattService.java b/src/com/android/bluetooth/gatt/GattService.java
index 4dbf0fed8..654df69b9 100644
--- a/src/com/android/bluetooth/gatt/GattService.java
+++ b/src/com/android/bluetooth/gatt/GattService.java
@@ -1721,10 +1721,14 @@ public class GattService extends ProfileService {
case HandleMap.TYPE_CHARACTERISTIC:
{
HandleMap.Entry serviceEntry = mHandleMap.getByHandle(entry.serviceHandle);
+ if (null != serviceEntry) {
app.callback.onCharacteristicReadRequest(address, transId, offset, isLong,
serviceEntry.serviceType, serviceEntry.instance,
new ParcelUuid(serviceEntry.uuid), entry.instance,
new ParcelUuid(entry.uuid));
+ }else {
+ Log.d(TAG, "null == serviceEntry");
+ }
break;
}
@@ -1732,11 +1736,15 @@ public class GattService extends ProfileService {
{
HandleMap.Entry serviceEntry = mHandleMap.getByHandle(entry.serviceHandle);
HandleMap.Entry charEntry = mHandleMap.getByHandle(entry.charHandle);
- app.callback.onDescriptorReadRequest(address, transId, offset, isLong,
+ if (null != serviceEntry && null != charEntry) {
+ app.callback.onDescriptorReadRequest(address, transId, offset, isLong,
serviceEntry.serviceType, serviceEntry.instance,
new ParcelUuid(serviceEntry.uuid), charEntry.instance,
new ParcelUuid(charEntry.uuid),
new ParcelUuid(entry.uuid));
+ } else {
+ Log.d(TAG, "null == serviceEntry || null == charEntry");
+ }
break;
}
@@ -1771,11 +1779,15 @@ public class GattService extends ProfileService {
case HandleMap.TYPE_CHARACTERISTIC:
{
HandleMap.Entry serviceEntry = mHandleMap.getByHandle(entry.serviceHandle);
+ if (null != serviceEntry) {
app.callback.onCharacteristicWriteRequest(address, transId,
offset, length, isPrep, needRsp,
serviceEntry.serviceType, serviceEntry.instance,
new ParcelUuid(serviceEntry.uuid), entry.instance,
new ParcelUuid(entry.uuid), data);
+ }else {
+ Log.d(TAG, "null == serviceEntry");
+ }
break;
}
@@ -1783,12 +1795,16 @@ public class GattService extends ProfileService {
{
HandleMap.Entry serviceEntry = mHandleMap.getByHandle(entry.serviceHandle);
HandleMap.Entry charEntry = mHandleMap.getByHandle(entry.charHandle);
+ if (null != serviceEntry && null != charEntry) {
app.callback.onDescriptorWriteRequest(address, transId,
offset, length, isPrep, needRsp,
serviceEntry.serviceType, serviceEntry.instance,
new ParcelUuid(serviceEntry.uuid), charEntry.instance,
new ParcelUuid(charEntry.uuid),
new ParcelUuid(entry.uuid), data);
+ } else {
+ Log.d(TAG, "null == serviceEntry || null == charEntry");
+ }
break;
}
@@ -1893,8 +1909,12 @@ public class GattService extends ProfileService {
if (DBG) Log.d(TAG, "beginServiceDeclaration() - uuid=" + srvcUuid +
" serverIf=" + serverIf);
ServiceDeclaration serviceDeclaration = addToActiveDeclaration(serverIf);
- serviceDeclaration.addService(srvcUuid, srvcType, srvcInstanceId, minHandles,
+ if (null != serviceDeclaration ) {
+ serviceDeclaration.addService(srvcUuid, srvcType, srvcInstanceId, minHandles,
advertisePreferred);
+ } else {
+ if (DBG) Log.d(TAG, "beginServiceDeclaration: Got null from addToActiveDeclaration()");
+ }
}
void addIncludedService(int serverIf, int srvcType, int srvcInstanceId,
@@ -1902,7 +1922,12 @@ public class GattService extends ProfileService {
enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
if (DBG) Log.d(TAG, "addIncludedService() - uuid=" + srvcUuid);
- getActiveDeclaration(serverIf).addIncludedService(srvcUuid, srvcType, srvcInstanceId);
+ ServiceDeclaration serviceDeclaration = getActiveDeclaration(serverIf);
+ if (null != serviceDeclaration) {
+ serviceDeclaration.addIncludedService(srvcUuid, srvcType, srvcInstanceId);
+ } else {
+ Log.d(TAG,"getActiveDeclaration(serverIf) is null");
+ }
}
void addCharacteristic(int serverIf, UUID charUuid, int properties,
@@ -1910,14 +1935,24 @@ public class GattService extends ProfileService {
enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
if (DBG) Log.d(TAG, "addCharacteristic() - uuid=" + charUuid);
- getActiveDeclaration(serverIf).addCharacteristic(charUuid, properties, permissions);
+ ServiceDeclaration serviceDeclaration = getActiveDeclaration(serverIf);
+ if (null != serviceDeclaration) {
+ serviceDeclaration.addCharacteristic(charUuid, properties, permissions);
+ } else {
+ Log.d(TAG,"getActiveDeclaration(serverIf) is null");
+ }
}
void addDescriptor(int serverIf, UUID descUuid, int permissions) {
enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
if (DBG) Log.d(TAG, "addDescriptor() - uuid=" + descUuid);
- getActiveDeclaration(serverIf).addDescriptor(descUuid, permissions);
+ ServiceDeclaration serviceDeclaration = getActiveDeclaration(serverIf);
+ if (null != serviceDeclaration) {
+ serviceDeclaration.addDescriptor(descUuid, permissions);
+ } else {
+ Log.d(TAG,"getActiveDeclaration(serverIf) is null");
+ }
}
void endServiceDeclaration(int serverIf) {
@@ -1965,9 +2000,11 @@ public class GattService extends ProfileService {
HandleMap.Entry entry = mHandleMap.getByRequestId(requestId);
if (entry != null) handle = entry.handle;
- int connId = mServerMap.connIdByAddress(serverIf, address);
- gattServerSendResponseNative(serverIf, connId, requestId, (byte)status,
+ Integer connId;
+ if(null != (connId = mServerMap.connIdByAddress(serverIf, address))) {
+ gattServerSendResponseNative(serverIf, connId, requestId, (byte)status,
handle, offset, value, (byte)0);
+ }
mHandleMap.deleteRequest(requestId);
}
@@ -1985,9 +2022,8 @@ public class GattService extends ProfileService {
int charHandle = mHandleMap.getCharacteristicHandle(srvcHandle, charUuid, charInstanceId);
if (charHandle == 0) return;
- int connId = mServerMap.connIdByAddress(serverIf, address);
- if (connId == 0) return;
-
+ Integer connId = mServerMap.connIdByAddress(serverIf, address);
+ if (connId == null) return;
if (confirm) {
gattServerSendIndicationNative(serverIf, charHandle, connId, value);
} else {
@@ -2060,12 +2096,14 @@ public class GattService extends ProfileService {
private void continueServiceDeclaration(int serverIf, int status, int srvcHandle) throws RemoteException {
if (mServiceDeclarations.size() == 0) return;
if (DBG) Log.d(TAG, "continueServiceDeclaration() - srvcHandle=" + srvcHandle);
-
+ ServiceDeclaration serviceDeclaration;
boolean finished = false;
ServiceDeclaration.Entry entry = null;
- if (status == 0)
- entry = getPendingDeclaration().getNext();
+ if (status == 0) {
+ if (null != (serviceDeclaration = getPendingDeclaration()))
+ entry = serviceDeclaration.getNext();
+ }
if (entry != null) {
if (DBG) Log.d(TAG, "continueServiceDeclaration() - next entry type="
@@ -2075,11 +2113,13 @@ public class GattService extends ProfileService {
if (entry.advertisePreferred) {
mAdvertisingServiceUuids.add(entry.uuid);
}
- gattServerAddServiceNative(serverIf, entry.serviceType,
+ if (null != (serviceDeclaration = getPendingDeclaration())) {
+ gattServerAddServiceNative(serverIf, entry.serviceType,
entry.instance,
entry.uuid.getLeastSignificantBits(),
entry.uuid.getMostSignificantBits(),
- getPendingDeclaration().getNumHandles());
+ serviceDeclaration.getNumHandles());
+ }
break;
case ServiceDeclaration.TYPE_CHARACTERISTIC:
diff --git a/src/com/android/bluetooth/gatt/ScanManager.java b/src/com/android/bluetooth/gatt/ScanManager.java
index bbbede26d..705d49e72 100644
--- a/src/com/android/bluetooth/gatt/ScanManager.java
+++ b/src/com/android/bluetooth/gatt/ScanManager.java
@@ -361,14 +361,15 @@ public class ScanManager {
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "awakened up at time " + SystemClock.elapsedRealtime());
- String action = intent.getAction();
-
- if (action.equals(ACTION_REFRESH_BATCHED_SCAN)) {
- if (mBatchClients.isEmpty()) {
- return;
+ String action;
+ if (null != (action = intent.getAction())) {
+ if (action.equals(ACTION_REFRESH_BATCHED_SCAN)) {
+ if (mBatchClients.isEmpty()) {
+ return;
+ }
+ // Note this actually flushes all pending batch data.
+ flushBatchScanResults(mBatchClients.iterator().next());
}
- // Note this actually flushes all pending batch data.
- flushBatchScanResults(mBatchClients.iterator().next());
}
}
};
@@ -659,20 +660,24 @@ public class ScanManager {
waitForCallback();
} else {
Deque<Integer> clientFilterIndices = new ArrayDeque<Integer>();
+ int featureSelection;
+ int filterIndex;
for (ScanFilter filter : client.filters) {
ScanFilterQueue queue = new ScanFilterQueue();
- queue.addScanFilter(filter);
- int featureSelection = queue.getFeatureSelection();
- int filterIndex = mFilterIndexStack.pop();
- while (!queue.isEmpty()) {
+ if (null != queue) {
+ queue.addScanFilter(filter);
+ featureSelection = queue.getFeatureSelection();
+ filterIndex = mFilterIndexStack.pop();
+ while (!queue.isEmpty()) {
+ resetCountDownLatch();
+ addFilterToController(clientIf, queue.pop(), filterIndex);
+ waitForCallback();
+ }
resetCountDownLatch();
- addFilterToController(clientIf, queue.pop(), filterIndex);
+ configureFilterParamter(clientIf, client, featureSelection, filterIndex);
waitForCallback();
+ clientFilterIndices.add(filterIndex);
}
- resetCountDownLatch();
- configureFilterParamter(clientIf, client, featureSelection, filterIndex);
- waitForCallback();
- clientFilterIndices.add(filterIndex);
}
mClientFilterIndexMap.put(clientIf, clientFilterIndices);
}
@@ -807,14 +812,16 @@ public class ScanManager {
}
private void initFilterIndexStack() {
- int maxFiltersSupported =
- AdapterService.getAdapterService().getNumOfOffloadedScanFilterSupported();
- // Start from index 3 as:
- // index 0 is reserved for ALL_PASS filter in Settings app.
- // index 1 is reserved for ALL_PASS filter for regular scan apps.
- // index 2 is reserved for ALL_PASS filter for batch scan apps.
- for (int i = 3; i < maxFiltersSupported; ++i) {
- mFilterIndexStack.add(i);
+ AdapterService adapterService;
+ if (null != (adapterService = AdapterService.getAdapterService())) {
+ int maxFiltersSupported = adapterService.getNumOfOffloadedScanFilterSupported();
+ // Start from index 3 as:
+ // index 0 is reserved for ALL_PASS filter in Settings app.
+ // index 1 is reserved for ALL_PASS filter for regular scan apps.
+ // index 2 is reserved for ALL_PASS filter for batch scan apps.
+ for (int i = 3; i < maxFiltersSupported; ++i) {
+ mFilterIndexStack.add(i);
+ }
}
}