Skip to content

Commit

Permalink
[PBE-6041] Fix mic muted in background bug (#1200)
Browse files Browse the repository at this point in the history
* Change CallService type

* Add new AudioCallService and audioCallServiceConfig

* Improve inline docs and comments

* Restore CallService type

* Update KDocs and comments
  • Loading branch information
liviu-timar authored Oct 9, 2024
1 parent 6c62e6a commit f34b377
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4239,6 +4239,7 @@ public final class io/getstream/video/android/core/notifications/internal/servic
}

public final class io/getstream/video/android/core/notifications/internal/service/CallServiceConfigKt {
public static final fun audioCallServiceConfig ()Lio/getstream/video/android/core/notifications/internal/service/CallServiceConfig;
public static final fun callServiceConfig ()Lio/getstream/video/android/core/notifications/internal/service/CallServiceConfig;
public static final fun livestreamAudioCallServiceConfig ()Lio/getstream/video/android/core/notifications/internal/service/CallServiceConfig;
public static final fun livestreamCallServiceConfig ()Lio/getstream/video/android/core/notifications/internal/service/CallServiceConfig;
Expand Down
31 changes: 15 additions & 16 deletions stream-video-android-core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,32 @@

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />

<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />

<!-- Call service permission -->
<!-- Call foreground service permission -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<!-- Optional, if incoming / outgoing calls feature is used -->
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
<uses-permission android:name="android.permission.MANAGE_OWN_CALLS"/>
<!-- Optional, if incoming & outgoing calls are used -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_PHONE_CALL" />
<uses-permission android:name="android.permission.MANAGE_OWN_CALLS"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />

<!-- If the app is only livestream host -->
<!-- Use in a livestream host scenario -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CAMERA" />

<!-- If the app is only livestream viewer/guest type -->
<!-- Use in a livestream viewer/guest scenario -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />

<!-- If the calls support screensharing -->
<!-- Required if calls support screensharing -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION"/>


<application>

<provider
android:name="io.getstream.android.push.delegate.PushDelegateProvider"
android:authorities="${applicationId}.io.getstream.android.push"
Expand Down Expand Up @@ -91,7 +86,6 @@
</intent-filter>
</receiver>


<service android:name=".notifications.internal.service.CallService"
android:foregroundServiceType="shortService|phoneCall"/>

Expand All @@ -112,5 +106,10 @@
android:name=".notifications.internal.service.LivestreamViewerService"
android:foregroundServiceType="mediaPlayback"
android:exported="false" />

<service
android:name=".notifications.internal.service.AudioCallService"
android:foregroundServiceType="microphone"
android:exported="false" />
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import java.net.ConnectException
* @property ensureSingleInstance Verify that only 1 version of the video client exists. Prevents integration mistakes.
* @property videoDomain URL overwrite to allow for testing against a local instance of video.
* @property runForegroundServiceForCalls If set to true, when there is an active call the SDK will run a foreground service to keep the process alive. (default: true)
* @property callServiceConfig Configuration for the call foreground service. See [CallServiceConfig].
* @property localSfuAddress Local SFU address (IP:port) to be used for testing. Leave null if not needed.
* @property sounds Overwrite the default SDK sounds. See [Sounds].
* @property permissionCheck Used to check for system permission based on call capabilities. See [StreamPermissionCheck].
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2014-2024 Stream.io Inc. All rights reserved.
*
* Licensed under the Stream License;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://github.com/GetStream/stream-video-android/blob/main/LICENSE
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.getstream.video.android.core.notifications.internal.service

import android.content.pm.ServiceInfo
import io.getstream.log.TaggedLogger
import io.getstream.log.taggedLogger

internal class AudioCallService : CallService() {
override val logger: TaggedLogger by taggedLogger("AudioCallService")
override val serviceType = ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@ internal const val ANY_MARKER = "ALL_CALL_TYPES"

// API
/**
* Configuration class for the call service.
* Configuration class for the call foreground service.
* @param runCallServiceInForeground If the call service should run in the foreground.
* @param callServicePerType A map of call service per type.
*
* @see callServiceConfig
* @see livestreamCallServiceConfig
* @see livestreamAudioCallServiceConfig
* @see livestreamGuestCallServiceConfig
* @see audioCallServiceConfig
*/
public data class CallServiceConfig(
val runCallServiceInForeground: Boolean = true,
Expand All @@ -38,7 +44,8 @@ public data class CallServiceConfig(
)

/**
* Return a default configuration for the call service configuration.
* Returns the default call foreground service configuration.
* Uses: `FOREGROUND_SERVICE_TYPE_PHONE_CALL`.
*/
public fun callServiceConfig(): CallServiceConfig {
return CallServiceConfig(
Expand All @@ -50,7 +57,8 @@ public fun callServiceConfig(): CallServiceConfig {
}

/**
* Return a default configuration for the call service configuration.
* Returns a foreground service configuration appropriate for livestream hosts.
* Uses: `FOREGROUND_SERVICE_TYPE_CAMERA` and `FOREGROUND_SERVICE_TYPE_MICROPHONE`.
*/
public fun livestreamCallServiceConfig(): CallServiceConfig {
return CallServiceConfig(
Expand All @@ -63,7 +71,8 @@ public fun livestreamCallServiceConfig(): CallServiceConfig {
}

/**
* Return a default configuration for the call service configuration for livestream which has no camera
* Returns a foreground service configuration appropriate for audio-only livestream hosts.
* Uses: `FOREGROUND_SERVICE_TYPE_MICROPHONE`.
*/
public fun livestreamAudioCallServiceConfig(): CallServiceConfig {
return CallServiceConfig(
Expand All @@ -76,7 +85,8 @@ public fun livestreamAudioCallServiceConfig(): CallServiceConfig {
}

/**
* Return a default configuration for the call service configuration.
* Returns a foreground service configuration appropriate for livestream viewers.
* Uses: `FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK`.
*/
public fun livestreamGuestCallServiceConfig(): CallServiceConfig {
return CallServiceConfig(
Expand All @@ -89,6 +99,20 @@ public fun livestreamGuestCallServiceConfig(): CallServiceConfig {
)
}

/**
* Returns a foreground service configuration appropriate for audio-only calls.
* Uses: `FOREGROUND_SERVICE_TYPE_MICROPHONE`.
*/
public fun audioCallServiceConfig(): CallServiceConfig {
return CallServiceConfig(
runCallServiceInForeground = true,
callServicePerType = mapOf(
Pair(ANY_MARKER, CallService::class.java),
Pair("audio_call", AudioCallService::class.java),
),
)
}

// Internal
internal fun resolveServiceClass(callId: StreamCallId, config: CallServiceConfig): Class<*> {
val callType = callId.type
Expand Down

0 comments on commit f34b377

Please sign in to comment.