diff --git a/frameworks/common/include/hisysevent_adapter.h b/frameworks/common/include/hisysevent_adapter.h index 10eb7e64852e1f16d2f75c30376421a2a2b97ea2..8a7fab772ec1a891f2ef689d01b2ddef18449106 100644 --- a/frameworks/common/include/hisysevent_adapter.h +++ b/frameworks/common/include/hisysevent_adapter.h @@ -23,20 +23,16 @@ namespace OHOS { namespace Security { namespace AccessToken { -// base info -struct BaseDfxInfo { +// add, update or delete +struct HapDfxInfo { AccessTokenID tokenId = 0; + AccessTokenIDEx tokenIdEx; + AccessTokenID oriTokenId; int32_t userID = 0; - std::string bundleName; int32_t instIndex; + std::string bundleName; int64_t duration = 0; int32_t ipcCode = -1; -}; - -// add or update or delete -struct HapDfxInfo : public BaseDfxInfo { - AccessTokenID oriTokenId; - AccessTokenIDEx tokenIdEx; std::string permInfo; std::string aclInfo; std::string preauthInfo; diff --git a/frameworks/ets/ani/common/src/ani_error.cpp b/frameworks/ets/ani/common/src/ani_error.cpp index d01e6bbbe13d5189709cb7fe9514250969b1765e..883431319d8b190c6b5ff894ed2e4fcb1da21924 100644 --- a/frameworks/ets/ani/common/src/ani_error.cpp +++ b/frameworks/ets/ani/common/src/ani_error.cpp @@ -69,39 +69,39 @@ ani_object BusinessErrorAni::CreateError(ani_env* env, ani_int code, const std:: ani_status status = env->FindClass(BUSINESS_ERROR_CLASS, &cls); if (status != ANI_OK) { - LOGE(ATM_DOMAIN, ATM_TAG, "Failed to FindClass: %{public}d.", status); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to FindClass: %{public}d.", static_cast(status)); return nullptr; } status = env->Class_FindMethod(cls, "", ":V", &method); if (status != ANI_OK) { - LOGE(ATM_DOMAIN, ATM_TAG, "Failed to Class_FindMethod: %{public}d.", status); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to Class_FindMethod: %{public}d.", static_cast(status)); return nullptr; } status = env->Object_New(cls, method, &obj); if (status != ANI_OK) { - LOGE(ATM_DOMAIN, ATM_TAG, "Failed to Object_New: %{public}d.", status); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to Object_New: %{public}d.", static_cast(status)); return nullptr; } status = env->Class_FindField(cls, "code", &field); if (status != ANI_OK) { - LOGE(ATM_DOMAIN, ATM_TAG, "Failed to Class_FindField: %{public}d.", status); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to Class_FindField: %{public}d.", static_cast(status)); return nullptr; } status = env->Object_SetField_Double(obj, field, code); if (status != ANI_OK) { - LOGE(ATM_DOMAIN, ATM_TAG, "Failed to Object_SetField_Double: %{public}d.", status); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to Object_SetField_Double: %{public}d.", static_cast(status)); return nullptr; } status = env->Class_FindField(cls, "data", &field); if (status != ANI_OK) { - LOGE(ATM_DOMAIN, ATM_TAG, "Failed to Class_FindField: %{public}d.", status); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to Class_FindField: %{public}d.", static_cast(status)); return nullptr; } ani_string string = nullptr; env->String_NewUTF8(msg.c_str(), msg.size(), &string); status = env->Object_SetField_Ref(obj, field, static_cast(string)); if (status != ANI_OK) { - LOGE(ATM_DOMAIN, ATM_TAG, "Failed to Object_SetField_Ref: %{public}d.", status); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to Object_SetField_Ref: %{public}d.", static_cast(status)); return nullptr; } return obj; diff --git a/frameworks/ets/ani/common/src/ani_utils.cpp b/frameworks/ets/ani/common/src/ani_utils.cpp index d2664afda26cea052db2d89a8b683ab6559c3ffc..a9705225e15afb553414fac4249c8afaf3ec8e6f 100644 --- a/frameworks/ets/ani/common/src/ani_utils.cpp +++ b/frameworks/ets/ani/common/src/ani_utils.cpp @@ -88,7 +88,7 @@ bool AniParseUint32(ani_env* env, const ani_ref& aniInt, uint32_t& out) ani_status status; if ((status = env->Object_CallMethodByName_Int( static_cast(aniInt), "unboxed", nullptr, &tmp)) != ANI_OK) { - LOGE(ATM_DOMAIN, ATM_TAG, "Object_CallMethodByName_Int failed! %{public}d", status); + LOGE(ATM_DOMAIN, ATM_TAG, "Object_CallMethodByName_Int failed! %{public}d", static_cast(status)); return false; } @@ -460,13 +460,14 @@ ani_object CreateArrayObject(ani_env* env, uint32_t length) ani_method aniMethod; ani_status status = env->Class_FindMethod(aniClass, "", "I:V", &aniMethod); if (status != ANI_OK) { - LOGE(ATM_DOMAIN, ATM_TAG, "Failed to FindMethod, status: %{public}d!", status); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to FindMethod, status: %{public}d!", static_cast(status)); return nullptr; } ani_object out; status = env->Object_New(aniClass, aniMethod, &out, length); if (status != ANI_OK) { - LOGE(ATM_DOMAIN, ATM_TAG, "Failed to Object_New(size: %{public}d), status %{public}d!", length, status); + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to Object_New(size: %{public}d), status %{public}d!", + length, static_cast(status)); return nullptr; } return out; @@ -483,7 +484,7 @@ bool GetBoolProperty(ani_env* env, const ani_object& object, const std::string& ani_status status = env->Object_GetPropertyByName_Ref(object, property.c_str(), &ref); if (status != ANI_OK) { LOGE(ATM_DOMAIN, ATM_TAG, "Failed to get property(%{public}s), status: %{public}d!", - property.c_str(), status); + property.c_str(), static_cast(status)); return false; } if (AniIsRefUndefined(env, ref)) { @@ -540,7 +541,7 @@ bool GetLongProperty(ani_env* env, const ani_object& object, const std::string& ani_status status = env->Object_GetPropertyByName_Ref(object, property.c_str(), &ref); if (status != ANI_OK) { LOGE(ATM_DOMAIN, ATM_TAG, "Failed to get property(%{public}s), status: %{public}d!", - property.c_str(), status); + property.c_str(), static_cast(status)); return false; } if (AniIsRefUndefined(env, ref)) { @@ -567,7 +568,7 @@ bool GetStringProperty(ani_env* env, const ani_object& object, const std::string ani_status status = env->Object_GetPropertyByName_Ref(object, property.c_str(), &ref); if (status != ANI_OK) { LOGE(ATM_DOMAIN, ATM_TAG, "Failed to get property(%{public}s), status: %{public}d!", - property.c_str(), status); + property.c_str(), static_cast(status)); return false; } if (AniIsRefUndefined(env, ref)) { @@ -588,7 +589,7 @@ bool GetEnumProperty(ani_env* env, const ani_object& object, const std::string& ani_status status = env->Object_GetPropertyByName_Ref(object, property.c_str(), &ref); if (status != ANI_OK) { LOGE(ATM_DOMAIN, ATM_TAG, "Failed to get property(%{public}s), status: %{public}d!", - property.c_str(), status); + property.c_str(), static_cast(status)); return false; } if (AniIsRefUndefined(env, ref)) { @@ -616,7 +617,7 @@ bool GetStringVecProperty( ani_status status = env->Object_GetPropertyByName_Ref(object, property.c_str(), &ref); if (status != ANI_OK) { LOGE(ATM_DOMAIN, ATM_TAG, "Failed to get property(%{public}s), status: %{public}d!", - property.c_str(), status); + property.c_str(), static_cast(status)); return false; } if (AniIsRefUndefined(env, ref)) { @@ -636,7 +637,7 @@ bool SetBoolProperty(ani_env* env, ani_object& object, const std::string& proper ani_status status = env->Object_SetPropertyByName_Boolean(object, property.c_str(), static_cast(in)); if (status != ANI_OK) { LOGE(ATM_DOMAIN, ATM_TAG, "Set property(%{public}s) failed, status: %{public}d!", - property.c_str(), status); + property.c_str(), static_cast(status)); return false; } return true; @@ -651,7 +652,7 @@ bool SetIntProperty(ani_env* env, ani_object& object, const std::string& propert ani_status status = env->Object_SetPropertyByName_Int(object, property.c_str(), static_cast(in)); if (status != ANI_OK) { LOGE(ATM_DOMAIN, ATM_TAG, "Set property(%{public}s) failed, status: %{public}d!", - property.c_str(), status); + property.c_str(), static_cast(status)); return false; } return true; @@ -666,7 +667,7 @@ bool SetLongProperty(ani_env* env, ani_object& aniObject, const std::string& pro ani_status status = env->Object_SetPropertyByName_Long(aniObject, property.c_str(), static_cast(in)); if (status != ANI_OK) { LOGE(ATM_DOMAIN, ATM_TAG, "Set property(%{public}s) failed, status: %{public}d!", - property.c_str(), status); + property.c_str(), static_cast(status)); return false; } return true; @@ -681,7 +682,7 @@ bool SetRefProperty(ani_env* env, ani_object& aniObject, const std::string& prop ani_status status = env->Object_SetPropertyByName_Ref(aniObject, property.c_str(), in); if (status != ANI_OK) { LOGE(ATM_DOMAIN, ATM_TAG, "Set property(%{public}s) failed, status: %{public}d!", - property.c_str(), status); + property.c_str(), static_cast(status)); return false; } return true; diff --git a/frameworks/ets/ani/privacy/src/privacy_manager.cpp b/frameworks/ets/ani/privacy/src/privacy_manager.cpp index 29424fa9a2fed37a85feed9ef2e43b54223605a5..40d03974c4749d36be2f1fd4b2a25bf73eb60e50 100644 --- a/frameworks/ets/ani/privacy/src/privacy_manager.cpp +++ b/frameworks/ets/ani/privacy/src/privacy_manager.cpp @@ -565,7 +565,7 @@ static ani_object ConvertUsedRecordDetails(ani_env* env, const std::vectorObject_CallMethodByName_Void( arrayObj, "$_set", "ILstd/core/Object;:V", index, aniRecord); if (status != ANI_OK) { - LOGE(PRI_DOMAIN, PRI_TAG, "status : %{public}d.", status); + LOGE(PRI_DOMAIN, PRI_TAG, "status : %{public}d.", static_cast(status)); break; } ++index; @@ -909,7 +909,8 @@ void InitPrivacyFunction(ani_env *env) }; ani_status status = env->Namespace_BindNativeFunctions(ns, nsMethods.data(), nsMethods.size()); if (status != ANI_OK) { - LOGE(PRI_DOMAIN, PRI_TAG, "Failed to Namespace_BindNativeFunctions status : %{public}d.", status); + LOGE(PRI_DOMAIN, PRI_TAG, "Failed to Namespace_BindNativeFunctions status : %{public}d.", + static_cast(status)); } if (env->ResetError() != ANI_OK) { LOGE(PRI_DOMAIN, PRI_TAG, "Failed to ResetError."); diff --git a/interfaces/innerkits/accesstoken/include/hap_token_info.h b/interfaces/innerkits/accesstoken/include/hap_token_info.h index 67a4e27f0f3518ddbf4b194425697f149718887c..6dc09bb15d261efcd09cac641486708bb907aff8 100644 --- a/interfaces/innerkits/accesstoken/include/hap_token_info.h +++ b/interfaces/innerkits/accesstoken/include/hap_token_info.h @@ -213,19 +213,6 @@ public: std::map aclExtendedMap; }; -/** - * @brief Declares hap Init info class - */ -class HapInitInfo final { -public: - HapInfoParams installInfo; - UpdateHapInfoParams updateInfo; - HapPolicy policy; - std::string bundleName = ""; - AccessTokenID tokenID = 0; - bool isUpdate = false; -}; - /** * @brief Declares permission with value */ diff --git a/services/accesstokenmanager/main/cpp/include/permission/hap_token_info_inner.h b/services/accesstokenmanager/main/cpp/include/permission/hap_token_info_inner.h index b02e9925c806c6fa6c40db3c5df3aba4ba20dc43..8f69edb9abc648652873191ef1ecf2debad54e92 100644 --- a/services/accesstokenmanager/main/cpp/include/permission/hap_token_info_inner.h +++ b/services/accesstokenmanager/main/cpp/include/permission/hap_token_info_inner.h @@ -31,6 +31,19 @@ namespace OHOS { namespace Security { namespace AccessToken { +/** + * @brief Declares hap Init info class + */ +class HapInitInfo final { +public: + HapInfoParams installInfo; + UpdateHapInfoParams updateInfo; + HapPolicy policy; + std::string bundleName = ""; + AccessTokenID tokenID = 0; + bool isUpdate = false; +}; + class HapTokenInfoInner final { public: HapTokenInfoInner(); diff --git a/services/accesstokenmanager/main/cpp/include/permission/permission_manager.h b/services/accesstokenmanager/main/cpp/include/permission/permission_manager.h index 8c390755dfc0b885ecbbfc690fc6b4016fed27c4..6f778ec11b2ee7cff38df4ff32cadfa808f00e23 100644 --- a/services/accesstokenmanager/main/cpp/include/permission/permission_manager.h +++ b/services/accesstokenmanager/main/cpp/include/permission/permission_manager.h @@ -105,7 +105,7 @@ public: void SetPermToKernel(AccessTokenID tokenID, const std::string& permissionName, bool isGranted); bool InitPermissionList(const HapInitInfo& initInfo, std::vector& initializedList, HapInfoCheckResult& result, std::vector& undefValues); - bool InitDlpPermissionList(const std::string& bundleName, int32_t userId, + bool InitDlpPermissionList(const HapInfoParams& initInfo, std::vector& initializedList, std::vector& undefValues); void NotifyUpdatedPermList(const std::vector& grantedPermListBefore, const std::vector& grantedPermListAfter, AccessTokenID tokenID); diff --git a/services/accesstokenmanager/main/cpp/src/permission/permission_manager.cpp b/services/accesstokenmanager/main/cpp/src/permission/permission_manager.cpp index d8c3deda976f6f61b5c70f8815eb7a8875c2e17a..23393b1b783fd6956d21e9b9c98870603a129114 100644 --- a/services/accesstokenmanager/main/cpp/src/permission/permission_manager.cpp +++ b/services/accesstokenmanager/main/cpp/src/permission/permission_manager.cpp @@ -1153,11 +1153,11 @@ void PermissionManager::GetMasterAppUndValues(AccessTokenID tokenId, std::vector } } -bool PermissionManager::InitDlpPermissionList(const std::string& bundleName, int32_t userId, +bool PermissionManager::InitDlpPermissionList(const HapInfoParams& info, std::vector& initializedList, std::vector& undefValues) { - // get dlp original app - AccessTokenIDEx tokenId = AccessTokenInfoManager::GetInstance().GetHapTokenID(userId, bundleName, 0); + // get dlp original app, index is 0 + AccessTokenIDEx tokenId = AccessTokenInfoManager::GetInstance().GetHapTokenID(info.userID, info.bundleName, 0); std::shared_ptr infoPtr = AccessTokenInfoManager::GetInstance().GetHapTokenInfoInner(tokenId.tokenIdExStruct.tokenID); if (infoPtr == nullptr) { diff --git a/services/accesstokenmanager/main/cpp/src/permission/short_grant_manager.cpp b/services/accesstokenmanager/main/cpp/src/permission/short_grant_manager.cpp index a3b23b5efc2729a509b275da261f148d7a460e5b..8622d431db9a69f361ce521a78bd8778b9d9e5fc 100644 --- a/services/accesstokenmanager/main/cpp/src/permission/short_grant_manager.cpp +++ b/services/accesstokenmanager/main/cpp/src/permission/short_grant_manager.cpp @@ -142,7 +142,6 @@ int ShortGrantManager::RefreshPermission(AccessTokenID tokenID, const std::strin shortGrantData_.begin(), shortGrantData_.end(), [tokenID, permission](const PermTimerData& data) { return data.tokenID == tokenID && data.permissionName == permission; }); - if (iter == shortGrantData_.end()) { auto iterator = std::find(g_shortGrantPermission.begin(), g_shortGrantPermission.end(), permission); if (iterator == g_shortGrantPermission.end()) { @@ -251,7 +250,7 @@ void ShortGrantManager::ScheduleRevokeTask(AccessTokenID tokenID, const std::str LOGI(ATM_DOMAIN, ATM_TAG, "Token: %{public}d, permission: %{public}s, delay revoke permission end.", tokenID, permission.c_str()); }); - LOGI(ATM_DOMAIN, ATM_TAG, "cancelTimes %{public}d", cancelTimes); + LOGI(ATM_DOMAIN, ATM_TAG, "CancelTimes %{public}d", cancelTimes); eventHandler->ProxyPostTask(delayed, taskName, cancelTimes * 1000); // 1000 means to ms return; #else diff --git a/services/accesstokenmanager/main/cpp/src/permission/token_modify_notifier.cpp b/services/accesstokenmanager/main/cpp/src/permission/token_modify_notifier.cpp index e4b74f2e79fb8267c7af4bbd891990b0d205a0b8..ac7206df273047dc46665ce909304aba2031ebda 100644 --- a/services/accesstokenmanager/main/cpp/src/permission/token_modify_notifier.cpp +++ b/services/accesstokenmanager/main/cpp/src/permission/token_modify_notifier.cpp @@ -175,11 +175,8 @@ int32_t TokenModifyNotifier::GetRemoteHapTokenInfo(const std::string& deviceID, int32_t TokenModifyNotifier::RegisterTokenSyncCallback(const sptr& callback) { Utils::UniqueWriteGuard infoGuard(this->notifyLock_); - tokenSyncCallbackObject_ = new (std::nothrow) TokenSyncCallbackProxy(callback); + tokenSyncCallbackObject_ = new TokenSyncCallbackProxy(callback); tokenSyncCallbackDeathRecipient_ = sptr::MakeSptr(); - if (tokenSyncCallbackDeathRecipient_ == nullptr) { - return RET_FAILED; - } callback->AddDeathRecipient(tokenSyncCallbackDeathRecipient_); LOGI(ATM_DOMAIN, ATM_TAG, "Register token sync callback successful."); return ERR_OK; diff --git a/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_service.cpp b/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_service.cpp index 70aa7169e4dac66ed8cfd1a09f4ad19837d9db32..5c9ba0ce54955dc2288ec1f745534d105259b564 100644 --- a/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_service.cpp +++ b/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_service.cpp @@ -662,22 +662,24 @@ int32_t AccessTokenManagerService::AllocHapToken(const HapInfoParcel& info, cons return ERR_OK; } -static void TransferHapPolicy(const HapPolicy& policyIn, HapPolicy& policyOut) -{ - policyOut.apl = policyIn.apl; - policyOut.domain = policyIn.domain; - policyOut.permList.assign(policyIn.permList.begin(), policyIn.permList.end()); - policyOut.aclRequestedList.assign(policyIn.aclRequestedList.begin(), policyIn.aclRequestedList.end()); - policyOut.preAuthorizationInfo.assign(policyIn.preAuthorizationInfo.begin(), policyIn.preAuthorizationInfo.end()); - for (const auto& perm : policyIn.permStateList) { +static void TransferHapPolicy(const HapPolicyParcel& policyIn, HapPolicy& policyOut) +{ + policyOut.apl = policyIn.hapPolicy.apl; + policyOut.domain = policyIn.hapPolicy.domain; + policyOut.permList.assign(policyIn.hapPolicy.permList.begin(), policyIn.hapPolicy.permList.end()); + policyOut.aclRequestedList.assign( + policyIn.hapPolicy.aclRequestedList.begin(), policyIn.hapPolicy.aclRequestedList.end()); + policyOut.preAuthorizationInfo.assign( + policyIn.hapPolicy.preAuthorizationInfo.begin(), policyIn.hapPolicy.preAuthorizationInfo.end()); + for (const auto& perm : policyIn.hapPolicy.permStateList) { PermissionStatus tmp; tmp.permissionName = perm.permissionName; tmp.grantStatus = perm.grantStatus; tmp.grantFlag = perm.grantFlag; policyOut.permStateList.emplace_back(tmp); } - policyOut.checkIgnore = policyIn.checkIgnore; - policyOut.aclExtendedMap = policyIn.aclExtendedMap; + policyOut.checkIgnore = policyIn.hapPolicy.checkIgnore; + policyOut.aclExtendedMap = policyIn.hapPolicy.aclExtendedMap; } static void DumpEventInfo(const HapPolicy& policy, HapDfxInfo& dfxInfo) @@ -738,7 +740,7 @@ void AccessTokenManagerService::ReportUpdateHap(AccessTokenIDEx fullTokenId, con dfxInfo.userID = info.userID; dfxInfo.bundleName = info.bundleName; dfxInfo.instIndex = info.instIndex; - dfxInfo.duration = TimeUtil::GetCurrentTimestamp() - dfxInfo.duration; + dfxInfo.duration = TimeUtil::GetCurrentTimestamp() - beginTime; DumpEventInfo(policy, dfxInfo); ReportSysEventUpdateHap(errorCode, dfxInfo); @@ -747,7 +749,8 @@ void AccessTokenManagerService::ReportUpdateHap(AccessTokenIDEx fullTokenId, con int32_t AccessTokenManagerService::InitHapToken(const HapInfoParcel& info, const HapPolicyParcel& policy, uint64_t& fullTokenId, HapInfoCheckResultIdl& resultInfoIdl) { - LOGI(ATM_DOMAIN, ATM_TAG, "Init hap %{public}s.", info.hapInfoParameter.bundleName.c_str()); + HapInfoParams hapInfoParm = info.hapInfoParameter; + LOGI(ATM_DOMAIN, ATM_TAG, "Init hap %{public}s.", hapInfoParm.bundleName.c_str()); AccessTokenID tokenID = IPCSkeleton::GetCallingTokenID(); if (!IsPrivilegedCalling() && (VerifyAccessToken(tokenID, MANAGE_HAP_TOKENID_PERMISSION) == PERMISSION_DENIED)) { @@ -755,32 +758,30 @@ int32_t AccessTokenManagerService::InitHapToken(const HapInfoParcel& info, const return AccessTokenError::ERR_PERMISSION_DENIED; } - int64_t beiginTime = TimeUtil::GetCurrentTimestamp(); + int64_t beginTime = TimeUtil::GetCurrentTimestamp(); HapPolicy policyCopy; - TransferHapPolicy(policy.hapPolicy, policyCopy); + TransferHapPolicy(policy, policyCopy); resultInfoIdl.realResult = ERR_OK; std::vector initializedList; std::vector undefValues; - if (info.hapInfoParameter.dlpType == DLP_COMMON) { + if (hapInfoParm.dlpType == DLP_COMMON) { HapInfoCheckResult permCheckResult; HapInitInfo initInfo; - initInfo.installInfo = info.hapInfoParameter; + initInfo.installInfo = hapInfoParm; initInfo.policy = policyCopy; - initInfo.bundleName = info.hapInfoParameter.bundleName; + initInfo.bundleName = hapInfoParm.bundleName; if (!PermissionManager::GetInstance().InitPermissionList(initInfo, initializedList, permCheckResult, undefValues)) { resultInfoIdl.realResult = ERROR; resultInfoIdl.permissionName = permCheckResult.permCheckResult.permissionName; - int32_t rule = permCheckResult.permCheckResult.rule; - resultInfoIdl.rule = static_cast(rule); - ReportAddHap({0}, info.hapInfoParameter, policyCopy, beiginTime, ERR_PERM_REQUEST_CFG_FAILED); + resultInfoIdl.rule = static_cast(permCheckResult.permCheckResult.rule); + ReportAddHap({0}, hapInfoParm, policyCopy, beginTime, ERR_PERM_REQUEST_CFG_FAILED); return ERR_OK; } } else { - if (!PermissionManager::GetInstance().InitDlpPermissionList( - info.hapInfoParameter.bundleName, info.hapInfoParameter.userID, initializedList, undefValues)) { - ReportAddHap({0}, info.hapInfoParameter, policyCopy, beiginTime, ERR_PERM_REQUEST_CFG_FAILED); + if (!PermissionManager::GetInstance().InitDlpPermissionList(hapInfoParm, initializedList, undefValues)) { + ReportAddHap({0}, hapInfoParm, policyCopy, beginTime, ERR_PERM_REQUEST_CFG_FAILED); return ERR_PERM_REQUEST_CFG_FAILED; } } @@ -788,9 +789,9 @@ int32_t AccessTokenManagerService::InitHapToken(const HapInfoParcel& info, const AccessTokenIDEx tokenIdEx; int32_t ret = AccessTokenInfoManager::GetInstance().CreateHapTokenInfo( - info.hapInfoParameter, policyCopy, tokenIdEx, undefValues); + hapInfoParm, policyCopy, tokenIdEx, undefValues); fullTokenId = tokenIdEx.tokenIDEx; - ReportAddHap(tokenIdEx, info.hapInfoParameter, policyCopy, beiginTime, ret); + ReportAddHap(tokenIdEx, hapInfoParm, policyCopy, beginTime, ret); return ret; } @@ -808,7 +809,7 @@ int AccessTokenManagerService::DeleteToken(AccessTokenID tokenID) return AccessTokenError::ERR_PARAM_INVALID; } - HapDfxInfo dfxInfo; + HapDfxInfo dfxInfo = {}; dfxInfo.tokenId = tokenID; dfxInfo.ipcCode = static_cast(IAccessTokenManagerIpcCode::COMMAND_DELETE_TOKEN); int64_t beginTime = TimeUtil::GetCurrentTimestamp(); @@ -890,7 +891,7 @@ int32_t AccessTokenManagerService::UpdateHapToken(uint64_t& fullTokenId, const U return AccessTokenError::ERR_PERMISSION_DENIED; } int64_t beginTime = TimeUtil::GetCurrentTimestamp(); - HapTokenInfo hapInfo; + HapTokenInfo hapInfo = { 0 }; int32_t error = AccessTokenInfoManager::GetInstance().GetHapTokenInfo(tokenIdEx.tokenIdExStruct.tokenID, hapInfo); if (error != ERR_OK) { LOGC(ATM_DOMAIN, ATM_TAG, "GetHapTokenInfo failed, err=%{public}d.", error); diff --git a/services/tokensyncmanager/test/unittest/token_sync_service_test.cpp b/services/tokensyncmanager/test/unittest/token_sync_service_test.cpp index 081c8fef88adf43c9ae0efc5df2e19daa038f410..6aa00d9fc3c1ced42e228c875d523cf303102855 100644 --- a/services/tokensyncmanager/test/unittest/token_sync_service_test.cpp +++ b/services/tokensyncmanager/test/unittest/token_sync_service_test.cpp @@ -1026,12 +1026,15 @@ HWTEST_F(TokenSyncServiceTest, RemoveRemoteDeviceInfo001, TestSize.Level0) */ HWTEST_F(TokenSyncServiceTest, ConvertToUniversallyUniqueIdOrFetch001, TestSize.Level0) { - std::string nodeId; - ASSERT_EQ("", DeviceInfoManager::GetInstance().ConvertToUniversallyUniqueIdOrFetch(nodeId)); // nodeId invalid + std::string nodeId; + ASSERT_EQ("", DeviceInfoManager::GetInstance().ConvertToUniversallyUniqueId(nodeId)); + ASSERT_EQ("", SoftBusManager::GetInstance().ConvertToUniversallyUniqueIdOrFetch(nodeId)); // nodeId invalid nodeId = "123"; // FindDeviceInfo false - ASSERT_EQ("", DeviceInfoManager::GetInstance().ConvertToUniversallyUniqueIdOrFetch(nodeId)); + ASSERT_EQ("", DeviceInfoManager::GetInstance().ConvertToUniversallyUniqueId(nodeId)); + // GetUuidByNetworkId success + ASSERT_EQ("123:uuid-001", SoftBusManager::GetInstance().ConvertToUniversallyUniqueIdOrFetch(nodeId)); std::string networkId = "123"; std::string universallyUniqueId = "123"; @@ -1064,10 +1067,15 @@ HWTEST_F(TokenSyncServiceTest, ConvertToUniversallyUniqueIdOrFetch001, TestSize. HWTEST_F(TokenSyncServiceTest, ConvertToUniqueDeviceIdOrFetch001, TestSize.Level0) { std::string nodeId; + bool isFound; + ASSERT_EQ("", DeviceInfoManager::GetInstance().ConvertToUniqueDeviceId(nodeId, isFound)); + ASSERT_EQ(false, isFound); ASSERT_EQ("", DeviceInfoManager::GetInstance().ConvertToUniqueDeviceIdOrFetch(nodeId)); // nodeId invalid nodeId = "123"; // FindDeviceInfo false + ASSERT_EQ("", DeviceInfoManager::GetInstance().ConvertToUniqueDeviceId(nodeId, isFound)); + ASSERT_EQ(false, isFound); ASSERT_EQ("", DeviceInfoManager::GetInstance().ConvertToUniqueDeviceIdOrFetch(nodeId)); std::string networkId = "123"; @@ -1080,6 +1088,8 @@ HWTEST_F(TokenSyncServiceTest, ConvertToUniqueDeviceIdOrFetch001, TestSize.Level nodeId = "123"; // FindDeviceInfo true + universallyUniqueId is not empty + ASSERT_EQ("", DeviceInfoManager::GetInstance().ConvertToUniqueDeviceId(nodeId, isFound)); + ASSERT_EQ(true, isFound); DeviceInfoManager::GetInstance().ConvertToUniqueDeviceIdOrFetch(nodeId); nodeId = uniqueDeviceId;