Skip to content

Commit b35471c

Browse files
committed
Move enterPictureInPicture to onUserLeaveHint from onPause and add exception handling.
1 parent bb9c515 commit b35471c

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

stream-video-android-ui-core/api/stream-video-android-ui-core.api

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ public abstract class io/getstream/video/android/ui/common/StreamCallActivity :
6969
public fun onResume (Lio/getstream/video/android/core/Call;)V
7070
public final fun onStop ()V
7171
public fun onStop (Lio/getstream/video/android/core/Call;)V
72+
public final fun onUserLeaveHint ()V
73+
public fun onUserLeaveHint (Lio/getstream/video/android/core/Call;)V
7274
public fun reject (Lio/getstream/video/android/core/Call;Lio/getstream/video/android/core/model/RejectReason;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)V
7375
public static synthetic fun reject$default (Lio/getstream/video/android/ui/common/StreamCallActivity;Lio/getstream/video/android/core/Call;Lio/getstream/video/android/core/model/RejectReason;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)V
7476
}

stream-video-android-ui-core/src/main/kotlin/io/getstream/video/android/ui/common/StreamCallActivity.kt

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import android.app.PictureInPictureParams
2020
import android.content.Context
2121
import android.content.Intent
2222
import android.content.pm.ActivityInfo
23+
import android.content.pm.PackageManager
2324
import android.os.Build
2425
import android.os.Bundle
2526
import android.os.PersistableBundle
@@ -231,6 +232,13 @@ public abstract class StreamCallActivity : ComponentActivity() {
231232
}
232233
}
233234

235+
public final override fun onUserLeaveHint() {
236+
withCachedCall {
237+
onUserLeaveHint(it)
238+
super.onUserLeaveHint()
239+
}
240+
}
241+
234242
public final override fun onPause() {
235243
withCachedCall {
236244
onPause(it)
@@ -352,20 +360,36 @@ public abstract class StreamCallActivity : ComponentActivity() {
352360
}
353361

354362
/**
355-
* Called when the activity is paused. Makes sure the call object is available.
363+
* Called when the activity is about to go into the background as the result of user choice. Makes sure the call object is available.
356364
*
357365
* @param call the call
358366
*/
359-
public open fun onPause(call: Call) {
367+
public open fun onUserLeaveHint(call: Call) {
360368
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
361369
// Default PiP behavior
362-
if (isConnected(call) &&
370+
if (packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE) &&
371+
isConnected(call) &&
363372
!isChangingConfigurations &&
364373
isVideoCall(call) &&
365374
!isInPictureInPictureMode
366375
) {
367-
enterPictureInPicture()
376+
try {
377+
enterPictureInPicture()
378+
} catch (e: Exception) {
379+
logger.e(e) { "[onUserLeaveHint] Something went wrong when entering PiP." }
380+
}
368381
}
382+
383+
logger.d { "DefaultCallActivity - Leave Hinted (call -> $call)" }
384+
}
385+
386+
/**
387+
* Called when the activity is paused. Makes sure the call object is available.
388+
*
389+
* @param call the call
390+
*/
391+
public open fun onPause(call: Call) {
392+
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
369393
logger.d { "DefaultCallActivity - Paused (call -> $call)" }
370394
}
371395

0 commit comments

Comments
 (0)