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 
16 #ifndef BUNDLE_ACTIVE_PROXY_H
17 #define BUNDLE_ACTIVE_PROXY_H
18 
19 #include "ibundle_active_service.h"
20 #include "bundle_active_event.h"
21 #include "bundle_active_event_stats.h"
22 #include "bundle_active_package_stats.h"
23 #include "bundle_active_module_record.h"
24 #include "bundle_state_inner_errors.h"
25 #include "iapp_group_callback.h"
26 
27 namespace OHOS {
28 namespace DeviceUsageStats {
29 class BundleActiveProxy : public IRemoteProxy<IBundleActiveService> {
30 public:
31     /*
32     * function: ReportEvent, used to report event.
33     * parameters: event, userId
34     * return: errorcode.
35     */
36     ErrCode ReportEvent(BundleActiveEvent& event, const int32_t userId) override;
37 
38     /*
39     * function: IsBundleIdle, used to check whether specific bundle is idle.
40     * parameters: bundleName
41     * return: if bundle is idle, return true. if bundle is not idle, return false.
42     */
43     ErrCode IsBundleIdle(bool& isBundleIdle, const std::string& bundleName, int32_t userId = -1) override;
44 
45     /*
46     * function: IsBundleUsePeriod, used to check whether specific bundle is use period.
47     * parameters: bundleName, userId.
48     * return: errorcode.
49     */
50     ErrCode IsBundleUsePeriod(bool& IsUsePeriod, const std::string& bundleName, int32_t userId = -1) override;
51 
52     /*
53     * function: QueryBundleStatsInfoByInterval, query all usage statistics in specific time span for calling user.
54     * parameters: intervalType, beginTime, endTime, errCode
55     * return: vector of bundle usage statistics.
56     */
57     ErrCode QueryBundleStatsInfoByInterval(std::vector<BundleActivePackageStats>& PackageStats,
58         const int32_t intervalType, const int64_t beginTime, const int64_t endTime, int32_t userId) override;
59 
60     /*
61     * function: QueryBundleEvents, query all events in specific time span for calling user.
62     * parameters: beginTime, endTime, errCode
63     * return: errorcode.
64     */
65     ErrCode QueryBundleEvents(std::vector<BundleActiveEvent>& bundleActiveEvents, const int64_t beginTime,
66         const int64_t endTime, int32_t userId) override;
67 
68     /*
69     * function: SetAppGroup, set specific bundle of specific user to a priority group.
70     * parameters: bundleName, newGroup, userId.
71     * return: errorcode.
72     */
73     ErrCode SetAppGroup(const std::string& bundleName, int32_t newGroup, int32_t userId) override;
74 
75     /*
76     * function: QueryBundleStatsInfos, query bundle usage statistics in specific time span for calling bundle.
77     * parameters: intervalType, beginTime, endTime
78     * return: errCode.
79     */
80     ErrCode QueryBundleStatsInfos(std::vector<BundleActivePackageStats>& bundleActivePackageStats,
81         const int32_t intervalType, const int64_t beginTime, const int64_t endTime) override;
82 
83     /*
84     * function: QueryCurrentBundleEvents, query bundle usage statistics in specific time span for calling bundle.
85     * parameters: beginTime, endTime
86     * return: errCode.
87     */
88     ErrCode QueryCurrentBundleEvents(std::vector<BundleActiveEvent>& bundleActiveEvents, const int64_t beginTime,
89         const int64_t endTime) override;
90 
91     /*
92     * function: QueryAppGroup, query bundle priority group calling bundle.
93     * return: the priority group of calling bundle.
94     * return: errorcode.
95     */
96     ErrCode QueryAppGroup(int32_t& appGroup, std::string& bundleName, const int32_t userId) override;
97 
98     /*
99     * function: QueryModuleUsageRecords, query all from usage statistics in specific time span for calling user.
100     * parameters: maxNum, results, userId, default userId is -1 for JS API,
101     * if other SAs call this API, they should explicit define userId.
102     * return: errorcode.
103     */
104     ErrCode QueryModuleUsageRecords(int32_t maxNum, std::vector<BundleActiveModuleRecord>& results,
105         int32_t userId = -1) override;
106 
107     /*
108     * function: QueryDeviceEventStats, query all from event stats in specific time span for calling user.
109     * parameters: beginTime, endTime, eventStats, userId, default userId is -1 for JS API,
110     * if other SAs call this API, they should explicit define userId.
111     * return: errorcode.
112     */
113     ErrCode QueryDeviceEventStats(int64_t beginTime, int64_t endTime,
114         std::vector<BundleActiveEventStats>& eventStats, int32_t userId) override;
115 
116     /*
117     * function: QueryNotificationEventStats, query all app notification number in specific time span for calling user.
118     * parameters: beginTime, endTime, eventStats, userId, default userId is -1 for JS API,
119     * if other SAs call this API, they should explicit define userId.
120     * return: errorcode.
121     */
122     ErrCode QueryNotificationEventStats(int64_t beginTime, int64_t endTime,
123         std::vector<BundleActiveEventStats>& eventStats, int32_t userId) override;
124 
125     /*
126     * function: BundleActiveProxy, default constructor.
127     * parameters: impl
128     */
BundleActiveProxy(const sptr<IRemoteObject> & impl)129     explicit BundleActiveProxy(const sptr<IRemoteObject>& impl)
130         : IRemoteProxy<IBundleActiveService>(impl) {}
131 
132     /*
133     * function: RegisterAppGroupCallBack, register the observer to groupObservers.
134     * parameters: observer.
135     * return: errorcode.
136     */
137     ErrCode RegisterAppGroupCallBack(const sptr<IAppGroupCallback> &observer) override;
138 
139     /*
140     * function: UnRegisterAppGroupCallBack, remove the observer from groupObservers.
141     * parameters: observer.
142     * return: errorcode.
143     */
144     ErrCode UnRegisterAppGroupCallBack(const sptr<IAppGroupCallback> &observer) override;
145 
146     /*
147     * function: ~BundleActiveProxy, default destructor.
148     */
~BundleActiveProxy()149     virtual ~BundleActiveProxy() {}
150 
151 private:
152     static inline BrokerDelegator<BundleActiveProxy> delegator_;
153     ErrCode IPCCommunication(int64_t beginTime, int64_t endTime, std::vector<BundleActiveEventStats>& eventStats,
154         int32_t userId, int32_t communicationFlag);
155 };
156 }  // namespace DeviceUsageStats
157 }  // namespace OHOS
158 #endif  // BUNDLE_ACTIVE_PROXY_H
159 
160