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

Commit 6ca8fba9 authored by Marie Janssen's avatar Marie Janssen
Browse files

AVRCP: Fix getFolderItems with all items request

start item and end item are uint32_t
0xFFFFFFFF is commonly used as an indicator for "all items" end value.

Using a jint (int32_t) doesn't work, use jlong instead.

Test: browse with audi kit
Bug: 35385700
Bug: 36645066
Change-Id: I364f70a8b985796a6bcc83148a4ecc368a0c0493
(cherry picked from commit aabff2d74224e1d122a2ae767330a69b9324779e)
parent d0cf5905
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -295,9 +295,9 @@ static void btavrcp_get_folder_items_callback(
                                    (jint*)puiAttr);
  }

  sCallbackEnv->CallVoidMethod(mCallbacksObj, method_getFolderItemsCallback,
                               addr.get(), (jbyte)scope, (jint)start_item,
                               (jint)end_item, (jbyte)num_attr, attr_ids.get());
  sCallbackEnv->CallVoidMethod(
      mCallbacksObj, method_getFolderItemsCallback, addr.get(), (jbyte)scope,
      (jlong)start_item, (jlong)end_item, (jbyte)num_attr, attr_ids.get());
}

static void btavrcp_change_path_callback(uint8_t direction, uint8_t* folder_uid,
@@ -547,7 +547,7 @@ static void classInitNative(JNIEnv* env, jclass clazz) {
      env->GetMethodID(clazz, "setBrowsedPlayerRequestFromNative", "([BI)V");

  method_getFolderItemsCallback =
      env->GetMethodID(clazz, "getFolderItemsRequestFromNative", "([BBIIB[I)V");
      env->GetMethodID(clazz, "getFolderItemsRequestFromNative", "([BBJJB[I)V");

  method_changePathCallback =
      env->GetMethodID(clazz, "changePathRequestFromNative", "([BB[B)V");
+5 −3
Original line number Diff line number Diff line
@@ -264,10 +264,12 @@ public class AddressedMediaPlayer {
     * MediaItem list. (Resultset containing all items in current path)
     */
    private List<MediaSession.QueueItem> checkIndexOutofBounds(
            byte[] bdaddr, List<MediaSession.QueueItem> items, int startItem, int endItem) {
            byte[] bdaddr, List<MediaSession.QueueItem> items, long startItem, long endItem) {
        if (endItem > items.size()) endItem = items.size() - 1;
        if (startItem > Integer.MAX_VALUE) startItem = Integer.MAX_VALUE;
        try {
            List<MediaSession.QueueItem> selected =
                    items.subList(startItem, Math.min(items.size(), endItem + 1));
                    items.subList((int) startItem, (int) Math.min(items.size(), endItem + 1));
            if (selected.isEmpty()) {
                Log.i(TAG, "itemsSubList is empty.");
                return null;
@@ -286,7 +288,7 @@ public class AddressedMediaPlayer {
     * response
     */
    private void getFolderItemsFilterAttr(byte[] bdaddr, AvrcpCmd.FolderItemsCmd folderItemsReqObj,
            List<MediaSession.QueueItem> items, byte scope, int startItem, int endItem,
            List<MediaSession.QueueItem> items, byte scope, long startItem, long endItem,
            MediaController mediaController) {
        if (DEBUG) Log.d(TAG, "getFolderItemsFilterAttr: startItem =" + startItem + ", endItem = "
                + endItem);
+2 −2
Original line number Diff line number Diff line
@@ -1233,8 +1233,8 @@ public final class Avrcp {
        mHandler.sendMessage(msg);
    }

    private void getFolderItemsRequestFromNative(byte[] address, byte scope, int startItem, int endItem,
            byte numAttr, int[] attrIds) {
    private void getFolderItemsRequestFromNative(
            byte[] address, byte scope, long startItem, long endItem, byte numAttr, int[] attrIds) {
        if (DEBUG) Log.v(TAG, "getFolderItemsRequestFromNative: scope=" + scope + ", numAttr=" + numAttr);
        AvrcpCmd avrcpCmdobj = new AvrcpCmd();
        AvrcpCmd.FolderItemsCmd folderObj = avrcpCmdobj.new FolderItemsCmd(address, scope,
+4 −4
Original line number Diff line number Diff line
@@ -36,14 +36,14 @@ class AvrcpCmd {
    /* Helper classes to pass parameters from callbacks to Avrcp handler */
    class FolderItemsCmd {
        byte mScope;
        int mStartItem;
        int mEndItem;
        long mStartItem;
        long mEndItem;
        byte mNumAttr;
        int[] mAttrIDs;
        public byte[] mAddress;

        public FolderItemsCmd(byte[] address,byte scope, int startItem, int endItem, byte numAttr,
                int[] attrIds) {
        public FolderItemsCmd(byte[] address, byte scope, long startItem, long endItem,
                byte numAttr, int[] attrIds) {
            mAddress = address;
            this.mScope = scope;
            this.mStartItem = startItem;
+6 −4
Original line number Diff line number Diff line
@@ -438,11 +438,13 @@ class BrowsedMediaPlayer {
     * helper method to check if startItem and endItem index is with range of
     * MediaItem list. (Resultset containing all items in current path)
     */
    private List<MediaBrowser.MediaItem> checkIndexOutofBounds(byte[] bdaddr,
        List<MediaBrowser.MediaItem> children, int startItem, int endItem) {
    private List<MediaBrowser.MediaItem> checkIndexOutofBounds(
            byte[] bdaddr, List<MediaBrowser.MediaItem> children, long startItem, long endItem) {
        if (endItem > children.size()) endItem = children.size() - 1;
        if (startItem >= Integer.MAX_VALUE) startItem = Integer.MAX_VALUE;
        try {
            List<MediaBrowser.MediaItem> childrenSubList =
                children.subList(startItem, Math.min(children.size(), endItem + 1));
                    children.subList((int) startItem, (int) endItem + 1);
            if (childrenSubList.isEmpty()) {
                Log.i(TAG, "childrenSubList is empty.");
                throw new IndexOutOfBoundsException();
@@ -465,7 +467,7 @@ class BrowsedMediaPlayer {
     * helper method to filter required attibutes before sending GetFolderItems response
     */
    public void getFolderItemsFilterAttr(byte[] bdaddr, AvrcpCmd.FolderItemsCmd mFolderItemsReqObj,
        List<MediaBrowser.MediaItem> children, byte scope, int startItem, int endItem) {
            List<MediaBrowser.MediaItem> children, byte scope, long startItem, long endItem) {
        if (DEBUG) Log.d(TAG, "getFolderItemsFilterAttr: startItem =" + startItem +
            ", endItem = " + endItem);