diff --git a/hisysevent.yaml b/hisysevent.yaml index 03ef0c2025015e57b9235ad46d672c19cd9bb9b9..485d515e9a2c06c7c79a82a4432ef8f46375c005 100644 --- a/hisysevent.yaml +++ b/hisysevent.yaml @@ -75,6 +75,8 @@ BUNDLE_CLEAN_CACHE_EXCEPTION: USERID: {type: INT32, desc: userId of the bundle} BUNDLE_NAME: {type: STRING, desc: bundleName} CLEAN_TYPE: {type: STRING, desc: clean cache or clean data} + CALLING_UID: {type: INT32, desc: calling uid} + CALLING_BUNDLE_NAME: {type: STRING, desc: calling bundleName} ################################################################################ # BEHAVIOR EVENT # @@ -177,6 +179,8 @@ BUNDLE_CLEAN_CACHE: USERID: {type: INT32, desc: userId of the bundle} BUNDLE_NAME: {type: STRING, desc: bundleName} CLEAN_TYPE: {type: STRING, desc: clean cache or clean data} + CALLING_UID: {type: INT32, desc: calling uid} + CALLING_BUNDLE_NAME: {type: STRING, desc: calling bundleName} GET_REMOTE_ABILITY_INFO: __BASE: {type: BEHAVIOR, level: MINOR, desc: get remote abilityInfo} diff --git a/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_interface.h b/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_interface.h index 340fa27f6cdf19eecf148836423919f51faeaea5..8547ec4a8e0f0e5350eed6d494955e5507850979 100644 --- a/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_interface.h +++ b/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_interface.h @@ -745,7 +745,8 @@ public: * @param appIndex Indicates the app index. * @return Returns true if the data cleared successfully; returns false otherwise. */ - virtual bool CleanBundleDataFiles(const std::string &bundleName, const int userId = 0, const int appIndex = 0) + virtual bool CleanBundleDataFiles(const std::string &bundleName, + const int userId = 0, const int appIndex = 0, const int callerUid = -1) { return false; } diff --git a/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_proxy.h b/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_proxy.h index 6b8e1d8fa82de081d242559a179226d7d2cd3148..423a7f32b2e704ed3fabdaa6be7dc8bce69579e3 100644 --- a/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_proxy.h +++ b/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_proxy.h @@ -551,8 +551,8 @@ public: * @param appIndex Indicates the app index. * @return Returns true if the data cleared successfully; returns false otherwise. */ - virtual bool CleanBundleDataFiles(const std::string &bundleName, const int userId = 0, - const int appIndex = 0) override; + virtual bool CleanBundleDataFiles(const std::string &bundleName, + const int userId = 0, const int appIndex = 0, const int callerUid = -1) override; /** * @brief Register the specific bundle status callback through the proxy object. * @param bundleStatusCallback Indicates the callback to be invoked for returning the bundle status changed result. diff --git a/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_mgr_host.cpp b/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_mgr_host.cpp index 93d5a024b912cfd53cfbaeae0979a2df3557732f..bd9bde9cd95d82ea9ca3cb2a7f74b23e711efb99 100644 --- a/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_mgr_host.cpp +++ b/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_mgr_host.cpp @@ -1750,8 +1750,9 @@ ErrCode BundleMgrHost::HandleCleanBundleDataFiles(MessageParcel &data, MessagePa std::string bundleName = data.ReadString(); int userId = data.ReadInt32(); int appIndex = data.ReadInt32(); + int callerUid = data.ReadInt32(); - bool ret = CleanBundleDataFiles(bundleName, userId, appIndex); + bool ret = CleanBundleDataFiles(bundleName, userId, appIndex, callerUid); if (!reply.WriteBool(ret)) { APP_LOGE("write failed"); return ERR_APPEXECFWK_PARCEL_ERROR; diff --git a/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_mgr_proxy.cpp b/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_mgr_proxy.cpp index a1c862bbbc7ba400eaa7d19a616a24310a8b6ba0..a83fdd53286383bb3a38ec4eab813fae554db08a 100644 --- a/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_mgr_proxy.cpp +++ b/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_mgr_proxy.cpp @@ -1725,7 +1725,8 @@ ErrCode BundleMgrProxy::CleanBundleCacheFiles( return reply.ReadInt32(); } -bool BundleMgrProxy::CleanBundleDataFiles(const std::string &bundleName, const int userId, const int appIndex) +bool BundleMgrProxy::CleanBundleDataFiles(const std::string &bundleName, + const int userId, const int appIndex, const int callerUid) { HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); APP_LOGD("begin to CleanBundleDataFiles of %{public}s, userId:%{public}d, appIndex:%{public}d", @@ -1752,6 +1753,10 @@ bool BundleMgrProxy::CleanBundleDataFiles(const std::string &bundleName, const i APP_LOGE("fail to CleanBundleDataFiles due to write appIndex fail"); return false; } + if (!data.WriteInt32(callerUid)) { + APP_LOGE("fail to CleanBundleDataFiles due to write callerUid fail"); + return false; + } MessageParcel reply; if (!SendTransactCmd(BundleMgrInterfaceCode::CLEAN_BUNDLE_DATA_FILES, data, reply)) { diff --git a/services/bundlemgr/include/bundle_mgr_host_impl.h b/services/bundlemgr/include/bundle_mgr_host_impl.h index c09df70a2a705a5ad59eff65f3ae0f1b0fc1255e..920e4ecf29a1046762fb9666619b1faf5d3da4e0 100644 --- a/services/bundlemgr/include/bundle_mgr_host_impl.h +++ b/services/bundlemgr/include/bundle_mgr_host_impl.h @@ -531,7 +531,7 @@ public: * @return Returns true if the data cleared successfully; returns false otherwise. */ virtual bool CleanBundleDataFiles(const std::string &bundleName, - const int userId = Constants::UNSPECIFIED_USERID, const int appIndex = 0) override; + const int userId = Constants::UNSPECIFIED_USERID, const int appIndex = 0, const int callerUid = -1) override; /** * @brief Register the specific bundle status callback. * @param bundleStatusCallback Indicates the callback to be invoked for returning the bundle status changed result. @@ -1108,7 +1108,7 @@ private: ErrCode CleanBundleCacheFilesGetCleanSize(const std::string &bundleName, int32_t userId, uint64_t &cleanCacheSize); void CleanBundleCacheTaskGetCleanSize(const std::string &bundleName, - int32_t userId, uint64_t &cleanCacheSize); + int32_t userId, uint64_t &cleanCacheSize, int32_t callingUid, const std::string &callingBundleName); void NotifyBundleStatus(const NotifyBundleEvents &installRes); ErrCode GetBundleArchiveInfoBySandBoxPath( const std::string &hapFilePath, int32_t flags, BundleInfo &bundleInfo, bool fromV9 = false); @@ -1117,7 +1117,7 @@ private: BundleInfo &bundleInfo); bool IsBundleExist(const std::string &bundleName); ErrCode ClearCache(const std::string &bundleName, const sptr cleanCacheCallback, - int32_t userId); + int32_t userId, int32_t callingUid, const std::string &callingBundleName); void FilterAbilityInfos(std::vector &abilityInfos); void SetProvisionInfoToInnerBundleInfo(const std::string &hapPath, InnerBundleInfo &info); bool CheckAppIndex(const std::string &bundleName, int32_t userId, int32_t appIndex); diff --git a/services/bundlemgr/include/event_report.h b/services/bundlemgr/include/event_report.h index 86cfa9625b72eb29f528affbe32f0cb02195c98c..ca12a8a271bc9e37a692d4d428a3c3525e1d5c76 100644 --- a/services/bundlemgr/include/event_report.h +++ b/services/bundlemgr/include/event_report.h @@ -272,7 +272,8 @@ public: * @param exception Indicates the exception. */ static void SendCleanCacheSysEvent( - const std::string &bundleName, int32_t userId, bool isCleanCache, bool exception); + const std::string &bundleName, int32_t userId, bool isCleanCache, bool exception, + int32_t callingUid, const std::string &callingBundleName); /** * @brief Send clean cache system events. * @param bundleName Indicates the bundleName. @@ -282,7 +283,8 @@ public: * @param exception Indicates the exception. */ static void SendCleanCacheSysEventWithIndex( - const std::string &bundleName, int32_t userId, int32_t appIndex, bool isCleanCache, bool exception); + const std::string &bundleName, int32_t userId, int32_t appIndex, bool isCleanCache, bool exception, + int32_t callingUid, const std::string &callingBundleName); /** * @brief Send system events. * @param eventType Indicates the bms eventInfo. diff --git a/services/bundlemgr/src/aging/recently_unused_bundle_aging_handler.cpp b/services/bundlemgr/src/aging/recently_unused_bundle_aging_handler.cpp index d948fbcd4859fc98505daa6fb175332b0d68d827..40c5985849789f85bd089d014c1d7ee46dc0b876 100644 --- a/services/bundlemgr/src/aging/recently_unused_bundle_aging_handler.cpp +++ b/services/bundlemgr/src/aging/recently_unused_bundle_aging_handler.cpp @@ -125,10 +125,18 @@ bool RecentlyUnuseBundleAgingHandler::AgingClean( bool RecentlyUnuseBundleAgingHandler::CleanCache(const AgingBundleInfo &agingBundle) const { std::vector caches; + auto dataMgr = OHOS::DelayedSingleton::GetInstance()->GetDataMgr(); + int32_t callingUid = IPCSkeleton::GetCallingUid(); + std::string callingBundleName; + if (dataMgr == nullptr) { + APP_LOGE("dataMgr is null"); + } else { + dataMgr->GetBundleNameForUid(callingUid, callingBundleName); + } if (!GetCachePath(agingBundle, caches)) { APP_LOGW("Get cache path failed: %{public}s", agingBundle.GetBundleName().c_str()); EventReport::SendCleanCacheSysEvent( - agingBundle.GetBundleName(), Constants::ALL_USERID, true, true); + agingBundle.GetBundleName(), Constants::ALL_USERID, true, true, callingUid, callingBundleName); return false; } @@ -145,7 +153,7 @@ bool RecentlyUnuseBundleAgingHandler::CleanCache(const AgingBundleInfo &agingBun } EventReport::SendCleanCacheSysEvent( - agingBundle.GetBundleName(), Constants::ALL_USERID, true, !hasCleanCache); + agingBundle.GetBundleName(), Constants::ALL_USERID, true, !hasCleanCache, callingUid, callingBundleName); return hasCleanCache; } diff --git a/services/bundlemgr/src/bundle_mgr_host_impl.cpp b/services/bundlemgr/src/bundle_mgr_host_impl.cpp index e613ed3e081fdb4a9dfddfe8640de364c320f70b..1cd399aa646fdabb485c2345d56a45058966ef89 100644 --- a/services/bundlemgr/src/bundle_mgr_host_impl.cpp +++ b/services/bundlemgr/src/bundle_mgr_host_impl.cpp @@ -1517,53 +1517,55 @@ ErrCode BundleMgrHostImpl::CleanBundleCacheFilesGetCleanSize(const std::string & APP_LOGE("non-system app calling system api"); return ERR_BUNDLE_MANAGER_SYSTEM_API_DENIED; } - + auto dataMgr = GetDataMgrFromService(); + int32_t callingUid = IPCSkeleton::GetCallingUid(); + std::string callingBundleName; + if (dataMgr == nullptr) { + APP_LOGE("DataMgr is nullptr"); + EventReport::SendCleanCacheSysEvent(bundleName, userId, true, true, callingUid, callingBundleName); + return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR; + } + dataMgr->GetBundleNameForUid(callingUid, callingBundleName); if (userId < 0) { APP_LOGE("userId is invalid"); - EventReport::SendCleanCacheSysEvent(bundleName, userId, true, true); + EventReport::SendCleanCacheSysEvent(bundleName, userId, true, true, callingUid, callingBundleName); return ERR_BUNDLE_MANAGER_INVALID_USER_ID; } if (bundleName.empty()) { APP_LOGE("the bundleName empty"); - EventReport::SendCleanCacheSysEvent(bundleName, userId, true, true); + EventReport::SendCleanCacheSysEvent(bundleName, userId, true, true, callingUid, callingBundleName); return ERR_BUNDLE_MANAGER_PARAM_ERROR; } ApplicationInfo applicationInfo; - auto dataMgr = GetDataMgrFromService(); - if (dataMgr == nullptr) { - APP_LOGE("DataMgr is nullptr"); - EventReport::SendCleanCacheSysEvent(bundleName, userId, true, true); - return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR; - } auto ret = dataMgr->GetApplicationInfoWithResponseId(bundleName, static_cast(GetApplicationFlag::GET_APPLICATION_INFO_WITH_DISABLE), userId, applicationInfo); if (ret != ERR_OK) { APP_LOGE("can not get application info of %{public}s", bundleName.c_str()); - EventReport::SendCleanCacheSysEvent(bundleName, userId, true, true); + EventReport::SendCleanCacheSysEvent(bundleName, userId, true, true, callingUid, callingBundleName); return ret; } if (!applicationInfo.userDataClearable) { APP_LOGE("can not clean cacheFiles of %{public}s due to userDataClearable is false", bundleName.c_str()); - EventReport::SendCleanCacheSysEvent(bundleName, userId, true, true); + EventReport::SendCleanCacheSysEvent(bundleName, userId, true, true, callingUid, callingBundleName); return ERR_BUNDLE_MANAGER_CAN_NOT_CLEAR_USER_DATA; } - CleanBundleCacheTaskGetCleanSize(bundleName, userId, cleanCacheSize); + CleanBundleCacheTaskGetCleanSize(bundleName, userId, cleanCacheSize, callingUid, callingBundleName); return ERR_OK; } void BundleMgrHostImpl::CleanBundleCacheTaskGetCleanSize(const std::string &bundleName, - int32_t userId, uint64_t &cleanCacheSize) + int32_t userId, uint64_t &cleanCacheSize, int32_t callingUid, const std::string &callingBundleName) { InnerBundleInfo info; auto dataMgr = GetDataMgrFromService(); if (!dataMgr->FetchInnerBundleInfo(bundleName, info)) { APP_LOGE("can not get bundleinfo of %{public}s", bundleName.c_str()); - EventReport::SendCleanCacheSysEvent(bundleName, userId, true, true); + EventReport::SendCleanCacheSysEvent(bundleName, userId, true, true, callingUid, callingBundleName); return; } std::vector, std::vector>> validBundles; @@ -1575,13 +1577,13 @@ void BundleMgrHostImpl::CleanBundleCacheTaskGetCleanSize(const std::string &bund auto ret = BundleCacheMgr().CleanBundleCache(validBundles, userId); if (ret != ERR_OK) { APP_LOGE("can not get CleanBundleCache of %{public}s", bundleName.c_str()); - EventReport::SendCleanCacheSysEvent(bundleName, userId, true, true); + EventReport::SendCleanCacheSysEvent(bundleName, userId, true, true, callingUid, callingBundleName); return; } cleanCacheSize = cleanSize; bool succeed = true; - EventReport::SendCleanCacheSysEvent(bundleName, userId, true, !succeed); + EventReport::SendCleanCacheSysEvent(bundleName, userId, true, !succeed, callingUid, callingBundleName); APP_LOGI("CleanBundleCacheFiles with succeed %{public}d", succeed); InnerBundleUserInfo innerBundleUserInfo; if (!this->GetBundleUserInfo(bundleName, userId, innerBundleUserInfo)) { @@ -1633,51 +1635,61 @@ ErrCode BundleMgrHostImpl::CleanBundleCacheFiles( APP_LOGE("non-system app calling system api"); return ERR_BUNDLE_MANAGER_SYSTEM_API_DENIED; } + auto dataMgr = GetDataMgrFromService(); + int32_t callingUid = IPCSkeleton::GetCallingUid(); + std::string callingBundleName; + if (dataMgr == nullptr) { + APP_LOGE("DataMgr is nullptr"); + EventReport::SendCleanCacheSysEventWithIndex(bundleName, userId, appIndex, true, true, + callingUid, callingBundleName); + return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR; + } + (void)dataMgr->GetBundleNameForUid(callingUid, callingBundleName); if (!BundlePermissionMgr::VerifyCallingPermissionForAll(Constants::PERMISSION_REMOVECACHEFILE) && !BundlePermissionMgr::IsBundleSelfCalling(bundleName, appIndex)) { APP_LOGE("ohos.permission.REMOVE_CACHE_FILES permission denied"); - EventReport::SendCleanCacheSysEventWithIndex(bundleName, userId, appIndex, true, true); + EventReport::SendCleanCacheSysEventWithIndex(bundleName, userId, appIndex, true, true, + callingUid, callingBundleName); return ERR_BUNDLE_MANAGER_PERMISSION_DENIED; } if (userId < 0) { APP_LOGE("userId is invalid"); - EventReport::SendCleanCacheSysEventWithIndex(bundleName, userId, appIndex, true, true); + EventReport::SendCleanCacheSysEventWithIndex(bundleName, userId, appIndex, true, true, + callingUid, callingBundleName); return ERR_BUNDLE_MANAGER_INVALID_USER_ID; } if (bundleName.empty() || !cleanCacheCallback) { APP_LOGE("the cleanCacheCallback is nullptr or bundleName empty"); - EventReport::SendCleanCacheSysEventWithIndex(bundleName, userId, appIndex, true, true); + EventReport::SendCleanCacheSysEventWithIndex(bundleName, userId, appIndex, true, true, + callingUid, callingBundleName); return ERR_BUNDLE_MANAGER_PARAM_ERROR; } if (isBrokerServiceExisted_ && !IsBundleExist(bundleName)) { - return ClearCache(bundleName, cleanCacheCallback, userId); + return ClearCache(bundleName, cleanCacheCallback, userId, callingUid, callingBundleName); } ApplicationInfo applicationInfo; - auto dataMgr = GetDataMgrFromService(); - if (dataMgr == nullptr) { - APP_LOGE("DataMgr is nullptr"); - EventReport::SendCleanCacheSysEventWithIndex(bundleName, userId, appIndex, true, true); - return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR; - } auto ret = dataMgr->GetApplicationInfoWithResponseId(bundleName, static_cast(GetApplicationFlag::GET_APPLICATION_INFO_WITH_DISABLE), userId, applicationInfo); if (ret != ERR_OK) { APP_LOGE("can not get application info of %{public}s", bundleName.c_str()); - EventReport::SendCleanCacheSysEventWithIndex(bundleName, userId, appIndex, true, true); + EventReport::SendCleanCacheSysEventWithIndex(bundleName, userId, appIndex, true, true, + callingUid, callingBundleName); return ret; } if (!CheckAppIndex(bundleName, userId, appIndex)) { - EventReport::SendCleanCacheSysEventWithIndex(bundleName, userId, appIndex, true, true); + EventReport::SendCleanCacheSysEventWithIndex(bundleName, userId, appIndex, true, true, + callingUid, callingBundleName); return ERR_APPEXECFWK_APP_INDEX_OUT_OF_RANGE; } if (!applicationInfo.userDataClearable) { APP_LOGE("can not clean cacheFiles of %{public}s due to userDataClearable is false", bundleName.c_str()); - EventReport::SendCleanCacheSysEventWithIndex(bundleName, userId, appIndex, true, true); + EventReport::SendCleanCacheSysEventWithIndex(bundleName, userId, appIndex, true, true, + callingUid, callingBundleName); return ERR_BUNDLE_MANAGER_CAN_NOT_CLEAR_USER_DATA; } @@ -1693,9 +1705,13 @@ void BundleMgrHostImpl::CleanBundleCacheTask(const std::string &bundleName, std::vector rootDir; std::vector moduleNameList; dataMgr->GetBundleModuleNames(bundleName, moduleNameList); + int32_t callingUid = IPCSkeleton::GetCallingUid(); + std::string callingBundleName; + (void)dataMgr->GetBundleNameForUid(callingUid, callingBundleName); rootDir = BundleCacheMgr().GetBundleCachePath(bundleName, userId, appIndex, moduleNameList); - auto cleanCache = [bundleName, userId, rootDir, dataMgr, cleanCacheCallback, appIndex, this]() { + auto cleanCache = [bundleName, userId, rootDir, dataMgr, cleanCacheCallback, appIndex, + this, callingUid, callingBundleName]() { std::vector caches = rootDir; std::string shaderCachePath; shaderCachePath.append(ServiceConstants::SHADER_CACHE_PATH).append(bundleName); @@ -1711,7 +1727,7 @@ void BundleMgrHostImpl::CleanBundleCacheTask(const std::string &bundleName, } } - EventReport::SendCleanCacheSysEvent(bundleName, userId, true, !succeed); + EventReport::SendCleanCacheSysEvent(bundleName, userId, true, !succeed, callingUid, callingBundleName); APP_LOGD("CleanBundleCacheFiles with succeed %{public}d", succeed); cleanCacheCallback->OnCleanCacheFinished(succeed); InnerBundleUserInfo innerBundleUserInfo; @@ -1752,68 +1768,90 @@ void BundleMgrHostImpl::CleanBundleCacheTask(const std::string &bundleName, ffrt::submit(cleanCache); } -bool BundleMgrHostImpl::CleanBundleDataFiles(const std::string &bundleName, const int userId, const int appIndex) +bool BundleMgrHostImpl::CleanBundleDataFiles(const std::string &bundleName, const int userId, + const int appIndex, const int callerUid) { APP_LOGI("start CleanBundleDataFiles, bundleName : %{public}s, userId:%{public}d, appIndex:%{public}d", bundleName.c_str(), userId, appIndex); + auto dataMgr = GetDataMgrFromService(); + if (dataMgr == nullptr) { + APP_LOGE("DataMgr is nullptr"); + return false; + } + int32_t callingUid = callerUid; + if (callerUid == -1) { + callingUid = IPCSkeleton::GetCallingUid(); + } + std::string callingBundleName; + (void)dataMgr->GetBundleNameForUid(callingUid, callingBundleName); if (!BundlePermissionMgr::IsSystemApp()) { APP_LOGE("ohos.permission.REMOVE_CACHE_FILES system api denied"); - EventReport::SendCleanCacheSysEventWithIndex(bundleName, userId, appIndex, false, true); + EventReport::SendCleanCacheSysEventWithIndex(bundleName, userId, appIndex, false, true, + callingUid, callingBundleName); return false; } if (!BundlePermissionMgr::VerifyCallingPermissionForAll(Constants::PERMISSION_REMOVECACHEFILE)) { APP_LOGE("ohos.permission.REMOVE_CACHE_FILES permission denied"); - EventReport::SendCleanCacheSysEventWithIndex(bundleName, userId, appIndex, false, true); + EventReport::SendCleanCacheSysEventWithIndex(bundleName, userId, appIndex, false, true, + callingUid, callingBundleName); return false; } if (bundleName.empty() || userId < 0) { APP_LOGE("the bundleName empty or invalid userid"); - EventReport::SendCleanCacheSysEventWithIndex(bundleName, userId, appIndex, false, true); + EventReport::SendCleanCacheSysEventWithIndex(bundleName, userId, appIndex, false, true, + callingUid, callingBundleName); return false; } if (!CheckAppIndex(bundleName, userId, appIndex)) { - EventReport::SendCleanCacheSysEventWithIndex(bundleName, userId, appIndex, false, true); + EventReport::SendCleanCacheSysEventWithIndex(bundleName, userId, appIndex, false, true, + callingUid, callingBundleName); return false; } if (isBrokerServiceExisted_ && !IsBundleExist(bundleName)) { auto bmsExtensionClient = std::make_shared(); ErrCode ret = bmsExtensionClient->ClearData(bundleName, userId); APP_LOGI("ret : %{public}d", ret); - EventReport::SendCleanCacheSysEventWithIndex(bundleName, userId, appIndex, false, ret != ERR_OK); + EventReport::SendCleanCacheSysEventWithIndex(bundleName, userId, appIndex, false, ret != ERR_OK, + callingUid, callingBundleName); return ret == ERR_OK; } ApplicationInfo applicationInfo; - auto dataMgr = GetDataMgrFromService(); - if (dataMgr == nullptr || dataMgr->GetApplicationInfoV9(bundleName, + if (dataMgr->GetApplicationInfoV9(bundleName, static_cast(GetApplicationFlag::GET_APPLICATION_INFO_WITH_DISABLE), userId, applicationInfo, appIndex) != ERR_OK) { APP_LOGE("can not get application info of %{public}s", bundleName.c_str()); - EventReport::SendCleanCacheSysEventWithIndex(bundleName, userId, appIndex, false, true); + EventReport::SendCleanCacheSysEventWithIndex(bundleName, userId, appIndex, false, true, + callingUid, callingBundleName); return false; } if (!applicationInfo.userDataClearable) { APP_LOGE("can not clean dataFiles of %{public}s due to userDataClearable is false", bundleName.c_str()); - EventReport::SendCleanCacheSysEventWithIndex(bundleName, userId, appIndex, false, true); + EventReport::SendCleanCacheSysEventWithIndex(bundleName, userId, appIndex, false, true, + callingUid, callingBundleName); return false; } InnerBundleUserInfo innerBundleUserInfo; if (!GetBundleUserInfo(bundleName, userId, innerBundleUserInfo)) { APP_LOGE("%{public}s, userId:%{public}d, GetBundleUserInfo failed", bundleName.c_str(), userId); - EventReport::SendCleanCacheSysEventWithIndex(bundleName, userId, appIndex, false, true); + EventReport::SendCleanCacheSysEventWithIndex(bundleName, userId, appIndex, false, true, + callingUid, callingBundleName); return false; } if (BundlePermissionMgr::ClearUserGrantedPermissionState(applicationInfo.accessTokenId)) { APP_LOGE("%{public}s, ClearUserGrantedPermissionState failed", bundleName.c_str()); - EventReport::SendCleanCacheSysEventWithIndex(bundleName, userId, appIndex, false, true); + EventReport::SendCleanCacheSysEventWithIndex(bundleName, userId, appIndex, false, true, + callingUid, callingBundleName); return false; } if (InstalldClient::GetInstance()->CleanBundleDataDirByName(bundleName, userId, appIndex) != ERR_OK) { APP_LOGE("%{public}s, CleanBundleDataDirByName failed", bundleName.c_str()); - EventReport::SendCleanCacheSysEventWithIndex(bundleName, userId, appIndex, false, true); + EventReport::SendCleanCacheSysEventWithIndex(bundleName, userId, appIndex, false, true, + callingUid, callingBundleName); return false; } - EventReport::SendCleanCacheSysEventWithIndex(bundleName, userId, appIndex, false, false); + EventReport::SendCleanCacheSysEventWithIndex(bundleName, userId, appIndex, false, false, + callingUid, callingBundleName); return true; } @@ -4373,7 +4411,8 @@ bool BundleMgrHostImpl::IsBundleExist(const std::string &bundleName) } ErrCode BundleMgrHostImpl::ClearCache(const std::string &bundleName, - const sptr cleanCacheCallback, int32_t userId) + const sptr cleanCacheCallback, int32_t userId, + int32_t callingUid, const std::string &callingBundleName) { auto bmsExtensionClient = std::make_shared(); ErrCode ret = bmsExtensionClient->ClearCache(bundleName, cleanCacheCallback->AsObject(), userId); @@ -4381,7 +4420,7 @@ ErrCode BundleMgrHostImpl::ClearCache(const std::string &bundleName, if (ret != ERR_OK) { ret = ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST; } - EventReport::SendCleanCacheSysEvent(bundleName, userId, true, ret != ERR_OK); + EventReport::SendCleanCacheSysEvent(bundleName, userId, true, ret != ERR_OK, callingUid, callingBundleName); return ret; } diff --git a/services/bundlemgr/src/event_report.cpp b/services/bundlemgr/src/event_report.cpp index 54d9532790589a8ac0586d34d7735bab8c8cc3c0..9423ba9ec5f9422ae7a6e3630ff9558c9e07991f 100644 --- a/services/bundlemgr/src/event_report.cpp +++ b/services/bundlemgr/src/event_report.cpp @@ -118,12 +118,15 @@ void EventReport::SendComponentStateSysEvent(const std::string &bundleName, cons } void EventReport::SendCleanCacheSysEvent( - const std::string &bundleName, int32_t userId, bool isCleanCache, bool exception) + const std::string &bundleName, int32_t userId, bool isCleanCache, bool exception, + int32_t callingUid, const std::string &callingBundleName) { EventInfo eventInfo; eventInfo.bundleName = bundleName; eventInfo.userId = userId; eventInfo.isCleanCache = isCleanCache; + eventInfo.callingUid = callingUid; + eventInfo.callingBundleName = callingBundleName; BMSEventType bmsEventType; if (exception) { bmsEventType = BMSEventType::BUNDLE_CLEAN_CACHE_EXCEPTION; @@ -135,13 +138,16 @@ void EventReport::SendCleanCacheSysEvent( } void EventReport::SendCleanCacheSysEventWithIndex( - const std::string &bundleName, int32_t userId, int32_t appIndex, bool isCleanCache, bool exception) + const std::string &bundleName, int32_t userId, int32_t appIndex, bool isCleanCache, bool exception, + int32_t callingUid, const std::string &callingBundleName) { EventInfo eventInfo; eventInfo.bundleName = bundleName; eventInfo.userId = userId; eventInfo.appIndex = appIndex; eventInfo.isCleanCache = isCleanCache; + eventInfo.callingUid = callingUid; + eventInfo.callingBundleName = callingBundleName; BMSEventType bmsEventType; if (exception) { bmsEventType = BMSEventType::BUNDLE_CLEAN_CACHE_EXCEPTION; diff --git a/services/bundlemgr/src/inner_event_report.cpp b/services/bundlemgr/src/inner_event_report.cpp index 102c8f4a9b05207786063380aede9960eba918eb..1b1dac16e61412ac5ee8cde180adcd519e623cad 100644 --- a/services/bundlemgr/src/inner_event_report.cpp +++ b/services/bundlemgr/src/inner_event_report.cpp @@ -399,7 +399,9 @@ void InnerEventReport::InnerSendBundleCleanCacheExceptionEvent(const EventInfo& EVENT_PARAM_PVERSIONID, eventInfo.applicationVersion, EVENT_PARAM_USERID, eventInfo.userId, EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName, - EVENT_PARAM_CLEAN_TYPE, cleanType); + EVENT_PARAM_CLEAN_TYPE, cleanType, + EVENT_PARAM_CALLING_UID, eventInfo.callingUid, + EVENT_PARAM_CALLING_BUNDLE_NAME, eventInfo.callingBundleName); } void InnerEventReport::InnerSendBootScanStartEvent(const EventInfo& eventInfo) @@ -533,7 +535,9 @@ void InnerEventReport::InnerSendBundleCleanCacheEvent(const EventInfo& eventInfo EVENT_PARAM_PVERSIONID, eventInfo.applicationVersion, EVENT_PARAM_USERID, eventInfo.userId, EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName, - EVENT_PARAM_CLEAN_TYPE, cleanType); + EVENT_PARAM_CLEAN_TYPE, cleanType, + EVENT_PARAM_CALLING_UID, eventInfo.callingUid, + EVENT_PARAM_CALLING_BUNDLE_NAME, eventInfo.callingBundleName); } void InnerEventReport::InnerSendUserEvent(const EventInfo& eventInfo) diff --git a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_kit_service_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_kit_service_test.cpp index de9a0438f1d1ca2f02c3575cc1d4635bcfa9953d..6d7afec257b7f19a5c9dae99020876683b28fdba 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_kit_service_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_kit_service_test.cpp @@ -24,6 +24,7 @@ #include "ability_manager_client.h" #include "ability_info.h" +#include "aging/aging_handler.h" #include "app_provision_info.h" #include "app_provision_info_manager.h" #include "bundle_cache_mgr.h" @@ -9435,7 +9436,9 @@ HWTEST_F(BmsBundleKitServiceTest, ClearCache_0100, Function | SmallTest | Level1 auto hostImpl = std::make_unique(); ASSERT_NE(hostImpl, nullptr); sptr cleanCacheCallback = new (std::nothrow) ICleanCacheCallbackTest(); - ErrCode ret = hostImpl->ClearCache(BUNDLE_NAME_DEMO, cleanCacheCallback, DEFAULT_USERID); + int32_t uid = 0; + std::string callingBundleName; + ErrCode ret = hostImpl->ClearCache(BUNDLE_NAME_DEMO, cleanCacheCallback, DEFAULT_USERID, uid, callingBundleName); EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST); } @@ -14008,7 +14011,8 @@ HWTEST_F(BmsBundleKitServiceTest, CleanBundleCacheTaskGetCleanSize_0100, Functio auto hostImpl = std::make_unique(); ASSERT_NE(hostImpl, nullptr); uint64_t cacheSize = 1; - hostImpl->CleanBundleCacheTaskGetCleanSize(BUNDLE_NAME_TEST, DEFAULT_USERID, cacheSize); + uint64_t uid = 1; + hostImpl->CleanBundleCacheTaskGetCleanSize(BUNDLE_NAME_TEST, DEFAULT_USERID, cacheSize, uid, BUNDLE_NAME_TEST); EXPECT_FALSE(DelayedSingleton::GetInstance()->GetDataMgr()->bundleInfos_.empty()); } @@ -14149,4 +14153,23 @@ HWTEST_F(BmsBundleKitServiceTest, PluginModuleInfoTest_0200, Function | SmallTes EXPECT_EQ(info1.moduleName, ret2->moduleName); EXPECT_EQ(info1.hapPath, ret2->hapPath); } + +#ifdef BUNDLE_FRAMEWORK_FREE_INSTALL +/** + * @tc.number: AginTest_0014 + * @tc.name: test RecentlyUnuseBundleAgingHandler of CleanCache + * @tc.desc: CleanCache is false + */ +HWTEST_F(BmsBundleKitServiceTest, AginTest_0014, Function | SmallTest | Level0) +{ + RecentlyUnuseBundleAgingHandler bundleAgingMgr; + bundleMgrService_ = DelayedSingleton::GetInstance(); + EXPECT_NE(bundleMgrService_, nullptr); + bundleMgrService_->dataMgr_ = nullptr; + AgingBundleInfo agingBundle; + bool ret = bundleAgingMgr.CleanCache(agingBundle); + EXPECT_FALSE(ret); + bundleMgrService_->InitBundleDataMgr(); +} +#endif } diff --git a/services/bundlemgr/test/unittest/bms_bundle_mgr_proxy_test/bms_bundle_mgr_proxy_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_mgr_proxy_test/bms_bundle_mgr_proxy_test.cpp index fec8787aeb58fca3790fb2ffcdc4933d87af527f..890591777ed8c00ed1d70543953c7779990952a1 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_mgr_proxy_test/bms_bundle_mgr_proxy_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_mgr_proxy_test/bms_bundle_mgr_proxy_test.cpp @@ -1026,10 +1026,11 @@ HWTEST_F(BmsBundleMgrProxyTest, CleanBundleDataFiles_0100, Function | MediumTest std::string bundleName = ""; int32_t userId = 100; int32_t appIndex = 1; - auto res = bundleMgrProxy.CleanBundleDataFiles(bundleName, userId, appIndex); + int32_t callerUid = 1001; + auto res = bundleMgrProxy.CleanBundleDataFiles(bundleName, userId, appIndex, callerUid); EXPECT_FALSE(res); bundleName = "com.example.bundleName.test"; - res = bundleMgrProxy.CleanBundleDataFiles(bundleName, userId, appIndex); + res = bundleMgrProxy.CleanBundleDataFiles(bundleName, userId, appIndex, callerUid); EXPECT_FALSE(res); }