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 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
9 changes: 6 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,13 @@

<service
android:name=".services.AudioRecorderService"
android:exported="false" />
android:exported="false"
android:foregroundServiceType="microphone" />

<service
android:name=".services.LosslessRecorderService"
android:exported="false" />
android:exported="false"
android:foregroundServiceType="microphone" />

<receiver
android:name=".receivers.FinishedNotificationReceiver"
Expand Down Expand Up @@ -95,4 +98,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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.app.ServiceCompat
import androidx.core.content.ContextCompat
import androidx.documentfile.provider.DocumentFile
import androidx.lifecycle.LifecycleService
import androidx.lifecycle.lifecycleScope
Expand Down Expand Up @@ -91,16 +92,18 @@ abstract class RecorderService : LifecycleService() {
runCatching {
unregisterReceiver(bluetoothReceiver)
}
registerReceiver(
ContextCompat.registerReceiver(
this,
bluetoothReceiver,
IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED)
IntentFilter(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED),
RECEIVER_EXPORTED
)
audioManager.startBluetoothSco()

runCatching {
unregisterReceiver(recorderReceiver)
}
registerReceiver(recorderReceiver, IntentFilter(RECORDER_INTENT_ACTION))
ContextCompat.registerReceiver(this, recorderReceiver, IntentFilter(RECORDER_INTENT_ACTION), RECEIVER_EXPORTED)

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