static void btavrcp_remote_features_callback(bt_bdaddr_t* bd_addr,
btrc_remote_features_t features) {
- ALOGI("%s", __func__);
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
/** Callback for play status request */
static void btavrcp_get_play_status_callback(bt_bdaddr_t* bd_addr) {
- ALOGI("%s", __func__);
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
static void btavrcp_get_element_attr_callback(uint8_t num_attr,
btrc_media_attr_t* p_attrs,
bt_bdaddr_t* bd_addr) {
- ALOGI("%s", __func__);
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
static void btavrcp_volume_change_callback(uint8_t volume, uint8_t ctype,
bt_bdaddr_t* bd_addr) {
- ALOGI("%s", __func__);
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
static void btavrcp_passthrough_command_callback(int id, int pressed,
bt_bdaddr_t* bd_addr) {
- ALOGI("%s", __func__);
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
static void btavrcp_set_addressed_player_callback(uint16_t player_id,
bt_bdaddr_t* bd_addr) {
- ALOGI("%s", __func__);
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
static void btavrcp_set_browsed_player_callback(uint16_t player_id,
bt_bdaddr_t* bd_addr) {
- ALOGI("%s", __func__);
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
if (!mCallbacksObj) {
static void btavrcp_get_folder_items_callback(
uint8_t scope, uint32_t start_item, uint32_t end_item, uint8_t num_attr,
uint32_t* p_attr_ids, bt_bdaddr_t* bd_addr) {
- ALOGI("%s", __func__);
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
static void btavrcp_change_path_callback(uint8_t direction, uint8_t* folder_uid,
bt_bdaddr_t* bd_addr) {
- ALOGI("%s", __func__);
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
uint8_t num_attr,
btrc_media_attr_t* p_attrs,
bt_bdaddr_t* bd_addr) {
- ALOGI("%s", __func__);
CallbackEnv sCallbackEnv(__func__);
if (!sCallbackEnv.valid()) return;
ScopedLocalRef<jbyteArray> attrs(sCallbackEnv.get(),
sCallbackEnv->NewByteArray(BTRC_UID_SIZE));
if (!attrs.get()) {
- ALOGE("%s:Fail to new jByteArray attrs for play_item command", __func__);
+ ALOGE("%s: Fail to new jByteArray attrs for play_item command", __func__);
return;
}
import android.os.Bundle;
import android.util.Log;
+import com.android.bluetooth.btservice.ProfileService;
import com.android.bluetooth.Utils;
import java.nio.ByteBuffer;
boolean sendTrackChangeWithId(boolean requesting, @Nullable MediaController mediaController) {
if (DEBUG)
Log.d(TAG, "sendTrackChangeWithId (" + requesting + "): controller " + mediaController);
- byte[] track;
- long qid = MediaSession.QueueItem.UNKNOWN_ID;
- if (mediaController != null) {
- PlaybackState state = mediaController.getPlaybackState();
- /* for any item associated with NowPlaying, uid is queueId */
- if (state != null) qid = state.getActiveQueueItemId();
- }
- track = ByteBuffer.allocate(AvrcpConstants.UID_SIZE).putLong(qid).array();
+ long qid = getActiveQueueItemId(mediaController);
+ byte[] track = ByteBuffer.allocate(AvrcpConstants.UID_SIZE).putLong(qid).array();
if (DEBUG) Log.d(TAG, "trackChangedRsp: 0x" + Utils.byteArrayToString(track));
int trackChangedNT = AvrcpConstants.NOTIFICATION_TYPE_CHANGED;
if (requesting) trackChangedNT = AvrcpConstants.NOTIFICATION_TYPE_INTERIM;
try {
MediaDescription desc = item.getDescription();
Bundle extras = desc.getExtras();
- if (mediaController != null) {
- PlaybackState state = mediaController.getPlaybackState();
- if (state != null && (item.getQueueId() == state.getActiveQueueItemId())) {
- if (DEBUG) Log.d(TAG, "getAttrValue: item is active, filling extra data");
- extras = fillBundle(mediaController.getMetadata(), extras);
- }
+ if (item.getQueueId() == getActiveQueueItemId(mediaController)) {
+ if (DEBUG) Log.d(TAG, "getAttrValue: item is active, filling extra data");
+ extras = fillBundle(mediaController.getMetadata(), extras);
}
if (DEBUG) Log.d(TAG, "getAttrValue: item " + item + " : " + desc);
switch (attr) {
return;
}
}
+
+ private long getActiveQueueItemId(@Nullable MediaController controller) {
+ if (controller == null) return MediaSession.QueueItem.UNKNOWN_ID;
+ PlaybackState state = controller.getPlaybackState();
+ if (state == null) return MediaSession.QueueItem.UNKNOWN_ID;
+ return state.getActiveQueueItemId();
+ }
+
+ public void dump(StringBuilder sb, @Nullable MediaController mediaController) {
+ ProfileService.println(sb, "AddressedPlayer info:");
+ ProfileService.println(sb, "mLastTrackIdSent: " + mLastTrackIdSent);
+ ProfileService.println(sb, "mNowPlayingList: " + mNowPlayingList);
+ List<MediaSession.QueueItem> queue = getNowPlayingList(mediaController);
+ ProfileService.println(sb, "Current Queue: " + queue.size() + " elements");
+ long currentQueueId = getActiveQueueItemId(mediaController);
+ for (MediaSession.QueueItem item : queue) {
+ long itemId = item.getQueueId();
+ ProfileService.println(sb, (itemId == currentQueueId ? "*" : " ") + item.toString());
+ }
+ }
}
private long mLastReportedPosition;
private long mNextPosMs;
private long mPrevPosMs;
- private long mSkipStartTime;
private int mFeatures;
private int mRemoteVolume;
private int mLastRemoteVolume;
private boolean mVolCmdAdjustInProgress;
private boolean mVolCmdSetInProgress;
private int mAbsVolRetryTimes;
- private int mSkipAmount;
private static final int NO_PLAYER_ID = 0;
case MSG_NATIVE_REQ_GET_PLAY_STATUS:
{
byte[] address = (byte[]) msg.obj;
- if (DEBUG) Log.v(TAG, "MSG_NATIVE_REQ_GET_PLAY_STATUS");
- getPlayStatusRspNative(address, convertPlayStateToPlayStatus(mCurrentPlayState),
- (int) mMediaAttributes.getLength(), (int) getPlayPosition());
+ int btstate = convertPlayStateToPlayStatus(mCurrentPlayState);
+ int length = (int) mMediaAttributes.getLength();
+ int position = (int) getPlayPosition();
+ if (DEBUG)
+ Log.v(TAG, "MSG_NATIVE_REQ_GET_PLAY_STATUS, responding with state " + btstate
+ + " len " + length + " pos " + position);
+ getPlayStatusRspNative(address, btstate, length, position);
break;
}
int[] attrIds = elem.mAttrIDs;
if (DEBUG) Log.v(TAG, "MSG_NATIVE_REQ_GET_ELEM_ATTRS:numAttr=" + numAttr);
textArray = new String[numAttr];
+ StringBuilder responseDebug = new StringBuilder();
+ responseDebug.append("getElementAttr response: ");
for (int i = 0; i < numAttr; ++i) {
textArray[i] = mMediaAttributes.getString(attrIds[i]);
- Log.v(TAG, "getAttributeString:attrId=" + attrIds[i] +
- " str=" + textArray[i]);
+ responseDebug.append("[" + attrIds[i] + "=" + textArray[i] + "] ");
}
+ Log.v(TAG, responseDebug.toString());
byte[] bdaddr = elem.mAddress;
getElementAttrRspNative(bdaddr, numAttr, attrIds, textArray);
break;
break;
case MSG_ADDRESSED_PLAYER_CHANGED_RSP:
- if (DEBUG)
- Log.v(TAG, "MSG_ADDRESSED_PLAYER_CHANGED_RSP: newAddrPlayer = " + msg.arg1);
// Later addressed players override earlier ones.
if (hasMessages(MSG_ADDRESSED_PLAYER_CHANGED_RSP)) {
Log.i(TAG, "MSG_ADDRESSED_PLAYER_CHANGED_RSP: skip, more changes in queue");
break;
}
+ if (DEBUG)
+ Log.v(TAG, "MSG_ADDRESSED_PLAYER_CHANGED_RSP: newAddrPlayer = " + msg.arg1);
registerNotificationRspAddrPlayerChangedNative(
AvrcpConstants.NOTIFICATION_TYPE_CHANGED, msg.arg1, sUIDCounter);
break;
case MSG_NATIVE_REQ_VOLUME_CHANGE:
if (!isAbsoluteVolumeSupported()) {
- if (DEBUG) Log.v(TAG, "ignore MSG_NATIVE_REQ_VOLUME_CHANGE");
+ if (DEBUG) Log.v(TAG, "MSG_NATIVE_REQ_VOLUME_CHANGE ignored, not supported");
break;
}
-
- if (DEBUG) Log.v(TAG, "MSG_NATIVE_REQ_VOLUME_CHANGE: volume=" + ((byte) msg.arg1 & 0x7f)
- + " ctype=" + msg.arg2);
+ byte absVol = (byte) ((byte) msg.arg1 & 0x7f); // discard MSB as it is RFD
+ if (DEBUG)
+ Log.v(TAG, "MSG_NATIVE_REQ_VOLUME_CHANGE: volume=" + absVol + " ctype="
+ + msg.arg2);
boolean volAdj = false;
if (msg.arg2 == AVRC_RSP_ACCEPT || msg.arg2 == AVRC_RSP_REJ) {
mAbsVolRetryTimes = 0;
}
- byte absVol = (byte) ((byte) msg.arg1 & 0x7f); // discard MSB as it is RFD
// convert remote volume to local volume
int volIndex = convertToAudioStreamVolume(absVol);
if (mInitialRemoteVolume == -1) {
}
private void getRcFeaturesRequestFromNative(byte[] address, int features) {
- if (DEBUG) Log.v(TAG, "getRcFeaturesRequestFromNative: address=" + address.toString());
Message msg = mHandler.obtainMessage(MSG_NATIVE_REQ_GET_RC_FEATURES, features, 0,
Utils.getAddressStringFromByte(address));
mHandler.sendMessage(msg);
}
private void getPlayStatusRequestFromNative(byte[] address) {
- if (DEBUG) Log.v(TAG, "getPlayStatusRequestFromNative: address" + address.toString());
Message msg = mHandler.obtainMessage(MSG_NATIVE_REQ_GET_PLAY_STATUS);
msg.obj = address;
mHandler.sendMessage(msg);
}
private void getElementAttrRequestFromNative(byte[] address, byte numAttr, int[] attrs) {
- if (DEBUG) Log.v(TAG, "getElementAttrRequestFromNative: numAttr=" + numAttr);
AvrcpCmd avrcpCmdobj = new AvrcpCmd();
AvrcpCmd.ElementAttrCmd elemAttr = avrcpCmdobj.new ElementAttrCmd(address, numAttr, attrs);
Message msg = mHandler.obtainMessage(MSG_NATIVE_REQ_GET_ELEM_ATTRS);
}
private void registerNotificationRequestFromNative(byte[] address,int eventId, int param) {
- if (DEBUG) Log.v(TAG, "registerNotificationRequestFromNative: eventId=" + eventId);
Message msg = mHandler.obtainMessage(MSG_NATIVE_REQ_REGISTER_NOTIFICATION, eventId, param);
msg.obj = address;
mHandler.sendMessage(msg);
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,
startItem, endItem, numAttr, attrIds);
}
private void setAddressedPlayerRequestFromNative(byte[] address, int playerId) {
- if (DEBUG) Log.v(TAG, "setAddrPlayerRequestFromNative: playerId=" + playerId);
Message msg = mHandler.obtainMessage(MSG_NATIVE_REQ_SET_ADDR_PLAYER, playerId, 0);
msg.obj = address;
mHandler.sendMessage(msg);
}
private void setBrowsedPlayerRequestFromNative(byte[] address, int playerId) {
- if (DEBUG) Log.v(TAG, "setBrPlayerRequestFromNative: playerId=" + playerId);
Message msg = mHandler.obtainMessage(MSG_NATIVE_REQ_SET_BR_PLAYER, playerId, 0);
msg.obj = address;
mHandler.sendMessage(msg);
}
private void changePathRequestFromNative(byte[] address, byte direction, byte[] folderUid) {
- if (DEBUG) Log.v(TAG, "changePathRequestFromNative: direction=" + direction);
Bundle data = new Bundle();
Message msg = mHandler.obtainMessage(MSG_NATIVE_REQ_CHANGE_PATH);
data.putByteArray("BdAddress" , address);
private void getItemAttrRequestFromNative(byte[] address, byte scope, byte[] itemUid, int uidCounter,
byte numAttr, int[] attrs) {
- if (DEBUG) Log.v(TAG, "getItemAttrRequestFromNative: scope=" + scope + ", numAttr=" + numAttr);
AvrcpCmd avrcpCmdobj = new AvrcpCmd();
AvrcpCmd.ItemAttrCmd itemAttr = avrcpCmdobj.new ItemAttrCmd(address, scope,
itemUid, uidCounter, numAttr, attrs);
}
private void searchRequestFromNative(byte[] address, int charsetId, byte[] searchStr) {
- if (DEBUG) Log.v(TAG, "searchRequestFromNative");
/* Search is not supported */
- if (DEBUG) Log.d(TAG, "search is not supported");
+ Log.w(TAG, "searchRequestFromNative: search is not supported");
searchRspNative(address, AvrcpConstants.RSP_SRCH_NOT_SPRTD, 0, 0);
}
private void playItemRequestFromNative(byte[] address, byte scope, int uidCounter, byte[] uid) {
- if (DEBUG) Log.v(TAG, "playItemRequestFromNative: scope=" + scope);
Bundle data = new Bundle();
Message msg = mHandler.obtainMessage(MSG_NATIVE_REQ_PLAY_ITEM);
data.putByteArray("BdAddress" , address);
}
private void addToPlayListRequestFromNative(byte[] address, byte scope, byte[] uid, int uidCounter) {
- if (DEBUG) Log.v(TAG, "addToPlayListRequestFromNative: scope=" + scope);
/* add to NowPlaying not supported */
- Log.w(TAG, "Add to NowPlayingList is not supported");
+ Log.w(TAG, "addToPlayListRequestFromNative: not supported! scope=" + scope);
addToNowPlayingRspNative(address, AvrcpConstants.RSP_INTERNAL_ERR);
}
private void getTotalNumOfItemsRequestFromNative(byte[] address, byte scope) {
- if (DEBUG) Log.v(TAG, "getTotalNumOfItemsRequestFromNative: scope=" + scope);
Bundle data = new Bundle();
Message msg = mHandler.obtainMessage(MSG_NATIVE_REQ_GET_TOTAL_NUM_OF_ITEMS);
msg.arg1 = scope;
ProfileService.println(sb, "mPlayPosChangedNT: " + mPlayPosChangedNT);
ProfileService.println(sb, "mNextPosMs: " + mNextPosMs);
ProfileService.println(sb, "mPrevPosMs: " + mPrevPosMs);
- ProfileService.println(sb, "mSkipStartTime: " + mSkipStartTime);
ProfileService.println(sb, "mFeatures: " + mFeatures);
ProfileService.println(sb, "mRemoteVolume: " + mRemoteVolume);
ProfileService.println(sb, "mLastRemoteVolume: " + mLastRemoteVolume);
ProfileService.println(sb, "mVolCmdAdjustInProgress: " + mVolCmdAdjustInProgress);
ProfileService.println(sb, "mVolCmdSetInProgress: " + mVolCmdSetInProgress);
ProfileService.println(sb, "mAbsVolRetryTimes: " + mAbsVolRetryTimes);
- ProfileService.println(sb, "mSkipAmount: " + mSkipAmount);
ProfileService.println(sb, "mVolumeMapping: " + mVolumeMapping.toString());
if (mMediaController != null)
ProfileService.println(sb, "mMediaController: " + mMediaController.getWrappedInstance()
}
}
+ ProfileService.println(sb, "");
+ mAddressedMediaPlayer.dump(sb, mMediaController);
+
+ ProfileService.println(sb, "");
ProfileService.println(sb, mPassthroughDispatched + " passthrough operations: ");
if (mPassthroughDispatched > mPassthroughLogs.size())
ProfileService.println(sb, " (last " + mPassthroughLogs.size() + ")");