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 DRIVER_PKG_MANAGER_H
17 #define DRIVER_PKG_MANAGER_H
18 
19 #include <iostream>
20 #include <stdint.h>
21 
22 #include "bundle_monitor.h"
23 #include "drv_bundle_state_callback.h"
24 #include "ibus_extension.h"
25 #include "single_instance.h"
26 #include "ext_object.h"
27 #include <future>
28 namespace OHOS {
29 namespace ExternalDeviceManager {
30 using namespace std;
31 using namespace OHOS;
32 using namespace OHOS::AAFwk;
33 using namespace OHOS::AppExecFwk;
34 using namespace OHOS::ExternalDeviceManager;
35 
36 enum {
37     ERR_DRV_PKG_MGR_ERROR = 1,
38 };
39 
40 struct BundleInfoNames {
41     string bundleName;
42     string abilityName;
43     string driverUid;
44 };
45 
46 class DriverPkgManager {
47     DECLARE_SINGLE_INSTANCE_BASE(DriverPkgManager);
48 
49 public:
50     void PrintTest();
51     /**
52      * @brief Called at first before Monitor DriverExtension Package.
53      * @param bundleName Indicates the bundle name of the application.
54      * @param launcherShortcutInfo List of LauncherShortcutInfo objects if obtained.
55      * @return Returns true if the function is successfully called; returns false otherwise.
56      */
57     int32_t Init();
58     int32_t Init(shared_future<int32_t> bmsFuture, shared_future<int32_t> accountFuture,
59         shared_future<int32_t> commEventFuture);
60     shared_ptr<BundleInfoNames> QueryMatchDriver(shared_ptr<DeviceInfo> devInfo);
61     int32_t QueryDriverInfo(vector<shared_ptr<DriverInfo>> &driverInfos,
62         bool isByDriverUid = false, const std::string &driverUid = "");
63     int32_t RegisterOnBundleUpdate(PCALLBACKFUN pFun);
64     int32_t RegisterBundleCallback(std::shared_ptr<IBundleUpdateCallback> callback);
65     int32_t UnRegisterOnBundleUpdate();
66     int32_t RegisterBundleStatusCallback();
67     bool SubscribeOsAccountSwitch();
68     ~DriverPkgManager();
69 
70 private:
71     shared_ptr<BundleMonitor> bundleMonitor_ = nullptr;
72     sptr<DrvBundleStateCallback> bundleStateCallback_ = nullptr;
73     BundleInfoNames bundleInfoName_;
74 
75     shared_future<int32_t> bmsFuture_;
76     shared_future<int32_t> accountFuture_;
77     shared_future<int32_t> commEventFuture_;
78 
79     int32_t UnRegisterBundleStatusCallback();
80     DriverPkgManager();
81 };
82 } // namespace ExternalDeviceManager
83 } // namespace OHOS
84 #endif // DRIVER_PKG_MANAGER_H