已开启
融合助手问题处理 #2709
taojuncun创建于 8月8日
融合助手问题处理 #2709
已开启
共 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); | ||
| 103 | private: | 104 | private: |
| 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 | 18 | ||
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | + | ||
| 21 | 22 | ||
| 22 | 23 | ||
| 23 | 24 | ||
| @@ -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 | + | ||
| 170 | RetError ElementOperatorManager::RegisterElementOperatorByWindowId(int32_t windowId, | 195 | RetError 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) { |