1 /* 2 * Copyright (c) 2021-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 BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_NOTIFICATION_CLONE_MANAGER_H 17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_NOTIFICATION_CLONE_MANAGER_H 18 19 #include <map> 20 #include <string> 21 22 #include "unique_fd.h" 23 #include "iremote_proxy.h" 24 #include "common_event_data.h" 25 #include "notification_clone_template.h" 26 #include "common_event_data.h" 27 #include "common_event_subscriber.h" 28 namespace OHOS { 29 namespace Notification { 30 31 class AncoRestoreStartEventSubscriber : public EventFwk::CommonEventSubscriber { 32 public: 33 DISALLOW_COPY_AND_MOVE(AncoRestoreStartEventSubscriber); 34 explicit AncoRestoreStartEventSubscriber(const EventFwk::CommonEventSubscribeInfo &subscribeInfo); 35 ~AncoRestoreStartEventSubscriber() override; 36 void OnReceiveEvent(const EventFwk::CommonEventData& data) override; 37 static std::shared_ptr<AncoRestoreStartEventSubscriber> create(); 38 39 private: 40 inline static const std::string EVENT_NAME = "usual.event.ANCO_RESTORE_START"; 41 inline static const std::string EVENT_PUBLISHER_PERMISSION = "ohos.permission.RECEIVE_BMS_BROKER_MESSAGES"; 42 }; 43 44 class NotificationCloneManager { 45 public: 46 static NotificationCloneManager& GetInstance(); 47 48 int32_t OnBackup(MessageParcel& data, MessageParcel& reply); 49 int32_t OnRestore(MessageParcel& data, MessageParcel& reply); 50 void OnUserSwitch(int32_t userId); 51 void OnRestoreStart(EventFwk::Want want); 52 void OnDhRestoreStart(const std::string bundleName, const int32_t uid); 53 54 private: 55 NotificationCloneManager(); 56 ~NotificationCloneManager(); 57 58 void RemoveBackUpFile(); 59 ErrCode LoadConfig(UniqueFd &fd, std::string& config); 60 ErrCode SaveConfig(const std::string& config); 61 std::vector<std::pair<std::string, std::shared_ptr<NotificationCloneTemplate>>> cloneTemplates; 62 std::shared_ptr<AncoRestoreStartEventSubscriber> restoreStartEventSubscriber_ = nullptr; 63 }; 64 } // namespace Notification 65 } // namespace OHOS 66 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_NOTIFICATION_CLONE_MANAGER_H 67