Skip to content

Commit 217fd53

Browse files
authored
Merge pull request #5483 from nextcloud/bugfix/noid/fixForegroundServicePermissionCrash
fix foreground service permission crash
2 parents e03134b + cb458bc commit 217fd53

File tree

4 files changed

+19
-23
lines changed

4 files changed

+19
-23
lines changed

.github/workflows/analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
run: |
7272
mkdir -p "$HOME/.gradle"
7373
{
74-
echo "org.gradle.jvmargs=-Xmx5g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:+UseParallelGC -XX:MaxMetaspaceSize=1g"
74+
echo "org.gradle.jvmargs=-Xmx3g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:+UseParallelGC -XX:MaxMetaspaceSize=1g"
7575
echo "org.gradle.configureondemand=true"
7676
echo "kapt.incremental.apt=true"
7777
} > "$HOME/.gradle/gradle.properties"

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@
306306
<service
307307
android:name=".services.CallForegroundService"
308308
android:exported="false"
309-
android:foregroundServiceType="phoneCall|microphone|camera" />
309+
android:foregroundServiceType="microphone|camera" />
310310

311311
<provider
312312
android:name="androidx.core.content.FileProvider"

app/src/main/java/com/nextcloud/talk/activities/CallActivity.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,6 @@ class CallActivity : CallBaseActivity() {
387387
setContentView(binding!!.root)
388388
hideNavigationIfNoPipAvailable()
389389
processExtras(intent.extras!!)
390-
CallForegroundService.start(applicationContext, conversationName, intent.extras)
391-
392390
conversationUser = currentUserProvider.currentUser.blockingGet()
393391

394392
credentials = ApiUtils.getCredentials(conversationUser!!.username, conversationUser!!.token)
@@ -1039,6 +1037,7 @@ class CallActivity : CallBaseActivity() {
10391037
checkRecordingConsentAndInitiateCall()
10401038

10411039
if (permissionUtil!!.isMicrophonePermissionGranted()) {
1040+
CallForegroundService.start(applicationContext, conversationName, intent.extras)
10421041
if (!microphoneOn) {
10431042
onMicrophoneClick()
10441043
}

app/src/main/java/com/nextcloud/talk/services/CallForegroundService.kt

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,15 @@ class CallForegroundService : Service() {
2929

3030
override fun onBind(intent: Intent?): IBinder? = null
3131

32+
@Suppress("ForegroundServiceType")
3233
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
3334
val conversationName = intent?.getStringExtra(EXTRA_CONVERSATION_NAME)
3435
val callExtras = intent?.getBundleExtra(EXTRA_CALL_INTENT_EXTRAS)
3536
val notification = buildNotification(conversationName, callExtras)
3637

3738
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
38-
startForeground(
39-
NOTIFICATION_ID,
40-
notification,
41-
resolveForegroundServiceType(callExtras)
42-
)
39+
val foregroundServiceType = resolveForegroundServiceType(callExtras)
40+
startForeground(NOTIFICATION_ID, notification, foregroundServiceType)
4341
} else {
4442
startForeground(NOTIFICATION_ID, notification)
4543
}
@@ -90,21 +88,20 @@ class CallForegroundService : Service() {
9088
}
9189

9290
private fun resolveForegroundServiceType(callExtras: Bundle?): Int {
93-
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
94-
return 0
95-
}
96-
97-
var serviceType = ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE
98-
val isVoiceOnlyCall = callExtras?.getBoolean(KEY_CALL_VOICE_ONLY, false) ?: false
99-
val canPublishVideo = callExtras?.getBoolean(
100-
KEY_PARTICIPANT_PERMISSION_CAN_PUBLISH_VIDEO,
101-
false
102-
) ?: false
103-
104-
if (!isVoiceOnlyCall && canPublishVideo) {
105-
serviceType = serviceType or ServiceInfo.FOREGROUND_SERVICE_TYPE_CAMERA
91+
var serviceType = 0
92+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
93+
serviceType = serviceType or ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE
94+
95+
val isVoiceOnlyCall = callExtras?.getBoolean(KEY_CALL_VOICE_ONLY, false) ?: false
96+
val canPublishVideo = callExtras?.getBoolean(
97+
KEY_PARTICIPANT_PERMISSION_CAN_PUBLISH_VIDEO,
98+
false
99+
) ?: false
100+
101+
if (!isVoiceOnlyCall && canPublishVideo) {
102+
serviceType = serviceType or ServiceInfo.FOREGROUND_SERVICE_TYPE_CAMERA
103+
}
106104
}
107-
108105
return serviceType
109106
}
110107

0 commit comments

Comments
 (0)