已开启
融合助手问题处理 #2709
融合助手问题处理 #2709
已开启
taojuncun创建于 8月8日
2 个文件变更+36-3
@@ -100,6 +100,7 @@ private:
100 sptr<AccessibilityWindowConnection> connection, AccessibilityElementInfo &elementInfo, uint64_t displayId);100 sptr<AccessibilityWindowConnection> connection, AccessibilityElementInfo &elementInfo, uint64_t displayId);
101 bool GetWindowBounds(int32_t windowId, int32_t &leftTopX, int32_t &leftTopY,101 bool GetWindowBounds(int32_t windowId, int32_t &leftTopX, int32_t &leftTopY,
102 int32_t &rightBottomX, int32_t &rightBottomY);102 int32_t &rightBottomX, int32_t &rightBottomY);
103+ bool IsShellAssistantToken(uint32_t tokenId);
103private:104private:
104 int32_t ApplyTreeId();105 int32_t ApplyTreeId();
105 void RecycleTreeId(int32_t treeId);106 void RecycleTreeId(int32_t treeId);
@@ -18,6 +18,7 @@
18#include "utils.h"18#include "utils.h"
19#include "hilog_wrapper.h"19#include "hilog_wrapper.h"
20#include "accessibility_account_data.h"20#include "accessibility_account_data.h"
21+#include "accesstoken_kit.h"
21#include "element_operator_callback_impl.h"22#include "element_operator_callback_impl.h"
22#include "accessible_extend_manager_service_proxy.h"23#include "accessible_extend_manager_service_proxy.h"
23#include "accessibility_window_manager.h"24#include "accessibility_window_manager.h"
@@ -167,14 +168,45 @@ void ElementOperatorManager::Clear()
167 asacConnections_.clear();168 asacConnections_.clear();
168}169}
169 170 
171+bool ElementOperatorManager::IsShellAssistantToken(uint32_t tokenId)
172+{
173+ Security::AccessToken::ATokenTypeEnum tokenType =
174+ Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenId);
175+ if (tokenType == Security::AccessToken::TOKEN_NATIVE) {
176+ Security::AccessToken::NativeTokenInfo tokenInfo;
177+ auto result = Security::AccessToken::AccessTokenKit::GetNativeTokenInfo(tokenId, tokenInfo);
178+ if (result != 0) {
179+ HILOG_ERROR("GetHapTokenInfo failed, result: %{public}d", result);
180+ return false;
181+ }
182+ return tokenInfo.processName == "broker";
183+ } else if (tokenType == Security::AccessToken::TOKEN_HAP) {
184+ Security::AccessToken::HapTokenInfo tokenInfo;
185+ auto result = Security::AccessToken::AccessTokenKit::GetHapTokenInfo(tokenId, tokenInfo);
186+ if (result != 0) {
187+ HILOG_ERROR("GetHapTokenInfo failed, result: %{public}d", result);
188+ return false;
189+ }
190+ return tokenInfo.bundleName == "com.huawei.shell_assistant";
191+ }
192+ return false;
193+}
194+ 
170RetError ElementOperatorManager::RegisterElementOperatorByWindowId(int32_t windowId,195RetError ElementOperatorManager::RegisterElementOperatorByWindowId(int32_t windowId,
171 const sptr<IAccessibilityElementOperator> &elementOperator, uint32_t tokenId, bool isBroker, uint64_t displayId)196 const sptr<IAccessibilityElementOperator> &elementOperator, uint32_t tokenId, bool isBroker, uint64_t displayId)
172{197{
173 HILOG_INFO("RegisterElementOperatorByWindowId %{public}d %{public}" PRIu64, windowId, displayId);198 HILOG_INFO("RegisterElementOperatorByWindowId %{public}d %{public}" PRIu64, windowId, displayId);
174 sptr<AccessibilityWindowConnection> oldConnection = GetAccessibilityWindowConnection(windowId);199 sptr<AccessibilityWindowConnection> oldConnection = GetAccessibilityWindowConnection(windowId);
175- if (!isBroker && oldConnection && oldConnection->GetRawProxy(displayId)) {200+ if (oldConnection && oldConnection->GetRawProxy(displayId)) {
176- HILOG_WARN("no need to register again.");201+ if (!isBroker) {
177- return RET_ERR_REGISTER_EXIST;202+ HILOG_WARN("no need to register again.");
203+ return RET_ERR_REGISTER_EXIST;
204+ }
205+ uint32_t oldTokenId = oldConnection->GetTokenIdMap(SINGLE_TREE_ID);
206+ if (!IsShellAssistantToken(oldTokenId)) {
207+ HILOG_ERROR("Broker hijack blocked: oldTokenId[%{public}u] is not shell_assistant", oldTokenId);
208+ return RET_ERR_FAILED;
209+ }
178 }210 }
179 sptr<AccessibilityWindowConnection> connection = oldConnection;211 sptr<AccessibilityWindowConnection> connection = oldConnection;
180 if (connection == nullptr) {212 if (connection == nullptr) {