From 57b73893ca0c51dab192bcb2747d438488bbfe4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=BB=E6=9D=B0?= Date: Fri, 18 Oct 2024 17:30:02 +0800 Subject: [PATCH] Issue:#IAY5NF Description: app update with clone updateHapToken just token Sig: SIG_ApplicaitonFramework Feature or Bugfix: Bugfix Binary Source: No Signed-off-by: renjie84 renjie84@huawei.com MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 任杰 --- .../bundlemgr/include/inner_bundle_info.h | 4 ++++ .../bundlemgr/src/base_bundle_installer.cpp | 15 +++++++++++++ services/bundlemgr/src/inner_bundle_info.cpp | 22 +++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/services/bundlemgr/include/inner_bundle_info.h b/services/bundlemgr/include/inner_bundle_info.h index e984c8c88..73ff3f497 100644 --- a/services/bundlemgr/include/inner_bundle_info.h +++ b/services/bundlemgr/include/inner_bundle_info.h @@ -1415,6 +1415,10 @@ public: void SetAccessTokenIdEx(const Security::AccessToken::AccessTokenIDEx accessTokenIdEx, const int32_t userId); + void SetAccessTokenIdExWithAppIndex( + const Security::AccessToken::AccessTokenIDEx accessTokenIdEx, + const int32_t userId, const int32_t appIndex); + void SetIsNewVersion(bool flag) { isNewVersion_ = flag; diff --git a/services/bundlemgr/src/base_bundle_installer.cpp b/services/bundlemgr/src/base_bundle_installer.cpp index a7593c432..aad8388c3 100644 --- a/services/bundlemgr/src/base_bundle_installer.cpp +++ b/services/bundlemgr/src/base_bundle_installer.cpp @@ -65,6 +65,7 @@ #include "storage_manager_proxy.h" #endif #include "iservice_registry.h" +#include "inner_bundle_clone_common.h" namespace OHOS { namespace AppExecFwk { @@ -5870,6 +5871,20 @@ ErrCode BaseBundleInstaller::UpdateHapToken(bool needUpdate, InnerBundleInfo &ne if (needUpdate) { newInfo.SetAccessTokenIdEx(accessTokenIdEx, uerInfo.second.bundleUserInfo.userId); } + + const std::map &cloneInfos = uerInfo.second.cloneInfos; + for (const auto &cloneInfoPair : cloneInfos) { + Security::AccessToken::AccessTokenIDEx cloneAccessTokenIdEx; + cloneAccessTokenIdEx.tokenIDEx = cloneInfoPair.second.accessTokenIdEx; + if (BundlePermissionMgr::UpdateHapToken(cloneAccessTokenIdEx, newInfo) != ERR_OK) { + LOG_NOFUNC_E(BMS_TAG_INSTALLER, "UpdateHapToken failed %{public}s", bundleName_.c_str()); + return ERR_APPEXECFWK_INSTALL_GRANT_REQUEST_PERMISSIONS_FAILED; + } + if (needUpdate) { + newInfo.SetAccessTokenIdExWithAppIndex(cloneAccessTokenIdEx, + uerInfo.second.bundleUserInfo.userId, cloneInfoPair.second.appIndex); + } + } } if (needUpdate && !dataMgr_->UpdateInnerBundleInfo(newInfo)) { LOG_NOFUNC_E(BMS_TAG_INSTALLER, "save UpdateInnerBundleInfo failed %{publlic}s", bundleName_.c_str()); diff --git a/services/bundlemgr/src/inner_bundle_info.cpp b/services/bundlemgr/src/inner_bundle_info.cpp index 5273700e6..d0304892d 100644 --- a/services/bundlemgr/src/inner_bundle_info.cpp +++ b/services/bundlemgr/src/inner_bundle_info.cpp @@ -2859,6 +2859,28 @@ void InnerBundleInfo::SetAccessTokenIdEx( infoItem->second.accessTokenIdEx = accessTokenIdEx.tokenIDEx; } +void InnerBundleInfo::SetAccessTokenIdExWithAppIndex( + const Security::AccessToken::AccessTokenIDEx accessTokenIdEx, + const int32_t userId, const int32_t appIndex) +{ + auto& key = NameAndUserIdToKey(GetBundleName(), userId); + auto infoItem = innerBundleUserInfos_.find(key); + if (infoItem == innerBundleUserInfos_.end()) { + return; + } + + auto& userInfo = infoItem->second; + std::map &cloneInfos = userInfo.cloneInfos; + + auto cloneKey = InnerBundleUserInfo::AppIndexToKey(appIndex); + auto cloneItem = cloneInfos.find(cloneKey); + if (cloneItem == cloneInfos.end()) { + return; + } + cloneItem->second.accessTokenId = accessTokenIdEx.tokenIdExStruct.tokenID; + cloneItem->second.accessTokenIdEx = accessTokenIdEx.tokenIDEx; +} + void InnerBundleInfo::SetkeyId(const int32_t userId, const std::string &keyId) { if (keyId.empty()) {