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: QueryBundleStatsInfoByInterval, query all usage statistics in specific time span for calling user. 67 * parameters: intervalType, beginTime, endTime, errCode 68 * return: errCode. 69 */ 70 virtual ErrCode QueryBundleStatsInfoByInterval(std::vector<BundleActivePackageStats>& PackageStats, 71 const int32_t intervalType, const int64_t beginTime, const int64_t endTime, int32_t userId) = 0; 72 73 /* 74 * function: QueryBundleEvents, query all events in specific time span for calling user. 75 * parameters: beginTime, endTime, errCode 76 * return: errCode. 77 */ 78 virtual ErrCode QueryBundleEvents(std::vector<BundleActiveEvent>& bundleActiveEvents, const int64_t beginTime, 79 const int64_t endTime, int32_t userId) = 0; 80 81 /* 82 * function: QueryBundleStatsInfos, query bundle usage statistics in specific time span for calling bundle. 83 * parameters: intervalType, beginTime, endTime 84 * return: vector of calling bundle usage statistics. 85 */ 86 virtual ErrCode QueryBundleStatsInfos(std::vector<BundleActivePackageStats>& bundleActivePackageStats, 87 const int32_t intervalType, const int64_t beginTime, const int64_t endTime) = 0; 88 89 /* 90 * function: QueryCurrentBundleEvents, query bundle usage statistics in specific time span for calling bundle. 91 * parameters: beginTime, endTime 92 * return: errCode. 93 */ 94 virtual ErrCode QueryCurrentBundleEvents(std::vector<BundleActiveEvent>& bundleActiveEvents, 95 const int64_t beginTime, const int64_t endTime) = 0; 96 97 /* 98 * function: QueryAppGroup, query app group by bundleName and userId. 99 * parameters: bundleName, userId. 100 * return: the priority group of calling bundle. 101 */ 102 virtual ErrCode QueryAppGroup(int32_t& appGroup, std::string& bundleName, const int32_t userId) = 0; 103 104 /* 105 * function: SetAppGroup, set specific bundle of specific user to a priority group. 106 * parameters: bundleName, newGroup, userId 107 * return: errorcode. 108 */ 109 virtual ErrCode SetAppGroup(const std::string& bundleName, int32_t newGroup, int32_t userId) = 0; 110 111 /* 112 * function: QueryModuleUsageRecords, query all from usage statistics in specific time span for calling user. 113 * parameters: maxNum, results, userId, default userId is -1 for JS API, 114 * if other SAs call this API, they should explicit define userId. 115 * return: errorcode. 116 */ 117 virtual ErrCode QueryModuleUsageRecords(int32_t maxNum, std::vector<BundleActiveModuleRecord>& results, 118 int32_t userId) = 0; 119 120 /* 121 * function: RegisterAppGroupCallBack, register the observer to groupObservers. 122 * parameters: observer 123 * return: errorcode. 124 */ 125 virtual ErrCode RegisterAppGroupCallBack(const sptr<IAppGroupCallback> &observer) = 0; 126 127 /* 128 * function: UnRegisterAppGroupCallBack, remove the observer from groupObservers. 129 * parameters: observer 130 * return: errorcode. 131 */ 132 virtual ErrCode UnRegisterAppGroupCallBack(const sptr<IAppGroupCallback> &observer) = 0; 133 134 /* 135 * function: QueryDeviceEventStats, query all from event stats in specific time span for calling user. 136 * parameters: beginTime, endTime, eventStats, userId, default userId is -1 for JS API, 137 * if other SAs call this API, they should explicit define userId. 138 * return: errorcode. 139 */ 140 virtual ErrCode QueryDeviceEventStats(int64_t beginTime, int64_t endTime, 141 std::vector<BundleActiveEventStats>& eventStats, int32_t userId) = 0; 142 143 /* 144 * function: QueryNotificationEventStats, query all app notification number in specific time span for calling user. 145 * parameters: beginTime, endTime, eventStats, userId, default userId is -1 for JS API, 146 * if other SAs call this API, they should explicit define userId. 147 * return: errorcode. 148 */ 149 virtual ErrCode QueryNotificationEventStats(int64_t beginTime, int64_t endTime, 150 std::vector<BundleActiveEventStats>& eventStats, int32_t userId) = 0; 151 public: 152 DECLARE_INTERFACE_DESCRIPTOR(u"Resourceschedule.IBundleActiveService"); 153 }; 154 } // namespace DeviceUsageStats 155 } // namespace OHOS 156 #endif // BUNDLE_ACTIVE_ISERVICE_H 157 158