Fix the camera permission step on Android
Your task
An AI wrote Android camera code that called Camera.open() straight away, because the CAMERA permission was declared in the manifest. On a fresh install it crashed with a SecurityException: a manifest entry only asks for a permission, and the user must grant it at runtime. The fix decides the next step from the permission state.
An assistant wrote next_permission_action(manifest_declared, granted, denial_count). It is in the editor. It has a bug. Find it and fix it.
Input and output:
manifest_declared: CAMERA is declared in the manifest.granted: the permission is granted right now.denial_count: how many times the user has denied the request.- Return the next step as a string.
Rules the tests check. Return the first that applies:
- Not declared in the manifest:
declare_in_manifest. - Granted:
open_camera, whatever the denial count. - Denied 2 or more times:
open_app_settings. Android stops showing the prompt after the second denial. - Denied exactly once:
show_rationale. - Otherwise, including a negative count:
request_permission.
Examples
next_permission_action(manifest_declared: bool, granted: bool, denial_count: int) -> strExample 1
Input
next_permission_action(True, False, 0)Output
"request_permission"Example 2
Input
next_permission_action(True, True, 0)Output
"open_camera"Example 3
Input
next_permission_action(True, False, 2)Output
"open_app_settings"