openharmony_ci decfcd474a !4885 merge 0726 into master
fix: reset privacy record merge window at minute boundary

Created-by: chennian
Commit-by: chennian
Merged-by: openharmony_ci
Description: ### 关联的issue:
https://gitcode.com/openharmony/security_access_token/issues/3600
### 修改描述(修改功能描述,规格变更说明):
以下任一条件下将当前记录作为新窗口首条、立即发送服务端:

  - 与缓存首条记录不在同一分钟。
  - 与缓存首条记录间隔 >= 200ms。

  窗口内的首条时间戳保持不变,仍是固定窗口。
  
### 测试用例(附上截图,不涉及不需要说明不涉及原因):
1、TDD:
![image.png](https://raw.gitcode.com/user-images/assets/4390047/933674b8-d86c-413c-8c0e-3bff652f9b29/image.png 'image.png')
2、XTS:
不涉及
3、手工用例(自验证步骤/预期结果/实际结果):
 不涉及
### 兼容性上库自检:
- [x] 不涉及API功能发生变化
- [x] 不涉及改变回调函数或生命周期的触发时机或时序,或删除生命周期和回调函数
- [x] 不涉及参数的规格发生了变化,例如取值范围缩小等
- [x] 不涉及对外接口新增权限校验
- [x] 不涉及接口的使用约束规格收紧,例如权限开放范围变化
- [x] 不涉及系统可创建的实例数量收紧
- [x] 不涉及修改了接口返回的数据
- [x] 未新增错误抛出,包括新增错误码、对已有的场景从不会抛错误码变成会抛出错误
- [x] 未修改已有的错误码,对于相同的输入原本抛出A错误码变成了抛出B错误码
- [x] 接口性能未出现明显劣化

### 权限合入自检:
#### 权限自检
- [ ] 仅向系统服务开放的权限(availableType为SERVICE的权限)不允许合入global_system_resources仓和docs仓
- [ ] 非SERVICE的权限与global_system_resources联合构建,即两笔pr关联同一个issue
- [ ] 填入必要参数name/grantMode/availableLevel/since/provisionEnable/distributedSceneEnable, 且与global_system_resources中声明(如果有)一致
- [ ] 声明权限生效的设备平台范围deviceTypes,以列表方式声明("deviceTypes" : [ "xxx", "xxx"]),非全平台生效按需填写,包括但不限于"phone"、"wearable"、"tablet"、"2in1"、"tv"、"car",不允许填写"general",

#### 资料自检(提供docs仓PR链接)
- [ ] 是,已刷新权限文档,PR链接(必填):
- [ ] 否,不涉及权限文档

### 安全编码自检:
- [x] 裸指针避免通过隐式转换构造为sptr
- [x] json对象在取值之前必须先判断类型,避免类型不匹配
- [x] 序列化时必须对传入的数组大小进行校验,避免出现超大数组
- [x] 避免使用未明确位宽的整型,选择使用int8_t、uint8_t等类型
- [x] 外部传入的路径要做规范化校验,对路径中的.、..、../等特殊字符严格校验
- [x] 指针变量、表示资源描述符的变量、bool变量必须赋初值
- [x] readParcelable获取的对象使用前需要判空
- [x] 分配和释放内存的函数需要成对出现
- [x] 申请内存后异常退出前需要及时进行内存释放
- [x] 内存申请前必须对内存大小进行合法性校验
- [x] 内存分配后必须判断是否成功
- [x] 禁止打印文件路径、口令等敏感信息,如有需要,使用private修饰
- [x] 禁止打印内存地址
- [x] 整数之间运算时必须严格检查,确保不会出现溢出、反转、除0
- [x] 禁止对有符号整数进行位操作符运算
- [x] 循环次数如果收外部数据控制,需要检验其合法性
- [x] 必须检查安全函数的返回值,并进行正确处理

### 日志规范自检:
- [x] 【规则】高频代码的正常流程中禁止打印日志
- [x] 【规则】在基本不可能发生的点必须要打印日志
- [x] 【规则】事件记录的日志使用who do what 主谓宾的形式打印
- [x] 【规则】状态变化的日志打印使用state_name:s1->s2, reason:msg的形式打印
- [x] 【规则】参数值的日志打印使用name1=value1, name2=value2…的形式打印


See merge request: openharmony/security_access_token!4885
2026-08-16 15:23:12 +08:00
2026-07-17 15:32:49 +08:00
2022-12-20 10:26:01 +08:00
2026-08-15 15:39:31 +08:00
2026-08-06 23:45:50 +08:00
2026-07-22 09:29:55 +08:00
2026-08-12 11:51:53 +08:00
2026-03-06 14:58:08 +08:00
2026-04-16 20:41:07 +08:00
2025-12-17 00:17:55 +08:00
2022-03-03 14:36:36 +08:00
2025-09-06 18:06:52 +08:00
2026-07-28 14:12:10 +08:00
2026-07-28 14:12:10 +08:00

ATM

Introduction

AccessTokenManager (ATM) implements unified app permission management based on access tokens on OpenHarmony.

The access token information of an app includes the app identifier (APPID), user ID, app twin index, app Ability Privilege Level (APL), and permission information. The access token of each app is identified by a 32-bit token identity (TokenID) in the device.

The ATM module provides the following functions:

  • Verifying app permissions based on the token ID before an app accesses sensitive data or calls an API.
  • Obtaining access token information (for example, APL) based on the token ID.

The following figure shows the ATM architecture.

Directory Structure

/base/security/access_token
├── frameworks                  # Code of basic functionalities.
│   ├── accesstoken             # Code of the ATM framework.
│   ├── common                  # Common code.
│   ├── privacy                 # Code of the privacy framework.
│   └── tokensync               # Code of the access token synchronization framework.
├── interfaces                  # Interfaces
│   ├── innerkits               # Internal interfaces.
│   │   ├── accesstoken         # Code of the internal access token interfaces.
│   │   ├── nativetoken         # Code of the internal native token interfaces.
│   │   ├── privacy             # Code of the internal privacy interfaces.
│   │   ├── token_callback      # Code of the internal callbacks.
│   │   ├── token_setproc       # Code of internal interfaces for exchanging token IDs.
│   │   └── tokensync           # Code of the internal access token synchronization interfaces.
│   └── kits                    # External interfaces.
│   │   ├── accesstoken         # Code of the external access token interfaces.
│   │   ├── common              # Common code of external interfaces.
│   │   └── privacy             # Code of the external privacy interfaces.
└── services                    # Services
    ├── accesstokenmanager      # ATM service code.
    ├── privacymanager          # Privacy manager service code.
    └── tokensyncmanager        # Code of the access token synchronization service. 

Usage

Available APIs

API Description
AccessTokenIDEx AllocHapToken(const HapInfoParams& info, const HapPolicyParams& policy); Allocates a token ID to an app.
FullTokenID AllocLocalTokenID(const std::string& remoteDeviceID, AccessTokenID remoteTokenID); Allocates a local token ID to the app of a remote device.
int UpdateHapToken(AccessTokenIDEx& tokenIdEx, bool isSystemApp, const std::string& appIDDesc, int32_t apiVersion, const HapPolicyParams& policy); Updates token information.
int DeleteToken(AccessTokenID tokenID); Deletes the app's token ID and information.
int GetTokenType(AccessTokenID tokenID); Obtains the type of an access token.
int GetTokenTypeFlag(AccessTokenID tokenID); Obtains the type of a trusted token ID.
int GetTokenType(FullTokenID tokenID); Obtains the type of an access token.
int GetTokenTypeFlag(FullTokenID tokenID); Obtains the type of a trusted token ID.
AccessTokenID GetHapTokenID(int32_t userID, const std::string& bundleName, int32_t instIndex); Obtains the token ID of an app.
AccessTokenIDEx GetHapTokenIDEx(int32_t userID, const std::string& bundleName, int32_t instIndex); Obtains the token ID of an app.
int GetHapTokenInfo(AccessTokenID tokenID, HapTokenInfo& hapTokenInfoRes); Obtains the token information about an OpenHarmony Ability Package (HAP).
int GetNativeTokenInfo(AccessTokenID tokenID, NativeTokenInfo& nativeTokenInfoRes); Obtains the native token information.
int VerifyAccessToken(AccessTokenID tokenID, const std::string& permissionName); Checks whether an access token has the specified permission.
int GetDefPermission(const std::string& permissionName, PermissionDef& permissionDefResult); Obtains definition information about the specified permission.
int GetReqPermissions(AccessTokenID tokenID, std::vector<PermissionStateFull>& reqPermList, bool isSystemGrant); Obtains the status set of the permission requested by a HAP.
int GetPermissionFlag(AccessTokenID tokenID, const std::string& permissionName); Obtains the permissions of the app with the specified token ID.
int GrantPermission(AccessTokenID tokenID, const std::string& permissionName, int flag); Grants a permission to the app with the specified token ID.
int RevokePermission(AccessTokenID tokenID, const std::string& permissionName, int flag); Revokes a permission from the app with the specified token ID.
int ClearUserGrantedPermissionState(AccessTokenID tokenID); Clears the user_grant permission status of the app with the specified token ID.
uint64_t GetAccessTokenId(const char *processname, const char **dcap, int32_t dacpNum, const char *aplStr); Obtains the token ID of a native process.

JS API

Access Token Manager Privacy Manager

API Reference

Public API for Access Token Manager System API for Access Token Manager System API for Privacy Manager API for El5 Filekey Manager

How to Use

ATM provides unified access control for apps and allows apps or service abilities to obtain and verify app permissions and APL. The ATM APIs can be called by a service ability started by a native process or an app HAP.

Native Process

  • Before a native process starts, it calls GetAccessTokenId to obtain a token ID, and then calls SetSelfTokenID to set the token ID to the kernel.

App HAP

  • When an app is installed, AllocHapToken is called to obtain the token ID of the app.
  • When an authentication is required during app running, VerifyAccessToken or GetReqPermissions is called to obtain and verify the app permissions and APL.
  • When an app is uninstalled, DeleteToken is called to delete the related access token information.

Repositories Involved

startup_init_lite

security_access_token

S
Description
ATM(AccessTokenManager)是OpenHarmony上基于AccessToken构建的统一的应用权限管理能力。
Readme 79 MiB
Languages
C++ 96.4%
C 3.3%
Python 0.3%