diff --git a/BUILD.gn b/BUILD.gn index 7a444088955600f2219d4f9972ac6e37736e15b9..cf37d4bd1a33e1a6aee7b57d512f276d010cdd1d 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -41,6 +41,9 @@ ohos_shared_library("usagestatsinner") { "samgr_standard:samgr_proxy", "utils_base:utils", ] + + deps = [ ":usagestatservice" ] + part_name = "${device_usage_statistics_part_name}" subsystem_name = "resourceschedule" } @@ -65,7 +68,10 @@ ohos_shared_library("bundlestate") { "services/packageusage/include", ] - deps = [ "//foundation/resourceschedule/${device_usage_statistics_part_name}:usagestatsinner" ] + deps = [ + ":usagestatservice", + ":usagestatsinner", + ] external_deps = [ "dmsfwk_standard:zuri", @@ -87,6 +93,7 @@ ohos_shared_library("usagestatservice") { "services/common/src/bundle_active_binary_search.cpp", "services/common/src/bundle_active_continuous_task_observer.cpp", "services/common/src/bundle_active_core.cpp", + "services/common/src/bundle_active_log.cpp", "services/common/src/bundle_active_open_callback.cpp", "services/common/src/bundle_active_service.cpp", "services/common/src/bundle_active_shutdown_callback_proxy.cpp", diff --git a/frameworks/src/bundle_state_common.cpp b/frameworks/src/bundle_state_common.cpp index b4908dca75b80f353ca56e4c4cb8e3d0ef00ba73..525b3d362aad8e2b8c7ff0e9a632879e5ffe7149 100644 --- a/frameworks/src/bundle_state_common.cpp +++ b/frameworks/src/bundle_state_common.cpp @@ -109,28 +109,28 @@ void BundleStateCommon::GetBundleStateInfoByIntervalForResult( } } -void BundleStateCommon::GetBundleStateInfoForResult( - napi_env env, const std::vector &packageStats, napi_value result) +void BundleStateCommon::GetBundleStateInfoForResult(napi_env env, + const std::shared_ptr> &packageStats, napi_value result) { - for (const auto &item : packageStats) { + for (const auto &item : *packageStats) { napi_value packageObject = nullptr; NAPI_CALL_RETURN_VOID(env, napi_create_object(env, &packageObject)); napi_value bundleName = nullptr; NAPI_CALL_RETURN_VOID( - env, napi_create_string_utf8(env, item.bundleName_.c_str(), NAPI_AUTO_LENGTH, &bundleName)); + env, napi_create_string_utf8(env, item.second.bundleName_.c_str(), NAPI_AUTO_LENGTH, &bundleName)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, packageObject, "bundleName", bundleName)); napi_value abilityPrevAccessTime = nullptr; - NAPI_CALL_RETURN_VOID(env, napi_create_int64(env, item.lastTimeUsed_, &abilityPrevAccessTime)); + NAPI_CALL_RETURN_VOID(env, napi_create_int64(env, item.second.lastTimeUsed_, &abilityPrevAccessTime)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, packageObject, "abilityPrevAccessTime", abilityPrevAccessTime)); napi_value abilityInFgTotalTime = nullptr; - NAPI_CALL_RETURN_VOID(env, napi_create_int64(env, item.totalInFrontTime_, &abilityInFgTotalTime)); + NAPI_CALL_RETURN_VOID(env, napi_create_int64(env, item.second.totalInFrontTime_, &abilityInFgTotalTime)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, packageObject, "abilityInFgTotalTime", abilityInFgTotalTime)); - NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, item.bundleName_.c_str(), packageObject)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, result, item.first.c_str(), packageObject)); } } @@ -236,5 +236,42 @@ void BundleStateCommon::SettingCallbackPromiseInfo( info.isCallback = false; } } + +std::shared_ptr> BundleStateCommon::GetPackageStats( + int64_t &beginTime, int64_t &endTime) +{ + std::vector packageStats = + BundleActiveClient::GetInstance().QueryPackageStats(INTERVAL_TYPE_DEFAULT, beginTime, endTime); + std::shared_ptr> mergedPackageStats = + std::make_shared>(); + if (packageStats.empty()) { + return nullptr; + } + for (auto packageStat : packageStats) { + std::map::iterator iter = + mergedPackageStats->find(packageStat.bundleName_); + if (iter != mergedPackageStats->end()) { + MergePackageStats(iter->second, packageStat); + } else { + mergedPackageStats-> + insert(std::pair(packageStat.bundleName_, packageStat)); + } + } + return mergedPackageStats; +} + +void BundleStateCommon::MergePackageStats(BundleActivePackageStats &left, const BundleActivePackageStats &right) +{ + if (left.bundleName_ != right.bundleName_) { + BUNDLE_ACTIVE_LOGE("Merge package stats failed, existing packageName : %{public}s," + " new packageName : %{public}s,", left.bundleName_.c_str(), right.bundleName_.c_str()); + return; + } + left.lastTimeUsed_ = std::max(left.lastTimeUsed_, right.lastTimeUsed_); + left.lastContiniousTaskUsed_ = std::max(left.lastContiniousTaskUsed_, right.lastContiniousTaskUsed_); + left.totalInFrontTime_ += right.totalInFrontTime_; + left.totalContiniousTaskUsedTime_ += right.totalContiniousTaskUsedTime_; + left.bundleStartedCount_ += right.bundleStartedCount_; +} } // namespace DeviceUsageStats } // namespace OHOS \ No newline at end of file diff --git a/frameworks/src/bundle_state_query.cpp b/frameworks/src/bundle_state_query.cpp index a00cded8a064c498bdf34f8a77a6308783528747..75a97beba83afc149a8b67c5ae7a1f81ed935228 100644 --- a/frameworks/src/bundle_state_query.cpp +++ b/frameworks/src/bundle_state_query.cpp @@ -17,9 +17,7 @@ #include "bundle_state_common.h" #include "bundle_active_log.h" -#include "bundle_active_client.h" #include "bundle_state_data.h" -#include "bundle_state_query.h" namespace OHOS { namespace DeviceUsageStats { @@ -522,7 +520,6 @@ napi_value QueryBundleStateInfos(napi_env env, napi_callback_info info) if (ParseAppUsageParameters(env, info, params) == nullptr) { return BundleStateCommon::JSParaError(env, params.callback); } - napi_value promise = nullptr; AsyncCallbackInfoAppUsage *asyncCallbackInfo = new (std::nothrow) AsyncCallbackInfoAppUsage {.env = env, .asyncWork = nullptr}; @@ -536,10 +533,8 @@ napi_value QueryBundleStateInfos(napi_env env, napi_callback_info info) BUNDLE_ACTIVE_LOGI("QueryBundleStateInfos asyncCallbackInfo->endTime: %{public}lld", asyncCallbackInfo->endTime); BundleStateCommon::SettingCallbackPromiseInfo(env, params.callback, asyncCallbackInfo->info, promise); - napi_value resourceName = nullptr; napi_create_string_latin1(env, "QueryBundleStateInfos", NAPI_AUTO_LENGTH, &resourceName); - napi_create_async_work(env, nullptr, resourceName, @@ -548,10 +543,9 @@ napi_value QueryBundleStateInfos(napi_env env, napi_callback_info info) AsyncCallbackInfoAppUsage *asyncCallbackInfo = (AsyncCallbackInfoAppUsage *)data; if (asyncCallbackInfo != nullptr) { asyncCallbackInfo->packageStats = - BundleActiveClient::GetInstance().QueryPackageStats(INTERVAL_TYPE_DEFAULT, - asyncCallbackInfo->beginTime, asyncCallbackInfo->endTime); + BundleStateCommon::GetPackageStats(asyncCallbackInfo->beginTime, asyncCallbackInfo->endTime); } else { - BUNDLE_ACTIVE_LOGE("QueryBundleStateInfos, asyncCallbackInfo == nullptr"); + BUNDLE_ACTIVE_LOGE("QueryBundleStateInfos asyncCallbackInfo == nullptr"); } BUNDLE_ACTIVE_LOGI("QueryBundleStateInfos worker pool thread execute end."); }, @@ -559,14 +553,12 @@ napi_value QueryBundleStateInfos(napi_env env, napi_callback_info info) AsyncCallbackInfoAppUsage *asyncCallbackInfo = (AsyncCallbackInfoAppUsage *)data; if (asyncCallbackInfo != nullptr) { napi_value result = nullptr; - napi_create_array(env, &result); + napi_create_object(env, &result); BundleStateCommon::GetBundleStateInfoForResult(env, asyncCallbackInfo->packageStats, result); BundleStateCommon::GetCallbackPromiseResult(env, asyncCallbackInfo->info, result); - if (asyncCallbackInfo->info.callback != nullptr) { napi_delete_reference(env, asyncCallbackInfo->info.callback); } - napi_delete_async_work(env, asyncCallbackInfo->asyncWork); delete asyncCallbackInfo; asyncCallbackInfo = nullptr; @@ -574,9 +566,7 @@ napi_value QueryBundleStateInfos(napi_env env, napi_callback_info info) }, (void *)asyncCallbackInfo, &asyncCallbackInfo->asyncWork); - NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork)); - if (asyncCallbackInfo->info.isCallback) { return BundleStateCommon::NapiGetNull(env); } else { diff --git a/interfaces/kits/bundlestats/napi/include/bundle_state_common.h b/interfaces/kits/bundlestats/napi/include/bundle_state_common.h index ce44bee4a78d0dfec0813df4731fb09f5b71c4a0..5e8daf4642d1195c4b1037b9515b09ffcf867404 100644 --- a/interfaces/kits/bundlestats/napi/include/bundle_state_common.h +++ b/interfaces/kits/bundlestats/napi/include/bundle_state_common.h @@ -16,11 +16,11 @@ #ifndef FOUNDATION_RESOURCESCHEDULE_DEVICE_USAGE_STATISTICS_BUNDLE_STATE_COMMON_H #define FOUNDATION_RESOURCESCHEDULE_DEVICE_USAGE_STATISTICS_BUNDLE_STATE_COMMON_H -#include - +#include "bundle_active_client.h" +#include "bundle_state_data.h" +#include "bundle_state_query.h" #include "napi/native_api.h" #include "napi/native_node_api.h" -#include "bundle_state_data.h" namespace OHOS { namespace DeviceUsageStats { @@ -50,8 +50,8 @@ public: static void GetBundleStateInfoByIntervalForResult( napi_env env, const std::vector &packageStats, napi_value result); - static void GetBundleStateInfoForResult( - napi_env env, const std::vector &packageStats, napi_value result); + static void GetBundleStateInfoForResult(napi_env env, + const std::shared_ptr> &packageStats, napi_value result); static void SetPromiseInfo(const napi_env &env, const napi_deferred &deferred, const napi_value &result); @@ -62,6 +62,11 @@ public: static napi_value GetInt64NumberValue(const napi_env &env, const napi_value &value, int64_t &result); static napi_value GetInt32NumberValue(const napi_env &env, const napi_value &value, int32_t &result); + + static std::shared_ptr> GetPackageStats( + int64_t &beginTime, int64_t &endTime); + + static void MergePackageStats(BundleActivePackageStats &left, const BundleActivePackageStats &right); }; } // namespace DeviceUsageStats } // namespace OHOS diff --git a/interfaces/kits/bundlestats/napi/include/bundle_state_data.h b/interfaces/kits/bundlestats/napi/include/bundle_state_data.h index a44f85b3c6b3bb333ad492e3ff68e36c25a52e54..c854436457ebebaa61efb2b6335b29ef5ded1a4b 100644 --- a/interfaces/kits/bundlestats/napi/include/bundle_state_data.h +++ b/interfaces/kits/bundlestats/napi/include/bundle_state_data.h @@ -16,6 +16,7 @@ #ifndef FOUNDATION_RESOURCESCHEDULE_DEVICE_USAGE_STATISTICS_BUNDLE_STATE_DATA_H #define FOUNDATION_RESOURCESCHEDULE_DEVICE_USAGE_STATISTICS_BUNDLE_STATE_DATA_H +#include #include #include "napi/native_api.h" @@ -85,7 +86,7 @@ struct AsyncCallbackInfoAppUsage { napi_async_work asyncWork = nullptr; int64_t beginTime; int64_t endTime; - std::vector packageStats; + std::shared_ptr> packageStats; CallbackPromiseInfo info; }; diff --git a/services/common/include/bundle_active_log.h b/services/common/include/bundle_active_log.h index 3a24733e5bdcb7d4b3e7a591a94caeb327f7a355..d4bc93a37ad4c9949d94b738d40bb8e5d4c225c7 100644 --- a/services/common/include/bundle_active_log.h +++ b/services/common/include/bundle_active_log.h @@ -16,10 +16,18 @@ #ifndef BUNDLE_ACTIVE_LOG_H #define BUNDLE_ACTIVE_LOG_H +#include #include "hilog/log.h" -#define LOG_TAG_BUNDLE_ACTIVE "BUNDLE_ACTIVE" +namespace OHOS { +namespace DeviceUsageStats { +#ifndef LOG_TAG_DOMAIN_ID_BUNDLE_ACTIVE #define LOG_TAG_DOMAIN_ID_BUNDLE_ACTIVE 0xD001701 +#endif + +#ifndef LOG_TAG_BUNDLE_ACTIVE +#define LOG_TAG_BUNDLE_ACTIVE "BUNDLE_ACTIVE" +#endif static constexpr OHOS::HiviewDFX::HiLogLabel BUNDLE_ACTIVE_LOG_LABEL = { LOG_CORE, @@ -27,10 +35,46 @@ static constexpr OHOS::HiviewDFX::HiLogLabel BUNDLE_ACTIVE_LOG_LABEL = { LOG_TAG_BUNDLE_ACTIVE }; -#define BUNDLE_ACTIVE_LOGF(...) (void)OHOS::HiviewDFX::HiLog::Fatal(BUNDLE_ACTIVE_LOG_LABEL, __VA_ARGS__) -#define BUNDLE_ACTIVE_LOGE(...) (void)OHOS::HiviewDFX::HiLog::Error(BUNDLE_ACTIVE_LOG_LABEL, __VA_ARGS__) -#define BUNDLE_ACTIVE_LOGW(...) (void)OHOS::HiviewDFX::HiLog::Warn(BUNDLE_ACTIVE_LOG_LABEL, __VA_ARGS__) -#define BUNDLE_ACTIVE_LOGI(...) (void)OHOS::HiviewDFX::HiLog::Info(BUNDLE_ACTIVE_LOG_LABEL, __VA_ARGS__) -#define BUNDLE_ACTIVE_LOGD(...) (void)OHOS::HiviewDFX::HiLog::Debug(BUNDLE_ACTIVE_LOG_LABEL, __VA_ARGS__) +enum class BundleActiveLogLevel : uint8_t { DEBUG = 0, INFO, WARN, ERROR, FATAL }; + +class BundleActiveLog { +public: + BundleActiveLog() = delete; + ~BundleActiveLog() = delete; + + static bool JudgeValidLevel(const BundleActiveLogLevel &level); + + static void SetLogLevel(const BundleActiveLogLevel &level) + { + logLevel_ = level; + } + + static const BundleActiveLogLevel &GetLogLevel() + { + return logLevel_; + } + + static std::string GetCurrFileName(const char *str); + +private: + static BundleActiveLogLevel logLevel_; +}; + +#define PRINT_LOG(LEVEL, Level, fmt, ...) \ + if (BundleActiveLog::JudgeValidLevel(BundleActiveLogLevel::LEVEL)) \ + OHOS::HiviewDFX::HiLog::Level(BUNDLE_ACTIVE_LOG_LABEL, \ + "[%{public}s(%{public}s):%{public}d] " fmt, \ + BundleActiveLog::GetCurrFileName(__FILE__).c_str(), \ + __FUNCTION__, \ + __LINE__, \ + ##__VA_ARGS__) + +#define BUNDLE_ACTIVE_LOGD(fmt, ...) PRINT_LOG(DEBUG, Debug, fmt, ##__VA_ARGS__) +#define BUNDLE_ACTIVE_LOGI(fmt, ...) PRINT_LOG(INFO, Info, fmt, ##__VA_ARGS__) +#define BUNDLE_ACTIVE_LOGW(fmt, ...) PRINT_LOG(WARN, Warn, fmt, ##__VA_ARGS__) +#define BUNDLE_ACTIVE_LOGE(fmt, ...) PRINT_LOG(ERROR, Error, fmt, ##__VA_ARGS__) +#define BUNDLE_ACTIVE_LOGF(fmt, ...) PRINT_LOG(FATAL, Fatal, fmt, ##__VA_ARGS__) +} // namespace DeviceUsageStats +} // namespace OHOS -#endif \ No newline at end of file +#endif // BUNDLE_ACTIVE_LOG_H \ No newline at end of file diff --git a/services/common/src/bundle_active_log.cpp b/services/common/src/bundle_active_log.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ddd88396ae277f3dc994e8192364ac3416ed1d05 --- /dev/null +++ b/services/common/src/bundle_active_log.cpp @@ -0,0 +1,43 @@ +/* + * 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" + +namespace OHOS { +namespace DeviceUsageStats { +BundleActiveLogLevel BundleActiveLog::logLevel_ = {BundleActiveLogLevel::DEBUG}; +bool BundleActiveLog::JudgeValidLevel(const BundleActiveLogLevel &level) +{ + const BundleActiveLogLevel &currLevel = BundleActiveLog::GetLogLevel(); + if (level < currLevel) { + return false; + } + return true; +} + +std::string BundleActiveLog::GetCurrFileName(const char *str) +{ + if (!str) { + return std::string(); + } + std::string fullPath(str); + size_t pos = fullPath.find_last_of("/"); + if (pos == std::string::npos) { + return std::string(); + } + return fullPath.substr(pos + 1); +} +} // namespace DeviceUsageStats +} // namespace OHOS diff --git a/services/common/src/bundle_active_open_callback.cpp b/services/common/src/bundle_active_open_callback.cpp index bf951e1f677347ae879b005e4006aebd9c137c67..6e1ce14b30b640c94487bf3ada4a49a4a7ea281b 100644 --- a/services/common/src/bundle_active_open_callback.cpp +++ b/services/common/src/bundle_active_open_callback.cpp @@ -29,13 +29,13 @@ BundleActiveOpenCallback::~BundleActiveOpenCallback() int32_t BundleActiveOpenCallback::OnCreate(NativeRdb::RdbStore &rdbStore) { - BUNDLE_ACTIVE_LOGI("wangyuanchao FlushDatabase SUCCESS.BundleActiveOpenCallback"); + BUNDLE_ACTIVE_LOGI("Create success."); return NativeRdb::E_OK; }; int32_t BundleActiveOpenCallback::OnUpgrade(NativeRdb::RdbStore &rdbStore, int oldVersion, int newVersion) { - BUNDLE_ACTIVE_LOGI("FlushDatabase SUCCESS.OnUpgrade"); + BUNDLE_ACTIVE_LOGI("Upgrade success."); return NativeRdb::E_OK; }; } // namespace DeviceUsageStats diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp index 9a378e53c7dee6f4d000bc7540d298a12ee2cf02..49330f0d551698f27a84b0fd7f6a7d80d716378b 100644 --- a/services/common/src/bundle_active_usage_database.cpp +++ b/services/common/src/bundle_active_usage_database.cpp @@ -190,7 +190,7 @@ unique_ptr BundleActiveUsageDatabase::QueryStatsInfoByStep { shared_ptr rdbStore = GetBundleActiveRdbStore(databaseType); if (rdbStore == nullptr) { - BUNDLE_ACTIVE_LOGE("queryStatsInfoByStep is failed"); + BUNDLE_ACTIVE_LOGE("rdbStore is nullptr"); return nullptr; } unique_ptr result; @@ -280,20 +280,19 @@ void BundleActiveUsageDatabase::DeleteExcessiveTableData(unsigned int databaseTy } shared_ptr rdbStore = GetBundleActiveRdbStore(databaseType); if (rdbStore == nullptr) { - BUNDLE_ACTIVE_LOGE("BundleActiveUsageDatabase DeleteExcessiveTableData is failed"); + BUNDLE_ACTIVE_LOGE("rdbStore is nullptr"); return; } string deleteEventDataSql = "delete from " + eventTableName_ + " where timeStamp <= " + to_string(deleteTimePoint); int32_t deleteResult = rdbStore->ExecuteSql(deleteEventDataSql); if (deleteResult != NativeRdb::E_OK) { - BUNDLE_ACTIVE_LOGE("BundleActiveUsageDatabase DeleteExcessiveTableData deleteEventData is failed"); + BUNDLE_ACTIVE_LOGE("delete event data failed, rdb error number: %{public}d", deleteResult); } } else if (databaseType == APP_GROUP_DATABASE_INDEX) { // 无数据删除 } else { - BUNDLE_ACTIVE_LOGE("BundleActiveUsageDatabase DeleteExcessiveTableData databaseType is invalid, databaseType = " - "%{public}d", databaseType); + BUNDLE_ACTIVE_LOGE("databaseType is invalid, databaseType = %{public}d", databaseType); } } @@ -302,8 +301,7 @@ std::unique_ptr> BundleActiveUsageDatabase::GetOverdueTable { std::unique_ptr> overdueTableCreateTime = std::make_unique>(); if (databaseType < 0 || databaseType >= sortedTableArray_.size()) { - BUNDLE_ACTIVE_LOGE("BundleActiveUsageDatabase GetOverdueTableCreateTime databaseType is invalid, databaseType " - "= %{public}d", databaseType); + BUNDLE_ACTIVE_LOGE("databaseType is invalid, databaseType = %{public}d", databaseType); return nullptr; } string queryDatabaseTableNames = "select * from sqlite_master where type = ?"; @@ -312,13 +310,13 @@ std::unique_ptr> BundleActiveUsageDatabase::GetOverdueTable unique_ptr bundleActiveResult = QueryStatsInfoByStep(databaseType, queryDatabaseTableNames, queryCondition); if (bundleActiveResult == nullptr) { - BUNDLE_ACTIVE_LOGE("BundleActiveUsageDatabase GetOverdueTableCreateTime bundleActiveResult is invalid"); + BUNDLE_ACTIVE_LOGE("bundleActiveResult is invalid"); return nullptr; } int32_t tableNumber; bundleActiveResult->GetRowCount(tableNumber); if (tableNumber == 0) { - BUNDLE_ACTIVE_LOGE("BundleActiveUsageDatabase GetOverdueTableCreateTime table does not exist"); + BUNDLE_ACTIVE_LOGE("table does not exist"); return nullptr; } int32_t tableNameIndex; @@ -338,7 +336,7 @@ int32_t BundleActiveUsageDatabase::DeleteInvalidTable(unsigned int databaseType, { shared_ptr rdbStore = GetBundleActiveRdbStore(databaseType); if (rdbStore == nullptr) { - BUNDLE_ACTIVE_LOGE("get rdbStore failed"); + BUNDLE_ACTIVE_LOGE("rdbStore is nullptr"); return BUNDLE_ACTIVE_FAIL; } if (databaseType >= 0 && databaseType < sortedTableArray_.size()) { @@ -346,7 +344,7 @@ int32_t BundleActiveUsageDatabase::DeleteInvalidTable(unsigned int databaseType, string deletePackageTableSql = "drop table " + packageTable; int32_t deletePackageTable = rdbStore->ExecuteSql(deletePackageTableSql); if (deletePackageTable != NativeRdb::E_OK) { - BUNDLE_ACTIVE_LOGE("deletePackageTable is %{public}d", deletePackageTable); + BUNDLE_ACTIVE_LOGE("delete package table failed, rdb error number: %{public}d", deletePackageTable); return BUNDLE_ACTIVE_FAIL; } } else if (databaseType == EVENT_DATABASE_INDEX) { @@ -354,7 +352,7 @@ int32_t BundleActiveUsageDatabase::DeleteInvalidTable(unsigned int databaseType, string deleteEventTableSql = "drop table " + eventTable; int32_t deleteEventTable = rdbStore->ExecuteSql(deleteEventTableSql); if (deleteEventTable != NativeRdb::E_OK) { - BUNDLE_ACTIVE_LOGE("deleteEventTable is %{public}d", deleteEventTable); + BUNDLE_ACTIVE_LOGE("delete event table failed, rdb error number: %{public}d", deleteEventTable); return BUNDLE_ACTIVE_FAIL; } } else if (databaseType == APP_GROUP_DATABASE_INDEX) { @@ -434,12 +432,13 @@ int32_t BundleActiveUsageDatabase::CreateEventLogTable(unsigned int databaseType + BUNDLE_ACTIVE_DB_ABILITY_ID + " TEXT NOT NULL);"; int32_t createEventTable = rdbStore->ExecuteSql(createEventTableSql); if (createEventTable != NativeRdb::E_OK) { + BUNDLE_ACTIVE_LOGE("create event table failed, rdb error number: %{public}d", createEventTable); return createEventTable; } string createEventTableIndex = GetTableIndexSql(EVENT_DATABASE_INDEX, currentTimeMillis, true); int32_t createResult = rdbStore->ExecuteSql(createEventTableIndex); if (createResult != NativeRdb::E_OK) { - BUNDLE_ACTIVE_LOGE("create event table index failed"); + BUNDLE_ACTIVE_LOGE("create event table index failed, rdb error number: %{public}d", createResult); return BUNDLE_ACTIVE_FAIL; } return BUNDLE_ACTIVE_SUCCESS; @@ -465,13 +464,13 @@ int32_t BundleActiveUsageDatabase::CreatePackageLogTable(unsigned int databaseTy + BUNDLE_ACTIVE_DB_TOTAL_TIME_CONTINUOUS_TASK + " INTEGER NOT NULL);"; int32_t createPackageTable = rdbStore->ExecuteSql(createPackageTableSql); if (createPackageTable != NativeRdb::E_OK) { - BUNDLE_ACTIVE_LOGE("create packageLog table failed"); + BUNDLE_ACTIVE_LOGE("create packageLog table failed, rdb error number: %{public}d", createPackageTable); return BUNDLE_ACTIVE_FAIL; } string createPackageTableIndex = GetTableIndexSql(databaseType, currentTimeMillis, true); int32_t createResult = rdbStore->ExecuteSql(createPackageTableIndex); if (createResult != NativeRdb::E_OK) { - BUNDLE_ACTIVE_LOGE("create package table index failed"); + BUNDLE_ACTIVE_LOGE("create package table index failed, rdb error number: %{public}d", createResult); return BUNDLE_ACTIVE_FAIL; } return BUNDLE_ACTIVE_SUCCESS; @@ -491,7 +490,7 @@ int32_t BundleActiveUsageDatabase::CreateDurationTable(unsigned int databaseType + BUNDLE_ACTIVE_DB_SCREEN_ON_DURATION + " INTEGER NOT NULL);"; int32_t createDurationTable = rdbStore->ExecuteSql(createDurationTableSql); if (createDurationTable != NativeRdb::E_OK) { - BUNDLE_ACTIVE_LOGE("create duration table failed"); + BUNDLE_ACTIVE_LOGE("create duration table failed, rdb error number: %{public}d", createDurationTable); return BUNDLE_ACTIVE_FAIL; } return BUNDLE_ACTIVE_SUCCESS; @@ -517,14 +516,14 @@ int32_t BundleActiveUsageDatabase::CreateBundleHistoryTable(unsigned int databas + BUNDLE_ACTIVE_DB_BUNDLE_DAILY_TIMEOUT_TIME + " INTEGER NOT NULL);"; int32_t createBundleHistoryTable = rdbStore->ExecuteSql(createBundleHistoryTableSql); if (createBundleHistoryTable != NativeRdb::E_OK) { - BUNDLE_ACTIVE_LOGE("create bundleHistory table failed"); + BUNDLE_ACTIVE_LOGE("create bundleHistory table failed, rdb error number: %{public}d", createBundleHistoryTable); return createBundleHistoryTable; } int32_t time = 0; string createBundleHistoryTableIndex = GetTableIndexSql(databaseType, time, true); int32_t createResult = rdbStore->ExecuteSql(createBundleHistoryTableIndex); if (createResult != NativeRdb::E_OK) { - BUNDLE_ACTIVE_LOGE("create bundleHistory table index failed"); + BUNDLE_ACTIVE_LOGE("create bundleHistory table index failed, rdb error number: %{public}d", createResult); return BUNDLE_ACTIVE_FAIL; } return BUNDLE_ACTIVE_SUCCESS;