diff --git a/interfaces/innerkits/include/bundle_active_event.h b/interfaces/innerkits/include/bundle_active_event.h index 70546da4aa0dde5e72b669449ae079427ff3d8af..2d73afd313883471be206051763eb3b4114484f6 100644 --- a/interfaces/innerkits/include/bundle_active_event.h +++ b/interfaces/innerkits/include/bundle_active_event.h @@ -61,6 +61,7 @@ public: int64_t formId_; int64_t timeStamp_; int32_t eventId_; + int32_t uid_; public: /* @@ -81,24 +82,26 @@ public: * function: BundleActiveEvent, constructor using event Id, time stamp. * parameters: eventId, bundleName. */ - BundleActiveEvent(const int32_t eventId, const std::string bundleName); + BundleActiveEvent(const int32_t eventId, const std::string bundleName, const int32_t uid = 0); /* * function: BundleActiveEvent, constructor of continuous task event. * parameters: bundleName, continuousTaskAbilityName */ - BundleActiveEvent(const std::string bundleName, const std::string continuousTaskAbilityName); + BundleActiveEvent(const std::string bundleName, const std::string continuousTaskAbilityName, + const int32_t uid = 0); /* * function: BundleActiveEvent, constructor of app ability event. * parameters: bundleName, abilityName, abilityId */ BundleActiveEvent(const std::string bundleName, const std::string abilityName, const std::string abilityId, - const std::string moduleName); + const std::string moduleName, const int32_t uid = 0); /* * function: BundleActiveEvent, constructor of form event. * parameters: bundleName, moduleName, formName, formDimension, formId, eventId */ BundleActiveEvent(const std::string bundleName, const std::string moduleName, - const std::string formName, const int32_t formDimension, const int64_t formId, const int32_t eventId); + const std::string formName, const int32_t formDimension, const int64_t formId, const int32_t eventId, + const int32_t uid = 0); void PrintEvent(const bool debug) const; /* * function: operator=, override operator =. diff --git a/interfaces/innerkits/include/bundle_active_event_stats.h b/interfaces/innerkits/include/bundle_active_event_stats.h index 5ffed9e19c7f3165b76cadf5b7e7a2e266c2b6be..b03864fd6af07ba08ad66f9b1149f9d7d8c7b78d 100644 --- a/interfaces/innerkits/include/bundle_active_event_stats.h +++ b/interfaces/innerkits/include/bundle_active_event_stats.h @@ -31,6 +31,7 @@ public: int64_t lastEventTime_; int64_t totalTime_; int32_t count_; + int32_t uid_; std::string name_; /* diff --git a/interfaces/innerkits/include/bundle_active_form_record.h b/interfaces/innerkits/include/bundle_active_form_record.h index ca105b68f6b60b6986aeeb19e2e07f776fdce701..d398e369bcaad0f758ff71ee71059073aff4d200 100644 --- a/interfaces/innerkits/include/bundle_active_form_record.h +++ b/interfaces/innerkits/include/bundle_active_form_record.h @@ -31,6 +31,7 @@ public: int64_t formLastUsedTime_; int32_t count_; int32_t userId_; + int32_t uid_; public: /* @@ -47,7 +48,7 @@ public: * 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); + const int64_t timeStamp, const int32_t userId, const int32_t uid); /* * function: ~BundleActiveFormRecord, default destructor. */ diff --git a/interfaces/innerkits/include/bundle_active_module_record.h b/interfaces/innerkits/include/bundle_active_module_record.h index 98f1701299d35f92332184b845e85572dd91706e..ba7246994681c155dd4602a3c13feee9016d2fc2 100644 --- a/interfaces/innerkits/include/bundle_active_module_record.h +++ b/interfaces/innerkits/include/bundle_active_module_record.h @@ -23,7 +23,7 @@ namespace DeviceUsageStats { class BundleActiveModuleRecord : public Parcelable { public: void AddOrUpdateOneFormRecord(const std::string formName, const int32_t formDimension, - const int64_t formId, const int64_t timeStamp); + const int64_t formId, const int64_t timeStamp, const int32_t uid); void RemoveOneFormRecord(const std::string formName, const int32_t formDimension, const int64_t formId); void UpdateModuleRecord(int64_t timeStamp); @@ -48,6 +48,7 @@ public: int32_t launchedCount_; int64_t lastModuleUsedTime_; int32_t userId_; + int32_t uid_; bool removed_; bool installFreeSupported_; bool isNewAdded_; diff --git a/interfaces/innerkits/include/bundle_active_package_stats.h b/interfaces/innerkits/include/bundle_active_package_stats.h index b5dc0ced1959abd1fbc3f5c4cec528f0e282e136..26d37be34052c07bb0b9b54dfd286680acd25067 100644 --- a/interfaces/innerkits/include/bundle_active_package_stats.h +++ b/interfaces/innerkits/include/bundle_active_package_stats.h @@ -37,6 +37,7 @@ public: int32_t bundleStartedCount_; int32_t lastEvent_; int32_t userId_; + int32_t uid_; // key is abilityId, value is the last event of this ability. Restore all abilities' last event of bundle. std::map abilities_; // key is name of continuous task, value is last event of this last continuous task. @@ -59,7 +60,7 @@ public: * parameters: longTimeTaskName timeStamp eventId abilityId */ void Update(const std::string& longTimeTaskName, const int64_t timeStamp, const int32_t eventId, - const std::string& abilityId); + const std::string& abilityId, const int32_t uid); /* * function: IncrementTimeUsed, increase bundle's use time. * parameters: timeStamp diff --git a/interfaces/innerkits/src/bundle_active_event.cpp b/interfaces/innerkits/src/bundle_active_event.cpp index 5b45e4659b094b1e57eeb9657a5250f0ef5fa06b..3137bda16e4c96164230dcce78d142d72c529b4b 100644 --- a/interfaces/innerkits/src/bundle_active_event.cpp +++ b/interfaces/innerkits/src/bundle_active_event.cpp @@ -30,6 +30,7 @@ BundleActiveEvent::BundleActiveEvent() formDimension_ = 0; timeStamp_ = 0; eventId_ = DEFAULT_EVENT_ID; + uid_ = 0; } BundleActiveEvent::BundleActiveEvent (const BundleActiveEvent& orig) @@ -44,6 +45,7 @@ BundleActiveEvent::BundleActiveEvent (const BundleActiveEvent& orig) formDimension_ = orig.formDimension_; timeStamp_ = orig.timeStamp_; eventId_ = orig.eventId_; + uid_ = orig.uid_; } BundleActiveEvent::BundleActiveEvent(int32_t eventId, int64_t timeStamp) @@ -58,9 +60,10 @@ BundleActiveEvent::BundleActiveEvent(int32_t eventId, int64_t timeStamp) formId_ = 0; timeStamp_ = timeStamp; eventId_ = eventId; + uid_ = 0; } -BundleActiveEvent::BundleActiveEvent(const int32_t eventId, const std::string bundleName) +BundleActiveEvent::BundleActiveEvent(const int32_t eventId, const std::string bundleName, const int32_t uid) { bundleName_ = bundleName; continuousTaskAbilityName_.clear(); @@ -72,9 +75,11 @@ BundleActiveEvent::BundleActiveEvent(const int32_t eventId, const std::string bu formId_ = 0; timeStamp_ = 0; eventId_ = eventId; + uid_ = uid; } -BundleActiveEvent::BundleActiveEvent(const std::string bundleName, const std::string continuousTaskAbilityName) +BundleActiveEvent::BundleActiveEvent(const std::string bundleName, const std::string continuousTaskAbilityName, + const int32_t uid) { bundleName_ = bundleName; continuousTaskAbilityName_ = continuousTaskAbilityName; @@ -86,10 +91,11 @@ BundleActiveEvent::BundleActiveEvent(const std::string bundleName, const std::st formId_ = 0; timeStamp_ = 0; eventId_ = DEFAULT_EVENT_ID; + uid_ = uid; } BundleActiveEvent::BundleActiveEvent(const std::string bundleName, const std::string abilityName, - const std::string abilityId, const std::string moduleName) + const std::string abilityId, const std::string moduleName, const int32_t uid) { bundleName_ = bundleName; continuousTaskAbilityName_.clear(); @@ -101,11 +107,12 @@ BundleActiveEvent::BundleActiveEvent(const std::string bundleName, const std::st formId_ = 0; timeStamp_ = 0; eventId_ = DEFAULT_EVENT_ID; + uid_ = uid; } BundleActiveEvent::BundleActiveEvent(const std::string bundleName, const std::string moduleName, const std::string formName, const int32_t formDimension, - const int64_t formId, const int32_t eventId) + const int64_t formId, const int32_t eventId, const int32_t uid) { bundleName_ = bundleName; continuousTaskAbilityName_.clear(); @@ -117,6 +124,7 @@ BundleActiveEvent::BundleActiveEvent(const std::string bundleName, const std::st formId_ = formId; timeStamp_ = 0; eventId_ = eventId; + uid_ = uid; } BundleActiveEvent& BundleActiveEvent::operator=(const BundleActiveEvent& orig) @@ -131,6 +139,7 @@ BundleActiveEvent& BundleActiveEvent::operator=(const BundleActiveEvent& orig) formId_ = orig.formId_; timeStamp_ = orig.timeStamp_; eventId_ = orig.eventId_; + uid_ = orig.uid_; return *this; } @@ -140,10 +149,10 @@ void BundleActiveEvent::PrintEvent(const bool debug) const return; } BUNDLE_ACTIVE_LOGI("bundle name is %{public}s, ability name is %{public}s, continue task ability is %{public}s, " - "module name is %{public}s, " - "form name is %{public}s, form dimension is %{public}d, form id is %{public}lld, event id is %{public}d", + "module name is %{public}s, form name is %{public}s, form dimension is %{public}d, " + "form id is %{public}lld, event id is %{public}d, uid is %{public}d", bundleName_.c_str(), abilityName_.c_str(), continuousTaskAbilityName_.c_str(), moduleName_.c_str(), - formName_.c_str(), formDimension_, (long long)formId_, eventId_); + formName_.c_str(), formDimension_, (long long)formId_, eventId_, uid_); } bool BundleActiveEvent::Marshalling(Parcel &parcel) const @@ -157,7 +166,8 @@ bool BundleActiveEvent::Marshalling(Parcel &parcel) const parcel.WriteInt32(formDimension_) && parcel.WriteInt64(formId_) && parcel.WriteInt64(timeStamp_) && - parcel.WriteInt32(eventId_)) { + parcel.WriteInt32(eventId_) && + parcel.WriteInt32(uid_)) { return true; } return false; @@ -176,12 +186,13 @@ std::shared_ptr BundleActiveEvent::UnMarshalling(Parcel &parc result->formId_ = parcel.ReadInt64(); result->timeStamp_ = parcel.ReadInt64(); result->eventId_ = parcel.ReadInt32(); + result->uid_ = parcel.ReadInt32(); return result; } std::string BundleActiveEvent::ToString() { - return "bundle name is " + this->bundleName_ + ", event is " + + return "bundle name is " + this->bundleName_ + "uid is " + std::to_string(this->uid_)+ ", event is " + std::to_string(this->eventId_) + ", timestamp is " + std::to_string(this->timeStamp_) + "\n"; } diff --git a/interfaces/innerkits/src/bundle_active_event_stats.cpp b/interfaces/innerkits/src/bundle_active_event_stats.cpp index 739019ed9d22f32d952c630ee17ab86310a4932c..4cdb0fc5ceae9ee53b8f50d5881add3b84834370 100644 --- a/interfaces/innerkits/src/bundle_active_event_stats.cpp +++ b/interfaces/innerkits/src/bundle_active_event_stats.cpp @@ -25,6 +25,7 @@ BundleActiveEventStats::BundleActiveEventStats() lastEventTime_ = 0; totalTime_ = 0; count_ = 0; + uid_ = 0; name_.clear(); } @@ -37,6 +38,7 @@ BundleActiveEventStats::BundleActiveEventStats(const BundleActiveEventStats& ori totalTime_ = orig.totalTime_; count_ = orig.count_; name_ = orig.name_; + uid_ = orig.uid_; } int32_t BundleActiveEventStats::GetEventId() @@ -92,7 +94,8 @@ bool BundleActiveEventStats::Marshalling(Parcel &parcel) const parcel.WriteInt64(lastEventTime_) && parcel.WriteInt64(totalTime_) && parcel.WriteInt32(count_) && - parcel.WriteString(name_)) { + parcel.WriteString(name_) && + parcel.WriteInt32(uid_)) { return true; } return false; @@ -108,6 +111,7 @@ std::shared_ptr BundleActiveEventStats::UnMarshalling(Pa result->totalTime_ = parcel.ReadInt64(); result->count_ = parcel.ReadInt32(); result->name_ = parcel.ReadString(); + result->uid_ = parcel.ReadInt32(); return result; } } // namespace DeviceUsageStats diff --git a/interfaces/innerkits/src/bundle_active_form_record.cpp b/interfaces/innerkits/src/bundle_active_form_record.cpp index 3ef3c59e2e842ba5be6ce3d3a67d09b45cfb031f..e32d270ad8ffe08ad6ba68eafbabc9a028432f60 100644 --- a/interfaces/innerkits/src/bundle_active_form_record.cpp +++ b/interfaces/innerkits/src/bundle_active_form_record.cpp @@ -25,10 +25,11 @@ BundleActiveFormRecord::BundleActiveFormRecord() formLastUsedTime_ = -1; count_ = 0; userId_ = -1; + uid_ = 0; } BundleActiveFormRecord::BundleActiveFormRecord(const std::string formName, const int32_t formDimension, - const int64_t formId, const int64_t timeStamp, const int32_t userId) + const int64_t formId, const int64_t timeStamp, const int32_t userId, const int32_t uid) { formName_ = formName; formDimension_ = formDimension; @@ -36,6 +37,7 @@ BundleActiveFormRecord::BundleActiveFormRecord(const std::string formName, const formLastUsedTime_ = timeStamp; count_ = 1; userId_ = userId; + uid_ = uid; } BundleActiveFormRecord::BundleActiveFormRecord(const BundleActiveFormRecord& orig) @@ -90,6 +92,7 @@ std::string BundleActiveFormRecord::ToString() return "form name is " + this->formName_ + ", form dimension is " + std::to_string(this->formDimension_) + ", form id is " + std::to_string(this->formId_) + + ", uid id is " + std::to_string(this->uid_) + ", last used time stamp is" + std::to_string(this->formLastUsedTime_) + ", touch count is " + std::to_string(this->count_) + "\n"; } diff --git a/interfaces/innerkits/src/bundle_active_module_record.cpp b/interfaces/innerkits/src/bundle_active_module_record.cpp index 4d6b4ca6f0e9860db96b1408721b6f7c40ea4696..b46612737e48ddefbfeadfcebd30679ffde4b08b 100644 --- a/interfaces/innerkits/src/bundle_active_module_record.cpp +++ b/interfaces/innerkits/src/bundle_active_module_record.cpp @@ -21,9 +21,9 @@ namespace { static const int32_t MAX_FORM_NUM = 1000; } void BundleActiveModuleRecord::AddOrUpdateOneFormRecord(const std::string formName, const int32_t formDimension, - const int64_t formId, const int64_t timeStamp) + const int64_t formId, const int64_t timeStamp, const int32_t uid) { - BundleActiveFormRecord newFormRecord(formName, formDimension, formId, timeStamp, userId_); + BundleActiveFormRecord newFormRecord(formName, formDimension, formId, timeStamp, userId_, uid); for (auto& formRecord : formRecords_) { if (formRecord == newFormRecord) { formRecord.UpdateFormRecord(timeStamp); @@ -70,6 +70,7 @@ BundleActiveModuleRecord::BundleActiveModuleRecord() installFreeSupported_ = false; isNewAdded_ = false; userId_ = -1; + uid_ = 0; } bool BundleActiveModuleRecord::Marshalling(Parcel &parcel) const @@ -85,7 +86,8 @@ bool BundleActiveModuleRecord::Marshalling(Parcel &parcel) const parcel.WriteUint32(abilityIconId_) && parcel.WriteInt32(launchedCount_) && parcel.WriteInt64(lastModuleUsedTime_) && - parcel.WriteUint32(formRecords_.size()) + parcel.WriteUint32(formRecords_.size()) && + parcel.WriteInt32(uid_) ) { for (auto formRecord : formRecords_) { formRecord.Marshalling(parcel); @@ -110,6 +112,7 @@ std::shared_ptr BundleActiveModuleRecord::UnMarshallin result->launchedCount_ = parcel.ReadInt32(); result->lastModuleUsedTime_ = parcel.ReadInt64(); uint32_t size = parcel.ReadUint32(); + result->uid_ = parcel.ReadInt32(); if (size > MAX_FORM_NUM) { return nullptr; } @@ -134,6 +137,7 @@ std::string BundleActiveModuleRecord::ToString() { return "bundle name is " + this->bundleName_ + ", module name is " + this->moduleName_ + + ", uid is " + std::to_string(this->uid_) + ", last used time stamp is " + std::to_string(this->lastModuleUsedTime_) + ", module is used for " + std::to_string(this->launchedCount_) + " times\n"; } diff --git a/interfaces/innerkits/src/bundle_active_package_stats.cpp b/interfaces/innerkits/src/bundle_active_package_stats.cpp index 4dd4a45e0a3ee86d57f2b9a515995fef07afc22b..e069b458f094839b532eaa43b75d2502a621afca 100644 --- a/interfaces/innerkits/src/bundle_active_package_stats.cpp +++ b/interfaces/innerkits/src/bundle_active_package_stats.cpp @@ -31,6 +31,7 @@ BundleActivePackageStats::BundleActivePackageStats() bundleStartedCount_ = 0; lastEvent_ = 0; userId_ = 0; + uid_ = 0; } BundleActivePackageStats::BundleActivePackageStats (const BundleActivePackageStats& orig) @@ -48,6 +49,7 @@ BundleActivePackageStats::BundleActivePackageStats (const BundleActivePackageSta longTimeTasks_ = orig.longTimeTasks_; lastEvent_ = orig.lastEvent_; userId_ = orig.userId_; + uid_ = orig.uid_; } bool BundleActivePackageStats::HasFrontAbility() @@ -169,7 +171,7 @@ void BundleActivePackageStats::UpdateLongTimeTask(const std::string& longTimeTas } void BundleActivePackageStats::Update(const std::string& longTimeTaskName, const int64_t timeStamp, - const int32_t eventId, const std::string& abilityId) + const int32_t eventId, const std::string& abilityId, const int32_t uid) { switch (eventId) { case BundleActiveEvent::ABILITY_FOREGROUND: diff --git a/services/common/include/bundle_active_constant.h b/services/common/include/bundle_active_constant.h index fed87fa24e8299c484fb80e4421e519831b64ca2..55321c981c9c3cba2b759fa32eff6f4d65110d28 100644 --- a/services/common/include/bundle_active_constant.h +++ b/services/common/include/bundle_active_constant.h @@ -23,6 +23,7 @@ namespace DeviceUsageStats { const int32_t DURATION_TABLE_ROW_NUMBER = 1; const int32_t TABLE_ROW_ZERO = 0; const int32_t SORTED_TABLE_ARRAY_NUMBER = 4; +const int32_t ALL_TABLE_ARRAY_NUMBER = 6; const int32_t NO_UPDATE_ROW = 0; const int32_t NO_DELETE_ROW = 0; const int32_t EVENT_TABLE_NUMBER = 1; @@ -34,7 +35,8 @@ const int32_t MONTHLY_DATABASE_INDEX = 2; const int32_t YEARLY_DATABASE_INDEX = 3; const int32_t EVENT_DATABASE_INDEX = 4; const int32_t APP_GROUP_DATABASE_INDEX = 5; -const int32_t BUNDLE_ACTIVE_CURRENT_VERSION = 1; +const int32_t BUNDLE_ACTIVE_VERSION_V1 = 1; +const int32_t BUNDLE_ACTIVE_CURRENT_VERSION = 2; const int32_t BUNDLE_ACTIVE_SUCCESS = 0; const int32_t BUNDLE_ACTIVE_FAIL = -1; const int32_t BUNDLE_ACTIVE_RDB_VERSION = 1; @@ -48,26 +50,31 @@ const int32_t LAST_TIME_COLUMN_INDEX = 3; const int32_t LAST_TIME_CONTINUOUS_TASK_COLUMN_INDEX = 4; const int32_t TOTAL_TIME_COLUMN_INDEX = 5; const int32_t TOTAL_TIME_CONTINUOUS_TASK_COLUMN_INDEX = 6; +const int32_t PACKAGE_LOG_UID_COLUMN_INDEX = 7; const int32_t EVENT_ID_COLUMN_INDEX = 2; const int32_t TIME_STAMP_COLUMN_INDEX = 3; const int32_t ABILITY_ID_COLUMN_INDEX = 4; +const int32_t EVENT_UID_COLUMN_INDEX = 5; const int32_t LAST_BOOT_FROM_USED_TIME_COLUMN_INDEX = 2; const int32_t LAST_SCREEN_USED_TIME_COLUMN_INDEX = 3; const int32_t CURRENT_GROUP_COLUMN_INDEX = 4; const int32_t REASON_IN_GROUP_COLUMN_INDEX = 5; const int32_t BUNDLE_ALIVE_TIMEOUT_TIME_COLUMN_INDEX = 6; const int32_t BUNDLE_DAILY_TIMEOUT_TIME_COLUMN_INDEX = 7; +const int32_t BUNDLE_HISTORY_LOG_UID_COLUMN_INDEX = 8; const int32_t BOOT_BASED_DURATION_COLUMN_INDEX = 0; const int32_t SCREEN_ON_DURATION_COLUMN_INDEX = 1; const int32_t DURATION_FLAG_COLUMN_INDEX = 2; const int32_t MODULE_NAME_COLUMN_INDEX = 2; const int32_t MODULE_USED_COUNT_COLUMN_INDEX = 3; const int32_t MODULE_LAST_TIME_COLUMN_INDEX = 4; +const int32_t MODULE_UID_COLUMN_INDEX = 5; const int32_t FORM_NAME_COLUMN_INDEX = 3; const int32_t FORM_DIMENSION_COLUMN_INDEX = 4; const int32_t FORM_ID_COLUMN_INDEX = 5; const int32_t FORM_COUNT_COLUMN_INDEX = 6; const int32_t FORM_LAST_TIME_COLUMN_INDEX = 7; +const int32_t FORM_UID_COLUMN_INDEX = 8; const int32_t QUERY_CONDITION_VALID = 0; const int32_t QUERY_CONDITION_INVALID = -1; const int64_t TWO_SECONDS = 2 * 1000LL; @@ -121,6 +128,9 @@ const std::string BUNDLE_ACTIVE_DB_BUNDLE_ALIVE_TIMEOUT_TIME = "bundleAliveTimeo const std::string BUNDLE_ACTIVE_DB_BUNDLE_DAILY_TIMEOUT_TIME = "bundleDailyTimeoutTime"; const std::string BUNDLE_ACTIVE_DB_BOOT_BASED_DURATION = "bootBasedDuration"; const std::string BUNDLE_ACTIVE_DB_SCREEN_ON_DURATION = "screenOnDuration"; +const std::string RDB_STORE_COLUMN_TYPE_INT = "INTERGER"; +const std::string BUNDLE_ACTIVE_DB_UID = "uid"; + const std::string REFRESH_DATABASE_RUNNER_NAME = "RefreshDatabase"; const std::string BUNDLE_ACTIVE_DATABASE_DIR = "/data/service/el1/public/bundle_usage/"; const std::string BUNDLE_ACTIVE_VERSION_FILE = "/version"; diff --git a/services/common/include/bundle_active_core.h b/services/common/include/bundle_active_core.h index fbb1b05cb3a16d6d40bf26619a09dded8c184fbe..07b2cef1efb7b2c4c36b1cfbaee57a2109d5c8d0 100644 --- a/services/common/include/bundle_active_core.h +++ b/services/common/include/bundle_active_core.h @@ -51,6 +51,8 @@ public: BundleActiveEvent event_; int32_t userId_; std::string bundleName_; + int32_t uid_ = 0; + int32_t appIndex_ = 0; BundleActiveReportHandlerObject(); BundleActiveReportHandlerObject(const int32_t userId, const std::string bundleName); BundleActiveReportHandlerObject(const BundleActiveReportHandlerObject& orig); @@ -107,7 +109,8 @@ public: * BundleActiveCommonEventSubscriber call it to remove data. * parameters: userId, bundleName */ - void OnBundleUninstalled(const int32_t userId, const std::string& bundleName); + void OnBundleUninstalled(const int32_t userId, const std::string& bundleName, const int32_t uid, + const int32_t appIndex); /* * function: Init, BundleAciveService call it to init systemTimeShot_, realTimeShot_, diff --git a/services/common/include/bundle_active_usage_database.h b/services/common/include/bundle_active_usage_database.h index 53cae81322600afc58da926fb8d00d0156102af4..111a5010a02650134aa6f178a4d9ade4d90c539e 100644 --- a/services/common/include/bundle_active_usage_database.h +++ b/services/common/include/bundle_active_usage_database.h @@ -63,13 +63,14 @@ public: std::shared_ptr>> userHistory); std::shared_ptr>> GetBundleHistoryData(int32_t userId); - void OnPackageUninstalled(const int32_t userId, const std::string& bundleName); + void OnPackageUninstalled(const int32_t userId, const std::string& bundleName, + const int32_t uid, const int32_t appIndex); void ChangeToDebug(); void UpdateModuleData(const int32_t userId, std::map>& moduleRecords, const int64_t timeStamp); void RemoveFormData(const int32_t userId, const std::string bundleName, const std::string moduleName, const std::string formName, const int32_t formDimension, - const int64_t formId); + const int64_t formId, const int32_t uid); void LoadModuleData(const int32_t userId, std::map>& moduleRecords); void LoadFormData(const int32_t userId, std::map QueryStatsInfoByStep(uint32_t databaseType, const std::string &sql, const std::vector &selectionArgs); - void DeleteUninstalledInfo(const int32_t userId, const std::string& bundleName, const std::string& tableName, - uint32_t databaseType); + void DeleteUninstalledInfo(const int32_t userId, const std::string& bundleName, const int32_t uid, + const std::string& tableName, uint32_t databaseType, const int32_t appIndex); int32_t CreateDatabasePath(); int64_t GetSystemTimeMs(); void CheckDatabaseFile(uint32_t databaseType); @@ -125,6 +126,16 @@ private: const int32_t databaseType, int32_t &startIndex, int32_t &endIndex); private: + int32_t GetOldDbVersion(); + int32_t GetVersionByFileInput(const std::string& FileVersionInput); + void createRecordTable(const int64_t timeStamp); + void HandleAllTableName(const uint32_t databaseType, std::vector>& allTableName); + void UpgradleDatabase(const int32_t oldVersion, const int32_t curVersion); + void UpdateOldDataUid(const std::shared_ptr store, const std::string& tableName, + const int32_t userId, std::map& bundleNameUidMap); + void SupportAppTwin(); + void AddRdbColumn(const std::shared_ptr store, const std::string& tableName, + const std::string& columnName, const std::string& columnType); std::vector databaseFiles_; std::vector> sortedTableArray_; std::map> bundleActiveRdbStoreCache_; diff --git a/services/common/src/bundle_active_app_state_obsever.cpp b/services/common/src/bundle_active_app_state_obsever.cpp index 739326c695f69e0b1705f053360d9f05831658eb..2040c862d59638ac3a06ba9c306d4b053a420ba5 100644 --- a/services/common/src/bundle_active_app_state_obsever.cpp +++ b/services/common/src/bundle_active_app_state_obsever.cpp @@ -47,7 +47,7 @@ void BundleActiveAppStateObserver::OnAbilityStateChanged(const AbilityStateData stream << abilityStateData.token.GetRefPtr(); BundleActiveReportHandlerObject tmpHandlerObject(userId, ""); BundleActiveEvent event(abilityStateData.bundleName, abilityStateData.abilityName, - abilityStateData.abilityName, abilityStateData.moduleName); + abilityStateData.abilityName, abilityStateData.moduleName, abilityStateData.uid); tmpHandlerObject.event_ = event; sptr timer = MiscServices::TimeServiceClient::GetInstance(); tmpHandlerObject.event_.timeStamp_ = timer->GetBootTimeMs(); diff --git a/services/common/src/bundle_active_continuous_task_observer.cpp b/services/common/src/bundle_active_continuous_task_observer.cpp index 9abc437b283d982396cd060e28167ffa839604fa..08a779a9b2a69c75eeb4e0a4bb8b519c246923c6 100644 --- a/services/common/src/bundle_active_continuous_task_observer.cpp +++ b/services/common/src/bundle_active_continuous_task_observer.cpp @@ -96,7 +96,7 @@ void BundleActiveContinuousTaskObserver::ReportContinuousTaskEvent( OHOS::ErrCode ret = BundleActiveAccountHelper::GetUserId(uid, userId); if (ret == ERR_OK && userId != -1 && !bundleName.empty()) { BundleActiveReportHandlerObject tmpHandlerObject(userId, ""); - BundleActiveEvent event(bundleName, continuousTaskAbilityName_); + BundleActiveEvent event(bundleName, continuousTaskAbilityName_, uid); sptr timer = MiscServices::TimeServiceClient::GetInstance(); tmpHandlerObject.event_ = event; tmpHandlerObject.event_.timeStamp_ = timer->GetBootTimeMs(); diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index d1001351c2bd90edf011e10a69d1203abd0f7f80..ec7694c7b23794f369f4a8d52939175d8c4308f1 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -47,6 +47,8 @@ BundleActiveReportHandlerObject::BundleActiveReportHandlerObject(const BundleAct event_ = orig.event_; userId_ = orig.userId_; bundleName_ = orig.bundleName_; + uid_ = orig.uid_; + appIndex_ = orig.appIndex_; } BundleActiveCore::BundleActiveCore() @@ -105,6 +107,8 @@ void BundleActiveCommonEventSubscriber::OnReceiveEvent(const CommonEventData &da action.c_str(), userId, bundleName.c_str()); if (!bundleActiveReportHandler_.expired()) { BundleActiveReportHandlerObject tmpHandlerObject(userId, bundleName); + tmpHandlerObject.uid_ = data.GetWant().GetIntParam("uid", 0); + tmpHandlerObject.appIndex_ = data.GetWant().GetIntParam("appIndex", -1); std::shared_ptr handlerobjToPtr = std::make_shared(tmpHandlerObject); auto event = AppExecFwk::InnerEvent::Get(BundleActiveReportHandler::MSG_BUNDLE_UNINSTALLED, @@ -232,7 +236,8 @@ std::shared_ptr WEAK_FUNC BundleActiveCore::GetUserData return it->second; } -void BundleActiveCore::OnBundleUninstalled(const int32_t userId, const std::string& bundleName) +void BundleActiveCore::OnBundleUninstalled(const int32_t userId, const std::string& bundleName, + const int32_t uid, const int32_t appIndex) { BUNDLE_ACTIVE_LOGD("OnBundleUninstalled CALLED"); std::lock_guard lock(mutex_); @@ -244,8 +249,8 @@ void BundleActiveCore::OnBundleUninstalled(const int32_t userId, const std::stri if (service == nullptr) { return; } - service->DeleteUninstalledBundleStats(bundleName); - bundleGroupController_->OnBundleUninstalled(userId, bundleName); + service->DeleteUninstalledBundleStats(bundleName, uid, appIndex); + bundleGroupController_->OnBundleUninstalled(userId, bundleName, uid, appIndex); } void BundleActiveCore::OnStatsChanged(const int32_t userId) diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp index a910551c98c63f3f8f288bcebb5300a79aeb5a71..85b971ea2bd9d65a06731ba6fed9a2758b9e596f 100644 --- a/services/common/src/bundle_active_usage_database.cpp +++ b/services/common/src/bundle_active_usage_database.cpp @@ -34,6 +34,8 @@ #include "bundle_active_binary_search.h" #include "bundle_active_period_stats.h" #include "bundle_active_usage_database.h" +#include "bundle_active_bundle_mgr_helper.h" +#include "bundle_active_account_helper.h" namespace OHOS { namespace DeviceUsageStats { @@ -41,6 +43,7 @@ using namespace OHOS::NativeRdb; using namespace std; namespace { const int32_t MAX_FILES_EVERY_INTERVAL_TYPE[SORTED_TABLE_ARRAY_NUMBER] = {30, 30, 12, 10}; + const int32_t FILE_VERSION_LINE_NUM = 50; } BundleActiveUsageDatabase::BundleActiveUsageDatabase() { @@ -266,6 +269,39 @@ void BundleActiveUsageDatabase::HandleTableInfo(uint32_t databaseType) } } +void BundleActiveUsageDatabase::HandleAllTableName(const uint32_t databaseType, + std::vector>& allTableName) +{ + string queryDatabaseTableNames = "select * from sqlite_master where type = ?"; + vector queryCondition; + queryCondition.push_back(DATABASE_FILE_TABLE_NAME); + auto bundleActiveResult = QueryStatsInfoByStep(databaseType, + queryDatabaseTableNames, queryCondition); + if (bundleActiveResult == nullptr) { + BUNDLE_ACTIVE_LOGE("bundleActiveResult is invalid"); + return; + } + int32_t tableNumber; + bundleActiveResult->GetRowCount(tableNumber); + if (tableNumber == TABLE_NOT_EXIST) { + BUNDLE_ACTIVE_LOGE("table not exist"); + return; + } + int32_t tableNameIndex; + bundleActiveResult->GetColumnIndex(SQLITE_MASTER_NAME, tableNameIndex); + if (databaseType >= 0 && databaseType < sortedTableArray_.size()) { + if (!allTableName.at(databaseType).empty()) { + allTableName.at(databaseType).clear(); + } + for (int32_t i = 0; i < tableNumber; i++) { + string tableName; + bundleActiveResult->GoToRow(i); + bundleActiveResult->GetString(tableNameIndex, tableName); + allTableName.at(databaseType).push_back(tableName); + } + } +} + void BundleActiveUsageDatabase::DeleteExcessiveTableData(uint32_t databaseType) { if (databaseType >= 0 && databaseType < SORTED_TABLE_ARRAY_NUMBER) { @@ -400,6 +436,10 @@ int64_t BundleActiveUsageDatabase::ParseStartTime(const string &tableName) void BundleActiveUsageDatabase::CheckDatabaseVersion() { if (access(BUNDLE_ACTIVE_DATABASE_DIR.c_str(), F_OK) == 0) { + int32_t oldVersion = GetOldDbVersion(); + if (oldVersion != BUNDLE_ACTIVE_FAIL && oldVersion < BUNDLE_ACTIVE_CURRENT_VERSION) { + UpgradleDatabase(oldVersion, BUNDLE_ACTIVE_CURRENT_VERSION); + } ofstream openVersionFile; openVersionFile.open(BUNDLE_ACTIVE_VERSION_DIRECTORY_PATH, ios::out); if (openVersionFile) { @@ -409,6 +449,124 @@ void BundleActiveUsageDatabase::CheckDatabaseVersion() } } +int32_t BundleActiveUsageDatabase::GetOldDbVersion() +{ + int32_t oldVersion = -1; + if (access(BUNDLE_ACTIVE_DATABASE_DIR.c_str(), F_OK) == 0) { + ifstream openVersionFile; + openVersionFile.open(BUNDLE_ACTIVE_VERSION_DIRECTORY_PATH, ios::in); + if (openVersionFile) { + char str[FILE_VERSION_LINE_NUM] = {0}; + openVersionFile.getline(str, FILE_VERSION_LINE_NUM); + oldVersion = GetVersionByFileInput(str); + } + openVersionFile.close(); + } + return oldVersion; +} + +int32_t BundleActiveUsageDatabase::GetVersionByFileInput(const std::string& FileVersionInput) +{ + if (FileVersionInput.empty()) { + return BUNDLE_ACTIVE_FAIL; + } + string databaseVersion = FileVersionInput; + for (uint32_t i = 0; i < databaseVersion.length(); i++) { + if (databaseVersion[i] >= '0' && databaseVersion[i] <= '9') { + databaseVersion = databaseVersion.substr(i); + break; + } + } + return atoi(databaseVersion.c_str()); +} + +void BundleActiveUsageDatabase::UpgradleDatabase(const int32_t oldVersion, const int32_t curVersion) +{ + BUNDLE_ACTIVE_LOGI("upgradle database oldVersion: %{public}d, curVersion: %{public}d", oldVersion, curVersion); + if (oldVersion < curVersion && curVersion == BUNDLE_ACTIVE_CURRENT_VERSION) { + if (oldVersion == BUNDLE_ACTIVE_VERSION_V1) { + SupportAppTwin(); + } + } +} + +void BundleActiveUsageDatabase::SupportAppTwin() +{ + vector> allTableName = vector>(ALL_TABLE_ARRAY_NUMBER); + for (uint32_t i = 0; i bundleNameUidMap; + vector activatedOsAccountIds; + BundleActiveAccountHelper::GetActiveUserId(activatedOsAccountIds); + for (uint32_t i = 0; i < allTableName.size(); i++) { + auto tableNames = allTableName.at(i); + BUNDLE_ACTIVE_LOGI("tableNames size %{public}lu", tableNames.size()); + shared_ptr rdbStore = GetBundleActiveRdbStore(i); + if (!rdbStore) { + BUNDLE_ACTIVE_LOGI("get RdbStore fail, databaseType: %{public}u", i); + continue; + } + for (string tableName: tableNames) { + if (DURATION_LOG_TABLE == tableName) { + continue; + } + AddRdbColumn(rdbStore, tableName, BUNDLE_ACTIVE_DB_UID, RDB_STORE_COLUMN_TYPE_INT); + for (auto userId: activatedOsAccountIds) { + UpdateOldDataUid(rdbStore, tableName, userId, bundleNameUidMap); + } + } + } +} + +void BundleActiveUsageDatabase::AddRdbColumn(const shared_ptr store, + const string& tableName, const string& columnName, const string& columnType) +{ + string sqlStr = ""; + if (columnType == RDB_STORE_COLUMN_TYPE_INT) { + sqlStr = "ALTER TABLE" + tableName + " ADD " + columnName + " " + columnType + " NOT NULL DEFAULT 0"; + } + store->ExecuteSql(sqlStr); +} + +void BundleActiveUsageDatabase::UpdateOldDataUid(const shared_ptr store, + const string& tableName, const int32_t userId, map& bundleNameUidMap) +{ + vector queryCondition; + string querySql = "select * from " + tableName; + shared_ptr bundleActiveResult; + bundleActiveResult = store->QueryByStep(querySql); + int32_t tableRowNumber = 0; + bundleActiveResult->GetRowCount(tableRowNumber); + string bundleName; + int32_t uid; + int32_t changeRow = BUNDLE_ACTIVE_FAIL; + NativeRdb::ValuesBucket valuesBucket; + for (int32_t i = 0; i < tableRowNumber; i++) { + bundleActiveResult->GoToRow(i); + bundleActiveResult->GetString(BUNDLE_NAME_COLUMN_INDEX, bundleName); + AppExecFwk::ApplicationInfo appInfo; + string bundleNameUserIdKey = bundleName + to_string(userId); + auto it = bundleNameUidMap.find(bundleNameUserIdKey); + if (it == bundleNameUidMap.end()) { + BundleActiveBundleMgrHelper::GetInstance()->GetApplicationInfo(bundleName, + AppExecFwk::ApplicationFlag::GET_BASIC_APPLICATION_INFO, userId, appInfo); + uid = appInfo.uid; + bundleNameUidMap[bundleNameUserIdKey] = uid; + } else { + uid = it->second; + } + queryCondition.push_back(to_string(userId)); + queryCondition.push_back(bundleName); + valuesBucket.PutInt(BUNDLE_ACTIVE_DB_UID, uid); + store->update(changeRow, tableName, valuesBucket, "userId = ? and bundleName = ?", queryCondition); + queryCondition.clear(); + valuesBucket.Clear(); + changeRow = BUNDLE_ACTIVE_FAIL; + } +} + shared_ptr WEAK_FUNC BundleActiveUsageDatabase::GetBundleActiveRdbStore(uint32_t databaseType) { shared_ptr rdbStore; @@ -477,7 +635,8 @@ int32_t BundleActiveUsageDatabase::CreateEventLogTable(uint32_t databaseType, in + 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);"; + + BUNDLE_ACTIVE_DB_ABILITY_ID + " TEXT NOT NULL, " + + BUNDLE_ACTIVE_DB_UID + " INTEGER NOT NULL DEFAULT 0);"; int32_t createEventTable = rdbStore->ExecuteSql(createEventTableSql); if (createEventTable != NativeRdb::E_OK) { BUNDLE_ACTIVE_LOGE("create event table failed, rdb error number: %{public}d", createEventTable); @@ -509,7 +668,8 @@ int32_t BundleActiveUsageDatabase::CreatePackageLogTable(uint32_t databaseType, + BUNDLE_ACTIVE_DB_LAST_TIME + " INTEGER NOT NULL, " + BUNDLE_ACTIVE_DB_LAST_TIME_CONTINUOUS_TASK + " INTEGER NOT NULL, " + BUNDLE_ACTIVE_DB_TOTAL_TIME + " INTEGER NOT NULL, " - + BUNDLE_ACTIVE_DB_TOTAL_TIME_CONTINUOUS_TASK + " INTEGER NOT NULL);"; + + BUNDLE_ACTIVE_DB_TOTAL_TIME_CONTINUOUS_TASK + " INTEGER NOT NULL " + + BUNDLE_ACTIVE_DB_UID + " INTEGER NOT NULL DEFAULT 0);"; int32_t createPackageTable = rdbStore->ExecuteSql(createPackageTableSql); if (createPackageTable != NativeRdb::E_OK) { BUNDLE_ACTIVE_LOGE("create packageLog table failed, rdb error number: %{public}d", createPackageTable); @@ -540,7 +700,8 @@ int32_t BundleActiveUsageDatabase::CreateModuleRecordTable(uint32_t databaseType + BUNDLE_ACTIVE_DB_BUNDLE_NAME + " TEXT NOT NULL, " + BUNDLE_ACTIVE_DB_MODULE_NAME + " TEXT NOT NULL, " + BUNDLE_ACTIVE_DB_MODULE_LAUNCHED_COUNT + " INTEGER NOT NULL, " - + BUNDLE_ACTIVE_DB_LAST_TIME + " INTEGER NOT NULL);"; + + BUNDLE_ACTIVE_DB_LAST_TIME + " INTEGER NOT NULL " + + BUNDLE_ACTIVE_DB_UID + " INTEGER NOT NULL DEFAULT 0);"; int32_t createModuleRecordTable = rdbStore->ExecuteSql(createModuleRecordTableSql); if (createModuleRecordTable != NativeRdb::E_OK) { BUNDLE_ACTIVE_LOGE("create ModuleRecord table failed, rdb error number: %{public}d", createModuleRecordTable); @@ -574,7 +735,8 @@ int32_t BundleActiveUsageDatabase::CreateFormRecordTable(uint32_t databaseType, + 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);"; + + BUNDLE_ACTIVE_DB_LAST_TIME + " INTEGER NOT NULL " + + BUNDLE_ACTIVE_DB_UID + " INTEGER NOT NULL DEFAULT 0);"; int32_t createFormRecordTable = rdbStore->ExecuteSql(createFormRecordTableSql); if (createFormRecordTable != NativeRdb::E_OK) { BUNDLE_ACTIVE_LOGE("create ModuleRecord table failed, rdb error number: %{public}d", createFormRecordTable); @@ -626,7 +788,8 @@ int32_t BundleActiveUsageDatabase::CreateBundleHistoryTable(uint32_t databaseTyp + BUNDLE_ACTIVE_DB_CURRENT_GROUP + " INTEGER NOT NULL, " + BUNDLE_ACTIVE_DB_REASON_IN_GROUP + " INTEGER NOT NULL, " + BUNDLE_ACTIVE_DB_BUNDLE_ALIVE_TIMEOUT_TIME + " INTEGER NOT NULL, " - + BUNDLE_ACTIVE_DB_BUNDLE_DAILY_TIMEOUT_TIME + " INTEGER NOT NULL);"; + + BUNDLE_ACTIVE_DB_BUNDLE_DAILY_TIMEOUT_TIME + " INTEGER NOT NULL " + + BUNDLE_ACTIVE_DB_UID + " INTEGER NOT NULL DEFAULT 0);"; int32_t createBundleHistoryTable = rdbStore->ExecuteSql(createBundleHistoryTableSql); if (createBundleHistoryTable != NativeRdb::E_OK) { BUNDLE_ACTIVE_LOGE("create bundleHistory table failed, rdb error number: %{public}d", createBundleHistoryTable); @@ -670,18 +833,20 @@ void BundleActiveUsageDatabase::PutBundleHistoryData(int32_t userId, continue; } queryCondition.push_back(to_string(userId)); - queryCondition.push_back(iter->first); + queryCondition.push_back(iter->second->bundleName_); + queryCondition.push_back(to_string(iter->second->uid_)); valuesBucket.PutLong(BUNDLE_ACTIVE_DB_LAST_BOOT_FROM_USED_TIME, iter->second->lastBootFromUsedTimeStamp_); valuesBucket.PutLong(BUNDLE_ACTIVE_DB_LAST_SCREEN_USED_TIME, iter->second->lastScreenUsedTimeStamp_); valuesBucket.PutInt(BUNDLE_ACTIVE_DB_CURRENT_GROUP, iter->second->currentGroup_); valuesBucket.PutInt(BUNDLE_ACTIVE_DB_REASON_IN_GROUP, static_cast(iter->second->reasonInGroup_)); valuesBucket.PutLong(BUNDLE_ACTIVE_DB_BUNDLE_ALIVE_TIMEOUT_TIME, iter->second->bundleAliveTimeoutTimeStamp_); valuesBucket.PutLong(BUNDLE_ACTIVE_DB_BUNDLE_DAILY_TIMEOUT_TIME, iter->second->bundleDailyTimeoutTimeStamp_); - rdbStore->Update(changeRow, BUNDLE_HISTORY_LOG_TABLE, valuesBucket, "userId = ? and bundleName = ?", - queryCondition); + rdbStore->Update(changeRow, BUNDLE_HISTORY_LOG_TABLE, valuesBucket, + "userId = ? and bundleName = ? and uid = ?", queryCondition); if (changeRow == NO_UPDATE_ROW) { - valuesBucket.PutString(BUNDLE_ACTIVE_DB_BUNDLE_NAME, iter->first); + valuesBucket.PutString(BUNDLE_ACTIVE_DB_BUNDLE_NAME, iter->second->bundleName_); valuesBucket.PutInt(BUNDLE_ACTIVE_DB_USER_ID, userId); + valuesBucket.PutInt(BUNDLE_ACTIVE_DB_UID, iter->second->uid_); rdbStore->Insert(outRowId, BUNDLE_HISTORY_LOG_TABLE, valuesBucket); outRowId = BUNDLE_ACTIVE_FAIL; } else { @@ -721,8 +886,8 @@ shared_ptr>> BundleActiveUsag int32_t currentBundleGroupReason = 0; for (int32_t i = 0; i < tableRowNumber; i++) { bundleActiveResult->GoToRow(i); - bundleActiveResult->GetString(BUNDLE_NAME_COLUMN_INDEX, bundleName); shared_ptr usageHistory = make_shared(); + bundleActiveResult->GetString(BUNDLE_NAME_COLUMN_INDEX, usageHistory->bundleName_); bundleActiveResult->GetLong(LAST_BOOT_FROM_USED_TIME_COLUMN_INDEX, usageHistory->lastBootFromUsedTimeStamp_); bundleActiveResult->GetLong(LAST_SCREEN_USED_TIME_COLUMN_INDEX, usageHistory->lastScreenUsedTimeStamp_); bundleActiveResult->GetInt(CURRENT_GROUP_COLUMN_INDEX, usageHistory->currentGroup_); @@ -732,7 +897,9 @@ shared_ptr>> BundleActiveUsag usageHistory->bundleAliveTimeoutTimeStamp_); bundleActiveResult->GetLong(BUNDLE_DAILY_TIMEOUT_TIME_COLUMN_INDEX, usageHistory->bundleDailyTimeoutTimeStamp_); - userUsageHistory->insert(pair>(bundleName, + bundleActiveResult->GetInt(BUNDLE_HISTORY_LOG_UID_COLUMN_INDEX, usageHistory->uid_); + string usageHistoryKey = usageHistory->bundleName_ + to_string(usageHistory->uid_); + userUsageHistory->insert(pair>(usageHistoryKey, usageHistory)); } return userUsageHistory; @@ -803,7 +970,8 @@ void BundleActiveUsageDatabase::FlushPackageInfo(uint32_t databaseType, const Bu continue; } queryCondition.push_back(to_string(stats.userId_)); - queryCondition.push_back(iter->first); + queryCondition.push_back(iter->second->bundleName_); + queryCondition.push_back(to_string(iter->second->uid_)); valuesBucket.PutLong(BUNDLE_ACTIVE_DB_BUNDLE_STARTED_COUNT, iter->second->startCount_); int64_t lastTimeUsedAdjusted = iter->second->lastTimeUsed_ == -1 ? iter->second->lastTimeUsed_ : iter->second->lastTimeUsed_ - stats.beginTime_; @@ -813,10 +981,12 @@ void BundleActiveUsageDatabase::FlushPackageInfo(uint32_t databaseType, const Bu valuesBucket.PutLong(BUNDLE_ACTIVE_DB_LAST_TIME_CONTINUOUS_TASK, lastContinuousTaskUsedAdjusted); valuesBucket.PutLong(BUNDLE_ACTIVE_DB_TOTAL_TIME, iter->second->totalInFrontTime_); valuesBucket.PutLong(BUNDLE_ACTIVE_DB_TOTAL_TIME_CONTINUOUS_TASK, iter->second->totalContiniousTaskUsedTime_); - rdbStore->Update(changeRow, tableName, valuesBucket, "userId = ? and bundleName = ?", queryCondition); + rdbStore->Update(changeRow, tableName, valuesBucket, "userId = ? and bundleName = ? and uid = ?", + queryCondition); if (changeRow == NO_UPDATE_ROW) { valuesBucket.PutString(BUNDLE_ACTIVE_DB_BUNDLE_NAME, iter->second->bundleName_); valuesBucket.PutInt(BUNDLE_ACTIVE_DB_USER_ID, stats.userId_); + valuesBucket.PutInt(BUNDLE_ACTIVE_DB_UID, iter->second->uid_); rdbStore->Insert(outRowId, tableName, valuesBucket); outRowId = BUNDLE_ACTIVE_FAIL; } else { @@ -900,6 +1070,7 @@ void BundleActiveUsageDatabase::FlushEventInfo(uint32_t databaseType, BundleActi 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_); + valuesBucket.PutInt(BUNDLE_ACTIVE_DB_UID, stats.events_.events_.at(i).uid_); rdbStore->Insert(outRowId, eventTableName_, valuesBucket); valuesBucket.Clear(); } @@ -1305,6 +1476,7 @@ vector BundleActiveUsageDatabase::QueryDatabaseUsageSt bundleActiveResult->GetLong(TOTAL_TIME_COLUMN_INDEX, usageStats.totalInFrontTime_); bundleActiveResult->GetLong(TOTAL_TIME_CONTINUOUS_TASK_COLUMN_INDEX, usageStats.totalContiniousTaskUsedTime_); + bundleActiveResult->GetInt(PACKAGE_LOG_UID_COLUMN_INDEX, usageStats.uid_); usageStats.userId_ = userId; databaseUsageStats.push_back(usageStats); } @@ -1360,7 +1532,8 @@ vector BundleActiveUsageDatabase::QueryDatabaseEvents(int64_t return databaseEvents; } -void BundleActiveUsageDatabase::OnPackageUninstalled(const int32_t userId, const string& bundleName) +void BundleActiveUsageDatabase::OnPackageUninstalled(const int32_t userId, const string& bundleName, + const int32_t uid, const int32_t appIndex) { lock_guard lock(databaseMutex_); for (uint32_t i = 0; i < sortedTableArray_.size(); i++) { @@ -1369,25 +1542,25 @@ void BundleActiveUsageDatabase::OnPackageUninstalled(const int32_t userId, const } for (uint32_t j = 0; j < sortedTableArray_.at(i).size(); j++) { string packageTableName = PACKAGE_LOG_TABLE + to_string(sortedTableArray_.at(i).at(j)); - DeleteUninstalledInfo(userId, bundleName, packageTableName, i); + DeleteUninstalledInfo(userId, bundleName, uid, packageTableName, i, appIndex); } } if (eventTableName_ != UNKNOWN_TABLE_NAME) { - DeleteUninstalledInfo(userId, bundleName, eventTableName_, EVENT_DATABASE_INDEX); + DeleteUninstalledInfo(userId, bundleName, uid, eventTableName_, EVENT_DATABASE_INDEX, appIndex); } if (bundleHistoryTableName_ != UNKNOWN_TABLE_NAME) { - DeleteUninstalledInfo(userId, bundleName, bundleHistoryTableName_, APP_GROUP_DATABASE_INDEX); + DeleteUninstalledInfo(userId, bundleName, uid, bundleHistoryTableName_, APP_GROUP_DATABASE_INDEX, appIndex); } if (moduleRecordsTableName_ != UNKNOWN_TABLE_NAME) { - DeleteUninstalledInfo(userId, bundleName, moduleRecordsTableName_, APP_GROUP_DATABASE_INDEX); + DeleteUninstalledInfo(userId, bundleName, uid, moduleRecordsTableName_, APP_GROUP_DATABASE_INDEX, appIndex); } if (formRecordsTableName_ != UNKNOWN_TABLE_NAME) { - DeleteUninstalledInfo(userId, bundleName, formRecordsTableName_, APP_GROUP_DATABASE_INDEX); + DeleteUninstalledInfo(userId, bundleName, uid, formRecordsTableName_, APP_GROUP_DATABASE_INDEX, appIndex); } } void BundleActiveUsageDatabase::DeleteUninstalledInfo(const int32_t userId, const string& bundleName, - const string& tableName, uint32_t databaseType) + const int32_t uid, const string& tableName, uint32_t databaseType, const int32_t appIndex) { shared_ptr rdbStore = GetBundleActiveRdbStore(databaseType); if (rdbStore == nullptr) { @@ -1399,10 +1572,16 @@ void BundleActiveUsageDatabase::DeleteUninstalledInfo(const int32_t userId, cons queryCondition.push_back(to_string(userId)); if (bundleName.empty()) { rdbStore->Delete(deletedRows, tableName, "userId = ?", queryCondition); - } else { + return; + } + if (appIndex != 0) { queryCondition.push_back(bundleName); rdbStore->Delete(deletedRows, tableName, "userId = ? and bundleName = ?", queryCondition); + return; } + queryCondition.push_back(bundleName); + queryCondition.push_back(to_string(uid)); + rdbStore->Delete(deletedRows, tableName, "userId = ? and bundleName = ? and uid = ?", queryCondition); } int64_t BundleActiveUsageDatabase::GetSystemTimeMs() @@ -1433,12 +1612,7 @@ void BundleActiveUsageDatabase::UpdateModuleData(const int32_t userId, 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); - } + createRecordTable(timeStamp); int64_t moduleTableTime = ParseStartTime(moduleRecordsTableName_); int32_t changeRow = BUNDLE_ACTIVE_FAIL; int64_t outRowId = BUNDLE_ACTIVE_FAIL; @@ -1449,16 +1623,18 @@ void BundleActiveUsageDatabase::UpdateModuleData(const int32_t userId, queryCondition.emplace_back(to_string(oneModuleRecord.second->userId_)); queryCondition.emplace_back(oneModuleRecord.second->bundleName_); queryCondition.emplace_back(oneModuleRecord.second->moduleName_); + queryCondition.emplace_back(to_string(oneModuleRecord.second->uid_)); moduleValuesBucket.PutInt(BUNDLE_ACTIVE_DB_MODULE_LAUNCHED_COUNT, oneModuleRecord.second->launchedCount_); int64_t adjustLastTime = oneModuleRecord.second->lastModuleUsedTime_ != -1 ? oneModuleRecord.second->lastModuleUsedTime_ - moduleTableTime : -1; moduleValuesBucket.PutLong(BUNDLE_ACTIVE_DB_LAST_TIME, adjustLastTime); rdbStore->Update(changeRow, moduleRecordsTableName_, moduleValuesBucket, - "userId = ? and bundleName = ? and moduleName = ?", queryCondition); + "userId = ? and bundleName = ? and moduleName = ? and uid = ?", queryCondition); if (changeRow == NO_UPDATE_ROW) { 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.PutInt(BUNDLE_ACTIVE_DB_UID, oneModuleRecord.second->uid_); rdbStore->Insert(outRowId, moduleRecordsTableName_, moduleValuesBucket); outRowId = BUNDLE_ACTIVE_FAIL; changeRow = BUNDLE_ACTIVE_FAIL; @@ -1475,6 +1651,16 @@ void BundleActiveUsageDatabase::UpdateModuleData(const int32_t userId, } } +void BundleActiveUsageDatabase::createRecordTable(const int64_t timeStamp) +{ + if (moduleRecordsTableName_ == UNKNOWN_TABLE_NAME) { + CreateModuleRecordTable(APP_GROUP_DATABASE_INDEX, timeStamp); + } + if (formRecordsTableName_ == UNKNOWN_TABLE_NAME) { + CreateFormRecordTable(APP_GROUP_DATABASE_INDEX, timeStamp); + } +} + void BundleActiveUsageDatabase::UpdateFormData(const int32_t userId, const std::string bundleName, const string moduleName, const BundleActiveFormRecord& formRecord, std::shared_ptr rdbStore) @@ -1493,6 +1679,7 @@ void BundleActiveUsageDatabase::UpdateFormData(const int32_t userId, const std:: queryCondition.emplace_back(formRecord.formName_); queryCondition.emplace_back(to_string(formRecord.formDimension_)); queryCondition.emplace_back(to_string(formRecord.formId_)); + queryCondition.emplace_back(to_string(formRecord.uid_)); formValueBucket.PutInt(BUNDLE_ACTIVE_DB_FORM_TOUCH_COUNT, formRecord.count_); int64_t adjustLastTime = formRecord.formLastUsedTime_ != -1 ? formRecord.formLastUsedTime_ - formRecordsTableTime : -1; @@ -1508,13 +1695,14 @@ void BundleActiveUsageDatabase::UpdateFormData(const int32_t userId, const std:: formValueBucket.PutString(BUNDLE_ACTIVE_DB_FORM_NAME, formRecord.formName_); formValueBucket.PutInt(BUNDLE_ACTIVE_DB_FORM_DIMENSION, formRecord.formDimension_); formValueBucket.PutInt(BUNDLE_ACTIVE_DB_FORM_ID, formRecord.formId_); + formValueBucket.PutInt(BUNDLE_ACTIVE_DB_FORM_ID, formRecord.uid_); rdbStore->Insert(outRowId, formRecordsTableName_, formValueBucket); } } void BundleActiveUsageDatabase::RemoveFormData(const int32_t userId, const std::string bundleName, const std::string moduleName, const std::string formName, const int32_t formDimension, - const int64_t formId) + const int64_t formId, const int32_t uid) { lock_guard lock(databaseMutex_); shared_ptr rdbStore = GetBundleActiveRdbStore(APP_GROUP_DATABASE_INDEX); @@ -1533,7 +1721,7 @@ void BundleActiveUsageDatabase::RemoveFormData(const int32_t userId, const std:: queryCondition.emplace_back(to_string(formId)); int32_t ret = rdbStore->Delete(deletedRows, formRecordsTableName_, "userId = ? and bundleName = ? and moduleName = ? and formName = ? and formDimension = ? " - "and formId = ?", + "and formId = ? and uid = ?", queryCondition); if (ret != NativeRdb::E_OK) { BUNDLE_ACTIVE_LOGE("delete event data failed, rdb error number: %{public}d", ret); @@ -1563,6 +1751,7 @@ void BundleActiveUsageDatabase::LoadModuleData(const int32_t userId, std::mapGetString(BUNDLE_NAME_COLUMN_INDEX, oneModuleRecord->bundleName_); moduleRecordResult->GetString(MODULE_NAME_COLUMN_INDEX, oneModuleRecord->moduleName_); moduleRecordResult->GetInt(MODULE_USED_COUNT_COLUMN_INDEX, oneModuleRecord->launchedCount_); + moduleRecordResult->GetInt(MODULE_UID_COLUMN_INDEX, oneModuleRecord->uid_); int64_t relativeLastTime = 0; moduleRecordResult->GetLong(MODULE_LAST_TIME_COLUMN_INDEX, relativeLastTime); oneModuleRecord->lastModuleUsedTime_ = relativeLastTime != -1 ? relativeLastTime + baseTime : -1; @@ -1703,6 +1892,7 @@ void BundleActiveUsageDatabase::QueryNotificationEventStats(int32_t eventId, int bundleActiveResult->GoToRow(i); bundleActiveResult->GetString(BUNDLE_NAME_COLUMN_INDEX, event.name_); bundleActiveResult->GetInt(EVENT_ID_COLUMN_INDEX, event.eventId_); + bundleActiveResult->GetInt(EVENT_UID_COLUMN_INDEX, event.uid_); iter = notificationEventStats.find(event.name_); if (iter != notificationEventStats.end()) { iter->second.count_++; diff --git a/services/packagegroup/include/bundle_active_group_controller.h b/services/packagegroup/include/bundle_active_group_controller.h index b203efdc3e41967f57992bf279284620f265b289..bb9decaeb4d3f72d17ad84a5b10d13e7fc45243c 100644 --- a/services/packagegroup/include/bundle_active_group_controller.h +++ b/services/packagegroup/include/bundle_active_group_controller.h @@ -60,12 +60,14 @@ public: void SetHandlerAndCreateUserHistory(const std::shared_ptr& groupHandler, const int64_t bootFromTimeStamp, const std::shared_ptr& bundleActiveCore); void ReportEvent(const BundleActiveEvent& event, const int64_t bootBasedTimeStamp, const int32_t userId); - void CheckAndUpdateGroup(const std::string& bundleName, const int32_t userId, const int64_t bootBasedTimeStamp); + void CheckAndUpdateGroup(const std::string& bundleName, const int32_t uid, + int32_t userId, const int64_t bootBasedTimeStamp); bool CheckEachBundleState(const int32_t userId); void CheckIdleStatsOneTime(); void PeriodCheckBundleState(const int32_t userId); void OnUserRemoved(const int32_t userId); - void OnBundleUninstalled(const int32_t userId, const std::string bundleName); + void OnBundleUninstalled(const int32_t userId, const std::string bundleName, const int32_t uid, + const int32_t appIndex); void OnScreenChanged(const bool& isScreenOn, const int64_t bootFromTimeStamp); int32_t SetAppGroup(const std::string& bundleName, const int32_t userId, int32_t newGroup, uint32_t reason, const int64_t bootBasedTimeStamp, const bool isFlush); @@ -90,7 +92,8 @@ private: sptr sptrBundleMgr_; bool calculationTimeOut(const std::shared_ptr& oneBundleHistory, const int64_t bootBasedTimeStamp); - int32_t GetNewGroup(const std::string& bundleName, const int32_t userId, const int64_t bootBasedTimeStamp); + int32_t GetNewGroup(const std::string& bundleName, const int32_t userId, const int64_t bootBasedTimeStamp, + const int32_t uid); }; } // namespace DeviceUsageStats } // namespace OHOS diff --git a/services/packagegroup/include/bundle_active_group_handler.h b/services/packagegroup/include/bundle_active_group_handler.h index 96ec7bfb20916c4dbdff0489425d3a8a54c9e8db..921ab9cc96c434800c1d95356fa6991606a62c81 100644 --- a/services/packagegroup/include/bundle_active_group_handler.h +++ b/services/packagegroup/include/bundle_active_group_handler.h @@ -29,6 +29,7 @@ class BundleActiveGroupHandlerObject { public: std::string bundleName_; int32_t userId_; + int32_t uid_; BundleActiveGroupHandlerObject(); BundleActiveGroupHandlerObject(const BundleActiveGroupHandlerObject& orig); ~BundleActiveGroupHandlerObject() {} diff --git a/services/packagegroup/include/bundle_active_package_history.h b/services/packagegroup/include/bundle_active_package_history.h index ac4b4503443205b01dc5f390e67db1420d0beea6..df59df968d8f3d7ec12902081238848828407b07 100644 --- a/services/packagegroup/include/bundle_active_package_history.h +++ b/services/packagegroup/include/bundle_active_package_history.h @@ -22,11 +22,13 @@ namespace OHOS { namespace DeviceUsageStats { class BundleActivePackageHistory { public: + std::string bundleName_; int64_t lastBootFromUsedTimeStamp_; int64_t lastScreenUsedTimeStamp_; int64_t lastGroupCalculatedTimeStamp_; int32_t lastCalculatedGroup_; int32_t currentGroup_; + int32_t uid_; uint32_t reasonInGroup_; int64_t bundleAliveTimeoutTimeStamp_; int64_t bundleDailyTimeoutTimeStamp_; diff --git a/services/packagegroup/include/bundle_active_user_history.h b/services/packagegroup/include/bundle_active_user_history.h index 7ed08debaf5ba6a6c82d7b4d230c184711c148cb..392ef1b429185ef7ec3a1074630b39660685049a 100644 --- a/services/packagegroup/include/bundle_active_user_history.h +++ b/services/packagegroup/include/bundle_active_user_history.h @@ -32,6 +32,7 @@ class BundleActiveCore; class BundleActiveUserHistory { public: std::map>>> userHistory_; + std::map> packageContainUid_; int64_t bootBasedTimeStamp_; int64_t bootBasedDuration_; int64_t screenOnTimeStamp_; @@ -40,27 +41,28 @@ public: BundleActiveUserHistory(const int64_t bootBasedTimeStamp, const std::shared_ptr& bundleActiveCore); std::shared_ptr GetUsageHistoryForBundle(const std::string& bundleName, - const int32_t userId, const int64_t bootBasedTimeStamp, const bool create); + const int32_t userId, const int64_t bootBasedTimeStamp, const bool create, const int32_t uid); std::shared_ptr>> GetUserHistory( const int32_t userId, const bool create); std::shared_ptr GetUsageHistoryInUserHistory(std::shared_ptr>> oneUserHistory, std::string bundleName, - int64_t bootBasedTimeStamp, bool create); + int64_t bootBasedTimeStamp, bool create, const int32_t uid); int64_t GetBootBasedTimeStamp(int64_t bootBasedTimeStamp); int64_t GetScreenOnTimeStamp(int64_t bootBasedTimeStamp); void ReportUsage(std::shared_ptr oneBundleUsageHistory, const std::string& bundleName, const int32_t newGroup, const uint32_t groupReason, const int64_t bootBasedTimeStamp, - const int64_t timeUntilNextCheck, const int32_t userId); - int32_t SetAppGroup(const std::string& bundleName, const int32_t userId, const int64_t bootBasedTimeStamp, - int32_t newGroup, uint32_t groupReason, const bool isFlush); + const int64_t timeUntilNextCheck, const int32_t userId, const int32_t uid); + int32_t SetAppGroup(const std::string& bundleName, const int32_t userId, const int32_t uid, + int64_t bootBasedTimeStamp, int32_t newGroup, uint32_t groupReason, const bool isFlush); int32_t GetLevelIndex(const std::string& bundleName, const int32_t userId, const int64_t bootBasedTimeStamp, - const std::vector screenTimeLeve, const std::vector bootFromTimeLevel); + const std::vector screenTimeLeve, const std::vector bootFromTimeLevel, const int32_t uid); void WriteDeviceDuration(); void WriteBundleUsage(const int32_t userId); void PrintData(int32_t userId); void UpdateBootBasedAndScreenTime(const bool& isScreenOn, const int64_t bootBasedTimeStamp, const bool& isShutdown = false); - void OnBundleUninstalled(const int32_t userId, const std::string bundleName); + void OnBundleUninstalled(const int32_t userId, const std::string bundleName, const int32_t uid, + const int32_t appIndex); private: std::mutex setGroupMutex_; diff --git a/services/packagegroup/src/bundle_active_group_controller.cpp b/services/packagegroup/src/bundle_active_group_controller.cpp index 393206547d005dee2b165170cff093029ebd85a4..71dea20ef7a6079229e22266a5be37a5d64b9648 100644 --- a/services/packagegroup/src/bundle_active_group_controller.cpp +++ b/services/packagegroup/src/bundle_active_group_controller.cpp @@ -104,7 +104,8 @@ void BundleActiveGroupController::SetHandlerAndCreateUserHistory( activeGroupHandler_ = groupHandler; } -void BundleActiveGroupController::OnBundleUninstalled(const int32_t userId, const std::string bundleName) +void BundleActiveGroupController::OnBundleUninstalled(const int32_t userId, const std::string bundleName, + const int32_t uid, const int32_t appIndex) { std::lock_guard lock(mutex_); BUNDLE_ACTIVE_LOGI("OnBundleUninstalled called, userId is %{public}d, bundlename is %{public}s", @@ -114,7 +115,7 @@ void BundleActiveGroupController::OnBundleUninstalled(const int32_t userId, cons return; } oneUserHistory->erase(bundleName); - bundleUserHistory_->OnBundleUninstalled(userId, bundleName); + bundleUserHistory_->OnBundleUninstalled(userId, bundleName, uid, appIndex); } bool BundleActiveGroupController::GetBundleMgrProxy() @@ -169,14 +170,10 @@ bool BundleActiveGroupController::CheckEachBundleState(const int32_t userId) return false; } sptrBundleMgr_->GetApplicationInfos(flag, userId, allBundlesForUser); - std::vector bundleNamesOfUser; - for (auto oneBundle : allBundlesForUser) { - bundleNamesOfUser.push_back(oneBundle.bundleName); - } sptr timer = MiscServices::TimeServiceClient::GetInstance(); int64_t bootBasedTimeStamp = timer->GetBootTimeMs(); - for (auto oneBundleName : bundleNamesOfUser) { - CheckAndUpdateGroup(oneBundleName, userId, bootBasedTimeStamp); + for (auto oneBundle : allBundlesForUser) { + CheckAndUpdateGroup(oneBundle.oneBundleName, oneBundle.uid, userId, bootBasedTimeStamp); } return true; } @@ -192,10 +189,10 @@ void BundleActiveGroupController::CheckIdleStatsOneTime() } int32_t BundleActiveGroupController::GetNewGroup(const std::string& bundleName, const int32_t userId, - const int64_t bootBasedTimeStamp) + const int64_t bootBasedTimeStamp, const int32_t uid) { int32_t groupIndex = bundleUserHistory_->GetLevelIndex(bundleName, userId, bootBasedTimeStamp, screenTimeLevel_, - bootTimeLevel_); + bootTimeLevel_, uid); if (groupIndex < 0) { return -1; } @@ -228,7 +225,7 @@ void BundleActiveGroupController::ReportEvent(const BundleActiveEvent& event, co auto item = eventIdMatchReason_.find(eventId); if (item != eventIdMatchReason_.end()) { std::shared_ptr bundleUsageHistory = bundleUserHistory_->GetUsageHistoryForBundle( - event.bundleName_, userId, bootBasedTimeStamp, true); + event.bundleName_, userId, bootBasedTimeStamp, true, event.uid_); if (bundleUsageHistory == nullptr) { return; } @@ -237,23 +234,24 @@ void BundleActiveGroupController::ReportEvent(const BundleActiveEvent& event, co switch (eventId) { case BundleActiveEvent::NOTIFICATION_SEEN: bundleUserHistory_->ReportUsage(bundleUsageHistory, event.bundleName_, ACTIVE_GROUP_DAILY, - eventReason, 0, bootBasedTimeStamp + timeoutForNotifySeen_, userId); + eventReason, 0, bootBasedTimeStamp + timeoutForNotifySeen_, userId, event.uid_); timeUntilNextCheck = timeoutForNotifySeen_; break; case BundleActiveEvent::SYSTEM_INTERACTIVE: bundleUserHistory_->ReportUsage(bundleUsageHistory, event.bundleName_, ACTIVE_GROUP_ALIVE, - eventReason, 0, bootBasedTimeStamp + timeoutForSystemInteraction_, userId); + eventReason, 0, bootBasedTimeStamp + timeoutForSystemInteraction_, userId, event.uid_); timeUntilNextCheck = timeoutForSystemInteraction_; break; default: bundleUserHistory_->ReportUsage(bundleUsageHistory, event.bundleName_, ACTIVE_GROUP_ALIVE, - eventReason, bootBasedTimeStamp, bootBasedTimeStamp + timeoutForDirectlyUse_, userId); + eventReason, bootBasedTimeStamp, bootBasedTimeStamp + timeoutForDirectlyUse_, userId, event.uid_); timeUntilNextCheck = timeoutForDirectlyUse_; break; } BundleActiveGroupHandlerObject tmpGroupHandlerObj; tmpGroupHandlerObj.userId_ = userId; tmpGroupHandlerObj.bundleName_ = event.bundleName_; + tmpGroupHandlerObj.uid_ = event.uid_; std::shared_ptr handlerobjToPtr = std::make_shared(tmpGroupHandlerObj); auto handlerEvent = AppExecFwk::InnerEvent::Get(BundleActiveGroupHandler::MSG_CHECK_BUNDLE_STATE, @@ -266,10 +264,11 @@ void BundleActiveGroupController::ReportEvent(const BundleActiveEvent& event, co } void BundleActiveGroupController::CheckAndUpdateGroup(const std::string& bundleName, const int32_t userId, - const int64_t bootBasedTimeStamp) + const int32_t uid, const int64_t bootBasedTimeStamp) { std::lock_guard lock(mutex_); - auto oneBundleHistory = bundleUserHistory_->GetUsageHistoryForBundle(bundleName, userId, bootBasedTimeStamp, true); + auto oneBundleHistory = bundleUserHistory_->GetUsageHistoryForBundle(bundleName, userId, + bootBasedTimeStamp, true, uid); if (oneBundleHistory == nullptr) { return; } @@ -284,7 +283,7 @@ void BundleActiveGroupController::CheckAndUpdateGroup(const std::string& bundleN if (oldGroupControlReason == GROUP_CONTROL_REASON_DEFAULT || oldGroupControlReason == GROUP_CONTROL_REASON_USAGE || oldGroupControlReason == GROUP_CONTROL_REASON_TIMEOUT) { - newGroup = GetNewGroup(bundleName, userId, bootBasedTimeStamp); + newGroup = GetNewGroup(bundleName, userId, bootBasedTimeStamp, uid); if (newGroup < 0) { return; } @@ -305,7 +304,8 @@ void BundleActiveGroupController::CheckAndUpdateGroup(const std::string& bundleN } if (oldGroup < newGroup || notTimeout) { BUNDLE_ACTIVE_LOGI("CheckAndUpdateGroup called SetAppGroup"); - bundleUserHistory_->SetAppGroup(bundleName, userId, bootBasedTimeStamp, newGroup, groupReason, false); + bundleUserHistory_->SetAppGroup(bundleName, userId, bootBasedTimeStamp, newGroup, + groupReason, false, uid); } } @@ -316,11 +316,25 @@ ErrCode BundleActiveGroupController::SetAppGroup(const std::string& bundleName, if (!IsBundleInstalled(bundleName, userId)) { return ERR_NO_APP_GROUP_INFO_IN_DATABASE; } - auto oneBundleHistory = bundleUserHistory_->GetUsageHistoryForBundle(bundleName, userId, bootBasedTimeStamp, true); - if (!oneBundleHistory) { + auto iter = bundleUserHistory_->packageContainUid_.find(bundleName); + if (iter == bundleUserHistory_->packageContainUid_.end()) { return ERR_NO_APP_GROUP_INFO_IN_DATABASE; } - return bundleUserHistory_->SetAppGroup(bundleName, userId, bootBasedTimeStamp, newGroup, reason, isFlush); + int32_t result = 0; + int32_t tempResult = 0; + for (int32_t uid: iter->second) { + auto oneBundleHistory = bundleUserHistory_->GetUsageHistoryForBundle(bundleName, + userId, bootBasedTimeStamp, true, uid); + if (!oneBundleHistory) { + continue; + } + tempResult = bundleUserHistory_->SetAppGroup(bundleName, userId, + uid, bootBasedTimeStamp, newGroup, reason, isFlush); + if (tempResult != ERR_OK) { + result = tempResult; + } + } + return result; } int32_t BundleActiveGroupController::IsBundleIdle(const std::string& bundleName, const int32_t userId) @@ -331,17 +345,22 @@ int32_t BundleActiveGroupController::IsBundleIdle(const std::string& bundleName, return -1; } int64_t bootBasedTimeStamp = timer->GetBootTimeMs(); - auto oneBundleHistory = bundleUserHistory_->GetUsageHistoryForBundle( - bundleName, userId, bootBasedTimeStamp, false); - if (oneBundleHistory == nullptr) { - return 1; - } else if (oneBundleHistory->currentGroup_ >= ACTIVE_GROUP_RARE) { - BUNDLE_ACTIVE_LOGI("IsBundleIdle, bundle group is %{public}d", oneBundleHistory->currentGroup_); - return 1; - } else { - BUNDLE_ACTIVE_LOGI("IsBundleIdle, bundle group is %{public}d", oneBundleHistory->currentGroup_); - return 0; + auto iter = bundleUserHistory_->packageContainUid_.find(bundleName); + if (iter == bundleUserHistory_->packageContainUid_.end()) { + return -1; + } + int32_t IsBundleIdle = 1; + for (int32_t uid: iter->second) { + auto oneBundleHistory = bundleUserHistory_->GetUsageHistoryForBundle(bundleName, + userId, bootBasedTimeStamp, false, uid); + if (!oneBundleHistory) { + continue; + } + if (oneBundleHistory->currentGroup_ <= ACTIVE_GROUP_RARE) { + IsBundleIdle = 0; + } } + return IsBundleIdle; } ErrCode BundleActiveGroupController::QueryAppGroup(int32_t& appGroup, @@ -358,13 +377,20 @@ ErrCode BundleActiveGroupController::QueryAppGroup(int32_t& appGroup, return ERR_APPLICATION_IS_NOT_INSTALLED; } int64_t bootBasedTimeStamp = timer->GetBootTimeMs(); - auto oneBundleHistory = bundleUserHistory_->GetUsageHistoryForBundle( - bundleName, userId, bootBasedTimeStamp, false); - if (!oneBundleHistory) { + auto iter = bundleUserHistory_->packageContainUid_.find(bundleName); + if (iter == bundleUserHistory_->packageContainUid_.end()) { return ERR_NO_APP_GROUP_INFO_IN_DATABASE; } - BUNDLE_ACTIVE_LOGI("QueryAppGroup group is %{public}d", oneBundleHistory->currentGroup_); - appGroup = oneBundleHistory->currentGroup_; + + for (int32_t uid: iter->second) { + auto oneBundleHistory = bundleUserHistory_->GetUsageHistoryForBundle(bundleName, userId, + bootBasedTimeStamp, false, uid); + if (!oneBundleHistory) { + continue; + } + BUNDLE_ACTIVE_LOGI("QueryAppGroup group is %{public}d", oneBundleHistory->currentGroup_); + appGroup = std::min(oneBundleHistory->currentGroup_, appGroup); + } return ERR_OK; } diff --git a/services/packagegroup/src/bundle_active_group_handler.cpp b/services/packagegroup/src/bundle_active_group_handler.cpp index 1b4ed196e9a05a246c66bd6a37733b199fb397b0..fa7ddf9249a003ef6d611b1e075abc33a31e2f92 100644 --- a/services/packagegroup/src/bundle_active_group_handler.cpp +++ b/services/packagegroup/src/bundle_active_group_handler.cpp @@ -63,7 +63,7 @@ void BundleActiveGroupHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointe sptr timer = MiscServices::TimeServiceClient::GetInstance(); int64_t bootBasedTimeStamp = timer->GetBootTimeMs(); bundleActiveGroupController_->CheckAndUpdateGroup( - tmpHandlerobj.bundleName_, tmpHandlerobj.userId_, bootBasedTimeStamp); + tmpHandlerobj.bundleName_, tmpHandlerobj.uid_, tmpHandlerobj.userId_, bootBasedTimeStamp); bundleActiveGroupController_->RestoreToDatabase(tmpHandlerobj.userId_); break; } diff --git a/services/packagegroup/src/bundle_active_user_history.cpp b/services/packagegroup/src/bundle_active_user_history.cpp index 536a18a1d04cd5172501f6b08100c4d7d8744988..8095019f50b63db0a68771f95b81e67c0267b261 100644 --- a/services/packagegroup/src/bundle_active_user_history.cpp +++ b/services/packagegroup/src/bundle_active_user_history.cpp @@ -24,6 +24,7 @@ using namespace std; BundleActivePackageHistory::BundleActivePackageHistory() { + bundleName_ = ""; lastBootFromUsedTimeStamp_ = 0; lastScreenUsedTimeStamp_ = 0; lastGroupCalculatedTimeStamp_ = 0; @@ -31,6 +32,7 @@ BundleActivePackageHistory::BundleActivePackageHistory() reasonInGroup_ = DeviceUsageStatsGroupConst::GROUP_CONTROL_REASON_DEFAULT; bundleAliveTimeoutTimeStamp_ = 0; bundleDailyTimeoutTimeStamp_ = 0; + uid_ = 0; lastCalculatedGroup_ = ACTIVE_GROUP_NEVER; isChanged_ = false; }; @@ -51,9 +53,10 @@ void BundleActiveUserHistory::WriteBundleUsage(const int32_t userId) database_.PutBundleHistoryData(userId, userHistory); } -void BundleActiveUserHistory::OnBundleUninstalled(const int32_t userId, const std::string bundleName) +void BundleActiveUserHistory::OnBundleUninstalled(const int32_t userId, const std::string bundleName, + const int32_t uid, const int32_t appIndex) { - database_.OnPackageUninstalled(userId, bundleName); + database_.OnPackageUninstalled(userId, bundleName, uid, appIndex); } BundleActiveUserHistory::BundleActiveUserHistory(const int64_t bootBasedTimeStamp, @@ -73,13 +76,13 @@ BundleActiveUserHistory::BundleActiveUserHistory(const int64_t bootBasedTimeStam int32_t BundleActiveUserHistory::GetLevelIndex(const string& bundleName, const int32_t userId, const int64_t bootBasedTimeStamp, const std::vector screenTimeLevel, - const std::vector bootFromTimeLevel) + const std::vector bootFromTimeLevel, const int32_t uid) { auto oneUserHistory = GetUserHistory(userId, false); if (oneUserHistory == nullptr) { return -1; } - auto oneBundleHistory = GetUsageHistoryInUserHistory(oneUserHistory, bundleName, bootBasedTimeStamp, false); + auto oneBundleHistory = GetUsageHistoryInUserHistory(oneUserHistory, bundleName, bootBasedTimeStamp, false, uid); if (oneBundleHistory == nullptr) { return -1; } @@ -125,39 +128,47 @@ shared_ptr>> BundleActiveUser BUNDLE_ACTIVE_LOGI("GetUserHistory usageHistoryInserted not null"); userHistory_[userId] = usageHistoryInserted; } + + if (it == userHistory_.end() && !create) { + return nullptr; + } return userHistory_[userId]; } shared_ptr BundleActiveUserHistory::GetUsageHistoryInUserHistory( shared_ptr>> oneUserHistory, - string bundleName, int64_t bootBasedTimeStamp, const bool create) + string bundleName, int64_t bootBasedTimeStamp, const bool create, const int32_t uid) { if (!oneUserHistory) { return nullptr; } + std::string userHistoryKey = bundleName + std::to_string(uid); auto it = oneUserHistory->find(bundleName); if ((it == oneUserHistory->end()) && create) { shared_ptr usageHistoryInserted = make_shared(); + usageHistoryInserted->bundleName_ = bundleName; usageHistoryInserted->lastBootFromUsedTimeStamp_ = GetBootBasedTimeStamp(bootBasedTimeStamp); usageHistoryInserted->lastScreenUsedTimeStamp_ = GetScreenOnTimeStamp(bootBasedTimeStamp); usageHistoryInserted->currentGroup_ = ACTIVE_GROUP_NEVER; usageHistoryInserted->reasonInGroup_ = GROUP_CONTROL_REASON_DEFAULT; usageHistoryInserted->bundleAliveTimeoutTimeStamp_ = 0; usageHistoryInserted->bundleDailyTimeoutTimeStamp_ = 0; - (*oneUserHistory)[bundleName] = usageHistoryInserted; + usageHistoryInserted->uid_ = uid; + (*oneUserHistory)[userHistoryKey] = usageHistoryInserted; } - return (*oneUserHistory)[bundleName]; + return (*oneUserHistory)[userHistoryKey]; } shared_ptr BundleActiveUserHistory::GetUsageHistoryForBundle( - const string& bundleName, const int32_t userId, const int64_t bootBasedTimeStamp, const bool create) + const string& bundleName, const int32_t userId, const int64_t bootBasedTimeStamp, const bool create, + const int32_t uid) { auto oneUserHistory = GetUserHistory(userId, create); if (!oneUserHistory) { return nullptr; } - auto oneBundleHistory = GetUsageHistoryInUserHistory(oneUserHistory, bundleName, bootBasedTimeStamp, create); + auto oneBundleHistory = GetUsageHistoryInUserHistory(oneUserHistory, bundleName, bootBasedTimeStamp, create, uid); if (!oneBundleHistory) { return nullptr; } @@ -166,7 +177,7 @@ shared_ptr BundleActiveUserHistory::GetUsageHistoryF void BundleActiveUserHistory::ReportUsage(shared_ptr oneBundleUsageHistory, const string& bundleName, const int32_t newGroup, const uint32_t groupReason, const int64_t bootBasedTimeStamp, - const int64_t timeUntilNextCheck, const int32_t userId) + const int64_t timeUntilNextCheck, const int32_t userId, const int32_t uid) { if ((oneBundleUsageHistory->reasonInGroup_ & GROUP_CONTROL_REASON_MASK) == GROUP_CONTROL_REASON_FORCED) { return; @@ -208,7 +219,7 @@ void BundleActiveUserHistory::ReportUsage(shared_ptr } } -int32_t BundleActiveUserHistory::SetAppGroup(const string& bundleName, const int32_t userId, +int32_t BundleActiveUserHistory::SetAppGroup(const string& bundleName, const int32_t userId, const int32_t uid, const int64_t bootBasedTimeStamp, int32_t newGroup, uint32_t groupReason, const bool isFlush) { std::lock_guard lock(setGroupMutex_); @@ -219,7 +230,7 @@ int32_t BundleActiveUserHistory::SetAppGroup(const string& bundleName, const int return ERR_GET_BUNDLE_USED_HISTORY_FAILED; } shared_ptr oneBundleHistory = GetUsageHistoryInUserHistory(userBundleHistory, - bundleName, bootBasedTimeStamp, false); + bundleName, bootBasedTimeStamp, false, uid); if (!oneBundleHistory) { return ERR_GET_BUNDLE_USED_HISTORY_FAILED; } diff --git a/services/packageusage/include/bundle_active_period_stats.h b/services/packageusage/include/bundle_active_period_stats.h index 4627e8492ff0ec6a9ac85e56af60e7438b855b46..2ee994ec5a39dd58dee445ba3eb77a62a0f5bd37 100644 --- a/services/packageusage/include/bundle_active_period_stats.h +++ b/services/packageusage/include/bundle_active_period_stats.h @@ -40,6 +40,7 @@ public: int64_t lastTimeSaved_; int32_t userId_; std::map> bundleStats_; + std::map> packageContainUid_; BundleActiveEventList events_; std::set packetNamesCache_; BundleActiveEventTracker interactiveTracker_; @@ -62,13 +63,13 @@ public: * parameters: bundleName * return: point to bundle usage statistics object. */ - std::shared_ptr GetOrCreateUsageStats(const std::string& bundleName); + std::shared_ptr GetOrCreateUsageStats(const std::string& bundleName, const int32_t uid); /* * function: Update, update usage statistics of specific bundle. * parameters: bundleName, longTimeTaskName, timeStamp, eventId, abilityId */ void Update(const std::string bundleName, const std::string longTimeTaskName, const int64_t timeStamp, - const int32_t eventId, const std::string abilityId); + const int32_t eventId, const std::string abilityId, const int32_t uid); /* * function: AddEvent, add a event to member events_. * parameters: event @@ -110,6 +111,9 @@ public: * return: string */ std::string GetCachedString(std::string str); +private: + void updateAllPackageStats(const std::string bundleName, const int64_t timeStamp, const int32_t eventId, + const std::string abilityId); }; } // namespace DeviceUsageStats } // namespace OHOS diff --git a/services/packageusage/include/bundle_active_user_service.h b/services/packageusage/include/bundle_active_user_service.h index bb1d1d9d21f25c84ea737de5785b2acb9b2d23bb..9fd1da2d2e59af8e28a272fa9bba429f0ccf52ff 100644 --- a/services/packageusage/include/bundle_active_user_service.h +++ b/services/packageusage/include/bundle_active_user_service.h @@ -63,7 +63,7 @@ public: void RenewStatsInMemory(const int64_t timeStamp); void RenewTableTime(int64_t oldTime, int64_t newTime); void OnUserRemoved(); - void DeleteUninstalledBundleStats(const std::string& bundleName); + void DeleteUninstalledBundleStats(const std::string& bundleName, const int32_t uid, const int32_t appIndex); int32_t userId_; BundleActiveCalendar dailyExpiryDate_; ErrCode QueryBundleStatsInfos(std::vector& PackageStats, int32_t intervalType, @@ -107,6 +107,12 @@ private: void FlushDataInMem(std::set &continueBundles, std::map> &continueAbilities, std::map> &continueServices); + void DeleteMemUsageStats(const std::shared_ptr& currentStats, + const std::string& bundleName, const int32_t deletedUid, int32_t appIndex); + void DeleteMemEvent(const std::shared_ptr& currentStats, const std::string& bundleName, + const int32_t deletedUid, int32_t appIndex); + void DeleteMemRecords(const std::shared_ptr& currentStats, const std::string& bundleName, + const int32_t deletedUid, int32_t appIndex); }; } // namespace DeviceUsageStats } // namespace OHOS diff --git a/services/packageusage/src/bundle_active_period_stats.cpp b/services/packageusage/src/bundle_active_period_stats.cpp index 502a7642cbe3d450a85e9df91aeeaefcb8b31252..aff653f3014f0da5ecaa845ff4ae51c5717f996d 100644 --- a/services/packageusage/src/bundle_active_period_stats.cpp +++ b/services/packageusage/src/bundle_active_period_stats.cpp @@ -14,7 +14,7 @@ */ #include "bundle_active_period_stats.h" -#include "bundle_active_event.h" +#include "bundle_active_event.h namespace OHOS { namespace DeviceUsageStats { @@ -41,32 +41,34 @@ BundleActivePeriodStats::BundleActivePeriodStats(int32_t userId, int64_t beginTi } std::shared_ptr BundleActivePeriodStats::GetOrCreateUsageStats( - const std::string& bundleName) + const std::string& bundleName, const int32_t uid) { - std::map>::iterator it = bundleStats_.find(bundleName); + string bundleStatsKey = bundleName + std::to_string(uid); + std::map>::iterator it = bundleStats_.find(bundleStatsKey); if (it == bundleStats_.end()) { std::shared_ptr insertedStats = std::make_shared(); insertedStats->endTimeStamp_ = endTime_; insertedStats->bundleName_ = GetCachedString(bundleName); - bundleStats_[insertedStats->bundleName_] = insertedStats; + insertedStats->uid_ = uid; + bundleStats_[bundleStatsKey] = insertedStats; } - return bundleStats_[bundleName]; + return bundleStats_[bundleStatsKey]; } void BundleActivePeriodStats::Update(const std::string bundleName, const std::string longTimeTaskName, - const int64_t timeStamp, const int32_t eventId, const std::string abilityId) + const int64_t timeStamp, const int32_t eventId, const std::string abilityId, const int32_t uid) { if (eventId == BundleActiveEvent::SHUTDOWN || eventId == BundleActiveEvent::FLUSH) { for (std::map>::iterator it = bundleStats_.begin(); it != bundleStats_.end(); ++it) { std::shared_ptr tmpUsageStats = it->second; if (tmpUsageStats != nullptr) { - tmpUsageStats->Update("", timeStamp, eventId, abilityId); + tmpUsageStats->Update("", timeStamp, eventId, abilityId, uid); } } } else if (BundleActiveEvent::IsBundleEvent(eventId)) { - auto usageStats = GetOrCreateUsageStats(bundleName); - usageStats->Update(longTimeTaskName, timeStamp, eventId, abilityId); + auto usageStats = GetOrCreateUsageStats(bundleName, uid); + usageStats->Update(longTimeTaskName, timeStamp, eventId, abilityId, uid); } if (timeStamp > endTime_) { endTime_ = timeStamp; diff --git a/services/packageusage/src/bundle_active_report_handler.cpp b/services/packageusage/src/bundle_active_report_handler.cpp index fab3800821c1fff1fef2023854a9d8a28b0b2d0a..369222f02b47d7a01dc97a3c80729ec5b21bdb07 100644 --- a/services/packageusage/src/bundle_active_report_handler.cpp +++ b/services/packageusage/src/bundle_active_report_handler.cpp @@ -63,7 +63,8 @@ void BundleActiveReportHandler::ProcessEvent(const AppExecFwk::InnerEvent::Point case MSG_BUNDLE_UNINSTALLED: { BUNDLE_ACTIVE_LOGI("MSG_BUNDLE_UNINSTALLED CALLED"); BundleActiveReportHandlerObject tmpHandlerobj = *ptrToHandlerobj; - bundleActiveCore_->OnBundleUninstalled(tmpHandlerobj.userId_, tmpHandlerobj.bundleName_); + bundleActiveCore_->OnBundleUninstalled(tmpHandlerobj.userId_, tmpHandlerobj.bundleName_, + tmpHandlerobj.uid_, tmpHandlerobj.appIndex_); break; } case MSG_SWITCH_USER: { diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp index 3291f34061513eebff43150947969a4efe38c39c..986f85b54d6599fa75eb4cb436ec9f61c92bc986 100644 --- a/services/packageusage/src/bundle_active_user_service.cpp +++ b/services/packageusage/src/bundle_active_user_service.cpp @@ -45,32 +45,88 @@ void BundleActiveUserService::Init(const int64_t timeStamp) void BundleActiveUserService::OnUserRemoved() { - database_.OnPackageUninstalled(userId_, ""); + database_.OnPackageUninstalled(userId_, "", 0, 0); } -void BundleActiveUserService::DeleteUninstalledBundleStats(const std::string& bundleName) +void BundleActiveUserService::DeleteUninstalledBundleStats(const std::string& bundleName, const int32_t uid, + const int32_t appIndex) { for (auto it : currentStats_) { if (it != nullptr) { - if (it->bundleStats_.find(bundleName) != it->bundleStats_.end()) { - it->bundleStats_.erase(bundleName); + DeleteMemUsageStats(it, bundleName, uid, appIndex); + DeleteMemEvent(it, bundleName, uid, appIndex); + DeleteMemRecords(it, bundleName, uid, appIndex); + } + } + database_.OnPackageUninstalled(userId_, bundleName, uid, appIndex); +} + +void BundleActiveUserService::DeleteMemUsageStats(const std::shared_ptr& currentStats, + const std::string& bundleName, const int32_t deletedUid, int32_t appIndex) +{ + std::string bundleStatsKey = bundleName + std::to_string(deletedUid); + if (appIndex != 0) { + if (currentStats->bundleStats_.find(bundleName) != currentStats->bundleStats_.end()) { + currentStats->bundleStats_.erase(bundleStatsKey); + } + return; + } + if (currentStats->packageContainUid_.find(bundleName) != currentStats->packageContainUid_.end()) { + for (auto it: currentStats->packageContainUid_.find(bundleName)->second) { + bundleStatsKey = bundleName + std::to_string(it); + currentStats->bundleStats_.erase(bundleStatsKey); + } + } +} + +void BundleActiveUserService::DeleteMemEvent(const std::shared_ptr& currentStats, + const std::string& bundleName, const int32_t deletedUid, int32_t appIndex) +{ + std::string bundleStatsKey = bundleName + std::to_string(deletedUid); + if (appIndex != 0) { + for (auto eventIter = currentStats->events_.events_.begin(); + eventIter != currentStats->events_.events_.end();) { + if (eventIter->bundleName_ == bundleName && eventIter->uid_ == deletedUid) { + currentStats->events_.events_.erase(eventIter); + } else { + eventIter++; } - for (auto eventIter = it->events_.events_.begin(); eventIter != it->events_.events_.end();) { - if (eventIter->bundleName_ == bundleName) { - it->events_.events_.erase(eventIter); - } else { - eventIter++; - } + } + return; + } + if (currentStats->packageContainUid_.find(bundleName) != currentStats->packageContainUid_.end()) { + auto uidSet = currentStats->packageContainUid_.find(bundleName)->second; + for (auto eventIter = currentStats->events_.events_.begin(); + eventIter != currentStats->events_.events_.end();) { + if (eventIter->bundleName_ == bundleName && uidSet.find(eventIter->uid_) != uidSet.end()) { + currentStats->events_.events_.erase(eventIter); + } else { + eventIter++; } } } +} + +void BundleActiveUserService::DeleteMemRecords(const std::shared_ptr& currentStats, + const std::string& bundleName, const int32_t deletedUid, int32_t appIndex) +{ + if (appIndex != 0) { + for (auto it : moduleRecords_) { + std::string moduleKey = bundleName + " " + std::to_string(deletedUid); + if (it.first.find(moduleKey) != std::string::npos) { + moduleRecords_.erase(it.first); + break; + } + } + return; + } for (auto it : moduleRecords_) { if (it.first.find(bundleName) != std::string::npos) { moduleRecords_.erase(it.first); break; } } - database_.OnPackageUninstalled(userId_, bundleName); + currentStats->packageContainUid_.erase(bundleName); } void BundleActiveUserService::RenewTableTime(int64_t oldTime, int64_t newTime) @@ -134,7 +190,7 @@ void BundleActiveUserService::ReportEvent(const BundleActiveEvent& event) break; default: it->Update(event.bundleName_, event.continuousTaskAbilityName_, event.timeStamp_, event.eventId_, - event.abilityId_); + event.abilityId_, event.uid_); if (incrementBundleLaunch) { it->bundleStats_[event.bundleName_]->IncrementBundleLaunchedCount(); } @@ -159,7 +215,7 @@ void BundleActiveUserService::ReportForShutdown(const BundleActiveEvent& event) } for (auto it : currentStats_) { it->Update(event.bundleName_, event.continuousTaskAbilityName_, event.timeStamp_, event.eventId_, - event.abilityId_); + event.abilityId_, event.uid_); } BUNDLE_ACTIVE_LOGI("ReportForShutdown called notify"); NotifyStatsChanged(); @@ -265,16 +321,17 @@ void BundleActiveUserService::FlushDataInMem(std::set &continueBund continue; } BundleActivePackageStats bundleUsageStats(*(bundleUsageStatsPair.second)); + std::string bundleStatsKey = bundleUsageStats.bundleName_ + std::to_string(bundleUsageStats.uid_); if (!bundleUsageStats.abilities_.empty()) { - continueAbilities[bundleUsageStats.bundleName_] = bundleUsageStats.abilities_; + continueAbilities[bundleStatsKey] = bundleUsageStats.abilities_; } if (!bundleUsageStats.longTimeTasks_.empty()) { - continueServices[bundleUsageStats.bundleName_] = bundleUsageStats.longTimeTasks_; + continueServices[bundleStatsKey] = bundleUsageStats.longTimeTasks_; } (*it)->Update(bundleUsageStats.bundleName_, "", dailyExpiryDate_.GetMilliseconds() - 1, - BundleActiveEvent::END_OF_THE_DAY, ""); + BundleActiveEvent::END_OF_THE_DAY, "", bundleUsageStats.uid_); - continueBundles.insert(bundleUsageStats.bundleName_); + continueBundles.insert(bundleStatsKey); NotifyStatsChanged(); } (*it)->CommitTime(dailyExpiryDate_.GetMilliseconds() - 1); @@ -285,15 +342,26 @@ void BundleActiveUserService::UpdateContinueAbilitiesMemory(const int64_t& begin const std::map>& continueAbilities, const std::string& continueBundleName, const std::vector>::iterator& itInterval) { + auto iter = (*itInterval)->packageContainUid_.find(continueBundleName); + if (iter == (*itInterval)->packageContainUid_.end()) { + return; + } auto ability = continueAbilities.find(continueBundleName); if (ability == continueAbilities.end()) { return; } - for (auto it = ability->second.begin(); it != ability->second.end(); ++it) { - if (it->second == BundleActiveEvent::ABILITY_BACKGROUND) { - continue; + for (auto uid: iter->second) { + std::string continueAbilitiesKey = continueBundleName + std::to_string(uid); + auto ability = continueAbilities.find(continueBundleName); + if (ability == continueAbilities.end()) { + return; + } + for (auto it = ability->second.begin(); it != ability->second.end(); ++it) { + if (it->second == BundleActiveEvent::ABILITY_BACKGROUND) { + continue; + } + (*itInterval)->Update(continueBundleName, "", beginTime, it->second, it->first, uid); } - (*itInterval)->Update(continueBundleName, "", beginTime, it->second, it->first); } } @@ -301,13 +369,20 @@ void BundleActiveUserService::UpdateContinueServicesMemory(const int64_t& beginT const std::map>& continueServices, const std::string& continueBundleName, const std::vector>::iterator& itInterval) { - auto service = continueServices.find(continueBundleName); - if (service == continueServices.end()) { + auto iter = (*itInterval)->packageContainUid_.find(continueBundleName); + if (iter == (*itInterval)->packageContainUid_.end()) { return; } - for (auto it = service->second.begin(); it != service->second.end(); ++it) { - (*itInterval)->Update(continueBundleName, it->first, beginTime, it->second, ""); + for (auto uid: iter->second) { + std::string continueServicesKey = continueBundleName + std::to_string(uid); + auto service = continueServices.find(continueServicesKey); + if (service == continueServices.end()) { + return; + } + for (auto it = service->second.begin(); it != service->second.end(); ++it) { + (*itInterval)->Update(continueBundleName, it->first, beginTime, it->second, "", uid); + } } } @@ -324,10 +399,6 @@ void BundleActiveUserService::RenewStatsInMemory(const int64_t timeStamp) LoadActiveStats(timeStamp, false, false); // update timestamps of events in memory for (std::string continueBundleName : continueBundles) { - if (continueAbilities.find(continueBundleName) == continueAbilities.end() && - continueServices.find(continueBundleName) == continueServices.end()) { - continue; - } int64_t beginTime = currentStats_[BundleActivePeriodStats::PERIOD_DAILY]->beginTime_; for (std::vector>::iterator itInterval = currentStats_.begin(); itInterval != currentStats_.end(); ++itInterval) { @@ -567,10 +638,11 @@ void BundleActiveUserService::PrintInMemPackageStats(const int32_t idx, const bo int64_t totalUsedTime = it.second->totalInFrontTime_; int64_t lastTimeContinuousTaskUsed = it.second->lastContiniousTaskUsed_; int64_t totalTimeContinuousTaskUsed = it.second->totalContiniousTaskUsedTime_; + int32_t uid = it.second->uid_; BUNDLE_ACTIVE_LOGI("bundle stat is, totaltime is %{public}lld, lastTimeUsed is %{public}lld" - "total continuous task is %{public}lld, lastTimeContinuousTaskUsed is %{public}lld", + "total continuous task is %{public}lld, lastTimeContinuousTaskUsed is %{public}lld uid is %{public}d", (long long)totalUsedTime, (long long)lastTimeUsed, - (long long)totalTimeContinuousTaskUsed, (long long)lastTimeContinuousTaskUsed); + (long long)totalTimeContinuousTaskUsed, (long long)lastTimeContinuousTaskUsed, uid); } } @@ -588,9 +660,10 @@ void BundleActiveUserService::PrintInMemEventStats(const bool debug) std::string bundlename = currentStats_[idx]->events_.events_[i].bundleName_; int32_t eventid = currentStats_[idx]->events_.events_[i].eventId_; int64_t timestamp = currentStats_[idx]->events_.events_[i].timeStamp_; + int32_t uid = currentStats_[idx]->events_.events_[i].uid_; BUNDLE_ACTIVE_LOGI("In mem, event stat is, abilityid is %{public}s, abilityname is %{public}s, " - "bundlename is %{public}s, eventid is %{public}d, timestamp is %{public}lld", - abilityId.c_str(), abilityname.c_str(), bundlename.c_str(), eventid, (long long)timestamp); + "bundlename is %{public}s, eventid is %{public}d, timestamp is %{public}lld, uid is %{public}d", + abilityId.c_str(), abilityname.c_str(), bundlename.c_str(), eventid, (long long)timestamp, uid); } } @@ -602,9 +675,9 @@ void BundleActiveUserService::PrintInMemFormStats(const bool debug, const bool p for (const auto& oneModule : moduleRecords_) { if (oneModule.second) { BUNDLE_ACTIVE_LOGI("bundle name is %{public}s, module name is %{public}s, " - "lastusedtime is %{public}lld, launchcount is %{public}d", oneModule.second->bundleName_.c_str(), - oneModule.second->moduleName_.c_str(), - (long long)oneModule.second->lastModuleUsedTime_, oneModule.second->launchedCount_); + "lastusedtime is %{public}lld, launchcount is %{public}d, uid is %{public}d", + oneModule.second->bundleName_.c_str(), oneModule.second->moduleName_.c_str(), + (long long)oneModule.second->lastModuleUsedTime_, oneModule.second->launchedCount_, oneModule.second->uid_); BUNDLE_ACTIVE_LOGI("combined info is %{public}s", oneModule.first.c_str()); if (printform) { for (const auto& oneForm : oneModule.second->formRecords_) { @@ -636,12 +709,13 @@ void BundleActiveUserService::ReportFormEvent(const BundleActiveEvent& event) BUNDLE_ACTIVE_LOGI("ReportFormEvent called"); auto moduleRecord = GetOrCreateModuleRecord(event); if (event.eventId_ == BundleActiveEvent::FORM_IS_CLICKED && moduleRecord) { - moduleRecord->AddOrUpdateOneFormRecord(event.formName_, event.formDimension_, event.formId_, event.timeStamp_); + moduleRecord->AddOrUpdateOneFormRecord(event.formName_, event.formDimension_, event.formId_, + event.timeStamp_, event.uid_); NotifyStatsChanged(); } else if (event.eventId_ == BundleActiveEvent::FORM_IS_REMOVED && moduleRecord) { moduleRecord->RemoveOneFormRecord(event.formName_, event.formDimension_, event.formId_); database_.RemoveFormData(userId_, event.bundleName_, event.moduleName_, event.formName_, event.formDimension_, - event.formId_); + event.formId_, event.uid_); } PrintInMemFormStats(debugUserService_, true); } @@ -650,13 +724,14 @@ std::shared_ptr BundleActiveUserService::GetOrCreateMo const BundleActiveEvent& event) { BUNDLE_ACTIVE_LOGI("GetOrCreateModuleRecord called"); - std::string combinedInfo = event.bundleName_ + " " + event.moduleName_; + std::string combinedInfo = event.bundleName_ + " " + std::to_string(event.uid) + " " + event.moduleName_; auto it = moduleRecords_.find(combinedInfo); if (it == moduleRecords_.end()) { auto moduleRecordInserted = std::make_shared(); moduleRecordInserted->bundleName_ = event.bundleName_; moduleRecordInserted->moduleName_ = event.moduleName_; moduleRecordInserted->userId_ = userId_; + moduleRecordInserted->uid_ = event.uid_; moduleRecords_[combinedInfo] = moduleRecordInserted; } return moduleRecords_[combinedInfo]; diff --git a/test/unittest/device_usage_statistics_mock_test.cpp b/test/unittest/device_usage_statistics_mock_test.cpp index 7048b29bb236ae77dd4aa76ab02bb8d7cf0ca259..3bab22303283cb8627c8e3b2efe1d36d53d96f8b 100644 --- a/test/unittest/device_usage_statistics_mock_test.cpp +++ b/test/unittest/device_usage_statistics_mock_test.cpp @@ -305,8 +305,9 @@ HWTEST_F(DeviceUsageStatisticsMockTest, DeviceUsageStatisticsMockTest_CheckTimeC BundleActiveEvent eventTemp; EXPECT_NE(bundleActiveCore->ReportEventToAllUserId(eventTemp), ERR_OK); - - bundleActiveCore->OnBundleUninstalled(g_defaultUserId, g_defaultBundleName); + int32_t uid = 0; + int32_t appIndex = 0; + bundleActiveCore->OnBundleUninstalled(g_defaultUserId, g_defaultBundleName, uid, appIndex); EXPECT_NE(bundleActiveCore->QueryNotificationEventStats(0, g_largeNum, eventStats, g_commonUserid), ERR_OK); EXPECT_NE(bundleActiveCore->QueryDeviceEventStats(0, g_largeNum, eventStats, g_commonUserid), ERR_OK); @@ -319,7 +320,7 @@ HWTEST_F(DeviceUsageStatisticsMockTest, DeviceUsageStatisticsMockTest_CheckTimeC g_intervalType, 0, g_largeNum, g_defaultBundleName); EXPECT_NE(code, ERR_OK); - bundleActiveCore->OnBundleUninstalled(g_commonUserid, g_defaultBundleName); + bundleActiveCore->OnBundleUninstalled(g_commonUserid, g_defaultBundleName, uid, appIndex); } /* @@ -333,10 +334,12 @@ HWTEST_F(DeviceUsageStatisticsMockTest, DeviceUsageStatisticsMockTest_getUserHis { auto groupController = std::make_shared(false); const int64_t timeStamp = g_largeNum; + int32_t uid = 0; + int32_t appIndex = 0; auto bundleActiveCore = std::make_shared(); groupController->bundleUserHistory_ = std::make_shared(timeStamp, bundleActiveCore); - groupController->OnBundleUninstalled(0, g_defaultBundleName); + groupController->OnBundleUninstalled(0, g_defaultBundleName, uid, appIndex); EXPECT_NE(groupController, nullptr); } @@ -443,7 +446,9 @@ HWTEST_F(DeviceUsageStatisticsMockTest, DeviceUsageStatisticsMockTest_GetBundleA database->RenameTableName(databaseType, 0, 0); std::string bundleName = "defaultBundleName"; std::string tableName = "defaultTableName"; - database->DeleteUninstalledInfo(userId, bundleName, tableName, databaseType); + int32_t uid = 0; + int32_t appIndex = 0; + database->DeleteUninstalledInfo(userId, bundleName, 0, tableName, databaseType, uid, appIndex); auto moduleRecords = std::map>(); int64_t timeStamp = 20000000000; @@ -451,7 +456,7 @@ HWTEST_F(DeviceUsageStatisticsMockTest, DeviceUsageStatisticsMockTest_GetBundleA std::string moduleName = "defaultMoudleName"; std::string formName = "defaultFormName"; - database->RemoveFormData(userId, bundleName, moduleName, formName, 0, 0); + database->RemoveFormData(userId, bundleName, moduleName, formName, 0, 0, uid); } /* diff --git a/test/unittest/device_usage_statistics_service_test.cpp b/test/unittest/device_usage_statistics_service_test.cpp index d8b829bedc59a8f8831720f5df481bc8fa7f305a..8a18c5a3274c02bd833919fd4267ecc9e1fc2bc4 100644 --- a/test/unittest/device_usage_statistics_service_test.cpp +++ b/test/unittest/device_usage_statistics_service_test.cpp @@ -776,7 +776,7 @@ HWTEST_F(DeviceUsageStatisticsServiceTest, BundleActiveGroupControllerTest_003, int64_t timeStamp = 20000000000000; userService->Init(timeStamp); coreObject->userStatServices_[userId] = userService; - coreObject->bundleGroupController_->GetNewGroup("test", userId, timeStamp); + coreObject->bundleGroupController_->GetNewGroup("test", userId, timeStamp, 0); } /* @@ -815,7 +815,7 @@ HWTEST_F(DeviceUsageStatisticsServiceTest, BundleActiveGroupControllerTest_005, coreObject->InitBundleGroupController(); int userId = 100; int64_t timeStamp = 20000000000000; - coreObject->bundleGroupController_->CheckAndUpdateGroup("test", userId, timeStamp); + coreObject->bundleGroupController_->CheckAndUpdateGroup("test", 0, userId, timeStamp); } /* @@ -901,7 +901,7 @@ HWTEST_F(DeviceUsageStatisticsServiceTest, BundleActiveUserHistoryTest_001, std::vector screenTimeLevel; std::vector bootFromTimeLevel; auto bundleUserHistory_ = std::make_shared(bootBasedTimeStamp, bundleActiveCore); - bundleUserHistory_->GetLevelIndex("test", 0, 20000, screenTimeLevel, bootFromTimeLevel); + bundleUserHistory_->GetLevelIndex("test", 0, 20000, screenTimeLevel, bootFromTimeLevel, 0); } /* @@ -917,7 +917,7 @@ HWTEST_F(DeviceUsageStatisticsServiceTest, BundleActiveUserHistoryTest_002, std::shared_ptr bundleActiveCore; auto bundleUserHistory_ = std::make_shared(bootBasedTimeStamp, bundleActiveCore); bundleUserHistory_->WriteDeviceDuration(); - bundleUserHistory_->OnBundleUninstalled(0, "test"); + bundleUserHistory_->OnBundleUninstalled(0, "test", 0, 0); } /* @@ -933,11 +933,11 @@ HWTEST_F(DeviceUsageStatisticsServiceTest, BundleActiveUserHistoryTest_003, std::shared_ptr bundleActiveCore; std::shared_ptr oneBundleUsageHistory; auto bundleUserHistory_ = std::make_shared(bootBasedTimeStamp, bundleActiveCore); - bundleUserHistory_->ReportUsage(oneBundleUsageHistory, "test", 0, 0, 1000, 2000, 100); - bundleUserHistory_->ReportUsage(oneBundleUsageHistory, "test", 0, 0, 2000, 1000, 100); - bundleUserHistory_->ReportUsage(oneBundleUsageHistory, "test", 10, 0, 1000, 2000, 100); - bundleUserHistory_->ReportUsage(oneBundleUsageHistory, "test", 20, 0, 1000, 2000, 100); - bundleUserHistory_->ReportUsage(oneBundleUsageHistory, "test", 20, 0, 0, 2000, 100); + bundleUserHistory_->ReportUsage(oneBundleUsageHistory, "test", 0, 0, 1000, 2000, 100, 0); + bundleUserHistory_->ReportUsage(oneBundleUsageHistory, "test", 0, 0, 2000, 1000, 100, 0); + bundleUserHistory_->ReportUsage(oneBundleUsageHistory, "test", 10, 0, 1000, 2000, 100, 0); + bundleUserHistory_->ReportUsage(oneBundleUsageHistory, "test", 20, 0, 1000, 2000, 100, 0); + bundleUserHistory_->ReportUsage(oneBundleUsageHistory, "test", 20, 0, 0, 2000, 100, 0); } /* @@ -954,9 +954,10 @@ HWTEST_F(DeviceUsageStatisticsServiceTest, BundleActiveUserHistoryTest_004, int64_t bootBasedTimeStamp = 2000; int32_t newgroup = 0; uint32_t groupReason = 0; + int32_t uid = 0; auto bundleUserHistory_ = std::make_shared(bootBasedTimeStamp, bundleActiveCore); - bundleUserHistory_->SetAppGroup("test", userId, bootBasedTimeStamp, newgroup, groupReason, true); - bundleUserHistory_->SetAppGroup("test", userId, bootBasedTimeStamp, newgroup, groupReason, false); + bundleUserHistory_->SetAppGroup("test", userId, uid, bootBasedTimeStamp, newgroup, groupReason, true); + bundleUserHistory_->SetAppGroup("test", userId, uid, bootBasedTimeStamp, newgroup, groupReason, false); } /* @@ -1087,12 +1088,12 @@ HWTEST_F(DeviceUsageStatisticsServiceTest, DeviceUsageStatisticsServiceTest_Chec coreObject->bundleGroupController_->QueryAppGroup(appGroup, bundleName, userId); coreObject->bundleGroupController_->SetAppGroup(bundleName, userId, newGroup, reason, bootBasedTimeStamp, isFlush); - coreObject->bundleGroupController_->CheckAndUpdateGroup(bundleName, userId, bootBasedTimeStamp); + coreObject->bundleGroupController_->CheckAndUpdateGroup(bundleName, 0, userId, bootBasedTimeStamp); newGroup = 20; reason = GROUP_CONTROL_REASON_CALCULATED; coreObject->bundleGroupController_->SetAppGroup(bundleName, userId, newGroup, reason, bootBasedTimeStamp, isFlush); - coreObject->bundleGroupController_->CheckAndUpdateGroup(bundleName, userId, bootBasedTimeStamp); + coreObject->bundleGroupController_->CheckAndUpdateGroup(bundleName, 0, userId, bootBasedTimeStamp); EXPECT_NE(coreObject, nullptr); } @@ -1327,7 +1328,7 @@ HWTEST_F(DeviceUsageStatisticsServiceTest, DeviceUsageStatisticsServiceTest_Remo std::string moduleName = "defaultModuleName"; std::string formName = "defaultFormName"; database->InitUsageGroupDatabase(0, true); - database->RemoveFormData(userId, bundleName, moduleName, formName, 0, 0); + database->RemoveFormData(userId, bundleName, moduleName, formName, 0, 0, 0); EXPECT_NE(database, nullptr); } diff --git a/test/unittest/package_usage_test.cpp b/test/unittest/package_usage_test.cpp index ddf5fa3f98c84d93d49287d7d34e62dfb7f2bf21..545a73dc54f492a94858408d2caf35fbc25bb9f4 100644 --- a/test/unittest/package_usage_test.cpp +++ b/test/unittest/package_usage_test.cpp @@ -71,31 +71,32 @@ HWTEST_F(PackageUsageTest, PackageUsageTest_Update_001, Function | MediumTest | int64_t timeStamp = 20000000000000; int32_t eventId = BundleActiveEvent::ABILITY_FOREGROUND; std::string abilityId = "defaultAbilityId"; - packageStats->Update(longTimeTaskName, timeStamp, eventId, abilityId); + int32_t uid = 0; + packageStats->Update(longTimeTaskName, timeStamp, eventId, abilityId, uid); eventId = BundleActiveEvent::ABILITY_BACKGROUND; - packageStats->Update(longTimeTaskName, timeStamp, eventId, abilityId); + packageStats->Update(longTimeTaskName, timeStamp, eventId, abilityId, uid); eventId = BundleActiveEvent::ABILITY_STOP; - packageStats->Update(longTimeTaskName, timeStamp, eventId, abilityId); + packageStats->Update(longTimeTaskName, timeStamp, eventId, abilityId, uid); eventId = BundleActiveEvent::END_OF_THE_DAY; - packageStats->Update(longTimeTaskName, timeStamp, eventId, abilityId); + packageStats->Update(longTimeTaskName, timeStamp, eventId, abilityId, uid); eventId = BundleActiveEvent::LONG_TIME_TASK_STARTTED; - packageStats->Update(longTimeTaskName, timeStamp, eventId, abilityId); + packageStats->Update(longTimeTaskName, timeStamp, eventId, abilityId, uid); eventId = BundleActiveEvent::LONG_TIME_TASK_ENDED; - packageStats->Update(longTimeTaskName, timeStamp, eventId, abilityId); + packageStats->Update(longTimeTaskName, timeStamp, eventId, abilityId, uid); eventId = BundleActiveEvent::SHUTDOWN; - packageStats->Update(longTimeTaskName, timeStamp, eventId, abilityId); + packageStats->Update(longTimeTaskName, timeStamp, eventId, abilityId, uid); eventId = BundleActiveEvent::FLUSH; - packageStats->Update(longTimeTaskName, timeStamp, eventId, abilityId); + packageStats->Update(longTimeTaskName, timeStamp, eventId, abilityId, uid); eventId = BundleActiveEvent::SYSTEM_LOCK; - packageStats->Update(longTimeTaskName, timeStamp, eventId, abilityId); + packageStats->Update(longTimeTaskName, timeStamp, eventId, abilityId, uid); EXPECT_NE(packageStats, nullptr); } @@ -181,8 +182,9 @@ HWTEST_F(PackageUsageTest, PackageUsageTest_BundleActiveModuleRecord_001, Functi int32_t formDimension = 1; int64_t formId = 1; int64_t timeStamp = 20000000000000; - moduleRecord->AddOrUpdateOneFormRecord(forName, formDimension, formId, timeStamp); - moduleRecord->AddOrUpdateOneFormRecord(forName, formDimension, formId, timeStamp*10); + int32_t uid = 0; + moduleRecord->AddOrUpdateOneFormRecord(forName, formDimension, formId, timeStamp, uid); + moduleRecord->AddOrUpdateOneFormRecord(forName, formDimension, formId, timeStamp*10, uid); moduleRecord->lastModuleUsedTime_ = timeStamp; moduleRecord->UpdateModuleRecord(timeStamp); moduleRecord->RemoveOneFormRecord(forName, formDimension, formId);