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

Commit 93ab2e38 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Fire off BluetoothConnectionCallback when we fire off the broadcasts...

Merge "Fire off BluetoothConnectionCallback when we fire off the broadcasts for ACL connections and disconnections." am: 17fc798f am: 26b41c8c

Original change: https://android-review.googlesource.com/c/platform/packages/apps/Bluetooth/+/1478638

Change-Id: I4f2dcc6bf903001c116bc1646bf5dd84bc5c3f96
parents 2fb6296d 26b41c8c
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import android.bluetooth.BluetoothProtoEnums;
import android.bluetooth.BluetoothUuid;
import android.bluetooth.IBluetooth;
import android.bluetooth.IBluetoothCallback;
import android.bluetooth.IBluetoothConnectionCallback;
import android.bluetooth.IBluetoothMetadataListener;
import android.bluetooth.IBluetoothSocketManager;
import android.bluetooth.OobData;
@@ -113,7 +114,9 @@ import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class AdapterService extends Service {
    private static final String TAG = "BluetoothAdapterService";
@@ -206,6 +209,7 @@ public class AdapterService extends Service {
    private final HashMap<BluetoothDevice, ArrayList<IBluetoothMetadataListener>>
            mMetadataListeners = new HashMap<>();
    private final HashMap<String, Integer> mProfileServicesState = new HashMap<String, Integer>();
    private Set<IBluetoothConnectionCallback> mBluetoothConnectionCallbacks = new HashSet<>();
    //Only BluetoothManagerService should be registered
    private RemoteCallbackList<IBluetoothCallback> mCallbacks;
    private int mCurrentRequestId;
@@ -1928,6 +1932,30 @@ public class AdapterService extends Service {
            return service.factoryResetNative();
        }

        @Override
        public boolean registerBluetoothConnectionCallback(IBluetoothConnectionCallback callback) {
            AdapterService service = getService();
            if (service == null || !callerIsSystemOrActiveUser(TAG,
                    "registerBluetoothConnectionCallback")) {
                return false;
            }
            enforceBluetoothPrivilegedPermission(service);
            service.mBluetoothConnectionCallbacks.add(callback);
            return true;
        }

        @Override
        public boolean unregisterBluetoothConnectionCallback(
                IBluetoothConnectionCallback callback) {
            AdapterService service = getService();
            if (service == null || !callerIsSystemOrActiveUser(TAG,
                    "unregisterBluetoothConnectionCallback")) {
                return false;
            }
            enforceBluetoothPrivilegedPermission(service);
            return service.mBluetoothConnectionCallbacks.remove(callback);
        }

        @Override
        public void registerCallback(IBluetoothCallback callback) {
            AdapterService service = getService();
@@ -2629,6 +2657,10 @@ public class AdapterService extends Service {
        return deviceProp.getUuids();
    }

    public Set<IBluetoothConnectionCallback> getBluetoothConnectionCallbacks() {
        return mBluetoothConnectionCallbacks;
    }

    void logUserBondResponse(BluetoothDevice device, boolean accepted, int event) {
        BluetoothStatsLog.write(BluetoothStatsLog.BLUETOOTH_BOND_STATE_CHANGED,
                obfuscateAddress(device), 0, device.getType(),
+18 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.IBluetoothConnectionCallback;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -30,6 +31,7 @@ import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.ParcelUuid;
import android.os.RemoteException;
import android.util.Log;

import com.android.bluetooth.BluetoothStatsLog;
@@ -666,6 +668,22 @@ final class RemoteDevices {
                    | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
            intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
            sAdapterService.sendBroadcast(intent, sAdapterService.BLUETOOTH_PERM);

            synchronized (sAdapterService.getBluetoothConnectionCallbacks()) {
                Set<IBluetoothConnectionCallback> bluetoothConnectionCallbacks =
                        sAdapterService.getBluetoothConnectionCallbacks();
                for (IBluetoothConnectionCallback callback : bluetoothConnectionCallbacks) {
                    try {
                        if (connectionState == BluetoothAdapter.STATE_CONNECTED) {
                            callback.onDeviceConnected(device);
                        } else {
                            callback.onDeviceDisconnected(device);
                        }
                    } catch (RemoteException ex) {
                        Log.e(TAG, "RemoteException in calling IBluetoothConnectionCallback");
                    }
                }
            }
        } else {
            Log.e(TAG, "aclStateChangeCallback intent is null. deviceBondState: "
                    + device.getBondState());