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