diff --git a/adapter/ohos/entrance/ui_session/ui_content_proxy.cpp b/adapter/ohos/entrance/ui_session/ui_content_proxy.cpp index 5be726b2882ce9dbcea07cc594b8e295e1120fa6..5797d12c90b1abf6c5057ec0c850c6716fc583bf 100644 --- a/adapter/ohos/entrance/ui_session/ui_content_proxy.cpp +++ b/adapter/ohos/entrance/ui_session/ui_content_proxy.cpp @@ -15,17 +15,34 @@ #include "interfaces/inner_api/ui_session/ui_content_proxy.h" +#include + #include "ipc_skeleton.h" #include "adapter/ohos/entrance/ui_session/include/ui_service_hilog.h" namespace OHOS::Ace { +bool UIContentServiceProxy::IsSACalling() +{ + const auto tokenId = IPCSkeleton::GetCallingTokenID(); + const auto flag = Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenId); + if (flag == Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE) { + LOGD("SA called, tokenId:%{private}u, flag:%{public}u", tokenId, flag); + return true; + } + LOGW("Not SA called, tokenId:%{private}u, flag:%{public}u", tokenId, flag); + return false; +} + int32_t UIContentServiceProxy::GetInspectorTree(const std::function& eventCallback) { MessageParcel data; MessageParcel reply; MessageOption option; + if (IsSACalling()) { + return FAILED; + } if (!data.WriteInterfaceToken(GetDescriptor())) { LOGW("GetInspectorTree write interface token failed"); return FAILED; @@ -48,6 +65,9 @@ int32_t UIContentServiceProxy::GetVisibleInspectorTree( MessageParcel data; MessageParcel reply; MessageOption option; + if (IsSACalling()) { + return FAILED; + } if (!data.WriteInterfaceToken(GetDescriptor())) { LOGW("GetVisibleInspectorTree write interface token failed"); return FAILED; @@ -69,6 +89,9 @@ int32_t UIContentServiceProxy::Connect(const EventCallback& eventCallback) MessageParcel data; MessageParcel reply; MessageOption option; + if (IsSACalling()) { + return FAILED; + } if (!data.WriteInterfaceToken(GetDescriptor())) { LOGW("connect write interface token failed"); return FAILED; @@ -101,6 +124,9 @@ int32_t UIContentServiceProxy::RegisterClickEventCallback(const EventCallback& e MessageParcel data; MessageParcel reply; MessageOption option; + if (IsSACalling()) { + return FAILED; + } if (!data.WriteInterfaceToken(GetDescriptor())) { LOGW("RegisterClickEventCallback write interface token failed"); return FAILED; @@ -122,6 +148,9 @@ int32_t UIContentServiceProxy::RegisterSearchEventCallback(const EventCallback& MessageParcel data; MessageParcel reply; MessageOption option; + if (IsSACalling()) { + return FAILED; + } if (!data.WriteInterfaceToken(GetDescriptor())) { LOGW("RegisterSearchEventCallback write interface token failed"); return FAILED; @@ -143,6 +172,9 @@ int32_t UIContentServiceProxy::RegisterRouterChangeEventCallback(const EventCall MessageParcel data; MessageParcel reply; MessageOption option; + if (IsSACalling()) { + return FAILED; + } if (!data.WriteInterfaceToken(GetDescriptor())) { LOGW("RegisterRouterChangeEventCallback write interface token failed"); return FAILED; @@ -164,6 +196,9 @@ int32_t UIContentServiceProxy::RegisterComponentChangeEventCallback(const EventC MessageParcel data; MessageParcel reply; MessageOption option; + if (IsSACalling()) { + return FAILED; + } if (!data.WriteInterfaceToken(GetDescriptor())) { LOGW("RegisterComponentChangeEventCallback write interface token failed"); return FAILED; @@ -186,6 +221,9 @@ int32_t UIContentServiceProxy::RegisterWebUnfocusEventCallback( MessageParcel data; MessageParcel reply; MessageOption option; + if (IsSACalling()) { + return FAILED; + } if (!data.WriteInterfaceToken(GetDescriptor())) { LOGW("RegisterWebUnfocusEventCallback write interface token failed"); return FAILED; @@ -207,6 +245,9 @@ int32_t UIContentServiceProxy::SendCommand(int32_t id, const std::string& comman MessageParcel data; MessageParcel reply; MessageOption option; + if (IsSACalling()) { + return FAILED; + } if (!data.WriteInterfaceToken(GetDescriptor())) { LOGW("SendCommand write interface token failed"); return FAILED; @@ -227,6 +268,9 @@ int32_t UIContentServiceProxy::SendCommandAsync(int32_t id, const std::string& c MessageParcel data; MessageParcel reply; MessageOption option(MessageOption::TF_ASYNC); + if (IsSACalling()) { + return FAILED; + } if (!data.WriteInterfaceToken(GetDescriptor())) { LOGW("SendCommand Async write interface token failed"); return FAILED; @@ -243,6 +287,9 @@ int32_t UIContentServiceProxy::SendCommand(const std::string command) MessageParcel data; MessageParcel reply; MessageOption option(MessageOption::TF_ASYNC); + if (IsSACalling()) { + return FAILED; + } if (!data.WriteInterfaceToken(GetDescriptor())) { LOGW("SendCommand write interface token failed"); return FAILED; @@ -270,6 +317,9 @@ int32_t UIContentServiceProxy::UnregisterClickEventCallback() MessageParcel data; MessageParcel reply; MessageOption option; + if (IsSACalling()) { + return FAILED; + } if (!data.WriteInterfaceToken(GetDescriptor())) { LOGW("UnregisterClickEventCallback write interface token failed"); return FAILED; @@ -291,6 +341,9 @@ int32_t UIContentServiceProxy::UnregisterSearchEventCallback() MessageParcel data; MessageParcel reply; MessageOption option; + if (IsSACalling()) { + return FAILED; + } if (!data.WriteInterfaceToken(GetDescriptor())) { LOGW("UnregisterSearchEventCallback write interface token failed"); return FAILED; @@ -312,6 +365,9 @@ int32_t UIContentServiceProxy::UnregisterRouterChangeEventCallback() MessageParcel data; MessageParcel reply; MessageOption option; + if (IsSACalling()) { + return FAILED; + } if (!data.WriteInterfaceToken(GetDescriptor())) { LOGW("UnregisterRouterChangeEventCallback write interface token failed"); return FAILED; @@ -333,6 +389,9 @@ int32_t UIContentServiceProxy::UnregisterComponentChangeEventCallback() MessageParcel data; MessageParcel reply; MessageOption option; + if (IsSACalling()) { + return FAILED; + } if (!data.WriteInterfaceToken(GetDescriptor())) { LOGW("UnregisterComponentChangeEventCallback write interface token failed"); return FAILED; @@ -354,6 +413,9 @@ int32_t UIContentServiceProxy::UnregisterWebUnfocusEventCallback() MessageParcel data; MessageParcel reply; MessageOption option; + if (IsSACalling()) { + return FAILED; + } if (!data.WriteInterfaceToken(GetDescriptor())) { LOGW("UnregisterComponentChangeEventCallback write interface token failed"); return FAILED; @@ -381,6 +443,9 @@ int32_t UIContentServiceProxy::GetWebViewTranslateText( MessageParcel value; MessageParcel reply; MessageOption option(MessageOption::TF_ASYNC); + if (IsSACalling()) { + return FAILED; + } if (!value.WriteInterfaceToken(GetDescriptor())) { LOGW("GetWebViewTranslateText write interface token failed"); return FAILED; @@ -412,6 +477,9 @@ int32_t UIContentServiceProxy::ResetTranslateTextAll() MessageParcel data; MessageParcel reply; MessageOption option(MessageOption::TF_ASYNC); + if (IsSACalling()) { + return FAILED; + } if (!data.WriteInterfaceToken(GetDescriptor())) { LOGW("ResetTranslateTextAll write interface token failed"); return FAILED; @@ -432,6 +500,9 @@ int32_t UIContentServiceProxy::ResetTranslateText(int32_t nodeId) MessageParcel data; MessageParcel reply; MessageOption option(MessageOption::TF_ASYNC); + if (IsSACalling()) { + return FAILED; + } if (!data.WriteInterfaceToken(GetDescriptor())) { LOGW("ResetTranslateText write interface token failed"); return FAILED; @@ -452,6 +523,9 @@ int32_t UIContentServiceProxy::GetWebViewCurrentLanguage(const EventCallback& ev MessageParcel data; MessageParcel reply; MessageOption option(MessageOption::TF_ASYNC); + if (IsSACalling()) { + return FAILED; + } if (!data.WriteInterfaceToken(GetDescriptor())) { LOGW("GetWebViewCurrentLanguage write interface token failed"); return FAILED; @@ -477,6 +551,9 @@ int32_t UIContentServiceProxy::GetCurrentPageName(const std::function& finishCallback) override; - + bool IsSACalling(); private: static inline BrokerDelegator delegator_; sptr report_ = nullptr;