Loading android/app/AndroidManifest.xml +10 −0 Original line number Diff line number Diff line Loading @@ -317,6 +317,16 @@ <action android:name="android.media.browse.MediaBrowserService" /> </intent-filter> </service> <activity android:name=".BluetoothPrefs" android:exported="@bool/profile_supported_a2dp_sink" android:enabled="@bool/profile_supported_a2dp_sink"> <intent-filter> <action android:name="android.intent.action.APPLICATION_PREFERENCES"/> </intent-filter> </activity> <service android:process="@string/process" android:name = ".avrcp.AvrcpTargetService" Loading android/app/res/values/strings.xml +1 −0 Original line number Diff line number Diff line Loading @@ -249,4 +249,5 @@ <string name="bluetooth_disconnected">Bluetooth audio disconnected"</string> <string name="a2dp_sink_mbs_label">Bluetooth Audio</string> <string name="bluetooth_opp_file_limit_exceeded">Files bigger than 4GB cannot be transferred</string> <string name="bluetooth_connect_action">Connect to Bluetooth</string> </resources> android/app/src/com/android/bluetooth/BluetoothPrefs.java 0 → 100644 +40 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.bluetooth; import android.app.Activity; import android.content.Intent; import android.os.Bundle; /** * Activity that routes to Bluetooth settings when launched */ public class BluetoothPrefs extends Activity { public static final String BLUETOOTH_SETTING_ACTION = "android.settings.BLUETOOTH_SETTINGS"; public static final String BLUETOOTH_SETTING_CATEGORY = "android.intent.category.DEFAULT"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent launchIntent = new Intent(); launchIntent.setAction(BLUETOOTH_SETTING_ACTION); launchIntent.addCategory(BLUETOOTH_SETTING_CATEGORY); startActivity(launchIntent); finish(); } } android/app/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerStateMachine.java +1 −5 Original line number Diff line number Diff line Loading @@ -233,11 +233,7 @@ class AvrcpControllerStateMachine extends StateMachine { mAddressedPlayer.updateCurrentTrack(null); mBrowseTree.mNowPlayingNode.setCached(false); BluetoothMediaBrowserService.notifyChanged(mBrowseTree.mNowPlayingNode); PlaybackStateCompat.Builder pbb = new PlaybackStateCompat.Builder(); pbb.setState(PlaybackStateCompat.STATE_ERROR, PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, 1.0f).setActions(0); pbb.setErrorMessage(mService.getString(R.string.bluetooth_disconnected)); BluetoothMediaBrowserService.notifyChanged(pbb.build()); BluetoothMediaBrowserService.addressedPlayerChanged(null); mService.sBrowseTree.mRootNode.removeChild( mBrowseTree.mRootNode); BluetoothMediaBrowserService.notifyChanged(mService Loading android/app/src/com/android/bluetooth/avrcpcontroller/BluetoothMediaBrowserService.java +31 −5 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.bluetooth.avrcpcontroller; import android.app.PendingIntent; import android.content.Intent; import android.media.MediaMetadata; import android.media.browse.MediaBrowser.MediaItem; import android.os.Bundle; Loading @@ -29,6 +31,7 @@ import android.util.Log; import androidx.media.MediaBrowserServiceCompat; import com.android.bluetooth.BluetoothPrefs; import com.android.bluetooth.R; import java.util.ArrayList; Loading Loading @@ -60,6 +63,12 @@ public class BluetoothMediaBrowserService extends MediaBrowserServiceCompat { // Browsing related structures. private List<MediaSessionCompat.QueueItem> mMediaQueue = new ArrayList<>(); // Error messaging extras public static final String ERROR_RESOLUTION_ACTION_INTENT = "android.media.extras.ERROR_RESOLUTION_ACTION_INTENT"; public static final String ERROR_RESOLUTION_ACTION_LABEL = "android.media.extras.ERROR_RESOLUTION_ACTION_LABEL"; /** * Initialize this BluetoothMediaBrowserService, creating our MediaSessionCompat, MediaPlayer * and MediaMetaData, and setting up mechanisms to talk with the AvrcpControllerService. Loading @@ -76,11 +85,7 @@ public class BluetoothMediaBrowserService extends MediaBrowserServiceCompat { | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS); mSession.setQueueTitle(getString(R.string.bluetooth_a2dp_sink_queue_name)); mSession.setQueue(mMediaQueue); PlaybackStateCompat.Builder playbackStateBuilder = new PlaybackStateCompat.Builder(); playbackStateBuilder.setState(PlaybackStateCompat.STATE_ERROR, PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, 1.0f).setActions(0); playbackStateBuilder.setErrorMessage(getString(R.string.bluetooth_disconnected)); mSession.setPlaybackState(playbackStateBuilder.build()); setErrorPlaybackState(); sBluetoothMediaBrowserService = this; } Loading @@ -94,6 +99,24 @@ public class BluetoothMediaBrowserService extends MediaBrowserServiceCompat { } } private void setErrorPlaybackState() { Bundle extras = new Bundle(); extras.putString(ERROR_RESOLUTION_ACTION_LABEL, getString(R.string.bluetooth_connect_action)); Intent launchIntent = new Intent(); launchIntent.setAction(BluetoothPrefs.BLUETOOTH_SETTING_ACTION); launchIntent.addCategory(BluetoothPrefs.BLUETOOTH_SETTING_CATEGORY); PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, launchIntent, PendingIntent.FLAG_UPDATE_CURRENT); extras.putParcelable(ERROR_RESOLUTION_ACTION_INTENT, pendingIntent); PlaybackStateCompat errorState = new PlaybackStateCompat.Builder() .setErrorMessage(getString(R.string.bluetooth_disconnected)) .setExtras(extras) .setState(PlaybackStateCompat.STATE_ERROR, 0, 0) .build(); mSession.setPlaybackState(errorState); } @Override public synchronized void onLoadChildren(final String parentMediaId, final Result<List<MediaBrowserCompat.MediaItem>> result) { Loading Loading @@ -138,6 +161,9 @@ public class BluetoothMediaBrowserService extends MediaBrowserServiceCompat { static synchronized void addressedPlayerChanged(MediaSessionCompat.Callback callback) { if (sBluetoothMediaBrowserService != null) { if (callback == null) { sBluetoothMediaBrowserService.setErrorPlaybackState(); } sBluetoothMediaBrowserService.mSession.setCallback(callback); } else { Log.w(TAG, "addressedPlayerChanged Unavailable"); Loading Loading
android/app/AndroidManifest.xml +10 −0 Original line number Diff line number Diff line Loading @@ -317,6 +317,16 @@ <action android:name="android.media.browse.MediaBrowserService" /> </intent-filter> </service> <activity android:name=".BluetoothPrefs" android:exported="@bool/profile_supported_a2dp_sink" android:enabled="@bool/profile_supported_a2dp_sink"> <intent-filter> <action android:name="android.intent.action.APPLICATION_PREFERENCES"/> </intent-filter> </activity> <service android:process="@string/process" android:name = ".avrcp.AvrcpTargetService" Loading
android/app/res/values/strings.xml +1 −0 Original line number Diff line number Diff line Loading @@ -249,4 +249,5 @@ <string name="bluetooth_disconnected">Bluetooth audio disconnected"</string> <string name="a2dp_sink_mbs_label">Bluetooth Audio</string> <string name="bluetooth_opp_file_limit_exceeded">Files bigger than 4GB cannot be transferred</string> <string name="bluetooth_connect_action">Connect to Bluetooth</string> </resources>
android/app/src/com/android/bluetooth/BluetoothPrefs.java 0 → 100644 +40 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.bluetooth; import android.app.Activity; import android.content.Intent; import android.os.Bundle; /** * Activity that routes to Bluetooth settings when launched */ public class BluetoothPrefs extends Activity { public static final String BLUETOOTH_SETTING_ACTION = "android.settings.BLUETOOTH_SETTINGS"; public static final String BLUETOOTH_SETTING_CATEGORY = "android.intent.category.DEFAULT"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent launchIntent = new Intent(); launchIntent.setAction(BLUETOOTH_SETTING_ACTION); launchIntent.addCategory(BLUETOOTH_SETTING_CATEGORY); startActivity(launchIntent); finish(); } }
android/app/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerStateMachine.java +1 −5 Original line number Diff line number Diff line Loading @@ -233,11 +233,7 @@ class AvrcpControllerStateMachine extends StateMachine { mAddressedPlayer.updateCurrentTrack(null); mBrowseTree.mNowPlayingNode.setCached(false); BluetoothMediaBrowserService.notifyChanged(mBrowseTree.mNowPlayingNode); PlaybackStateCompat.Builder pbb = new PlaybackStateCompat.Builder(); pbb.setState(PlaybackStateCompat.STATE_ERROR, PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, 1.0f).setActions(0); pbb.setErrorMessage(mService.getString(R.string.bluetooth_disconnected)); BluetoothMediaBrowserService.notifyChanged(pbb.build()); BluetoothMediaBrowserService.addressedPlayerChanged(null); mService.sBrowseTree.mRootNode.removeChild( mBrowseTree.mRootNode); BluetoothMediaBrowserService.notifyChanged(mService Loading
android/app/src/com/android/bluetooth/avrcpcontroller/BluetoothMediaBrowserService.java +31 −5 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.bluetooth.avrcpcontroller; import android.app.PendingIntent; import android.content.Intent; import android.media.MediaMetadata; import android.media.browse.MediaBrowser.MediaItem; import android.os.Bundle; Loading @@ -29,6 +31,7 @@ import android.util.Log; import androidx.media.MediaBrowserServiceCompat; import com.android.bluetooth.BluetoothPrefs; import com.android.bluetooth.R; import java.util.ArrayList; Loading Loading @@ -60,6 +63,12 @@ public class BluetoothMediaBrowserService extends MediaBrowserServiceCompat { // Browsing related structures. private List<MediaSessionCompat.QueueItem> mMediaQueue = new ArrayList<>(); // Error messaging extras public static final String ERROR_RESOLUTION_ACTION_INTENT = "android.media.extras.ERROR_RESOLUTION_ACTION_INTENT"; public static final String ERROR_RESOLUTION_ACTION_LABEL = "android.media.extras.ERROR_RESOLUTION_ACTION_LABEL"; /** * Initialize this BluetoothMediaBrowserService, creating our MediaSessionCompat, MediaPlayer * and MediaMetaData, and setting up mechanisms to talk with the AvrcpControllerService. Loading @@ -76,11 +85,7 @@ public class BluetoothMediaBrowserService extends MediaBrowserServiceCompat { | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS); mSession.setQueueTitle(getString(R.string.bluetooth_a2dp_sink_queue_name)); mSession.setQueue(mMediaQueue); PlaybackStateCompat.Builder playbackStateBuilder = new PlaybackStateCompat.Builder(); playbackStateBuilder.setState(PlaybackStateCompat.STATE_ERROR, PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, 1.0f).setActions(0); playbackStateBuilder.setErrorMessage(getString(R.string.bluetooth_disconnected)); mSession.setPlaybackState(playbackStateBuilder.build()); setErrorPlaybackState(); sBluetoothMediaBrowserService = this; } Loading @@ -94,6 +99,24 @@ public class BluetoothMediaBrowserService extends MediaBrowserServiceCompat { } } private void setErrorPlaybackState() { Bundle extras = new Bundle(); extras.putString(ERROR_RESOLUTION_ACTION_LABEL, getString(R.string.bluetooth_connect_action)); Intent launchIntent = new Intent(); launchIntent.setAction(BluetoothPrefs.BLUETOOTH_SETTING_ACTION); launchIntent.addCategory(BluetoothPrefs.BLUETOOTH_SETTING_CATEGORY); PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, launchIntent, PendingIntent.FLAG_UPDATE_CURRENT); extras.putParcelable(ERROR_RESOLUTION_ACTION_INTENT, pendingIntent); PlaybackStateCompat errorState = new PlaybackStateCompat.Builder() .setErrorMessage(getString(R.string.bluetooth_disconnected)) .setExtras(extras) .setState(PlaybackStateCompat.STATE_ERROR, 0, 0) .build(); mSession.setPlaybackState(errorState); } @Override public synchronized void onLoadChildren(final String parentMediaId, final Result<List<MediaBrowserCompat.MediaItem>> result) { Loading Loading @@ -138,6 +161,9 @@ public class BluetoothMediaBrowserService extends MediaBrowserServiceCompat { static synchronized void addressedPlayerChanged(MediaSessionCompat.Callback callback) { if (sBluetoothMediaBrowserService != null) { if (callback == null) { sBluetoothMediaBrowserService.setErrorPlaybackState(); } sBluetoothMediaBrowserService.mSession.setCallback(callback); } else { Log.w(TAG, "addressedPlayerChanged Unavailable"); Loading