Merge b1f1ac7fa309e24e904af71203195d6a6563c1e7 on remote branch
Change-Id: I4a907af7ec7df7646b604167abbdc46a2e8f9b9c
diff --git a/packages_apps_bluetooth_ext/src/avrcp/Avrcp_ext.java b/packages_apps_bluetooth_ext/src/avrcp/Avrcp_ext.java
index 49768e3..115d4cf 100644
--- a/packages_apps_bluetooth_ext/src/avrcp/Avrcp_ext.java
+++ b/packages_apps_bluetooth_ext/src/avrcp/Avrcp_ext.java
@@ -178,8 +178,6 @@
public static final String ABS_VOL_MAP = "bluetooth_ABS_VOL_map";
private boolean isShoActive = false;
private boolean twsShoEnabled = false;
- byte[] dummyaddr = {(byte)0xFA, (byte)0xCE, (byte)0xFA,
- (byte)0xCE, (byte)0xFA, (byte)0xCE};
private static final String playerStateUpdateBlackListedAddr[] = {
"BC:30:7E", //bc-30-7e-5e-f6-27, Name: Porsche BT 0310; bc-30-7e-8c-22-cb, Name: Audi MMI 1193
"2C:DC:AD", //2C-DC-AD-BB-2F-25, Name: PORSCHE
@@ -196,7 +194,6 @@
"Porsche"
};
-
private static final ArrayList<String> playerBrowseWhiteListDB =
new ArrayList<String>(Arrays.asList(
"com.google.android.music",
@@ -268,9 +265,6 @@
public static final int AVRC_ID_VOL_DOWN = 0x42;
private static final int SET_MEDIA_SESSION_DELAY = 300;
- /* Communicates with MediaPlayer to fetch media content */
- private BrowsedMediaPlayer_ext mBrowsedMediaPlayer;
-
/* Addressed player handling */
private AddressedMediaPlayer_ext mAddressedMediaPlayer;
@@ -278,8 +272,6 @@
private SortedMap<Integer, MediaPlayerInfo_ext> mMediaPlayerInfoList;
private boolean mAvailablePlayerViewChanged;
- private List<String> mPkgRequestedMBSConnect;
-
/* List of media players which supports browse */
private List<BrowsePlayerInfo_ext> mBrowsePlayerInfoList;
@@ -390,7 +382,7 @@
public DeviceDependentFeature(Context context) {
mContext = context;
mCurrentDevice = null;
- mCurrentPlayState = new PlaybackState.Builder().setState(PlaybackState.STATE_NONE, -1L, 0.0f).build();;
+ mCurrentPlayState = new PlaybackState.Builder().setState(PlaybackState.STATE_NONE, -1L, 0.0f).build();
mPlayStatusChangedNT = AvrcpConstants_ext.NOTIFICATION_TYPE_CHANGED;
mNowPlayingListChangedNT = AvrcpConstants_ext.NOTIFICATION_TYPE_CHANGED;
mAddrPlayerChangedNT = AvrcpConstants_ext.NOTIFICATION_TYPE_CHANGED;
@@ -557,7 +549,6 @@
mAvrcpPlayerAppSettingsRsp = new AvrcpPlayerAppSettingsRsp();
mMediaPlayerInfoList = new TreeMap<Integer, MediaPlayerInfo_ext>();
mAvailablePlayerViewChanged = false;
- mPkgRequestedMBSConnect = new ArrayList<String>();
mBrowsePlayerInfoList = Collections.synchronizedList(new ArrayList<BrowsePlayerInfo_ext>());
mPassthroughDispatched = 0;
mPassthroughLogs = new EvictingQueue_ext<MediaKeyLog>(PASSTHROUGH_LOG_MAX_SIZE);
@@ -607,11 +598,6 @@
initMediaPlayersList();
- BrowsedMediaPlayer_ext player =
- mAvrcpBrowseManager.getBrowsedMediaPlayer(dummyaddr);
- if (player != null)
- player.start();
-
UserManager manager = UserManager.get(mContext);
if (manager == null || manager.isUserUnlocked()) {
if (DEBUG) Log.d(TAG, "User already unlocked, initializing player lists");
@@ -684,7 +670,6 @@
mContext.unregisterReceiver(mBootReceiver);
mContext.unregisterReceiver(mShutDownReceiver);
- mPkgRequestedMBSConnect.clear();
mAddressedMediaPlayer.cleanup();
mAvrcpBrowseManager.cleanup();
mCurrentBrowsingDevice = null;
@@ -2932,8 +2917,6 @@
return status;
}
-
-
public boolean isAbsoluteVolumeSupported(int index) {
boolean status = false;
Log.v(TAG, "Enter isAbsoluteVolumeSupported with index " + index);
@@ -3566,11 +3549,7 @@
if ((mCurrentBrowsingDevice != null) &&
(mCurrentBrowsingDevice.equals(device))) {
Log.v(TAG,"BT device is matched with browsing device:");
- BrowsedMediaPlayer_ext player =
- mAvrcpBrowseManager.getBrowsedMediaPlayer(getByteAddress(device));
- if (player != null)
- player.disconnect();
- mAvrcpBrowseManager.clearBrowsedMediaPlayer(getByteAddress(device));
+ mAvrcpBrowseManager.cleanup();
mCurrentBrowsingDevice = null;
changePathDepth = 0;
changePathFolderType = 0;
@@ -3689,10 +3668,6 @@
int browseInfoID = getBrowseId(packageName);
if (browseInfoID != -1) {
mBrowsePlayerInfoList.remove(browseInfoID);
- BrowsedMediaPlayer_ext player =
- mAvrcpBrowseManager.getBrowsedMediaPlayer(dummyaddr);
- if (player != null)
- player.updateBrowsablePlayerList(packageName);
}
}
}
@@ -3991,16 +3966,18 @@
mPackageManager.queryIntentServices(intent, PackageManager.MATCH_ALL);
for (ResolveInfo info : playerList) {
- String serviceName = info.serviceInfo.name;
String packageName = info.serviceInfo.packageName;
- Log.d(TAG, "Fetch the displayName of package - start");
- String displayName = getAppLabel(packageName);
- if (displayName == null) displayName = new String();
- Log.d(TAG, "Fetch the displayName of package -" + displayName + " end");
- Log.d(TAG, "svc " + serviceName + " pkg " + packageName);
- BrowsePlayerInfo_ext currentPlayer =
- new BrowsePlayerInfo_ext(packageName, displayName, serviceName);
- mBrowsePlayerInfoList.add(currentPlayer);
+ if (playerBrowseWhiteListDB.contains(packageName)) {
+ Log.d(TAG, "Fetching the displayName of package - start");
+ String serviceName = info.serviceInfo.name;
+ String displayName = getAppLabel(packageName);
+ if (displayName == null) displayName = new String();
+ Log.d(TAG, "Fetching the displayName of package -" + displayName + " end");
+ Log.d(TAG, "svc " + serviceName + " pkg " + packageName);
+ BrowsePlayerInfo_ext currentPlayer =
+ new BrowsePlayerInfo_ext(packageName, displayName, serviceName);
+ mBrowsePlayerInfoList.add(currentPlayer);
+ }
MediaPlayerInfo_ext playerInfo = getMediaPlayerInfo(packageName);
MediaController controller =
(playerInfo == null) ? null : playerInfo.getMediaController();
@@ -4339,13 +4316,7 @@
private MediaPlayerListRsp_ext prepareMediaPlayerRspObj() {
synchronized (this) {
synchronized (mMediaPlayerInfoList) {
- // TODO(apanicke): This hack will go away as soon as a developer
- // option to enable or disable player selection is created. Right
- // now this is needed to fix BMW i3 carkits and any other carkits
- // that might try to connect to a player that isnt the current
- // player based on this list
int numPlayers = 1;
-
int[] playerIds = new int[numPlayers];
byte[] playerTypes = new byte[numPlayers];
int[] playerSubTypes = new int[numPlayers];
@@ -4362,7 +4333,7 @@
if (entry.getKey() == mCurrAddrPlayerID)
idx = 0;
else
- continue; // TODO(apanicke): Remove, see above note
+ continue;
MediaPlayerInfo_ext info = entry.getValue();
playerIds[idx] = entry.getKey();
playerTypes[idx] = info.getMajorType();
@@ -4371,25 +4342,13 @@
playStatusValues[idx] = info.getPlayStatus();
short[] featureBits = info.getFeatureBitMask();
- short[] featureBitsArray = {0x00, 0x00, 0x00, 0x00, 0x00, 0xb7, 0x01, 0x04,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
- String browsedPackage = getPackageName(mCurrAddrPlayerID);
- BrowsedMediaPlayer_ext player =
- mAvrcpBrowseManager.getBrowsedMediaPlayer(dummyaddr);
- String currPkg = (info != null) ? info.getPackageName():"";
- if (playerBrowseWhiteListDB.contains(currPkg)) {
- for (int numBit = 0; numBit < featureBits.length; numBit++) {
- /* gives which octet this belongs to */
- byte octet = (byte) (featureBits[numBit] / 8);
- /* gives the bit position within the octet */
- byte bit = (byte) (featureBits[numBit] % 8);
- featureBitMaskValues[(idx * AvrcpConstants_ext.AVRC_FEATURE_MASK_SIZE) + octet] |=
- (1 << bit);
- }
- } else {
- featureBitMaskValues =
- Arrays.copyOf(featureBitsArray, featureBitsArray.length);
- Log.w(TAG, "sending bit mask for non Browsable Player");
+ for (int numBit = 0; numBit < featureBits.length; numBit++) {
+ /* gives which octet this belongs to */
+ byte octet = (byte) (featureBits[numBit] / 8);
+ /* gives the bit position within the octet */
+ byte bit = (byte) (featureBits[numBit] % 8);
+ featureBitMaskValues[(idx*AvrcpConstants_ext.AVRC_FEATURE_MASK_SIZE)+octet]
+ |= (1 << bit);
}
/* printLogs */
diff --git a/packages_apps_bluetooth_ext/src/avrcp/BrowsedMediaPlayer_ext.java b/packages_apps_bluetooth_ext/src/avrcp/BrowsedMediaPlayer_ext.java
index 6974369..6fbeabe 100644
--- a/packages_apps_bluetooth_ext/src/avrcp/BrowsedMediaPlayer_ext.java
+++ b/packages_apps_bluetooth_ext/src/avrcp/BrowsedMediaPlayer_ext.java
@@ -26,10 +26,6 @@
import android.media.session.MediaSession;
import android.os.Bundle;
import android.util.Log;
-import android.os.Handler;
-import android.os.HandlerThread;
-import android.os.Looper;
-import android.os.Message;
import java.math.BigInteger;
import java.util.ArrayList;
@@ -52,11 +48,6 @@
private static final int CONNECTED = 1;
private static final int SUSPENDED = 2;
- private static final int MSG_CONNECT_PLAYER = 1;
- private static final int MSG_DISCONNECT_PLAYER = 2;
- private static final int MSG_TIMEOUT = 3;
-
- private static final int TIMEOUT = 3000;
private static final int BROWSED_ITEM_ID_INDEX = 2;
private static final int BROWSED_FOLDER_ID_INDEX = 4;
private static final String[] ROOT_FOLDER = {"root"};
@@ -77,9 +68,6 @@
private String mCurrentBrowsePackage;
private String mCurrentBrowseClass;
- private BrowseMediaHandler mHandler = null;
- private HandlerThread mHandlerThread;
-
/* Object used to connect to MediaBrowseService of Media Player */
private MediaBrowser mMediaBrowser = null;
private MediaController mMediaController = null;
@@ -106,45 +94,6 @@
/* store result of getfolderitems with scope="vfs" */
private List<MediaBrowser.MediaItem> mFolderItems = null;
- private List<String> mBrowsablePlayerList = new ArrayList<String>();
-
- class BrowseMediaHandler extends Handler {
- BrowseMediaHandler(Looper looper) {
- super(looper);
- }
-
- @Override
- public void handleMessage(Message msg) {
- Log.w(TAG, "handleMessage " + msg.what + " obj " + msg.obj);
- switch (msg.what) {
- case MSG_CONNECT_PLAYER:
- Bundle data = msg.getData();
- String packageName = data.getCharSequence("package").toString();
- String cls = data.getCharSequence("class").toString();
- Log.w(TAG, "package = " + packageName + " svc class " + cls);
- MediaConnectionCallback callback = new MediaConnectionCallback(packageName);
- MediaBrowser tempBrowser = new MediaBrowser(
- mContext, new ComponentName(packageName, cls), callback, null);
- callback.setBrowser(tempBrowser);
- tempBrowser.connect();
- Log.w(TAG, "TryconnectMBS with Browser service");
- Message m = mHandler.obtainMessage(MSG_TIMEOUT, 0, 0, packageName);
- mHandler.sendMessageDelayed(m, TIMEOUT);
- break;
- case MSG_DISCONNECT_PLAYER:
- MediaBrowser mb = (MediaBrowser)msg.obj;
- Log.w(TAG, "Trigger disconnect for MediaBrowser " + mb);
- if (mb != null)
- mb.disconnect();
- break;
- case MSG_TIMEOUT:
- Log.w(TAG, "MSG_TIMEOUT");
- break;
- default:
- break;
- }
- }
- };
/* Connection state callback handler */
class MediaConnectionCallback extends MediaBrowser.ConnectionCallback {
@@ -163,16 +112,6 @@
@Override
public void onConnected() {
Log.d(TAG, "Onconnected pkg " + mCallbackPackageName + " mb " + mBrowser);
- if ((mHandler != null) && !mBrowsablePlayerList.contains(mCallbackPackageName)
- && mHandler.hasMessages(MSG_TIMEOUT, mCallbackPackageName)) {
- Log.d(TAG, "Add " + mCallbackPackageName + " to MBS List " + mBrowsablePlayerList);
- mBrowsablePlayerList.add(mCallbackPackageName);
- mHandler.removeMessages(MSG_TIMEOUT, mCallbackPackageName);
- Message msg = mHandler.obtainMessage(MSG_DISCONNECT_PLAYER, 0, 0, mBrowser);
- mHandler.sendMessage(msg);
- mBrowser = null;
- return;
- }
mConnState = CONNECTED;
Log.d(TAG, "mediaBrowser CONNECTED to " + mPackageName);
/* perform init tasks and set player as browsed player on successful connection */
@@ -185,12 +124,6 @@
@Override
public void onConnectionFailed() {
Log.d(TAG, "Onconnectedfail pkg " + mCallbackPackageName + " mb " + mBrowser);
- if ((mHandler != null) && !mBrowsablePlayerList.contains(mCallbackPackageName)
- && mHandler.hasMessages(MSG_TIMEOUT, mCallbackPackageName)) {
- mHandler.removeMessages(MSG_TIMEOUT, mCallbackPackageName);
- mBrowser = null;
- return;
- }
mConnState = DISCONNECTED;
mTempMediaBrowser = null;
// Remove what could be a circular dependency causing GC to never happen on this object
@@ -204,12 +137,6 @@
@Override
public void onConnectionSuspended() {
Log.d(TAG, "Onconnectedsuspend pkg " + mCallbackPackageName + " mb " + mBrowser);
- if ((mHandler != null) && !mBrowsablePlayerList.contains(mCallbackPackageName)
- && mHandler.hasMessages(MSG_TIMEOUT, mCallbackPackageName)) {
- mHandler.removeMessages(MSG_TIMEOUT, mCallbackPackageName);
- mBrowser = null;
- return;
- }
mBrowser = null;
mTempMediaBrowser = null;
mConnState = SUSPENDED;
@@ -567,95 +494,17 @@
Log.w(TAG, "Reconnected with Browser service");
}
- public void updateBrowsablePlayerList(String packageName) {
- if (packageName == null || packageName.isEmpty())
- return;
- if (mBrowsablePlayerList.contains(packageName)) {
- Log.w(TAG, "Remove pkg" + packageName + "from list" + mBrowsablePlayerList);
- mBrowsablePlayerList.remove(packageName);
- }
- }
-
- public void CheckMBSConnection(String packageName, String cls) {
- Log.w(TAG, "TryconnectMBS with Browser service for package = " + packageName);
- if (mBrowsablePlayerList.contains(packageName)) {
- Log.w(TAG, "Already in MBS List don't reconnect" + mBrowsablePlayerList);
- return;
- }
- if (mHandler != null) {
- Message msg = mHandler.obtainMessage(MSG_CONNECT_PLAYER);
- Bundle data = new Bundle();
- data.putCharSequence("package", packageName);
- data.putCharSequence("class", cls);
- msg.setData(data);
- mHandler.sendMessage(msg);
- Log.w(TAG, "Exit MSG_CONNECT_PLAYER for package = " + packageName);
- }
- }
-
- public boolean isPackageInMBSList(String packageName) {
- if (packageName == null || packageName.isEmpty())
- return false;
- Log.w(TAG, "isPlayerConnectedMBS for package = " + packageName);
-
- // Wait while pending messages are in queue
- while ((mHandler != null) && (mHandler.hasMessages(MSG_CONNECT_PLAYER)
- || mHandler.hasMessages(MSG_TIMEOUT))) {
- try {
- Log.d(TAG, "Connection with MBS ongoing, sleep for 200 ms and recheck");
- Thread.sleep(200);
- } catch (InterruptedException e) {
- Log.w(TAG, "Interrupt sleep caught Exception");
- }
- }
-
- Log.w(TAG, "List of Browse supported players = " + mBrowsablePlayerList);
- for (String pkg : mBrowsablePlayerList) {
- if (packageName.equals(pkg))
- return true;
- }
- return false;
- }
-
public void setCurrentPackage(String packageName, String cls) {
Log.w(TAG, "Set current Browse based on Addr Player as " + packageName);
mCurrentBrowsePackage = packageName;
mCurrentBrowseClass = cls;
}
- public void start() {
- if (mHandler == null) {
- Log.w(TAG, "start");
- mHandlerThread = new HandlerThread("BrowseMediaHandler");
- mHandlerThread.start();
- mHandler = new BrowseMediaHandler(mHandlerThread.getLooper());
- }
- Log.w(TAG, "start exit");
- }
-
/* called when connection to media player is closed */
public void cleanup() {
- disconnect();
if (DEBUG) {
Log.d(TAG, "cleanup");
}
- mBrowsablePlayerList.clear();
- if (mHandler != null) {
- Log.d(TAG, "cleanup handlers");
- mHandler.removeCallbacksAndMessages(null);
- Looper looper = mHandler.getLooper();
- if (looper != null)
- looper.quit();
- }
- if (mHandlerThread != null) {
- mHandlerThread.quitSafely();
- }
- }
-
- public void disconnect() {
- if (DEBUG) {
- Log.d(TAG, "disconnect");
- }
if (mConnState != DISCONNECTED) {
if (mMediaBrowser != null) mMediaBrowser.disconnect();
}
@@ -676,7 +525,6 @@
}
return false;
}
-
return mMediaBrowser.isConnected();
}