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

Commit 9efb1343 authored by Jaikumar Ganesh's avatar Jaikumar Ganesh
Browse files

Fix ANR in Settings and Phone app.

When we have a lot of devices paired and try to enable bluetooth,
loadBondState will take a some time. During this all UUIDs would
have been registered and we would send out the Bluetooth On intent.
When Settings apps or phone app gets the Bluetooth On intent, they
try to initialize state. However, the enable Thread in Bluetooth Service
is still initializing internal state in loadBondState leading to
ANRs and deadlocks. So register SDP records as the last step of enable Thread.

Change-Id: Iaa0a773e31b9d269f4c56c4f975a0e2973e02d6e
parent 30b8cbe0
Loading
Loading
Loading
Loading
+19 −10
Original line number Diff line number Diff line
@@ -561,21 +561,16 @@ public class BluetoothService extends IBluetooth.Stub {
                    persistBluetoothOnSetting(true);
                }

                updateSdpRecords();

                mIsDiscovering = false;
                mBondState.readAutoPairingData();
                mBondState.loadBondState();
                initProfileState();

                // Log bluetooth on to battery stats.
                long ident = Binder.clearCallingIdentity();
                try {
                    mBatteryStats.noteBluetoothOn();
                } catch (RemoteException e) {
                } finally {
                    Binder.restoreCallingIdentity(ident);
                }
                // This should be the last step of the the enable thread.
                // Because this adds SDP records which asynchronously
                // broadcasts the Bluetooth On State in updateBluetoothState.
                // So we want all internal state setup before this.
                updateSdpRecords();
            } else {
                setBluetoothState(BluetoothAdapter.STATE_OFF);
            }
@@ -623,6 +618,11 @@ public class BluetoothService extends IBluetooth.Stub {
        }
    }

    /**
     * This function is called from Bluetooth Event Loop when onPropertyChanged
     * for adapter comes in with UUID property.
     * @param uuidsThe uuids of adapter as reported by Bluez.
     */
    synchronized void updateBluetoothState(String uuids) {
        if (mBluetoothState == BluetoothAdapter.STATE_TURNING_ON) {
            ParcelUuid[] adapterUuids = convertStringToParcelUuid(uuids);
@@ -633,6 +633,15 @@ public class BluetoothService extends IBluetooth.Stub {
                String[] propVal = {"Pairable", getProperty("Pairable")};
                mEventLoop.onPropertyChanged(propVal);

                // Log bluetooth on to battery stats.
                long ident = Binder.clearCallingIdentity();
                try {
                    mBatteryStats.noteBluetoothOn();
                } catch (RemoteException e) {
                } finally {
                    Binder.restoreCallingIdentity(ident);
                }

                if (mIsAirplaneSensitive && isAirplaneModeOn() && !mIsAirplaneToggleable) {
                    disable(false);
                }