• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 
40     class ComponentEventHandler : public AppExecFwk::EventHandler {
41     public:
42         explicit ComponentEventHandler(const std::shared_ptr<AppExecFwk::EventRunner> &runner,
43             ComponentPrivacy *comPrivacy);
44         ~ComponentEventHandler() override;
45 
46         void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override;
47     private:
48         void ProcessStartPage(const AppExecFwk::InnerEvent::Pointer &event);
49         void ProcessStopPage(const AppExecFwk::InnerEvent::Pointer &event);
50 
51         using compEventFunc = void (ComponentEventHandler::*)(
52             const AppExecFwk::InnerEvent::Pointer &event);
53         std::map<int32_t, compEventFunc> eventFuncMap_;
54         ComponentPrivacy *comPrivacyObj_;
55     };
56 
57 private:
58     std::string DeviceTypeToString(uint16_t deviceTypeId);
59 
60     std::shared_ptr<ComponentPrivacy::ComponentEventHandler> eventHandler_;
61 };
62 } // namespace DistributedHardware
63 } // namespace OHOS
64 #endif
65