Loading src/com/android/bluetooth/gatt/AdvertiseManager.java +10 −6 Original line number Diff line number Diff line Loading @@ -229,13 +229,17 @@ class AdvertiseManager { // Returns maximum advertise instances supported by controller. private int maxAdvertiseInstances() { AdapterService adapter = AdapterService.getAdapterService(); int numOfAdvtInstances = adapter.getNumOfAdvertisementInstancesSupported(); 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; } } // Class that wraps advertise native related constants, methods etc. Loading src/com/android/bluetooth/gatt/GattService.java +55 −15 Original line number Diff line number Diff line Loading @@ -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; } Loading @@ -1732,11 +1736,15 @@ 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.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; } Loading Loading @@ -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; } Loading @@ -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; } Loading Loading @@ -1893,8 +1909,12 @@ public class GattService extends ProfileService { if (DBG) Log.d(TAG, "beginServiceDeclaration() - uuid=" + srvcUuid + " serverIf=" + serverIf); ServiceDeclaration serviceDeclaration = addToActiveDeclaration(serverIf); 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, Loading @@ -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, Loading @@ -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) { Loading Loading @@ -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); Integer connId; if(null != (connId = mServerMap.connIdByAddress(serverIf, address))) { gattServerSendResponseNative(serverIf, connId, requestId, (byte)status, handle, offset, value, (byte)0); } mHandleMap.deleteRequest(requestId); } Loading @@ -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 { Loading Loading @@ -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=" Loading @@ -2075,11 +2113,13 @@ public class GattService extends ProfileService { if (entry.advertisePreferred) { mAdvertisingServiceUuids.add(entry.uuid); } 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: Loading src/com/android/bluetooth/gatt/ScanManager.java +31 −24 Original line number Diff line number Diff line Loading @@ -361,8 +361,8 @@ public class ScanManager { @Override public void onReceive(Context context, Intent intent) { Log.d(TAG, "awakened up at time " + SystemClock.elapsedRealtime()); String action = intent.getAction(); String action; if (null != (action = intent.getAction())) { if (action.equals(ACTION_REFRESH_BATCHED_SCAN)) { if (mBatchClients.isEmpty()) { return; Loading @@ -371,6 +371,7 @@ public class ScanManager { flushBatchScanResults(mBatchClients.iterator().next()); } } } }; mService.registerReceiver(mBatchAlarmReceiver, filter); mBatchAlarmReceiverRegistered = true; Loading Loading @@ -659,11 +660,14 @@ public class ScanManager { waitForCallback(); } else { Deque<Integer> clientFilterIndices = new ArrayDeque<Integer>(); int featureSelection; int filterIndex; for (ScanFilter filter : client.filters) { ScanFilterQueue queue = new ScanFilterQueue(); if (null != queue) { queue.addScanFilter(filter); int featureSelection = queue.getFeatureSelection(); int filterIndex = mFilterIndexStack.pop(); featureSelection = queue.getFeatureSelection(); filterIndex = mFilterIndexStack.pop(); while (!queue.isEmpty()) { resetCountDownLatch(); addFilterToController(clientIf, queue.pop(), filterIndex); Loading @@ -674,6 +678,7 @@ public class ScanManager { waitForCallback(); clientFilterIndices.add(filterIndex); } } mClientFilterIndexMap.put(clientIf, clientFilterIndices); } } Loading Loading @@ -807,8 +812,9 @@ public class ScanManager { } private void initFilterIndexStack() { int maxFiltersSupported = AdapterService.getAdapterService().getNumOfOffloadedScanFilterSupported(); 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. Loading @@ -817,6 +823,7 @@ public class ScanManager { mFilterIndexStack.add(i); } } } // Configure filter parameters. private void configureFilterParamter(int clientIf, ScanClient client, int featureSelection, Loading Loading
src/com/android/bluetooth/gatt/AdvertiseManager.java +10 −6 Original line number Diff line number Diff line Loading @@ -229,13 +229,17 @@ class AdvertiseManager { // Returns maximum advertise instances supported by controller. private int maxAdvertiseInstances() { AdapterService adapter = AdapterService.getAdapterService(); int numOfAdvtInstances = adapter.getNumOfAdvertisementInstancesSupported(); 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; } } // Class that wraps advertise native related constants, methods etc. Loading
src/com/android/bluetooth/gatt/GattService.java +55 −15 Original line number Diff line number Diff line Loading @@ -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; } Loading @@ -1732,11 +1736,15 @@ 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.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; } Loading Loading @@ -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; } Loading @@ -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; } Loading Loading @@ -1893,8 +1909,12 @@ public class GattService extends ProfileService { if (DBG) Log.d(TAG, "beginServiceDeclaration() - uuid=" + srvcUuid + " serverIf=" + serverIf); ServiceDeclaration serviceDeclaration = addToActiveDeclaration(serverIf); 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, Loading @@ -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, Loading @@ -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) { Loading Loading @@ -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); Integer connId; if(null != (connId = mServerMap.connIdByAddress(serverIf, address))) { gattServerSendResponseNative(serverIf, connId, requestId, (byte)status, handle, offset, value, (byte)0); } mHandleMap.deleteRequest(requestId); } Loading @@ -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 { Loading Loading @@ -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=" Loading @@ -2075,11 +2113,13 @@ public class GattService extends ProfileService { if (entry.advertisePreferred) { mAdvertisingServiceUuids.add(entry.uuid); } 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: Loading
src/com/android/bluetooth/gatt/ScanManager.java +31 −24 Original line number Diff line number Diff line Loading @@ -361,8 +361,8 @@ public class ScanManager { @Override public void onReceive(Context context, Intent intent) { Log.d(TAG, "awakened up at time " + SystemClock.elapsedRealtime()); String action = intent.getAction(); String action; if (null != (action = intent.getAction())) { if (action.equals(ACTION_REFRESH_BATCHED_SCAN)) { if (mBatchClients.isEmpty()) { return; Loading @@ -371,6 +371,7 @@ public class ScanManager { flushBatchScanResults(mBatchClients.iterator().next()); } } } }; mService.registerReceiver(mBatchAlarmReceiver, filter); mBatchAlarmReceiverRegistered = true; Loading Loading @@ -659,11 +660,14 @@ public class ScanManager { waitForCallback(); } else { Deque<Integer> clientFilterIndices = new ArrayDeque<Integer>(); int featureSelection; int filterIndex; for (ScanFilter filter : client.filters) { ScanFilterQueue queue = new ScanFilterQueue(); if (null != queue) { queue.addScanFilter(filter); int featureSelection = queue.getFeatureSelection(); int filterIndex = mFilterIndexStack.pop(); featureSelection = queue.getFeatureSelection(); filterIndex = mFilterIndexStack.pop(); while (!queue.isEmpty()) { resetCountDownLatch(); addFilterToController(clientIf, queue.pop(), filterIndex); Loading @@ -674,6 +678,7 @@ public class ScanManager { waitForCallback(); clientFilterIndices.add(filterIndex); } } mClientFilterIndexMap.put(clientIf, clientFilterIndices); } } Loading Loading @@ -807,8 +812,9 @@ public class ScanManager { } private void initFilterIndexStack() { int maxFiltersSupported = AdapterService.getAdapterService().getNumOfOffloadedScanFilterSupported(); 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. Loading @@ -817,6 +823,7 @@ public class ScanManager { mFilterIndexStack.add(i); } } } // Configure filter parameters. private void configureFilterParamter(int clientIf, ScanClient client, int featureSelection, Loading