1 /* 2 * Copyright (c) 2024 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 #ifndef OHOS_CAMERA_REPORT_UITLS_H 17 #define OHOS_CAMERA_REPORT_UITLS_H 18 19 #include <map> 20 21 namespace OHOS { 22 namespace CameraStandard { 23 static const std::string S_BEHAVIORNAME = "behaviorName:"; 24 static const std::string S_VALUE = ",value:"; 25 static const std::string S_CUR_MODE = ",curMode:"; 26 static const std::string S_CUR_CAMERAID = ",curCameraId:"; 27 static const std::string S_CPID = ",cPid:"; 28 static const std::string S_CUID = ",cUid:"; 29 static const std::string S_CTOKENID = ",cTokenID:"; 30 static const std::string S_CBUNDLENAME = ",cBundleName:"; 31 32 static const std::string DFX_PROFILE = "Profile"; 33 static const std::string DFX_PHOTO_SETTING_QUALITY = "Quality"; 34 static const std::string DFX_PHOTO_SETTING_MIRROR = "Mirror"; 35 static const std::string DFX_PHOTO_SETTING_ROTATION = "Rotation"; 36 37 static const std::string DFX_ZOOMRATIO = "ZoomRatio"; 38 static const std::string DFX_VIDEOSTABILIZATIONMODE = "VideoStabilizationMode"; 39 static const std::string DFX_FILTERTYPE = "FilterType"; 40 static const std::string DFX_PORTRAITEFFECT = "PortraitEffect"; 41 static const std::string DFX_BEAUTY_AUTOVALUE = "BeautyValue"; 42 static const std::string DFX_BEAUTY_SKINSMOOTH = "SkinSmooth"; 43 static const std::string DFX_BEAUTY_FACESLENDER = "FaceSlender"; 44 static const std::string DFX_BEAUTY_SKINTONE = "SkinTone"; 45 static const std::string DFX_FOCUSMODE = "FocusMode"; 46 static const std::string DFX_FOCUSPOINT = "FocusPoint"; 47 static const std::string DFX_EXPOSUREMODE = "ExposureMode"; 48 static const std::string DFX_EXPOSUREBIAS = "ExposureBias"; 49 static const std::string DFX_METERINGPOINT = "MeteringPoint"; 50 static const std::string DFX_FLASHMODE = "FlashMode"; 51 static const std::string DFX_FRAMERATERANGE = "FrameRateRange"; 52 static const std::string DFX_MUTE_CAMERA = "MuteCamera"; 53 54 static const std::string DFX_UB_NOT_REPORT = ""; 55 static const std::string DFX_UB_SET_ZOOMRATIO = "SetZoomRatio"; 56 static const std::string DFX_UB_SET_SMOOTHZOOM = "SetSmoothZoom"; 57 static const std::string DFX_UB_SET_VIDEOSTABILIZATIONMODE = "SetVideoStabilizationMode"; 58 static const std::string DFX_UB_SET_FILTER = "SetFilter"; 59 static const std::string DFX_UB_SET_PORTRAITEFFECT = "SetPortraitEffect"; 60 static const std::string DFX_UB_SET_BEAUTY_AUTOVALUE = "SetBeautyaAutoValue"; 61 static const std::string DFX_UB_SET_BEAUTY_SKINSMOOTH = "SetBeautySkinSmooth"; 62 static const std::string DFX_UB_SET_BEAUTY_FACESLENDER = "SetBeautyFaceSlender"; 63 static const std::string DFX_UB_SET_BEAUTY_SKINTONE = "SetBeautySkinTone"; 64 static const std::string DFX_UB_SET_FOCUSMODE = "SetFocusMode"; 65 static const std::string DFX_UB_SET_FOCUSPOINT = "SetFocusPoint"; 66 static const std::string DFX_UB_SET_EXPOSUREMODE = "SetExposureMode"; 67 static const std::string DFX_UB_SET_EXPOSUREBIAS = "SetExposureBias"; 68 static const std::string DFX_UB_SET_METERINGPOINT = "SetMeteringPoint"; 69 static const std::string DFX_UB_SET_FLASHMODE = "setFlashMode"; 70 static const std::string DFX_UB_SET_FRAMERATERANGE = "SetFrameRateRange"; 71 static const std::string DFX_UB_MUTE_CAMERA = "MuteCamera"; 72 73 static const std::unordered_map<std::string, std::string> mapBehaviorImagingKey = { 74 {DFX_UB_SET_ZOOMRATIO, DFX_ZOOMRATIO}, 75 {DFX_UB_SET_SMOOTHZOOM, DFX_ZOOMRATIO}, 76 {DFX_UB_SET_VIDEOSTABILIZATIONMODE, DFX_VIDEOSTABILIZATIONMODE}, 77 {DFX_UB_SET_FILTER, DFX_FILTERTYPE}, 78 {DFX_UB_SET_PORTRAITEFFECT, DFX_PORTRAITEFFECT}, 79 {DFX_UB_SET_BEAUTY_AUTOVALUE, DFX_BEAUTY_AUTOVALUE}, 80 {DFX_UB_SET_BEAUTY_SKINSMOOTH, DFX_BEAUTY_SKINSMOOTH}, 81 {DFX_UB_SET_BEAUTY_FACESLENDER, DFX_BEAUTY_FACESLENDER}, 82 {DFX_UB_SET_BEAUTY_SKINTONE, DFX_BEAUTY_SKINTONE}, 83 {DFX_UB_SET_FOCUSMODE, DFX_FOCUSMODE}, 84 {DFX_UB_SET_FOCUSPOINT, DFX_FOCUSPOINT}, 85 {DFX_UB_SET_EXPOSUREMODE, DFX_EXPOSUREMODE}, 86 {DFX_UB_SET_EXPOSUREBIAS, DFX_EXPOSUREBIAS}, 87 {DFX_UB_SET_METERINGPOINT, DFX_METERINGPOINT}, 88 {DFX_UB_SET_FLASHMODE, DFX_FLASHMODE}, 89 {DFX_UB_SET_FRAMERATERANGE, DFX_FRAMERATERANGE}, 90 {DFX_UB_MUTE_CAMERA, DFX_MUTE_CAMERA} 91 }; 92 93 struct CallerInfo { 94 int32_t pid; 95 int32_t uid; 96 uint32_t tokenID; 97 std::string bundleName; 98 }; 99 100 struct DfxCaptureInfo { 101 int32_t captureId; 102 CallerInfo caller; 103 uint64_t captureStartTime; 104 uint64_t captureEndTime; 105 }; 106 107 class CameraReportUtils { 108 public: GetInstance()109 static CameraReportUtils &GetInstance() 110 { 111 static CameraReportUtils instance; 112 return instance; 113 } 114 static CallerInfo GetCallerInfo(); 115 static void ReportCameraError( 116 std::string funcName, int32_t errCode, bool isHdiErr, CallerInfo callerInfo); 117 void ReportUserBehavior(std::string behaviorName, 118 std::string value, 119 CallerInfo callerInfo); 120 121 void SetOpenCamPerfPreInfo(const std::string& cameraId, CallerInfo caller); 122 void SetOpenCamPerfStartInfo(const std::string& cameraId, CallerInfo caller); 123 void SetOpenCamPerfEndInfo(); 124 125 void SetModeChangePerfStartInfo(int32_t preMode, CallerInfo caller); 126 void updateModeChangePerfInfo(int32_t curMode, CallerInfo caller); 127 void SetModeChangePerfEndInfo(); 128 129 void SetCapturePerfStartInfo(DfxCaptureInfo captureInfo); 130 void SetCapturePerfEndInfo(int32_t captureId); 131 132 void SetSwitchCamPerfStartInfo(CallerInfo caller); 133 void SetSwitchCamPerfEndInfo(); 134 135 void UpdateProfileInfo(const std::string& profileStr); 136 void UpdateImagingInfo(const std::string& imagingKey, const std::string& value); 137 void SetVideoStartInfo(DfxCaptureInfo captureInfo); 138 void SetVideoEndInfo(int32_t captureId); 139 140 private: 141 std::mutex mutex_; 142 CallerInfo caller_; 143 std::string preCameraId_; 144 std::string cameraId_; 145 int32_t preMode_; 146 int32_t curMode_; 147 148 std::string profile_; 149 150 uint64_t openCamPerfStartTime_; 151 uint64_t openCamPerfEndTime_; 152 bool isPrelaunching_; 153 bool isOpening_; 154 155 uint64_t modeChangeStartTime_; 156 uint64_t modeChangeEndTime_; 157 bool isModeChanging_; 158 159 uint64_t switchCamPerfStartTime_; 160 uint64_t switchCamPerfEndTime_; 161 bool isSwitching_; 162 163 std::map<int32_t, DfxCaptureInfo> captureList_; 164 std::unordered_map<std::string, std::string> imagingValueList_; 165 166 bool IsCallerChanged(CallerInfo preCaller, CallerInfo curCaller); 167 bool IsBehaviorNeedReport(const std::string& behaviorName, const std::string& value); 168 169 void ReportOpenCameraPerf(uint64_t costTime, const std::string& startType); 170 void ReportModeChangePerf(uint64_t costTime); 171 void ReportCapturePerf(DfxCaptureInfo captureInfo); 172 void ReportSwitchCameraPerf(uint64_t costTime); 173 void ReportImagingInfo(DfxCaptureInfo captureInfo); 174 void ResetImagingValue(); 175 }; 176 } // namespace CameraStandard 177 } // namespace OHOS 178 #endif // OHOS_CAMERA_REPORT_UITLS_H 179