Closed
[新需求]: add process.appuid property and fix its unit test #2566
jizaiyiAdd on  4 days agoClosed at  2 days ago
jizaiyi
jizaiyi
4 days ago Create

需求背景

多用户/应用分身场景下,process.uid 含用户偏移(uid = userId × 200000 + appUid),JS 侧无公开换算规则,应用无法直接获得纯应用身份 uid(AppUid);模块内部 isIsolatedProcess 等判定逻辑同样需要应用级 uid。third_party_musl 已提供 getappuid(),需要通过 @ohos.process 新增只读属性 appuid 暴露给应用,并对进程生命周期内不变的 AppUid 做静态缓存。

(前续需求单 #2555 已被 PR #2725 关联,按仓库同仓一 Issue 只关联一 PR 的流程,本单为重提 PR 的关联单。)

本次同时修复的 UT 缺陷

PR #2725 检视阶段暴露:新增用例 ProcessUidCombinedScenarioTest001 的断言依赖真实应用进程身份(ASSERT_TRUE(isAppUidRes) 要求 appuid 落在应用 uid 区间),而任何 UT 二进制(host x86 或设备 native UT)都是 uid=0、无 access token 的进程:

  • GetAppUid() 回退/stub 契约下 appuid == getuid() == 0;
  • IsAppUid(0) 恒为 false;
  • 故 ASSERT_TRUE(isAppUidRes) 在 UT 环境确定性失败(检视人设备侧实测与本机复现一致:Actual: false / Expected: true)。

修复方案

期望值改为从 appUid 本身推导(appUid > 0 且 appUid % 100000 落在 [10000, 65535] 区间),断言在任意可执行环境(host UT / 设备 native UT / 真实应用进程)均自洽成立;同时删除 host 守卫,让用例回归全部 UT lane 长期看护。"真应用身份返回 true" 的路径由 xts HAP 用例(xts 测试仓独立提交)覆盖。

本机 host 全量回归:67/67 通过(含修复后的组合场景用例)。

likedislike
openharmony_ci
openharmony_ciCollaborators
4 days ago Comments:

感谢提交Issue!关于Issue的交互操作,请访问OpenHarmony社区支持命令清单。如果有问题,请联系 [@weng-changcheng](https://gitcode.com/weng-changcheng) [@xliu-huanwei](https://gitcode.com/xliu-huanwei) [@gong_19901](https://gitcode.com/gong_19901) 。如果需要调整订阅PR、Issue的变更状态,请访问链接。


Thanks for submitting the issue. For more commands, please visit OpenHarmony Command List. If you have any questions, please refer to committer gitcode for help. If you need to change the subscription of a Pull Request or Issue, please visit the link.

likedislike
openharmony_ciopenharmony_ciCollaborators
4 days ago Added label: waiting_for_assign
jizaiyijizaiyi
4 days ago Associated pull request
jizaiyijizaiyi
4 days ago Associated pull request
openharmony_ciopenharmony_ciCollaborators
2 days ago Close issue
openharmony_ciopenharmony_ciCollaborators
2 days ago changed custom state from 待办的 to 已完成