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

Commit 18999c2c authored by Wei Wang's avatar Wei Wang
Browse files

Add a default impelementation of IBluetoothGattCallback(2/2).

b/16636127 Explicitly use UTF-8 for ScanRecord's local name

Change-Id: Ib152239cdee0becf3f49f1b610dfe1c2296c3647
parent 7dca73a9
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -137,12 +137,24 @@ class AdvertiseManager {
    // Post callback status to app process.
    private void postCallback(int clientIf, int status) {
        try {
            mService.onMultipleAdvertiseCallback(clientIf, status);
            AdvertiseClient client = getAdvertiseClient(clientIf);
            AdvertiseSettings settings = (client == null) ? null : client.settings;
            boolean isStart = true;
            mService.onMultipleAdvertiseCallback(clientIf, status, isStart, settings);
        } catch (RemoteException e) {
            loge("failed onMultipleAdvertiseCallback", e);
        }
    }

    private AdvertiseClient getAdvertiseClient(int clientIf) {
        for (AdvertiseClient client : mAdvertiseClients) {
            if (client.clientIf == clientIf) {
                return client;
            }
        }
        return null;
    }

    // Handler class that handles BLE advertising operations.
    private class ClientHandler extends Handler {

@@ -181,7 +193,6 @@ class AdvertiseManager {
                        AdvertiseCallback.ADVERTISE_FAILED_TOO_MANY_ADVERTISERS);
                return;
            }
            // TODO: check if the advertise data length is larger than 31 bytes.
            if (!mAdvertiseNative.startAdverising(client)) {
                postCallback(clientIf, AdvertiseCallback.ADVERTISE_FAILED_INTERNAL_ERROR);
                return;
+8 −5
Original line number Diff line number Diff line
@@ -567,7 +567,7 @@ public class GattService extends ProfileService {
                            rssi, scanTimeNanos);
                    if (matchesFilters(client, result)) {
                        try {
                            app.callback.onScanResult(address, rssi, adv_data);
                            app.callback.onScanResult(result);
                        } catch (RemoteException e) {
                            Log.e(TAG, "Exception: " + e);
                            mClientMap.remove(client.clientIf);
@@ -1071,13 +1071,14 @@ public class GattService extends ProfileService {
    }

    // callback from AdvertiseManager for advertise status dispatch.
    void onMultipleAdvertiseCallback(int clientIf, int status) throws RemoteException {
    void onMultipleAdvertiseCallback(int clientIf, int status, boolean isStart,
            AdvertiseSettings settings) throws RemoteException {
        ClientMap.App app = mClientMap.getById(clientIf);
        if (app == null || app.callback == null) {
            Log.e(TAG, "Advertise app or callback is null");
            return;
        }
        app.callback.onMultiAdvertiseCallback(status);
        app.callback.onMultiAdvertiseCallback(status, isStart, settings);
    }

    void onConfigureMTU(int connId, int status, int mtu) throws RemoteException {
@@ -1130,11 +1131,13 @@ public class GattService extends ProfileService {
        ClientMap.App app = mClientMap.getById(clientIf);
        if (app != null) {
            Log.d(TAG, "Client app is not null!");
            boolean isStart = false;
            if (status == 0) {
                app.callback.onMultiAdvertiseCallback(AdvertiseCallback.ADVERTISE_SUCCESS);
                app.callback.onMultiAdvertiseCallback(AdvertiseCallback.ADVERTISE_SUCCESS,
                        isStart, null);
            } else {
                app.callback.onMultiAdvertiseCallback(
                        AdvertiseCallback.ADVERTISE_FAILED_INTERNAL_ERROR);
                        AdvertiseCallback.ADVERTISE_FAILED_INTERNAL_ERROR, isStart, null);
            }
        }
    }