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

Commit 458a6ae4 authored by Sal Savage's avatar Sal Savage
Browse files

Refactor AVRCP Controller 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: I5152d89cc22c2a7aab3eeb1280395aea8e3b3ae1
parent d3bac830
Loading
Loading
Loading
Loading
+3 −6
Original line number Diff line number Diff line
@@ -45,8 +45,7 @@ import java.lang.ref.WeakReference;
 * disconnection has occurred, please create a new client.
 */
public class AvrcpBipClient {
    private static final String TAG = "AvrcpBipClient";
    private static final boolean DBG = Log.isLoggable(TAG, Log.DEBUG);
    private static final String TAG = AvrcpBipClient.class.getSimpleName();

    // AVRCP Controller BIP Image Initiator/Cover Art UUID - AVRCP 1.6 Section 5.14.2.1
    private static final byte[] BLUETOOTH_UUID_AVRCP_COVER_ART = new byte[] {
@@ -466,10 +465,8 @@ public class AvrcpBipClient {
     * Print to debug if debug is enabled for this class
     */
    private void debug(String msg) {
        if (DBG) {
        Log.d(TAG, "[" + mDevice + "] " + msg);
    }
    }

    /**
     * Print to warn
+56 −98
Original line number Diff line number Diff line
@@ -30,8 +30,6 @@ import java.util.UUID;
/** Provides Bluetooth AVRCP Controller native interface for the AVRCP Controller service */
public class AvrcpControllerNativeInterface {
    static final String TAG = AvrcpControllerNativeInterface.class.getSimpleName();
    static final boolean DBG = Log.isLoggable(TAG, Log.DEBUG);
    static final boolean VDBG = Log.isLoggable(TAG, Log.VERBOSE);

    private AvrcpControllerService mAvrcpController;

@@ -123,14 +121,12 @@ public class AvrcpControllerNativeInterface {
    void onConnectionStateChanged(
            boolean remoteControlConnected, boolean browsingConnected, byte[] address) {
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        if (DBG) {
        Log.d(
                TAG,
                "onConnectionStateChanged: "
                        + (" remoteControlConnected=" + remoteControlConnected)
                        + (" browsingConnected=" + browsingConnected)
                        + (" device=" + device));
        }

        mAvrcpController.onConnectionStateChanged(
                remoteControlConnected, browsingConnected, device);
@@ -140,9 +136,7 @@ public class AvrcpControllerNativeInterface {
    @VisibleForTesting
    void getRcPsm(byte[] address, int psm) {
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        if (DBG) {
        Log.d(TAG, "getRcPsm: device=" + device + " psm=" + psm);
        }

        mAvrcpController.getRcPsm(device, psm);
    }
@@ -150,9 +144,7 @@ public class AvrcpControllerNativeInterface {
    // Called by JNI to report remote Player's capabilities
    void handlePlayerAppSetting(byte[] address, byte[] playerAttribRsp, int rspLen) {
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        if (DBG) {
        Log.d(TAG, "handlePlayerAppSetting: device=" + device + " rspLen=" + rspLen);
        }

        mAvrcpController.handlePlayerAppSetting(device, playerAttribRsp, rspLen);
    }
@@ -160,9 +152,7 @@ public class AvrcpControllerNativeInterface {
    @VisibleForTesting
    void onPlayerAppSettingChanged(byte[] address, byte[] playerAttribRsp, int rspLen) {
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        if (DBG) {
        Log.d(TAG, "onPlayerAppSettingChanged: device=" + device);
        }

        mAvrcpController.onPlayerAppSettingChanged(device, playerAttribRsp, rspLen);
    }
@@ -170,9 +160,7 @@ public class AvrcpControllerNativeInterface {
    // Called by JNI when remote wants to set absolute volume.
    void handleSetAbsVolume(byte[] address, byte absVol, byte label) {
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        if (DBG) {
        Log.d(TAG, "handleSetAbsVolume: device=" + device);
        }

        mAvrcpController.handleSetAbsVolume(device, absVol, label);
    }
@@ -180,9 +168,7 @@ public class AvrcpControllerNativeInterface {
    // Called by JNI when remote wants to receive absolute volume notifications.
    void handleRegisterNotificationAbsVol(byte[] address, byte label) {
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        if (DBG) {
        Log.d(TAG, "handleRegisterNotificationAbsVol: device=" + device);
        }

        mAvrcpController.handleRegisterNotificationAbsVol(device, label);
    }
@@ -190,9 +176,7 @@ public class AvrcpControllerNativeInterface {
    // Called by JNI when a track changes and local AvrcpController is registered for updates.
    void onTrackChanged(byte[] address, byte numAttributes, int[] attributes, String[] attribVals) {
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        if (DBG) {
        Log.d(TAG, "onTrackChanged: device=" + device);
        }

        mAvrcpController.onTrackChanged(device, numAttributes, attributes, attribVals);
    }
@@ -200,9 +184,7 @@ public class AvrcpControllerNativeInterface {
    // Called by JNI periodically based upon timer to update play position
    void onPlayPositionChanged(byte[] address, int songLen, int currSongPosition) {
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        if (DBG) {
        Log.d(TAG, "onPlayPositionChanged: device=" + device + " pos=" + currSongPosition);
        }

        mAvrcpController.onPlayPositionChanged(device, songLen, currSongPosition);
    }
@@ -210,9 +192,7 @@ public class AvrcpControllerNativeInterface {
    // Called by JNI on changes of play status
    void onPlayStatusChanged(byte[] address, byte playStatus) {
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        if (DBG) {
        Log.d(TAG, "onPlayStatusChanged: device=" + device + " playStatus=" + playStatus);
        }

        mAvrcpController.onPlayStatusChanged(device, toPlaybackStateFromJni(playStatus));
    }
@@ -220,27 +200,23 @@ public class AvrcpControllerNativeInterface {
    // Browsing related JNI callbacks.
    void handleGetFolderItemsRsp(byte[] address, int status, AvrcpItem[] items) {
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        if (DBG) {
        Log.d(
                TAG,
                "handleGetFolderItemsRsp:"
                        + (" device=" + device)
                        + (" status=" + status)
                        + (" NumberOfItems=" + items.length));
        }

        mAvrcpController.handleGetFolderItemsRsp(device, status, items);
    }

    void handleGetPlayerItemsRsp(byte[] address, AvrcpPlayer[] items) {
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        if (DBG) {
        Log.d(
                TAG,
                "handleGetFolderItemsRsp:"
                        + (" device=" + device)
                        + (" NumberOfItems=" + items.length));
        }

        mAvrcpController.handleGetPlayerItemsRsp(device, Arrays.asList(items));
    }
@@ -249,7 +225,6 @@ public class AvrcpControllerNativeInterface {
    static AvrcpItem createFromNativeMediaItem(
            byte[] address, long uid, int type, String name, int[] attrIds, String[] attrVals) {
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        if (VDBG) {
        Log.d(
                TAG,
                "createFromNativeMediaItem:"
@@ -259,7 +234,6 @@ public class AvrcpControllerNativeInterface {
                        + (" name=" + name)
                        + (" attrids=" + Arrays.toString(attrIds))
                        + (" attrVals=" + Arrays.toString(attrVals)));
        }

        return new AvrcpItem.Builder()
                .fromAvrcpAttributeArray(attrIds, attrVals)
@@ -275,7 +249,6 @@ public class AvrcpControllerNativeInterface {
    static AvrcpItem createFromNativeFolderItem(
            byte[] address, long uid, int type, String name, int playable) {
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        if (VDBG) {
        Log.d(
                TAG,
                "createFromNativeFolderItem:"
@@ -284,7 +257,6 @@ public class AvrcpControllerNativeInterface {
                        + (" type=" + type)
                        + (" name=" + name)
                        + (" playable=" + playable));
        }

        return new AvrcpItem.Builder()
                .setDevice(device)
@@ -306,7 +278,6 @@ public class AvrcpControllerNativeInterface {
            int playStatus,
            int playerType) {
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        if (VDBG) {
        Log.d(
                TAG,
                "createFromNativePlayerItem:"
@@ -315,7 +286,6 @@ public class AvrcpControllerNativeInterface {
                        + (" transportFlags=" + Arrays.toString(transportFlags))
                        + (" playStatus=" + playStatus)
                        + (" playerType=" + playerType));
        }

        return new AvrcpPlayer.Builder()
                .setDevice(device)
@@ -328,53 +298,41 @@ public class AvrcpControllerNativeInterface {

    void handleChangeFolderRsp(byte[] address, int count) {
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        if (DBG) {
        Log.d(TAG, "handleChangeFolderRsp: device=" + device + " count=" + count);
        }

        mAvrcpController.handleChangeFolderRsp(device, count);
    }

    void handleSetBrowsedPlayerRsp(byte[] address, int items, int depth) {
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        if (DBG) {
        Log.d(TAG, "handleSetBrowsedPlayerRsp: device=" + device + " depth=" + depth);
        }

        mAvrcpController.handleSetBrowsedPlayerRsp(device, items, depth);
    }

    void handleSetAddressedPlayerRsp(byte[] address, int status) {
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        if (DBG) {
        Log.d(TAG, "handleSetAddressedPlayerRsp device=" + device + " status=" + status);
        }

        mAvrcpController.handleSetAddressedPlayerRsp(device, status);
    }

    void handleAddressedPlayerChanged(byte[] address, int id) {
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        if (DBG) {
        Log.d(TAG, "handleAddressedPlayerChanged: device=" + device + " id=" + id);
        }

        mAvrcpController.handleAddressedPlayerChanged(device, id);
    }

    void handleNowPlayingContentChanged(byte[] address) {
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        if (DBG) {
        Log.d(TAG, "handleNowPlayingContentChanged: device=" + device);
        }
        mAvrcpController.handleNowPlayingContentChanged(device);
    }

    void onAvailablePlayerChanged(byte[] address) {
        BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address);
        if (DBG) {
        Log.d(TAG, "onAvailablePlayerChanged: device=" + device);
        }
        mAvrcpController.onAvailablePlayerChanged(device);
    }

+20 −34
Original line number Diff line number Diff line
@@ -54,8 +54,6 @@ import java.util.concurrent.ConcurrentHashMap;
 */
public class AvrcpControllerService extends ProfileService {
    static final String TAG = AvrcpControllerService.class.getSimpleName();
    static final boolean DBG = Log.isLoggable(TAG, Log.DEBUG);
    static final boolean VDBG = Log.isLoggable(TAG, Log.VERBOSE);

    static final int MAXIMUM_CONNECTED_DEVICES = 5;

@@ -119,10 +117,8 @@ public class AvrcpControllerService extends ProfileService {
        @Override
        public void onImageDownloadComplete(BluetoothDevice device,
                AvrcpCoverArtManager.DownloadEvent event) {
            if (DBG) {
            Log.d(TAG, "Image downloaded [device: " + device + ", uuid: " + event.getUuid()
                    + ", uri: " + event.getUri());
            }
            AvrcpControllerStateMachine stateMachine = getStateMachine(device);
            if (stateMachine == null) {
                Log.e(TAG, "No state machine found for device " + device);
@@ -207,9 +203,7 @@ public class AvrcpControllerService extends ProfileService {
     */
    @VisibleForTesting
    boolean setActiveDevice(BluetoothDevice device) {
        if (DBG) {
        Log.d(TAG, "setActiveDevice(device=" + device + ")");
        }
        A2dpSinkService a2dpSinkService = A2dpSinkService.getA2dpSinkService();
        if (a2dpSinkService == null) {
            Log.w(TAG, "setActiveDevice(device=" + device + "): A2DP Sink not available");
@@ -274,7 +268,7 @@ public class AvrcpControllerService extends ProfileService {
    }

    void playItem(String parentMediaId) {
        if (DBG) Log.d(TAG, "playItem(" + parentMediaId + ")");
        Log.d(TAG, "playItem(" + parentMediaId + ")");
        // Check if the requestedNode is a player rather than a song
        BrowseTree.BrowseNode requestedNode = sBrowseTree.findBrowseNodeByID(parentMediaId);
        if (requestedNode == null) {
@@ -282,7 +276,7 @@ public class AvrcpControllerService extends ProfileService {
                // Check each state machine for the song and then play it
                requestedNode = stateMachine.findNode(parentMediaId);
                if (requestedNode != null) {
                    if (DBG) Log.d(TAG, "Found a node");
                    Log.d(TAG, "Found a node, node=" + requestedNode);
                    BluetoothDevice device = stateMachine.getDevice();
                    if (device != null) {
                        setActiveDevice(device);
@@ -304,7 +298,7 @@ public class AvrcpControllerService extends ProfileService {
     *     must be performed.
     */
    public synchronized BrowseResult getContents(String parentMediaId) {
        if (DBG) Log.d(TAG, "getContents(" + parentMediaId + ")");
        Log.d(TAG, "getContents(" + parentMediaId + ")");

        BrowseTree.BrowseNode requestedNode = sBrowseTree.findBrowseNodeByID(parentMediaId);
        if (requestedNode == null) {
@@ -316,12 +310,10 @@ public class AvrcpControllerService extends ProfileService {
            }
        }

        if (DBG) {
        Log.d(TAG, "getContents(" + parentMediaId + "): "
                + (requestedNode == null
                        ? "Failed to find node"
                        : "node=" + requestedNode + ", device=" + requestedNode.getDevice()));
        }

        // If we don't find a node in the tree then do not have any way to browse for the contents.
        // Return an empty list instead.
@@ -340,7 +332,7 @@ public class AvrcpControllerService extends ProfileService {
        List<MediaItem> contents = requestedNode.getContents();

        if (!requestedNode.isCached()) {
            if (DBG) Log.d(TAG, "getContents(" + parentMediaId + "): node download pending");
            Log.d(TAG, "getContents(" + parentMediaId + "): node download pending");
            refreshContents(requestedNode);
            /* Ongoing downloads can have partial results and we want to make sure they get sent
             * to the client. If a download gets kicked off as a result of this request, the
@@ -348,10 +340,8 @@ public class AvrcpControllerService extends ProfileService {
             */
            return new BrowseResult(contents, BrowseResult.DOWNLOAD_PENDING);
        }
        if (DBG) {
        Log.d(TAG, "getContents(" + parentMediaId + "): return node, contents="
                + requestedNode.getContents());
        }
        return new BrowseResult(contents, BrowseResult.SUCCESS);
    }

@@ -526,9 +516,7 @@ public class AvrcpControllerService extends ProfileService {
     * player to stop and start playing.
     */
    public void onAudioFocusStateChanged(int state) {
        if (DBG) {
        Log.d(TAG, "onAudioFocusStateChanged(state=" + state + ")");
        }

        // Make sure the active device isn't changed while we're processing the event so play/pause
        // commands get routed to the correct device
@@ -639,9 +627,10 @@ public class AvrcpControllerService extends ProfileService {

    // Browsing related JNI callbacks.
    void handleGetFolderItemsRsp(BluetoothDevice device, int status, AvrcpItem[] items) {
        Log.d(TAG, "handleGetFolderItemsRsp(device=" + device + ", status=" + status);
        List<AvrcpItem> itemsList = new ArrayList<>();
        for (AvrcpItem item : items) {
            if (VDBG) Log.d(TAG, item.toString());
            Log.v(TAG, "handleGetFolderItemsRsp(device=" + device + "): item=" + item.toString());
            if (mCoverArtManager != null) {
                String handle = item.getCoverArtHandle();
                if (handle != null) {
@@ -718,9 +707,7 @@ public class AvrcpControllerService extends ProfileService {
     * @return true if disconnect is successful, false otherwise.
     */
    public synchronized boolean disconnect(BluetoothDevice device) {
        if (DBG) {
        Log.d(TAG, "disconnect(device=" + device + ")");
        }
        AvrcpControllerStateMachine stateMachine = mDeviceStateMap.get(device);
        // a map state machine instance doesn't exist. maybe it is already gone?
        if (stateMachine == null) {
@@ -786,21 +773,20 @@ public class AvrcpControllerService extends ProfileService {
    }

    List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) {
        if (DBG) Log.d(TAG, "getDevicesMatchingConnectionStates" + Arrays.toString(states));
        Log.d(TAG, "getDevicesMatchingConnectionStates(states=" + Arrays.toString(states) + ")");
        List<BluetoothDevice> deviceList = new ArrayList<>();
        BluetoothDevice[] bondedDevices = mAdapterService.getBondedDevices();
        int connectionState;
        for (BluetoothDevice device : bondedDevices) {
            connectionState = getConnectionState(device);
            if (DBG) Log.d(TAG, "Device: " + device + "State: " + connectionState);
            for (int i = 0; i < states.length; i++) {
                if (connectionState == states[i]) {
                    deviceList.add(device);
                }
            }
        }
        if (DBG) Log.d(TAG, deviceList.toString());
        Log.d(TAG, "GetDevicesDone");
        Log.d(TAG, "getDevicesMatchingConnectionStates(states=" + Arrays.toString(states)
                + "): Found " + deviceList.toString());
        return deviceList;
    }

Loading