Search in sources :

Example 81 with ParcelUuid

use of android.os.ParcelUuid in project android_frameworks_base by ParanoidAndroid.

the class BluetoothGattServer method removeService.

/**
     * Removes a service from the list of services to be provided.
     *
     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
     *
     * @param service Service to be removed.
     * @return true, if the service has been removed
     */
public boolean removeService(BluetoothGattService service) {
    if (DBG)
        Log.d(TAG, "removeService() - service: " + service.getUuid());
    if (mService == null || mServerIf == 0)
        return false;
    BluetoothGattService intService = getService(service.getUuid(), service.getInstanceId(), service.getType());
    if (intService == null)
        return false;
    try {
        mService.removeService(mServerIf, service.getType(), service.getInstanceId(), new ParcelUuid(service.getUuid()));
        mServices.remove(intService);
    } catch (RemoteException e) {
        Log.e(TAG, "", e);
        return false;
    }
    return true;
}
Also used : ParcelUuid(android.os.ParcelUuid) RemoteException(android.os.RemoteException)

Example 82 with ParcelUuid

use of android.os.ParcelUuid in project platform_frameworks_base by android.

the class BluetoothAdapter method startLeScan.

/**
     * Starts a scan for Bluetooth LE devices, looking for devices that
     * advertise given services.
     *
     * <p>Devices which advertise all specified services are reported using the
     * {@link LeScanCallback#onLeScan} callback.
     *
     * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} permission.
     *
     * @param serviceUuids Array of services to look for
     * @param callback the callback LE scan results are delivered
     * @return true, if the scan was started successfully
     * @deprecated use {@link BluetoothLeScanner#startScan(List, ScanSettings, ScanCallback)}
     *             instead.
     */
@Deprecated
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
public boolean startLeScan(final UUID[] serviceUuids, final LeScanCallback callback) {
    if (DBG)
        Log.d(TAG, "startLeScan(): " + Arrays.toString(serviceUuids));
    if (callback == null) {
        if (DBG)
            Log.e(TAG, "startLeScan: null callback");
        return false;
    }
    BluetoothLeScanner scanner = getBluetoothLeScanner();
    if (scanner == null) {
        if (DBG)
            Log.e(TAG, "startLeScan: cannot get BluetoothLeScanner");
        return false;
    }
    synchronized (mLeScanClients) {
        if (mLeScanClients.containsKey(callback)) {
            if (DBG)
                Log.e(TAG, "LE Scan has already started");
            return false;
        }
        try {
            IBluetoothGatt iGatt = mManagerService.getBluetoothGatt();
            if (iGatt == null) {
                // BLE is not supported
                return false;
            }
            ScanCallback scanCallback = new ScanCallback() {

                @Override
                public void onScanResult(int callbackType, ScanResult result) {
                    if (callbackType != ScanSettings.CALLBACK_TYPE_ALL_MATCHES) {
                        // Should not happen.
                        Log.e(TAG, "LE Scan has already started");
                        return;
                    }
                    ScanRecord scanRecord = result.getScanRecord();
                    if (scanRecord == null) {
                        return;
                    }
                    if (serviceUuids != null) {
                        List<ParcelUuid> uuids = new ArrayList<ParcelUuid>();
                        for (UUID uuid : serviceUuids) {
                            uuids.add(new ParcelUuid(uuid));
                        }
                        List<ParcelUuid> scanServiceUuids = scanRecord.getServiceUuids();
                        if (scanServiceUuids == null || !scanServiceUuids.containsAll(uuids)) {
                            if (DBG)
                                Log.d(TAG, "uuids does not match");
                            return;
                        }
                    }
                    callback.onLeScan(result.getDevice(), result.getRssi(), scanRecord.getBytes());
                }
            };
            ScanSettings settings = new ScanSettings.Builder().setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES).setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build();
            List<ScanFilter> filters = new ArrayList<ScanFilter>();
            if (serviceUuids != null && serviceUuids.length > 0) {
                // Note scan filter does not support matching an UUID array so we put one
                // UUID to hardware and match the whole array in callback.
                ScanFilter filter = new ScanFilter.Builder().setServiceUuid(new ParcelUuid(serviceUuids[0])).build();
                filters.add(filter);
            }
            scanner.startScan(filters, settings, scanCallback);
            mLeScanClients.put(callback, scanCallback);
            return true;
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        }
    }
    return false;
}
Also used : ParcelUuid(android.os.ParcelUuid) BluetoothLeScanner(android.bluetooth.le.BluetoothLeScanner) ScanResult(android.bluetooth.le.ScanResult) ScanSettings(android.bluetooth.le.ScanSettings) ScanFilter(android.bluetooth.le.ScanFilter) ArrayList(java.util.ArrayList) ScanCallback(android.bluetooth.le.ScanCallback) UUID(java.util.UUID) RemoteException(android.os.RemoteException) ScanRecord(android.bluetooth.le.ScanRecord) RequiresPermission(android.annotation.RequiresPermission)

Example 83 with ParcelUuid

use of android.os.ParcelUuid in project platform_frameworks_base by android.

the class BluetoothGatt method registerApp.

