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

Commit 639631af authored by William Escande's avatar William Escande
Browse files

RemoteDevices: remove dead code

All final collection cannot be null, it serve no purpose to check them
init is an empty method that we remove

Bug: 323672160
Test: atest BluetoothInstrumentationTests
Change-Id: I3d09891e25cbd1d2e8416f3500ffc77e4f49ec3a
parent 38c7cb1f
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -652,7 +652,6 @@ public class AdapterService extends Service {
        }

        mRemoteDevices = new RemoteDevices(this, mLooper);
        mRemoteDevices.init();
        clearDiscoveringPackages();
        if (!Flags.fastBindToApp()) {
            mBinder = new AdapterServiceBinder(this);
@@ -1372,7 +1371,7 @@ public class AdapterService extends Service {
        }

        if (mRemoteDevices != null) {
            mRemoteDevices.cleanup();
            mRemoteDevices.reset();
        }

        if (mSdpManager != null) {
+38 −57
Original line number Diff line number Diff line
@@ -79,7 +79,7 @@ public class RemoteDevices {

    private final HashMap<String, DeviceProperties> mDevices;
    private final HashMap<String, String> mDualDevicesMap;
    private ArrayDeque<String> mDeviceQueue;
    private final ArrayDeque<String> mDeviceQueue;

    /**
     * Bluetooth HFP v1.8 specifies the Battery Charge indicator of AG can take values from
@@ -154,42 +154,26 @@ public class RemoteDevices {
    RemoteDevices(AdapterService service, Looper looper) {
        mAdapter = ((Context) service).getSystemService(BluetoothManager.class).getAdapter();
        mAdapterService = service;
        mSdpTracker = new ArrayList<BluetoothDevice>();
        mDevices = new HashMap<String, DeviceProperties>();
        mDualDevicesMap = new HashMap<String, String>();
        mSdpTracker = new ArrayList<>();
        mDevices = new HashMap<>();
        mDualDevicesMap = new HashMap<>();
        mDeviceQueue = new ArrayDeque<>();
        mHandler = new RemoteDevicesHandler(looper);
        mMainHandler = new Handler(Looper.getMainLooper());
    }

    /** Init should be called before using this RemoteDevices object */
    void init() {}

    /**
     * Clean up should be called when this object is no longer needed, must be called after init()
     */
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    void cleanup() {
        reset();
    }

    /**
     * Reset should be called when the state of this object needs to be cleared
     * RemoteDevices is still usable after reset
     */
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    void reset() {
        if (mSdpTracker != null) {
        mSdpTracker.clear();
        }

        // Unregister Handler and stop all queued messages.
        if (mMainHandler != null) {
        mMainHandler.removeCallbacksAndMessages(null);
        }

        synchronized (mDevices) {
            if (mDevices != null) {
            debugLog("reset(): Broadcasting ACL_DISCONNECTED");

            mDevices.forEach(
@@ -203,30 +187,27 @@ public class RemoteDevices {
                                        + bluetoothDevice.isConnected());

                        if (bluetoothDevice.isConnected()) {
                        int transport = deviceProperties.getConnectionHandle(
                                BluetoothDevice.TRANSPORT_BREDR) != BluetoothDevice.ERROR
                            int transport =
                                    deviceProperties.getConnectionHandle(
                                                            BluetoothDevice.TRANSPORT_BREDR)
                                                    != BluetoothDevice.ERROR
                                            ? BluetoothDevice.TRANSPORT_BREDR
                                            : BluetoothDevice.TRANSPORT_LE;
                            mAdapterService.notifyAclDisconnected(bluetoothDevice, transport);
                            Intent intent = new Intent(BluetoothDevice.ACTION_ACL_DISCONNECTED);
                            intent.putExtra(BluetoothDevice.EXTRA_DEVICE, bluetoothDevice);
                        intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
                            intent.addFlags(
                                    Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
                                            | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
                            mAdapterService.sendBroadcast(intent, BLUETOOTH_CONNECT);
                        }
                    });
            mDevices.clear();
        }
        }

        if (mDualDevicesMap != null) {
        mDualDevicesMap.clear();
        }

        if (mDeviceQueue != null) {
        mDeviceQueue.clear();
    }
    }

    @Override
    public Object clone() throws CloneNotSupportedException {
@@ -574,7 +555,7 @@ public class RemoteDevices {
        }

        /**
         * @param isBondingInitiatedLocally wether bonding is initiated locally
         * @param isBondingInitiatedLocally whether bonding is initiated locally
         */
        void setBondingInitiatedLocally(boolean isBondingInitiatedLocally) {
            synchronized (mObject) {