• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 DISTRIBUTEDDATAMGR_UNINSTALLER_IMPL_H
17 #define DISTRIBUTEDDATAMGR_UNINSTALLER_IMPL_H
18 
19 #include "common_event_subscriber.h"
20 #include "kvstore_data_service.h"
21 #include "uninstaller.h"
22 
23 namespace OHOS::DistributedKv {
24 class UninstallEventSubscriber : public EventFwk::CommonEventSubscriber {
25 public:
26 using UninstallEventCallback = void (UninstallEventSubscriber::*)
27     (const std::string &bundleName, int32_t userId, int32_t appIndex);
28     UninstallEventSubscriber(const EventFwk::CommonEventSubscribeInfo &info, KvStoreDataService *kvStoreDataService);
29 
~UninstallEventSubscriber()30     ~UninstallEventSubscriber() {}
31     void OnReceiveEvent(const EventFwk::CommonEventData &event) override;
32 
33 private:
34     static constexpr const char *USER_ID = "userId";
35     static constexpr const char *SANDBOX_APP_INDEX = "sandbox_app_index";
36     void OnUninstall(const std::string &bundleName, int32_t userId, int32_t appIndex);
37     void OnUpdate(const std::string &bundleName, int32_t userId, int32_t appIndex);
38     std::map<std::string, UninstallEventCallback> callbacks_;
39     KvStoreDataService *kvStoreDataService_;
40 };
41 
42 class UninstallerImpl : public Uninstaller {
43 public:
44     UninstallerImpl() = default;
45     ~UninstallerImpl();
46 
47     Status Init(KvStoreDataService *kvStoreDataService, std::shared_ptr<ExecutorPool> executors) override;
48 
49     void UnsubscribeEvent() override;
50 
51 private:
52     static constexpr int32_t RETRY_TIME = 300;
53     static constexpr int32_t RETRY_INTERVAL = 100;
54     int32_t retryTime_ = 0;
55     ExecutorPool::Task GetTask();
56     std::shared_ptr<UninstallEventSubscriber> subscriber_ {};
57     std::shared_ptr<ExecutorPool> executors_ {};
58 };
59 } // namespace OHOS::DistributedKv
60 #endif // DISTRIBUTEDDATAMGR_UNINSTALLER_IMPL_H
61