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 static const std::string DFX_QUALITY_PRIORITIZATION = "QualityPrioritization"; 54 55 static const std::string DFX_UB_NOT_REPORT = ""; 56 static const std::string DFX_UB_SET_ZOOMRATIO = "SetZoomRatio"; 57 static const std::string DFX_UB_SET_SMOOTHZOOM = "SetSmoothZoom"; 58 static const std::string DFX_UB_SET_VIDEOSTABILIZATIONMODE = "SetVideoStabilizationMode"; 59 static const std::string DFX_UB_SET_FILTER = "SetFilter"; 60 static const std::string DFX_UB_SET_PORTRAITEFFECT = "SetPortraitEffect"; 61 static const std::string DFX_UB_SET_BEAUTY_AUTOVALUE = "SetBeautyaAutoValue"; 62 static const std::string DFX_UB_SET_BEAUTY_SKINSMOOTH = "SetBeautySkinSmooth"; 63 static const std::string DFX_UB_SET_BEAUTY_FACESLENDER = "SetBeautyFaceSlender"; 64 static const std::string DFX_UB_SET_BEAUTY_SKINTONE = "SetBeautySkinTone"; 65 static const std::string DFX_UB_SET_FOCUSMODE = "SetFocusMode"; 66 static const std::string DFX_UB_SET_FOCUSPOINT = "SetFocusPoint"; 67 static const std::string DFX_UB_SET_EXPOSUREMODE = "SetExposureMode"; 68 static const std::string DFX_UB_SET_EXPOSUREBIAS = "SetExposureBias"; 69 static const std::string DFX_UB_SET_METERINGPOINT = "SetMeteringPoint"; 70 static const std::string DFX_UB_SET_FLASHMODE = "setFlashMode"; 71 static const std::string DFX_UB_SET_FRAMERATERANGE = "SetFrameRateRange"; 72 static const std::string DFX_UB_MUTE_CAMERA = "MuteCamera"; 73 static const std::string DFX_UB_SET_QUALITY_PRIORITIZATION = "SetQualityPrioritization"; 74 75 static const std::unordered_map<std::string, std::string> mapBehaviorImagingKey = { 76 {DFX_UB_SET_ZOOMRATIO, DFX_ZOOMRATIO}, 77 {DFX_UB_SET_SMOOTHZOOM, DFX_ZOOMRATIO}, 78 {DFX_UB_SET_VIDEOSTABILIZATIONMODE, DFX_VIDEOSTABILIZATIONMODE}, 79 {DFX_UB_SET_FILTER, DFX_FILTERTYPE}, 80 {DFX_UB_SET_PORTRAITEFFECT, DFX_PORTRAITEFFECT}, 81 {DFX_UB_SET_BEAUTY_AUTOVALUE, DFX_BEAUTY_AUTOVALUE}, 82 {DFX_UB_SET_BEAUTY_SKINSMOOTH, DFX_BEAUTY_SKINSMOOTH}, 83 {DFX_UB_SET_BEAUTY_FACESLENDER, DFX_BEAUTY_FACESLENDER}, 84 {DFX_UB_SET_BEAUTY_SKINTONE, DFX_BEAUTY_SKINTONE}, 85 {DFX_UB_SET_FOCUSMODE, DFX_FOCUSMODE}, 86 {DFX_UB_SET_FOCUSPOINT, DFX_FOCUSPOINT}, 87 {DFX_UB_SET_EXPOSUREMODE, DFX_EXPOSUREMODE}, 88 {DFX_UB_SET_EXPOSUREBIAS, DFX_EXPOSUREBIAS}, 89 {DFX_UB_SET_METERINGPOINT, DFX_METERINGPOINT}, 90 {DFX_UB_SET_FLASHMODE, DFX_FLASHMODE}, 91 {DFX_UB_SET_FRAMERATERANGE, DFX_FRAMERATERANGE}, 92 {DFX_UB_MUTE_CAMERA, DFX_MUTE_CAMERA}, 93 {DFX_UB_SET_QUALITY_PRIORITIZATION, DFX_QUALITY_PRIORITIZATION}, 94 }; 95 96 struct CallerInfo { 97 int32_t pid; 98 int32_t uid; 99 uint32_t tokenID; 100 std::string bundleName; 101 }; 102 103 struct DfxCaptureInfo { 104 int32_t captureId; 105 CallerInfo caller; 106 uint64_t captureStartTime; 107 uint64_t captureEndTime; 108 }; 109 110 class CameraReportUtils { 111 public: GetInstance()112 static CameraReportUtils &GetInstance() 113 { 114 static CameraReportUtils instance; 115 return instance; 116 } 117 static CallerInfo GetCallerInfo(); 118 static void ReportCameraError( 119 std::string funcName, int32_t errCode, bool isHdiErr, CallerInfo callerInfo); 120 void ReportUserBehavior(std::string behaviorName, 121 std::string value, 122 CallerInfo callerInfo); 123 124 void SetOpenCamPerfPreInfo(const std::string& cameraId, CallerInfo caller); 125 void SetOpenCamPerfStartInfo(const std::string& cameraId, CallerInfo caller); 126 void SetOpenCamPerfEndInfo(); 127 128 void SetModeChangePerfStartInfo(int32_t preMode, CallerInfo caller); 129 void updateModeChangePerfInfo(int32_t curMode, CallerInfo caller); 130 void SetModeChangePerfEndInfo(); 131 132 void SetCapturePerfStartInfo(DfxCaptureInfo captureInfo); 133 void SetCapturePerfEndInfo(int32_t captureId); 134 135 void SetSwitchCamPerfStartInfo(CallerInfo caller); 136 void SetSwitchCamPerfEndInfo(); 137 138 void UpdateProfileInfo(const std::string& profileStr); 139 void UpdateImagingInfo(const std::string& imagingKey, const std::string& value); 140 void SetVideoStartInfo(DfxCaptureInfo captureInfo); 141 void SetVideoEndInfo(int32_t captureId); 142 143 private: 144 std::mutex mutex_; 145 CallerInfo caller_; 146 std::string preCameraId_; 147 std::string cameraId_; 148 int32_t preMode_; 149 int32_t curMode_; 150 151 std::string profile_; 152 153 uint64_t openCamPerfStartTime_; 154 uint64_t openCamPerfEndTime_; 155 bool isPrelaunching_; 156 bool isOpening_; 157 158 uint64_t modeChangeStartTime_; 159 uint64_t modeChangeEndTime_; 160 bool isModeChanging_; 161 162 uint64_t switchCamPerfStartTime_; 163 uint64_t switchCamPerfEndTime_; 164 bool isSwitching_; 165 166 std::map<int32_t, DfxCaptureInfo> captureList_; 167 std::unordered_map<std::string, std::string> imagingValueList_; 168 169 bool IsCallerChanged(CallerInfo preCaller, CallerInfo curCaller); 170 bool IsBehaviorNeedReport(const std::string& behaviorName, const std::string& value); 171 172 void ReportOpenCameraPerf(uint64_t costTime, const std::string& startType); 173 void ReportModeChangePerf(uint64_t costTime); 174 void ReportCapturePerf(DfxCaptureInfo captureInfo); 175 void ReportSwitchCameraPerf(uint64_t costTime); 176 void ReportImagingInfo(DfxCaptureInfo captureInfo); 177 void ResetImagingValue(); 178 }; 179 } // namespace CameraStandard 180 } // namespace OHOS 181 #endif // OHOS_CAMERA_REPORT_UITLS_H 182