1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
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 */
15
16 #include "time_lapse_photo_session_fuzzer.h"
17 #include "camera_log.h"
18 #include "camera_output_capability.h"
19 #include "input/camera_manager.h"
20 #include "message_parcel.h"
21 #include "time_lapse_photo_session.h"
22 #include "token_setproc.h"
23 #include "nativetoken_kit.h"
24 #include "accesstoken_kit.h"
25
26 namespace OHOS {
27 namespace CameraStandard {
28 namespace TimeLapsePhotoSessionFuzzer {
29 const int32_t LIMITSIZE = 4;
30 const int32_t NUM_TWO = 2;
GetPermission()31 void GetPermission()
32 {
33 uint64_t tokenId;
34 const char* perms[2];
35 perms[0] = "ohos.permission.DISTRIBUTED_DATASYNC";
36 perms[1] = "ohos.permission.CAMERA";
37 NativeTokenInfoParams infoInstance = {
38 .dcapsNum = 0,
39 .permsNum = 2,
40 .aclsNum = 0,
41 .dcaps = NULL,
42 .perms = perms,
43 .acls = NULL,
44 .processName = "native_camera_tdd",
45 .aplStr = "system_basic",
46 };
47 tokenId = GetAccessTokenId(&infoInstance);
48 SetSelfTokenID(tokenId);
49 OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
50 }
51
52 sptr<CameraManager> manager;
53 sptr<TimeLapsePhotoSession> session;
54 sptr<CameraDevice> camera;
55 SceneMode sceneMode = SceneMode::TIMELAPSE_PHOTO;
56
AddOutput()57 auto AddOutput()
58 {
59 sptr<CameraOutputCapability> capability = manager->GetSupportedOutputCapability(camera, sceneMode);
60 CHECK_ERROR_RETURN_LOG(!capability, "TimeLapsePhotoSessionFuzzer: capability Error");
61 Profile preview(CameraFormat::CAMERA_FORMAT_YUV_420_SP, {640, 480});
62 sptr<CaptureOutput> previewOutput = manager->CreatePreviewOutput(preview, Surface::CreateSurfaceAsConsumer());
63 CHECK_ERROR_RETURN_LOG(!previewOutput, "TimeLapsePhotoSessionFuzzer: previewOutput Error");
64 session->AddOutput(previewOutput);
65 Profile photo(CameraFormat::CAMERA_FORMAT_JPEG, {640, 480});
66 sptr<IConsumerSurface> photoSurface = IConsumerSurface::Create();
67 CHECK_ERROR_RETURN_LOG(!photoSurface, "TimeLapsePhotoSessionFuzzer: photoSurface Error");
68 sptr<IBufferProducer> surface = photoSurface->GetProducer();
69 CHECK_ERROR_RETURN_LOG(!surface, "TimeLapsePhotoSessionFuzzer: surface Error");
70 sptr<CaptureOutput> photoOutput = manager->CreatePhotoOutput(photo, surface);
71 CHECK_ERROR_RETURN_LOG(!photoOutput, "TimeLapsePhotoSessionFuzzer: photoOutput Error");
72 session->AddOutput(photoOutput);
73 }
74
TestProcessor(uint8_t * rawData,size_t size)75 auto TestProcessor(uint8_t *rawData, size_t size)
76 {
77 class ExposureInfoCallbackMock : public ExposureInfoCallback {
78 public:
79 void OnExposureInfoChanged(ExposureInfo info) override {}
80 };
81 session->SetExposureInfoCallback(make_shared<ExposureInfoCallbackMock>());
82 camera_rational_t r = {1, 1000000};
83 auto meta = make_shared<OHOS::Camera::CameraMetadata>(10, 100);
84 meta->addEntry(OHOS_STATUS_SENSOR_EXPOSURE_TIME, &r, 1);
85 session->ProcessExposureChange(meta);
86 r.numerator++;
87 meta->updateEntry(OHOS_STATUS_SENSOR_EXPOSURE_TIME, &r, 1);
88 class IsoInfoCallbackMock : public IsoInfoCallback {
89 public:
90 void OnIsoInfoChanged(IsoInfo info) override {}
91 };
92 session->SetIsoInfoCallback(make_shared<IsoInfoCallbackMock>());
93 uint32_t iso = 1;
94 meta->addEntry(OHOS_STATUS_ISO_VALUE, &iso, 1);
95 session->ProcessIsoInfoChange(meta);
96 iso++;
97 meta->updateEntry(OHOS_STATUS_ISO_VALUE, &iso, 1);
98 static const uint32_t lumination = 256;
99 class LuminationInfoCallbackMock : public LuminationInfoCallback {
100 public:
101 void OnLuminationInfoChanged(LuminationInfo info) override {}
102 };
103 session->SetLuminationInfoCallback(make_shared<LuminationInfoCallbackMock>());
104 meta->addEntry(OHOS_STATUS_ALGO_MEAN_Y, &lumination, 1);
105
106 static const int32_t value = 1;
107 class TryAEInfoCallbackMock : public TryAEInfoCallback {
108 public:
109 void OnTryAEInfoChanged(TryAEInfo info) override {}
110 };
111 session->SetTryAEInfoCallback(make_shared<TryAEInfoCallbackMock>());
112 meta->addEntry(OHOS_STATUS_TIME_LAPSE_TRYAE_DONE, &value, 1);
113 meta->addEntry(OHOS_STATUS_TIME_LAPSE_TRYAE_HINT, &value, 1);
114 meta->addEntry(OHOS_STATUS_TIME_LAPSE_PREVIEW_TYPE, &value, 1);
115 meta->addEntry(OHOS_STATUS_TIME_LAPSE_CAPTURE_INTERVAL, &value, 1);
116
117 meta->addEntry(OHOS_STATUS_PREVIEW_PHYSICAL_CAMERA_ID, &value, 1);
118
119 MessageParcel data;
120 data.WriteRawData(rawData, size);
121 TimeLapsePhotoSessionMetadataResultProcessor processor(session);
122 processor.ProcessCallbacks(data.ReadUint64(), meta);
123 }
124
TestTimeLapsePhoto()125 auto TestTimeLapsePhoto()
126 {
127 bool isTryAENeeded;
128 session->IsTryAENeeded(isTryAENeeded);
129 session->LockForControl();
130 session->StartTryAE();
131 session->UnlockForControl();
132 session->LockForControl();
133 session->StopTryAE();
134 session->UnlockForControl();
135
136 vector<int32_t> intervalRange;
137 session->GetSupportedTimeLapseIntervalRange(intervalRange);
138 if (!intervalRange.empty()) {
139 int32_t interval = intervalRange[intervalRange.size() - 1];
140 session->LockForControl();
141 session->SetTimeLapseInterval(interval);
142 session->UnlockForControl();
143 auto meta = session->GetInputDevice()->GetCameraDeviceInfo()->GetMetadata();
144 AddOrUpdateMetadata(meta, OHOS_CONTROL_TIME_LAPSE_INTERVAL, &interval, 1);
145 session->GetTimeLapseInterval(interval);
146 }
147 session->LockForControl();
148 session->SetTimeLapseRecordState(TimeLapseRecordState::RECORDING);
149 session->UnlockForControl();
150 session->LockForControl();
151 session->SetTimeLapsePreviewType(TimeLapsePreviewType::DARK);
152 session->UnlockForControl();
153 session->LockForControl();
154 session->SetExposureHintMode(ExposureHintMode::EXPOSURE_HINT_MODE_OFF);
155 session->SetExposureHintMode(static_cast<ExposureHintMode>(ExposureHintMode::EXPOSURE_HINT_UNSUPPORTED + 1));
156 session->UnlockForControl();
157 }
158
TestManualExposure(uint8_t * rawData,size_t size)159 auto TestManualExposure(uint8_t *rawData, size_t size)
160 {
161 MessageParcel data;
162 data.WriteRawData(rawData, size);
163 auto meta = session->GetMetadata();
164 const camera_rational_t rs[] = {
165 {3, 1000000},
166 {9, 1000000},
167 };
168 uint32_t dataCount = sizeof(rs) / sizeof(rs[0]);
169 AddOrUpdateMetadata(meta, OHOS_ABILITY_SENSOR_EXPOSURE_TIME_RANGE, rs, dataCount);
170 vector<uint32_t> exposureRange;
171 session->GetSupportedExposureRange(exposureRange);
172 meta = session->GetInputDevice()->GetCameraDeviceInfo()->GetMetadata();
173 session->LockForControl();
174 session->SetExposure(0);
175 session->SetExposure(1);
176 const uint32_t MAX_UINT = 0xFFFFFFFF;
177 session->SetExposure(MAX_UINT);
178 session->SetExposure(data.ReadUint32());
179 session->UnlockForControl();
180 uint32_t exposure = data.ReadUint32();
181 camera_rational_t expT = {.numerator = 1, .denominator = 1000000};
182 AddOrUpdateMetadata(meta, OHOS_CONTROL_SENSOR_EXPOSURE_TIME, &expT, 1);
183 session->GetExposure(exposure);
184 vector<MeteringMode> modes;
185 session->GetSupportedMeteringModes(modes);
186 bool supported;
187 session->IsExposureMeteringModeSupported(METERING_MODE_CENTER_WEIGHTED, supported);
188 session->IsExposureMeteringModeSupported(
189 static_cast<MeteringMode>(MeteringMode::METERING_MODE_OVERALL + 1), supported);
190 session->LockForControl();
191 session->SetExposureMeteringMode(MeteringMode::METERING_MODE_CENTER_WEIGHTED);
192 session->SetExposureMeteringMode(static_cast<MeteringMode>(MeteringMode::METERING_MODE_OVERALL + 1));
193 session->UnlockForControl();
194 MeteringMode mode = MeteringMode::METERING_MODE_OVERALL;
195 AddOrUpdateMetadata(meta, OHOS_CONTROL_METER_MODE, &mode, 1);
196 session->GetExposureMeteringMode(mode);
197 mode = static_cast<MeteringMode>(MeteringMode::METERING_MODE_OVERALL + 1);
198 AddOrUpdateMetadata(meta, OHOS_CONTROL_METER_MODE, &mode, 1);
199 session->GetExposureMeteringMode(mode);
200 }
201
TestManualIso()202 void TestManualIso()
203 {
204 auto meta = session->GetInputDevice()->GetCameraDeviceInfo()->GetMetadata();
205 bool isManualIsoSupported;
206 session->IsManualIsoSupported(isManualIsoSupported);
207 if (isManualIsoSupported) {
208 vector<int32_t> isoRange;
209 session->GetIsoRange(isoRange);
210 if (!isoRange.empty()) {
211 session->LockForControl();
212 session->SetIso(isoRange[0]);
213 session->UnlockForControl();
214 int32_t iso = 1000;
215 AddOrUpdateMetadata(meta, OHOS_CONTROL_ISO_VALUE, &iso, 1);
216 session->GetIso(iso);
217 }
218 }
219 int32_t aIso = 1000;
220 AddOrUpdateMetadata(meta, OHOS_ABILITY_ISO_VALUES, &aIso, 1);
221 session->IsManualIsoSupported(isManualIsoSupported);
222 }
223
TestWhiteBalance()224 void TestWhiteBalance()
225 {
226 vector<WhiteBalanceMode> wbModes;
227 session->GetSupportedWhiteBalanceModes(wbModes);
228 bool isWhiteBalanceModeSupported;
229 session->IsWhiteBalanceModeSupported(WhiteBalanceMode::AWB_MODE_AUTO, isWhiteBalanceModeSupported);
230 session->LockForControl();
231 session->SetWhiteBalanceMode(WhiteBalanceMode::AWB_MODE_AUTO);
232 session->UnlockForControl();
233 WhiteBalanceMode wbMode;
234 session->GetWhiteBalanceMode(wbMode);
235 vector<int32_t> wbRange;
236 session->GetWhiteBalanceRange(wbRange);
237 if (!wbRange.empty()) {
238 session->LockForControl();
239 session->SetWhiteBalance(wbRange[0]);
240 session->UnlockForControl();
241 int32_t wb;
242 session->GetWhiteBalance(wb);
243 }
244 auto meta = session->GetInputDevice()->GetCameraDeviceInfo()->GetMetadata();
245 camera_awb_mode_t awbModes[] = {camera_awb_mode_t::OHOS_CAMERA_AWB_MODE_AUTO};
246 AddOrUpdateMetadata(meta, OHOS_ABILITY_AWB_MODES, awbModes, 1);
247 session->GetSupportedWhiteBalanceModes(wbModes);
248 AddOrUpdateMetadata(meta, OHOS_CONTROL_AWB_MODE, awbModes, 1);
249 session->GetWhiteBalanceMode(wbMode);
250 session->LockForControl();
251 session->SetWhiteBalanceMode(static_cast<WhiteBalanceMode>(WhiteBalanceMode::AWB_MODE_SHADE + 1));
252 int32_t wb = 1;
253 AddOrUpdateMetadata(meta, OHOS_CONTROL_SENSOR_WB_VALUE, &wb, 1);
254 session->GetWhiteBalance(wb);
255 }
256
TestGetMetadata()257 void TestGetMetadata()
258 {
259 auto cameras = manager->GetSupportedCameras();
260 sptr<CameraDevice> phyCam;
261 for (auto item : cameras) {
262 if (item->GetCameraType() == CAMERA_TYPE_WIDE_ANGLE) {
263 phyCam = item;
264 }
265 }
266 CHECK_ERROR_RETURN_LOG(cameras.empty(), "TimeLapsePhotoSessionFuzzer: No Wide Angle Camera");
267 string cameraId = phyCam->GetID();
268 MEDIA_INFO_LOG("TimeLapsePhotoSessionFuzzer: Wide Angle Camera Id = %{public}s", cameraId.c_str());
269 auto meta = make_shared<OHOS::Camera::CameraMetadata>(10, 100);
270 size_t delimPos = cameraId.find("/");
271 cameraId = cameraId.substr(delimPos + 1);
272 auto index = atoi(cameraId.c_str());
273 MEDIA_INFO_LOG("TimeLapsePhotoSessionFuzzer: Wide Angle Camera Id = %{public}d", index);
274 AddOrUpdateMetadata(meta, OHOS_STATUS_PREVIEW_PHYSICAL_CAMERA_ID, &index, 1);
275 session->ProcessPhysicalCameraSwitch(meta);
276 session->GetMetadata();
277 }
278
TestGetMetadata2()279 void TestGetMetadata2()
280 {
281 sptr<ICaptureSession> iCaptureSession;
282 {
283 sptr<CaptureSession> captureSession = manager->CreateCaptureSession(sceneMode);
284 iCaptureSession = captureSession->GetCaptureSession();
285 }
286 vector<sptr<CameraDevice>> devices{};
287 sptr<TimeLapsePhotoSession> tlpSession = new TimeLapsePhotoSession(iCaptureSession, devices);
288 tlpSession->BeginConfig();
289 sptr<CaptureInput> input = manager->CreateCameraInput(camera);
290 tlpSession->AddInput(input);
291 tlpSession->GetMetadata();
292 tlpSession->Release();
293 }
294
Test2()295 void Test2()
296 {
297 CaptureSessionCallback callback(session);
298 callback.OnError(1);
299 auto s = manager->CreateCaptureSession(SceneMode::VIDEO);
300 s->BeginConfig();
301 auto cap = s->GetCameraOutputCapabilities(camera)[0];
302 auto vp = cap->GetVideoProfiles()[0];
303 sptr<Surface> surface = Surface::CreateSurfaceAsConsumer();
304 auto vo = manager->CreateVideoOutput(vp, surface);
305 sptr<CaptureOutput> output = static_cast<CaptureOutput*>(vo.GetRefPtr());
306 s->AddOutput(output);
307 const int32_t N_30 = 30;
308 const int32_t N_60 = 60;
309 const int32_t N_200 = 200;
310 vo->SetFrameRateRange(N_30, N_30);
311 s->CanSetFrameRateRangeForOutput(N_30, N_30, output);
312 vo->SetFrameRateRange(N_30, N_60);
313 s->CanSetFrameRateRangeForOutput(N_30, N_60, output);
314 s->CanSetFrameRateRangeForOutput(1, N_200, output);
315
316 Profile p = cap->GetPreviewProfiles()[0];
317 output = manager->CreatePreviewOutput(p, Surface::CreateSurfaceAsConsumer());
318 output->AddTag(CaptureOutput::DYNAMIC_PROFILE);
319 s->AddOutput(output);
320 surface = Surface::CreateSurfaceAsConsumer();
321 output = manager->CreateVideoOutput(vp, surface);
322 output->AddTag(CaptureOutput::DYNAMIC_PROFILE);
323 s->AddOutput(output);
324 s->Release();
325
326 s = manager->CreateCaptureSession(SceneMode::CAPTURE);
327 s->BeginConfig();
328 sptr<IConsumerSurface> cs = IConsumerSurface::Create();
329 sptr<IBufferProducer> bp = cs->GetProducer();
330 p = cap->GetPhotoProfiles()[0];
331 output = manager->CreatePhotoOutput(p, bp);
332 output->AddTag(CaptureOutput::DYNAMIC_PROFILE);
333 s->AddOutput(output);
334
335 output = manager->CreateMetadataOutput();
336 s->AddOutput(output);
337 output = manager->CreateMetadataOutput();
338 output->AddTag(CaptureOutput::DYNAMIC_PROFILE);
339 s->AddOutput(output);
340 s->Release();
341 }
342
Test31(sptr<CaptureSession> s)343 void Test31(sptr<CaptureSession> s)
344 {
345 s->UnlockForControl();
346 bool supported = true;
347 bool configed = true;
348 set<camera_face_detect_mode_t> metadataObjectTypes{};
349 s->SetCaptureMetadataObjectTypes(metadataObjectTypes);
350 metadataObjectTypes.emplace(OHOS_CAMERA_FACE_DETECT_MODE_SIMPLE);
351 s->SetCaptureMetadataObjectTypes(metadataObjectTypes);
352 s->EnableFaceDetection(supported);
353 const float distance = 1.0f;
354 s->IsSessionStarted();
355 s->EnableMovingPhotoMirror(supported, configed);
356 vector<WhiteBalanceMode> modes;
357 s->GetSupportedWhiteBalanceModes(modes);
358 s->IsWhiteBalanceModeSupported(WhiteBalanceMode::AWB_MODE_AUTO, supported);
359 s->LockForControl();
360 s->SetFocusDistance(distance);
361
362 s->EnableLowLightDetection(supported);
363 s->EnableMovingPhoto(supported);
364 s->SetSensorSensitivity(1);
365 s->SetWhiteBalanceMode(WhiteBalanceMode::AWB_MODE_AUTO);
366 WhiteBalanceMode mode;
367 s->GetWhiteBalanceMode(mode);
368 vector<int32_t> whiteBalanceRange;
369 s->GetManualWhiteBalanceRange(whiteBalanceRange);
370 s->IsManualWhiteBalanceSupported(supported);
371 int32_t wbValue;
372 s->GetManualWhiteBalance(wbValue);
373 s->SetManualWhiteBalance(wbValue);
374 vector<std::vector<float>> supportedPhysicalApertures;
375 s->GetSupportedPhysicalApertures(supportedPhysicalApertures);
376 vector<float> apertures;
377 s->GetSupportedVirtualApertures(apertures);
378 s->GetSupportedPortraitEffects();
379 float aperture;
380 s->GetVirtualAperture(aperture);
381 s->SetVirtualAperture(aperture);
382 s->GetPhysicalAperture(aperture);
383 s->SetPhysicalAperture(aperture);
384 s->IsLcdFlashSupported();
385 s->EnableLcdFlash(supported);
386 s->EnableLcdFlashDetection(supported);
387 auto callback = s->GetLcdFlashStatusCallback();
388 s->SetLcdFlashStatusCallback(callback);
389 s->IsTripodDetectionSupported();
390 s->EnableTripodStabilization(supported);
391 s->EnableTripodDetection(supported);
392 }
393
Test3()394 void Test3()
395 {
396 sptr<CaptureInput> input = manager->CreateCameraInput(camera);
397 input->Open();
398 auto s = manager->CreateCaptureSession(SceneMode::SECURE);
399 s->BeginConfig();
400 auto cap = manager->GetSupportedOutputCapability(camera, SceneMode::CAPTURE);
401 if (!cap->GetDepthProfiles().empty()) {
402 DepthProfile dp = cap->GetDepthProfiles()[0];
403 sptr<IConsumerSurface> cs = IConsumerSurface::Create();
404 sptr<IBufferProducer> bp = cs->GetProducer();
405 sptr<CaptureOutput> output = manager->CreateDepthDataOutput(dp, bp);
406 s->AddSecureOutput(output);
407 }
408 sptr<CaptureOutput> output = manager->CreateMetadataOutput();
409 s->AddOutput(output);
410 s->AddInput(input);
411 s->CommitConfig();
412 s->Start();
413 string deviceClass{"device/0"};
414 s->SetPreviewRotation(deviceClass);
415 uint32_t value = 1;
416 auto meta = s->GetInputDevice()->GetCameraDeviceInfo()->GetMetadata();
417 AddOrUpdateMetadata(meta, OHOS_CONTROL_VIDEO_STABILIZATION_MODE, &value, 1);
418 s->GetActiveVideoStabilizationMode();
419 s->UnlockForControl();
420 s->SetExposureMode(ExposureMode::EXPOSURE_MODE_AUTO);
421 s->LockForControl();
422 s->SetExposureMode(ExposureMode::EXPOSURE_MODE_AUTO);
423 s->GetSupportedFlashModes();
424 vector<FlashMode> flashModes;
425 s->GetSupportedFlashModes(flashModes);
426 s->GetFlashMode();
427 FlashMode flashMode;
428 s->GetFlashMode(flashMode);
429 s->SetFlashMode(flashMode);
430 s->IsFlashModeSupported(flashMode);
431 bool supported;
432 s->IsFlashModeSupported(flashMode, supported);
433 s->HasFlash();
434 s->HasFlash(supported);
435 meta = camera->GetMetadata();
436 AddOrUpdateMetadata(meta, OHOS_ABILITY_AVAILABLE_PROFILE_LEVEL, &value, 0);
437 AddOrUpdateMetadata(meta, OHOS_ABILITY_SCENE_ZOOM_CAP, &value, 1);
438 vector<float> zoomRatioRange;
439 s->GetZoomRatioRange(zoomRatioRange);
440 Test31(s);
441 s->Stop();
442 s->Release();
443 }
444
TestMetadataResultProcessor()445 void TestMetadataResultProcessor()
446 {
447 auto s = manager->CreateCaptureSession(SceneMode::CAPTURE);
448 s->BeginConfig();
449 sptr<CaptureOutput> output = manager->CreateMetadataOutput();
450 s->AddOutput(output);
451 sptr<CaptureInput> input = manager->CreateCameraInput(camera);
452 input->Open();
453 s->AddInput(input);
454 CaptureSession::CaptureSessionMetadataResultProcessor processor(s);
455 auto metadata = make_shared<OHOS::Camera::CameraMetadata>(10, 100);
456 uint64_t data = 1;
457 AddOrUpdateMetadata(metadata, OHOS_CONTROL_EXPOSURE_STATE, &data, 1);
458 AddOrUpdateMetadata(metadata, OHOS_CONTROL_FOCUS_MODE, &data, 1);
459 AddOrUpdateMetadata(metadata, OHOS_CONTROL_FOCUS_STATE, &data, 1);
460 AddOrUpdateMetadata(metadata, OHOS_CAMERA_MACRO_STATUS, &data, 1);
461 AddOrUpdateMetadata(metadata, FEATURE_MOON_CAPTURE_BOOST, &data, 1);
462 AddOrUpdateMetadata(metadata, OHOS_STATUS_MOON_CAPTURE_DETECTION, &data, 1);
463 AddOrUpdateMetadata(metadata, FEATURE_LOW_LIGHT_BOOST, &data, 1);
464 AddOrUpdateMetadata(metadata, OHOS_STATUS_LOW_LIGHT_DETECTION, &data, 1);
465 AddOrUpdateMetadata(metadata, OHOS_CAMERA_CUSTOM_SNAPSHOT_DURATION, &data, 1);
466 AddOrUpdateMetadata(metadata, OHOS_STATUS_SENSOR_EXPOSURE_TIME, &data, 1);
467 AddOrUpdateMetadata(metadata, OHOS_CAMERA_EFFECT_SUGGESTION_TYPE, &data, 1);
468 AddOrUpdateMetadata(metadata, OHOS_STATUS_LCD_FLASH_STATUS, &data, 1);
469 processor.ProcessCallbacks(1, metadata);
470 s->Release();
471 }
472
Test(uint8_t * rawData,size_t size)473 void Test(uint8_t *rawData, size_t size)
474 {
475 CHECK_ERROR_RETURN(rawData == nullptr || size < LIMITSIZE);
476 GetPermission();
477 manager = CameraManager::GetInstance();
478 sptr<CaptureSession> captureSession = manager->CreateCaptureSession(sceneMode);
479 session = reinterpret_cast<TimeLapsePhotoSession*>(captureSession.GetRefPtr());
480 session->BeginConfig();
481 auto cameras = manager->GetSupportedCameras();
482 CHECK_ERROR_RETURN_LOG(cameras.size() < NUM_TWO, "TimeLapsePhotoSessionFuzzer: GetSupportedCameras Error");
483 camera = cameras[0];
484 CHECK_ERROR_RETURN_LOG(!camera, "TimeLapsePhotoSessionFuzzer: Camera is null");
485 sptr<CaptureInput> input = manager->CreateCameraInput(camera);
486 CHECK_ERROR_RETURN_LOG(!input, "TimeLapsePhotoSessionFuzzer: CreateCameraInput Error");
487 input->Open();
488 session->AddInput(input);
489 AddOutput();
490 session->CommitConfig();
491 TestProcessor(rawData, size);
492 TestTimeLapsePhoto();
493 TestManualExposure(rawData, size);
494 TestManualIso();
495 TestWhiteBalance();
496 TestGetMetadata();
497 session->Release();
498 TestGetMetadata2();
499 Test2();
500 Test3();
501 TestMetadataResultProcessor();
502 }
503
504 } // namespace StreamRepeatStubFuzzer
505 } // namespace CameraStandard
506 } // namespace OHOS
507
508 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(uint8_t * data,size_t size)509 extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size)
510 {
511 /* Run your code on data */
512 OHOS::CameraStandard::TimeLapsePhotoSessionFuzzer::Test(data, size);
513 return 0;
514 }