Skip to content
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
335 changes: 247 additions & 88 deletions stream-video-android-core/api/stream-video-android-core.api

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

package io.getstream.video.android.core

import android.content.Context.POWER_SERVICE
import android.content.Intent
import android.graphics.Bitmap
import android.os.PowerManager
import androidx.annotation.VisibleForTesting
import androidx.compose.runtime.Stable
import io.getstream.log.taggedLogger
Expand All @@ -44,6 +46,7 @@ import io.getstream.video.android.core.model.VideoTrack
import io.getstream.video.android.core.model.toIceServer
import io.getstream.video.android.core.utils.RampValueUpAndDownHelper
import io.getstream.video.android.core.utils.safeCall
import io.getstream.video.android.core.utils.safeCallWithDefault
import io.getstream.video.android.core.utils.toQueriedMembers
import io.getstream.video.android.model.User
import io.getstream.webrtc.android.ui.VideoTextureViewRenderer
Expand Down Expand Up @@ -130,6 +133,7 @@ public class Call(
private val logger by taggedLogger("Call:$type:$id")
private val supervisorJob = SupervisorJob()
private var callStatsReportingJob: Job? = null
private var powerManager: PowerManager? = null

private val scope = CoroutineScope(clientImpl.scope.coroutineContext + supervisorJob)

Expand Down Expand Up @@ -266,6 +270,9 @@ public class Call(
audioLevelOutputHelper.rampToValue(it)
}
}
powerManager = safeCallWithDefault(null) {
clientImpl.context.getSystemService(POWER_SERVICE) as? PowerManager
}
}

/** Basic crud operations */
Expand Down Expand Up @@ -465,6 +472,7 @@ public class Call(
sfuWsUrl = sfuWsUrl,
sfuToken = sfuToken,
remoteIceServers = iceServers,
powerManager = powerManager,
)
}

Expand Down Expand Up @@ -643,6 +651,7 @@ public class Call(
session.prepareRejoin()
this.session = RtcSession(
clientImpl,
powerManager,
this,
sessionId,
clientImpl.apiKey,
Expand Down Expand Up @@ -694,6 +703,7 @@ public class Call(
session.prepareRejoin()
val newSession = RtcSession(
clientImpl,
powerManager,
this,
sessionId,
clientImpl.apiKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
package io.getstream.video.android.core.call

import android.os.Build
import android.os.PowerManager
import android.os.PowerManager.THERMAL_STATUS_CRITICAL
import android.os.PowerManager.THERMAL_STATUS_EMERGENCY
import android.os.PowerManager.THERMAL_STATUS_LIGHT
import android.os.PowerManager.THERMAL_STATUS_MODERATE
import android.os.PowerManager.THERMAL_STATUS_NONE
import android.os.PowerManager.THERMAL_STATUS_SEVERE
import android.os.PowerManager.THERMAL_STATUS_SHUTDOWN
import androidx.annotation.VisibleForTesting
import androidx.lifecycle.Lifecycle
import io.getstream.log.taggedLogger
Expand Down Expand Up @@ -68,6 +76,7 @@ import io.getstream.video.android.core.utils.buildMediaConstraints
import io.getstream.video.android.core.utils.buildRemoteIceServers
import io.getstream.video.android.core.utils.mangleSdpUtil
import io.getstream.video.android.core.utils.mapState
import io.getstream.video.android.core.utils.safeCallWithDefault
import io.getstream.video.android.core.utils.stringify
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
Expand Down Expand Up @@ -110,6 +119,8 @@ import stream.video.sfu.event.JoinRequest
import stream.video.sfu.event.LeaveCallRequest
import stream.video.sfu.event.ReconnectDetails
import stream.video.sfu.event.SfuRequest
import stream.video.sfu.models.AndroidState
import stream.video.sfu.models.AndroidThermalState
import stream.video.sfu.models.ClientDetails
import stream.video.sfu.models.Device
import stream.video.sfu.models.ICETrickle
Expand Down Expand Up @@ -184,6 +195,7 @@ data class TrackDimensions(
*/
public class RtcSession internal constructor(
client: StreamVideo,
private val powerManager: PowerManager?,
private val call: Call,
private val sessionId: String,
private val apiKey: String,
Expand Down Expand Up @@ -1628,6 +1640,26 @@ public class RtcSession internal constructor(

internal suspend fun sendCallStats(report: CallStatsReport) {
val result = wrapAPICall {
val androidThermalState =
safeCallWithDefault(AndroidThermalState.ANDROID_THERMAL_STATE_UNSPECIFIED) {
val thermalState = powerManager?.currentThermalStatus
logger.d { "[sendCallStats] #thermals state: $thermalState" }
when (thermalState) {
THERMAL_STATUS_NONE -> AndroidThermalState.ANDROID_THERMAL_STATE_NONE
THERMAL_STATUS_LIGHT -> AndroidThermalState.ANDROID_THERMAL_STATE_LIGHT
THERMAL_STATUS_MODERATE -> AndroidThermalState.ANDROID_THERMAL_STATE_MODERATE
THERMAL_STATUS_SEVERE -> AndroidThermalState.ANDROID_THERMAL_STATE_SEVERE
THERMAL_STATUS_CRITICAL -> AndroidThermalState.ANDROID_THERMAL_STATE_CRITICAL
THERMAL_STATUS_EMERGENCY -> AndroidThermalState.ANDROID_THERMAL_STATE_EMERGENCY
THERMAL_STATUS_SHUTDOWN -> AndroidThermalState.ANDROID_THERMAL_STATE_SHUTDOWN
else -> AndroidThermalState.ANDROID_THERMAL_STATE_UNSPECIFIED
}
}
val powerSaving = safeCallWithDefault(false) {
val powerSaveMode = powerManager?.isPowerSaveMode
logger.d { "[sendCallStats] #powerSaveMode state: $powerSaveMode" }
powerSaveMode ?: false
}
sfuConnectionModule.api.sendStats(
sendStatsRequest = SendStatsRequest(
session_id = sessionId,
Expand All @@ -1636,6 +1668,10 @@ public class RtcSession internal constructor(
webrtc_version = BuildConfig.STREAM_WEBRTC_VERSION,
publisher_stats = report.toJson(StreamPeerType.PUBLISHER),
subscriber_stats = report.toJson(StreamPeerType.SUBSCRIBER),
android = AndroidState(
thermal_state = androidThermalState,
is_power_saver_mode = powerSaving,
),
),
)
}
Expand Down
Loading
Loading