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

Commit 16fb9f65 authored by Jakub Pawlowski's avatar Jakub Pawlowski
Browse files

Improve BondStateMachine logging

Use strings instead of hard to guess numbers when displaying bond state
changes.

Bug: 67907612
Test: observe logs in console during bonding
Change-Id: I4223ba9267387f497be280d44f2f4b562a16218c
parent 84516ab2
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -140,7 +140,8 @@ final class BondStateMachine extends StateMachine {
                    /* if the link key was deleted by the stack */
                        sendIntent(dev, newState, 0);
                    } else {
                        Log.e(TAG, "In stable state, received invalid newState: " + newState);
                        Log.e(TAG, "In stable state, received invalid newState: "
                                + state2str(newState));
                    }
                    break;

@@ -348,8 +349,8 @@ final class BondStateMachine extends StateMachine {
            intent.putExtra(BluetoothDevice.EXTRA_REASON, reason);
        }
        mAdapterService.sendBroadcastAsUser(intent, UserHandle.ALL, AdapterService.BLUETOOTH_PERM);
        infoLog("Bond State Change Intent:" + device + " OldState: " + oldState + " NewState: "
                + newState);
        infoLog("Bond State Change Intent:" + device + " " + state2str(oldState) + " => "
                + state2str(newState));
    }

    void bondStateChangeCallback(int status, byte[] address, int newState) {
@@ -479,6 +480,16 @@ final class BondStateMachine extends StateMachine {
        }
    }

    private String state2str(int state) {
        if (state == BluetoothDevice.BOND_NONE) {
            return "BOND_NONE";
        } else if (state == BluetoothDevice.BOND_BONDING) {
            return "BOND_BONDING";
        } else if (state == BluetoothDevice.BOND_BONDED) {
            return "BOND_BONDED";
        } else return "UNKNOWN(" + state + ")";
    }

    private void infoLog(String msg) {
        Log.i(TAG, msg);
    }