1 /*
2  * Copyright 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package androidx.camera.integration.extensions
18 
19 /** Invalid extension mode */
20 const val INVALID_EXTENSION_MODE = -1
21 
22 /** Extension is not enabled. Uses a non camera extension session (eg. camera2 or cameraX) */
23 const val EXTENSION_MODE_NONE = -1
24 
25 /** Invalid lens facing */
26 const val INVALID_LENS_FACING = -1
27 
28 /** Permissions request code */
29 const val PERMISSIONS_REQUEST_CODE = 42
30 
31 /** Intent extra keys to pass necessary information between the caller and callee activities. */
32 object IntentExtraKey {
33     /** Launches the activity with the specified CameraX implementation. */
34     const val INTENT_EXTRA_CAMERA_IMPLEMENTATION = "camera_implementation"
35 
36     /**
37      * Launches the activity with the specified direction of camera.
38      *
39      * Possible values for this intent key are listed in [CameraDirection]
40      */
41     const val INTENT_EXTRA_KEY_CAMERA_DIRECTION = "camera_direction"
42 
43     /**
44      * Launches the activity with the specified lens facing of camera.
45      *
46      * Possible values for this intent key: [CameraMetadata#LENS_FACING_BACK] or
47      * [CameraMetadata#LENS_FACING_FRONT].
48      */
49     const val INTENT_EXTRA_KEY_LENS_FACING = "LensFacing"
50 
51     /** Launches the activity with the specified id of camera. */
52     const val INTENT_EXTRA_KEY_CAMERA_ID = "camera_id"
53 
54     /** Launches the activity with the specified extension mode. */
55     const val INTENT_EXTRA_KEY_EXTENSION_MODE = "extension_mode"
56 
57     /** Takes the still image with the specified output format. */
58     const val INTENT_EXTRA_KEY_OUTPUT_FORMAT = "still_image_output_format"
59 
60     /**
61      * The captured image will be deleted automatically if the intent used to launch the activity
62      * includes the setting as true.
63      */
64     const val INTENT_EXTRA_KEY_DELETE_CAPTURED_IMAGE = "delete_captured_image"
65 
66     /**
67      * Launches the activity for the specified test type.
68      *
69      * Possible values for this intent key are listed in [ExtensionTestType]
70      */
71     const val INTENT_EXTRA_KEY_TEST_TYPE = "TestType"
72 
73     /** Used to pass the captured image Uri to the caller activity. */
74     const val INTENT_EXTRA_KEY_IMAGE_URI = "ImageUri"
75 
76     /**
77      * Used to pass the rotation degrees of the captured image to the caller activity to show the
78      * image in correct orientation.
79      */
80     const val INTENT_EXTRA_KEY_IMAGE_ROTATION_DEGREES = "ImageRotationDegrees"
81 
82     /** Used to pass the info that whether VideoCapture should be enabled. */
83     const val INTENT_EXTRA_KEY_VIDEO_CAPTURE_ENABLED = "VideoCaptureEnabled"
84 
85     /** Used to pass the request code to the callee activity. */
86     const val INTENT_EXTRA_KEY_REQUEST_CODE = "RequestCode"
87 
88     /** Used to pass the error code to the caller activity. */
89     const val INTENT_EXTRA_KEY_ERROR_CODE = "ErrorCode"
90 
91     /** Used to pass the running mode to check. The valid values are debug and release. */
92     const val INTENT_EXTRA_RUNNING_MODE_CHECK = "running_mode_check"
93 
94     /** Used to pass the result error message. */
95     const val INTENT_EXTRA_RESULT_ERROR_MESSAGE = "result_error_message"
96 }
97 
98 /** Implementation options */
99 object ImplementationOption {
100     /** CameraX implementation option */
101     const val CAMERA2_IMPLEMENTATION_OPTION: String = "camera2"
102     /** Camera-pipe implementation option */
103     const val CAMERA_PIPE_IMPLEMENTATION_OPTION: String = "camera_pipe"
104 }
105 
106 /** Camera directions */
107 object CameraDirection {
108     /** Backward direction */
109     const val BACKWARD = "BACKWARD"
110 
111     /** Forward direction */
112     const val FORWARD = "FORWARD"
113 }
114 
115 /** Error Codes for validation activity results */
116 object ValidationErrorCode {
117     /** No error */
118     const val ERROR_CODE_NONE = 0
119 
120     /** Failed to bind the use cases to the lifecycle owner */
121     const val ERROR_CODE_BIND_TO_LIFECYCLE_FAILED = 1
122 
123     /** The specified extension mode is not supported */
124     const val ERROR_CODE_EXTENSION_MODE_NOT_SUPPORT = 2
125 
126     /** Failed to take picture */
127     const val ERROR_CODE_TAKE_PICTURE_FAILED = 3
128 
129     /** Failed to save the captured image */
130     const val ERROR_CODE_SAVE_IMAGE_FAILED = 4
131 }
132 
133 /** Extension test types. */
134 object ExtensionTestType {
135     const val TEST_TYPE_CAMERAX_EXTENSION = "CameraX Extension"
136     const val TEST_TYPE_CAMERA2_EXTENSION = "Camera2 Extension"
137     const val TEST_TYPE_CAMERA2_EXTENSION_STREAM_CONFIG_LATENCY =
138         "Camera2 Extension Stream Config Latency"
139 }
140 
141 /** Test result types */
142 object TestResultType {
143     /** Extension mode is not supported on the camera device */
144     const val TEST_RESULT_NOT_SUPPORTED = -1
145 
146     /** Not tested yet */
147     const val TEST_RESULT_NOT_TESTED = 0
148 
149     /** Only part of the tests are tested */
150     const val TEST_RESULT_PARTIALLY_TESTED = 1
151 
152     /** All tests have been run and all passed */
153     const val TEST_RESULT_PASSED = 2
154 
155     /** All tests have been run and some items are failed */
156     const val TEST_RESULT_FAILED = 3
157 }
158 
159 /** Request result error codes for release apk test. */
160 object RequestResultErrorCode {
161     /** None error happens. */
162     const val RESULT_SUCCESS = 0
163     /** Running mode (debug or release) incorrect. */
164     const val RESULT_ERROR_RUNNING_MODE_INCORRECT = 1
165     /** Permission requirements are not satisfied. */
166     const val RESULT_ERROR_PERMISSION_NOT_SATISFIED = 2
167     /** Failed to retrieve ExtensionsManager. */
168     const val RESULT_ERROR_FAILED_TO_RETRIEVE_EXTENSIONS_MANAGER = 3
169     /** Target testing extension mode is not supported on the target camera device. */
170     const val RESULT_ERROR_EXTENSION_MOD_NOT_SUPPORTED = 4
171     /** Incorrect camera implementation. */
172     const val RESULT_ERROR_INCORRECT_CAMERA_IMPLEMENTATION = 5
173     /** Failed to take a picture. */
174     const val RESULT_ERROR_TAKE_PICTURE_FAILED = 6
175 }
176