Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Android 14 related fixes #271

Merged
merged 4 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 4 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

Expand Down Expand Up @@ -46,11 +47,11 @@

<service
android:name=".services.AudioRecorderService"
android:exported="false" />
android:exported="false" android:foregroundServiceType="microphone" />
pvagner marked this conversation as resolved.
Show resolved Hide resolved

<service
android:name=".services.LosslessRecorderService"
android:exported="false" />
android:exported="false" android:foregroundServiceType="microphone" />
pvagner marked this conversation as resolved.
Show resolved Hide resolved

<receiver
android:name=".receivers.FinishedNotificationReceiver"
Expand Down Expand Up @@ -95,4 +96,4 @@

</application>

</manifest>
</manifest>
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.bnyro.recorder.services

import android.content.pm.ServiceInfo
import android.media.MediaRecorder
import android.os.Build
import android.widget.Toast
import com.bnyro.recorder.App
import com.bnyro.recorder.R
Expand All @@ -14,6 +16,13 @@ class AudioRecorderService : RecorderService() {
override val notificationTitle: String
get() = getString(R.string.recording_audio)

override val fgServiceType: Int?
get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE
} else {
null
}

override fun start() {
val audioFormat = AudioFormat.getCurrent()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bnyro.recorder.services

import android.annotation.SuppressLint
import android.content.pm.ServiceInfo
import android.media.AudioFormat
import android.media.AudioRecord
import android.media.MediaRecorder
Expand All @@ -22,6 +23,13 @@ class LosslessRecorderService : RecorderService() {
override val notificationTitle: String
get() = getString(R.string.recording_audio)

override val fgServiceType: Int?
get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE
} else {
null
}

private var audioRecorder: AudioRecord? = null
private var recorderThread: Thread? = null
private var pcmConverter: PcmConverter? = null
Expand Down
22 changes: 17 additions & 5 deletions app/src/main/java/com/bnyro/recorder/services/RecorderService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,28 @@ abstract class RecorderService : LifecycleService() {
runCatching {
unregisterReceiver(bluetoothReceiver)
}
registerReceiver(
bluetoothReceiver,
IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED)
)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
registerReceiver(
bluetoothReceiver,
IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED),
RECEIVER_EXPORTED
)
} else {
registerReceiver(
bluetoothReceiver,
IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED)
)
}
pvagner marked this conversation as resolved.
Show resolved Hide resolved
audioManager.startBluetoothSco()

runCatching {
unregisterReceiver(recorderReceiver)
}
registerReceiver(recorderReceiver, IntentFilter(RECORDER_INTENT_ACTION))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
registerReceiver(recorderReceiver, IntentFilter(RECORDER_INTENT_ACTION), RECEIVER_EXPORTED)
} else {
registerReceiver(recorderReceiver, IntentFilter(RECORDER_INTENT_ACTION))
}
pvagner marked this conversation as resolved.
Show resolved Hide resolved

super.onCreate()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ class ScreenRecorderService : RecorderService() {
Log.e("Media Projection Error", e.toString())
onDestroy()
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
mediaProjection!!.registerCallback(object : MediaProjection.Callback() {
override fun onStop() {
onDestroy()
}
}, null)
}
}

override fun start() {
Expand Down
Loading