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: QueryBundleStatsInfoByInterval, query all usage statistics in specific time span for calling user. 47 * parameters: intervalType, beginTime, endTime, errCode 48 * return: vector of bundle usage statistics. 49 */ 50 ErrCode QueryBundleStatsInfoByInterval(std::vector<BundleActivePackageStats>& PackageStats, 51 const int32_t intervalType, const int64_t beginTime, const int64_t endTime, int32_t userId) override; 52 53 /* 54 * function: QueryBundleEvents, query all events in specific time span for calling user. 55 * parameters: beginTime, endTime, errCode 56 * return: errorcode. 57 */ 58 ErrCode QueryBundleEvents(std::vector<BundleActiveEvent>& bundleActiveEvents, const int64_t beginTime, 59 const int64_t endTime, int32_t userId) override; 60 61 /* 62 * function: SetAppGroup, set specific bundle of specific user to a priority group. 63 * parameters: bundleName, newGroup, userId. 64 * return: errorcode. 65 */ 66 ErrCode SetAppGroup(const std::string& bundleName, int32_t newGroup, int32_t userId) override; 67 68 /* 69 * function: QueryBundleStatsInfos, query bundle usage statistics in specific time span for calling bundle. 70 * parameters: intervalType, beginTime, endTime 71 * return: errCode. 72 */ 73 ErrCode QueryBundleStatsInfos(std::vector<BundleActivePackageStats>& bundleActivePackageStats, 74 const int32_t intervalType, const int64_t beginTime, const int64_t endTime) override; 75 76 /* 77 * function: QueryCurrentBundleEvents, query bundle usage statistics in specific time span for calling bundle. 78 * parameters: beginTime, endTime 79 * return: errCode. 80 */ 81 ErrCode QueryCurrentBundleEvents(std::vector<BundleActiveEvent>& bundleActiveEvents, const int64_t beginTime, 82 const int64_t endTime) override; 83 84 /* 85 * function: QueryAppGroup, query bundle priority group calling bundle. 86 * return: the priority group of calling bundle. 87 * return: errorcode. 88 */ 89 ErrCode QueryAppGroup(int32_t& appGroup, std::string& bundleName, const int32_t userId) override; 90 91 /* 92 * function: QueryModuleUsageRecords, query all from usage statistics in specific time span for calling user. 93 * parameters: maxNum, results, userId, default userId is -1 for JS API, 94 * if other SAs call this API, they should explicit define userId. 95 * return: errorcode. 96 */ 97 ErrCode QueryModuleUsageRecords(int32_t maxNum, std::vector<BundleActiveModuleRecord>& results, 98 int32_t userId = -1) override; 99 100 /* 101 * function: QueryDeviceEventStats, query all from event stats in specific time span for calling user. 102 * parameters: beginTime, endTime, eventStats, userId, default userId is -1 for JS API, 103 * if other SAs call this API, they should explicit define userId. 104 * return: errorcode. 105 */ 106 ErrCode QueryDeviceEventStats(int64_t beginTime, int64_t endTime, 107 std::vector<BundleActiveEventStats>& eventStats, int32_t userId) override; 108 109 /* 110 * function: QueryNotificationEventStats, query all app notification number in specific time span for calling user. 111 * parameters: beginTime, endTime, eventStats, userId, default userId is -1 for JS API, 112 * if other SAs call this API, they should explicit define userId. 113 * return: errorcode. 114 */ 115 ErrCode QueryNotificationEventStats(int64_t beginTime, int64_t endTime, 116 std::vector<BundleActiveEventStats>& eventStats, int32_t userId) override; 117 118 /* 119 * function: BundleActiveProxy, default constructor. 120 * parameters: impl 121 */ BundleActiveProxy(const sptr<IRemoteObject> & impl)122 explicit BundleActiveProxy(const sptr<IRemoteObject>& impl) 123 : IRemoteProxy<IBundleActiveService>(impl) {} 124 125 /* 126 * function: RegisterAppGroupCallBack, register the observer to groupObservers. 127 * parameters: observer. 128 * return: errorcode. 129 */ 130 ErrCode RegisterAppGroupCallBack(const sptr<IAppGroupCallback> &observer) override; 131 132 /* 133 * function: UnRegisterAppGroupCallBack, remove the observer from groupObservers. 134 * parameters: observer. 135 * return: errorcode. 136 */ 137 ErrCode UnRegisterAppGroupCallBack(const sptr<IAppGroupCallback> &observer) override; 138 139 /* 140 * function: ~BundleActiveProxy, default destructor. 141 */ ~BundleActiveProxy()142 virtual ~BundleActiveProxy() {} 143 144 private: 145 static inline BrokerDelegator<BundleActiveProxy> delegator_; 146 ErrCode IPCCommunication(int64_t beginTime, int64_t endTime, std::vector<BundleActiveEventStats>& eventStats, 147 int32_t userId, int32_t communicationFlag); 148 }; 149 } // namespace DeviceUsageStats 150 } // namespace OHOS 151 #endif // BUNDLE_ACTIVE_PROXY_H 152 153