1 /* 2 * Copyright (c) 2023-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_DISTRIBUTED_HARDWARE_COMPONENT_PRIVACY_H 17 #define OHOS_DISTRIBUTED_HARDWARE_COMPONENT_PRIVACY_H 18 19 #include "idistributed_hardware_sink.h" 20 #include "event_handler.h" 21 22 namespace OHOS { 23 namespace DistributedHardware { 24 const std::string PRIVACY_SUBTYPE = "subtype"; 25 const std::string PRIVACY_NETWORKID = "networkId"; 26 constexpr uint32_t COMP_START_PAGE = 1; 27 constexpr uint32_t COMP_STOP_PAGE = 2; 28 constexpr uint32_t COMP_PRIVACY_DELAY_TIME = 1000; // million seconds 29 class ComponentPrivacy : public PrivacyResourcesListener { 30 public: 31 ComponentPrivacy(); 32 virtual ~ComponentPrivacy(); 33 int32_t OnPrivaceResourceMessage(const ResourceEventType &type, const std::string &subtype, 34 const std::string &networkId, bool &isSensitive, bool &isSameAccout) override; 35 int32_t OnResourceInfoCallback(const std::string &subtype, const std::string &networkId, 36 bool &isSensitive, bool &isSameAccout); 37 int32_t StartPrivacePage(const std::string &subtype, const std::string &networkId); 38 int32_t StopPrivacePage(const std::string &subtype); 39 void SetPageFlagTrue(); 40 void SetPageFlagFalse(); 41 bool GetPageFlag(); 42 43 class ComponentEventHandler : public AppExecFwk::EventHandler { 44 public: 45 explicit ComponentEventHandler(const std::shared_ptr<AppExecFwk::EventRunner> runner, 46 ComponentPrivacy *comPrivacy); 47 ~ComponentEventHandler() override; 48 49 void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; 50 private: 51 void ProcessStartPage(const AppExecFwk::InnerEvent::Pointer &event); 52 void ProcessStopPage(const AppExecFwk::InnerEvent::Pointer &event); 53 54 ComponentPrivacy *comPrivacyObj_; 55 }; 56 57 private: 58 std::string DeviceTypeToString(uint16_t deviceTypeId); 59 void HandleClosePage(const std::string &subtype); 60 void HandlePullUpPage(const std::string &subtype, const std::string &networkId); 61 62 std::shared_ptr<ComponentPrivacy::ComponentEventHandler> eventHandler_; 63 std::atomic<bool> isPrivacePageOpen_ = false; 64 }; 65 } // namespace DistributedHardware 66 } // namespace OHOS 67 #endif 68