summaryrefslogtreecommitdiffstats
path: root/src/com/android/bluetooth/a2dp
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/bluetooth/a2dp')
-rw-r--r--src/com/android/bluetooth/a2dp/A2dpService.java8
-rw-r--r--src/com/android/bluetooth/a2dp/A2dpStateMachine.java10
-rw-r--r--src/com/android/bluetooth/a2dp/Avrcp.java46
3 files changed, 53 insertions, 11 deletions
diff --git a/src/com/android/bluetooth/a2dp/A2dpService.java b/src/com/android/bluetooth/a2dp/A2dpService.java
index 22c6081b9..7c5721b60 100644
--- a/src/com/android/bluetooth/a2dp/A2dpService.java
+++ b/src/com/android/bluetooth/a2dp/A2dpService.java
@@ -37,7 +37,7 @@ import java.util.Map;
* @hide
*/
public class A2dpService extends ProfileService {
- private static final boolean DBG = false;
+ private static final boolean DBG = true;
private static final String TAG="A2dpService";
private A2dpStateMachine mStateMachine;
@@ -60,8 +60,8 @@ public class A2dpService extends ProfileService {
}
protected boolean start() {
- mStateMachine = A2dpStateMachine.make(this, this);
mAvrcp = Avrcp.make(this);
+ mStateMachine = A2dpStateMachine.make(this, this);
setA2dpService(this);
return true;
}
@@ -236,6 +236,10 @@ public class A2dpService extends ProfileService {
mAvrcp.setAbsoluteVolume(volume);
}
+ public void setAvrcpAudioState(int state) {
+ mAvrcp.setA2dpAudioState(state);
+ }
+
synchronized boolean isA2dpPlaying(BluetoothDevice device) {
enforceCallingOrSelfPermission(BLUETOOTH_PERM,
"Need BLUETOOTH permission");
diff --git a/src/com/android/bluetooth/a2dp/A2dpStateMachine.java b/src/com/android/bluetooth/a2dp/A2dpStateMachine.java
index b88e7b11c..7648acd90 100644
--- a/src/com/android/bluetooth/a2dp/A2dpStateMachine.java
+++ b/src/com/android/bluetooth/a2dp/A2dpStateMachine.java
@@ -62,7 +62,7 @@ import java.util.List;
import java.util.Set;
final class A2dpStateMachine extends StateMachine {
- private static final boolean DBG = false;
+ private static final boolean DBG = true;
static final int CONNECT = 1;
static final int DISCONNECT = 2;
@@ -656,14 +656,16 @@ final class A2dpStateMachine extends StateMachine {
switch (state) {
case AUDIO_STATE_STARTED:
if (mPlayingA2dpDevice == null) {
- mPlayingA2dpDevice = device;
- broadcastAudioState(device, BluetoothA2dp.STATE_PLAYING,
- BluetoothA2dp.STATE_NOT_PLAYING);
+ mPlayingA2dpDevice = device;
+ mService.setAvrcpAudioState(BluetoothA2dp.STATE_PLAYING);
+ broadcastAudioState(device, BluetoothA2dp.STATE_PLAYING,
+ BluetoothA2dp.STATE_NOT_PLAYING);
}
break;
case AUDIO_STATE_STOPPED:
if (mPlayingA2dpDevice != null) {
mPlayingA2dpDevice = null;
+ mService.setAvrcpAudioState(BluetoothA2dp.STATE_NOT_PLAYING);
broadcastAudioState(device, BluetoothA2dp.STATE_NOT_PLAYING,
BluetoothA2dp.STATE_PLAYING);
}
diff --git a/src/com/android/bluetooth/a2dp/Avrcp.java b/src/com/android/bluetooth/a2dp/Avrcp.java
index f2d559801..6ad7d28b9 100644
--- a/src/com/android/bluetooth/a2dp/Avrcp.java
+++ b/src/com/android/bluetooth/a2dp/Avrcp.java
@@ -20,6 +20,7 @@ import java.util.Timer;
import java.util.TimerTask;
import android.app.PendingIntent;
+import android.bluetooth.BluetoothA2dp;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
@@ -124,8 +125,9 @@ final class Avrcp {
private static final int MESSAGE_FAST_FORWARD = 10;
private static final int MESSAGE_REWIND = 11;
private static final int MESSAGE_CHANGE_PLAY_POS = 12;
+ private static final int MESSAGE_SET_A2DP_AUDIO_STATE = 13;
- private static final int MESSAGE_SET_ADDR_PLAYER_REQ_TIMEOUT = 13;
+ private static final int MESSAGE_SET_ADDR_PLAYER_REQ_TIMEOUT = 14;
private static final int SET_ADDR_PLAYER_TIMEOUT = 2000;
private int mAddressedPlayerChangedNT;
@@ -777,10 +779,24 @@ final class Avrcp {
int isAvailable = msg.arg2;
processRCCStateChange(callingPackageName, isFocussed, isAvailable);
break;
+
+ case MESSAGE_SET_A2DP_AUDIO_STATE:
+ if (DEBUG) Log.v(TAG, "MESSAGE_SET_A2DP_AUDIO_STATE:" + msg.arg1);
+ updateA2dpAudioState(msg.arg1);
+ break;
}
}
}
+ private void updateA2dpAudioState(int state) {
+ boolean isPlaying = (state == BluetoothA2dp.STATE_PLAYING);
+ if (isPlaying != isPlayingState(mCurrentPlayState)) {
+ updatePlayPauseState(isPlaying ? RemoteControlClient.PLAYSTATE_PLAYING :
+ RemoteControlClient.PLAYSTATE_PAUSED,
+ RemoteControlClient.PLAYBACK_POSITION_INVALID);
+ }
+ }
+
private void updatePlayPauseState(int state, long currentPosMs) {
if (DEBUG) Log.v(TAG,"updatePlayPauseState");
boolean oldPosValid = (mCurrentPosMs !=
@@ -951,9 +967,6 @@ final class Avrcp {
while (rccIterator.hasNext()) {
final MediaPlayerInfo di = rccIterator.next();
if (di.GetPlayerFocus()) {
- if (DEBUG) Log.v(TAG, "incrementing TrackNumber:" + mTrackNumber + "by 1");
- mTrackNumber = di.GetTrackNumber();
- mTrackNumber ++;
di.SetTrackNumber(mTrackNumber);
break;
}
@@ -978,6 +991,7 @@ final class Avrcp {
mMetadata.trackTitle = getMdString(data, MediaMetadataRetriever.METADATA_KEY_TITLE);
mMetadata.albumTitle = getMdString(data, MediaMetadataRetriever.METADATA_KEY_ALBUM);
mMetadata.genre = getMdString(data, MediaMetadataRetriever.METADATA_KEY_GENRE);
+ mTrackNumber = getMdLong(data, MediaMetadataRetriever.METADATA_KEY_NUM_TRACKS);
mMetadata.tracknum = getMdLong(data, MediaMetadataRetriever.METADATA_KEY_CD_TRACK_NUMBER);
Log.v(TAG,"mMetadata.toString() = " + mMetadata.toString());
@@ -1399,6 +1413,20 @@ final class Avrcp {
return playStatus;
}
+ private boolean isPlayingState(int playState) {
+ boolean isPlaying = false;
+ switch (playState) {
+ case RemoteControlClient.PLAYSTATE_PLAYING:
+ case RemoteControlClient.PLAYSTATE_BUFFERING:
+ isPlaying = true;
+ break;
+ default:
+ isPlaying = false;
+ break;
+ }
+ return isPlaying;
+ }
+
/**
* This is called from AudioService. It will return whether this device supports abs volume.
* NOT USED AT THE MOMENT.
@@ -1445,7 +1473,7 @@ final class Avrcp {
private int convertToAudioStreamVolume(int volume) {
// Rescale volume to match AudioSystem's volume
- return (int) Math.ceil((double) volume*mAudioStreamMax/AVRCP_MAX_VOL);
+ return (int) Math.round((double) volume*mAudioStreamMax/AVRCP_MAX_VOL);
}
private int convertToAvrcpVolume(int volume) {
@@ -1587,6 +1615,14 @@ private void updateLocalPlayerSettings( byte[] data) {
mHandler.sendMessageDelayed(msg, 130);
}
+ /**
+ * This is called from A2dpStateMachine to set A2dp audio state.
+ */
+ public void setA2dpAudioState(int state) {
+ Message msg = mHandler.obtainMessage(MESSAGE_SET_A2DP_AUDIO_STATE, state, 0);
+ mHandler.sendMessage(msg);
+ }
+
// Do not modify without updating the HAL bt_rc.h files.
// match up with btrc_play_status_t enum of bt_rc.h