1 /* 2 * Copyright (c) 2024-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 #ifndef CAMERA_PRIVACY_H 16 #define CAMERA_PRIVACY_H 17 18 #include <refbase.h> 19 #include <memory> 20 #include "camera_util.h" 21 #include "accesstoken_kit.h" 22 #include "perm_state_change_callback_customize.h" 23 #include "privacy_kit.h" 24 #include "state_customized_cbk.h" 25 26 namespace OHOS { 27 namespace CameraStandard { 28 class HCameraDevice; 29 class PermissionStatusChangeCb : public Security::AccessToken::PermStateChangeCallbackCustomize { 30 public: PermissionStatusChangeCb( wptr<HCameraDevice> device, const Security::AccessToken::PermStateChangeScope& scopeInfo)31 explicit PermissionStatusChangeCb( 32 wptr<HCameraDevice> device, const Security::AccessToken::PermStateChangeScope& scopeInfo) 33 : PermStateChangeCallbackCustomize(scopeInfo), cameraDevice_(device) 34 {} 35 virtual ~PermissionStatusChangeCb() = default; 36 void PermStateChangeCallback(Security::AccessToken::PermStateChangeInfo& result) override; 37 38 private: 39 wptr<HCameraDevice> cameraDevice_; 40 }; 41 42 class CameraUseStateChangeCb : public Security::AccessToken::StateCustomizedCbk { 43 public: CameraUseStateChangeCb(wptr<HCameraDevice> device)44 explicit CameraUseStateChangeCb(wptr<HCameraDevice> device) : cameraDevice_(device) {} 45 virtual ~CameraUseStateChangeCb() = default; 46 void StateChangeNotify(Security::AccessToken::AccessTokenID tokenId, bool isShowing) override; 47 48 private: 49 wptr<HCameraDevice> cameraDevice_; 50 }; 51 52 class CameraPrivacy : public RefBase { 53 public: CameraPrivacy(wptr<HCameraDevice> device, uint32_t callingTokenId, int32_t pid)54 explicit CameraPrivacy(wptr<HCameraDevice> device, uint32_t callingTokenId, int32_t pid) 55 : pid_(pid), callerToken_(callingTokenId), cameraDevice_(device) {} 56 ~CameraPrivacy(); 57 bool RegisterPermissionCallback(); 58 void UnregisterPermissionCallback(); 59 bool StartUsingPermissionCallback(); 60 void StopUsingPermissionCallback(); 61 bool AddCameraPermissionUsedRecord(); 62 bool IsAllowUsingCamera(); 63 64 private: 65 int32_t pid_; 66 uint32_t callerToken_; 67 wptr<HCameraDevice> cameraDevice_; 68 std::shared_ptr<PermissionStatusChangeCb> permissionCallbackPtr_; 69 std::shared_ptr<CameraUseStateChangeCb> cameraUseCallbackPtr_; 70 }; 71 } // namespace CameraStandard 72 } // namespace OHOS 73 #endif // CAMERA_PRIVACY_H