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

Commit b9f33066 authored by Sal Savage's avatar Sal Savage
Browse files

Refactor some Bluetooth Media related logging

A few useful messages were missing when debug logging was enabled,
including browse node changes, the package name of clients that are
connecting to us, active device changes, and the browse node found's
associated device.

Tag: #refactor
Bug: 293511407
Test: atest BluetoothInstrumentationTests
Change-Id: I525d8f3b6e2948896abb8c5533cd85636966f070
parent eaa6ee58
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -134,6 +134,7 @@ public class A2dpSinkService extends ProfileService {
     * Set the device that should be allowed to actively stream
     */
    public boolean setActiveDevice(BluetoothDevice device) {
        Log.i(TAG, "setActiveDevice(device=" + device + ")");
        synchronized (mActiveDeviceLock) {
            if (mNativeInterface.setActiveDevice(device)) {
                mActiveDevice = device;
+19 −4
Original line number Diff line number Diff line
@@ -208,8 +208,12 @@ 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");
            return false;
        }

@@ -242,6 +246,8 @@ public class AvrcpControllerService extends ProfileService {
                return true;
            }
        }

        Log.w(TAG, "setActiveDevice(device=" + device + "): A2DP Sink request failed");
        return false;
    }

@@ -333,15 +339,21 @@ public class AvrcpControllerService extends ProfileService {
            for (AvrcpControllerStateMachine stateMachine : mDeviceStateMap.values()) {
                requestedNode = stateMachine.findNode(parentMediaId);
                if (requestedNode != null) {
                    Log.d(TAG, "Found a node");
                    break;
                }
            }
        }

        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.
        if (requestedNode == null) {
            if (DBG) Log.d(TAG, "Didn't find a node");
            return new BrowseResult(new ArrayList(0), BrowseResult.ERROR_MEDIA_ID_INVALID);
        }
        if (parentMediaId.equals(BrowseTree.ROOT) && requestedNode.getChildrenCount() == 0) {
@@ -355,9 +367,8 @@ public class AvrcpControllerService extends ProfileService {

        List<MediaItem> contents = requestedNode.getContents();

        if (DBG) Log.d(TAG, "Returning contents");
        if (!requestedNode.isCached()) {
            if (DBG) Log.d(TAG, "node is not cached");
            if (DBG) 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
@@ -365,6 +376,10 @@ 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);
    }

+12 −7
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@ public class BluetoothMediaBrowserService extends MediaBrowserServiceCompat {
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action.equals(Intent.ACTION_LOCALE_CHANGED)) {
                if (DBG) Log.d(TAG, "Locale has updated");
                if (sBluetoothMediaBrowserService == null) return;
                MediaSessionCompat session = sBluetoothMediaBrowserService.getSession();
                MediaControllerCompat controller = session.getController();
@@ -106,7 +107,7 @@ public class BluetoothMediaBrowserService extends MediaBrowserServiceCompat {
     */
    @Override
    public void onCreate() {
        if (DBG) Log.d(TAG, "onCreate");
        if (DBG) Log.d(TAG, "Service Created");
        super.onCreate();

        // Create and configure the MediaSessionCompat
@@ -128,6 +129,7 @@ public class BluetoothMediaBrowserService extends MediaBrowserServiceCompat {

    @Override
    public void onDestroy() {
        if (DBG) Log.d(TAG, "Service Destroyed");
        unregisterReceiver(mReceiver);
        mReceiver = null;
    }
@@ -191,6 +193,7 @@ public class BluetoothMediaBrowserService extends MediaBrowserServiceCompat {
        AvrcpControllerService avrcpControllerService =
                AvrcpControllerService.getAvrcpControllerService();
        if (avrcpControllerService == null) {
            Log.w(TAG, "getContents(id=" + parentMediaId + "): AVRCP Controller Service not ready");
            return new BrowseResult(new ArrayList(0), BrowseResult.ERROR_NO_AVRCP_SERVICE);
        } else {
            return avrcpControllerService.getContents(parentMediaId);
@@ -227,7 +230,7 @@ public class BluetoothMediaBrowserService extends MediaBrowserServiceCompat {
    @Override
    public synchronized void onLoadChildren(final String parentMediaId,
            final Result<List<MediaItem>> result) {
        if (DBG) Log.d(TAG, "onLoadChildren parentMediaId= " + parentMediaId);
        if (DBG) Log.d(TAG, "Request for contents, id= " + parentMediaId);
        BrowseResult contents = getContents(parentMediaId);
        byte status = contents.getStatus();
        List<MediaItem> results = contents.getResults();
@@ -236,8 +239,8 @@ public class BluetoothMediaBrowserService extends MediaBrowserServiceCompat {
            result.detach();
        } else {
            if (DBG) {
                Log.d(TAG, "id= " + parentMediaId + ", status= " + contents.getStatusString()
                        + ", results=" + results);
                Log.d(TAG, "Received Contents, id= " + parentMediaId + ", status= "
                        + contents.getStatusString() + ", results=" + results);
            }
            result.sendResult(results);
        }
@@ -245,7 +248,7 @@ public class BluetoothMediaBrowserService extends MediaBrowserServiceCompat {

    @Override
    public BrowserRoot onGetRoot(String clientPackageName, int clientUid, Bundle rootHints) {
        if (DBG) Log.d(TAG, "onGetRoot");
        Log.i(TAG, "Browser Client Connection Request, client='" + clientPackageName + "')");
        Bundle style = getDefaultStyle();
        return new BrowserRoot(BrowseTree.ROOT, style);
    }
@@ -263,6 +266,7 @@ public class BluetoothMediaBrowserService extends MediaBrowserServiceCompat {
        } else {
            mSession.setQueue(null);
        }
        if (DBG) Log.d(TAG, "Now Playing List Changed, queue=" + mMediaQueue);
    }

    private void clearNowPlayingQueue() {
@@ -275,6 +279,7 @@ public class BluetoothMediaBrowserService extends MediaBrowserServiceCompat {
            if (node.getScope() == AvrcpControllerService.BROWSE_SCOPE_NOW_PLAYING) {
                sBluetoothMediaBrowserService.updateNowPlayingQueue(node);
            } else {
                if (DBG) Log.d(TAG, "Browse Node contents changed, node=" + node);
                sBluetoothMediaBrowserService.notifyChildrenChanged(node.getID());
            }
        }
@@ -293,7 +298,7 @@ public class BluetoothMediaBrowserService extends MediaBrowserServiceCompat {
    }

    static synchronized void trackChanged(AvrcpItem track) {
        if (DBG) Log.d(TAG, "trackChanged setMetadata=" + track);
        if (DBG) Log.d(TAG, "Track Changed, track=" + track);
        if (sBluetoothMediaBrowserService != null) {
            if (track != null) {
                sBluetoothMediaBrowserService.mSession.setMetadata(track.toMediaMetadata());
@@ -307,7 +312,7 @@ public class BluetoothMediaBrowserService extends MediaBrowserServiceCompat {
    }

    static synchronized void notifyChanged(PlaybackStateCompat playbackState) {
        Log.d(TAG, "notifyChanged PlaybackState" + playbackState);
        if (DBG) Log.d(TAG, "Playback State Changed, state=" + playbackState);
        if (sBluetoothMediaBrowserService != null) {
            sBluetoothMediaBrowserService.mSession.setPlaybackState(playbackState);
        } else {