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

Commit 723ee54c authored by Stanley Tng's avatar Stanley Tng Committed by Andre Eisenbach
Browse files

Allow the Bluetooth MAC address to be updated asynchronously (2/3)

There are intermittent issues where either the returned Bluetooth
MAC address to Java framework is uninitialized or this address update
arrives too late. This fix will do 2 things:
(1) Returns error when MAC address is unavailable in the native code.
(2) Updates the MAC address later by adding a new broadcast event.

Test: Check address for these cases: factory reset, system reboot, and
Bluetooth re-enable.
Bug: 36709382

Change-Id: I09720193e38fdf9139e1bb146f8e1847e2b65b1a
parent cb942394
Loading
Loading
Loading
Loading
+24 −0
Original line number Original line Diff line number Diff line
@@ -465,6 +465,30 @@ public final class BluetoothAdapter {
    public static final String ACTION_BLE_STATE_CHANGED =
    public static final String ACTION_BLE_STATE_CHANGED =
        "android.bluetooth.adapter.action.BLE_STATE_CHANGED";
        "android.bluetooth.adapter.action.BLE_STATE_CHANGED";


    /**
     * Intent used to broadcast the change in the Bluetooth address
     * of the local Bluetooth adapter.
     * <p>Always contains the extra field {@link
     * #EXTRA_BLUETOOTH_ADDRESS} containing the Bluetooth address.
     *
     * Note: only system level processes are allowed to send this
     * defined broadcast.
     *
     * @hide
     */
    public static final String ACTION_BLUETOOTH_ADDRESS_CHANGED =
        "android.bluetooth.adapter.action.BLUETOOTH_ADDRESS_CHANGED";

    /**
     * Used as a String extra field in {@link
     * #ACTION_BLUETOOTH_ADDRESS_CHANGED} intent to store the local
     * Bluetooth address.
     *
     * @hide
     */
    public static final String EXTRA_BLUETOOTH_ADDRESS =
          "android.bluetooth.adapter.extra.BLUETOOTH_ADDRESS";

    /**
    /**
     * Broadcast Action: The notifys Bluetooth ACL connected event. This will be
     * Broadcast Action: The notifys Bluetooth ACL connected event. This will be
     * by BLE Always on enabled application to know the ACL_CONNECTED event
     * by BLE Always on enabled application to know the ACL_CONNECTED event
+11 −0
Original line number Original line Diff line number Diff line
@@ -307,6 +307,14 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
                if (newName != null) {
                if (newName != null) {
                    storeNameAndAddress(newName, null);
                    storeNameAndAddress(newName, null);
                }
                }
            } else if (BluetoothAdapter.ACTION_BLUETOOTH_ADDRESS_CHANGED.equals(action)) {
                String newAddress = intent.getStringExtra(BluetoothAdapter.EXTRA_BLUETOOTH_ADDRESS);
                if (newAddress != null) {
                    if (DBG) Slog.d(TAG, "Bluetooth Adapter address changed to " + newAddress);
                    storeNameAndAddress(null, newAddress);
                } else {
                    if (DBG) Slog.e(TAG, "No Bluetooth Adapter address parameter found");
                }
            }
            }
        }
        }
    };
    };
@@ -343,6 +351,9 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
        IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_LOCAL_NAME_CHANGED);
        IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_LOCAL_NAME_CHANGED);
        filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
        filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
        mContext.registerReceiver(mReceiver, filter);
        mContext.registerReceiver(mReceiver, filter);
        filter = new IntentFilter(BluetoothAdapter.ACTION_BLUETOOTH_ADDRESS_CHANGED);
        filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
        mContext.registerReceiver(mReceiver, filter);
        loadStoredNameAndAddress();
        loadStoredNameAndAddress();
        if (isBluetoothPersistedStateOn()) {
        if (isBluetoothPersistedStateOn()) {
            if (DBG) Slog.d(TAG, "Startup: Bluetooth persisted state is ON.");
            if (DBG) Slog.d(TAG, "Startup: Bluetooth persisted state is ON.");