1## 7.5\. Cameras 2 3If device implementations include at least one camera, they: 4 5* [C-1-1] MUST declare the `android.hardware.camera.any` feature flag. 6* [C-1-2] MUST be possible for an application to simultaneously allocate 73 RGBA_8888 bitmaps equal to the size of the images produced by the 8largest-resolution camera sensor on the device, while camera is open for the 9purpose of basic preview and still capture. 10* [C-1-3] MUST ensure that the preinstalled default camera application 11handling intents [`MediaStore.ACTION_IMAGE_CAPTURE`](https://developer.android.com/reference/android/provider/MediaStore.html#ACTION_IMAGE_CAPTURE), 12[`MediaStore.ACTION_IMAGE_CAPTURE_SECURE`](https://developer.android.com/reference/android/provider/MediaStore.html#ACTION_IMAGE_CAPTURE_SECURE), 13or 14[`MediaStore.ACTION_VIDEO_CAPTURE`](https://developer.android.com/reference/android/provider/MediaStore.html#ACTION_VIDEO_CAPTURE), 15is responsible for removing the user location in the image metadata before 16sending it to the receiving application when the receiving application does not 17have [`ACCESS_FINE_LOCATION`](https://developer.android.com/reference/android/Manifest.permission.html#ACCESS_FINE_LOCATION). 18 19### 7.5.1\. Rear-Facing Camera 20 21A rear-facing camera is a camera located on the side of 22the device opposite the display; that is, it images scenes on the far side of 23the device, like a traditional camera. 24 25Device implementations: 26 27* SHOULD include a rear-facing camera. 28 29If device implementations include at least one rear-facing camera, they: 30 31* [C-1-1] MUST report the feature flag `android.hardware.camera` and 32`android.hardware.camera.any`. 33* [C-1-2] MUST have a resolution of at least 2 megapixels. 34* SHOULD have either hardware auto-focus or software auto-focus implemented 35in the camera driver (transparent to application software). 36* MAY have fixed-focus or EDOF (extended depth of field) hardware. 37* MAY include a flash. 38 39If the camera includes a flash: 40 41* [C-2-1] the flash lamp MUST NOT be lit while an 42`android.hardware.Camera.PreviewCallback` instance has been registered 43on a Camera preview surface, unless the application has explicitly enabled 44the flash by enabling the `FLASH_MODE_AUTO` or `FLASH_MODE_ON` attributes 45of a `Camera.Parameters` object. Note that this constraint does not apply to the 46device’s built-in system camera application, but only to third-party 47applications using `Camera.PreviewCallback`. 48 49### 7.5.2\. Front-Facing Camera 50 51A front-facing camera is a camera located on the same side of the device 52as the display; that is, a camera typically used to image the user, such 53as for video conferencing and similar applications. 54 55Device implementations: 56 57* MAY include a front-facing camera. 58 59If device implementations include at least one front-facing camera, they: 60 61* [C-1-1] MUST report the feature flag `android.hardware.camera.any` and 62`android.hardware.camera.front`. 63* [C-1-2] MUST have a resolution of at least VGA (640x480 pixels). 64* [C-1-3] MUST NOT use a front-facing camera as the default for the 65Camera API and MUST NOT configure the API to treat a front-facing camera as 66the default rear-facing camera, even if it is the only camera on the device. 67* [C-1-4] The camera preview MUST be mirrored horizontally relative to the 68orientation specified by the application when the current application has 69explicitly requested that the Camera 70display be rotated via a call to the 71[`android.hardware.Camera.setDisplayOrientation()`]( 72http://developer.android.com/reference/android/hardware/Camera.html#setDisplayOrientation(int)) 73method. Conversely, the preview MUST be mirrored along the device’s default 74horizontal axis when the current application does not explicitly request 75that the Camera display be rotated via a call to the 76[`android.hardware.Camera.setDisplayOrientation()`]( 77http://developer.android.com/reference/android/hardware/Camera.html#setDisplayOrientation(int)) 78method. 79* [C-1-5] MUST NOT mirror the final captured still image or video streams 80returned to application callbacks or committed to media storage. 81* [C-1-6] MUST mirror the image displayed by the postview in the same manner 82as the camera preview image stream. 83* MAY include features (such as auto-focus, flash, etc.) available to 84rear-facing cameras as described in [section 7.5.1](#7_5_1_rear-facing_camera). 85 86If device implementations are capable of being rotated by user (such as 87automatically via an accelerometer or manually via user input): 88 89* [C-2-1] The camera preview MUST be mirrored horizontally relative to 90the device’s current orientation. 91 92### 7.5.3\. External Camera 93 94Device implementations: 95 96* MAY include support for an external camera that is not necessarily 97always connected. 98 99If device implementations include support for an external camera, they: 100 101* [C-1-1] MUST declare the platform feature flag 102`android.hardware.camera.external` and `android.hardware camera.any`. 103* [C-1-2] MUST support USB Video Class (UVC 1.0 or higher) if the external 104camera connects through the USB host port. 105* [C-1-3] MUST pass camera CTS tests with a physical external camera device 106connected. Details of camera CTS testing are available at [source.android.com]( 107https://source.android.com/compatibility/cts/camera-hal). 108* SHOULD support video compressions such as MJPEG to enable transfer of 109 high-quality unencoded streams (i.e. raw or independently compressed picture 110 streams). 111* MAY support multiple cameras. 112* MAY support camera-based video encoding. 113 114If camera-based video encoding is supported: 115 116* [C-2-1] A simultaneous 117 unencoded / MJPEG stream (QVGA or greater resolution) MUST be accessible to 118 the device implementation. 119 120### 7.5.4\. Camera API Behavior 121 122Android includes two API packages to access the camera, the newer 123android.hardware.camera2 API expose lower-level camera control to the app, 124including efficient zero-copy burst/streaming flows and per-frame controls of 125exposure, gain, white balance gains, color conversion, denoising, sharpening, 126and more. 127 128The older API package,`android.hardware.Camera`, is marked as deprecated in 129Android 5.0 but as it should still be available for apps to use. Android device 130implementations MUST ensure the continued support of the API as described in 131this section and in the Android SDK. 132 133All features that are common between the deprecated android.hardware.Camera class 134and the newer android.hardware.camera2 package MUST have equivalent performance 135and quality in both APIs. For example, with equivalent settings, 136autofocus speed and accuracy must be identical, and the quality of captured images 137must be the same. Features that depend on the different semantics of the two APIs 138are not required to have matching speed or quality, but SHOULD match as closely 139as possible. 140 141Device implementations MUST implement the following behaviors for the 142camera-related APIs, for all available cameras. Device implementations: 143 144* [C-0-1] MUST use `android.hardware.PixelFormat.YCbCr_420_SP` for preview 145data provided to application callbacks when an application has never called 146`android.hardware.Camera.Parameters.setPreviewFormat(int)`. 147* [C-0-2] MUST further be in the NV21 encoding format when an application 148registers an `android.hardware.Camera.PreviewCallback` 149instance and the system calls the `onPreviewFrame()` method and the preview 150format is YCbCr_420_SP, the data in the byte[] passed into `onPreviewFrame()`. 151That is, NV21 MUST be the default. 152* [C-0-3] MUST support the YV12 format (as denoted by the 153`android.graphics.ImageFormat.YV12` constant) for camera previews for both 154front- and rear-facing cameras for `android.hardware.Camera`. (The hardware 155video encoder and camera may use any native pixel format, but the device 156implementation MUST support conversion to YV12.) 157* [C-0-4] MUST support the `android.hardware.ImageFormat.YUV_420_888` and 158`android.hardware.ImageFormat.JPEG` formats as outputs through the 159`android.media.ImageReader` API for `android.hardware.camera2` devices that 160advertise [`REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE`]( 161https://developer.android.com/reference/android/hardware/camera2/CameraMetadata.html#REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE) 162 capability in [`android.request.availableCapabilities`]( 163 https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.html#REQUEST_AVAILABLE_CAPABILITIES). 164* [C-0-5] MUST still implement the full [Camera API]( 165http://developer.android.com/reference/android/hardware/Camera.html) 166included in the Android SDK documentation, regardless of whether the device 167includes hardware autofocus or other capabilities. For instance, cameras that 168lack autofocus MUST still call any registered 169`android.hardware.Camera.AutoFocusCallback` instances (even though this has no 170relevance to a non-autofocus camera.) Note that this does apply to front-facing 171cameras; for instance, even though most front-facing cameras do not support 172autofocus, the API callbacks must still be “faked” as described. 173* [C-0-6] MUST recognize and honor each parameter name 174defined as a constant in the 175[`android.hardware.Camera.Parameters`]( 176https://developer.android.com/reference/android/hardware/Camera.Parameters.html) 177class and the [`android.hardware.camera2.CaptureRequest`]( 178https://developer.android.com/reference/android/hardware/camera2/CaptureRequest) class. 179Conversely, device implementations MUST NOT honor or recognize string constants 180passed to the `android.hardware.Camera.setParameters()` method other than those 181documented as constants on the `android.hardware.Camera.Parameters`. That is, 182device implementations MUST support all standard Camera parameters if the 183hardware allows, and MUST NOT support custom Camera parameter types. 184For instance, device implementations that support image capture 185using high dynamic range (HDR) imaging techniques MUST support camera parameter 186`Camera.SCENE_MODE_HDR`. 187* [C-0-7] MUST report the proper level of support with the 188[`android.info.supportedHardwareLevel`]( 189https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.html#INFO_SUPPORTED_HARDWARE_LEVEL) 190property as described in the Android SDK and report the appropriate 191[framework feature flags]( 192http://source.android.com/devices/camera/versioning.html). 193* [C-0-8] MUST also declare its individual camera capabilities of 194`android.hardware.camera2` via the 195`android.request.availableCapabilities` property 196and declare the appropriate [feature flags]( 197http://source.android.com/devices/camera/versioning.html); 198MUST define the feature flag if any of its attached camera devices 199supports the feature. 200* [C-0-9] MUST broadcast the `Camera.ACTION_NEW_PICTURE` 201intent whenever a new picture is taken by the camera and the entry of the 202picture has been added to the media store. 203* [C-0-10] MUST broadcast the `Camera.ACTION_NEW_VIDEO` 204intent whenever a new video is recorded by the camera and the entry of the 205picture has been added to the media store. 206* [C-0-11] MUST have all cameras accessible via the deprecated 207[`android.hardware.Camera`](https://developer.android.com/reference/android/hardware/Camera) 208API also accessible via the [`android.hardware.camera2`](https://developer.android.com/reference/android/hardware/camera2/package-summary) 209API. 210* [C-SR] For devices with multiple RGB cameras facing in the same direction, 211are STRONGLY RECOMMENDED to support a logical camera device that lists 212capability 213[`CameraMetadata.REQUEST_AVAILABLE_CAPABILITIES_LOGICAL_MULTI_CAMERA`]( 214https://developer.android.com/reference/android/hardware/camera2/CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_LOGICAL_MULTI_CAMERA), 215consisting of all of the RGB cameras facing that direction as physical sub-devices. 216 217If device implementations provide a proprietary camera API to 3rd-party apps, 218they: 219 220* [C-1-1] MUST implement such a camera API using [`android.hardware.camera2`](https://developer.android.com/reference/android/hardware/camera2/package-summary) 221API. 222* MAY provide vendor tags and/or extensions to [`android.hardware.camera2`](https://developer.android.com/reference/android/hardware/camera2/package-summary) 223API. 224 225### 7.5.5\. Camera Orientation 226 227If device implementations have a front- or a rear-facing camera, such camera(s): 228 229* [C-1-1] MUST be oriented so that the long dimension of the camera 230aligns with the screen’s long dimension. That is, when the device is held in the 231landscape orientation, cameras MUST capture images in the landscape orientation. 232This applies regardless of the device’s natural orientation; that is, it applies 233to landscape-primary devices as well as portrait-primary devices. 234