playback: disable bluetooth autoplay

Temporarily disable and clean up the bluetooth autoplay system for now
until I can get it working sensibly.
This commit is contained in:
Alexander Capehart 2022-11-14 20:42:38 -07:00
parent 1447069efd
commit 2b35fd07b6
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
9 changed files with 36 additions and 67 deletions

View file

@ -44,6 +44,7 @@ audio focus was lost
#### Dev/Meta
- Completed migration to reactive playback system
- Refactor music backends into a unified chain of extractors
- Add bluetooth connection reciever (No functionality in app yet)
## 2.6.3

View file

@ -8,10 +8,10 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- Bluetooth auto-connect functionality -->
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" android:minSdkVersion="31" />
<uses-feature android:name="android.hardware.bluetooth" android:required="false"/>
<!-- Bluetooth auto-connect functionality (Disabled until permission workflow can be made) -->
<!-- <uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />-->
<!-- <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" android:minSdkVersion="31" />-->
<!-- <uses-feature android:name="android.hardware.bluetooth" android:required="false"/>-->
<!-- Work around ExoPlayer requiring network permissions we do not use -->
<uses-permission
@ -107,14 +107,14 @@
</intent-filter>
</receiver>
<!-- Auxio's auto-playback on BT connect receiver. -->
<receiver
android:name=".playback.system.BluetoothConnectReceiver"
android:exported="true">
<intent-filter>
<action android:name="android.bluetooth.a2dp.profile.action.CONNECTION_STATE_CHANGED" />
</intent-filter>
</receiver>
<!-- Auxio's reciever for bluetooth headset events -->
<!-- <receiver-->
<!-- android:name=".playback.system.BluetoothConnectReceiver"-->
<!-- android:exported="true">-->
<!-- <intent-filter>-->
<!-- <action android:name="android.bluetooth.a2dp.profile.action.CONNECTION_STATE_CHANGED" />-->
<!-- </intent-filter>-->
<!-- </receiver>-->
<!-- Auxio's one and only AppWidget. -->
<receiver

View file

@ -71,18 +71,6 @@ class MainActivity : AppCompatActivity() {
if (!startIntentAction(intent)) {
playbackModel.startAction(InternalPlayer.Action.RestoreState)
}
// Check bluetooth connect permissions if required for bt autoconnect feature
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
val settings = Settings(this)
if (settings.bluetoothAutoplay) {
ActivityCompat.requestPermissions(
this,
arrayOf<String>(android.Manifest.permission.BLUETOOTH_CONNECT),
BLUETOOTH_PERMISSION_REQUEST_ID
)
}
}
}
override fun onNewIntent(intent: Intent?) {
@ -145,6 +133,5 @@ class MainActivity : AppCompatActivity() {
companion object {
private const val KEY_INTENT_USED = BuildConfig.APPLICATION_ID + ".key.FILE_INTENT_USED"
private const val BLUETOOTH_PERMISSION_REQUEST_ID = 1337 * 42;
}
}

View file

@ -1,33 +0,0 @@
package org.oxycblt.auxio.playback.system
import android.bluetooth.BluetoothProfile
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.os.Build
import org.oxycblt.auxio.playback.state.InternalPlayer
import org.oxycblt.auxio.playback.state.PlaybackStateManager
import org.oxycblt.auxio.settings.Settings
class BluetoothConnectReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (intent.action == android.bluetooth.BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED) {
val newState = intent.getIntExtra(BluetoothProfile.EXTRA_STATE, BluetoothProfile.STATE_DISCONNECTED)
if (newState == BluetoothProfile.STATE_CONNECTED) {
val settings = Settings(context)
if (settings.bluetoothAutoplay) {
// make sure required services are up and running
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(Intent(context, PlaybackService::class.java))
} else {
context.startService(Intent(context, PlaybackService::class.java))
}
// start playback
val playbackManager = PlaybackStateManager.getInstance()
playbackManager.startAction(InternalPlayer.Action.RestoreState)
playbackManager.changePlaying(true)
}
}
}
}
}

View file

@ -0,0 +1,23 @@
package org.oxycblt.auxio.playback.system
import android.bluetooth.BluetoothProfile
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
/**
* A [BroadcastReceiver] that handles connections from bluetooth headsets, starting playback if
* they occur.
* @author seijikun, OxygenCobalt
*/
class BluetoothHeadsetReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (intent.action == android.bluetooth.BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED) {
val newState = intent.getIntExtra(BluetoothProfile.EXTRA_STATE, BluetoothProfile.STATE_DISCONNECTED)
if (newState == BluetoothProfile.STATE_CONNECTED) {
// TODO: Initialize the service (Permission workflow must be figured out)
// Perhaps move this to the internal receivers?
}
}
}
}

View file

@ -230,10 +230,6 @@ class Settings(private val context: Context, private val callback: Callback? = n
val headsetAutoplay: Boolean
get() = inner.getBoolean(context.getString(R.string.set_key_headset_autoplay), false)
/** Whether a connected bluetooth device should cause Auxio to spawn and start playback */
val bluetoothAutoplay: Boolean
get() = inner.getBoolean(context.getString(R.string.set_key_bluetooth_autoplay), false)
/** The current ReplayGain configuration */
val replayGainMode: ReplayGainMode
get() =

View file

@ -49,8 +49,6 @@
<string name="set_audio">Audio</string>
<string name="set_headset_autoplay">Kopfhörer: automatische Wiedergabe</string>
<string name="set_headset_autoplay_desc">Beginne die Wiedergabe immer, wenn Kopfhörer verbunden sind (funktioniert nicht auf allen Geräten)</string>
<string name="set_bluetooth_autoplay">Bluetooth: automatische Wiedergabe</string>
<string name="set_bluetooth_autoplay_desc">Auxio starten und Wiedergabe fortführen, sobald ein Bluetooth Audio fähiges Gerät verbunden wurde</string>
<string name="set_replay_gain">ReplayGain-Strategie</string>
<string name="set_pre_amp">ReplayGain-Prälautverstärkung</string>
<string name="set_pre_amp_desc">Während der Musikwiedergabe, trifft die Prälautverstärkung dem aktuellem Abgleich zu</string>

View file

@ -14,7 +14,6 @@
<string name="set_key_separators" translatable="false">auxio_separators</string>
<string name="set_key_headset_autoplay" translatable="false">auxio_headset_autoplay</string>
<string name="set_key_bluetooth_autoplay" translatable="false">auxio_bluetooth_autoplay</string>
<string name="set_key_replay_gain" translatable="false">auxio_replay_gain</string>
<string name="set_key_pre_amp" translatable="false">auxio_pre_amp</string>
<string name="set_key_pre_amp_with" translatable="false">auxio_pre_amp_with</string>

View file

@ -186,8 +186,6 @@
<string name="set_audio">Audio</string>
<string name="set_headset_autoplay">Headset autoplay</string>
<string name="set_headset_autoplay_desc">Always start playing when a headset is connected (may not work on all devices)</string>
<string name="set_bluetooth_autoplay">Bluetooth autoplay</string>
<string name="set_bluetooth_autoplay_desc">A connected bluetooth audio device causes Auxio to spawn and start playback</string>
<string name="set_replay_gain">ReplayGain strategy</string>
<string name="set_replay_gain_track">Prefer track</string>
<string name="set_replay_gain_album">Prefer album</string>