Merge branch 'dev' of github.com:seijikun/Auxio into seijikun-dev
This commit is contained in:
commit
1447069efd
8 changed files with 74 additions and 0 deletions
|
@ -8,6 +8,11 @@
|
|||
<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"/>
|
||||
|
||||
<!-- Work around ExoPlayer requiring network permissions we do not use -->
|
||||
<uses-permission
|
||||
android:name="android.permission.ACCESS_NETWORK_STATE"
|
||||
|
@ -102,6 +107,15 @@
|
|||
</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 one and only AppWidget. -->
|
||||
<receiver
|
||||
android:name=".widgets.WidgetProvider"
|
||||
|
|
|
@ -22,6 +22,7 @@ import android.os.Bundle
|
|||
import android.view.View
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.core.view.updatePadding
|
||||
import org.oxycblt.auxio.databinding.ActivityMainBinding
|
||||
|
@ -70,6 +71,18 @@ 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?) {
|
||||
|
@ -132,5 +145,6 @@ 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -230,6 +230,10 @@ 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() =
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
|
||||
package org.oxycblt.auxio.settings.prefs
|
||||
|
||||
import android.app.Activity
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.annotation.DrawableRes
|
||||
|
@ -41,6 +43,8 @@ import org.oxycblt.auxio.util.isNight
|
|||
import org.oxycblt.auxio.util.logD
|
||||
import org.oxycblt.auxio.util.showToast
|
||||
import org.oxycblt.auxio.util.systemBarInsetsCompat
|
||||
import java.security.Permission
|
||||
import java.util.jar.Manifest
|
||||
|
||||
/**
|
||||
* The actual fragment containing the settings menu. Inherits [PreferenceFragmentCompat].
|
||||
|
|
|
@ -49,6 +49,8 @@
|
|||
<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>
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
<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>
|
||||
|
|
|
@ -186,6 +186,8 @@
|
|||
<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>
|
||||
|
|
Loading…
Reference in a new issue