diff --git a/frameworks/src/bundle_state_common.cpp b/frameworks/src/bundle_state_common.cpp index d32538686601f96bf87c76f21400d0e70b8839db..ecd0a7ce5ed313b25eab4b621978024f40ff1fd7 100644 --- a/frameworks/src/bundle_state_common.cpp +++ b/frameworks/src/bundle_state_common.cpp @@ -174,7 +174,7 @@ void BundleStateCommon::GetModuleRecordBasicForResult(napi_env env, NAPI_CALL_RETURN_VOID(env, napi_create_int64(env, oneModuleRecord.abilityIconId_, &abilityIconId)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "abilityIconId", abilityIconId)); napi_value launchedCount = nullptr; - NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, oneModuleRecord.launchedCount_, &launchedCount)); + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, oneModuleRecord.launchedCount_, &launchedCount)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "launchedCount", launchedCount)); napi_value lastModuleUsedTime = nullptr; NAPI_CALL_RETURN_VOID(env, napi_create_int64(env, oneModuleRecord.lastModuleUsedTime_, &lastModuleUsedTime)); diff --git a/frameworks/src/bundle_state_query.cpp b/frameworks/src/bundle_state_query.cpp index b5eb3a14bc46182f4b9fb19020a3bd36c35f7279..278d2bf53b5301736b40baa83c928b5675deb923 100644 --- a/frameworks/src/bundle_state_query.cpp +++ b/frameworks/src/bundle_state_query.cpp @@ -81,6 +81,8 @@ napi_value GetModuleUsageRecords(napi_env env, napi_callback_info info) if (memset_s(asyncCallbackInfo, sizeof(AsyncCallbackInfoModuleRecord), 0, sizeof(AsyncCallbackInfoModuleRecord)) != EOK) { params.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_INIT_FAILED; + delete asyncCallbackInfo; + asyncCallbackInfo = nullptr; return BundleStateCommon::JSParaError(env, params.callback, params.errorCode); } asyncCallbackInfo->env = env; @@ -180,6 +182,8 @@ napi_value IsIdleState(napi_env env, napi_callback_info info) if (memset_s(asyncCallbackInfo, sizeof(AsyncCallbackInfoIsIdleState), 0, sizeof(AsyncCallbackInfoIsIdleState)) != EOK) { params.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_INIT_FAILED; + delete asyncCallbackInfo; + asyncCallbackInfo = nullptr; return BundleStateCommon::JSParaError(env, params.callback, params.errorCode); } asyncCallbackInfo->env = env; @@ -260,6 +264,8 @@ napi_value QueryAppUsagePriorityGroup(napi_env env, napi_callback_info info) if (memset_s(asyncCallbackInfo, sizeof(AsyncCallbackInfoPriorityGroup), 0, sizeof(AsyncCallbackInfoPriorityGroup)) != EOK) { params.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_INIT_FAILED; + delete asyncCallbackInfo; + asyncCallbackInfo = nullptr; return BundleStateCommon::JSParaError(env, params.callback, params.errorCode); } asyncCallbackInfo->env = env; @@ -366,6 +372,8 @@ napi_value QueryCurrentBundleActiveStates(napi_env env, napi_callback_info info) if (memset_s(asyncCallbackInfo, sizeof(AsyncCallbackInfoStates), 0, sizeof(AsyncCallbackInfoStates)) != EOK) { params.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_INIT_FAILED; + delete asyncCallbackInfo; + asyncCallbackInfo = nullptr; return BundleStateCommon::JSParaError(env, params.callback, params.errorCode); } asyncCallbackInfo->env = env; @@ -439,6 +447,8 @@ napi_value QueryBundleActiveStates(napi_env env, napi_callback_info info) if (memset_s(asyncCallbackInfo, sizeof(AsyncCallbackInfoStates), 0, sizeof(AsyncCallbackInfoStates)) != EOK) { params.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_INIT_FAILED; + delete asyncCallbackInfo; + asyncCallbackInfo = nullptr; return BundleStateCommon::JSParaError(env, params.callback, params.errorCode); } asyncCallbackInfo->env = env; @@ -569,6 +579,8 @@ napi_value QueryBundleStateInfoByInterval(napi_env env, napi_callback_info info) if (memset_s(asyncCallbackInfo, sizeof(AsyncCallbackInfoAppUsageByInterval), 0, sizeof(AsyncCallbackInfoAppUsageByInterval)) != EOK) { params.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_INIT_FAILED; + delete asyncCallbackInfo; + asyncCallbackInfo = nullptr; return BundleStateCommon::JSParaError(env, params.callback, params.errorCode); } asyncCallbackInfo->env = env; @@ -689,6 +701,8 @@ napi_value QueryBundleStateInfos(napi_env env, napi_callback_info info) if (memset_s(asyncCallbackInfo, sizeof(AsyncCallbackInfoAppUsage), 0, sizeof(AsyncCallbackInfoAppUsage)) != EOK) { params.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_INIT_FAILED; + delete asyncCallbackInfo; + asyncCallbackInfo = nullptr; return BundleStateCommon::JSParaError(env, params.callback, params.errorCode); } asyncCallbackInfo->env = env; diff --git a/interfaces/innerkits/include/bundle_active_client.h b/interfaces/innerkits/include/bundle_active_client.h index 5fa5b7ebf7690f90c20673d7030f97a15e46b8a6..09c2be01e7533787161be59a8a51922cf0b5f45d 100644 --- a/interfaces/innerkits/include/bundle_active_client.h +++ b/interfaces/innerkits/include/bundle_active_client.h @@ -58,14 +58,14 @@ public: void SetBundleGroup(std::string bundleName, const int newGroup, const int userId); /* * function: QueryCurrentPackageStats, query bundle usage statistics in specific time span for calling bundle. - * parameters: intervalType, beginTime, endTime, errCode + * parameters: intervalType, beginTime, endTime * return: vector of calling bundle usage statistics. */ std::vector QueryCurrentPackageStats(const int intervalType, const int64_t beginTime, const int64_t endTime); /* * function: QueryCurrentEvents, query bundle usage statistics in specific time span for calling bundle. - * parameters: beginTime, endTime, errCode + * parameters: beginTime, endTime * return: vector of calling bundle events. */ std::vector QueryCurrentEvents(const int64_t beginTime, const int64_t endTime); @@ -76,7 +76,7 @@ public: int QueryPackageGroup(); /* * function: QueryFormStatistics, query all from usage statistics in specific time span for calling user. - * parameters: maxNum + * parameters: maxNum, results * return: errorcode. */ int QueryFormStatistics(int32_t maxNum, std::vector& results); diff --git a/interfaces/innerkits/include/bundle_active_proxy.h b/interfaces/innerkits/include/bundle_active_proxy.h index 2c55c4305528ead2df964a7e389089a7c1ed7d14..649a45af997f178c8f0ef7503b60ec28d5dabd33 100644 --- a/interfaces/innerkits/include/bundle_active_proxy.h +++ b/interfaces/innerkits/include/bundle_active_proxy.h @@ -59,14 +59,14 @@ public: void SetBundleGroup(const std::string& bundleName, int newGroup, int userId) override; /* * function: QueryCurrentPackageStats, query bundle usage statistics in specific time span for calling bundle. - * parameters: intervalType, beginTime, endTime, errCode + * parameters: intervalType, beginTime, endTime * return: vector of calling bundle usage statistics. */ std::vector QueryCurrentPackageStats(const int intervalType, const int64_t beginTime, const int64_t endTime) override; /* * function: QueryCurrentEvents, query bundle usage statistics in specific time span for calling bundle. - * parameters: beginTime, endTime, errCode + * parameters: beginTime, endTime * return: vector of calling bundle events. */ std::vector QueryCurrentEvents(const int64_t beginTime, const int64_t endTime) override; @@ -77,12 +77,13 @@ public: int QueryPackageGroup() override; /* * function: QueryFormStatistics, query all from usage statistics in specific time span for calling user. - * parameters: maxNum + * parameters: maxNum, results * return: errorcode. */ int QueryFormStatistics(int32_t maxNum, std::vector& results) override; /* * function: BundleActiveProxy, default constructor. + * parameters: impl */ explicit BundleActiveProxy(const sptr& impl) : IRemoteProxy(impl) {} diff --git a/services/common/include/bundle_active_constant.h b/services/common/include/bundle_active_constant.h index 77fd19118f20090345ee60ce64a615709c95ef28..e2b4f4198449c3273b639961b50c95e769b25fe9 100644 --- a/services/common/include/bundle_active_constant.h +++ b/services/common/include/bundle_active_constant.h @@ -39,6 +39,9 @@ const int32_t BUNDLE_ACTIVE_CURRENT_VERSION = 1; const int32_t BUNDLE_ACTIVE_SUCCESS = 0; const int32_t BUNDLE_ACTIVE_FAIL = -1; const int32_t BUNDLE_ACTIVE_RDB_VERSION = 1; +const int32_t BUNDLE_ACTIVE_DB_INDEX_NORMAL = 0; +const int32_t BUNDLE_ACTIVE_DB_INDEX_MODULE = 1; +const int32_t BUNDLE_ACTIVE_DB_INDEX_FORM = 2; const int USER_ID_COLUMN_INDEX = 0; const int BUNDLE_NAME_COLUMN_INDEX = 1; const int BUNDLE_STARTED_COUNT_COLUMN_INDEX = 2; @@ -58,6 +61,16 @@ const int BUNDLE_DAILY_TIMEOUT_TIME_COLUMN_INDEX = 7; const int BOOT_BASED_DURATION_COLUMN_INDEX = 0; const int SCREEN_ON_DURATION_COLUMN_INDEX = 1; const int DURATION_FLAG_COLUMN_INDEX = 2; +const int MODULE_NAME_COLUMN_INDEX = 2; +const int MODULE_PACKAGE_COLUMN_INDEX = 3; +const int MODULE_LAST_TIME_COLUMN_INDEX = 4; +const int MODULE_USED_COUNT_COLUMN_INDEX = 5; +const int MODULE_COMBINED_INFO_COLUMN_INDEX = 1; +const int FORM_NAME_COLUMN_INDEX = 2; +const int FORM_DIMENSION_COLUMN_INDEX = 3; +const int FORM_ID_COLUMN_INDEX = 4; +const int FORM_LAST_TIME_COLUMN_INDEX = 5; +const int FORM_COUNT_COLUMN_INDEXT = 6; const int TWO_SECONDS = 2 * 1000; const int64_t THIRTY_MINUTE = 30 * 60 * 1000; const int64_t SIX_DAY_IN_MILLIS_MAX_DEBUG = (int64_t)6 * 1 * 10 * 60 * 1000; @@ -80,9 +93,21 @@ const std::string EVENT_LOG_TABLE_INDEX_PREFIX = "DeviceEventLogIndex"; const std::string DURATION_LOG_TABLE = "DurationLog"; const std::string BUNDLE_HISTORY_LOG_TABLE = "BundleHistoryLog"; const std::string BUNDLE_HISTORY_LOG_TABLE_INDEX_PREFIX = "BundleHistoryLogIndex"; +const std::string MODULE_RECORD_LOG_TABLE = "ModuleRecordLog"; +const std::string MODULE_RECORD_LOG_TABLE_INDEX_PREFIX = "ModuleRecordLogIndex"; +const std::string FORM_RECORD_LOG_TABLE = "FormRecordLog"; +const std::string FORM_RECORD_LOG_TABLE_INDEX_PREFIX = "FormRecordLogIndex"; const std::string UNKNOWN_TABLE_NAME = "unknownTableName"; const std::string BUNDLE_ACTIVE_DB_USER_ID = "userId"; -const std::string BUNDLE_ACTIVE_DB_NAME = "bundleName"; +const std::string BUNDLE_ACTIVE_DB_BUNDLE_NAME = "bundleName"; +const std::string BUNDLE_ACTIVE_DB_MODULE_NAME = "moduleName"; +const std::string BUNDLE_ACTIVE_DB_MODULE_PACKAGE = "modulePackage"; +const std::string BUNDLE_ACTVIE_DB_MODULE_COMBINED_INFO = "moduleCombinedInfo"; +const std::string BUNDLE_ACTIVE_DB_FORM_NAME = "formName"; +const std::string BUNDLE_ACTIVE_DB_FORM_DIMENSION = "formDimension"; +const std::string BUNDLE_ACTIVE_DB_FORM_ID = "formId"; +const std::string BUNDLE_ACTIVE_DB_MODULE_LAUNCHED_COUNT = "launchedCount"; +const std::string BUNDLE_ACTIVE_DB_FORM_TOUCH_COUNT = "touchCount"; const std::string BUNDLE_ACTIVE_DB_BUNDLE_STARTED_COUNT = "bundleStartedCount"; const std::string BUNDLE_ACTIVE_DB_LAST_TIME = "lastTime"; const std::string BUNDLE_ACTIVE_DB_LAST_TIME_CONTINUOUS_TASK = "lastTimeContinuousTask"; diff --git a/services/common/include/bundle_active_core.h b/services/common/include/bundle_active_core.h index 9fd2de2e8ea0716c1a501ba28d1b537b6788835c..543c0376c8124cad25558162a714c3fa61cfee98 100644 --- a/services/common/include/bundle_active_core.h +++ b/services/common/include/bundle_active_core.h @@ -61,6 +61,7 @@ public: int ReportEventToAllUserId(BundleActiveEvent& event); /* * function: OnStatsChanged, report flush to disk, end_of_day event to service. + * parameters: userId */ void OnStatsChanged(const int userId) override; /* @@ -70,12 +71,13 @@ public: void OnStatsReload() override; /* * function: OnSystemUpdate, now is emtpy, later will called when system is updated. + * parameters: userId */ void OnSystemUpdate(int userId) override; /* * function: OnBundleUninstalled when received a PACKATE_REMOVED commen event, * BundleActiveCommonEventSubscriber call it to remove data. - * parameter: userId, Bundlename. + * parameters: userId, bundleName */ void OnBundleUninstalled(const int userId, const std::string& bundleName); /* @@ -91,15 +93,28 @@ public: void InitBundleGroupController(); /* * function: SetHandler, BundleActiveService call it to set event report handler + * parameters: reportHandler */ void SetHandler(const std::shared_ptr& reportHandler); - // flush database for one user data + /* + * function: RestoreToDatabase, restore bundle usage data and form data to database + * parameters: userId + */ void RestoreToDatabase(const int userId); - // flush database for one user data + /* + * function: RestoreToDatabaseLocked, flush database for one user data + * parameters: userId + */ void RestoreToDatabaseLocked(const int userId); - // called when device shutdown, update the in-memory stat and flush the database. + /* + * function: ShutDown, called when device shutdown, update the in-memory stat and flush the database. + */ void ShutDown(); - // query the package stat for calling user. + /* + * function: QueryPackageStats, query the package stat for calling user. + * parameters: userId, intervalType, beginTime, endTime, bundleName + * return: vector of BundleActivePackageStats + */ std::vector QueryPackageStats(const int userId, const int intervalType, const int64_t beginTime, const int64_t endTime, std::string bundleName); // query the event stat for calling user. diff --git a/services/common/include/bundle_active_service.h b/services/common/include/bundle_active_service.h index be95c8bb4f0694c6268fe1a38d4c095e450da74e..3008daf818265a050746ba623b6f306d98ca7d68 100644 --- a/services/common/include/bundle_active_service.h +++ b/services/common/include/bundle_active_service.h @@ -73,14 +73,14 @@ public: void SetBundleGroup(const std::string& bundleName, int newGroup, int userId) override; /* * function: QueryCurrentPackageStats, query bundle usage statistics in specific time span for calling bundle. - * parameters: intervalType, beginTime, endTime, errCode + * parameters: intervalType, beginTime, endTime * return: vector of calling bundle usage statistics. */ std::vector QueryCurrentPackageStats(const int intervalType, const int64_t beginTime, const int64_t endTime) override; /* * function: QueryCurrentEvents, query bundle usage statistics in specific time span for calling bundle. - * parameters: beginTime, endTime, errCode + * parameters: beginTime, endTime * return: vector of calling bundle events. */ std::vector QueryCurrentEvents(const int64_t beginTime, const int64_t endTime) override; @@ -91,12 +91,13 @@ public: int QueryPackageGroup() override; /* * function: QueryFormStatistics, query all from usage statistics in specific time span for calling user. - * parameters: maxNum + * parameters: maxNum, results * return: errorcode. */ int QueryFormStatistics(int32_t maxNum, std::vector& results) override; /* * function: BundleActiveService, default constructor. + * parameters: systemAbilityId, runOnCreate */ BundleActiveService(int32_t systemAbilityId, int runOnCreate) : SystemAbility(systemAbilityId, runOnCreate) {} diff --git a/services/common/include/bundle_active_usage_database.h b/services/common/include/bundle_active_usage_database.h index 5281d34506a98646caf57e5a6e44f49c041f990b..96a986e7653740b9ac002a1946283378637e2178 100644 --- a/services/common/include/bundle_active_usage_database.h +++ b/services/common/include/bundle_active_usage_database.h @@ -40,7 +40,7 @@ public: BundleActiveUsageDatabase(); ~BundleActiveUsageDatabase(); void InitDatabaseTableInfo(int64_t currentTime); - void InitUsageGroupInfo(int32_t databaseType); + void InitUsageGroupDatabase(const int32_t databaseType, const bool forModuleRecords); void UpdateUsageData(int32_t databaseType, BundleActivePeriodStats &stats); std::shared_ptr GetCurrentUsageData(int32_t databaseType, int userId); void RenewTableTime(int64_t timeDiffMillis); @@ -59,10 +59,10 @@ public: void OnPackageUninstalled(const int userId, const std::string& bundleName); void ChangeToDebug(); void UpdateModuleData(const int userId, - std::map>& moduleRecords_, const int64_t timeStamp); + std::map>& moduleRecords, const int64_t timeStamp); void RemoveFormData(const int userId, const std::string formName, const int32_t formDimension, const int64_t formId); - void LoadFormData(const int32_t userId, std::map>& moduleRecords); private: @@ -73,7 +73,8 @@ private: int32_t NearIndexOnOrAfterCurrentTime(int64_t currentTime, std::vector &sortedTableArray); int32_t NearIndexOnOrBeforeCurrentTime(int64_t currentTime, std::vector &sortedTableArray); int32_t RenameTableName(unsigned int databaseType, int64_t tableOldTime, int64_t tableNewTime); - std::string GetTableIndexSql(unsigned int databaseType, int64_t tableTime, bool createFlag); + std::string GetTableIndexSql(unsigned int databaseType, int64_t tableTime, bool createFlag, + int32_t indexFlag = BUNDLE_ACTIVE_DB_INDEX_NORMAL); void FlushPackageInfo(unsigned int databaseType, const BundleActivePeriodStats &stats); void FlushEventInfo(unsigned int databaseType, BundleActivePeriodStats &stats); void DeleteExcessiveTableData(unsigned int databaseType); @@ -84,6 +85,8 @@ private: int32_t CreateEventLogTable(unsigned int databaseType, int64_t currentTimeMillis); int32_t CreateDurationTable(unsigned int databaseType); int32_t CreateBundleHistoryTable(unsigned int databaseType); + int32_t CreateModuleRecordTable(unsigned int databaseType, int64_t timeStamp); + int32_t CreateFormRecordTable(unsigned int databaseType, int64_t timeStamp); std::unique_ptr QueryStatsInfoByStep(unsigned int databaseType, const std::string &sql, const std::vector &selectionArgs); void DeleteUninstalledInfo(const int userId, const std::string& bundleName, const std::string& tableName, @@ -91,6 +94,8 @@ private: int32_t CreateDatabasePath(); int64_t GetSystemTimeMs(); void CheckDatabaseFile(unsigned int databaseType); + void LoadFormData(const int32_t userId, std::map>& moduleRecords); private: std::vector databaseFiles_; @@ -100,6 +105,8 @@ private: std::string eventTableName_; std::string durationTableName_; std::string bundleHistoryTableName_; + std::string moduleRecordsTableName_; + std::string formRecordsTableName_; std::string versionDirectoryPath_; std::string versionFile_; uint32_t currentVersion_; diff --git a/services/common/include/ibundle_active_service.h b/services/common/include/ibundle_active_service.h index 9b0b9edaf59e97b43da9487bad91f7428fc8d8ea..865e1d7e9b5a5a0754f8f638ced3d52f9df37166 100644 --- a/services/common/include/ibundle_active_service.h +++ b/services/common/include/ibundle_active_service.h @@ -72,14 +72,14 @@ public: int32_t& errCode) = 0; /* * function: QueryCurrentPackageStats, query bundle usage statistics in specific time span for calling bundle. - * parameters: intervalType, beginTime, endTime, errCode + * parameters: intervalType, beginTime, endTime * return: vector of calling bundle usage statistics. */ virtual std::vector QueryCurrentPackageStats(const int intervalType, const int64_t beginTime, const int64_t endTime) = 0; /* * function: QueryCurrentEvents, query bundle usage statistics in specific time span for calling bundle. - * parameters: beginTime, endTime, errCode + * parameters: beginTime, endTime * return: vector of calling bundle events. */ virtual std::vector QueryCurrentEvents(const int64_t beginTime, const int64_t endTime) = 0; @@ -95,7 +95,7 @@ public: virtual void SetBundleGroup(const std::string& bundleName, int newGroup, int userId) = 0; /* * function: QueryFormStatistics, query all from usage statistics in specific time span for calling user. - * parameters: maxNum + * parameters: maxNum, results * return: errorcode. */ virtual int QueryFormStatistics(int32_t maxNum, std::vector& results) = 0; diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp index 058aad1c2c2aabe1345dad34e6a38363efb1b168..a463ed4ec9ce561f971ad357de80bf26af7a1f15 100644 --- a/services/common/src/bundle_active_usage_database.cpp +++ b/services/common/src/bundle_active_usage_database.cpp @@ -50,6 +50,8 @@ BundleActiveUsageDatabase::BundleActiveUsageDatabase() eventTableName_ = UNKNOWN_TABLE_NAME; durationTableName_ = UNKNOWN_TABLE_NAME; bundleHistoryTableName_ = UNKNOWN_TABLE_NAME; + moduleRecordsTableName_ = UNKNOWN_TABLE_NAME; + formRecordsTableName_ = UNKNOWN_TABLE_NAME; sortedTableArray_ = vector>(SORTED_TABLE_ARRAY_NUMBER); calendar_ = make_shared(); eventBeginTime_ = EVENT_BEGIN_TIME_INITIAL_VALUE; @@ -67,7 +69,7 @@ void BundleActiveUsageDatabase::ChangeToDebug() debugDatabase_ = true; } -void BundleActiveUsageDatabase::InitUsageGroupInfo(int32_t databaseType) +void BundleActiveUsageDatabase::InitUsageGroupDatabase(const int32_t databaseType, const bool forModuleRecords) { lock_guard lock(databaseMutex_); if (CreateDatabasePath() == BUNDLE_ACTIVE_FAIL) { @@ -99,12 +101,18 @@ void BundleActiveUsageDatabase::InitUsageGroupInfo(int32_t databaseType) for (int32_t i = 0; i < tableNumber; i++) { bundleActiveResult->GoToRow(i); bundleActiveResult->GetString(tableNameIndex, tableName); - if (DURATION_LOG_TABLE == tableName) { - durationTableName_ = DURATION_LOG_TABLE; - } else if (BUNDLE_HISTORY_LOG_TABLE == tableName) { - bundleHistoryTableName_ = BUNDLE_HISTORY_LOG_TABLE; + if (!forModuleRecords) { + if (DURATION_LOG_TABLE == tableName) { + durationTableName_ = DURATION_LOG_TABLE; + } else if (BUNDLE_HISTORY_LOG_TABLE == tableName) { + bundleHistoryTableName_ = BUNDLE_HISTORY_LOG_TABLE; + } } else { - // 无效的数据表 + if (MODULE_RECORD_LOG_TABLE == tableName) { + moduleRecordsTableName_ = MODULE_RECORD_LOG_TABLE; + } else if (FORM_RECORD_LOG_TABLE == tableName) { + formRecordsTableName_ = FORM_RECORD_LOG_TABLE; + } } } } @@ -445,6 +453,8 @@ void BundleActiveUsageDatabase::CheckDatabaseFile(unsigned int databaseType) } else if (databaseType == APP_GROUP_DATABASE_INDEX) { durationTableName_ = UNKNOWN_TABLE_NAME; bundleHistoryTableName_ = UNKNOWN_TABLE_NAME; + moduleRecordsTableName_ = UNKNOWN_TABLE_NAME; + formRecordsTableName_ = UNKNOWN_TABLE_NAME; } return; } @@ -464,7 +474,7 @@ int32_t BundleActiveUsageDatabase::CreateEventLogTable(unsigned int databaseType + eventTable + " (" + BUNDLE_ACTIVE_DB_USER_ID + " INTEGER NOT NULL, " - + BUNDLE_ACTIVE_DB_NAME + " TEXT NOT NULL, " + + BUNDLE_ACTIVE_DB_BUNDLE_NAME + " TEXT NOT NULL, " + BUNDLE_ACTIVE_DB_EVENT_ID + " INTEGER NOT NULL, " + BUNDLE_ACTIVE_DB_TIME_STAMP + " INTEGER NOT NULL, " + BUNDLE_ACTIVE_DB_ABILITY_ID + " TEXT NOT NULL);"; @@ -494,7 +504,7 @@ int32_t BundleActiveUsageDatabase::CreatePackageLogTable(unsigned int databaseTy + packageTable + " (" + BUNDLE_ACTIVE_DB_USER_ID + " INTEGER NOT NULL, " - + BUNDLE_ACTIVE_DB_NAME + " TEXT NOT NULL, " + + BUNDLE_ACTIVE_DB_BUNDLE_NAME + " TEXT NOT NULL, " + BUNDLE_ACTIVE_DB_BUNDLE_STARTED_COUNT + " INTEGER NOT NULL, " + BUNDLE_ACTIVE_DB_LAST_TIME + " INTEGER NOT NULL, " + BUNDLE_ACTIVE_DB_LAST_TIME_CONTINUOUS_TASK + " INTEGER NOT NULL, " @@ -514,6 +524,73 @@ int32_t BundleActiveUsageDatabase::CreatePackageLogTable(unsigned int databaseTy return BUNDLE_ACTIVE_SUCCESS; } +int32_t BundleActiveUsageDatabase::CreateModuleRecordTable(unsigned int databaseType, int64_t timeStamp) +{ + shared_ptr rdbStore = GetBundleActiveRdbStore(databaseType); + if (rdbStore == nullptr) { + BUNDLE_ACTIVE_LOGE("rdbStore is nullptr"); + return BUNDLE_ACTIVE_FAIL; + } + string moduleRecord = MODULE_RECORD_LOG_TABLE + to_string(timeStamp); + moduleRecordsTableName_ = moduleRecord; + string createModuleRecordTableSql = "CREATE TABLE IF NOT EXISTS " + + moduleRecord + + " (" + + BUNDLE_ACTIVE_DB_USER_ID + " INTEGER NOT NULL, " + + BUNDLE_ACTIVE_DB_BUNDLE_NAME + " TEXT NOT NULL, " + + BUNDLE_ACTIVE_DB_MODULE_NAME + " TEXT NOT NULL, " + + BUNDLE_ACTIVE_DB_MODULE_PACKAGE + " TEXT NOT NULL, " + + BUNDLE_ACTIVE_DB_MODULE_LAUNCHED_COUNT + " INTEGER NOT NULL, " + + BUNDLE_ACTIVE_DB_LAST_TIME + " INTEGER NOT NULL);"; + int32_t createModuleRecordTable = rdbStore->ExecuteSql(createModuleRecordTableSql); + if (createModuleRecordTable != NativeRdb::E_OK) { + BUNDLE_ACTIVE_LOGE("create ModuleRecord table failed, rdb error number: %{public}d", createModuleRecordTable); + return BUNDLE_ACTIVE_FAIL; + } + string createModuleTableIndex = GetTableIndexSql(databaseType, timeStamp, true, BUNDLE_ACTIVE_DB_INDEX_MODULE); + int32_t createResult = rdbStore->ExecuteSql(createModuleTableIndex); + if (createResult != NativeRdb::E_OK) { + BUNDLE_ACTIVE_LOGE("create module table index failed, rdb error number: %{public}d", createResult); + return BUNDLE_ACTIVE_FAIL; + } + return BUNDLE_ACTIVE_SUCCESS; +} + +int32_t BundleActiveUsageDatabase::CreateFormRecordTable(unsigned int databaseType, int64_t timeStamp) +{ + shared_ptr rdbStore = GetBundleActiveRdbStore(databaseType); + if (rdbStore == nullptr) { + BUNDLE_ACTIVE_LOGE("rdbStore is nullptr"); + return BUNDLE_ACTIVE_FAIL; + } + string formRecord = FORM_RECORD_LOG_TABLE + to_string(timeStamp); + formRecordsTableName_ = formRecord; + string createFormRecordTableSql = "CREATE TABLE IF NOT EXISTS " + + formRecord + + " (" + + BUNDLE_ACTIVE_DB_USER_ID + " INTEGER NOT NULL, " + + BUNDLE_ACTIVE_DB_BUNDLE_NAME + " TEXT NOT NULL, " + + BUNDLE_ACTIVE_DB_MODULE_NAME + " TEXT NOT NULL, " + + BUNDLE_ACTIVE_DB_MODULE_PACKAGE + " TEXT NOT NULL, " + + BUNDLE_ACTIVE_DB_FORM_NAME + " TEXT NOT NULL, " + + BUNDLE_ACTIVE_DB_FORM_DIMENSION + " INTEGER NOT NULL, " + + BUNDLE_ACTIVE_DB_FORM_ID + " INTEGER NOT NULL, " + + BUNDLE_ACTIVE_DB_FORM_TOUCH_COUNT + " INTEGER NOT NULL, " + + BUNDLE_ACTIVE_DB_LAST_TIME + " INTEGER NOT NULL);"; + int32_t createFormRecordTable = rdbStore->ExecuteSql(createFormRecordTableSql); + if (createFormRecordTable != NativeRdb::E_OK) { + BUNDLE_ACTIVE_LOGE("create ModuleRecord table failed, rdb error number: %{public}d", createFormRecordTable); + return BUNDLE_ACTIVE_FAIL; + } + string createFormTableIndex = GetTableIndexSql(databaseType, timeStamp, true, BUNDLE_ACTIVE_DB_INDEX_FORM); + int32_t createResult = rdbStore->ExecuteSql(createFormTableIndex); + if (createResult != NativeRdb::E_OK) { + BUNDLE_ACTIVE_LOGE("create module table index failed, rdb error number: %{public}d", createResult); + return BUNDLE_ACTIVE_FAIL; + } + return BUNDLE_ACTIVE_SUCCESS; +} + int32_t BundleActiveUsageDatabase::CreateDurationTable(unsigned int databaseType) { shared_ptr rdbStore = GetBundleActiveRdbStore(databaseType); @@ -545,7 +622,7 @@ int32_t BundleActiveUsageDatabase::CreateBundleHistoryTable(unsigned int databas + BUNDLE_HISTORY_LOG_TABLE + " (" + BUNDLE_ACTIVE_DB_USER_ID + " INTEGER NOT NULL, " - + BUNDLE_ACTIVE_DB_NAME + " TEXT NOT NULL, " + + BUNDLE_ACTIVE_DB_BUNDLE_NAME + " TEXT NOT NULL, " + BUNDLE_ACTIVE_DB_LAST_BOOT_FROM_USED_TIME + " INTEGER NOT NULL, " + BUNDLE_ACTIVE_DB_LAST_SCREEN_USED_TIME + " INTEGER NOT NULL, " + BUNDLE_ACTIVE_DB_CURRENT_GROUP + " INTEGER NOT NULL, " @@ -606,7 +683,7 @@ void BundleActiveUsageDatabase::PutBundleHistoryData(int userId, rdbStore->Update(changeRow, BUNDLE_HISTORY_LOG_TABLE, valuesBucket, "userId = ? and bundleName = ?", queryCondition); if (changeRow == NO_UPDATE_ROW) { - valuesBucket.PutString(BUNDLE_ACTIVE_DB_NAME, iter->first); + valuesBucket.PutString(BUNDLE_ACTIVE_DB_BUNDLE_NAME, iter->first); valuesBucket.PutInt(BUNDLE_ACTIVE_DB_USER_ID, userId); rdbStore->Insert(outRowId, BUNDLE_HISTORY_LOG_TABLE, valuesBucket); outRowId = BUNDLE_ACTIVE_FAIL; @@ -739,7 +816,7 @@ void BundleActiveUsageDatabase::FlushPackageInfo(unsigned int databaseType, cons valuesBucket.PutLong(BUNDLE_ACTIVE_DB_TOTAL_TIME_CONTINUOUS_TASK, iter->second->totalContiniousTaskUsedTime_); rdbStore->Update(changeRow, tableName, valuesBucket, "userId = ? and bundleName = ?", queryCondition); if (changeRow == NO_UPDATE_ROW) { - valuesBucket.PutString(BUNDLE_ACTIVE_DB_NAME, iter->second->bundleName_); + valuesBucket.PutString(BUNDLE_ACTIVE_DB_BUNDLE_NAME, iter->second->bundleName_); valuesBucket.PutInt(BUNDLE_ACTIVE_DB_USER_ID, stats.userId_); rdbStore->Insert(outRowId, tableName, valuesBucket); outRowId = BUNDLE_ACTIVE_FAIL; @@ -825,7 +902,7 @@ void BundleActiveUsageDatabase::FlushEventInfo(unsigned int databaseType, Bundle NativeRdb::ValuesBucket valuesBucket; for (int32_t i = 0; i < stats.events_.Size(); i++) { valuesBucket.PutInt(BUNDLE_ACTIVE_DB_USER_ID, stats.userId_); - valuesBucket.PutString(BUNDLE_ACTIVE_DB_NAME, stats.events_.events_.at(i).bundleName_); + valuesBucket.PutString(BUNDLE_ACTIVE_DB_BUNDLE_NAME, stats.events_.events_.at(i).bundleName_); valuesBucket.PutInt(BUNDLE_ACTIVE_DB_EVENT_ID, stats.events_.events_.at(i).eventId_); valuesBucket.PutLong(BUNDLE_ACTIVE_DB_TIME_STAMP, stats.events_.events_.at(i).timeStamp_ - eventTableTime); valuesBucket.PutString(BUNDLE_ACTIVE_DB_ABILITY_ID, stats.events_.events_.at(i).abilityId_); @@ -834,7 +911,8 @@ void BundleActiveUsageDatabase::FlushEventInfo(unsigned int databaseType, Bundle } } -string BundleActiveUsageDatabase::GetTableIndexSql(unsigned int databaseType, int64_t tableTime, bool createFlag) +string BundleActiveUsageDatabase::GetTableIndexSql(unsigned int databaseType, int64_t tableTime, bool createFlag, + int32_t indexFlag) { string tableIndexSql; if (databaseType >= 0 && databaseType < sortedTableArray_.size()) { @@ -857,10 +935,25 @@ string BundleActiveUsageDatabase::GetTableIndexSql(unsigned int databaseType, in } } else if (databaseType == APP_GROUP_DATABASE_INDEX) { if (createFlag) { - tableIndexSql = "CREATE INDEX " + BUNDLE_HISTORY_LOG_TABLE_INDEX_PREFIX - + " ON " + BUNDLE_HISTORY_LOG_TABLE + " (userId, bundleName);"; + if (indexFlag == BUNDLE_ACTIVE_DB_INDEX_NORMAL) { + tableIndexSql = "CREATE INDEX " + BUNDLE_HISTORY_LOG_TABLE_INDEX_PREFIX + + " ON " + BUNDLE_HISTORY_LOG_TABLE + " (userId, bundleName);"; + } else if (indexFlag == BUNDLE_ACTIVE_DB_INDEX_MODULE) { + tableIndexSql = "CREATE INDEX " + MODULE_RECORD_LOG_TABLE_INDEX_PREFIX + + " ON " + MODULE_RECORD_LOG_TABLE + to_string(tableTime) + " (userId, bundleName, moduleName " + ", modulePackage);"; + } else if (indexFlag == BUNDLE_ACTIVE_DB_INDEX_FORM) { + tableIndexSql = "CREATE INDEX " + FORM_RECORD_LOG_TABLE_INDEX_PREFIX + + " ON " + FORM_RECORD_LOG_TABLE + to_string(tableTime) + " (userId, formId);"; + } } else { - tableIndexSql = "DROP INDEX " + BUNDLE_HISTORY_LOG_TABLE_INDEX_PREFIX; + if (indexFlag == BUNDLE_ACTIVE_DB_INDEX_NORMAL) { + tableIndexSql = "DROP INDEX " + BUNDLE_HISTORY_LOG_TABLE_INDEX_PREFIX; + } else if (indexFlag == BUNDLE_ACTIVE_DB_INDEX_MODULE) { + tableIndexSql = "DROP INDEX " + MODULE_RECORD_LOG_TABLE_INDEX_PREFIX; + } else if (indexFlag == BUNDLE_ACTIVE_DB_INDEX_FORM) { + tableIndexSql = "DROP INDEX " + FORM_RECORD_LOG_TABLE_INDEX_PREFIX; + } } } else { BUNDLE_ACTIVE_LOGE("databaseType is invalid, databaseType = %{public}d", databaseType); @@ -1219,6 +1312,12 @@ void BundleActiveUsageDatabase::OnPackageUninstalled(const int userId, const str if (bundleHistoryTableName_ != UNKNOWN_TABLE_NAME) { DeleteUninstalledInfo(userId, bundleName, bundleHistoryTableName_, APP_GROUP_DATABASE_INDEX); } + if (moduleRecordsTableName_ != UNKNOWN_TABLE_NAME) { + DeleteUninstalledInfo(userId, bundleName, moduleRecordsTableName_, APP_GROUP_DATABASE_INDEX); + } + if (formRecordsTableName_ != UNKNOWN_TABLE_NAME) { + DeleteUninstalledInfo(userId, bundleName, formRecordsTableName_, APP_GROUP_DATABASE_INDEX); + } } void BundleActiveUsageDatabase::DeleteUninstalledInfo(const int userId, const string& bundleName, @@ -1259,22 +1358,131 @@ int64_t BundleActiveUsageDatabase::GetSystemTimeMs() } void BundleActiveUsageDatabase::UpdateModuleData(const int userId, - std::map>& moduleRecords_, const int64_t timeStamp) + std::map>& moduleRecords, const int64_t timeStamp) { - // mock + lock_guard lock(databaseMutex_); + CheckDatabaseFile(APP_GROUP_DATABASE_INDEX); + shared_ptr rdbStore = GetBundleActiveRdbStore(APP_GROUP_DATABASE_INDEX); + if (rdbStore == nullptr) { + BUNDLE_ACTIVE_LOGE("rdbStore is nullptr"); + return; + } + if (moduleRecordsTableName_ == UNKNOWN_TABLE_NAME) { + CreateModuleRecordTable(APP_GROUP_DATABASE_INDEX, timeStamp); + } + if (formRecordsTableName_ == UNKNOWN_TABLE_NAME) { + CreateFormRecordTable(APP_GROUP_DATABASE_INDEX, timeStamp); + } + int64_t moduleTableTime = ParseStartTime(moduleRecordsTableName_); + int64_t formRecordsTableTime = ParseStartTime(formRecordsTableName_); + int64_t outRowId = BUNDLE_ACTIVE_FAIL; + NativeRdb::ValuesBucket moduleValuesBucket; + NativeRdb::ValuesBucket formValueBucket; + for (const auto& oneModuleRecord : moduleRecords) { + if (oneModuleRecord.second) { + moduleValuesBucket.PutInt(BUNDLE_ACTIVE_DB_USER_ID, oneModuleRecord.second->userId_); + moduleValuesBucket.PutString(BUNDLE_ACTIVE_DB_BUNDLE_NAME, oneModuleRecord.second->bundleName_); + moduleValuesBucket.PutString(BUNDLE_ACTIVE_DB_MODULE_NAME, oneModuleRecord.second->moduleName_); + moduleValuesBucket.PutString(BUNDLE_ACTIVE_DB_MODULE_PACKAGE, oneModuleRecord.second->modulePackage_); + moduleValuesBucket.PutInt(BUNDLE_ACTIVE_DB_MODULE_LAUNCHED_COUNT, oneModuleRecord.second->launchedCount_); + moduleValuesBucket.PutLong(BUNDLE_ACTIVE_DB_LAST_TIME, oneModuleRecord.second->lastModuleUsedTime_ - + moduleTableTime); + rdbStore->Insert(outRowId, moduleRecordsTableName_, moduleValuesBucket); + moduleValuesBucket.Clear(); + string combinedInfo = oneModuleRecord.second->bundleName_ + " " + oneModuleRecord.second->moduleName_ + + " " + oneModuleRecord.second->modulePackage_; + for (const auto& oneFormRecord : oneModuleRecord.second->formRecords_) { + formValueBucket.PutInt(BUNDLE_ACTIVE_DB_USER_ID, oneModuleRecord.second->userId_); + formValueBucket.PutString(BUNDLE_ACTVIE_DB_MODULE_COMBINED_INFO, combinedInfo); + formValueBucket.PutString(BUNDLE_ACTIVE_DB_FORM_NAME, oneFormRecord.formName_); + formValueBucket.PutInt(BUNDLE_ACTIVE_DB_FORM_DIMENSION, oneFormRecord.formDimension_); + formValueBucket.PutInt(BUNDLE_ACTIVE_DB_FORM_ID, oneFormRecord.formId_); + formValueBucket.PutInt(BUNDLE_ACTIVE_DB_FORM_TOUCH_COUNT, oneFormRecord.count_); + formValueBucket.PutLong(BUNDLE_ACTIVE_DB_LAST_TIME, oneFormRecord.formLastUsedTime_ - + formRecordsTableTime); + rdbStore->Insert(outRowId, formRecordsTableName_, formValueBucket); + formValueBucket.Clear(); + } + } + } } void BundleActiveUsageDatabase::RemoveFormData(const int userId, const std::string formName, const int32_t formDimension, const int64_t formId) { - // mock + shared_ptr rdbStore = GetBundleActiveRdbStore(APP_GROUP_DATABASE_INDEX); + if (rdbStore == nullptr) { + BUNDLE_ACTIVE_LOGE("rdbStore is nullptr"); + return; + } + int32_t deletedRows = BUNDLE_ACTIVE_FAIL; + vector queryCondition; + if (formRecordsTableName_ != UNKNOWN_TABLE_NAME) { + queryCondition.emplace_back(to_string(userId)); + queryCondition.emplace_back(formName); + queryCondition.emplace_back(to_string(formDimension)); + queryCondition.emplace_back(to_string(formId)); + rdbStore->Delete(deletedRows, formRecordsTableName_, + "userId = ? and formName = ? and formDimension = ? and formId = ?", queryCondition); + } +} + +void BundleActiveUsageDatabase::LoadModuleData(const int32_t userId, std::map>& moduleRecords) +{ + lock_guard lock(databaseMutex_); + string queryModuleSql = "select * from " + moduleRecordsTableName_ + " where userId = ?"; + vector queryCondition; + queryCondition.emplace_back(userId); + unique_ptr moduleRecordResult = QueryStatsInfoByStep(APP_GROUP_DATABASE_INDEX, queryModuleSql, + queryCondition); + if (!moduleRecordResult) { + return; + } + int32_t numOfModuleRecord = 0; + moduleRecordResult->GetRowCount(numOfModuleRecord); + for (int32_t i = 0; i < numOfModuleRecord; i++) { + shared_ptr oneModuleRecord = make_shared(); + moduleRecordResult->GoToRow(i); + moduleRecordResult->GetInt(USER_ID_COLUMN_INDEX, oneModuleRecord->userId_); + moduleRecordResult->GetString(BUNDLE_NAME_COLUMN_INDEX, oneModuleRecord->bundleName_); + moduleRecordResult->GetString(MODULE_NAME_COLUMN_INDEX, oneModuleRecord->moduleName_); + moduleRecordResult->GetString(MODULE_PACKAGE_COLUMN_INDEX, oneModuleRecord->modulePackage_); + moduleRecordResult->GetInt(MODULE_USED_COUNT_COLUMN_INDEX, oneModuleRecord->launchedCount_); + moduleRecordResult->GetLong(MODULE_LAST_TIME_COLUMN_INDEX, oneModuleRecord->lastModuleUsedTime_); + string combinedInfo = oneModuleRecord->bundleName_ + " " + oneModuleRecord->moduleName_ + " " + + oneModuleRecord->modulePackage_; + moduleRecords[combinedInfo] = oneModuleRecord; + } + LoadFormData(userId, moduleRecords); } void BundleActiveUsageDatabase::LoadFormData(const int32_t userId, std::map>& moduleRecords) { - // key: std::string combineInfo = bundlename + " " + modulePackage + " " + moduleName - // mock + string queryFormSql = "select * from " + formRecordsTableName_ + " where userId = ?"; + vector queryCondition; + queryCondition.emplace_back(userId); + unique_ptr formRecordResult = QueryStatsInfoByStep(APP_GROUP_DATABASE_INDEX, queryFormSql, + queryCondition); + int32_t numOfFormRecord = 0; + formRecordResult->GetRowCount(numOfFormRecord); + for (int32_t i = 0; i < numOfFormRecord; i++) { + BundleActiveFormRecord oneFormRecord; + string combinedInfo = ""; + formRecordResult->GoToRow(i); + formRecordResult->GetInt(USER_ID_COLUMN_INDEX, oneFormRecord.userId_); + formRecordResult->GetString(MODULE_COMBINED_INFO_COLUMN_INDEX, combinedInfo); + formRecordResult->GetString(FORM_NAME_COLUMN_INDEX, oneFormRecord.formName_); + formRecordResult->GetInt(FORM_DIMENSION_COLUMN_INDEX, oneFormRecord.formDimension_); + formRecordResult->GetLong(FORM_ID_COLUMN_INDEX, oneFormRecord.formId_); + formRecordResult->GetInt(FORM_COUNT_COLUMN_INDEXT, oneFormRecord.count_); + formRecordResult->GetLong(FORM_LAST_TIME_COLUMN_INDEX, oneFormRecord.formLastUsedTime_); + auto it = moduleRecords.find(combinedInfo); + if (it != moduleRecords.end() && it->second) { + it->second->formRecords_.emplace_back(oneFormRecord); + } + } } } // namespace DeviceUsageStats } // namespace OHOS diff --git a/services/packagegroup/src/bundle_active_user_history.cpp b/services/packagegroup/src/bundle_active_user_history.cpp index 6a6309a79a5346357fd106270ddfc60f9f19597d..c8f0a8b442a9b66406dee04b94871874ede682b6 100644 --- a/services/packagegroup/src/bundle_active_user_history.cpp +++ b/services/packagegroup/src/bundle_active_user_history.cpp @@ -55,7 +55,7 @@ BundleActiveUserHistory::BundleActiveUserHistory(const int64_t bootBasedTimeStam { bootBasedTimeStamp_ = bootBasedTimeStamp; screenOnTimeStamp_ = bootBasedTimeStamp; - database_.InitUsageGroupInfo(APP_GROUP_DATABASE_INDEX); + database_.InitUsageGroupDatabase(APP_GROUP_DATABASE_INDEX, false); auto bootAndScreenOnDuraton = database_.GetDurationData(); bootBasedDuration_ = bootAndScreenOnDuraton.first; ScreenOnDuration_ = bootAndScreenOnDuraton.second; diff --git a/services/packageusage/include/bundle_active_event_list.h b/services/packageusage/include/bundle_active_event_list.h index 32d3d6cb1cbc4695cdcf82e44c9d6d162ee0a9e5..6c45a576ad4b8ef7c6a7383f01cb6110fea54c8a 100644 --- a/services/packageusage/include/bundle_active_event_list.h +++ b/services/packageusage/include/bundle_active_event_list.h @@ -42,7 +42,7 @@ public: void Clear(); /* * function: Insert, insert a event to member events_. - * parameter: event + * parameters: event */ void Insert(BundleActiveEvent event); /* diff --git a/services/packageusage/include/bundle_active_form_record.h b/services/packageusage/include/bundle_active_form_record.h index cca215861eef13a1a74179644a70929f7b43d61a..ac6e07b83ec67bdb71717f8c76679ebb5df1d144 100644 --- a/services/packageusage/include/bundle_active_form_record.h +++ b/services/packageusage/include/bundle_active_form_record.h @@ -43,7 +43,7 @@ public: BundleActiveFormRecord(); /* * function: BundleActiveFormRecord, use formName, formDimension, formId, timeStamp, userId to construct object. - * parameters: formName formDimension formId timeStamp userId + * parameters: formName, formDimension, formId, timeStamp, userId */ BundleActiveFormRecord(const std::string formName, const int32_t formDimension, const int64_t formId, const int64_t timeStamp, const int32_t userId); @@ -76,7 +76,7 @@ public: } /* * function: cmp, compare two BundleActiveFormRecord. - * parameters: formRecordA formRecordB + * parameters: formRecordA, formRecordB * return: true if formRecordA.count_ > formRecordB. */ static bool cmp(const BundleActiveFormRecord& formRecordA, const BundleActiveFormRecord& formRecordB); diff --git a/services/packageusage/include/bundle_active_module_record.h b/services/packageusage/include/bundle_active_module_record.h index e3e6fe00c83f89975aee4d13ce207eb195cd6237..ef4c89cab5b836da1eea4d5f9bd919f408bf0926 100644 --- a/services/packageusage/include/bundle_active_module_record.h +++ b/services/packageusage/include/bundle_active_module_record.h @@ -50,7 +50,7 @@ public: uint32_t abilityLableId_; uint32_t abilityDescriptionId_; uint32_t abilityIconId_; - uint32_t launchedCount_; + int32_t launchedCount_; int64_t lastModuleUsedTime_; int32_t userId_; bool removed_; diff --git a/services/packageusage/include/bundle_active_period_stats.h b/services/packageusage/include/bundle_active_period_stats.h index 72646b7e92f2a14cc033e510177c86382ccefba4..2cd7951cd55899976a854a2500d35556d2b03e9a 100644 --- a/services/packageusage/include/bundle_active_period_stats.h +++ b/services/packageusage/include/bundle_active_period_stats.h @@ -58,7 +58,7 @@ public: std::shared_ptr GetOrCreateUsageStats(const std::string& bundleName); /* * function: Update, update usage statistics of specific bundle. - * parameters: bundleName longTimeTaskName timeStamp eventId abilityId + * parameters: bundleName, longTimeTaskName, timeStamp, eventId, abilityId */ void Update(const std::string bundleName, const std::string longTimeTaskName, const int64_t timeStamp, const int eventId, const std::string abilityId); diff --git a/services/packageusage/src/bundle_active_module_record.cpp b/services/packageusage/src/bundle_active_module_record.cpp index e99ce0ec7542c85505dc6274a908202582f934d0..c04937c2819f76392cb7bdfa763af7e9df0ea757 100644 --- a/services/packageusage/src/bundle_active_module_record.cpp +++ b/services/packageusage/src/bundle_active_module_record.cpp @@ -82,7 +82,7 @@ bool BundleActiveModuleRecord::Marshalling(Parcel &parcel) const parcel.WriteUint32(abilityLableId_) && parcel.WriteUint32(abilityDescriptionId_) && parcel.WriteUint32(abilityIconId_) && - parcel.WriteUint32(launchedCount_) && + parcel.WriteInt32(launchedCount_) && parcel.WriteInt64(lastModuleUsedTime_) && parcel.WriteUint32(formRecords_.size()) ) { @@ -107,7 +107,7 @@ std::shared_ptr BundleActiveModuleRecord::UnMarshallin result->abilityLableId_ = parcel.ReadUint32(); result->abilityDescriptionId_ = parcel.ReadUint32(); result->abilityIconId_ = parcel.ReadUint32(); - result->launchedCount_ = parcel.ReadUint32(); + result->launchedCount_ = parcel.ReadInt32(); result->lastModuleUsedTime_ = parcel.ReadInt64(); uint32_t size = parcel.ReadUint32(); std::shared_ptr tmp = std::make_shared(); diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp index 97e834b8a47a59e6263ff982a5169411d2867d05..441d0860d87b8341c3db7142936480aa6bb92513 100644 --- a/services/packageusage/src/bundle_active_user_service.cpp +++ b/services/packageusage/src/bundle_active_user_service.cpp @@ -21,9 +21,10 @@ namespace DeviceUsageStats { void BundleActiveUserService::Init(const int64_t timeStamp) { database_.InitDatabaseTableInfo(timeStamp); + database_.InitUsageGroupDatabase(APP_GROUP_DATABASE_INDEX, true); BUNDLE_ACTIVE_LOGI("Init called"); LoadActiveStats(timeStamp, false, false); - database_.LoadFormData(userId_, moduleRecords_); + database_.LoadModuleData(userId_, moduleRecords_); std::shared_ptr currentDailyStats = currentStats_[BundleActivePeriodStats::PERIOD_DAILY]; if (currentDailyStats != nullptr) { BundleActiveEvent startupEvent(BundleActiveEvent::STARTUP, timeStamp - ONE_SECOND_MILLISECONDS); @@ -318,12 +319,12 @@ std::vector BundleActiveUserService::QueryPackageStats return result; } int64_t truncatedEndTime = std::min(currentStats->beginTime_, endTime); - BUNDLE_ACTIVE_LOGI("Query package data in db from %{public}lld to %{public}lld, current begin %{public}lld", - beginTime, truncatedEndTime, currentStats->beginTime_); + BUNDLE_ACTIVE_LOGI("Query package data in db from %{public}lld to %{public}lld", beginTime, truncatedEndTime); result = database_.QueryDatabaseUsageStats(intervalType, beginTime, truncatedEndTime, userId); - BUNDLE_ACTIVE_LOGI("Query package data in db result size is %{public}d", - static_cast(result.size())); - PrintInMemPackageStats(intervalType); + BUNDLE_ACTIVE_LOGI("Query package data in db result size is %{public}d", static_cast(result.size())); + if (debugUserService_) { + PrintInMemPackageStats(intervalType); + } // if we need a in-memory stats, combine current stats with result from database. if (currentStats->endTime_ != 0 && endTime > currentStats->beginTime_) { BUNDLE_ACTIVE_LOGI("QueryPackageStats need in memory stats"); @@ -361,7 +362,9 @@ std::vector BundleActiveUserService::QueryEvents(const int64_ BUNDLE_ACTIVE_LOGI("Query event bundle name is %{public}s", bundleName.c_str()); result = database_.QueryDatabaseEvents(beginTime, endTime, userId, bundleName); BUNDLE_ACTIVE_LOGI("Query event data in db result size is %{public}d", result.size()); - PrintInMemEventStats(); + if (debugUserService_) { + PrintInMemEventStats(); + } // if we need a in-memory stats, combine current stats with result from database. if (currentStats->endTime_ != 0 && endTime > currentStats->beginTime_) { BUNDLE_ACTIVE_LOGI("QueryEvents need in memory stats"); @@ -462,7 +465,9 @@ void BundleActiveUserService::ReportFormEvent(const BundleActiveEvent& event) database_.RemoveFormData(userId_, event.formName_, event.formDimension_, event.formId_); NotifyStatsChanged(); } - PrintInMemFormStats(); + if (debugUserService_) { + PrintInMemFormStats(); + } } std::shared_ptr BundleActiveUserService::GetOrCreateModuleRecord(