Fix the camera permission step on Android

Review the AI's codeEasy10 minGoogle style

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:

  1. Not declared in the manifest: declare_in_manifest.
  2. Granted: open_camera, whatever the denial count.
  3. Denied 2 or more times: open_app_settings. Android stops showing the prompt after the second denial.
  4. Denied exactly once: show_rationale.
  5. Otherwise, including a negative count: request_permission.

Examples

next_permission_action(manifest_declared: bool, granted: bool, denial_count: int) -> str
Example 1
Inputnext_permission_action(True, False, 0)
Output"request_permission"
Example 2
Inputnext_permission_action(True, True, 0)
Output"open_camera"
Example 3
Inputnext_permission_action(True, False, 2)
Output"open_app_settings"