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

Commit c8775899 authored by jackqdyulei's avatar jackqdyulei
Browse files

Create class BluetoothBroadcastReceiver

Then we could reuse it for normal intent and profile intent.

Bug: 111803044
Test: Build
Change-Id: Id85e0f6803b1d8897f2e573f1c71e8f98b28f747
parent f4663919
Loading
Loading
Loading
Loading
+32 −48
Original line number Diff line number Diff line
@@ -49,15 +49,15 @@ public class BluetoothEventManager {

    private final LocalBluetoothAdapter mLocalAdapter;
    private final CachedBluetoothDeviceManager mDeviceManager;
    private LocalBluetoothProfileManager mProfileManager;
    private final IntentFilter mAdapterIntentFilter, mProfileIntentFilter;
    private final Map<String, Handler> mHandlerMap;
    private Context mContext;

    private final Collection<BluetoothCallback> mCallbacks =
            new ArrayList<BluetoothCallback>();
    private final BroadcastReceiver mBroadcastReceiver = new BluetoothBroadcastReceiver();
    private final BroadcastReceiver mProfileBroadcastReceiver = new BluetoothBroadcastReceiver();
    private final Collection<BluetoothCallback> mCallbacks = new ArrayList<>();

    private LocalBluetoothProfileManager mProfileManager;
    private android.os.Handler mReceiverHandler;
    private Context mContext;

    interface Handler {
        void onReceive(Context context, Intent intent, BluetoothDevice device);
@@ -110,10 +110,8 @@ public class BluetoothEventManager {
        addHandler(BluetoothDevice.ACTION_BATTERY_LEVEL_CHANGED, new BatteryLevelChangedHandler());

        // Active device broadcasts
        addHandler(BluetoothA2dp.ACTION_ACTIVE_DEVICE_CHANGED,
                   new ActiveDeviceChangedHandler());
        addHandler(BluetoothHeadset.ACTION_ACTIVE_DEVICE_CHANGED,
                   new ActiveDeviceChangedHandler());
        addHandler(BluetoothA2dp.ACTION_ACTIVE_DEVICE_CHANGED, new ActiveDeviceChangedHandler());
        addHandler(BluetoothHeadset.ACTION_ACTIVE_DEVICE_CHANGED, new ActiveDeviceChangedHandler());
        addHandler(BluetoothHearingAid.ACTION_ACTIVE_DEVICE_CHANGED,
                new ActiveDeviceChangedHandler());

@@ -153,7 +151,7 @@ public class BluetoothEventManager {
        }
    }

    private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
    private class BluetoothBroadcastReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
@@ -165,21 +163,7 @@ public class BluetoothEventManager {
                handler.onReceive(context, intent, device);
            }
        }
    };

    private final BroadcastReceiver mProfileBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            BluetoothDevice device = intent
                    .getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

            Handler handler = mHandlerMap.get(action);
            if (handler != null) {
                handler.onReceive(context, intent, device);
            }
    }
    };

    private class AdapterStateChangedHandler implements Handler {
        public void onReceive(Context context, Intent intent,