1# Copyright 2014 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import unittest
16import its.objects
17import sys
18
19
20def skip_unless(cond):
21    """Skips the test if the condition is false.
22
23    If a test is skipped, then it is exited and returns the special code
24    of 101 to the calling shell, which can be used by an external test
25    harness to differentiate a skip from a pass or fail.
26
27    Args:
28        cond: Boolean, which must be true for the test to not skip.
29
30    Returns:
31        Nothing.
32    """
33    SKIP_RET_CODE = 101
34
35    if not cond:
36        print "Test skipped"
37        sys.exit(SKIP_RET_CODE)
38
39
40def full(props):
41    """Returns whether a device is a FULL capability camera2 device.
42
43    Args:
44        props: Camera properties object.
45
46    Returns:
47        Boolean.
48    """
49    return props.has_key("android.info.supportedHardwareLevel") and \
50           props["android.info.supportedHardwareLevel"] == 1
51
52def limited(props):
53    """Returns whether a device is a LIMITED capability camera2 device.
54
55    Args:
56        props: Camera properties object.
57
58    Returns:
59        Boolean.
60    """
61    return props.has_key("android.info.supportedHardwareLevel") and \
62           props["android.info.supportedHardwareLevel"] == 0
63
64def legacy(props):
65    """Returns whether a device is a LEGACY capability camera2 device.
66
67    Args:
68        props: Camera properties object.
69
70    Returns:
71        Boolean.
72    """
73    return props.has_key("android.info.supportedHardwareLevel") and \
74           props["android.info.supportedHardwareLevel"] == 2
75
76def manual_sensor(props):
77    """Returns whether a device supports MANUAL_SENSOR capabilities.
78
79    Args:
80        props: Camera properties object.
81
82    Returns:
83        Boolean.
84    """
85    return    props.has_key("android.request.availableCapabilities") and \
86              1 in props["android.request.availableCapabilities"] \
87           or full(props)
88
89def manual_post_proc(props):
90    """Returns whether a device supports MANUAL_POST_PROCESSING capabilities.
91
92    Args:
93        props: Camera properties object.
94
95    Returns:
96        Boolean.
97    """
98    return    props.has_key("android.request.availableCapabilities") and \
99              2 in props["android.request.availableCapabilities"] \
100           or full(props)
101
102def raw(props):
103    """Returns whether a device supports RAW capabilities.
104
105    Args:
106        props: Camera properties object.
107
108    Returns:
109        Boolean.
110    """
111    return props.has_key("android.request.availableCapabilities") and \
112           3 in props["android.request.availableCapabilities"]
113
114def raw16(props):
115    """Returns whether a device supports RAW16 output.
116
117    Args:
118        props: Camera properties object.
119
120    Returns:
121        Boolean.
122    """
123    return len(its.objects.get_available_output_sizes("raw", props)) > 0
124
125def raw10(props):
126    """Returns whether a device supports RAW10 output.
127
128    Args:
129        props: Camera properties object.
130
131    Returns:
132        Boolean.
133    """
134    return len(its.objects.get_available_output_sizes("raw10", props)) > 0
135
136def raw12(props):
137    """Returns whether a device supports RAW12 output.
138
139    Args:
140        props: Camera properties object.
141
142    Returns:
143        Boolean.
144    """
145    return len(its.objects.get_available_output_sizes("raw12", props)) > 0
146
147def sensor_fusion(props):
148    """Returns whether the camera and motion sensor timestamps for the device
149    are in the same time domain and can be compared directly.
150
151    Args:
152        props: Camera properties object.
153
154    Returns:
155        Boolean.
156    """
157    return props.has_key("android.sensor.info.timestampSource") and \
158           props["android.sensor.info.timestampSource"] == 1
159
160def read_3a(props):
161    """Return whether a device supports reading out the following 3A settings:
162        sensitivity
163        exposure time
164        awb gain
165        awb cct
166        focus distance
167
168    Args:
169        props: Camera properties object.
170
171    Returns:
172        Boolean.
173    """
174    # TODO: check available result keys explicitly
175    return manual_sensor(props) and manual_post_proc(props)
176
177def compute_target_exposure(props):
178    """Return whether a device supports target exposure computation in its.target module.
179
180    Args:
181        props: Camera properties object.
182
183    Returns:
184        Boolean.
185    """
186    return manual_sensor(props) and manual_post_proc(props)
187
188def freeform_crop(props):
189    """Returns whether a device supports freefrom cropping.
190
191    Args:
192        props: Camera properties object.
193
194    Return:
195        Boolean.
196    """
197    return props.has_key("android.scaler.croppingType") and \
198           props["android.scaler.croppingType"] == 1
199
200def flash(props):
201    """Returns whether a device supports flash control.
202
203    Args:
204        props: Camera properties object.
205
206    Return:
207        Boolean.
208    """
209    return props.has_key("android.flash.info.available") and \
210           props["android.flash.info.available"] == 1
211
212def per_frame_control(props):
213    """Returns whether a device supports per frame control
214
215    Args:
216        props: Camera properties object.
217
218    Return:
219        Boolean.
220    """
221    return props.has_key("android.sync.maxLatency") and \
222           props["android.sync.maxLatency"] == 0
223
224def ev_compensation(props):
225    """Returns whether a device supports ev compensation
226
227    Args:
228        props: Camera properties object.
229
230    Return:
231        Boolean.
232    """
233    return props.has_key("android.control.aeCompensationRange") and \
234           props["android.control.aeCompensationRange"] != [0, 0]
235
236def ae_lock(props):
237    """Returns whether a device supports AE lock
238
239    Args:
240        props: Camera properties object.
241
242    Return:
243        Boolean.
244    """
245    return props.has_key("android.control.aeLockAvailable") and \
246           props["android.control.aeLockAvailable"] == 1
247
248def awb_lock(props):
249    """Returns whether a device supports AWB lock
250
251    Args:
252        props: Camera properties object.
253
254    Return:
255        Boolean.
256    """
257    return props.has_key("android.control.awbLockAvailable") and \
258           props["android.control.awbLockAvailable"] == 1
259
260def lsc_map(props):
261    """Returns whether a device supports lens shading map output
262
263    Args:
264        props: Camera properties object.
265
266    Return:
267        Boolean.
268    """
269    return props.has_key(
270            "android.statistics.info.availableLensShadingMapModes") and \
271        1 in props["android.statistics.info.availableLensShadingMapModes"]
272
273def lsc_off(props):
274    """Returns whether a device supports disabling lens shading correction
275
276    Args:
277        props: Camera properties object.
278
279    Return:
280        Boolean.
281    """
282    return props.has_key(
283            "android.shading.availableModes") and \
284        0 in props["android.shading.availableModes"]
285
286def yuv_reprocess(props):
287    """Returns whether a device supports YUV reprocessing.
288
289    Args:
290        props: Camera properties object.
291
292    Returns:
293        Boolean.
294    """
295    return props.has_key("android.request.availableCapabilities") and \
296           7 in props["android.request.availableCapabilities"]
297
298def private_reprocess(props):
299    """Returns whether a device supports PRIVATE reprocessing.
300
301    Args:
302        props: Camera properties object.
303
304    Returns:
305        Boolean.
306    """
307    return props.has_key("android.request.availableCapabilities") and \
308           4 in props["android.request.availableCapabilities"]
309
310def noise_reduction_mode(props, mode):
311    """Returns whether a device supports the noise reduction mode.
312
313    Args:
314        props: Camera properties objects.
315        mode: Integer, indicating the noise reduction mode to check for
316              availability.
317
318    Returns:
319        Boolean.
320    """
321    return props.has_key(
322            "android.noiseReduction.availableNoiseReductionModes") and mode \
323            in props["android.noiseReduction.availableNoiseReductionModes"];
324
325def edge_mode(props, mode):
326    """Returns whether a device supports the edge mode.
327
328    Args:
329        props: Camera properties objects.
330        mode: Integer, indicating the edge mode to check for availability.
331
332    Returns:
333        Boolean.
334    """
335    return props.has_key(
336            "android.edge.availableEdgeModes") and mode \
337            in props["android.edge.availableEdgeModes"];
338
339class __UnitTest(unittest.TestCase):
340    """Run a suite of unit tests on this module.
341    """
342    # TODO: Add more unit tests.
343
344if __name__ == '__main__':
345    unittest.main()
346
347