diff --git a/services/ans/include/access_token_helper.h b/services/ans/include/access_token_helper.h index 11de4e9da6620989fa45ea11321fb9da7b3c5081..965ca236a41f5cfd8835f40908d8086eebb8a605 100644 --- a/services/ans/include/access_token_helper.h +++ b/services/ans/include/access_token_helper.h @@ -34,6 +34,7 @@ public: static bool VerifyCallerPermission( const Security::AccessToken::AccessTokenID &tokenCaller, const std::string &permission); static bool VerifyNativeToken(const Security::AccessToken::AccessTokenID &callerToken); + static bool IsSystemHap(); }; } // namespace Notification } // namespace OHOS diff --git a/services/ans/src/access_token_helper.cpp b/services/ans/src/access_token_helper.cpp index b49617be6ad571b0c72cdd76099d51e8121767e2..a54e4ce61562d12e6792c3e16868d730a333d2ea 100644 --- a/services/ans/src/access_token_helper.cpp +++ b/services/ans/src/access_token_helper.cpp @@ -15,6 +15,9 @@ #include "access_token_helper.h" +#include "ans_log_wrapper.h" +#include "ipc_skeleton.h" + namespace OHOS { namespace Notification { bool AccessTokenHelper::VerifyCallerPermission( @@ -30,5 +33,27 @@ bool AccessTokenHelper::VerifyNativeToken(const Security::AccessToken::AccessTok Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(callerToken); return tokenType == Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE; } + +bool AccessTokenHelper::IsSystemHap() +{ + AccessTokenID tokenId = IPCSkeleton::GetCallingTokenID(); + ATokenTypeEnum type = AccessTokenKit::GetTokenTypeFlag(tokenId); + if (type == Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE) { + return true; + } + if (type == Security::AccessToken::ATokenTypeEnum::TOKEN_HAP) { + HapTokenInfo info; + AccessTokenKit::GetHapTokenInfo(tokenId, info); + if (info.apl == ATokenAplEnum::APL_SYSTEM_CORE || info.apl == ATokenAplEnum::APL_SYSTEM_BASIC) { + return true; + } + pid_t pid = IPCSkeleton::GetCallingPid(); + pid_t uid = IPCSkeleton::GetCallingUid(); + ANS_LOGW("apl not match, info.apl=%{public}d, type=%{public}d, pid=%{public}d, uid=%{public}d", + static_cast(info.apl), static_cast(type), pid, uid); + } + return false; +} + } // namespace Notification } // namespace OHOS \ No newline at end of file diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 2ebdcdd1e96921fe01baedb63f34864ba4ad169f..1f67cf01fddb3950ca6521bd8d440921aa338c76 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -122,8 +122,7 @@ inline bool IsSystemApp() if (bundleManager != nullptr) { isSystemApp = bundleManager->IsSystemApp(callingUid); } - - return isSystemApp; + return isSystemApp || AccessTokenHelper::IsSystemHap(); } inline int64_t ResetSeconds(int64_t date)