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

Commit 8b525485 authored by Myles Watson's avatar Myles Watson
Browse files

AdapterProperties: Add dumpsys support

AdapterProperties
  Name: PhoneName
  Address: 0A:DD:7E:55:00:01
  BluetoothClass: null
  ScanMode: SCAN_MODE_CONNECTABLE
  ConnectionState: STATE_CONNECTED
  State: ON
  MaxConnectedAudioDevices: 3
  A2dpOffloadEnabled: false
  Discovering: false
  DiscoveryEndMs: 0
  Bonded devices:
    40:40:00:40:60:10 [BR/EDR] Pixel 2
    AC:50:80:30:00:1F [BR/EDR] BB-BTHP

Bug: 75375851
Test: adb shell dumpsys bluetooth_manager
Change-Id: I4a84bd5224e4d047359b58f2a9812be0c59893a5
(cherry picked from commit 9578c95ea86bab135fa1159dab8a0363f97861c5)
Merged-In: I4a84bd5224e4d047359b58f2a9812be0c59893a5
parent 68504303
Loading
Loading
Loading
Loading
+75 −9
Original line number Original line Diff line number Diff line
@@ -46,6 +46,8 @@ import android.util.Pair;
import com.android.bluetooth.Utils;
import com.android.bluetooth.Utils;
import com.android.bluetooth.btservice.RemoteDevices.DeviceProperties;
import com.android.bluetooth.btservice.RemoteDevices.DeviceProperties;


import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.HashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArrayList;


@@ -189,8 +191,7 @@ class AdapterProperties {
                + propertyOverlayedMaxConnectedAudioDevices + ", finalValue="
                + propertyOverlayedMaxConnectedAudioDevices + ", finalValue="
                + mMaxConnectedAudioDevices);
                + mMaxConnectedAudioDevices);


        mA2dpOffloadEnabled = SystemProperties.getBoolean(
        mA2dpOffloadEnabled = SystemProperties.getBoolean(A2DP_OFFLOAD_ENABLE_PROPERTY, false);
                A2DP_OFFLOAD_ENABLE_PROPERTY, false);


        IntentFilter filter = new IntentFilter();
        IntentFilter filter = new IntentFilter();
        filter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED);
