Skip to content

Commit

Permalink
Revert "switch foreground service type"
Browse files Browse the repository at this point in the history
This reverts commit a518a3d.
  • Loading branch information
mwarning committed Aug 29, 2024
1 parent b7da2d3 commit 86cebda
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
5 changes: 2 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
android:name="android.hardware.camera"
android:required="false" />

<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CAMERA" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />

<!-- Backup Import/Export -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Expand Down Expand Up @@ -57,7 +56,7 @@
<service
android:name=".MainService"
android:exported="false"
android:foregroundServiceType="camera|microphone" />
android:foregroundServiceType="mediaPlayback" />

<activity
android:name=".StartActivity"
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/kotlin/d/d/meshenger/MainService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ package d.d.meshenger
import android.app.*
import android.content.Context
import android.content.Intent
import android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_CAMERA
import android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE
import android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK
import android.graphics.Color
import android.os.Binder
import android.os.Build
Expand Down Expand Up @@ -187,7 +186,7 @@ class MainService : Service(), Runnable {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
startForeground(NOTIFICATION_ID, notification)
} else {
startForeground(NOTIFICATION_ID, notification, FOREGROUND_SERVICE_TYPE_MICROPHONE or FOREGROUND_SERVICE_TYPE_CAMERA)
startForeground(NOTIFICATION_ID, notification, FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK)
}
} else if (intent.action == STOP_FOREGROUND_ACTION) {
Log.d(this, "onStartCommand() Received Stop Foreground Intent")
Expand Down

7 comments on commit 86cebda

@iddq
Copy link

@iddq iddq commented on 86cebda Sep 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't use both in same time? it fixed the problem on samsung android 13

https://developer.android.com/about/versions/14/changes/fgs-types-required

@mwarning
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of the foreground service here is to accept incoming calls.

Can you explain what you fixed on samsung on android 13? And how?

@iddq
Copy link

@iddq iddq commented on 86cebda Sep 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it fixed the microphone access problem of non foreground meshenger

#160 (comment)

@mwarning
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iddq ok, and how? By using FOREGROUND_SERVICE_TYPE_MICROPHONE and FOREGROUND_SERVICE_TYPE_CAMERA?
If that is the case, then have you tried to reinstall Meshenger to see if it still works?

@iddq
Copy link

@iddq iddq commented on 86cebda Sep 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understood the Android documentation correctly, for the FGS to access the microphone even when the app is not in the foreground, the FOREGROUND_SERVICE_TYPE_MICROPHONE is necessary. So, I don’t understand how this can work on some devices without it… If you find that in certain cases the FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK works better, it might be worth trying to specify all the above service types at once.

@mwarning
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not certain yet and need to perform more testing. But to put a CallActivity into background does not make it a FGS. And the FGS is starting the MainActivity. So I am not entirely certain this will fix the issue.

@iddq
Copy link

@iddq iddq commented on 86cebda Sep 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is microphone access handled from the MainService FGS?

Please sign in to comment.