Skip to content

Commit

Permalink
AND-27 Improve behaviour when receiving incoming call when device is …
Browse files Browse the repository at this point in the history
…locked (#1273)

* Enable display on lock screen

* Fix canSkiPermissionRationale typo

* Clean up

---------

Co-authored-by: Aleksandar Apostolov <[email protected]>
  • Loading branch information
liviu-timar and aleksandar-apostolov authored Jan 9, 2025
1 parent 1d69320 commit 9dbdd10
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion demo-app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@
<activity
android:name=".CallActivity"
android:supportsPictureInPicture="true"
android:showOnLockScreen="true"
android:showWhenLocked="true"
android:turnScreenOn="true"
android:launchMode="singleTop"
android:exported="false">
<intent-filter android:priority="1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ public class io/getstream/video/android/compose/ui/ComposeStreamCallActivity : i
public static final field $stable I
public fun <init> ()V
public fun getUiDelegate ()Lio/getstream/video/android/ui/common/StreamActivityUiDelegate;
public fun onPreCreate (Landroid/os/Bundle;Landroid/os/PersistableBundle;)V
}

public class io/getstream/video/android/compose/ui/StreamCallActivityComposeDelegate : io/getstream/video/android/compose/ui/StreamCallActivityComposeUi {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
<activity
android:name=".ui.ComposeStreamCallActivity"
android:supportsPictureInPicture="true"
android:showOnLockScreen="true"
android:showWhenLocked="true"
android:turnScreenOn="true"
android:launchMode="singleTop"
android:exported="false">
<intent-filter android:priority="1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@

package io.getstream.video.android.compose.ui

import android.app.KeyguardManager
import android.os.Build
import android.os.Bundle
import android.os.PersistableBundle
import android.view.WindowManager
import io.getstream.video.android.ui.common.StreamActivityUiDelegate
import io.getstream.video.android.ui.common.StreamCallActivity
import io.getstream.video.android.ui.common.util.StreamCallActivityDelicateApi

/**
* Default [StreamCallActivity] for use with compose.
Expand All @@ -27,4 +33,24 @@ public open class ComposeStreamCallActivity : StreamCallActivity() {

override val uiDelegate: StreamActivityUiDelegate<StreamCallActivity> =
StreamCallActivityComposeDelegate()

@StreamCallActivityDelicateApi
override fun onPreCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
enableDisplayOnLockScreen()
super.onPreCreate(savedInstanceState, persistentState)
}

private fun enableDisplayOnLockScreen() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
val keyguardManager = getSystemService(KEYGUARD_SERVICE) as? KeyguardManager
keyguardManager?.requestDismissKeyguard(this, null)
} else {
@Suppress("DEPRECATION")
window.addFlags(
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD or
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON,
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public open class StreamCallActivityComposeDelegate : StreamCallActivityComposeU
granted: List<String>,
notGranted: List<String>,
) {
if (!showRationale && configuration.canSkiPermissionRationale) {
if (!showRationale && configuration.canSkipPermissionRationale) {
logger.w { "Permissions were not granted, but rationale is required to be skipped." }
finish()
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public final class io/getstream/video/android/ui/common/StreamCallActivityConfig
public static synthetic fun copy$default (Lio/getstream/video/android/ui/common/StreamCallActivityConfiguration;ZZZZLandroid/os/Bundle;ILjava/lang/Object;)Lio/getstream/video/android/ui/common/StreamCallActivityConfiguration;
public fun equals (Ljava/lang/Object;)Z
public final fun getCanKeepScreenOn ()Z
public final fun getCanSkiPermissionRationale ()Z
public final fun getCanSkipPermissionRationale ()Z
public final fun getCloseScreenOnCallEnded ()Z
public final fun getCloseScreenOnError ()Z
public final fun getCustom ()Landroid/os/Bundle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public data class StreamCallActivityConfiguration(
/** When the call has ended for any reason, close the screen */
val closeScreenOnCallEnded: Boolean = true,
/** When set to false, the activity will simply ignore the `showRationale` from the system and show the rationale screen anyway. */
val canSkiPermissionRationale: Boolean = true,
val canSkipPermissionRationale: Boolean = true,
/** When set to true, the activity will keep the screen on. */
val canKeepScreenOn: Boolean = true,
/**
Expand All @@ -62,7 +62,7 @@ public fun Bundle.extractStreamActivityConfig(): StreamCallActivityConfiguration
closeScreenOnError = closeScreenOnError,
closeScreenOnCallEnded = closeScreenOnCallEnded,
canKeepScreenOn = canKeepScreenOn,
canSkiPermissionRationale = canSkipPermissionRationale,
canSkipPermissionRationale = canSkipPermissionRationale,
custom = custom,
)
}
Expand All @@ -76,7 +76,7 @@ public fun StreamCallActivityConfiguration.toBundle(): Bundle {
bundle.putBoolean(StreamCallActivityConfigStrings.EXTRA_CLOSE_ON_ENDED, closeScreenOnCallEnded)
bundle.putBoolean(
StreamCallActivityConfigStrings.EXTRA_CAN_SKIP_RATIONALE,
canSkiPermissionRationale,
canSkipPermissionRationale,
)
bundle.putBoolean(StreamCallActivityConfigStrings.EXTRA_KEEP_SCREEN_ON, canKeepScreenOn)
bundle.putBundle(StreamCallActivityConfigStrings.EXTRA_CUSTOM, custom)
Expand Down

0 comments on commit 9dbdd10

Please sign in to comment.