mirror of
https://gitee.com/openharmony/account_os_account
synced 2024-11-23 02:00:01 +00:00
update OpenHarmony 2.0 Canary
This commit is contained in:
parent
1f54b2fde6
commit
831b40a6df
15
.gitattributes
vendored
Normal file
15
.gitattributes
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
*.tgz filter=lfs diff=lfs merge=lfs -text
|
||||
*.trp filter=lfs diff=lfs merge=lfs -text
|
||||
*.apk filter=lfs diff=lfs merge=lfs -text
|
||||
*.jar filter=lfs diff=lfs merge=lfs -text
|
||||
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
||||
*.zip filter=lfs diff=lfs merge=lfs -text
|
||||
*.asm filter=lfs diff=lfs merge=lfs -text
|
||||
*.8svn filter=lfs diff=lfs merge=lfs -text
|
||||
*.9svn filter=lfs diff=lfs merge=lfs -text
|
||||
*.dylib filter=lfs diff=lfs merge=lfs -text
|
||||
*.exe filter=lfs diff=lfs merge=lfs -text
|
||||
*.a filter=lfs diff=lfs merge=lfs -text
|
||||
*.so filter=lfs diff=lfs merge=lfs -text
|
||||
*.bin filter=lfs diff=lfs merge=lfs -text
|
||||
*.dll filter=lfs diff=lfs merge=lfs -text
|
177
LICENSE
Normal file
177
LICENSE
Normal file
@ -0,0 +1,177 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
36
README.en.md
36
README.en.md
@ -1,36 +0,0 @@
|
||||
# account_os_account
|
||||
|
||||
#### Description
|
||||
Allowing apps to use OS account-related functions | 允许您的应用程序使用操作系统帐号相关功能
|
||||
|
||||
#### Software Architecture
|
||||
Software architecture description
|
||||
|
||||
#### Installation
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
|
||||
#### Instructions
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
|
||||
#### Contribution
|
||||
|
||||
1. Fork the repository
|
||||
2. Create Feat_xxx branch
|
||||
3. Commit your code
|
||||
4. Create Pull Request
|
||||
|
||||
|
||||
#### Gitee Feature
|
||||
|
||||
1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
|
||||
2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
|
||||
3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
|
||||
4. The most valuable open source project [GVP](https://gitee.com/gvp)
|
||||
5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
|
||||
6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
|
153
README.md
Normal file → Executable file
153
README.md
Normal file → Executable file
@ -1,37 +1,140 @@
|
||||
# account_os_account
|
||||
# os\_account<a name="EN-US_TOPIC_0000001123681215"></a>
|
||||
|
||||
#### 介绍
|
||||
Allowing apps to use OS account-related functions | 允许您的应用程序使用操作系统帐号相关功能
|
||||
- [Introduction](#section11660541593)
|
||||
- [Architecture](#section1412183212132)
|
||||
- [Directory Structure](#section161941989596)
|
||||
- [Usage](#section1312121216216)
|
||||
- [Available APIs](#section1551164914237)
|
||||
|
||||
#### 软件架构
|
||||
软件架构说明
|
||||
- [Repositories Involved](#section1371113476307)
|
||||
|
||||
## Introduction<a name="section11660541593"></a>
|
||||
|
||||
In a standard system, the OS account module supports login status management of distributed cloud accounts, interconnection with vendors' cloud account apps on the device side, and query and update of the cloud account login status.
|
||||
|
||||
## Architecture<a name="section1412183212132"></a>
|
||||
|
||||
**Figure 1** OS account architecture<a name="fig4460722185514"></a>
|
||||
|
||||
|
||||
#### 安装教程
|
||||
![](figures/en-us_image_0000001123704367.png)
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
## Directory Structure<a name="section161941989596"></a>
|
||||
|
||||
#### 使用说明
|
||||
```
|
||||
/base/account/os_account
|
||||
├── common # Common basic code
|
||||
│ ├── account_error # Error codes
|
||||
│ ├── log # Code for printing logs
|
||||
│ ├── perf_stat # Performance statistics
|
||||
│ └── test # Test code of common modules
|
||||
├── interfaces # APIs exposed externally
|
||||
│ └── innerkits # Header files for internal modules
|
||||
├── kits # Development framework
|
||||
├── sa_profile # SA profile
|
||||
├── services # Service code
|
||||
│ └── accountmgr # Account manager service
|
||||
└── test # Test code
|
||||
└── resource # Test resources
|
||||
```
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
## Usage<a name="section1312121216216"></a>
|
||||
|
||||
#### 参与贡献
|
||||
### Available APIs<a name="section1551164914237"></a>
|
||||
|
||||
1. Fork 本仓库
|
||||
2. 新建 Feat_xxx 分支
|
||||
3. 提交代码
|
||||
4. 新建 Pull Request
|
||||
The APIs available for distributed accounts can be called to query and update the account login status, and are supported only by system apps.
|
||||
|
||||
**Table 1** Description of the distributed account module
|
||||
|
||||
#### 特技
|
||||
<a name="table1650615420620"></a>
|
||||
<table><thead align="left"><tr id="row175061254462"><th class="cellrowborder" valign="top" width="31.230000000000004%" id="mcps1.2.3.1.1"><p id="p1250613547612"><a name="p1250613547612"></a><a name="p1250613547612"></a>Module</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="68.77%" id="mcps1.2.3.1.2"><p id="p85066541767"><a name="p85066541767"></a><a name="p85066541767"></a>Description</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="row0506185417614"><td class="cellrowborder" valign="top" width="31.230000000000004%" headers="mcps1.2.3.1.1 "><p id="p1561112131788"><a name="p1561112131788"></a><a name="p1561112131788"></a>distributedAccount</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="68.77%" headers="mcps1.2.3.1.2 "><p id="p1954531161115"><a name="p1954531161115"></a><a name="p1954531161115"></a>Provides methods for managing the distributed account module.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
**Table 2** Classes for distributed accounts
|
||||
|
||||
<a name="table1324102194217"></a>
|
||||
<table><thead align="left"><tr id="row43241021174219"><th class="cellrowborder" valign="top" width="51.61%" id="mcps1.2.3.1.1"><p id="p10324621104214"><a name="p10324621104214"></a><a name="p10324621104214"></a>Class</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="48.39%" id="mcps1.2.3.1.2"><p id="p2324221174213"><a name="p2324221174213"></a><a name="p2324221174213"></a>Description</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="row1432413213425"><td class="cellrowborder" valign="top" width="51.61%" headers="mcps1.2.3.1.1 "><p id="p1732472184212"><a name="p1732472184212"></a><a name="p1732472184212"></a>DistributedAccountAbility</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="48.39%" headers="mcps1.2.3.1.2 "><p id="p1932432110421"><a name="p1932432110421"></a><a name="p1932432110421"></a>Provides methods for querying and updating the login status of distributed accounts.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row12324162116427"><td class="cellrowborder" valign="top" width="51.61%" headers="mcps1.2.3.1.1 "><p id="p1232422184216"><a name="p1232422184216"></a><a name="p1232422184216"></a>DistributedInfo</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="48.39%" headers="mcps1.2.3.1.2 "><p id="p1324821164215"><a name="p1324821164215"></a><a name="p1324821164215"></a>Provides methods for querying distributed account information, including the account name, UID, and login status.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
**Table 3** Methods for the distributed account module
|
||||
|
||||
<a name="table6561120114219"></a>
|
||||
<table><thead align="left"><tr id="row115642084211"><th class="cellrowborder" valign="top" width="51.67%" id="mcps1.2.3.1.1"><p id="p7565201424"><a name="p7565201424"></a><a name="p7565201424"></a>Method</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="48.33%" id="mcps1.2.3.1.2"><p id="p0568204427"><a name="p0568204427"></a><a name="p0568204427"></a>Description</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="row456162064218"><td class="cellrowborder" valign="top" width="51.67%" headers="mcps1.2.3.1.1 "><p id="p8388718174317"><a name="p8388718174317"></a><a name="p8388718174317"></a>function getDistributedAccountAbility(): DistributedAccountAbility</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="48.33%" headers="mcps1.2.3.1.2 "><p id="p5561920194211"><a name="p5561920194211"></a><a name="p5561920194211"></a>Obtains a singleton of a distributed account.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
**Table 4** DistributedAccountAbility description
|
||||
|
||||
<a name="table1738121244713"></a>
|
||||
<table><thead align="left"><tr id="row4381111254710"><th class="cellrowborder" valign="top" width="31.209999999999997%" id="mcps1.2.3.1.1"><p id="p1738116127470"><a name="p1738116127470"></a><a name="p1738116127470"></a>Method</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="68.78999999999999%" id="mcps1.2.3.1.2"><p id="p10381161224717"><a name="p10381161224717"></a><a name="p10381161224717"></a>Description</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="row18381121274715"><td class="cellrowborder" valign="top" width="31.209999999999997%" headers="mcps1.2.3.1.1 "><p id="p1671817233812"><a name="p1671817233812"></a><a name="p1671817233812"></a>queryOsAccountDistributedInfo(callback: AsyncCallback<DistributedInfo>): void</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="68.78999999999999%" headers="mcps1.2.3.1.2 "><p id="p63421233134612"><a name="p63421233134612"></a><a name="p63421233134612"></a>Queries information about the distributed account.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row1938113125470"><td class="cellrowborder" valign="top" width="31.209999999999997%" headers="mcps1.2.3.1.1 "><p id="p73429332466"><a name="p73429332466"></a><a name="p73429332466"></a>queryOsAccountDistributedInfo(): Promise<DistributedInfo></p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="68.78999999999999%" headers="mcps1.2.3.1.2 "><p id="p7342133394620"><a name="p7342133394620"></a><a name="p7342133394620"></a>Queries information about the distributed account.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row13811912164716"><td class="cellrowborder" valign="top" width="31.209999999999997%" headers="mcps1.2.3.1.1 "><p id="p186182593814"><a name="p186182593814"></a><a name="p186182593814"></a>updateOsAccountDistributedInfo(accountInfo: DistributedInfo, callback: AsyncCallback<boolean>): void</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="68.78999999999999%" headers="mcps1.2.3.1.2 "><p id="p1534263304617"><a name="p1534263304617"></a><a name="p1534263304617"></a>Updates information about the distributed account.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row10382181218477"><td class="cellrowborder" valign="top" width="31.209999999999997%" headers="mcps1.2.3.1.1 "><p id="p686934433810"><a name="p686934433810"></a><a name="p686934433810"></a>updateOsAccountDistributedInfo(accountInfo: DistributedInfo): Promise<boolean></p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="68.78999999999999%" headers="mcps1.2.3.1.2 "><p id="p0342193384611"><a name="p0342193384611"></a><a name="p0342193384611"></a>Updates information about the distributed account.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
## Repositories Involved<a name="section1371113476307"></a>
|
||||
|
||||
Account subsystem
|
||||
|
||||
**account\_os\_account**
|
||||
|
||||
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
|
||||
2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
|
||||
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
|
||||
4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
|
||||
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
|
||||
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
|
||||
|
140
README_zh.md
Executable file
140
README_zh.md
Executable file
@ -0,0 +1,140 @@
|
||||
# 系统帐号组件<a name="ZH-CN_TOPIC_0000001123681215"></a>
|
||||
|
||||
- [简介](#section11660541593)
|
||||
- [组件架构图](#section1412183212132)
|
||||
- [目录](#section161941989596)
|
||||
- [说明](#section1312121216216)
|
||||
- [接口说明](#section1551164914237)
|
||||
|
||||
- [相关仓](#section1371113476307)
|
||||
|
||||
## 简介<a name="section11660541593"></a>
|
||||
|
||||
在标准系统上,系统帐号组件主要提供分布式帐号登录状态管理能力,支持在端侧对接厂商云帐号应用,提供云帐号登录状态查询和更新的管理能力。
|
||||
|
||||
## 组件架构图<a name="section1412183212132"></a>
|
||||
|
||||
**图 1** 系统帐号组件架构图<a name="fig4460722185514"></a>
|
||||
|
||||
|
||||
![](figures/zh-cn_image_0000001123704367.png)
|
||||
|
||||
## 目录<a name="section161941989596"></a>
|
||||
|
||||
```
|
||||
/base/account/os_account
|
||||
├── common # 公共基础模块
|
||||
│ ├── account_error # 错误码定义
|
||||
│ ├── log # 日志打印代码
|
||||
│ ├── perf_stat # 性能统计
|
||||
│ └── test # 公共模块测试代码
|
||||
├── interfaces # 对外接口存放目录
|
||||
│ └── innerkits # 对内部组件暴露的头文件存放目录
|
||||
├── kits # 系统帐号组件开发框架
|
||||
├── sa_profile # 帐号SA配置文件定义目录
|
||||
├── services # 系统帐号组件服务代码
|
||||
│ └── accountmgr # 帐号管理服务目录
|
||||
└── test # 系统帐号组件测试代码
|
||||
└── resource # 系统帐号组件测试资源
|
||||
```
|
||||
|
||||
## 说明<a name="section1312121216216"></a>
|
||||
|
||||
### 接口说明<a name="section1551164914237"></a>
|
||||
|
||||
分布式帐号的功能主要包括查询和更新帐号登录状态,仅支持系统应用。
|
||||
|
||||
**表 1** 分布式帐号模块说明
|
||||
|
||||
<a name="table1650615420620"></a>
|
||||
<table><thead align="left"><tr id="row175061254462"><th class="cellrowborder" valign="top" width="51.53%" id="mcps1.2.3.1.1"><p id="p1250613547612"><a name="p1250613547612"></a><a name="p1250613547612"></a>模块名</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="48.47%" id="mcps1.2.3.1.2"><p id="p85066541767"><a name="p85066541767"></a><a name="p85066541767"></a>描述</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="row0506185417614"><td class="cellrowborder" valign="top" width="51.53%" headers="mcps1.2.3.1.1 "><p id="p1561112131788"><a name="p1561112131788"></a><a name="p1561112131788"></a>distributedAccount</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="48.47%" headers="mcps1.2.3.1.2 "><p id="p1954531161115"><a name="p1954531161115"></a><a name="p1954531161115"></a>提供分布式帐号模块管理方法</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
**表 2** 分布式帐号类说明
|
||||
|
||||
<a name="table1324102194217"></a>
|
||||
<table><thead align="left"><tr id="row43241021174219"><th class="cellrowborder" valign="top" width="51.61%" id="mcps1.2.3.1.1"><p id="p10324621104214"><a name="p10324621104214"></a><a name="p10324621104214"></a>类名</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="48.39%" id="mcps1.2.3.1.2"><p id="p2324221174213"><a name="p2324221174213"></a><a name="p2324221174213"></a>描述</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="row1432413213425"><td class="cellrowborder" valign="top" width="51.61%" headers="mcps1.2.3.1.1 "><p id="p1732472184212"><a name="p1732472184212"></a><a name="p1732472184212"></a>DistributedAccountAbility</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="48.39%" headers="mcps1.2.3.1.2 "><p id="p1932432110421"><a name="p1932432110421"></a><a name="p1932432110421"></a>提供查询和更新分布式帐号登录状态方法</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row12324162116427"><td class="cellrowborder" valign="top" width="51.61%" headers="mcps1.2.3.1.1 "><p id="p1232422184216"><a name="p1232422184216"></a><a name="p1232422184216"></a>DistributedInfo</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="48.39%" headers="mcps1.2.3.1.2 "><p id="p1324821164215"><a name="p1324821164215"></a><a name="p1324821164215"></a>提供分布式帐号信息,主要包括帐号名、帐号UID和帐号登录状态。</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
**表 3** 分布式帐号模块方法说明
|
||||
|
||||
<a name="table6561120114219"></a>
|
||||
<table><thead align="left"><tr id="row115642084211"><th class="cellrowborder" valign="top" width="51.67%" id="mcps1.2.3.1.1"><p id="p7565201424"><a name="p7565201424"></a><a name="p7565201424"></a>方法</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="48.33%" id="mcps1.2.3.1.2"><p id="p0568204427"><a name="p0568204427"></a><a name="p0568204427"></a>描述</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="row456162064218"><td class="cellrowborder" valign="top" width="51.67%" headers="mcps1.2.3.1.1 "><p id="p8388718174317"><a name="p8388718174317"></a><a name="p8388718174317"></a>function getDistributedAccountAbility(): DistributedAccountAbility</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="48.33%" headers="mcps1.2.3.1.2 "><p id="p5561920194211"><a name="p5561920194211"></a><a name="p5561920194211"></a>获取分布式帐号单实例对象</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
**表 4** DistributedAccountAbility方法说明
|
||||
|
||||
<a name="table1738121244713"></a>
|
||||
<table><thead align="left"><tr id="row4381111254710"><th class="cellrowborder" valign="top" width="64.72%" id="mcps1.2.3.1.1"><p id="p1738116127470"><a name="p1738116127470"></a><a name="p1738116127470"></a>方法</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="35.28%" id="mcps1.2.3.1.2"><p id="p10381161224717"><a name="p10381161224717"></a><a name="p10381161224717"></a>描述</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="row18381121274715"><td class="cellrowborder" valign="top" width="64.72%" headers="mcps1.2.3.1.1 "><p id="p1671817233812"><a name="p1671817233812"></a><a name="p1671817233812"></a>queryOsAccountDistributedInfo(callback: AsyncCallback<DistributedInfo>): void</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="35.28%" headers="mcps1.2.3.1.2 "><p id="p63421233134612"><a name="p63421233134612"></a><a name="p63421233134612"></a>查询分布式帐号信息</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row1938113125470"><td class="cellrowborder" valign="top" width="64.72%" headers="mcps1.2.3.1.1 "><p id="p73429332466"><a name="p73429332466"></a><a name="p73429332466"></a>queryOsAccountDistributedInfo(): Promise<DistributedInfo></p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="35.28%" headers="mcps1.2.3.1.2 "><p id="p7342133394620"><a name="p7342133394620"></a><a name="p7342133394620"></a>查询分布式帐号信息</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row13811912164716"><td class="cellrowborder" valign="top" width="64.72%" headers="mcps1.2.3.1.1 "><p id="p186182593814"><a name="p186182593814"></a><a name="p186182593814"></a>updateOsAccountDistributedInfo(accountInfo: DistributedInfo, callback: AsyncCallback<boolean>): void</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="35.28%" headers="mcps1.2.3.1.2 "><p id="p1534263304617"><a name="p1534263304617"></a><a name="p1534263304617"></a>更新分布式帐号信息</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row10382181218477"><td class="cellrowborder" valign="top" width="64.72%" headers="mcps1.2.3.1.1 "><p id="p686934433810"><a name="p686934433810"></a><a name="p686934433810"></a>updateOsAccountDistributedInfo(accountInfo: DistributedInfo): Promise<boolean></p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="35.28%" headers="mcps1.2.3.1.2 "><p id="p0342193384611"><a name="p0342193384611"></a><a name="p0342193384611"></a>更新分布式帐号信息</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
## 相关仓<a name="section1371113476307"></a>
|
||||
|
||||
帐号子系统
|
||||
|
||||
**account\_os\_account**
|
||||
|
49
common/BUILD.gn
Executable file
49
common/BUILD.gn
Executable file
@ -0,0 +1,49 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//base/account/os_account/os_account.gni")
|
||||
import("//build/ohos.gni")
|
||||
|
||||
group("common_target") {
|
||||
deps = [ ":libaccount_common" ]
|
||||
}
|
||||
|
||||
config("account_common_config") {
|
||||
include_dirs = [
|
||||
"log/include",
|
||||
"perf_stat/include",
|
||||
"//utils/native/base/include",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_shared_library("libaccount_common") {
|
||||
sources = [
|
||||
"log/src/account_log_wrapper.cpp",
|
||||
"perf_stat/src/perf_stat.cpp",
|
||||
]
|
||||
|
||||
defines = [
|
||||
"ACCOUNT_LOG_TAG = \"ACCOUNT_COMMON\"",
|
||||
"LOG_DOMAIN = 0xD001B00",
|
||||
]
|
||||
|
||||
public_configs = [
|
||||
":account_common_config",
|
||||
"//utils/native/base:utils_config",
|
||||
]
|
||||
|
||||
public_deps = [ "//utils/native/base:utils" ]
|
||||
|
||||
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
|
||||
part_name = "os_account_standard"
|
||||
}
|
72
common/account_error/include/account_error_no.h
Executable file
72
common/account_error/include/account_error_no.h
Executable file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef BASE_ACCOUNT_INCLUDE_ACCOUNT_ERROR_NO_H
|
||||
#define BASE_ACCOUNT_INCLUDE_ACCOUNT_ERROR_NO_H
|
||||
|
||||
#include "errors.h"
|
||||
|
||||
namespace OHOS {
|
||||
enum {
|
||||
ACCOUNT_MODULE_COMMON = 0x00,
|
||||
ACCOUNT_MODULE_ACCOUNTMGR,
|
||||
ACCOUNT_MODULE_DATADEAL,
|
||||
ACCOUNT_MODULE_IACCOUNT
|
||||
};
|
||||
|
||||
/* Error code for common */
|
||||
constexpr ErrCode ACCOUNT_COMMON_ERR_OFFSET = ErrCodeOffset(SUBSYS_ACCOUNT, ACCOUNT_MODULE_COMMON);
|
||||
|
||||
/* Error code for AccountMgr */
|
||||
constexpr ErrCode ACCOUNT_ACCOUNTMGR_ERR_OFFSET = ErrCodeOffset(SUBSYS_ACCOUNT, ACCOUNT_MODULE_ACCOUNTMGR);
|
||||
enum {
|
||||
ERR_ACCOUNT_MGR_DUMP_ERROR = ACCOUNT_ACCOUNTMGR_ERR_OFFSET + 0x0001,
|
||||
ERR_ACCOUNT_MGR_GET_REMOTE_SA_ERROR,
|
||||
ERR_ACCOUNT_MGR_CONNECT_SA_ERROR,
|
||||
ERR_ACCOUNT_MGR_ADD_TO_SA_ERROR
|
||||
};
|
||||
|
||||
/* Error code for DataDeal module */
|
||||
constexpr ErrCode ACCOUNT_DATADEAL_ERR_OFFSET = ErrCodeOffset(SUBSYS_ACCOUNT, ACCOUNT_MODULE_DATADEAL);
|
||||
enum {
|
||||
ERR_ACCOUNT_DATADEAL_INPUT_FILE_ERROR = ACCOUNT_DATADEAL_ERR_OFFSET + 0x0001,
|
||||
ERR_ACCOUNT_DATADEAL_FILE_PARSE_FAILED,
|
||||
ERR_ACCOUNT_DATADEAL_DIGEST_ERROR,
|
||||
ERR_ACCOUNT_DATADEAL_FILE_WRITE_FAILED,
|
||||
ERR_ACCOUNT_DATADEAL_JSON_KEY_NOT_EXIST,
|
||||
ERR_ACCOUNT_DATADEAL_NOT_READY,
|
||||
ERR_ACCOUNT_DATADEAL_JSON_FILE_CORRUPTION
|
||||
};
|
||||
|
||||
/* Error code for IAccount */
|
||||
constexpr ErrCode ACCOUNT_IACCOUNT_ERR_OFFSET = ErrCodeOffset(SUBSYS_ACCOUNT, ACCOUNT_MODULE_IACCOUNT);
|
||||
enum {
|
||||
ERR_ACCOUNT_ZIDL_ACCOUNT_INFO_CHECK_ERROR = ACCOUNT_IACCOUNT_ERR_OFFSET + 0x0001,
|
||||
ERR_ACCOUNT_ZIDL_WRITE_DESCRIPTOR_ERROR,
|
||||
ERR_ACCOUNT_ZIDL_READ_RESULT_ERROR,
|
||||
ERR_ACCOUNT_ZIDL_WRITE_RESULT_ERROR,
|
||||
ERR_ACCOUNT_ZIDL_ACCOUNT_STUB_ERROR,
|
||||
ERR_ACCOUNT_ZIDL_ACCOUNT_SEND_REQUEST_ERROR,
|
||||
ERR_ACCOUNT_ZIDL_WRITE_NAME_ERROR,
|
||||
ERR_ACCOUNT_ZIDL_WRITE_UID_ERROR,
|
||||
ERR_ACCOUNT_ZIDL_WRITE_ACCOUNT_STATUS_ERROR,
|
||||
ERR_ACCOUNT_ZIDL_MGR_NOT_READY_ERROR,
|
||||
ERR_ACCOUNT_ZIDL_CHECK_PERMISSION_ERROR,
|
||||
ERR_ACCOUNT_ZIDL_WRITE_PARCEL_DATA_ERROR,
|
||||
ERR_ACCOUNT_ZIDL_INVALID_RESULT_ERROR
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* BASE_ACCOUNT_INCLUDE_ACCOUNT_ERROR_NO_H */
|
67
common/log/include/account_log_wrapper.h
Executable file
67
common/log/include/account_log_wrapper.h
Executable file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef BASE_ACCOUNT_COMMON_LOG_INCLUDE_ACCOUNT_LOG_WRAPPER_H
|
||||
#define BASE_ACCOUNT_COMMON_LOG_INCLUDE_ACCOUNT_LOG_WRAPPER_H
|
||||
|
||||
#include "hilog/log.h"
|
||||
#include <string>
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountSA {
|
||||
enum class AccountLogLevel {
|
||||
DEBUG = 0,
|
||||
INFO,
|
||||
WARN,
|
||||
ERROR,
|
||||
FATAL
|
||||
};
|
||||
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel ACCOUNT_LABEL = {LOG_CORE, LOG_DOMAIN, ACCOUNT_LOG_TAG};
|
||||
|
||||
class AccountLogWrapper {
|
||||
public:
|
||||
static bool JudgeLevel(const AccountLogLevel& level);
|
||||
|
||||
static void SetLogLevel(const AccountLogLevel& level)
|
||||
{
|
||||
level_ = level;
|
||||
}
|
||||
|
||||
static const AccountLogLevel& GetLogLevel()
|
||||
{
|
||||
return level_;
|
||||
}
|
||||
|
||||
static std::string GetBriefFileName(const std::string &file);
|
||||
|
||||
private:
|
||||
static AccountLogLevel level_;
|
||||
};
|
||||
|
||||
#define PRINT_LOG(LEVEL, Level, fmt, ...) \
|
||||
if (AccountLogWrapper::JudgeLevel(AccountLogLevel::LEVEL)) \
|
||||
OHOS::HiviewDFX::HiLog::Level(ACCOUNT_LABEL, "[%{public}s(%{public}s)] " fmt, \
|
||||
AccountLogWrapper::GetBriefFileName(std::string(__FILE__)).c_str(), __FUNCTION__, ##__VA_ARGS__)
|
||||
|
||||
#define ACCOUNT_LOGD(fmt, ...) PRINT_LOG(DEBUG, Debug, fmt, ##__VA_ARGS__)
|
||||
#define ACCOUNT_LOGI(fmt, ...) PRINT_LOG(INFO, Info, fmt, ##__VA_ARGS__)
|
||||
#define ACCOUNT_LOGW(fmt, ...) PRINT_LOG(WARN, Warn, fmt, ##__VA_ARGS__)
|
||||
#define ACCOUNT_LOGE(fmt, ...) PRINT_LOG(ERROR, Error, fmt, ##__VA_ARGS__)
|
||||
#define ACCOUNT_LOGF(fmt, ...) PRINT_LOG(FATAL, Fatal, fmt, ##__VA_ARGS__)
|
||||
} // namespace AccountSA
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_ACCOUNT_COMMON_LOG_INCLUDE_ACCOUNT_LOG_WRAPPER_H
|
44
common/log/src/account_log_wrapper.cpp
Executable file
44
common/log/src/account_log_wrapper.cpp
Executable file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "account_log_wrapper.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountSA {
|
||||
// initial static member object
|
||||
AccountLogLevel AccountLogWrapper::level_ = AccountLogLevel::INFO;
|
||||
|
||||
bool AccountLogWrapper::JudgeLevel(const AccountLogLevel& level)
|
||||
{
|
||||
return (level >= AccountLogWrapper::GetLogLevel());
|
||||
}
|
||||
|
||||
std::string AccountLogWrapper::GetBriefFileName(const std::string &file)
|
||||
{
|
||||
auto pos = file.find_last_of("/");
|
||||
if (pos != std::string::npos) {
|
||||
return file.substr(pos + 1);
|
||||
}
|
||||
|
||||
pos = file.find_last_of("\\");
|
||||
if (pos != std::string::npos) {
|
||||
return file.substr(pos + 1);
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
} // namespace AccountSA
|
||||
} // namespace OHOS
|
90
common/perf_stat/include/perf_stat.h
Executable file
90
common/perf_stat/include/perf_stat.h
Executable file
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef BASE_ACCOUNT_SERVICES_COMMON_INCLUDE_PERF_STAT_H
|
||||
#define BASE_ACCOUNT_SERVICES_COMMON_INCLUDE_PERF_STAT_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include "singleton.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountSA {
|
||||
class PerfStat : public Singleton<PerfStat> {
|
||||
DECLARE_SINGLETON(PerfStat);
|
||||
|
||||
public:
|
||||
int64_t GetAccountBindStartTime() const;
|
||||
void SetAccountBindStartTime(int64_t time);
|
||||
|
||||
int64_t GetAccountBindEndTime() const;
|
||||
void SetAccountBindEndTime(int64_t time);
|
||||
|
||||
int64_t GetAccountAddStartTime() const;
|
||||
void SetAccountAddStartTime(int64_t time);
|
||||
|
||||
int64_t GetAccountAddEndTime() const;
|
||||
void SetAccountAddEndTime(int64_t time);
|
||||
|
||||
int64_t GetAccountDelStartTime() const;
|
||||
void SetAccountDelStartTime(int64_t time);
|
||||
|
||||
int64_t GetAccountDelEndTime() const;
|
||||
void SetAccountDelEndTime(int64_t time);
|
||||
|
||||
int64_t GetAccountQueryStartTime() const;
|
||||
void SetAccountQueryStartTime(int64_t time);
|
||||
|
||||
int64_t GetAccountQueryEndTime() const;
|
||||
void SetAccountQueryEndTime(int64_t time);
|
||||
|
||||
void SetInstanceStopTime(int64_t);
|
||||
void SetInstanceStartTime(int64_t);
|
||||
void SetInstanceInitTime(int64_t);
|
||||
void SetInstanceCreateTime(int64_t);
|
||||
void SetAccountStateChangeTime(const std::string &stateStr, int64_t time);
|
||||
|
||||
bool GetPerfStatEnabled() const;
|
||||
void SetPerfStatEnabled(bool enable);
|
||||
|
||||
void Reset();
|
||||
void Dump(std::string& result) const;
|
||||
|
||||
private:
|
||||
int64_t accountBindBegin_ = 0;
|
||||
int64_t accountBindEnd_ = 0;
|
||||
|
||||
int64_t accountAddBegin_ = 0;
|
||||
int64_t accountAddEnd_ = 0;
|
||||
|
||||
int64_t accountDelBegin_ = 0;
|
||||
int64_t accountDelEnd_ = 0;
|
||||
|
||||
int64_t accountQueryBegin_ = 0;
|
||||
int64_t accountQueryEnd_ = 0;
|
||||
|
||||
int64_t instanceCreate_ = 0;
|
||||
int64_t serviceOnStart_ = 0;
|
||||
int64_t serviceOnStop_ = 0;
|
||||
int64_t serviceInit_ = 0;
|
||||
|
||||
std::map<std::string, int64_t> accountStateChangeRecords_;
|
||||
|
||||
bool enableStat_ = true;
|
||||
};
|
||||
} // namespace AccountSA
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_ACCOUNT_SERVICES_COMMON_INCLUDE_PERF_STAT_H
|
236
common/perf_stat/src/perf_stat.cpp
Executable file
236
common/perf_stat/src/perf_stat.cpp
Executable file
@ -0,0 +1,236 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "perf_stat.h"
|
||||
|
||||
#include "account_log_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountSA {
|
||||
PerfStat::PerfStat()
|
||||
{
|
||||
ACCOUNT_LOGD("create");
|
||||
}
|
||||
|
||||
PerfStat::~PerfStat()
|
||||
{
|
||||
ACCOUNT_LOGD("destroy");
|
||||
Reset();
|
||||
}
|
||||
|
||||
/* Account Bind process statistic */
|
||||
int64_t PerfStat::GetAccountBindStartTime() const
|
||||
{
|
||||
return accountBindBegin_;
|
||||
}
|
||||
|
||||
void PerfStat::SetAccountBindStartTime(int64_t time)
|
||||
{
|
||||
accountBindBegin_ = (time > 0) ? time : 0;
|
||||
}
|
||||
|
||||
int64_t PerfStat::GetAccountBindEndTime() const
|
||||
{
|
||||
return accountBindEnd_;
|
||||
}
|
||||
|
||||
void PerfStat::SetAccountBindEndTime(int64_t time)
|
||||
{
|
||||
accountBindEnd_ = (time > 0 && time > accountBindBegin_) ? time : accountBindBegin_;
|
||||
}
|
||||
|
||||
/* Account Add process statistic */
|
||||
int64_t PerfStat::GetAccountAddStartTime() const
|
||||
{
|
||||
return accountAddBegin_;
|
||||
}
|
||||
|
||||
void PerfStat::SetAccountAddStartTime(int64_t time)
|
||||
{
|
||||
accountAddBegin_ = (time > 0) ? time : 0;
|
||||
}
|
||||
|
||||
int64_t PerfStat::GetAccountAddEndTime() const
|
||||
{
|
||||
return accountAddEnd_;
|
||||
}
|
||||
|
||||
void PerfStat::SetAccountAddEndTime(int64_t time)
|
||||
{
|
||||
accountAddEnd_ = (time > 0 && time > accountAddBegin_) ? time : accountAddBegin_;
|
||||
}
|
||||
|
||||
/* Account Delete process statistic */
|
||||
int64_t PerfStat::GetAccountDelStartTime() const
|
||||
{
|
||||
return accountDelBegin_;
|
||||
}
|
||||
|
||||
void PerfStat::SetAccountDelStartTime(int64_t time)
|
||||
{
|
||||
accountDelBegin_ = (time > 0) ? time : 0;
|
||||
}
|
||||
|
||||
int64_t PerfStat::GetAccountDelEndTime() const
|
||||
{
|
||||
return accountDelEnd_;
|
||||
}
|
||||
|
||||
void PerfStat::SetAccountDelEndTime(int64_t time)
|
||||
{
|
||||
accountDelEnd_ = (time > 0 && time > accountDelBegin_) ? time : accountDelBegin_;
|
||||
}
|
||||
|
||||
/* Account Query process statistic */
|
||||
int64_t PerfStat::GetAccountQueryStartTime() const
|
||||
{
|
||||
return accountQueryBegin_;
|
||||
}
|
||||
|
||||
void PerfStat::SetAccountQueryStartTime(int64_t time)
|
||||
{
|
||||
accountQueryBegin_ = (time > 0) ? time : 0;
|
||||
}
|
||||
|
||||
int64_t PerfStat::GetAccountQueryEndTime() const
|
||||
{
|
||||
return accountQueryEnd_;
|
||||
}
|
||||
|
||||
void PerfStat::SetAccountQueryEndTime(int64_t time)
|
||||
{
|
||||
accountQueryEnd_ = (time > 0 && time > accountQueryBegin_) ? time : accountQueryBegin_;
|
||||
}
|
||||
|
||||
/* Account Service process statistic */
|
||||
void PerfStat::SetInstanceStartTime(int64_t time)
|
||||
{
|
||||
serviceOnStart_ = time;
|
||||
}
|
||||
|
||||
void PerfStat::SetInstanceStopTime(int64_t time)
|
||||
{
|
||||
serviceOnStop_ = time;
|
||||
}
|
||||
|
||||
void PerfStat::SetInstanceCreateTime(int64_t time)
|
||||
{
|
||||
instanceCreate_ = time;
|
||||
}
|
||||
|
||||
void PerfStat::SetInstanceInitTime(int64_t time)
|
||||
{
|
||||
serviceInit_ = time;
|
||||
}
|
||||
|
||||
/* Account state machine process statistic */
|
||||
void PerfStat::SetAccountStateChangeTime(const std::string &stateStr, int64_t time)
|
||||
{
|
||||
accountStateChangeRecords_[stateStr] = time;
|
||||
}
|
||||
|
||||
/* Set/Get perf statistic enable state */
|
||||
bool PerfStat::GetPerfStatEnabled() const
|
||||
{
|
||||
return enableStat_;
|
||||
}
|
||||
|
||||
void PerfStat::SetPerfStatEnabled(bool enable)
|
||||
{
|
||||
enableStat_ = enable;
|
||||
}
|
||||
|
||||
/* reset to default */
|
||||
void PerfStat::Reset()
|
||||
{
|
||||
accountBindBegin_ = 0;
|
||||
accountBindEnd_ = 0;
|
||||
|
||||
accountAddBegin_ = 0;
|
||||
accountAddEnd_ = 0;
|
||||
|
||||
accountDelBegin_ = 0;
|
||||
accountDelEnd_ = 0;
|
||||
|
||||
accountQueryBegin_ = 0;
|
||||
accountQueryEnd_ = 0;
|
||||
|
||||
instanceCreate_ = 0;
|
||||
serviceOnStart_ = 0;
|
||||
serviceOnStop_ = 0;
|
||||
serviceInit_ = 0;
|
||||
|
||||
accountStateChangeRecords_.clear();
|
||||
|
||||
enableStat_ = true;
|
||||
}
|
||||
|
||||
void PerfStat::Dump(std::string& result) const
|
||||
{
|
||||
if (!enableStat_) {
|
||||
ACCOUNT_LOGI("statistics disabled!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (instanceCreate_ > 0) {
|
||||
result.append("InstanceCreateTick: ").append(std::to_string(instanceCreate_)).append("\n");
|
||||
}
|
||||
|
||||
if (serviceInit_ > 0) {
|
||||
result.append("ServiceInitTick: ").append(std::to_string(serviceInit_)).append("\n");
|
||||
}
|
||||
|
||||
if (serviceOnStart_ > 0) {
|
||||
result.append("ServiceStartTick: ").append(std::to_string(serviceOnStart_)).append("\n");
|
||||
}
|
||||
|
||||
if (serviceOnStop_ > 0) {
|
||||
result.append("ServiceStopTick: ").append(std::to_string(serviceOnStop_)).append("\n");
|
||||
}
|
||||
|
||||
if (accountBindEnd_ > accountBindBegin_) {
|
||||
result.append("AccountBindTime: ")
|
||||
.append(std::to_string(accountBindEnd_ - accountBindBegin_))
|
||||
.append("\n");
|
||||
}
|
||||
|
||||
if (accountAddEnd_ > accountAddBegin_) {
|
||||
result.append("AccountAddTime: ")
|
||||
.append(std::to_string(accountAddEnd_ - accountAddBegin_))
|
||||
.append("\n");
|
||||
}
|
||||
|
||||
if (accountDelEnd_ > accountDelBegin_) {
|
||||
result.append("AccountDelTime: ")
|
||||
.append(std::to_string(accountDelEnd_ - accountDelBegin_))
|
||||
.append("\n");
|
||||
}
|
||||
|
||||
if (accountQueryEnd_ > accountQueryBegin_) {
|
||||
result.append("AccountQueryTime: ")
|
||||
.append(std::to_string((accountQueryEnd_ - accountQueryBegin_)))
|
||||
.append("\n");
|
||||
}
|
||||
|
||||
auto iter = accountStateChangeRecords_.begin();
|
||||
for (; iter != accountStateChangeRecords_.end(); iter++) {
|
||||
result.append(iter->first.c_str())
|
||||
.append(": ")
|
||||
.append(std::to_string(iter->second))
|
||||
.append(" Ticks\n");
|
||||
}
|
||||
}
|
||||
} // namespace AccountSA
|
||||
} // namespace OHOS
|
31
common/test/BUILD.gn
Executable file
31
common/test/BUILD.gn
Executable file
@ -0,0 +1,31 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//base/account/os_account/os_account.gni")
|
||||
import("//build/ohos.gni")
|
||||
|
||||
config("common_test_config") {
|
||||
defines = [
|
||||
"ACCOUNT_LOG_TAG = \"ACCOUNT_TEST\"",
|
||||
"LOG_DOMAIN = 0xD001B00",
|
||||
]
|
||||
}
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
|
||||
deps = [
|
||||
"unittest/common_account_log_test:unittest",
|
||||
"unittest/common_account_perf_test:unittest",
|
||||
]
|
||||
}
|
42
common/test/unittest/common_account_log_test/BUILD.gn
Executable file
42
common/test/unittest/common_account_log_test/BUILD.gn
Executable file
@ -0,0 +1,42 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//base/account/os_account/os_account.gni")
|
||||
import("//build/ohos.gni")
|
||||
import("//build/test.gni")
|
||||
|
||||
module_output_path = "os_account_standard/accountdfx"
|
||||
|
||||
ohos_unittest("AccountSALogTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
sources = [ "${common_path}/log/src/account_log_wrapper.cpp" ]
|
||||
|
||||
sources += [ "account_log_test.cpp" ]
|
||||
|
||||
configs = [
|
||||
"${common_path}:account_common_config",
|
||||
"${common_path}/test:common_test_config",
|
||||
]
|
||||
|
||||
deps = [ "//third_party/googletest:gtest_main" ]
|
||||
|
||||
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
|
||||
part_name = "os_account_standard"
|
||||
}
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
|
||||
deps = [ ":AccountSALogTest" ]
|
||||
}
|
97
common/test/unittest/common_account_log_test/account_log_test.cpp
Executable file
97
common/test/unittest/common_account_log_test/account_log_test.cpp
Executable file
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "account_log_wrapper.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::AccountSA;
|
||||
|
||||
class AccountLogTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
void AccountLogTest::SetUpTestCase() {}
|
||||
|
||||
void AccountLogTest::TearDownTestCase() {}
|
||||
|
||||
void AccountLogTest::SetUp() {}
|
||||
|
||||
void AccountLogTest::TearDown() {}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountLogLevel001
|
||||
* @tc.desc: Dynamically control log print level
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CUF6K
|
||||
*/
|
||||
HWTEST_F(AccountLogTest, AccountLogLevel001, TestSize.Level0)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. Get default log level
|
||||
* @tc.expected: step1. The default log level is AccountLogLevel::INFO
|
||||
*/
|
||||
EXPECT_EQ(AccountLogLevel::INFO, AccountLogWrapper::GetLogLevel());
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Set log level with DEBUG
|
||||
* @tc.expected: step2. Get log level is AccountLogLevel::DEBUG
|
||||
*/
|
||||
AccountLogWrapper::SetLogLevel(AccountLogLevel::DEBUG);
|
||||
EXPECT_EQ(AccountLogLevel::DEBUG, AccountLogWrapper::GetLogLevel());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountLogFileName002
|
||||
* @tc.desc: splice filename
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CUF6L
|
||||
*/
|
||||
HWTEST_F(AccountLogTest, AccountLogFileName002, TestSize.Level0)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. Constructor fileName and execeptStr strings
|
||||
*/
|
||||
std::string fileName = "../base/account/test.cpp";
|
||||
std::string exceptStr = "test.cpp";
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Call the GetBriefFileName method to split the string
|
||||
* @tc.expected: step2. The result string is "test.cpp"
|
||||
*/
|
||||
std::string result = AccountLogWrapper::GetBriefFileName(fileName);
|
||||
EXPECT_EQ(exceptStr, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountLogFileName003
|
||||
* @tc.desc: splice filename
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CUF6M
|
||||
*/
|
||||
HWTEST_F(AccountLogTest, AccountLogFileName003, TestSize.Level0)
|
||||
{
|
||||
std::string fileName = "test.cpp";
|
||||
std::string result = AccountLogWrapper::GetBriefFileName(fileName);
|
||||
EXPECT_EQ(fileName, result);
|
||||
fileName = "";
|
||||
result = AccountLogWrapper::GetBriefFileName(fileName);
|
||||
EXPECT_EQ(fileName, result);
|
||||
}
|
45
common/test/unittest/common_account_perf_test/BUILD.gn
Executable file
45
common/test/unittest/common_account_perf_test/BUILD.gn
Executable file
@ -0,0 +1,45 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//base/account/os_account/os_account.gni")
|
||||
import("//build/ohos.gni")
|
||||
import("//build/test.gni")
|
||||
|
||||
module_output_path = "os_account_standard/accountdfx"
|
||||
|
||||
ohos_unittest("AccountSAPerfTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
sources = [
|
||||
"${common_path}/log/src/account_log_wrapper.cpp",
|
||||
"${common_path}/perf_stat/src/perf_stat.cpp",
|
||||
]
|
||||
|
||||
sources += [ "account_perf_stat_test.cpp" ]
|
||||
|
||||
configs = [
|
||||
"${common_path}:account_common_config",
|
||||
"${common_path}/test:common_test_config",
|
||||
]
|
||||
|
||||
deps = [ "//third_party/googletest:gtest_main" ]
|
||||
|
||||
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
|
||||
part_name = "os_account_standard"
|
||||
}
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
|
||||
deps = [ ":AccountSAPerfTest" ]
|
||||
}
|
161
common/test/unittest/common_account_perf_test/account_perf_stat_test.cpp
Executable file
161
common/test/unittest/common_account_perf_test/account_perf_stat_test.cpp
Executable file
@ -0,0 +1,161 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "perf_stat.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::AccountSA;
|
||||
|
||||
namespace {
|
||||
const int64_t INVALID_TIME = -1;
|
||||
const int64_t ACCOUNT_BIND_START_TIME = 10;
|
||||
const int64_t ACCOUNT_BIND_END_TIME = 120;
|
||||
const int64_t ACCOUNT_ADD_START_TIME = 100;
|
||||
const int64_t ACCOUNT_ADD_END_TIME = 10000;
|
||||
const int64_t ACCOUNT_QUERY_START_TIME = 1220;
|
||||
const int64_t ACCOUNT_QUERY_END_TIME = 10222;
|
||||
const int64_t ACCOUNT_DEL_START_TIME = 10;
|
||||
const int64_t ACCOUNT_DEL_END_TIME = 100;
|
||||
}
|
||||
|
||||
class AccountPerfStatTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
void AccountPerfStatTest::SetUpTestCase() {}
|
||||
|
||||
void AccountPerfStatTest::TearDownTestCase() {}
|
||||
|
||||
void AccountPerfStatTest::SetUp()
|
||||
{
|
||||
/**
|
||||
* @tc.setup: reset perfStat
|
||||
*/
|
||||
PerfStat::GetInstance().Reset();
|
||||
}
|
||||
|
||||
void AccountPerfStatTest::TearDown() {}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountPerfEndGreaterBegin001
|
||||
* @tc.desc: Test bind start time and end
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CUF6O
|
||||
*/
|
||||
HWTEST_F(AccountPerfStatTest, AccountPerfEndGreaterBegin001, TestSize.Level0)
|
||||
{
|
||||
std::string result;
|
||||
/**
|
||||
* @tc.steps: step1. check valid bind start time
|
||||
*/
|
||||
PerfStat::GetInstance().SetAccountBindStartTime(ACCOUNT_BIND_START_TIME);
|
||||
int64_t bindStartTime = PerfStat::GetInstance().GetAccountBindStartTime();
|
||||
EXPECT_EQ(bindStartTime, ACCOUNT_BIND_START_TIME);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. check valid bind end time
|
||||
*/
|
||||
PerfStat::GetInstance().SetAccountBindEndTime(ACCOUNT_BIND_END_TIME);
|
||||
PerfStat::GetInstance().Dump(result);
|
||||
int64_t bindEndTime = PerfStat::GetInstance().GetAccountBindEndTime();
|
||||
EXPECT_EQ(bindEndTime, ACCOUNT_BIND_END_TIME);
|
||||
|
||||
/**
|
||||
* @tc.steps: step1. check valid add start time
|
||||
*/
|
||||
PerfStat::GetInstance().SetAccountAddStartTime(ACCOUNT_ADD_START_TIME);
|
||||
int64_t addStartTime = PerfStat::GetInstance().GetAccountAddStartTime();
|
||||
EXPECT_EQ(addStartTime, ACCOUNT_ADD_START_TIME);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. check valid add end time
|
||||
*/
|
||||
PerfStat::GetInstance().SetAccountAddEndTime(ACCOUNT_ADD_END_TIME);
|
||||
PerfStat::GetInstance().Dump(result);
|
||||
int64_t addEndTime = PerfStat::GetInstance().GetAccountAddEndTime();
|
||||
EXPECT_EQ(addEndTime, ACCOUNT_ADD_END_TIME);
|
||||
|
||||
/**
|
||||
* @tc.steps: step1. check valid add start time
|
||||
*/
|
||||
PerfStat::GetInstance().SetAccountDelStartTime(ACCOUNT_DEL_START_TIME);
|
||||
int64_t delStartTime = PerfStat::GetInstance().GetAccountDelStartTime();
|
||||
EXPECT_EQ(delStartTime, ACCOUNT_DEL_START_TIME);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. check valid add end time
|
||||
*/
|
||||
PerfStat::GetInstance().SetAccountDelEndTime(ACCOUNT_DEL_END_TIME);
|
||||
PerfStat::GetInstance().Dump(result);
|
||||
int64_t delEndTime = PerfStat::GetInstance().GetAccountDelEndTime();
|
||||
EXPECT_EQ(delEndTime, ACCOUNT_DEL_END_TIME);
|
||||
|
||||
/**
|
||||
* @tc.steps: step1. check valid add start time
|
||||
*/
|
||||
PerfStat::GetInstance().SetAccountQueryStartTime(ACCOUNT_QUERY_START_TIME);
|
||||
int64_t queryStartTime = PerfStat::GetInstance().GetAccountQueryStartTime();
|
||||
EXPECT_EQ(queryStartTime, ACCOUNT_QUERY_START_TIME);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. check valid add end time
|
||||
*/
|
||||
PerfStat::GetInstance().SetAccountQueryEndTime(ACCOUNT_QUERY_END_TIME);
|
||||
PerfStat::GetInstance().Dump(result);
|
||||
int64_t queryEndTime = PerfStat::GetInstance().GetAccountQueryEndTime();
|
||||
EXPECT_EQ(queryEndTime, ACCOUNT_QUERY_END_TIME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountPerfInvalidEndTimeTest002
|
||||
* @tc.desc: invalid end time test
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CUF6O
|
||||
*/
|
||||
HWTEST_F(AccountPerfStatTest, AccountPerfInvalidEndTimeTest002, TestSize.Level0)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. set invalid end time
|
||||
*/
|
||||
PerfStat::GetInstance().SetAccountBindStartTime(ACCOUNT_BIND_START_TIME);
|
||||
PerfStat::GetInstance().SetAccountBindEndTime(ACCOUNT_BIND_START_TIME - 1);
|
||||
int64_t bindEndTime = PerfStat::GetInstance().GetAccountBindEndTime();
|
||||
int64_t bindBeginTime = PerfStat::GetInstance().GetAccountBindStartTime();
|
||||
EXPECT_EQ(bindEndTime, bindBeginTime);
|
||||
|
||||
PerfStat::GetInstance().SetAccountAddStartTime(ACCOUNT_ADD_START_TIME);
|
||||
PerfStat::GetInstance().SetAccountAddEndTime(INVALID_TIME);
|
||||
int64_t addStartTime = PerfStat::GetInstance().GetAccountAddStartTime();
|
||||
int64_t addEndTime = PerfStat::GetInstance().GetAccountAddEndTime();
|
||||
EXPECT_EQ(addStartTime, addEndTime);
|
||||
|
||||
PerfStat::GetInstance().SetAccountQueryStartTime(ACCOUNT_QUERY_START_TIME);
|
||||
PerfStat::GetInstance().SetAccountQueryEndTime(INVALID_TIME);
|
||||
int64_t queryBeginTime = PerfStat::GetInstance().GetAccountQueryStartTime();
|
||||
int64_t queryEndTime = PerfStat::GetInstance().GetAccountQueryEndTime();
|
||||
EXPECT_EQ(queryEndTime, queryBeginTime);
|
||||
|
||||
PerfStat::GetInstance().SetAccountDelEndTime(ACCOUNT_DEL_START_TIME);
|
||||
PerfStat::GetInstance().SetAccountDelEndTime(INVALID_TIME);
|
||||
int64_t delStartTime = PerfStat::GetInstance().GetAccountDelStartTime();
|
||||
int64_t delEndTime = PerfStat::GetInstance().GetAccountDelEndTime();
|
||||
EXPECT_EQ(delEndTime, delStartTime);
|
||||
}
|
BIN
figures/en-us_image_0000001123704367.png
Executable file
BIN
figures/en-us_image_0000001123704367.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
BIN
figures/zh-cn_image_0000001123704367.png
Executable file
BIN
figures/zh-cn_image_0000001123704367.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
23
interfaces/innerkits/account_kits_headers.gni
Executable file
23
interfaces/innerkits/account_kits_headers.gni
Executable file
@ -0,0 +1,23 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
account_sdk_headers = {
|
||||
header_files = [
|
||||
"account_info.h",
|
||||
"device_account_info.h",
|
||||
"iaccount.h",
|
||||
"ohos_account_kits.h",
|
||||
]
|
||||
|
||||
header_base = "interfaces/innerkits/include"
|
||||
}
|
62
interfaces/innerkits/accountmgr/BUILD.gn
Executable file
62
interfaces/innerkits/accountmgr/BUILD.gn
Executable file
@ -0,0 +1,62 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//base/account/os_account/os_account.gni")
|
||||
import("//build/ohos.gni")
|
||||
|
||||
config("public_account_config") {
|
||||
include_dirs = [ "../include" ]
|
||||
}
|
||||
|
||||
config("accountkits_config") {
|
||||
defines = [
|
||||
"ACCOUNT_LOG_TAG = \"ACCOUNT_INNER_KITS\"",
|
||||
"LOG_DOMAIN = 0xD001B00",
|
||||
]
|
||||
include_dirs = [
|
||||
"../include",
|
||||
"${common_path}/log/include",
|
||||
"${common_path}/perf_stat/include",
|
||||
"${common_path}/account_error/include",
|
||||
"${services_path}/accountmgr/include",
|
||||
"${innerkits_path}/include",
|
||||
"//third_party/json/include",
|
||||
"//utils/native/base/include",
|
||||
"//utils/system/safwk/native/include",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_shared_library("libaccountkits") {
|
||||
sources = [
|
||||
"src/account_proxy.cpp",
|
||||
"src/ohos_account_kits.cpp",
|
||||
"src/ohos_account_kits_impl.cpp",
|
||||
]
|
||||
|
||||
configs = [ ":accountkits_config" ]
|
||||
|
||||
public_configs = [ ":public_account_config" ]
|
||||
|
||||
deps = [ "${common_path}:libaccount_common" ]
|
||||
|
||||
external_deps = [
|
||||
"aafwk_standard:base",
|
||||
"aafwk_standard:intent",
|
||||
"appexecfwk_standard:appexecfwk_base",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr_L2:samgr_proxy",
|
||||
]
|
||||
part_name = "os_account_standard"
|
||||
}
|
132
interfaces/innerkits/accountmgr/src/account_proxy.cpp
Executable file
132
interfaces/innerkits/accountmgr/src/account_proxy.cpp
Executable file
@ -0,0 +1,132 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "account_proxy.h"
|
||||
#include <ipc_types.h>
|
||||
#include <string_ex.h>
|
||||
#include "account_error_no.h"
|
||||
#include "account_log_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountSA {
|
||||
bool AccountProxy::UpdateOhosAccountInfo(const std::string& accountName, const std::string& uid,
|
||||
const std::string& eventStr)
|
||||
{
|
||||
ACCOUNT_LOGI("UpdateOhosAccountInfo enter");
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(AccountProxy::GetDescriptor())) {
|
||||
ACCOUNT_LOGE("Write descriptor failed");
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteString16(Str8ToStr16(accountName.c_str()))) {
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteString16(Str8ToStr16(uid.c_str()))) {
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteString16(Str8ToStr16(eventStr.c_str()))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
auto ret = Remote()->SendRequest(UPDATE_OHOS_ACCOUNT_INFO, data, reply, option);
|
||||
if (ret != ERR_NONE) {
|
||||
ACCOUNT_LOGE("SendRequest failed %d", ret);
|
||||
return false;
|
||||
}
|
||||
|
||||
std::int32_t result = ERR_OK;
|
||||
if (!reply.ReadInt32(result)) {
|
||||
ACCOUNT_LOGE("reply ReadInt32 failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (result != ERR_OK) {
|
||||
ACCOUNT_LOGE("UpdateOhosAccountInfo failed: %{public}d", result);
|
||||
return false;
|
||||
}
|
||||
|
||||
ACCOUNT_LOGI("UpdateOhosAccountInfo exit");
|
||||
return true;
|
||||
}
|
||||
|
||||
std::pair<bool, OhosAccountInfo> AccountProxy::QueryOhosAccountInfo(void)
|
||||
{
|
||||
ACCOUNT_LOGI("QueryOhosAccountInfo enter");
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(AccountProxy::GetDescriptor())) {
|
||||
ACCOUNT_LOGE("Write descriptor failed");
|
||||
return std::make_pair(false, OhosAccountInfo());
|
||||
}
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
auto ret = Remote()->SendRequest(QUERY_OHOS_ACCOUNT_INFO, data, reply, option);
|
||||
if (ret != ERR_NONE) {
|
||||
ACCOUNT_LOGE("SendRequest failed %d", ret);
|
||||
return std::make_pair(false, OhosAccountInfo());
|
||||
}
|
||||
|
||||
std::u16string name = reply.ReadString16();
|
||||
std::u16string uid = reply.ReadString16();
|
||||
std::int32_t status = reply.ReadInt32();
|
||||
ACCOUNT_LOGI("QueryOhosAccountInfo exit");
|
||||
return std::make_pair(true, OhosAccountInfo(Str16ToStr8(name), Str16ToStr8(uid), status));
|
||||
}
|
||||
|
||||
std::int32_t AccountProxy::QueryDeviceAccountIdFromUid(std::int32_t uid)
|
||||
{
|
||||
ACCOUNT_LOGI("QueryDeviceAccountIdFromUid enter");
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(AccountProxy::GetDescriptor())) {
|
||||
ACCOUNT_LOGE("Write descriptor failed");
|
||||
return ERR_ACCOUNT_ZIDL_WRITE_DESCRIPTOR_ERROR;
|
||||
}
|
||||
if (!data.WriteInt32(uid)) {
|
||||
return ERR_ACCOUNT_ZIDL_WRITE_PARCEL_DATA_ERROR;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
auto ret = Remote()->SendRequest(QUERY_DEVICE_ACCOUNT_ID_FROM_UID, data, reply, option);
|
||||
if (ret != ERR_NONE) {
|
||||
ACCOUNT_LOGE("SendRequest failed %d", ret);
|
||||
return ERR_ACCOUNT_ZIDL_ACCOUNT_SEND_REQUEST_ERROR;
|
||||
}
|
||||
|
||||
return reply.ReadInt32();
|
||||
}
|
||||
|
||||
std::int32_t AccountProxy::QueryDeviceAccountId(std::int32_t& accountId)
|
||||
{
|
||||
ACCOUNT_LOGI("QueryDeviceAccountId enter");
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(AccountProxy::GetDescriptor())) {
|
||||
ACCOUNT_LOGE("Write descriptor failed");
|
||||
return ERR_ACCOUNT_ZIDL_WRITE_DESCRIPTOR_ERROR;
|
||||
}
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
auto ret = Remote()->SendRequest(QUERY_DEVICE_ACCOUNT_ID, data, reply, option);
|
||||
if (ret != ERR_NONE) {
|
||||
ACCOUNT_LOGE("SendRequest failed %d", ret);
|
||||
return ERR_ACCOUNT_ZIDL_ACCOUNT_SEND_REQUEST_ERROR;
|
||||
}
|
||||
|
||||
accountId = reply.ReadInt32();
|
||||
return ERR_OK;
|
||||
}
|
||||
} // namespace AccountSA
|
||||
} // namespace OHOS
|
26
interfaces/innerkits/accountmgr/src/ohos_account_kits.cpp
Executable file
26
interfaces/innerkits/accountmgr/src/ohos_account_kits.cpp
Executable file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ohos_account_kits.h"
|
||||
#include "ohos_account_kits_impl.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountSA {
|
||||
OhosAccountKits& OhosAccountKits::GetInstance()
|
||||
{
|
||||
return DelayedRefSingleton<OhosAccountKitsImpl>::GetInstance();
|
||||
}
|
||||
} // namespace AccountSA
|
||||
} // namespace OHOS
|
148
interfaces/innerkits/accountmgr/src/ohos_account_kits_impl.cpp
Executable file
148
interfaces/innerkits/accountmgr/src/ohos_account_kits_impl.cpp
Executable file
@ -0,0 +1,148 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ohos_account_kits_impl.h"
|
||||
#include "account_error_no.h"
|
||||
#include "account_log_wrapper.h"
|
||||
#include "account_proxy.h"
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountSA {
|
||||
OhosAccountKitsImpl::OhosAccountKitsImpl() {}
|
||||
OhosAccountKitsImpl::~OhosAccountKitsImpl() {}
|
||||
|
||||
void OhosAccountKitsImpl::ResetService(const wptr<IRemoteObject>& remote)
|
||||
{
|
||||
ACCOUNT_LOGI("Remote is dead, reset service instance");
|
||||
|
||||
std::lock_guard<std::mutex> lock(accountProxyLock_);
|
||||
if (accountProxy_ != nullptr) {
|
||||
sptr<IRemoteObject> object = accountProxy_->AsObject();
|
||||
if ((object != nullptr) && (remote == object)) {
|
||||
object->RemoveDeathRecipient(deathRecipient_);
|
||||
accountProxy_ = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sptr<IAccount> OhosAccountKitsImpl::GetService()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(accountProxyLock_);
|
||||
if (accountProxy_ != nullptr) {
|
||||
return accountProxy_;
|
||||
}
|
||||
|
||||
sptr<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (samgr == nullptr) {
|
||||
ACCOUNT_LOGE("Get samgr failed");
|
||||
return nullptr;
|
||||
}
|
||||
sptr<IRemoteObject> object = samgr->GetSystemAbility(SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN);
|
||||
if (object == nullptr) {
|
||||
ACCOUNT_LOGE("Get account object from samgr failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (deathRecipient_ == nullptr) {
|
||||
deathRecipient_ = new DeathRecipient();
|
||||
}
|
||||
|
||||
if ((object->IsProxyObject()) && (!object->AddDeathRecipient(deathRecipient_))) {
|
||||
ACCOUNT_LOGE("Failed to add death recipient");
|
||||
}
|
||||
|
||||
ACCOUNT_LOGI("get remote object ok");
|
||||
accountProxy_ = iface_cast<AccountProxy>(object);
|
||||
if (accountProxy_ == nullptr) {
|
||||
ACCOUNT_LOGE("account iface_cast failed");
|
||||
}
|
||||
return accountProxy_;
|
||||
}
|
||||
|
||||
void OhosAccountKitsImpl::DeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
|
||||
{
|
||||
DelayedRefSingleton<OhosAccountKitsImpl>::GetInstance().ResetService(remote);
|
||||
}
|
||||
|
||||
template<typename F, typename... Args>
|
||||
ErrCode OhosAccountKitsImpl::CallService(F func, Args&&... args)
|
||||
{
|
||||
auto service = GetService();
|
||||
if (service == nullptr) {
|
||||
ACCOUNT_LOGE("get service failed");
|
||||
return ERR_DEAD_OBJECT;
|
||||
}
|
||||
|
||||
ErrCode result = (service->*func)(std::forward<Args>(args)...);
|
||||
if (SUCCEEDED(result)) {
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
// Reset service instance if 'ERR_DEAD_OBJECT' happened.
|
||||
if (result == ERR_DEAD_OBJECT) {
|
||||
ResetService(service);
|
||||
}
|
||||
|
||||
ACCOUNT_LOGE("Callservice failed with: %{public}d", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool OhosAccountKitsImpl::UpdateOhosAccountInfo(const std::string& accountName, const std::string& uid,
|
||||
const std::string& eventStr)
|
||||
{
|
||||
auto accountProxy = GetService();
|
||||
if (accountProxy == nullptr) {
|
||||
ACCOUNT_LOGE("Get proxy failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return accountProxy->UpdateOhosAccountInfo(accountName, uid, eventStr);
|
||||
}
|
||||
|
||||
std::pair<bool, OhosAccountInfo> OhosAccountKitsImpl::QueryOhosAccountInfo()
|
||||
{
|
||||
auto accountProxy = GetService();
|
||||
if (accountProxy == nullptr) {
|
||||
ACCOUNT_LOGE("Get proxy failed");
|
||||
return std::make_pair(false, OhosAccountInfo());
|
||||
}
|
||||
|
||||
return accountProxy->QueryOhosAccountInfo();
|
||||
}
|
||||
|
||||
ErrCode OhosAccountKitsImpl::QueryDeviceAccountId(std::int32_t& accountId)
|
||||
{
|
||||
auto ret = CallService(&IAccount::QueryDeviceAccountId, accountId);
|
||||
if (ret != ERR_OK) {
|
||||
ACCOUNT_LOGE("Query device account id failed: %{public}d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::int32_t OhosAccountKitsImpl::GetDeviceAccountIdByUID(std::int32_t& uid)
|
||||
{
|
||||
auto accountProxy = GetService();
|
||||
if (accountProxy == nullptr) {
|
||||
ACCOUNT_LOGE("Get proxy failed");
|
||||
return ERR_DEAD_OBJECT;
|
||||
}
|
||||
|
||||
return accountProxy->QueryDeviceAccountIdFromUid(uid);
|
||||
}
|
||||
} // namespace AccountSA
|
||||
} // namespace OHOS
|
124
interfaces/innerkits/include/account_info.h
Executable file
124
interfaces/innerkits/include/account_info.h
Executable file
@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef BASE_ACCOUNT_ACCOUNT_INFO_H
|
||||
#define BASE_ACCOUNT_ACCOUNT_INFO_H
|
||||
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountSA {
|
||||
/**
|
||||
* Account state type .
|
||||
*/
|
||||
typedef enum : std::int32_t {
|
||||
// invalid state
|
||||
ACCOUNT_STATE_INVALID = -1,
|
||||
// no account bound
|
||||
ACCOUNT_STATE_UNBOUND = 0,
|
||||
// account login
|
||||
ACCOUNT_STATE_LOGIN,
|
||||
// account logout but not unbound
|
||||
ACCOUNT_STATE_NOTLOGIN,
|
||||
// account logoff, all the data of this account will be deleted in the network
|
||||
ACCOUNT_STATE_LOGOFF,
|
||||
} OHOS_ACCOUNT_STATE;
|
||||
|
||||
// event string
|
||||
const std::string OHOS_ACCOUNT_EVENT_LOGIN = "Ohos.account.event.LOGIN";
|
||||
const std::string OHOS_ACCOUNT_EVENT_LOGOUT = "Ohos.account.event.LOGOUT";
|
||||
const std::string OHOS_ACCOUNT_EVENT_TOKEN_INVALID = "Ohos.account.event.TOKEN_INVALID";
|
||||
const std::string OHOS_ACCOUNT_EVENT_LOGOFF = "Ohos.account.event.LOGOFF";
|
||||
/**
|
||||
* Account operation events
|
||||
*/
|
||||
typedef enum : std::int32_t {
|
||||
ACCOUNT_INVALID_EVT = -1, // invalid account event
|
||||
ACCOUNT_BIND_SUCCESS_EVT = 0, // bind account successfully
|
||||
ACCOUNT_BIND_FAILED_EVT, // bind account failed
|
||||
ACCOUNT_AUTHENTICATE_SUCCESS_EVT, // authenticate account successfully
|
||||
ACCOUNT_AUTHENTICATE_FAILED_EVT, // authenticate account failed
|
||||
ACCOUNT_TOKEN_EXPIRED_EVT, // local token of account expired
|
||||
ACCOUNT_PASSWORD_CHANGED_EVT, // account password changed in remount server
|
||||
ACCOUNT_MANUAL_LOGOUT_EVT, // account logout manually
|
||||
ACCOUNT_MANUAL_UNBOUND_EVT, // account unbound manually
|
||||
ACCOUNT_MANUAL_LOGOFF_EVT, // account logoff manually
|
||||
} ACCOUNT_INNER_EVENT_TYPE;
|
||||
|
||||
const std::string DEFAULT_OHOS_ACCOUNT_NAME = "anonymous"; // default name
|
||||
const std::string DEFAULT_OHOS_ACCOUNT_UID = "ohosAnonymousUid"; // default UID
|
||||
|
||||
class OhosAccountInfo {
|
||||
public:
|
||||
std::string name_;
|
||||
std::string uid_;
|
||||
std::int32_t status_;
|
||||
OhosAccountInfo(const std::string &name, const std::string &id, std::int32_t status)
|
||||
: name_(name), uid_(id), status_(status)
|
||||
{
|
||||
}
|
||||
OhosAccountInfo()
|
||||
{
|
||||
status_ = ACCOUNT_STATE_UNBOUND;
|
||||
};
|
||||
~OhosAccountInfo() {};
|
||||
};
|
||||
|
||||
class AccountInfo {
|
||||
public:
|
||||
std::string ohosAccountName_;
|
||||
std::string ohosAccountUid_;
|
||||
std::int32_t ohosAccountStatus_;
|
||||
std::time_t bindTime_;
|
||||
std::int32_t userId_;
|
||||
std::string digest_;
|
||||
AccountInfo()
|
||||
{
|
||||
ohosAccountName_.clear();
|
||||
ohosAccountUid_.clear();
|
||||
digest_.clear();
|
||||
ohosAccountStatus_ = ACCOUNT_STATE_UNBOUND;
|
||||
bindTime_ = 0;
|
||||
userId_ = 0;
|
||||
}
|
||||
AccountInfo(const std::string& name, const std::string& id, const std::int32_t& status)
|
||||
: ohosAccountName_(name), ohosAccountUid_(id), ohosAccountStatus_(status)
|
||||
{
|
||||
bindTime_ = 0;
|
||||
userId_ = 0;
|
||||
}
|
||||
|
||||
bool operator==(const AccountInfo &info)
|
||||
{
|
||||
return ohosAccountUid_ == info.ohosAccountUid_;
|
||||
}
|
||||
|
||||
void clear(std::int32_t clrStatus = ACCOUNT_STATE_UNBOUND)
|
||||
{
|
||||
ohosAccountName_ = DEFAULT_OHOS_ACCOUNT_NAME;
|
||||
ohosAccountUid_ = DEFAULT_OHOS_ACCOUNT_UID;
|
||||
digest_.clear();
|
||||
ohosAccountStatus_ = clrStatus;
|
||||
bindTime_ = 0;
|
||||
userId_ = 0;
|
||||
}
|
||||
|
||||
~AccountInfo() {};
|
||||
};
|
||||
} // namespace AccountSA
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_ACCOUNT_ACCOUNT_INFO_H
|
215
interfaces/innerkits/include/device_account_info.h
Executable file
215
interfaces/innerkits/include/device_account_info.h
Executable file
@ -0,0 +1,215 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef BASE_ACCOUNT_DEVICE_ACCOUNT_INFO_H
|
||||
#define BASE_ACCOUNT_DEVICE_ACCOUNT_INFO_H
|
||||
|
||||
#include "string_ex.h"
|
||||
#include "message_parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountSA {
|
||||
/**
|
||||
* Device account type.
|
||||
*/
|
||||
enum class DeviceAccountType {
|
||||
DEVICE_ACCOUNT_TYPE_INVALID = -1, // invalid type
|
||||
DEVICE_ACCOUNT_TYPE_OWNER = 0, // device owner account
|
||||
DEVICE_ACCOUNT_TYPE_NORMAL, // device normal account
|
||||
DEVICE_ACCOUNT_TYPE_HIDDEN_SPACE, // device hidden space account
|
||||
DEVICE_ACCOUNT_TYPE_REPAIR_MODE, // device repair account
|
||||
DEVICE_ACCOUNT_TYPE_GUEST, // device guest account
|
||||
};
|
||||
|
||||
/**
|
||||
* Device account state.
|
||||
*/
|
||||
enum class DeviceAccountState {
|
||||
DEVICE_ACCOUNT_STATE_INVALID = -1, // invalid state
|
||||
DEVICE_ACCOUNT_STATE_BOOTING = 0, // device account is booting
|
||||
DEVICE_ACCOUNT_STATE_RUNNING_LOCKED, // device account is locked
|
||||
DEVICE_ACCOUNT_STATE_RUNNING_UNLOCKING, // device account is unlocking
|
||||
DEVICE_ACCOUNT_STATE_RUNNING_UNLOCKED, // device account is unlocked
|
||||
DEVICE_ACCOUNT_STATE_STOPPING, // device account is stopping
|
||||
DEVICE_ACCOUNT_STATE_SHUTDOWN, // device account is shutdown
|
||||
};
|
||||
|
||||
/**
|
||||
* Invalid device account id.
|
||||
*/
|
||||
constexpr std::int32_t DEVICE_ACCOUNT_ID_INVALID = -1;
|
||||
|
||||
/**
|
||||
* Device account owner
|
||||
*/
|
||||
constexpr std::int32_t DEVICE_ACCOUNT_OWNER = 0;
|
||||
|
||||
/**
|
||||
* no error
|
||||
*/
|
||||
constexpr std::int32_t ERROR_NONE = 0;
|
||||
|
||||
/**
|
||||
* error
|
||||
*/
|
||||
constexpr std::int32_t ERROR_HAPPEN = -1;
|
||||
|
||||
class DeviceAccountInfo {
|
||||
public:
|
||||
/**
|
||||
* Device account ID.
|
||||
*/
|
||||
std::int32_t id_;
|
||||
|
||||
/**
|
||||
* Device account type.
|
||||
*/
|
||||
DeviceAccountType type_;
|
||||
|
||||
/**
|
||||
* Device account name.
|
||||
*/
|
||||
std::string name_;
|
||||
|
||||
/**
|
||||
* Device account icon path.
|
||||
*/
|
||||
std::string iconPath_;
|
||||
|
||||
/**
|
||||
* Device account state.
|
||||
*/
|
||||
DeviceAccountState state_;
|
||||
|
||||
/**
|
||||
* Device account flags, like admin or system flag.
|
||||
*/
|
||||
std::int32_t flags_;
|
||||
|
||||
/**
|
||||
* Device account create time.
|
||||
*/
|
||||
int64_t creationTime_;
|
||||
|
||||
/**
|
||||
* Device account last logged time.
|
||||
*/
|
||||
int64_t lastLoggedInTime_;
|
||||
|
||||
/**
|
||||
* Guest device account to be removed.
|
||||
*/
|
||||
bool guestToRemoved_;
|
||||
|
||||
/**
|
||||
* Device account information class default Constructor.
|
||||
*/
|
||||
DeviceAccountInfo()
|
||||
{
|
||||
id_ = DEVICE_ACCOUNT_ID_INVALID;
|
||||
type_ = DeviceAccountType::DEVICE_ACCOUNT_TYPE_INVALID;
|
||||
name_.clear();
|
||||
iconPath_.clear();
|
||||
state_ = DeviceAccountState::DEVICE_ACCOUNT_STATE_INVALID;
|
||||
flags_ = 0;
|
||||
creationTime_ = 0;
|
||||
lastLoggedInTime_ = 0;
|
||||
guestToRemoved_ = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Device account information class Constructor.
|
||||
*/
|
||||
DeviceAccountInfo(const std::int32_t accountId, const DeviceAccountType accountType, const std::string &accountName)
|
||||
: id_(accountId), type_(accountType), name_(accountName)
|
||||
{
|
||||
iconPath_.clear();
|
||||
state_ = DeviceAccountState::DEVICE_ACCOUNT_STATE_INVALID;
|
||||
flags_ = 0;
|
||||
creationTime_ = 0;
|
||||
lastLoggedInTime_ = 0;
|
||||
guestToRemoved_ = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Device account information class Constructor.
|
||||
*/
|
||||
DeviceAccountInfo(const std::int32_t accountId, const DeviceAccountType accountType,
|
||||
const std::string &accountName, const std::string &path)
|
||||
: id_(accountId), type_(accountType), name_(accountName), iconPath_(path)
|
||||
{
|
||||
state_ = DeviceAccountState::DEVICE_ACCOUNT_STATE_INVALID;
|
||||
flags_ = 0;
|
||||
creationTime_ = 0;
|
||||
lastLoggedInTime_ = 0;
|
||||
guestToRemoved_ = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Device account information class default Destructor.
|
||||
*/
|
||||
~DeviceAccountInfo() {}
|
||||
|
||||
/**
|
||||
* == redefinition
|
||||
*
|
||||
* @return whether id is equal
|
||||
*/
|
||||
bool operator==(const DeviceAccountInfo &source)
|
||||
{
|
||||
return ((id_ == source.id_) && (id_ != DEVICE_ACCOUNT_ID_INVALID));
|
||||
}
|
||||
|
||||
/**
|
||||
* write device account info to parcel
|
||||
*
|
||||
* @return 0 when succeeded, otherwise -1
|
||||
*/
|
||||
std::int32_t WriteDataToParcel(MessageParcel &data)
|
||||
{
|
||||
if (!data.WriteInt32(id_)) {
|
||||
return ERROR_HAPPEN;
|
||||
}
|
||||
|
||||
if (!data.WriteInt32(static_cast<std::int32_t>(type_))) {
|
||||
return ERROR_HAPPEN;
|
||||
}
|
||||
|
||||
if (!data.WriteString16(Str8ToStr16(name_))) {
|
||||
return ERROR_HAPPEN;
|
||||
}
|
||||
|
||||
if (!data.WriteInt32(static_cast<std::int32_t>(state_))) {
|
||||
return ERROR_HAPPEN;
|
||||
}
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* read device account info from parcel
|
||||
*
|
||||
*/
|
||||
void ReadDataFromParcel(MessageParcel &data)
|
||||
{
|
||||
id_ = data.ReadInt32();
|
||||
type_ = static_cast<DeviceAccountType>(data.ReadInt32());
|
||||
name_ = Str16ToStr8(data.ReadString16());
|
||||
state_ = static_cast<DeviceAccountState>(data.ReadInt32());
|
||||
}
|
||||
};
|
||||
} // namespace AccountSA
|
||||
} // namespace OHOS
|
||||
#endif // BASE_ACCOUNT_DEVICE_ACCOUNT_INFO_H
|
50
interfaces/innerkits/include/iaccount.h
Executable file
50
interfaces/innerkits/include/iaccount.h
Executable file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef BASE_ACCOUNT_IACCOUNT_H
|
||||
#define BASE_ACCOUNT_IACCOUNT_H
|
||||
|
||||
#include <string>
|
||||
#include <stdint.h>
|
||||
#include <iremote_broker.h>
|
||||
#include "account_info.h"
|
||||
#include "device_account_info.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountSA {
|
||||
const std::string ACCOUNT_SERVICE_NAME = "AccountService";
|
||||
|
||||
class IAccount : public IRemoteBroker {
|
||||
public:
|
||||
enum {
|
||||
UPDATE_OHOS_ACCOUNT_INFO = 1,
|
||||
QUERY_OHOS_ACCOUNT_INFO = 2,
|
||||
QUERY_OHOS_ACCOUNT_QUIT_TIPS = 3,
|
||||
QUERY_DEVICE_ACCOUNT_ID = 104,
|
||||
QUERY_DEVICE_ACCOUNT_ID_FROM_UID = 105,
|
||||
};
|
||||
|
||||
virtual bool UpdateOhosAccountInfo(const std::string& accountName, const std::string& uid,
|
||||
const std::string& eventStr) = 0;
|
||||
virtual std::pair<bool, OhosAccountInfo> QueryOhosAccountInfo(void) = 0;
|
||||
virtual std::int32_t QueryDeviceAccountId(std::int32_t& accountId) = 0;
|
||||
virtual std::int32_t QueryDeviceAccountIdFromUid(std::int32_t uid) = 0;
|
||||
public:
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.AccountSA.IAccount");
|
||||
};
|
||||
} // namespace AccountSA
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_ACCOUNT_IACCOUNT_H
|
80
interfaces/innerkits/include/ohos_account_kits.h
Executable file
80
interfaces/innerkits/include/ohos_account_kits.h
Executable file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef BASE_ACCOUNT_OHOS_ACCOUNT_KITS_H
|
||||
#define BASE_ACCOUNT_OHOS_ACCOUNT_KITS_H
|
||||
|
||||
#include "nocopyable.h"
|
||||
#include "iaccount.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountSA {
|
||||
/**
|
||||
* Interfaces for ohos account subsystem.
|
||||
*/
|
||||
class OhosAccountKits {
|
||||
public:
|
||||
virtual ~OhosAccountKits() = default;
|
||||
DISALLOW_COPY_AND_MOVE(OhosAccountKits);
|
||||
|
||||
/**
|
||||
* Get instance of ohos account manager.
|
||||
*
|
||||
* @return Instance of ohos account manager.
|
||||
*/
|
||||
static OhosAccountKits& GetInstance();
|
||||
|
||||
/**
|
||||
* Query OHOS Account Info.
|
||||
*
|
||||
* @param VOID.
|
||||
* @return Return a pair of operation result and ohos account info.
|
||||
*/
|
||||
virtual std::pair<bool, OhosAccountInfo> QueryOhosAccountInfo() = 0;
|
||||
|
||||
/**
|
||||
* Update OHOS Account Info.
|
||||
*
|
||||
* @param accountName Indicates the name of the OS account used for a distributed system.
|
||||
* @param uid Uniquely identifies the OS account used for a distributed system.
|
||||
* @param eventStr Indicates the event of the OS account used for a distributed system.
|
||||
* @return Returns {@code true} if the distributed information of the account is updated;
|
||||
* returns {@code false} otherwise.
|
||||
*/
|
||||
virtual bool UpdateOhosAccountInfo(const std::string& accountName, const std::string& uid,
|
||||
const std::string& eventStr) = 0;
|
||||
|
||||
/**
|
||||
* Query Device Account Id.
|
||||
*
|
||||
* @param device account id.
|
||||
* @return if succeed, return ERR_OK and device account Id.
|
||||
*/
|
||||
virtual ErrCode QueryDeviceAccountId(std::int32_t& accountId) = 0;
|
||||
|
||||
/**
|
||||
* Transform uid to device account id.
|
||||
*
|
||||
* @param process calling uid.
|
||||
* @return transformed device account Id
|
||||
*/
|
||||
virtual std::int32_t GetDeviceAccountIdByUID(std::int32_t& uid) = 0;
|
||||
protected:
|
||||
OhosAccountKits() = default;
|
||||
};
|
||||
} // namespace AccountSA
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_ACCOUNT_OHOS_ACCOUNT_KITS_H
|
60
interfaces/innerkits/include/ohos_account_kits_impl.h
Executable file
60
interfaces/innerkits/include/ohos_account_kits_impl.h
Executable file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef BASE_ACCOUNT_OHOS_ACCOUNT_KITS_IMPL_H
|
||||
#define BASE_ACCOUNT_OHOS_ACCOUNT_KITS_IMPL_H
|
||||
|
||||
#include <mutex>
|
||||
#include "ipc_skeleton.h"
|
||||
#include "ohos_account_kits.h"
|
||||
#include "singleton.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountSA {
|
||||
class OhosAccountKitsImpl final : public OhosAccountKits, public DelayedRefSingleton<OhosAccountKitsImpl> {
|
||||
DECLARE_DELAYED_REF_SINGLETON(OhosAccountKitsImpl);
|
||||
|
||||
public:
|
||||
DISALLOW_COPY_AND_MOVE(OhosAccountKitsImpl);
|
||||
bool UpdateOhosAccountInfo(const std::string& accountName, const std::string& uid,
|
||||
const std::string& eventStr) final;
|
||||
std::pair<bool, OhosAccountInfo> QueryOhosAccountInfo() final;
|
||||
ErrCode QueryDeviceAccountId(std::int32_t& accountId) final;
|
||||
std::int32_t GetDeviceAccountIdByUID(std::int32_t& uid) final;
|
||||
private:
|
||||
// For death event procession
|
||||
class DeathRecipient final : public IRemoteObject::DeathRecipient {
|
||||
public:
|
||||
DeathRecipient() = default;
|
||||
~DeathRecipient() final = default;
|
||||
DISALLOW_COPY_AND_MOVE(DeathRecipient);
|
||||
|
||||
void OnRemoteDied(const wptr<IRemoteObject>& remote) final;
|
||||
};
|
||||
|
||||
template<typename F, typename... Args>
|
||||
ErrCode CallService(F func, Args&&... args);
|
||||
|
||||
void ResetService(const wptr<IRemoteObject>& remote);
|
||||
sptr<IAccount> GetService();
|
||||
|
||||
sptr<IRemoteObject::DeathRecipient> deathRecipient_{};
|
||||
std::mutex accountProxyLock_;
|
||||
sptr<IAccount> accountProxy_{};
|
||||
};
|
||||
} // namespace AccountSA
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_ACCOUNT_OHOS_ACCOUNT_KITS_IMPL_H
|
19
interfaces/innerkits/test/BUILD.gn
Executable file
19
interfaces/innerkits/test/BUILD.gn
Executable file
@ -0,0 +1,19 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//base/account/os_account/os_account.gni")
|
||||
|
||||
group("moduletest") {
|
||||
testonly = true
|
||||
deps = [ "moduletests/account_mgr_test:moduletest" ]
|
||||
}
|
76
interfaces/innerkits/test/moduletests/account_mgr_test/BUILD.gn
Executable file
76
interfaces/innerkits/test/moduletests/account_mgr_test/BUILD.gn
Executable file
@ -0,0 +1,76 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import(
|
||||
"//base/account/os_account/interfaces/innerkits/account_kits_headers.gni")
|
||||
import("//base/account/os_account/os_account.gni")
|
||||
import("//build/ohos.gni")
|
||||
import("//build/test.gni")
|
||||
|
||||
module_output_path = "os_account_standard/mstaccountmgr"
|
||||
|
||||
# mst test common config defines here
|
||||
config("accountmgr_mst_test_config") {
|
||||
include_dirs = [
|
||||
"${common_path}/log/include",
|
||||
"${common_path}/perf_stat/include",
|
||||
"${common_path}/account_error/include",
|
||||
"${services_path}/accountmgr/include",
|
||||
"//third_party/json/include",
|
||||
"${innerkits_path}/include",
|
||||
"//utils/native/base/include",
|
||||
"//utils/system/safwk/native/include",
|
||||
]
|
||||
configs = []
|
||||
}
|
||||
|
||||
ohos_moduletest("AccountInnerSdkModuleTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
sources = [
|
||||
"${common_path}/log/src/account_log_wrapper.cpp",
|
||||
"${innerkits_path}/accountmgr/src/account_proxy.cpp",
|
||||
"${innerkits_path}/accountmgr/src/ohos_account_kits.cpp",
|
||||
"${innerkits_path}/accountmgr/src/ohos_account_kits_impl.cpp",
|
||||
]
|
||||
|
||||
sources += [ "account_mgr_inner_sdk_func_test.cpp" ]
|
||||
|
||||
configs = [
|
||||
":accountmgr_mst_test_config",
|
||||
"${services_path}/accountmgr/test:accountmgr_test_config",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//third_party/googletest:gtest_main",
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"aafwk_standard:base",
|
||||
"aafwk_standard:intent",
|
||||
"appexecfwk_standard:appexecfwk_base",
|
||||
"appexecfwk_standard:libeventhandler",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"os_account_standard:libaccountkits",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr_L2:samgr_proxy",
|
||||
]
|
||||
part_name = "os_account_standard"
|
||||
}
|
||||
|
||||
group("moduletest") {
|
||||
testonly = true
|
||||
deps = [ ":AccountInnerSdkModuleTest" ]
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "account_proxy.h"
|
||||
#include "iaccount.h"
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "ohos_account_kits.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS;
|
||||
using namespace OHOS::AccountSA;
|
||||
|
||||
class AccountMgrInnerSdkFuncTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
static void TearDownTestCase(void);
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
void AccountMgrInnerSdkFuncTest::SetUpTestCase(void)
|
||||
{}
|
||||
|
||||
void AccountMgrInnerSdkFuncTest::TearDownTestCase(void)
|
||||
{}
|
||||
|
||||
void AccountMgrInnerSdkFuncTest::SetUp(void)
|
||||
{}
|
||||
|
||||
void AccountMgrInnerSdkFuncTest::TearDown(void)
|
||||
{}
|
||||
|
||||
/**
|
||||
* @tc.name: GetDeviceAccountIdTest
|
||||
* @tc.desc: get device account info test
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CUF64
|
||||
*/
|
||||
HWTEST_F(AccountMgrInnerSdkFuncTest, GetDeviceAccountIdTest, TestSize.Level0)
|
||||
{
|
||||
std::int32_t id;
|
||||
auto ret = OhosAccountKits::GetInstance().QueryDeviceAccountId(id);
|
||||
EXPECT_EQ(ERR_OK, ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetOhosAccountInfoTest
|
||||
* @tc.desc: get ohos account info test
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CUF64
|
||||
*/
|
||||
HWTEST_F(AccountMgrInnerSdkFuncTest, GetOhosAccountInfoTest, TestSize.Level0)
|
||||
{
|
||||
auto ret = OhosAccountKits::GetInstance().QueryOhosAccountInfo();
|
||||
EXPECT_EQ(true, ret.first);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetDefaultOhosAccountInfoTest
|
||||
* @tc.desc: get default ohos account info test
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DIJ27
|
||||
*/
|
||||
HWTEST_F(AccountMgrInnerSdkFuncTest, GetDefaultOhosAccountInfoTest, TestSize.Level1)
|
||||
{
|
||||
std::unique_ptr<OhosAccountInfo> accountInfo = std::make_unique<OhosAccountInfo>();
|
||||
ASSERT_TRUE(accountInfo != nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: UidTranslateTest
|
||||
* @tc.desc: translate uid to deviceAccountId
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CUF64
|
||||
*/
|
||||
HWTEST_F(AccountMgrInnerSdkFuncTest, UidTranslateTest, TestSize.Level0)
|
||||
{
|
||||
std::int32_t uid = 1000000;
|
||||
auto ret = OhosAccountKits::GetInstance().GetDeviceAccountIdByUID(uid);
|
||||
EXPECT_EQ(10, ret);
|
||||
}
|
51
kits/js/impl/napi/distributedaccount/BUILD.gn
Executable file
51
kits/js/impl/napi/distributedaccount/BUILD.gn
Executable file
@ -0,0 +1,51 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//base/account/os_account/os_account.gni")
|
||||
import("//build/ohos.gni")
|
||||
|
||||
ohos_shared_library("distributedaccount") {
|
||||
include_dirs = [
|
||||
"//third_party/libuv/include",
|
||||
"//third_party/node/src",
|
||||
"//foundation/ace/napi/interfaces/kits",
|
||||
]
|
||||
|
||||
cflags = [
|
||||
"-fPIC",
|
||||
"-g3",
|
||||
]
|
||||
|
||||
sources = [ "napi_distributed_account.cpp" ]
|
||||
|
||||
defines = [
|
||||
"ACCOUNT_LOG_TAG = \"AccountJsKit\"",
|
||||
"LOG_DOMAIN = 0xD001B00",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"${common_path}:libaccount_common",
|
||||
"//foundation/ace/napi/:ace_napi",
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
|
||||
relative_install_dir = "module/account"
|
||||
|
||||
subsystem_name = "account"
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"os_account_standard:libaccountkits",
|
||||
]
|
||||
part_name = "os_account_standard"
|
||||
}
|
280
kits/js/impl/napi/distributedaccount/napi_distributed_account.cpp
Executable file
280
kits/js/impl/napi/distributedaccount/napi_distributed_account.cpp
Executable file
@ -0,0 +1,280 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "napi_distributed_account.h"
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <unistd.h>
|
||||
#include "account_log_wrapper.h"
|
||||
#include "napi/native_api.h"
|
||||
#include "napi/native_node_api.h"
|
||||
#include "ohos_account_kits.h"
|
||||
|
||||
using namespace OHOS::AccountSA;
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountJsKit {
|
||||
namespace {
|
||||
constexpr std::int32_t MAX_VALUE_LEN = 4096;
|
||||
constexpr std::int32_t QUERY_ARGC = 1;
|
||||
constexpr std::int32_t UPDATE_ARGC = 2;
|
||||
const std::string DISTRIBUTED_ACCOUNT_CLASS_NAME = "DistributedAccountAbility";
|
||||
const std::string PROPERTY_KEY_NAME = "name";
|
||||
const std::string PROPERTY_KEY_ID = "id";
|
||||
const std::string PROPERTY_KEY_EVENT = "event";
|
||||
const std::string PROPERTY_KEY_SCALABLE = "scalableData";
|
||||
|
||||
struct DistributedAccountAsyncContext {
|
||||
napi_env env;
|
||||
napi_async_work work;
|
||||
|
||||
std::string name;
|
||||
std::string id;
|
||||
std::string event;
|
||||
std::map<std::string, std::string> scalableData;
|
||||
|
||||
napi_deferred deferred;
|
||||
napi_ref callbackRef;
|
||||
napi_status status;
|
||||
};
|
||||
|
||||
std::string GetNamedProperty(napi_env env, napi_value obj, const std::string &keyStr)
|
||||
{
|
||||
napi_value value = nullptr;
|
||||
napi_get_named_property(env, obj, keyStr.c_str(), &value);
|
||||
char propValue[MAX_VALUE_LEN] = {0};
|
||||
size_t propLen;
|
||||
napi_get_value_string_utf8(env, value, propValue, MAX_VALUE_LEN, &propLen);
|
||||
return std::string(propValue);
|
||||
}
|
||||
|
||||
void ParseAsyncContextFromArgs(napi_env env, napi_callback_info cbInfo, DistributedAccountAsyncContext *asyncContext,
|
||||
bool isUpdate)
|
||||
{
|
||||
ACCOUNT_LOGI("enter");
|
||||
size_t argc = isUpdate ? UPDATE_ARGC : QUERY_ARGC;
|
||||
napi_value argv[UPDATE_ARGC] = {0};
|
||||
napi_get_cb_info(env, cbInfo, &argc, argv, nullptr, nullptr);
|
||||
for (size_t i = 0; i < argc; i++) {
|
||||
napi_valuetype valueType = napi_undefined;
|
||||
napi_typeof(env, argv[i], &valueType);
|
||||
if (i == 0 && valueType == napi_object) {
|
||||
asyncContext->name = GetNamedProperty(env, argv[i], PROPERTY_KEY_NAME);
|
||||
asyncContext->id = GetNamedProperty(env, argv[i], PROPERTY_KEY_ID);
|
||||
asyncContext->event = GetNamedProperty(env, argv[i], PROPERTY_KEY_EVENT);
|
||||
} else if (valueType == napi_function) {
|
||||
napi_create_reference(env, argv[i], 1, &asyncContext->callbackRef);
|
||||
break;
|
||||
} else {
|
||||
ACCOUNT_LOGE("type mismatch");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessCallbackOrPromise(napi_env env, DistributedAccountAsyncContext *asyncContext, napi_value result)
|
||||
{
|
||||
napi_value args[1] = { result };
|
||||
if (asyncContext->deferred) {
|
||||
ACCOUNT_LOGI("Promise");
|
||||
if (asyncContext->status == napi_ok) {
|
||||
napi_resolve_deferred(env, asyncContext->deferred, result);
|
||||
} else {
|
||||
napi_reject_deferred(env, asyncContext->deferred, result);
|
||||
}
|
||||
} else {
|
||||
ACCOUNT_LOGI("Callback");
|
||||
napi_value callback = nullptr;
|
||||
napi_get_reference_value(env, asyncContext->callbackRef, &callback);
|
||||
napi_value returnVal = nullptr;
|
||||
napi_call_function(env, nullptr, callback, 1, args, &returnVal);
|
||||
napi_delete_reference(env, asyncContext->callbackRef);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
napi_ref NapiDistributedAccount::constructorRef_;
|
||||
|
||||
napi_value NapiDistributedAccount::Init(napi_env env, napi_value exports)
|
||||
{
|
||||
ACCOUNT_LOGI("enter");
|
||||
napi_property_descriptor descriptor[] = {
|
||||
DECLARE_NAPI_FUNCTION("getDistributedAccountAbility", GetDistributedAccountAbility),
|
||||
};
|
||||
napi_define_properties(env, exports, sizeof(descriptor) / sizeof(napi_property_descriptor), descriptor);
|
||||
|
||||
napi_property_descriptor properties[] = {
|
||||
DECLARE_NAPI_FUNCTION("queryOsAccountDistributedInfo", QueryOhosAccountInfo),
|
||||
DECLARE_NAPI_FUNCTION("updateOsAccountDistributedInfo", UpdateOsAccountDistributedInfo),
|
||||
};
|
||||
napi_value cons = nullptr;
|
||||
napi_define_class(env, DISTRIBUTED_ACCOUNT_CLASS_NAME.c_str(), DISTRIBUTED_ACCOUNT_CLASS_NAME.size(),
|
||||
JsConstructor, nullptr, sizeof(properties) / sizeof(napi_property_descriptor), properties, &cons);
|
||||
napi_create_reference(env, cons, 1, &constructorRef_);
|
||||
napi_set_named_property(env, exports, DISTRIBUTED_ACCOUNT_CLASS_NAME.c_str(), cons);
|
||||
|
||||
return exports;
|
||||
}
|
||||
|
||||
napi_value NapiDistributedAccount::JsConstructor(napi_env env, napi_callback_info cbinfo)
|
||||
{
|
||||
napi_value thisVar = nullptr;
|
||||
napi_get_cb_info(env, cbinfo, nullptr, nullptr, &thisVar, nullptr);
|
||||
return thisVar;
|
||||
}
|
||||
|
||||
napi_value NapiDistributedAccount::GetDistributedAccountAbility(napi_env env, napi_callback_info cbInfo)
|
||||
{
|
||||
ACCOUNT_LOGI("enter");
|
||||
napi_value instance = nullptr;
|
||||
napi_value cons = nullptr;
|
||||
if (napi_get_reference_value(env, constructorRef_, &cons) != napi_ok) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (napi_new_instance(env, cons, 0, nullptr, &instance) != napi_ok) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
napi_value NapiDistributedAccount::QueryOhosAccountInfo(napi_env env, napi_callback_info cbInfo)
|
||||
{
|
||||
ACCOUNT_LOGI("enter");
|
||||
auto *asyncContext = new DistributedAccountAsyncContext();
|
||||
asyncContext->env = env;
|
||||
asyncContext->callbackRef = nullptr;
|
||||
ParseAsyncContextFromArgs(env, cbInfo, asyncContext, false);
|
||||
|
||||
napi_value result = nullptr;
|
||||
if (asyncContext->callbackRef == nullptr) {
|
||||
napi_create_promise(env, &asyncContext->deferred, &result);
|
||||
} else {
|
||||
napi_get_undefined(env, &result);
|
||||
}
|
||||
|
||||
napi_value resource = nullptr;
|
||||
napi_create_string_utf8(env, "QueryOhosAccountInfo", NAPI_AUTO_LENGTH, &resource);
|
||||
|
||||
napi_create_async_work(
|
||||
env, nullptr, resource,
|
||||
[](napi_env env, void *data) {
|
||||
DistributedAccountAsyncContext *asyncContext = (DistributedAccountAsyncContext*)data;
|
||||
std::pair<bool, OhosAccountInfo> accountInfo = OhosAccountKits::GetInstance().QueryOhosAccountInfo();
|
||||
if (accountInfo.first) {
|
||||
asyncContext->name = accountInfo.second.name_;
|
||||
asyncContext->id = accountInfo.second.uid_;
|
||||
asyncContext->status = napi_ok;
|
||||
} else {
|
||||
asyncContext->status = napi_generic_failure;
|
||||
}
|
||||
},
|
||||
[](napi_env env, napi_status status, void *data) {
|
||||
DistributedAccountAsyncContext *asyncContext = (DistributedAccountAsyncContext*)data;
|
||||
napi_value queryResult = nullptr;
|
||||
if (asyncContext->status == napi_ok) {
|
||||
napi_create_object(env, &queryResult);
|
||||
napi_value value = nullptr;
|
||||
napi_create_string_utf8(env, asyncContext->name.c_str(), asyncContext->name.size(), &value);
|
||||
napi_set_named_property(env, queryResult, PROPERTY_KEY_NAME.c_str(), value);
|
||||
|
||||
napi_create_string_utf8(env, asyncContext->id.c_str(), asyncContext->id.size(), &value);
|
||||
napi_set_named_property(env, queryResult, PROPERTY_KEY_ID.c_str(), value);
|
||||
} else {
|
||||
napi_value message = nullptr;
|
||||
napi_create_string_utf8(env, "query ohos account info failed", NAPI_AUTO_LENGTH, &message);
|
||||
napi_create_error(env, nullptr, message, &queryResult);
|
||||
}
|
||||
|
||||
ProcessCallbackOrPromise(env, asyncContext, queryResult);
|
||||
napi_delete_async_work(env, asyncContext->work);
|
||||
delete asyncContext;
|
||||
},
|
||||
(void*)asyncContext, &asyncContext->work);
|
||||
napi_queue_async_work(env, asyncContext->work);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value NapiDistributedAccount::UpdateOsAccountDistributedInfo(napi_env env, napi_callback_info cbInfo)
|
||||
{
|
||||
ACCOUNT_LOGI("enter");
|
||||
auto *asyncContext = new DistributedAccountAsyncContext();
|
||||
asyncContext->env = env;
|
||||
asyncContext->callbackRef = nullptr;
|
||||
ParseAsyncContextFromArgs(env, cbInfo, asyncContext, true);
|
||||
|
||||
napi_value result = nullptr;
|
||||
if (asyncContext->callbackRef == nullptr) {
|
||||
napi_create_promise(env, &asyncContext->deferred, &result);
|
||||
} else {
|
||||
napi_get_undefined(env, &result);
|
||||
}
|
||||
|
||||
napi_value resource = nullptr;
|
||||
napi_create_string_utf8(env, "UpdateOsAccountDistributedInfo", NAPI_AUTO_LENGTH, &resource);
|
||||
|
||||
napi_create_async_work(
|
||||
env, nullptr, resource,
|
||||
[](napi_env env, void *data) {
|
||||
DistributedAccountAsyncContext *asyncContext = (DistributedAccountAsyncContext*)data;
|
||||
asyncContext->status = OhosAccountKits::GetInstance().UpdateOhosAccountInfo(asyncContext->name,
|
||||
asyncContext->id, asyncContext->event) ? napi_ok : napi_generic_failure;
|
||||
},
|
||||
[](napi_env env, napi_status status, void *data) {
|
||||
DistributedAccountAsyncContext *asyncContext = (DistributedAccountAsyncContext*)data;
|
||||
napi_value updateResult = nullptr;
|
||||
napi_get_boolean(env, asyncContext->status == napi_ok, &updateResult);
|
||||
ProcessCallbackOrPromise(env, asyncContext, updateResult);
|
||||
napi_delete_async_work(env, asyncContext->work);
|
||||
delete asyncContext;
|
||||
},
|
||||
(void*)asyncContext, &asyncContext->work);
|
||||
napi_queue_async_work(env, asyncContext->work);
|
||||
|
||||
return result;
|
||||
}
|
||||
} // namespace AccountJsKit
|
||||
} // namespace OHOS
|
||||
|
||||
EXTERN_C_START
|
||||
/*
|
||||
* function for module exports
|
||||
*/
|
||||
static napi_value Init(napi_env env, napi_value exports)
|
||||
{
|
||||
return OHOS::AccountJsKit::NapiDistributedAccount::Init(env, exports);
|
||||
}
|
||||
EXTERN_C_END
|
||||
|
||||
/*
|
||||
* module define
|
||||
*/
|
||||
static napi_module _module = {
|
||||
.nm_version = 1,
|
||||
.nm_flags = 0,
|
||||
.nm_filename = nullptr,
|
||||
.nm_register_func = Init,
|
||||
.nm_modname = "account.distributedAccount",
|
||||
.nm_priv = ((void*)0),
|
||||
.reserved = {0}
|
||||
};
|
||||
/*
|
||||
* module register
|
||||
*/
|
||||
extern "C" __attribute__((constructor)) void Register()
|
||||
{
|
||||
napi_module_register(&_module);
|
||||
}
|
38
kits/js/impl/napi/distributedaccount/napi_distributed_account.h
Executable file
38
kits/js/impl/napi/distributedaccount/napi_distributed_account.h
Executable file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef NAPI_DISTRIBUTED_ACCOUNT_H
|
||||
#define NAPI_DISTRIBUTED_ACCOUNT_H
|
||||
|
||||
#include "napi/native_api.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountJsKit {
|
||||
class NapiDistributedAccount {
|
||||
public:
|
||||
static napi_value Init(napi_env env, napi_value exports);
|
||||
|
||||
private:
|
||||
static napi_value GetDistributedAccountAbility(napi_env env, napi_callback_info cbInfo);
|
||||
static napi_value QueryOhosAccountInfo(napi_env env, napi_callback_info cbInfo);
|
||||
static napi_value UpdateOsAccountDistributedInfo(napi_env env, napi_callback_info cbInfo);
|
||||
static napi_value JsConstructor(napi_env env, napi_callback_info cbinfo);
|
||||
|
||||
static napi_ref constructorRef_;
|
||||
};
|
||||
} // namespace AccountJsKit
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // NAPI_DISTRIBUTED_ACCOUNT_H
|
32
ohos.build
Executable file
32
ohos.build
Executable file
@ -0,0 +1,32 @@
|
||||
{
|
||||
"subsystem": "account",
|
||||
"parts": {
|
||||
"os_account_standard": {
|
||||
"module_list": [
|
||||
"//base/account/os_account/common:common_target",
|
||||
"//base/account/os_account/services:services_target",
|
||||
"//base/account/os_account/sa_profile:account_sa_profile",
|
||||
"//base/account/os_account/kits/js/impl/napi/distributedaccount:distributedaccount"
|
||||
],
|
||||
"inner_kits": [
|
||||
{
|
||||
"name": "//base/account/os_account/interfaces/innerkits/accountmgr:libaccountkits",
|
||||
"header": {
|
||||
"header_files": [
|
||||
"account_info.h",
|
||||
"device_account_info.h",
|
||||
"iaccount.h",
|
||||
"ohos_account_kits.h"
|
||||
],
|
||||
"header_base": "//base/account/os_account/interfaces/innerkits/include"
|
||||
}
|
||||
}
|
||||
],
|
||||
"test_list": [
|
||||
"//base/account/os_account/common/test:unittest",
|
||||
"//base/account/os_account/services/accountmgr/test:unittest",
|
||||
"//base/account/os_account/interfaces/innerkits/test:moduletest"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
20
os_account.gni
Executable file
20
os_account.gni
Executable file
@ -0,0 +1,20 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
os_account_path = "//base/account/os_account"
|
||||
|
||||
common_path = "${os_account_path}/common"
|
||||
|
||||
services_path = "${os_account_path}/services"
|
||||
|
||||
innerkits_path = "${os_account_path}/interfaces/innerkits"
|
24
sa_profile/200.xml
Executable file
24
sa_profile/200.xml
Executable file
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<info>
|
||||
<process>accountmgr</process>
|
||||
<systemability> <!-- Declare a system ability and its profile -->
|
||||
<name>200</name> <!-- Declare the name of system ability -->
|
||||
<libpath>libaccountmgr.z.so</libpath>
|
||||
<run-on-create>true</run-on-create>
|
||||
<distributed>false</distributed>
|
||||
<dump-level>1</dump-level> <!-- Declare the dump level. 1-high; 2-media; 3-low -->
|
||||
</systemability>
|
||||
</info>
|
19
sa_profile/BUILD.gn
Executable file
19
sa_profile/BUILD.gn
Executable file
@ -0,0 +1,19 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos/sa_profile/sa_profile.gni")
|
||||
|
||||
ohos_sa_profile("account_sa_profile") {
|
||||
sources = [ "200.xml" ]
|
||||
part_name = "os_account_standard"
|
||||
}
|
16
services/BUILD.gn
Executable file
16
services/BUILD.gn
Executable file
@ -0,0 +1,16 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
group("services_target") {
|
||||
deps = [ "accountmgr:accountmgr_target" ]
|
||||
}
|
82
services/accountmgr/BUILD.gn
Executable file
82
services/accountmgr/BUILD.gn
Executable file
@ -0,0 +1,82 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//base/account/os_account/os_account.gni")
|
||||
import("//build/ohos.gni")
|
||||
|
||||
ohos_prebuilt_etc("accountmgr.rc") {
|
||||
source = "accountmgr.rc"
|
||||
relative_install_dir = "init"
|
||||
part_name = "os_account_standard"
|
||||
}
|
||||
|
||||
config("accountmgr_config") {
|
||||
include_dirs = [
|
||||
"./include",
|
||||
"${common_path}/log/include",
|
||||
"${common_path}/perf_stat/include",
|
||||
"${common_path}/account_error/include",
|
||||
"${innerkits_path}/include",
|
||||
"//third_party/json/include",
|
||||
"//utils/native/base/include",
|
||||
"//utils/system/safwk/native/include",
|
||||
]
|
||||
}
|
||||
|
||||
group("accountmgr_target") {
|
||||
deps = [
|
||||
":accountmgr",
|
||||
":accountmgr.rc",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_shared_library("accountmgr") {
|
||||
visibility = [ "${os_account_path}/*" ]
|
||||
|
||||
sources = [
|
||||
"src/account_dump_helper.cpp",
|
||||
"src/account_helper_data.cpp",
|
||||
"src/account_mgr_service.cpp",
|
||||
"src/account_state_machine.cpp",
|
||||
"src/account_stub.cpp",
|
||||
"src/ohos_account_data_deal.cpp",
|
||||
"src/ohos_account_manager.cpp",
|
||||
]
|
||||
|
||||
defines = [
|
||||
"ACCOUNT_LOG_TAG = \"AccountMgrService\"",
|
||||
"LOG_DOMAIN = 0xD001B00",
|
||||
]
|
||||
|
||||
configs = [ ":accountmgr_config" ]
|
||||
|
||||
deps = [
|
||||
"${common_path}:libaccount_common",
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"aafwk_standard:base",
|
||||
"aafwk_standard:intent",
|
||||
"aafwk_standard:want",
|
||||
"appexecfwk_standard:appexecfwk_base",
|
||||
"appexecfwk_standard:appexecfwk_core",
|
||||
"hisysevent_native:libhisysevent",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr_L2:samgr_proxy",
|
||||
"startup_l2:syspara",
|
||||
]
|
||||
part_name = "os_account_standard"
|
||||
}
|
22
services/accountmgr/accountmgr.rc
Executable file
22
services/accountmgr/accountmgr.rc
Executable file
@ -0,0 +1,22 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
on post-fs-data
|
||||
start accountmgr
|
||||
|
||||
service accountmgr /system/bin/sa_main /system/profile/accountmgr.xml
|
||||
class z_core
|
||||
user system
|
||||
group system shell
|
||||
seclabel u:r:accountmgr:s0
|
||||
writepid /dev/cpuset/foreground/tasks /dev/stune/foreground/tasks /dev/blkio/foreground/tasks
|
45
services/accountmgr/include/account_dump_helper.h
Executable file
45
services/accountmgr/include/account_dump_helper.h
Executable file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef BASE_ACCOUNT_SERVICES_INCLUDE_DUMP_HELPER_H
|
||||
#define BASE_ACCOUNT_SERVICES_INCLUDE_DUMP_HELPER_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "ohos_account_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountSA {
|
||||
class AccountMgrService;
|
||||
|
||||
class AccountDumpHelper {
|
||||
public:
|
||||
explicit AccountDumpHelper(const std::shared_ptr<OhosAccountManager>& accountMgr);
|
||||
~AccountDumpHelper() = default;
|
||||
bool Dump(const std::vector<std::string>& args, std::string& result) const;
|
||||
|
||||
private:
|
||||
void ShowIllegalInformation(std::string& result) const;
|
||||
void ShowHelp(std::string& result) const;
|
||||
bool ProcessOneParameter(const std::string& arg, std::string& result) const;
|
||||
bool ProcessTwoParameter(const std::string& arg1, const std::string& arg2, std::string& result) const;
|
||||
std::weak_ptr<OhosAccountManager> accountMgr_;
|
||||
void ShowAccountInfo(std::string &result) const;
|
||||
bool SimulateInputEvent(const std::string &eventStr, std::string &result) const;
|
||||
bool SetLogLevel(const std::string& levelStr, std::string& result) const;
|
||||
};
|
||||
} // namespace AccountSA
|
||||
} // namespace OHOS
|
||||
#endif // BASE_ACCOUNT_SERVICES_INCLUDE_DUMP_HELPER_H
|
29
services/accountmgr/include/account_helper_data.h
Executable file
29
services/accountmgr/include/account_helper_data.h
Executable file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ACCOUNT_HELPER_DATA_H
|
||||
#define ACCOUNT_HELPER_DATA_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountSA {
|
||||
class AccountHelperData {
|
||||
public:
|
||||
static std::vector<std::string> GetBundleNameTrustList();
|
||||
};
|
||||
} // namespace AccountSA
|
||||
} // namespace OHOS
|
||||
#endif // ACCOUNT_HELPER_DATA_H
|
72
services/accountmgr/include/account_mgr_service.h
Executable file
72
services/accountmgr/include/account_mgr_service.h
Executable file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef BASE_ACCOUNT_INCLUDE_ACCOUNT_SERVICE_H
|
||||
#define BASE_ACCOUNT_INCLUDE_ACCOUNT_SERVICE_H
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include "account_dump_helper.h"
|
||||
#include "account_info.h"
|
||||
#include "account_stub.h"
|
||||
#include "iaccount.h"
|
||||
#include "iremote_object.h"
|
||||
#include "ohos_account_manager.h"
|
||||
#include "singleton.h"
|
||||
#include "system_ability.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountSA {
|
||||
enum ServiceRunningState {
|
||||
STATE_NOT_START,
|
||||
STATE_RUNNING
|
||||
};
|
||||
|
||||
class AccountMgrService : public SystemAbility, public AccountStub,
|
||||
public OHOS::DelayedRefSingleton<AccountMgrService> {
|
||||
public:
|
||||
AccountMgrService();
|
||||
~AccountMgrService();
|
||||
DISALLOW_COPY_AND_MOVE(AccountMgrService);
|
||||
DECLARE_SYSTEM_ABILITY(AccountMgrService);
|
||||
bool UpdateOhosAccountInfo(const std::string& accountName, const std::string& uid,
|
||||
const std::string& eventStr) override;
|
||||
std::pair<bool, OhosAccountInfo> QueryOhosAccountInfo(void) override;
|
||||
std::int32_t QueryDeviceAccountId(std::int32_t& accountId) override;
|
||||
std::int32_t QueryDeviceAccountIdFromUid(std::int32_t uid) override;
|
||||
virtual void OnStart() override;
|
||||
virtual void OnStop() override;
|
||||
bool IsServiceStarted(void) const override;
|
||||
static AccountMgrService& GetInstance()
|
||||
{
|
||||
return DelayedRefSingleton<AccountMgrService>::GetInstance();
|
||||
}
|
||||
int Dump(std::int32_t fd, const std::vector<std::u16string>& args) override;
|
||||
void HandleNotificationEvents(const std::string &eventStr) override;
|
||||
|
||||
private:
|
||||
bool Init();
|
||||
void SelfClean();
|
||||
std::int32_t GetDeviceAccountIdFromCurrentProcess();
|
||||
|
||||
bool registerToService_ = false;
|
||||
ServiceRunningState state_ = ServiceRunningState::STATE_NOT_START;
|
||||
std::unique_ptr<AccountDumpHelper> dumpHelper_{};
|
||||
std::shared_ptr<OhosAccountManager> ohosAccountMgr_{};
|
||||
};
|
||||
} // namespace AccountSA
|
||||
} // namespace OHOS
|
||||
#endif // BASE_ACCOUNT_INCLUDE_ACCOUNT_SERVICE_H
|
44
services/accountmgr/include/account_proxy.h
Executable file
44
services/accountmgr/include/account_proxy.h
Executable file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ACCOUNT_PROXY_H
|
||||
#define ACCOUNT_PROXY_H
|
||||
|
||||
#include "iaccount.h"
|
||||
#include "account_info.h"
|
||||
#include <iremote_proxy.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountSA {
|
||||
class AccountProxy : public IRemoteProxy<IAccount> {
|
||||
public:
|
||||
explicit AccountProxy(const sptr<IRemoteObject>& impl)
|
||||
: IRemoteProxy<IAccount>(impl) {
|
||||
}
|
||||
~AccountProxy() { }
|
||||
bool UpdateOhosAccountInfo(const std::string& accountName, const std::string& uid,
|
||||
const std::string& eventStr) override;
|
||||
std::pair<bool, OhosAccountInfo> QueryOhosAccountInfo(void) override;
|
||||
std::int32_t QueryDeviceAccountId(std::int32_t& accountId) override;
|
||||
std::int32_t QueryDeviceAccountIdFromUid(std::int32_t uid) override;
|
||||
|
||||
private:
|
||||
std::int32_t DeviceAccountRequest(std::uint32_t code, std::int32_t accountId);
|
||||
static inline BrokerDelegator<AccountProxy> delegator_;
|
||||
};
|
||||
} // namespace AccountSA
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // ACCOUNT_PROXY_H
|
57
services/accountmgr/include/account_state_action.h
Executable file
57
services/accountmgr/include/account_state_action.h
Executable file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef BASE_ACCOUNT_INCLUDE_ACCOUNT_STATE_ACTION_H
|
||||
#define BASE_ACCOUNT_INCLUDE_ACCOUNT_STATE_ACTION_H
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountSA {
|
||||
/**
|
||||
* Base class of state change process.
|
||||
*/
|
||||
class AccountStateAction {
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param nextStateId the unique State ID. It should be a non-negative number.
|
||||
*/
|
||||
explicit AccountStateAction(const int nextStateId) : nextState_(nextStateId) {}
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*
|
||||
*/
|
||||
virtual ~AccountStateAction() {}
|
||||
|
||||
/**
|
||||
* Get the next State ID.
|
||||
*
|
||||
* @return the next State ID
|
||||
*/
|
||||
int GetNextState() const
|
||||
{
|
||||
return nextState_;
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
* the next State ID
|
||||
*/
|
||||
int nextState_;
|
||||
};
|
||||
} // namespace AccountSA
|
||||
} // namespace OHOS
|
||||
#endif // BASE_ACCOUNT_INCLUDE_ACCOUNT_STATE_ACTION_H
|
175
services/accountmgr/include/account_state_machine.h
Executable file
175
services/accountmgr/include/account_state_machine.h
Executable file
@ -0,0 +1,175 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef BASE_ACCOUNT_INCLUDE_ACCOUNT_STATE_MACHINE_H
|
||||
#define BASE_ACCOUNT_INCLUDE_ACCOUNT_STATE_MACHINE_H
|
||||
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include "account_state_action.h"
|
||||
#include "account_info.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountSA {
|
||||
/**
|
||||
* Account state machine
|
||||
*/
|
||||
class AccountStateMachine {
|
||||
public:
|
||||
|
||||
/**
|
||||
* exception event action, to re-init state machine, and get account state from account server.
|
||||
*/
|
||||
class ExceptionAction : public AccountStateAction {
|
||||
public:
|
||||
/**
|
||||
* exception event action Constructor.
|
||||
*/
|
||||
explicit ExceptionAction(int status) : AccountStateAction(status) {}
|
||||
|
||||
/**
|
||||
* exception event action Destructor.
|
||||
*/
|
||||
~ExceptionAction() {}
|
||||
};
|
||||
|
||||
/**
|
||||
* unbound state action.
|
||||
*/
|
||||
class UnboundAction : public AccountStateAction {
|
||||
public:
|
||||
/**
|
||||
* unbound state action Constructor.
|
||||
*/
|
||||
explicit UnboundAction(int status) : AccountStateAction(status) {}
|
||||
|
||||
/**
|
||||
* unbound state action Destructor.
|
||||
*/
|
||||
~UnboundAction() {}
|
||||
};
|
||||
|
||||
/**
|
||||
* login state action.
|
||||
*/
|
||||
class LoginAction : public AccountStateAction {
|
||||
public:
|
||||
/**
|
||||
* login state action Constructor.
|
||||
*/
|
||||
explicit LoginAction(int status) : AccountStateAction(status) {}
|
||||
|
||||
/**
|
||||
* login state action Destructor.
|
||||
*/
|
||||
~LoginAction() {}
|
||||
};
|
||||
|
||||
/**
|
||||
* logout state action.
|
||||
*/
|
||||
class LogoutAction : public AccountStateAction {
|
||||
public:
|
||||
/**
|
||||
* logout state action Constructor.
|
||||
*/
|
||||
explicit LogoutAction(int status) : AccountStateAction(status) {}
|
||||
|
||||
/**
|
||||
* logout state action Destructor.
|
||||
*/
|
||||
~LogoutAction() {}
|
||||
};
|
||||
|
||||
/**
|
||||
* logoff state action.
|
||||
*/
|
||||
class LogoffAction : public AccountStateAction {
|
||||
public:
|
||||
/**
|
||||
* logoff state action Constructor.
|
||||
*/
|
||||
explicit LogoffAction(int status) : AccountStateAction(status) {}
|
||||
|
||||
/**
|
||||
* logoff state action Destructor.
|
||||
*/
|
||||
~LogoffAction() {}
|
||||
};
|
||||
|
||||
/**
|
||||
* Account state machine Constructor.
|
||||
*/
|
||||
AccountStateMachine() : currentState_(ACCOUNT_STATE_UNBOUND)
|
||||
{
|
||||
OnInitialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Account state machine Destructor.
|
||||
*/
|
||||
~AccountStateMachine()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Account state machine initialize.
|
||||
*/
|
||||
void OnInitialize();
|
||||
|
||||
/**
|
||||
* Account state machine clean.
|
||||
*/
|
||||
void Clean();
|
||||
|
||||
/**
|
||||
* Get account current state
|
||||
*
|
||||
* @return account current state
|
||||
*/
|
||||
int GetAccountState()
|
||||
{
|
||||
return currentState_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set account current state
|
||||
*
|
||||
* @param current state
|
||||
*/
|
||||
void SetAccountState(int currentState)
|
||||
{
|
||||
currentState_ = currentState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process an state change event.
|
||||
*
|
||||
* @param evt the event info
|
||||
* @return true if the processing was completed, otherwise false
|
||||
*/
|
||||
bool StateChangeProcess(int evt);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Account current state.
|
||||
*/
|
||||
int currentState_;
|
||||
std::map<int, std::map<int, AccountStateAction *>> stateMachineMap_;
|
||||
};
|
||||
} // namespace AccountSA
|
||||
} // namespace OHOS
|
||||
#endif // BASE_ACCOUNT_INCLUDE_ACCOUNT_STATE_MACHINE_H
|
52
services/accountmgr/include/account_stub.h
Executable file
52
services/accountmgr/include/account_stub.h
Executable file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ACCOUNT_STUB_H
|
||||
#define ACCOUNT_STUB_H
|
||||
|
||||
#include "iaccount.h"
|
||||
#include "iaccount_context.h"
|
||||
#include <iremote_broker.h>
|
||||
#include <iremote_object.h>
|
||||
#include <iremote_stub.h>
|
||||
#include <map>
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountSA {
|
||||
class AccountStub;
|
||||
using AccountStubFunc = std::int32_t (AccountStub::*)(MessageParcel &data, MessageParcel &reply);
|
||||
class AccountStub : public IRemoteStub<IAccount>, public IAccountContext {
|
||||
public:
|
||||
virtual std::int32_t OnRemoteRequest(std::uint32_t code,
|
||||
MessageParcel &data,
|
||||
MessageParcel &reply,
|
||||
MessageOption &option) override;
|
||||
private:
|
||||
std::int32_t CmdUpdateOhosAccountInfo(MessageParcel &data, MessageParcel &reply);
|
||||
std::int32_t CmdQueryOhosAccountInfo(MessageParcel &data, MessageParcel &reply);
|
||||
std::int32_t CmdQueryOhosQuitTips(MessageParcel &data, MessageParcel &reply);
|
||||
std::int32_t CmdQueryDeviceAccountId(MessageParcel &data, MessageParcel &reply);
|
||||
std::int32_t CmdQueryDeviceAccountIdFromUid(MessageParcel &data, MessageParcel &reply);
|
||||
bool HasAccountRequestPermission(const std::string &permissionName);
|
||||
bool IsRootOrSystemAccount();
|
||||
bool CheckCallerForTrustList();
|
||||
|
||||
private:
|
||||
static const std::map<std::uint32_t, AccountStubFunc> stubFuncMap_;
|
||||
};
|
||||
} // namespace AccountSA
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // ACCOUNT_STUB_H
|
45
services/accountmgr/include/iaccount_context.h
Executable file
45
services/accountmgr/include/iaccount_context.h
Executable file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef BASE_ACCOUNT_CONTEXT_H
|
||||
#define BASE_ACCOUNT_CONTEXT_H
|
||||
|
||||
#include "message_parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountSA {
|
||||
class IAccountContext {
|
||||
public:
|
||||
static IAccountContext *GetInstance()
|
||||
{
|
||||
return IAccountContext::instance_;
|
||||
}
|
||||
|
||||
virtual ~IAccountContext() = default;
|
||||
virtual void HandleNotificationEvents(const std::string &eventStr) = 0;
|
||||
virtual bool IsServiceStarted(void) const = 0;
|
||||
|
||||
protected:
|
||||
static void SetInstance(IAccountContext *instance)
|
||||
{
|
||||
IAccountContext::instance_ = instance;
|
||||
}
|
||||
|
||||
private:
|
||||
static IAccountContext *instance_;
|
||||
};
|
||||
} // namespace AccountSA
|
||||
} // namespace OHOS
|
||||
#endif // BASE_ACCOUNT_CONTEXT_H
|
52
services/accountmgr/include/ohos_account_data_deal.h
Executable file
52
services/accountmgr/include/ohos_account_data_deal.h
Executable file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef BASE_ACCOUNT_INCLUDE_OHOS_ACCOUNT_DATA_DEAL_H
|
||||
#define BASE_ACCOUNT_INCLUDE_OHOS_ACCOUNT_DATA_DEAL_H
|
||||
|
||||
#include <string>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include "account_info.h"
|
||||
#include "account_error_no.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountSA {
|
||||
using json = nlohmann::json;
|
||||
|
||||
const std::string DATADEAL_JSON_KEY_ACCOUNT_NAME = "account_name";
|
||||
const std::string DATADEAL_JSON_KEY_OPENID = "openId";
|
||||
const std::string DATADEAL_JSON_KEY_UID = "uid";
|
||||
const std::string DATADEAL_JSON_KEY_BIND_TIME = "bind_time";
|
||||
const std::string DATADEAL_JSON_KEY_STATUS = "bind_status";
|
||||
|
||||
class OhosAccountDataDeal {
|
||||
public:
|
||||
explicit OhosAccountDataDeal(const std::string &configFile);
|
||||
ErrCode Init();
|
||||
ErrCode AccountInfoFromJson(AccountInfo &accountInfo);
|
||||
ErrCode AccountInfoToJson(AccountInfo &accountInfo);
|
||||
~OhosAccountDataDeal() {};
|
||||
|
||||
private:
|
||||
json jsonData_;
|
||||
bool initOk_;
|
||||
std::string configFile_;
|
||||
void BuildJsonFileFromScratch();
|
||||
void CreateDefaultAccountInfo(AccountInfo &accountInfo);
|
||||
void SaveAccountInfo(AccountInfo &accountInfo);
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // BASE_ACCOUNT_INCLUDE_OHOS_ACCOUNT_DATA_DEAL_H
|
187
services/accountmgr/include/ohos_account_manager.h
Executable file
187
services/accountmgr/include/ohos_account_manager.h
Executable file
@ -0,0 +1,187 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ACCOUNT_OHOSACCOUNTMANAGER_H
|
||||
#define ACCOUNT_OHOSACCOUNTMANAGER_H
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include "account_state_machine.h"
|
||||
#include "account_info.h"
|
||||
#include "ohos_account_data_deal.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountSA {
|
||||
const std::string ACCOUNT_CFG_DIR_ROOT_PATH = "/data/system/users/";
|
||||
const std::string ACCOUNT_CFG_FILE_NAME = "/account.json";
|
||||
class OhosAccountManager;
|
||||
using OhosAccountEventFunc = bool (OhosAccountManager::*)(const std::string &name, const std::string &uid,
|
||||
const std::string &eventStr);
|
||||
/**
|
||||
* Ohos account manager
|
||||
*/
|
||||
class OhosAccountManager {
|
||||
public:
|
||||
/**
|
||||
* Get current account information.
|
||||
*
|
||||
* @return current account information.
|
||||
*/
|
||||
AccountInfo GetAccountInfo();
|
||||
|
||||
/**
|
||||
* Get current account state.
|
||||
*
|
||||
* @return current account state id.
|
||||
*/
|
||||
int GetAccountState() const;
|
||||
|
||||
/**
|
||||
* Init ohos account manager.
|
||||
*
|
||||
*/
|
||||
bool OnInitialize();
|
||||
|
||||
/**
|
||||
* Process an account event.
|
||||
*
|
||||
* @param eventStr ohos account state change event
|
||||
* @return true if the processing was completed, otherwise false
|
||||
*/
|
||||
bool HandleEvent(const std::string &eventStr);
|
||||
|
||||
/**
|
||||
* login ohos (for distributed network) account.
|
||||
*
|
||||
* @param name ohos account name
|
||||
* @param uid ohos account uid
|
||||
* @param eventStr ohos account state change event
|
||||
* @return true if the processing was completed, otherwise false
|
||||
*/
|
||||
bool LoginOhosAccount(const std::string &name, const std::string &uid, const std::string &eventStr);
|
||||
|
||||
/**
|
||||
* logout ohos (for distributed network) account.
|
||||
*
|
||||
* @param name ohos account name
|
||||
* @param uid ohos account uid
|
||||
* @param eventStr ohos account state change event
|
||||
* @return true if the processing was completed, otherwise false
|
||||
*/
|
||||
bool LogoutOhosAccount(const std::string &name, const std::string &uid, const std::string &eventStr);
|
||||
|
||||
/**
|
||||
* logoff ohos (for distributed network) account.
|
||||
*
|
||||
* @param name ohos account name
|
||||
* @param uid ohos account uid
|
||||
* @param eventStr ohos account state change event
|
||||
* @return true if the processing was completed, otherwise false
|
||||
*/
|
||||
bool LogoffOhosAccount(const std::string &name, const std::string &uid, const std::string &eventStr);
|
||||
|
||||
/**
|
||||
* Handle token_invalid event of ohos (for distributed network) account .
|
||||
*
|
||||
* @param name ohos account name
|
||||
* @param uid ohos account uid
|
||||
* @param eventStr ohos account state change event
|
||||
* @return true if the processing was completed, otherwise false
|
||||
*/
|
||||
bool HandleOhosAccountTokenInvalidEvent(const std::string &name,
|
||||
const std::string &uid, const std::string &eventStr);
|
||||
|
||||
/**
|
||||
* Handle device account switch event.
|
||||
*
|
||||
* @param None
|
||||
* @return None
|
||||
*/
|
||||
void HandleDevAccountSwitchEvent();
|
||||
|
||||
/**
|
||||
* Ohos account state change.
|
||||
*
|
||||
* @param name ohos account name
|
||||
* @param uid ohos account uid
|
||||
* @param eventStr ohos account state change event
|
||||
* @return true if the processing was completed, otherwise false
|
||||
*/
|
||||
bool OhosAccountStateChange(const std::string &name, const std::string &uid, const std::string &eventStr);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Get Current user Id.
|
||||
*/
|
||||
std::int32_t GetUserId();
|
||||
|
||||
/**
|
||||
* Account state machine.
|
||||
*/
|
||||
std::unique_ptr<AccountStateMachine> accountState_{};
|
||||
|
||||
/**
|
||||
* Current account.
|
||||
*/
|
||||
AccountInfo currentAccount_;
|
||||
|
||||
/**
|
||||
* Deal with file storage.
|
||||
*/
|
||||
std::unique_ptr<OhosAccountDataDeal> dataDealer_{};
|
||||
|
||||
/**
|
||||
* event mapper.
|
||||
*/
|
||||
std::map<std::string, ACCOUNT_INNER_EVENT_TYPE> eventMap_;
|
||||
|
||||
/**
|
||||
* mutex lock for synchronization.
|
||||
*/
|
||||
std::mutex mgrMutex_;
|
||||
|
||||
/**
|
||||
* build event mapper.
|
||||
*/
|
||||
void BuildEventsMapper();
|
||||
|
||||
/**
|
||||
* Records dfx event of ohos account status
|
||||
*/
|
||||
void ReportPublishFailureEvent(std::int32_t errCode, std::int32_t oldStatus);
|
||||
|
||||
/**
|
||||
* Config current account config.
|
||||
*
|
||||
* @param account account information.
|
||||
* @return true if success.
|
||||
*/
|
||||
bool SetAccount(AccountInfo &account);
|
||||
|
||||
/**
|
||||
* Clear current account config.
|
||||
* @param clrStatus account status.
|
||||
*/
|
||||
bool ClearAccount(std::int32_t clrStatus = ACCOUNT_STATE_UNBOUND);
|
||||
|
||||
/**
|
||||
* event function map
|
||||
*/
|
||||
std::map<std::string, OhosAccountEventFunc> eventFuncMap_;
|
||||
};
|
||||
} // namespace AccountSA
|
||||
} // namespace OHOS
|
||||
#endif // ACCOUNT_OHOSACCOUNTMANAGER_H
|
192
services/accountmgr/src/account_dump_helper.cpp
Executable file
192
services/accountmgr/src/account_dump_helper.cpp
Executable file
@ -0,0 +1,192 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "account_dump_helper.h"
|
||||
#include <regex>
|
||||
#include <string>
|
||||
#include "account_error_no.h"
|
||||
#include "account_info.h"
|
||||
#include "account_log_wrapper.h"
|
||||
#include "ohos_account_manager.h"
|
||||
#include "perf_stat.h"
|
||||
#include "string_ex.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountSA {
|
||||
namespace {
|
||||
const std::int32_t ARGS_SIZE_ONE = 1;
|
||||
const std::int32_t ARGS_SIZE_TWO = 2;
|
||||
const std::int32_t FIRST_PARAMETER = 0;
|
||||
const std::int32_t SECOND_PARAMETER = 1;
|
||||
const std::string ARGS_HELP = "-h";
|
||||
const std::string ARGS_ACCOUNT_INFO = "-account_info";
|
||||
const std::string ARGS_INPUT_SIMULATE = "-input_simulate";
|
||||
const std::string ARGS_OUTPUT_SIMULATE = "-output_simulate";
|
||||
const std::string ARGS_SHOW_LOG_LEVEL = "-show_log_level";
|
||||
const std::string ARGS_SET_LOG_LEVEL = "-set_log_level";
|
||||
const std::string ARGS_DUMP_PERF_STAT = "-perf_dump";
|
||||
const std::string ILLEGAL_INFORMATION = "Ohos Account Manager service, enter '-h' for usage.\n";
|
||||
const std::string SYSTEM_ERROR = "system error\n";
|
||||
const std::string NO_INFORMATION = "no such information\n";
|
||||
} // namespace
|
||||
|
||||
AccountDumpHelper::AccountDumpHelper(const std::shared_ptr<OhosAccountManager>& accountMgr)
|
||||
{
|
||||
accountMgr_ = accountMgr;
|
||||
}
|
||||
|
||||
bool AccountDumpHelper::Dump(const std::vector<std::string>& args, std::string& result) const
|
||||
{
|
||||
result.clear();
|
||||
bool retRes = false;
|
||||
auto argsSize = args.size();
|
||||
if (argsSize == ARGS_SIZE_ONE) {
|
||||
retRes = ProcessOneParameter(args[FIRST_PARAMETER], result);
|
||||
} else if (argsSize == ARGS_SIZE_TWO) {
|
||||
retRes = ProcessTwoParameter(args[FIRST_PARAMETER], args[SECOND_PARAMETER], result);
|
||||
} else {
|
||||
ShowIllegalInformation(result);
|
||||
}
|
||||
|
||||
return retRes;
|
||||
}
|
||||
|
||||
void AccountDumpHelper::ShowHelp(std::string& result) const
|
||||
{
|
||||
result.append("Usage:dump <command> [options]\n")
|
||||
.append("Description:\n")
|
||||
.append("-account_info ")
|
||||
.append("dump all account information in the system\n")
|
||||
.append("-input_simulate <event> ")
|
||||
.append("simulate event from ohos account, supported events: login/logout/token_invalid\n")
|
||||
.append("-output_simulate <event> ")
|
||||
.append("simulate event output\n")
|
||||
.append("-show_log_level ")
|
||||
.append("show account SA's log level\n")
|
||||
.append("-set_log_level <level> ")
|
||||
.append("set account SA's log level\n")
|
||||
.append("-perf_dump ")
|
||||
.append("dump performance statistics\n");
|
||||
}
|
||||
|
||||
void AccountDumpHelper::ShowIllegalInformation(std::string& result) const
|
||||
{
|
||||
result.append(ILLEGAL_INFORMATION);
|
||||
}
|
||||
|
||||
void AccountDumpHelper::ShowAccountInfo(std::string& result) const
|
||||
{
|
||||
auto lockPtr = accountMgr_.lock();
|
||||
if (lockPtr == nullptr) {
|
||||
ACCOUNT_LOGE("Invalid lockPtr");
|
||||
return;
|
||||
}
|
||||
|
||||
AccountInfo accountInfo = lockPtr->GetAccountInfo();
|
||||
result.append("Ohos account name: ");
|
||||
result.append(accountInfo.ohosAccountName_.c_str());
|
||||
result.append(", Ohos account uid: ");
|
||||
result.append(accountInfo.ohosAccountUid_.c_str());
|
||||
result.append(", Local user Id: ");
|
||||
result.append(std::to_string(accountInfo.userId_));
|
||||
result.append(", Ohos account status: ");
|
||||
result.append(std::to_string(accountInfo.ohosAccountStatus_));
|
||||
result.append(", Ohos account bind time: " + std::to_string(accountInfo.bindTime_));
|
||||
result.append("\n");
|
||||
}
|
||||
|
||||
bool AccountDumpHelper::ProcessOneParameter(const std::string& arg, std::string& result) const
|
||||
{
|
||||
if (accountMgr_.expired()) {
|
||||
result.append("Internal error!\n");
|
||||
return false;
|
||||
}
|
||||
bool retRes = true;
|
||||
if (arg == ARGS_HELP) {
|
||||
ShowHelp(result);
|
||||
} else if (arg == ARGS_ACCOUNT_INFO) {
|
||||
ShowAccountInfo(result);
|
||||
} else if (arg == ARGS_SHOW_LOG_LEVEL) {
|
||||
auto logLevel = static_cast<std::int32_t>(AccountLogWrapper::GetLogLevel());
|
||||
result.append("Current Log Level: " + std::to_string(logLevel) + "\n");
|
||||
} else if (arg == ARGS_DUMP_PERF_STAT) {
|
||||
PerfStat::GetInstance().Dump(result);
|
||||
} else {
|
||||
ShowHelp(result);
|
||||
retRes = false;
|
||||
}
|
||||
|
||||
return retRes;
|
||||
}
|
||||
|
||||
bool AccountDumpHelper::SimulateInputEvent(const std::string& eventStr, std::string& result) const
|
||||
{
|
||||
auto lockPtr = accountMgr_.lock();
|
||||
if (lockPtr == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool retRes = lockPtr->HandleEvent(eventStr);
|
||||
if (retRes) {
|
||||
result.append("process event success");
|
||||
} else {
|
||||
result.append("process event failed");
|
||||
}
|
||||
|
||||
return retRes;
|
||||
}
|
||||
|
||||
bool AccountDumpHelper::SetLogLevel(const std::string& levelStr, std::string& result) const
|
||||
{
|
||||
if (!regex_match(levelStr, std::regex("^\\d+$"))) {
|
||||
ACCOUNT_LOGE("Invalid format of log level");
|
||||
result.append("Invalid format of log level\n");
|
||||
return false;
|
||||
}
|
||||
auto level = std::stoi(levelStr);
|
||||
if ((level < static_cast<std::int32_t>(AccountLogLevel::DEBUG)) ||
|
||||
(level > static_cast<std::int32_t>(AccountLogLevel::FATAL))) {
|
||||
result.append("Invalid logLevel\n");
|
||||
} else {
|
||||
AccountLogLevel logLevel = static_cast<AccountLogLevel>(level);
|
||||
AccountLogWrapper::SetLogLevel(logLevel);
|
||||
result.append("Set logLevel success\n");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AccountDumpHelper::ProcessTwoParameter(const std::string& arg1, const std::string& arg2, std::string& result) const
|
||||
{
|
||||
if (accountMgr_.expired()) {
|
||||
result.append("Internal error!\n");
|
||||
return false;
|
||||
}
|
||||
bool retRes = false;
|
||||
if (arg1 == ARGS_INPUT_SIMULATE) {
|
||||
retRes = SimulateInputEvent(arg2, result);
|
||||
if (retRes) {
|
||||
result.append("handle input simulate event ok\n");
|
||||
}
|
||||
} else if (arg1 == ARGS_SET_LOG_LEVEL) {
|
||||
retRes = SetLogLevel(arg2, result);
|
||||
} else {
|
||||
ShowHelp(result);
|
||||
}
|
||||
|
||||
return retRes;
|
||||
}
|
||||
} // namespace AccountSA
|
||||
} // namespace OHOS
|
61
services/accountmgr/src/account_helper_data.cpp
Executable file
61
services/accountmgr/src/account_helper_data.cpp
Executable file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "account_helper_data.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <vector>
|
||||
#include "account_log_wrapper.h"
|
||||
#include "file_ex.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountSA {
|
||||
using json = nlohmann::json;
|
||||
namespace {
|
||||
const std::string ACCOUNTMGR_HELPER_JSON_FILE = "/system/etc/account/accountmgr_helper.json";
|
||||
const std::string KEY_BUNDLE_NAME_LIST = "BundleNameTrustList";
|
||||
}
|
||||
|
||||
std::vector<std::string> AccountHelperData::GetBundleNameTrustList()
|
||||
{
|
||||
std::vector<std::string> result = {""};
|
||||
if (!FileExists(ACCOUNTMGR_HELPER_JSON_FILE)) {
|
||||
ACCOUNT_LOGI("file %{public}s not exist, empty default!", ACCOUNTMGR_HELPER_JSON_FILE.c_str());
|
||||
return result;
|
||||
}
|
||||
|
||||
std::ifstream fin(ACCOUNTMGR_HELPER_JSON_FILE);
|
||||
if (!fin) {
|
||||
ACCOUNT_LOGE("Failed to open file %{public}s", ACCOUNTMGR_HELPER_JSON_FILE.c_str());
|
||||
return result;
|
||||
}
|
||||
|
||||
nlohmann::json jsonData = json::parse(fin, nullptr, false);
|
||||
if (!jsonData.is_structured()) {
|
||||
ACCOUNT_LOGE("not valid json file!");
|
||||
fin.close();
|
||||
return result;
|
||||
}
|
||||
fin.close();
|
||||
|
||||
if (jsonData.find(KEY_BUNDLE_NAME_LIST) != jsonData.end() && jsonData.at(KEY_BUNDLE_NAME_LIST).is_array()) {
|
||||
result = jsonData.at(KEY_BUNDLE_NAME_LIST).get<std::vector<std::string>>();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
} // namespace AccountSA
|
||||
} // namespace OHOS
|
204
services/accountmgr/src/account_mgr_service.cpp
Executable file
204
services/accountmgr/src/account_mgr_service.cpp
Executable file
@ -0,0 +1,204 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "account_mgr_service.h"
|
||||
#include "account_dump_helper.h"
|
||||
#include "account_log_wrapper.h"
|
||||
#include "datetime_ex.h"
|
||||
#include "device_account_info.h"
|
||||
#include "directory_ex.h"
|
||||
#include "file_ex.h"
|
||||
#include "hisysevent.h"
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "perf_stat.h"
|
||||
#include "string_ex.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountSA {
|
||||
const std::string DEVICE_OWNER_DIR = "/data/system/users/0/";
|
||||
|
||||
constexpr std::int32_t UID_TRANSFORM_DIVISOR = 100000;
|
||||
IAccountContext *IAccountContext::instance_ = nullptr;
|
||||
|
||||
const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(
|
||||
&DelayedRefSingleton<AccountMgrService>::GetInstance());
|
||||
|
||||
AccountMgrService::AccountMgrService() : SystemAbility(SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN, true)
|
||||
{
|
||||
PerfStat::GetInstance().SetInstanceCreateTime(GetTickCount());
|
||||
}
|
||||
|
||||
AccountMgrService::~AccountMgrService()
|
||||
{
|
||||
}
|
||||
|
||||
bool AccountMgrService::UpdateOhosAccountInfo(const std::string& accountName, const std::string& uid,
|
||||
const std::string& eventStr)
|
||||
{
|
||||
ACCOUNT_LOGI("Account event %s", eventStr.c_str());
|
||||
if (!ohosAccountMgr_->OhosAccountStateChange(accountName, uid, eventStr)) {
|
||||
ACCOUNT_LOGE("Ohos account state change failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
ACCOUNT_LOGI("Successful");
|
||||
return true;
|
||||
}
|
||||
|
||||
std::pair<bool, OhosAccountInfo> AccountMgrService::QueryOhosAccountInfo(void)
|
||||
{
|
||||
AccountInfo accountInfo = ohosAccountMgr_->GetAccountInfo();
|
||||
if (accountInfo.ohosAccountUid_.empty()) {
|
||||
ACCOUNT_LOGE("invalid id");
|
||||
accountInfo.clear();
|
||||
}
|
||||
std::string name = accountInfo.ohosAccountName_;
|
||||
std::string id = accountInfo.ohosAccountUid_;
|
||||
std::int32_t status = accountInfo.ohosAccountStatus_;
|
||||
return std::make_pair(true, OhosAccountInfo(name, id, status));
|
||||
}
|
||||
|
||||
std::int32_t AccountMgrService::QueryDeviceAccountIdFromUid(std::int32_t uid)
|
||||
{
|
||||
return uid / UID_TRANSFORM_DIVISOR;
|
||||
}
|
||||
|
||||
std::int32_t AccountMgrService::QueryDeviceAccountId(std::int32_t& accountId)
|
||||
{
|
||||
accountId = DEVICE_ACCOUNT_OWNER;
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
bool AccountMgrService::IsServiceStarted(void) const
|
||||
{
|
||||
return (state_ == STATE_RUNNING);
|
||||
}
|
||||
|
||||
void AccountMgrService::OnStart()
|
||||
{
|
||||
if (state_ == ServiceRunningState::STATE_RUNNING) {
|
||||
ACCOUNT_LOGI("AccountMgrService has already started.");
|
||||
return;
|
||||
}
|
||||
|
||||
PerfStat::GetInstance().SetInstanceStartTime(GetTickCount());
|
||||
ACCOUNT_LOGI("start is triggered");
|
||||
if (!Init()) {
|
||||
ACCOUNT_LOGE("failed to init AccountMgrService");
|
||||
return;
|
||||
}
|
||||
state_ = ServiceRunningState::STATE_RUNNING;
|
||||
ACCOUNT_LOGI("AccountMgrService::OnStart start service success.");
|
||||
}
|
||||
|
||||
void AccountMgrService::OnStop()
|
||||
{
|
||||
PerfStat::GetInstance().SetInstanceStopTime(GetTickCount());
|
||||
ACCOUNT_LOGI("onstop is called");
|
||||
IAccountContext::SetInstance(nullptr);
|
||||
SelfClean();
|
||||
}
|
||||
|
||||
bool AccountMgrService::Init()
|
||||
{
|
||||
if (state_ == ServiceRunningState::STATE_RUNNING) {
|
||||
ACCOUNT_LOGW("Service is already running!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!OHOS::FileExists(DEVICE_OWNER_DIR)) {
|
||||
ACCOUNT_LOGI("Device owner dir not exist, create!");
|
||||
if (!OHOS::ForceCreateDirectory(DEVICE_OWNER_DIR)) {
|
||||
ACCOUNT_LOGW("Create device owner dir failure!");
|
||||
}
|
||||
}
|
||||
|
||||
bool ret = false;
|
||||
if (!registerToService_) {
|
||||
ret = Publish(&DelayedRefSingleton<AccountMgrService>::GetInstance());
|
||||
if (!ret) {
|
||||
HiviewDFX::HiSysEvent::Write(HiviewDFX::HiSysEvent::Domain::ACCOUNT, "AccountServiceStartFailed",
|
||||
HiviewDFX::HiSysEvent::EventType::FAULT, "ERROR_TYPE", ERR_ACCOUNT_MGR_ADD_TO_SA_ERROR);
|
||||
ACCOUNT_LOGE("AccountMgrService::Init Publish failed!");
|
||||
return false;
|
||||
}
|
||||
registerToService_ = true;
|
||||
}
|
||||
|
||||
PerfStat::GetInstance().SetInstanceInitTime(GetTickCount());
|
||||
|
||||
ohosAccountMgr_ = std::make_shared<OhosAccountManager>();
|
||||
ret = ohosAccountMgr_->OnInitialize();
|
||||
if (!ret) {
|
||||
ACCOUNT_LOGE("Ohos account manager initialize failed");
|
||||
HiviewDFX::HiSysEvent::Write(HiviewDFX::HiSysEvent::Domain::ACCOUNT, "AccountServiceStartFailed",
|
||||
HiviewDFX::HiSysEvent::EventType::FAULT, "ERROR_TYPE", ret);
|
||||
return ret;
|
||||
}
|
||||
dumpHelper_ = std::make_unique<AccountDumpHelper>(ohosAccountMgr_);
|
||||
IAccountContext::SetInstance(this);
|
||||
ACCOUNT_LOGI("init end success");
|
||||
return true;
|
||||
}
|
||||
|
||||
int AccountMgrService::Dump(std::int32_t fd, const std::vector<std::u16string>& args)
|
||||
{
|
||||
if (fd < 0) {
|
||||
ACCOUNT_LOGE("dump fd invalid");
|
||||
return ERR_ACCOUNT_MGR_DUMP_ERROR;
|
||||
}
|
||||
|
||||
std::vector<std::string> argsInStr;
|
||||
for (const auto& arg : args) {
|
||||
ACCOUNT_LOGI("Dump args: %s", Str16ToStr8(arg).c_str());
|
||||
argsInStr.emplace_back(Str16ToStr8(arg));
|
||||
}
|
||||
|
||||
std::string result;
|
||||
if (dumpHelper_ && dumpHelper_->Dump(argsInStr, result)) {
|
||||
ACCOUNT_LOGI("%s", result.c_str());
|
||||
std::int32_t ret = dprintf(fd, "%s", result.c_str());
|
||||
if (ret < 0) {
|
||||
ACCOUNT_LOGE("dprintf to dump fd failed");
|
||||
return ERR_ACCOUNT_MGR_DUMP_ERROR;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ACCOUNT_LOGW("dumpHelper failed");
|
||||
return ERR_ACCOUNT_MGR_DUMP_ERROR;
|
||||
}
|
||||
|
||||
void AccountMgrService::SelfClean()
|
||||
{
|
||||
state_ = ServiceRunningState::STATE_NOT_START;
|
||||
registerToService_ = false;
|
||||
ACCOUNT_LOGI("selfclean finished");
|
||||
}
|
||||
|
||||
void AccountMgrService::HandleNotificationEvents(const std::string &eventStr)
|
||||
{
|
||||
if (state_ == ServiceRunningState::STATE_NOT_START) {
|
||||
ACCOUNT_LOGW("service not running for handling event: %{public}s", eventStr.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
ACCOUNT_LOGI("Unhandled event: %{public}s", eventStr.c_str());
|
||||
}
|
||||
} // namespace AccountSA
|
||||
} // namespace OHOS
|
179
services/accountmgr/src/account_state_machine.cpp
Executable file
179
services/accountmgr/src/account_state_machine.cpp
Executable file
@ -0,0 +1,179 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "account_state_machine.h"
|
||||
#include "account_info.h"
|
||||
#include "account_log_wrapper.h"
|
||||
#include "datetime_ex.h"
|
||||
#include "perf_stat.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountSA {
|
||||
/**
|
||||
* Account state machine initialize.
|
||||
*/
|
||||
void AccountStateMachine::OnInitialize()
|
||||
{
|
||||
stateMachineMap_ = {
|
||||
// ACCOUNT_STATE_UNBOUND state
|
||||
std::make_pair(ACCOUNT_STATE_UNBOUND, std::map<int, AccountStateAction *> {
|
||||
// normal event, transform to login state
|
||||
std::make_pair(ACCOUNT_BIND_SUCCESS_EVT, new LoginAction(ACCOUNT_STATE_LOGIN)),
|
||||
// normal event, keep in unbound state
|
||||
std::make_pair(ACCOUNT_BIND_FAILED_EVT, new ExceptionAction(ACCOUNT_STATE_UNBOUND)),
|
||||
// unexpected event, re-initial state machine, check the state from account server
|
||||
std::make_pair(ACCOUNT_AUTHENTICATE_SUCCESS_EVT, new LoginAction(ACCOUNT_STATE_LOGIN)),
|
||||
// unexpected event, re-initial state machine, check the state from account server
|
||||
std::make_pair(ACCOUNT_AUTHENTICATE_FAILED_EVT, nullptr),
|
||||
// unexpected event, re-initial state machine, check the state from account server
|
||||
std::make_pair(ACCOUNT_TOKEN_EXPIRED_EVT, nullptr),
|
||||
// unexpected event, re-initial state machine, check the state from account server
|
||||
std::make_pair(ACCOUNT_PASSWORD_CHANGED_EVT, nullptr),
|
||||
// unexpected event, re-initial state machine, check the state from account server
|
||||
std::make_pair(ACCOUNT_MANUAL_LOGOUT_EVT, nullptr),
|
||||
// unexpected event, keep in unbound state
|
||||
std::make_pair(ACCOUNT_MANUAL_UNBOUND_EVT, nullptr),
|
||||
// unexpected event, keep in unbound state
|
||||
std::make_pair(ACCOUNT_MANUAL_LOGOFF_EVT, nullptr)}
|
||||
),
|
||||
// ACCOUNT_STATE_LOGIN state
|
||||
std::make_pair(ACCOUNT_STATE_LOGIN, std::map<int, AccountStateAction *> {
|
||||
// expected event, keep in login state
|
||||
std::make_pair(ACCOUNT_BIND_SUCCESS_EVT, nullptr),
|
||||
// unexpected event, re-initial state machine, check the state from account server
|
||||
std::make_pair(ACCOUNT_BIND_FAILED_EVT, new ExceptionAction(ACCOUNT_STATE_LOGIN)),
|
||||
// normal event, keep in login state
|
||||
std::make_pair(ACCOUNT_AUTHENTICATE_SUCCESS_EVT, nullptr),
|
||||
// normal event, transform to logout state
|
||||
std::make_pair(ACCOUNT_AUTHENTICATE_FAILED_EVT, nullptr),
|
||||
// expected event, transform to logout state
|
||||
std::make_pair(ACCOUNT_TOKEN_EXPIRED_EVT, new LogoutAction(ACCOUNT_STATE_NOTLOGIN)),
|
||||
// expected event, transform to logout state
|
||||
std::make_pair(ACCOUNT_PASSWORD_CHANGED_EVT, new LogoutAction(ACCOUNT_STATE_NOTLOGIN)),
|
||||
// expected event, transform to logout state
|
||||
std::make_pair(ACCOUNT_MANUAL_LOGOUT_EVT, new LogoutAction(ACCOUNT_STATE_NOTLOGIN)),
|
||||
// expected event, transform to unbound state
|
||||
std::make_pair(ACCOUNT_MANUAL_UNBOUND_EVT, new UnboundAction(ACCOUNT_STATE_UNBOUND)),
|
||||
// expected event, transform to logoff state
|
||||
std::make_pair(ACCOUNT_MANUAL_LOGOFF_EVT, new LogoffAction(ACCOUNT_STATE_LOGOFF))}
|
||||
),
|
||||
// ACCOUNT_STATE_NOTLOGIN state
|
||||
std::make_pair(ACCOUNT_STATE_NOTLOGIN, std::map<int, AccountStateAction *> {
|
||||
// normal event, transform to login state
|
||||
std::make_pair(ACCOUNT_BIND_SUCCESS_EVT, new LoginAction(ACCOUNT_STATE_LOGIN)),
|
||||
// unexpected event, re-initial state machine, check the state from account server
|
||||
std::make_pair(ACCOUNT_BIND_FAILED_EVT, new ExceptionAction(ACCOUNT_STATE_NOTLOGIN)),
|
||||
// expected event, transform to login state
|
||||
std::make_pair(ACCOUNT_AUTHENTICATE_SUCCESS_EVT, new LoginAction(ACCOUNT_STATE_LOGIN)),
|
||||
// expected event, keep in logout state
|
||||
std::make_pair(ACCOUNT_AUTHENTICATE_FAILED_EVT, nullptr),
|
||||
// unexpected event, re-initial state machine, check the state from account server
|
||||
std::make_pair(ACCOUNT_TOKEN_EXPIRED_EVT, nullptr),
|
||||
// unexpected event, re-initial state machine, check the state from account server
|
||||
std::make_pair(ACCOUNT_PASSWORD_CHANGED_EVT, nullptr),
|
||||
// unexpected event, re-initial state machine, check the state from account server
|
||||
std::make_pair(ACCOUNT_MANUAL_LOGOUT_EVT, nullptr),
|
||||
// expected event, transform to unbound state
|
||||
std::make_pair(ACCOUNT_MANUAL_UNBOUND_EVT, new UnboundAction(ACCOUNT_STATE_UNBOUND)),
|
||||
// expected event, transform to logoff state
|
||||
std::make_pair(ACCOUNT_MANUAL_LOGOFF_EVT, new LogoffAction(ACCOUNT_STATE_LOGOFF))}
|
||||
),
|
||||
// ACCOUNT_STATE_LOGOFF state
|
||||
std::make_pair(ACCOUNT_STATE_LOGOFF, std::map<int, AccountStateAction *> {
|
||||
// normal event, transform to login state
|
||||
std::make_pair(ACCOUNT_BIND_SUCCESS_EVT, new LoginAction(ACCOUNT_STATE_LOGIN)),
|
||||
// unexpected event, re-initial state machine, check the state from account server
|
||||
std::make_pair(ACCOUNT_BIND_FAILED_EVT, new ExceptionAction(ACCOUNT_STATE_LOGOFF)),
|
||||
// expected event, transform to login state
|
||||
std::make_pair(ACCOUNT_AUTHENTICATE_SUCCESS_EVT, nullptr),
|
||||
// expected event, keep in logoff state
|
||||
std::make_pair(ACCOUNT_AUTHENTICATE_FAILED_EVT, nullptr),
|
||||
// unexpected event, re-initial state machine, check the state from account server
|
||||
std::make_pair(ACCOUNT_TOKEN_EXPIRED_EVT, nullptr),
|
||||
// unexpected event, re-initial state machine, check the state from account server
|
||||
std::make_pair(ACCOUNT_PASSWORD_CHANGED_EVT, nullptr),
|
||||
// unexpected event, re-initial state machine, check the state from account server
|
||||
std::make_pair(ACCOUNT_MANUAL_LOGOUT_EVT, nullptr),
|
||||
// expected event, transform to logoff state
|
||||
std::make_pair(ACCOUNT_MANUAL_UNBOUND_EVT, nullptr),
|
||||
// expected event, transform to logoff state
|
||||
std::make_pair(ACCOUNT_MANUAL_LOGOFF_EVT, nullptr)}
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Account state machine clean.
|
||||
*/
|
||||
void AccountStateMachine::Clean()
|
||||
{
|
||||
for (auto ¤tStateIter : stateMachineMap_) {
|
||||
for (auto &eventIter : currentStateIter.second) {
|
||||
if (eventIter.second != nullptr) {
|
||||
delete eventIter.second;
|
||||
eventIter.second = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a state change event
|
||||
*
|
||||
* @param evt the event info
|
||||
* @return true if the processing was completed, otherwise false
|
||||
*/
|
||||
bool AccountStateMachine::StateChangeProcess(int evt)
|
||||
{
|
||||
// for performance record
|
||||
std::string stateRecordStr;
|
||||
int64_t processTicks = GetTickCount();
|
||||
stateRecordStr.append("state from[").append(std::to_string(currentState_)).append("] to [");
|
||||
|
||||
// get all the current state event action
|
||||
auto stateIter = stateMachineMap_.find(currentState_);
|
||||
if (stateIter == stateMachineMap_.end()) {
|
||||
ACCOUNT_LOGE("current state %d is not in state machine map.", currentState_);
|
||||
return false;
|
||||
}
|
||||
|
||||
// get the current event action
|
||||
auto eventIter = stateIter->second.find(evt);
|
||||
if (eventIter == stateIter->second.end()) {
|
||||
ACCOUNT_LOGE("event %d is not in state machine map.", evt);
|
||||
return false;
|
||||
}
|
||||
|
||||
// maybe action is null
|
||||
if (eventIter->second == nullptr) {
|
||||
ACCOUNT_LOGI("event %d has no action.", evt);
|
||||
return true;
|
||||
}
|
||||
|
||||
int nextState = eventIter->second->GetNextState();
|
||||
if (currentState_ != nextState) {
|
||||
ACCOUNT_LOGI("account state change, (oldstate, newstate) = (%d, %d)", currentState_, nextState);
|
||||
currentState_ = nextState;
|
||||
}
|
||||
|
||||
// Record state change performance
|
||||
processTicks = GetTickCount() - processTicks;
|
||||
stateRecordStr.append(std::to_string(nextState)).append("], event[").append(std::to_string(evt)).append("] Cost");
|
||||
PerfStat::GetInstance().SetAccountStateChangeTime(stateRecordStr, processTicks);
|
||||
|
||||
return true;
|
||||
}
|
||||
} // namespace AccountSA
|
||||
} // namespace OHOS
|
272
services/accountmgr/src/account_stub.cpp
Executable file
272
services/accountmgr/src/account_stub.cpp
Executable file
@ -0,0 +1,272 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "account_stub.h"
|
||||
#include <dlfcn.h>
|
||||
#include <ipc_types.h>
|
||||
#include "account_error_no.h"
|
||||
#include "account_helper_data.h"
|
||||
#include "account_info.h"
|
||||
#include "account_log_wrapper.h"
|
||||
#include "account_mgr_service.h"
|
||||
#include "bundlemgr/bundle_mgr_interface.h"
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "ohos_account_kits.h"
|
||||
#include "string_ex.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountSA {
|
||||
namespace {
|
||||
const std::string OHOS_ACCOUNT_QUIT_TIPS_TITLE = "";
|
||||
const std::string OHOS_ACCOUNT_QUIT_TIPS_CONTENT = "";
|
||||
const std::string PERMISSION_MANAGE_USERS = "ohos.permission.MANAGE_LOCAL_ACCOUNTS";
|
||||
const std::string PERMISSION_INTERACT_ACROSS_USERS = "ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS";
|
||||
const std::string PERMISSION_INTERACT_ACROSS_USERS_FULL =
|
||||
"ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS_EXTENSION";
|
||||
const std::string PERMISSION_DISTRIBUTED_DATASYNC = "ohos.permission.DISTRIBUTED_DATASYNC";
|
||||
const std::string DEFAULT_ACCOUNT_NAME = "no_name";
|
||||
constexpr std::int32_t SYSTEM_UID = 1000;
|
||||
constexpr std::int32_t ROOT_UID = 0;
|
||||
|
||||
std::int32_t GetBundleNamesForUid(std::int32_t uid, std::vector<std::string> &bundleNameVec)
|
||||
{
|
||||
sptr<ISystemAbilityManager> systemMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (systemMgr == nullptr) {
|
||||
ACCOUNT_LOGE("Fail to get system ability mgr");
|
||||
return ERR_ACCOUNT_ZIDL_ACCOUNT_STUB_ERROR;
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> remoteObject = systemMgr->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
|
||||
if (remoteObject == nullptr) {
|
||||
ACCOUNT_LOGE("Fail to get bundle manager proxy");
|
||||
return ERR_ACCOUNT_ZIDL_ACCOUNT_STUB_ERROR;
|
||||
}
|
||||
|
||||
sptr<OHOS::AppExecFwk::IBundleMgr> bundleMgrProxy = iface_cast<OHOS::AppExecFwk::IBundleMgr>(remoteObject);
|
||||
if (bundleMgrProxy == nullptr) {
|
||||
ACCOUNT_LOGE("Bundle mgr proxy is nullptr");
|
||||
return ERR_ACCOUNT_ZIDL_ACCOUNT_STUB_ERROR;
|
||||
}
|
||||
|
||||
std::string bundleName;
|
||||
if (bundleMgrProxy->GetBundleNameForUid(uid, bundleName)) {
|
||||
bundleNameVec.emplace_back(bundleName);
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
}
|
||||
const std::map<std::uint32_t, AccountStubFunc> AccountStub::stubFuncMap_ {
|
||||
std::make_pair(UPDATE_OHOS_ACCOUNT_INFO, &AccountStub::CmdUpdateOhosAccountInfo),
|
||||
std::make_pair(QUERY_OHOS_ACCOUNT_INFO, &AccountStub::CmdQueryOhosAccountInfo),
|
||||
std::make_pair(QUERY_OHOS_ACCOUNT_QUIT_TIPS, &AccountStub::CmdQueryOhosQuitTips),
|
||||
std::make_pair(QUERY_DEVICE_ACCOUNT_ID, &AccountStub::CmdQueryDeviceAccountId),
|
||||
std::make_pair(QUERY_DEVICE_ACCOUNT_ID_FROM_UID, &AccountStub::CmdQueryDeviceAccountIdFromUid),
|
||||
};
|
||||
|
||||
std::int32_t AccountStub::CmdUpdateOhosAccountInfo(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
if (!IsRootOrSystemAccount() && !HasAccountRequestPermission(PERMISSION_MANAGE_USERS)) {
|
||||
ACCOUNT_LOGE("Check permission failed");
|
||||
return ERR_ACCOUNT_ZIDL_CHECK_PERMISSION_ERROR;
|
||||
}
|
||||
|
||||
// ignore the real account name
|
||||
Str16ToStr8(data.ReadString16());
|
||||
const std::string accountName = DEFAULT_ACCOUNT_NAME;
|
||||
const std::string uid = Str16ToStr8(data.ReadString16());
|
||||
if (uid.empty()) {
|
||||
ACCOUNT_LOGE("invalid user id");
|
||||
return ERR_ACCOUNT_ZIDL_ACCOUNT_STUB_ERROR;
|
||||
}
|
||||
const std::string eventStr = Str16ToStr8(data.ReadString16());
|
||||
ACCOUNT_LOGI("CmdUpdateOhosAccountInfo eventStr: %s", eventStr.c_str());
|
||||
|
||||
std::int32_t ret = ERR_OK;
|
||||
bool result = UpdateOhosAccountInfo(accountName, uid, eventStr);
|
||||
if (!result) {
|
||||
ACCOUNT_LOGE("Update ohos account info failed");
|
||||
ret = ERR_ACCOUNT_ZIDL_ACCOUNT_STUB_ERROR;
|
||||
}
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
ACCOUNT_LOGE("Write result data failed");
|
||||
ret = ERR_ACCOUNT_ZIDL_WRITE_RESULT_ERROR;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::int32_t AccountStub::CmdQueryOhosAccountInfo(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
if (!IsRootOrSystemAccount() && !HasAccountRequestPermission(PERMISSION_MANAGE_USERS)) {
|
||||
ACCOUNT_LOGE("Check permission failed");
|
||||
return ERR_ACCOUNT_ZIDL_CHECK_PERMISSION_ERROR;
|
||||
}
|
||||
|
||||
std::pair<bool, OhosAccountInfo> info = QueryOhosAccountInfo();
|
||||
if (!info.first) {
|
||||
ACCOUNT_LOGE("Query ohos account info failed");
|
||||
return ERR_ACCOUNT_ZIDL_ACCOUNT_STUB_ERROR;
|
||||
}
|
||||
|
||||
std::string name = info.second.name_;
|
||||
std::string id = info.second.uid_;
|
||||
if (!reply.WriteString16(Str8ToStr16(name))) {
|
||||
ACCOUNT_LOGE("Write name data failed");
|
||||
return ERR_ACCOUNT_ZIDL_WRITE_NAME_ERROR;
|
||||
}
|
||||
if (!reply.WriteString16(Str8ToStr16(id))) {
|
||||
ACCOUNT_LOGE("Write id data failed");
|
||||
return ERR_ACCOUNT_ZIDL_WRITE_UID_ERROR;
|
||||
}
|
||||
if (!reply.WriteInt32(info.second.status_)) {
|
||||
ACCOUNT_LOGE("Write status data failed");
|
||||
return ERR_ACCOUNT_ZIDL_WRITE_ACCOUNT_STATUS_ERROR;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
std::int32_t AccountStub::CmdQueryOhosQuitTips(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
if (!IsRootOrSystemAccount() && !HasAccountRequestPermission(PERMISSION_MANAGE_USERS)) {
|
||||
ACCOUNT_LOGE("Check permission failed");
|
||||
return ERR_ACCOUNT_ZIDL_CHECK_PERMISSION_ERROR;
|
||||
}
|
||||
|
||||
if (!reply.WriteString16(Str8ToStr16(OHOS_ACCOUNT_QUIT_TIPS_TITLE))) {
|
||||
ACCOUNT_LOGE("Write quit tips title failed");
|
||||
return ERR_ACCOUNT_ZIDL_WRITE_RESULT_ERROR;
|
||||
}
|
||||
if (!reply.WriteString16(Str8ToStr16(OHOS_ACCOUNT_QUIT_TIPS_CONTENT))) {
|
||||
ACCOUNT_LOGE("Write quit tips content failed");
|
||||
return ERR_ACCOUNT_ZIDL_WRITE_RESULT_ERROR;
|
||||
}
|
||||
ACCOUNT_LOGI("CmdQueryOhosQuitTips exit");
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
std::int32_t AccountStub::CmdQueryDeviceAccountId(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
if (!IsRootOrSystemAccount()) {
|
||||
ACCOUNT_LOGE("Check permission failed");
|
||||
return ERR_ACCOUNT_ZIDL_CHECK_PERMISSION_ERROR;
|
||||
}
|
||||
|
||||
std::int32_t id;
|
||||
auto ret = QueryDeviceAccountId(id);
|
||||
if (ret != ERR_OK) {
|
||||
ACCOUNT_LOGE("QueryDevice AccountId failed: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (!reply.WriteInt32(id)) {
|
||||
ACCOUNT_LOGE("Write result data failed");
|
||||
return ERR_ACCOUNT_ZIDL_WRITE_RESULT_ERROR;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
std::int32_t AccountStub::CmdQueryDeviceAccountIdFromUid(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
std::int32_t uid = data.ReadInt32();
|
||||
auto ret = QueryDeviceAccountIdFromUid(uid);
|
||||
if (ret < 0) {
|
||||
ACCOUNT_LOGE("QueryDevice accountid from uid failed: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
ACCOUNT_LOGE("Write result data failed");
|
||||
return ERR_ACCOUNT_ZIDL_WRITE_RESULT_ERROR;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
std::int32_t AccountStub::OnRemoteRequest(std::uint32_t code, MessageParcel &data,
|
||||
MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
ACCOUNT_LOGI("Received stub message: %{public}d", code);
|
||||
if (!IsServiceStarted()) {
|
||||
ACCOUNT_LOGE("account mgr not ready");
|
||||
return ERR_ACCOUNT_ZIDL_MGR_NOT_READY_ERROR;
|
||||
}
|
||||
|
||||
if (!CheckCallerForTrustList()) {
|
||||
const std::u16string descriptor = AccountStub::GetDescriptor();
|
||||
const std::u16string remoteDescriptor = data.ReadInterfaceToken();
|
||||
if (descriptor != remoteDescriptor) {
|
||||
ACCOUNT_LOGE("Check remote descriptor failed");
|
||||
return ERR_ACCOUNT_ZIDL_ACCOUNT_STUB_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
const auto &itFunc = stubFuncMap_.find(code);
|
||||
if (itFunc != stubFuncMap_.end()) {
|
||||
return (this->*(itFunc->second))(data, reply);
|
||||
}
|
||||
|
||||
ACCOUNT_LOGW("remote request unhandled: %{public}d", code);
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
|
||||
bool AccountStub::HasAccountRequestPermission(const std::string &permissionName)
|
||||
{
|
||||
if (permissionName.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ACCOUNT_LOGI("Check permission: %{public}s", permissionName.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AccountStub::IsRootOrSystemAccount()
|
||||
{
|
||||
const auto id = IPCSkeleton::GetCallingUid();
|
||||
return (id == ROOT_UID || id == SYSTEM_UID);
|
||||
}
|
||||
|
||||
bool AccountStub::CheckCallerForTrustList()
|
||||
{
|
||||
if (!IsServiceStarted()) {
|
||||
ACCOUNT_LOGE("account mgr not ready");
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::int32_t uid = IPCSkeleton::GetCallingUid();
|
||||
if (uid == ROOT_UID || uid == SYSTEM_UID) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::string> bundleNameVec;
|
||||
if (GetBundleNamesForUid(uid, bundleNameVec) != ERR_OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (bundleNameVec.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::string> trustList = AccountHelperData::GetBundleNameTrustList();
|
||||
for (const auto &bundleName : bundleNameVec) {
|
||||
if (std::find(trustList.begin(), trustList.end(), bundleName) == trustList.end()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace AccountSA
|
||||
} // namespace OHOS
|
23
services/accountmgr/src/iaccount.cpp
Executable file
23
services/accountmgr/src/iaccount.cpp
Executable file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "iaccount.h"
|
||||
#include "account_proxy.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountSA {
|
||||
IMPLEMENT_META_INTERFACE(Account, ACCOUNT_SERVICE_NAME);
|
||||
} // namespace AccountSA
|
||||
} // namespace OHOS
|
144
services/accountmgr/src/ohos_account_data_deal.cpp
Executable file
144
services/accountmgr/src/ohos_account_data_deal.cpp
Executable file
@ -0,0 +1,144 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ohos_account_data_deal.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "account_error_no.h"
|
||||
#include "account_info.h"
|
||||
#include "account_log_wrapper.h"
|
||||
#include "directory_ex.h"
|
||||
#include "file_ex.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountSA {
|
||||
OhosAccountDataDeal::OhosAccountDataDeal(const std::string &configFile) : configFile_(configFile)
|
||||
{
|
||||
initOk_ = false;
|
||||
}
|
||||
|
||||
ErrCode OhosAccountDataDeal::Init()
|
||||
{
|
||||
if (!FileExists(configFile_)) {
|
||||
ACCOUNT_LOGI("file %{public}s not exist, create!", configFile_.c_str());
|
||||
BuildJsonFileFromScratch();
|
||||
}
|
||||
|
||||
std::ifstream fin(configFile_);
|
||||
if (!fin) {
|
||||
ACCOUNT_LOGE("Failed to open file %{public}s", configFile_.c_str());
|
||||
return ERR_ACCOUNT_DATADEAL_INPUT_FILE_ERROR;
|
||||
}
|
||||
|
||||
// NOT-allow exceptions when parse json file
|
||||
nlohmann::json jsonData = json::parse(fin, nullptr, false);
|
||||
if (!jsonData.is_structured()) {
|
||||
ACCOUNT_LOGE("Invalid json file, remove");
|
||||
fin.close();
|
||||
if (RemoveFile(configFile_)) {
|
||||
ACCOUNT_LOGE("Remove invalid json file failed");
|
||||
}
|
||||
return ERR_ACCOUNT_DATADEAL_JSON_FILE_CORRUPTION;
|
||||
}
|
||||
|
||||
// jsonData_ keeps well-structured json key-values
|
||||
jsonData_ = jsonData;
|
||||
initOk_ = true;
|
||||
fin.close();
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode OhosAccountDataDeal::AccountInfoFromJson(AccountInfo &accountInfo)
|
||||
{
|
||||
if (!initOk_) {
|
||||
return ERR_ACCOUNT_DATADEAL_NOT_READY;
|
||||
}
|
||||
|
||||
const auto &jsonObjectEnd = jsonData_.end();
|
||||
if (jsonData_.find(DATADEAL_JSON_KEY_ACCOUNT_NAME) != jsonObjectEnd) {
|
||||
accountInfo.ohosAccountName_ = jsonData_.at(DATADEAL_JSON_KEY_ACCOUNT_NAME).get<std::string>();
|
||||
}
|
||||
|
||||
if (jsonData_.find(DATADEAL_JSON_KEY_OPENID) != jsonObjectEnd) {
|
||||
accountInfo.ohosAccountUid_ = jsonData_.at(DATADEAL_JSON_KEY_OPENID).get<std::string>();
|
||||
}
|
||||
|
||||
if (jsonData_.find(DATADEAL_JSON_KEY_UID) != jsonObjectEnd) {
|
||||
accountInfo.userId_ = jsonData_.at(DATADEAL_JSON_KEY_UID).get<std::int32_t>();
|
||||
}
|
||||
|
||||
if (jsonData_.find(DATADEAL_JSON_KEY_BIND_TIME) != jsonObjectEnd) {
|
||||
accountInfo.bindTime_ = jsonData_.at(DATADEAL_JSON_KEY_BIND_TIME).get<std::time_t>();
|
||||
}
|
||||
ACCOUNT_LOGI("AccountInfo, bindTime: %{public}ld", accountInfo.bindTime_);
|
||||
|
||||
if (jsonData_.find(DATADEAL_JSON_KEY_STATUS) != jsonObjectEnd) {
|
||||
accountInfo.ohosAccountStatus_ = jsonData_.at(DATADEAL_JSON_KEY_STATUS).get<std::int32_t>();
|
||||
}
|
||||
ACCOUNT_LOGI("AccountInfo, ohos account status: %{public}d", accountInfo.ohosAccountStatus_);
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode OhosAccountDataDeal::AccountInfoToJson(AccountInfo &accountInfo)
|
||||
{
|
||||
if (!initOk_) {
|
||||
ACCOUNT_LOGE("Not init ok");
|
||||
return ERR_ACCOUNT_DATADEAL_NOT_READY;
|
||||
}
|
||||
|
||||
SaveAccountInfo(accountInfo);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
void OhosAccountDataDeal::CreateDefaultAccountInfo(AccountInfo &accountInfo)
|
||||
{
|
||||
accountInfo.userId_ = 0;
|
||||
accountInfo.bindTime_ = 0;
|
||||
accountInfo.ohosAccountUid_ = DEFAULT_OHOS_ACCOUNT_UID;
|
||||
accountInfo.ohosAccountName_ = DEFAULT_OHOS_ACCOUNT_NAME;
|
||||
accountInfo.ohosAccountStatus_ = ACCOUNT_STATE_UNBOUND;
|
||||
accountInfo.digest_ = "";
|
||||
}
|
||||
|
||||
void OhosAccountDataDeal::SaveAccountInfo(AccountInfo &accountInfo)
|
||||
{
|
||||
jsonData_[DATADEAL_JSON_KEY_BIND_TIME] = accountInfo.bindTime_;
|
||||
jsonData_[DATADEAL_JSON_KEY_UID] = accountInfo.userId_;
|
||||
jsonData_[DATADEAL_JSON_KEY_OPENID] = accountInfo.ohosAccountUid_;
|
||||
jsonData_[DATADEAL_JSON_KEY_ACCOUNT_NAME] = accountInfo.ohosAccountName_;
|
||||
jsonData_[DATADEAL_JSON_KEY_STATUS] = accountInfo.ohosAccountStatus_;
|
||||
|
||||
/* update config file */
|
||||
std::ofstream out(configFile_);
|
||||
if (!out) {
|
||||
ACCOUNT_LOGE("Failed to open file %{public}s", configFile_.c_str());
|
||||
return;
|
||||
}
|
||||
out << jsonData_;
|
||||
out.close();
|
||||
}
|
||||
|
||||
void OhosAccountDataDeal::BuildJsonFileFromScratch()
|
||||
{
|
||||
AccountInfo accountInfo;
|
||||
|
||||
CreateDefaultAccountInfo(accountInfo);
|
||||
|
||||
SaveAccountInfo(accountInfo);
|
||||
}
|
||||
} // namespace AccountSA
|
||||
} // namespace OHOS
|
340
services/accountmgr/src/ohos_account_manager.cpp
Executable file
340
services/accountmgr/src/ohos_account_manager.cpp
Executable file
@ -0,0 +1,340 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ohos_account_manager.h"
|
||||
#include "account_info.h"
|
||||
#include "account_log_wrapper.h"
|
||||
#include "account_mgr_service.h"
|
||||
#include "hisysevent.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountSA {
|
||||
constexpr std::int32_t MAX_RETRY_TIMES = 2; // give another chance when json file corrupted
|
||||
|
||||
/**
|
||||
* Ohos account state change.
|
||||
*
|
||||
* @param name ohos account name
|
||||
* @param uid ohos account uid
|
||||
* @param eventStr ohos account state change event
|
||||
* @return true if the processing was completed, otherwise false
|
||||
*/
|
||||
bool OhosAccountManager::OhosAccountStateChange(const std::string &name, const std::string &uid,
|
||||
const std::string &eventStr)
|
||||
{
|
||||
auto itFunc = eventFuncMap_.find(eventStr);
|
||||
if (itFunc == eventFuncMap_.end()) {
|
||||
ACCOUNT_LOGE("invalid event: %{public}s", eventStr.c_str());
|
||||
return false;
|
||||
}
|
||||
return (this->*(itFunc->second))(name, uid, eventStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear current account information
|
||||
*
|
||||
*/
|
||||
bool OhosAccountManager::ClearAccount(std::int32_t clrStatus)
|
||||
{
|
||||
currentAccount_.clear(clrStatus);
|
||||
ErrCode errCode = dataDealer_->AccountInfoToJson(currentAccount_);
|
||||
if (errCode != ERR_OK) {
|
||||
ACCOUNT_LOGE("AccountInfoToJson error");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Config current account config.
|
||||
*
|
||||
* @param account account information.
|
||||
* @return true if success.
|
||||
*/
|
||||
bool OhosAccountManager::SetAccount(AccountInfo &account)
|
||||
{
|
||||
currentAccount_ = account;
|
||||
ErrCode errCode = dataDealer_->AccountInfoToJson(currentAccount_);
|
||||
if (errCode != ERR_OK) {
|
||||
ACCOUNT_LOGE("AccountInfoToJson error");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current account information.
|
||||
*
|
||||
* @return current account information.
|
||||
*/
|
||||
AccountInfo OhosAccountManager::GetAccountInfo()
|
||||
{
|
||||
std::lock_guard<std::mutex> mutexLock(mgrMutex_);
|
||||
return currentAccount_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current account state.
|
||||
*
|
||||
* @return current account state id.
|
||||
*/
|
||||
std::int32_t OhosAccountManager::GetAccountState() const
|
||||
{
|
||||
return currentAccount_.ohosAccountStatus_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process an account event.
|
||||
*
|
||||
* @param eventStr ohos account state change event
|
||||
* @return true if the processing was completed, otherwise false
|
||||
*/
|
||||
bool OhosAccountManager::HandleEvent(const std::string &eventStr)
|
||||
{
|
||||
auto iter = eventMap_.find(eventStr);
|
||||
if (iter == eventMap_.end()) {
|
||||
ACCOUNT_LOGE("invalid event: %{public}s", eventStr.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
int event = iter->second;
|
||||
bool ret = accountState_->StateChangeProcess(event);
|
||||
if (!ret) {
|
||||
ACCOUNT_LOGE("Handle event %{public}d failed", event);
|
||||
return false;
|
||||
}
|
||||
std::int32_t newState = accountState_->GetAccountState();
|
||||
if (newState != currentAccount_.ohosAccountStatus_) {
|
||||
HiviewDFX::HiSysEvent::Write(HiviewDFX::HiSysEvent::Domain::ACCOUNT, "AccountServiceStateMachineEvent",
|
||||
HiviewDFX::HiSysEvent::EventType::FAULT, "DEVICE_MODE", currentAccount_.userId_,
|
||||
"OPERATION_TYPE", event, "OLD_STATE", currentAccount_.ohosAccountStatus_, "NEW_STATE", newState);
|
||||
currentAccount_.ohosAccountStatus_ = newState;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* login ohos (for distributed network) account.
|
||||
*
|
||||
* @param name ohos account name
|
||||
* @param uid ohos account uid
|
||||
* @param eventStr ohos account state change event
|
||||
* @return true if the processing was completed, otherwise false
|
||||
*/
|
||||
bool OhosAccountManager::LoginOhosAccount(const std::string &name, const std::string &uid, const std::string &eventStr)
|
||||
{
|
||||
std::lock_guard<std::mutex> mutexLock(mgrMutex_);
|
||||
bool ret = HandleEvent(eventStr); // update account status
|
||||
if (!ret) {
|
||||
ACCOUNT_LOGE("LoginOhosAccount: HandleEvent %{public}s failed", eventStr.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
AccountInfo accountInfo(name, uid, currentAccount_.ohosAccountStatus_);
|
||||
accountInfo.bindTime_ = std::time(nullptr);
|
||||
accountInfo.userId_ = GetUserId();
|
||||
ret = SetAccount(accountInfo); // set account info
|
||||
if (!ret) {
|
||||
ACCOUNT_LOGE("LoginOhosAccount: SetAccount failed");
|
||||
return false;
|
||||
}
|
||||
ACCOUNT_LOGI("LoginOhosAccount success");
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* logout ohos (for distributed network) account.
|
||||
*
|
||||
* @param name ohos account name
|
||||
* @param uid ohos account uid
|
||||
* @param eventStr ohos account state change event
|
||||
* @return true if the processing was completed, otherwise false
|
||||
*/
|
||||
bool OhosAccountManager::LogoutOhosAccount(const std::string &name, const std::string &uid, const std::string &eventStr)
|
||||
{
|
||||
std::lock_guard<std::mutex> mutexLock(mgrMutex_);
|
||||
bool ret = HandleEvent(eventStr); // update account status
|
||||
if (!ret) {
|
||||
ACCOUNT_LOGE("LogoutOhosAccount: HandleEvent %{public}s failed", eventStr.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = ClearAccount(); // clear account info with ACCOUNT_STATE_LOGOUT
|
||||
if (!ret) {
|
||||
ACCOUNT_LOGE("LogoutOhosAccount: ClearAccount failed");
|
||||
return false;
|
||||
}
|
||||
ACCOUNT_LOGI("LogoutOhosAccount success");
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* logoff ohos (for distributed network) account.
|
||||
*
|
||||
* @param name ohos account name
|
||||
* @param uid ohos account uid
|
||||
* @param eventStr ohos account state change event
|
||||
* @return true if the processing was completed, otherwise false
|
||||
*/
|
||||
bool OhosAccountManager::LogoffOhosAccount(const std::string &name, const std::string &uid, const std::string &eventStr)
|
||||
{
|
||||
std::lock_guard<std::mutex> mutexLock(mgrMutex_);
|
||||
bool ret = HandleEvent(eventStr); // update account status
|
||||
if (!ret) {
|
||||
ACCOUNT_LOGE("LogoffOhosAccount: HandleEvent %{public}s failed", eventStr.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = ClearAccount(ACCOUNT_STATE_LOGOFF); // clear account info with ACCOUNT_STATE_LOGOFF
|
||||
if (!ret) {
|
||||
ACCOUNT_LOGE("LogoffOhosAccount: ClearAccount failed");
|
||||
return false;
|
||||
}
|
||||
ACCOUNT_LOGI("LogoffOhosAccount success");
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle token_invalid event.
|
||||
*
|
||||
* @param name ohos account name
|
||||
* @param uid ohos account uid
|
||||
* @param eventStr ohos account state change event
|
||||
* @return true if the processing was completed, otherwise false
|
||||
*/
|
||||
bool OhosAccountManager::HandleOhosAccountTokenInvalidEvent(const std::string &name,
|
||||
const std::string &uid, const std::string &eventStr)
|
||||
{
|
||||
std::lock_guard<std::mutex> mutexLock(mgrMutex_);
|
||||
bool ret = HandleEvent(eventStr); // update account status
|
||||
if (!ret) {
|
||||
ACCOUNT_LOGE("HandleOhosAccountTokenInvalidEvent: HandleEvent %{public}s failed", eventStr.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
AccountInfo accountInfo(name, uid, currentAccount_.ohosAccountStatus_);
|
||||
accountInfo.userId_ = GetUserId();
|
||||
ret = SetAccount(accountInfo);
|
||||
if (!ret) {
|
||||
// moving on even if failed to update account info
|
||||
ACCOUNT_LOGW("Handle TokenInvalid event: SetAccount failed");
|
||||
}
|
||||
ACCOUNT_LOGI("HandleOhosAccountTokenInvalidEvent success");
|
||||
return true;
|
||||
}
|
||||
|
||||
std::int32_t OhosAccountManager::GetUserId()
|
||||
{
|
||||
std::int32_t id = DEVICE_ACCOUNT_OWNER; // default to OWNER MODE
|
||||
|
||||
if (!AccountMgrService::GetInstance().IsServiceStarted()) {
|
||||
ACCOUNT_LOGW("account mgr not ready, default as OWNER");
|
||||
return id;
|
||||
}
|
||||
|
||||
auto ret = AccountMgrService::GetInstance().QueryDeviceAccountId(id);
|
||||
if (ret != ERR_OK) {
|
||||
ACCOUNT_LOGW("Get device account Id failed: %d", ret);
|
||||
}
|
||||
|
||||
return (id == DEVICE_ACCOUNT_ID_INVALID) ? DEVICE_ACCOUNT_OWNER : id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Init event mapper.
|
||||
*/
|
||||
void OhosAccountManager::BuildEventsMapper()
|
||||
{
|
||||
eventMap_.insert(std::pair<std::string, ACCOUNT_INNER_EVENT_TYPE>(OHOS_ACCOUNT_EVENT_LOGIN,
|
||||
ACCOUNT_BIND_SUCCESS_EVT));
|
||||
eventMap_.insert(std::pair<std::string, ACCOUNT_INNER_EVENT_TYPE>(OHOS_ACCOUNT_EVENT_LOGOUT,
|
||||
ACCOUNT_MANUAL_UNBOUND_EVT));
|
||||
eventMap_.insert(std::pair<std::string, ACCOUNT_INNER_EVENT_TYPE>(OHOS_ACCOUNT_EVENT_TOKEN_INVALID,
|
||||
ACCOUNT_TOKEN_EXPIRED_EVT));
|
||||
eventMap_.insert(std::pair<std::string, ACCOUNT_INNER_EVENT_TYPE>(OHOS_ACCOUNT_EVENT_LOGOFF,
|
||||
ACCOUNT_MANUAL_LOGOFF_EVT));
|
||||
|
||||
eventFuncMap_.insert(std::make_pair(OHOS_ACCOUNT_EVENT_LOGIN, &OhosAccountManager::LoginOhosAccount));
|
||||
eventFuncMap_.insert(std::make_pair(OHOS_ACCOUNT_EVENT_LOGOUT, &OhosAccountManager::LogoutOhosAccount));
|
||||
eventFuncMap_.insert(std::make_pair(OHOS_ACCOUNT_EVENT_LOGOFF, &OhosAccountManager::LogoffOhosAccount));
|
||||
eventFuncMap_.insert(std::make_pair(OHOS_ACCOUNT_EVENT_TOKEN_INVALID,
|
||||
&OhosAccountManager::HandleOhosAccountTokenInvalidEvent));
|
||||
}
|
||||
|
||||
/**
|
||||
* Init ohos account manager.
|
||||
*
|
||||
*/
|
||||
bool OhosAccountManager::OnInitialize()
|
||||
{
|
||||
accountState_ = std::make_unique<AccountStateMachine>();
|
||||
BuildEventsMapper();
|
||||
|
||||
std::int32_t userId = GetUserId();
|
||||
std::string filePath;
|
||||
filePath.append(ACCOUNT_CFG_DIR_ROOT_PATH).append(std::to_string(userId)).append(ACCOUNT_CFG_FILE_NAME);
|
||||
dataDealer_ = std::make_unique<OhosAccountDataDeal>(filePath);
|
||||
|
||||
std::int32_t tryTimes = 0;
|
||||
while (tryTimes < MAX_RETRY_TIMES) {
|
||||
tryTimes++;
|
||||
ErrCode errCode = dataDealer_->Init();
|
||||
if (errCode == ERR_OK) {
|
||||
break;
|
||||
}
|
||||
|
||||
// when json file corrupted, have it another try
|
||||
if ((tryTimes == MAX_RETRY_TIMES) || (errCode != ERR_ACCOUNT_DATADEAL_JSON_FILE_CORRUPTION)) {
|
||||
ACCOUNT_LOGE("parse json file failed: %{public}d, tryTime: %{public}d", errCode, tryTimes);
|
||||
eventMap_.clear();
|
||||
eventFuncMap_.clear();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// get account info from config file
|
||||
dataDealer_->AccountInfoFromJson(currentAccount_);
|
||||
accountState_->SetAccountState(currentAccount_.ohosAccountStatus_);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle device account switch event.
|
||||
*
|
||||
* @param None
|
||||
* @return None
|
||||
*/
|
||||
void OhosAccountManager::HandleDevAccountSwitchEvent()
|
||||
{
|
||||
std::lock_guard<std::mutex> mutexLock(mgrMutex_);
|
||||
eventMap_.clear();
|
||||
eventFuncMap_.clear();
|
||||
|
||||
// Re-Init
|
||||
if (!OnInitialize()) {
|
||||
ACCOUNT_LOGE("Handle dev Account SwitchEvent failed");
|
||||
}
|
||||
}
|
||||
|
||||
void OhosAccountManager::ReportPublishFailureEvent(std::int32_t errCode, std::int32_t oldStatus)
|
||||
{
|
||||
HiviewDFX::HiSysEvent::Write(HiviewDFX::HiSysEvent::Domain::ACCOUNT, "AccountServicePublishEventFailed",
|
||||
HiviewDFX::HiSysEvent::EventType::FAULT, "ERROR_TYPE", errCode, "OLD_STATE", oldStatus,
|
||||
"NEW_STATE", currentAccount_.ohosAccountStatus_, "DEVICE_MODE", currentAccount_.userId_);
|
||||
}
|
||||
} // namespace AccountSA
|
||||
} // namespace OHOS
|
41
services/accountmgr/test/BUILD.gn
Executable file
41
services/accountmgr/test/BUILD.gn
Executable file
@ -0,0 +1,41 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//base/account/os_account/os_account.gni")
|
||||
import("//build/ohos.gni")
|
||||
import("//build/test.gni")
|
||||
|
||||
config("accountmgr_test_config") {
|
||||
include_dirs = [
|
||||
"//utils/native/base/include",
|
||||
"mock/include",
|
||||
]
|
||||
|
||||
defines = [
|
||||
"ACCOUNT_LOG_TAG = \"ACCOUNT_TEST\"",
|
||||
"LOG_DOMAIN = 0xD001B00",
|
||||
]
|
||||
|
||||
configs = []
|
||||
}
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
|
||||
deps = [
|
||||
"unittest/account_dump_helper_test:unittest",
|
||||
"unittest/account_mgr_service_test:unittest",
|
||||
"unittest/account_mgr_stub_test:unittest",
|
||||
"unittest/ohos_account_data_deal_test:unittest",
|
||||
]
|
||||
}
|
48
services/accountmgr/test/mock/include/mock_account_mgr_service.h
Executable file
48
services/accountmgr/test/mock/include/mock_account_mgr_service.h
Executable file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef BASE_MOCK_ACCOUNT_MGR_SERVICE_H
|
||||
#define BASE_MOCK_ACCOUNT_MGR_SERVICE_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <cstdint>
|
||||
#include "iaccount_context.h"
|
||||
#include "account_stub.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountSA {
|
||||
constexpr std::int32_t MAX_SUPPORTED_ACCOUNT_NUMBER = 4;
|
||||
class MockAccountMgrService final: public AccountStub {
|
||||
public:
|
||||
MockAccountMgrService();
|
||||
MockAccountMgrService(const MockAccountMgrService&) = delete;
|
||||
~MockAccountMgrService() override;
|
||||
|
||||
void HandleNotificationEvents(const std::string& eventStr) override;
|
||||
std::int32_t QueryDeviceAccountId(std::int32_t& accountId) override;
|
||||
bool UpdateOhosAccountInfo(const std::string& accountName, const std::string& uid,
|
||||
const std::string& eventStr) override;
|
||||
std::pair<bool, OhosAccountInfo> QueryOhosAccountInfo(void) override;
|
||||
std::int32_t QueryDeviceAccountIdFromUid(std::int32_t uid) override;
|
||||
bool IsServiceStarted() const override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
std::int32_t devAccountId_;
|
||||
};
|
||||
} // namespace AccountSA
|
||||
} // namespace OHOS
|
||||
#endif // BASE_MOCK_ACCOUNT_MGR_SERVICE_H
|
67
services/accountmgr/test/mock/src/mock_account_mgr_service.cpp
Executable file
67
services/accountmgr/test/mock/src/mock_account_mgr_service.cpp
Executable file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "mock_account_mgr_service.h"
|
||||
#include "account_log_wrapper.h"
|
||||
#include "account_error_no.h"
|
||||
#include "device_account_info.h"
|
||||
#include "iaccount.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountSA {
|
||||
constexpr std::int32_t UID_TRANSFORM_DIVISOR = 100000;
|
||||
MockAccountMgrService::MockAccountMgrService()
|
||||
{
|
||||
devAccountId_ = 0;
|
||||
IAccountContext::SetInstance(this);
|
||||
}
|
||||
|
||||
MockAccountMgrService::~MockAccountMgrService()
|
||||
{
|
||||
IAccountContext::SetInstance(nullptr);
|
||||
}
|
||||
|
||||
void MockAccountMgrService::HandleNotificationEvents(const std::string& eventStr)
|
||||
{
|
||||
ACCOUNT_LOGI("Get event: %{public}s", eventStr.c_str());
|
||||
}
|
||||
|
||||
std::int32_t MockAccountMgrService::QueryDeviceAccountId(std::int32_t& accountId)
|
||||
{
|
||||
accountId = devAccountId_;
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
bool MockAccountMgrService::UpdateOhosAccountInfo(const std::string& accountName, const std::string& uid,
|
||||
const std::string& eventStr)
|
||||
{
|
||||
ACCOUNT_LOGI("MockUpdateOhosAccountInfo: success done");
|
||||
return true;
|
||||
}
|
||||
|
||||
std::pair<bool, OhosAccountInfo> MockAccountMgrService::QueryOhosAccountInfo(void)
|
||||
{
|
||||
std::string name = DEFAULT_OHOS_ACCOUNT_NAME;
|
||||
std::string id = DEFAULT_OHOS_ACCOUNT_UID;
|
||||
std::int32_t status = ACCOUNT_STATE_UNBOUND;
|
||||
return std::make_pair(true, OhosAccountInfo(name, id, status));
|
||||
}
|
||||
|
||||
std::int32_t MockAccountMgrService::QueryDeviceAccountIdFromUid(std::int32_t uid)
|
||||
{
|
||||
return (uid / UID_TRANSFORM_DIVISOR);
|
||||
}
|
||||
} // namespace AccountSA
|
||||
} // namespace OHOS
|
74
services/accountmgr/test/unittest/account_dump_helper_test/BUILD.gn
Executable file
74
services/accountmgr/test/unittest/account_dump_helper_test/BUILD.gn
Executable file
@ -0,0 +1,74 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//base/account/os_account/os_account.gni")
|
||||
import("//build/ohos.gni")
|
||||
import("//build/test.gni")
|
||||
|
||||
module_output_path = "os_account_standard/accountmgrservice"
|
||||
|
||||
config("accountmgr_dump_test_config") {
|
||||
include_dirs = [
|
||||
"./include",
|
||||
"${common_path}/log/include",
|
||||
"${common_path}/perf_stat/include",
|
||||
"${common_path}/account_error/include",
|
||||
"${services_path}/accountmgr/include",
|
||||
"${innerkits_path}/include",
|
||||
"//third_party/json/include",
|
||||
"//utils/native/base/include",
|
||||
"//utils/system/safwk/native/include",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_unittest("AccountDumpHelperTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
sources = [
|
||||
"${common_path}/log/src/account_log_wrapper.cpp",
|
||||
"${common_path}/perf_stat/src/perf_stat.cpp",
|
||||
"${services_path}/accountmgr/src/account_dump_helper.cpp",
|
||||
"${services_path}/accountmgr/src/account_state_machine.cpp",
|
||||
"${services_path}/accountmgr/src/ohos_account_data_deal.cpp",
|
||||
"${services_path}/accountmgr/src/ohos_account_manager.cpp",
|
||||
]
|
||||
sources += [ "account_dump_helper_test.cpp" ]
|
||||
|
||||
configs = [
|
||||
":accountmgr_dump_test_config",
|
||||
"${services_path}/accountmgr/test:accountmgr_test_config",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//third_party/googletest:gmock_main",
|
||||
"//third_party/googletest:gtest_main",
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"aafwk_standard:base",
|
||||
"aafwk_standard:intent",
|
||||
"appexecfwk_standard:appexecfwk_base",
|
||||
"hisysevent_native:libhisysevent",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"safwk:system_ability_fwk",
|
||||
]
|
||||
part_name = "os_account_standard"
|
||||
}
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
|
||||
deps = [ ":AccountDumpHelperTest" ]
|
||||
}
|
@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "account_dump_helper.h"
|
||||
#include "account_error_no.h"
|
||||
#include "account_info.h"
|
||||
#include "account_log_wrapper.h"
|
||||
#include "ohos_account_manager.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS;
|
||||
using namespace OHOS::AccountSA;
|
||||
|
||||
class AccountDumpHelperTest : public testing::Test {
|
||||
public:
|
||||
AccountDumpHelperTest();
|
||||
~AccountDumpHelperTest() {};
|
||||
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
std::shared_ptr<OhosAccountManager> ohosAccount_{};
|
||||
};
|
||||
|
||||
AccountDumpHelperTest::AccountDumpHelperTest()
|
||||
{
|
||||
ohosAccount_ = std::make_shared<OhosAccountManager>();
|
||||
}
|
||||
|
||||
void AccountDumpHelperTest::SetUpTestCase() {}
|
||||
|
||||
void AccountDumpHelperTest::TearDownTestCase() {}
|
||||
|
||||
void AccountDumpHelperTest::SetUp(){}
|
||||
|
||||
void AccountDumpHelperTest::TearDown() {}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountDumpParameterTest001
|
||||
* @tc.desc: Test account info display
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: SR000CUF6J
|
||||
*/
|
||||
HWTEST_F(AccountDumpHelperTest, AccountDumpParameterTest001, TestSize.Level0)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. Input one parameter
|
||||
*/
|
||||
std::string out;
|
||||
vector<std::string> cmd = {"-account_info"};
|
||||
AccountDumpHelper accountDumpHelper(ohosAccount_);
|
||||
|
||||
bool ret = accountDumpHelper.Dump(cmd, out);
|
||||
EXPECT_EQ(true, ret);
|
||||
auto pos = out.find("Ohos account name: ", 0);
|
||||
EXPECT_NE(std::string::npos, ret);
|
||||
pos = out.find("Ohos account openId: ", 0);
|
||||
EXPECT_NE(std::string::npos, ret);
|
||||
pos = out.find("Local user Id: ", 0);
|
||||
EXPECT_NE(std::string::npos, ret);
|
||||
pos = out.find("Ohos account status: ", 0);
|
||||
EXPECT_NE(std::string::npos, ret);
|
||||
pos = out.find("Ohos account bind time: ", 0);
|
||||
EXPECT_NE(std::string::npos, ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountDumpTwoParameterTest002
|
||||
* @tc.desc: Test account log-level set
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CUF6N
|
||||
*/
|
||||
HWTEST_F(AccountDumpHelperTest, AccountDumpTwoParameterTest002, TestSize.Level0)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. Input two parameters
|
||||
*/
|
||||
std::string out;
|
||||
std::string logLevel;
|
||||
std::string prompt = "Current Log Level: ";
|
||||
vector<std::string> setCmd = {"-set_log_level", "1"};
|
||||
vector<std::string> getCmd = {"-show_log_level"};
|
||||
AccountDumpHelper accountDumpHelper(ohosAccount_);
|
||||
|
||||
bool ret = accountDumpHelper.Dump(setCmd, out);
|
||||
EXPECT_EQ(true, ret);
|
||||
ret = accountDumpHelper.Dump(getCmd, out);
|
||||
EXPECT_EQ(true, ret);
|
||||
auto pos = out.find(prompt, 0);
|
||||
EXPECT_NE(std::string::npos, ret);
|
||||
logLevel = out.substr(pos + prompt.length());
|
||||
EXPECT_EQ("1", logLevel.substr(0, 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountDumpInvalidParameterTest003
|
||||
* @tc.desc: Test account info display
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CUF6N
|
||||
*/
|
||||
HWTEST_F(AccountDumpHelperTest, AccountDumpInvalidParameterTest003, TestSize.Level0)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. Input invalid parameter
|
||||
*/
|
||||
std::string out;
|
||||
vector<std::string> cmd = {"This_is_invalid_cmd"};
|
||||
AccountDumpHelper accountDumpHelper(ohosAccount_);
|
||||
EXPECT_EQ(false, accountDumpHelper.Dump(cmd, out));
|
||||
}
|
87
services/accountmgr/test/unittest/account_mgr_service_test/BUILD.gn
Executable file
87
services/accountmgr/test/unittest/account_mgr_service_test/BUILD.gn
Executable file
@ -0,0 +1,87 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//base/account/os_account/os_account.gni")
|
||||
import("//build/ohos.gni")
|
||||
import("//build/test.gni")
|
||||
|
||||
module_output_path = "os_account_standard/accountmgrservice"
|
||||
|
||||
config("accountmgr_service_test_config") {
|
||||
include_dirs = [
|
||||
"./include",
|
||||
"${common_path}/log/include",
|
||||
"${common_path}/perf_stat/include",
|
||||
"${common_path}/account_error/include",
|
||||
"${innerkits_path}/include",
|
||||
"//third_party/json/include",
|
||||
"//utils/native/base/include",
|
||||
"//utils/native/base/include",
|
||||
"//utils/system/safwk/native/include",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_unittest("account_mgr_test") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
sources = [
|
||||
"${common_path}/log/src/account_log_wrapper.cpp",
|
||||
"${common_path}/perf_stat/src/perf_stat.cpp",
|
||||
"${innerkits_path}/accountmgr/src/account_proxy.cpp",
|
||||
"${services_path}/accountmgr/src/account_dump_helper.cpp",
|
||||
"${services_path}/accountmgr/src/account_helper_data.cpp",
|
||||
"${services_path}/accountmgr/src/account_mgr_service.cpp",
|
||||
"${services_path}/accountmgr/src/account_state_machine.cpp",
|
||||
"${services_path}/accountmgr/src/account_stub.cpp",
|
||||
"${services_path}/accountmgr/src/ohos_account_data_deal.cpp",
|
||||
"${services_path}/accountmgr/src/ohos_account_manager.cpp",
|
||||
]
|
||||
|
||||
sources += [
|
||||
"account_mgr_service_test.cpp",
|
||||
"account_state_machine_test.cpp",
|
||||
"ohos_account_manager_test.cpp",
|
||||
]
|
||||
|
||||
configs = [
|
||||
":accountmgr_service_test_config",
|
||||
"${services_path}/accountmgr:accountmgr_config",
|
||||
"${services_path}/accountmgr/test:accountmgr_test_config",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//third_party/googletest:gtest_main",
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"aafwk_standard:base",
|
||||
"aafwk_standard:intent",
|
||||
"aafwk_standard:want",
|
||||
"appexecfwk_standard:appexecfwk_base",
|
||||
"appexecfwk_standard:appexecfwk_core",
|
||||
"hisysevent_native:libhisysevent",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr_L2:samgr_proxy",
|
||||
"startup_l2:syspara",
|
||||
]
|
||||
part_name = "os_account_standard"
|
||||
}
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
|
||||
deps = [ ":account_mgr_test" ]
|
||||
}
|
@ -0,0 +1,211 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "account_dump_helper.h"
|
||||
#include "account_info.h"
|
||||
#include "account_log_wrapper.h"
|
||||
#include "account_proxy.h"
|
||||
#include "iaccount.h"
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "string_ex.h"
|
||||
#include "system_ability.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS;
|
||||
using namespace OHOS::AccountSA;
|
||||
|
||||
namespace {
|
||||
static std::pair<bool, OhosAccountInfo> g_oldInfo;
|
||||
|
||||
sptr<IAccount> GetAccountMgr()
|
||||
{
|
||||
sptr<ISystemAbilityManager> systemMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (systemMgr == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> accountObj = systemMgr->GetSystemAbility(SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN);
|
||||
return iface_cast<AccountProxy>(accountObj);
|
||||
}
|
||||
}
|
||||
|
||||
class AccountMgrServiceTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
void AccountMgrServiceTest::SetUpTestCase()
|
||||
{
|
||||
sptr<IAccount> accountMgr = GetAccountMgr();
|
||||
if (!accountMgr) {
|
||||
std::cout << "TearDownTestCase::GetAccountMgr failed" << std::endl;
|
||||
return;
|
||||
}
|
||||
g_oldInfo = accountMgr->QueryOhosAccountInfo();
|
||||
if (!g_oldInfo.first) {
|
||||
std::cout << "AccountMgrServiceTest::SetUpTestCase GET old info failed" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void AccountMgrServiceTest::TearDownTestCase()
|
||||
{
|
||||
if (g_oldInfo.first) {
|
||||
sptr<IAccount> accountMgr = GetAccountMgr();
|
||||
if (!accountMgr) {
|
||||
std::cout << "TearDownTestCase::GetAccountMgr failed" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
auto name = g_oldInfo.second.name_;
|
||||
auto uid = g_oldInfo.second.uid_;
|
||||
std::string eventStr;
|
||||
bool ret = false;
|
||||
switch (g_oldInfo.second.status_) {
|
||||
case ACCOUNT_STATE_UNBOUND:
|
||||
case ACCOUNT_STATE_LOGOFF:
|
||||
break;
|
||||
case ACCOUNT_STATE_LOGIN:
|
||||
eventStr = OHOS_ACCOUNT_EVENT_LOGIN;
|
||||
ret = accountMgr->UpdateOhosAccountInfo(name, uid, eventStr);
|
||||
if (!ret) {
|
||||
std::cout << "TearDownTestCase RESUME to LOGIN failed" << std::endl;
|
||||
}
|
||||
break;
|
||||
case ACCOUNT_STATE_NOTLOGIN:
|
||||
eventStr = OHOS_ACCOUNT_EVENT_LOGIN;
|
||||
ret = accountMgr->UpdateOhosAccountInfo(name, uid, eventStr);
|
||||
if (!ret) {
|
||||
std::cout << "TearDownTestCase RESUME to LOGIN failed" << std::endl;
|
||||
}
|
||||
eventStr = OHOS_ACCOUNT_EVENT_TOKEN_INVALID;
|
||||
ret = accountMgr->UpdateOhosAccountInfo(name, uid, eventStr);
|
||||
if (!ret) {
|
||||
std::cout << "TearDownTestCase RESUME to NOTLOGIN failed" << std::endl;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AccountMgrServiceTest::SetUp() {}
|
||||
|
||||
void AccountMgrServiceTest::TearDown() {}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountMgrServiceSetOhosIdStatusLoginTest001
|
||||
* @tc.desc: Test ohos account status
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CUF5H SR000CUF5T
|
||||
*/
|
||||
HWTEST_F(AccountMgrServiceTest, AccountMgrServiceSetOhosIdStatusLoginTest001, TestSize.Level2)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. get AccountMgrService Iinterface
|
||||
* @tc.expected: step1. The current account is not set
|
||||
*/
|
||||
sptr<IAccount> accountMgr = GetAccountMgr();
|
||||
ASSERT_TRUE(accountMgr != nullptr);
|
||||
|
||||
std::pair<bool, OhosAccountInfo> info = accountMgr->QueryOhosAccountInfo();
|
||||
EXPECT_EQ(true, info.first);
|
||||
bool ret = false;
|
||||
switch (info.second.status_) {
|
||||
case ACCOUNT_STATE_LOGIN:
|
||||
case ACCOUNT_STATE_NOTLOGIN:
|
||||
ret = accountMgr->UpdateOhosAccountInfo(info.second.name_,
|
||||
info.second.uid_, OHOS_ACCOUNT_EVENT_LOGOUT);
|
||||
EXPECT_EQ(true, ret);
|
||||
info = accountMgr->QueryOhosAccountInfo();
|
||||
EXPECT_EQ(true, info.first);
|
||||
EXPECT_EQ(ACCOUNT_STATE_UNBOUND, info.second.status_);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// update status with test info
|
||||
std::string name("User001");
|
||||
std::string uid("1001");
|
||||
std::string eventStr(OHOS_ACCOUNT_EVENT_LOGIN);
|
||||
ret = accountMgr->UpdateOhosAccountInfo(name, uid, eventStr);
|
||||
EXPECT_EQ(true, ret);
|
||||
// param 1: name, param 2: UID, param 3: status
|
||||
std::pair<bool, OhosAccountInfo> testInfo = accountMgr->QueryOhosAccountInfo();
|
||||
EXPECT_EQ(true, testInfo.first);
|
||||
EXPECT_EQ(uid, testInfo.second.uid_);
|
||||
EXPECT_EQ(ACCOUNT_STATE_LOGIN, testInfo.second.status_);
|
||||
|
||||
eventStr = OHOS_ACCOUNT_EVENT_LOGOUT;
|
||||
ret = accountMgr->UpdateOhosAccountInfo(name, uid, eventStr);
|
||||
EXPECT_EQ(true, ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountMgrServiceSetOhosIdStatusLogoffTest002
|
||||
* @tc.desc: Test ohos account status
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CUF64 AR000CUF5K AR000CUF5O
|
||||
*/
|
||||
HWTEST_F(AccountMgrServiceTest, AccountMgrServiceSetOhosIdStatusLogoffTest002, TestSize.Level2)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. get AccountMgrService Iinterface
|
||||
* @tc.expected: step1. The current account is not set
|
||||
*/
|
||||
sptr<IAccount> accountMgr = GetAccountMgr();
|
||||
ASSERT_TRUE(accountMgr != nullptr);
|
||||
|
||||
std::pair<bool, OhosAccountInfo> retInfo = accountMgr->QueryOhosAccountInfo();
|
||||
EXPECT_EQ(true, retInfo.first);
|
||||
std::string name(retInfo.second.name_);
|
||||
std::string uid(retInfo.second.uid_);
|
||||
std::string eventStr;
|
||||
bool ret = false;
|
||||
switch (retInfo.second.status_) {
|
||||
case ACCOUNT_STATE_LOGIN:
|
||||
case ACCOUNT_STATE_NOTLOGIN:
|
||||
eventStr = OHOS_ACCOUNT_EVENT_LOGOUT;
|
||||
ret = accountMgr->UpdateOhosAccountInfo(name, uid, eventStr);
|
||||
EXPECT_EQ(true, ret);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// update status with test info
|
||||
name = "User002";
|
||||
uid = "1002";
|
||||
eventStr = OHOS_ACCOUNT_EVENT_LOGIN;
|
||||
// param 1: name, param 2: UID, param 3: status
|
||||
ret = accountMgr->UpdateOhosAccountInfo(name, uid, eventStr);
|
||||
EXPECT_EQ(true, ret);
|
||||
|
||||
eventStr = OHOS_ACCOUNT_EVENT_LOGOFF;
|
||||
ret = accountMgr->UpdateOhosAccountInfo(name, uid, eventStr);
|
||||
EXPECT_EQ(true, ret);
|
||||
|
||||
std::pair<bool, OhosAccountInfo> testInfo = accountMgr->QueryOhosAccountInfo();
|
||||
EXPECT_EQ(true, testInfo.first);
|
||||
EXPECT_EQ(ACCOUNT_STATE_LOGOFF, testInfo.second.status_);
|
||||
}
|
@ -0,0 +1,612 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "account_state_machine.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::AccountSA;
|
||||
|
||||
class AccountStateMachineTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
void AccountStateMachineTest::SetUpTestCase() {}
|
||||
|
||||
void AccountStateMachineTest::TearDownTestCase() {}
|
||||
|
||||
void AccountStateMachineTest::SetUp() {}
|
||||
|
||||
void AccountStateMachineTest::TearDown() {}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountStateMachineTestInitState001
|
||||
* @tc.desc: Account state machine initial state
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CUF54
|
||||
*/
|
||||
HWTEST_F(AccountStateMachineTest, AccountStateMachineTestInitState001, TestSize.Level0)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. AccountStateMachine init
|
||||
* @tc.expected: step1. The current state is AccountStateMachine::ACCOUNT_STATE_UNBOUND
|
||||
*/
|
||||
AccountStateMachine stateMachine;
|
||||
EXPECT_EQ(ACCOUNT_STATE_UNBOUND, stateMachine.GetAccountState());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountStateMachineTestUnbound2LoginState002
|
||||
* @tc.desc: Account state machine transform unbound state to login state
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CUF54
|
||||
*/
|
||||
HWTEST_F(AccountStateMachineTest, AccountStateMachineTestUnbound2LoginState002, TestSize.Level0)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. AccountStateMachine init
|
||||
* @tc.expected: step1. The current state is AccountStateMachine::ACCOUNT_STATE_UNBOUND
|
||||
*/
|
||||
AccountStateMachine stateMachine;
|
||||
EXPECT_EQ(ACCOUNT_STATE_UNBOUND, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Input the event ACCOUNT_BIND_SUCCESS_EVT
|
||||
* @tc.expected: step2. The current state is AccountStateMachine::ACCOUNT_STATE_LOGIN
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_BIND_SUCCESS_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_LOGIN, stateMachine.GetAccountState());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountStateMachineTestUnboundBindAccountFailed003
|
||||
* @tc.desc: Account state machine keep the last state
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CUF54
|
||||
*/
|
||||
HWTEST_F(AccountStateMachineTest, AccountStateMachineTestUnboundBindAccountFailed003, TestSize.Level0)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. AccountStateMachine init
|
||||
* @tc.expected: step1. The current state is AccountStateMachine::ACCOUNT_STATE_UNBOUND
|
||||
*/
|
||||
AccountStateMachine stateMachine;
|
||||
EXPECT_EQ(ACCOUNT_STATE_UNBOUND, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Input the event ACCOUNT_BIND_FAILED_EVT
|
||||
* @tc.expected: step2. The current state is AccountStateMachine::ACCOUNT_STATE_UNBOUND
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_BIND_FAILED_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_UNBOUND, stateMachine.GetAccountState());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountStateMachineUnboundInputUntreatedEvent004
|
||||
* @tc.desc: Account state machine keep the last state
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: SR000CUF50
|
||||
*/
|
||||
HWTEST_F(AccountStateMachineTest, AccountStateMachineUnboundInputUntreatedEvent004, TestSize.Level0)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. AccountStateMachine init
|
||||
* @tc.expected: step1. The current state is AccountStateMachine::ACCOUNT_STATE_UNBOUND
|
||||
*/
|
||||
AccountStateMachine stateMachine;
|
||||
EXPECT_EQ(ACCOUNT_STATE_UNBOUND, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Input the event ACCOUNT_PASSWORD_CHANGED_EVT
|
||||
* @tc.expected: step2. The current state is AccountStateMachine::ACCOUNT_STATE_UNBOUND
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_PASSWORD_CHANGED_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_UNBOUND, stateMachine.GetAccountState());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountStateMachineTestLoginTokenExpired005
|
||||
* @tc.desc: Account state machine transform login state to logout state
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CUF5J
|
||||
*/
|
||||
HWTEST_F(AccountStateMachineTest, AccountStateMachineTestLoginTokenExpired005, TestSize.Level0)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. AccountStateMachine init
|
||||
* @tc.expected: step1. The current state is AccountStateMachine::ACCOUNT_STATE_UNBOUND
|
||||
*/
|
||||
AccountStateMachine stateMachine;
|
||||
EXPECT_EQ(ACCOUNT_STATE_UNBOUND, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Input the event ACCOUNT_BIND_SUCCESS_EVT
|
||||
* @tc.expected: step2. The current state is AccountStateMachine::ACCOUNT_STATE_LOGIN
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_BIND_SUCCESS_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_LOGIN, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Input the event ACCOUNT_TOKEN_EXPIRED_EVT
|
||||
* @tc.expected: step3. The current state is AccountStateMachine::ACCOUNT_STATE_NOTLOGIN
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_TOKEN_EXPIRED_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_NOTLOGIN, stateMachine.GetAccountState());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountStateMachineTestLoginPasswordChanged006
|
||||
* @tc.desc: Account state machine transform login state to logout state
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CUF5J SR000CUF60
|
||||
*/
|
||||
HWTEST_F(AccountStateMachineTest, AccountStateMachineTestLoginPasswordChanged006, TestSize.Level0)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. AccountStateMachine init
|
||||
* @tc.expected: step1. The current state is AccountStateMachine::ACCOUNT_STATE_UNBOUND
|
||||
*/
|
||||
AccountStateMachine stateMachine;
|
||||
EXPECT_EQ(ACCOUNT_STATE_UNBOUND, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Input the event ACCOUNT_BIND_SUCCESS_EVT
|
||||
* @tc.expected: step2. The current state is AccountStateMachine::ACCOUNT_STATE_LOGIN
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_BIND_SUCCESS_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_LOGIN, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Input the event ACCOUNT_PASSWORD_CHANGED_EVT
|
||||
* @tc.expected: step3. The current state is AccountStateMachine::ACCOUNT_STATE_NOTLOGIN
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_PASSWORD_CHANGED_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_NOTLOGIN, stateMachine.GetAccountState());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountStateMachineTestManualLogout007
|
||||
* @tc.desc: Account state machine transform login state to logout state
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CUF5R AR000CUF64 AR000CUF66
|
||||
*/
|
||||
HWTEST_F(AccountStateMachineTest, AccountStateMachineTestManualLogout007, TestSize.Level0)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. AccountStateMachine init
|
||||
* @tc.expected: step1. The current state is AccountStateMachine::ACCOUNT_STATE_UNBOUND
|
||||
*/
|
||||
AccountStateMachine stateMachine;
|
||||
EXPECT_EQ(ACCOUNT_STATE_UNBOUND, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Input the event ACCOUNT_BIND_SUCCESS_EVT
|
||||
* @tc.expected: step2. The current state is AccountStateMachine::ACCOUNT_STATE_LOGIN
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_BIND_SUCCESS_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_LOGIN, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Input the event ACCOUNT_MANUAL_LOGOUT_EVT
|
||||
* @tc.expected: step3. The current state is AccountStateMachine::ACCOUNT_STATE_NOTLOGIN
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_MANUAL_LOGOUT_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_NOTLOGIN, stateMachine.GetAccountState());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountStateMachineTestLoginManualUnbound008
|
||||
* @tc.desc: Account state machine transform login state to unbound state
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CUF5M SR000CUF63 AR000CUF65
|
||||
*/
|
||||
HWTEST_F(AccountStateMachineTest, AccountStateMachineTestLoginManualUnbound008, TestSize.Level0)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. AccountStateMachine init
|
||||
* @tc.expected: step1. The current state is AccountStateMachine::ACCOUNT_STATE_UNBOUND
|
||||
*/
|
||||
AccountStateMachine stateMachine;
|
||||
EXPECT_EQ(ACCOUNT_STATE_UNBOUND, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Input the event ACCOUNT_BIND_SUCCESS_EVT
|
||||
* @tc.expected: step2. The current state is AccountStateMachine::ACCOUNT_STATE_LOGIN
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_BIND_SUCCESS_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_LOGIN, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Input the event ACCOUNT_MANUAL_UNBOUND_EVT
|
||||
* @tc.expected: step3. The current state is AccountStateMachine::ACCOUNT_STATE_UNBOUND
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_MANUAL_UNBOUND_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_UNBOUND, stateMachine.GetAccountState());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountStateMachineTestLoginInputUntreatedEvent009
|
||||
* @tc.desc: Account state machine keep the last state
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CUF5I AR000CUF66
|
||||
*/
|
||||
HWTEST_F(AccountStateMachineTest, AccountStateMachineTestLoginInputUntreatedEvent009, TestSize.Level0)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. AccountStateMachine init
|
||||
* @tc.expected: step1. The current state is AccountStateMachine::ACCOUNT_STATE_UNBOUND
|
||||
*/
|
||||
AccountStateMachine stateMachine;
|
||||
EXPECT_EQ(ACCOUNT_STATE_UNBOUND, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Input the event ACCOUNT_BIND_SUCCESS_EVT
|
||||
* @tc.expected: step2. The current state is AccountStateMachine::ACCOUNT_STATE_LOGIN
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_BIND_SUCCESS_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_LOGIN, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Input the event ACCOUNT_BIND_FAILED_EVT
|
||||
* @tc.expected: step3. The current state is AccountStateMachine::ACCOUNT_STATE_LOGIN
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_BIND_FAILED_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_LOGIN, stateMachine.GetAccountState());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountStateMachineTestLogoutAuthenticateSuccess010
|
||||
* @tc.desc: Account state machine transform logout state to login state
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CUF5M AR000CUF61
|
||||
*/
|
||||
HWTEST_F(AccountStateMachineTest, AccountStateMachineTestLogoutAuthenticateSuccess010, TestSize.Level0)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. AccountStateMachine init
|
||||
* @tc.expected: step1. The current state is AccountStateMachine::ACCOUNT_STATE_UNBOUND
|
||||
*/
|
||||
AccountStateMachine stateMachine;
|
||||
EXPECT_EQ(ACCOUNT_STATE_UNBOUND, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Input the event ACCOUNT_BIND_SUCCESS_EVT
|
||||
* @tc.expected: step2. The current state is AccountStateMachine::ACCOUNT_STATE_LOGIN
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_BIND_SUCCESS_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_LOGIN, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Input the event ACCOUNT_MANUAL_LOGOUT_EVT
|
||||
* @tc.expected: step3. The current state is AccountStateMachine::ACCOUNT_STATE_NOTLOGIN
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_MANUAL_LOGOUT_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_NOTLOGIN, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step4. Input the event ACCOUNT_AUTHENTICATE_SUCCESS_EVT
|
||||
* @tc.expected: step4. The current state is AccountStateMachine::ACCOUNT_STATE_LOGIN
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_AUTHENTICATE_SUCCESS_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_LOGIN, stateMachine.GetAccountState());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountStateMachineTestLogoutAuthenticateFailed011
|
||||
* @tc.desc: Account state machine keep the last state
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CUF5J AR000CUF5I
|
||||
*/
|
||||
HWTEST_F(AccountStateMachineTest, AccountStateMachineTestLogoutAuthenticateFailed011, TestSize.Level0)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. AccountStateMachine init
|
||||
* @tc.expected: step1. The current state is AccountStateMachine::ACCOUNT_STATE_UNBOUND
|
||||
*/
|
||||
AccountStateMachine stateMachine;
|
||||
EXPECT_EQ(ACCOUNT_STATE_UNBOUND, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Input the event ACCOUNT_BIND_SUCCESS_EVT
|
||||
* @tc.expected: step2. The current state is AccountStateMachine::ACCOUNT_STATE_LOGIN
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_BIND_SUCCESS_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_LOGIN, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Input the event ACCOUNT_MANUAL_LOGOUT_EVT
|
||||
* @tc.expected: step3. The current state is AccountStateMachine::ACCOUNT_STATE_NOTLOGIN
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_MANUAL_LOGOUT_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_NOTLOGIN, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step4. Input the event ACCOUNT_AUTHENTICATE_FAILED_EVT
|
||||
* @tc.expected: step4. The current state is AccountStateMachine::ACCOUNT_STATE_NOTLOGIN
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_AUTHENTICATE_FAILED_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_NOTLOGIN, stateMachine.GetAccountState());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountStateMachineTestLogoutInputUntreatedEvent012
|
||||
* @tc.desc: Account state machine keep the last state
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CUF5M AR000CUF5I
|
||||
*/
|
||||
HWTEST_F(AccountStateMachineTest, AccountStateMachineTestLogoutInputUntreatedEvent012, TestSize.Level0)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. AccountStateMachine init
|
||||
* @tc.expected: step1. The current state is AccountStateMachine::ACCOUNT_STATE_UNBOUND
|
||||
*/
|
||||
AccountStateMachine stateMachine;
|
||||
EXPECT_EQ(ACCOUNT_STATE_UNBOUND, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Input the event ACCOUNT_BIND_SUCCESS_EVT
|
||||
* @tc.expected: step2. The current state is AccountStateMachine::ACCOUNT_STATE_LOGIN
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_BIND_SUCCESS_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_LOGIN, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Input the event ACCOUNT_MANUAL_LOGOUT_EVT
|
||||
* @tc.expected: step3. The current state is AccountStateMachine::ACCOUNT_STATE_NOTLOGIN
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_MANUAL_LOGOUT_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_NOTLOGIN, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step4. Input the event ACCOUNT_AUTHENTICATE_FAILED_EVT
|
||||
* @tc.expected: step4. The current state is AccountStateMachine::ACCOUNT_STATE_NOTLOGIN
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_AUTHENTICATE_FAILED_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_NOTLOGIN, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Input the event ACCOUNT_BIND_FAILED_EVT
|
||||
* @tc.expected: step3. The current state is AccountStateMachine::ACCOUNT_STATE_NOTLOGIN
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_BIND_FAILED_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_NOTLOGIN, stateMachine.GetAccountState());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountStateMachineTestLogoutManualUnbound013
|
||||
* @tc.desc: Account state machine transform logout state to unbound state
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CUF5M
|
||||
*/
|
||||
HWTEST_F(AccountStateMachineTest, AccountStateMachineTestLogoutManualUnbound013, TestSize.Level0)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. AccountStateMachine init
|
||||
* @tc.expected: step1. The current state is AccountStateMachine::ACCOUNT_STATE_UNBOUND
|
||||
*/
|
||||
AccountStateMachine stateMachine;
|
||||
EXPECT_EQ(ACCOUNT_STATE_UNBOUND, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Input the event ACCOUNT_BIND_SUCCESS_EVT
|
||||
* @tc.expected: step2. The current state is AccountStateMachine::ACCOUNT_STATE_LOGIN
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_BIND_SUCCESS_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_LOGIN, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Input the event ACCOUNT_MANUAL_LOGOUT_EVT
|
||||
* @tc.expected: step3. The current state is AccountStateMachine::ACCOUNT_STATE_NOTLOGIN
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_MANUAL_LOGOUT_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_NOTLOGIN, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step4. Input the event ACCOUNT_MANUAL_UNBOUND_EVT
|
||||
* @tc.expected: step4. The current state is AccountStateMachine::ACCOUNT_STATE_UNBOUND
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_MANUAL_UNBOUND_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_UNBOUND, stateMachine.GetAccountState());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountStateMachineTestLoginManualLogoff014
|
||||
* @tc.desc: Account state machine transform login state to logoff state
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CUF5M AR000CUF5O
|
||||
*/
|
||||
HWTEST_F(AccountStateMachineTest, AccountStateMachineTestLoginManualLogoff014, TestSize.Level0)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. AccountStateMachine init
|
||||
* @tc.expected: step1. The current state is AccountStateMachine::ACCOUNT_STATE_UNBOUND
|
||||
*/
|
||||
AccountStateMachine stateMachine;
|
||||
EXPECT_EQ(ACCOUNT_STATE_UNBOUND, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Input the event ACCOUNT_BIND_SUCCESS_EVT
|
||||
* @tc.expected: step2. The current state is AccountStateMachine::ACCOUNT_STATE_LOGIN
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_BIND_SUCCESS_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_LOGIN, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Input the event ACCOUNT_MANUAL_LOGOFF_EVT
|
||||
* @tc.expected: step3. The current state is AccountStateMachine::ACCOUNT_STATE_LOGOFF
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_MANUAL_LOGOFF_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_LOGOFF, stateMachine.GetAccountState());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountStateMachineTestLogoutManualLogoff015
|
||||
* @tc.desc: Account state machine transform logout state to logoff state
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CUF5M AR000CUF5O
|
||||
*/
|
||||
HWTEST_F(AccountStateMachineTest, AccountStateMachineTestLogoutManualLogoff015, TestSize.Level0)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. AccountStateMachine init
|
||||
* @tc.expected: step1. The current state is AccountStateMachine::ACCOUNT_STATE_UNBOUND
|
||||
*/
|
||||
AccountStateMachine stateMachine;
|
||||
EXPECT_EQ(ACCOUNT_STATE_UNBOUND, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Input the event ACCOUNT_BIND_SUCCESS_EVT
|
||||
* @tc.expected: step2. The current state is AccountStateMachine::ACCOUNT_STATE_LOGIN
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_BIND_SUCCESS_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_LOGIN, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Input the event ACCOUNT_MANUAL_LOGOUT_EVT
|
||||
* @tc.expected: step3. The current state is AccountStateMachine::ACCOUNT_STATE_NOTLOGIN
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_MANUAL_LOGOUT_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_NOTLOGIN, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step4. Input the event ACCOUNT_MANUAL_LOGOFF_EVT
|
||||
* @tc.expected: step4. The current state is AccountStateMachine::ACCOUNT_STATE_LOGOFF
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_MANUAL_LOGOFF_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_LOGOFF, stateMachine.GetAccountState());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountStateMachineTestLogoutBindSuccess016
|
||||
* @tc.desc: Account state machine transform logout state to login state
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CUF5M AR000CUF62
|
||||
*/
|
||||
HWTEST_F(AccountStateMachineTest, AccountStateMachineTestLogoutBindSuccess016, TestSize.Level0)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. AccountStateMachine init
|
||||
* @tc.expected: step1. The current state is AccountStateMachine::ACCOUNT_STATE_UNBOUND
|
||||
*/
|
||||
AccountStateMachine stateMachine;
|
||||
EXPECT_EQ(ACCOUNT_STATE_UNBOUND, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Input the event ACCOUNT_BIND_SUCCESS_EVT
|
||||
* @tc.expected: step2. The current state is AccountStateMachine::ACCOUNT_STATE_LOGIN
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_BIND_SUCCESS_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_LOGIN, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Input the event ACCOUNT_MANUAL_LOGOUT_EVT
|
||||
* @tc.expected: step3. The current state is AccountStateMachine::ACCOUNT_STATE_NOTLOGIN
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_MANUAL_LOGOUT_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_NOTLOGIN, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step4. Input the event ACCOUNT_BIND_SUCCESS_EVT
|
||||
* @tc.expected: step4. The current state is AccountStateMachine::ACCOUNT_STATE_LOGIN
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_BIND_SUCCESS_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_LOGIN, stateMachine.GetAccountState());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountStateMachineTestLogoffBindSuccess017
|
||||
* @tc.desc: Account state machine transform logoff state to login state
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CUF5M AR000CUF5P
|
||||
*/
|
||||
HWTEST_F(AccountStateMachineTest, AccountStateMachineTestLogoffBindSuccess017, TestSize.Level0)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. AccountStateMachine init
|
||||
* @tc.expected: step1. The current state is AccountStateMachine::ACCOUNT_STATE_UNBOUND
|
||||
*/
|
||||
AccountStateMachine stateMachine;
|
||||
EXPECT_EQ(ACCOUNT_STATE_UNBOUND, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Input the event ACCOUNT_BIND_SUCCESS_EVT
|
||||
* @tc.expected: step2. The current state is AccountStateMachine::ACCOUNT_STATE_LOGIN
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_BIND_SUCCESS_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_LOGIN, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Input the event ACCOUNT_MANUAL_LOGOFF_EVT
|
||||
* @tc.expected: step3. The current state is AccountStateMachine::ACCOUNT_STATE_LOGOFF
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_MANUAL_LOGOFF_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_LOGOFF, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step4. Input the event ACCOUNT_BIND_SUCCESS_EVT
|
||||
* @tc.expected: step4. The current state is AccountStateMachine::ACCOUNT_STATE_LOGIN
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_BIND_SUCCESS_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_LOGIN, stateMachine.GetAccountState());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountStateMachineTestLogoffInputUntreatedEvent018
|
||||
* @tc.desc: Account state machine keep the last state
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CUF5M AR000CUF5I
|
||||
*/
|
||||
HWTEST_F(AccountStateMachineTest, AccountStateMachineTestLogoffInputUntreatedEvent018, TestSize.Level0)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. AccountStateMachine init
|
||||
* @tc.expected: step1. The current state is AccountStateMachine::ACCOUNT_STATE_UNBOUND
|
||||
*/
|
||||
AccountStateMachine stateMachine;
|
||||
EXPECT_EQ(ACCOUNT_STATE_UNBOUND, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Input the event ACCOUNT_BIND_SUCCESS_EVT
|
||||
* @tc.expected: step2. The current state is AccountStateMachine::ACCOUNT_STATE_LOGIN
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_BIND_SUCCESS_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_LOGIN, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Input the event ACCOUNT_MANUAL_LOGOFF_EVT
|
||||
* @tc.expected: step3. The current state is AccountStateMachine::ACCOUNT_STATE_LOGOFF
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_MANUAL_LOGOFF_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_LOGOFF, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step4. Input the event ACCOUNT_AUTHENTICATE_FAILED_EVT
|
||||
* @tc.expected: step4. The current state is AccountStateMachine::ACCOUNT_STATE_LOGOFF
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_AUTHENTICATE_FAILED_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_LOGOFF, stateMachine.GetAccountState());
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Input the event ACCOUNT_BIND_FAILED_EVT
|
||||
* @tc.expected: step3. The current state is AccountStateMachine::ACCOUNT_STATE_LOGOFF
|
||||
*/
|
||||
EXPECT_EQ(true, stateMachine.StateChangeProcess(ACCOUNT_BIND_FAILED_EVT));
|
||||
EXPECT_EQ(ACCOUNT_STATE_LOGOFF, stateMachine.GetAccountState());
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "ohos_account_manager.h"
|
||||
#include "account_info.h"
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::AccountSA;
|
||||
class OhosAccountManagerTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
void OhosAccountManagerTest::SetUpTestCase() {}
|
||||
void OhosAccountManagerTest::TearDownTestCase() {}
|
||||
void OhosAccountManagerTest::SetUp() {}
|
||||
void OhosAccountManagerTest::TearDown() {}
|
||||
/**
|
||||
* @tc.name: OhosAccountManagerTestTokenInvalid004
|
||||
* @tc.desc: Account manager handle token invalid event test
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CUF5U AR000CUF5V SR000CUF5T
|
||||
*/
|
||||
HWTEST_F(OhosAccountManagerTest, OhosAccountManagerTestTokenInvalid004, TestSize.Level0)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. init one account
|
||||
* @tc.expected: step1. The current account state is AccountStateMachine::ACCOUNT_STATE_UNBOUND
|
||||
*/
|
||||
OhosAccountManager accountManager;
|
||||
std::string uid("TestUid");
|
||||
std::string invalidUid("NotExistUid");
|
||||
std::string name("TestName");
|
||||
accountManager.OnInitialize();
|
||||
auto ret = accountManager.LoginOhosAccount(name, uid, OHOS_ACCOUNT_EVENT_LOGIN);
|
||||
EXPECT_EQ(true, ret);
|
||||
/**
|
||||
* @tc.steps: step2. trigger token_invalid event for a different uid
|
||||
* @tc.expected: step2. process result is true AND state changes
|
||||
*/
|
||||
ret = accountManager.HandleOhosAccountTokenInvalidEvent(name, invalidUid, OHOS_ACCOUNT_EVENT_TOKEN_INVALID);
|
||||
EXPECT_EQ(true, ret);
|
||||
EXPECT_EQ(ACCOUNT_STATE_NOTLOGIN, accountManager.GetAccountState());
|
||||
/**
|
||||
* @tc.steps: step3. trigger token_invalid event with the same uid
|
||||
* @tc.expected: step3. process result is true AND state changes
|
||||
*/
|
||||
ret = accountManager.HandleOhosAccountTokenInvalidEvent(name, uid, OHOS_ACCOUNT_EVENT_TOKEN_INVALID);
|
||||
EXPECT_EQ(true, ret);
|
||||
EXPECT_EQ(ACCOUNT_STATE_NOTLOGIN, accountManager.GetAccountState());
|
||||
/**
|
||||
* @tc.steps: step4. logout the account
|
||||
* @tc.expected: step4. The current account logout
|
||||
*/
|
||||
ret = accountManager.LogoutOhosAccount(name, uid, OHOS_ACCOUNT_EVENT_LOGOUT);
|
||||
EXPECT_EQ(true, ret);
|
||||
}
|
85
services/accountmgr/test/unittest/account_mgr_stub_test/BUILD.gn
Executable file
85
services/accountmgr/test/unittest/account_mgr_stub_test/BUILD.gn
Executable file
@ -0,0 +1,85 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//base/account/os_account/os_account.gni")
|
||||
import("//build/ohos.gni")
|
||||
import("//build/test.gni")
|
||||
|
||||
module_output_path = "os_account_standard/accountmgrservice"
|
||||
|
||||
config("accountmgr_stub_test_config") {
|
||||
visibility = [ ":*" ]
|
||||
|
||||
include_dirs = [
|
||||
"./include",
|
||||
"${common_path}/log/include",
|
||||
"${common_path}/account_error/include",
|
||||
"${common_path}/perf_stat/include",
|
||||
"${services_path}/accountmgr/include",
|
||||
"${innerkits_path}/include",
|
||||
"//third_party/json/include",
|
||||
"//utils/native/base/include",
|
||||
"//utils/system/safwk/native/include",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_unittest("AccountSAMgrStubTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
sources = [
|
||||
"${common_path}/log/src/account_log_wrapper.cpp",
|
||||
"${common_path}/perf_stat/src/perf_stat.cpp",
|
||||
"${services_path}/accountmgr/src/account_dump_helper.cpp",
|
||||
"${services_path}/accountmgr/src/account_helper_data.cpp",
|
||||
"${services_path}/accountmgr/src/account_mgr_service.cpp",
|
||||
"${services_path}/accountmgr/src/account_state_machine.cpp",
|
||||
"${services_path}/accountmgr/src/account_stub.cpp",
|
||||
"${services_path}/accountmgr/src/ohos_account_data_deal.cpp",
|
||||
"${services_path}/accountmgr/src/ohos_account_manager.cpp",
|
||||
"${services_path}/accountmgr/test/mock/src/mock_account_mgr_service.cpp",
|
||||
]
|
||||
|
||||
sources += [ "account_mgr_stub_test.cpp" ]
|
||||
|
||||
configs = [
|
||||
":accountmgr_stub_test_config",
|
||||
"${services_path}/accountmgr/test:accountmgr_test_config",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//third_party/googletest:gmock_main",
|
||||
"//third_party/googletest:gtest_main",
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"aafwk_standard:base",
|
||||
"aafwk_standard:intent",
|
||||
"aafwk_standard:want",
|
||||
"appexecfwk_standard:appexecfwk_base",
|
||||
"appexecfwk_standard:appexecfwk_core",
|
||||
"hisysevent_native:libhisysevent",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr_L2:samgr_proxy",
|
||||
"startup_l2:syspara",
|
||||
]
|
||||
part_name = "os_account_standard"
|
||||
}
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
|
||||
deps = [ ":AccountSAMgrStubTest" ]
|
||||
}
|
@ -0,0 +1,142 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <ipc_types.h>
|
||||
|
||||
#include "mock_account_mgr_service.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS;
|
||||
using namespace OHOS::AccountSA;
|
||||
class AccountMgrStubTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
void AccountMgrStubTest::SetUpTestCase() {}
|
||||
|
||||
void AccountMgrStubTest::TearDownTestCase() {}
|
||||
|
||||
void AccountMgrStubTest::SetUp() {}
|
||||
|
||||
void AccountMgrStubTest::TearDown() {}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountStubQuitTipsTest001
|
||||
* @tc.desc: test QUERY_OHOS_ACCOUNT_QUIT_TIPS cmd process.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CVBCA SR000CVBC9
|
||||
*/
|
||||
HWTEST_F(AccountMgrStubTest, AccountStubQuitTipsTest001, TestSize.Level0)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. create mock instance and send QUERY_OHOS_ACCOUNT_QUIT_TIPS cmd
|
||||
* @tc.expected: step1. result success, title and content are empty
|
||||
*/
|
||||
MessageParcel inData;
|
||||
MessageParcel reply;
|
||||
MessageOption msgOption;
|
||||
MockAccountMgrService mockSrv{};
|
||||
inData.WriteInterfaceToken(AccountStub::GetDescriptor());
|
||||
auto ret = mockSrv.OnRemoteRequest(AccountStub::QUERY_OHOS_ACCOUNT_QUIT_TIPS, inData, reply, msgOption);
|
||||
EXPECT_EQ(ret, ERR_OK);
|
||||
std::u16string title = reply.ReadString16();
|
||||
std::u16string content = reply.ReadString16();
|
||||
EXPECT_EQ(true, title.empty());
|
||||
EXPECT_EQ(true, content.empty());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountStubQueryOhosInfoTest002
|
||||
* @tc.desc: test QUERY_OHOS_ACCOUNT_INFO cmd process.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CVBCC SR000CVBCB
|
||||
*/
|
||||
HWTEST_F(AccountMgrStubTest, AccountStubQueryOhosInfoTest002, TestSize.Level0)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. create mock instance and send QUERY_OHOS_ACCOUNT_QUIT_TIPS cmd
|
||||
* @tc.expected: step1. result success, title and content are not empty
|
||||
*/
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption msgOption;
|
||||
MockAccountMgrService mockSrv{};
|
||||
data.WriteInterfaceToken(AccountStub::GetDescriptor());
|
||||
auto ret = mockSrv.OnRemoteRequest(AccountStub::QUERY_OHOS_ACCOUNT_INFO, data, reply, msgOption);
|
||||
EXPECT_EQ(ret, ERR_OK);
|
||||
std::u16string name = reply.ReadString16();
|
||||
std::u16string uid = reply.ReadString16();
|
||||
std::int32_t status = reply.ReadInt32();
|
||||
EXPECT_EQ(Str16ToStr8(name), DEFAULT_OHOS_ACCOUNT_NAME);
|
||||
EXPECT_EQ(Str16ToStr8(uid), DEFAULT_OHOS_ACCOUNT_UID);
|
||||
EXPECT_EQ(status, ACCOUNT_STATE_UNBOUND);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountStubQueryDeviceAccountIdTest003
|
||||
* @tc.desc: test QUERY_DEVICE_ACCOUNT_ID_FROM_UID cmd process.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CVBCE SR000CVBCD
|
||||
*/
|
||||
HWTEST_F(AccountMgrStubTest, AccountStubQueryDeviceAccountIdTest003, TestSize.Level0)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. Init, create mock instance
|
||||
* @tc.expected: None
|
||||
*/
|
||||
MockAccountMgrService mockSrv{};
|
||||
std::int32_t testUid = 1000000;
|
||||
std::int32_t expectedId = 10;
|
||||
|
||||
MessageParcel inData;
|
||||
inData.WriteInterfaceToken(AccountStub::GetDescriptor());
|
||||
/**
|
||||
* @tc.steps: step2. write UID and send QUERY_DEVICE_ACCOUNT_ID_FROM_UID cmd
|
||||
* @tc.expected: result is ok, and expected device account id is 10: expectedId = testUid/100000
|
||||
*/
|
||||
inData.WriteInt32(testUid);
|
||||
MessageParcel outData;
|
||||
MessageOption option;
|
||||
auto ret = mockSrv.OnRemoteRequest(AccountStub::QUERY_DEVICE_ACCOUNT_ID_FROM_UID, inData, outData, option);
|
||||
EXPECT_EQ(ret, ERR_OK);
|
||||
auto result = outData.ReadInt32();
|
||||
EXPECT_EQ(result, expectedId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountStubInvalidCmdTest004
|
||||
* @tc.desc: test INVALID cmd process.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CUF5N SR000CUF5L
|
||||
*/
|
||||
HWTEST_F(AccountMgrStubTest, AccountStubInvalidCmdTest004, TestSize.Level0)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. Init, create mock instance and send an invalid cmd
|
||||
* @tc.expected: result is failure
|
||||
*/
|
||||
MessageParcel inData;
|
||||
MessageParcel outData;
|
||||
MessageOption msgOption;
|
||||
MockAccountMgrService mockSrv{};
|
||||
inData.WriteInterfaceToken(AccountStub::GetDescriptor());
|
||||
auto ret = mockSrv.OnRemoteRequest(0, inData, outData, msgOption);
|
||||
EXPECT_NE(ret, ERR_OK);
|
||||
}
|
63
services/accountmgr/test/unittest/ohos_account_data_deal_test/BUILD.gn
Executable file
63
services/accountmgr/test/unittest/ohos_account_data_deal_test/BUILD.gn
Executable file
@ -0,0 +1,63 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//base/account/os_account/os_account.gni")
|
||||
import("//build/ohos.gni")
|
||||
import("//build/test.gni")
|
||||
|
||||
module_output_path = "os_account_standard/accountmgrservice"
|
||||
|
||||
config("accountmgr_data_deal_test_config") {
|
||||
include_dirs = [
|
||||
"./include",
|
||||
"${common_path}/log/include",
|
||||
"${common_path}/account_error/include",
|
||||
"${services_path}/accountmgr/include",
|
||||
"//third_party/json/include",
|
||||
"${innerkits_path}/include",
|
||||
"//utils/native/base/include",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_unittest("AccountSADataDealTest") {
|
||||
module_out_path = module_output_path
|
||||
resource_config_file =
|
||||
"${os_account_path}/test/resource/accountmgrservice/ohos_test.xml"
|
||||
|
||||
sources = [
|
||||
"${common_path}/log/src/account_log_wrapper.cpp",
|
||||
"${services_path}/accountmgr/src/ohos_account_data_deal.cpp",
|
||||
]
|
||||
|
||||
sources += [ "ohos_account_data_deal_test.cpp" ]
|
||||
|
||||
configs = [
|
||||
":accountmgr_data_deal_test_config",
|
||||
"${services_path}/accountmgr/test:accountmgr_test_config",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//third_party/googletest:gmock_main",
|
||||
"//third_party/googletest:gtest_main",
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
|
||||
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
|
||||
part_name = "os_account_standard"
|
||||
}
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
|
||||
deps = [ ":AccountSADataDealTest" ]
|
||||
}
|
@ -0,0 +1,172 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <fstream>
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <iostream>
|
||||
|
||||
#include "account_error_no.h"
|
||||
#include "account_info.h"
|
||||
#include "account_log_wrapper.h"
|
||||
#include "ohos_account_data_deal.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS;
|
||||
using namespace OHOS::AccountSA;
|
||||
|
||||
namespace {
|
||||
const std::string RESOURCE_ROOT_PATH = "/data/test/account/data_deal/";
|
||||
const std::string ACCOUNT_SUFFIX = ".json";
|
||||
const std::string TEST_STR_ACCOUNT_NAME = "incubation";
|
||||
const std::string TEST_STR_OPEN_ID = "test open id";
|
||||
}
|
||||
|
||||
class OhosAccountDataDealTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
|
||||
static void TearDownTestCase();
|
||||
|
||||
void SetUp();
|
||||
|
||||
void TearDown();
|
||||
|
||||
protected:
|
||||
std::ostringstream pathStream_;
|
||||
};
|
||||
|
||||
void OhosAccountDataDealTest::SetUpTestCase() {}
|
||||
|
||||
void OhosAccountDataDealTest::TearDownTestCase() {}
|
||||
|
||||
void OhosAccountDataDealTest::SetUp() {}
|
||||
|
||||
void OhosAccountDataDealTest::TearDown()
|
||||
{
|
||||
pathStream_.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: OhosAccountJsonNotInitTest001
|
||||
* @tc.desc: Test invalid event publish
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CUF55
|
||||
*/
|
||||
HWTEST_F(OhosAccountDataDealTest, OhosAccountJsonNotInitTest001, TestSize.Level0)
|
||||
{
|
||||
AccountInfo accountInfo;
|
||||
pathStream_ << RESOURCE_ROOT_PATH << "test" << ACCOUNT_SUFFIX;
|
||||
|
||||
/**
|
||||
* @tc.steps: step1. init json object
|
||||
*/
|
||||
OhosAccountDataDeal dataDeal(pathStream_.str());
|
||||
ErrCode errCode = dataDeal.AccountInfoFromJson(accountInfo);
|
||||
EXPECT_EQ(errCode, ERR_ACCOUNT_DATADEAL_NOT_READY);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: OhosAccountJsonCreateDefaultJsonFileTest002
|
||||
* @tc.desc: Test invalid event publish
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CUF6P
|
||||
*/
|
||||
HWTEST_F(OhosAccountDataDealTest, OhosAccountJsonCreateDefaultJsonFileTest002, TestSize.Level0)
|
||||
{
|
||||
AccountInfo accountInfo;
|
||||
ErrCode errCode = ERR_OK;
|
||||
pathStream_ << RESOURCE_ROOT_PATH << "not_exist" << ACCOUNT_SUFFIX;
|
||||
|
||||
/**
|
||||
* @tc.steps: step1. init json object
|
||||
*/
|
||||
OhosAccountDataDeal dataDeal(pathStream_.str());
|
||||
errCode = dataDeal.Init();
|
||||
EXPECT_EQ(errCode, ERR_OK);
|
||||
|
||||
errCode = dataDeal.AccountInfoFromJson(accountInfo);
|
||||
EXPECT_EQ(errCode, ERR_OK);
|
||||
EXPECT_EQ(accountInfo.ohosAccountStatus_, ACCOUNT_STATE_UNBOUND);
|
||||
EXPECT_EQ(accountInfo.ohosAccountName_, DEFAULT_OHOS_ACCOUNT_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: OhosAccountInvalidFileNameTest003
|
||||
* @tc.desc: Test invalid event publish
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CUF6Q
|
||||
*/
|
||||
HWTEST_F(OhosAccountDataDealTest, OhosAccountInvalidFileNameTest003, TestSize.Level0)
|
||||
{
|
||||
AccountInfo accountInfo;
|
||||
accountInfo.ohosAccountStatus_ = ACCOUNT_STATE_UNBOUND;
|
||||
ErrCode errCode = ERR_OK;
|
||||
pathStream_ << RESOURCE_ROOT_PATH << "invalid_format" << ACCOUNT_SUFFIX;
|
||||
|
||||
/**
|
||||
* @tc.steps: step1. init json object
|
||||
*/
|
||||
OhosAccountDataDeal dataDeal(pathStream_.str());
|
||||
errCode = dataDeal.Init();
|
||||
EXPECT_NE(errCode, ERR_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: OhosAccountJsonFileWriteTest004
|
||||
* @tc.desc: Test invalid event publish
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000CUF55
|
||||
*/
|
||||
HWTEST_F(OhosAccountDataDealTest, OhosAccountJsonFileWriteTest004, TestSize.Level0)
|
||||
{
|
||||
AccountInfo accountInfo;
|
||||
ErrCode errCode = ERR_OK;
|
||||
pathStream_ << RESOURCE_ROOT_PATH << "valid" << ACCOUNT_SUFFIX;
|
||||
|
||||
/**
|
||||
* @tc.steps: step1. init json object
|
||||
*/
|
||||
OhosAccountDataDeal dataDeal(pathStream_.str());
|
||||
|
||||
errCode = dataDeal.Init();
|
||||
EXPECT_EQ(errCode, ERR_OK);
|
||||
errCode = dataDeal.AccountInfoFromJson(accountInfo);
|
||||
EXPECT_EQ(errCode, ERR_OK);
|
||||
EXPECT_EQ(accountInfo.ohosAccountStatus_, ACCOUNT_STATE_UNBOUND);
|
||||
EXPECT_EQ(accountInfo.ohosAccountName_, TEST_STR_ACCOUNT_NAME);
|
||||
EXPECT_EQ(accountInfo.ohosAccountUid_, TEST_STR_OPEN_ID);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. update json object
|
||||
*/
|
||||
accountInfo.ohosAccountStatus_ = ACCOUNT_STATE_NOTLOGIN;
|
||||
accountInfo.ohosAccountName_ = TEST_STR_ACCOUNT_NAME;
|
||||
accountInfo.ohosAccountUid_ = TEST_STR_OPEN_ID;
|
||||
dataDeal.AccountInfoToJson(accountInfo);
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. read json object and validate info
|
||||
*/
|
||||
OhosAccountDataDeal dataDealNew(pathStream_.str());
|
||||
errCode = dataDealNew.Init();
|
||||
EXPECT_EQ(errCode, ERR_OK);
|
||||
AccountInfo accountInfoNew;
|
||||
errCode = dataDeal.AccountInfoFromJson(accountInfoNew);
|
||||
EXPECT_EQ(errCode, ERR_OK);
|
||||
EXPECT_EQ(accountInfoNew.ohosAccountStatus_, ACCOUNT_STATE_NOTLOGIN);
|
||||
EXPECT_EQ(accountInfoNew.ohosAccountName_, TEST_STR_ACCOUNT_NAME);
|
||||
EXPECT_EQ(accountInfoNew.ohosAccountUid_, TEST_STR_OPEN_ID);
|
||||
}
|
0
test/resource/accountmgrservice/data_deal/empty.json
Executable file
0
test/resource/accountmgrservice/data_deal/empty.json
Executable file
1
test/resource/accountmgrservice/data_deal/invalid_format.json
Executable file
1
test/resource/accountmgrservice/data_deal/invalid_format.json
Executable file
@ -0,0 +1 @@
|
||||
1223243234234
|
1
test/resource/accountmgrservice/data_deal/valid.json
Normal file
1
test/resource/accountmgrservice/data_deal/valid.json
Normal file
@ -0,0 +1 @@
|
||||
{"account_name":"incubation","bind_status":0,"bind_time":0,"digest":[45,145,50,8,135,116,146,201,87,221,139,68,62,143,171,47,73,238,251,120,110,1],"openId":"test open id","uid":0}
|
21
test/resource/accountmgrservice/ohos_test.xml
Executable file
21
test/resource/accountmgrservice/ohos_test.xml
Executable file
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<configuration ver="2.0">
|
||||
<target name="AccountSADataDealTest">
|
||||
<preparer>
|
||||
<option name="push" value="data_deal/. -> /data/test/account/data_deal/" src="res"/>
|
||||
</preparer>
|
||||
</target>
|
||||
</configuration>
|
Loading…
Reference in New Issue
Block a user