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 ENTERPRISE_DEVICE_MANAGEMENT_ADAPTER_IMPL_H 17 #define ENTERPRISE_DEVICE_MANAGEMENT_ADAPTER_IMPL_H 18 19 #include "enterprise_device_management_adapter.h" 20 21 #include "common_event_manager.h" 22 #include "common_event_support.h" 23 #include "matching_skills.h" 24 #include "want.h" 25 #include "common_event_subscriber.h" 26 27 namespace OHOS::NWeb { 28 29 #if defined(NWEB_ENTERPRISE_DEVICE_MANAGER_ENABLE) 30 class NWebEdmEventSubscriber : public EventFwk::CommonEventSubscriber { 31 public: 32 NWebEdmEventSubscriber(EventFwk::CommonEventSubscribeInfo& in, 33 std::shared_ptr<EdmPolicyChangedEventCallbackAdapter> cb); 34 35 ~NWebEdmEventSubscriber() override = default; 36 37 void OnReceiveEvent(const EventFwk::CommonEventData& data) override; 38 private: 39 std::shared_ptr<EdmPolicyChangedEventCallbackAdapter> eventCallback_; 40 }; 41 #endif 42 43 class EnterpriseDeviceManagementAdapterImpl : public EnterpriseDeviceManagementAdapter { 44 public: 45 static EnterpriseDeviceManagementAdapterImpl& GetInstance(); 46 ~EnterpriseDeviceManagementAdapterImpl() override = default; 47 int32_t GetPolicies(std::string& policies) override; 48 49 /** 50 * Set an EDM policy change event callback. 51 * 52 * @param eventCallback EDM policy change event callback. 53 */ 54 void RegistPolicyChangeEventCallback(std::shared_ptr<EdmPolicyChangedEventCallbackAdapter> eventCallback) override; 55 56 /** 57 * Subscribe EDM policy change event from CommonEventSubscriber. 58 * 59 * @return Returns true if success; false otherwise. 60 */ 61 bool StartObservePolicyChange() override; 62 63 /** 64 * Unsubscribe EDM policy change event from CommonEventSubscriber. 65 * 66 * @return Returns true if success; false otherwise. 67 */ 68 bool StopObservePolicyChange() override; 69 70 private: 71 EnterpriseDeviceManagementAdapterImpl() = default; 72 EnterpriseDeviceManagementAdapterImpl(const EnterpriseDeviceManagementAdapterImpl& other) = delete; 73 EnterpriseDeviceManagementAdapterImpl& operator=(const EnterpriseDeviceManagementAdapterImpl&) = delete; 74 75 std::shared_ptr<EdmPolicyChangedEventCallbackAdapter> eventCallback_ = nullptr; 76 std::shared_ptr<EventFwk::CommonEventSubscriber> commonEventSubscriber_ = nullptr; 77 }; 78 79 } // namespace OHOS::NWeb 80 81 #endif // ENTERPRISE_DEVICE_MANAGEMENT_ADAPTER_IMPL_H 82