xref: /aosp_15_r20/frameworks/base/packages/SystemUI/docs/camera.md (revision d57664e9bc4670b3ecf6748a746a57c557b6bc9e)
1*d57664e9SAndroid Build Coastguard Worker# How double-click power launches the camera
2*d57664e9SAndroid Build Coastguard Worker_Last update: July 2022_
3*d57664e9SAndroid Build Coastguard Worker
4*d57664e9SAndroid Build Coastguard Worker## Sequence of events
5*d57664e9SAndroid Build Coastguard Worker1. [PhoneWindowManager.java](/services/core/java/com/android/server/policy/PhoneWindowManager.java) is responsible for all power button presses (see `interceptPowerKeyDown`)
6*d57664e9SAndroid Build Coastguard Worker2. Even though `PhoneWindowManager` has a lot of logic to detect all manner of power button multi-presses and gestures, it also checks with `GestureLauncherService`, which is also [offered the chance](/services/core/java/com/android/server/policy/PhoneWindowManager.java#943) to [intercept](/services/core/java/com/android/server/GestureLauncherService.java) the power key
7*d57664e9SAndroid Build Coastguard Worker3. `GestureLauncherService` is responsible for the camera timeout, and if it detects one, it [forwards it to the StatusBarManagerService](/services/core/java/com/android/server/GestureLauncherService.java) (which hands it off to SystemUI)
8*d57664e9SAndroid Build Coastguard Worker4. Inside SystemUI, `onCameraLaunchDetected` in [CentralSurfacesCommandQueueCallbacks.java](/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesCommandQueueCallbacks.java) looks at the keyguard state and determines
9*d57664e9SAndroid Build Coastguard Worker    1. whether the camera is even allowed
10*d57664e9SAndroid Build Coastguard Worker    2. whether the screen is on; if not, we need to delay until that happens
11*d57664e9SAndroid Build Coastguard Worker    3. whether the device is locked (defined as "keyguard is showing").
12*d57664e9SAndroid Build Coastguard Worker5. If the device is unlocked (no keyguard), the camera is launched immediately
13*d57664e9SAndroid Build Coastguard Worker6. If the keyguard is up, however, [NotificationPanelViewController.launchCamera](/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java) takes over to handle the "secure camera" (a different intent, usually directing to the same app, but giving that app the cue to not allow access to the photo roll, etc).
14*d57664e9SAndroid Build Coastguard Worker7. If the intent would have to launch a resolver (because the user has multiple camera apps installed and has not chosen one to always launch for the `SECURE_CAMERA_INTENT`, then - in order to show the resolver, the lockscreen "bouncer" (authentication method) is first presented
15*d57664e9SAndroid Build Coastguard Worker8. Otherwise (just one secure camera), it is launched
16*d57664e9SAndroid Build Coastguard Worker
17*d57664e9SAndroid Build Coastguard Worker## Which intent launches the camera app?
18*d57664e9SAndroid Build Coastguard Worker[CameraGestureHelper](/packages/SystemUI/src/com/android/systemui/camera/CameraGestureHelper.kt) encapsulate this logic. Roughly:
19*d57664e9SAndroid Build Coastguard Worker* If the keyguard is not showing (device is unlocked)
20*d57664e9SAndroid Build Coastguard Worker    *   `CameraIntents.getInsecureCameraIntent()`, defined to be `MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA`.
21*d57664e9SAndroid Build Coastguard Worker* If the keyguard is showing (device is locked)
22*d57664e9SAndroid Build Coastguard Worker    *   one of `CameraIntents.getInsecureCameraIntent()` or `CameraIntents.getSecureCameraIntent()`, which are `MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA` and `MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE`, respectively
23*d57664e9SAndroid Build Coastguard Worker* Note that starting in Android 12, as required by some OEMs, if the special string resource `config_cameraGesturePackage` is nonempty, this will be treated as a package name to be added to the insecure camera intent, constraining the invocation to that single app and typically preventing implicit intent resolution. This package must be on the device or the camera gesture will no longer work properly
24