11package io.github.sds100.keymapper.constraints
22
3- import android.media.AudioAttributes
3+ import android.media.AudioManager
44import android.os.Build
55import io.github.sds100.keymapper.system.accessibility.IAccessibilityService
66import io.github.sds100.keymapper.system.bluetooth.BluetoothDeviceInfo
@@ -43,9 +43,9 @@ class ConstraintSnapshotImpl(
4343 private val isScreenOn: Boolean by lazy { displayAdapter.isScreenOn.firstBlocking() }
4444 private val appsPlayingMedia: List <String > by lazy { mediaAdapter.getActiveMediaSessionPackages() }
4545
46- private val audioContentTypes : Set <Int > by lazy {
46+ private val audioVolumeStreams : Set <Int > by lazy {
4747 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
48- mediaAdapter.getActiveAudioContentTypes ()
48+ mediaAdapter.getActiveAudioVolumeStreams ()
4949 } else {
5050 emptySet()
5151 }
@@ -65,9 +65,8 @@ class ConstraintSnapshotImpl(
6565 }
6666 }
6767
68- private fun isMediaContentTypePlaying (): Boolean {
69- return audioContentTypes.contains(AudioAttributes .CONTENT_TYPE_MOVIE ) ||
70- audioContentTypes.contains(AudioAttributes .CONTENT_TYPE_MUSIC )
68+ private fun isMediaPlaying (): Boolean {
69+ return audioVolumeStreams.contains(AudioManager .STREAM_MUSIC ) || appsPlayingMedia.isNotEmpty()
7170 }
7271
7372 override fun isSatisfied (constraint : Constraint ): Boolean {
@@ -77,7 +76,7 @@ class ConstraintSnapshotImpl(
7776 is Constraint .AppPlayingMedia -> {
7877 if (appsPlayingMedia.contains(constraint.packageName)) {
7978 return true
80- } else if (appInForeground == constraint.packageName && isMediaContentTypePlaying ()) {
79+ } else if (appInForeground == constraint.packageName && isMediaPlaying ()) {
8180 return true
8281 } else {
8382 return false
@@ -86,13 +85,11 @@ class ConstraintSnapshotImpl(
8685
8786 is Constraint .AppNotPlayingMedia ->
8887 appsPlayingMedia.none { it == constraint.packageName } &&
89- ! (appInForeground == constraint.packageName && isMediaContentTypePlaying ())
88+ ! (appInForeground == constraint.packageName && isMediaPlaying ())
9089
91- Constraint .MediaPlaying ->
92- isMediaContentTypePlaying() || appsPlayingMedia.isNotEmpty()
90+ Constraint .MediaPlaying -> isMediaPlaying()
9391
94- Constraint .NoMediaPlaying ->
95- ! isMediaContentTypePlaying() && appsPlayingMedia.isEmpty()
92+ Constraint .NoMediaPlaying -> ! isMediaPlaying()
9693
9794 is Constraint .BtDeviceConnected -> {
9895 connectedBluetoothDevices.any { it.address == constraint.bluetoothAddress }
0 commit comments