diff --git a/bundle.json b/bundle.json index 95085d8e4ee3dc4da8eab12f019ea402859c5a70..e8c741ffc7b42613c01183c00fdc9d87931ce9bc 100644 --- a/bundle.json +++ b/bundle.json @@ -24,7 +24,7 @@ "deps": { "components": [ "relational_store", - "safwk", + "safwk", "config_policy", "os_account", "ipc", diff --git a/interfaces/test/unittest/device_usage_statistics_jsunittest/BUILD.gn b/interfaces/test/unittest/device_usage_statistics_jsunittest/BUILD.gn index 2bbb48c7d8bbcd370077a8774cf3ecc0aa78a365..c505e9abe098b22865f17964b992bd5331fe5b37 100644 --- a/interfaces/test/unittest/device_usage_statistics_jsunittest/BUILD.gn +++ b/interfaces/test/unittest/device_usage_statistics_jsunittest/BUILD.gn @@ -12,8 +12,7 @@ # limitations under the License. import("//build/test.gni") -module_output_path = - "device_usage_statistics/device_usage_statistics/interfaces" +module_output_path = "device_usage_statistics/interfaces" ohos_js_unittest("DeviceUsageStatisticsJsTest") { module_out_path = module_output_path diff --git a/services/common/include/bundle_active_usage_database.h b/services/common/include/bundle_active_usage_database.h index 41123f45a36e259a46c80f2d5633dd3b9ae34734..891cf78aa2e21896bfeb194eb57a516f9c5c191a 100644 --- a/services/common/include/bundle_active_usage_database.h +++ b/services/common/include/bundle_active_usage_database.h @@ -140,11 +140,11 @@ private: void SupportAppTwin(); void AddRdbColumn(const std::shared_ptr store, const std::string& tableName, const std::string& columnName, const std::string& columnType); + void CheckDatabaseFileAndTable(); std::vector databaseFiles_; std::vector> sortedTableArray_; std::map> bundleActiveRdbStoreCache_; std::shared_ptr calendar_; - void CheckDatabaseFileAndTable(); std::string eventTableName_; std::string durationTableName_; std::string bundleHistoryTableName_; diff --git a/services/common/src/bundle_active_stub.cpp b/services/common/src/bundle_active_stub.cpp deleted file mode 100644 index d06a935f0ff9a958debc437f97bb6c5038a5957c..0000000000000000000000000000000000000000 --- a/services/common/src/bundle_active_stub.cpp +++ /dev/null @@ -1,322 +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_stub.h" - -#include "ipc_object_stub.h" -#include "iremote_broker.h" - -#include "bundle_active_event.h" -#include "bundle_active_event_stats.h" -#include "bundle_state_inner_errors.h" -#include "bundle_active_log.h" -#include "bundle_active_module_record.h" -#include "bundle_active_package_stats.h" -#include "iapp_group_callback.h" -#include "ibundle_active_service_ipc_interface_code.h" - -namespace OHOS { -namespace DeviceUsageStats { -namespace { - constexpr int32_t EVENT_MAX_SIZE = 100000; - constexpr int32_t PACKAGE_MAX_SIZE = 1000; -} - -int32_t BundleActiveStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel &reply, - MessageOption &option) -{ - if (data.ReadInterfaceToken() != GetDescriptor()) { - return -1; - } - switch (code) { - case static_cast(IBundleActiveServiceInterfaceCode::REPORT_EVENT): - return HandleReportEvent(data, reply); - case static_cast(IBundleActiveServiceInterfaceCode::IS_BUNDLE_IDLE): - return HandleIsBundleIdle(data, reply); - case static_cast(IBundleActiveServiceInterfaceCode::QUERY_BUNDLE_STATS_INFO_BY_INTERVAL): - return HandleQueryBundleStatsInfoByInterval(data, reply); - case static_cast(IBundleActiveServiceInterfaceCode::QUERY_BUNDLE_EVENTS): - return HandleQueryBundleEvents(data, reply); - case static_cast(IBundleActiveServiceInterfaceCode::SET_APP_GROUP): - return HandleSetAppGroup(data, reply); - case static_cast(IBundleActiveServiceInterfaceCode::QUERY_BUNDLE_STATS_INFOS): - return HandleQueryBundleStatsInfos(data, reply); - case static_cast(IBundleActiveServiceInterfaceCode::QUERY_CURRENT_BUNDLE_EVENTS): - return HandleQueryCurrentBundleEvents(data, reply); - case static_cast(IBundleActiveServiceInterfaceCode::QUERY_APP_GROUP): - return HandleQueryAppGroup(data, reply); - case static_cast(IBundleActiveServiceInterfaceCode::QUERY_MODULE_USAGE_RECORDS): - return HandleQueryModuleUsageRecords(data, reply); - case static_cast(IBundleActiveServiceInterfaceCode::REGISTER_APP_GROUP_CALLBACK): - return HandleRegisterAppGroupCallBack(data, reply); - case static_cast(IBundleActiveServiceInterfaceCode::UNREGISTER_APP_GROUP_CALLBACK): - return HandleUnRegisterAppGroupCallBack(data, reply); - case static_cast(IBundleActiveServiceInterfaceCode::QUERY_DEVICE_EVENT_STATES): - return HandleQueryDeviceEventStats(data, reply); - case static_cast(IBundleActiveServiceInterfaceCode::QUERY_NOTIFICATION_NUMBER): - return HandleQueryNotificationEventStats(data, reply); - case static_cast(IBundleActiveServiceInterfaceCode::IS_BUNDLE_USE_PERIOD): - return HandleIsBundleUsePeriod(data, reply); - default: - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } - return ERR_OK; -} - -ErrCode BundleActiveStub::HandleReportEvent(MessageParcel& data, MessageParcel& reply) -{ - int32_t userId = data.ReadInt32(); - std::shared_ptr tmpEvent = BundleActiveEvent::UnMarshalling(data); - if (!tmpEvent) { - return -1; - } - int32_t result = ReportEvent(*tmpEvent, userId); - return reply.WriteInt32(result); -} - -ErrCode BundleActiveStub::HandleIsBundleIdle(MessageParcel& data, MessageParcel& reply) -{ - bool isBundleIdle = false; - std::string bundleName = data.ReadString(); - int32_t userId = data.ReadInt32(); - ErrCode errCode = IsBundleIdle(isBundleIdle, bundleName, userId); - reply.WriteInt32(isBundleIdle); - return reply.WriteInt32(errCode); -} - -ErrCode BundleActiveStub::HandleIsBundleUsePeriod(MessageParcel& data, MessageParcel& reply) -{ - bool IsUsePeriod = false; - std::string bundleName = data.ReadString(); - int32_t userId = data.ReadInt32(); - ErrCode errCode = IsBundleUsePeriod(IsUsePeriod, bundleName, userId); - reply.WriteInt32(IsUsePeriod); - return reply.WriteInt32(errCode); -} - -ErrCode BundleActiveStub::HandleQueryBundleStatsInfoByInterval(MessageParcel& data, MessageParcel& reply) -{ - std::vector result; - int32_t intervalType = data.ReadInt32(); - BUNDLE_ACTIVE_LOGI("OnRemoteRequest intervaltype is %{public}d", intervalType); - int64_t beginTime = data.ReadInt64(); - int64_t endTime = data.ReadInt64(); - int32_t userId = data.ReadInt32(); - ErrCode errCode = QueryBundleStatsInfoByInterval(result, intervalType, beginTime, endTime, userId); - int32_t size = static_cast(result.size()); - if (size > PACKAGE_MAX_SIZE) { - errCode = ERR_QUERY_RESULT_TOO_LARGE; - reply.WriteInt32(errCode); - return -1; - } - BUNDLE_ACTIVE_LOGI("OnRemoteRequest result size is %{public}d", size); - reply.WriteInt32(errCode); - reply.WriteInt32(size); - for (int32_t i = 0; i < size; i++) { - bool tmp = result[i].Marshalling(reply); - if (tmp == false) { - return 1; - } - } - return size == 0; -} - -ErrCode BundleActiveStub::HandleQueryBundleEvents(MessageParcel& data, MessageParcel& reply) -{ - std::vector result; - int64_t beginTime = data.ReadInt64(); - int64_t endTime = data.ReadInt64(); - int32_t userId = data.ReadInt32(); - ErrCode errCode = QueryBundleEvents(result, beginTime, endTime, userId); - int32_t size = static_cast(result.size()); - if (size > EVENT_MAX_SIZE) { - errCode = ERR_QUERY_RESULT_TOO_LARGE; - reply.WriteInt32(errCode); - return -1; - } - reply.WriteInt32(errCode); - reply.WriteInt32(size); - for (int32_t i = 0; i < size; i++) { - bool tmp = result[i].Marshalling(reply); - if (tmp == false) { - return 1; - } - } - return size == 0; -} - -ErrCode BundleActiveStub::HandleQueryBundleStatsInfos(MessageParcel& data, MessageParcel& reply) -{ - std::vector result; - int32_t intervalType = data.ReadInt32(); - BUNDLE_ACTIVE_LOGI("OnRemoteRequest QUERY_BUNDLE_STATS_INFOS intervaltype is %{public}d", intervalType); - int64_t beginTime = data.ReadInt64(); - int64_t endTime = data.ReadInt64(); - ErrCode errCode = QueryBundleStatsInfos(result, intervalType, beginTime, endTime); - int32_t size = static_cast(result.size()); - if (size > PACKAGE_MAX_SIZE) { - errCode = ERR_QUERY_RESULT_TOO_LARGE; - reply.WriteInt32(errCode); - return -1; - } - BUNDLE_ACTIVE_LOGI("OnRemoteRequest QUERY_BUNDLE_STATS_INFOS result size is %{public}d", size); - reply.WriteInt32(errCode); - reply.WriteInt32(size); - for (int32_t i = 0; i < size; i++) { - bool tmp = result[i].Marshalling(reply); - if (tmp == false) { - return 1; - } - } - return size == 0; -} -ErrCode BundleActiveStub::HandleSetAppGroup(MessageParcel &data, MessageParcel &reply) -{ - std::string bundleName = data.ReadString(); - int32_t newGroup = data.ReadInt32(); - int32_t userId = data.ReadInt32(); - ErrCode errCode = SetAppGroup(bundleName, newGroup, userId); - return reply.WriteInt32(errCode); -} - -ErrCode BundleActiveStub::HandleQueryCurrentBundleEvents(MessageParcel &data, MessageParcel &reply) -{ - std::vector result; - int64_t beginTime = data.ReadInt64(); - int64_t endTime = data.ReadInt64(); - ErrCode errCode = QueryCurrentBundleEvents(result, beginTime, endTime); - int32_t size = static_cast(result.size()); - if (size > EVENT_MAX_SIZE) { - errCode = ERR_QUERY_RESULT_TOO_LARGE; - reply.WriteInt32(errCode); - return -1; - } - reply.WriteInt32(errCode); - reply.WriteInt32(size); - for (int32_t i = 0; i < size; i++) { - bool tmp = result[i].Marshalling(reply); - if (tmp == false) { - return 1; - } - } - return size == 0; -} - -ErrCode BundleActiveStub::HandleQueryModuleUsageRecords(MessageParcel &data, MessageParcel &reply) -{ - std::vector results; - int32_t maxNum = data.ReadInt32(); - int32_t userId = data.ReadInt32(); - ErrCode errCode = QueryModuleUsageRecords(maxNum, results, userId); - int32_t size = static_cast(results.size()); - if (size > PACKAGE_MAX_SIZE) { - errCode = ERR_QUERY_RESULT_TOO_LARGE; - reply.WriteInt32(errCode); - return -1; - } - reply.WriteInt32(errCode); - reply.WriteInt32(size); - for (int32_t i = 0; i < size; i++) { - bool tmp = results[i].Marshalling(reply); - if (tmp == false) { - return 1; - } - } - return size == 0; -} - -ErrCode BundleActiveStub::HandleQueryAppGroup(MessageParcel& data, MessageParcel& reply) -{ - int32_t appGroup = -1; - std::string bundleName = data.ReadString(); - int32_t userId = data.ReadInt32(); - ErrCode errCode = QueryAppGroup(appGroup, bundleName, userId); - reply.WriteInt32(appGroup); - return reply.WriteInt32(errCode); -} - -ErrCode BundleActiveStub::HandleRegisterAppGroupCallBack(MessageParcel& data, MessageParcel& reply) -{ - auto observer = iface_cast(data.ReadRemoteObject()); - if (!observer) { - BUNDLE_ACTIVE_LOGE("RegisterAppGroupCallBack observer is null, return"); - return false; - } - BUNDLE_ACTIVE_LOGI("RegisterAppGroupCallBack observer is ok"); - ErrCode errCode = RegisterAppGroupCallBack(observer); - return reply.WriteInt32(errCode); -} - -ErrCode BundleActiveStub::HandleUnRegisterAppGroupCallBack(MessageParcel& data, MessageParcel& reply) -{ - auto observer = iface_cast(data.ReadRemoteObject()); - if (!observer) { - BUNDLE_ACTIVE_LOGE("UnRegisterAppGroupCallBack observer is null, return"); - return false; - } - ErrCode errCode = UnRegisterAppGroupCallBack(observer); - return reply.WriteInt32(errCode); -} - -ErrCode BundleActiveStub::HandleQueryDeviceEventStats(MessageParcel& data, MessageParcel& reply) -{ - std::vector result; - int64_t beginTime = data.ReadInt64(); - int64_t endTime = data.ReadInt64(); - int32_t userId = data.ReadInt32(); - ErrCode errCode = QueryDeviceEventStats(beginTime, endTime, result, userId); - int32_t size = static_cast(result.size()); - if (size > EVENT_MAX_SIZE) { - errCode = ERR_QUERY_RESULT_TOO_LARGE; - reply.WriteInt32(errCode); - return -1; - } - reply.WriteInt32(errCode); - reply.WriteInt32(size); - for (int32_t i = 0; i < size; i++) { - bool tmp = result[i].Marshalling(reply); - if (!tmp) { - return 1; - } - } - return size == 0; -} - -ErrCode BundleActiveStub::HandleQueryNotificationEventStats(MessageParcel& data, MessageParcel& reply) -{ - std::vector result; - int64_t beginTime = data.ReadInt64(); - int64_t endTime = data.ReadInt64(); - int32_t userId = data.ReadInt32(); - ErrCode errCode = QueryNotificationEventStats(beginTime, endTime, result, userId); - int32_t size = static_cast(result.size()); - if (size > PACKAGE_MAX_SIZE) { - errCode = ERR_QUERY_RESULT_TOO_LARGE; - reply.WriteInt32(errCode); - return -1; - } - reply.WriteInt32(errCode); - reply.WriteInt32(size); - for (int32_t i = 0; i < size; i++) { - bool tmp = result[i].Marshalling(reply); - if (!tmp) { - return 1; - } - } - return size == 0; -} -} // namespace DeviceUsageStats -} // namespace OHOS - diff --git a/services/packagegroup/src/bundle_active_group_controller.cpp b/services/packagegroup/src/bundle_active_group_controller.cpp index 3ce28c47ff41c80ef0197d45eae2d102c6894a47..05100247f46e11296825c16017dd3bad00dfffd0 100644 --- a/services/packagegroup/src/bundle_active_group_controller.cpp +++ b/services/packagegroup/src/bundle_active_group_controller.cpp @@ -79,7 +79,6 @@ void BundleActiveGroupController::OnUserSwitched(const int32_t userId, const int CheckEachBundleState(currentUsedUser); bundleUserHistory_->WriteBundleUsage(currentUsedUser); std::lock_guard lock(mutex_); - auto activeGroupHandler = activeGroupHandler_.lock(); if (!activeGroupHandler_.expired()) { activeGroupHandler_.lock()->RemoveEvent(BundleActiveGroupHandler::MSG_CHECK_IDLE_STATE); activeGroupHandler_.lock()->RemoveEvent(BundleActiveGroupHandler::MSG_CHECK_DEFAULT_BUNDLE_STATE); diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 39bb926b8fd89e5692dc340e830fdb09b6045223..0afae0ae51e7032fa0c1f40a666b8d6caf888e6d 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -13,8 +13,7 @@ import("//build/test.gni") import("../../device_usage_statistics.gni") -module_output_path = - "device_usage_statistics/device_usage_statistics/deviceusagestatisticstest" +module_output_path = "device_usage_statistics/device_usage_statistics/deviceusagestatisticstest" config("module_private_config") { visibility = [ ":*" ] diff --git a/test/unittest/bundle_active_total_test.cpp b/test/unittest/bundle_active_total_test.cpp index 3f8c01e789a49646a10d05fbd3abb113864192e1..9b3eec4662fd605cbb750ecd3ae7ff874ca675b3 100644 --- a/test/unittest/bundle_active_total_test.cpp +++ b/test/unittest/bundle_active_total_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 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 @@ -18,7 +18,6 @@ #include #include "system_ability_definition.h" -#include "bundle_active_power_state_callback_service.h" #include "bundle_active_power_state_callback_service.h" #include "bundle_active_service_stub.h" #include "bundle_active_core.h"