Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2571,14 +2571,19 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
return
}

val shouldTakeOver = when (bleManager.getMostRecentStatus()?.connectionState) {
val airPodsState = bleManager.getMostRecentStatus()?.connectionState
Log.d(TAG, "AirPods state for takeover: $airPodsState")
val shouldTakeOver = when (airPodsState) {
"Disconnected" -> config.takeoverWhenDisconnected
"Idle" -> config.takeoverWhenIdle
"Music" -> config.takeoverWhenMusic
"Call" -> config.takeoverWhenCall
"Ringing" -> config.takeoverWhenCall
"Hanging Up" -> config.takeoverWhenCall
else -> false
// The first advertisement after the AirPods reappear often carries a state byte that
// isn't mapped (or there is no status yet). Refusing then means the takeover only
// happens on the next media change, so follow the media setting instead.
else -> config.takeoverWhenMusic
}

if (!shouldTakeOver) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,16 @@ object MediaController {

Log.d("MediaController", "Current active content types: $currentActiveContentTypes")

val hasNewMusicOrMovie = currentActiveContentTypes.any { contentType ->
// Some players (e.g. Poweramp over OpenSL ES) leave the content type unknown, so a
// USAGE_MEDIA stream with no content type counts as music too.
val hasUntypedMedia = configs?.any { config ->
config.audioAttributes?.let { attrs ->
attrs.usage == android.media.AudioAttributes.USAGE_MEDIA &&
attrs.contentType == android.media.AudioAttributes.CONTENT_TYPE_UNKNOWN
} ?: false
} ?: false

val hasNewMusicOrMovie = hasUntypedMedia || currentActiveContentTypes.any { contentType ->
contentType == android.media.AudioAttributes.CONTENT_TYPE_MUSIC ||
contentType == android.media.AudioAttributes.CONTENT_TYPE_MOVIE
}
Expand Down