1 /* 2 * Copyright (c) 2025 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 CAMERA_HOST_SELFKILL_H 17 #define CAMERA_HOST_SELFKILL_H 18 #include "thread" 19 #include "stdint.h" 20 #include "functional" 21 #include "string" 22 namespace OHOS::Camera { 23 24 class CameraHostSelfkiller { 25 public: 26 explicit CameraHostSelfkiller(uint8_t sleepInterval = 3, uint32_t noCameraForExitMaxTimeSecond = 30); 27 ~CameraHostSelfkiller(); 28 void Init(std::function<bool(void)> canBeKilledFn, std::function<void(void)> killerTimeoutCb = nullptr, 29 std::string selfKillParamName = DEFAULT_SELF_KILL_PARAM_NAME, 30 std::string cameraServiceName = DEFAULT_CAMERA_SERVICE_NAME); 31 void DeInit(); 32 static void UnloadHdfServiceByName(const std::string &serviceName); 33 static void WaitForBootComplete(); 34 35 private: 36 std::thread *selfKillerThread_ = nullptr; 37 bool selfKillerThreadLoopFlag_ = false; 38 std::string selfKillParamName_ = ""; 39 std::string cameraServiceName_ = ""; 40 std::function<void(void)> killerTimeoutCb_ = nullptr; 41 std::function<bool(void)> canBeKilledFn_ = nullptr; 42 void CameraHostSelfkillerHandler(); 43 static constexpr const char *DEFAULT_SELF_KILL_PARAM_NAME = "const.camera.setting.selfkill.enable"; 44 static constexpr const char *DEFAULT_CAMERA_SERVICE_NAME = "camera_service_usb"; 45 uint8_t sleepInterval_ = 3; 46 uint32_t noCameraForExitMaxTimeSecond_ = 30; 47 }; // class CameraHostSelfkiller 48 }; // namespace OHOS::Camera 49 #endif