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

Commit 1bc37f4b authored by Sal Savage's avatar Sal Savage
Browse files

Refactor HID logging to be unguarded

With the recent addition of a process minimum default log level, the
Android Log framework will now enforce the set log level against the
various log invocations we make in code. We no longer need to guard log
invocations on our own.

Tag: #refactor
Flag: EXEMPT, logging only change
Bug: 315046089
Test: atest BluetoothInstrumentationTests
Change-Id: I4ca60b59e49ff149dda13cc3e7a8901960a11f37
parent e8593771
Loading
Loading
Loading
Loading
+39 −90
Original line number Diff line number Diff line
@@ -57,7 +57,6 @@ import java.util.NoSuchElementException;
import java.util.Objects;

public class HidDeviceService extends ProfileService {
    private static final boolean DBG = false;
    private static final String TAG = HidDeviceService.class.getSimpleName();

    private static final int MESSAGE_APPLICATION_STATE_CHANGED = 1;
@@ -102,9 +101,7 @@ public class HidDeviceService extends ProfileService {

        @Override
        public void handleMessage(Message msg) {
            if (DBG) {
            Log.d(TAG, "handleMessage(): msg.what=" + msg.what);
            }

            switch (msg.what) {
                case MESSAGE_APPLICATION_STATE_CHANGED: {
@@ -332,7 +329,7 @@ public class HidDeviceService extends ProfileService {
                BluetoothHidDeviceAppQosSettings inQos, BluetoothHidDeviceAppQosSettings outQos,
                IBluetoothHidDeviceCallback callback, AttributionSource source,
                SynchronousResultReceiver receiver) {
            if (DBG) Log.d(TAG, "registerApp()");
            Log.d(TAG, "registerApp()");
            try {
                HidDeviceService service = getService(source);
                boolean defaultValue = false;
@@ -348,7 +345,7 @@ public class HidDeviceService extends ProfileService {
        @Override
        public void unregisterApp(AttributionSource source, SynchronousResultReceiver receiver) {
            try {
                if (DBG) Log.d(TAG, "unregisterApp()");
                Log.d(TAG, "unregisterApp()");
                boolean defaultValue = false;

                HidDeviceService service = getService(source);
@@ -366,7 +363,7 @@ public class HidDeviceService extends ProfileService {
        public void sendReport(BluetoothDevice device, int id, byte[] data,
                AttributionSource source, SynchronousResultReceiver receiver) {
            try {
                if (DBG) Log.d(TAG, "sendReport(): device=" + device + "  id=" + id);
                Log.d(TAG, "sendReport(): device=" + device + "  id=" + id);
                boolean defaultValue = false ;

                HidDeviceService service = getService(source);
@@ -384,7 +381,7 @@ public class HidDeviceService extends ProfileService {
        public void replyReport(BluetoothDevice device, byte type, byte id, byte[] data,
                AttributionSource source, SynchronousResultReceiver receiver) {
            try {
                if (DBG) Log.d(TAG, "replyReport(): device=" + device
                Log.d(TAG, "replyReport(): device=" + device
                        + " type=" + type + " id=" + id);
                boolean defaultValue = false;
                HidDeviceService service = getService(source);
@@ -401,7 +398,7 @@ public class HidDeviceService extends ProfileService {
        public void unplug(BluetoothDevice device, AttributionSource source,
                SynchronousResultReceiver receiver) {
            try {
                if (DBG) Log.d(TAG, "unplug(): device=" + device);
                Log.d(TAG, "unplug(): device=" + device);
                boolean defaultValue = false;
                HidDeviceService service = getService(source);
                if (service != null) {
@@ -417,7 +414,7 @@ public class HidDeviceService extends ProfileService {
        public void connect(BluetoothDevice device, AttributionSource source,
                SynchronousResultReceiver receiver) {
            try {
                if (DBG) Log.d(TAG, "connect(): device=" + device);
                Log.d(TAG, "connect(): device=" + device);
                HidDeviceService service = getService(source);
                boolean defaultValue = false;
                if (service != null) {
@@ -434,7 +431,7 @@ public class HidDeviceService extends ProfileService {
        public void disconnect(BluetoothDevice device, AttributionSource source,
                SynchronousResultReceiver receiver) {
            try {
                if (DBG) Log.d(TAG, "disconnect(): device=" + device);
                Log.d(TAG, "disconnect(): device=" + device);
                HidDeviceService service = getService(source);
                boolean defaultValue = false;
                if (service != null) {
@@ -451,10 +448,8 @@ public class HidDeviceService extends ProfileService {
        public void setConnectionPolicy(BluetoothDevice device, int connectionPolicy,
                AttributionSource source, SynchronousResultReceiver receiver) {
            try {
                if (DBG) {
                Log.d(TAG, "setConnectionPolicy(): device=" + device + " connectionPolicy="
                        + connectionPolicy);
                }
                HidDeviceService service = getService(source);
                boolean defaultValue = false;
                if (service != null) {
@@ -471,7 +466,7 @@ public class HidDeviceService extends ProfileService {
        public void reportError(BluetoothDevice device, byte error, AttributionSource source,
                SynchronousResultReceiver receiver) {
            try {
                if (DBG) Log.d(TAG, "reportError(): device=" + device + " error=" + error);
                Log.d(TAG, "reportError(): device=" + device + " error=" + error);

                HidDeviceService service = getService(source);
                boolean defaultValue = false;
@@ -488,7 +483,7 @@ public class HidDeviceService extends ProfileService {
        public void getConnectionState(BluetoothDevice device, AttributionSource source,
                SynchronousResultReceiver receiver) {
            try {
                if (DBG) Log.d(TAG, "getConnectionState(): device=" + device);
                Log.d(TAG, "getConnectionState(): device=" + device);

                HidDeviceService service = getService(source);
                int defaultValue = BluetoothHidDevice.STATE_DISCONNECTED;
@@ -504,7 +499,7 @@ public class HidDeviceService extends ProfileService {
        @Override
        public void getConnectedDevices(AttributionSource source,
                SynchronousResultReceiver receiver) {
            if (DBG) Log.d(TAG, "getConnectedDevices()");
            Log.d(TAG, "getConnectedDevices()");

            getDevicesMatchingConnectionStates(new int[] { BluetoothProfile.STATE_CONNECTED },
                    source, receiver);
@@ -514,10 +509,8 @@ public class HidDeviceService extends ProfileService {
        public void getDevicesMatchingConnectionStates(int[] states,
                AttributionSource source, SynchronousResultReceiver receiver) {
            try {
                if (DBG) {
                Log.d(TAG, "getDevicesMatchingConnectionStates(): states="
                        + Arrays.toString(states));
                }
                HidDeviceService service = getService(source);
                List<BluetoothDevice> defaultValue = new ArrayList<BluetoothDevice>(0);
                if (service != null) {
@@ -575,9 +568,7 @@ public class HidDeviceService extends ProfileService {
        }

        int callingUid = Binder.getCallingUid();
        if (DBG) {
        Log.d(TAG, "registerApp(): calling uid=" + callingUid);
        }
        if (callingUid >= Process.FIRST_APPLICATION_UID
                && mActivityManager.getUidImportance(callingUid) > FOREGROUND_IMPORTANCE_CUTOFF) {
            Log.w(TAG, "registerApp(): failed because the app is not foreground");
@@ -615,51 +606,39 @@ public class HidDeviceService extends ProfileService {
    }

    synchronized boolean unregisterApp() {
        if (DBG) {
        Log.d(TAG, "unregisterApp()");
        }

        int callingUid = Binder.getCallingUid();
        return unregisterAppUid(callingUid);
    }

    private synchronized boolean unregisterAppUid(int uid) {
        if (DBG) {
        Log.d(TAG, "unregisterAppUid(): uid=" + uid);
        }

        if (mUserUid != 0 && (uid == mUserUid || uid < Process.FIRST_APPLICATION_UID)) {
            mUserUid = 0;
            return mHidDeviceNativeInterface.unregisterApp();
        }
        if (DBG) {
        Log.d(TAG, "unregisterAppUid(): caller UID doesn't match user UID");
        }
        return false;
    }

    synchronized boolean sendReport(BluetoothDevice device, int id, byte[] data) {
        if (DBG) {
        Log.d(TAG, "sendReport(): device=" + device + " id=" + id);
        }

        return checkDevice(device) && checkCallingUid()
                && mHidDeviceNativeInterface.sendReport(id, data);
    }

    synchronized boolean replyReport(BluetoothDevice device, byte type, byte id, byte[] data) {
        if (DBG) {
        Log.d(TAG, "replyReport(): device=" + device + " type=" + type + " id=" + id);
        }

        return checkDevice(device) && checkCallingUid()
                && mHidDeviceNativeInterface.replyReport(type, id, data);
    }

    synchronized boolean unplug(BluetoothDevice device) {
        if (DBG) {
        Log.d(TAG, "unplug(): device=" + device);
        }

        return checkDevice(device) && checkCallingUid()
                && mHidDeviceNativeInterface.unplug();
@@ -672,9 +651,7 @@ public class HidDeviceService extends ProfileService {
     * @return true if the connection is successful, false otherwise
     */
    public synchronized boolean connect(BluetoothDevice device) {
        if (DBG) {
        Log.d(TAG, "connect(): device=" + device);
        }

        return checkCallingUid() && mHidDeviceNativeInterface.connect(device);
    }
@@ -686,9 +663,7 @@ public class HidDeviceService extends ProfileService {
     * @return true if the disconnection is successful, false otherwise
     */
    public synchronized boolean disconnect(BluetoothDevice device) {
        if (DBG) {
        Log.d(TAG, "disconnect(): device=" + device);
        }

        int callingUid = Binder.getCallingUid();
        if (callingUid != mUserUid && callingUid >= Process.FIRST_APPLICATION_UID) {
@@ -717,9 +692,7 @@ public class HidDeviceService extends ProfileService {
    public boolean setConnectionPolicy(BluetoothDevice device, int connectionPolicy) {
        enforceCallingOrSelfPermission(
                BLUETOOTH_PRIVILEGED, "Need BLUETOOTH_PRIVILEGED permission");
        if (DBG) {
        Log.d(TAG, "Saved connectionPolicy " + device + " = " + connectionPolicy);
        }

        if (!mDatabaseManager.setProfileConnectionPolicy(device, BluetoothProfile.HID_DEVICE,
                  connectionPolicy)) {
@@ -754,9 +727,7 @@ public class HidDeviceService extends ProfileService {
    }

    synchronized boolean reportError(BluetoothDevice device, byte error) {
        if (DBG) {
        Log.d(TAG, "reportError(): device=" + device + " error=" + error);
        }

        return checkDevice(device) && checkCallingUid()
                && mHidDeviceNativeInterface.reportError(error);
@@ -772,9 +743,7 @@ public class HidDeviceService extends ProfileService {

    @Override
    public void start() {
        if (DBG) {
        Log.d(TAG, "start()");
        }

        mDatabaseManager = Objects.requireNonNull(AdapterService.getAdapterService().getDatabase(),
                "DatabaseManager cannot be null when HidDeviceService starts");
@@ -791,9 +760,7 @@ public class HidDeviceService extends ProfileService {

    @Override
    public void stop() {
        if (DBG) {
        Log.d(TAG, "stop()");
        }

        if (sHidDeviceService == null) {
            Log.w(TAG, "stop() called before start()");
@@ -826,9 +793,7 @@ public class HidDeviceService extends ProfileService {

    @VisibleForTesting
    static synchronized void setHidDeviceService(HidDeviceService instance) {
        if (DBG) {
        Log.d(TAG, "setHidDeviceService(): set to: " + instance);
        }
        sHidDeviceService = instance;
    }

@@ -863,9 +828,7 @@ public class HidDeviceService extends ProfileService {

    synchronized void onApplicationStateChangedFromNative(BluetoothDevice device,
            boolean registered) {
        if (DBG) {
        Log.d(TAG, "onApplicationStateChanged(): registered=" + registered);
        }

        Message msg = mHandler.obtainMessage(MESSAGE_APPLICATION_STATE_CHANGED);
        msg.obj = device;
@@ -874,10 +837,8 @@ public class HidDeviceService extends ProfileService {
    }

    synchronized void onConnectStateChangedFromNative(BluetoothDevice device, int state) {
        if (DBG) {
        Log.d(TAG, "onConnectStateChanged(): device="
                + device + " state=" + state);
        }

        Message msg = mHandler.obtainMessage(MESSAGE_CONNECT_STATE_CHANGED);
        msg.obj = device;
@@ -886,9 +847,7 @@ public class HidDeviceService extends ProfileService {
    }

    synchronized void onGetReportFromNative(byte type, byte id, short bufferSize) {
        if (DBG) {
        Log.d(TAG, "onGetReport(): type=" + type + " id=" + id + " bufferSize=" + bufferSize);
        }

        Message msg = mHandler.obtainMessage(MESSAGE_GET_REPORT);
        msg.obj = bufferSize > 0 ? Integer.valueOf(bufferSize) : null;
@@ -898,9 +857,7 @@ public class HidDeviceService extends ProfileService {
    }

    synchronized void onSetReportFromNative(byte reportType, byte reportId, byte[] data) {
        if (DBG) {
        Log.d(TAG, "onSetReport(): reportType=" + reportType + " reportId=" + reportId);
        }

        ByteBuffer bb = ByteBuffer.wrap(data);

@@ -912,9 +869,7 @@ public class HidDeviceService extends ProfileService {
    }

    synchronized void onSetProtocolFromNative(byte protocol) {
        if (DBG) {
        Log.d(TAG, "onSetProtocol(): protocol=" + protocol);
        }

        Message msg = mHandler.obtainMessage(MESSAGE_SET_PROTOCOL);
        msg.arg1 = protocol;
@@ -922,9 +877,7 @@ public class HidDeviceService extends ProfileService {
    }

    synchronized void onInterruptDataFromNative(byte reportId, byte[] data) {
        if (DBG) {
        Log.d(TAG, "onInterruptData(): reportId=" + reportId);
        }

        ByteBuffer bb = ByteBuffer.wrap(data);

@@ -935,19 +888,15 @@ public class HidDeviceService extends ProfileService {
    }

    synchronized void onVirtualCableUnplugFromNative() {
        if (DBG) {
        Log.d(TAG, "onVirtualCableUnplug()");
        }

        Message msg = mHandler.obtainMessage(MESSAGE_VC_UNPLUG);
        mHandler.sendMessage(msg);
    }

    private void setAndBroadcastConnectionState(BluetoothDevice device, int newState) {
        if (DBG) {
        Log.d(TAG, "setAndBroadcastConnectionState(): device=" + device
                + " oldState=" + mHidDeviceState + " newState=" + newState);
        }

        if (mHidDevice != null && !mHidDevice.equals(device)) {
            Log.w(TAG, "Connection state changed for unknown device, ignoring");
+6 −7
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import com.android.internal.annotations.VisibleForTesting;
/** Provides Bluetooth Hid Host profile, as a service in the Bluetooth application. */
public class HidHostNativeInterface {
    private static final String TAG = HidHostNativeInterface.class.getSimpleName();
    private static final boolean DBG = Log.isLoggable(TAG, Log.DEBUG);

    private HidHostService mHidHostService;

@@ -130,34 +129,34 @@ public class HidHostNativeInterface {
    /**********************************************************************************************/

    private void onConnectStateChanged(byte[] address, int addressType, int transport, int state) {
        if (DBG) Log.d(TAG, "onConnectStateChanged: state=" + state);
        Log.d(TAG, "onConnectStateChanged: state=" + state);
        mHidHostService.onConnectStateChanged(
                address, addressType, transport, convertHalState(state));
    }

    private void onGetProtocolMode(byte[] address, int addressType, int transport, int mode) {
        if (DBG) Log.d(TAG, "onGetProtocolMode()");
        Log.d(TAG, "onGetProtocolMode()");
        mHidHostService.onGetProtocolMode(address, addressType, transport, mode);
    }

    private void onGetReport(
            byte[] address, int addressType, int transport, byte[] report, int rptSize) {
        if (DBG) Log.d(TAG, "onGetReport()");
        Log.d(TAG, "onGetReport()");
        mHidHostService.onGetReport(address, addressType, transport, report, rptSize);
    }

    private void onHandshake(byte[] address, int addressType, int transport, int status) {
        if (DBG) Log.d(TAG, "onHandshake: status=" + status);
        Log.d(TAG, "onHandshake: status=" + status);
        mHidHostService.onHandshake(address, addressType, transport, status);
    }

    private void onVirtualUnplug(byte[] address, int addressType, int transport, int status) {
        if (DBG) Log.d(TAG, "onVirtualUnplug: status=" + status);
        Log.d(TAG, "onVirtualUnplug: status=" + status);
        mHidHostService.onVirtualUnplug(address, addressType, transport, status);
    }

    private void onGetIdleTime(byte[] address, int addressType, int transport, int idleTime) {
        if (DBG) Log.d(TAG, "onGetIdleTime()");
        Log.d(TAG, "onGetIdleTime()");
        mHidHostService.onGetIdleTime(address, addressType, transport, idleTime);
    }

+30 −63
Original line number Diff line number Diff line
@@ -63,7 +63,6 @@ import java.util.stream.Collectors;
 * the Bluetooth application.
 */
public class HidHostService extends ProfileService {
    private static final boolean DBG = false;
    private static final String TAG = "BluetoothHidHostService";

    private static class InputDevice {
@@ -167,14 +166,12 @@ public class HidHostService extends ProfileService {

    @Override
    public void stop() {
        if (DBG) {
        Log.d(TAG, "Stopping Bluetooth HidHostService");
    }
    }

    @Override
    public void cleanup() {
        if (DBG) Log.d(TAG, "Stopping Bluetooth HidHostService");
        Log.d(TAG, "Stopping Bluetooth HidHostService");
        if (mNativeAvailable) {
            mNativeInterface.cleanup();
            mNativeAvailable = false;
@@ -291,9 +288,7 @@ public class HidHostService extends ProfileService {
    }

    private static synchronized void setHidHostService(HidHostService instance) {
        if (DBG) {
        Log.d(TAG, "setHidHostService(): set to: " + instance);
        }
        sHidHostService = instance;
    }

@@ -357,7 +352,8 @@ public class HidHostService extends ProfileService {
            new Handler() {
                @Override
                public void handleMessage(Message msg) {
                    if (DBG) Log.v(TAG, "handleMessage(): msg.what=" + msg.what);
                    Log.v(TAG, "handleMessage(): msg.what=" + msg.what);

                    switch (msg.what) {
                        case MESSAGE_CONNECT:
                            handleMessageConnect(msg);
@@ -1068,7 +1064,7 @@ public class HidHostService extends ProfileService {
     * @return true if connection request is passed down to mHandler.
     */
    public boolean connect(BluetoothDevice device) {
        if (DBG) Log.d(TAG, "connect: " + device);
        Log.d(TAG, "connect: " + device);
        int state = getConnectionState(device);
        if (state != BluetoothProfile.STATE_DISCONNECTED) {
            Log.e(TAG, "Hid Device not disconnected: " + device + ", state: " + state);
@@ -1091,9 +1087,7 @@ public class HidHostService extends ProfileService {
     * @return true
     */
    private boolean disconnect(BluetoothDevice device, int connectionPolicy) {
        if (DBG) {
        Log.d(TAG, "disconnect: " + device + ", connection policy: " + connectionPolicy);
        }
        Message msg = mHandler.obtainMessage(MESSAGE_DISCONNECT, device);
        msg.arg1 = connectionPolicy;
        mHandler.sendMessage(msg);
@@ -1121,7 +1115,7 @@ public class HidHostService extends ProfileService {
     * {@link BluetoothProfile#STATE_DISCONNECTING} if this profile is being disconnected
     */
    public int getConnectionState(BluetoothDevice device) {
        if (DBG) Log.d(TAG, "getConnectionState: " + device);
        Log.d(TAG, "getConnectionState: " + device);
        InputDevice inputDevice = mInputDevices.get(device);
        if (inputDevice != null) {
            return inputDevice.getState();
@@ -1130,8 +1124,7 @@ public class HidHostService extends ProfileService {
    }

    List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
        if (DBG) Log.d(TAG, "getDevicesMatchingConnectionStates()");

        Log.d(TAG, "getDevicesMatchingConnectionStates()");
        return mInputDevices.entrySet().stream()
                .filter(entry -> Ints.asList(states).contains(entry.getValue().getState()))
                .map(Map.Entry::getKey)
@@ -1154,17 +1147,13 @@ public class HidHostService extends ProfileService {
     * @return true if connectionPolicy is set, false on error
     */
    public boolean setConnectionPolicy(BluetoothDevice device, int connectionPolicy) {
        if (DBG) {
        Log.d(TAG, "setConnectionPolicy: " + device);
        }

        if (!mDatabaseManager.setProfileConnectionPolicy(device, BluetoothProfile.HID_HOST,
                  connectionPolicy)) {
            return false;
        }
        if (DBG) {
        Log.d(TAG, "Saved connectionPolicy " + device + " = " + connectionPolicy);
        }
        if (connectionPolicy == BluetoothProfile.CONNECTION_POLICY_ALLOWED) {
            connect(device);
        } else if (connectionPolicy == BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) {
@@ -1177,9 +1166,7 @@ public class HidHostService extends ProfileService {
     * @see BluetoothHidHost#setPreferredTransport
     */
    boolean setPreferredTransport(BluetoothDevice device, int transport) {
        if (DBG) {
        Log.i(TAG, "setPreferredTransport: " + device + " transport: " + transport);
        }

        if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
            Log.w(TAG, "Device not bonded" + device);
@@ -1215,9 +1202,7 @@ public class HidHostService extends ProfileService {
     * @return connection policy of the device
     */
    public int getConnectionPolicy(BluetoothDevice device) {
        if (DBG) {
        Log.d(TAG, "getConnectionPolicy: " + device);
        }
        return mDatabaseManager
                .getProfileConnectionPolicy(device, BluetoothProfile.HID_HOST);
    }
@@ -1226,9 +1211,7 @@ public class HidHostService extends ProfileService {
     * @see BluetoothHidHost#getPreferredTransport
     */
    int getPreferredTransport(BluetoothDevice device) {
        if (DBG) {
        Log.d(TAG, "getPreferredTransport: " + device);
        }

        // TODO: Access to mInputDevices should be protected in binder thread
        return getTransport(device);
@@ -1236,9 +1219,7 @@ public class HidHostService extends ProfileService {

    /* The following APIs regarding test app for compliance */
    boolean getProtocolMode(BluetoothDevice device) {
        if (DBG) {
        Log.d(TAG, "getProtocolMode: " + device);
        }
        int state = this.getConnectionState(device);
        if (state != BluetoothProfile.STATE_CONNECTED) {
            return false;
@@ -1249,9 +1230,7 @@ public class HidHostService extends ProfileService {
    }

    boolean virtualUnplug(BluetoothDevice device) {
        if (DBG) {
        Log.d(TAG, "virtualUnplug: " + device);
        }
        int state = this.getConnectionState(device);
        if (state != BluetoothProfile.STATE_CONNECTED) {
            return false;
@@ -1262,9 +1241,7 @@ public class HidHostService extends ProfileService {
    }

    boolean setProtocolMode(BluetoothDevice device, int protocolMode) {
        if (DBG) {
        Log.d(TAG, "setProtocolMode: " + device);
        }
        int state = this.getConnectionState(device);
        if (state != BluetoothProfile.STATE_CONNECTED) {
            return false;
@@ -1277,9 +1254,7 @@ public class HidHostService extends ProfileService {
    }

    boolean getReport(BluetoothDevice device, byte reportType, byte reportId, int bufferSize) {
        if (DBG) {
        Log.d(TAG, "getReport: " + device);
        }
        int state = this.getConnectionState(device);
        if (state != BluetoothProfile.STATE_CONNECTED) {
            return false;
@@ -1296,9 +1271,7 @@ public class HidHostService extends ProfileService {
    }

    boolean setReport(BluetoothDevice device, byte reportType, String report) {
        if (DBG) {
        Log.d(TAG, "setReport: " + device);
        }
        int state = this.getConnectionState(device);
        if (state != BluetoothProfile.STATE_CONNECTED) {
            return false;
@@ -1314,9 +1287,7 @@ public class HidHostService extends ProfileService {
    }

    boolean sendData(BluetoothDevice device, String report) {
        if (DBG) {
        Log.d(TAG, "sendData: " + device);
        }
        int state = this.getConnectionState(device);
        if (state != BluetoothProfile.STATE_CONNECTED) {
            return false;
@@ -1330,7 +1301,7 @@ public class HidHostService extends ProfileService {
    }

    boolean getIdleTime(BluetoothDevice device) {
        if (DBG) Log.d(TAG, "getIdleTime: " + device);
        Log.d(TAG, "getIdleTime: " + device);
        int state = this.getConnectionState(device);
        if (state != BluetoothProfile.STATE_CONNECTED) {
            return false;
@@ -1341,7 +1312,7 @@ public class HidHostService extends ProfileService {
    }

    boolean setIdleTime(BluetoothDevice device, byte idleTime) {
        if (DBG) Log.d(TAG, "setIdleTime: " + device);
        Log.d(TAG, "setIdleTime: " + device);
        int state = this.getConnectionState(device);
        if (state != BluetoothProfile.STATE_CONNECTED) {
            return false;
@@ -1356,7 +1327,7 @@ public class HidHostService extends ProfileService {
    }

    void onGetProtocolMode(byte[] address, int addressType, int transport, int mode) {
        if (DBG) Log.d(TAG, "onGetProtocolMode()");
        Log.d(TAG, "onGetProtocolMode()");
        Message msg = mHandler.obtainMessage(MESSAGE_ON_GET_PROTOCOL_MODE);
        msg.obj = address;
        msg.arg1 = transport;
@@ -1365,7 +1336,7 @@ public class HidHostService extends ProfileService {
    }

    void onGetIdleTime(byte[] address, int addressType, int transport, int idleTime) {
        if (DBG) Log.d(TAG, "onGetIdleTime()");
        Log.d(TAG, "onGetIdleTime()");
        Message msg = mHandler.obtainMessage(MESSAGE_ON_GET_IDLE_TIME);
        msg.obj = address;
        msg.arg1 = transport;
@@ -1374,7 +1345,7 @@ public class HidHostService extends ProfileService {
    }

    void onGetReport(byte[] address, int addressType, int transport, byte[] report, int rptSize) {
        if (DBG) Log.d(TAG, "onGetReport()");
        Log.d(TAG, "onGetReport()");
        Message msg = mHandler.obtainMessage(MESSAGE_ON_GET_REPORT);
        msg.obj = address;
        msg.arg1 = transport;
@@ -1386,7 +1357,7 @@ public class HidHostService extends ProfileService {
    }

    void onHandshake(byte[] address, int addressType, int transport, int status) {
        if (DBG) Log.d(TAG, "onHandshake: status=" + status);
        Log.d(TAG, "onHandshake: status=" + status);
        Message msg = mHandler.obtainMessage(MESSAGE_ON_HANDSHAKE);
        msg.obj = address;
        msg.arg1 = transport;
@@ -1395,7 +1366,7 @@ public class HidHostService extends ProfileService {
    }

    void onVirtualUnplug(byte[] address, int addressType, int transport, int status) {
        if (DBG) Log.d(TAG, "onVirtualUnplug: status=" + status);
        Log.d(TAG, "onVirtualUnplug: status=" + status);
        Message msg = mHandler.obtainMessage(MESSAGE_ON_VIRTUAL_UNPLUG);
        msg.obj = address;
        msg.arg1 = transport;
@@ -1404,7 +1375,7 @@ public class HidHostService extends ProfileService {
    }

    void onConnectStateChanged(byte[] address, int addressType, int transport, int state) {
        if (DBG) Log.d(TAG, "onConnectStateChanged: state=" + state);
        Log.d(TAG, "onConnectStateChanged: state=" + state);
        Message msg = mHandler.obtainMessage(MESSAGE_CONNECT_STATE_CHANGED, address);
        msg.arg1 = transport;
        msg.arg2 = state;
@@ -1534,10 +1505,8 @@ public class HidHostService extends ProfileService {
        intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
        Utils.sendBroadcast(this, intent, BLUETOOTH_CONNECT,
                Utils.getTempAllowlistBroadcastOptions());
        if (DBG) {
        Log.d(TAG, "Protocol Mode (" + device + "): " + protocolMode);
    }
    }

    private void broadcastReport(BluetoothDevice device, byte[] report, int rptSize) {
        Intent intent = new Intent(BluetoothHidHost.ACTION_REPORT);
@@ -1565,10 +1534,8 @@ public class HidHostService extends ProfileService {
        intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
        Utils.sendBroadcast(this, intent, BLUETOOTH_CONNECT,
                Utils.getTempAllowlistBroadcastOptions());
        if (DBG) {
        Log.d(TAG, "Idle time (" + device + "): " + idleTime);
    }
    }

    /**
     * Check whether can connect to a peer device.