• 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_INSTALLER_IMPL_H
17 #define DISTRIBUTEDDATAMGR_INSTALLER_IMPL_H
18 
19 #include "common_event_subscriber.h"
20 #include "kvstore_data_service.h"
21 #include "installer.h"
22 
23 namespace OHOS::DistributedKv {
24 class InstallEventSubscriber : public EventFwk::CommonEventSubscriber {
25 public:
26 using InstallEventCallback = void (InstallEventSubscriber::*)
27     (const std::string &bundleName, int32_t userId, int32_t appIndex);
28     InstallEventSubscriber(const EventFwk::CommonEventSubscribeInfo &info, KvStoreDataService *kvStoreDataService);
29 
~InstallEventSubscriber()30     ~InstallEventSubscriber() {}
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     static constexpr const char *APP_INDEX = "appIndex";
37     void OnUninstall(const std::string &bundleName, int32_t userId, int32_t appIndex);
38     void OnUpdate(const std::string &bundleName, int32_t userId, int32_t appIndex);
39     void OnInstall(const std::string &bundleName, int32_t userId, int32_t appIndex);
40     std::map<std::string, InstallEventCallback> callbacks_;
41     KvStoreDataService *kvStoreDataService_;
42 };
43 
44 class InstallerImpl : public Installer {
45 public:
46     InstallerImpl() = default;
47     ~InstallerImpl();
48 
49     Status Init(KvStoreDataService *kvStoreDataService, std::shared_ptr<ExecutorPool> executors) override;
50 
51     void UnsubscribeEvent() override;
52 
53 private:
54     static constexpr int32_t RETRY_TIME = 300;
55     static constexpr int32_t RETRY_INTERVAL = 100;
56     int32_t retryTime_ = 0;
57     ExecutorPool::Task GetTask();
58     std::shared_ptr<InstallEventSubscriber> subscriber_ {};
59     std::shared_ptr<ExecutorPool> executors_ {};
60 };
61 } // namespace OHOS::DistributedKv
62 #endif // DISTRIBUTEDDATAMGR_INSTALLER_IMPL_H