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

Commit 1600cbe7 authored by Joseph Pirozzo's avatar Joseph Pirozzo
Browse files

AVRCP controller browsing range limit

Previous code was erroneously only considering lowest byte of integer
length for start and stop range resulting in incorrect results when
getting folder contents.  Updated to use full 32 bits of range, and
allow early exit from long running commands.

Bug: 72496280
Test: stream music and browse at the same time.

Change-Id: I3a1ed990a6e9612c79535348137cfaa428a11d46
parent a60c0cdb
Loading
Loading
Loading
Loading
+10 −11
Original line number Original line Diff line number Diff line
@@ -545,7 +545,7 @@ static void btavrcp_get_folder_items_callback(
  }
  }
}
}


static void btavrcp_change_path_callback(RawAddress* bd_addr, uint8_t count) {
static void btavrcp_change_path_callback(RawAddress* bd_addr, uint32_t count) {
  ALOGI("%s count %d", __func__, count);
  ALOGI("%s count %d", __func__, count);
  CallbackEnv sCallbackEnv(__func__);
  CallbackEnv sCallbackEnv(__func__);
  if (!sCallbackEnv.valid()) return;
  if (!sCallbackEnv.valid()) return;
@@ -882,8 +882,7 @@ static void getPlaybackStateNative(JNIEnv* env, jobject object,
}
}


static void getNowPlayingListNative(JNIEnv* env, jobject object,
static void getNowPlayingListNative(JNIEnv* env, jobject object,
                                    jbyteArray address, jbyte start,
                                    jbyteArray address, jint start, jint end) {
                                    jbyte items) {
  if (!sBluetoothAvrcpInterface) return;
  if (!sBluetoothAvrcpInterface) return;
  jbyte* addr = env->GetByteArrayElements(address, NULL);
  jbyte* addr = env->GetByteArrayElements(address, NULL);
  if (!addr) {
  if (!addr) {
@@ -892,7 +891,7 @@ static void getNowPlayingListNative(JNIEnv* env, jobject object,
  }
  }
  ALOGV("%s: sBluetoothAvrcpInterface: %p", __func__, sBluetoothAvrcpInterface);
  ALOGV("%s: sBluetoothAvrcpInterface: %p", __func__, sBluetoothAvrcpInterface);
  bt_status_t status = sBluetoothAvrcpInterface->get_now_playing_list_cmd(
  bt_status_t status = sBluetoothAvrcpInterface->get_now_playing_list_cmd(
      (RawAddress*)addr, (uint8_t)start, (uint8_t)items);
      (RawAddress*)addr, start, end);
  if (status != BT_STATUS_SUCCESS) {
  if (status != BT_STATUS_SUCCESS) {
    ALOGE("Failed sending getNowPlayingListNative command, status: %d", status);
    ALOGE("Failed sending getNowPlayingListNative command, status: %d", status);
  }
  }
@@ -900,7 +899,7 @@ static void getNowPlayingListNative(JNIEnv* env, jobject object,
}
}


static void getFolderListNative(JNIEnv* env, jobject object, jbyteArray address,
static void getFolderListNative(JNIEnv* env, jobject object, jbyteArray address,
                                jbyte start, jbyte items) {
                                jint start, jint end) {
  if (!sBluetoothAvrcpInterface) return;
  if (!sBluetoothAvrcpInterface) return;
  jbyte* addr = env->GetByteArrayElements(address, NULL);
  jbyte* addr = env->GetByteArrayElements(address, NULL);
  if (!addr) {
  if (!addr) {
@@ -909,7 +908,7 @@ static void getFolderListNative(JNIEnv* env, jobject object, jbyteArray address,
  }
  }
  ALOGV("%s: sBluetoothAvrcpInterface: %p", __func__, sBluetoothAvrcpInterface);
  ALOGV("%s: sBluetoothAvrcpInterface: %p", __func__, sBluetoothAvrcpInterface);
  bt_status_t status = sBluetoothAvrcpInterface->get_folder_list_cmd(
  bt_status_t status = sBluetoothAvrcpInterface->get_folder_list_cmd(
      (RawAddress*)addr, (uint8_t)start, (uint8_t)items);
      (RawAddress*)addr, start, end);
  if (status != BT_STATUS_SUCCESS) {
  if (status != BT_STATUS_SUCCESS) {
    ALOGE("Failed sending getFolderListNative command, status: %d", status);
    ALOGE("Failed sending getFolderListNative command, status: %d", status);
  }
  }
@@ -917,7 +916,7 @@ static void getFolderListNative(JNIEnv* env, jobject object, jbyteArray address,
}
}


static void getPlayerListNative(JNIEnv* env, jobject object, jbyteArray address,
static void getPlayerListNative(JNIEnv* env, jobject object, jbyteArray address,
                                jbyte start, jbyte items) {
                                jint start, jint end) {
  if (!sBluetoothAvrcpInterface) return;
  if (!sBluetoothAvrcpInterface) return;
  jbyte* addr = env->GetByteArrayElements(address, NULL);
  jbyte* addr = env->GetByteArrayElements(address, NULL);
  if (!addr) {
  if (!addr) {
@@ -927,7 +926,7 @@ static void getPlayerListNative(JNIEnv* env, jobject object, jbyteArray address,
  ALOGI("%s: sBluetoothAvrcpInterface: %p", __func__, sBluetoothAvrcpInterface);
  ALOGI("%s: sBluetoothAvrcpInterface: %p", __func__, sBluetoothAvrcpInterface);


  bt_status_t status = sBluetoothAvrcpInterface->get_player_list_cmd(
  bt_status_t status = sBluetoothAvrcpInterface->get_player_list_cmd(
      (RawAddress*)addr, (uint8_t)start, (uint8_t)items);
      (RawAddress*)addr, start, end);
  if (status != BT_STATUS_SUCCESS) {
  if (status != BT_STATUS_SUCCESS) {
    ALOGE("Failed sending getPlayerListNative command, status: %d", status);
    ALOGE("Failed sending getPlayerListNative command, status: %d", status);
  }
  }
@@ -1035,9 +1034,9 @@ static JNINativeMethod sMethods[] = {
    {"sendRegisterAbsVolRspNative", "([BBII)V",
    {"sendRegisterAbsVolRspNative", "([BBII)V",
     (void*)sendRegisterAbsVolRspNative},
     (void*)sendRegisterAbsVolRspNative},
    {"getPlaybackStateNative", "([B)V", (void*)getPlaybackStateNative},
    {"getPlaybackStateNative", "([B)V", (void*)getPlaybackStateNative},
    {"getNowPlayingListNative", "([BBB)V", (void*)getNowPlayingListNative},
    {"getNowPlayingListNative", "([BII)V", (void*)getNowPlayingListNative},
    {"getFolderListNative", "([BBB)V", (void*)getFolderListNative},
    {"getFolderListNative", "([BII)V", (void*)getFolderListNative},
    {"getPlayerListNative", "([BBB)V", (void*)getPlayerListNative},
    {"getPlayerListNative", "([BII)V", (void*)getPlayerListNative},
    {"changeFolderPathNative", "([BB[B)V", (void*)changeFolderPathNative},
    {"changeFolderPathNative", "([BB[B)V", (void*)changeFolderPathNative},
    {"playItemNative", "([BB[BI)V", (void*)playItemNative},
    {"playItemNative", "([BB[BI)V", (void*)playItemNative},
    {"setBrowsedPlayerNative", "([BI)V", (void*)setBrowsedPlayerNative},
    {"setBrowsedPlayerNative", "([BI)V", (void*)setBrowsedPlayerNative},
+3 −3
Original line number Original line Diff line number Diff line
@@ -1120,13 +1120,13 @@ public class AvrcpControllerService extends ProfileService {
    static native void getPlaybackStateNative(byte[] address);
    static native void getPlaybackStateNative(byte[] address);


    /* API used to fetch the current now playing list */
    /* API used to fetch the current now playing list */
    static native void getNowPlayingListNative(byte[] address, byte start, byte end);
    static native void getNowPlayingListNative(byte[] address, int start, int end);


    /* API used to fetch the current folder's listing */
    /* API used to fetch the current folder's listing */
    static native void getFolderListNative(byte[] address, byte start, byte end);
    static native void getFolderListNative(byte[] address, int start, int end);


    /* API used to fetch the listing of players */
    /* API used to fetch the listing of players */
    static native void getPlayerListNative(byte[] address, byte start, byte end);
    static native void getPlayerListNative(byte[] address, int start, int end);


    /* API used to change the folder */
    /* API used to change the folder */
    static native void changeFolderPathNative(byte[] address, byte direction, byte[] uid);
    static native void changeFolderPathNative(byte[] address, byte direction, byte[] uid);
+14 −4
Original line number Original line Diff line number Diff line
@@ -315,7 +315,7 @@ class AvrcpControllerStateMachine extends StateMachine {


                    case MESSAGE_PROCESS_SET_ADDRESSED_PLAYER:
                    case MESSAGE_PROCESS_SET_ADDRESSED_PLAYER:
                        AvrcpControllerService.getPlayerListNative(
                        AvrcpControllerService.getPlayerListNative(
                                mRemoteDevice.getBluetoothAddress(), (byte) 0, (byte) 255);
                                mRemoteDevice.getBluetoothAddress(), 0, 255);
                        transitionTo(mGetPlayerListing);
                        transitionTo(mGetPlayerListing);
                        sendMessageDelayed(MESSAGE_INTERNAL_CMD_TIMEOUT, CMD_TIMEOUT_MILLIS);
                        sendMessageDelayed(MESSAGE_INTERNAL_CMD_TIMEOUT, CMD_TIMEOUT_MILLIS);
                        break;
                        break;
@@ -598,7 +598,7 @@ class AvrcpControllerStateMachine extends StateMachine {
                        transitionTo(mConnected);
                        transitionTo(mConnected);
                    } else {
                    } else {
                        // Fetch the next set of items.
                        // Fetch the next set of items.
                        callNativeFunctionForScope((byte) mCurrInd, (byte) Math.min(mEndInd,
                        callNativeFunctionForScope(mCurrInd, Math.min(mEndInd,
                                mCurrInd + GET_FOLDER_ITEMS_PAGINATION_SIZE - 1));
                                mCurrInd + GET_FOLDER_ITEMS_PAGINATION_SIZE - 1));
                        // Reset the timeout message since we are doing a new fetch now.
                        // Reset the timeout message since we are doing a new fetch now.
                        removeMessages(MESSAGE_INTERNAL_CMD_TIMEOUT);
                        removeMessages(MESSAGE_INTERNAL_CMD_TIMEOUT);
@@ -620,6 +620,16 @@ class AvrcpControllerStateMachine extends StateMachine {
                    transitionTo(mConnected);
                    transitionTo(mConnected);
                    break;
                    break;


                case MESSAGE_CHANGE_FOLDER_PATH:
                case MESSAGE_FETCH_ATTR_AND_PLAY_ITEM:
                case MESSAGE_GET_PLAYER_LIST:
                case MESSAGE_GET_NOW_PLAYING_LIST:
                case MESSAGE_SET_BROWSED_PLAYER:
                    // A new request has come in, no need to fetch more.
                    mEndInd = 0;
                    deferMessage(msg);
                    break;

                case MESSAGE_SEND_PASS_THROUGH_CMD:
                case MESSAGE_SEND_PASS_THROUGH_CMD:
                case MESSAGE_SEND_GROUP_NAVIGATION_CMD:
                case MESSAGE_SEND_GROUP_NAVIGATION_CMD:
                case MESSAGE_PROCESS_SET_ABS_VOL_CMD:
                case MESSAGE_PROCESS_SET_ABS_VOL_CMD:
@@ -673,11 +683,11 @@ class AvrcpControllerStateMachine extends StateMachine {
            switch (mScope) {
            switch (mScope) {
                case AvrcpControllerService.BROWSE_SCOPE_NOW_PLAYING:
                case AvrcpControllerService.BROWSE_SCOPE_NOW_PLAYING:
                    AvrcpControllerService.getNowPlayingListNative(
                    AvrcpControllerService.getNowPlayingListNative(
                            mRemoteDevice.getBluetoothAddress(), (byte) start, (byte) end);
                            mRemoteDevice.getBluetoothAddress(), start, end);
                    break;
                    break;
                case AvrcpControllerService.BROWSE_SCOPE_VFS:
                case AvrcpControllerService.BROWSE_SCOPE_VFS:
                    AvrcpControllerService.getFolderListNative(mRemoteDevice.getBluetoothAddress(),
                    AvrcpControllerService.getFolderListNative(mRemoteDevice.getBluetoothAddress(),
                            (byte) start, (byte) end);
                            start, end);
                    break;
                    break;
                default:
                default:
                    Log.e(STATE_TAG, "Scope " + mScope + " cannot be handled here.");
                    Log.e(STATE_TAG, "Scope " + mScope + " cannot be handled here.");