@@ -313,10 +314,10 @@ class AdapterProperties {
    }
    }


    /**
    /**
     * @param mConnectionState the mConnectionState to set
     * @param connectionState the mConnectionState to set
     */
     */
    void setConnectionState(int mConnectionState) {
    void setConnectionState(int connectionState) {
        this.mConnectionState = mConnectionState;
        mConnectionState = connectionState;
    }
    }


    /**
    /**
@@ -329,9 +330,9 @@ class AdapterProperties {
    /**
    /**
     * @param mState the mState to set
     * @param mState the mState to set
     */
     */
    void setState(int mState) {
    void setState(int state) {
        debugLog("Setting state to " + BluetoothAdapter.nameForState(mState));
        debugLog("Setting state to " + BluetoothAdapter.nameForState(state));
        this.mState = mState;
        mState = state;
    }
    }


    /**
    /**
@@ -823,7 +824,8 @@ class AdapterProperties {
    }
    }


    void onBluetoothReady() {
    void onBluetoothReady() {
        debugLog("onBluetoothReady, state=" + getState() + ", ScanMode=" + mScanMode);
        debugLog("onBluetoothReady, state=" + BluetoothAdapter.nameForState(getState())
                + ", ScanMode=" + mScanMode);


        synchronized (mObject) {
        synchronized (mObject) {
            // Reset adapter and profile connection states
            // Reset adapter and profile connection states
@@ -894,6 +896,70 @@ class AdapterProperties {
        }
        }
    }
    }


    protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
        writer.println(TAG);
        writer.println("  " + "Name: " + getName());
        writer.println("  " + "Address: " + Utils.getAddressStringFromByte(mAddress));
        writer.println("  " + "BluetoothClass: " + getBluetoothClass());
        writer.println("  " + "ScanMode: " + dumpScanMode(getScanMode()));
        writer.println("  " + "ConnectionState: " + dumpConnectionState(getConnectionState()));
        writer.println("  " + "State: " + BluetoothAdapter.nameForState(getState()));
        writer.println("  " + "MaxConnectedAudioDevices: " + getMaxConnectedAudioDevices());
        writer.println("  " + "A2dpOffloadEnabled: " + mA2dpOffloadEnabled);
        writer.println("  " + "Discovering: " + mDiscovering);
        writer.println("  " + "DiscoveryEndMs: " + mDiscoveryEndMs);

        writer.println("  " + "Bonded devices:");
        for (BluetoothDevice device : mBondedDevices) {
            writer.println(
                    "    " + device.getAddress() + " [" + dumpDeviceType(device.getType()) + "] "
                            + device.getName());
        }
    }

    private String dumpDeviceType(int deviceType) {
        switch (deviceType) {
            case BluetoothDevice.DEVICE_TYPE_UNKNOWN:
                return " ???? ";
            case BluetoothDevice.DEVICE_TYPE_CLASSIC:
                return "BR/EDR";
            case BluetoothDevice.DEVICE_TYPE_LE:
                return "  LE  ";
            case BluetoothDevice.DEVICE_TYPE_DUAL:
                return " DUAL ";
            default:
                return "Invalid device type: " + deviceType;
        }
    }

    private String dumpConnectionState(int state) {
        switch (state) {
            case BluetoothAdapter.STATE_DISCONNECTED:
                return "STATE_DISCONNECTED";
            case BluetoothAdapter.STATE_DISCONNECTING:
                return "STATE_DISCONNECTING";
            case BluetoothAdapter.STATE_CONNECTING:
                return "STATE_CONNECTING";
            case BluetoothAdapter.STATE_CONNECTED:
                return "STATE_CONNECTED";
            default:
                return "Unknown Connection State " + state;
        }
    }

    private String dumpScanMode(int scanMode) {
        switch (scanMode) {
            case BluetoothAdapter.SCAN_MODE_NONE:
                return "SCAN_MODE_NONE";
            case BluetoothAdapter.SCAN_MODE_CONNECTABLE:
                return "SCAN_MODE_CONNECTABLE";
            case BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE:
                return "SCAN_MODE_CONNECTABLE_DISCOVERABLE";
            default:
                return "Unknown Scan Mode " + scanMode;
        }
    }

    private static void infoLog(String msg) {
    private static void infoLog(String msg) {
        if (VDBG) {
        if (VDBG) {
            Log.i(TAG, msg);
            Log.i(TAG, msg);
+1 −14
Original line number Original line Diff line number Diff line
@@ -122,10 +122,6 @@ public class AdapterService extends Service {
            "message_access_permission";
            "message_access_permission";
    private static final String SIM_ACCESS_PERMISSION_PREFERENCE_FILE = "sim_access_permission";
    private static final String SIM_ACCESS_PERMISSION_PREFERENCE_FILE = "sim_access_permission";


    private static final String[] DEVICE_TYPE_NAMES = new String[]{
            "???", "BR/EDR", "LE", "DUAL"
    };

    private static final int CONTROLLER_ENERGY_UPDATE_TIMEOUT_MILLIS = 30;
    private static final int CONTROLLER_ENERGY_UPDATE_TIMEOUT_MILLIS = 30;


    static {
    static {
@@ -2422,17 +2418,8 @@ public class AdapterService extends Service {
            return;
            return;
        }
        }


        writer.println("AdapterProperties");
        writer.println("  " + "MaxConnectedAudioDevices: " + getMaxConnectedAudioDevices());
        writer.println();
        writer.println();

        mAdapterProperties.dump(fd, writer, args);

        writer.println("Bonded devices:");
        for (BluetoothDevice device : getBondedDevices()) {
            writer.println(
                    "  " + device.getAddress() + " [" + DEVICE_TYPE_NAMES[device.getType()] + "] "
                            + device.getName());
        }


        writer.println();
        writer.println();
        mAdapterStateMachine.dump(fd, writer, args);
        mAdapterStateMachine.dump(fd, writer, args);