Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 67242681 authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Andre Eisenbach
Browse files

Separate LE scanner from GATT client (1/4)

Right now, LE scanning functionality is combined with the GATT client.
This is the source of various bugs, like scans suddenly stoppinging when
a GATT client is killed. It also increases memory consumption, because
we associate many structures with a GATT client, which are not necessary
when just scanning.

Test: sl4a BleScanApiTest ConcurrentBleScanTest
Change-Id: I0c25bd4a58bb430eb0ee4100d5f2bbab194f9621
parent 4d3a3d81
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -136,7 +136,7 @@ public final class BluetoothGatt implements BluetoothProfile {
     * Bluetooth GATT callbacks. Overrides the default BluetoothGattCallback implementation.
     */
    private final IBluetoothGattCallback mBluetoothGattCallback =
        new BluetoothGattCallbackWrapper() {
        new IBluetoothGattCallback.Stub() {
            /**
             * Application interface registered - app is ready to go
             * @hide
+0 −96
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.bluetooth;

import android.bluetooth.le.AdvertiseSettings;
import android.bluetooth.le.ScanResult;
import android.bluetooth.BluetoothGattService;
import android.os.ParcelUuid;
import android.os.RemoteException;

import java.util.List;

/**
 * Wrapper class for default implementation of IBluetoothGattCallback.
 *
 * @hide
 */
public class BluetoothGattCallbackWrapper extends IBluetoothGattCallback.Stub {

    @Override
    public void onClientRegistered(int status, int clientIf) throws RemoteException {
    }

    @Override
    public void onClientConnectionState(int status, int clientIf, boolean connected, String address)
            throws RemoteException {
    }

    @Override
    public void onScanResult(ScanResult scanResult) throws RemoteException {
    }

    @Override
    public void onBatchScanResults(List<ScanResult> batchResults) throws RemoteException {
    }

    @Override
    public void onSearchComplete(String address, List<BluetoothGattService> services,
            int status) throws RemoteException {
    }

    @Override
    public void onCharacteristicRead(String address, int status, int handle, byte[] value)
            throws RemoteException {
    }

    @Override
    public void onCharacteristicWrite(String address, int status, int handle) throws RemoteException {
    }

    @Override
    public void onExecuteWrite(String address, int status) throws RemoteException {
    }

    @Override
    public void onDescriptorRead(String address, int status, int handle, byte[] value) throws RemoteException {
    }

    @Override
    public void onDescriptorWrite(String address, int status, int handle) throws RemoteException {
    }

    @Override
    public void onNotify(String address, int handle, byte[] value) throws RemoteException {
    }

    @Override
    public void onReadRemoteRssi(String address, int rssi, int status) throws RemoteException {
    }

    @Override
    public void onConfigureMTU(String address, int mtu, int status) throws RemoteException {
    }

    @Override
    public void onFoundOrLost(boolean onFound, ScanResult scanResult) throws RemoteException {
    }

    @Override
    public void onScanManagerErrorCallback(int errorCode) throws RemoteException {
    }
}
+7 −5
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.os.WorkSource;
import android.bluetooth.IBluetoothGattCallback;
import android.bluetooth.IBluetoothGattServerCallback;
import android.bluetooth.le.IAdvertiserCallback;
import android.bluetooth.le.IScannerCallback;

/**
 * API for interacting with BLE / GATT
@@ -37,11 +38,12 @@ import android.bluetooth.le.IAdvertiserCallback;
interface IBluetoothGatt {
    List<BluetoothDevice> getDevicesMatchingConnectionStates(in int[] states);

    void startScan(in int appIf, in boolean isServer, in ScanSettings settings,
                   in List<ScanFilter> filters, in WorkSource workSource, in List scanStorages,
                   in String callingPackage);
    void stopScan(in int appIf, in boolean isServer);
    void flushPendingBatchResults(in int appIf, in boolean isServer);
    void registerScanner(in IScannerCallback callback);
    void unregisterScanner(in int scannerId);
    void startScan(in int scannerId, in ScanSettings settings, in List<ScanFilter> filters,
                   in WorkSource workSource, in List scanStorages, in String callingPackage);
    void stopScan(in int scannerId);
    void flushPendingBatchResults(in int scannerId);

    void registerAdvertiser(in IAdvertiserCallback callback);
    void unregisterAdvertiser(in int advertiserId);
+0 −6
Original line number Diff line number Diff line
@@ -17,8 +17,6 @@ package android.bluetooth;

import android.os.ParcelUuid;
import android.bluetooth.BluetoothGattService;
import android.bluetooth.le.AdvertiseSettings;
import android.bluetooth.le.ScanResult;

/**
 * Callback definitions for interacting with BLE / GATT
@@ -28,8 +26,6 @@ oneway interface IBluetoothGattCallback {
    void onClientRegistered(in int status, in int clientIf);
    void onClientConnectionState(in int status, in int clientIf,
                                 in boolean connected, in String address);
    void onScanResult(in ScanResult scanResult);
    void onBatchScanResults(in List<ScanResult> batchResults);
    void onSearchComplete(in String address, in List<BluetoothGattService> services, in int status);
    void onCharacteristicRead(in String address, in int status, in int handle, in byte[] value);
    void onCharacteristicWrite(in String address, in int status, in int handle);
@@ -38,7 +34,5 @@ oneway interface IBluetoothGattCallback {
    void onDescriptorWrite(in String address, in int status, in int handle);
    void onNotify(in String address, in int handle, in byte[] value);
    void onReadRemoteRssi(in String address, in int rssi, in int status);
    void onScanManagerErrorCallback(in int errorCode);
    void onConfigureMTU(in String address, in int mtu, in int status);
    void onFoundOrLost(in boolean onFound, in ScanResult scanResult);
}
+0 −1
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import android.bluetooth.BluetoothGattService;
 */
oneway interface IBluetoothGattServerCallback {
    void onServerRegistered(in int status, in int serverIf);
    void onScanResult(in String address, in int rssi, in byte[] advData);
    void onServerConnectionState(in int status, in int serverIf,
                                 in boolean connected, in String address);
    void onServiceAdded(in int status, in BluetoothGattService service);
Loading