From ebd824478af8d061b563b8b021a5638fc9db42db Mon Sep 17 00:00:00 2001 From: fengj130406 Date: Sat, 11 Jan 2025 14:53:51 +0800 Subject: [PATCH] 1907 idl Signed-off-by: fengj130406 --- BUILD.gn | 53 ++- IAppGroupCallback.idl | 4 + IBundleActiveService.idl | 27 ++ bundle.json | 8 +- frameworks/src/app_group_observer_napi.cpp | 9 +- .../include/app_group_callback_info.h | 87 ---- .../include/app_group_callback_proxy.h | 47 --- .../include/app_group_callback_stub.h | 46 -- .../innerkits/include/bundle_active_client.h | 4 + .../innerkits/include/bundle_active_event.h | 4 +- .../include/bundle_active_event_stats.h | 4 +- .../include/bundle_active_form_record.h | 4 +- .../include/bundle_active_module_record.h | 2 +- .../include/bundle_active_package_stats.h | 4 +- .../innerkits/include/bundle_active_proxy.h | 159 ------- .../innerkits/include/iapp_group_callback.h | 41 -- .../src/app_group_callback_proxy.cpp | 54 --- .../innerkits/src/app_group_callback_stub.cpp | 54 --- .../innerkits/src/bundle_active_event.cpp | 4 +- .../src/bundle_active_event_stats.cpp | 4 +- .../src/bundle_active_form_record.cpp | 4 +- .../src/bundle_active_module_record.cpp | 6 +- .../src/bundle_active_package_stats.cpp | 4 +- .../innerkits/src/bundle_active_proxy.cpp | 396 ------------------ .../napi/include/app_group_observer_napi.h | 2 +- libusagestatsinner.versionscript | 3 +- .../common/include/bundle_active_service.h | 8 +- services/common/include/bundle_active_stub.h | 56 --- .../common/include/ibundle_active_service.h | 164 -------- services/common/src/bundle_active_service.cpp | 2 +- .../include/bundle_active_period_stats.h | 1 + .../include/bundle_active_stats_combiner.h | 1 + .../appgroupcallbackstub_fuzzer.cpp | 13 +- test/unittest/bundle_active_total_test.cpp | 2 +- .../device_usage_statistics_multi_test.cpp | 5 +- .../device_usage_statistics_service_test.cpp | 5 +- .../unittest/device_usage_statistics_test.cpp | 21 +- 37 files changed, 150 insertions(+), 1162 deletions(-) create mode 100644 IAppGroupCallback.idl create mode 100644 IBundleActiveService.idl delete mode 100644 interfaces/innerkits/include/app_group_callback_info.h delete mode 100644 interfaces/innerkits/include/app_group_callback_proxy.h delete mode 100644 interfaces/innerkits/include/app_group_callback_stub.h delete mode 100644 interfaces/innerkits/include/bundle_active_proxy.h delete mode 100644 interfaces/innerkits/include/iapp_group_callback.h delete mode 100644 interfaces/innerkits/src/app_group_callback_proxy.cpp delete mode 100644 interfaces/innerkits/src/app_group_callback_stub.cpp delete mode 100644 interfaces/innerkits/src/bundle_active_proxy.cpp delete mode 100644 services/common/include/bundle_active_stub.h delete mode 100644 services/common/include/ibundle_active_service.h diff --git a/BUILD.gn b/BUILD.gn index b6c53b4..5f11893 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -11,9 +11,22 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//build/config/components/idl_tool/idl.gni") import("//build/ohos/sa_profile/sa_profile.gni") import("device_usage_statistics.gni") +idl_gen_interface("bundle_active_interface") { + src_idl = rebase_path("IBundleActiveService.idl") + log_domainid = "0xD001710" + log_tag = "BUNDLE_ACTIVE" +} + +idl_gen_interface("app_group_callback_interface") { + src_idl = rebase_path("IAppGroupCallback.idl") + log_domainid = "0xD001710" + log_tag = "BUNDLE_ACTIVE" +} + ohos_sa_profile("device_usage_statistics_sa_profile") { sources = [ "sa_profile/1907.json" ] part_name = "${device_usage_statistics_part_name}" @@ -21,6 +34,7 @@ ohos_sa_profile("device_usage_statistics_sa_profile") { config("usagestats_public_config") { include_dirs = [ + "${target_gen_dir}", "interfaces/innerkits/include", "interfaces/kits/bundlestats/napi/include", "services/common/include", @@ -33,28 +47,57 @@ config("usagestatsutils_config") { include_dirs = [ "utils/include" ] } +ohos_source_set("bundle_active_service_stub") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + output_values = get_target_outputs(":bundle_active_interface") + sources = filter_include(output_values, ["*_stub.cpp"]) + public_configs = [] + deps = [":bundle_active_interface"] + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_single", + "samgr:samgr_proxy", + ] + subsystem_name = "resourceschedule" + part_name = "${device_usage_statistics_part_name}" +} + ohos_shared_library("usagestatsinner") { sources = [ "interfaces/innerkits/src/app_group_callback_info.cpp", - "interfaces/innerkits/src/app_group_callback_proxy.cpp", - "interfaces/innerkits/src/app_group_callback_stub.cpp", "interfaces/innerkits/src/bundle_active_client.cpp", "interfaces/innerkits/src/bundle_active_event.cpp", "interfaces/innerkits/src/bundle_active_event_stats.cpp", "interfaces/innerkits/src/bundle_active_form_record.cpp", "interfaces/innerkits/src/bundle_active_module_record.cpp", "interfaces/innerkits/src/bundle_active_package_stats.cpp", - "interfaces/innerkits/src/bundle_active_proxy.cpp", ] public_configs = [ ":usagestats_public_config" ] - deps = [ ":usagestatsutils" ] + deps = [ + ":usagestatsutils", + ":bundle_active_interface", + ":app_group_callback_interface", + ] external_deps = [ "c_utils:utils", "eventhandler:libeventhandler", "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", "ipc:ipc_single", "samgr:samgr_proxy", ] + + bundle_active_output_values = get_target_outputs(":bundle_active_interface") + sources += filter_include(bundle_active_output_values, ["*.cpp"]) + app_group_callback_output_values = get_target_outputs(":app_group_callback_interface") + sources += filter_include(app_group_callback_output_values, ["*.cpp"]) + public_external_deps = [ "ffrt:libffrt" ] part_name = "${device_usage_statistics_part_name}" subsystem_name = "resourceschedule" @@ -177,7 +220,6 @@ ohos_shared_library("usagestatservice") { "services/common/src/bundle_active_power_state_callback_service.cpp", "services/common/src/bundle_active_service.cpp", "services/common/src/bundle_active_shutdown_callback_service.cpp", - "services/common/src/bundle_active_stub.cpp", "services/common/src/bundle_active_usage_database.cpp", "services/packagegroup/src/bundle_active_group_controller.cpp", "services/packagegroup/src/bundle_active_group_handler.cpp", @@ -263,7 +305,6 @@ ohos_static_library("usagestatservice_static") { "services/common/src/bundle_active_power_state_callback_service.cpp", "services/common/src/bundle_active_service.cpp", "services/common/src/bundle_active_shutdown_callback_service.cpp", - "services/common/src/bundle_active_stub.cpp", "services/common/src/bundle_active_usage_database.cpp", "services/packagegroup/src/bundle_active_group_controller.cpp", "services/packagegroup/src/bundle_active_group_handler.cpp", diff --git a/IAppGroupCallback.idl b/IAppGroupCallback.idl new file mode 100644 index 0000000..775151b --- /dev/null +++ b/IAppGroupCallback.idl @@ -0,0 +1,4 @@ +sequenceable OHOS.DeviceUsageStats.AppGroupCallbackInfo; +interface OHOS.DeviceUsageStats.IAppGroupCallback { + void OnAppGroupChanged([in] AppGroupCallbackInfo appGroupCallbackInfo); +} \ No newline at end of file diff --git a/IBundleActiveService.idl b/IBundleActiveService.idl new file mode 100644 index 0000000..5087837 --- /dev/null +++ b/IBundleActiveService.idl @@ -0,0 +1,27 @@ +sequenceable OHOS.DeviceUsageStats.BundleActiveEvent; +sequenceable OHOS.DeviceUsageStats.BundleActivePackageStats; +sequenceable OHOS.DeviceUsageStats.BundleActiveModuleRecord; +sequenceable OHOS.DeviceUsageStats.BundleActiveEventStats; +interface OHOS.DeviceUsageStats.IAppGroupCallback; +interface OHOS.DeviceUsageStats.IBundleActiveService { + void ReportEvent([out] BundleActiveEvent event, [in] int userId); + void IsBundleIdle([out] boolean isBundleIdle, [in] String bundleName, [in] int userId); + void IsBundleUsePeriod([out] boolean isUsePeriod, [in] String bundleName, [in] int userId); + void QueryBundleStatsInfoByInterval([out] List packageStats, + [in] int intervalType, [in] long beginTime, [in] long endTime, [in] int userId); + void QueryBundleEvents([out] List bundleActiveEvents, [in] long beginTime, + [in] long endTime, [in] int userId); + void QueryBundleStatsInfos([out] List BundleActivePackageStats, + [in] int intervalType, [in] long beginTime, [in] long endTime); + void QueryCurrentBundleEvents([out] List bundleActiveEvents, + [in] long beginTime, [in]long endTime); + void QueryAppGroup([out] in appGroup, [out] String bundleName, [in] int userId); + void SetAppGroup([in] String bundleName, [in] int newGroup, [in] int userId); + void QueryModuleUsageRecords([in] int maxNum, [out] List results, [in] int userId); + void RegisterAppGroupCallBack([in] IAppGroupCallback observer); + void UnRegisterAppGroupCallBack([in] IAppGroupCallback observer); + void QueryDeviceEventStats([in] long beginTime, [in] long endTime, + [out]List eventStats, [in] int userId); + void QueryNotificationEventStats([in] long beginTime, [in] long endTime, + [out]List eventStats, [in] int userId); +} \ No newline at end of file diff --git a/bundle.json b/bundle.json index 5f7bf35..0b6e8d3 100644 --- a/bundle.json +++ b/bundle.json @@ -34,6 +34,7 @@ "ability_runtime", "hicollie", "hilog", + "hitrace", "samgr", "cJSON", "c_utils", @@ -65,18 +66,13 @@ "header": { "header_base": "//foundation/resourceschedule/device_usage_statistics/interfaces/innerkits/include", "header_files": [ - "app_group_callback_info.h", - "app_group_callback_proxy.h", - "app_group_callback_stub.h", "bundle_active_client.h", "bundle_active_event.h", "bundle_active_event_stats.h", "bundle_active_form_record.h", "bundle_active_group_map.h", "bundle_active_module_record.h", - "bundle_active_package_stats.h", - "bundle_active_proxy.h", - "iapp_group_callback.h" + "bundle_active_package_stats.h" ] }, "name": "//foundation/resourceschedule/device_usage_statistics:usagestatsinner" diff --git a/frameworks/src/app_group_observer_napi.cpp b/frameworks/src/app_group_observer_napi.cpp index 01ad399..e3ed903 100644 --- a/frameworks/src/app_group_observer_napi.cpp +++ b/frameworks/src/app_group_observer_napi.cpp @@ -129,26 +129,26 @@ void UvQueueWorkOnAppGroupChanged(uv_work_t *work, int status) /* * observer callback when group change */ -void AppGroupObserver::OnAppGroupChanged(const AppGroupCallbackInfo &appGroupCallbackInfo) +ErrCode AppGroupObserver::OnAppGroupChanged(const AppGroupCallbackInfo &appGroupCallbackInfo) { BUNDLE_ACTIVE_LOGD("OnAppGroupChanged start"); uv_loop_s *loop = nullptr; napi_get_uv_event_loop(bundleGroupCallbackInfo_.env, &loop); if (!loop) { BUNDLE_ACTIVE_LOGE("loop instance is nullptr"); - return; + return ERR_OK; } uv_work_t* work = new (std::nothrow) uv_work_t; if (!work) { BUNDLE_ACTIVE_LOGE("work is null"); - return; + return ERR_OK; } CallbackReceiveDataWorker* callbackReceiveDataWorker = new (std::nothrow) CallbackReceiveDataWorker(); if (!callbackReceiveDataWorker) { BUNDLE_ACTIVE_LOGE("callbackReceiveDataWorker is null"); delete work; work = nullptr; - return; + return ERR_OK; } MessageParcel data; if (!appGroupCallbackInfo.Marshalling(data)) { @@ -172,6 +172,7 @@ void AppGroupObserver::OnAppGroupChanged(const AppGroupCallbackInfo &appGroupCal delete work; work = nullptr; } + return ERR_OK; } } // namespace DeviceUsageStats } // namespace OHOS \ No newline at end of file diff --git a/interfaces/innerkits/include/app_group_callback_info.h b/interfaces/innerkits/include/app_group_callback_info.h deleted file mode 100644 index 0c01151..0000000 --- a/interfaces/innerkits/include/app_group_callback_info.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef APP_GROUP_CALLBACK_INFO_H -#define APP_GROUP_CALLBACK_INFO_H - -#include - -#include "parcel.h" - -namespace OHOS { -namespace DeviceUsageStats { -class AppGroupCallbackInfo : public Parcelable { -public: - AppGroupCallbackInfo() {}; - AppGroupCallbackInfo(int32_t userId, int32_t oldGroup, int32_t newGroup, uint32_t changeReason, - std::string bundleName); - - /** - * @brief Get the user id. - * - * @return The id of user. - */ - int32_t GetUserId() const; - - /** - * @brief Get the old group. - * - * @return old group of app. - */ - int32_t GetOldGroup() const; - - /** - * @brief Get the new group. - * - * @return the new group of app. - */ - int32_t GetNewGroup() const; - - /** - * @brief Get the reason of change group. - * - * @return the reason of change group. - */ - uint32_t GetChangeReason() const; - - /** - * @brief Get the name of bundle. - * - * @return The name of bundle. - */ - std::string GetBundleName() const; - - /** - * @brief Marshals a purpose into a parcel. - * - * @param parcel Indicates the parcel object for marshalling. - * @return True if success, else false. - */ - bool Marshalling(Parcel &parcel) const; - static AppGroupCallbackInfo* Unmarshalling(Parcel &parcel); - -private: - bool ReadFromParcel(Parcel &parcel); - -private: - int32_t oldGroup_ {0}; - int32_t newGroup_ {0}; - int32_t userId_ {-1}; - uint32_t changeReason_ {0}; - std::string bundleName_ {""}; -}; -} // namespace DeviceUsageStats -} // namespace OHOS -#endif // APP_GROUP_CALLBACK_INFO_H \ No newline at end of file diff --git a/interfaces/innerkits/include/app_group_callback_proxy.h b/interfaces/innerkits/include/app_group_callback_proxy.h deleted file mode 100644 index 1de0867..0000000 --- a/interfaces/innerkits/include/app_group_callback_proxy.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef APP_GROUP_CALLBACK_PROXY_H -#define APP_GROUP_CALLBACK_PROXY_H - -#include -#include "nocopyable.h" - -#include "iremote_proxy.h" - -#include "iapp_group_callback.h" -#include "app_group_callback_info.h" - -namespace OHOS { -namespace DeviceUsageStats { -class BundleActiveGroupCallbackProxy : public IRemoteProxy { -public: - explicit BundleActiveGroupCallbackProxy(const sptr& impl); - ~BundleActiveGroupCallbackProxy() override; - DISALLOW_COPY_AND_MOVE(BundleActiveGroupCallbackProxy); - /* - * function: OnAppGroupChanged, bundleGroupChanged callback, IPC proxy, send message to stub. - * parameters: AppGroupCallbackInfo - * return: void. - */ - void OnAppGroupChanged( - const AppGroupCallbackInfo& appGroupCallbackInfo) override; - -private: - static inline BrokerDelegator delegator_; -}; -} // namespace DeviceUsageStats -} // namespace OHOS -#endif // APP_GROUP_CALLBACK_PROXY_H \ No newline at end of file diff --git a/interfaces/innerkits/include/app_group_callback_stub.h b/interfaces/innerkits/include/app_group_callback_stub.h deleted file mode 100644 index 50272de..0000000 --- a/interfaces/innerkits/include/app_group_callback_stub.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef APP_GROUP_CALLBACK_STUB_H -#define APP_GROUP_CALLBACK_STUB_H - -#include "iremote_stub.h" -#include "iapp_group_callback.h" - -namespace OHOS { -namespace DeviceUsageStats { -class AppGroupCallbackStub : public IRemoteStub { -public: - AppGroupCallbackStub()=default; - virtual ~AppGroupCallbackStub()=default; - /* - * function: OnRemoteRequest, handle message from proxy. - * parameters: code, data, reply, option - * return: errorcode. - */ - int OnRemoteRequest( - uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - /* - * function: OnAppGroupChanged, bundleGroupChanged callback, handle message from proxy. - * parameters: AppGroupCallbackInfo - * return: void. - */ - void OnAppGroupChanged(const AppGroupCallbackInfo &appGroupCallbackInfo) override; -private: - DISALLOW_COPY_AND_MOVE(AppGroupCallbackStub); -}; -} // namespace DeviceUsageStats -} // namespace OHOS -#endif // APP_GROUP_CALLBACK_STUB_H diff --git a/interfaces/innerkits/include/bundle_active_client.h b/interfaces/innerkits/include/bundle_active_client.h index 3936b80..03d19bb 100644 --- a/interfaces/innerkits/include/bundle_active_client.h +++ b/interfaces/innerkits/include/bundle_active_client.h @@ -29,6 +29,10 @@ #include "event_runner.h" #include "ffrt.h" +#include "system_ability_definition.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + namespace OHOS { namespace DeviceUsageStats { class BundleActiveClient { diff --git a/interfaces/innerkits/include/bundle_active_event.h b/interfaces/innerkits/include/bundle_active_event.h index 6e80eba..af39d1e 100644 --- a/interfaces/innerkits/include/bundle_active_event.h +++ b/interfaces/innerkits/include/bundle_active_event.h @@ -117,11 +117,11 @@ public: */ virtual bool Marshalling(Parcel &parcel) const override; /* - * function: UnMarshalling, Unmashalling event object from parcel. + * function: Unmarshalling, Unmashalling event object from parcel. * parameters: parcel * return: point to a BundleActiveEvent. */ - static std::shared_ptr UnMarshalling(Parcel &parcel); + static BundleActiveEvent *Unmarshalling(Parcel &parcel); /* * function: ToString, change event object to string. * return: string of bundlename, timestamp, eventid. diff --git a/interfaces/innerkits/include/bundle_active_event_stats.h b/interfaces/innerkits/include/bundle_active_event_stats.h index b03864f..d27d805 100644 --- a/interfaces/innerkits/include/bundle_active_event_stats.h +++ b/interfaces/innerkits/include/bundle_active_event_stats.h @@ -87,11 +87,11 @@ public: bool Marshalling(Parcel &parcel) const override; /* - * function: UnMarshalling, Unmashalling event stats object from parcel. + * function: Unmarshalling, Unmashalling event stats object from parcel. * parameters: parcel * return: point to a BundleActiveEventStats. */ - static std::shared_ptr UnMarshalling(Parcel &parcel); + static BundleActiveEventStats *Unmarshalling(Parcel &parcel); }; } // namespace DeviceUsageStats } // namespace OHOS diff --git a/interfaces/innerkits/include/bundle_active_form_record.h b/interfaces/innerkits/include/bundle_active_form_record.h index d398e36..774e225 100644 --- a/interfaces/innerkits/include/bundle_active_form_record.h +++ b/interfaces/innerkits/include/bundle_active_form_record.h @@ -89,11 +89,11 @@ public: */ bool Marshalling(Parcel &parcel) const override; /* - * function: UnMarshalling, Unmashalling record object from parcel. + * function: Unmarshalling, Unmashalling record object from parcel. * parameters: parcel * return: point to a BundleActiveFormRecord. */ - static std::shared_ptr UnMarshalling(Parcel &parcel); + static BundleActiveFormRecord *Unmarshalling(Parcel &parcel); /* * function: ToString, change form record object to string. * return: string of form name, form id, form dimension, last used time and touch count. diff --git a/interfaces/innerkits/include/bundle_active_module_record.h b/interfaces/innerkits/include/bundle_active_module_record.h index ba72469..c44c698 100644 --- a/interfaces/innerkits/include/bundle_active_module_record.h +++ b/interfaces/innerkits/include/bundle_active_module_record.h @@ -31,7 +31,7 @@ public: ~BundleActiveModuleRecord() {} static bool cmp(const BundleActiveModuleRecord& moduleRecordA, const BundleActiveModuleRecord& moduleRecordB); bool Marshalling(Parcel &parcel) const override; - static std::shared_ptr UnMarshalling(Parcel &parcel); + static BundleActiveModuleRecord *Unmarshalling(Parcel &parcel); std::string ToString(); public: diff --git a/interfaces/innerkits/include/bundle_active_package_stats.h b/interfaces/innerkits/include/bundle_active_package_stats.h index 26d37be..ee6299b 100644 --- a/interfaces/innerkits/include/bundle_active_package_stats.h +++ b/interfaces/innerkits/include/bundle_active_package_stats.h @@ -82,11 +82,11 @@ public: */ virtual bool Marshalling(Parcel &parcel) const override; /* - * function: UnMarshalling, Unmashalling BundleActivePackageStats object from parcel. + * function: Unmarshalling, Unmashalling BundleActivePackageStats object from parcel. * parameters: parcel * return: point to a BundleActivePackageStats. */ - static std::shared_ptr UnMarshalling(Parcel &parcel); + static BundleActivePackageStats *Unmarshalling(Parcel &parcel); /* * function: ToString, change module record object to string. * return: string of bundle name, last used time, total front time, last continuous task used time, diff --git a/interfaces/innerkits/include/bundle_active_proxy.h b/interfaces/innerkits/include/bundle_active_proxy.h deleted file mode 100644 index f4c077f..0000000 --- a/interfaces/innerkits/include/bundle_active_proxy.h +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef BUNDLE_ACTIVE_PROXY_H -#define BUNDLE_ACTIVE_PROXY_H - -#include "ibundle_active_service.h" -#include "bundle_active_event.h" -#include "bundle_active_event_stats.h" -#include "bundle_active_package_stats.h" -#include "bundle_active_module_record.h" -#include "bundle_state_inner_errors.h" -#include "iapp_group_callback.h" - -namespace OHOS { -namespace DeviceUsageStats { -class BundleActiveProxy : public IRemoteProxy { -public: - /* - * function: ReportEvent, used to report event. - * parameters: event, userId - * return: errorcode. - */ - ErrCode ReportEvent(BundleActiveEvent& event, const int32_t userId) override; - - /* - * function: IsBundleIdle, used to check whether specific bundle is idle. - * parameters: bundleName - * return: if bundle is idle, return true. if bundle is not idle, return false. - */ - ErrCode IsBundleIdle(bool& isBundleIdle, const std::string& bundleName, int32_t userId = -1) override; - - /* - * function: IsBundleUsePeriod, used to check whether specific bundle is use period. - * parameters: bundleName, userId. - * return: errorcode. - */ - ErrCode IsBundleUsePeriod(bool& IsUsePeriod, const std::string& bundleName, int32_t userId = -1) override; - - /* - * function: QueryBundleStatsInfoByInterval, query all usage statistics in specific time span for calling user. - * parameters: intervalType, beginTime, endTime, errCode - * return: vector of bundle usage statistics. - */ - ErrCode QueryBundleStatsInfoByInterval(std::vector& PackageStats, - const int32_t intervalType, const int64_t beginTime, const int64_t endTime, int32_t userId) override; - - /* - * function: QueryBundleEvents, query all events in specific time span for calling user. - * parameters: beginTime, endTime, errCode - * return: errorcode. - */ - ErrCode QueryBundleEvents(std::vector& bundleActiveEvents, const int64_t beginTime, - const int64_t endTime, int32_t userId) override; - - /* - * function: SetAppGroup, set specific bundle of specific user to a priority group. - * parameters: bundleName, newGroup, userId. - * return: errorcode. - */ - ErrCode SetAppGroup(const std::string& bundleName, int32_t newGroup, int32_t userId) override; - - /* - * function: QueryBundleStatsInfos, query bundle usage statistics in specific time span for calling bundle. - * parameters: intervalType, beginTime, endTime - * return: errCode. - */ - ErrCode QueryBundleStatsInfos(std::vector& bundleActivePackageStats, - const int32_t intervalType, const int64_t beginTime, const int64_t endTime) override; - - /* - * function: QueryCurrentBundleEvents, query bundle usage statistics in specific time span for calling bundle. - * parameters: beginTime, endTime - * return: errCode. - */ - ErrCode QueryCurrentBundleEvents(std::vector& bundleActiveEvents, const int64_t beginTime, - const int64_t endTime) override; - - /* - * function: QueryAppGroup, query bundle priority group calling bundle. - * return: the priority group of calling bundle. - * return: errorcode. - */ - ErrCode QueryAppGroup(int32_t& appGroup, std::string& bundleName, const int32_t userId) override; - - /* - * function: QueryModuleUsageRecords, query all from usage statistics in specific time span for calling user. - * parameters: maxNum, results, userId, default userId is -1 for JS API, - * if other SAs call this API, they should explicit define userId. - * return: errorcode. - */ - ErrCode QueryModuleUsageRecords(int32_t maxNum, std::vector& results, - int32_t userId = -1) override; - - /* - * function: QueryDeviceEventStats, query all from event stats in specific time span for calling user. - * parameters: beginTime, endTime, eventStats, userId, default userId is -1 for JS API, - * if other SAs call this API, they should explicit define userId. - * return: errorcode. - */ - ErrCode QueryDeviceEventStats(int64_t beginTime, int64_t endTime, - std::vector& eventStats, int32_t userId) override; - - /* - * function: QueryNotificationEventStats, query all app notification number in specific time span for calling user. - * parameters: beginTime, endTime, eventStats, userId, default userId is -1 for JS API, - * if other SAs call this API, they should explicit define userId. - * return: errorcode. - */ - ErrCode QueryNotificationEventStats(int64_t beginTime, int64_t endTime, - std::vector& eventStats, int32_t userId) override; - - /* - * function: BundleActiveProxy, default constructor. - * parameters: impl - */ - explicit BundleActiveProxy(const sptr& impl) - : IRemoteProxy(impl) {} - - /* - * function: RegisterAppGroupCallBack, register the observer to groupObservers. - * parameters: observer. - * return: errorcode. - */ - ErrCode RegisterAppGroupCallBack(const sptr &observer) override; - - /* - * function: UnRegisterAppGroupCallBack, remove the observer from groupObservers. - * parameters: observer. - * return: errorcode. - */ - ErrCode UnRegisterAppGroupCallBack(const sptr &observer) override; - - /* - * function: ~BundleActiveProxy, default destructor. - */ - virtual ~BundleActiveProxy() {} - -private: - static inline BrokerDelegator delegator_; - ErrCode IPCCommunication(int64_t beginTime, int64_t endTime, std::vector& eventStats, - int32_t userId, int32_t communicationFlag); -}; -} // namespace DeviceUsageStats -} // namespace OHOS -#endif // BUNDLE_ACTIVE_PROXY_H - diff --git a/interfaces/innerkits/include/iapp_group_callback.h b/interfaces/innerkits/include/iapp_group_callback.h deleted file mode 100644 index 5e281e9..0000000 --- a/interfaces/innerkits/include/iapp_group_callback.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef IAPP_GROUP_CALLBACK_H -#define IAPP_GROUP_CALLBACK_H - -#include -#include - -#include "app_group_callback_info.h" - -namespace OHOS { -namespace DeviceUsageStats { -class IAppGroupCallback : public IRemoteBroker { -public: - - /** - * @brief Called back when a app priority group change. - * - * @param appGroupCallbackInfo app group info. - */ - virtual void OnAppGroupChanged( - const AppGroupCallbackInfo &appGroupCallbackInfo) = 0; -public: - DECLARE_INTERFACE_DESCRIPTOR(u"Resourceschedule.IAppGroupCallback"); -}; -} // namespace BackgroundTaskMgr -} // namespace OHOS -#endif // IAPP_GROUP_CALLBACK_H \ No newline at end of file diff --git a/interfaces/innerkits/src/app_group_callback_proxy.cpp b/interfaces/innerkits/src/app_group_callback_proxy.cpp deleted file mode 100644 index 5772af9..0000000 --- a/interfaces/innerkits/src/app_group_callback_proxy.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "app_group_callback_proxy.h" -#include "message_parcel.h" -#include "bundle_active_log.h" -#include "errors.h" -#include "iapp_group_callback_ipc_interface_code.h" -#include "message_option.h" - -namespace OHOS { -namespace DeviceUsageStats { -BundleActiveGroupCallbackProxy::BundleActiveGroupCallbackProxy(const sptr& impl) - : IRemoteProxy(impl) {} -BundleActiveGroupCallbackProxy::~BundleActiveGroupCallbackProxy() {} - -void BundleActiveGroupCallbackProxy::OnAppGroupChanged( - const AppGroupCallbackInfo &appGroupCallbackInfo) -{ - sptr remote = Remote(); - if (remote == nullptr) { - BUNDLE_ACTIVE_LOGE("RegisterAppGroupCallBack remote is dead."); - return; - } - MessageParcel data; - if (!data.WriteInterfaceToken(BundleActiveGroupCallbackProxy::GetDescriptor())) { - BUNDLE_ACTIVE_LOGE("RegisterAppGroupCallBack write interface token failed."); - return; - } - if (!data.WriteParcelable(&appGroupCallbackInfo)) { - BUNDLE_ACTIVE_LOGE("RegisterAppGroupCallBack write parcel failed."); - return; - } - MessageParcel reply; - MessageOption option = {MessageOption::TF_ASYNC}; - int32_t ret = remote->SendRequest( - static_cast(IAppGroupCallBackInterfaceCode::ON_BUNDLE_GROUP_CHANGED), data, reply, option); - if (ret!= ERR_OK) { - BUNDLE_ACTIVE_LOGE("RegisterAppGroupCallBack SendRequest failed, error code: %{public}d", ret); - } -} -} // namespace BackgroundTaskMgr -} // namespace OHOS \ No newline at end of file diff --git a/interfaces/innerkits/src/app_group_callback_stub.cpp b/interfaces/innerkits/src/app_group_callback_stub.cpp deleted file mode 100644 index ac3602c..0000000 --- a/interfaces/innerkits/src/app_group_callback_stub.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "bundle_active_log.h" -#include "app_group_callback_stub.h" -#include "iapp_group_callback_ipc_interface_code.h" - -namespace OHOS { -namespace DeviceUsageStats { -int32_t AppGroupCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel &reply, - MessageOption &option) -{ - std::u16string descriptor = AppGroupCallbackStub::GetDescriptor(); - std::u16string remoteDescriptor = data.ReadInterfaceToken(); - if (descriptor != remoteDescriptor) { - BUNDLE_ACTIVE_LOGE("RegisterAppGroupCallBack OnRemoteRequest cannot get power mgr service"); - return -1; - } - switch (code) { - case static_cast(IAppGroupCallBackInterfaceCode::ON_BUNDLE_GROUP_CHANGED): { - std::shared_ptr groupInfo( - data.ReadParcelable()); - if (!groupInfo) { - BUNDLE_ACTIVE_LOGE("RegisterAppGroupCallBack ReadParcelable failed"); - return -1; - } - OnAppGroupChanged(*(groupInfo.get())); - groupInfo = nullptr; - break; - } - default: - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } - return ERR_OK; -} - -void AppGroupCallbackStub::OnAppGroupChanged(const AppGroupCallbackInfo &appGroupCallbackInfo) -{ -} -} // namespace DeviceUsageStats -} // namespace OHOS - diff --git a/interfaces/innerkits/src/bundle_active_event.cpp b/interfaces/innerkits/src/bundle_active_event.cpp index 88037c2..3983c8a 100644 --- a/interfaces/innerkits/src/bundle_active_event.cpp +++ b/interfaces/innerkits/src/bundle_active_event.cpp @@ -173,9 +173,9 @@ bool BundleActiveEvent::Marshalling(Parcel &parcel) const return false; } -std::shared_ptr BundleActiveEvent::UnMarshalling(Parcel &parcel) +BundleActiveEvent *BundleActiveEvent::Unmarshalling(Parcel &parcel) { - std::shared_ptr result = std::make_shared(); + BundleActiveEvent *result = new (std::nothrow) BundleActiveEvent(); result->bundleName_ = parcel.ReadString(); result->continuousTaskAbilityName_ = parcel.ReadString(); result->abilityName_ = parcel.ReadString(); diff --git a/interfaces/innerkits/src/bundle_active_event_stats.cpp b/interfaces/innerkits/src/bundle_active_event_stats.cpp index 16b649b..4850e17 100644 --- a/interfaces/innerkits/src/bundle_active_event_stats.cpp +++ b/interfaces/innerkits/src/bundle_active_event_stats.cpp @@ -102,9 +102,9 @@ bool BundleActiveEventStats::Marshalling(Parcel &parcel) const return false; } -std::shared_ptr BundleActiveEventStats::UnMarshalling(Parcel &parcel) +BundleActiveEventStats *BundleActiveEventStats::Unmarshalling(Parcel &parcel) { - std::shared_ptr result = std::make_shared(); + BundleActiveEventStats *result = new (std::nothrow) BundleActiveEventStats(); result->eventId_ = parcel.ReadInt32(); result->beginTimeStamp_ = parcel.ReadInt64(); result->endTimeStamp_ = parcel.ReadInt64(); diff --git a/interfaces/innerkits/src/bundle_active_form_record.cpp b/interfaces/innerkits/src/bundle_active_form_record.cpp index 86a3f8c..15bf981 100644 --- a/interfaces/innerkits/src/bundle_active_form_record.cpp +++ b/interfaces/innerkits/src/bundle_active_form_record.cpp @@ -71,9 +71,9 @@ bool BundleActiveFormRecord::Marshalling(Parcel &parcel) const return false; } -std::shared_ptr BundleActiveFormRecord::UnMarshalling(Parcel &parcel) +BundleActiveFormRecord *BundleActiveFormRecord::Unmarshalling(Parcel &parcel) { - std::shared_ptr result = std::make_shared(); + BundleActiveFormRecord *result = new (std::nothrow) BundleActiveFormRecord(); result->formName_ = parcel.ReadString(); result->formDimension_ = parcel.ReadInt32(); result->formId_ = parcel.ReadInt64(); diff --git a/interfaces/innerkits/src/bundle_active_module_record.cpp b/interfaces/innerkits/src/bundle_active_module_record.cpp index b466127..325c05e 100644 --- a/interfaces/innerkits/src/bundle_active_module_record.cpp +++ b/interfaces/innerkits/src/bundle_active_module_record.cpp @@ -97,9 +97,9 @@ bool BundleActiveModuleRecord::Marshalling(Parcel &parcel) const return false; } -std::shared_ptr BundleActiveModuleRecord::UnMarshalling(Parcel &parcel) +BundleActiveModuleRecord *BundleActiveModuleRecord::Unmarshalling(Parcel &parcel) { - std::shared_ptr result = std::make_shared(); + BundleActiveModuleRecord *result = new (std::nothrow) BundleActiveModuleRecord(); result->deviceId_ = parcel.ReadString(); result->bundleName_ = parcel.ReadString(); result->moduleName_ = parcel.ReadString(); @@ -116,7 +116,7 @@ std::shared_ptr BundleActiveModuleRecord::UnMarshallin if (size > MAX_FORM_NUM) { return nullptr; } - std::shared_ptr tmp = std::make_shared(); + BundleActiveFormRecord *tmp = new (std::nothrow) BundleActiveFormRecord; for (uint32_t i = 0; i < size; i++) { tmp = tmp->UnMarshalling(parcel); if (!tmp) { diff --git a/interfaces/innerkits/src/bundle_active_package_stats.cpp b/interfaces/innerkits/src/bundle_active_package_stats.cpp index b4683f8..ca7e494 100644 --- a/interfaces/innerkits/src/bundle_active_package_stats.cpp +++ b/interfaces/innerkits/src/bundle_active_package_stats.cpp @@ -221,9 +221,9 @@ bool BundleActivePackageStats::Marshalling(Parcel &parcel) const return false; } -std::shared_ptr BundleActivePackageStats::UnMarshalling(Parcel &parcel) +BundleActivePackageStats *BundleActivePackageStats::Unmarshalling(Parcel &parcel) { - std::shared_ptr result = std::make_shared(); + BundleActivePackageStats *result = new (std::nothrow) BundleActivePackageStats(); result->bundleName_ = parcel.ReadString(); result->beginTimeStamp_ = parcel.ReadInt64(); result->lastTimeUsed_ = parcel.ReadInt64(); diff --git a/interfaces/innerkits/src/bundle_active_proxy.cpp b/interfaces/innerkits/src/bundle_active_proxy.cpp deleted file mode 100644 index c82533a..0000000 --- a/interfaces/innerkits/src/bundle_active_proxy.cpp +++ /dev/null @@ -1,396 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "bundle_active_log.h" -#include "bundle_active_proxy.h" -#include "ibundle_active_service_ipc_interface_code.h" -#include - -namespace OHOS { -namespace DeviceUsageStats { - constexpr int32_t MAX_EVENT_SECOND = 4; - constexpr int32_t MAX_EVENT_WEEKLY = MAX_EVENT_SECOND * 60 * 60 * 24 * 7; - constexpr int32_t MAX_REPLY_SIZE = MAX_EVENT_WEEKLY; -ErrCode BundleActiveProxy::ReportEvent(BundleActiveEvent& event, const int32_t userId) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option = { MessageOption::TF_ASYNC }; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return ERR_PARCEL_WRITE_FALIED; - } - data.WriteInt32(userId); - event.Marshalling(data); - Remote() -> SendRequest( - static_cast(IBundleActiveServiceInterfaceCode::REPORT_EVENT), data, reply, option); - - int32_t result = reply.ReadInt32(); - return result; -} - -ErrCode BundleActiveProxy::IsBundleIdle(bool& isBundleIdle, const std::string& bundleName, int32_t userId) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor()) || - !data.WriteString(bundleName) || - !data.WriteInt32(userId)) { - return ERR_PARCEL_WRITE_FALIED; - } - Remote() -> SendRequest( - static_cast(IBundleActiveServiceInterfaceCode::IS_BUNDLE_IDLE), data, reply, option); - isBundleIdle = reply.ReadInt32(); - return reply.ReadInt32(); -} - -ErrCode BundleActiveProxy::IsBundleUsePeriod(bool& IsUsePeriod, const std::string& bundleName, int32_t userId) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor()) || - !data.WriteString(bundleName) || - !data.WriteInt32(userId)) { - return ERR_PARCEL_WRITE_FALIED; - } - Remote() -> SendRequest( - static_cast(IBundleActiveServiceInterfaceCode::IS_BUNDLE_USE_PERIOD), data, reply, option); - IsUsePeriod = reply.ReadInt32(); - return reply.ReadInt32(); -} - -ErrCode BundleActiveProxy::QueryBundleStatsInfoByInterval(std::vector& PackageStats, - const int32_t intervalType, const int64_t beginTime, const int64_t endTime, int32_t userId) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return ERR_PARCEL_WRITE_FALIED; - } - data.WriteInt32(intervalType); - data.WriteInt64(beginTime); - data.WriteInt64(endTime); - data.WriteInt32(userId); - Remote() -> SendRequest(static_cast( - IBundleActiveServiceInterfaceCode::QUERY_BUNDLE_STATS_INFO_BY_INTERVAL), data, reply, option); - ErrCode errCode = reply.ReadInt32(); - if (errCode == ERR_QUERY_RESULT_TOO_LARGE) { - return errCode; - } - int32_t size = std::min(reply.ReadInt32(), MAX_REPLY_SIZE); - std::shared_ptr tmp; - for (int32_t i = 0; i < size; i++) { - tmp = tmp->UnMarshalling(reply); - if (tmp == nullptr) { - continue; - } - PackageStats.push_back(*tmp); - } - for (uint32_t i = 0; i < PackageStats.size(); i++) { - BUNDLE_ACTIVE_LOGD("QueryBundleStatsInfoByInterval PackageStats idx is %{public}d, bundleName_ is %{public}s, " - "lastTimeUsed_ is %{public}lld, lastContiniousTaskUsed_ is %{public}lld, " - "totalInFrontTime_ is %{public}lld, totalContiniousTaskUsedTime_ is %{public}lld", - i + 1, PackageStats[i].bundleName_.c_str(), - (long long)PackageStats[i].lastTimeUsed_, (long long)PackageStats[i].lastContiniousTaskUsed_, - (long long)PackageStats[i].totalInFrontTime_, (long long)PackageStats[i].totalContiniousTaskUsedTime_); - } - return errCode; -} - -ErrCode BundleActiveProxy::QueryBundleEvents(std::vector& bundleActiveEvents, - const int64_t beginTime, const int64_t endTime, int32_t userId) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return ERR_PARCEL_WRITE_FALIED; - } - data.WriteInt64(beginTime); - data.WriteInt64(endTime); - data.WriteInt32(userId); - Remote() -> SendRequest(static_cast( - IBundleActiveServiceInterfaceCode::QUERY_BUNDLE_EVENTS), data, reply, option); - ErrCode errCode = reply.ReadInt32(); - if (errCode == ERR_QUERY_RESULT_TOO_LARGE) { - return errCode; - } - int32_t size = std::min(reply.ReadInt32(), MAX_REPLY_SIZE); - std::shared_ptr tmp; - for (int32_t i = 0; i < size; i++) { - tmp = tmp->UnMarshalling(reply); - if (tmp == nullptr) { - continue; - } - bundleActiveEvents.push_back(*tmp); - } - for (uint32_t i = 0; i < bundleActiveEvents.size(); i++) { - bundleActiveEvents[i].PrintEvent(true); - } - return errCode; -} - -ErrCode BundleActiveProxy::SetAppGroup(const std::string& bundleName, int32_t newGroup, int32_t userId) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return ERR_PARCEL_WRITE_FALIED; - } - data.WriteString(bundleName); - data.WriteInt32(newGroup); - data.WriteInt32(userId); - - Remote() -> SendRequest(static_cast( - IBundleActiveServiceInterfaceCode::SET_APP_GROUP), data, reply, option); - return reply.ReadInt32(); -} - -ErrCode BundleActiveProxy::QueryBundleStatsInfos(std::vector& bundleActivePackageStats, - const int32_t intervalType, const int64_t beginTime, const int64_t endTime) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return ERR_PARCEL_WRITE_FALIED; - } - data.WriteInt32(intervalType); - data.WriteInt64(beginTime); - data.WriteInt64(endTime); - Remote() -> SendRequest(static_cast( - IBundleActiveServiceInterfaceCode::QUERY_BUNDLE_STATS_INFOS), data, reply, option); - ErrCode errCode = reply.ReadInt32(); - if (errCode == ERR_QUERY_RESULT_TOO_LARGE) { - return errCode; - } - int32_t size = std::min(reply.ReadInt32(), MAX_REPLY_SIZE); - std::shared_ptr tmp; - for (int32_t i = 0; i < size; i++) { - tmp = tmp->UnMarshalling(reply); - if (tmp == nullptr) { - continue; - } - bundleActivePackageStats.push_back(*tmp); - } - for (uint32_t i = 0; i < bundleActivePackageStats.size(); i++) { - BUNDLE_ACTIVE_LOGD("bundleActivePackageStats idx is %{public}d, bundleName_ is %{public}s, " - "lastTimeUsed_ is %{public}lld, lastContiniousTaskUsed_ is %{public}lld, " - "totalInFrontTime_ is %{public}lld, totalContiniousTaskUsedTime_ is %{public}lld", - i + 1, bundleActivePackageStats[i].bundleName_.c_str(), - (long long)bundleActivePackageStats[i].lastTimeUsed_, - (long long)bundleActivePackageStats[i].lastContiniousTaskUsed_, - (long long)bundleActivePackageStats[i].totalInFrontTime_, - (long long)bundleActivePackageStats[i].totalContiniousTaskUsedTime_); - } - return errCode; -} - -ErrCode BundleActiveProxy::QueryCurrentBundleEvents(std::vector& bundleActiveEvents, - const int64_t beginTime, const int64_t endTime) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return ERR_PARCEL_WRITE_FALIED; - } - data.WriteInt64(beginTime); - data.WriteInt64(endTime); - Remote() -> SendRequest(static_cast( - IBundleActiveServiceInterfaceCode::QUERY_CURRENT_BUNDLE_EVENTS), data, reply, option); - ErrCode errCode = reply.ReadInt32(); - if (errCode == ERR_QUERY_RESULT_TOO_LARGE) { - return errCode; - } - int32_t size = std::min(reply.ReadInt32(), MAX_REPLY_SIZE); - std::shared_ptr tmp; - for (int32_t i = 0; i < size; i++) { - tmp = tmp->UnMarshalling(reply); - if (tmp == nullptr) { - continue; - } - bundleActiveEvents.push_back(*tmp); - } - for (uint32_t i = 0; i < bundleActiveEvents.size(); i++) { - BUNDLE_ACTIVE_LOGD("QueryCurrentBundleEvents event id is %{public}d, bundle name is %{public}s," - "time stamp is %{public}lld", bundleActiveEvents[i].eventId_, bundleActiveEvents[i].bundleName_.c_str(), - (long long)bundleActiveEvents[i].timeStamp_); - } - return errCode; -} - -ErrCode BundleActiveProxy::QueryAppGroup(int32_t& appGroup, std::string& bundleName, const int32_t userId) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(GetDescriptor())) { - return ERR_PARCEL_WRITE_FALIED; - } - - data.WriteString(bundleName); - data.WriteInt32(userId); - Remote() -> SendRequest(static_cast( - IBundleActiveServiceInterfaceCode::QUERY_APP_GROUP), data, reply, option); - appGroup = reply.ReadInt32(); - return reply.ReadInt32(); -} - -ErrCode BundleActiveProxy::QueryModuleUsageRecords(int32_t maxNum, std::vector& results, - int32_t userId) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return ERR_PARCEL_WRITE_FALIED; - } - data.WriteInt32(maxNum); - data.WriteInt32(userId); - Remote() -> SendRequest(static_cast( - IBundleActiveServiceInterfaceCode::QUERY_MODULE_USAGE_RECORDS), data, reply, option); - ErrCode errCode = reply.ReadInt32(); - if (errCode == ERR_QUERY_RESULT_TOO_LARGE) { - return errCode; - } - int32_t size = std::min(reply.ReadInt32(), MAX_REPLY_SIZE); - std::shared_ptr tmp; - for (int32_t i = 0; i < size; i++) { - tmp = tmp->UnMarshalling(reply); - if (tmp == nullptr) { - continue; - } - results.emplace_back(*tmp); - } - for (const auto& oneModule : results) { - BUNDLE_ACTIVE_LOGD("bundle name is %{public}s, module name is %{public}s, " - "lastusedtime is %{public}lld, launchcount is %{public}d", oneModule.bundleName_.c_str(), - oneModule.moduleName_.c_str(), (long long)oneModule.lastModuleUsedTime_, oneModule.launchedCount_); - for (const auto& oneForm : oneModule.formRecords_) { - BUNDLE_ACTIVE_LOGD("form name is %{public}s, form dimension is %{public}d, form id is %{public}lld, " - "lasttouchtime is %{public}lld, touchcount is %{public}d", oneForm.formName_.c_str(), - oneForm.formDimension_, (long long)oneForm.formId_, - (long long)oneForm.formLastUsedTime_, oneForm.count_); - } - } - return errCode; -} - -ErrCode BundleActiveProxy::RegisterAppGroupCallBack(const sptr &observer) -{ - if (!observer) { - BUNDLE_ACTIVE_LOGE("RegisterAppGroupCallBack observer is nullptr"); - return ERR_MEMORY_OPERATION_FAILED; - } - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - BUNDLE_ACTIVE_LOGE("RegisterAppGroupCallBack WriteInterfaceToken fail"); - return ERR_PARCEL_WRITE_FALIED; - } - if (!data.WriteRemoteObject(observer->AsObject())) { - BUNDLE_ACTIVE_LOGE("RegisterAppGroupCallBack observer write failed."); - return ERR_PARCEL_WRITE_FALIED; - } - int32_t ret = Remote()->SendRequest(static_cast( - IBundleActiveServiceInterfaceCode::REGISTER_APP_GROUP_CALLBACK), data, reply, option); - if (ret!= ERR_OK) { - BUNDLE_ACTIVE_LOGE("RegisterAppGroupCallBack SendRequest failed, error code: %{public}d", ret); - } - return reply.ReadInt32(); -} - -ErrCode BundleActiveProxy::UnRegisterAppGroupCallBack(const sptr &observer) -{ - if (!observer) { - BUNDLE_ACTIVE_LOGE("UnRegisterAppGroupCallBack observer is nullptr"); - return ERR_MEMORY_OPERATION_FAILED; - } - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return ERR_PARCEL_WRITE_FALIED; - } - if (!data.WriteRemoteObject(observer->AsObject())) { - BUNDLE_ACTIVE_LOGE("UnRegisterAppGroupCallBack observer write failed."); - return ERR_PARCEL_WRITE_FALIED; - } - Remote()->SendRequest(static_cast( - IBundleActiveServiceInterfaceCode::UNREGISTER_APP_GROUP_CALLBACK), data, reply, option); - return reply.ReadInt32(); -} - -ErrCode BundleActiveProxy::QueryDeviceEventStats(int64_t beginTime, int64_t endTime, - std::vector& eventStats, int32_t userId) -{ - ErrCode errCode = IPCCommunication(beginTime, endTime, eventStats, userId, static_cast( - IBundleActiveServiceInterfaceCode::QUERY_DEVICE_EVENT_STATES)); - for (const auto& singleEvent : eventStats) { - BUNDLE_ACTIVE_LOGD("QueryDeviceEventStats name is %{public}s, eventId is %{public}d, count is %{public}d", - singleEvent.name_.c_str(), singleEvent.eventId_, singleEvent.count_); - } - return errCode; -} - -ErrCode BundleActiveProxy::QueryNotificationEventStats(int64_t beginTime, int64_t endTime, - std::vector& eventStats, int32_t userId) -{ - ErrCode errCode = IPCCommunication(beginTime, endTime, eventStats, userId, static_cast( - IBundleActiveServiceInterfaceCode::QUERY_NOTIFICATION_NUMBER)); - for (const auto& singleEvent : eventStats) { - BUNDLE_ACTIVE_LOGD("QueryNotificationEventStats name is %{public}s, eventId is %{public}d, count is %{public}d", - singleEvent.name_.c_str(), singleEvent.eventId_, singleEvent.count_); - } - return errCode; -} - -ErrCode BundleActiveProxy::IPCCommunication(int64_t beginTime, int64_t endTime, - std::vector& eventStats, int32_t userId, int32_t communicationFlag) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return ERR_PARCEL_WRITE_FALIED; - } - data.WriteInt64(beginTime); - data.WriteInt64(endTime); - data.WriteInt32(userId); - Remote() -> SendRequest(communicationFlag, data, reply, option); - ErrCode errCode = reply.ReadInt32(); - if (errCode == ERR_QUERY_RESULT_TOO_LARGE) { - return errCode; - } - int32_t size = std::min(reply.ReadInt32(), MAX_REPLY_SIZE); - std::shared_ptr tmp; - for (int32_t i = 0; i < size; i++) { - tmp = tmp->UnMarshalling(reply); - if (!tmp) { - continue; - } - eventStats.emplace_back(*tmp); - } - return errCode; -} -} // namespace DeviceUsageStats -} // namespace OHOS - diff --git a/interfaces/kits/bundlestats/napi/include/app_group_observer_napi.h b/interfaces/kits/bundlestats/napi/include/app_group_observer_napi.h index 6950448..be2cee1 100644 --- a/interfaces/kits/bundlestats/napi/include/app_group_observer_napi.h +++ b/interfaces/kits/bundlestats/napi/include/app_group_observer_napi.h @@ -30,7 +30,7 @@ public: ~AppGroupObserver(); - void OnAppGroupChanged(const AppGroupCallbackInfo &appGroupCallbackInfo) override; + ErrCode OnAppGroupChanged(const AppGroupCallbackInfo &appGroupCallbackInfo) override; void SetCallbackInfo(const napi_env &env, const napi_ref &ref); diff --git a/libusagestatsinner.versionscript b/libusagestatsinner.versionscript index b5e4d25..9823f6a 100644 --- a/libusagestatsinner.versionscript +++ b/libusagestatsinner.versionscript @@ -14,10 +14,11 @@ 1.0 { global: *AppGroupCallbackInfo*; - *AppGroupCallbackStub*; + *AppGroupCallback*; *IAppGroupCallback*; *BundleActiveGroupCallbackProxy*; *BundleActiveClient*; + *BundleActiveService*; *BundleActiveProxy*; *IBundleActiveService*; *BundleActiveEvent*; diff --git a/services/common/include/bundle_active_service.h b/services/common/include/bundle_active_service.h index cf33fee..5d5d87a 100644 --- a/services/common/include/bundle_active_service.h +++ b/services/common/include/bundle_active_service.h @@ -20,7 +20,7 @@ #include "app_mgr_interface.h" #include "ibundle_active_service.h" -#include "bundle_active_stub.h" +#include "bundle_active_service_stub.h" #include "bundle_active_core.h" #include "bundle_active_report_handler.h" #ifdef DEVICE_USAGES_STATISTICS_POWERMANGER_ENABLE @@ -37,7 +37,7 @@ namespace OHOS { namespace DeviceUsageStats { -class BundleActiveService : public SystemAbility, public BundleActiveStub, +class BundleActiveService : public SystemAbility, public BundleActiveServiceStub, public std::enable_shared_from_this { DISALLOW_COPY_AND_MOVE(BundleActiveService); DECLARE_SYSTEM_ABILITY(BundleActiveService); @@ -59,7 +59,7 @@ public: * @param userId . * @return errCode. */ - ErrCode ReportEvent(BundleActiveEvent& event, const int32_t userId) override; + ErrCode ReportEvent(BundleActiveEvent& event, int32_t userId) override; /** * @brief IsBundleIdle, used to check whether specific bundle is idle. @@ -148,7 +148,7 @@ public: * @param userId default userId is -1 for JS API, if other SAs call this API, they should explicit define userId. * @return errCode. */ - ErrCode QueryAppGroup(int32_t& appGroup, std::string& bundleName, const int32_t userId) override; + ErrCode QueryAppGroup(int32_t& appGroup, std::string& bundleName, int32_t userId) override; /** * @brief QueryModuleUsageRecords, query all from usage statistics in specific time span for calling user. diff --git a/services/common/include/bundle_active_stub.h b/services/common/include/bundle_active_stub.h deleted file mode 100644 index 79f98be..0000000 --- a/services/common/include/bundle_active_stub.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef BUNDLE_ACTIVE_STUB_H -#define BUNDLE_ACTIVE_STUB_H - -#include -#include "ibundle_active_service.h" -#include "nocopyable.h" - -namespace OHOS { -namespace DeviceUsageStats { -class BundleActiveStub : public IRemoteStub { -public: - BundleActiveStub(bool serialInvokeFlag = true) : IRemoteStub(serialInvokeFlag) {} - ~BundleActiveStub() override = default; - DISALLOW_COPY_AND_MOVE(BundleActiveStub); - /* - * function: OnRemoteRequest, handle message from proxy. - * parameters: code, data, reply, option - * return: errorcode. - */ - int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel &reply, - MessageOption &option) override; -private: - ErrCode HandleReportEvent(MessageParcel& data, MessageParcel& reply); - ErrCode HandleIsBundleIdle(MessageParcel& data, MessageParcel& reply); - ErrCode HandleIsBundleUsePeriod(MessageParcel& data, MessageParcel& reply); - ErrCode HandleQueryBundleStatsInfoByInterval(MessageParcel& data, MessageParcel& reply); - ErrCode HandleQueryBundleEvents(MessageParcel& data, MessageParcel& reply); - ErrCode HandleQueryBundleStatsInfos(MessageParcel& data, MessageParcel& reply); - ErrCode HandleSetAppGroup(MessageParcel &data, MessageParcel &reply); - ErrCode HandleQueryCurrentBundleEvents(MessageParcel &data, MessageParcel &reply); - ErrCode HandleQueryModuleUsageRecords(MessageParcel &data, MessageParcel &reply); - ErrCode HandleQueryAppGroup(MessageParcel& data, MessageParcel& reply); - ErrCode HandleRegisterAppGroupCallBack(MessageParcel& data, MessageParcel& reply); - ErrCode HandleUnRegisterAppGroupCallBack(MessageParcel& data, MessageParcel& reply); - ErrCode HandleQueryDeviceEventStats(MessageParcel& data, MessageParcel& reply); - ErrCode HandleQueryNotificationEventStats(MessageParcel& data, MessageParcel& reply); -}; -} // namespace DeviceUsageStats -} // namespace OHOS -#endif // BUNDLE_ACTIVE_STUB_H - diff --git a/services/common/include/ibundle_active_service.h b/services/common/include/ibundle_active_service.h deleted file mode 100644 index 8a6102c..0000000 --- a/services/common/include/ibundle_active_service.h +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef BUNDLE_ACTIVE_ISERVICE_H -#define BUNDLE_ACTIVE_ISERVICE_H - -#include -#include -#include -#include -#include -#include - -#include "iremote_broker.h" -#include "iremote_stub.h" -#include "iremote_proxy.h" -#include "iremote_object.h" -#include "ipc_skeleton.h" -#include "system_ability_definition.h" -#include "if_system_ability_manager.h" -#include "iservice_registry.h" -#include "iapp_group_callback.h" -#include "app_group_callback_proxy.h" - - -namespace OHOS { -namespace DeviceUsageStats { -class BundleActivePackageStats; -class BundleActiveEvent; -class BundleActiveEventStats; -class BundleActiveModuleRecord; - -class IBundleActiveService : public IRemoteBroker { -public: - IBundleActiveService() = default; - ~IBundleActiveService() override = default; - DISALLOW_COPY_AND_MOVE(IBundleActiveService); - - /* - * function: ReportEvent, used to report event. - * parameters: event, userId - * return: errorcode. - */ - virtual ErrCode ReportEvent(BundleActiveEvent& event, const int32_t userId) = 0; - - /* - * function: IsBundleIdle, used to check whether specific bundle is idle. - * parameters: bundleName - * return: if bundle is idle, return true. if bundle is not idle, return false. - */ - virtual ErrCode IsBundleIdle(bool& isBundleIdle, const std::string& bundleName, int32_t userId) = 0; - - /* - * function: IsUsePeriod, used to check whether specific bundle is use period. - * parameters: bundleName, userId - * return: if bundle is use period, return true. if bundle is not idle, return false. - */ - virtual ErrCode IsBundleUsePeriod(bool& IsUsePeriod, const std::string& bundleName, int32_t userId) = 0; - - /* - * function: QueryBundleStatsInfoByInterval, query all usage statistics in specific time span for calling user. - * parameters: intervalType, beginTime, endTime, errCode - * return: errCode. - */ - virtual ErrCode QueryBundleStatsInfoByInterval(std::vector& PackageStats, - const int32_t intervalType, const int64_t beginTime, const int64_t endTime, int32_t userId) = 0; - - /* - * function: QueryBundleEvents, query all events in specific time span for calling user. - * parameters: beginTime, endTime, errCode - * return: errCode. - */ - virtual ErrCode QueryBundleEvents(std::vector& bundleActiveEvents, const int64_t beginTime, - const int64_t endTime, int32_t userId) = 0; - - /* - * function: QueryBundleStatsInfos, query bundle usage statistics in specific time span for calling bundle. - * parameters: intervalType, beginTime, endTime - * return: vector of calling bundle usage statistics. - */ - virtual ErrCode QueryBundleStatsInfos(std::vector& bundleActivePackageStats, - const int32_t intervalType, const int64_t beginTime, const int64_t endTime) = 0; - - /* - * function: QueryCurrentBundleEvents, query bundle usage statistics in specific time span for calling bundle. - * parameters: beginTime, endTime - * return: errCode. - */ - virtual ErrCode QueryCurrentBundleEvents(std::vector& bundleActiveEvents, - const int64_t beginTime, const int64_t endTime) = 0; - - /* - * function: QueryAppGroup, query app group by bundleName and userId. - * parameters: bundleName, userId. - * return: the priority group of calling bundle. - */ - virtual ErrCode QueryAppGroup(int32_t& appGroup, std::string& bundleName, const int32_t userId) = 0; - - /* - * function: SetAppGroup, set specific bundle of specific user to a priority group. - * parameters: bundleName, newGroup, userId - * return: errorcode. - */ - virtual ErrCode SetAppGroup(const std::string& bundleName, int32_t newGroup, int32_t userId) = 0; - - /* - * function: QueryModuleUsageRecords, query all from usage statistics in specific time span for calling user. - * parameters: maxNum, results, userId, default userId is -1 for JS API, - * if other SAs call this API, they should explicit define userId. - * return: errorcode. - */ - virtual ErrCode QueryModuleUsageRecords(int32_t maxNum, std::vector& results, - int32_t userId) = 0; - - /* - * function: RegisterAppGroupCallBack, register the observer to groupObservers. - * parameters: observer - * return: errorcode. - */ - virtual ErrCode RegisterAppGroupCallBack(const sptr &observer) = 0; - - /* - * function: UnRegisterAppGroupCallBack, remove the observer from groupObservers. - * parameters: observer - * return: errorcode. - */ - virtual ErrCode UnRegisterAppGroupCallBack(const sptr &observer) = 0; - - /* - * function: QueryDeviceEventStats, query all from event stats in specific time span for calling user. - * parameters: beginTime, endTime, eventStats, userId, default userId is -1 for JS API, - * if other SAs call this API, they should explicit define userId. - * return: errorcode. - */ - virtual ErrCode QueryDeviceEventStats(int64_t beginTime, int64_t endTime, - std::vector& eventStats, int32_t userId) = 0; - - /* - * function: QueryNotificationEventStats, query all app notification number in specific time span for calling user. - * parameters: beginTime, endTime, eventStats, userId, default userId is -1 for JS API, - * if other SAs call this API, they should explicit define userId. - * return: errorcode. - */ - virtual ErrCode QueryNotificationEventStats(int64_t beginTime, int64_t endTime, - std::vector& eventStats, int32_t userId) = 0; -public: - DECLARE_INTERFACE_DESCRIPTOR(u"Resourceschedule.IBundleActiveService"); -}; -} // namespace DeviceUsageStats -} // namespace OHOS -#endif // BUNDLE_ACTIVE_ISERVICE_H - diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index d9203ca..ab4fb48 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -243,7 +243,7 @@ void BundleActiveService::OnStop() ready_ = false; } -ErrCode BundleActiveService::ReportEvent(BundleActiveEvent& event, const int32_t userId) +ErrCode BundleActiveService::ReportEvent(BundleActiveEvent& event, int32_t userId) { AccessToken::AccessTokenID tokenId = OHOS::IPCSkeleton::GetCallingTokenID(); if (CheckNativePermission(tokenId) == ERR_OK) { diff --git a/services/packageusage/include/bundle_active_period_stats.h b/services/packageusage/include/bundle_active_period_stats.h index ca7bee2..804b510 100644 --- a/services/packageusage/include/bundle_active_period_stats.h +++ b/services/packageusage/include/bundle_active_period_stats.h @@ -17,6 +17,7 @@ #define BUNDLE_ACTIVE_PERIOD_STATS_H #include +#include #include "ibundle_active_service.h" #include "bundle_active_event.h" diff --git a/services/packageusage/include/bundle_active_stats_combiner.h b/services/packageusage/include/bundle_active_stats_combiner.h index 1299cb0..4ff2833 100644 --- a/services/packageusage/include/bundle_active_stats_combiner.h +++ b/services/packageusage/include/bundle_active_stats_combiner.h @@ -16,6 +16,7 @@ #ifndef BUNDLE_ACTIVE_STATS_COMBINER_H #define BUNDLE_ACTIVE_STATS_COMBINER_H +#include #include #include "bundle_active_period_stats.h" diff --git a/test/fuzztest/appgroupcallbackstub_fuzzer/appgroupcallbackstub_fuzzer.cpp b/test/fuzztest/appgroupcallbackstub_fuzzer/appgroupcallbackstub_fuzzer.cpp index 5395f83..95b0378 100644 --- a/test/fuzztest/appgroupcallbackstub_fuzzer/appgroupcallbackstub_fuzzer.cpp +++ b/test/fuzztest/appgroupcallbackstub_fuzzer/appgroupcallbackstub_fuzzer.cpp @@ -32,6 +32,17 @@ namespace DeviceUsageStats { constexpr uint8_t TWO = 2; constexpr uint8_t THREE = 3; const std::u16string APP_GOUNP_ACTIVE_TOKEN = u"Resourceschedule.IAppGroupCallback"; + + class TestAppGroupCallback : public AppGroupCallbackStub { + public: + ErrCode OnAppGroupChanged(const AppGroupCallbackInfo &appGroupCallbackInfo) override; + }; + + ErrCode TestAppGroupChangeCallback::OnAppGroupChanged(const AppGroupCallbackInfo &appGroupCallbackInfo) + { + return ERR_OK; + } + uint32_t GetU32Data(const char* ptr) { return (ptr[0] << TWENTYFOUR) | (ptr[1] << SIXTEEN) | (ptr[TWO] << EIGHT) | (ptr[THREE]); @@ -47,7 +58,7 @@ namespace DeviceUsageStats { datas.RewindRead(0); MessageParcel reply; MessageOption option; - DelayedSingleton::GetInstance()->OnRemoteRequest(code % MAX_CODE, datas, reply, option); + DelayedSingleton::GetInstance()->OnRemoteRequest(code % MAX_CODE, datas, reply, option); return true; } } // namespace DeviceUsageStats diff --git a/test/unittest/bundle_active_total_test.cpp b/test/unittest/bundle_active_total_test.cpp index bda6776..aa085a1 100644 --- a/test/unittest/bundle_active_total_test.cpp +++ b/test/unittest/bundle_active_total_test.cpp @@ -20,7 +20,7 @@ #include "bundle_active_power_state_callback_service.h" #include "bundle_active_power_state_callback_service.h" -#include "bundle_active_stub.h" +#include "bundle_active_service_stub.h" #include "bundle_active_core.h" #include "bundle_active_continuous_task_observer.h" #include "bundle_active_bundle_mgr_helper.h" diff --git a/test/unittest/device_usage_statistics_multi_test.cpp b/test/unittest/device_usage_statistics_multi_test.cpp index 2c37a5e..2bb99fa 100644 --- a/test/unittest/device_usage_statistics_multi_test.cpp +++ b/test/unittest/device_usage_statistics_multi_test.cpp @@ -104,10 +104,10 @@ void DeviceUsageStatisticsMultiTest::TearDown(void) class TestAppGroupChangeCallback : public AppGroupCallbackStub { public: - void OnAppGroupChanged(const AppGroupCallbackInfo &appGroupCallbackInfo) override; + ErrCode OnAppGroupChanged(const AppGroupCallbackInfo &appGroupCallbackInfo) override; }; -void TestAppGroupChangeCallback::OnAppGroupChanged(const AppGroupCallbackInfo &appGroupCallbackInfo) +ErrCode TestAppGroupChangeCallback::OnAppGroupChanged(const AppGroupCallbackInfo &appGroupCallbackInfo) { BUNDLE_ACTIVE_LOGI("TestAppGroupChangeCallback::OnAppGroupChanged!"); MessageParcel data; @@ -115,6 +115,7 @@ void TestAppGroupChangeCallback::OnAppGroupChanged(const AppGroupCallbackInfo &a BUNDLE_ACTIVE_LOGE("Marshalling fail"); } appGroupCallbackInfo.Unmarshalling(data); + return ERR_OK; } /* diff --git a/test/unittest/device_usage_statistics_service_test.cpp b/test/unittest/device_usage_statistics_service_test.cpp index f45ba49..ccc3728 100644 --- a/test/unittest/device_usage_statistics_service_test.cpp +++ b/test/unittest/device_usage_statistics_service_test.cpp @@ -92,12 +92,13 @@ void DeviceUsageStatisticsServiceTest::TearDown(void) class TestServiceAppGroupChangeCallback : public AppGroupCallbackStub { public: - void OnAppGroupChanged(const AppGroupCallbackInfo &appGroupCallbackInfo) override; + ErrCode OnAppGroupChanged(const AppGroupCallbackInfo &appGroupCallbackInfo) override; }; -void TestServiceAppGroupChangeCallback::OnAppGroupChanged(const AppGroupCallbackInfo &appGroupCallbackInfo) +ErrCode TestServiceAppGroupChangeCallback::OnAppGroupChanged(const AppGroupCallbackInfo &appGroupCallbackInfo) { BUNDLE_ACTIVE_LOGI("TestServiceAppGroupChangeCallback::OnAppGroupChanged!"); + return ERR_OK; } /* diff --git a/test/unittest/device_usage_statistics_test.cpp b/test/unittest/device_usage_statistics_test.cpp index 20783e9..86b1e7c 100644 --- a/test/unittest/device_usage_statistics_test.cpp +++ b/test/unittest/device_usage_statistics_test.cpp @@ -99,10 +99,12 @@ void DeviceUsageStatisticsTest::TearDown(void) class TestAppGroupChangeCallback : public AppGroupCallbackStub { public: - void OnAppGroupChanged(const AppGroupCallbackInfo &appGroupCallbackInfo) override; + TestAppGroupChangeCallback() = default; + virtual ~TestAppGroupChangeCallback() = default; + ErrCode OnAppGroupChanged(const AppGroupCallbackInfo &appGroupCallbackInfo) override; }; -void TestAppGroupChangeCallback::OnAppGroupChanged(const AppGroupCallbackInfo &appGroupCallbackInfo) +ErrCode TestAppGroupChangeCallback::OnAppGroupChanged(const AppGroupCallbackInfo &appGroupCallbackInfo) { BUNDLE_ACTIVE_LOGI("TestAppGroupChangeCallback::OnAppGroupChanged!"); MessageParcel data; @@ -110,6 +112,7 @@ void TestAppGroupChangeCallback::OnAppGroupChanged(const AppGroupCallbackInfo &a BUNDLE_ACTIVE_LOGE("Marshalling fail"); } appGroupCallbackInfo.Unmarshalling(data); + return ERR_OK; } /* @@ -454,12 +457,12 @@ HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_BundleActiveEventS MessageParcel data; EXPECT_TRUE(bundleActiveEventStats->Marshalling(data)); - auto tempEventStats = bundleActiveEventStats->UnMarshalling(data); + auto tempEventStats = bundleActiveEventStats->Unmarshalling(data); EXPECT_TRUE(tempEventStats != nullptr); auto bundleActiveEvent = std::make_shared(); EXPECT_TRUE(bundleActiveEvent->Marshalling(data)); - auto tempEvent = bundleActiveEvent->UnMarshalling(data); + auto tempEvent = bundleActiveEvent->Unmarshalling(data); EXPECT_TRUE(tempEvent != nullptr); EXPECT_EQ(tempEventStats->GetEventId(), g_commonUserid); @@ -483,7 +486,7 @@ HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_FormRecord_001, Fu MessageParcel data; EXPECT_TRUE(bundleActiveFormRecord->Marshalling(data)); - EXPECT_TRUE(bundleActiveFormRecord->UnMarshalling(data) != nullptr); + EXPECT_TRUE(bundleActiveFormRecord->Unmarshalling(data) != nullptr); BundleActiveFormRecord bundleActiveFormRecordA; bundleActiveFormRecordA.count_ = 2; @@ -520,7 +523,7 @@ HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_PackageStats_001, MessageParcel data; EXPECT_TRUE(bundleActivePackageStats->Marshalling(data)); - EXPECT_TRUE(bundleActivePackageStats->UnMarshalling(data) != nullptr); + EXPECT_TRUE(bundleActivePackageStats->Unmarshalling(data) != nullptr); } /* @@ -536,7 +539,7 @@ HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_ModuleRecord_001, MessageParcel data; EXPECT_TRUE(bundleActiveModuleRecord->Marshalling(data)); - EXPECT_TRUE(bundleActiveModuleRecord->UnMarshalling(data) != nullptr); + EXPECT_TRUE(bundleActiveModuleRecord->Unmarshalling(data) != nullptr); BundleActiveModuleRecord bundleActiveModuleRecordA; bundleActiveModuleRecordA.lastModuleUsedTime_ = 2; @@ -563,7 +566,7 @@ HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_AppGroupCallbackPr uint32_t changeReason = 1; AppGroupCallbackInfo appGroupCallbackInfo(g_commonUserid, oldGroup, newGroup, changeReason, g_defaultBundleName); - auto appGroupCallbackProxy = std::make_shared(nullptr); + auto appGroupCallbackProxy = std::make_shared(nullptr); appGroupCallbackProxy->OnAppGroupChanged(appGroupCallbackInfo); EXPECT_NE(appGroupCallbackProxy, nullptr); } @@ -581,7 +584,7 @@ HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_AppGroupCallbackSt uint32_t changeReason = 1; AppGroupCallbackInfo appGroupCallbackInfo(g_commonUserid, oldGroup, newGroup, changeReason, g_defaultBundleName); - auto appGroupCallbackStub = std::make_shared(); + auto appGroupCallbackStub = std::make_shared(); appGroupCallbackStub->OnAppGroupChanged(appGroupCallbackInfo); MessageParcel data1; MessageParcel reply; -- Gitee