Repository navigation
fix(call): keep the incoming call window open on a sleeping phone - #6851
ToteMeiSter wants to merge 13 commits into
Conversation
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🔵 Low · up to A screen-off transition can leave the active call window eligible to appear over the lock screen when the phone wakes. Clear the lock-screen override before skipping PiP; the correction is localized, so the remaining risk is bounded. Pre-merge checks |
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Organization UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
a14c18d0-6b96-4ab2-9207-d5d0228d4bd9
📒 Files selected for processing (3)
app/src/main/AndroidManifest.xmlapp/src/main/java/com/nextcloud/talk/activities/CallBaseActivity.javaapp/src/main/java/com/nextcloud/talk/callnotification/CallNotificationActivity.kt
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
|
Hello there, We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process. Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6 Thank you for contributing to Nextcloud and we hope to hear from you soon! (If you believe you should not receive this message, you can add yourself to the blocklist.) |
|
Thank you for you contributions. We will try to review this soon! |
f21d382 to
acc45dd
Compare
|
…y stopped CallNotificationActivity.onStop() removed the call notification. The window closes itself once the notification is gone. On a sleeping phone the window opened by the full-screen intent gets a short onStop at once, so the call screen disappeared after about a second and the caller did not get through. Home and the power button did the same. The notification is now removed only when the window is finishing. Decline still removes it, answering is handled by CallActivity. Signed-off-by: Krainov Gleb <krajnov.g@kontentplus.ru> Assisted-by: Claude-Code:claude-opus-5-5
…w in the manifest The platform decides in ActivityRecord.completeResumeLocked whether a started activity may pause for a sleeping screen. It reads turnScreenOn and showWhenLocked from the manifest. The setTurnScreenOn() and setShowWhenLocked() calls in onCreate reach the system server too late, so the window paused, stopped and resumed again. With the manifest attributes the platform wakes the screen at once and skips the extra pause. The attributes need API 27. The calls in CallBaseActivity.dismissKeyguard() stay for API 26. Signed-off-by: Krainov Gleb <krajnov.g@kontentplus.ru> Assisted-by: Claude-Code:claude-opus-5-5
…ing screen The incoming call window is started by a full-screen intent on a sleeping screen. The platform then pauses and may stop it before the screen wakes up and resumes it again. This is the normal lifecycle, so the window must not read it as a decision of the user. - CallNotificationActivity removes the call notification only when the window is finishing (decline, closing the window, e2ee refusal), in onDestroy. The old onStop override is gone. A window that finished in onCreate has no notification timestamp and does not crash. - CallBaseActivity does not enter PiP when the screen is not interactive. Entering PiP calls enableKeyguard(), which hides the window behind the lock screen on API 26-30. - CallBaseActivity logs the interactive and keyguard state in onStart, onPause, onStop and onTopResumedActivityChanged. Signed-off-by: Krainov Gleb <krajnov.g@kontentplus.ru> Assisted-by: Claude-Code:claude-opus-5-5
…destroyed The Runnable that finishes the window once the call notification is gone ran on a local Handler that onDestroy never cleared. Now that the window may stay alive in the background, a recreated window (dark mode, locale, font scale) left the old loop running, holding the destroyed activity and calling finish() on it every second until the notification was gone. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
CallNotificationActivity is singleTask and the full-screen intent uses CLEAR_TOP | SINGLE_TOP, so a second incoming call reached the existing window through onNewIntent, which was not handled. Now that the window survives Home and the power button, it kept showing the first call: answer joined the wrong room and decline cancelled the wrong notification. A new intent for another notification now recreates the window. The first call keeps its notification. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
The interactive and keyguard state logged on every lifecycle step cost two system service calls each time and was only needed to find the bug. The onDestroy comment of CallNotificationActivity is shortened and no longer names an e2ee refusal, which CallNotificationActivity does not have anymore. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
The handler field of CallNotificationActivity never posted anything and only marked the first onStart for the cache eviction, next to a second handler for the notification check. One main thread handler and an isCacheEvicted flag replace both. leavingScreen was never read and is removed. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
… picture window Cancelling the call notification for every finishing onDestroy also stopped the ringing when the system removed the background task of the call window, for example after Home and opening another app. The call then disappeared without a missed call notification. On Android 10 and later, closing the picture in picture window only stops the window, so that no longer stopped the ringing. Decline now cancels the notification directly. Closing the picture in picture window is detected by the mode change while the window is stopped, and by a finishing destroy while still in picture in picture on older versions. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
- Bundle.getInt returns 0 for a missing key, so an intent without a notification timestamp recreated the window, which then closed itself. - The notification check of the old call is stopped before recreate(), so it can not finish the window and drop the relaunch. - A window recreated while in picture in picture gets no mode change, so it sets up the picture in picture layout itself. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
… screen state Addresses code-review findings on top of the sleeping-screen fix: - CallNotificationActivity: the notification id is the push timestamp, but a missing KEY_NOTIFICATION_TIMESTAMP extra decodes to 0 (not null) via Bundle.getInt(). Add notificationIdOrNull() so notificationTimestamp is null when no notification backs the window; the onDestroy guard then no longer cancels an unrelated id 0, and setupNotificationCanceledRoutine() closes a window with no backing notification instead of polling id 0 forever. - CallNotificationActivity: accepting a call now dismisses the ringing notification in proceedToCall() via a shared dismissCallNotification() helper instead of relying on CallActivity to cancel it from the forwarded extras. - CallBaseActivity: gate setAutoEnterEnabled on the screen being interactive via the pure shouldAutoEnterPip() predicate, and re-evaluate it on ACTION_SCREEN_ON /OFF, so API 31+ does not auto-enter picture in picture behind the keyguard when the display sleeps. Add unit tests for notificationIdOrNull() and shouldAutoEnterPip(). Cherry-picked onto the reworked branch: the notification is no longer cancelled for every finishing onDestroy but on decline, answer and closing the picture in picture window, so the onDestroy part is dropped. The notification check uses the shared handler of the window, and dismissCallNotification() replaces the identical cancelCallNotification(). Signed-off-by: rapterjet2004 <juliuslinus1@gmail.com> Assisted-by: Claude Code:claude-opus-4-8
…up an expanded one A picture in picture mode change while the window was stopped counted as closing the window. Expanding a stopped window, for example from the call notification on the lock screen, can deliver the mode change before the start, so the call was declined without the user deciding it. The check now runs one second later and only hangs up when the window has not started again and the device is not locked. On older Android versions closing picture in picture finishes the window, but the mode change may already have cleared isInPipMode. onDestroy now uses a flag that is only cleared when the window resumes outside of picture in picture. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
…en state With turnScreenOn the screen wakes up while the call window is created. When SCREEN_ON was sent between the interactive check and the registration, auto enter picture in picture stayed off for the whole call. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
The notification id is the push timestamp in milliseconds cut to an Int, so 0 and negative values are valid ids. notificationIdOrNull now reads the extras and returns null only when the timestamp extra is missing. onNewIntent uses it too and ignores intents without an id. The tests check the helper with real Bundles, drop a test that repeated the others, and no longer use section dividers or describe the change history. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
acc45dd to
4cdd948
Compare
🖼️ Screenshots
No UI change.
🚧 Problem
On a sleeping phone the incoming call window is started by the full-screen intent and closes again after about one second. The caller does not get through.
Cause. The platform decides in
ActivityRecord.completeResumeLockedwhether a just resumed activity turns the screen on or goes to sleep (android-12.0.0_r34, ActivityRecord.java#5425):canTurnScreenOn()needsturnScreenOnandshowWhenLocked.CallBaseActivitysets both withsetTurnScreenOn()/setShowWhenLocked()inonCreate. These are one-way calls and reach the system server after that decision, so the window is resumed, paused for the sleeping display, often stopped, and resumed again when the screen wakes up. The documentation ofR.attr.turnScreenOndescribes exactly this: "When using the Window flag during activity startup, there may not be time to add it before the system stops your activity because the screen has not yet turned on. This leads to a double life-cycle as it is then restarted." The manifest only hasshowOnLockScreen, which is the old name ofshowForAllUsers.Device logs (Android 12): all 7 call windows started on a sleeping screen got two
onResume; 3 of them got anonStopin between, 35–70 ms after the firstonResume.The window then reads this
onStopas the user leaving:onStop()cancels the call notification, andsetupNotificationCanceledRoutinecloses the window within a second because the notification is gone.On API 26–30 the same pause also calls
enterPipMode()fromonTopResumedActivityChanged(false)/onPause(). It first callsenableKeyguard()(setShowWhenLocked(false)), and PiP is refused on the lock screen, so the window ends up behind the keyguard.Possibly related: #6585, #2763.
🔧 Change
CallNotificationActivitydeclaresandroid:showWhenLockedandandroid:turnScreenOn. The platform knows them before the start, wakes the screen at once and does not pause the window. The calls indismissKeyguard()stay for API 26.onStop; it cancels it inonDestroyonly when finishing (decline, e2ee refusal, closing the window). A stop for any other reason (Home, power button, another app) keeps the notification, the ringing and the window. A window finished inonCreatehas no timestamp and no longer crashes there.CallBaseActivitydoes not enter PiP while the screen is not interactive: a pause of a sleeping screen is not the user leaving. On API 26–30 the call window stays on the lock screen, the same as on API 31+.CallBaseActivitylogs the interactive and keyguard state inonStart,onPause,onStopandonTopResumedActivityChanged.Not changed:
CallActivity.processExtrascancels the notification forKEY_FROM_NOTIFICATION_START_CALL; the routine then closes the window.getPeersForCallcheck inNotificationWorkerremove the notification as before; the routine closes the window.🧪 How to verify
CallBaseActivityshows noonStopbetween start and answer.🏁 Checklist
CallNotificationActivitycannot be created in a Robolectric test without the Dagger application graph (onCreateinjects it), and the change inCallBaseActivityis a single check ofPowerManager.isInteractive()inside the activity./backport to stable-xx.x🤖 AI (if applicable)
The change was prepared with Claude Code (
Assisted-by: Claude-Code:claude-opus-5-5). The cause was found in device logs of affected phones and in the AOSP sources; the fix has not been tested on a device yet.