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