/**
     * Register an application callback to start using GATT.
     *
     * <p>This is an asynchronous call. The callback {@link BluetoothGattCallbackExt#onAppRegistered}
     * is used to notify success or failure if the function returns true.
     *
     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
     *
     * @param callback GATT callback handler that will receive asynchronous callbacks.
     * @return If true, the callback will be called to notify success or failure,
     *         false on immediate error
     */
private boolean registerApp(BluetoothGattCallbackExt callback) {
    if (DBG)
        Log.d(TAG, "registerApp()");
    if (mService == null)
        return false;
    mCallback = callback;
    UUID uuid = UUID.randomUUID();
    if (DBG)
        Log.d(TAG, "registerApp() - UUID=" + uuid);
    try {
        mService.registerClient(new ParcelUuid(uuid), mBluetoothGattCallbackExt);
    } catch (RemoteException e) {
        Log.e(TAG, "", e);
        return false;
    }
    return true;
}
Also used : ParcelUuid(android.os.ParcelUuid) UUID(java.util.UUID) RemoteException(android.os.RemoteException)

Example 84 with ParcelUuid

use of android.os.ParcelUuid in project platform_frameworks_base by android.

the class BluetoothLeAdvertiser method totalBytes.

// Compute the size of advertisement data or scan resp
private int totalBytes(AdvertiseData data, boolean isFlagsIncluded) {
    if (data == null)
        return 0;
    // Flags field is omitted if the advertising is not connectable.
    int size = (isFlagsIncluded) ? FLAGS_FIELD_BYTES : 0;
    if (data.getServiceUuids() != null) {
        int num16BitUuids = 0;
        int num32BitUuids = 0;
        int num128BitUuids = 0;
        for (ParcelUuid uuid : data.getServiceUuids()) {
            if (BluetoothUuid.is16BitUuid(uuid)) {
                ++num16BitUuids;
            } else if (BluetoothUuid.is32BitUuid(uuid)) {
                ++num32BitUuids;
            } else {
                ++num128BitUuids;
            }
        }
        // 16 bit service uuids are grouped into one field when doing advertising.
        if (num16BitUuids != 0) {
            size += OVERHEAD_BYTES_PER_FIELD + num16BitUuids * BluetoothUuid.UUID_BYTES_16_BIT;
        }
        // 32 bit service uuids are grouped into one field when doing advertising.
        if (num32BitUuids != 0) {
            size += OVERHEAD_BYTES_PER_FIELD + num32BitUuids * BluetoothUuid.UUID_BYTES_32_BIT;
        }
        // 128 bit service uuids are grouped into one field when doing advertising.
        if (num128BitUuids != 0) {
            size += OVERHEAD_BYTES_PER_FIELD + num128BitUuids * BluetoothUuid.UUID_BYTES_128_BIT;
        }
    }
    for (ParcelUuid uuid : data.getServiceData().keySet()) {
        size += OVERHEAD_BYTES_PER_FIELD + SERVICE_DATA_UUID_LENGTH + byteLength(data.getServiceData().get(uuid));
    }
    for (int i = 0; i < data.getManufacturerSpecificData().size(); ++i) {
        size += OVERHEAD_BYTES_PER_FIELD + MANUFACTURER_SPECIFIC_DATA_LENGTH + byteLength(data.getManufacturerSpecificData().valueAt(i));
    }
    if (data.getIncludeTxPowerLevel()) {
        // tx power level value is one byte.
        size += OVERHEAD_BYTES_PER_FIELD + 1;
    }
    if (data.getIncludeDeviceName() && mBluetoothAdapter.getName() != null) {
        size += OVERHEAD_BYTES_PER_FIELD + mBluetoothAdapter.getName().length();
    }
    return size;
}
Also used : ParcelUuid(android.os.ParcelUuid)

Example 85 with ParcelUuid

use of android.os.ParcelUuid in project platform_frameworks_base by android.

the class BluetoothGattIncludedService method writeToParcel.

public void writeToParcel(Parcel out, int flags) {
    out.writeParcelable(new ParcelUuid(mUuid), 0);
    out.writeInt(mInstanceId);
    out.writeInt(mServiceType);
}
Also used : ParcelUuid(android.os.ParcelUuid)

Aggregations

ParcelUuid (android.os.ParcelUuid)147 SmallTest (android.test.suitebuilder.annotation.SmallTest)43 RemoteException (android.os.RemoteException)29 UUID (java.util.UUID)24 ArrayList (java.util.ArrayList)23 GenericSoundModel (android.hardware.soundtrigger.SoundTrigger.GenericSoundModel)20 Parcel (android.os.Parcel)20 ScanFilter (android.bluetooth.le.ScanFilter)19 RecognitionConfig (android.hardware.soundtrigger.SoundTrigger.RecognitionConfig)12 LargeTest (android.test.suitebuilder.annotation.LargeTest)12 ScanRecord (android.bluetooth.le.ScanRecord)10 BluetoothDevice (android.bluetooth.BluetoothDevice)9 Socket (java.net.Socket)9 DataOutputStream (java.io.DataOutputStream)8 ByteBuffer (java.nio.ByteBuffer)8 SparseArray (android.util.SparseArray)6 RequiresPermission (android.annotation.RequiresPermission)5 BluetoothClass (android.bluetooth.BluetoothClass)5 BluetoothLeScanner (android.bluetooth.le.BluetoothLeScanner)5 ScanCallback (android.bluetooth.le.ScanCallback)5