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

Commit 340fafb6 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Dump HeadsetClientStateMachine state log"

parents 7f159433 8e3c73f3
Loading
Loading
Loading
Loading
+100 −14
Original line number Diff line number Diff line
@@ -65,6 +65,9 @@ import com.android.bluetooth.statemachine.StateMachine;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.ArrayUtils;

import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
@@ -72,6 +75,7 @@ import java.util.Hashtable;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;

public class HeadsetClientStateMachine extends StateMachine {
@@ -192,6 +196,8 @@ public class HeadsetClientStateMachine extends StateMachine {

    public void dump(StringBuilder sb) {
        if (mCurrentDevice == null) return;
        ProfileService.println(sb,
                "==== StateMachine for " + mCurrentDevice + " ====");
        ProfileService.println(sb, "  mCurrentDevice: " + mCurrentDevice.getAddress() + "("
                + mCurrentDevice.getName() + ") " + this.toString());
        ProfileService.println(sb, "  mAudioState: " + mAudioState);
@@ -216,6 +222,86 @@ public class HeadsetClientStateMachine extends StateMachine {
                ProfileService.println(sb, "    " + call);
            }
        }

        // Dump the state machine logs
        StringWriter stringWriter = new StringWriter();
        PrintWriter printWriter = new PrintWriter(stringWriter);
        super.dump(new FileDescriptor(), printWriter, new String[]{});
        printWriter.flush();
        stringWriter.flush();
        ProfileService.println(sb, "  StateMachineLog:");
        Scanner scanner = new Scanner(stringWriter.toString());
        while (scanner.hasNextLine()) {
            String line = scanner.nextLine();
            ProfileService.println(sb, "    " + line);
        }
    }

    @Override
    protected String getLogRecString(Message msg) {
        StringBuilder builder = new StringBuilder();
        builder.append(getMessageName(msg.what));
        builder.append(": ");
        builder.append("arg1=")
                .append(msg.arg1)
                .append(", arg2=")
                .append(msg.arg2)
                .append(", obj=")
                .append(msg.obj);
        return builder.toString();
    }

    private static String getMessageName(int what) {
        switch (what) {
            case StackEvent.STACK_EVENT:
                return "STACK_EVENT";
            case CONNECT:
                return "CONNECT";
            case DISCONNECT:
                return "DISCONNECT";
            case CONNECT_AUDIO:
                return "CONNECT_AUDIO";
            case DISCONNECT_AUDIO:
                return "DISCONNECT_AUDIO";
            case VOICE_RECOGNITION_START:
                return "VOICE_RECOGNITION_START";
            case VOICE_RECOGNITION_STOP:
                return "VOICE_RECOGNITION_STOP";
            case SET_MIC_VOLUME:
                return "SET_MIC_VOLUME";
            case SET_SPEAKER_VOLUME:
                return "SET_SPEAKER_VOLUME";
            case DIAL_NUMBER:
                return "DIAL_NUMBER";
            case ACCEPT_CALL:
                return "ACCEPT_CALL";
            case REJECT_CALL:
                return "REJECT_CALL";
            case HOLD_CALL:
                return "HOLD_CALL";
            case TERMINATE_CALL:
                return "TERMINATE_CALL";
            case ENTER_PRIVATE_MODE:
                return "ENTER_PRIVATE_MODE";
            case SEND_DTMF:
                return "SEND_DTMF";
            case EXPLICIT_CALL_TRANSFER:
                return "EXPLICIT_CALL_TRANSFER";
            case DISABLE_NREC:
                return "DISABLE_NREC";
            case SEND_VENDOR_AT_COMMAND:
                return "SEND_VENDOR_AT_COMMAND";
            case QUERY_CURRENT_CALLS:
                return "QUERY_CURRENT_CALLS";
            case QUERY_OPERATOR_NAME:
                return "QUERY_OPERATOR_NAME";
            case SUBSCRIBER_INFO:
                return "SUBSCRIBER_INFO";
            case CONNECTING_TIMEOUT:
                return "CONNECTING_TIMEOUT";
            default:
                return "UNKNOWN(" + what + ")";
        }
    }

    private void clearPendingAction() {