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

Commit 43948710 authored by Joseph Pirozzo's avatar Joseph Pirozzo
Browse files

AVRCP Browsing large playlist support

When browsing large playlists with aproximately 1k entries the intent
that delivers content between the AVRCP Controller and Media Browser
Service could grow excessively large.  This patch moves that data into a
service call.

Bug: 72496280
Test: Browse all songs directory with 5000 items.
Change-Id: Ic252ee0b21bb42194a81548ad9af03fd0e86e002
parent b9051ca6
Loading
Loading
Loading
Loading
+38 −1
Original line number Diff line number Diff line
@@ -97,6 +97,7 @@ public class A2dpMediaBrowserService extends MediaBrowserService {
    private static final String CUSTOM_ACTION_GET_PLAY_STATUS_NATIVE =
            "com.android.bluetooth.a2dpsink.mbs.CUSTOM_ACTION_GET_PLAY_STATUS_NATIVE";

    private static A2dpMediaBrowserService sA2dpMediaBrowserService;
    private MediaSession mSession;
    private MediaMetadata mA2dpMetadata;

@@ -185,16 +186,38 @@ public class A2dpMediaBrowserService extends MediaBrowserService {
        synchronized (this) {
            mParentIdToRequestMap.clear();
        }
        setA2dpMediaBrowserService(this);

    }

    @Override
    public void onDestroy() {
        if (DBG) Log.d(TAG, "onDestroy");
        setA2dpMediaBrowserService(null);
        mSession.release();
        unregisterReceiver(mBtReceiver);
        super.onDestroy();
    }


    /**
     *  getA2dpMediaBrowserService()
     *  Routine to get direct access to MediaBrowserService from within the same process.
     */
    public static synchronized A2dpMediaBrowserService getA2dpMediaBrowserService() {
        if (sA2dpMediaBrowserService == null) {
            Log.w(TAG, "getA2dpMediaBrowserService(): service is NULL");
            return null;
        }
        if (DBG) Log.d(TAG, "getA2dpMediaBrowserService(): returning " + sA2dpMediaBrowserService);
        return sA2dpMediaBrowserService;
    }

    private static synchronized void setA2dpMediaBrowserService(A2dpMediaBrowserService instance) {
        if (DBG) Log.d(TAG, "setA2dpMediaBrowserService(): set to: " + instance);
        sA2dpMediaBrowserService = instance;
    }

    @Override
    public BrowserRoot onGetRoot(String clientPackageName, int clientUid, Bundle rootHints) {
        return new BrowserRoot(BrowseTree.ROOT, null);
@@ -549,13 +572,26 @@ public class A2dpMediaBrowserService extends MediaBrowserService {
            Result<List<MediaItem>> results = mParentIdToRequestMap.remove(id);
            if (results == null) {
                Log.w(TAG, "Request no longer exists, notifying that children changed.");
                if (!id.equals("__ROOT__")) {
                    notifyChildrenChanged(id);
                }
            } else {
                results.sendResult(folderList);
            }
        }
    }

    /**
     * processInternalEvent(Intent intent)
     * Routine to provide MediaBrowserService with content updates from within the same process.
     */
    public void processInternalEvent(Intent intent) {
        String action = intent.getAction();
        if (AvrcpControllerService.ACTION_FOLDER_LIST.equals(action)) {
            mAvrcpCommandQueue.obtainMessage(MSG_FOLDER_LIST, intent).sendToTarget();
        }
    }

    private void msgDeviceBrowseDisconnect(BluetoothDevice device) {
        if (DBG) Log.d(TAG, "msgDeviceBrowseDisconnect device " + device);
        // Disconnect only if mA2dpDevice is non null
@@ -566,4 +602,5 @@ public class A2dpMediaBrowserService extends MediaBrowserService {
        }
        mBrowseConnected = false;
    }

}
+7 −1
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import android.util.SparseArray;
import com.android.bluetooth.BluetoothMetricsProto;
import com.android.bluetooth.Utils;
import com.android.bluetooth.a2dpsink.A2dpSinkService;
import com.android.bluetooth.a2dpsink.mbs.A2dpMediaBrowserService;
import com.android.bluetooth.btservice.MetricsLogger;
import com.android.bluetooth.btservice.ProfileService;
import com.android.internal.util.State;
@@ -1181,6 +1182,7 @@ class AvrcpControllerStateMachine extends StateMachine {
            Log.d(TAG, " broadcastMetaDataChanged = " + metadata.getDescription());
        }
        mContext.sendBroadcast(intent, ProfileService.BLUETOOTH_PERM);

    }

    private void broadcastFolderList(String id, ArrayList<MediaItem> items) {
@@ -1188,7 +1190,11 @@ class AvrcpControllerStateMachine extends StateMachine {
        if (VDBG) Log.d(TAG, "broadcastFolderList id " + id + " items " + items);
        intent.putExtra(AvrcpControllerService.EXTRA_FOLDER_ID, id);
        intent.putParcelableArrayListExtra(AvrcpControllerService.EXTRA_FOLDER_LIST, items);
        mContext.sendBroadcast(intent, ProfileService.BLUETOOTH_PERM);
        A2dpMediaBrowserService a2dpMediaBrowserService =
                A2dpMediaBrowserService.getA2dpMediaBrowserService();
        if (a2dpMediaBrowserService != null) {
            a2dpMediaBrowserService.processInternalEvent(intent);
        }
    }

    private void broadcastPlayBackStateChanged(PlaybackState state) {