1 /* 2 * Copyright (c) 2022 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 WORK_SCHED_SERVICES_POLICY_APP_DATA_CLEAR_LISTENER_H 16 #define WORK_SCHED_SERVICES_POLICY_APP_DATA_CLEAR_LISTENER_H 17 18 #include "ipolicy_listener.h" 19 #include "common_event_subscriber.h" 20 #include "work_policy_manager.h" 21 22 namespace OHOS { 23 using namespace EventFwk; 24 namespace WorkScheduler { 25 class WorkPolicyManager; 26 class AppDataClearListener : public IPolicyListener, public std::enable_shared_from_this<AppDataClearListener> { 27 public: 28 explicit AppDataClearListener(std::shared_ptr<WorkPolicyManager> workPolicyManager); 29 ~AppDataClearListener() override; 30 31 /** 32 * @brief The OnPolicyChanged callback. 33 * 34 * @param policyType The policy type. 35 * @param detectorVal The detector val. 36 */ 37 void OnPolicyChanged(PolicyType policyType, std::shared_ptr<DetectorValue> detectorVal) override; 38 /** 39 * @brief Start. 40 * 41 * @return True if success,else false. 42 */ 43 bool Start() override; 44 /** 45 * @brief Stop. 46 * 47 * @return True if success,else false. 48 */ 49 bool Stop() override; 50 private: 51 std::shared_ptr<WorkPolicyManager> workPolicyManager_; 52 std::shared_ptr<CommonEventSubscriber> commonEventSubscriber = nullptr; 53 }; 54 55 class AppDataClearSubscriber : public CommonEventSubscriber { 56 public: 57 AppDataClearSubscriber(const CommonEventSubscribeInfo &subscribeInfo, AppDataClearListener &listener); 58 ~AppDataClearSubscriber() override = default; 59 /** 60 * @brief The OnReceiveEvent callback. 61 * 62 * @param data The data. 63 */ 64 void OnReceiveEvent(const CommonEventData &data) override; 65 private: 66 AppDataClearListener &listener_; 67 }; 68 } // namespace WorkScheduler 69 } // namespace OHOS 70 #endif // WORK_SCHED_SERVICES_POLICY_APP_DATA_CLEAR_LISTENER_H