Skip to content

Camera resource preemption in multi-window mode causing app crash #870

Open
@Huimilia

Description

@Huimilia

Code of conduct

Self-training on how to write a bug report

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Issue Description
In multi-window mode, when an application is running in full-screen mode and using the camera, if another application is opened in floating window mode and takes control of the camera resource, a focus switch may cause the original application’s camera resource to fail to recover properly. When the user switches back to the original application, the camera resource should be restored for use. However, in practice, the application interface may freeze or crash, and the application needs to be restarted to recover normal functionality.

Expected Behavior
In multi-window mode, applications using the camera resource should be able to smoothly transfer camera resource control during focus changes:

  • When the application loses focus, it should suspend its use of the camera resource.
  • When the application regains focus, it should be able to resume access to the camera resource without affecting the user experience.

Suggested Solution
It is recommended to add appropriate logic in the onWindowFocusChanged method to handle the camera resource allocation during focus changes. This method is triggered when the Activity's window focus state changes, including when the application starts for the first time or when returning from another Activity. By checking the hasFocus parameter, the application can determine whether it has regained focus, and if so, it should attempt to reinitialize or request access to the camera resource. In multi-window mode, adding this logic can help better coordinate the use of camera resources, thereby improving the application’s stability and user experience in multi-tasking scenarios. Below is an example of pseudocode:

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);

    if (hasFocus) {
        // Activity has gained focus
        if (isInMultiWindowMode()) {
            Log.i("CameraHandler", "Attempting to reinitialize camera...");
            try {
                // Request camera resource again 
            } catch (Exception e) {
                Log.e("CameraHandler", "Error handling camera during focus change: " + e.getMessage());
            }
        }
    } else {
        // Activity has lost focus
        // Optionally pause camera usage and release resources here
    }
}

By incorporating this logic during focus changes, it can effectively reduce camera resource conflicts in multi-window mode and enhance the application's stability and reliability.

Expected Behavior

No response

Steps To Reproduce

No response

Android Version

Android 12

Session Version

No response

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    JiraThis ticket is being tracked in JirabugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions