mirror of
https://github.com/openharmony/notification_ans_standard.git
synced 2026-06-30 21:57:55 -04:00
Update framework struct and add new function
Signed-off-by: chensi10 <chen.s@neusoft.com>
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
# 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.gni")
|
||||
@@ -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
|
||||
@@ -0,0 +1,70 @@
|
||||
<?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.
|
||||
|
||||
Notes:
|
||||
This is project config file for OpenHarmony OSS Audit Tool, if you have any questions or concerns, please email chenyaxun@huawei.com.
|
||||
-->
|
||||
<!-- OAT(OSS Audit Tool) configuration guide:
|
||||
basedir: Root dir, the basedir + project path is the real source file location.
|
||||
licensefile:
|
||||
1.If the project don't have "LICENSE" in root dir, please define all the license files in this project in , OAT will check license files according to this rule.
|
||||
|
||||
tasklist(only for batch mode):
|
||||
1. task: Define oat check thread, each task will start a new thread.
|
||||
2. task name: Only an name, no practical effect.
|
||||
3. task policy: Default policy for projects under this task, this field is required and the specified policy must defined in policylist.
|
||||
4. task filter: Default filefilter for projects under this task, this field is required and the specified filefilter must defined in filefilterlist.
|
||||
5. task project: Projects to be checked, the path field define the source root dir of the project.
|
||||
|
||||
|
||||
policyList:
|
||||
1. policy: All policyitems will be merged to default OAT.xml rules, the name of policy doesn't affect OAT check process.
|
||||
2. policyitem: The fields type, name, path, desc is required, and the fields rule, group, filefilter is optional,the default value is:
|
||||
<policyitem type="" name="" path="" desc="" rule="may" group="defaultGroup" filefilter="defaultPolicyFilter"/>
|
||||
3. policyitem type:
|
||||
"compatibility" is used to check license compatibility in the specified path;
|
||||
"license" is used to check source license header in the specified path;
|
||||
"copyright" is used to check source copyright header in the specified path;
|
||||
"import" is used to check source dependency in the specified path, such as import ... ,include ...
|
||||
"filetype" is used to check file type in the specified path, supported file types: archive, binary
|
||||
"filename" is used to check whether the specified file exists in the specified path(support projectroot in default OAT.xml), supported file names: LICENSE, README, README.OpenSource
|
||||
|
||||
4. policyitem name: This field is used for define the license, copyright, "*" means match all, the "!" prefix means could not match this value. For example, "!GPL" means can not use GPL license.
|
||||
5. policyitem path: This field is used for define the source file scope to apply this policyitem, the "!" prefix means exclude the files. For example, "!.*/lib/.*" means files in lib dir will be exclude while process this policyitem.
|
||||
6. policyitem rule and group: These two fields are used together to merge policy results. "may" policyitems in the same group means any one in this group passed, the result will be passed.
|
||||
7. policyitem filefilter: Used to bind filefilter which define filter rules.
|
||||
8. filefilter: Filter rules, the type filename is used to filter file name, the type filepath is used to filter file path.
|
||||
|
||||
Note:If the text contains special characters, please escape them according to the following rules:
|
||||
" == >
|
||||
& == >
|
||||
' == >
|
||||
< == >
|
||||
> == >
|
||||
-->
|
||||
<configuration>
|
||||
<oatconfig>
|
||||
<licensefile></licensefile>
|
||||
<policylist>
|
||||
<policy name="projectPolicy" desc="">
|
||||
</policy>
|
||||
</policylist>
|
||||
<filefilterlist>
|
||||
<filefilter name="defaultFilter" desc="Files not to check">
|
||||
<filteritem type="filename" name="*.hap|*.rpk" desc="valid and invalid bundle files for tests"/>
|
||||
</filefilter>
|
||||
</filefilterlist>
|
||||
</oatconfig>
|
||||
</configuration>
|
||||
@@ -1,36 +0,0 @@
|
||||
# notification_ans_standard
|
||||
|
||||
#### Description
|
||||
{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**}
|
||||
|
||||
#### 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/)
|
||||
@@ -1,39 +0,0 @@
|
||||
# notification_ans_standard
|
||||
|
||||
#### 介绍
|
||||
{**以下是 Gitee 平台说明,您可以替换此简介**
|
||||
Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台
|
||||
无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)}
|
||||
|
||||
#### 软件架构
|
||||
软件架构说明
|
||||
|
||||
|
||||
#### 安装教程
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
|
||||
#### 使用说明
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
|
||||
#### 参与贡献
|
||||
|
||||
1. Fork 本仓库
|
||||
2. 新建 Feat_xxx 分支
|
||||
3. 提交代码
|
||||
4. 新建 Pull Request
|
||||
|
||||
|
||||
#### 特技
|
||||
|
||||
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/)
|
||||
@@ -0,0 +1,48 @@
|
||||
# 事件通知子系统
|
||||
|
||||
## 简介
|
||||
|
||||
OpenHarmony通过ANS(Advanced Notification Service,通知系统服务)对通知类型的消息进行管理,支持多种通知类型,包括文本,长文本,多文本,图片,社交,媒体等。所有系统服务以及应用都可以通过通知接口发送通知消息,用户可以通过SystemUI系统APP查看所有通知消息。 为应用程序提供订阅、发布、取消订阅的能力。
|
||||
|
||||
通知常见的使用场景:
|
||||
|
||||
- 显示接收到短消息、即时消息等。
|
||||
- 显示应用的推送消息,如广告、版本更新等。
|
||||
- 显示当前正在进行的事件,如播放音乐、导航、下载等。
|
||||
|
||||
### 架构图
|
||||
|
||||

|
||||
|
||||
## 目录
|
||||
|
||||
```
|
||||
/base/notification/ans_standard/
|
||||
├── innerkits # 对内接口目录
|
||||
├── kits # 对外接口目录
|
||||
├── sa_profile # 组件服务配置
|
||||
├── services # 组件服务实现
|
||||
├── tools # 组件工具实现
|
||||
│── ohos.build # 组件编译脚本
|
||||
|
||||
```
|
||||
|
||||
## 使用说明
|
||||
|
||||
以下模块的JS接口为非正式API,仅供SystemUI等系统应用使用,不排除对这些接口进行变更的可能性,后续版本将提供正式API。
|
||||
|
||||
- notificationSlot.d.ts
|
||||
- notificationRequest.d.ts
|
||||
- notificationContent.d.ts
|
||||
- notificationActionButton.ts
|
||||
- triggerInfo.d.ts
|
||||
- wantAgentInfo.d.ts
|
||||
- @ohos.notification.d.ts
|
||||
- @ohos.wantAgent.d.ts
|
||||
|
||||
## 相关仓
|
||||
|
||||
事件通知子系统
|
||||
|
||||
**notification_ans_standard**
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 60 KiB |
@@ -0,0 +1,89 @@
|
||||
# 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/notification/ans_standard/notification.gni")
|
||||
import("//build/ohos.gni")
|
||||
|
||||
ANS_STANDARD_INNERKITS_CORE_PATH = "${innerkits_path}/core"
|
||||
ANS_STANDARD_INNERKITS_BASE_PATH = "${innerkits_path}/base"
|
||||
|
||||
group("innerkits_target") {
|
||||
deps = [ ":ans_innerkits" ]
|
||||
}
|
||||
|
||||
config("private_config") {
|
||||
include_dirs = [ "//utils/system/safwk/native/include" ]
|
||||
}
|
||||
|
||||
config("public_ans_innerkits_config") {
|
||||
include_dirs = [
|
||||
"${ANS_STANDARD_INNERKITS_CORE_PATH}/include",
|
||||
"${ANS_STANDARD_INNERKITS_BASE_PATH}/include",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/base/include",
|
||||
"${kits_path}/native/include",
|
||||
"//utils/native/base/include",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_shared_library("ans_innerkits") {
|
||||
sources = [
|
||||
"${ANS_STANDARD_INNERKITS_BASE_PATH}/src/ans_log_wrapper.cpp",
|
||||
"${ANS_STANDARD_INNERKITS_CORE_PATH}/src/ans_manager_death_recipient.cpp",
|
||||
"${ANS_STANDARD_INNERKITS_CORE_PATH}/src/ans_manager_proxy.cpp",
|
||||
"${ANS_STANDARD_INNERKITS_CORE_PATH}/src/ans_manager_stub.cpp",
|
||||
"${ANS_STANDARD_INNERKITS_CORE_PATH}/src/ans_notification.cpp",
|
||||
"${ANS_STANDARD_INNERKITS_CORE_PATH}/src/ans_subscriber_proxy.cpp",
|
||||
"${ANS_STANDARD_INNERKITS_CORE_PATH}/src/ans_subscriber_stub.cpp",
|
||||
"${kits_path}/native/src/message_user.cpp",
|
||||
"${kits_path}/native/src/notification.cpp",
|
||||
"${kits_path}/native/src/notification_action_button.cpp",
|
||||
"${kits_path}/native/src/notification_basic_content.cpp",
|
||||
"${kits_path}/native/src/notification_constant.cpp",
|
||||
"${kits_path}/native/src/notification_content.cpp",
|
||||
"${kits_path}/native/src/notification_conversational_content.cpp",
|
||||
"${kits_path}/native/src/notification_conversational_message.cpp",
|
||||
"${kits_path}/native/src/notification_helper.cpp",
|
||||
"${kits_path}/native/src/notification_long_text_content.cpp",
|
||||
"${kits_path}/native/src/notification_media_content.cpp",
|
||||
"${kits_path}/native/src/notification_multiline_content.cpp",
|
||||
"${kits_path}/native/src/notification_normal_content.cpp",
|
||||
"${kits_path}/native/src/notification_picture_content.cpp",
|
||||
"${kits_path}/native/src/notification_request.cpp",
|
||||
"${kits_path}/native/src/notification_slot.cpp",
|
||||
"${kits_path}/native/src/notification_slot_group.cpp",
|
||||
"${kits_path}/native/src/notification_sorting.cpp",
|
||||
"${kits_path}/native/src/notification_sorting_map.cpp",
|
||||
"${kits_path}/native/src/notification_subscribe_info.cpp",
|
||||
"${kits_path}/native/src/notification_subscriber.cpp",
|
||||
"${kits_path}/native/src/notification_user_input.cpp",
|
||||
]
|
||||
|
||||
configs = [ ":private_config" ]
|
||||
|
||||
public_configs = [ ":public_ans_innerkits_config" ]
|
||||
|
||||
deps = [
|
||||
"${kits_path}/native/wantagent:wantagent_kits",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/want:want",
|
||||
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"samgr_L2:samgr_proxy",
|
||||
]
|
||||
|
||||
part_name = "ans_standard"
|
||||
subsystem_name = "notification"
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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_NOTIFICATION_ANS_STANDARD_INNERKITS_BASE_INCLUDE_ANS_CONST_DEFINE_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_INNERKITS_BASE_INCLUDE_ANS_CONST_DEFINE_H
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
|
||||
// Max active notification number
|
||||
constexpr uint32_t MAX_ACTIVE_NUM = 1024 * 1024;
|
||||
constexpr uint32_t MAX_SLOT_NUM = 5;
|
||||
constexpr uint32_t MAX_SLOT_GROUP_NUM = 4;
|
||||
constexpr int32_t ANS_UID = 1000;
|
||||
constexpr int32_t ANS_GID = 1000;
|
||||
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_INNERKITS_BASE_INCLUDE_ANS_CONST_DEFINE_H
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
#ifndef BASE_NOTIFICATION_ANS_STANDARD_INNERKITS_BASE_INCLUDE_ANS_INNER_ERRORS_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_INNERKITS_BASE_INCLUDE_ANS_INNER_ERRORS_H
|
||||
|
||||
#include "errors.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
/**
|
||||
* ErrCode layout
|
||||
*
|
||||
* +-----+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
* | Bit |31|30|29|28|27|26|25|24|23|22|21|20|19|18|17|16|15|14|13|12|11|10|09|08|07|06|05|04|03|02|01|00|
|
||||
* +-----+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
* |Field|Reserved| Subsystem | Module | Code |
|
||||
* +-----+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
*/
|
||||
|
||||
constexpr uint32_t EVENT_SUB_MODULE_OFFSET = 8; // sub-module offset value
|
||||
|
||||
// ANS's module const defined.
|
||||
enum AnsModule : uint32_t {
|
||||
ANS_MODULE_COMMON = 0x00,
|
||||
};
|
||||
|
||||
// Offset of common event sub-system's errcode base.
|
||||
constexpr ErrCode ANS_COMMON_ERR_OFFSET = ErrCodeOffset(SUBSYS_NOTIFICATION, ANS_MODULE_COMMON);
|
||||
|
||||
// Error code defined.
|
||||
enum ErrorCode : uint32_t {
|
||||
ERR_ANS_SERVICE_NOT_READY = ANS_COMMON_ERR_OFFSET + 1,
|
||||
ERR_ANS_SERVICE_NOT_CONNECTED,
|
||||
ERR_ANS_INVALID_PARAM,
|
||||
ERR_ANS_INVALID_UID,
|
||||
ERR_ANS_INVALID_PID,
|
||||
ERR_ANS_NOT_ALLOWED,
|
||||
ERR_ANS_PARCELABLE_FAILED,
|
||||
ERR_ANS_TRANSACT_FAILED,
|
||||
ERR_ANS_REMOTE_DEAD,
|
||||
ERR_ANS_NO_MEMORY,
|
||||
ERR_ANS_TASK_ERR,
|
||||
ERR_ANS_NON_SYSTEM_APP,
|
||||
ERR_ANS_NOTIFICATION_NOT_EXISTS,
|
||||
ERR_ANS_NOTIFICATION_IS_UNREMOVABLE,
|
||||
|
||||
ERR_ANS_PREFERENCES_FILE_IS_NULL,
|
||||
ERR_ANS_PREFERENCES_FILE_DOES_NOT_OPEN,
|
||||
ERR_ANS_PREFERENCES_FILE_EXCEPTION,
|
||||
ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_NOT_EXIST,
|
||||
ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST,
|
||||
ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_ID_INVALID,
|
||||
ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_TYPE_NOT_EXIST,
|
||||
ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_EXCEED_MAX_NUM,
|
||||
ERR_ANS_PREFERENCES_NOTIFICATION_SLOTGROUP_NOT_EXIST,
|
||||
ERR_ANS_PREFERENCES_NOTIFICATION_SLOTGROUP_HAS_EXISTED,
|
||||
ERR_ANS_PREFERENCES_NOTIFICATION_SLOTGROUP_ID_INVALID,
|
||||
ERR_ANS_PREFERENCES_NOTIFICATION_SLOTGROUP_EXCEED_MAX_NUM,
|
||||
};
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_INNERKITS_BASE_INCLUDE_ANS_INNER_ERRORS_H
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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_NOTIFICATION_ANS_STANDARD_INNERKITS_BASE_INCLUDE_ANS_LOG_HELPER_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_INNERKITS_BASE_INCLUDE_ANS_LOG_HELPER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "hilog/log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
|
||||
#ifndef LOG_DOMAIN
|
||||
#define LOG_DOMAIN 0xD001800
|
||||
#endif
|
||||
|
||||
#ifndef ANS_LOG_TAG
|
||||
#define ANS_LOG_TAG NULL
|
||||
#endif
|
||||
|
||||
enum class AnsLogLevel : uint8_t { DEBUG = 0, INFO, WARN, ERROR, FATAL };
|
||||
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel ANS_LABEL = {LOG_CORE, LOG_DOMAIN, "ANS_STANDARD"};
|
||||
|
||||
class AnsLogWrapper {
|
||||
public:
|
||||
AnsLogWrapper() = delete;
|
||||
~AnsLogWrapper() = delete;
|
||||
|
||||
static bool JudgeLevel(const AnsLogLevel &level);
|
||||
|
||||
static void SetLogLevel(const AnsLogLevel &level)
|
||||
{
|
||||
level_ = level;
|
||||
}
|
||||
|
||||
static const AnsLogLevel &GetLogLevel()
|
||||
{
|
||||
return level_;
|
||||
}
|
||||
|
||||
static std::string GetBriefFileName(const char *str);
|
||||
|
||||
private:
|
||||
static AnsLogLevel level_;
|
||||
};
|
||||
|
||||
#define PRINT_LOG(LEVEL, Level, fmt, ...) \
|
||||
if (AnsLogWrapper::JudgeLevel(AnsLogLevel::LEVEL)) \
|
||||
OHOS::HiviewDFX::HiLog::Level(ANS_LABEL, \
|
||||
"[%{public}s(%{public}s):%{public}d] " fmt, \
|
||||
AnsLogWrapper::GetBriefFileName(__FILE__).c_str(), \
|
||||
__FUNCTION__, \
|
||||
__LINE__, \
|
||||
##__VA_ARGS__)
|
||||
|
||||
#define ANS_LOGD(fmt, ...) PRINT_LOG(DEBUG, Debug, fmt, ##__VA_ARGS__)
|
||||
#define ANS_LOGI(fmt, ...) PRINT_LOG(INFO, Info, fmt, ##__VA_ARGS__)
|
||||
#define ANS_LOGW(fmt, ...) PRINT_LOG(WARN, Warn, fmt, ##__VA_ARGS__)
|
||||
#define ANS_LOGE(fmt, ...) PRINT_LOG(ERROR, Error, fmt, ##__VA_ARGS__)
|
||||
#define ANS_LOGF(fmt, ...) PRINT_LOG(FATAL, Fatal, fmt, ##__VA_ARGS__)
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_INNERKITS_BASE_INCLUDE_ANS_LOG_HELPER_H
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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 "ans_log_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
AnsLogLevel AnsLogWrapper::level_ = {AnsLogLevel::DEBUG};
|
||||
bool AnsLogWrapper::JudgeLevel(const AnsLogLevel &level)
|
||||
{
|
||||
const AnsLogLevel &curLevel = AnsLogWrapper::GetLogLevel();
|
||||
if (level < curLevel) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string AnsLogWrapper::GetBriefFileName(const char *str)
|
||||
{
|
||||
if (!str) {
|
||||
return std::string();
|
||||
}
|
||||
std::string fullPath(str);
|
||||
size_t pos = fullPath.find_last_of("/");
|
||||
if (pos == std::string::npos) {
|
||||
return std::string();
|
||||
}
|
||||
return fullPath.substr(pos + 1);
|
||||
}
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_DEATH_RECIPIENT_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_DEATH_RECIPIENT_H
|
||||
|
||||
#include "iremote_object.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
class AnsManagerDeathRecipient : public IRemoteObject::DeathRecipient {
|
||||
public:
|
||||
AnsManagerDeathRecipient() = default;
|
||||
|
||||
virtual ~AnsManagerDeathRecipient() = default;
|
||||
|
||||
virtual void OnRemoteDied(const wptr<IRemoteObject> &object) override;
|
||||
};
|
||||
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* 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_NOTIFICATION_ANS_STANDARD_INNERKITS_CORE_INCLUDE_ANS_MANAGER_INTERFACE_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_INNERKITS_CORE_INCLUDE_ANS_MANAGER_INTERFACE_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "ans_subscriber_interface.h"
|
||||
#include "iremote_broker.h"
|
||||
#include "notification_constant.h"
|
||||
#include "notification_request.h"
|
||||
#include "notification_slot.h"
|
||||
#include "notification_slot_group.h"
|
||||
#include "notification_sorting.h"
|
||||
#include "notification_subscribe_info.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
class IAnsManager : public IRemoteBroker {
|
||||
public:
|
||||
IAnsManager() = default;
|
||||
virtual ~IAnsManager() override = default;
|
||||
DISALLOW_COPY_AND_MOVE(IAnsManager);
|
||||
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Notification.IAnsManager");
|
||||
|
||||
virtual ErrCode Publish(const std::string &label, const sptr<NotificationRequest> ¬ification) = 0;
|
||||
virtual ErrCode PublishToDevice(const sptr<NotificationRequest> ¬ification, const std::string &deviceId) = 0;
|
||||
virtual ErrCode Cancel(int notificationId, const std::string &label) = 0;
|
||||
virtual ErrCode CancelAll() = 0;
|
||||
virtual ErrCode AddSlots(const std::vector<sptr<NotificationSlot>> &slots) = 0;
|
||||
virtual ErrCode RemoveSlots(const std::vector<std::string> &slotIds) = 0;
|
||||
virtual ErrCode RemoveSlotByType(const NotificationConstant::SlotType slotType) = 0;
|
||||
virtual ErrCode AddSlotGroups(std::vector<sptr<NotificationSlotGroup>> groups) = 0;
|
||||
virtual ErrCode GetSlot(const std::string &slotId, sptr<NotificationSlot> &slot) = 0;
|
||||
virtual ErrCode GetSlotByType(const NotificationConstant::SlotType slotType, sptr<NotificationSlot> &slot) = 0;
|
||||
virtual ErrCode GetSlots(std::vector<sptr<NotificationSlot>> &slots) = 0;
|
||||
virtual ErrCode GetSlotGroup(const std::string &groupId, sptr<NotificationSlotGroup> &group) = 0;
|
||||
virtual ErrCode GetSlotGroups(std::vector<sptr<NotificationSlotGroup>> &groups) = 0;
|
||||
virtual ErrCode RemoveSlotGroups(const std::vector<std::string> &groupIds) = 0;
|
||||
virtual ErrCode GetActiveNotifications(std::vector<sptr<NotificationRequest>> ¬ifications) = 0;
|
||||
virtual ErrCode GetActiveNotificationNums(int &num) = 0;
|
||||
virtual ErrCode GetAllActiveNotifications(std::vector<sptr<Notification>> ¬ifications) = 0;
|
||||
virtual ErrCode GetSpecialActiveNotifications(
|
||||
const std::vector<std::string> &key, std::vector<sptr<Notification>> ¬ifications) = 0;
|
||||
virtual ErrCode SetNotificationAgent(const std::string &agent) = 0;
|
||||
virtual ErrCode GetNotificationAgent(std::string &agent) = 0;
|
||||
virtual ErrCode CanPublishAsBundle(const std::string &representativeBundle, bool &canPublish) = 0;
|
||||
virtual ErrCode PublishAsBundle(
|
||||
const sptr<NotificationRequest> notification, const std::string &representativeBundle) = 0;
|
||||
virtual ErrCode SetNotificationBadgeNum(int num) = 0;
|
||||
virtual ErrCode GetBundleImportance(int &importance) = 0;
|
||||
virtual ErrCode SetDisturbMode(NotificationConstant::DisturbMode mode) = 0;
|
||||
virtual ErrCode GetDisturbMode(NotificationConstant::DisturbMode &mode) = 0;
|
||||
virtual ErrCode HasNotificationPolicyAccessPermission(bool &granted) = 0;
|
||||
virtual ErrCode SetPrivateNotificationsAllowed(bool allow) = 0;
|
||||
virtual ErrCode GetPrivateNotificationsAllowed(bool &allow) = 0;
|
||||
virtual ErrCode Delete(const std::string &key) = 0;
|
||||
virtual ErrCode DeleteByBundle(const std::string &bundle) = 0;
|
||||
virtual ErrCode DeleteAll() = 0;
|
||||
virtual ErrCode GetSlotsByBundle(const std::string &bundle, std::vector<sptr<NotificationSlot>> &slots) = 0;
|
||||
virtual ErrCode UpdateSlots(const std::string &bundle, const std::vector<sptr<NotificationSlot>> &slots) = 0;
|
||||
virtual ErrCode UpdateSlotGroups(
|
||||
const std::string &bundle, const std::vector<sptr<NotificationSlotGroup>> &groups) = 0;
|
||||
virtual ErrCode SetNotificationsEnabledForBundle(const std::string &deviceId, bool enabled) = 0;
|
||||
virtual ErrCode SetNotificationsEnabledForAllBundles(const std::string &deviceId, bool enabled) = 0;
|
||||
virtual ErrCode SetNotificationsEnabledForSpecialBundle(
|
||||
const std::string &deviceId, const std::string &bundleName, bool enabled) = 0;
|
||||
virtual ErrCode SetShowBadgeEnabledForBundle(const std::string &bundle, bool enabled) = 0;
|
||||
virtual ErrCode GetShowBadgeEnabledForBundle(const std::string &bundle, bool &enabled) = 0;
|
||||
virtual ErrCode Subscribe(const sptr<IAnsSubscriber> &subscriber, const sptr<NotificationSubscribeInfo> &info) = 0;
|
||||
virtual ErrCode Unsubscribe(
|
||||
const sptr<IAnsSubscriber> &subscriber, const sptr<NotificationSubscribeInfo> &info) = 0;
|
||||
virtual ErrCode AreNotificationsSuspended(bool &suspended) = 0;
|
||||
virtual ErrCode GetCurrentAppSorting(sptr<NotificationSortingMap> &sortingMap) = 0;
|
||||
virtual ErrCode IsAllowedNotify(bool &allowed) = 0;
|
||||
virtual ErrCode IsSpecialBundleAllowedNotify(const std::string &bundle, bool &allowed) = 0;
|
||||
|
||||
protected:
|
||||
enum TransactId : uint32_t {
|
||||
PUBLISH_NOTIFICATION = FIRST_CALL_TRANSACTION,
|
||||
PUBLISH_NOTIFICATION_TO_DEVICE,
|
||||
CANCEL_NOTIFICATION,
|
||||
CANCEL_ALL_NOTIFICATIONS,
|
||||
ADD_SLOTS,
|
||||
REMOVE_SLOTS,
|
||||
REMOVE_SLOT_BY_TYPE,
|
||||
ADD_SLOT_GROUPS,
|
||||
GET_SLOT,
|
||||
GET_SLOT_BY_TYPE,
|
||||
GET_SLOTS,
|
||||
GET_SLOT_GROUP,
|
||||
GET_SLOT_GROUPS,
|
||||
REMOVE_SLOT_GROUPS,
|
||||
GET_ACTIVE_NOTIFICATIONS,
|
||||
GET_ACTIVE_NOTIFICATION_NUMS,
|
||||
GET_ALL_ACTIVE_NOTIFICATIONS,
|
||||
GET_SPECIAL_ACTIVE_NOTIFICATIONS,
|
||||
SET_NOTIFICATION_AGENT,
|
||||
GET_NOTIFICATION_AGENT,
|
||||
CAN_PUBLISH_AS_BUNDLE,
|
||||
PUBLISH_AS_BUNDLE,
|
||||
SET_NOTIFICATION_BADGE_NUM,
|
||||
GET_BUNDLE_IMPORTANCE,
|
||||
SET_DISTURB_MODE,
|
||||
GET_DISTURB_MODE,
|
||||
IS_NOTIFICATION_POLICY_ACCESS_GRANTED,
|
||||
SET_PRIVATIVE_NOTIFICATIONS_ALLOWED,
|
||||
GET_PRIVATIVE_NOTIFICATIONS_ALLOWED,
|
||||
DELETE_NOTIFICATION,
|
||||
DELETE_NOTIFICATION_BY_BUNDLE,
|
||||
DELETE_ALL_NOTIFICATIONS,
|
||||
GET_SLOTS_BY_BUNDLE,
|
||||
UPDATE_SLOTS,
|
||||
UPDATE_SLOT_GROUPS,
|
||||
SET_NOTIFICATION_ENABLED_FOR_BUNDLE,
|
||||
SET_NOTIFICATION_ENABLED_FOR_ALL_BUNDLE,
|
||||
SET_NOTIFICATION_ENABLED_FOR_SPECIAL_BUNDLE,
|
||||
SET_SHOW_BADGE_ENABLED_FOR_BUNDLE,
|
||||
GET_SHOW_BADGE_ENABLED_FOR_BUNDLE,
|
||||
SUBSCRIBE_NOTIFICATION,
|
||||
UNSUBSCRIBE_NOTIFICATION,
|
||||
ARE_NOTIFICATION_SUSPENDED,
|
||||
GET_CURRENT_APP_SORTING,
|
||||
IS_ALLOWED_NOTIFY,
|
||||
IS_SPECIAL_BUNDLE_ALLOWED_NOTIFY,
|
||||
};
|
||||
};
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_INNERKITS_CORE_INCLUDE_ANS_MANAGER_INTERFACE_H
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* 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_NOTIFICATION_ANS_STANDARD_INNERKITS_CORE_INCLUDE_ANS_MANAGER_PROXY_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_INNERKITS_CORE_INCLUDE_ANS_MANAGER_PROXY_H
|
||||
|
||||
#include "ans_manager_interface.h"
|
||||
#include "iremote_proxy.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
class AnsManagerProxy : public IRemoteProxy<IAnsManager> {
|
||||
public:
|
||||
AnsManagerProxy() = delete;
|
||||
explicit AnsManagerProxy(const sptr<IRemoteObject> &impl);
|
||||
~AnsManagerProxy() override;
|
||||
DISALLOW_COPY_AND_MOVE(AnsManagerProxy);
|
||||
|
||||
ErrCode Publish(const std::string &label, const sptr<NotificationRequest> ¬ification) override;
|
||||
ErrCode PublishToDevice(const sptr<NotificationRequest> ¬ification, const std::string &deviceId) override;
|
||||
ErrCode Cancel(int notificationId, const std::string &label) override;
|
||||
ErrCode CancelAll() override;
|
||||
ErrCode AddSlots(const std::vector<sptr<NotificationSlot>> &slots) override;
|
||||
ErrCode RemoveSlots(const std::vector<std::string> &slotIds) override;
|
||||
ErrCode RemoveSlotByType(const NotificationConstant::SlotType slotType) override;
|
||||
ErrCode AddSlotGroups(std::vector<sptr<NotificationSlotGroup>> groups) override;
|
||||
ErrCode GetSlot(const std::string &slotId, sptr<NotificationSlot> &slot) override;
|
||||
ErrCode GetSlotByType(const NotificationConstant::SlotType slotType, sptr<NotificationSlot> &slot) override;
|
||||
ErrCode GetSlots(std::vector<sptr<NotificationSlot>> &slots) override;
|
||||
ErrCode GetSlotGroup(const std::string &groupId, sptr<NotificationSlotGroup> &group) override;
|
||||
ErrCode GetSlotGroups(std::vector<sptr<NotificationSlotGroup>> &groups) override;
|
||||
ErrCode RemoveSlotGroups(const std::vector<std::string> &groupIds) override;
|
||||
ErrCode GetActiveNotifications(std::vector<sptr<NotificationRequest>> ¬ifications) override;
|
||||
ErrCode GetActiveNotificationNums(int &num) override;
|
||||
ErrCode GetAllActiveNotifications(std::vector<sptr<Notification>> ¬ifications) override;
|
||||
ErrCode GetSpecialActiveNotifications(
|
||||
const std::vector<std::string> &key, std::vector<sptr<Notification>> ¬ifications) override;
|
||||
ErrCode SetNotificationAgent(const std::string &agent) override;
|
||||
ErrCode GetNotificationAgent(std::string &agent) override;
|
||||
ErrCode CanPublishAsBundle(const std::string &representativeBundle, bool &canPublish) override;
|
||||
ErrCode PublishAsBundle(
|
||||
const sptr<NotificationRequest> notification, const std::string &representativeBundle) override;
|
||||
ErrCode SetNotificationBadgeNum(int num) override;
|
||||
ErrCode GetBundleImportance(int &importance) override;
|
||||
ErrCode SetDisturbMode(NotificationConstant::DisturbMode mode) override;
|
||||
ErrCode GetDisturbMode(NotificationConstant::DisturbMode &mode) override;
|
||||
ErrCode HasNotificationPolicyAccessPermission(bool &granted) override;
|
||||
ErrCode SetPrivateNotificationsAllowed(bool allow) override;
|
||||
ErrCode GetPrivateNotificationsAllowed(bool &allow) override;
|
||||
ErrCode Delete(const std::string &key) override;
|
||||
ErrCode DeleteByBundle(const std::string &bundle) override;
|
||||
ErrCode DeleteAll() override;
|
||||
ErrCode GetSlotsByBundle(const std::string &bundle, std::vector<sptr<NotificationSlot>> &slots) override;
|
||||
ErrCode UpdateSlots(const std::string &bundle, const std::vector<sptr<NotificationSlot>> &slots) override;
|
||||
ErrCode UpdateSlotGroups(
|
||||
const std::string &bundle, const std::vector<sptr<NotificationSlotGroup>> &groups) override;
|
||||
ErrCode SetNotificationsEnabledForBundle(const std::string &deviceId, bool enabled) override;
|
||||
ErrCode SetNotificationsEnabledForAllBundles(const std::string &deviceId, bool enabled) override;
|
||||
ErrCode SetNotificationsEnabledForSpecialBundle(
|
||||
const std::string &deviceId, const std::string &bundleName, bool enabled) override;
|
||||
ErrCode SetShowBadgeEnabledForBundle(const std::string &bundle, bool enabled) override;
|
||||
ErrCode GetShowBadgeEnabledForBundle(const std::string &bundle, bool &enabled) override;
|
||||
ErrCode Subscribe(const sptr<IAnsSubscriber> &subscriber, const sptr<NotificationSubscribeInfo> &info) override;
|
||||
ErrCode Unsubscribe(const sptr<IAnsSubscriber> &subscriber, const sptr<NotificationSubscribeInfo> &info) override;
|
||||
ErrCode AreNotificationsSuspended(bool &suspended) override;
|
||||
ErrCode GetCurrentAppSorting(sptr<NotificationSortingMap> &sortingMap) override;
|
||||
ErrCode IsAllowedNotify(bool &allowed) override;
|
||||
ErrCode IsSpecialBundleAllowedNotify(const std::string &bundle, bool &allowed) override;
|
||||
|
||||
private:
|
||||
ErrCode InnerTransact(uint32_t code, MessageOption &flags, MessageParcel &data, MessageParcel &reply);
|
||||
|
||||
template <typename T>
|
||||
bool WriteParcelableVector(const std::vector<sptr<T>> &parcelableVector, MessageParcel &data);
|
||||
|
||||
template <typename T>
|
||||
bool ReadParcelableVector(std::vector<sptr<T>> &parcelableInfos, MessageParcel &reply, ErrCode &result);
|
||||
static inline BrokerDelegator<AnsManagerProxy> delegator_;
|
||||
};
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_INNERKITS_CORE_INCLUDE_ANS_MANAGER_PROXY_H
|
||||
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* 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_NOTIFICATION_ANS_STANDARD_INNERKITS_CORE_INCLUDE_ANS_MANAGER_STUB_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_INNERKITS_CORE_INCLUDE_ANS_MANAGER_STUB_H
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
|
||||
#include "ans_manager_interface.h"
|
||||
#include "iremote_stub.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
class AnsManagerStub : public IRemoteStub<IAnsManager> {
|
||||
public:
|
||||
AnsManagerStub();
|
||||
~AnsManagerStub() override;
|
||||
DISALLOW_COPY_AND_MOVE(AnsManagerStub);
|
||||
|
||||
virtual int OnRemoteRequest(
|
||||
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
||||
|
||||
virtual ErrCode Publish(const std::string &label, const sptr<NotificationRequest> ¬ification) override;
|
||||
virtual ErrCode PublishToDevice(
|
||||
const sptr<NotificationRequest> ¬ification, const std::string &deviceId) override;
|
||||
virtual ErrCode Cancel(int notificationId, const std::string &label) override;
|
||||
virtual ErrCode CancelAll() override;
|
||||
virtual ErrCode AddSlots(const std::vector<sptr<NotificationSlot>> &slots) override;
|
||||
virtual ErrCode RemoveSlots(const std::vector<std::string> &slotIds) override;
|
||||
virtual ErrCode RemoveSlotByType(const NotificationConstant::SlotType slotType) override;
|
||||
virtual ErrCode AddSlotGroups(std::vector<sptr<NotificationSlotGroup>> groups) override;
|
||||
virtual ErrCode GetSlot(const std::string &slotId, sptr<NotificationSlot> &slot) override;
|
||||
virtual ErrCode GetSlotByType(const NotificationConstant::SlotType slotType, sptr<NotificationSlot> &slot) override;
|
||||
virtual ErrCode GetSlots(std::vector<sptr<NotificationSlot>> &slots) override;
|
||||
virtual ErrCode GetSlotGroup(const std::string &groupId, sptr<NotificationSlotGroup> &group) override;
|
||||
virtual ErrCode GetSlotGroups(std::vector<sptr<NotificationSlotGroup>> &groups) override;
|
||||
virtual ErrCode RemoveSlotGroups(const std::vector<std::string> &groupIds) override;
|
||||
virtual ErrCode GetActiveNotifications(std::vector<sptr<NotificationRequest>> ¬ifications) override;
|
||||
virtual ErrCode GetActiveNotificationNums(int &num) override;
|
||||
virtual ErrCode GetAllActiveNotifications(std::vector<sptr<Notification>> ¬ifications) override;
|
||||
virtual ErrCode GetSpecialActiveNotifications(
|
||||
const std::vector<std::string> &key, std::vector<sptr<Notification>> ¬ifications) override;
|
||||
virtual ErrCode SetNotificationAgent(const std::string &agent) override;
|
||||
virtual ErrCode GetNotificationAgent(std::string &agent) override;
|
||||
virtual ErrCode CanPublishAsBundle(const std::string &representativeBundle, bool &canPublish) override;
|
||||
virtual ErrCode PublishAsBundle(
|
||||
const sptr<NotificationRequest> notification, const std::string &representativeBundle) override;
|
||||
virtual ErrCode SetNotificationBadgeNum(int num) override;
|
||||
virtual ErrCode GetBundleImportance(int &importance) override;
|
||||
virtual ErrCode SetDisturbMode(NotificationConstant::DisturbMode mode) override;
|
||||
virtual ErrCode GetDisturbMode(NotificationConstant::DisturbMode &mode) override;
|
||||
virtual ErrCode HasNotificationPolicyAccessPermission(bool &granted) override;
|
||||
virtual ErrCode SetPrivateNotificationsAllowed(bool allow) override;
|
||||
virtual ErrCode GetPrivateNotificationsAllowed(bool &allow) override;
|
||||
virtual ErrCode Delete(const std::string &key) override;
|
||||
virtual ErrCode DeleteByBundle(const std::string &bundle) override;
|
||||
virtual ErrCode DeleteAll() override;
|
||||
virtual ErrCode GetSlotsByBundle(const std::string &bundle, std::vector<sptr<NotificationSlot>> &slots) override;
|
||||
virtual ErrCode UpdateSlots(const std::string &bundle, const std::vector<sptr<NotificationSlot>> &slots) override;
|
||||
virtual ErrCode UpdateSlotGroups(
|
||||
const std::string &bundle, const std::vector<sptr<NotificationSlotGroup>> &groups) override;
|
||||
virtual ErrCode SetNotificationsEnabledForBundle(const std::string &deviceId, bool enabled) override;
|
||||
virtual ErrCode SetNotificationsEnabledForAllBundles(const std::string &deviceId, bool enabled) override;
|
||||
virtual ErrCode SetNotificationsEnabledForSpecialBundle(
|
||||
const std::string &deviceId, const std::string &bundleName, bool enabled) override;
|
||||
virtual ErrCode SetShowBadgeEnabledForBundle(const std::string &bundle, bool enabled) override;
|
||||
virtual ErrCode GetShowBadgeEnabledForBundle(const std::string &bundle, bool &enabled) override;
|
||||
virtual ErrCode Subscribe(
|
||||
const sptr<IAnsSubscriber> &subscriber, const sptr<NotificationSubscribeInfo> &info) override;
|
||||
virtual ErrCode Unsubscribe(
|
||||
const sptr<IAnsSubscriber> &subscriber, const sptr<NotificationSubscribeInfo> &info) override;
|
||||
virtual ErrCode AreNotificationsSuspended(bool &suspended) override;
|
||||
virtual ErrCode GetCurrentAppSorting(sptr<NotificationSortingMap> &sortingMap) override;
|
||||
virtual ErrCode IsAllowedNotify(bool &allowed) override;
|
||||
virtual ErrCode IsSpecialBundleAllowedNotify(const std::string &bundle, bool &allowed) override;
|
||||
|
||||
private:
|
||||
static const std::map<uint32_t, std::function<ErrCode(AnsManagerStub*, MessageParcel &, MessageParcel &)>> interfaces_;
|
||||
|
||||
ErrCode HandlePublish(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandlePublishToDevice(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleCancel(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleCancelAll(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleAddSlots(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleRemoveSlots(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleRemoveSlotByType(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleAddSlotGroups(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleGetSlot(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleGetSlots(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleGetSlotByType(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleGetSlotGroup(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleGetSlotGroups(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleRemoveSlotGroups(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleGetActiveNotifications(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleGetActiveNotificationNums(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleGetAllActiveNotifications(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleGetSpecialActiveNotifications(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleSetNotificationAgent(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleGetNotificationAgent(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleCanPublishAsBundle(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandlePublishAsBundle(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleSetNotificationBadgeNum(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleGetBundleImportance(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleSetDisturbMode(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleGetDisturbMode(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleIsNotificationPolicyAccessGranted(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleSetPrivateNotificationsAllowed(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleGetPrivateNotificationsAllowed(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleDelete(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleDeleteByBundle(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleDeleteAll(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleGetSlotsByBundle(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleUpdateSlots(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleUpdateSlotGroups(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleSetNotificationsEnabledForBundle(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleSetNotificationsEnabledForAllBundles(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleSetNotificationsEnabledForSpecialBundle(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleSetShowBadgeEnabledForBundle(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleGetShowBadgeEnabledForBundle(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleSubscribe(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleUnsubscribe(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleAreNotificationsSuspended(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleGetCurrentAppSorting(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleIsAllowedNotify(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleIsSpecialBundleAllowedNotify(MessageParcel &data, MessageParcel &reply);
|
||||
|
||||
template <typename T>
|
||||
bool WriteParcelableVector(const std::vector<sptr<T>> &parcelableVector, MessageParcel &reply, ErrCode &result);
|
||||
|
||||
template <typename T>
|
||||
bool ReadParcelableVector(std::vector<sptr<T>> &parcelableInfos, MessageParcel &data);
|
||||
};
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_INNERKITS_CORE_INCLUDE_ANS_MANAGER_STUB_H
|
||||
@@ -0,0 +1,532 @@
|
||||
/*
|
||||
* 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_NOTIFICATION_ANS_STANDARD_INNERKITS_CORE_INCLUDE_ANS_NOTIFICATION_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_INNERKITS_CORE_INCLUDE_ANS_NOTIFICATION_H
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "ans_manager_death_recipient.h"
|
||||
#include "ans_manager_interface.h"
|
||||
#include "notification_request.h"
|
||||
#include "notification_slot.h"
|
||||
#include "notification_slot_group.h"
|
||||
#include "notification_sorting_map.h"
|
||||
#include "notification_subscriber.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
class AnsNotification {
|
||||
public:
|
||||
/**
|
||||
* Creates a notification slot.
|
||||
* @note You can call the NotificationRequest::SetSlotType(NotificationConstant::SlotType) method to bind the slot
|
||||
* for publishing. A NotificationSlot instance cannot be used directly after being initialized. Instead, you have to
|
||||
* call this method to create a notification slot and bind the slot ID to a NotificationRequest object so that the
|
||||
* notification published can have all the characteristics set in the NotificationSlot. After a notification slot is
|
||||
* created by using this method, only the name and description of the notification slot can be changed. Changes to
|
||||
* the other attributes, such as the vibration status and notification tone, will no longer take effect.
|
||||
*
|
||||
* @param slot Indicates the notification slot to be created, which is set by NotificationSlot.
|
||||
* This parameter must be specified.
|
||||
* @return Returns add notification slot result.
|
||||
*/
|
||||
ErrCode AddNotificationSlot(const NotificationSlot &slot);
|
||||
|
||||
/**
|
||||
* Creates multiple notification slots.
|
||||
*
|
||||
* @param slots Indicates the notification slots to create.
|
||||
* @return Returns add notification slots result.
|
||||
*/
|
||||
ErrCode AddNotificationSlots(const std::vector<NotificationSlot> &slots);
|
||||
|
||||
/**
|
||||
* Deletes a created notification slot based on the slot ID.
|
||||
*
|
||||
* @param slotType Indicates the ID of the slot, which is created by AddNotificationSlot
|
||||
* This parameter must be specified.
|
||||
* @return Returns remove notification slot result.
|
||||
*/
|
||||
ErrCode RemoveNotificationSlot(const NotificationConstant::SlotType &slotType);
|
||||
|
||||
/**
|
||||
* Queries a created notification slot.
|
||||
*
|
||||
* @param slotType Indicates the ID of the slot, which is created by AddNotificationSlot(NotificationSlot). This
|
||||
* parameter must be specified.
|
||||
* @param slot Indicates the created NotificationSlot.
|
||||
* @return Returns the get notification slot result.
|
||||
*/
|
||||
ErrCode GetNotificationSlot(const NotificationConstant::SlotType &slotType, sptr<NotificationSlot> &slot);
|
||||
|
||||
/**
|
||||
* Obtains all notification slots of this application.
|
||||
* @param slots Indicates the created NotificationSlot.
|
||||
* @return Returns all notification slots of this application.
|
||||
*/
|
||||
ErrCode GetNotificationSlots(std::vector<sptr<NotificationSlot>> &slots);
|
||||
|
||||
/**
|
||||
* Creates a notification slot group to which a NotificationSlot object can be bound by
|
||||
* calling NotificationSlot::SetSlotGroup(string).
|
||||
* @note A NotificationSlotGroup instance cannot be used directly after being initialized.
|
||||
* Instead, you have to call this method to create a notification slot group so that you can bind
|
||||
* NotificationSlot objects to it.
|
||||
*
|
||||
* @param slotGroup Indicates the notification slot group to be created, which is set by NotificationSlotGroup.
|
||||
* This parameter must be specified. the notification slot to be created, which is set by
|
||||
* NotificationSlot.
|
||||
* @return Returns add notification slot group result.
|
||||
*/
|
||||
ErrCode AddNotificationSlotGroup(const NotificationSlotGroup &slotGroup);
|
||||
|
||||
/**
|
||||
* Creates multiple notification slot groups.
|
||||
* @note The precautions for using this method are similar to those for
|
||||
* AddNotificationSlotGroup(NotificationSlotGroup).
|
||||
*
|
||||
* @param slotGroups Indicates a list of NotificationSlotGroup objects to create. This parameter cannot be null.
|
||||
* @return Returns add notification slot groups result.
|
||||
*/
|
||||
ErrCode AddNotificationSlotGroups(const std::vector<NotificationSlotGroup> &slotGroups);
|
||||
|
||||
/**
|
||||
* Deletes a created notification slot group based on the slot group ID.
|
||||
*
|
||||
* @param slotGroupId Indicates the ID of the notification slot group, which is created by
|
||||
* AddNotificationSlotGroup(NotificationSlotGroup) This parameter must be specified.
|
||||
* @return Returns remove notification slot group result.
|
||||
*/
|
||||
ErrCode RemoveNotificationSlotGroup(const std::string &slotGroupId);
|
||||
|
||||
/**
|
||||
* Queries a created notification slot group.
|
||||
*
|
||||
* @param groupId Indicates the ID of the slot group.
|
||||
* @param group Indicates the created NotificationSlotGroup.
|
||||
* @return Returns get notification slot group result.
|
||||
*/
|
||||
ErrCode GetNotificationSlotGroup(const std::string &groupId, sptr<NotificationSlotGroup> &group);
|
||||
|
||||
/**
|
||||
* Obtains a list of created notification slot groups.
|
||||
*
|
||||
* @param groups Indicates a list of created notification slot groups.
|
||||
* @return Returns get notification slot groups result.
|
||||
*/
|
||||
ErrCode GetNotificationSlotGroups(std::vector<sptr<NotificationSlotGroup>> &groups);
|
||||
|
||||
/**
|
||||
* Publishes a notification.
|
||||
* @note If a notification with the same ID has been published by the current application and has not been deleted,
|
||||
* this method will update the notification.
|
||||
*
|
||||
* @param request Indicates the NotificationRequest object for setting the notification content.
|
||||
* This parameter must be specified.
|
||||
* @return returns publish notification result.
|
||||
*/
|
||||
ErrCode PublishNotification(const NotificationRequest &request);
|
||||
|
||||
/**
|
||||
* Publishes a notification with a specified label.
|
||||
* @note If a notification with the same ID has been published by the current application and has not been deleted,
|
||||
* this method will update the notification.
|
||||
*
|
||||
* @param label Indicates the label of the notification to publish.
|
||||
* @param request Indicates the NotificationRequest object for setting the notification content.
|
||||
* This parameter must be specified.
|
||||
* @return returns publish notification result.
|
||||
*/
|
||||
ErrCode PublishNotification(const std::string &label, const NotificationRequest &request);
|
||||
|
||||
/**
|
||||
* Publishes a notification on a specified remote device.
|
||||
* @note If a notification with the same ID has been published by the current application and has not been deleted,
|
||||
* this method will update the notification.
|
||||
*
|
||||
* @param request Indicates the NotificationRequest object for setting the notification content.
|
||||
* This parameter must be specified.
|
||||
* @param deviceId Indicates the ID of the remote device. If this parameter is null or an empty string,
|
||||
* the notification will be published on the local device.
|
||||
* @return returns publish notification result.
|
||||
*/
|
||||
ErrCode PublishNotification(const NotificationRequest &request, const std::string &deviceId);
|
||||
|
||||
/**
|
||||
* Cancels a published notification.
|
||||
*
|
||||
* @param notificationId Indicates the unique notification ID in the application.
|
||||
* The value must be the ID of a published notification.
|
||||
* Otherwise, this method does not take effect.
|
||||
* @return returns cancel notification result.
|
||||
*/
|
||||
ErrCode CancelNotification(int32_t notificationId);
|
||||
|
||||
/**
|
||||
* Cancels a published notification matching the specified label and notificationId.
|
||||
*
|
||||
* @param label Indicates the label of the notification to cancel.
|
||||
* @param notificationId Indicates the ID of the notification to cancel.
|
||||
* @return returns cancel notification result.
|
||||
*/
|
||||
ErrCode CancelNotification(const std::string &label, int32_t notificationId);
|
||||
|
||||
/**
|
||||
* Cancels all the published notifications.
|
||||
* @note To cancel a specified notification, see CancelNotification(int_32).
|
||||
* @return returns cancel all notifications result.
|
||||
*/
|
||||
ErrCode CancelAllNotifications();
|
||||
|
||||
/**
|
||||
* Obtains the number of active notifications of the current application in the system.
|
||||
*
|
||||
* @param num Indicates the number of active notifications of the current application.
|
||||
* @return Returns get active notification nums result.
|
||||
*/
|
||||
ErrCode GetActiveNotificationNums(int32_t &num);
|
||||
|
||||
/**
|
||||
* Obtains active notifications of the current application in the system.
|
||||
* @param request Indicates active NotificationRequest objects of the current application.
|
||||
* @return Returns get active notifications result.
|
||||
*/
|
||||
ErrCode GetActiveNotifications(std::vector<sptr<NotificationRequest>> &request);
|
||||
|
||||
/**
|
||||
* Obtains the map for sorting notifications of the current application.
|
||||
*
|
||||
* @param sortingMap Indicates the NotificationSortingMap object for the current application.
|
||||
* @return Returns get current app sorting result.
|
||||
*/
|
||||
ErrCode GetCurrentAppSorting(sptr<NotificationSortingMap> &sortingMap);
|
||||
|
||||
/**
|
||||
* Allows another application to act as an agent to publish notifications in the name of your application bundle.
|
||||
* You can revoke this authorization by passing null to this method.
|
||||
*
|
||||
* @param agent Indicates the name of the application bundle that can publish notifications for your application.
|
||||
* @return Returns set notification agent result.
|
||||
*/
|
||||
ErrCode SetNotificationAgent(const std::string &agent);
|
||||
|
||||
/**
|
||||
* Obtains the name of the application bundle that can publish notifications in the name of your application.
|
||||
*
|
||||
* @param agent Indicates the name of the application bundle that can publish notifications for your application if
|
||||
* any; returns null otherwise.
|
||||
* @return Returns get notification agent result.
|
||||
*/
|
||||
ErrCode GetNotificationAgent(std::string &agent);
|
||||
|
||||
/**
|
||||
* Checks whether your application has permission to publish notifications by calling
|
||||
* PublishNotificationAsBundle(string, NotificationRequest) in the name of another application indicated by the
|
||||
* given representativeBundle.
|
||||
*
|
||||
* @param representativeBundle Indicates the name of application bundle your application is representing.
|
||||
* @param canPublish Indicates whether your application has permission to publish notifications.
|
||||
* @return Returns can publish notification as bundle result.
|
||||
*/
|
||||
ErrCode CanPublishNotificationAsBundle(const std::string &representativeBundle, bool &canPublish);
|
||||
|
||||
/**
|
||||
* Publishes a notification in the name of a specified application bundle.
|
||||
* @note If the notification to be published has the same ID as a published notification that has not been canceled,
|
||||
* the existing notification will be replaced by the new one.
|
||||
*
|
||||
* @param request Indicates the NotificationRequest object for setting the notification content.
|
||||
* This parameter must be specified.
|
||||
* @param representativeBundle Indicates the name of the application bundle that allows your application to publish
|
||||
* notifications for it by calling setNotificationAgent.
|
||||
* @return Returns publish notification as bundle result.
|
||||
*/
|
||||
ErrCode PublishNotificationAsBundle(const std::string &representativeBundle, const NotificationRequest &request);
|
||||
|
||||
/**
|
||||
* Sets the number of active notifications of the current application as the number to be displayed on the
|
||||
* notification badge.
|
||||
* @return Returns set notification badge num result.
|
||||
*/
|
||||
ErrCode SetNotificationBadgeNum();
|
||||
|
||||
/**
|
||||
* Sets the number to be displayed on the notification badge of the application.
|
||||
*
|
||||
* @param num Indicates the number to display. A negative number indicates that the badge setting remains unchanged.
|
||||
* The value 0 indicates that no badge is displayed on the application icon.
|
||||
* If the value is greater than 99, 99+ will be displayed.
|
||||
* @return Returns set notification badge num result.
|
||||
*/
|
||||
ErrCode SetNotificationBadgeNum(int32_t num);
|
||||
|
||||
/**
|
||||
* Checks whether this application has permission to publish notifications.
|
||||
*
|
||||
* @param allowed True if this application has the permission; returns false otherwise
|
||||
* @return Returns is allowed notify result.
|
||||
*/
|
||||
ErrCode IsAllowedNotify(bool &allowed);
|
||||
|
||||
/**
|
||||
* Checks whether this application is in the suspended state.Applications in this state cannot publish
|
||||
* notifications.
|
||||
*
|
||||
* @param suspended True if this application is suspended; returns false otherwise.
|
||||
* @return Returns are notifications suspended.
|
||||
*/
|
||||
ErrCode AreNotificationsSuspended(bool &suspended);
|
||||
|
||||
/**
|
||||
* Checks whether this application has permission to modify the Do Not Disturb (DND) notification policy.
|
||||
*
|
||||
* @param hasPermission True if this application is suspended; returns false otherwise.
|
||||
* @return Returns has notification policy access permission.
|
||||
*/
|
||||
ErrCode HasNotificationPolicyAccessPermission(bool &hasPermission);
|
||||
|
||||
/**
|
||||
* Obtains the importance level of this application.
|
||||
*
|
||||
* @param importance the importance level of this application, which can be LEVEL_NONE,
|
||||
LEVEL_MIN, LEVEL_LOW, LEVEL_DEFAULT, LEVEL_HIGH, or LEVEL_UNDEFINED.
|
||||
* @return Returns get bundle importance result
|
||||
*/
|
||||
ErrCode GetBundleImportance(NotificationSlot::NotificationLevel &importance);
|
||||
|
||||
/**
|
||||
* Subscribes to notifications from all applications. This method can be called only by applications
|
||||
* with required system permissions.
|
||||
* @note To subscribe to a notification, inherit the {NotificationSubscriber} class, override its
|
||||
* callback methods and create a subscriber. The subscriber will be used as a parameter of this method.
|
||||
* After the notification is published, subscribers that meet the filter criteria can receive the
|
||||
* notification. To subscribe to notifications published only by specified sources, for example, notifications from
|
||||
* certain applications, call the {SubscribeNotification(NotificationSubscriber, NotificationSubscribeInfo)}
|
||||
* method.
|
||||
*
|
||||
* @param subscriber Indicates the {NotificationSubscriber} to receive notifications.
|
||||
* This parameter must be specified.
|
||||
* @return Returns subscribe notification result.
|
||||
*/
|
||||
ErrCode SubscribeNotification(const NotificationSubscriber &subscriber);
|
||||
|
||||
/**
|
||||
* Subscribes to all notifications based on the filtering criteria. This method can be called only
|
||||
* by applications with required system permissions.
|
||||
* @note After {subscribeInfo} is specified, a subscriber receives only the notifications that
|
||||
* meet the filter criteria specified by {subscribeInfo}.
|
||||
* To subscribe to a notification, inherit the {NotificationSubscriber} class, override its
|
||||
* callback methods and create a subscriber. The subscriber will be used as a parameter of this method.
|
||||
* After the notification is published, subscribers that meet the filter criteria can receive the
|
||||
* notification. To subscribe to and receive all notifications, call the
|
||||
* {SubscribeNotification(NotificationSubscriber)} method.
|
||||
*
|
||||
* @param subscriber Indicates the subscribers to receive notifications. This parameter must be specified.
|
||||
* For details, see {NotificationSubscriber}.
|
||||
* @param subscribeInfo Indicates the filters for specified notification sources, including application name,
|
||||
* user ID, or device name. This parameter is optional.
|
||||
* @return Returns subscribe notification result.
|
||||
*/
|
||||
ErrCode SubscribeNotification(
|
||||
const NotificationSubscriber &subscriber, const NotificationSubscribeInfo &subscribeInfo);
|
||||
|
||||
/**
|
||||
* Unsubscribes from all notifications. This method can be called only by applications with required
|
||||
* system permissions.
|
||||
* @note Generally, you subscribe to a notification by calling the
|
||||
* {SubscribeNotification(NotificationSubscriber)} method. If you do not want your application
|
||||
* to receive a notification any longer, unsubscribe from that notification using this method.
|
||||
* You can unsubscribe from only those notifications that your application has subscribed to.
|
||||
* To unsubscribe from notifications published only by specified sources, for example,
|
||||
* notifications from certain applications, call the
|
||||
* {UnSubscribeNotification(NotificationSubscriber, NotificationSubscribeInfo)} method.
|
||||
*
|
||||
* @param subscriber Indicates the {NotificationSubscriber} to receive notifications.
|
||||
* This parameter must be specified.
|
||||
* @return Returns unsubscribe notification result.
|
||||
*/
|
||||
ErrCode UnSubscribeNotification(NotificationSubscriber &subscriber);
|
||||
|
||||
/**
|
||||
* Unsubscribes from all notifications based on the filtering criteria. This method can be called
|
||||
* only by applications with required system permissions.
|
||||
* @note A subscriber will no longer receive the notifications from specified notification sources.
|
||||
*
|
||||
* @param subscriber Indicates the {NotificationSubscriber} to receive notifications.
|
||||
* This parameter must be specified.
|
||||
* @param subscribeInfo Indicates the filters for , including application name,
|
||||
* user ID, or device name. This parameter is optional.
|
||||
* @return Returns unsubscribe notification result.
|
||||
*/
|
||||
ErrCode UnSubscribeNotification(NotificationSubscriber &subscriber, NotificationSubscribeInfo subscribeInfo);
|
||||
|
||||
/**
|
||||
* Removes a specified removable notification of other applications.
|
||||
* @note Your application must have platform signature to use this method.
|
||||
*
|
||||
* @param key Indicates the key of the notification to remove.
|
||||
* @return Returns remove notification result.
|
||||
*/
|
||||
ErrCode RemoveNotification(const std::string &key);
|
||||
|
||||
/**
|
||||
* Removes all removable notifications of a specified bundle.
|
||||
* @note Your application must have platform signature to use this method.
|
||||
*
|
||||
* @param bundleName Indicates the bundle name of the application whose notifications are to be removed.
|
||||
* @return Returns remove notifications result.
|
||||
*/
|
||||
ErrCode RemoveNotifications(const std::string &bundleName);
|
||||
|
||||
/**
|
||||
* Removes all removable notifications in the system.
|
||||
* @note Your application must have platform signature to use this method.
|
||||
* @return Returns remove notifications result.
|
||||
*/
|
||||
ErrCode RemoveNotifications();
|
||||
|
||||
/**
|
||||
* Returns all notification slots belonging to the specified bundle.
|
||||
*
|
||||
* @param bundleName Indicates the application name.
|
||||
* @param slots Indicates a list of notification slots.
|
||||
* @return Returns get notification slots for bundle result.
|
||||
*/
|
||||
ErrCode GetNotificationSlotsForBundle(const std::string &bundleName, std::vector<sptr<NotificationSlot>> &slots);
|
||||
|
||||
/**
|
||||
* Obtains all active notifications in the current system. The caller must have system permissions to
|
||||
* call this method.
|
||||
*
|
||||
* @param notification Indicates all active notifications of this application.
|
||||
* @return Returns get all active notifications
|
||||
*/
|
||||
ErrCode GetAllActiveNotifications(std::vector<sptr<Notification>> ¬ification);
|
||||
|
||||
/**
|
||||
* Obtains the active notifications corresponding to the specified key in the system. To call this method
|
||||
* to obtain particular active notifications, you must have received the notifications and obtained the key
|
||||
* via {Notification::GetKey()}.
|
||||
*
|
||||
* @param key Indicates the key array for querying corresponding active notifications.
|
||||
* If this parameter is null, this method returns all active notifications in the system.
|
||||
* @param notification Indicates the set of active notifications corresponding to the specified key.
|
||||
* @return Returns get all active notifications result.
|
||||
*/
|
||||
ErrCode GetAllActiveNotifications(
|
||||
const std::vector<std::string> key, std::vector<sptr<Notification>> ¬ification);
|
||||
|
||||
/**
|
||||
* Checks whether a specified application has the permission to publish notifications. If bundle specifies
|
||||
* the current application, no permission is required for calling this method. If bundle specifies another
|
||||
* application, the caller must have system permissions.
|
||||
*
|
||||
* @param bundle Indicates the bundle name of the application to check.
|
||||
* @param allowed True if the application has permissions; returns false otherwise.
|
||||
* @return Returns is allowed notify result.
|
||||
*/
|
||||
ErrCode IsAllowedNotify(const std::string &bundle, bool &allowed);
|
||||
|
||||
/**
|
||||
* Sets whether to allow all applications to publish notifications on a specified device. The caller must have
|
||||
* system permissions to call this method.
|
||||
*
|
||||
* @param deviceId Indicates the ID of the device running the application. At present, this parameter can only
|
||||
* be null or an empty string, indicating the current device.
|
||||
* @param enabled Specifies whether to allow all applications to publish notifications. The value true
|
||||
* indicates that notifications are allowed, and the value false indicates that notifications are not
|
||||
* allowed.
|
||||
* @return Returns set notifications enabled for all bundles result.
|
||||
*/
|
||||
ErrCode SetNotificationsEnabledForAllBundles(const std::string &deviceId, bool enabled);
|
||||
|
||||
/**
|
||||
* Sets whether to allow the current application to publish notifications on a specified device. The caller
|
||||
* must have system permissions to call this method.
|
||||
*
|
||||
* @param deviceId Indicates the ID of the device running the application. At present, this parameter can
|
||||
* only be null or an empty string, indicating the current device.
|
||||
* @param enabled Specifies whether to allow the current application to publish notifications. The value
|
||||
* true indicates that notifications are allowed, and the value false indicates that
|
||||
* notifications are not allowed.
|
||||
* @return Returns set notifications enabled for default bundle result.
|
||||
*/
|
||||
ErrCode SetNotificationsEnabledForDefaultBundle(const std::string &deviceId, bool enabled);
|
||||
|
||||
/**
|
||||
* Sets whether to allow a specified application to publish notifications on a specified device. The caller
|
||||
* must have system permissions to call this method.
|
||||
*
|
||||
* @param bundle Indicates the bundle name of the application.
|
||||
* @param deviceId Indicates the ID of the device running the application. At present, this parameter can only
|
||||
* be null or an empty string, indicating the current device.
|
||||
* @param enabled Specifies whether to allow the given application to publish notifications. The value
|
||||
* true indicates that notifications are allowed, and the value false indicates that notifications
|
||||
* are not allowed.
|
||||
* @return Returns set notifications enabled for specified bundle result.
|
||||
*/
|
||||
ErrCode SetNotificationsEnabledForSpecifiedBundle(
|
||||
const std::string &bundle, const std::string &deviceId, bool enabled);
|
||||
|
||||
/**
|
||||
* Sets the type of the Do Not Disturb mode. The Do Not Disturb mode type specifies the type of notifications
|
||||
* that are allowed to interrupt users.
|
||||
* @note Your application must have system signature to call this method.
|
||||
*
|
||||
* @param mode Indicates the Do Not Disturb mode to set. The value must be
|
||||
* {NotificationConstant.DisturbMode.ALLOW_ALL}, {NotificationConstant.DisturbMode.ALLOW_PRIORITY},
|
||||
* {NotificationConstant.DisturbMode.ALLOW_NONE}, or {NotificationConstant.DisturbMode.ALLOW_ALARMS}.
|
||||
* @return Returns set disturb mode result.
|
||||
*/
|
||||
ErrCode SetDisturbMode(NotificationConstant::DisturbMode mode);
|
||||
|
||||
/**
|
||||
* Obtains the Disturb Mode.
|
||||
* @param disturbMode The current type of the Do Not Disturb mode.
|
||||
* @return Returns get disturb mode result.
|
||||
*/
|
||||
ErrCode GetDisturbMode(NotificationConstant::DisturbMode &disturbMode);
|
||||
|
||||
/**
|
||||
* Reset ans manager proxy when OnRemoteDied called.
|
||||
*/
|
||||
void ResetAnsManagerProxy();
|
||||
|
||||
private:
|
||||
/**
|
||||
* Get Ans Manager proxy.
|
||||
*
|
||||
* @return Get Ans Manager proxy success or not
|
||||
*/
|
||||
bool GetAnsManagerProxy();
|
||||
|
||||
/**
|
||||
* Can Publish Media Content
|
||||
*
|
||||
* @return Can publish return true otherwise return false
|
||||
*/
|
||||
bool CanPublishMediaContent(const NotificationRequest &request) const;
|
||||
|
||||
private:
|
||||
std::mutex mutex_;
|
||||
sptr<IAnsManager> ansManagerProxy_;
|
||||
sptr<AnsManagerDeathRecipient> recipient_;
|
||||
};
|
||||
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_INNERKITS_CORE_INCLUDE_ANS_NOTIFICATION_H
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
#ifndef BASE_NOTIFICATION_ANS_STANDARD_INNERKITS_CORE_INCLUDE_ANS_SUBSCRIBER_INTERFACE_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_INNERKITS_CORE_INCLUDE_ANS_SUBSCRIBER_INTERFACE_H
|
||||
|
||||
#include "iremote_broker.h"
|
||||
|
||||
#include "notification.h"
|
||||
#include "notification_constant.h"
|
||||
#include "notification_request.h"
|
||||
#include "notification_sorting.h"
|
||||
#include "notification_sorting_map.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
class IAnsSubscriber : public IRemoteBroker {
|
||||
public:
|
||||
IAnsSubscriber() = default;
|
||||
virtual ~IAnsSubscriber() override = default;
|
||||
DISALLOW_COPY_AND_MOVE(IAnsSubscriber);
|
||||
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Notification.IAnsSubscriber");
|
||||
|
||||
virtual void OnSubscribeResult(NotificationConstant::SubscribeResult result) = 0;
|
||||
virtual void OnUnsubscribeResult(NotificationConstant::SubscribeResult result) = 0;
|
||||
virtual void OnConsumed(const sptr<Notification> ¬ification) = 0;
|
||||
virtual void OnConsumed(
|
||||
const sptr<Notification> ¬ification, const sptr<NotificationSortingMap> ¬ificationMap) = 0;
|
||||
virtual void OnCanceled(const sptr<Notification> ¬ification) = 0;
|
||||
virtual void OnCanceled(const sptr<Notification> ¬ification, const sptr<NotificationSortingMap> ¬ificationMap,
|
||||
int deleteReason) = 0;
|
||||
virtual void OnUpdated(const sptr<NotificationSortingMap> ¬ificationMap) = 0;
|
||||
virtual void OnDisturbModeChanged(NotificationConstant::DisturbMode mode) = 0;
|
||||
|
||||
protected:
|
||||
enum TransactId : uint32_t {
|
||||
ON_SUBSCRIBE = FIRST_CALL_TRANSACTION,
|
||||
ON_UNSUBSCRIBE,
|
||||
ON_CONSUMED,
|
||||
ON_CONSUMED_MAP,
|
||||
ON_CANCELED,
|
||||
ON_CANCELED_MAP,
|
||||
ON_UPDATED,
|
||||
ON_DISTURB_MODE_CHANGED,
|
||||
};
|
||||
};
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_INNERKITS_CORE_INCLUDE_ANS_SUBSCRIBER_INTERFACE_H
|
||||
@@ -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_NOTIFICATION_ANS_STANDARD_INNERKITS_CORE_INCLUDE_ANS_SUBSCRIBER_PROXY_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_INNERKITS_CORE_INCLUDE_ANS_SUBSCRIBER_PROXY_H
|
||||
|
||||
#include "ans_subscriber_interface.h"
|
||||
#include "iremote_proxy.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
|
||||
class AnsSubscriberProxy : public IRemoteProxy<IAnsSubscriber> {
|
||||
public:
|
||||
AnsSubscriberProxy() = delete;
|
||||
explicit AnsSubscriberProxy(const sptr<IRemoteObject> &impl);
|
||||
~AnsSubscriberProxy() override;
|
||||
DISALLOW_COPY_AND_MOVE(AnsSubscriberProxy);
|
||||
|
||||
void OnSubscribeResult(NotificationConstant::SubscribeResult result) override;
|
||||
void OnUnsubscribeResult(NotificationConstant::SubscribeResult result) override;
|
||||
void OnConsumed(const sptr<Notification> ¬ification) override;
|
||||
void OnConsumed(
|
||||
const sptr<Notification> ¬ification, const sptr<NotificationSortingMap> ¬ificationMap) override;
|
||||
void OnCanceled(const sptr<Notification> ¬ification) override;
|
||||
void OnCanceled(const sptr<Notification> ¬ification, const sptr<NotificationSortingMap> ¬ificationMap,
|
||||
int deleteReason) override;
|
||||
void OnUpdated(const sptr<NotificationSortingMap> ¬ificationMap) override;
|
||||
void OnDisturbModeChanged(NotificationConstant::DisturbMode mode) override;
|
||||
|
||||
private:
|
||||
ErrCode InnerTransact(uint32_t code, MessageOption &flags, MessageParcel &data, MessageParcel &reply);
|
||||
static inline BrokerDelegator<AnsSubscriberProxy> delegator_;
|
||||
};
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_INNERKITS_CORE_INCLUDE_ANS_SUBSCRIBER_PROXY_H
|
||||
@@ -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_NOTIFICATION_ANS_STANDARD_INNERKITS_CORE_INCLUDE_ANS_SUBSCRIBER_STUB_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_INNERKITS_CORE_INCLUDE_ANS_SUBSCRIBER_STUB_H
|
||||
|
||||
#include "ans_subscriber_interface.h"
|
||||
#include "iremote_stub.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
|
||||
class AnsSubscriberStub : public IRemoteStub<IAnsSubscriber> {
|
||||
public:
|
||||
AnsSubscriberStub();
|
||||
~AnsSubscriberStub() override;
|
||||
DISALLOW_COPY_AND_MOVE(AnsSubscriberStub);
|
||||
|
||||
virtual int OnRemoteRequest(
|
||||
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
||||
|
||||
void OnSubscribeResult(NotificationConstant::SubscribeResult result) override;
|
||||
void OnUnsubscribeResult(NotificationConstant::SubscribeResult result) override;
|
||||
void OnConsumed(const sptr<Notification> ¬ification) override;
|
||||
void OnConsumed(
|
||||
const sptr<Notification> ¬ification, const sptr<NotificationSortingMap> ¬ificationMap) override;
|
||||
void OnCanceled(const sptr<Notification> ¬ification) override;
|
||||
void OnCanceled(const sptr<Notification> ¬ification, const sptr<NotificationSortingMap> ¬ificationMap,
|
||||
int deleteReason) override;
|
||||
void OnUpdated(const sptr<NotificationSortingMap> ¬ificationMap) override;
|
||||
void OnDisturbModeChanged(NotificationConstant::DisturbMode mode) override;
|
||||
|
||||
private:
|
||||
std::map<uint32_t, std::function<ErrCode(MessageParcel &, MessageParcel &)>> interfaces_;
|
||||
|
||||
ErrCode HandleOnSubscribe(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleOnUnsubscribe(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleOnConsumed(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleOnConsumedMap(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleOnCanceled(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleOnCanceledMap(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleOnUpdated(MessageParcel &data, MessageParcel &reply);
|
||||
ErrCode HandleOnDisturbModeChanged(MessageParcel &data, MessageParcel &reply);
|
||||
};
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_INNERKITS_CORE_INCLUDE_ANS_SUBSCRIBER_STUB_H
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
#include "ans_manager_death_recipient.h"
|
||||
#include "ans_log_wrapper.h"
|
||||
#include "ans_notification.h"
|
||||
#include "singleton.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
void AnsManagerDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
|
||||
{
|
||||
ANS_LOGE("Ans service died");
|
||||
DelayedSingleton<AnsNotification>::GetInstance()->ResetAnsManagerProxy();
|
||||
}
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,656 @@
|
||||
/*
|
||||
* 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 "ans_notification.h"
|
||||
#include "ans_inner_errors.h"
|
||||
#include "ans_log_wrapper.h"
|
||||
#include "notification_request.h"
|
||||
#include "notification_sorting.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
ErrCode AnsNotification::AddNotificationSlot(const NotificationSlot &slot)
|
||||
{
|
||||
std::vector<NotificationSlot> slots;
|
||||
slots.push_back(slot);
|
||||
return AddNotificationSlots(slots);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::AddNotificationSlots(const std::vector<NotificationSlot> &slots)
|
||||
{
|
||||
if (slots.size() == 0) {
|
||||
ANS_LOGE("Failed to add notification slots because input slots size is 0.");
|
||||
return ERR_ANS_INVALID_PARAM;
|
||||
}
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
|
||||
std::vector<sptr<NotificationSlot>> slotsSptr;
|
||||
for (auto it = slots.begin(); it != slots.end(); ++it) {
|
||||
sptr<NotificationSlot> slot = new NotificationSlot(*it);
|
||||
if (slot == nullptr) {
|
||||
ANS_LOGE("Failed to create NotificationSlot ptr.");
|
||||
return ERR_ANS_NO_MEMORY;
|
||||
}
|
||||
slotsSptr.emplace_back(slot);
|
||||
}
|
||||
|
||||
return ansManagerProxy_->AddSlots(slotsSptr);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::RemoveNotificationSlot(const NotificationConstant::SlotType &slotType)
|
||||
{
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
return ansManagerProxy_->RemoveSlotByType(slotType);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::GetNotificationSlot(
|
||||
const NotificationConstant::SlotType &slotType, sptr<NotificationSlot> &slot)
|
||||
{
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
return ansManagerProxy_->GetSlotByType(slotType, slot);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::GetNotificationSlots(std::vector<sptr<NotificationSlot>> &slots)
|
||||
{
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
return ansManagerProxy_->GetSlots(slots);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::AddNotificationSlotGroup(const NotificationSlotGroup &slotGroup)
|
||||
{
|
||||
std::vector<NotificationSlotGroup> slotGroups;
|
||||
slotGroups.emplace_back(slotGroup);
|
||||
return AddNotificationSlotGroups(slotGroups);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::AddNotificationSlotGroups(const std::vector<NotificationSlotGroup> &slotGroups)
|
||||
{
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
|
||||
std::vector<sptr<NotificationSlotGroup>> slotGroupsSptr;
|
||||
for (auto it = slotGroups.begin(); it != slotGroups.end(); ++it) {
|
||||
sptr<NotificationSlotGroup> slotGroup = new NotificationSlotGroup((*it).GetId(), (*it).GetName());
|
||||
if (slotGroup == nullptr) {
|
||||
ANS_LOGE("Failed to add notification slot groups with NotificationSlotGroup nullptr");
|
||||
return ERR_ANS_NO_MEMORY;
|
||||
}
|
||||
slotGroupsSptr.emplace_back(slotGroup);
|
||||
}
|
||||
|
||||
return ansManagerProxy_->AddSlotGroups(slotGroupsSptr);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::RemoveNotificationSlotGroup(const std::string &slotGroupId)
|
||||
{
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
std::vector<std::string> slotGroupIds;
|
||||
slotGroupIds.emplace_back(slotGroupId);
|
||||
return ansManagerProxy_->RemoveSlotGroups(slotGroupIds);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::GetNotificationSlotGroup(const std::string &groupId, sptr<NotificationSlotGroup> &group)
|
||||
{
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
return ansManagerProxy_->GetSlotGroup(groupId, group);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::GetNotificationSlotGroups(std::vector<sptr<NotificationSlotGroup>> &groups)
|
||||
{
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
return ansManagerProxy_->GetSlotGroups(groups);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::PublishNotification(const NotificationRequest &request)
|
||||
{
|
||||
ANS_LOGI("enter");
|
||||
return PublishNotification(std::string(), request);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::PublishNotification(const std::string &label, const NotificationRequest &request)
|
||||
{
|
||||
ANS_LOGI("enter");
|
||||
|
||||
if (request.GetContent() == nullptr || request.GetNotificationType() == NotificationContent::Type::NONE) {
|
||||
ANS_LOGE("Refuse to publish the notification without valid content");
|
||||
return ERR_ANS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (!CanPublishMediaContent(request)) {
|
||||
ANS_LOGE("Refuse to publish the notification because the sequence numbers actions not match those assigned to "
|
||||
"added action buttons.");
|
||||
return ERR_ANS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
|
||||
sptr<NotificationRequest> reqPtr = new (std::nothrow) NotificationRequest(request);
|
||||
if (reqPtr == nullptr) {
|
||||
ANS_LOGE("Failed to create NotificationRequest ptr");
|
||||
return ERR_ANS_NO_MEMORY;
|
||||
}
|
||||
return ansManagerProxy_->Publish(label, reqPtr);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::PublishNotification(const NotificationRequest &request, const std::string &deviceId)
|
||||
{
|
||||
if (request.GetContent() == nullptr || request.GetNotificationType() == NotificationContent::Type::NONE) {
|
||||
ANS_LOGE("Refuse to publish the notification without valid content");
|
||||
return ERR_ANS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (!CanPublishMediaContent(request)) {
|
||||
ANS_LOGE("Refuse to publish the notification because the sequence numbers actions not match those assigned to "
|
||||
"added action buttons.");
|
||||
return ERR_ANS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
|
||||
sptr<NotificationRequest> reqPtr = new (std::nothrow) NotificationRequest(request);
|
||||
if (reqPtr == nullptr) {
|
||||
ANS_LOGE("Failed to create NotificationRequest ptr");
|
||||
return ERR_ANS_NO_MEMORY;
|
||||
}
|
||||
return ansManagerProxy_->PublishToDevice(reqPtr, deviceId);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::CancelNotification(int32_t notificationId)
|
||||
{
|
||||
return CancelNotification("", notificationId);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::CancelNotification(const std::string &label, int32_t notificationId)
|
||||
{
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
return ansManagerProxy_->Cancel(notificationId, label);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::CancelAllNotifications()
|
||||
{
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
return ansManagerProxy_->CancelAll();
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::GetActiveNotificationNums(int32_t &num)
|
||||
{
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
return ansManagerProxy_->GetActiveNotificationNums(num);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::GetActiveNotifications(std::vector<sptr<NotificationRequest>> &request)
|
||||
{
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
return ansManagerProxy_->GetActiveNotifications(request);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::GetCurrentAppSorting(sptr<NotificationSortingMap> &sortingMap)
|
||||
{
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
return ansManagerProxy_->GetCurrentAppSorting(sortingMap);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::SetNotificationAgent(const std::string &agent)
|
||||
{
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
return ansManagerProxy_->SetNotificationAgent(agent);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::GetNotificationAgent(std::string &agent)
|
||||
{
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
return ansManagerProxy_->GetNotificationAgent(agent);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::CanPublishNotificationAsBundle(const std::string &representativeBundle, bool &canPublish)
|
||||
{
|
||||
if (representativeBundle.empty()) {
|
||||
ANS_LOGW("Input representativeBundle is empty");
|
||||
return ERR_ANS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
return ansManagerProxy_->CanPublishAsBundle(representativeBundle, canPublish);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::PublishNotificationAsBundle(
|
||||
const std::string &representativeBundle, const NotificationRequest &request)
|
||||
{
|
||||
if (representativeBundle.empty()) {
|
||||
ANS_LOGE("Refuse to publish the notification whit invalid representativeBundle");
|
||||
return ERR_ANS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (request.GetContent() == nullptr || request.GetNotificationType() == NotificationContent::Type::NONE) {
|
||||
ANS_LOGE("Refuse to publish the notification without valid content");
|
||||
return ERR_ANS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (!CanPublishMediaContent(request)) {
|
||||
ANS_LOGE("Refuse to publish the notification because the sequence numbers actions not match those assigned to "
|
||||
"added action buttons.");
|
||||
return ERR_ANS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
|
||||
sptr<NotificationRequest> reqPtr = new (std::nothrow) NotificationRequest(request);
|
||||
if (reqPtr == nullptr) {
|
||||
ANS_LOGE("Failed to create NotificationRequest ptr");
|
||||
return ERR_ANS_NO_MEMORY;
|
||||
}
|
||||
return ansManagerProxy_->PublishAsBundle(reqPtr, representativeBundle);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::SetNotificationBadgeNum()
|
||||
{
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
int32_t num = -1;
|
||||
return ansManagerProxy_->SetNotificationBadgeNum(num);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::SetNotificationBadgeNum(int32_t num)
|
||||
{
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
return ansManagerProxy_->SetNotificationBadgeNum(num);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::IsAllowedNotify(bool &allowed)
|
||||
{
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
return ansManagerProxy_->IsAllowedNotify(allowed);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::AreNotificationsSuspended(bool &suspended)
|
||||
{
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
return ansManagerProxy_->AreNotificationsSuspended(suspended);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::HasNotificationPolicyAccessPermission(bool &hasPermission)
|
||||
{
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
return ansManagerProxy_->HasNotificationPolicyAccessPermission(hasPermission);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::GetBundleImportance(NotificationSlot::NotificationLevel &importance)
|
||||
{
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
int importanceTemp;
|
||||
ErrCode ret = ansManagerProxy_->GetBundleImportance(importanceTemp);
|
||||
if ((NotificationSlot::LEVEL_NONE <= importanceTemp) && (importanceTemp <= NotificationSlot::LEVEL_HIGH)) {
|
||||
importance = static_cast<NotificationSlot::NotificationLevel>(importanceTemp);
|
||||
} else {
|
||||
importance = NotificationSlot::LEVEL_UNDEFINED;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::SubscribeNotification(const NotificationSubscriber &subscriber)
|
||||
{
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
|
||||
sptr<NotificationSubscriber::SubscriberImpl> subscriberSptr = subscriber.GetImpl();
|
||||
if (subscriberSptr == nullptr) {
|
||||
ANS_LOGE("Failed to subscribe with SubscriberImpl null ptr.");
|
||||
return ERR_ANS_INVALID_PARAM;
|
||||
}
|
||||
return ansManagerProxy_->Subscribe(subscriberSptr, nullptr);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::SubscribeNotification(
|
||||
const NotificationSubscriber &subscriber, const NotificationSubscribeInfo &subscribeInfo)
|
||||
{
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
|
||||
sptr<NotificationSubscribeInfo> sptrInfo = new (std::nothrow) NotificationSubscribeInfo(subscribeInfo);
|
||||
if (sptrInfo == nullptr) {
|
||||
ANS_LOGE("Failed to create NotificationSubscribeInfo ptr.");
|
||||
return ERR_ANS_NO_MEMORY;
|
||||
}
|
||||
|
||||
sptr<NotificationSubscriber::SubscriberImpl> subscriberSptr = subscriber.GetImpl();
|
||||
if (subscriberSptr == nullptr) {
|
||||
ANS_LOGE("Failed to subscribe with SubscriberImpl null ptr.");
|
||||
return ERR_ANS_INVALID_PARAM;
|
||||
}
|
||||
return ansManagerProxy_->Subscribe(subscriberSptr, sptrInfo);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::UnSubscribeNotification(NotificationSubscriber &subscriber)
|
||||
{
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
|
||||
sptr<NotificationSubscriber::SubscriberImpl> subscriberSptr = subscriber.GetImpl();
|
||||
if (subscriberSptr == nullptr) {
|
||||
ANS_LOGE("Failed to unsubscribe with SubscriberImpl null ptr.");
|
||||
return ERR_ANS_INVALID_PARAM;
|
||||
}
|
||||
return ansManagerProxy_->Unsubscribe(subscriberSptr, nullptr);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::UnSubscribeNotification(
|
||||
NotificationSubscriber &subscriber, NotificationSubscribeInfo subscribeInfo)
|
||||
{
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
|
||||
sptr<NotificationSubscribeInfo> sptrInfo = new (std::nothrow) NotificationSubscribeInfo(subscribeInfo);
|
||||
if (sptrInfo == nullptr) {
|
||||
ANS_LOGE("Failed to create NotificationSubscribeInfo ptr.");
|
||||
return ERR_ANS_NO_MEMORY;
|
||||
}
|
||||
|
||||
sptr<NotificationSubscriber::SubscriberImpl> subscriberSptr = subscriber.GetImpl();
|
||||
if (subscriberSptr == nullptr) {
|
||||
ANS_LOGE("Failed to unsubscribe with SubscriberImpl null ptr.");
|
||||
return ERR_ANS_INVALID_PARAM;
|
||||
}
|
||||
return ansManagerProxy_->Unsubscribe(subscriberSptr, sptrInfo);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::RemoveNotification(const std::string &key)
|
||||
{
|
||||
if (key.empty()) {
|
||||
ANS_LOGW("Input key is empty.");
|
||||
return ERR_ANS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
return ansManagerProxy_->Delete(key);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::RemoveNotifications(const std::string &bundleName)
|
||||
{
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
return ansManagerProxy_->DeleteByBundle(bundleName);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::RemoveNotifications()
|
||||
{
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
return ansManagerProxy_->DeleteAll();
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::GetNotificationSlotsForBundle(
|
||||
const std::string &bundleName, std::vector<sptr<NotificationSlot>> &slots)
|
||||
{
|
||||
if (bundleName.empty()) {
|
||||
ANS_LOGE("Input bundleName is empty.");
|
||||
return ERR_ANS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
return ansManagerProxy_->GetSlotsByBundle(bundleName, slots);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::GetAllActiveNotifications(std::vector<sptr<Notification>> ¬ification)
|
||||
{
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
return ansManagerProxy_->GetAllActiveNotifications(notification);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::GetAllActiveNotifications(
|
||||
const std::vector<std::string> key, std::vector<sptr<Notification>> ¬ification)
|
||||
{
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
return ansManagerProxy_->GetSpecialActiveNotifications(key, notification);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::IsAllowedNotify(const std::string &bundle, bool &allowed)
|
||||
{
|
||||
if (bundle.empty()) {
|
||||
ANS_LOGE("Input bundle is empty.");
|
||||
return ERR_ANS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
return ansManagerProxy_->IsSpecialBundleAllowedNotify(bundle, allowed);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::SetNotificationsEnabledForAllBundles(const std::string &deviceId, bool enabled)
|
||||
{
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
return ansManagerProxy_->SetNotificationsEnabledForAllBundles(deviceId, enabled);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::SetNotificationsEnabledForDefaultBundle(const std::string &deviceId, bool enabled)
|
||||
{
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
return ansManagerProxy_->SetNotificationsEnabledForBundle(deviceId, enabled);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::SetNotificationsEnabledForSpecifiedBundle(
|
||||
const std::string &bundle, const std::string &deviceId, bool enabled)
|
||||
{
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
return ansManagerProxy_->SetNotificationsEnabledForSpecialBundle(deviceId, bundle, enabled);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::SetDisturbMode(NotificationConstant::DisturbMode mode)
|
||||
{
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
return ansManagerProxy_->SetDisturbMode(mode);
|
||||
}
|
||||
|
||||
ErrCode AnsNotification::GetDisturbMode(NotificationConstant::DisturbMode &disturbMode)
|
||||
{
|
||||
if (!GetAnsManagerProxy()) {
|
||||
ANS_LOGE("GetAnsManagerProxy fail.");
|
||||
return ERR_ANS_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
return ansManagerProxy_->GetDisturbMode(disturbMode);
|
||||
}
|
||||
|
||||
void AnsNotification::ResetAnsManagerProxy()
|
||||
{
|
||||
ANS_LOGI("enter");
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if ((ansManagerProxy_ != nullptr) && (ansManagerProxy_->AsObject() != nullptr)) {
|
||||
ansManagerProxy_->AsObject()->RemoveDeathRecipient(recipient_);
|
||||
}
|
||||
ansManagerProxy_ = nullptr;
|
||||
}
|
||||
|
||||
bool AnsNotification::GetAnsManagerProxy()
|
||||
{
|
||||
if (!ansManagerProxy_) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (!ansManagerProxy_) {
|
||||
sptr<ISystemAbilityManager> systemAbilityManager =
|
||||
SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (!systemAbilityManager) {
|
||||
ANS_LOGE("Failed to get system ability mgr.");
|
||||
return false;
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> remoteObject =
|
||||
systemAbilityManager->GetSystemAbility(ADVANCED_NOTIFICATION_SERVICE_ABILITY_ID);
|
||||
if (!remoteObject) {
|
||||
ANS_LOGE("Failed to get notification Manager.");
|
||||
return false;
|
||||
}
|
||||
|
||||
ansManagerProxy_ = iface_cast<IAnsManager>(remoteObject);
|
||||
if ((!ansManagerProxy_) || (!ansManagerProxy_->AsObject())) {
|
||||
ANS_LOGE("Failed to get notification Manager's proxy");
|
||||
return false;
|
||||
}
|
||||
|
||||
recipient_ = new AnsManagerDeathRecipient();
|
||||
if (!recipient_) {
|
||||
ANS_LOGE("Failed to create death recipient");
|
||||
return false;
|
||||
}
|
||||
ansManagerProxy_->AsObject()->AddDeathRecipient(recipient_);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AnsNotification::CanPublishMediaContent(const NotificationRequest &request) const
|
||||
{
|
||||
if (NotificationContent::Type::MEDIA != request.GetNotificationType()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (request.GetContent() == nullptr) {
|
||||
ANS_LOGE("Failed to publish notification with null content.");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto media = std::static_pointer_cast<NotificationMediaContent>(request.GetContent()->GetNotificationContent());
|
||||
if (media == nullptr) {
|
||||
ANS_LOGE("Failed to get media content.");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto showActions = media->GetShownActions();
|
||||
uint32_t size = request.GetActionButtons().size();
|
||||
for (auto it = showActions.begin(); it != showActions.end(); ++it) {
|
||||
if (*it > size) {
|
||||
ANS_LOGE("The sequence numbers actions is: %{public}d, the assigned to added action buttons size is: "
|
||||
"%{public}d.",
|
||||
*it,
|
||||
size);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,289 @@
|
||||
/*
|
||||
* 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 "ans_subscriber_proxy.h"
|
||||
|
||||
#include "ans_inner_errors.h"
|
||||
#include "ans_log_wrapper.h"
|
||||
#include "message_option.h"
|
||||
#include "message_parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
AnsSubscriberProxy::AnsSubscriberProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IAnsSubscriber>(impl)
|
||||
{}
|
||||
|
||||
AnsSubscriberProxy::~AnsSubscriberProxy()
|
||||
{}
|
||||
|
||||
ErrCode AnsSubscriberProxy::InnerTransact(
|
||||
uint32_t code, MessageOption &flags, MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
auto remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
ANS_LOGW("[InnerTransact] fail: get Remote fail code %{public}d", code);
|
||||
return ERR_DEAD_OBJECT;
|
||||
}
|
||||
|
||||
int err = remote->SendRequest(code, data, reply, flags);
|
||||
switch (err) {
|
||||
case NO_ERROR: {
|
||||
return ERR_OK;
|
||||
}
|
||||
case DEAD_OBJECT: {
|
||||
ANS_LOGW("[InnerTransact] fail: ipcErr=%{public}d code %{public}d", err, code);
|
||||
return ERR_DEAD_OBJECT;
|
||||
}
|
||||
default: {
|
||||
ANS_LOGW("[InnerTransact] fail: ipcErr=%{public}d code %{public}d", err, code);
|
||||
return ERR_ANS_TRANSACT_FAILED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AnsSubscriberProxy::OnSubscribeResult(NotificationConstant::SubscribeResult result)
|
||||
{
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(AnsSubscriberProxy::GetDescriptor())) {
|
||||
ANS_LOGW("[OnSubscribeResult] fail: write interface token failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data.WriteUint32(result)) {
|
||||
ANS_LOGW("[OnSubscribeResult] fail: write result failed");
|
||||
return;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
MessageOption option = {MessageOption::TF_ASYNC};
|
||||
ErrCode transactResult = InnerTransact(ON_SUBSCRIBE, option, data, reply);
|
||||
if (transactResult != ERR_OK) {
|
||||
ANS_LOGW("[OnSubscribeResult] fail: transact ErrCode=ERR_ANS_TRANSACT_FAILED");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void AnsSubscriberProxy::OnUnsubscribeResult(NotificationConstant::SubscribeResult result)
|
||||
{
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(AnsSubscriberProxy::GetDescriptor())) {
|
||||
ANS_LOGW("[OnUnsubscribeResult] fail: write interface token failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data.WriteUint32(result)) {
|
||||
ANS_LOGW("[OnUnsubscribeResult] fail: write result failed");
|
||||
return;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
MessageOption option = {MessageOption::TF_ASYNC};
|
||||
ErrCode transactResult = InnerTransact(ON_UNSUBSCRIBE, option, data, reply);
|
||||
if (transactResult != ERR_OK) {
|
||||
ANS_LOGW("[OnUnsubscribeResult] fail: transact ErrCode=ERR_ANS_TRANSACT_FAILED");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void AnsSubscriberProxy::OnConsumed(const sptr<Notification> ¬ification)
|
||||
{
|
||||
if (notification == nullptr) {
|
||||
ANS_LOGW("[OnConsumed] fail: notification is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(AnsSubscriberProxy::GetDescriptor())) {
|
||||
ANS_LOGW("[OnConsumed] fail: write interface token failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data.WriteParcelable(notification)) {
|
||||
ANS_LOGW("[OnConsumed] fail: write notification failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
MessageOption option = {MessageOption::TF_ASYNC};
|
||||
ErrCode result = InnerTransact(ON_CONSUMED, option, data, reply);
|
||||
if (result != ERR_OK) {
|
||||
ANS_LOGW("[OnConsumed] fail: transact ErrCode=ERR_ANS_TRANSACT_FAILED");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void AnsSubscriberProxy::OnConsumed(
|
||||
const sptr<Notification> ¬ification, const sptr<NotificationSortingMap> ¬ificationMap)
|
||||
{
|
||||
if (notification == nullptr) {
|
||||
ANS_LOGW("[OnConsumed] fail: notification is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(AnsSubscriberProxy::GetDescriptor())) {
|
||||
ANS_LOGW("[OnConsumed] fail: write interface token failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data.WriteParcelable(notification)) {
|
||||
ANS_LOGW("[OnConsumed] fail: write notification failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data.WriteBool(notificationMap != nullptr)) {
|
||||
ANS_LOGW("[OnConsumed] fail: write existMap failed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (notificationMap != nullptr) {
|
||||
if (!data.WriteParcelable(notificationMap)) {
|
||||
ANS_LOGW("[OnConsumed] fail: write notificationMap failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
MessageOption option = {MessageOption::TF_ASYNC};
|
||||
ErrCode result = InnerTransact(ON_CONSUMED_MAP, option, data, reply);
|
||||
if (result != ERR_OK) {
|
||||
ANS_LOGW("[OnConsumed] fail: transact ErrCode=ERR_ANS_TRANSACT_FAILED");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void AnsSubscriberProxy::OnCanceled(const sptr<Notification> ¬ification)
|
||||
{
|
||||
if (notification == nullptr) {
|
||||
ANS_LOGW("[OnCanceled] fail: notification is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(AnsSubscriberProxy::GetDescriptor())) {
|
||||
ANS_LOGW("[OnCanceled] fail: write interface token failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data.WriteParcelable(notification)) {
|
||||
ANS_LOGW("[OnCanceled] fail: write notification failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
MessageOption option = {MessageOption::TF_ASYNC};
|
||||
ErrCode result = InnerTransact(ON_CANCELED, option, data, reply);
|
||||
if (result != ERR_OK) {
|
||||
ANS_LOGW("[OnCanceled] fail: transact ErrCode=ERR_ANS_TRANSACT_FAILED");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void AnsSubscriberProxy::OnCanceled(
|
||||
const sptr<Notification> ¬ification, const sptr<NotificationSortingMap> ¬ificationMap, int deleteReason)
|
||||
{
|
||||
if (notification == nullptr) {
|
||||
ANS_LOGW("[OnCanceled] fail: notification is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(AnsSubscriberProxy::GetDescriptor())) {
|
||||
ANS_LOGW("[OnCanceled] fail: write interface token failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data.WriteParcelable(notification)) {
|
||||
ANS_LOGW("[OnCanceled] fail: write notification failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data.WriteBool(notificationMap != nullptr)) {
|
||||
ANS_LOGW("[OnCanceled] fail: write existMap failed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (notificationMap != nullptr) {
|
||||
if (!data.WriteParcelable(notificationMap)) {
|
||||
ANS_LOGW("[OnCanceled] fail: write notificationMap failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!data.WriteInt32(deleteReason)) {
|
||||
ANS_LOGW("[OnCanceled] fail: write deleteReason failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
MessageOption option = {MessageOption::TF_ASYNC};
|
||||
ErrCode result = InnerTransact(ON_CANCELED_MAP, option, data, reply);
|
||||
if (result != ERR_OK) {
|
||||
ANS_LOGW("[OnCanceled] fail: transact ErrCode=ERR_ANS_TRANSACT_FAILED");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void AnsSubscriberProxy::OnUpdated(const sptr<NotificationSortingMap> ¬ificationMap)
|
||||
{
|
||||
if (notificationMap == nullptr) {
|
||||
ANS_LOGW("[OnUpdated] fail: notificationMap is empty.");
|
||||
return;
|
||||
}
|
||||
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(AnsSubscriberProxy::GetDescriptor())) {
|
||||
ANS_LOGW("[OnUpdated] fail: write interface token failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data.WriteParcelable(notificationMap)) {
|
||||
ANS_LOGW("[OnUpdated] fail: write notificationMap failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
MessageOption option = {MessageOption::TF_ASYNC};
|
||||
ErrCode result = InnerTransact(ON_UPDATED, option, data, reply);
|
||||
if (result != ERR_OK) {
|
||||
ANS_LOGW("[OnUpdated] fail: transact ErrCode=ERR_ANS_TRANSACT_FAILED");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void AnsSubscriberProxy::OnDisturbModeChanged(NotificationConstant::DisturbMode mode)
|
||||
{
|
||||
MessageParcel data;
|
||||
if (!data.WriteInterfaceToken(AnsSubscriberProxy::GetDescriptor())) {
|
||||
ANS_LOGW("[OnDisturbModeChanged] fail: write interface token failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data.WriteUint32(mode)) {
|
||||
ANS_LOGW("[OnDisturbModeChanged] fail: write mode failed");
|
||||
return;
|
||||
}
|
||||
|
||||
MessageParcel reply;
|
||||
MessageOption option = {MessageOption::TF_ASYNC};
|
||||
ErrCode result = InnerTransact(ON_DISTURB_MODE_CHANGED, option, data, reply);
|
||||
if (result != ERR_OK) {
|
||||
ANS_LOGW("[OnDisturbModeChanged] fail: transact ErrCode=ERR_ANS_TRANSACT_FAILED");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,224 @@
|
||||
/*
|
||||
* 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 <functional>
|
||||
|
||||
#include "ans_subscriber_stub.h"
|
||||
|
||||
#include "ans_const_define.h"
|
||||
#include "ans_inner_errors.h"
|
||||
#include "ans_log_wrapper.h"
|
||||
#include "message_option.h"
|
||||
#include "message_parcel.h"
|
||||
#include "parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
AnsSubscriberStub::AnsSubscriberStub()
|
||||
{
|
||||
interfaces_.emplace(ON_SUBSCRIBE,
|
||||
std::bind(&AnsSubscriberStub::HandleOnSubscribe, this, std::placeholders::_1, std::placeholders::_2));
|
||||
interfaces_.emplace(ON_UNSUBSCRIBE,
|
||||
std::bind(&AnsSubscriberStub::HandleOnUnsubscribe, this, std::placeholders::_1, std::placeholders::_2));
|
||||
interfaces_.emplace(ON_CONSUMED,
|
||||
std::bind(&AnsSubscriberStub::HandleOnConsumed, this, std::placeholders::_1, std::placeholders::_2));
|
||||
interfaces_.emplace(ON_CONSUMED_MAP,
|
||||
std::bind(&AnsSubscriberStub::HandleOnConsumedMap, this, std::placeholders::_1, std::placeholders::_2));
|
||||
interfaces_.emplace(ON_CANCELED,
|
||||
std::bind(&AnsSubscriberStub::HandleOnCanceled, this, std::placeholders::_1, std::placeholders::_2));
|
||||
interfaces_.emplace(ON_CANCELED_MAP,
|
||||
std::bind(&AnsSubscriberStub::HandleOnCanceledMap, this, std::placeholders::_1, std::placeholders::_2));
|
||||
interfaces_.emplace(
|
||||
ON_UPDATED, std::bind(&AnsSubscriberStub::HandleOnUpdated, this, std::placeholders::_1, std::placeholders::_2));
|
||||
interfaces_.emplace(ON_DISTURB_MODE_CHANGED,
|
||||
std::bind(&AnsSubscriberStub::HandleOnDisturbModeChanged, this, std::placeholders::_1, std::placeholders::_2));
|
||||
}
|
||||
|
||||
AnsSubscriberStub::~AnsSubscriberStub()
|
||||
{}
|
||||
|
||||
int32_t AnsSubscriberStub::OnRemoteRequest(
|
||||
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &flags)
|
||||
{
|
||||
std::u16string descriptor = AnsSubscriberStub::GetDescriptor();
|
||||
std::u16string remoteDescriptor = data.ReadInterfaceToken();
|
||||
if (descriptor != remoteDescriptor) {
|
||||
ANS_LOGW("[OnRemoteRequest] fail: invalid interface token!");
|
||||
return OBJECT_NULL;
|
||||
}
|
||||
|
||||
auto it = interfaces_.find(code);
|
||||
if (it == interfaces_.end()) {
|
||||
ANS_LOGW("[OnRemoteRequest] fail: unknown code!");
|
||||
return IRemoteStub<IAnsSubscriber>::OnRemoteRequest(code, data, reply, flags);
|
||||
}
|
||||
|
||||
auto fun = it->second;
|
||||
if (fun == nullptr) {
|
||||
ANS_LOGW("[OnRemoteRequest] fail: not find function!");
|
||||
return IRemoteStub<IAnsSubscriber>::OnRemoteRequest(code, data, reply, flags);
|
||||
}
|
||||
|
||||
fun(data, reply);
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
ErrCode AnsSubscriberStub::HandleOnSubscribe(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
NotificationConstant::SubscribeResult result =
|
||||
static_cast<NotificationConstant::SubscribeResult>(data.ReadUint32());
|
||||
OnSubscribeResult(result);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode AnsSubscriberStub::HandleOnUnsubscribe(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
NotificationConstant::SubscribeResult result =
|
||||
static_cast<NotificationConstant::SubscribeResult>(data.ReadUint32());
|
||||
OnUnsubscribeResult(result);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode AnsSubscriberStub::HandleOnConsumed(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
sptr<Notification> notification = data.ReadParcelable<Notification>();
|
||||
if (!notification) {
|
||||
ANS_LOGW("[HandleOnConsumed] fail: notification ReadParcelable failed");
|
||||
return ERR_ANS_PARCELABLE_FAILED;
|
||||
}
|
||||
|
||||
OnConsumed(notification);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode AnsSubscriberStub::HandleOnConsumedMap(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
sptr<Notification> notification = data.ReadParcelable<Notification>();
|
||||
if (!notification) {
|
||||
ANS_LOGW("[HandleOnConsumedMap] fail: notification ReadParcelable failed");
|
||||
return ERR_ANS_PARCELABLE_FAILED;
|
||||
}
|
||||
|
||||
bool existMap;
|
||||
if (!data.ReadBool(existMap)) {
|
||||
ANS_LOGW("[HandleOnConsumedMap] fail: read existMap failed");
|
||||
return ERR_ANS_PARCELABLE_FAILED;
|
||||
}
|
||||
|
||||
sptr<NotificationSortingMap> notificationMap = nullptr;
|
||||
if (existMap) {
|
||||
notificationMap = data.ReadParcelable<NotificationSortingMap>();
|
||||
if (notificationMap == nullptr) {
|
||||
ANS_LOGW("[HandleOnConsumedMap] fail: read NotificationSortingMap failed");
|
||||
return ERR_ANS_PARCELABLE_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
OnConsumed(notification, notificationMap);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode AnsSubscriberStub::HandleOnCanceled(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
sptr<Notification> notification = data.ReadParcelable<Notification>();
|
||||
if (!notification) {
|
||||
ANS_LOGW("[HandleOnCanceled] fail: notification ReadParcelable failed");
|
||||
return ERR_ANS_PARCELABLE_FAILED;
|
||||
}
|
||||
|
||||
OnCanceled(notification);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode AnsSubscriberStub::HandleOnCanceledMap(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
sptr<Notification> notification = data.ReadParcelable<Notification>();
|
||||
if (!notification) {
|
||||
ANS_LOGW("[HandleOnCanceledMap] fail: notification ReadParcelable failed");
|
||||
return ERR_ANS_PARCELABLE_FAILED;
|
||||
}
|
||||
|
||||
bool existMap;
|
||||
if (!data.ReadBool(existMap)) {
|
||||
ANS_LOGW("[HandleOnCanceledMap] fail: read existMap failed");
|
||||
return ERR_ANS_PARCELABLE_FAILED;
|
||||
}
|
||||
|
||||
sptr<NotificationSortingMap> notificationMap = nullptr;
|
||||
if (existMap) {
|
||||
notificationMap = data.ReadParcelable<NotificationSortingMap>();
|
||||
if (notificationMap == nullptr) {
|
||||
ANS_LOGW("[HandleOnCanceledMap] fail: read NotificationSortingMap failed");
|
||||
return ERR_ANS_PARCELABLE_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
int reason = 0;
|
||||
if (!data.ReadInt32(reason)) {
|
||||
ANS_LOGW("[HandleOnCanceledMap] fail: read reason failed");
|
||||
return ERR_ANS_PARCELABLE_FAILED;
|
||||
}
|
||||
|
||||
OnCanceled(notification, notificationMap, reason);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode AnsSubscriberStub::HandleOnUpdated(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
sptr<NotificationSortingMap> notificationMap = data.ReadParcelable<NotificationSortingMap>();
|
||||
if (!notificationMap) {
|
||||
ANS_LOGW("[HandleOnUpdated] fail: notificationMap ReadParcelable failed");
|
||||
return ERR_ANS_PARCELABLE_FAILED;
|
||||
}
|
||||
|
||||
OnUpdated(notificationMap);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode AnsSubscriberStub::HandleOnDisturbModeChanged(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
NotificationConstant::DisturbMode mode = static_cast<NotificationConstant::DisturbMode>(data.ReadUint32());
|
||||
OnDisturbModeChanged(mode);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
void AnsSubscriberStub::OnSubscribeResult(NotificationConstant::SubscribeResult result)
|
||||
{}
|
||||
|
||||
void AnsSubscriberStub::OnUnsubscribeResult(NotificationConstant::SubscribeResult result)
|
||||
{}
|
||||
|
||||
void AnsSubscriberStub::OnConsumed(const sptr<Notification> ¬ification)
|
||||
{}
|
||||
|
||||
void AnsSubscriberStub::OnConsumed(
|
||||
const sptr<Notification> ¬ification, const sptr<NotificationSortingMap> ¬ificationMap)
|
||||
{}
|
||||
|
||||
void AnsSubscriberStub::OnCanceled(const sptr<Notification> ¬ification)
|
||||
{}
|
||||
|
||||
void AnsSubscriberStub::OnCanceled(
|
||||
const sptr<Notification> ¬ification, const sptr<NotificationSortingMap> ¬ificationMap, int deleteReason)
|
||||
{}
|
||||
|
||||
void AnsSubscriberStub::OnUpdated(const sptr<NotificationSortingMap> ¬ificationMap)
|
||||
{}
|
||||
|
||||
void AnsSubscriberStub::OnDisturbModeChanged(NotificationConstant::DisturbMode mode)
|
||||
{}
|
||||
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,21 @@
|
||||
# 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("kits_target") {
|
||||
deps = [
|
||||
"napi:notification",
|
||||
"native:native_targets",
|
||||
"native/wantagent:native_wantagent",
|
||||
"wantAgent:wantagent",
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
# 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/notification/ans_standard/notification.gni")
|
||||
import("//build/ohos.gni")
|
||||
|
||||
cflags = []
|
||||
|
||||
config("native_module_config") {
|
||||
visibility = [ ":*" ]
|
||||
|
||||
include_dirs = []
|
||||
|
||||
if (target_cpu == "arm") {
|
||||
cflags += [ "-DBINDER_IPC_32BIT" ]
|
||||
}
|
||||
|
||||
defines = [
|
||||
"APP_LOG_TAG = \"ANS_STANDARD\"",
|
||||
"LOG_DOMAIN = 0xD001800",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_shared_library("notification") {
|
||||
include_dirs = [
|
||||
"//foundation/ace/napi/interfaces/kits/napi",
|
||||
"${kits_path}/napi/include",
|
||||
"//third_party/node/src",
|
||||
"//third_party/libuv/include",
|
||||
"//third_party/jsoncpp/include",
|
||||
]
|
||||
|
||||
configs = [ ":native_module_config" ]
|
||||
|
||||
sources = [
|
||||
"src/cancel.cpp",
|
||||
"src/common.cpp",
|
||||
"src/constant.cpp",
|
||||
"src/create_subscriber.cpp",
|
||||
"src/get_active.cpp",
|
||||
"src/init.cpp",
|
||||
"src/publish.cpp",
|
||||
"src/remove.cpp",
|
||||
"src/slot.cpp",
|
||||
"src/subscribe.cpp",
|
||||
"src/unsubscribe.cpp",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"${innerkits_path}:ans_innerkits",
|
||||
"${kits_path}/native:ans_kits",
|
||||
"${kits_path}/native/wantagent:wantagent_kits",
|
||||
"//foundation/ace/napi:ace_napi",
|
||||
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
|
||||
"//third_party/jsoncpp:jsoncpp",
|
||||
"//third_party/libuv:uv_static",
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"appexecfwk_standard:appexecfwk_base",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
|
||||
relative_install_dir = "module"
|
||||
subsystem_name = "notification"
|
||||
part_name = "ans_standard"
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_CANCEL_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_CANCEL_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace NotificationNapi {
|
||||
using namespace OHOS::Notification;
|
||||
|
||||
const int CANCEL_MAX_PARA = 3;
|
||||
const int CANCEL_ALL_MAX_PARA = 1;
|
||||
|
||||
struct AsyncCallbackInfoCancel {
|
||||
napi_env env;
|
||||
napi_async_work asyncWork;
|
||||
napi_ref callback = nullptr;
|
||||
napi_deferred deferred;
|
||||
std::string label;
|
||||
int id;
|
||||
bool hasLabel = false;
|
||||
bool isCallback = false;
|
||||
int errorCode = 0;
|
||||
};
|
||||
|
||||
struct paraInfoCancel {
|
||||
int id = 0;
|
||||
std::string label;
|
||||
bool hasLabel = false;
|
||||
};
|
||||
|
||||
napi_value Cancel(napi_env env, napi_callback_info info);
|
||||
napi_value CancelAll(napi_env env, napi_callback_info info);
|
||||
napi_value ParseParameters(const napi_env &env, const napi_value (&argv)[CANCEL_MAX_PARA], const size_t &argc,
|
||||
paraInfoCancel &info, napi_ref &callback);
|
||||
napi_value ParseParametersByAll(
|
||||
const napi_env &env, const napi_value (&argv)[CANCEL_ALL_MAX_PARA], const size_t &argc, napi_ref &callback);
|
||||
void PaddingAsyncCallbackInfoIs(
|
||||
const napi_env &env, AsyncCallbackInfoCancel *&asynccallbackinfo, const napi_ref &callback, napi_value &promise);
|
||||
|
||||
} // namespace NotificationNapi
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_CANCEL_H
|
||||
@@ -0,0 +1,193 @@
|
||||
/*
|
||||
* 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_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_COMMON_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_COMMON_H
|
||||
|
||||
#include "ans_log_wrapper.h"
|
||||
#include "napi/native_api.h"
|
||||
#include "napi/native_node_api.h"
|
||||
#include "notification_helper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace NotificationNapi {
|
||||
using namespace OHOS::Notification;
|
||||
|
||||
const std::int32_t STR_MAX_SIZE = 64;
|
||||
const int NO_ERROR = 0;
|
||||
const int ERROR = -1;
|
||||
|
||||
enum ContentType {
|
||||
NOTIFICATION_CONTENT_BASIC_TEXT,
|
||||
NOTIFICATION_CONTENT_LONG_TEXT,
|
||||
NOTIFICATION_CONTENT_PICTURE,
|
||||
NOTIFICATION_CONTENT_CONVERSATION,
|
||||
NOTIFICATION_CONTENT_MULTILINE,
|
||||
NOTIFICATION_CONTENT_MEDIA
|
||||
};
|
||||
|
||||
enum SlotType {
|
||||
UNKNOWN_TYPE = 0,
|
||||
SOCIAL_COMMUNICATION = 1,
|
||||
SERVICE_INFORMATION = 2,
|
||||
CONTENT_INFORMATION = 3,
|
||||
OTHER_TYPES = 0xFFFF,
|
||||
};
|
||||
|
||||
enum NotificationReason {
|
||||
CLICK_REASON_DELETE,
|
||||
CANCEL_REASON_DELETE,
|
||||
CANCEL_ALL_REASON_DELETE,
|
||||
ERROR_REASON_DELETE,
|
||||
PACKAGE_CHANGED_REASON_DELETE,
|
||||
USER_STOPPED_REASON_DELETE,
|
||||
PACKAGE_BANNED_REASON_DELETE,
|
||||
APP_CANCEL_REASON_DELETE,
|
||||
APP_CANCEL_ALL_REASON_DELETE,
|
||||
APP_CANCEL_REASON_OTHER
|
||||
};
|
||||
|
||||
enum SemanticActionButton {
|
||||
NONE_ACTION_BUTTON,
|
||||
REPLY_ACTION_BUTTON,
|
||||
READ_ACTION_BUTTON,
|
||||
UNREAD_ACTION_BUTTON,
|
||||
DELETE_ACTION_BUTTON,
|
||||
ARCHIVE_ACTION_BUTTON,
|
||||
MUTE_ACTION_BUTTON,
|
||||
UNMUTE_ACTION_BUTTON,
|
||||
THUMBS_UP_ACTION_BUTTON,
|
||||
THUMBS_DOWN_ACTION_BUTTON,
|
||||
CALL_ACTION_BUTTON
|
||||
};
|
||||
|
||||
enum InputsSource { FREE_FORM_INPUT, OPTION };
|
||||
|
||||
enum DisturbMode { ALLOW_UNKNOWN, ALLOW_ALL, ALLOW_PRIORITY, ALLOW_NONE, ALLOW_ALARMS };
|
||||
|
||||
enum InputEditType { EDIT_AUTO, EDIT_DISABLED, EDIT_ENABLED };
|
||||
|
||||
struct NotificationSubscriberInfo {
|
||||
std::vector<std::string> bundleNames;
|
||||
// std::vector<std::string> deviceIds;
|
||||
int userId = 0;
|
||||
bool hasSubscriberInfo = false;
|
||||
};
|
||||
|
||||
struct CallbackPromiseInfo {
|
||||
napi_ref callback = nullptr;
|
||||
napi_deferred deferred;
|
||||
bool isCallback = false;
|
||||
int errorCode = 0;
|
||||
};
|
||||
|
||||
class Common {
|
||||
|
||||
Common();
|
||||
|
||||
~Common();
|
||||
|
||||
public:
|
||||
static napi_value NapiGetboolean(napi_env env, const bool &isValue);
|
||||
|
||||
static napi_value NapiGetNull(napi_env env);
|
||||
|
||||
static napi_value GetCallbackErrorValue(napi_env env, int errCode);
|
||||
|
||||
static void ReturnCallbackPromise(const napi_env &env, const CallbackPromiseInfo &info, const napi_value &result);
|
||||
|
||||
static void SetCallback(
|
||||
const napi_env &env, const napi_ref &callbackIn, const int &errorCode, const napi_value &result);
|
||||
|
||||
static void SetPromise(const napi_env &env, const napi_deferred &deferred, const napi_value &result);
|
||||
|
||||
static napi_value SetNotificationRequest(
|
||||
const napi_env &env, const std::shared_ptr<OHOS::Notification::Notification> ¬ification, napi_value &result);
|
||||
|
||||
static napi_value SetNotificationRequest2(const napi_env &env,
|
||||
const std::shared_ptr<OHOS::Notification::NotificationRequest> &request, napi_value &result);
|
||||
|
||||
static napi_value SetNotificationSortingMap(
|
||||
const napi_env &env, const std::shared_ptr<NotificationSortingMap> &sortingMap, napi_value &result);
|
||||
|
||||
static napi_value SetNotificationSorting(
|
||||
const napi_env &env, const NotificationSorting &sorting, napi_value &result);
|
||||
|
||||
static napi_value SetNotificationSlot(const napi_env &env, const NotificationSlot &slot, napi_value &result);
|
||||
|
||||
static napi_value SetNotificationContent(
|
||||
const napi_env &env, const std::shared_ptr<NotificationContent> &content, napi_value &result);
|
||||
|
||||
static napi_value SetNotificationBasicContent(
|
||||
const napi_env &env, NotificationBasicContent *basicContent, napi_value &result);
|
||||
|
||||
static napi_value SetNotificationLongTextContent(
|
||||
const napi_env &env, OHOS::Notification::NotificationLongTextContent *longTextContent, napi_value &result);
|
||||
|
||||
// static napi_value SetNotificationPictureContent(
|
||||
// const napi_env &env, OHOS::Notification::NotificationPictureContent * pictureContent, napi_value &result);
|
||||
|
||||
// static napi_value SetNotificationConversationalContent(const napi_env &env,
|
||||
// OHOS::Notification::NotificationConversationalContent * conversationalContent, napi_value &result);
|
||||
|
||||
static napi_value SetNotificationMultiLineContent(
|
||||
const napi_env &env, OHOS::Notification::NotificationMultiLineContent *multiLineContent, napi_value &result);
|
||||
|
||||
// static napi_value SetMessageUser(
|
||||
// const napi_env &env, std::shared_ptr<MessageUser> &messageUser, napi_value &result);
|
||||
|
||||
// static napi_value SetConversationalMessage(const napi_env &env,
|
||||
// std::shared_ptr<NotificationConversationalMessage> &conversationalMessage, napi_value &result);
|
||||
|
||||
static napi_value SetNotificationActionButton(
|
||||
const napi_env &env, std::shared_ptr<NotificationActionButton> &actionButton, napi_value &result);
|
||||
|
||||
static napi_value GetNotificationSubscriberInfo(
|
||||
const napi_env &env, const napi_value &value, NotificationSubscriberInfo &result);
|
||||
|
||||
static napi_value GetNotificationRequest(
|
||||
const napi_env &env, const napi_value &value, NotificationRequest &request);
|
||||
|
||||
static napi_value GetNotificationContent(
|
||||
const napi_env &env, const napi_value &value, NotificationRequest &request);
|
||||
|
||||
static napi_value GetNotificationWantAgent(
|
||||
const napi_env &env, const napi_value &value, NotificationRequest &request);
|
||||
|
||||
static napi_value GetNotificationSlot(const napi_env &env, NotificationSlot &slot, const napi_value &result);
|
||||
|
||||
static bool ContentTypeJSToC(const enum ContentType &inType, enum NotificationContent::Type &outType);
|
||||
|
||||
static bool ContentTypeCToJS(const enum NotificationContent::Type &inType, enum ContentType &outType);
|
||||
|
||||
static bool SlotTypeJSToC(const enum SlotType &inType, enum NotificationConstant::SlotType &outType);
|
||||
|
||||
static bool SlotTypeCToJS(const enum NotificationConstant::SlotType &inType, enum SlotType &outType);
|
||||
|
||||
static bool ReasonCToJS(const int &inType, int &outType);
|
||||
|
||||
static bool DisturbModeJSToC(const enum DisturbMode &inType, enum NotificationConstant::DisturbMode &outType);
|
||||
|
||||
static napi_value CreateWantAgentByJS(const napi_env &env, const std::shared_ptr<WantAgent::WantAgent> &agent);
|
||||
|
||||
private:
|
||||
static const int ARGS_TWO = 2;
|
||||
static const int PARAM0 = 0;
|
||||
static const int PARAM1 = 1;
|
||||
};
|
||||
|
||||
} // namespace NotificationNapi
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_COMMON_H
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_CONSTANT_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_CONSTANT_H
|
||||
|
||||
#include "ans_log_wrapper.h"
|
||||
#include "napi/native_api.h"
|
||||
#include "napi/native_node_api.h"
|
||||
#include "notification_helper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace NotificationNapi {
|
||||
napi_value NotificationReasonInit(napi_env env, napi_value exports);
|
||||
napi_value SlotTypeInit(napi_env env, napi_value exports);
|
||||
napi_value SemanticActionButtonInit(napi_env env, napi_value exports);
|
||||
napi_value InputsSourceInit(napi_env env, napi_value exports);
|
||||
napi_value DisturbModeInit(napi_env env, napi_value exports);
|
||||
napi_value InputEditTypeInit(napi_env env, napi_value exports);
|
||||
napi_value ContentTypeInit(napi_env env, napi_value exports);
|
||||
napi_value ConstantInit(napi_env env, napi_value exports);
|
||||
|
||||
} // namespace NotificationNapi
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_CONSTANT_H
|
||||
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* 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_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_CREATE_SUBSCRIBER_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_CREATE_SUBSCRIBER_H
|
||||
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace NotificationNapi {
|
||||
using namespace OHOS::Notification;
|
||||
|
||||
const int ON_MAX_PARA = 2;
|
||||
const int OFF_MAX_PARA = 1;
|
||||
const std::string CONSUME = "consume";
|
||||
const std::string CANCEL = "cancel";
|
||||
const std::string UPDATE = "update";
|
||||
const std::string SUBSCRIBE = "subscribe";
|
||||
const std::string UNSUBSCRIBE = "unsubscribe";
|
||||
const std::string DIE = "die";
|
||||
const std::string DISTURB_MODE_CHANGE = "disturbModeChange";
|
||||
|
||||
class SubscriberInstance;
|
||||
|
||||
struct AsyncCallbackInfoOn {
|
||||
napi_env env;
|
||||
napi_async_work asyncWork;
|
||||
napi_ref callback = 0;
|
||||
SubscriberInstance *objectInfo;
|
||||
std::string type;
|
||||
};
|
||||
|
||||
struct AsyncCallbackInfoOff {
|
||||
napi_env env;
|
||||
napi_async_work asyncWork;
|
||||
napi_ref callback = 0;
|
||||
SubscriberInstance *objectInfo;
|
||||
std::string type;
|
||||
};
|
||||
|
||||
struct CallbackInfo {
|
||||
napi_env env;
|
||||
napi_ref ref;
|
||||
};
|
||||
|
||||
struct NotificationReceiveDataWorker {
|
||||
napi_env env;
|
||||
napi_ref ref = 0;
|
||||
std::shared_ptr<OHOS::Notification::Notification> request = nullptr;
|
||||
std::shared_ptr<NotificationSortingMap> sortingMap = nullptr;
|
||||
int deleteReason = 0;
|
||||
int result = 0;
|
||||
int disturbMode = 0;
|
||||
};
|
||||
|
||||
class SubscriberInstance : public NotificationSubscriber {
|
||||
public:
|
||||
SubscriberInstance();
|
||||
|
||||
virtual ~SubscriberInstance();
|
||||
|
||||
virtual void OnCanceled(const std::shared_ptr<OHOS::Notification::Notification> &request) override;
|
||||
|
||||
virtual void OnCanceled(const std::shared_ptr<OHOS::Notification::Notification> &request,
|
||||
const std::shared_ptr<NotificationSortingMap> &sortingMap, int deleteReason) override;
|
||||
|
||||
virtual void OnConsumed(const std::shared_ptr<OHOS::Notification::Notification> &request) override;
|
||||
|
||||
virtual void OnConsumed(const std::shared_ptr<OHOS::Notification::Notification> &request,
|
||||
const std::shared_ptr<NotificationSortingMap> &sortingMap) override;
|
||||
|
||||
virtual void OnUpdate(const std::shared_ptr<NotificationSortingMap> &sortingMap) override;
|
||||
|
||||
virtual void OnSubscribeResult(NotificationConstant::SubscribeResult result) override;
|
||||
|
||||
virtual void OnUnsubscribeResult(NotificationConstant::SubscribeResult result) override;
|
||||
|
||||
virtual void OnDied() override;
|
||||
|
||||
virtual void OnDisturbModeChanged(int disturbMode) override;
|
||||
|
||||
void SetCallbackInfo(const napi_env &env, const std::string &type, const napi_ref &ref);
|
||||
|
||||
private:
|
||||
void SetCancelCallbackInfo(const napi_env &env, const napi_ref &ref);
|
||||
|
||||
void SetConsumeCallbackInfo(const napi_env &env, const napi_ref &ref);
|
||||
|
||||
void SetUpdateCallbackInfo(const napi_env &env, const napi_ref &ref);
|
||||
|
||||
void SetSubscribeCallbackInfo(const napi_env &env, const napi_ref &ref);
|
||||
|
||||
void SetUnsubscribeCallbackInfo(const napi_env &env, const napi_ref &ref);
|
||||
|
||||
void SetDieCallbackInfo(const napi_env &env, const napi_ref &ref);
|
||||
|
||||
void SetDisturbModeCallbackInfo(const napi_env &env, const napi_ref &ref);
|
||||
|
||||
private:
|
||||
CallbackInfo canceCallbackInfo_;
|
||||
CallbackInfo consumeCallbackInfo_;
|
||||
CallbackInfo updateCallbackInfo_;
|
||||
CallbackInfo subscribeCallbackInfo_;
|
||||
CallbackInfo unsubscribeCallbackInfo_;
|
||||
CallbackInfo dieCallbackInfo_;
|
||||
CallbackInfo disturbModeCallbackInfo_;
|
||||
};
|
||||
|
||||
napi_value SetSubscriberCallbackData(
|
||||
const napi_env &env, const std::shared_ptr<OHOS::Notification::Notification> &request, napi_value &result);
|
||||
|
||||
napi_value SetSubscriberCallbackData(const napi_env &env,
|
||||
const std::shared_ptr<OHOS::Notification::Notification> &request,
|
||||
const std::shared_ptr<NotificationSortingMap> &sortingMap, int deleteReason, napi_value &result);
|
||||
|
||||
napi_value NotificationSubscriberInit(napi_env env, napi_value exports);
|
||||
|
||||
napi_value On(napi_env env, napi_callback_info info);
|
||||
|
||||
napi_value ParseParametersByOn(const napi_env &env, const size_t &argc, const napi_value (&argv)[ON_MAX_PARA],
|
||||
std::string &type, napi_ref &callback);
|
||||
|
||||
napi_value Off(napi_env env, napi_callback_info info);
|
||||
|
||||
napi_value ParseParametersByOff(
|
||||
const napi_env &env, const size_t &argc, const napi_value (&argv)[OFF_MAX_PARA], std::string &type);
|
||||
|
||||
napi_value SubscriberConstructor(napi_env env, napi_callback_info info);
|
||||
|
||||
napi_value CreateSubscriber(napi_env env, napi_callback_info info);
|
||||
|
||||
bool CreateSubscriberInstanceRecord(SubscriberInstance **subscriber);
|
||||
|
||||
bool AddAsyncCallbackInfoOn(SubscriberInstance *subscriber, AsyncCallbackInfoOn *asynccallbackinfo);
|
||||
|
||||
bool DelAsyncCallbackInfoOn(SubscriberInstance *subscriber, const std::string &type = "");
|
||||
|
||||
bool HasNotificationSubscriber(SubscriberInstance *subscriber);
|
||||
|
||||
static std::mutex mutex_;
|
||||
static napi_value g_NotificationSubscriber;
|
||||
static std::map<SubscriberInstance *, std::vector<AsyncCallbackInfoOn *>> g_SubscriberInstances;
|
||||
|
||||
} // namespace NotificationNapi
|
||||
} // namespace OHOS
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_CREATE_SUBSCRIBER_H
|
||||
@@ -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_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_GET_ACTIVE_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_GET_ACTIVE_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace NotificationNapi {
|
||||
using namespace OHOS::Notification;
|
||||
|
||||
const int ALL_ACTIVE_MAX_PARA = 2;
|
||||
const int ACTIVE_OR_NUMS_MAX_PARA = 1;
|
||||
|
||||
struct AsyncCallbackInfoActive {
|
||||
napi_env env;
|
||||
napi_async_work asyncWork;
|
||||
napi_ref callback = nullptr;
|
||||
napi_deferred deferred;
|
||||
std::vector<std::string> strValue;
|
||||
bool isCallback = false;
|
||||
napi_value result = nullptr;
|
||||
int errorCode = 0;
|
||||
};
|
||||
|
||||
napi_value GetAllActiveNotifications(napi_env env, napi_callback_info info);
|
||||
napi_value GetActiveNotifications(napi_env env, napi_callback_info info);
|
||||
napi_value GetActiveNotificationNums(napi_env env, napi_callback_info info);
|
||||
napi_value ParseParametersByAllActive(const napi_env &env, const napi_value (&argv)[ALL_ACTIVE_MAX_PARA],
|
||||
const size_t &argc, std::vector<std::string> &strValue, napi_ref &callback);
|
||||
napi_value ParseParameters(
|
||||
const napi_env &env, const napi_value (&argv)[ACTIVE_OR_NUMS_MAX_PARA], const size_t &argc, napi_ref &callback);
|
||||
void PaddingAsyncCallbackInfoIs(
|
||||
const napi_env &env, AsyncCallbackInfoActive *&asynccallbackinfo, const napi_ref &callback, napi_value &promise);
|
||||
|
||||
} // namespace NotificationNapi
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_GET_ACTIVE_H
|
||||
@@ -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_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_INIT_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_INIT_H
|
||||
|
||||
#include "napi/native_api.h"
|
||||
#include "napi/native_node_api.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace NotificationNapi {
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
__attribute__((constructor)) void RegisterModule(void);
|
||||
napi_value NotificationInit(napi_env env, napi_value exports);
|
||||
static napi_value Init(napi_env env, napi_value exports);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Module define
|
||||
*/
|
||||
napi_module _module = {
|
||||
|
||||
.nm_version = 1,
|
||||
.nm_flags = 0,
|
||||
.nm_filename = nullptr,
|
||||
.nm_register_func = Init,
|
||||
.nm_modname = "notificationnapi",
|
||||
.nm_priv = ((void *)0),
|
||||
.reserved = {0}
|
||||
|
||||
};
|
||||
|
||||
} // namespace NotificationNapi
|
||||
} // namespace OHOS
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_INIT_H
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_PUBLISH_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_PUBLISH_H
|
||||
|
||||
#include <string>
|
||||
#include "common.h"
|
||||
|
||||
static const int32_t PUBLISH_NOTIFICATION_MAX = 2;
|
||||
|
||||
namespace OHOS {
|
||||
namespace NotificationNapi {
|
||||
struct AsyncCallbackInfoPublish {
|
||||
napi_env env;
|
||||
napi_async_work asyncWork;
|
||||
napi_ref callback = 0;
|
||||
napi_deferred deferred;
|
||||
NotificationRequest notificationRequest;
|
||||
std::string lable;
|
||||
bool isCallback = false;
|
||||
bool isPublishNotificationTwoPara = false;
|
||||
int errorCode = 0;
|
||||
};
|
||||
|
||||
struct NotificationLongTextContent {
|
||||
std::string longText;
|
||||
std::string briefText;
|
||||
std::string expandedTitle;
|
||||
};
|
||||
|
||||
struct NotificationPictureContent {};
|
||||
|
||||
struct NotificationConversationalContent {};
|
||||
|
||||
struct NotificationMultiLineContent {};
|
||||
|
||||
struct NotificationContentPublish {
|
||||
int32_t type;
|
||||
NotificationBasicContent notificationBasicContent;
|
||||
NotificationLongTextContent notificationLongTextContent;
|
||||
NotificationPictureContent notificationPictureContent;
|
||||
NotificationConversationalContent notificationConversationalContent;
|
||||
NotificationMultiLineContent notificationMultiLineContent;
|
||||
};
|
||||
|
||||
struct ParseParametersPublish {
|
||||
napi_env env;
|
||||
size_t argc;
|
||||
bool isCallback;
|
||||
std::string lable;
|
||||
napi_ref callback;
|
||||
};
|
||||
|
||||
napi_value ParseParametersByPublish(ParseParametersPublish &parseParameters,
|
||||
const napi_value (&argv)[PUBLISH_NOTIFICATION_MAX], NotificationRequest ¬ificationRequest);
|
||||
void PaddingCallbackInfoInfoPublish(AsyncCallbackInfoPublish *&asynccallbackinfo,
|
||||
const ParseParametersPublish &parseParameters, const NotificationRequest ¬ificationRequest);
|
||||
void PaddingPublishCallbackPromise(const napi_env &env, const ParseParametersPublish &parseParameters,
|
||||
AsyncCallbackInfoPublish *&asynccallbackinfo, napi_value &promise);
|
||||
napi_value Publish(napi_env env, napi_callback_info info);
|
||||
} // namespace NotificationNapi
|
||||
} // namespace OHOS
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_PUBLISH_H
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_REMOVE_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_REMOVE_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace NotificationNapi {
|
||||
using namespace OHOS::Notification;
|
||||
|
||||
const int REMOVE_OR_BUNDLE_MAX_PARA = 2;
|
||||
const int REMOVE_ALL_MAX_PARA = 1;
|
||||
|
||||
struct AsyncCallbackInfoRemove {
|
||||
napi_env env;
|
||||
napi_async_work asyncWork;
|
||||
napi_ref callback = nullptr;
|
||||
napi_deferred deferred;
|
||||
std::string strValue;
|
||||
bool isCallback = false;
|
||||
int errorCode = 0;
|
||||
};
|
||||
|
||||
napi_value Remove(napi_env env, napi_callback_info info);
|
||||
napi_value RemoveAsBundle(napi_env env, napi_callback_info info);
|
||||
napi_value RemoveAll(napi_env env, napi_callback_info info);
|
||||
|
||||
napi_value ParseParameters(const napi_env &env, const napi_value (&argv)[REMOVE_OR_BUNDLE_MAX_PARA], const size_t &argc,
|
||||
std::string &strValue, napi_ref &callback);
|
||||
|
||||
napi_value ParseParametersByRemoveAll(
|
||||
const napi_env &env, const napi_value (&argv)[REMOVE_ALL_MAX_PARA], const size_t &argc, napi_ref &callback);
|
||||
|
||||
void PaddingAsyncCallbackInfoIs(
|
||||
const napi_env &env, AsyncCallbackInfoRemove *&asynccallbackinfo, const napi_ref &callback, napi_value &promise);
|
||||
|
||||
} // namespace NotificationNapi
|
||||
} // namespace OHOS
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_REMOVE_H
|
||||
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* 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_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_SLOT_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_SLOT_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace NotificationNapi {
|
||||
using namespace OHOS::Notification;
|
||||
|
||||
const int ADD_SLOT_MAX_PARA = 2;
|
||||
const int ADD_SLOTS_MAX_PARA = 2;
|
||||
const int GET_SLOT_MAX_PARA = 2;
|
||||
const int GET_SLOTS_MAX_PARA = 1;
|
||||
const int REMOVE_SLOT_MAX_PARA = 2;
|
||||
|
||||
struct AsyncCallbackInfoAddSlot {
|
||||
napi_env env;
|
||||
napi_async_work asyncWork;
|
||||
napi_ref callback = nullptr;
|
||||
napi_deferred deferred;
|
||||
NotificationSlot slot;
|
||||
bool isCallback = false;
|
||||
int errorCode = 0;
|
||||
};
|
||||
|
||||
struct AsyncCallbackInfoAddSlots {
|
||||
napi_env env;
|
||||
napi_async_work asyncWork;
|
||||
napi_ref callback = nullptr;
|
||||
napi_deferred deferred;
|
||||
std::vector<NotificationSlot> slots;
|
||||
bool isCallback = false;
|
||||
int errorCode = 0;
|
||||
};
|
||||
|
||||
struct AsyncCallbackInfoGetSlot {
|
||||
napi_env env;
|
||||
napi_async_work asyncWork;
|
||||
napi_ref callback = nullptr;
|
||||
napi_deferred deferred;
|
||||
enum NotificationConstant::SlotType outType;
|
||||
bool isCallback = false;
|
||||
napi_value result = nullptr;
|
||||
int errorCode = 0;
|
||||
};
|
||||
|
||||
struct AsyncCallbackInfoGetSlots {
|
||||
napi_env env;
|
||||
napi_async_work asyncWork;
|
||||
napi_ref callback = nullptr;
|
||||
napi_deferred deferred;
|
||||
bool isCallback = false;
|
||||
napi_value result = nullptr;
|
||||
int errorCode = 0;
|
||||
};
|
||||
|
||||
struct AsyncCallbackInfoRemoveSlot {
|
||||
napi_env env;
|
||||
napi_async_work asyncWork;
|
||||
napi_ref callback = nullptr;
|
||||
napi_deferred deferred;
|
||||
enum NotificationConstant::SlotType outType;
|
||||
bool isCallback = false;
|
||||
int errorCode = 0;
|
||||
};
|
||||
|
||||
napi_value AddSlot(napi_env env, napi_callback_info info);
|
||||
napi_value AddSlots(napi_env env, napi_callback_info info);
|
||||
napi_value GetSlot(napi_env env, napi_callback_info info);
|
||||
napi_value GetSlots(napi_env env, napi_callback_info info);
|
||||
napi_value RemoveSlot(napi_env env, napi_callback_info info);
|
||||
|
||||
napi_value ParseParametersByAddSlot(const napi_env &env, const napi_value (&argv)[ADD_SLOT_MAX_PARA],
|
||||
const size_t &argc, NotificationSlot &slot, napi_ref &callback);
|
||||
|
||||
void PaddingAsyncCallbackInfoIsByAddSlot(
|
||||
const napi_env &env, AsyncCallbackInfoAddSlot *&asynccallbackinfo, const napi_ref &callback, napi_value &promise);
|
||||
|
||||
napi_value ParseParametersByAddSlots(const napi_env &env, const napi_value (&argv)[ADD_SLOTS_MAX_PARA],
|
||||
const size_t &argc, std::vector<NotificationSlot> &slots, napi_ref &callback);
|
||||
|
||||
void PaddingAsyncCallbackInfoIsByAddSlots(
|
||||
const napi_env &env, AsyncCallbackInfoAddSlots *&asynccallbackinfo, const napi_ref &callback, napi_value &promise);
|
||||
|
||||
napi_value ParseParametersByGetSlot(const napi_env &env, const napi_value (&argv)[GET_SLOT_MAX_PARA],
|
||||
const size_t &argc, enum NotificationConstant::SlotType &outType, napi_ref &callback);
|
||||
|
||||
void PaddingAsyncCallbackInfoIsByGetSlot(
|
||||
const napi_env &env, AsyncCallbackInfoGetSlot *&asynccallbackinfo, const napi_ref &callback, napi_value &promise);
|
||||
|
||||
napi_value ParseParametersByGetSlots(
|
||||
const napi_env &env, const napi_value (&argv)[GET_SLOTS_MAX_PARA], const size_t &argc, napi_ref &callback);
|
||||
|
||||
void PaddingAsyncCallbackInfoIsByGetSlots(
|
||||
const napi_env &env, AsyncCallbackInfoGetSlots *&asynccallbackinfo, const napi_ref &callback, napi_value &promise);
|
||||
|
||||
napi_value ParseParametersByRemoveSlot(const napi_env &env, const napi_value (&argv)[REMOVE_SLOT_MAX_PARA],
|
||||
const size_t &argc, enum NotificationConstant::SlotType &outType, napi_ref &callback);
|
||||
|
||||
void PaddingAsyncCallbackInfoIsByRemoveSlot(const napi_env &env, AsyncCallbackInfoRemoveSlot *&asynccallbackinfo,
|
||||
const napi_ref &callback, napi_value &promise);
|
||||
|
||||
} // namespace NotificationNapi
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_SLOT_H
|
||||
@@ -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_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_SUBSCRIBE_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_SUBSCRIBE_H
|
||||
|
||||
#include "create_subscriber.h"
|
||||
#include "common.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace NotificationNapi {
|
||||
using namespace OHOS::Notification;
|
||||
|
||||
const int SUBSRIBE_MAX_PARA = 3;
|
||||
|
||||
struct AsyncCallbackInfoSubscribe {
|
||||
napi_env env;
|
||||
napi_async_work asyncWork;
|
||||
napi_ref callback = 0;
|
||||
napi_deferred deferred;
|
||||
SubscriberInstance *objectInfo = nullptr;
|
||||
NotificationSubscriberInfo subscriberInfo;
|
||||
bool isCallback = false;
|
||||
int errorCode = 0;
|
||||
};
|
||||
|
||||
napi_value ParseParameters(const napi_env &env, const napi_value (&argv)[SUBSRIBE_MAX_PARA], const size_t &argc,
|
||||
NotificationSubscriberInfo &subscriberInfo, SubscriberInstance *&objectInfo, napi_ref &callback);
|
||||
|
||||
void PaddingAsyncCallbackInfoIs(
|
||||
const napi_env &env, AsyncCallbackInfoSubscribe *&asynccallbackinfo, const napi_ref &callback, napi_value &promise);
|
||||
|
||||
napi_value Subscribe(napi_env env, napi_callback_info info);
|
||||
|
||||
} // namespace NotificationNapi
|
||||
} // namespace OHOS
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_SUBSCRIBE_H
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
#ifndef BASE_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_UNSUBSCRIBE_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_UNSUBSCRIBE_H
|
||||
|
||||
#include "common.h"
|
||||
#include "create_subscriber.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace NotificationNapi {
|
||||
using namespace OHOS::Notification;
|
||||
|
||||
const int UNSUBSCRIBE_MAX_PARA = 2;
|
||||
|
||||
struct AsyncCallbackInfoUnsubscribe {
|
||||
napi_env env;
|
||||
napi_async_work asyncWork;
|
||||
napi_ref callback = 0;
|
||||
napi_deferred deferred;
|
||||
SubscriberInstance *objectInfo = nullptr;
|
||||
bool isCallback = false;
|
||||
int errorCode = 0;
|
||||
};
|
||||
|
||||
napi_value ParseParameters(const napi_env &env, const size_t &argc, const napi_value (&argv)[UNSUBSCRIBE_MAX_PARA],
|
||||
SubscriberInstance *&objectInfo, napi_ref &callback);
|
||||
|
||||
void PaddingAsyncCallbackInfoIs(const napi_env &env, const size_t &argc,
|
||||
AsyncCallbackInfoUnsubscribe *&asynccallbackinfo, const napi_ref &callback, napi_value &promise);
|
||||
|
||||
napi_value Unsubscribe(napi_env env, napi_callback_info info);
|
||||
|
||||
} // namespace NotificationNapi
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NAPI_INCLUDE_UNSUBSCRIBE_H
|
||||
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
* 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 "cancel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace NotificationNapi {
|
||||
napi_value ParseParameters(const napi_env &env, const napi_value (&argv)[CANCEL_MAX_PARA], const size_t &argc,
|
||||
paraInfoCancel &info, napi_ref &callback)
|
||||
{
|
||||
ANS_LOGI("ParseParameters start");
|
||||
|
||||
napi_valuetype valuetype;
|
||||
// argv[0]: id: number
|
||||
NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype));
|
||||
NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number expected.");
|
||||
NAPI_CALL(env, napi_get_value_int32(env, argv[0], &info.id));
|
||||
|
||||
// argv[1]: label: string / callback
|
||||
if (argc >= CANCEL_MAX_PARA - 1) {
|
||||
NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype));
|
||||
if (valuetype == napi_string) {
|
||||
char str[STR_MAX_SIZE] = {0};
|
||||
size_t strLen = 0;
|
||||
NAPI_CALL(env, napi_get_value_string_utf8(env, argv[1], str, STR_MAX_SIZE - 1, &strLen));
|
||||
info.label = str;
|
||||
info.hasLabel = true;
|
||||
} else if (valuetype == napi_function) {
|
||||
napi_create_reference(env, argv[1], 1, &callback);
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// argv[2]:callback
|
||||
if (argc >= CANCEL_MAX_PARA) {
|
||||
NAPI_CALL(env, napi_typeof(env, argv[CANCEL_MAX_PARA - 1], &valuetype));
|
||||
NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected.");
|
||||
napi_create_reference(env, argv[CANCEL_MAX_PARA - 1], 1, &callback);
|
||||
}
|
||||
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
|
||||
napi_value ParseParametersByAll(
|
||||
const napi_env &env, const napi_value (&argv)[CANCEL_ALL_MAX_PARA], const size_t &argc, napi_ref &callback)
|
||||
{
|
||||
ANS_LOGI("ParseParametersByAll start");
|
||||
|
||||
if (argc >= CANCEL_ALL_MAX_PARA) {
|
||||
napi_valuetype valuetype;
|
||||
// argv[0]:callback
|
||||
NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype));
|
||||
NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected.");
|
||||
napi_create_reference(env, argv[0], 1, &callback);
|
||||
}
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
|
||||
void PaddingAsyncCallbackInfoIs(
|
||||
const napi_env &env, AsyncCallbackInfoCancel *&asynccallbackinfo, const napi_ref &callback, napi_value &promise)
|
||||
{
|
||||
ANS_LOGI("PaddingAsyncCallbackInfoIs start");
|
||||
|
||||
if (callback) {
|
||||
asynccallbackinfo->callback = callback;
|
||||
asynccallbackinfo->isCallback = true;
|
||||
} else {
|
||||
napi_deferred deferred = nullptr;
|
||||
NAPI_CALL_RETURN_VOID(env, napi_create_promise(env, &deferred, &promise));
|
||||
asynccallbackinfo->deferred = deferred;
|
||||
asynccallbackinfo->isCallback = false;
|
||||
}
|
||||
}
|
||||
|
||||
napi_value Cancel(napi_env env, napi_callback_info info)
|
||||
{
|
||||
ANS_LOGI("Cancel start");
|
||||
|
||||
size_t argc = CANCEL_MAX_PARA;
|
||||
napi_value argv[CANCEL_MAX_PARA];
|
||||
napi_value thisVar = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL));
|
||||
NAPI_ASSERT(env, argc >= 1, "Wrong number of arguments");
|
||||
napi_ref callback = nullptr;
|
||||
|
||||
paraInfoCancel paraInfo;
|
||||
if (ParseParameters(env, argv, argc, paraInfo, callback) == nullptr) {
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
ANS_LOGI("Cancel id = %{public}d", paraInfo.id);
|
||||
ANS_LOGI("Cancel label = %{public}s", paraInfo.label.c_str());
|
||||
|
||||
AsyncCallbackInfoCancel *asynccallbackinfo = new AsyncCallbackInfoCancel{
|
||||
.env = env, .asyncWork = nullptr, .id = paraInfo.id, .label = paraInfo.label, .hasLabel = paraInfo.hasLabel};
|
||||
|
||||
napi_value promise = 0;
|
||||
PaddingAsyncCallbackInfoIs(env, asynccallbackinfo, callback, promise);
|
||||
|
||||
napi_value resourceName;
|
||||
napi_create_string_latin1(env, "cancel", NAPI_AUTO_LENGTH, &resourceName);
|
||||
// Asynchronous function call
|
||||
napi_create_async_work(env,
|
||||
nullptr,
|
||||
resourceName,
|
||||
[](napi_env env, void *data) {
|
||||
ANS_LOGI("Cancel napi_create_async_work start");
|
||||
AsyncCallbackInfoCancel *asynccallbackinfo = (AsyncCallbackInfoCancel *)data;
|
||||
|
||||
if (asynccallbackinfo->hasLabel) {
|
||||
asynccallbackinfo->errorCode = NotificationHelper::CancelNotification(asynccallbackinfo->id);
|
||||
} else {
|
||||
asynccallbackinfo->errorCode =
|
||||
NotificationHelper::CancelNotification(asynccallbackinfo->label, asynccallbackinfo->id);
|
||||
}
|
||||
},
|
||||
[](napi_env env, napi_status status, void *data) {
|
||||
ANS_LOGI("Cancel napi_create_async_work end");
|
||||
AsyncCallbackInfoCancel *asynccallbackinfo = (AsyncCallbackInfoCancel *)data;
|
||||
|
||||
CallbackPromiseInfo info;
|
||||
info.isCallback = asynccallbackinfo->isCallback;
|
||||
info.callback = asynccallbackinfo->callback;
|
||||
info.deferred = asynccallbackinfo->deferred;
|
||||
info.errorCode = asynccallbackinfo->errorCode;
|
||||
|
||||
Common::ReturnCallbackPromise(env, info, Common::NapiGetNull(env));
|
||||
|
||||
napi_delete_async_work(env, asynccallbackinfo->asyncWork);
|
||||
if (asynccallbackinfo) {
|
||||
delete asynccallbackinfo;
|
||||
asynccallbackinfo = nullptr;
|
||||
}
|
||||
},
|
||||
(void *)asynccallbackinfo,
|
||||
&asynccallbackinfo->asyncWork);
|
||||
|
||||
NAPI_CALL(env, napi_queue_async_work(env, asynccallbackinfo->asyncWork));
|
||||
|
||||
if (asynccallbackinfo->isCallback) {
|
||||
return Common::NapiGetNull(env);
|
||||
} else {
|
||||
return promise;
|
||||
}
|
||||
}
|
||||
|
||||
napi_value CancelAll(napi_env env, napi_callback_info info)
|
||||
{
|
||||
ANS_LOGI("CancelAll start");
|
||||
|
||||
size_t argc = CANCEL_ALL_MAX_PARA;
|
||||
napi_value argv[CANCEL_ALL_MAX_PARA];
|
||||
napi_value thisVar = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL));
|
||||
NAPI_ASSERT(env, argc >= 0, "Wrong number of arguments");
|
||||
napi_ref callback = nullptr;
|
||||
|
||||
if (ParseParametersByAll(env, argv, argc, callback) == nullptr) {
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
|
||||
AsyncCallbackInfoCancel *asynccallbackinfo = new AsyncCallbackInfoCancel{.env = env, .asyncWork = nullptr};
|
||||
|
||||
napi_value promise = 0;
|
||||
PaddingAsyncCallbackInfoIs(env, asynccallbackinfo, callback, promise);
|
||||
|
||||
napi_value resourceName;
|
||||
napi_create_string_latin1(env, "cancelAll", NAPI_AUTO_LENGTH, &resourceName);
|
||||
// Asynchronous function call
|
||||
napi_create_async_work(env,
|
||||
nullptr,
|
||||
resourceName,
|
||||
[](napi_env env, void *data) {
|
||||
ANS_LOGI("CancelAll napi_create_async_work start");
|
||||
AsyncCallbackInfoCancel *asynccallbackinfo = (AsyncCallbackInfoCancel *)data;
|
||||
asynccallbackinfo->errorCode = NotificationHelper::CancelAllNotifications();
|
||||
},
|
||||
[](napi_env env, napi_status status, void *data) {
|
||||
ANS_LOGI("CancelAll napi_create_async_work end");
|
||||
AsyncCallbackInfoCancel *asynccallbackinfo = (AsyncCallbackInfoCancel *)data;
|
||||
|
||||
CallbackPromiseInfo info;
|
||||
info.isCallback = asynccallbackinfo->isCallback;
|
||||
info.callback = asynccallbackinfo->callback;
|
||||
info.deferred = asynccallbackinfo->deferred;
|
||||
info.errorCode = asynccallbackinfo->errorCode;
|
||||
Common::ReturnCallbackPromise(env, info, Common::NapiGetNull(env));
|
||||
|
||||
napi_delete_async_work(env, asynccallbackinfo->asyncWork);
|
||||
if (asynccallbackinfo) {
|
||||
delete asynccallbackinfo;
|
||||
asynccallbackinfo = nullptr;
|
||||
}
|
||||
},
|
||||
(void *)asynccallbackinfo,
|
||||
&asynccallbackinfo->asyncWork);
|
||||
|
||||
NAPI_CALL(env, napi_queue_async_work(env, asynccallbackinfo->asyncWork));
|
||||
|
||||
if (asynccallbackinfo->isCallback) {
|
||||
return Common::NapiGetNull(env);
|
||||
} else {
|
||||
return promise;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace NotificationNapi
|
||||
} // namespace OHOS
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,203 @@
|
||||
/*
|
||||
* 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 "constant.h"
|
||||
#include "common.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace NotificationNapi {
|
||||
using namespace OHOS::Notification;
|
||||
|
||||
void SetNamedPropertyByInteger(napi_env env, napi_value dstObj, int32_t objName, const char *propName)
|
||||
{
|
||||
napi_value prop = nullptr;
|
||||
if (napi_create_int32(env, objName, &prop) == napi_ok) {
|
||||
napi_set_named_property(env, dstObj, propName, prop);
|
||||
}
|
||||
}
|
||||
|
||||
napi_value NotificationReasonInit(napi_env env, napi_value exports)
|
||||
{
|
||||
ANS_LOGI("%{public}s, called", __func__);
|
||||
|
||||
napi_value obj = nullptr;
|
||||
napi_create_object(env, &obj);
|
||||
|
||||
SetNamedPropertyByInteger(env, obj, NotificationReason::CLICK_REASON_DELETE, "CLICK_REASON_DELETE");
|
||||
SetNamedPropertyByInteger(env, obj, NotificationReason::CANCEL_REASON_DELETE, "CANCEL_REASON_DELETE");
|
||||
SetNamedPropertyByInteger(env, obj, NotificationReason::CANCEL_ALL_REASON_DELETE, "CANCEL_ALL_REASON_DELETE");
|
||||
SetNamedPropertyByInteger(env, obj, NotificationReason::ERROR_REASON_DELETE, "ERROR_REASON_DELETE");
|
||||
SetNamedPropertyByInteger(
|
||||
env, obj, NotificationReason::PACKAGE_CHANGED_REASON_DELETE, "PACKAGE_CHANGED_REASON_DELETE");
|
||||
SetNamedPropertyByInteger(env, obj, NotificationReason::USER_STOPPED_REASON_DELETE, "USER_STOPPED_REASON_DELETE");
|
||||
SetNamedPropertyByInteger(
|
||||
env, obj, NotificationReason::PACKAGE_BANNED_REASON_DELETE, "PACKAGE_BANNED_REASON_DELETE");
|
||||
SetNamedPropertyByInteger(env, obj, NotificationReason::APP_CANCEL_REASON_DELETE, "APP_CANCEL_REASON_DELETE");
|
||||
SetNamedPropertyByInteger(
|
||||
env, obj, NotificationReason::APP_CANCEL_ALL_REASON_DELETE, "APP_CANCEL_ALL_REASON_DELETE");
|
||||
SetNamedPropertyByInteger(env, obj, NotificationReason::APP_CANCEL_REASON_OTHER, "APP_CANCEL_REASON_OTHER");
|
||||
|
||||
napi_property_descriptor exportFuncs[] = {
|
||||
DECLARE_NAPI_PROPERTY("NotificationReason", obj),
|
||||
};
|
||||
|
||||
napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
|
||||
return exports;
|
||||
}
|
||||
|
||||
napi_value SlotTypeInit(napi_env env, napi_value exports)
|
||||
{
|
||||
ANS_LOGI("%{public}s, called", __func__);
|
||||
|
||||
napi_value obj = nullptr;
|
||||
napi_create_object(env, &obj);
|
||||
|
||||
SetNamedPropertyByInteger(env, obj, SlotType::UNKNOWN_TYPE, "UNKNOWN_TYPE");
|
||||
SetNamedPropertyByInteger(env, obj, SlotType::SOCIAL_COMMUNICATION, "SOCIAL_COMMUNICATION");
|
||||
SetNamedPropertyByInteger(env, obj, SlotType::SERVICE_INFORMATION, "SERVICE_INFORMATION");
|
||||
SetNamedPropertyByInteger(env, obj, SlotType::CONTENT_INFORMATION, "CONTENT_INFORMATION");
|
||||
SetNamedPropertyByInteger(env, obj, SlotType::OTHER_TYPES, "OTHER_TYPES");
|
||||
|
||||
napi_property_descriptor exportFuncs[] = {
|
||||
DECLARE_NAPI_PROPERTY("SlotType", obj),
|
||||
};
|
||||
|
||||
napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
|
||||
return exports;
|
||||
}
|
||||
|
||||
napi_value SemanticActionButtonInit(napi_env env, napi_value exports)
|
||||
{
|
||||
ANS_LOGI("%{public}s, called", __func__);
|
||||
|
||||
napi_value obj = nullptr;
|
||||
napi_create_object(env, &obj);
|
||||
|
||||
SetNamedPropertyByInteger(env, obj, SemanticActionButton::NONE_ACTION_BUTTON, "NONE_ACTION_BUTTON");
|
||||
SetNamedPropertyByInteger(env, obj, SemanticActionButton::REPLY_ACTION_BUTTON, "REPLY_ACTION_BUTTON");
|
||||
SetNamedPropertyByInteger(env, obj, SemanticActionButton::READ_ACTION_BUTTON, "READ_ACTION_BUTTON");
|
||||
SetNamedPropertyByInteger(env, obj, SemanticActionButton::UNREAD_ACTION_BUTTON, "UNREAD_ACTION_BUTTON");
|
||||
SetNamedPropertyByInteger(env, obj, SemanticActionButton::DELETE_ACTION_BUTTON, "DELETE_ACTION_BUTTON");
|
||||
SetNamedPropertyByInteger(env, obj, SemanticActionButton::ARCHIVE_ACTION_BUTTON, "ARCHIVE_ACTION_BUTTON");
|
||||
SetNamedPropertyByInteger(env, obj, SemanticActionButton::MUTE_ACTION_BUTTON, "MUTE_ACTION_BUTTON");
|
||||
SetNamedPropertyByInteger(env, obj, SemanticActionButton::UNMUTE_ACTION_BUTTON, "UNMUTE_ACTION_BUTTON");
|
||||
SetNamedPropertyByInteger(env, obj, SemanticActionButton::THUMBS_UP_ACTION_BUTTON, "THUMBS_UP_ACTION_BUTTON");
|
||||
SetNamedPropertyByInteger(env, obj, SemanticActionButton::THUMBS_DOWN_ACTION_BUTTON, "THUMBS_DOWN_ACTION_BUTTON");
|
||||
SetNamedPropertyByInteger(env, obj, SemanticActionButton::CALL_ACTION_BUTTON, "CALL_ACTION_BUTTON");
|
||||
|
||||
napi_property_descriptor exportFuncs[] = {
|
||||
DECLARE_NAPI_PROPERTY("SemanticActionButton", obj),
|
||||
};
|
||||
|
||||
napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
|
||||
return exports;
|
||||
}
|
||||
|
||||
napi_value InputsSourceInit(napi_env env, napi_value exports)
|
||||
{
|
||||
ANS_LOGI("%{public}s, called", __func__);
|
||||
|
||||
napi_value obj = nullptr;
|
||||
napi_create_object(env, &obj);
|
||||
|
||||
SetNamedPropertyByInteger(env, obj, InputsSource::FREE_FORM_INPUT, "FREE_FORM_INPUT");
|
||||
SetNamedPropertyByInteger(env, obj, InputsSource::OPTION, "OPTION");
|
||||
|
||||
napi_property_descriptor exportFuncs[] = {
|
||||
DECLARE_NAPI_PROPERTY("InputsSource", obj),
|
||||
};
|
||||
|
||||
napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
|
||||
return exports;
|
||||
}
|
||||
|
||||
napi_value DisturbModeInit(napi_env env, napi_value exports)
|
||||
{
|
||||
ANS_LOGI("%{public}s, called", __func__);
|
||||
|
||||
napi_value obj = nullptr;
|
||||
napi_create_object(env, &obj);
|
||||
|
||||
SetNamedPropertyByInteger(env, obj, DisturbMode::ALLOW_UNKNOWN, "ALLOW_UNKNOWN");
|
||||
SetNamedPropertyByInteger(env, obj, DisturbMode::ALLOW_ALL, "ALLOW_ALL");
|
||||
SetNamedPropertyByInteger(env, obj, DisturbMode::ALLOW_PRIORITY, "ALLOW_PRIORITY");
|
||||
SetNamedPropertyByInteger(env, obj, DisturbMode::ALLOW_NONE, "ALLOW_NONE");
|
||||
SetNamedPropertyByInteger(env, obj, DisturbMode::ALLOW_ALARMS, "ALLOW_ALARMS");
|
||||
|
||||
napi_property_descriptor exportFuncs[] = {
|
||||
DECLARE_NAPI_PROPERTY("DisturbMode", obj),
|
||||
};
|
||||
|
||||
napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
|
||||
return exports;
|
||||
}
|
||||
|
||||
napi_value InputEditTypeInit(napi_env env, napi_value exports)
|
||||
{
|
||||
ANS_LOGI("%{public}s, called", __func__);
|
||||
|
||||
napi_value obj = nullptr;
|
||||
napi_create_object(env, &obj);
|
||||
|
||||
SetNamedPropertyByInteger(env, obj, InputEditType::EDIT_AUTO, "EDIT_AUTO");
|
||||
SetNamedPropertyByInteger(env, obj, InputEditType::EDIT_DISABLED, "EDIT_DISABLED");
|
||||
SetNamedPropertyByInteger(env, obj, InputEditType::EDIT_ENABLED, "EDIT_ENABLED");
|
||||
|
||||
napi_property_descriptor exportFuncs[] = {
|
||||
DECLARE_NAPI_PROPERTY("InputEditType", obj),
|
||||
};
|
||||
|
||||
napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
|
||||
return exports;
|
||||
}
|
||||
|
||||
napi_value ContentTypeInit(napi_env env, napi_value exports)
|
||||
{
|
||||
ANS_LOGI("%{public}s, called", __func__);
|
||||
|
||||
napi_value obj = nullptr;
|
||||
napi_create_object(env, &obj);
|
||||
|
||||
SetNamedPropertyByInteger(
|
||||
env, obj, ContentType::NOTIFICATION_CONTENT_BASIC_TEXT, "NOTIFICATION_CONTENT_BASIC_TEXT");
|
||||
SetNamedPropertyByInteger(env, obj, ContentType::NOTIFICATION_CONTENT_LONG_TEXT, "NOTIFICATION_CONTENT_LONG_TEXT");
|
||||
SetNamedPropertyByInteger(env, obj, ContentType::NOTIFICATION_CONTENT_PICTURE, "NOTIFICATION_CONTENT_PICTURE");
|
||||
SetNamedPropertyByInteger(
|
||||
env, obj, ContentType::NOTIFICATION_CONTENT_CONVERSATION, "NOTIFICATION_CONTENT_CONVERSATION");
|
||||
SetNamedPropertyByInteger(env, obj, ContentType::NOTIFICATION_CONTENT_MULTILINE, "NOTIFICATION_CONTENT_MULTILINE");
|
||||
SetNamedPropertyByInteger(env, obj, ContentType::NOTIFICATION_CONTENT_MEDIA, "NOTIFICATION_CONTENT_MEDIA");
|
||||
|
||||
napi_property_descriptor exportFuncs[] = {
|
||||
DECLARE_NAPI_PROPERTY("ContentType", obj),
|
||||
};
|
||||
|
||||
napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
|
||||
return exports;
|
||||
}
|
||||
|
||||
napi_value ConstantInit(napi_env env, napi_value exports)
|
||||
{
|
||||
NotificationReasonInit(env, exports);
|
||||
SlotTypeInit(env, exports);
|
||||
SemanticActionButtonInit(env, exports);
|
||||
InputsSourceInit(env, exports);
|
||||
DisturbModeInit(env, exports);
|
||||
InputEditTypeInit(env, exports);
|
||||
ContentTypeInit(env, exports);
|
||||
return exports;
|
||||
}
|
||||
|
||||
} // namespace NotificationNapi
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,988 @@
|
||||
/*
|
||||
* 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 <uv.h>
|
||||
#include "create_subscriber.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace NotificationNapi {
|
||||
SubscriberInstance::SubscriberInstance()
|
||||
{}
|
||||
|
||||
SubscriberInstance::~SubscriberInstance()
|
||||
{}
|
||||
|
||||
void SubscriberInstance::OnCanceled(const std::shared_ptr<OHOS::Notification::Notification> &request)
|
||||
{
|
||||
ANS_LOGI("OnCanceled start");
|
||||
|
||||
if (canceCallbackInfo_.ref == nullptr) {
|
||||
ANS_LOGI("cancel callback unset");
|
||||
return;
|
||||
}
|
||||
|
||||
if (request == nullptr) {
|
||||
ANS_LOGE("request is null");
|
||||
return;
|
||||
}
|
||||
ANS_LOGI("OnCanceled NotificationId = %{public}d", request->GetNotificationRequest().GetNotificationId());
|
||||
|
||||
uv_loop_s *loop = nullptr;
|
||||
#if NAPI_VERSION >= 2
|
||||
napi_get_uv_event_loop(canceCallbackInfo_.env, &loop);
|
||||
#endif // NAPI_VERSION >= 2
|
||||
|
||||
NotificationReceiveDataWorker *dataWorker = new NotificationReceiveDataWorker();
|
||||
dataWorker->request = request;
|
||||
dataWorker->env = canceCallbackInfo_.env;
|
||||
dataWorker->ref = canceCallbackInfo_.ref;
|
||||
|
||||
uv_work_t *work = new uv_work_t;
|
||||
work->data = (void *)dataWorker;
|
||||
|
||||
uv_queue_work(loop,
|
||||
work,
|
||||
[](uv_work_t *work) {},
|
||||
[](uv_work_t *work, int status) {
|
||||
ANS_LOGI("OnCanceled uv_work_t start");
|
||||
NotificationReceiveDataWorker *dataWorkerData = (NotificationReceiveDataWorker *)work->data;
|
||||
if (dataWorkerData == nullptr) {
|
||||
ANS_LOGI("dataWorkerData is nullptr");
|
||||
return;
|
||||
}
|
||||
napi_value result;
|
||||
napi_create_object(dataWorkerData->env, &result);
|
||||
int error = 0;
|
||||
if (!SetSubscriberCallbackData(dataWorkerData->env, dataWorkerData->request, result)) {
|
||||
result = Common::NapiGetNull(dataWorkerData->env);
|
||||
error = ERROR;
|
||||
} else {
|
||||
error = NO_ERROR;
|
||||
}
|
||||
Common::SetCallback(dataWorkerData->env, dataWorkerData->ref, error, result);
|
||||
|
||||
delete dataWorkerData;
|
||||
dataWorkerData = nullptr;
|
||||
delete work;
|
||||
work = nullptr;
|
||||
});
|
||||
}
|
||||
|
||||
void SubscriberInstance::OnCanceled(const std::shared_ptr<OHOS::Notification::Notification> &request,
|
||||
const std::shared_ptr<NotificationSortingMap> &sortingMap, int deleteReason)
|
||||
{
|
||||
ANS_LOGI("OnCanceled2 start");
|
||||
|
||||
if (canceCallbackInfo_.ref == nullptr) {
|
||||
ANS_LOGI("cancel callback unset");
|
||||
return;
|
||||
}
|
||||
|
||||
if (request == nullptr) {
|
||||
ANS_LOGE("request is null");
|
||||
return;
|
||||
}
|
||||
|
||||
if (sortingMap == nullptr) {
|
||||
ANS_LOGE("sortingMap is null");
|
||||
return;
|
||||
}
|
||||
ANS_LOGI("OnCanceled2 NotificationId = %{public}d", request->GetNotificationRequest().GetNotificationId());
|
||||
ANS_LOGI("OnCanceled2 sortingMap size = %{public}d", sortingMap->GetKey().size());
|
||||
ANS_LOGI("OnCanceled2 deleteReason = %{public}d", deleteReason);
|
||||
|
||||
uv_loop_s *loop = nullptr;
|
||||
#if NAPI_VERSION >= 2
|
||||
napi_get_uv_event_loop(canceCallbackInfo_.env, &loop);
|
||||
#endif // NAPI_VERSION >= 2
|
||||
|
||||
NotificationReceiveDataWorker *dataWorker = new NotificationReceiveDataWorker();
|
||||
dataWorker->request = request;
|
||||
dataWorker->sortingMap = sortingMap;
|
||||
dataWorker->deleteReason = deleteReason;
|
||||
dataWorker->env = canceCallbackInfo_.env;
|
||||
dataWorker->ref = canceCallbackInfo_.ref;
|
||||
|
||||
uv_work_t *work = new uv_work_t;
|
||||
work->data = (void *)dataWorker;
|
||||
|
||||
uv_queue_work(loop,
|
||||
work,
|
||||
[](uv_work_t *work) {},
|
||||
[](uv_work_t *work, int status) {
|
||||
ANS_LOGI("OnCanceled2 uv_work_t start");
|
||||
NotificationReceiveDataWorker *dataWorkerData = (NotificationReceiveDataWorker *)work->data;
|
||||
if (dataWorkerData == nullptr) {
|
||||
ANS_LOGE("dataWorkerData is null");
|
||||
return;
|
||||
}
|
||||
napi_value result;
|
||||
napi_create_object(dataWorkerData->env, &result);
|
||||
int error = 0;
|
||||
if (!SetSubscriberCallbackData(dataWorkerData->env,
|
||||
dataWorkerData->request,
|
||||
dataWorkerData->sortingMap,
|
||||
dataWorkerData->deleteReason,
|
||||
result)) {
|
||||
result = Common::NapiGetNull(dataWorkerData->env);
|
||||
error = ERROR;
|
||||
} else {
|
||||
error = NO_ERROR;
|
||||
}
|
||||
Common::SetCallback(dataWorkerData->env, dataWorkerData->ref, error, result);
|
||||
|
||||
delete dataWorkerData;
|
||||
dataWorkerData = nullptr;
|
||||
delete work;
|
||||
work = nullptr;
|
||||
});
|
||||
}
|
||||
|
||||
void SubscriberInstance::OnConsumed(const std::shared_ptr<OHOS::Notification::Notification> &request)
|
||||
{
|
||||
ANS_LOGI("OnConsumed start");
|
||||
|
||||
if (consumeCallbackInfo_.ref == nullptr) {
|
||||
ANS_LOGI("consume callback unset");
|
||||
return;
|
||||
}
|
||||
|
||||
if (request == nullptr) {
|
||||
ANS_LOGE("request is null");
|
||||
return;
|
||||
}
|
||||
ANS_LOGI("OnConsumed NotificationId = %{public}d", request->GetNotificationRequest().GetNotificationId());
|
||||
|
||||
uv_loop_s *loop = nullptr;
|
||||
#if NAPI_VERSION >= 2
|
||||
napi_get_uv_event_loop(consumeCallbackInfo_.env, &loop);
|
||||
#endif // NAPI_VERSION >= 2
|
||||
|
||||
NotificationReceiveDataWorker *dataWorker = new NotificationReceiveDataWorker();
|
||||
dataWorker->request = request;
|
||||
dataWorker->env = consumeCallbackInfo_.env;
|
||||
dataWorker->ref = consumeCallbackInfo_.ref;
|
||||
|
||||
uv_work_t *work = new uv_work_t;
|
||||
work->data = (void *)dataWorker;
|
||||
|
||||
uv_queue_work(loop,
|
||||
work,
|
||||
[](uv_work_t *work) {},
|
||||
[](uv_work_t *work, int status) {
|
||||
ANS_LOGI("OnConsumed uv_work_t start");
|
||||
NotificationReceiveDataWorker *dataWorkerData = (NotificationReceiveDataWorker *)work->data;
|
||||
if (dataWorkerData == nullptr) {
|
||||
ANS_LOGE("dataWorkerData is null");
|
||||
return;
|
||||
}
|
||||
napi_value result;
|
||||
napi_create_object(dataWorkerData->env, &result);
|
||||
int error = 0;
|
||||
if (!SetSubscriberCallbackData(dataWorkerData->env, dataWorkerData->request, result)) {
|
||||
result = Common::NapiGetNull(dataWorkerData->env);
|
||||
error = ERROR;
|
||||
} else {
|
||||
error = NO_ERROR;
|
||||
}
|
||||
Common::SetCallback(dataWorkerData->env, dataWorkerData->ref, error, result);
|
||||
|
||||
delete dataWorkerData;
|
||||
dataWorkerData = nullptr;
|
||||
delete work;
|
||||
work = nullptr;
|
||||
});
|
||||
}
|
||||
|
||||
void SubscriberInstance::OnConsumed(const std::shared_ptr<OHOS::Notification::Notification> &request,
|
||||
const std::shared_ptr<NotificationSortingMap> &sortingMap)
|
||||
{
|
||||
ANS_LOGI("OnConsumed2 start");
|
||||
|
||||
if (consumeCallbackInfo_.ref == nullptr) {
|
||||
ANS_LOGI("consume callback unset");
|
||||
return;
|
||||
}
|
||||
|
||||
if (request == nullptr) {
|
||||
ANS_LOGE("request is null");
|
||||
return;
|
||||
}
|
||||
|
||||
if (sortingMap == nullptr) {
|
||||
ANS_LOGE("sortingMap is null");
|
||||
return;
|
||||
}
|
||||
ANS_LOGI("OnConsumed2 NotificationId = %{public}d", request->GetNotificationRequest().GetNotificationId());
|
||||
ANS_LOGI("OnConsumed2 sortingMap size = %{public}d", sortingMap->GetKey().size());
|
||||
|
||||
uv_loop_s *loop = nullptr;
|
||||
#if NAPI_VERSION >= 2
|
||||
napi_get_uv_event_loop(consumeCallbackInfo_.env, &loop);
|
||||
#endif // NAPI_VERSION >= 2
|
||||
|
||||
NotificationReceiveDataWorker *dataWorker = new NotificationReceiveDataWorker();
|
||||
dataWorker->request = request;
|
||||
dataWorker->sortingMap = sortingMap;
|
||||
dataWorker->env = consumeCallbackInfo_.env;
|
||||
dataWorker->ref = consumeCallbackInfo_.ref;
|
||||
|
||||
uv_work_t *work = new uv_work_t;
|
||||
work->data = (void *)dataWorker;
|
||||
|
||||
uv_queue_work(loop,
|
||||
work,
|
||||
[](uv_work_t *work) {},
|
||||
[](uv_work_t *work, int status) {
|
||||
ANS_LOGI("OnConsumed2 uv_work_t start");
|
||||
NotificationReceiveDataWorker *dataWorkerData = (NotificationReceiveDataWorker *)work->data;
|
||||
if (dataWorkerData == nullptr) {
|
||||
ANS_LOGE("dataWorkerData is null");
|
||||
return;
|
||||
}
|
||||
napi_value result;
|
||||
napi_create_object(dataWorkerData->env, &result);
|
||||
int error = 0;
|
||||
if (!SetSubscriberCallbackData(dataWorkerData->env,
|
||||
dataWorkerData->request,
|
||||
dataWorkerData->sortingMap,
|
||||
dataWorkerData->deleteReason,
|
||||
result)) {
|
||||
result = Common::NapiGetNull(dataWorkerData->env);
|
||||
error = ERROR;
|
||||
} else {
|
||||
error = NO_ERROR;
|
||||
}
|
||||
Common::SetCallback(dataWorkerData->env, dataWorkerData->ref, error, result);
|
||||
|
||||
delete dataWorkerData;
|
||||
dataWorkerData = nullptr;
|
||||
delete work;
|
||||
work = nullptr;
|
||||
});
|
||||
}
|
||||
|
||||
void SubscriberInstance::OnUpdate(const std::shared_ptr<NotificationSortingMap> &sortingMap)
|
||||
{
|
||||
ANS_LOGI("OnUpdate start");
|
||||
|
||||
if (updateCallbackInfo_.ref == nullptr) {
|
||||
ANS_LOGI("update callback unset");
|
||||
return;
|
||||
}
|
||||
|
||||
if (sortingMap == nullptr) {
|
||||
ANS_LOGE("sortingMap is null");
|
||||
return;
|
||||
}
|
||||
ANS_LOGI("OnUpdate sortingMap size = %{public}d", sortingMap->GetKey().size());
|
||||
|
||||
uv_loop_s *loop = nullptr;
|
||||
#if NAPI_VERSION >= 2
|
||||
napi_get_uv_event_loop(updateCallbackInfo_.env, &loop);
|
||||
#endif // NAPI_VERSION >= 2
|
||||
|
||||
NotificationReceiveDataWorker *dataWorker = new NotificationReceiveDataWorker();
|
||||
dataWorker->sortingMap = sortingMap;
|
||||
dataWorker->env = updateCallbackInfo_.env;
|
||||
dataWorker->ref = updateCallbackInfo_.ref;
|
||||
|
||||
uv_work_t *work = new uv_work_t;
|
||||
work->data = (void *)dataWorker;
|
||||
|
||||
uv_queue_work(loop,
|
||||
work,
|
||||
[](uv_work_t *work) {},
|
||||
[](uv_work_t *work, int status) {
|
||||
ANS_LOGI("OnUpdate uv_work_t start");
|
||||
NotificationReceiveDataWorker *dataWorkerData = (NotificationReceiveDataWorker *)work->data;
|
||||
if (dataWorkerData == nullptr) {
|
||||
ANS_LOGE("dataWorkerData is null");
|
||||
return;
|
||||
}
|
||||
napi_value result;
|
||||
napi_create_object(dataWorkerData->env, &result);
|
||||
int error = 0;
|
||||
if (!Common::SetNotificationSortingMap(dataWorkerData->env, dataWorkerData->sortingMap, result)) {
|
||||
result = Common::NapiGetNull(dataWorkerData->env);
|
||||
error = ERROR;
|
||||
} else {
|
||||
error = NO_ERROR;
|
||||
}
|
||||
Common::SetCallback(dataWorkerData->env, dataWorkerData->ref, error, result);
|
||||
|
||||
delete dataWorkerData;
|
||||
dataWorkerData = nullptr;
|
||||
delete work;
|
||||
work = nullptr;
|
||||
});
|
||||
}
|
||||
|
||||
void SubscriberInstance::OnSubscribeResult(NotificationConstant::SubscribeResult result)
|
||||
{
|
||||
ANS_LOGI("OnSubscribeResult start");
|
||||
|
||||
if (subscribeCallbackInfo_.ref == nullptr) {
|
||||
ANS_LOGI("subscribe callback unset");
|
||||
return;
|
||||
}
|
||||
ANS_LOGI("OnSubscribeResult result = %{public}d", result);
|
||||
|
||||
uv_loop_s *loop = nullptr;
|
||||
#if NAPI_VERSION >= 2
|
||||
napi_get_uv_event_loop(subscribeCallbackInfo_.env, &loop);
|
||||
#endif // NAPI_VERSION >= 2
|
||||
|
||||
NotificationReceiveDataWorker *dataWorker = new NotificationReceiveDataWorker();
|
||||
dataWorker->result = (int)result;
|
||||
dataWorker->env = subscribeCallbackInfo_.env;
|
||||
dataWorker->ref = subscribeCallbackInfo_.ref;
|
||||
|
||||
uv_work_t *work = new uv_work_t;
|
||||
work->data = (void *)dataWorker;
|
||||
|
||||
uv_queue_work(loop,
|
||||
work,
|
||||
[](uv_work_t *work) {},
|
||||
[](uv_work_t *work, int status) {
|
||||
ANS_LOGI("OnSubscribeResult uv_work_t start");
|
||||
NotificationReceiveDataWorker *dataWorkerData = (NotificationReceiveDataWorker *)work->data;
|
||||
if (dataWorkerData == nullptr) {
|
||||
ANS_LOGE("dataWorkerData is null");
|
||||
return;
|
||||
}
|
||||
// result: number
|
||||
napi_value result;
|
||||
napi_create_int32(dataWorkerData->env, dataWorkerData->result, &result);
|
||||
|
||||
Common::SetCallback(dataWorkerData->env, dataWorkerData->ref, NO_ERROR, result);
|
||||
|
||||
delete dataWorkerData;
|
||||
dataWorkerData = nullptr;
|
||||
delete work;
|
||||
work = nullptr;
|
||||
});
|
||||
}
|
||||
|
||||
void SubscriberInstance::OnUnsubscribeResult(NotificationConstant::SubscribeResult result)
|
||||
{
|
||||
ANS_LOGI("OnUnsubscribeResult start");
|
||||
|
||||
if (unsubscribeCallbackInfo_.ref == nullptr) {
|
||||
ANS_LOGI("unsubscribe callback unset");
|
||||
return;
|
||||
}
|
||||
ANS_LOGI("OnUnsubscribeResult result = %{public}d", result);
|
||||
|
||||
uv_loop_s *loop = nullptr;
|
||||
#if NAPI_VERSION >= 2
|
||||
napi_get_uv_event_loop(unsubscribeCallbackInfo_.env, &loop);
|
||||
#endif // NAPI_VERSION >= 2
|
||||
|
||||
NotificationReceiveDataWorker *dataWorker = new NotificationReceiveDataWorker();
|
||||
dataWorker->result = (int)result;
|
||||
dataWorker->env = unsubscribeCallbackInfo_.env;
|
||||
dataWorker->ref = unsubscribeCallbackInfo_.ref;
|
||||
|
||||
uv_work_t *work = new uv_work_t;
|
||||
work->data = (void *)dataWorker;
|
||||
|
||||
uv_queue_work(loop,
|
||||
work,
|
||||
[](uv_work_t *work) {},
|
||||
[](uv_work_t *work, int status) {
|
||||
ANS_LOGI("OnUnsubscribeResult uv_work_t start");
|
||||
NotificationReceiveDataWorker *dataWorkerData = (NotificationReceiveDataWorker *)work->data;
|
||||
if (dataWorkerData == nullptr) {
|
||||
ANS_LOGE("dataWorkerData is null");
|
||||
return;
|
||||
}
|
||||
// result: number
|
||||
napi_value result;
|
||||
napi_create_int32(dataWorkerData->env, dataWorkerData->result, &result);
|
||||
|
||||
Common::SetCallback(dataWorkerData->env, dataWorkerData->ref, NO_ERROR, result);
|
||||
|
||||
delete dataWorkerData;
|
||||
dataWorkerData = nullptr;
|
||||
delete work;
|
||||
work = nullptr;
|
||||
});
|
||||
}
|
||||
|
||||
void SubscriberInstance::OnDied()
|
||||
{
|
||||
ANS_LOGI("OnDied start");
|
||||
|
||||
if (dieCallbackInfo_.ref == nullptr) {
|
||||
ANS_LOGE("die callback unset");
|
||||
return;
|
||||
}
|
||||
|
||||
uv_loop_s *loop = nullptr;
|
||||
#if NAPI_VERSION >= 2
|
||||
napi_get_uv_event_loop(dieCallbackInfo_.env, &loop);
|
||||
#endif // NAPI_VERSION >= 2
|
||||
|
||||
NotificationReceiveDataWorker *dataWorker = new NotificationReceiveDataWorker();
|
||||
dataWorker->env = dieCallbackInfo_.env;
|
||||
dataWorker->ref = dieCallbackInfo_.ref;
|
||||
|
||||
uv_work_t *work = new uv_work_t;
|
||||
work->data = (void *)dataWorker;
|
||||
|
||||
uv_queue_work(loop,
|
||||
work,
|
||||
[](uv_work_t *work) {},
|
||||
[](uv_work_t *work, int status) {
|
||||
ANS_LOGI("OnDied uv_work_t start");
|
||||
NotificationReceiveDataWorker *dataWorkerData = (NotificationReceiveDataWorker *)work->data;
|
||||
if (dataWorkerData == nullptr) {
|
||||
ANS_LOGE("dataWorkerData is null");
|
||||
return;
|
||||
}
|
||||
|
||||
Common::SetCallback(
|
||||
dataWorkerData->env, dataWorkerData->ref, NO_ERROR, Common::NapiGetNull(dataWorkerData->env));
|
||||
|
||||
delete dataWorkerData;
|
||||
dataWorkerData = nullptr;
|
||||
delete work;
|
||||
work = nullptr;
|
||||
});
|
||||
}
|
||||
|
||||
void SubscriberInstance::OnDisturbModeChanged(int disturbMode)
|
||||
{
|
||||
ANS_LOGI("OnDisturbModeChanged start");
|
||||
|
||||
if (disturbModeCallbackInfo_.ref == nullptr) {
|
||||
ANS_LOGI("disturbModeChange callback unset");
|
||||
return;
|
||||
}
|
||||
ANS_LOGI("OnDisturbModeChanged disturbMode = %{public}d", disturbMode);
|
||||
|
||||
uv_loop_s *loop = nullptr;
|
||||
#if NAPI_VERSION >= 2
|
||||
napi_get_uv_event_loop(disturbModeCallbackInfo_.env, &loop);
|
||||
#endif // NAPI_VERSION >= 2
|
||||
|
||||
NotificationReceiveDataWorker *dataWorker = new NotificationReceiveDataWorker();
|
||||
dataWorker->disturbMode = disturbMode;
|
||||
dataWorker->env = disturbModeCallbackInfo_.env;
|
||||
dataWorker->ref = disturbModeCallbackInfo_.ref;
|
||||
|
||||
uv_work_t *work = new uv_work_t;
|
||||
work->data = (void *)dataWorker;
|
||||
|
||||
uv_queue_work(loop,
|
||||
work,
|
||||
[](uv_work_t *work) {},
|
||||
[](uv_work_t *work, int status) {
|
||||
ANS_LOGI("OnDisturbModeChanged uv_work_t start");
|
||||
NotificationReceiveDataWorker *dataWorkerData = (NotificationReceiveDataWorker *)work->data;
|
||||
if (dataWorkerData == nullptr) {
|
||||
ANS_LOGE("dataWorkerData is null");
|
||||
return;
|
||||
}
|
||||
// disturbMode: number
|
||||
napi_value result;
|
||||
napi_create_int32(dataWorkerData->env, dataWorkerData->disturbMode, &result);
|
||||
|
||||
Common::SetCallback(dataWorkerData->env, dataWorkerData->ref, NO_ERROR, result);
|
||||
|
||||
delete dataWorkerData;
|
||||
dataWorkerData = nullptr;
|
||||
delete work;
|
||||
work = nullptr;
|
||||
});
|
||||
}
|
||||
|
||||
void SubscriberInstance::SetCancelCallbackInfo(const napi_env &env, const napi_ref &ref)
|
||||
{
|
||||
canceCallbackInfo_.env = env;
|
||||
canceCallbackInfo_.ref = ref;
|
||||
}
|
||||
|
||||
void SubscriberInstance::SetConsumeCallbackInfo(const napi_env &env, const napi_ref &ref)
|
||||
{
|
||||
consumeCallbackInfo_.env = env;
|
||||
consumeCallbackInfo_.ref = ref;
|
||||
}
|
||||
|
||||
void SubscriberInstance::SetUpdateCallbackInfo(const napi_env &env, const napi_ref &ref)
|
||||
{
|
||||
updateCallbackInfo_.env = env;
|
||||
updateCallbackInfo_.ref = ref;
|
||||
}
|
||||
|
||||
void SubscriberInstance::SetSubscribeCallbackInfo(const napi_env &env, const napi_ref &ref)
|
||||
{
|
||||
subscribeCallbackInfo_.env = env;
|
||||
subscribeCallbackInfo_.ref = ref;
|
||||
}
|
||||
|
||||
void SubscriberInstance::SetUnsubscribeCallbackInfo(const napi_env &env, const napi_ref &ref)
|
||||
{
|
||||
unsubscribeCallbackInfo_.env = env;
|
||||
unsubscribeCallbackInfo_.ref = ref;
|
||||
}
|
||||
|
||||
void SubscriberInstance::SetDieCallbackInfo(const napi_env &env, const napi_ref &ref)
|
||||
{
|
||||
dieCallbackInfo_.env = env;
|
||||
dieCallbackInfo_.ref = ref;
|
||||
}
|
||||
|
||||
void SubscriberInstance::SetDisturbModeCallbackInfo(const napi_env &env, const napi_ref &ref)
|
||||
{
|
||||
disturbModeCallbackInfo_.env = env;
|
||||
disturbModeCallbackInfo_.ref = ref;
|
||||
}
|
||||
|
||||
void SubscriberInstance::SetCallbackInfo(const napi_env &env, const std::string &type, const napi_ref &ref)
|
||||
{
|
||||
if (type == CONSUME) {
|
||||
SetConsumeCallbackInfo(env, ref);
|
||||
} else if (type == CANCEL) {
|
||||
SetCancelCallbackInfo(env, ref);
|
||||
} else if (type == UPDATE) {
|
||||
SetUpdateCallbackInfo(env, ref);
|
||||
} else if (type == SUBSCRIBE) {
|
||||
SetSubscribeCallbackInfo(env, ref);
|
||||
} else if (type == UNSUBSCRIBE) {
|
||||
SetUnsubscribeCallbackInfo(env, ref);
|
||||
} else if (type == DIE) {
|
||||
SetDieCallbackInfo(env, ref);
|
||||
} else if (type == DISTURB_MODE_CHANGE) {
|
||||
SetDisturbModeCallbackInfo(env, ref);
|
||||
} else {
|
||||
ANS_LOGI("type is error");
|
||||
}
|
||||
}
|
||||
|
||||
napi_value ParseParametersByOn(const napi_env &env, const size_t &argc, const napi_value (&argv)[ON_MAX_PARA],
|
||||
std::string &type, napi_ref &callback)
|
||||
{
|
||||
ANS_LOGI("napi_value ParseParametersByOn start");
|
||||
napi_valuetype valuetype;
|
||||
size_t strLen = 0;
|
||||
char str[STR_MAX_SIZE] = {0};
|
||||
|
||||
if (argc >= ON_MAX_PARA) {
|
||||
// argv[0]:type
|
||||
NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype));
|
||||
NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected.");
|
||||
NAPI_CALL(env, napi_get_value_string_utf8(env, argv[0], str, STR_MAX_SIZE - 1, &strLen));
|
||||
type = str;
|
||||
if (!(type == CONSUME || type == CANCEL || type == UPDATE || type == SUBSCRIBE || type == UNSUBSCRIBE ||
|
||||
type == DIE || type == DISTURB_MODE_CHANGE)) {
|
||||
ANS_LOGI("type parameter is error");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// argv[1]:callback
|
||||
NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype));
|
||||
NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected.");
|
||||
napi_create_reference(env, argv[1], 1, &callback);
|
||||
}
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
|
||||
napi_value On(napi_env env, napi_callback_info info)
|
||||
{
|
||||
ANS_LOGI("On start");
|
||||
|
||||
size_t argc = ON_MAX_PARA;
|
||||
napi_value argv[ON_MAX_PARA];
|
||||
napi_value thisVar = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL));
|
||||
NAPI_ASSERT(env, argc >= ON_MAX_PARA, "Wrong number of arguments");
|
||||
|
||||
std::string type;
|
||||
napi_ref callback = 0;
|
||||
if (ParseParametersByOn(env, argc, argv, type, callback) == nullptr) {
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
|
||||
SubscriberInstance *objectInfo = nullptr;
|
||||
napi_unwrap(env, thisVar, (void **)&objectInfo);
|
||||
ANS_LOGI("On objectInfo = %{public}p", objectInfo);
|
||||
|
||||
AsyncCallbackInfoOn *asynccallbackinfo = new AsyncCallbackInfoOn{
|
||||
.env = env, .asyncWork = nullptr, .objectInfo = objectInfo, .type = type, .callback = callback};
|
||||
|
||||
if (!AddAsyncCallbackInfoOn(objectInfo, asynccallbackinfo)) {
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
|
||||
napi_value resourceName;
|
||||
napi_create_string_latin1(env, "on", NAPI_AUTO_LENGTH, &resourceName);
|
||||
// Asynchronous function call
|
||||
napi_create_async_work(env,
|
||||
nullptr,
|
||||
resourceName,
|
||||
[](napi_env env, void *data) {
|
||||
ANS_LOGI("On napi_create_async_work start");
|
||||
AsyncCallbackInfoOn *asynccallbackinfo = (AsyncCallbackInfoOn *)data;
|
||||
ANS_LOGI("On asynccallbackinfo->type = %{public}s", asynccallbackinfo->type.c_str());
|
||||
asynccallbackinfo->objectInfo->SetCallbackInfo(env, asynccallbackinfo->type, asynccallbackinfo->callback);
|
||||
},
|
||||
[](napi_env env, napi_status status, void *data) {
|
||||
ANS_LOGI("On napi_create_async_work end");
|
||||
AsyncCallbackInfoOn *asynccallbackinfo = (AsyncCallbackInfoOn *)data;
|
||||
napi_delete_async_work(env, asynccallbackinfo->asyncWork);
|
||||
},
|
||||
(void *)asynccallbackinfo,
|
||||
&asynccallbackinfo->asyncWork);
|
||||
|
||||
NAPI_CALL(env, napi_queue_async_work(env, asynccallbackinfo->asyncWork));
|
||||
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
|
||||
napi_value ParseParametersByOff(
|
||||
const napi_env &env, const size_t &argc, const napi_value (&argv)[OFF_MAX_PARA], std::string &type)
|
||||
{
|
||||
ANS_LOGI("napi_value ParseParametersByOff start");
|
||||
napi_valuetype valuetype;
|
||||
size_t strLen = 0;
|
||||
char str[STR_MAX_SIZE] = {0};
|
||||
|
||||
if (argc >= OFF_MAX_PARA) {
|
||||
// argv[0]:type
|
||||
NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype));
|
||||
NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected.");
|
||||
NAPI_CALL(env, napi_get_value_string_utf8(env, argv[0], str, STR_MAX_SIZE - 1, &strLen));
|
||||
type = str;
|
||||
if (!(type == CONSUME || type == CANCEL || type == UPDATE || type == SUBSCRIBE || type == UNSUBSCRIBE ||
|
||||
type == DIE || type == DISTURB_MODE_CHANGE)) {
|
||||
ANS_LOGI("type parameter is error");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
|
||||
napi_value Off(napi_env env, napi_callback_info info)
|
||||
{
|
||||
ANS_LOGI("Off start");
|
||||
|
||||
size_t argc = OFF_MAX_PARA;
|
||||
napi_value argv[OFF_MAX_PARA];
|
||||
napi_value thisVar = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL));
|
||||
NAPI_ASSERT(env, argc >= OFF_MAX_PARA, "Wrong number of arguments");
|
||||
|
||||
std::string type;
|
||||
if (ParseParametersByOff(env, argc, argv, type) == nullptr) {
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
|
||||
SubscriberInstance *objectInfo = nullptr;
|
||||
napi_unwrap(env, thisVar, (void **)&objectInfo);
|
||||
ANS_LOGI("Off objectInfo = %{public}p", objectInfo);
|
||||
|
||||
AsyncCallbackInfoOff *asynccallbackinfo = new AsyncCallbackInfoOff{
|
||||
.env = env, .asyncWork = nullptr, .objectInfo = objectInfo, .type = type, .callback = nullptr};
|
||||
|
||||
napi_value resourceName;
|
||||
napi_create_string_latin1(env, "off", NAPI_AUTO_LENGTH, &resourceName);
|
||||
// Asynchronous function call
|
||||
napi_create_async_work(env,
|
||||
nullptr,
|
||||
resourceName,
|
||||
[](napi_env env, void *data) {
|
||||
ANS_LOGI("Off napi_create_async_work start");
|
||||
AsyncCallbackInfoOff *asynccallbackinfo = (AsyncCallbackInfoOff *)data;
|
||||
ANS_LOGI("Off asynccallbackinfo->type = %{public}s", asynccallbackinfo->type.c_str());
|
||||
asynccallbackinfo->objectInfo->SetCallbackInfo(env, asynccallbackinfo->type, asynccallbackinfo->callback);
|
||||
},
|
||||
[](napi_env env, napi_status status, void *data) {
|
||||
ANS_LOGI("Off napi_create_async_work end");
|
||||
AsyncCallbackInfoOff *asynccallbackinfo = (AsyncCallbackInfoOff *)data;
|
||||
napi_delete_async_work(env, asynccallbackinfo->asyncWork);
|
||||
|
||||
DelAsyncCallbackInfoOn(asynccallbackinfo->objectInfo, asynccallbackinfo->type);
|
||||
|
||||
if (asynccallbackinfo) {
|
||||
delete asynccallbackinfo;
|
||||
asynccallbackinfo = nullptr;
|
||||
}
|
||||
},
|
||||
(void *)asynccallbackinfo,
|
||||
&asynccallbackinfo->asyncWork);
|
||||
|
||||
NAPI_CALL(env, napi_queue_async_work(env, asynccallbackinfo->asyncWork));
|
||||
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
|
||||
napi_value CreateSubscriber(napi_env env, napi_callback_info info)
|
||||
{
|
||||
ANS_LOGI("CreateSubscriber start");
|
||||
|
||||
size_t argc = 0;
|
||||
napi_value argv[1];
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL));
|
||||
NAPI_ASSERT(env, argc == 0, "Wrong number of arguments");
|
||||
|
||||
napi_value result = 0;
|
||||
napi_new_instance(env, g_NotificationSubscriber, 0, nullptr, &result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value SubscriberConstructor(napi_env env, napi_callback_info info)
|
||||
{
|
||||
ANS_LOGI("SubscriberConstructor start");
|
||||
|
||||
size_t argc = 0;
|
||||
napi_value argv[1];
|
||||
napi_value thisVar = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr));
|
||||
|
||||
SubscriberInstance *objectInfo = nullptr;
|
||||
if (!CreateSubscriberInstanceRecord(&objectInfo)) {
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
ANS_LOGI("SubscriberConstructor objectInfo = %{public}p", objectInfo);
|
||||
|
||||
napi_wrap(env,
|
||||
thisVar,
|
||||
objectInfo,
|
||||
[](napi_env env, void *data, void *hint) {
|
||||
SubscriberInstance *objectInfo = (SubscriberInstance *)data;
|
||||
ANS_LOGI("SubscriberConstructor this = %{public}p, destruct", objectInfo);
|
||||
|
||||
DelAsyncCallbackInfoOn(objectInfo);
|
||||
|
||||
if (objectInfo) {
|
||||
delete objectInfo;
|
||||
objectInfo = nullptr;
|
||||
}
|
||||
},
|
||||
nullptr,
|
||||
nullptr);
|
||||
|
||||
ANS_LOGI("SubscriberConstructor end");
|
||||
return thisVar;
|
||||
}
|
||||
|
||||
bool CreateSubscriberInstanceRecord(SubscriberInstance **subscriber)
|
||||
{
|
||||
ANS_LOGI("CreateSubscriberInstanceRecord start");
|
||||
|
||||
*subscriber = new SubscriberInstance();
|
||||
|
||||
if (*subscriber == nullptr) {
|
||||
ANS_LOGE("subscriber is null");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<AsyncCallbackInfoOn *> info;
|
||||
g_SubscriberInstances[*subscriber] = info;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AddAsyncCallbackInfoOn(SubscriberInstance *subscriber, AsyncCallbackInfoOn *asynccallbackinfo)
|
||||
{
|
||||
ANS_LOGI("AddAsyncCallbackInfoOn start");
|
||||
|
||||
if (subscriber == nullptr) {
|
||||
ANS_LOGE("subscriber is null");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (asynccallbackinfo == nullptr) {
|
||||
ANS_LOGE("asynccallbackinfo is null");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
auto infoItem = g_SubscriberInstances.find(subscriber);
|
||||
if (infoItem != g_SubscriberInstances.end()) {
|
||||
ANS_LOGI("AddAsyncCallbackInfoOn AsyncCallbackInfoOn size = %{public}d", infoItem->second.size());
|
||||
for (auto asyncCallbackInfoOn : infoItem->second) {
|
||||
ANS_LOGI("AddAsyncCallbackInfoOn AsyncCallbackInfoOn ptr = %{public}p", asyncCallbackInfoOn);
|
||||
ANS_LOGI("AsyncCallbackInfoOn->type = %{public}s", asyncCallbackInfoOn->type.c_str());
|
||||
if (asyncCallbackInfoOn->type == asynccallbackinfo->type) {
|
||||
asyncCallbackInfoOn = asynccallbackinfo;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
g_SubscriberInstances[subscriber].emplace_back(asynccallbackinfo);
|
||||
} else {
|
||||
ANS_LOGE("the current subscriber does not exist");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DelAsyncCallbackInfoOn(SubscriberInstance *subscriber, const std::string &type)
|
||||
{
|
||||
ANS_LOGI("DelSubscriberInstance start");
|
||||
|
||||
if (subscriber == nullptr) {
|
||||
ANS_LOGE("subscriber is null");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
auto infoItem = g_SubscriberInstances.find(subscriber);
|
||||
if (infoItem != g_SubscriberInstances.end()) {
|
||||
ANS_LOGI("DelSubscriberInstance AsyncCallbackInfoOn size = %{public}d", infoItem->second.size());
|
||||
if (type.empty()) {
|
||||
for (auto asyncCallbackInfoOn : infoItem->second) {
|
||||
ANS_LOGI("DelSubscriberInstance AsyncCallbackInfoOn ptr = %{public}p", asyncCallbackInfoOn);
|
||||
delete asyncCallbackInfoOn;
|
||||
asyncCallbackInfoOn = nullptr;
|
||||
}
|
||||
g_SubscriberInstances.erase(subscriber);
|
||||
} else {
|
||||
for (auto it = infoItem->second.begin(); it != infoItem->second.end(); ++it) {
|
||||
ANS_LOGI("DelSubscriberInstance AsyncCallbackInfoOn ptr = %{public}p", *it);
|
||||
ANS_LOGI("DelSubscriberInstance type = %{public}s", (*it)->type.c_str());
|
||||
if ((*it)->type == type) {
|
||||
delete *it;
|
||||
*it = nullptr;
|
||||
infoItem->second.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (infoItem->second.size() == 0) {
|
||||
g_SubscriberInstances.erase(subscriber);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
ANS_LOGI("DelSubscriberInstance end");
|
||||
}
|
||||
|
||||
bool HasNotificationSubscriber(SubscriberInstance *subscriber)
|
||||
{
|
||||
ANS_LOGI("HasNotificationSubscriber start");
|
||||
|
||||
if (subscriber == nullptr) {
|
||||
ANS_LOGE("subscriber is null");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
auto infoItem = g_SubscriberInstances.find(subscriber);
|
||||
if (infoItem != g_SubscriberInstances.end()) {
|
||||
return true;
|
||||
} else {
|
||||
ANS_LOGE("HasNotificationSubscriber The curren subscriber does not exist");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
napi_value SetSubscriberCallbackData(
|
||||
const napi_env &env, const std::shared_ptr<OHOS::Notification::Notification> &request, napi_value &result)
|
||||
{
|
||||
ANS_LOGI("SetSubscriberCallbackData start");
|
||||
if (request == nullptr) {
|
||||
ANS_LOGE("request is null");
|
||||
return Common::NapiGetboolean(env, false);
|
||||
}
|
||||
|
||||
// request: NotificationRequest
|
||||
napi_value requestResult;
|
||||
napi_create_object(env, &requestResult);
|
||||
if (!Common::SetNotificationRequest(env, request, requestResult)) {
|
||||
ANS_LOGE("SetNotificationRequest call failed");
|
||||
return Common::NapiGetboolean(env, false);
|
||||
}
|
||||
napi_set_named_property(env, result, "request", requestResult);
|
||||
return Common::NapiGetboolean(env, true);
|
||||
}
|
||||
|
||||
napi_value SetSubscriberCallbackData(const napi_env &env,
|
||||
const std::shared_ptr<OHOS::Notification::Notification> &request,
|
||||
const std::shared_ptr<NotificationSortingMap> &sortingMap, int deleteReason, napi_value &result)
|
||||
{
|
||||
ANS_LOGI("SetSubscriberCallbackData2 start");
|
||||
if (request == nullptr) {
|
||||
ANS_LOGE("request is null");
|
||||
return Common::NapiGetboolean(env, false);
|
||||
}
|
||||
|
||||
if (sortingMap == nullptr) {
|
||||
ANS_LOGE("sortingMap is null");
|
||||
return Common::NapiGetboolean(env, false);
|
||||
}
|
||||
|
||||
// request: NotificationRequest
|
||||
napi_value requestResult;
|
||||
napi_create_object(env, &requestResult);
|
||||
if (!Common::SetNotificationRequest(env, request, requestResult)) {
|
||||
ANS_LOGE("SetNotificationRequest call failed");
|
||||
return Common::NapiGetboolean(env, false);
|
||||
}
|
||||
napi_set_named_property(env, result, "request", requestResult);
|
||||
|
||||
// sortingMap?: NotificationSortingMap
|
||||
napi_value sortingMapResult;
|
||||
napi_create_object(env, &sortingMapResult);
|
||||
if (!Common::SetNotificationSortingMap(env, sortingMap, sortingMapResult)) {
|
||||
ANS_LOGE("SetNotificationSortingMap call failed");
|
||||
return Common::NapiGetboolean(env, false);
|
||||
}
|
||||
napi_set_named_property(env, result, "sortingMap", sortingMapResult);
|
||||
|
||||
// reason?: number
|
||||
napi_value value = 0;
|
||||
int outReason = 0;
|
||||
if (!Common::ReasonCToJS(deleteReason, outReason)) {
|
||||
return Common::NapiGetboolean(env, false);
|
||||
}
|
||||
napi_create_int32(env, outReason, &value);
|
||||
napi_set_named_property(env, result, "reason", value);
|
||||
|
||||
return Common::NapiGetboolean(env, true);
|
||||
}
|
||||
|
||||
napi_value NotificationSubscriberInit(napi_env env, napi_value exports)
|
||||
{
|
||||
ANS_LOGI("NotificationSubscriberInit start");
|
||||
|
||||
napi_property_descriptor properties[] = {
|
||||
DECLARE_NAPI_FUNCTION("on", On),
|
||||
DECLARE_NAPI_FUNCTION("off", Off),
|
||||
};
|
||||
|
||||
NAPI_CALL(env,
|
||||
napi_define_class(env,
|
||||
"notificationSubscriber",
|
||||
NAPI_AUTO_LENGTH,
|
||||
SubscriberConstructor,
|
||||
nullptr,
|
||||
sizeof(properties) / sizeof(*properties),
|
||||
properties,
|
||||
&g_NotificationSubscriber));
|
||||
|
||||
return exports;
|
||||
}
|
||||
} // namespace NotificationNapi
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,332 @@
|
||||
/*
|
||||
* 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 "get_active.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace NotificationNapi {
|
||||
napi_value ParseParametersByAllActive(const napi_env &env, const napi_value (&argv)[ALL_ACTIVE_MAX_PARA],
|
||||
const size_t &argc, std::vector<std::string> &strValue, napi_ref &callback)
|
||||
{
|
||||
ANS_LOGI("ParseParametersByAllActive start");
|
||||
|
||||
if (argc >= 1) {
|
||||
napi_valuetype valuetype;
|
||||
// argv[0]: hashcode: Array<string> / callback
|
||||
bool isArray = false;
|
||||
napi_is_array(env, argv[0], &isArray);
|
||||
if (isArray) {
|
||||
uint32_t length = 0;
|
||||
napi_get_array_length(env, argv[0], &length);
|
||||
if (length > 0) {
|
||||
for (uint32_t i = 0; i < length; ++i) {
|
||||
napi_value nHashcode;
|
||||
char str[STR_MAX_SIZE] = {0};
|
||||
size_t strLen = 0;
|
||||
napi_get_element(env, argv[0], i, &nHashcode);
|
||||
NAPI_CALL(env, napi_typeof(env, nHashcode, &valuetype));
|
||||
NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected.");
|
||||
NAPI_CALL(env, napi_get_value_string_utf8(env, nHashcode, str, STR_MAX_SIZE - 1, &strLen));
|
||||
strValue.emplace_back(str);
|
||||
}
|
||||
} else {
|
||||
ANS_LOGI("hashcode: Array lenth is 0");
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype));
|
||||
NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected.");
|
||||
napi_create_reference(env, argv[0], 1, &callback);
|
||||
}
|
||||
if (argc >= ALL_ACTIVE_MAX_PARA) {
|
||||
// argv[1]:callback
|
||||
NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype));
|
||||
NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected.");
|
||||
napi_create_reference(env, argv[1], 1, &callback);
|
||||
}
|
||||
}
|
||||
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
|
||||
napi_value ParseParameters(
|
||||
const napi_env &env, const napi_value (&argv)[ACTIVE_OR_NUMS_MAX_PARA], const size_t &argc, napi_ref &callback)
|
||||
{
|
||||
ANS_LOGI("ParseParameters start");
|
||||
|
||||
if (argc >= ACTIVE_OR_NUMS_MAX_PARA) {
|
||||
napi_valuetype valuetype;
|
||||
// argv[0]:callback
|
||||
NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype));
|
||||
NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected.");
|
||||
napi_create_reference(env, argv[0], 1, &callback);
|
||||
}
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
|
||||
void PaddingAsyncCallbackInfoIs(
|
||||
const napi_env &env, AsyncCallbackInfoActive *&asynccallbackinfo, const napi_ref &callback, napi_value &promise)
|
||||
{
|
||||
ANS_LOGI("PaddingAsyncCallbackInfoIs start");
|
||||
|
||||
if (callback) {
|
||||
asynccallbackinfo->callback = callback;
|
||||
asynccallbackinfo->isCallback = true;
|
||||
} else {
|
||||
napi_deferred deferred = nullptr;
|
||||
NAPI_CALL_RETURN_VOID(env, napi_create_promise(env, &deferred, &promise));
|
||||
asynccallbackinfo->deferred = deferred;
|
||||
asynccallbackinfo->isCallback = false;
|
||||
}
|
||||
}
|
||||
|
||||
napi_value GetAllActiveNotifications(napi_env env, napi_callback_info info)
|
||||
{
|
||||
ANS_LOGI("GetAllActiveNotifications start");
|
||||
|
||||
size_t argc = ALL_ACTIVE_MAX_PARA;
|
||||
napi_value argv[ALL_ACTIVE_MAX_PARA];
|
||||
napi_value thisVar = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL));
|
||||
NAPI_ASSERT(env, argc >= 0, "Wrong number of arguments");
|
||||
napi_ref callback = nullptr;
|
||||
|
||||
std::vector<std::string> hashcode;
|
||||
if (ParseParametersByAllActive(env, argv, argc, hashcode, callback) == nullptr) {
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
ANS_LOGI("GetAllActiveNotifications hashcode.size = %{public}d", hashcode.size());
|
||||
|
||||
AsyncCallbackInfoActive *asynccallbackinfo =
|
||||
new AsyncCallbackInfoActive{.env = env, .asyncWork = nullptr, .strValue = hashcode};
|
||||
|
||||
napi_value promise = 0;
|
||||
PaddingAsyncCallbackInfoIs(env, asynccallbackinfo, callback, promise);
|
||||
|
||||
napi_value resourceName;
|
||||
napi_create_string_latin1(env, "getAllActiveNotifications", NAPI_AUTO_LENGTH, &resourceName);
|
||||
// Asynchronous function call
|
||||
napi_create_async_work(env,
|
||||
nullptr,
|
||||
resourceName,
|
||||
[](napi_env env, void *data) {
|
||||
ANS_LOGI("GetAllActiveNotifications napi_create_async_work start");
|
||||
AsyncCallbackInfoActive *asynccallbackinfo = (AsyncCallbackInfoActive *)data;
|
||||
|
||||
std::vector<sptr<OHOS::Notification::Notification>> notification;
|
||||
if (asynccallbackinfo->strValue.size() > 0) {
|
||||
asynccallbackinfo->errorCode =
|
||||
NotificationHelper::GetAllActiveNotifications(asynccallbackinfo->strValue, notification);
|
||||
} else {
|
||||
asynccallbackinfo->errorCode = NotificationHelper::GetAllActiveNotifications(notification);
|
||||
}
|
||||
|
||||
napi_value arr;
|
||||
int count = 0;
|
||||
napi_create_array(env, &arr);
|
||||
for (auto vec : notification) {
|
||||
if (vec) {
|
||||
napi_value result;
|
||||
std::shared_ptr<OHOS::Notification::Notification> notificationSharedPtr(
|
||||
static_cast<OHOS::Notification::Notification *>(vec.GetRefPtr()));
|
||||
if (Common::SetNotificationRequest(env, notificationSharedPtr, result)) {
|
||||
napi_set_element(env, arr, count, result);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count > 0) {
|
||||
ANS_LOGI("GetAllActiveNotifications count = %{public}d", count);
|
||||
asynccallbackinfo->result = arr;
|
||||
} else {
|
||||
asynccallbackinfo->result = Common::NapiGetNull(env);
|
||||
}
|
||||
},
|
||||
[](napi_env env, napi_status status, void *data) {
|
||||
ANS_LOGI("GetAllActiveNotifications napi_create_async_work end");
|
||||
AsyncCallbackInfoActive *asynccallbackinfo = (AsyncCallbackInfoActive *)data;
|
||||
|
||||
CallbackPromiseInfo info;
|
||||
info.isCallback = asynccallbackinfo->isCallback;
|
||||
info.callback = asynccallbackinfo->callback;
|
||||
info.deferred = asynccallbackinfo->deferred;
|
||||
info.errorCode = asynccallbackinfo->errorCode;
|
||||
Common::ReturnCallbackPromise(env, info, asynccallbackinfo->result);
|
||||
|
||||
napi_delete_async_work(env, asynccallbackinfo->asyncWork);
|
||||
if (asynccallbackinfo) {
|
||||
delete asynccallbackinfo;
|
||||
asynccallbackinfo = nullptr;
|
||||
}
|
||||
},
|
||||
(void *)asynccallbackinfo,
|
||||
&asynccallbackinfo->asyncWork);
|
||||
|
||||
NAPI_CALL(env, napi_queue_async_work(env, asynccallbackinfo->asyncWork));
|
||||
|
||||
if (asynccallbackinfo->isCallback) {
|
||||
return Common::NapiGetNull(env);
|
||||
} else {
|
||||
return promise;
|
||||
}
|
||||
}
|
||||
|
||||
napi_value GetActiveNotifications(napi_env env, napi_callback_info info)
|
||||
{
|
||||
ANS_LOGI("GetActiveNotifications start");
|
||||
|
||||
size_t argc = ACTIVE_OR_NUMS_MAX_PARA;
|
||||
napi_value argv[ACTIVE_OR_NUMS_MAX_PARA];
|
||||
napi_value thisVar = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL));
|
||||
NAPI_ASSERT(env, argc >= 0, "Wrong number of arguments");
|
||||
napi_ref callback = nullptr;
|
||||
|
||||
if (ParseParameters(env, argv, argc, callback) == nullptr) {
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
|
||||
AsyncCallbackInfoActive *asynccallbackinfo = new AsyncCallbackInfoActive{.env = env, .asyncWork = nullptr};
|
||||
|
||||
napi_value promise = 0;
|
||||
PaddingAsyncCallbackInfoIs(env, asynccallbackinfo, callback, promise);
|
||||
|
||||
napi_value resourceName;
|
||||
napi_create_string_latin1(env, "getActiveNotifications", NAPI_AUTO_LENGTH, &resourceName);
|
||||
// Asynchronous function call
|
||||
napi_create_async_work(env,
|
||||
nullptr,
|
||||
resourceName,
|
||||
[](napi_env env, void *data) {
|
||||
ANS_LOGI("GetActiveNotifications napi_create_async_work start");
|
||||
AsyncCallbackInfoActive *asynccallbackinfo = (AsyncCallbackInfoActive *)data;
|
||||
|
||||
std::vector<sptr<OHOS::Notification::NotificationRequest>> request;
|
||||
asynccallbackinfo->errorCode = NotificationHelper::GetActiveNotifications(request);
|
||||
|
||||
napi_value arr;
|
||||
int count = 0;
|
||||
napi_create_array(env, &arr);
|
||||
for (auto vec : request) {
|
||||
if (vec) {
|
||||
napi_value result;
|
||||
std::shared_ptr<OHOS::Notification::NotificationRequest> requestSharedPtr(
|
||||
static_cast<OHOS::Notification::NotificationRequest *>(vec.GetRefPtr()));
|
||||
if (Common::SetNotificationRequest2(env, requestSharedPtr, result)) {
|
||||
napi_set_element(env, arr, count, result);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count > 0) {
|
||||
ANS_LOGI("GetActiveNotifications count = %{public}d", count);
|
||||
asynccallbackinfo->result = arr;
|
||||
} else {
|
||||
asynccallbackinfo->result = Common::NapiGetNull(env);
|
||||
}
|
||||
},
|
||||
[](napi_env env, napi_status status, void *data) {
|
||||
ANS_LOGI("GetActiveNotifications napi_create_async_work end");
|
||||
AsyncCallbackInfoActive *asynccallbackinfo = (AsyncCallbackInfoActive *)data;
|
||||
|
||||
CallbackPromiseInfo info;
|
||||
info.isCallback = asynccallbackinfo->isCallback;
|
||||
info.callback = asynccallbackinfo->callback;
|
||||
info.deferred = asynccallbackinfo->deferred;
|
||||
info.errorCode = asynccallbackinfo->errorCode;
|
||||
Common::ReturnCallbackPromise(env, info, asynccallbackinfo->result);
|
||||
|
||||
napi_delete_async_work(env, asynccallbackinfo->asyncWork);
|
||||
if (asynccallbackinfo) {
|
||||
delete asynccallbackinfo;
|
||||
asynccallbackinfo = nullptr;
|
||||
}
|
||||
},
|
||||
(void *)asynccallbackinfo,
|
||||
&asynccallbackinfo->asyncWork);
|
||||
|
||||
NAPI_CALL(env, napi_queue_async_work(env, asynccallbackinfo->asyncWork));
|
||||
|
||||
if (asynccallbackinfo->isCallback) {
|
||||
return Common::NapiGetNull(env);
|
||||
} else {
|
||||
return promise;
|
||||
}
|
||||
}
|
||||
napi_value GetActiveNotificationNums(napi_env env, napi_callback_info info)
|
||||
{
|
||||
ANS_LOGI("GetActiveNotificationNums start");
|
||||
|
||||
size_t argc = ACTIVE_OR_NUMS_MAX_PARA;
|
||||
napi_value argv[ACTIVE_OR_NUMS_MAX_PARA];
|
||||
napi_value thisVar = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL));
|
||||
NAPI_ASSERT(env, argc >= 0, "Wrong number of arguments");
|
||||
napi_ref callback = nullptr;
|
||||
|
||||
if (ParseParameters(env, argv, argc, callback) == nullptr) {
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
|
||||
AsyncCallbackInfoActive *asynccallbackinfo = new AsyncCallbackInfoActive{.env = env, .asyncWork = nullptr};
|
||||
|
||||
napi_value promise = 0;
|
||||
PaddingAsyncCallbackInfoIs(env, asynccallbackinfo, callback, promise);
|
||||
|
||||
napi_value resourceName;
|
||||
napi_create_string_latin1(env, "getActiveNotificationNums", NAPI_AUTO_LENGTH, &resourceName);
|
||||
// Asynchronous function call
|
||||
napi_create_async_work(env,
|
||||
nullptr,
|
||||
resourceName,
|
||||
[](napi_env env, void *data) {
|
||||
ANS_LOGI("GetActiveNotificationNums napi_create_async_work start");
|
||||
AsyncCallbackInfoActive *asynccallbackinfo = (AsyncCallbackInfoActive *)data;
|
||||
|
||||
int32_t nums = 0;
|
||||
asynccallbackinfo->errorCode = NotificationHelper::GetActiveNotificationNums(nums);
|
||||
ANS_LOGI("GetActiveNotificationNums nums = %{public}d", nums);
|
||||
napi_create_int32(env, nums, &asynccallbackinfo->result);
|
||||
},
|
||||
[](napi_env env, napi_status status, void *data) {
|
||||
ANS_LOGI("GetActiveNotificationNums napi_create_async_work end");
|
||||
AsyncCallbackInfoActive *asynccallbackinfo = (AsyncCallbackInfoActive *)data;
|
||||
|
||||
CallbackPromiseInfo info;
|
||||
info.isCallback = asynccallbackinfo->isCallback;
|
||||
info.callback = asynccallbackinfo->callback;
|
||||
info.deferred = asynccallbackinfo->deferred;
|
||||
info.errorCode = asynccallbackinfo->errorCode;
|
||||
Common::ReturnCallbackPromise(env, info, asynccallbackinfo->result);
|
||||
|
||||
napi_delete_async_work(env, asynccallbackinfo->asyncWork);
|
||||
if (asynccallbackinfo) {
|
||||
delete asynccallbackinfo;
|
||||
asynccallbackinfo = nullptr;
|
||||
}
|
||||
},
|
||||
(void *)asynccallbackinfo,
|
||||
&asynccallbackinfo->asyncWork);
|
||||
|
||||
NAPI_CALL(env, napi_queue_async_work(env, asynccallbackinfo->asyncWork));
|
||||
|
||||
if (asynccallbackinfo->isCallback) {
|
||||
return Common::NapiGetNull(env);
|
||||
} else {
|
||||
return promise;
|
||||
}
|
||||
}
|
||||
} // namespace NotificationNapi
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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 "init.h"
|
||||
#include "cancel.h"
|
||||
#include "constant.h"
|
||||
#include "create_subscriber.h"
|
||||
#include "get_active.h"
|
||||
#include "publish.h"
|
||||
#include "remove.h"
|
||||
#include "slot.h"
|
||||
#include "subscribe.h"
|
||||
#include "unsubscribe.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace NotificationNapi {
|
||||
using namespace OHOS::Notification;
|
||||
|
||||
EXTERN_C_START
|
||||
|
||||
napi_value NotificationInit(napi_env env, napi_value exports)
|
||||
{
|
||||
ANS_LOGI("notificationInit start");
|
||||
|
||||
napi_property_descriptor desc[] = {
|
||||
DECLARE_NAPI_FUNCTION("createSubscriber", CreateSubscriber),
|
||||
DECLARE_NAPI_FUNCTION("subscribe", Subscribe),
|
||||
DECLARE_NAPI_FUNCTION("unsubscribe", Unsubscribe),
|
||||
DECLARE_NAPI_FUNCTION("publish", Publish),
|
||||
DECLARE_NAPI_FUNCTION("remove", Remove),
|
||||
DECLARE_NAPI_FUNCTION("removeAll", RemoveAll),
|
||||
DECLARE_NAPI_FUNCTION("removeAsBundle", RemoveAsBundle),
|
||||
DECLARE_NAPI_FUNCTION("getAllActiveNotifications", GetAllActiveNotifications),
|
||||
DECLARE_NAPI_FUNCTION("getActiveNotifications", GetActiveNotifications),
|
||||
DECLARE_NAPI_FUNCTION("getActiveNotificationNums", GetActiveNotificationNums),
|
||||
DECLARE_NAPI_FUNCTION("cancel", Cancel),
|
||||
DECLARE_NAPI_FUNCTION("cancelAll", CancelAll),
|
||||
DECLARE_NAPI_FUNCTION("addSlot", AddSlot),
|
||||
DECLARE_NAPI_FUNCTION("addSlots", AddSlots),
|
||||
DECLARE_NAPI_FUNCTION("getSlot", GetSlot),
|
||||
DECLARE_NAPI_FUNCTION("getSlots", GetSlots),
|
||||
DECLARE_NAPI_FUNCTION("removeSlot", RemoveSlot),
|
||||
};
|
||||
|
||||
NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
|
||||
|
||||
return exports;
|
||||
}
|
||||
|
||||
/*
|
||||
* Module export function
|
||||
*/
|
||||
static napi_value Init(napi_env env, napi_value exports)
|
||||
{
|
||||
/*
|
||||
* Propertise define
|
||||
*/
|
||||
NotificationSubscriberInit(env, exports);
|
||||
NotificationInit(env, exports);
|
||||
ConstantInit(env, exports);
|
||||
return exports;
|
||||
}
|
||||
|
||||
/*
|
||||
* Module register function
|
||||
*/
|
||||
__attribute__((constructor)) void RegisterModule(void)
|
||||
{
|
||||
napi_module_register(&_module);
|
||||
}
|
||||
EXTERN_C_END
|
||||
|
||||
} // namespace NotificationNapi
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* 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 "publish.h"
|
||||
#include "notification_basic_content.h"
|
||||
#include "notification_constant.h"
|
||||
#include "notification_content.h"
|
||||
#include "notification_normal_content.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace NotificationNapi {
|
||||
using namespace OHOS::Notification;
|
||||
|
||||
static napi_value GetCallbackByPublish(
|
||||
ParseParametersPublish &parseParameters, const napi_value &value, napi_valuetype &valuetype);
|
||||
|
||||
napi_value Publish(napi_env env, napi_callback_info info)
|
||||
{
|
||||
ANS_LOGI("enter");
|
||||
|
||||
size_t argc = PUBLISH_NOTIFICATION_MAX;
|
||||
napi_value argv[PUBLISH_NOTIFICATION_MAX];
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL));
|
||||
NAPI_ASSERT(env, argc >= 1, "Wrong number of arguments");
|
||||
|
||||
ParseParametersPublish parseParameters = {env, argc, false, "", nullptr};
|
||||
NotificationRequest notificationRequest;
|
||||
if (ParseParametersByPublish(parseParameters, argv, notificationRequest) == nullptr) {
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
AsyncCallbackInfoPublish *asynccallbackinfo = new AsyncCallbackInfoPublish{.env = env, .asyncWork = nullptr};
|
||||
napi_value promise = 0;
|
||||
|
||||
PaddingCallbackInfoInfoPublish(asynccallbackinfo, parseParameters, notificationRequest);
|
||||
|
||||
PaddingPublishCallbackPromise(env, parseParameters, asynccallbackinfo, promise);
|
||||
|
||||
napi_value resourceName;
|
||||
napi_create_string_latin1(env, "publish", NAPI_AUTO_LENGTH, &resourceName);
|
||||
|
||||
napi_create_async_work(env,
|
||||
nullptr,
|
||||
resourceName,
|
||||
[](napi_env env, void *data) {
|
||||
ANS_LOGI("Publish napi_create_async_work start");
|
||||
AsyncCallbackInfoPublish *asynccallbackinfo = (AsyncCallbackInfoPublish *)data;
|
||||
ANS_LOGI("==============Publish napi_create_async_work start notificationId = %{public}d,contentType = "
|
||||
"%{public}d",
|
||||
asynccallbackinfo->notificationRequest.GetNotificationId(),
|
||||
asynccallbackinfo->notificationRequest.GetContent()->GetContentType());
|
||||
|
||||
asynccallbackinfo->errorCode = NotificationHelper::PublishNotification(
|
||||
asynccallbackinfo->lable, asynccallbackinfo->notificationRequest);
|
||||
},
|
||||
[](napi_env env, napi_status status, void *data) {
|
||||
ANS_LOGI("Publish napi_create_async_work complete start");
|
||||
AsyncCallbackInfoPublish *asynccallbackinfo = (AsyncCallbackInfoPublish *)data;
|
||||
|
||||
CallbackPromiseInfo info;
|
||||
info.isCallback = asynccallbackinfo->isCallback;
|
||||
info.callback = asynccallbackinfo->callback;
|
||||
info.deferred = asynccallbackinfo->deferred;
|
||||
info.errorCode = asynccallbackinfo->errorCode;
|
||||
Common::ReturnCallbackPromise(env, info, Common::NapiGetNull(env));
|
||||
|
||||
napi_delete_async_work(env, asynccallbackinfo->asyncWork);
|
||||
if (asynccallbackinfo) {
|
||||
delete asynccallbackinfo;
|
||||
asynccallbackinfo = nullptr;
|
||||
}
|
||||
ANS_LOGI("Publish napi_create_async_work complete end");
|
||||
},
|
||||
(void *)asynccallbackinfo,
|
||||
&asynccallbackinfo->asyncWork);
|
||||
|
||||
NAPI_CALL(env, napi_queue_async_work(env, asynccallbackinfo->asyncWork));
|
||||
|
||||
if (asynccallbackinfo->isCallback) {
|
||||
return Common::NapiGetNull(env);
|
||||
} else {
|
||||
return promise;
|
||||
}
|
||||
}
|
||||
|
||||
napi_value ParseParametersByPublish(ParseParametersPublish &parseParameters,
|
||||
const napi_value (&argv)[PUBLISH_NOTIFICATION_MAX], NotificationRequest ¬ificationRequest)
|
||||
{
|
||||
ANS_LOGI("enter");
|
||||
|
||||
napi_valuetype valuetype;
|
||||
|
||||
NAPI_CALL(parseParameters.env, napi_typeof(parseParameters.env, argv[0], &valuetype));
|
||||
NAPI_ASSERT(parseParameters.env, valuetype == napi_object, "Wrong argument type. Object expected.");
|
||||
|
||||
// argv[0]----NotificationRequest
|
||||
if (Common::GetNotificationRequest(parseParameters.env, argv[0], notificationRequest) == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// argv[1] : callback
|
||||
if (parseParameters.argc == PUBLISH_NOTIFICATION_MAX) {
|
||||
GetCallbackByPublish(parseParameters, argv[1], valuetype);
|
||||
}
|
||||
|
||||
ANS_LOGI("end");
|
||||
return Common::NapiGetNull(parseParameters.env);
|
||||
}
|
||||
|
||||
napi_value GetCallbackByPublish(
|
||||
ParseParametersPublish &parseParameters, const napi_value &value, napi_valuetype &valuetype)
|
||||
{
|
||||
ANS_LOGI("enter");
|
||||
|
||||
NAPI_CALL(parseParameters.env, napi_typeof(parseParameters.env, value, &valuetype));
|
||||
NAPI_ASSERT(parseParameters.env, valuetype = napi_function, "Wrong argument type. Function expected.");
|
||||
napi_create_reference(parseParameters.env, value, 1, &parseParameters.callback);
|
||||
ANS_LOGI("end");
|
||||
return Common::NapiGetNull(parseParameters.env);
|
||||
}
|
||||
|
||||
void PaddingCallbackInfoInfoPublish(AsyncCallbackInfoPublish *&asynccallbackinfo,
|
||||
const ParseParametersPublish &parseParameters, const NotificationRequest ¬ificationRequest)
|
||||
{
|
||||
ANS_LOGI("enter");
|
||||
|
||||
asynccallbackinfo->lable = parseParameters.lable;
|
||||
asynccallbackinfo->notificationRequest = notificationRequest;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void PaddingPublishCallbackPromise(const napi_env &env, const ParseParametersPublish &parseParameters,
|
||||
AsyncCallbackInfoPublish *&asynccallbackinfo, napi_value &promise)
|
||||
{
|
||||
ANS_LOGI("enter");
|
||||
|
||||
if (parseParameters.callback != nullptr) {
|
||||
asynccallbackinfo->callback = parseParameters.callback;
|
||||
asynccallbackinfo->isCallback = true;
|
||||
} else {
|
||||
napi_deferred deferred = nullptr;
|
||||
napi_create_promise(env, &deferred, &promise);
|
||||
asynccallbackinfo->deferred = deferred;
|
||||
asynccallbackinfo->isCallback = false;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
} // namespace NotificationNapi
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,254 @@
|
||||
/*
|
||||
* 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 "remove.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace NotificationNapi {
|
||||
napi_value ParseParameters(const napi_env &env, const napi_value (&argv)[REMOVE_OR_BUNDLE_MAX_PARA], const size_t &argc,
|
||||
std::string &strValue, napi_ref &callback)
|
||||
{
|
||||
// argv[0]: hashCode/bundleName
|
||||
size_t strLen;
|
||||
char str[STR_MAX_SIZE] = {0};
|
||||
napi_valuetype valuetype;
|
||||
NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype));
|
||||
NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected.");
|
||||
NAPI_CALL(env, napi_get_value_string_utf8(env, argv[0], str, STR_MAX_SIZE - 1, &strLen));
|
||||
strValue = str;
|
||||
|
||||
// argv[1]:callback
|
||||
if (argc >= REMOVE_OR_BUNDLE_MAX_PARA) {
|
||||
NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype));
|
||||
NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected.");
|
||||
napi_create_reference(env, argv[1], 1, &callback);
|
||||
}
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
|
||||
napi_value ParseParametersByRemoveAll(
|
||||
const napi_env &env, const napi_value (&argv)[REMOVE_ALL_MAX_PARA], const size_t &argc, napi_ref &callback)
|
||||
{
|
||||
// argv[0]:callback
|
||||
napi_valuetype valuetype;
|
||||
if (argc >= REMOVE_ALL_MAX_PARA) {
|
||||
NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype));
|
||||
NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected.");
|
||||
napi_create_reference(env, argv[0], 1, &callback);
|
||||
}
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
void PaddingAsyncCallbackInfoIs(
|
||||
const napi_env &env, AsyncCallbackInfoRemove *&asynccallbackinfo, const napi_ref &callback, napi_value &promise)
|
||||
{
|
||||
ANS_LOGI("PaddingAsyncCallbackInfoIs start");
|
||||
|
||||
if (callback) {
|
||||
asynccallbackinfo->callback = callback;
|
||||
asynccallbackinfo->isCallback = true;
|
||||
} else {
|
||||
napi_deferred deferred = nullptr;
|
||||
NAPI_CALL_RETURN_VOID(env, napi_create_promise(env, &deferred, &promise));
|
||||
asynccallbackinfo->deferred = deferred;
|
||||
asynccallbackinfo->isCallback = false;
|
||||
}
|
||||
}
|
||||
|
||||
napi_value Remove(napi_env env, napi_callback_info info)
|
||||
{
|
||||
ANS_LOGI("Remove start");
|
||||
|
||||
size_t argc = REMOVE_OR_BUNDLE_MAX_PARA;
|
||||
napi_value argv[REMOVE_OR_BUNDLE_MAX_PARA];
|
||||
napi_value thisVar = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL));
|
||||
NAPI_ASSERT(env, argc >= 1, "Wrong number of arguments");
|
||||
napi_ref callback = nullptr;
|
||||
|
||||
std::string hashCode;
|
||||
if (ParseParameters(env, argv, argc, hashCode, callback) == nullptr) {
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
ANS_LOGI("Remove hashCode = %{public}s", hashCode.c_str());
|
||||
|
||||
AsyncCallbackInfoRemove *asynccallbackinfo =
|
||||
new AsyncCallbackInfoRemove{.env = env, .asyncWork = nullptr, .strValue = hashCode};
|
||||
|
||||
napi_value promise = 0;
|
||||
PaddingAsyncCallbackInfoIs(env, asynccallbackinfo, callback, promise);
|
||||
|
||||
napi_value resourceName;
|
||||
napi_create_string_latin1(env, "remove", NAPI_AUTO_LENGTH, &resourceName);
|
||||
// Asynchronous function call
|
||||
napi_create_async_work(env,
|
||||
nullptr,
|
||||
resourceName,
|
||||
[](napi_env env, void *data) {
|
||||
ANS_LOGI("Remove napi_create_async_work start");
|
||||
AsyncCallbackInfoRemove *asynccallbackinfo = (AsyncCallbackInfoRemove *)data;
|
||||
asynccallbackinfo->errorCode = NotificationHelper::RemoveNotification(asynccallbackinfo->strValue);
|
||||
},
|
||||
[](napi_env env, napi_status status, void *data) {
|
||||
ANS_LOGI("Remove napi_create_async_work end");
|
||||
AsyncCallbackInfoRemove *asynccallbackinfo = (AsyncCallbackInfoRemove *)data;
|
||||
|
||||
CallbackPromiseInfo info;
|
||||
info.isCallback = asynccallbackinfo->isCallback;
|
||||
info.callback = asynccallbackinfo->callback;
|
||||
info.deferred = asynccallbackinfo->deferred;
|
||||
info.errorCode = asynccallbackinfo->errorCode;
|
||||
Common::ReturnCallbackPromise(env, info, Common::NapiGetNull(env));
|
||||
|
||||
napi_delete_async_work(env, asynccallbackinfo->asyncWork);
|
||||
if (asynccallbackinfo) {
|
||||
delete asynccallbackinfo;
|
||||
asynccallbackinfo = nullptr;
|
||||
}
|
||||
},
|
||||
(void *)asynccallbackinfo,
|
||||
&asynccallbackinfo->asyncWork);
|
||||
|
||||
NAPI_CALL(env, napi_queue_async_work(env, asynccallbackinfo->asyncWork));
|
||||
|
||||
if (asynccallbackinfo->isCallback) {
|
||||
return Common::NapiGetNull(env);
|
||||
} else {
|
||||
return promise;
|
||||
}
|
||||
}
|
||||
napi_value RemoveAsBundle(napi_env env, napi_callback_info info)
|
||||
{
|
||||
ANS_LOGI("RemoveAsBundle start");
|
||||
|
||||
size_t argc = REMOVE_OR_BUNDLE_MAX_PARA;
|
||||
napi_value argv[REMOVE_OR_BUNDLE_MAX_PARA];
|
||||
napi_value thisVar = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL));
|
||||
NAPI_ASSERT(env, argc >= 1, "Wrong number of arguments");
|
||||
napi_ref callback = nullptr;
|
||||
|
||||
std::string bundleName;
|
||||
if (ParseParameters(env, argv, argc, bundleName, callback) == nullptr) {
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
ANS_LOGI("RemoveAsBundle bundleName = %{public}s", bundleName.c_str());
|
||||
|
||||
AsyncCallbackInfoRemove *asynccallbackinfo =
|
||||
new AsyncCallbackInfoRemove{.env = env, .asyncWork = nullptr, .strValue = bundleName};
|
||||
|
||||
napi_value promise = 0;
|
||||
PaddingAsyncCallbackInfoIs(env, asynccallbackinfo, callback, promise);
|
||||
|
||||
napi_value resourceName;
|
||||
napi_create_string_latin1(env, "removeAsBundle", NAPI_AUTO_LENGTH, &resourceName);
|
||||
// Asynchronous function call
|
||||
napi_create_async_work(env,
|
||||
nullptr,
|
||||
resourceName,
|
||||
[](napi_env env, void *data) {
|
||||
ANS_LOGI("removeAsBundle napi_create_async_work start");
|
||||
AsyncCallbackInfoRemove *asynccallbackinfo = (AsyncCallbackInfoRemove *)data;
|
||||
asynccallbackinfo->errorCode = NotificationHelper::RemoveNotifications(asynccallbackinfo->strValue);
|
||||
},
|
||||
[](napi_env env, napi_status status, void *data) {
|
||||
ANS_LOGI("removeAsBundle napi_create_async_work end");
|
||||
AsyncCallbackInfoRemove *asynccallbackinfo = (AsyncCallbackInfoRemove *)data;
|
||||
|
||||
CallbackPromiseInfo info;
|
||||
info.isCallback = asynccallbackinfo->isCallback;
|
||||
info.callback = asynccallbackinfo->callback;
|
||||
info.deferred = asynccallbackinfo->deferred;
|
||||
info.errorCode = asynccallbackinfo->errorCode;
|
||||
Common::ReturnCallbackPromise(env, info, Common::NapiGetNull(env));
|
||||
|
||||
napi_delete_async_work(env, asynccallbackinfo->asyncWork);
|
||||
if (asynccallbackinfo) {
|
||||
delete asynccallbackinfo;
|
||||
asynccallbackinfo = nullptr;
|
||||
}
|
||||
},
|
||||
(void *)asynccallbackinfo,
|
||||
&asynccallbackinfo->asyncWork);
|
||||
|
||||
NAPI_CALL(env, napi_queue_async_work(env, asynccallbackinfo->asyncWork));
|
||||
|
||||
if (asynccallbackinfo->isCallback) {
|
||||
return Common::NapiGetNull(env);
|
||||
} else {
|
||||
return promise;
|
||||
}
|
||||
}
|
||||
napi_value RemoveAll(napi_env env, napi_callback_info info)
|
||||
{
|
||||
ANS_LOGI("RemoveAll start");
|
||||
|
||||
size_t argc = REMOVE_ALL_MAX_PARA;
|
||||
napi_value argv[REMOVE_ALL_MAX_PARA];
|
||||
napi_value thisVar = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL));
|
||||
NAPI_ASSERT(env, argc >= 0, "Wrong number of arguments");
|
||||
napi_ref callback = nullptr;
|
||||
|
||||
if (ParseParametersByRemoveAll(env, argv, argc, callback) == nullptr) {
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
|
||||
AsyncCallbackInfoRemove *asynccallbackinfo = new AsyncCallbackInfoRemove{.env = env, .asyncWork = nullptr};
|
||||
|
||||
napi_value promise = 0;
|
||||
PaddingAsyncCallbackInfoIs(env, asynccallbackinfo, callback, promise);
|
||||
|
||||
napi_value resourceName;
|
||||
napi_create_string_latin1(env, "removeAll", NAPI_AUTO_LENGTH, &resourceName);
|
||||
// Asynchronous function call
|
||||
napi_create_async_work(env,
|
||||
nullptr,
|
||||
resourceName,
|
||||
[](napi_env env, void *data) {
|
||||
ANS_LOGI("RemoveAll napi_create_async_work start");
|
||||
AsyncCallbackInfoRemove *asynccallbackinfo = (AsyncCallbackInfoRemove *)data;
|
||||
asynccallbackinfo->errorCode = NotificationHelper::RemoveNotifications();
|
||||
},
|
||||
[](napi_env env, napi_status status, void *data) {
|
||||
ANS_LOGI("RemoveAll napi_create_async_work end");
|
||||
AsyncCallbackInfoRemove *asynccallbackinfo = (AsyncCallbackInfoRemove *)data;
|
||||
|
||||
CallbackPromiseInfo info;
|
||||
info.isCallback = asynccallbackinfo->isCallback;
|
||||
info.callback = asynccallbackinfo->callback;
|
||||
info.deferred = asynccallbackinfo->deferred;
|
||||
info.errorCode = asynccallbackinfo->errorCode;
|
||||
Common::ReturnCallbackPromise(env, info, Common::NapiGetNull(env));
|
||||
|
||||
napi_delete_async_work(env, asynccallbackinfo->asyncWork);
|
||||
if (asynccallbackinfo) {
|
||||
delete asynccallbackinfo;
|
||||
asynccallbackinfo = nullptr;
|
||||
}
|
||||
},
|
||||
(void *)asynccallbackinfo,
|
||||
&asynccallbackinfo->asyncWork);
|
||||
|
||||
NAPI_CALL(env, napi_queue_async_work(env, asynccallbackinfo->asyncWork));
|
||||
|
||||
if (asynccallbackinfo->isCallback) {
|
||||
return Common::NapiGetNull(env);
|
||||
} else {
|
||||
return promise;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace NotificationNapi
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,552 @@
|
||||
/*
|
||||
* 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 "slot.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace NotificationNapi {
|
||||
napi_value ParseParametersByAddSlot(const napi_env &env, const napi_value (&argv)[ADD_SLOT_MAX_PARA],
|
||||
const size_t &argc, NotificationSlot &slot, napi_ref &callback)
|
||||
{
|
||||
napi_valuetype valuetype;
|
||||
// argv[0]: NotificationSlot
|
||||
NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype));
|
||||
NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected.");
|
||||
if (!Common::GetNotificationSlot(env, slot, argv[0])) {
|
||||
return nullptr;
|
||||
}
|
||||
// argv[1]:callback
|
||||
if (argc >= ADD_SLOT_MAX_PARA) {
|
||||
NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype));
|
||||
NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected.");
|
||||
napi_create_reference(env, argv[1], 1, &callback);
|
||||
}
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
|
||||
void PaddingAsyncCallbackInfoIsByAddSlot(
|
||||
const napi_env &env, AsyncCallbackInfoAddSlot *&asynccallbackinfo, const napi_ref &callback, napi_value &promise)
|
||||
{
|
||||
ANS_LOGI("PaddingAsyncCallbackInfoIs start");
|
||||
|
||||
if (callback) {
|
||||
asynccallbackinfo->callback = callback;
|
||||
asynccallbackinfo->isCallback = true;
|
||||
} else {
|
||||
napi_deferred deferred = nullptr;
|
||||
NAPI_CALL_RETURN_VOID(env, napi_create_promise(env, &deferred, &promise));
|
||||
asynccallbackinfo->deferred = deferred;
|
||||
asynccallbackinfo->isCallback = false;
|
||||
}
|
||||
}
|
||||
|
||||
napi_value ParseParametersByAddSlots(const napi_env &env, const napi_value (&argv)[ADD_SLOTS_MAX_PARA],
|
||||
const size_t &argc, std::vector<NotificationSlot> &slots, napi_ref &callback)
|
||||
{
|
||||
napi_valuetype valuetype;
|
||||
// argv[0]: Array<NotificationSlot>
|
||||
bool isArray = false;
|
||||
napi_is_array(env, argv[0], &isArray);
|
||||
if (isArray) {
|
||||
uint32_t length = 0;
|
||||
napi_get_array_length(env, argv[0], &length);
|
||||
for (size_t i = 0; i < length; i++) {
|
||||
napi_value nSlot;
|
||||
napi_get_element(env, argv[0], i, &nSlot);
|
||||
NAPI_CALL(env, napi_typeof(env, nSlot, &valuetype));
|
||||
NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected.");
|
||||
NotificationSlot slot;
|
||||
if (!Common::GetNotificationSlot(env, slot, argv[0])) {
|
||||
return nullptr;
|
||||
}
|
||||
slots.emplace_back(slot);
|
||||
}
|
||||
if (slots.size() == 0) {
|
||||
ANS_LOGI("slots size is empyt");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
// argv[1]:callback
|
||||
if (argc >= ADD_SLOTS_MAX_PARA) {
|
||||
NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype));
|
||||
NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected.");
|
||||
napi_create_reference(env, argv[1], 1, &callback);
|
||||
}
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
|
||||
void PaddingAsyncCallbackInfoIsByAddSlots(
|
||||
const napi_env &env, AsyncCallbackInfoAddSlots *&asynccallbackinfo, const napi_ref &callback, napi_value &promise)
|
||||
{
|
||||
ANS_LOGI("PaddingAsyncCallbackInfoIs start");
|
||||
|
||||
if (callback) {
|
||||
asynccallbackinfo->callback = callback;
|
||||
asynccallbackinfo->isCallback = true;
|
||||
} else {
|
||||
napi_deferred deferred = nullptr;
|
||||
NAPI_CALL_RETURN_VOID(env, napi_create_promise(env, &deferred, &promise));
|
||||
asynccallbackinfo->deferred = deferred;
|
||||
asynccallbackinfo->isCallback = false;
|
||||
}
|
||||
}
|
||||
|
||||
napi_value ParseParametersByGetSlot(const napi_env &env, const napi_value (&argv)[GET_SLOT_MAX_PARA],
|
||||
const size_t &argc, enum NotificationConstant::SlotType &outType, napi_ref &callback)
|
||||
{
|
||||
napi_valuetype valuetype;
|
||||
// argv[0]: SlotType
|
||||
NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype));
|
||||
NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number expected.");
|
||||
|
||||
int slotType = 0;
|
||||
napi_get_value_int32(env, argv[0], &slotType);
|
||||
|
||||
if (!Common::SlotTypeJSToC(SlotType(slotType), outType)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// argv[1]:callback
|
||||
if (argc >= GET_SLOT_MAX_PARA) {
|
||||
NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype));
|
||||
NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected.");
|
||||
napi_create_reference(env, argv[1], 1, &callback);
|
||||
}
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
|
||||
void PaddingAsyncCallbackInfoIsByGetSlot(
|
||||
const napi_env &env, AsyncCallbackInfoGetSlot *&asynccallbackinfo, const napi_ref &callback, napi_value &promise)
|
||||
{
|
||||
ANS_LOGI("PaddingAsyncCallbackInfoIs start");
|
||||
|
||||
if (callback) {
|
||||
asynccallbackinfo->callback = callback;
|
||||
asynccallbackinfo->isCallback = true;
|
||||
} else {
|
||||
napi_deferred deferred = nullptr;
|
||||
NAPI_CALL_RETURN_VOID(env, napi_create_promise(env, &deferred, &promise));
|
||||
asynccallbackinfo->deferred = deferred;
|
||||
asynccallbackinfo->isCallback = false;
|
||||
}
|
||||
}
|
||||
|
||||
napi_value ParseParametersByGetSlots(
|
||||
const napi_env &env, const napi_value (&argv)[GET_SLOTS_MAX_PARA], const size_t &argc, napi_ref &callback)
|
||||
{
|
||||
// argv[0]:callback
|
||||
napi_valuetype valuetype;
|
||||
if (argc >= GET_SLOTS_MAX_PARA) {
|
||||
NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype));
|
||||
NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected.");
|
||||
napi_create_reference(env, argv[0], 1, &callback);
|
||||
}
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
|
||||
void PaddingAsyncCallbackInfoIsByGetSlots(
|
||||
const napi_env &env, AsyncCallbackInfoGetSlots *&asynccallbackinfo, const napi_ref &callback, napi_value &promise)
|
||||
{
|
||||
ANS_LOGI("PaddingAsyncCallbackInfoIs start");
|
||||
|
||||
if (callback) {
|
||||
asynccallbackinfo->callback = callback;
|
||||
asynccallbackinfo->isCallback = true;
|
||||
} else {
|
||||
napi_deferred deferred = nullptr;
|
||||
NAPI_CALL_RETURN_VOID(env, napi_create_promise(env, &deferred, &promise));
|
||||
asynccallbackinfo->deferred = deferred;
|
||||
asynccallbackinfo->isCallback = false;
|
||||
}
|
||||
}
|
||||
|
||||
napi_value ParseParametersByRemoveSlot(const napi_env &env, const napi_value (&argv)[REMOVE_SLOT_MAX_PARA],
|
||||
const size_t &argc, enum NotificationConstant::SlotType &outType, napi_ref &callback)
|
||||
{
|
||||
napi_valuetype valuetype;
|
||||
// argv[0]: SlotType
|
||||
NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype));
|
||||
NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number expected.");
|
||||
|
||||
int slotType = 0;
|
||||
napi_get_value_int32(env, argv[0], &slotType);
|
||||
|
||||
if (!Common::SlotTypeJSToC(SlotType(slotType), outType)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// argv[1]:callback
|
||||
if (argc >= REMOVE_SLOT_MAX_PARA) {
|
||||
NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype));
|
||||
NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected.");
|
||||
napi_create_reference(env, argv[1], 1, &callback);
|
||||
}
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
|
||||
void PaddingAsyncCallbackInfoIsByRemoveSlot(
|
||||
const napi_env &env, AsyncCallbackInfoRemoveSlot *&asynccallbackinfo, const napi_ref &callback, napi_value &promise)
|
||||
{
|
||||
ANS_LOGI("PaddingAsyncCallbackInfoIs start");
|
||||
|
||||
if (callback) {
|
||||
asynccallbackinfo->callback = callback;
|
||||
asynccallbackinfo->isCallback = true;
|
||||
} else {
|
||||
napi_deferred deferred = nullptr;
|
||||
NAPI_CALL_RETURN_VOID(env, napi_create_promise(env, &deferred, &promise));
|
||||
asynccallbackinfo->deferred = deferred;
|
||||
asynccallbackinfo->isCallback = false;
|
||||
}
|
||||
}
|
||||
|
||||
napi_value AddSlot(napi_env env, napi_callback_info info)
|
||||
{
|
||||
ANS_LOGI("AddSlot start");
|
||||
|
||||
size_t argc = ADD_SLOT_MAX_PARA;
|
||||
napi_value argv[ADD_SLOT_MAX_PARA];
|
||||
napi_value thisVar = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL));
|
||||
NAPI_ASSERT(env, argc >= 1, "Wrong number of arguments");
|
||||
napi_ref callback = nullptr;
|
||||
|
||||
NotificationSlot slot;
|
||||
if (ParseParametersByAddSlot(env, argv, argc, slot, callback) == nullptr) {
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
|
||||
AsyncCallbackInfoAddSlot *asynccallbackinfo =
|
||||
new AsyncCallbackInfoAddSlot{.env = env, .asyncWork = nullptr, .slot = slot};
|
||||
|
||||
napi_value promise = 0;
|
||||
PaddingAsyncCallbackInfoIsByAddSlot(env, asynccallbackinfo, callback, promise);
|
||||
|
||||
napi_value resourceName;
|
||||
napi_create_string_latin1(env, "addSlot", NAPI_AUTO_LENGTH, &resourceName);
|
||||
// Asynchronous function call
|
||||
napi_create_async_work(env,
|
||||
nullptr,
|
||||
resourceName,
|
||||
[](napi_env env, void *data) {
|
||||
ANS_LOGI("AddSlot napi_create_async_work start");
|
||||
AsyncCallbackInfoAddSlot *asynccallbackinfo = (AsyncCallbackInfoAddSlot *)data;
|
||||
asynccallbackinfo->errorCode = NotificationHelper::AddNotificationSlot(asynccallbackinfo->slot);
|
||||
},
|
||||
[](napi_env env, napi_status status, void *data) {
|
||||
ANS_LOGI("AddSlot napi_create_async_work end");
|
||||
AsyncCallbackInfoAddSlot *asynccallbackinfo = (AsyncCallbackInfoAddSlot *)data;
|
||||
|
||||
CallbackPromiseInfo info;
|
||||
info.isCallback = asynccallbackinfo->isCallback;
|
||||
info.callback = asynccallbackinfo->callback;
|
||||
info.deferred = asynccallbackinfo->deferred;
|
||||
info.errorCode = asynccallbackinfo->errorCode;
|
||||
Common::ReturnCallbackPromise(env, info, Common::NapiGetNull(env));
|
||||
|
||||
napi_delete_async_work(env, asynccallbackinfo->asyncWork);
|
||||
if (asynccallbackinfo) {
|
||||
delete asynccallbackinfo;
|
||||
asynccallbackinfo = nullptr;
|
||||
}
|
||||
},
|
||||
(void *)asynccallbackinfo,
|
||||
&asynccallbackinfo->asyncWork);
|
||||
|
||||
NAPI_CALL(env, napi_queue_async_work(env, asynccallbackinfo->asyncWork));
|
||||
|
||||
if (asynccallbackinfo->isCallback) {
|
||||
return Common::NapiGetNull(env);
|
||||
} else {
|
||||
return promise;
|
||||
}
|
||||
}
|
||||
napi_value AddSlots(napi_env env, napi_callback_info info)
|
||||
{
|
||||
ANS_LOGI("AddSlots start");
|
||||
|
||||
size_t argc = ADD_SLOTS_MAX_PARA;
|
||||
napi_value argv[ADD_SLOTS_MAX_PARA];
|
||||
napi_value thisVar = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL));
|
||||
NAPI_ASSERT(env, argc >= 1, "Wrong number of arguments");
|
||||
napi_ref callback = nullptr;
|
||||
|
||||
std::vector<NotificationSlot> slots;
|
||||
if (ParseParametersByAddSlots(env, argv, argc, slots, callback) == nullptr) {
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
|
||||
AsyncCallbackInfoAddSlots *asynccallbackinfo =
|
||||
new AsyncCallbackInfoAddSlots{.env = env, .asyncWork = nullptr, .slots = slots};
|
||||
|
||||
napi_value promise = 0;
|
||||
PaddingAsyncCallbackInfoIsByAddSlots(env, asynccallbackinfo, callback, promise);
|
||||
|
||||
napi_value resourceName;
|
||||
napi_create_string_latin1(env, "addSlots", NAPI_AUTO_LENGTH, &resourceName);
|
||||
// Asynchronous function call
|
||||
napi_create_async_work(env,
|
||||
nullptr,
|
||||
resourceName,
|
||||
[](napi_env env, void *data) {
|
||||
ANS_LOGI("AddSlots napi_create_async_work start");
|
||||
AsyncCallbackInfoAddSlots *asynccallbackinfo = (AsyncCallbackInfoAddSlots *)data;
|
||||
asynccallbackinfo->errorCode = NotificationHelper::AddNotificationSlots(asynccallbackinfo->slots);
|
||||
},
|
||||
[](napi_env env, napi_status status, void *data) {
|
||||
ANS_LOGI("AddSlots napi_create_async_work end");
|
||||
AsyncCallbackInfoAddSlots *asynccallbackinfo = (AsyncCallbackInfoAddSlots *)data;
|
||||
|
||||
CallbackPromiseInfo info;
|
||||
info.isCallback = asynccallbackinfo->isCallback;
|
||||
info.callback = asynccallbackinfo->callback;
|
||||
info.deferred = asynccallbackinfo->deferred;
|
||||
info.errorCode = asynccallbackinfo->errorCode;
|
||||
Common::ReturnCallbackPromise(env, info, Common::NapiGetNull(env));
|
||||
|
||||
napi_delete_async_work(env, asynccallbackinfo->asyncWork);
|
||||
if (asynccallbackinfo) {
|
||||
delete asynccallbackinfo;
|
||||
asynccallbackinfo = nullptr;
|
||||
}
|
||||
},
|
||||
(void *)asynccallbackinfo,
|
||||
&asynccallbackinfo->asyncWork);
|
||||
|
||||
NAPI_CALL(env, napi_queue_async_work(env, asynccallbackinfo->asyncWork));
|
||||
|
||||
if (asynccallbackinfo->isCallback) {
|
||||
return Common::NapiGetNull(env);
|
||||
} else {
|
||||
return promise;
|
||||
}
|
||||
}
|
||||
napi_value GetSlot(napi_env env, napi_callback_info info)
|
||||
{
|
||||
ANS_LOGI("GetSlot start");
|
||||
|
||||
size_t argc = GET_SLOT_MAX_PARA;
|
||||
napi_value argv[GET_SLOT_MAX_PARA];
|
||||
napi_value thisVar = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL));
|
||||
NAPI_ASSERT(env, argc >= 1, "Wrong number of arguments");
|
||||
napi_ref callback = nullptr;
|
||||
|
||||
enum NotificationConstant::SlotType outType;
|
||||
if (ParseParametersByGetSlot(env, argv, argc, outType, callback) == nullptr) {
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
|
||||
AsyncCallbackInfoGetSlot *asynccallbackinfo =
|
||||
new AsyncCallbackInfoGetSlot{.env = env, .asyncWork = nullptr, .outType = outType};
|
||||
|
||||
napi_value promise = 0;
|
||||
PaddingAsyncCallbackInfoIsByGetSlot(env, asynccallbackinfo, callback, promise);
|
||||
|
||||
napi_value resourceName;
|
||||
napi_create_string_latin1(env, "getSlot", NAPI_AUTO_LENGTH, &resourceName);
|
||||
// Asynchronous function call
|
||||
napi_create_async_work(env,
|
||||
nullptr,
|
||||
resourceName,
|
||||
[](napi_env env, void *data) {
|
||||
ANS_LOGI("GetSlot napi_create_async_work start");
|
||||
AsyncCallbackInfoGetSlot *asynccallbackinfo = (AsyncCallbackInfoGetSlot *)data;
|
||||
|
||||
sptr<NotificationSlot> slot;
|
||||
asynccallbackinfo->errorCode = NotificationHelper::GetNotificationSlot(asynccallbackinfo->outType, slot);
|
||||
if (slot) {
|
||||
napi_create_object(env, &asynccallbackinfo->result);
|
||||
if (!Common::SetNotificationSlot(env, *slot, asynccallbackinfo->result)) {
|
||||
asynccallbackinfo->result = Common::NapiGetNull(env);
|
||||
}
|
||||
} else {
|
||||
asynccallbackinfo->result = Common::NapiGetNull(env);
|
||||
}
|
||||
},
|
||||
[](napi_env env, napi_status status, void *data) {
|
||||
ANS_LOGI("GetSlot napi_create_async_work end");
|
||||
AsyncCallbackInfoGetSlot *asynccallbackinfo = (AsyncCallbackInfoGetSlot *)data;
|
||||
|
||||
CallbackPromiseInfo info;
|
||||
info.isCallback = asynccallbackinfo->isCallback;
|
||||
info.callback = asynccallbackinfo->callback;
|
||||
info.deferred = asynccallbackinfo->deferred;
|
||||
info.errorCode = asynccallbackinfo->errorCode;
|
||||
Common::ReturnCallbackPromise(env, info, asynccallbackinfo->result);
|
||||
|
||||
napi_delete_async_work(env, asynccallbackinfo->asyncWork);
|
||||
if (asynccallbackinfo) {
|
||||
delete asynccallbackinfo;
|
||||
asynccallbackinfo = nullptr;
|
||||
}
|
||||
},
|
||||
(void *)asynccallbackinfo,
|
||||
&asynccallbackinfo->asyncWork);
|
||||
|
||||
NAPI_CALL(env, napi_queue_async_work(env, asynccallbackinfo->asyncWork));
|
||||
|
||||
if (asynccallbackinfo->isCallback) {
|
||||
return Common::NapiGetNull(env);
|
||||
} else {
|
||||
return promise;
|
||||
}
|
||||
}
|
||||
|
||||
napi_value GetSlots(napi_env env, napi_callback_info info)
|
||||
{
|
||||
ANS_LOGI("GetSlots start");
|
||||
|
||||
size_t argc = GET_SLOTS_MAX_PARA;
|
||||
napi_value argv[GET_SLOTS_MAX_PARA];
|
||||
napi_value thisVar = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL));
|
||||
NAPI_ASSERT(env, argc >= 0, "Wrong number of arguments");
|
||||
napi_ref callback = nullptr;
|
||||
|
||||
if (ParseParametersByGetSlots(env, argv, argc, callback) == nullptr) {
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
|
||||
AsyncCallbackInfoGetSlots *asynccallbackinfo = new AsyncCallbackInfoGetSlots{.env = env, .asyncWork = nullptr};
|
||||
|
||||
napi_value promise = 0;
|
||||
PaddingAsyncCallbackInfoIsByGetSlots(env, asynccallbackinfo, callback, promise);
|
||||
|
||||
napi_value resourceName;
|
||||
napi_create_string_latin1(env, "getSlots", NAPI_AUTO_LENGTH, &resourceName);
|
||||
// Asynchronous function call
|
||||
napi_create_async_work(env,
|
||||
nullptr,
|
||||
resourceName,
|
||||
[](napi_env env, void *data) {
|
||||
ANS_LOGI("GetSlots napi_create_async_work start");
|
||||
AsyncCallbackInfoGetSlots *asynccallbackinfo = (AsyncCallbackInfoGetSlots *)data;
|
||||
|
||||
std::vector<sptr<NotificationSlot>> slots;
|
||||
asynccallbackinfo->errorCode = NotificationHelper::GetNotificationSlots(slots);
|
||||
|
||||
napi_value arr;
|
||||
napi_create_array(env, &arr);
|
||||
size_t count = 0;
|
||||
for (auto vec : slots) {
|
||||
if (vec) {
|
||||
napi_value nSlot;
|
||||
napi_create_object(env, &nSlot);
|
||||
if (Common::SetNotificationSlot(env, *vec, nSlot)) {
|
||||
napi_set_element(env, arr, count, nSlot);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
ANS_LOGI("getSlots count = %{public}d", count);
|
||||
if (count == 0) {
|
||||
asynccallbackinfo->result = Common::NapiGetNull(env);
|
||||
}
|
||||
asynccallbackinfo->result = arr;
|
||||
},
|
||||
[](napi_env env, napi_status status, void *data) {
|
||||
ANS_LOGI("GetSlots napi_create_async_work end");
|
||||
AsyncCallbackInfoGetSlots *asynccallbackinfo = (AsyncCallbackInfoGetSlots *)data;
|
||||
|
||||
CallbackPromiseInfo info;
|
||||
info.isCallback = asynccallbackinfo->isCallback;
|
||||
info.callback = asynccallbackinfo->callback;
|
||||
info.deferred = asynccallbackinfo->deferred;
|
||||
info.errorCode = asynccallbackinfo->errorCode;
|
||||
Common::ReturnCallbackPromise(env, info, asynccallbackinfo->result);
|
||||
|
||||
napi_delete_async_work(env, asynccallbackinfo->asyncWork);
|
||||
if (asynccallbackinfo) {
|
||||
delete asynccallbackinfo;
|
||||
asynccallbackinfo = nullptr;
|
||||
}
|
||||
},
|
||||
(void *)asynccallbackinfo,
|
||||
&asynccallbackinfo->asyncWork);
|
||||
|
||||
NAPI_CALL(env, napi_queue_async_work(env, asynccallbackinfo->asyncWork));
|
||||
|
||||
if (asynccallbackinfo->isCallback) {
|
||||
return Common::NapiGetNull(env);
|
||||
} else {
|
||||
return promise;
|
||||
}
|
||||
}
|
||||
napi_value RemoveSlot(napi_env env, napi_callback_info info)
|
||||
{
|
||||
ANS_LOGI("RemoveSlot start");
|
||||
|
||||
size_t argc = REMOVE_SLOT_MAX_PARA;
|
||||
napi_value argv[REMOVE_SLOT_MAX_PARA];
|
||||
napi_value thisVar = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL));
|
||||
NAPI_ASSERT(env, argc >= 1, "Wrong number of arguments");
|
||||
napi_ref callback = nullptr;
|
||||
|
||||
enum NotificationConstant::SlotType outType;
|
||||
if (ParseParametersByRemoveSlot(env, argv, argc, outType, callback) == nullptr) {
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
|
||||
AsyncCallbackInfoRemoveSlot *asynccallbackinfo =
|
||||
new AsyncCallbackInfoRemoveSlot{.env = env, .asyncWork = nullptr, .outType = outType};
|
||||
|
||||
napi_value promise = 0;
|
||||
PaddingAsyncCallbackInfoIsByRemoveSlot(env, asynccallbackinfo, callback, promise);
|
||||
|
||||
napi_value resourceName;
|
||||
napi_create_string_latin1(env, "removeSlot", NAPI_AUTO_LENGTH, &resourceName);
|
||||
// Asynchronous function call
|
||||
napi_create_async_work(env,
|
||||
nullptr,
|
||||
resourceName,
|
||||
[](napi_env env, void *data) {
|
||||
ANS_LOGI("removeSlot napi_create_async_work start");
|
||||
AsyncCallbackInfoRemoveSlot *asynccallbackinfo = (AsyncCallbackInfoRemoveSlot *)data;
|
||||
asynccallbackinfo->errorCode = NotificationHelper::RemoveNotificationSlot(asynccallbackinfo->outType);
|
||||
},
|
||||
[](napi_env env, napi_status status, void *data) {
|
||||
ANS_LOGI("removeSlot napi_create_async_work end");
|
||||
AsyncCallbackInfoRemoveSlot *asynccallbackinfo = (AsyncCallbackInfoRemoveSlot *)data;
|
||||
|
||||
CallbackPromiseInfo info;
|
||||
info.isCallback = asynccallbackinfo->isCallback;
|
||||
info.callback = asynccallbackinfo->callback;
|
||||
info.deferred = asynccallbackinfo->deferred;
|
||||
info.errorCode = asynccallbackinfo->errorCode;
|
||||
Common::ReturnCallbackPromise(env, info, Common::NapiGetNull(env));
|
||||
|
||||
napi_delete_async_work(env, asynccallbackinfo->asyncWork);
|
||||
if (asynccallbackinfo) {
|
||||
delete asynccallbackinfo;
|
||||
asynccallbackinfo = nullptr;
|
||||
}
|
||||
},
|
||||
(void *)asynccallbackinfo,
|
||||
&asynccallbackinfo->asyncWork);
|
||||
|
||||
NAPI_CALL(env, napi_queue_async_work(env, asynccallbackinfo->asyncWork));
|
||||
|
||||
if (asynccallbackinfo->isCallback) {
|
||||
return Common::NapiGetNull(env);
|
||||
} else {
|
||||
return promise;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace NotificationNapi
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* 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 "subscribe.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace NotificationNapi {
|
||||
napi_value ParseParameters(const napi_env &env, const napi_value (&argv)[SUBSRIBE_MAX_PARA], const size_t &argc,
|
||||
NotificationSubscriberInfo &subscriberInfo, SubscriberInstance *&objectInfo, napi_ref &callback)
|
||||
{
|
||||
napi_valuetype valuetype;
|
||||
|
||||
// argv[0]:Subscriber
|
||||
NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype));
|
||||
NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type for arg0. Subscribe expected.");
|
||||
|
||||
napi_unwrap(env, argv[0], (void **)&objectInfo);
|
||||
if (!objectInfo) {
|
||||
ANS_LOGE("ParseParameters subscriberInstance is null");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ANS_LOGI("ParseParameters subscriberInstance = %{public}p start", objectInfo);
|
||||
|
||||
if (!HasNotificationSubscriber(objectInfo)) {
|
||||
return nullptr;
|
||||
}
|
||||
ANS_LOGI("================ParseParameters 1111111111111111111111=================");
|
||||
// argv[1]:callback/NotificationSubscriberInfo
|
||||
if (argc >= 2) {
|
||||
NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype));
|
||||
if (valuetype == napi_function) {
|
||||
napi_create_reference(env, argv[1], 1, &callback);
|
||||
} else if (valuetype == napi_object) {
|
||||
if (Common::GetNotificationSubscriberInfo(env, argv[1], subscriberInfo) == nullptr) {
|
||||
ANS_LOGE("ParseParameters SubscriberInfo parse failed");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
ANS_LOGI("================ParseParameters 22222222222222222222222222=================");
|
||||
// argv[2]:callback
|
||||
if (argc >= SUBSRIBE_MAX_PARA) {
|
||||
NAPI_CALL(env, napi_typeof(env, argv[2], &valuetype));
|
||||
NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected.");
|
||||
ANS_LOGI("================ParseParameters 33333333333333333333333=================");
|
||||
napi_create_reference(env, argv[2], 1, &callback);
|
||||
}
|
||||
ANS_LOGI("================ParseParameters 444444444444444444444444444=================");
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
|
||||
void PaddingAsyncCallbackInfoIs(
|
||||
const napi_env &env, AsyncCallbackInfoSubscribe *&asynccallbackinfo, const napi_ref &callback, napi_value &promise)
|
||||
{
|
||||
ANS_LOGI("PaddingAsyncCallbackInfoIs start");
|
||||
|
||||
if (callback) {
|
||||
asynccallbackinfo->callback = callback;
|
||||
asynccallbackinfo->isCallback = true;
|
||||
} else {
|
||||
napi_deferred deferred = nullptr;
|
||||
NAPI_CALL_RETURN_VOID(env, napi_create_promise(env, &deferred, &promise));
|
||||
asynccallbackinfo->deferred = deferred;
|
||||
asynccallbackinfo->isCallback = false;
|
||||
}
|
||||
}
|
||||
|
||||
napi_value Subscribe(napi_env env, napi_callback_info info)
|
||||
{
|
||||
ANS_LOGI("Subscribe start");
|
||||
|
||||
size_t argc = SUBSRIBE_MAX_PARA;
|
||||
napi_value argv[SUBSRIBE_MAX_PARA];
|
||||
napi_value thisVar = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL));
|
||||
NAPI_ASSERT(env, argc >= 1, "Wrong number of arguments");
|
||||
napi_ref callback = nullptr;
|
||||
|
||||
SubscriberInstance *objectInfo = nullptr;
|
||||
NotificationSubscriberInfo subscriberInfo;
|
||||
if (ParseParameters(env, argv, argc, subscriberInfo, objectInfo, callback) == nullptr) {
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
ANS_LOGI("Subscribe objectInfo = %{public}p", objectInfo);
|
||||
|
||||
AsyncCallbackInfoSubscribe *asynccallbackinfo = new AsyncCallbackInfoSubscribe{
|
||||
.env = env, .asyncWork = nullptr, .objectInfo = objectInfo, .subscriberInfo = subscriberInfo};
|
||||
|
||||
napi_value promise = 0;
|
||||
PaddingAsyncCallbackInfoIs(env, asynccallbackinfo, callback, promise);
|
||||
|
||||
napi_value resourceName;
|
||||
napi_create_string_latin1(env, "subscribeNotification", NAPI_AUTO_LENGTH, &resourceName);
|
||||
// Asynchronous function call
|
||||
napi_create_async_work(env,
|
||||
nullptr,
|
||||
resourceName,
|
||||
[](napi_env env, void *data) {
|
||||
ANS_LOGI("Subscribe napi_create_async_work start");
|
||||
AsyncCallbackInfoSubscribe *asynccallbackinfo = (AsyncCallbackInfoSubscribe *)data;
|
||||
if (asynccallbackinfo->subscriberInfo.hasSubscriberInfo) {
|
||||
ANS_LOGI("Subscribe There are NotificationSubscribeInfo");
|
||||
NotificationSubscribeInfo subscribeInfo;
|
||||
subscribeInfo.AddAppNames(asynccallbackinfo->subscriberInfo.bundleNames);
|
||||
asynccallbackinfo->errorCode =
|
||||
NotificationHelper::SubscribeNotification(*(asynccallbackinfo->objectInfo), subscribeInfo);
|
||||
} else {
|
||||
asynccallbackinfo->errorCode =
|
||||
NotificationHelper::SubscribeNotification(*(asynccallbackinfo->objectInfo));
|
||||
}
|
||||
},
|
||||
[](napi_env env, napi_status status, void *data) {
|
||||
ANS_LOGI("Subscribe napi_create_async_work end");
|
||||
AsyncCallbackInfoSubscribe *asynccallbackinfo = (AsyncCallbackInfoSubscribe *)data;
|
||||
|
||||
CallbackPromiseInfo info;
|
||||
info.isCallback = asynccallbackinfo->isCallback;
|
||||
info.callback = asynccallbackinfo->callback;
|
||||
info.deferred = asynccallbackinfo->deferred;
|
||||
info.errorCode = asynccallbackinfo->errorCode;
|
||||
Common::ReturnCallbackPromise(env, info, Common::NapiGetNull(env));
|
||||
|
||||
napi_delete_async_work(env, asynccallbackinfo->asyncWork);
|
||||
if (asynccallbackinfo) {
|
||||
delete asynccallbackinfo;
|
||||
asynccallbackinfo = nullptr;
|
||||
}
|
||||
},
|
||||
(void *)asynccallbackinfo,
|
||||
&asynccallbackinfo->asyncWork);
|
||||
|
||||
NAPI_CALL(env, napi_queue_async_work(env, asynccallbackinfo->asyncWork));
|
||||
|
||||
if (asynccallbackinfo->isCallback) {
|
||||
return Common::NapiGetNull(env);
|
||||
} else {
|
||||
return promise;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace NotificationNapi
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* 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 "unsubscribe.h"
|
||||
#include "create_subscriber.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace NotificationNapi {
|
||||
napi_value ParseParameters(const napi_env &env, const size_t &argc, const napi_value (&argv)[UNSUBSCRIBE_MAX_PARA],
|
||||
SubscriberInstance *&objectInfo, napi_ref &callback)
|
||||
{
|
||||
ANS_LOGI("ParseParameters start");
|
||||
|
||||
napi_valuetype valuetype;
|
||||
// argv[0]:subscriber
|
||||
NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype));
|
||||
NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type for arg0. Subscribe expected.");
|
||||
|
||||
napi_unwrap(env, argv[0], (void **)&objectInfo);
|
||||
if (!objectInfo) {
|
||||
ANS_LOGE("ParseParameters objectInfo is null");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ANS_LOGI("ParseParameters objectInfo = %{public}p start", objectInfo);
|
||||
|
||||
if (!HasNotificationSubscriber(objectInfo)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// argv[1]:callback
|
||||
if (argc >= UNSUBSCRIBE_MAX_PARA) {
|
||||
NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype));
|
||||
NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected.");
|
||||
napi_create_reference(env, argv[1], 1, &callback);
|
||||
}
|
||||
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
|
||||
void PaddingAsyncCallbackInfoIs(const napi_env &env, const size_t &argc,
|
||||
AsyncCallbackInfoUnsubscribe *&asynccallbackinfo, const napi_ref &callback, napi_value &promise)
|
||||
{
|
||||
ANS_LOGI("PaddingAsyncCallbackInfoIs start");
|
||||
|
||||
if (argc >= UNSUBSCRIBE_MAX_PARA) {
|
||||
asynccallbackinfo->callback = callback;
|
||||
asynccallbackinfo->isCallback = true;
|
||||
} else {
|
||||
napi_deferred deferred = nullptr;
|
||||
NAPI_CALL_RETURN_VOID(env, napi_create_promise(env, &deferred, &promise));
|
||||
asynccallbackinfo->deferred = deferred;
|
||||
asynccallbackinfo->isCallback = false;
|
||||
}
|
||||
}
|
||||
|
||||
napi_value Unsubscribe(napi_env env, napi_callback_info info)
|
||||
{
|
||||
ANS_LOGI("Unsubscribe start");
|
||||
|
||||
// Argument parsing
|
||||
size_t argc = UNSUBSCRIBE_MAX_PARA;
|
||||
napi_value argv[UNSUBSCRIBE_MAX_PARA];
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL));
|
||||
NAPI_ASSERT(env, argc >= 1, "Wrong number of arguments");
|
||||
|
||||
napi_ref callback = 0;
|
||||
SubscriberInstance *subscriberInstance = nullptr;
|
||||
if (ParseParameters(env, argc, argv, subscriberInstance, callback) == nullptr) {
|
||||
return Common::NapiGetNull(env);
|
||||
}
|
||||
|
||||
AsyncCallbackInfoUnsubscribe *asynccallbackinfo =
|
||||
new AsyncCallbackInfoUnsubscribe{.env = env, .asyncWork = nullptr, .objectInfo = subscriberInstance};
|
||||
|
||||
napi_value promise = 0;
|
||||
PaddingAsyncCallbackInfoIs(env, argc, asynccallbackinfo, callback, promise);
|
||||
|
||||
napi_value resourceName;
|
||||
napi_create_string_latin1(env, "Unsubscribe", NAPI_AUTO_LENGTH, &resourceName);
|
||||
|
||||
// Asynchronous function call
|
||||
napi_create_async_work(env,
|
||||
nullptr,
|
||||
resourceName,
|
||||
[](napi_env env, void *data) {
|
||||
ANS_LOGI("Unsubscribe napi_create_async_work start");
|
||||
AsyncCallbackInfoUnsubscribe *asynccallbackinfo = (AsyncCallbackInfoUnsubscribe *)data;
|
||||
|
||||
asynccallbackinfo->errorCode =
|
||||
NotificationHelper::UnSubscribeNotification(*(asynccallbackinfo->objectInfo));
|
||||
},
|
||||
[](napi_env env, napi_status status, void *data) {
|
||||
ANS_LOGI("Unsubscribe napi_create_async_work end");
|
||||
AsyncCallbackInfoUnsubscribe *asynccallbackinfo = (AsyncCallbackInfoUnsubscribe *)data;
|
||||
|
||||
CallbackPromiseInfo info;
|
||||
info.isCallback = asynccallbackinfo->isCallback;
|
||||
info.callback = asynccallbackinfo->callback;
|
||||
info.deferred = asynccallbackinfo->deferred;
|
||||
info.errorCode = asynccallbackinfo->errorCode;
|
||||
Common::ReturnCallbackPromise(env, info, Common::NapiGetNull(env));
|
||||
|
||||
DelAsyncCallbackInfoOn(asynccallbackinfo->objectInfo);
|
||||
|
||||
napi_delete_async_work(env, asynccallbackinfo->asyncWork);
|
||||
if (asynccallbackinfo) {
|
||||
delete asynccallbackinfo;
|
||||
asynccallbackinfo = nullptr;
|
||||
}
|
||||
},
|
||||
(void *)asynccallbackinfo,
|
||||
&asynccallbackinfo->asyncWork);
|
||||
|
||||
NAPI_CALL(env, napi_queue_async_work(env, asynccallbackinfo->asyncWork));
|
||||
|
||||
if (asynccallbackinfo->isCallback) {
|
||||
return Common::NapiGetNull(env);
|
||||
} else {
|
||||
return promise;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace NotificationNapi
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,96 @@
|
||||
# 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/notification/ans_standard/notification.gni")
|
||||
import("//build/ohos.gni")
|
||||
|
||||
group("native_targets") {
|
||||
deps = [ ":ans_kits" ]
|
||||
}
|
||||
|
||||
config("ans_kits_config") {
|
||||
include_dirs = [ "${kits_path}/native/include" ]
|
||||
configs = [ "${innerkits_path}:public_ans_innerkits_config" ]
|
||||
}
|
||||
|
||||
config("ans_kit_public_config") {
|
||||
visibility = [ ":*" ]
|
||||
|
||||
include_dirs = [
|
||||
"${kits_path}/native/include",
|
||||
"${innerkits_path}/core/include",
|
||||
"${innerkits_path}/base/include",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_shared_library("ans_kits") {
|
||||
include_dirs = [
|
||||
"${kits_path}/native/include",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content",
|
||||
"//utils/system/safwk/native/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"${innerkits_path}/base/src/ans_log_wrapper.cpp",
|
||||
"src/message_user.cpp",
|
||||
"src/notification.cpp",
|
||||
"src/notification_action_button.cpp",
|
||||
"src/notification_basic_content.cpp",
|
||||
"src/notification_constant.cpp",
|
||||
"src/notification_content.cpp",
|
||||
"src/notification_conversational_content.cpp",
|
||||
"src/notification_conversational_message.cpp",
|
||||
"src/notification_helper.cpp",
|
||||
"src/notification_long_text_content.cpp",
|
||||
"src/notification_media_content.cpp",
|
||||
"src/notification_multiline_content.cpp",
|
||||
"src/notification_normal_content.cpp",
|
||||
"src/notification_picture_content.cpp",
|
||||
"src/notification_request.cpp",
|
||||
"src/notification_slot.cpp",
|
||||
"src/notification_slot_group.cpp",
|
||||
"src/notification_sorting.cpp",
|
||||
"src/notification_sorting_map.cpp",
|
||||
"src/notification_subscribe_info.cpp",
|
||||
"src/notification_subscriber.cpp",
|
||||
"src/notification_user_input.cpp",
|
||||
]
|
||||
|
||||
configs = [
|
||||
"//utils/native/base:utils_config",
|
||||
"${innerkits_path}:public_ans_innerkits_config",
|
||||
]
|
||||
|
||||
public_configs = [ ":ans_kit_public_config" ]
|
||||
|
||||
deps = [
|
||||
"${innerkits_path}:ans_innerkits",
|
||||
"${kits_path}/native/wantagent:wantagent_kits",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/want:want",
|
||||
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"samgr_L2:samgr_proxy",
|
||||
]
|
||||
|
||||
if (is_double_framework) {
|
||||
cflags = [ "-DCONFIG_DUAL_FRAMEWORK" ]
|
||||
}
|
||||
|
||||
subsystem_name = "notification"
|
||||
part_name = "ans_standard"
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* 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_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_MESSAGE_USER_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_MESSAGE_USER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "parcel.h"
|
||||
#include "uri.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
class PixelMap;
|
||||
class MessageUser final : public Parcelable {
|
||||
public:
|
||||
/**
|
||||
* A constructor used to construct MessageUser
|
||||
*/
|
||||
MessageUser();
|
||||
|
||||
/**
|
||||
* Default deconstructor used to deconstruct.
|
||||
*/
|
||||
~MessageUser();
|
||||
|
||||
/**
|
||||
* Sets the key used to uniquely identify this MessageUser.
|
||||
* @note Sets the key used to uniquely identify this MessageUser.
|
||||
* If no key is set, the name set by SetName(string) is used to uniquely identify a MessageUser.
|
||||
* @param key Indicates the key to set.
|
||||
*/
|
||||
void SetKey(const std::string &key);
|
||||
|
||||
/**
|
||||
* Obtains the key of this MessageUser.
|
||||
*
|
||||
* @return Returns the key of this MessageUser.
|
||||
*/
|
||||
std::string GetKey() const;
|
||||
|
||||
/**
|
||||
* Sets the name of this MessageUser.
|
||||
* @name Indicates the name to set.
|
||||
*/
|
||||
void SetName(const std::string &name);
|
||||
|
||||
/**
|
||||
* Obtains the name of this MessageUser.
|
||||
*
|
||||
* @return Returns the name of this MessageUser.
|
||||
*/
|
||||
std::string GetName() const;
|
||||
|
||||
/**
|
||||
* Sets the pixel map of this MessageUser.
|
||||
* @param pixelMap Indicates the pixel map to set.
|
||||
*/
|
||||
void SetPixelMap(const std::shared_ptr<PixelMap> &pixelMap);
|
||||
|
||||
/**
|
||||
* Obtains the pixel map of this MessageUser.
|
||||
*
|
||||
* @return Returns the pixel map of this MessageUser.
|
||||
*/
|
||||
const std::shared_ptr<PixelMap> GetPixelMap() const;
|
||||
|
||||
/**
|
||||
* Sets the URI of this MessageUser.
|
||||
* @param uri Indicates the URI to set.
|
||||
*/
|
||||
void SetUri(const Uri &uri);
|
||||
|
||||
/**
|
||||
* Obtains the URI of this MessageUser.
|
||||
*
|
||||
* @return Returns the URI of this MessageUser.
|
||||
*/
|
||||
Uri GetUri() const;
|
||||
|
||||
/**
|
||||
* Sets whether this MessageUser is a machine.
|
||||
* @param machine Specifies whether this MessageUser is a machine.
|
||||
* The value true indicates that it is, and the value false indicates not.
|
||||
*/
|
||||
void SetMachine(bool machine);
|
||||
|
||||
/**
|
||||
* Checks whether this MessageUser is a machine.
|
||||
*
|
||||
* @return Returns true if this MessageUser is a machine; returns false otherwise.
|
||||
*/
|
||||
bool IsMachine() const;
|
||||
|
||||
/**
|
||||
* Sets whether this MessageUser is important.
|
||||
* @note This method can be used to denote users who frequently interact with the user of this device.
|
||||
* @param userImportant Specifies whether this MessageUser is important.
|
||||
* The value true indicates that it is important, and the value false indicates not.
|
||||
*/
|
||||
void SetUserAsImportant(bool userImportant);
|
||||
|
||||
/**
|
||||
* Checks whether this MessageUser is important.
|
||||
*
|
||||
* @return Returns true if this MessageUser is important; returns false otherwise.
|
||||
*/
|
||||
bool IsUserImportant() const;
|
||||
|
||||
/**
|
||||
* Dumps a string representation of the object.
|
||||
*
|
||||
* @return A string representation of the object.
|
||||
*/
|
||||
std::string Dump() const;
|
||||
|
||||
/**
|
||||
* Marshals a MessageUser object into a Parcel.
|
||||
*
|
||||
* @param parcel Indicates the Parcel object for marshalling.
|
||||
* @return Returns true if the marshalling is successful; returns false otherwise.
|
||||
*/
|
||||
bool Marshalling(Parcel &parcel) const override;
|
||||
|
||||
/**
|
||||
* Unmarshals a MessageUser object from a Parcel.
|
||||
*
|
||||
* @param parcel Indicates the Parcel object for unmarshalling.
|
||||
* @return Returns true if the unmarshalling is successful; returns false otherwise.
|
||||
*/
|
||||
static MessageUser *Unmarshalling(Parcel &parcel);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Read NotificationSlot object from a Parcel.
|
||||
*
|
||||
* @param parcel the parcel
|
||||
* @return read from parcel success or fail
|
||||
*/
|
||||
bool ReadFromParcel(Parcel &parcel);
|
||||
|
||||
private:
|
||||
std::string key_;
|
||||
std::string name_;
|
||||
std::shared_ptr<PixelMap> pixelMap_;
|
||||
Uri uri_;
|
||||
bool isMachine_;
|
||||
bool isUserImportant_;
|
||||
|
||||
// no object in parcel
|
||||
static constexpr int VALUE_NULL = -1;
|
||||
// object exist in parcel
|
||||
static constexpr int VALUE_OBJECT = 1;
|
||||
};
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_MESSAGE_USER_H
|
||||
@@ -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_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_H
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "notification_request.h"
|
||||
#include "parcel.h"
|
||||
#include "uri.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
|
||||
class Notification final : public Parcelable {
|
||||
public:
|
||||
/**
|
||||
* A constructor used to create a Notification instance by existing NotificationRequest object.
|
||||
*
|
||||
* @param request the existing NotificationRequest object.
|
||||
*/
|
||||
Notification(const sptr<NotificationRequest> &request);
|
||||
|
||||
/**
|
||||
* @brief A constructor used to create a Notification instance by copying parameters from an existing one.
|
||||
*
|
||||
* @param other Indicates the Notification object.
|
||||
*/
|
||||
Notification(const Notification &other);
|
||||
|
||||
/**
|
||||
* @brief Obtains whether to enable the notification light when a notification is received on the device, provided
|
||||
* that this device has a notification light.
|
||||
*
|
||||
* @return Return true if led light color is set.
|
||||
*/
|
||||
bool EnableLight() const;
|
||||
|
||||
/**
|
||||
* @brief Obtains the sound enabled or not, set by ANS.
|
||||
*
|
||||
* @return Return true if sound is set.
|
||||
*/
|
||||
bool EnableSound() const;
|
||||
|
||||
/**
|
||||
* @brief Obtains the vibrate enabled or not, set by ANS.
|
||||
*
|
||||
* @return Return true if vibrate style is set.
|
||||
*/
|
||||
bool EnableVibrate() const;
|
||||
|
||||
/**
|
||||
* @brief Obtains the bundle's name which publish this notification.
|
||||
*
|
||||
* @return Return the bundle's name.
|
||||
*/
|
||||
std::string GetBundleName() const;
|
||||
|
||||
/**
|
||||
* @brief Obtains the bundle's name which create this notification.
|
||||
*
|
||||
* @return Return the creator bundle name.
|
||||
*/
|
||||
std::string GetCreateBundle() const;
|
||||
|
||||
/**
|
||||
* @brief Obtains the label of this notification.
|
||||
*
|
||||
* @return Return the label.
|
||||
*/
|
||||
std::string GetLabel() const;
|
||||
|
||||
/**
|
||||
* @brief Obtains the color of the notification light in a NotificationSlot object
|
||||
*
|
||||
* @return Returns the color of the notification light.
|
||||
*/
|
||||
int32_t GetLedLightColor() const;
|
||||
/**
|
||||
* @brief Sets the notification display effect, including whether to display this notification on the lock screen,
|
||||
* and how it will be presented if displayed.
|
||||
*
|
||||
* @return Return the display effect of this notification on the lock screen.
|
||||
*/
|
||||
int32_t GetLockscreenVisibleness() const;
|
||||
|
||||
/**
|
||||
* @brief The ID passed to setGroup(), or the override, or null.
|
||||
*
|
||||
* @return string of group.
|
||||
*/
|
||||
std::string GetGroup() const;
|
||||
|
||||
/**
|
||||
* @brief Obtains the id of the notification.
|
||||
*
|
||||
* @return The id supplied to NotificationManager::Notify(int, NotificationRequest).
|
||||
*/
|
||||
int32_t GetId() const;
|
||||
|
||||
/**
|
||||
* @brief A key for this notification record.
|
||||
*
|
||||
* @return A unique instance key.
|
||||
*/
|
||||
std::string GetKey() const;
|
||||
|
||||
/**
|
||||
* @brief Obtains the notificanton request set by ANS.
|
||||
*
|
||||
* @return Return sptr<NotificationRequest>.
|
||||
*/
|
||||
NotificationRequest GetNotificationRequest() const;
|
||||
|
||||
/**
|
||||
* @brief Obtains the time notification was posted.
|
||||
*
|
||||
* @return The time notificationRequest was posted.
|
||||
*/
|
||||
int64_t GetPostTime() const;
|
||||
|
||||
/**
|
||||
* @brief Obtains the sound uri.
|
||||
*
|
||||
* @return Return the sound set by ANS.
|
||||
*/
|
||||
Uri GetSound() const;
|
||||
|
||||
/**
|
||||
* @brief Obtains bundle's uid.
|
||||
*
|
||||
* @return Return the uid set by ANS.
|
||||
*/
|
||||
int32_t GetUid() const;
|
||||
|
||||
/**
|
||||
* @brief Obtains the vibration style for this notifications. if
|
||||
*
|
||||
* @return Return the vibration style.
|
||||
*/
|
||||
std::vector<int64_t> GetVibrationStyle() const;
|
||||
|
||||
/**
|
||||
* @brief This notification is part of a group or not.
|
||||
*
|
||||
* @return true if this notification is part of a group.
|
||||
*/
|
||||
bool IsGroup() const;
|
||||
|
||||
/**
|
||||
* @brief Dumps a string representation of the object.
|
||||
*
|
||||
* @return A string representation of the object.
|
||||
*/
|
||||
std::string Dump() const;
|
||||
|
||||
/**
|
||||
* @brief Marshals a Notification object into a Parcel.
|
||||
*
|
||||
* @param parcel Indicates the Parcel object for marshalling.
|
||||
*
|
||||
* @return Returns true if the marshalling is successful; returns false otherwise.
|
||||
*/
|
||||
bool Marshalling(Parcel &parcel) const;
|
||||
|
||||
/**
|
||||
* @brief Unmarshals a Notification object from a Parcel.
|
||||
*
|
||||
* @param Indicates the Parcel object for unmarshalling.
|
||||
*
|
||||
* @return Returns true if the unmarshalling is successful; returns false otherwise.
|
||||
*/
|
||||
static Notification *Unmarshalling(Parcel &parcel);
|
||||
|
||||
private:
|
||||
Notification();
|
||||
void SetLedLightColor(const int32_t &color);
|
||||
void SetLockScreenVisbleness(const int32_t &visbleness);
|
||||
void SetPostTime(const int64_t &time);
|
||||
void SetSound(const Uri &sound);
|
||||
void SetVibrationStyle(const std::vector<int64_t> &style);
|
||||
bool ReadFromParcel(Parcel &parcel);
|
||||
std::string GenerateNotificationKey(int32_t uid, const std::string &label, int32_t id);
|
||||
|
||||
private:
|
||||
std::string key_{""};
|
||||
int32_t ledLightColor_ = -1;
|
||||
int32_t lockscreenVisibleness_;
|
||||
sptr<NotificationRequest> request_ = nullptr;
|
||||
int64_t postTime_;
|
||||
std::shared_ptr<Uri> sound_ = nullptr;
|
||||
std::vector<int64_t> vibrationStyle_{};
|
||||
|
||||
friend class AdvancedNotificationService;
|
||||
friend class NotificationSlotFilter;
|
||||
friend class DisturbFilter;
|
||||
};
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -0,0 +1,212 @@
|
||||
/*
|
||||
* 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_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_ACTION_BUTTON_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_ACTION_BUTTON_H
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "notification_constant.h"
|
||||
#include "notification_user_input.h"
|
||||
#include "want_agent.h"
|
||||
#include "pac_map.h"
|
||||
#include "parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
class PixelMap;
|
||||
|
||||
class NotificationActionButton : public Parcelable {
|
||||
public:
|
||||
/**
|
||||
* A static function used to create a NotificationActionButton instance with the input parameters passed.
|
||||
* @param icon Indicates the icon to represent this NotificationActionButton.
|
||||
* @param title Indicates the title of this NotificationActionButton.
|
||||
* @param wantAgent Indicates the wantAgent to be triggered when this NotificationActionButton is triggered.
|
||||
* @param extras Indicates the PacMap object containing the additional data.
|
||||
* @param semanticActionButton Indicates the semantic action to add.
|
||||
* @param autoCreatedReplies Indicates whether to allow the platform to automatically generate possible replies.
|
||||
* @param userInputs Indicates the NotificationUserInput object to add.
|
||||
* @return the shared_ptr object owns the created NotificationActionButton object otherwise return empty object if
|
||||
* isContextual is true but icon or wantAgent is dempty.
|
||||
*/
|
||||
static std::shared_ptr<NotificationActionButton> Create(const std::shared_ptr<PixelMap> &icon,
|
||||
const std::string &title, const std::shared_ptr<WantAgent::WantAgent> &wantAgent,
|
||||
const std::shared_ptr<AppExecFwk::PacMap> &extras,
|
||||
NotificationConstant::SemanticActionButton semanticActionButton, bool autoCreatedReplies,
|
||||
const std::vector<std::shared_ptr<NotificationUserInput>> &userInputs, bool isContextual);
|
||||
|
||||
/**
|
||||
* Default deconstructor used to deconstruct.
|
||||
*/
|
||||
~NotificationActionButton() = default;
|
||||
|
||||
/**
|
||||
* Adds additional data to this Builder.
|
||||
* @param pacMap Indicates the PacMap object containing the additional data.
|
||||
*/
|
||||
void AddAdditionalData(AppExecFwk::PacMap &pacMap);
|
||||
|
||||
/**
|
||||
* Obtains the additional data included in this NotificationActionButton.
|
||||
* @return the additional data included in this NotificationActionButton.
|
||||
*/
|
||||
const std::shared_ptr<AppExecFwk::PacMap> GetAdditionalData() const;
|
||||
|
||||
/**
|
||||
* Obtains the icon of this NotificationActionButton.
|
||||
* @return the icon of this NotificationActionButton.
|
||||
*/
|
||||
const std::shared_ptr<PixelMap> GetIcon() const;
|
||||
|
||||
/**
|
||||
* Obtains the WantAgent of this NotificationActionButton.
|
||||
* @return the WantAgent of this NotificationActionButton.
|
||||
*/
|
||||
const std::shared_ptr<WantAgent::WantAgent> GetWantAgent() const;
|
||||
|
||||
/**
|
||||
* Obtains the NotificationUserInput objects that only allow values of particular MIME types
|
||||
* when this NotificationActionButton is sent.
|
||||
* @return the list of NotificationUserInput objects allowing only values of particular MIME types.
|
||||
*/
|
||||
std::vector<std::shared_ptr<NotificationUserInput>> GetMimeTypeOnlyUserInputs() const;
|
||||
|
||||
/**
|
||||
* Sets a semantic action for this NotificationActionButton.
|
||||
* @param semanticActionButton Indicates the semantic action to add.
|
||||
* For available values, see NotificationConstant::SemanticActionButton.
|
||||
*/
|
||||
void SetSemanticActionButton(NotificationConstant::SemanticActionButton semanticActionButton);
|
||||
|
||||
/**
|
||||
* Obtains the semantic action of this NotificationActionButton.
|
||||
* @return the semantic action of this NotificationActionButton,
|
||||
* as enumerated in NotificationConstant::SemanticActionButton.
|
||||
*/
|
||||
NotificationConstant::SemanticActionButton GetSemanticActionButton() const;
|
||||
|
||||
/**
|
||||
* Obtains the title of this NotificationActionButton.
|
||||
* @return the title of this NotificationActionButton.
|
||||
*/
|
||||
std::string GetTitle() const;
|
||||
|
||||
/**
|
||||
* Adds a NotificationUserInput object used to collect user input.
|
||||
* @param userInput Indicates the NotificationUserInput object to add.
|
||||
*/
|
||||
void AddNotificationUserInput(const std::shared_ptr<NotificationUserInput> &userInput);
|
||||
|
||||
/**
|
||||
* Obtains the NotificationUserInput objects to be collected from the user when this NotificationActionButton
|
||||
* is sent.
|
||||
* @return the list of NotificationUserInput objects.
|
||||
*/
|
||||
std::vector<std::shared_ptr<NotificationUserInput>> GetUserInputs() const;
|
||||
|
||||
/**
|
||||
* Sets whether to allow the platform to automatically generate possible replies and add them to
|
||||
* NotificationUserInput::getOptions().
|
||||
* @param autoCreatedReplies Specifies whether to allow the platform to automatically generate possible replies.
|
||||
* The value true means to allow generated replies; and the value false means not.
|
||||
*/
|
||||
void SetAutoCreatedReplies(bool autoCreatedReplies);
|
||||
|
||||
/**
|
||||
* Checks whether the platform can automatically generate possible replies for this NotificationActionButton.
|
||||
* @return true if the platform can generate replies; returns false otherwise.
|
||||
*/
|
||||
bool IsAutoCreatedReplies() const;
|
||||
|
||||
/**
|
||||
* Sets whether this NotificationActionButton is a contextual action, that is, whether this
|
||||
* NotificationActionButton is dependent on the notification message body. For example, a contextual
|
||||
* NotificationActionButton provides an address in the notification for users to open a map application.
|
||||
* @param isContextual Specifies whether this NotificationActionButton is a contextual action.
|
||||
* The value true indicates a contextual action, and the value false indicates not.
|
||||
*/
|
||||
void SetContextDependent(bool isContextual);
|
||||
|
||||
/**
|
||||
* Checks whether this NotificationActionButton is a contextual action, that is, whether this
|
||||
* NotificationActionButton is dependent on the notification message body. For example, a contextual
|
||||
* NotificationActionButton provides an address in the notification for users to open a map application.
|
||||
* @return true if this NotificationActionButton is a contextual action; returns false otherwise.
|
||||
*/
|
||||
bool IsContextDependent() const;
|
||||
|
||||
/**
|
||||
* Returns a string representation of the object.
|
||||
* @return a string representation of the object.
|
||||
*/
|
||||
std::string Dump();
|
||||
|
||||
/**
|
||||
* Marshal a object into a Parcel.
|
||||
* @param parcel the object into the parcel
|
||||
*/
|
||||
virtual bool Marshalling(Parcel &parcel) const override;
|
||||
|
||||
/**
|
||||
* Unmarshal object from a Parcel.
|
||||
* @return the NotificationActionButton
|
||||
*/
|
||||
static NotificationActionButton *Unmarshalling(Parcel &parcel);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Default constructor used to create a NotificationActionButton instance.
|
||||
*/
|
||||
NotificationActionButton() = default;
|
||||
|
||||
/**
|
||||
* A constructor used to create a NotificationActionButton instance with the input parameters passed.
|
||||
* @param icon Indicates the icon to represent this NotificationActionButton.
|
||||
* @param title Indicates the title of this NotificationActionButton.
|
||||
* @param wantAgent Indicates the WantAgent to be triggered when this NotificationActionButton is triggered.
|
||||
* @param extras Indicates the PacMap object containing the additional data.
|
||||
* @param semanticActionButton Indicates the semantic action to add.
|
||||
* @param autoCreatedReplies Indicates whether to allow the platform to automatically generate possible replies.
|
||||
* @param userInputs Indicates the NotificationUserInput object to add.
|
||||
* @param isContextual Indicates whether this NotificationActionButton is a contextual action.
|
||||
*/
|
||||
NotificationActionButton(const std::shared_ptr<PixelMap> &icon, const std::string &title,
|
||||
const std::shared_ptr<WantAgent::WantAgent> &wantAgent, const std::shared_ptr<AppExecFwk::PacMap> &extras,
|
||||
NotificationConstant::SemanticActionButton semanticActionButton, bool autoCreatedReplies,
|
||||
const std::vector<std::shared_ptr<NotificationUserInput>> &userInputs, bool isContextual);
|
||||
|
||||
/**
|
||||
* Read a NotificationActionButton object from a Parcel.
|
||||
* @param parcel the parcel
|
||||
*/
|
||||
bool ReadFromParcel(Parcel &parcel);
|
||||
|
||||
private:
|
||||
std::shared_ptr<PixelMap> icon_{};
|
||||
std::string title_{};
|
||||
std::shared_ptr<WantAgent::WantAgent> wantAgent_{};
|
||||
std::shared_ptr<AppExecFwk::PacMap> extras_{};
|
||||
NotificationConstant::SemanticActionButton semanticActionButton_{
|
||||
NotificationConstant::SemanticActionButton::NONE_ACTION_BUTTON};
|
||||
bool autoCreatedReplies_{true};
|
||||
std::vector<std::shared_ptr<NotificationUserInput>> userInputs_{};
|
||||
bool isContextual_{false};
|
||||
};
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_ACTION_BUTTON_H
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_BASIC_CONTENT_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_BASIC_CONTENT_H
|
||||
|
||||
#include <string>
|
||||
#include "parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
class NotificationBasicContent : public Parcelable {
|
||||
public:
|
||||
/**
|
||||
* Default deconstructor used to deconstruct.
|
||||
*/
|
||||
virtual ~NotificationBasicContent();
|
||||
|
||||
/**
|
||||
* Sets the additional text to be included in a notification.
|
||||
* The additional text is mainly a supplement to the notification text set by calling setText(std::string).
|
||||
* The font of the additional text is smaller than the notification text and is displayed in a separate line.
|
||||
* @param text Indicates the additional text to be included.
|
||||
*/
|
||||
virtual void SetAdditionalText(const std::string &additionalText);
|
||||
|
||||
/**
|
||||
* Obtains the additional text of a notification specified by calling setAdditionalText(std::string).
|
||||
* @return the additional text of the notification.
|
||||
*/
|
||||
virtual std::string GetAdditionalText() const;
|
||||
|
||||
/**
|
||||
* Sets the text to be included in a notification.
|
||||
* @param text Indicates the text to be included.
|
||||
*/
|
||||
virtual void SetText(const std::string &text);
|
||||
|
||||
/**
|
||||
* Obtains the text of a notification specified by calling setText(std::string).
|
||||
* @return the text of the notification.
|
||||
*/
|
||||
virtual std::string GetText() const;
|
||||
|
||||
/**
|
||||
* Sets the title of a notification.
|
||||
* @param title Indicates the title of the notification.
|
||||
*/
|
||||
virtual void SetTitle(const std::string &title);
|
||||
|
||||
/**
|
||||
* Obtains the title of a notification specified by calling the setTitle(std::string) method.
|
||||
* @return the title of the notification.
|
||||
*/
|
||||
virtual std::string GetTitle() const;
|
||||
|
||||
/**
|
||||
* Returns a string representation of the object.
|
||||
* @return a string representation of the object.
|
||||
*/
|
||||
virtual std::string Dump();
|
||||
|
||||
/**
|
||||
* Marshal a object into a Parcel.
|
||||
* @param parcel the object into the parcel
|
||||
*/
|
||||
virtual bool Marshalling(Parcel &parcel) const override;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
NotificationBasicContent() = default;
|
||||
|
||||
/**
|
||||
* Read data from a Parcel.
|
||||
* @param parcel the parcel
|
||||
* @return true if read success; returns false otherwise.
|
||||
*/
|
||||
virtual bool ReadFromParcel(Parcel &parcel);
|
||||
|
||||
protected:
|
||||
std::string text_{};
|
||||
std::string title_{};
|
||||
std::string additionalText_{};
|
||||
};
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_BASIC_CONTENT_H
|
||||
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* 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_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_CONSTANT_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_CONSTANT_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
class NotificationConstant {
|
||||
public:
|
||||
enum DisturbMode {
|
||||
ALLOW_ALARMS, // Indicates that only notifications of the NotificationRequest::CLASSIFICATION_ALARM
|
||||
// category are allowed to interrupt the user in Do Not Disturb mode.
|
||||
ALLOW_ALL, // Indicates that all notifications are allowed to interrupt the user in Do Not Disturb mode.
|
||||
ALLOW_NONE, // Indicates that no notifications are allowed to interrupt the user in Do Not Disturb mode.
|
||||
ALLOW_PRIORITY, // Indicates that only notifications meeting the specified priority criteria are allowed
|
||||
// to interrupt the user in Do Not Disturb mode.
|
||||
ALLOW_UNKNOWN, // Indicates the value returned if the Do Not Disturb mode type cannot be obtained.
|
||||
};
|
||||
|
||||
enum InputEditType {
|
||||
EDIT_AUTO, // Indicates that the system determines whether to allow the user to edit the options before they
|
||||
// are sent to the application.
|
||||
EDIT_DISABLED, // Indicates that the user is not allowed to edit an option before the option is sent to the
|
||||
// application.
|
||||
EDIT_ENABLED, // Indicates that the user is allowed to edit an option before the option is sent to the
|
||||
// application.
|
||||
};
|
||||
|
||||
enum InputsSource {
|
||||
FREE_FORM_INPUT, // Indicates that the user manually input the content.
|
||||
OPTION, // Indicates that the user selected one of the provided options.
|
||||
};
|
||||
|
||||
enum SemanticActionButton {
|
||||
ARCHIVE_ACTION_BUTTON, // Indicates the action of archiving the content associated with the notification.
|
||||
CALL_ACTION_BUTTON, // Indicates the action of making a call.
|
||||
DELETE_ACTION_BUTTON, // Indicates the action of deleting the content associated with the notification.
|
||||
MUTE_ACTION_BUTTON, // Indicates the action of muting the content associated with the notification.
|
||||
NONE_ACTION_BUTTON, // Indicates that no WantAgent is associated.
|
||||
READ_ACTION_BUTTON, // Indicates the action of marking the content as read.
|
||||
REPLY_ACTION_BUTTON, // Indicates the action of replying to a conversation.
|
||||
THUMBS_DOWN_ACTION_BUTTON, // Indicates the action of marking the content with a thumbs-down.
|
||||
THUMBS_UP_ACTION_BUTTON, // Indicates the action of marking the content with a thumbs-up.
|
||||
UNMUTE_ACTION_BUTTON, // Indicates the action of unmuting the content associated with the notification.
|
||||
UNREAD_ACTION_BUTTON, // Indicates the action of marking the content as unread.
|
||||
};
|
||||
|
||||
enum SubscribeResult : uint32_t {
|
||||
SUCCESS,
|
||||
PREMISSION_FAIL,
|
||||
RESOURCES_FAIL,
|
||||
};
|
||||
|
||||
enum SlotType {
|
||||
SOCIAL_COMMUNICATION, // the notification type is social communication
|
||||
SERVICE_REMINDER, // the notification type is service reminder
|
||||
CONTENT_INFORMATION, // the notificatin type is content information
|
||||
OTHER, // the notificatin type is other
|
||||
CUSTOM, // the notification type is custom
|
||||
};
|
||||
|
||||
enum class VisiblenessType {
|
||||
/**
|
||||
* the notification display effect has not been set by NotificationRequest::setVisibleness().
|
||||
* This method is usually not used.
|
||||
*/
|
||||
NO_OVERRIDE,
|
||||
/**
|
||||
* only the basic information, such as application icon and application name is displayed on the lock screen.
|
||||
*/
|
||||
PRIVATE,
|
||||
/**
|
||||
* contents of a notification are displayed on the lock screen.
|
||||
*/
|
||||
PUBLIC,
|
||||
/**
|
||||
* notifications are not displayed on the lock screen.
|
||||
*/
|
||||
SECRET
|
||||
};
|
||||
|
||||
/**
|
||||
* Indicates that a notification is deleted because it is clicked.
|
||||
*/
|
||||
static const int CLICK_REASON_DELETE = 1;
|
||||
|
||||
/**
|
||||
* Indicates that a notification is deleted because the user clears it.
|
||||
*/
|
||||
static const int CANCEL_REASON_DELETE = 2;
|
||||
|
||||
/**
|
||||
* Indicates that a notification is deleted because the user clears all notifications.
|
||||
*/
|
||||
static const int CANCEL_ALL_REASON_DELETE = 3;
|
||||
|
||||
/**
|
||||
* Indicates that a notification is deleted because of a UI error.
|
||||
*/
|
||||
static const int ERROR_REASON_DELETE = 4;
|
||||
|
||||
/**
|
||||
* Indicates that a notification is deleted because a change has been made to the application.
|
||||
*/
|
||||
static const int PACKAGE_CHANGED_REASON_DELETE = 5;
|
||||
|
||||
/**
|
||||
* Indicates that a notification is deleted because the application context is stopped.
|
||||
*/
|
||||
static const int USER_STOPPED_REASON_DELETE = 6;
|
||||
|
||||
/**
|
||||
* Indicates that a notification is deleted because the application is banned from sending notifications.
|
||||
*/
|
||||
static const int PACKAGE_BANNED_REASON_DELETE = 7;
|
||||
|
||||
/**
|
||||
* Indicates that a notification is deleted because the application cancels it.
|
||||
*/
|
||||
static const int APP_CANCEL_REASON_DELETE = 8;
|
||||
|
||||
/**
|
||||
* Indicates that a notification is deleted because the application cancels all notifications.
|
||||
*/
|
||||
static const int APP_CANCEL_ALL_REASON_DELETE = 9;
|
||||
|
||||
/**
|
||||
* Indicates that a notification is deleted for other reasons.
|
||||
*/
|
||||
static const int APP_CANCEL_REASON_OTHER = 10;
|
||||
|
||||
/**
|
||||
* The key indicates input source.
|
||||
*/
|
||||
static const std::string EXTRA_INPUTS_SOURCE;
|
||||
};
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_CONSTANT_H
|
||||
@@ -0,0 +1,182 @@
|
||||
/*
|
||||
* 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_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_CONTENT_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_CONTENT_H
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "notification_basic_content.h"
|
||||
#include "notification_normal_content.h"
|
||||
#include "notification_long_text_content.h"
|
||||
#include "notification_picture_content.h"
|
||||
#include "notification_conversational_content.h"
|
||||
#include "notification_multiline_content.h"
|
||||
#include "notification_media_content.h"
|
||||
#include "parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
class NotificationContent : public Parcelable {
|
||||
public:
|
||||
enum class Type {
|
||||
/**
|
||||
* invalid type
|
||||
*/
|
||||
NONE,
|
||||
/**
|
||||
* Indicates basic notifications. Such notifications are created using NotificationNormalContent.
|
||||
*/
|
||||
BASIC_TEXT,
|
||||
/**
|
||||
* Indicates notifications that include a conversation among multiple users.
|
||||
* Such notifications are created using NotificationConversationalContent.
|
||||
*/
|
||||
CONVERSATION,
|
||||
/**
|
||||
* Indicates notifications that include long text.
|
||||
* Such notifications are created using NotificationLongTextContent.
|
||||
*/
|
||||
LONG_TEXT,
|
||||
/**
|
||||
* Indicates notifications that include media playback sessions.
|
||||
* Such notifications are created using NotificationMediaContent.
|
||||
*/
|
||||
MEDIA,
|
||||
/**
|
||||
* Indicates notifications that include multiple independent lines of text.
|
||||
* Such notifications are created using NotificationMultiLineContent.
|
||||
*/
|
||||
MULTILINE,
|
||||
/**
|
||||
* Indicates notifications that include a picture.
|
||||
* Such notifications are created using NotificationPictureContent.
|
||||
*/
|
||||
PICTURE
|
||||
};
|
||||
|
||||
/**
|
||||
* A constructor used to create a NotificationNormalContent instance (obtained by calling GetNotificationContent())
|
||||
* and set the content type to NotificationContent::Type::BASIC_TEXT (obtained by calling GetContentType()).
|
||||
* @param normalContent Indicates the NotificationNormalContent object.
|
||||
*/
|
||||
explicit NotificationContent(const std::shared_ptr<NotificationNormalContent> &normalContent);
|
||||
|
||||
/**
|
||||
* A constructor used to create a NotificationLongTextContent instance (obtained by calling
|
||||
* GetNotificationContent()) and set the content type to NotificationContent::Type::LONG_TEXT (obtained by calling
|
||||
* GetContentType()).
|
||||
* @param longTextContent Indicates the NotificationLongTextContent object.
|
||||
*/
|
||||
explicit NotificationContent(const std::shared_ptr<NotificationLongTextContent> &longTextContent);
|
||||
|
||||
/**
|
||||
* A constructor used to create a NotificationPictureContent instance (obtained by calling GetNotificationContent())
|
||||
* and set the content type to NotificationContent::Type::PICTURE (obtained by calling GetContentType()).
|
||||
* @param pictureContent Indicates the NotificationPictureContent object.
|
||||
*/
|
||||
explicit NotificationContent(const std::shared_ptr<NotificationPictureContent> &pictureContent);
|
||||
|
||||
/**
|
||||
* A constructor used to create a NotificationConversationalContent instance
|
||||
* (obtained by calling GetNotificationContent()) and set the content type to
|
||||
* NotificationContent::Type::CONVERSATION (obtained by calling GetContentType()).
|
||||
* @param conversationContent Indicates the NotificationConversationalContent object.
|
||||
*/
|
||||
explicit NotificationContent(const std::shared_ptr<NotificationConversationalContent> &conversationContent);
|
||||
|
||||
/**
|
||||
* A constructor used to create a NotificationMultiLineContent instance
|
||||
* (obtained by calling GetNotificationContent()) and set the content type to
|
||||
* NotificationContent::Type::MULTILINE (obtained by calling GetContentType()).
|
||||
* @param multiLineContent Indicates the NotificationMultiLineContent object.
|
||||
*/
|
||||
explicit NotificationContent(const std::shared_ptr<NotificationMultiLineContent> &multiLineContent);
|
||||
|
||||
/**
|
||||
* A constructor used to create a NotificationMediaContent instance
|
||||
* (obtained by calling GetNotificationContent()) and set the content type to
|
||||
* NotificationContent::Type::MEDIA (obtained by calling GetContentType()).
|
||||
* @param mediaContent Indicates the NotificationMediaContent object.
|
||||
*/
|
||||
explicit NotificationContent(const std::shared_ptr<NotificationMediaContent> &mediaContent);
|
||||
|
||||
/**
|
||||
* Default deconstructor used to deconstruct.
|
||||
*/
|
||||
virtual ~NotificationContent();
|
||||
|
||||
/**
|
||||
* Obtains the type value of the notification content.
|
||||
* @return the type value of the current content, which can be
|
||||
* NotificationContent::Type::BASIC_TEXT,
|
||||
* NotificationContent::Type::LONG_TEXT,
|
||||
* NotificationContent::Type::PICTURE,
|
||||
* NotificationContent::Type::CONVERSATION,
|
||||
* NotificationContent::Type::MULTILINE, or
|
||||
* NotificationContent::Type::MEDIA.
|
||||
*/
|
||||
NotificationContent::Type GetContentType() const;
|
||||
|
||||
/**
|
||||
* Obtains the object matching the current notification content.
|
||||
* @return the content object, which can be NotificationLongTextContent,
|
||||
* NotificationNormalContent,
|
||||
* NotificationPictureContent,
|
||||
* NotificationConversationalContent,
|
||||
* NotificationMultiLineContent, or
|
||||
* NotificationMediaContent.
|
||||
*/
|
||||
std::shared_ptr<NotificationBasicContent> GetNotificationContent() const;
|
||||
|
||||
/**
|
||||
* Returns a string representation of the object.
|
||||
* @return a string representation of the object.
|
||||
*/
|
||||
std::string Dump();
|
||||
|
||||
/**
|
||||
* Marshal a object into a Parcel.
|
||||
* @param parcel the object into the parcel
|
||||
*/
|
||||
virtual bool Marshalling(Parcel &parcel) const override;
|
||||
|
||||
/**
|
||||
* Unmarshal object from a Parcel.
|
||||
* @return the NotificationContent
|
||||
*/
|
||||
static NotificationContent *Unmarshalling(Parcel &parcel);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Default constructor used to create an empty NotificationContent instance.
|
||||
*/
|
||||
NotificationContent() = default;
|
||||
|
||||
/**
|
||||
* Read data from a Parcel.
|
||||
* @param parcel the parcel
|
||||
* @return true if read success; returns false otherwise.
|
||||
*/
|
||||
bool ReadFromParcel(Parcel &parcel);
|
||||
|
||||
private:
|
||||
NotificationContent::Type contentType_{NotificationContent::Type::NONE};
|
||||
std::shared_ptr<NotificationBasicContent> content_{};
|
||||
};
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_CONTENT_H
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
#ifndef BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_CONVERSATIONAL_CONTENT_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_CONVERSATIONAL_CONTENT_H
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "message_user.h"
|
||||
#include "notification_basic_content.h"
|
||||
#include "notification_conversational_message.h"
|
||||
#include "parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
class NotificationConversationalContent : public NotificationBasicContent {
|
||||
public:
|
||||
using MessagePtr = std::shared_ptr<NotificationConversationalMessage>;
|
||||
using MessageVector = std::vector<MessagePtr>;
|
||||
|
||||
/**
|
||||
* A constructor used to create a NotificationConversationalContent instance with the MessageUser specified.
|
||||
* @param messageUser Indicates the MessageUser who sends all Message objects in this conversation-like
|
||||
* notification. This parameter cannot be null.
|
||||
*/
|
||||
NotificationConversationalContent(const MessageUser &messageUser);
|
||||
|
||||
/**
|
||||
* Default deconstructor used to deconstruct.
|
||||
*/
|
||||
~NotificationConversationalContent() = default;
|
||||
|
||||
/**
|
||||
* Obtains the message sender to be displayed for any messages
|
||||
* sent by the user in this conversation-like notification.
|
||||
* @return the message sender.
|
||||
*/
|
||||
MessageUser GetMessageUser() const;
|
||||
|
||||
/**
|
||||
* Sets the title to be displayed for the conversation.
|
||||
* The title set in this method will overwrite the one set by calling setTitle(std::tring).
|
||||
* @param conversationTitle Indicates the title to be displayed for the conversation.
|
||||
*/
|
||||
void SetConversationTitle(const std::string &conversationTitle);
|
||||
|
||||
/**
|
||||
* Obtains the title to be displayed for the conversation.
|
||||
* @return the title to be displayed for the conversation.
|
||||
*/
|
||||
std::string GetConversationTitle() const;
|
||||
|
||||
/**
|
||||
* Checks whether this notification represents a group conversation.
|
||||
* @return true if this notification represents a group conversation; returns false otherwise.
|
||||
*/
|
||||
bool IsConversationGroup() const;
|
||||
|
||||
/**
|
||||
* Sets whether this notification represents a group conversation.
|
||||
* The big icon, if any, set for this notification by calling NotificationRequest::setBigIcon(PixelMap)
|
||||
* will be displayed only when this method is set to true.
|
||||
* @param isGroup Specifies whether this notification represents a group conversation.
|
||||
*/
|
||||
void SetConversationGroup(bool isGroup);
|
||||
|
||||
/**
|
||||
* Adds a message to this conversation-like notification based on
|
||||
* the specified message content, timestamp, and MessageUser.
|
||||
* All messages will be displayed in the order they are added.
|
||||
* @param text Indicates the text to be displayed as the message content.
|
||||
* @param timestamp Indicates the time when the message arrived.
|
||||
* @param sender Indicates the MessageUser who sent the message.
|
||||
*/
|
||||
void AddConversationalMessage(
|
||||
const std::string &text, int64_t timestamp, const MessageUser &sender);
|
||||
|
||||
/**
|
||||
* Adds a specified message to this conversation-like notification.
|
||||
* All messages will be displayed in the order they are added.
|
||||
* @param message Indicates the ConversationalMessage object to add.
|
||||
*/
|
||||
void AddConversationalMessage(const MessagePtr &message);
|
||||
|
||||
/**
|
||||
* Obtains all messages included in this conversation-like notification.
|
||||
* @return the list of all Message objects included.
|
||||
*/
|
||||
MessageVector GetAllConversationalMessages() const;
|
||||
|
||||
/**
|
||||
* Returns a string representation of the object.
|
||||
* @return a string representation of the object.
|
||||
*/
|
||||
std::string Dump() override;
|
||||
|
||||
/**
|
||||
* Marshal a object into a Parcel.
|
||||
* @param parcel the object into the parcel
|
||||
*/
|
||||
virtual bool Marshalling(Parcel &parcel) const override;
|
||||
|
||||
/**
|
||||
* Unmarshal object from a Parcel.
|
||||
* @return the NotificationConversationalContent
|
||||
*/
|
||||
static NotificationConversationalContent *Unmarshalling(Parcel &parcel);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Read a NotificationConversationalContent object from a Parcel.
|
||||
* @param parcel the parcel
|
||||
*/
|
||||
bool ReadFromParcel(Parcel &parcel) override;
|
||||
|
||||
private:
|
||||
/**
|
||||
* Default constructor used to create an empty NotificationConversationalContent instance.
|
||||
*/
|
||||
NotificationConversationalContent() = default;
|
||||
|
||||
private:
|
||||
MessageUser messageUser_{};
|
||||
std::string conversationTitle_{};
|
||||
bool isGroup_{false};
|
||||
MessageVector messages_{};
|
||||
};
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_CONVERSATIONAL_CONTENT_H
|
||||
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* 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_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_CONVERSATIONAL_MESSAGE_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_CONVERSATIONAL_MESSAGE_H
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "message_user.h"
|
||||
#include "parcel.h"
|
||||
#include "uri.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
class NotificationConversationalMessage : public Parcelable {
|
||||
public:
|
||||
/**
|
||||
* A constructor used to create a NotificationConversationalMessage instance with the input parameters passed.
|
||||
* @param text Indicates the text to be displayed as the message content. This parameter cannot be null.
|
||||
* @param timestamp Indicates the time when the message arrived.
|
||||
* @param sender Indicates the MessageUser who sent the message.
|
||||
*/
|
||||
NotificationConversationalMessage(
|
||||
const std::string &text, int64_t timestamp, const MessageUser &sender);
|
||||
|
||||
/**
|
||||
* Default deconstructor used to deconstruct.
|
||||
*/
|
||||
~NotificationConversationalMessage() = default;
|
||||
|
||||
/**
|
||||
* Obtains the text to be displayed as the content of this message.
|
||||
* @return the message content.
|
||||
*/
|
||||
std::string GetText() const;
|
||||
|
||||
/**
|
||||
* Obtains the time when this message arrived.
|
||||
* @return the time when this message arrived.
|
||||
*/
|
||||
int64_t GetArrivedTime() const;
|
||||
|
||||
/**
|
||||
* Obtains the sender of this message.
|
||||
* @return the message sender.
|
||||
*/
|
||||
MessageUser GetSender() const;
|
||||
|
||||
/**
|
||||
* Sets the MIME type and URI of this message.
|
||||
* @param mimeType Indicates the MIME type of this message.
|
||||
* @param uri Indicates the URI that points to the message content whose type is specified by the given MIME type.
|
||||
*/
|
||||
void SetData(const std::string &mimeType, const std::shared_ptr<Uri> &uri);
|
||||
|
||||
/**
|
||||
* Obtains the MIME type of this message.
|
||||
* @return the MIME type of this message.
|
||||
*/
|
||||
std::string GetMimeType() const;
|
||||
|
||||
/**
|
||||
* Obtains the URI of the message content with the specific MIME type.
|
||||
* @return the URI of the message content with the specific MIME type.
|
||||
*/
|
||||
const std::shared_ptr<Uri> GetUri() const;
|
||||
|
||||
/**
|
||||
* Returns a string representation of the object.
|
||||
* @return a string representation of the object.
|
||||
*/
|
||||
std::string Dump();
|
||||
|
||||
/**
|
||||
* Marshal a object into a Parcel.
|
||||
* @param parcel the object into the parcel
|
||||
*/
|
||||
virtual bool Marshalling(Parcel &parcel) const override;
|
||||
|
||||
/**
|
||||
* Unmarshal object from a Parcel.
|
||||
* @return the NotificationConversationalMessage
|
||||
*/
|
||||
static NotificationConversationalMessage *Unmarshalling(Parcel &parcel);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Default constructor used to create an empty NotificationConversationalMessage instance.
|
||||
*/
|
||||
NotificationConversationalMessage() = default;
|
||||
|
||||
/**
|
||||
* Read a NotificationConversationalMessage object from a Parcel.
|
||||
* @param parcel the parcel
|
||||
*/
|
||||
bool ReadFromParcel(Parcel &parcel);
|
||||
|
||||
private:
|
||||
int64_t arrivedTime_{0};
|
||||
std::string text_{};
|
||||
MessageUser sender_{};
|
||||
std::shared_ptr<Uri> uri_{};
|
||||
std::string mimeType_{};
|
||||
};
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_CONVERSATIONAL_MESSAGE_H
|
||||
@@ -0,0 +1,503 @@
|
||||
/*
|
||||
* 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_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_HELPER_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_HELPER_H
|
||||
|
||||
#include "notification_request.h"
|
||||
#include "notification_slot.h"
|
||||
#include "notification_slot_group.h"
|
||||
#include "notification_sorting_map.h"
|
||||
#include "notification_subscriber.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
class NotificationHelper {
|
||||
public:
|
||||
/**
|
||||
* Creates a notification slot.
|
||||
* @note You can call the NotificationRequest::SetSlotType(NotificationConstant::SlotType) method to bind the slot
|
||||
* for publishing. A NotificationSlot instance cannot be used directly after being initialized. Instead, you have to
|
||||
* call this method to create a notification slot and bind the slot ID to a NotificationRequest object so that the
|
||||
* notification published can have all the characteristics set in the NotificationSlot. After a notification slot is
|
||||
* created by using this method, only the name and description of the notification slot can be changed. Changes to
|
||||
* the other attributes, such as the vibration status and notification tone, will no longer take effect.
|
||||
*
|
||||
* @param slot Indicates the notification slot to be created, which is set by NotificationSlot.
|
||||
* This parameter must be specified.
|
||||
* @return Returns add notification slot result.
|
||||
*/
|
||||
static ErrCode AddNotificationSlot(const NotificationSlot &slot);
|
||||
|
||||
/**
|
||||
* Creates multiple notification slots.
|
||||
*
|
||||
* @param slots Indicates the notification slots to create.
|
||||
* @return Returns add notification slots result.
|
||||
*/
|
||||
static ErrCode AddNotificationSlots(const std::vector<NotificationSlot> &slots);
|
||||
|
||||
/**
|
||||
* Deletes a created notification slot based on the slot ID.
|
||||
*
|
||||
* @param slotType Indicates the type of the slot, which is created by AddNotificationSlot
|
||||
* This parameter must be specified.
|
||||
* @return Returns remove notification slot result.
|
||||
*/
|
||||
static ErrCode RemoveNotificationSlot(const NotificationConstant::SlotType &slotType);
|
||||
|
||||
/**
|
||||
* Queries a created notification slot.
|
||||
*
|
||||
* @param slotType Indicates the ID of the slot, which is created by AddNotificationSlot(NotificationSlot). This
|
||||
* parameter must be specified.
|
||||
* @param slot Indicates the created NotificationSlot.
|
||||
* @return Returns the get notification slot result.
|
||||
*/
|
||||
static ErrCode GetNotificationSlot(const NotificationConstant::SlotType &slotType, sptr<NotificationSlot> &slot);
|
||||
|
||||
/**
|
||||
* Obtains all notification slots of this application.
|
||||
* @param slots Indicates the created NotificationSlot.
|
||||
* @return Returns all notification slots of this application.
|
||||
*/
|
||||
static ErrCode GetNotificationSlots(std::vector<sptr<NotificationSlot>> &slots);
|
||||
|
||||
/**
|
||||
* Creates a notification slot group to which a NotificationSlot object can be bound by
|
||||
* calling NotificationSlot::SetSlotGroup(string).
|
||||
* @note A NotificationSlotGroup instance cannot be used directly after being initialized.
|
||||
* Instead, you have to call this method to create a notification slot group so that you can bind
|
||||
* NotificationSlot objects to it.
|
||||
*
|
||||
* @param slotGroup Indicates the notification slot group to be created, which is set by NotificationSlotGroup.
|
||||
* This parameter must be specified. the notification slot to be created, which is set by
|
||||
* NotificationSlot.
|
||||
* @return Returns add notification slot group result.
|
||||
*/
|
||||
static ErrCode AddNotificationSlotGroup(const NotificationSlotGroup &slotGroup);
|
||||
|
||||
/**
|
||||
* Creates multiple notification slot groups.
|
||||
* @note The precautions for using this method are similar to those for
|
||||
* AddNotificationSlotGroup(NotificationSlotGroup).
|
||||
*
|
||||
* @param slotGroups Indicates a list of NotificationSlotGroup objects to create. This parameter cannot be null.
|
||||
* @return Returns add notification slot groups result.
|
||||
*/
|
||||
static ErrCode AddNotificationSlotGroups(const std::vector<NotificationSlotGroup> &slotGroups);
|
||||
|
||||
/**
|
||||
* Deletes a created notification slot group based on the slot group ID.
|
||||
*
|
||||
* @param slotGroupId Indicates the ID of the notification slot group, which is created by
|
||||
* AddNotificationSlotGroup(NotificationSlotGroup) This parameter must be specified.
|
||||
* @return Returns remove notification slot group result.
|
||||
*/
|
||||
static ErrCode RemoveNotificationSlotGroup(const std::string &slotGroupId);
|
||||
|
||||
/**
|
||||
* Queries a created notification slot group.
|
||||
*
|
||||
* @param groupId Indicates the ID of the slot group.
|
||||
* @param group Indicates the created NotificationSlotGroup.
|
||||
* @return Returns get notification slot group result.
|
||||
*/
|
||||
static ErrCode GetNotificationSlotGroup(const std::string &groupId, sptr<NotificationSlotGroup> &group);
|
||||
|
||||
/**
|
||||
* Obtains a list of created notification slot groups.
|
||||
*
|
||||
* @param groups Indicates a list of created notification slot groups.
|
||||
* @return Returns get notification slot groups result.
|
||||
*/
|
||||
static ErrCode GetNotificationSlotGroups(std::vector<sptr<NotificationSlotGroup>> &groups);
|
||||
|
||||
/**
|
||||
* Publishes a notification.
|
||||
* @note If a notification with the same ID has been published by the current application and has not been deleted,
|
||||
* this method will update the notification.
|
||||
*
|
||||
* @param request Indicates the NotificationRequest object for setting the notification content.
|
||||
* This parameter must be specified.
|
||||
* @return Returns publish notification result.
|
||||
*/
|
||||
static ErrCode PublishNotification(const NotificationRequest &request);
|
||||
|
||||
/**
|
||||
* Publishes a notification with a specified label.
|
||||
* @note If a notification with the same ID has been published by the current application and has not been deleted,
|
||||
* this method will update the notification.
|
||||
*
|
||||
* @param label Indicates the label of the notification to publish.
|
||||
* @param request Indicates the NotificationRequest object for setting the notification content.
|
||||
* This parameter must be specified.
|
||||
* @return Returns publish notification result.
|
||||
*/
|
||||
static ErrCode PublishNotification(const std::string &label, const NotificationRequest &request);
|
||||
|
||||
/**
|
||||
* Publishes a notification on a specified remote device.
|
||||
* @note If a notification with the same ID has been published by the current application and has not been deleted,
|
||||
* this method will update the notification.
|
||||
*
|
||||
* @param request Indicates the NotificationRequest object for setting the notification content.
|
||||
* This parameter must be specified.
|
||||
* @param deviceId Indicates the ID of the remote device. If this parameter is null or an empty string,
|
||||
* the notification will be published on the local device.
|
||||
* @return Returns publish notification result.
|
||||
*/
|
||||
static ErrCode PublishNotification(const NotificationRequest &request, const std::string &deviceId);
|
||||
|
||||
/**
|
||||
* Cancels a published notification.
|
||||
*
|
||||
* @param notificationId Indicates the unique notification ID in the application.
|
||||
* The value must be the ID of a published notification.
|
||||
* Otherwise, this method does not take effect.
|
||||
* @return Returns cancel notification result.
|
||||
*/
|
||||
static ErrCode CancelNotification(int32_t notificationId);
|
||||
|
||||
/**
|
||||
* Cancels a published notification matching the specified label and notificationId.
|
||||
*
|
||||
* @param label Indicates the label of the notification to cancel.
|
||||
* @param notificationId Indicates the ID of the notification to cancel.
|
||||
* @return Returns cancel notification result.
|
||||
*/
|
||||
static ErrCode CancelNotification(const std::string &label, int32_t notificationId);
|
||||
|
||||
/**
|
||||
* Cancels all the published notifications.
|
||||
* @note To cancel a specified notification, see CancelNotification(int_32).
|
||||
* @return Returns cancel all notifications result.
|
||||
*/
|
||||
static ErrCode CancelAllNotifications();
|
||||
|
||||
/**
|
||||
* Obtains the number of active notifications of the current application in the system.
|
||||
*
|
||||
* @param nums Indicates the number of active notifications of the current application.
|
||||
* @return Returns get active notification nums result.
|
||||
*/
|
||||
static ErrCode GetActiveNotificationNums(int32_t &num);
|
||||
|
||||
/**
|
||||
* Obtains active notifications of the current application in the system.
|
||||
* @param request Indicates active NotificationRequest objects of the current application.
|
||||
* @return Returns get active notifications result.
|
||||
*/
|
||||
static ErrCode GetActiveNotifications(std::vector<sptr<NotificationRequest>> &request);
|
||||
|
||||
/**
|
||||
* Obtains the map for sorting notifications of the current application.
|
||||
*
|
||||
* @param sortingMap Indicates the NotificationSortingMap object for the current application.
|
||||
* @return Returns get current app sorting result.
|
||||
*/
|
||||
static ErrCode GetCurrentAppSorting(sptr<NotificationSortingMap> &sortingMap);
|
||||
|
||||
/**
|
||||
* Allows another application to act as an agent to publish notifications in the name of your application bundle.
|
||||
*
|
||||
* @param agent Indicates the name of the application bundle that can publish notifications for your application.
|
||||
* @return Returns set notification agent result.
|
||||
*/
|
||||
static ErrCode SetNotificationAgent(const std::string &agent);
|
||||
|
||||
/**
|
||||
* Obtains the name of the application bundle that can publish notifications in the name of your application.
|
||||
*
|
||||
* @param agent Indicates the name of the application bundle that can publish notifications for your application if
|
||||
* any; returns null otherwise.
|
||||
* @return Returns get notification agent result.
|
||||
*/
|
||||
static ErrCode GetNotificationAgent(std::string &agent);
|
||||
|
||||
/**
|
||||
* Checks whether your application has permission to publish notifications by calling
|
||||
* PublishNotificationAsBundle(string, NotificationRequest) in the name of another application indicated by the
|
||||
* given representativeBundle.
|
||||
*
|
||||
* @param representativeBundle Indicates the name of application bundle your application is representing.
|
||||
* @param canPublish Indicates whether your application has permission to publish notifications.
|
||||
* @return Returns can publish notification as bundle result.
|
||||
*/
|
||||
static ErrCode CanPublishNotificationAsBundle(const std::string &representativeBundle, bool &canPublish);
|
||||
|
||||
/**
|
||||
* Publishes a notification in the name of a specified application bundle.
|
||||
* @note If the notification to be published has the same ID as a published notification that has not been canceled,
|
||||
* the existing notification will be replaced by the new one.
|
||||
*
|
||||
* @param request Indicates the NotificationRequest object for setting the notification content.
|
||||
* This parameter must be specified.
|
||||
* @param representativeBundle Indicates the name of the application bundle that allows your application to publish
|
||||
* notifications for it by calling setNotificationAgent.
|
||||
* @return publish notification as bundle result.
|
||||
*/
|
||||
static ErrCode PublishNotificationAsBundle(
|
||||
const std::string &representativeBundle, const NotificationRequest &request);
|
||||
|
||||
/**
|
||||
* Sets the number of active notifications of the current application as the number to be displayed on the
|
||||
* notification badge.
|
||||
* @return Returns set notification badge num result.
|
||||
*/
|
||||
static ErrCode SetNotificationBadgeNum();
|
||||
|
||||
/**
|
||||
* Sets the number to be displayed on the notification badge of the application.
|
||||
*
|
||||
* @param num Indicates the number to display. A negative number indicates that the badge setting remains unchanged.
|
||||
* The value 0 indicates that no badge is displayed on the application icon.
|
||||
* If the value is greater than 99, 99+ will be displayed.
|
||||
* @return Returns set notification badge num result.
|
||||
*/
|
||||
static ErrCode SetNotificationBadgeNum(int32_t num);
|
||||
|
||||
/**
|
||||
* Checks whether this application has permission to publish notifications.
|
||||
*
|
||||
* @param allowed True if this application has the permission; returns false otherwise
|
||||
* @return Returns is allowed notify result.
|
||||
*/
|
||||
static ErrCode IsAllowedNotify(bool &allowed);
|
||||
|
||||
/**
|
||||
* Checks whether this application is in the suspended state.Applications in this state cannot publish
|
||||
* notifications.
|
||||
*
|
||||
* @param suspended True if this application is suspended; returns false otherwise.
|
||||
* @return Returns are notifications suspended.
|
||||
*/
|
||||
static ErrCode AreNotificationsSuspended(bool &suspended);
|
||||
|
||||
/**
|
||||
* Checks whether this application has permission to modify the Do Not Disturb (DND) notification policy.
|
||||
*
|
||||
* @param hasPermission True if this application is suspended; returns false otherwise.
|
||||
* @return Returns has notification policy access permission.
|
||||
*/
|
||||
static ErrCode HasNotificationPolicyAccessPermission(bool &hasPermission);
|
||||
|
||||
/**
|
||||
* Obtains the importance level of this application.
|
||||
*
|
||||
* @param importance the importance level of this application, which can be LEVEL_NONE,
|
||||
LEVEL_MIN, LEVEL_LOW, LEVEL_DEFAULT, LEVEL_HIGH, or LEVEL_UNDEFINED.
|
||||
* @return Returns get bundle importance result
|
||||
*/
|
||||
static ErrCode GetBundleImportance(NotificationSlot::NotificationLevel &importance);
|
||||
|
||||
/**
|
||||
* Subscribes to notifications from all applications. This method can be called only by applications
|
||||
* with required system permissions.
|
||||
* @note To subscribe to a notification, inherit the {NotificationSubscriber} class, override its
|
||||
* callback methods and create a subscriber. The subscriber will be used as a parameter of this method.
|
||||
* After the notification is published, subscribers that meet the filter criteria can receive the
|
||||
* notification. To subscribe to notifications published only by specified sources, for example, notifications from
|
||||
* certain applications, call the {SubscribeNotification(NotificationSubscriber, NotificationSubscribeInfo)}
|
||||
* method.
|
||||
*
|
||||
* @param subscriber Indicates the {NotificationSubscriber} to receive notifications.
|
||||
* This parameter must be specified.
|
||||
* @return Returns unsubscribe notification result.
|
||||
*/
|
||||
static ErrCode SubscribeNotification(const NotificationSubscriber &subscriber);
|
||||
|
||||
/**
|
||||
* Subscribes to all notifications based on the filtering criteria. This method can be called only
|
||||
* by applications with required system permissions.
|
||||
* @note After {subscribeInfo} is specified, a subscriber receives only the notifications that
|
||||
* meet the filter criteria specified by {subscribeInfo}.
|
||||
* To subscribe to a notification, inherit the {NotificationSubscriber} class, override its
|
||||
* callback methods and create a subscriber. The subscriber will be used as a parameter of this method.
|
||||
* After the notification is published, subscribers that meet the filter criteria can receive the
|
||||
* notification. To subscribe to and receive all notifications, call the
|
||||
* {SubscribeNotification(NotificationSubscriber)} method.
|
||||
*
|
||||
* @param subscriber Indicates the subscribers to receive notifications. This parameter must be specified.
|
||||
* For details, see {NotificationSubscriber}.
|
||||
* @param subscribeInfo Indicates the filters for specified notification sources, including application name,
|
||||
* user ID, or device name. This parameter is optional.
|
||||
* @return Returns subscribe notification result.
|
||||
*/
|
||||
static ErrCode SubscribeNotification(
|
||||
const NotificationSubscriber &subscriber, const NotificationSubscribeInfo &subscribeInfo);
|
||||
|
||||
/**
|
||||
* Unsubscribes from all notifications. This method can be called only by applications with required
|
||||
* system permissions.
|
||||
* @note Generally, you subscribe to a notification by calling the
|
||||
* {SubscribeNotification(NotificationSubscriber)} method. If you do not want your application
|
||||
* to receive a notification any longer, unsubscribe from that notification using this method.
|
||||
* You can unsubscribe from only those notifications that your application has subscribed to.
|
||||
* To unsubscribe from notifications published only by specified sources, for example,
|
||||
* notifications from certain applications, call the
|
||||
* {UnSubscribeNotification(NotificationSubscriber, NotificationSubscribeInfo)} method.
|
||||
*
|
||||
* @param subscriber Indicates the {NotificationSubscriber} to receive notifications.
|
||||
* This parameter must be specified.
|
||||
* @return Returns unsubscribe notification result.
|
||||
*/
|
||||
static ErrCode UnSubscribeNotification(NotificationSubscriber &subscriber);
|
||||
|
||||
/**
|
||||
* Unsubscribes from all notifications based on the filtering criteria. This method can be called
|
||||
* only by applications with required system permissions.
|
||||
* @note A subscriber will no longer receive the notifications from specified notification sources.
|
||||
*
|
||||
* @param subscriber Indicates the {NotificationSubscriber} to receive notifications.
|
||||
* This parameter must be specified.
|
||||
* @param subscribeInfo Indicates the filters for , including application name,
|
||||
* user ID, or device name. This parameter is optional.
|
||||
* @return Returns unsubscribe notification result.
|
||||
*/
|
||||
static ErrCode UnSubscribeNotification(NotificationSubscriber &subscriber, NotificationSubscribeInfo subscribeInfo);
|
||||
|
||||
/**
|
||||
* Removes a specified removable notification of other applications.
|
||||
* @note Your application must have platform signature to use this method.
|
||||
*
|
||||
* @param key Indicates the key of the notification to remove.
|
||||
* @return Returns remove notification result.
|
||||
*/
|
||||
static ErrCode RemoveNotification(const std::string &key);
|
||||
|
||||
/**
|
||||
* Removes all removable notifications of a specified bundle.
|
||||
* @note Your application must have platform signature to use this method.
|
||||
*
|
||||
* @param bundleName Indicates the bundle name of the application whose notifications are to be removed.
|
||||
* @return Returns remove notifications result.
|
||||
*/
|
||||
static ErrCode RemoveNotifications(const std::string &bundleName);
|
||||
|
||||
/**
|
||||
* Removes all removable notifications in the system.
|
||||
* @note Your application must have platform signature to use this method.
|
||||
* @return Returns remove notifications result.
|
||||
*/
|
||||
static ErrCode RemoveNotifications();
|
||||
|
||||
/**
|
||||
* Returns all notification slots belonging to the specified bundle.
|
||||
*
|
||||
* @param bundleName Indicates the application name.
|
||||
* @param slots Indicates a list of notification slots.
|
||||
* @return Returns get notification slots for bundle result.
|
||||
*/
|
||||
static ErrCode GetNotificationSlotsForBundle(
|
||||
const std::string &bundleName, std::vector<sptr<NotificationSlot>> &slots);
|
||||
|
||||
/**
|
||||
* Obtains all active notifications in the current system. The caller must have system permissions to
|
||||
* call this method.
|
||||
*
|
||||
* @param notification Indicates all active notifications of this application.
|
||||
* @return Returns get all active notifications
|
||||
*/
|
||||
static ErrCode GetAllActiveNotifications(std::vector<sptr<Notification>> ¬ification);
|
||||
|
||||
/**
|
||||
* Obtains the active notifications corresponding to the specified key in the system. To call this method
|
||||
* to obtain particular active notifications, you must have received the notifications and obtained the key
|
||||
* via {Notification::GetKey()}.
|
||||
*
|
||||
* @param key Indicates the key array for querying corresponding active notifications.
|
||||
* If this parameter is null, this method returns all active notifications in the system.
|
||||
* @return Returns the set of active notifications corresponding to the specified key.
|
||||
*/
|
||||
static ErrCode GetAllActiveNotifications(
|
||||
const std::vector<std::string> key, std::vector<sptr<Notification>> ¬ification);
|
||||
|
||||
/**
|
||||
* Checks whether a specified application has the permission to publish notifications. If bundle specifies
|
||||
* the current application, no permission is required for calling this method. If bundle specifies another
|
||||
* application, the caller must have system permissions.
|
||||
*
|
||||
* @param bundle Indicates the bundle name of the application to check.
|
||||
* @param allowed True if the application has permissions; returns false otherwise.
|
||||
* @return Returns is allowed notify result.
|
||||
*/
|
||||
static ErrCode IsAllowedNotify(const std::string &bundle, bool &allowed);
|
||||
|
||||
/**
|
||||
* Sets whether to allow all applications to publish notifications on a specified device. The caller must have
|
||||
* system permissions to call this method.
|
||||
*
|
||||
* @param deviceId Indicates the ID of the device running the application. At present, this parameter can only
|
||||
* be null or an empty string, indicating the current device.
|
||||
* @param enabled Specifies whether to allow all applications to publish notifications. The value true
|
||||
* indicates that notifications are allowed, and the value false indicates that notifications are not
|
||||
* allowed.
|
||||
* @return Returns set notifications enabled for all bundles result.
|
||||
*/
|
||||
static ErrCode SetNotificationsEnabledForAllBundles(const std::string &deviceId, bool enabled);
|
||||
|
||||
/**
|
||||
* Sets whether to allow the current application to publish notifications on a specified device. The caller
|
||||
* must have system permissions to call this method.
|
||||
*
|
||||
* @param deviceId Indicates the ID of the device running the application. At present, this parameter can
|
||||
* only be null or an empty string, indicating the current device.
|
||||
* @param enabled Specifies whether to allow the current application to publish notifications. The value
|
||||
* true indicates that notifications are allowed, and the value false indicates that
|
||||
* notifications are not allowed.\
|
||||
* @return Returns set notifications enabled for default bundle result.
|
||||
*/
|
||||
static ErrCode SetNotificationsEnabledForDefaultBundle(const std::string &deviceId, bool enabled);
|
||||
|
||||
/**
|
||||
* Sets whether to allow a specified application to publish notifications on a specified device. The caller
|
||||
* must have system permissions to call this method.
|
||||
*
|
||||
* @param bundle Indicates the bundle name of the application.
|
||||
* @param deviceId Indicates the ID of the device running the application. At present, this parameter can only
|
||||
* be null or an empty string, indicating the current device.
|
||||
* @param enabled Specifies whether to allow the given application to publish notifications. The value
|
||||
* true indicates that notifications are allowed, and the value false indicates that notifications
|
||||
* are not allowed.
|
||||
* @return Returns set notifications enabled for specified bundle result.
|
||||
*/
|
||||
static ErrCode SetNotificationsEnabledForSpecifiedBundle(
|
||||
const std::string &bundle, std::string &deviceId, bool enabled);
|
||||
|
||||
/**
|
||||
* Sets the type of the Do Not Disturb mode. The Do Not Disturb mode type specifies the type of notifications
|
||||
* that are allowed to interrupt users.
|
||||
* @note Your application must have system signature to call this method.
|
||||
*
|
||||
* @param mode Indicates the Do Not Disturb mode to set. The value must be
|
||||
* {NotificationConstant.DisturbMode.ALLOW_ALL}, {NotificationConstant.DisturbMode.ALLOW_PRIORITY},
|
||||
* {NotificationConstant.DisturbMode.ALLOW_NONE}, or {NotificationConstant.DisturbMode.ALLOW_ALARMS}.
|
||||
* @return Returns set disturb mode result.
|
||||
*/
|
||||
static ErrCode SetDisturbMode(NotificationConstant::DisturbMode mode);
|
||||
|
||||
/**
|
||||
* Obtains the Disturb Mode.
|
||||
* @param disturbMode The current type of the Do Not Disturb mode.
|
||||
* @return Returns get disturb mode result.
|
||||
*/
|
||||
static ErrCode GetDisturbMode(NotificationConstant::DisturbMode &disturbMode);
|
||||
};
|
||||
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_HELPER_H
|
||||
@@ -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_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_LONG_TEXT_CONTENT_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_LONG_TEXT_CONTENT_H
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "notification_basic_content.h"
|
||||
#include "parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
class NotificationLongTextContent : public NotificationBasicContent {
|
||||
public:
|
||||
/**
|
||||
* Default constructor used to create a NotificationLongTextContent instance.
|
||||
*/
|
||||
NotificationLongTextContent() = default;
|
||||
|
||||
/**
|
||||
* A constructor used to create a NotificationLongTextContent instance with the input parameter longText passed.
|
||||
* @param longText Indicates the long text to be included. The value contains a maximum of 1024 characters.
|
||||
*/
|
||||
explicit NotificationLongTextContent(const std::string &longText);
|
||||
|
||||
/**
|
||||
* Default deconstructor used to deconstruct.
|
||||
*/
|
||||
~NotificationLongTextContent() = default;
|
||||
|
||||
/**
|
||||
* Sets the title to be displayed when this long text notification is expanded. After this title is set,
|
||||
* the title set by setTitle(string) will be displayed only when this notification is in the collapsed state.
|
||||
* @param exTitle Indicates the title to be displayed when this notification is expanded.
|
||||
*/
|
||||
void SetExpandedTitle(const std::string &exTitle);
|
||||
|
||||
/**
|
||||
* Obtains the title that will be displayed for this long text notification when it is expanded.
|
||||
* @return the title to be displayed when this notification is expanded.
|
||||
*/
|
||||
std::string GetExpandedTitle() const;
|
||||
|
||||
/**
|
||||
* Sets the brief text to be included in a long text notification.
|
||||
* The brief text is a summary of a long text notification and is displayed in the first line of the notification.
|
||||
* Similar to setAdditionalText(string), the font of the brief text is also smaller than the notification text.
|
||||
* The positions where the brief text and additional text will display may conflict.
|
||||
* If both texts are set, only the additional text will be displayed.
|
||||
* @param briefText Indicates the brief text to be included.
|
||||
*/
|
||||
void SetBriefText(const std::string &briefText);
|
||||
|
||||
/**
|
||||
* Obtains the brief text of a long text notification specified by calling the setBriefText(string) method.
|
||||
* @return the brief text of the long text notification.
|
||||
*/
|
||||
std::string GetBriefText() const;
|
||||
|
||||
/**
|
||||
* Sets the long text to be included in a long text notification.
|
||||
* @param longText Indicates the long text to be included. The value contains a maximum of 1024 characters.
|
||||
*/
|
||||
void SetLongText(const std::string &longText);
|
||||
|
||||
/**
|
||||
* Obtains a notification's long text, which is set by calling the setLongText(string) method.
|
||||
* @return the long text.
|
||||
*/
|
||||
std::string GetLongText() const;
|
||||
|
||||
/**
|
||||
* Returns a string representation of the object.
|
||||
* @return a string representation of the object.
|
||||
*/
|
||||
std::string Dump() override;
|
||||
|
||||
/**
|
||||
* Marshal a object into a Parcel.
|
||||
* @param parcel the object into the parcel
|
||||
*/
|
||||
virtual bool Marshalling(Parcel &parcel) const override;
|
||||
|
||||
/**
|
||||
* Unmarshal object from a Parcel.
|
||||
* @return the NotificationLongTextContent
|
||||
*/
|
||||
static NotificationLongTextContent *Unmarshalling(Parcel &parcel);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Read a NotificationLongTextContent object from a Parcel.
|
||||
* @param parcel the parcel
|
||||
*/
|
||||
bool ReadFromParcel(Parcel &parcel) override;
|
||||
|
||||
private:
|
||||
/**
|
||||
* the maximum lenth of longtext is 1024 characters.
|
||||
*/
|
||||
static const std::size_t MAX_LONGTEXT_LENGTH;
|
||||
|
||||
private:
|
||||
std::string longText_{};
|
||||
std::string expandedTitle_{};
|
||||
std::string briefText_{};
|
||||
};
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_LONG_TEXT_CONTENT_H
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_MEDIA_CONTENT_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_MEDIA_CONTENT_H
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "notification_basic_content.h"
|
||||
#include "parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
class AVToken;
|
||||
|
||||
class NotificationMediaContent : public NotificationBasicContent {
|
||||
public:
|
||||
/**
|
||||
* Default constructor used to create a NotificationMediaContent instance.
|
||||
*/
|
||||
NotificationMediaContent() = default;
|
||||
|
||||
/**
|
||||
* Default deconstructor used to deconstruct.
|
||||
*/
|
||||
~NotificationMediaContent() = default;
|
||||
|
||||
/**
|
||||
* Attaches a specified AVToken to this media playback notification.
|
||||
* After an AVToken is attached, this notification can interact with the associated AVSession
|
||||
* so that users can control media playback in this notification.
|
||||
* @param avToken Indicates the AVToken to attach.
|
||||
*/
|
||||
void SetAVToken(const std::shared_ptr<AVToken> &avToken);
|
||||
|
||||
/**
|
||||
* Obtains the AVToken attached to this media playback notification.
|
||||
* @return the AVToken attached to this notification.
|
||||
*/
|
||||
const std::shared_ptr<AVToken> GetAVToken() const;
|
||||
|
||||
/**
|
||||
* Sets up to three NotificationActionButton objects to be shown in this media playback notification.
|
||||
* Before publishing this notification, you should also call
|
||||
* NotificationRequest::addActionButton(NotificationActionButton) to add specified NotificationActionButton objects
|
||||
* for this notification so that this method can take effect. The added action buttons will be assigned sequence
|
||||
* numbers in the order they were added. The sequence numbers specified in the value of actions for this method
|
||||
* must match those assigned to added action buttons. Otherwise, the notification will fail to publish. By default,
|
||||
* the sequence number starts from 0. If you want to show three action buttons, the value of actions should be 0,
|
||||
* 1, 2.
|
||||
* @param actions Indicates the list of sequence numbers representing the NotificationActionButton objects
|
||||
* to be shown in this notification.
|
||||
*/
|
||||
void SetShownActions(const std::vector<uint32_t> &actions);
|
||||
|
||||
/**
|
||||
* Obtains the list of sequence numbers representing the NotificationActionButton objects
|
||||
* to be shown in this media playback notification.
|
||||
* @return the list of the action buttons to be shown.
|
||||
*/
|
||||
std::vector<uint32_t> GetShownActions() const;
|
||||
|
||||
/**
|
||||
* Returns a string representation of the object.
|
||||
* @return a string representation of the object.
|
||||
*/
|
||||
std::string Dump() override;
|
||||
|
||||
/**
|
||||
* Marshal a object into a Parcel.
|
||||
* @param parcel the object into the parcel
|
||||
*/
|
||||
virtual bool Marshalling(Parcel &parcel) const override;
|
||||
|
||||
/**
|
||||
* Unmarshal object from a Parcel.
|
||||
* @return the NotificationMediaContent
|
||||
*/
|
||||
static NotificationMediaContent *Unmarshalling(Parcel &parcel);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Read a NotificationMediaContent object from a Parcel.
|
||||
* @param parcel the parcel
|
||||
*/
|
||||
bool ReadFromParcel(Parcel &parcel) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<AVToken> avToken_{};
|
||||
std::vector<uint32_t> sequenceNumbers_{};
|
||||
};
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_MEDIA_CONTENT_H
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* 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_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_MULTILINE_CONTENT_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_MULTILINE_CONTENT_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "notification_basic_content.h"
|
||||
#include "parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
class NotificationMultiLineContent : public NotificationBasicContent {
|
||||
public:
|
||||
/**
|
||||
* Default constructor used to create a NotificationMultiLineContent instance.
|
||||
*/
|
||||
NotificationMultiLineContent() = default;
|
||||
|
||||
/**
|
||||
* Default deconstructor used to deconstruct.
|
||||
*/
|
||||
~NotificationMultiLineContent() = default;
|
||||
|
||||
/**
|
||||
* Sets the title to be displayed when this multi-line notification is expanded.
|
||||
* After this title is set, the title set by setTitle(string) will be displayed only
|
||||
* when this notification is in the collapsed state.
|
||||
* @param exTitle Indicates the title to be displayed when this notification is expanded.
|
||||
*/
|
||||
void SetExpandedTitle(const std::string &exTitle);
|
||||
|
||||
/**
|
||||
* Obtains the title that will be displayed for this multi-line notification when it is expanded.
|
||||
* @return the title to be displayed when this notification is expanded.
|
||||
*/
|
||||
std::string GetExpandedTitle() const;
|
||||
|
||||
/**
|
||||
* Sets the brief text to be included in a multi-line notification.
|
||||
* The brief text is a summary of this multi-line notification and is displayed in the first line of
|
||||
* the notification. Similar to setAdditionalText(string), the font of the brief text is also
|
||||
* smaller than the notification text set by calling setText(string).
|
||||
* The positions where the brief text and additional text will display may conflict.
|
||||
* If both texts are set, only the additional text will be displayed.
|
||||
* @param briefText Indicates the brief text to be included.
|
||||
*/
|
||||
void SetBriefText(const std::string &briefText);
|
||||
|
||||
/**
|
||||
* Obtains the brief text that has been set by calling setBriefText(string) for this multi-line notification.
|
||||
* @return the brief text of this notification.
|
||||
*/
|
||||
std::string GetBriefText() const;
|
||||
|
||||
/**
|
||||
* Adds a single line of text to this notification.
|
||||
* You can call this method up to seven times to add seven lines to a notification.
|
||||
* @param oneLine Indicates the single line of text to be included.
|
||||
*/
|
||||
void AddSingleLine(const std::string &oneLine);
|
||||
|
||||
/**
|
||||
* Obtains the list of lines included in this multi-line notification.
|
||||
* @return the list of lines included in this notification.
|
||||
*/
|
||||
std::vector<std::string> GetAllLines() const;
|
||||
|
||||
/**
|
||||
* Returns a string representation of the object.
|
||||
* @return a string representation of the object.
|
||||
*/
|
||||
std::string Dump() override;
|
||||
|
||||
/**
|
||||
* Marshal a object into a Parcel.
|
||||
* @param parcel the object into the parcel
|
||||
*/
|
||||
virtual bool Marshalling(Parcel &parcel) const override;
|
||||
|
||||
/**
|
||||
* Unmarshal object from a Parcel.
|
||||
* @return the NotificationMultiLineContent
|
||||
*/
|
||||
static NotificationMultiLineContent *Unmarshalling(Parcel &parcel);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Read a NotificationMultiLineContent object from a Parcel.
|
||||
* @param parcel the parcel
|
||||
*/
|
||||
bool ReadFromParcel(Parcel &parcel) override;
|
||||
|
||||
private:
|
||||
/**
|
||||
* the maximum size of vector is 7.
|
||||
*/
|
||||
static const std::vector<std::string>::size_type MAX_LINES;
|
||||
|
||||
private:
|
||||
std::string expandedTitle_{};
|
||||
std::string briefText_{};
|
||||
std::vector<std::string> allLines_{};
|
||||
};
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_MULTILINE_CONTENT_H
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_NORMAL_CONTENT_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_NORMAL_CONTENT_H
|
||||
|
||||
#include <string>
|
||||
#include "notification_basic_content.h"
|
||||
#include "parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
class NotificationNormalContent : public NotificationBasicContent {
|
||||
public:
|
||||
/**
|
||||
* Default constructor used to create a NotificationNormalContent instance.
|
||||
*/
|
||||
NotificationNormalContent() = default;
|
||||
|
||||
/**
|
||||
* Default deconstructor used to deconstruct.
|
||||
*/
|
||||
~NotificationNormalContent() = default;
|
||||
|
||||
/**
|
||||
* Returns a string representation of the object.
|
||||
* @return a string representation of the object.
|
||||
*/
|
||||
std::string Dump() override;
|
||||
|
||||
/**
|
||||
* Marshal a object into a Parcel.
|
||||
* @param parcel the object into the parcel
|
||||
*/
|
||||
virtual bool Marshalling(Parcel &parcel) const override;
|
||||
|
||||
/**
|
||||
* Unmarshal object from a Parcel.
|
||||
* @return the NotificationNormalContent
|
||||
*/
|
||||
static NotificationNormalContent *Unmarshalling(Parcel &parcel);
|
||||
};
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_NORMAL_CONTENT_H
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* 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_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_PICTURE_CONTENT_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_PICTURE_CONTENT_H
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "notification_basic_content.h"
|
||||
#include "parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
class PixelMap;
|
||||
|
||||
class NotificationPictureContent : public NotificationBasicContent {
|
||||
public:
|
||||
/**
|
||||
* Default constructor used to create an empty NotificationPictureContent instance.
|
||||
*/
|
||||
NotificationPictureContent() = default;
|
||||
|
||||
/**
|
||||
* Default deconstructor used to deconstruct.
|
||||
*/
|
||||
~NotificationPictureContent() = default;
|
||||
|
||||
/**
|
||||
* Sets the title to be displayed when this picture-attached notification is expanded.
|
||||
* After this title is set, the title set by setTitle(string) will be displayed only
|
||||
* when this notification is in the collapsed state.
|
||||
* @param exTitle Indicates the title to be displayed when this notification is expanded.
|
||||
*/
|
||||
void SetExpandedTitle(const std::string &exTitle);
|
||||
|
||||
/**
|
||||
* Obtains the title that will be displayed for this picture-attached notification when it is expanded.
|
||||
* @return the title to be displayed when this notification is expanded.
|
||||
*/
|
||||
std::string GetExpandedTitle() const;
|
||||
|
||||
/**
|
||||
* Sets the brief text to be included in a picture-attached notification.
|
||||
* The brief text is a summary of a picture-attached notification and is displayed in the first line of the
|
||||
* notification. Similar to setAdditionalText(string), the font of the brief text is also smaller than the
|
||||
* notification text. The positions where the brief text and additional text will display may conflict. If both
|
||||
* texts are set, only the additional text will be displayed.
|
||||
* @param briefText Indicates the brief text to be included.
|
||||
*/
|
||||
void SetBriefText(const std::string &briefText);
|
||||
|
||||
/**
|
||||
* Obtains the brief text of a picture-attached notification specified by calling the setBriefText(string) method.
|
||||
* @return the brief text of the picture-attached notification.
|
||||
*/
|
||||
std::string GetBriefText() const;
|
||||
|
||||
/**
|
||||
* Sets the picture to be included in a notification.
|
||||
* @param bigPicture Indicates the PixelMap of the picture to be included.
|
||||
*/
|
||||
void SetBigPicture(const std::shared_ptr<PixelMap> &bigPicture);
|
||||
|
||||
/**
|
||||
* Obtains the PixelMap of the picture specified by calling the setBigPicture(PixelMap) method.
|
||||
* @return the PixelMap of the picture included in the notification.
|
||||
*/
|
||||
const std::shared_ptr<PixelMap> GetBigPicture() const;
|
||||
|
||||
/**
|
||||
* Returns a string representation of the object.
|
||||
* @return a string representation of the object.
|
||||
*/
|
||||
std::string Dump() override;
|
||||
|
||||
/**
|
||||
* Marshal a object into a Parcel.
|
||||
* @param parcel the object into the parcel
|
||||
*/
|
||||
virtual bool Marshalling(Parcel &parcel) const override;
|
||||
|
||||
/**
|
||||
* Unmarshal object from a Parcel.
|
||||
* @return the NotificationPictureContent
|
||||
*/
|
||||
static NotificationPictureContent *Unmarshalling(Parcel &parcel);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Read a NotificationPictureContent object from a Parcel.
|
||||
* @param parcel the parcel
|
||||
*/
|
||||
bool ReadFromParcel(Parcel &parcel) override;
|
||||
|
||||
private:
|
||||
std::string expandedTitle_{};
|
||||
std::string briefText_{};
|
||||
std::shared_ptr<PixelMap> bigPicture_{};
|
||||
};
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_PICTURE_CONTENT_H
|
||||
@@ -0,0 +1,996 @@
|
||||
/*
|
||||
* 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_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_REQUEST_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_REQUEST_H
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "message_user.h"
|
||||
#include "notification_action_button.h"
|
||||
#include "notification_content.h"
|
||||
#include "want_agent.h"
|
||||
#include "context.h"
|
||||
#include "ohos/aafwk/content/want_params.h"
|
||||
#include "parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
class ComponentProvider;
|
||||
class PixelMap;
|
||||
|
||||
class NotificationRequest : public Parcelable {
|
||||
public:
|
||||
enum class BadgeStyle {
|
||||
/**
|
||||
* displays only numbers.
|
||||
*/
|
||||
NONE,
|
||||
/**
|
||||
* displayed as a large icon.
|
||||
*/
|
||||
BIG,
|
||||
/**
|
||||
* displayed as a small icon.
|
||||
*/
|
||||
LITTLE
|
||||
};
|
||||
|
||||
enum class GroupAlertType {
|
||||
/**
|
||||
* all notifications in a group have sound or vibration if sound or vibration is enabled
|
||||
* for the associated NotificationSlot objects.
|
||||
*/
|
||||
ALL,
|
||||
/**
|
||||
* child notifications have sound or vibration but the overview notification is muted (no sound or vibration)
|
||||
* in a group if sound or vibration is enabled for the associated NotificationSlot objects.
|
||||
*/
|
||||
CHILD,
|
||||
/**
|
||||
* the overview notification has sound or vibration but child notifications are muted (no sound or vibration)
|
||||
* in a group if sound or vibration is enabled for the associated NotificationSlot objects.
|
||||
*/
|
||||
OVERVIEW
|
||||
};
|
||||
|
||||
/**
|
||||
* Indicates the classification of notifications for alarms or timers.
|
||||
*/
|
||||
static const std::string CLASSIFICATION_ALARM;
|
||||
/**
|
||||
* Indicates the classification of notifications for incoming calls or similar synchronous communication requests.
|
||||
*/
|
||||
static const std::string CLASSIFICATION_CALL;
|
||||
/**
|
||||
* Indicates the classification of notifications for emails.
|
||||
*/
|
||||
static const std::string CLASSIFICATION_EMAIL;
|
||||
/**
|
||||
* Indicates the classification of notifications for errors occurred during background operations or identity
|
||||
* authentication.
|
||||
*/
|
||||
static const std::string CLASSIFICATION_ERROR;
|
||||
/**
|
||||
* Indicates the classification of notifications for calendar events.
|
||||
*/
|
||||
static const std::string CLASSIFICATION_EVENT;
|
||||
/**
|
||||
* Indicates the classification of notifications for short messages or instant messages.
|
||||
*/
|
||||
static const std::string CLASSIFICATION_MESSAGE;
|
||||
/**
|
||||
* Indicates the classification of notifications for map navigation.
|
||||
*/
|
||||
static const std::string CLASSIFICATION_NAVIGATION;
|
||||
/**
|
||||
* Indicates the classification of notifications for processes that are operated in the background for a long time.
|
||||
*/
|
||||
static const std::string CLASSIFICATION_PROGRESS;
|
||||
/**
|
||||
* Indicates the classification of notifications for advertisement or promotion information.
|
||||
*/
|
||||
static const std::string CLASSIFICATION_PROMO;
|
||||
/**
|
||||
* Indicates the classification of notifications for specific and timely recommendations of a particular
|
||||
* transaction.
|
||||
*/
|
||||
static const std::string CLASSIFICATION_RECOMMENDATION;
|
||||
/**
|
||||
* Indicates the classification of notifications for reminders previously set by the user.
|
||||
*/
|
||||
static const std::string CLASSIFICATION_REMINDER;
|
||||
/**
|
||||
* Indicates the classification of notifications for ongoing background services.
|
||||
*/
|
||||
static const std::string CLASSIFICATION_SERVICE;
|
||||
/**
|
||||
* Indicates the classification of notifications for social network or sharing updates.
|
||||
*/
|
||||
static const std::string CLASSIFICATION_SOCIAL;
|
||||
/**
|
||||
* Indicates the classification of notifications for ongoing information about the device and contextual status.
|
||||
*/
|
||||
static const std::string CLASSIFICATION_STATUS;
|
||||
/**
|
||||
* Indicates the classification of notifications for system or device status updates.
|
||||
*/
|
||||
static const std::string CLASSIFICATION_SYSTEM;
|
||||
/**
|
||||
* Indicates the classification of notifications for media transport control during playback.
|
||||
*/
|
||||
static const std::string CLASSIFICATION_TRANSPORT;
|
||||
|
||||
/**
|
||||
* Indicates the default notification background color, which means that no color is displayed.
|
||||
*/
|
||||
static const int32_t COLOR_DEFAULT;
|
||||
|
||||
private:
|
||||
/**
|
||||
* Indicates the color mask, used for calculation with the ARGB value set by setColor(int32_t).
|
||||
*/
|
||||
static const int32_t COLOR_MASK;
|
||||
|
||||
/**
|
||||
* the maximum number of user input history is 5.
|
||||
*/
|
||||
static const std::size_t MAX_USER_INPUT_HISTORY;
|
||||
|
||||
/**
|
||||
* the maximum number of action buttons is 3.
|
||||
*/
|
||||
static const std::size_t MAX_ACTION_BUTTONS;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Default constructor used to create a NotificationRequest instance.
|
||||
*/
|
||||
NotificationRequest() = default;
|
||||
|
||||
/**
|
||||
* A constructor used to create a NotificationRequest instance with the input parameter notificationId passed.
|
||||
* @param notificationId notification ID
|
||||
*/
|
||||
explicit NotificationRequest(int32_t notificationId);
|
||||
|
||||
/**
|
||||
* A constructor used to create a NotificationRequest instance based on the specified context and notification ID.
|
||||
* To publish a notification with a custom view, you must call such a constructor with the Context specified.
|
||||
* @param context the specified context
|
||||
* @param notificationId notification ID
|
||||
*/
|
||||
NotificationRequest(const std::shared_ptr<AppExecFwk::Context> &context, int32_t notificationId);
|
||||
|
||||
/**
|
||||
* A constructor used to create a NotificationRequest instance by copying parameters from an existing one.
|
||||
* @param other the existing object
|
||||
*/
|
||||
NotificationRequest(const NotificationRequest &other);
|
||||
|
||||
/**
|
||||
* A constructor used to create a NotificationRequest instance by copying parameters from an existing one.
|
||||
* @param other the existing object
|
||||
*/
|
||||
NotificationRequest &operator=(const NotificationRequest &other);
|
||||
|
||||
/**
|
||||
* Default deconstructor used to deconstruct.
|
||||
*/
|
||||
virtual ~NotificationRequest();
|
||||
|
||||
/**
|
||||
* Checks whether this notification is in progress.
|
||||
* @return true if this notification is in progress; returns false otherwise.
|
||||
*/
|
||||
bool IsInProgress() const;
|
||||
|
||||
/**
|
||||
* Sets whether this notification is in progress.
|
||||
* Users cannot directly dismiss notifications in progress because
|
||||
* they usually contain some ongoing background services such as music playback.
|
||||
* @param isOngoing Specifies whether this notification is in progress.
|
||||
*/
|
||||
void SetInProgress(bool isOngoing);
|
||||
|
||||
/**
|
||||
* Checks whether this notification is unremovable.
|
||||
* @return true if this notification is unremovable; returns false otherwise.
|
||||
*/
|
||||
bool IsUnremovable() const;
|
||||
|
||||
/**
|
||||
* Sets whether this notification is unremovable.
|
||||
* If it is set to be unremovable, it cannot be removed by users.
|
||||
* @param isUnremovable Specifies whether this notification is unremovable.
|
||||
*/
|
||||
void SetUnremovable(bool isUnremovable);
|
||||
|
||||
/**
|
||||
* Sets the number to be displayed for this notification.
|
||||
* @param number Indicates the number to set.
|
||||
*/
|
||||
void SetBadgeNumber(int32_t number);
|
||||
|
||||
/**
|
||||
* Obtains the number to be displayed for this notification.
|
||||
* @return the number to be displayed for this notification.
|
||||
*/
|
||||
int32_t GetBadgeNumber() const;
|
||||
|
||||
/**
|
||||
* Sets the current notification ID to uniquely identify the notification in the application.
|
||||
* After a notification is received, its ID is obtained by using the getNotificationId() method.
|
||||
* @param notificationId Indicates the ID of the notification to be set.
|
||||
*/
|
||||
void SetNotificationId(int32_t notificationId);
|
||||
|
||||
/**
|
||||
* Obtains the notification ID, which is unique in the current application.
|
||||
* @return the notification ID.
|
||||
*/
|
||||
int32_t GetNotificationId() const;
|
||||
|
||||
/**
|
||||
* Adds an WantAgent to this notification.
|
||||
* After a notification is tapped,
|
||||
* subsequent operations such as ability and common events will be triggered as set by WantAgent.
|
||||
* @param wantAgent Indicates the operation triggered by tapping the notification, which can be set by
|
||||
* WantAgent.
|
||||
*/
|
||||
void SetWantAgent(const std::shared_ptr<WantAgent::WantAgent> &wantAgent);
|
||||
|
||||
/**
|
||||
* Obtains the WantAgent contained in this notification.
|
||||
* @return the WantAgent contained in this notification.
|
||||
*/
|
||||
const std::shared_ptr<WantAgent::WantAgent> GetWantAgent() const;
|
||||
|
||||
/**
|
||||
* Sets an WantAgent object that is triggered when the user explicitly removes this notification.
|
||||
* @param wantAgent Indicates the WantAgent object to be triggered.
|
||||
*/
|
||||
void SetRemovalWantAgent(const std::shared_ptr<WantAgent::WantAgent> &wantAgent);
|
||||
|
||||
/**
|
||||
* Obtains the WantAgent object that is triggered when the user explicitly removes this notification.
|
||||
* @return the WantAgent object to be triggered.
|
||||
*/
|
||||
const std::shared_ptr<WantAgent::WantAgent> GetRemovalWantAgent() const;
|
||||
|
||||
/**
|
||||
* Sets the WantAgent to start when the device is not in use,
|
||||
* instead of showing this notification in the status bar.
|
||||
* When the device is in use, the system UI displays a pop-up notification
|
||||
* instead of starting the WantAgent specified by maxScreenWantAgent.
|
||||
* Your application must have the ohos.permission.USE_WHOLE_SCREEN permission to use this method.
|
||||
* @param wantAgent Indicates the WantAgent object containing information about the to-be-started ability that
|
||||
* uses the Page template.
|
||||
*/
|
||||
void SetMaxScreenWantAgent(const std::shared_ptr<WantAgent::WantAgent> &wantAgent);
|
||||
|
||||
/**
|
||||
* Obtains the full-screen WantAgent set by calling setMaxScreenWantAgent(WantAgent).
|
||||
* @return the full-screen WantAgent.
|
||||
*/
|
||||
const std::shared_ptr<WantAgent::WantAgent> GetMaxScreenWantAgent() const;
|
||||
|
||||
/**
|
||||
* Sets extra parameters that are stored as key-value pairs for the notification.
|
||||
* @param extras Indicates the WantParams object containing the extra parameters in key-value pair format.
|
||||
*/
|
||||
void SetAdditionalData(const std::shared_ptr<AAFwk::WantParams> &extras);
|
||||
|
||||
/**
|
||||
* Obtains the WantParams object set in the notification.
|
||||
* @return the WantParams object.
|
||||
*/
|
||||
const std::shared_ptr<AAFwk::WantParams> GetAdditionalData() const;
|
||||
|
||||
/**
|
||||
* Sets the time to deliver a notification.
|
||||
* @param deliveryTime Indicates the time in milliseconds.
|
||||
*/
|
||||
void SetDeliveryTime(int64_t deliveryTime);
|
||||
|
||||
/**
|
||||
* Obtains the time when a notification is delivered.
|
||||
* @return the time in milliseconds.
|
||||
*/
|
||||
int64_t GetDeliveryTime() const;
|
||||
|
||||
/**
|
||||
* Checks whether the notification delivery time is displayed for this notification.
|
||||
* @return true if the time is displayed; returns false otherwise.
|
||||
*/
|
||||
bool IsShowDeliveryTime() const;
|
||||
|
||||
/**
|
||||
* Sets whether to show the notification delivery time for this notification.
|
||||
* This method is valid only when the notification delivery time has been set by calling setDeliveryTime(int64_t).
|
||||
* @param showDeliveryTime Specifies whether to show the notification delivery time.
|
||||
*/
|
||||
void SetShowDeliveryTime(bool showDeliveryTime);
|
||||
|
||||
/**
|
||||
* Adds a NotificationActionButton to this notification.
|
||||
* The system typically places action buttons next to the notification content.
|
||||
* Each action button must contain an icon, a title, and an WantAgent. When a notification is expanded,
|
||||
* a maximum of three action buttons can be displayed from left to right in the order they were added.
|
||||
* When the notification is collapsed, no action buttons will be displayed.
|
||||
* @param actionButton Indicates the NotificationActionButton object to add.
|
||||
*/
|
||||
void AddActionButton(const std::shared_ptr<NotificationActionButton> &actionButton);
|
||||
|
||||
/**
|
||||
* Obtains the list of all NotificationActionButton objects included in this notification.
|
||||
* @return the list of NotificationActionButton objects.
|
||||
*/
|
||||
const std::vector<std::shared_ptr<NotificationActionButton>> GetActionButtons() const;
|
||||
|
||||
/**
|
||||
* Checks whether the platform is allowed to generate contextual NotificationActionButton objects for this
|
||||
* notification.
|
||||
* @return true if the platform is allowed to generate contextual NotificationActionButton objects;
|
||||
* returns false otherwise.
|
||||
*/
|
||||
bool IsPermitSystemGeneratedContextualActionButtons() const;
|
||||
|
||||
/**
|
||||
* Sets whether to allow the platform to generate contextual NotificationActionButton objects for this notification.
|
||||
* @param permitted Specifies whether to allow the platform to generate contextual NotificationActionButton objects.
|
||||
* The default value true indicates that the platform is allowed to generate contextual action buttons,
|
||||
* and the value false indicates not.
|
||||
*/
|
||||
void SetPermitSystemGeneratedContextualActionButtons(bool permitted);
|
||||
|
||||
/**
|
||||
* Adds a MessageUser object and associates it with this notification.
|
||||
* @param messageUser Indicates the MessageUser object to add.
|
||||
*/
|
||||
void AddMessageUser(const std::shared_ptr<MessageUser> &messageUser);
|
||||
|
||||
/**
|
||||
* Obtains all MessageUser objects associated with this notification.
|
||||
* @return the list of MessageUser objects associated with this notification.
|
||||
*/
|
||||
const std::vector<std::shared_ptr<MessageUser>> GetMessageUsers() const;
|
||||
|
||||
/**
|
||||
* Checks whether this notification is set to alert only once,
|
||||
* which means that sound or vibration will no longer be played
|
||||
* for notifications with the same ID upon their updates.
|
||||
* @return true if this notification is set to alert only once; returns false otherwise.
|
||||
*/
|
||||
bool IsAlertOneTime() const;
|
||||
|
||||
/**
|
||||
* Sets whether to have this notification alert only once.
|
||||
* If a notification alerts only once, sound or vibration will no longer be played
|
||||
* for notifications with the same ID upon their updates after they are published.
|
||||
* @param isAlertOnce Specifies whether to have this notification alert only once.
|
||||
*/
|
||||
void SetAlertOneTime(bool isAlertOnce);
|
||||
|
||||
/**
|
||||
* Sets the time to delete a notification.
|
||||
* @param deletedTime Indicates the time in milliseconds.
|
||||
* The default value is 0, indicating that the notification will not be automatically deleted.
|
||||
* To enable the notification to be automatically deleted, set this parameter to an integer greater than 0.
|
||||
*/
|
||||
void SetAutoDeletedTime(int64_t deletedTime);
|
||||
|
||||
/**
|
||||
* Obtains the period during which a notification is deleted.
|
||||
* @return the period in milliseconds.
|
||||
*/
|
||||
int64_t GetAutoDeletedTime() const;
|
||||
|
||||
/**
|
||||
* Sets the little icon of the notification.
|
||||
* @param littleIcon Indicates the icon of the notification.
|
||||
*/
|
||||
void SetLittleIcon(const std::shared_ptr<PixelMap> &littleIcon);
|
||||
|
||||
/**
|
||||
* Obtains the icon of the notification.
|
||||
* @return the notification icon.
|
||||
*/
|
||||
const std::shared_ptr<PixelMap> GetLittleIcon() const;
|
||||
|
||||
/**
|
||||
* Sets the large icon of this notification, which is usually displayed on the right of the notification.
|
||||
* @param bigIcon Indicates the large icon to set. It must be a PixelMap object.
|
||||
*/
|
||||
void SetBigIcon(const std::shared_ptr<PixelMap> &bigIcon);
|
||||
|
||||
/**
|
||||
* Obtains the large icon of this notification.
|
||||
* @return the large icon of this notification.
|
||||
*/
|
||||
const std::shared_ptr<PixelMap> GetBigIcon() const;
|
||||
|
||||
/**
|
||||
* Sets the classification of this notification, which describes the purpose of this notification.
|
||||
* Notification classifications are used to filter and sort notifications.
|
||||
* @param classification Indicates the notification classification predefined in the system,
|
||||
* such as CLASSIFICATION_CALL or CLASSIFICATION_NAVIGATION etc.
|
||||
*/
|
||||
void SetClassification(const std::string &classification);
|
||||
|
||||
/**
|
||||
* Obtains the classification of this notification.
|
||||
* @return the classification of this notification.
|
||||
*/
|
||||
std::string GetClassification() const;
|
||||
|
||||
/**
|
||||
* Sets the background color of this notification.
|
||||
* This method is valid only when background color has been enabled by calling setColorEnabled(bool).
|
||||
* @param color Indicates the background color to set. For details about the value range, see Color.
|
||||
*/
|
||||
void SetColor(int32_t color);
|
||||
|
||||
/**
|
||||
* Obtains the background color of this notification.
|
||||
* The return value, except for the default color COLOR_DEFAULT,
|
||||
* is the bitwise OR operation result of 0xFF000000 and the ARGB value set by setColor(int32_t).
|
||||
* @return the background color of this notification.
|
||||
*/
|
||||
int32_t GetColor() const;
|
||||
|
||||
/**
|
||||
* Checks whether background color is enabled for this notification.
|
||||
* @return true if background color is enabled; returns false otherwise.
|
||||
*/
|
||||
bool IsColorEnabled();
|
||||
|
||||
/**
|
||||
* Sets whether to enable background color for this notification.
|
||||
* If colorEnabled is set to true, this method takes effect only
|
||||
* when the notification content type has been set to NotificationRequest.
|
||||
* NotificationMediaContent in the NotificationRequest object through
|
||||
* NotificationRequest::setContent(NotificationContent) and an AVToken has been attached to
|
||||
* that NotificationMediaContent object through NotificationMediaContent::setAVToken(AVToken).
|
||||
* @param colorEnabled Specifies whether to enable background color.
|
||||
*/
|
||||
void SetColorEnabled(bool colorEnabled);
|
||||
|
||||
/**
|
||||
* Sets the notification content type to NotificationNormalContent, NotificationLongTextContent,
|
||||
* or NotificationPictureContent etc.
|
||||
* Each content type indicates a particular notification content.
|
||||
* @param content Indicates the notification content type.
|
||||
*/
|
||||
void SetContent(const std::shared_ptr<NotificationContent> &content);
|
||||
|
||||
/**
|
||||
* Obtains the notification content set by calling the setContent(NotificationContent) method.
|
||||
* @return the notification content.
|
||||
*/
|
||||
const std::shared_ptr<NotificationContent> GetContent() const;
|
||||
|
||||
/**
|
||||
* Obtains the notification type.
|
||||
* @return the type of the current notification, which can be
|
||||
* NotificationContent::Type::BASIC_TEXT,
|
||||
* NotificationContent::Type::LONG_TEXT,
|
||||
* NotificationContent::Type::PICTURE,
|
||||
* NotificationContent::Type::CONVERSATION,
|
||||
* NotificationContent::Type::MULTILINE,
|
||||
* or NotificationContent::Type::MEDIA.
|
||||
*/
|
||||
NotificationContent::Type GetNotificationType() const;
|
||||
|
||||
/**
|
||||
* Checks whether the notification creation time is displayed as a countdown timer.
|
||||
* @return true if the time is displayed as a countdown timer; returns false otherwise.
|
||||
*/
|
||||
bool IsCountdownTimer() const;
|
||||
|
||||
/**
|
||||
* Sets whether to show the notification creation time as a countdown timer.
|
||||
* This method is valid only when setShowStopwatch(boolean) is set to true.
|
||||
* @param isCountDown Specifies whether to show the notification creation time as a countdown timer.
|
||||
*/
|
||||
void SetCountdownTimer(bool isCountDown);
|
||||
|
||||
/**
|
||||
* Sets the custom view to be displayed when this notification is expanded.
|
||||
* @param view Indicates the ComponentProvider object defining the custom view.
|
||||
*/
|
||||
void SetCustomBigView(const std::shared_ptr<ComponentProvider> &view);
|
||||
|
||||
/**
|
||||
* Obtains the ComponentProvider object defining the custom view to be displayed when this notification is expanded
|
||||
* The ComponentProvider object is set in setCustomBigView(ComponentProvider).
|
||||
* @return the ComponentProvider object defining the custom view.
|
||||
*/
|
||||
const std::shared_ptr<ComponentProvider> GetCustomBigView() const;
|
||||
|
||||
/**
|
||||
* Sets the custom view to be displayed when this notification is shown as a floating window at the top of the
|
||||
* screen
|
||||
* @param view Indicates the ComponentProvider object defining the custom view.
|
||||
*/
|
||||
void SetCustomFloatView(const std::shared_ptr<ComponentProvider> &view);
|
||||
|
||||
/**
|
||||
* Obtains the ComponentProvider object defining the custom view to be displayed
|
||||
* when this notification is shown as a floating window at the top of the screen.
|
||||
* The ComponentProvider object is set in setCustomFloatView(ComponentProvider).
|
||||
* @return the ComponentProvider object defining the custom view.
|
||||
*/
|
||||
const std::shared_ptr<ComponentProvider> GetCustomFloatView() const;
|
||||
|
||||
/**
|
||||
* Sets the custom view of this notification.
|
||||
* @param view Indicates the ComponentProvider object defining the custom view.
|
||||
*/
|
||||
void SetCustomView(const std::shared_ptr<ComponentProvider> &view);
|
||||
|
||||
/**
|
||||
* Obtains the ComponentProvider object defining the custom view set in this notification.
|
||||
* The ComponentProvider object is set in setCustomView(ComponentProvider).
|
||||
* @return the ComponentProvider object defining the custom view.
|
||||
*/
|
||||
const std::shared_ptr<ComponentProvider> GetCustomView() const;
|
||||
|
||||
/**
|
||||
* Sets the group alert type for this notification,
|
||||
* which determines how the group overview and other notifications in a group are published.
|
||||
* The group information must have been set by calling setGroupValue(string).
|
||||
* Otherwise, this method does not take effect.
|
||||
* @param type Indicates the group alert type to set. which can be GroupAlertType::ALL (default value),
|
||||
* GroupAlertType::OVERVIEW, or GroupAlertType::CHILD etc.
|
||||
*/
|
||||
void SetGroupAlertType(NotificationRequest::GroupAlertType type);
|
||||
|
||||
/**
|
||||
* Obtains the group alert type of this notification.
|
||||
* @return the group alert type of this notification.
|
||||
*/
|
||||
NotificationRequest::GroupAlertType GetGroupAlertType() const;
|
||||
|
||||
/**
|
||||
* Checks whether this notification is the group overview.
|
||||
* @return true if this notification is the group overview; returns false otherwise.
|
||||
*/
|
||||
bool IsGroupOverview() const;
|
||||
|
||||
/**
|
||||
* Sets whether to use this notification as the overview of its group.
|
||||
* This method helps display the notifications that are assigned the same group value by calling
|
||||
* setGroupValue(string) as one stack in the notification bar.
|
||||
* Each group requires only one group overview. After a notification is set as the group overview,
|
||||
* it becomes invisible if another notification in the same group is published.
|
||||
* @param overView Specifies whether to set this notification as the group overview.
|
||||
*/
|
||||
void SetGroupOverview(bool overView);
|
||||
|
||||
/**
|
||||
* Sets the group information for this notification.
|
||||
* If no groups are set for notifications, all notifications from the same application will appear
|
||||
* in the notification bar as one stack with the number of stacked notifications displayed.
|
||||
* If notifications are grouped and there are multiple groups identified by different groupValue,
|
||||
* notifications with different groupValue will appear in separate stacks.
|
||||
* Note that one of the notifications in a group must be set as the overview of its group by calling
|
||||
* setGroupOverview(bool), and other notifications are considered as child notifications.
|
||||
* Otherwise, notifications will not be displayed as one group even if they are assigned the same groupValue by
|
||||
* calling setGroupValue(string).
|
||||
* @param groupValue Specifies whether to set this notification as the group overview.
|
||||
*/
|
||||
void SetGroupValue(const std::string &groupValue);
|
||||
|
||||
/**
|
||||
* Obtains the group information about this notification.
|
||||
* @return the group information about this notification.
|
||||
*/
|
||||
std::string GetGroupValue() const;
|
||||
|
||||
/**
|
||||
* Checks whether this notification is relevant only to the local device and cannot be displayed on remote devices.
|
||||
* @return true if this notification is relevant only to the local device; returns false otherwise.
|
||||
*/
|
||||
bool IsOnlyLocal() const;
|
||||
|
||||
/**
|
||||
* Sets whether this notification is relevant only to the local device and cannot be displayed on remote devices.
|
||||
* This method takes effect only for notifications published by calling
|
||||
* NotificationHelper::publishNotification(NotificationRequest) or
|
||||
* NotificationHelper#publishNotification(string, NotificationRequest).
|
||||
* Notifications published using NotificationHelper::publishNotification(NotificationRequest, string)
|
||||
* in a distributed system will not be affected.
|
||||
* @param flag Specifies whether this notification can be displayed only on the local device.
|
||||
*/
|
||||
void SetOnlyLocal(bool flag);
|
||||
|
||||
/**
|
||||
* Sets the text that will be displayed as a link to the settings of the application.
|
||||
* Calling this method is invalid if the notification content type has been set to NotificationLongTextContent
|
||||
* or NotificationPictureContent in the NotificationRequest object through setContent(NotificationContent).
|
||||
* @param text Indicates the text to be included. You can set it to any valid link.
|
||||
*/
|
||||
void SetSettingsText(const std::string &text);
|
||||
|
||||
/**
|
||||
* Obtains the text that will be displayed as a link to the settings of the application.
|
||||
* @return the text displayed as the link to the application settings.
|
||||
*/
|
||||
std::string GetSettingsText() const;
|
||||
|
||||
/**
|
||||
* Deprecated.
|
||||
* Obtains the time when a notification is created.
|
||||
* @return the time in milliseconds.
|
||||
*/
|
||||
int64_t GetCreateTime() const;
|
||||
|
||||
/**
|
||||
* Checks whether the notification creation time is displayed as a stopwatch.
|
||||
* @return true if the time is displayed as a stopwatch; returns false otherwise.
|
||||
*/
|
||||
bool IsShowStopwatch() const;
|
||||
|
||||
/**
|
||||
* Sets whether to show the notification creation time as a stopwatch.
|
||||
* This method is valid only when the notification creation time has been set by calling setDeliveryTime(int64_t).
|
||||
* When the notification creation time is set to be shown as a stopwatch, the interval between the current time
|
||||
* and the creation time set by setDeliveryTime(int64_t) is dynamically displayed for this notification
|
||||
* in Minutes: Seconds format. If the interval is longer than 60 minutes, it will be displayed
|
||||
* in Hours: Minutes: Seconds format. If this method and setShowDeliveryTime(boolean) are both set to true, only
|
||||
* this method takes effect, that is, the notification creation time will be shown as a stopwatch.
|
||||
* @param isShow Specifies whether to show the notification creation time as a stopwatch.
|
||||
*/
|
||||
void SetShowStopwatch(bool isShow);
|
||||
|
||||
/**
|
||||
* Sets the slot type of a notification to bind the created NotificationSlot object.
|
||||
* You can use NotificationSlot to create a slot object,
|
||||
* then set the notification vibration and lock screen display, and use the current method to bind the slot.
|
||||
* The value must be the type of an existing NotificationSlot object.
|
||||
* @param slotType Indicates the unique type of the NotificationSlot object.
|
||||
*/
|
||||
void SetSlotType(NotificationConstant::SlotType slotType);
|
||||
|
||||
/**
|
||||
* Obtains the slot type of a notification set by calling the setSlotType(string) method.
|
||||
* @return the notification slot type.
|
||||
*/
|
||||
NotificationConstant::SlotType GetSlotType() const;
|
||||
|
||||
/**
|
||||
* Sets a key used for sorting notifications from the same application bundle.
|
||||
* @param key Indicates the key to set.
|
||||
*/
|
||||
void SetSortingKey(const std::string &key);
|
||||
|
||||
/**
|
||||
* Obtains the key used for sorting notifications from the same application bundle.
|
||||
* @return the key for sorting notifications.
|
||||
*/
|
||||
std::string GetSortingKey() const;
|
||||
|
||||
/**
|
||||
* Sets the scrolling text to be displayed in the status bar when this notification is received.
|
||||
* @param text Indicates the scrolling text to be displayed.
|
||||
*/
|
||||
void SetStatusBarText(const std::string &text);
|
||||
|
||||
/**
|
||||
* Obtains the scrolling text that will be displayed in the status bar when this notification is received.
|
||||
* @return the scrolling notification text.
|
||||
*/
|
||||
std::string GetStatusBarText() const;
|
||||
|
||||
/**
|
||||
* Checks whether the current notification will be automatically dismissed after being tapped.
|
||||
* @return true if the notification will be automatically dismissed; returns false otherwise.
|
||||
*/
|
||||
bool IsTapDismissed() const;
|
||||
|
||||
/**
|
||||
* Sets whether to automatically dismiss a notification after being tapped.
|
||||
* If you set tapDismissed to true,
|
||||
* you must call the setWantAgent(WantAgent) method to make the settings take effect.
|
||||
* @param isDismissed Specifies whether a notification will be automatically dismissed after being tapped.
|
||||
*/
|
||||
void SetTapDismissed(bool isDismissed);
|
||||
|
||||
/**
|
||||
* Sets the notification display effect, including whether to display this notification on the lock screen,
|
||||
* and how it will be presented if displayed.
|
||||
* For details, see NotificationSlot::setLockscreenVisibleness(int).
|
||||
* If the lock screen display effect is set for a NotificationRequest object
|
||||
* and its associated NotificationSlot object, the display effect set in the NotificationRequest object prevails.
|
||||
* @param type Indicates the notification display effect on the lock screen.
|
||||
*/
|
||||
void SetVisibleness(NotificationConstant::VisiblenessType type);
|
||||
|
||||
/**
|
||||
* Obtains the display effect of this notification on the lock screen.
|
||||
* @return the display effect of this notification on the lock screen.
|
||||
*/
|
||||
NotificationConstant::VisiblenessType GetVisibleness() const;
|
||||
|
||||
/**
|
||||
* Sets the badge icon style for this notification.
|
||||
* This method does not take effect if the home screen does not support badge icons.
|
||||
* @param style Indicates the type of the badge icon to be displayed for this notification.
|
||||
* The value must be BadgeStyle::NONE, BadgeStyle::LITTLE, or BadgeStyle::BIG.
|
||||
*/
|
||||
void SetBadgeIconStyle(NotificationRequest::BadgeStyle style);
|
||||
|
||||
/**
|
||||
* Obtains the badge icon style of this notification.
|
||||
* @return the badge icon style of this notification.
|
||||
*/
|
||||
NotificationRequest::BadgeStyle GetBadgeIconStyle() const;
|
||||
|
||||
/**
|
||||
* Sets the shortcut ID for this notification.
|
||||
* After a shortcut ID is set for a notification, the notification will be associated with the corresponding
|
||||
* home-screen shortcut, and the shortcut will be hidden when the Home application displays the badge or content
|
||||
* of the notification.
|
||||
* @param shortcutId Indicates the shortcut ID to set.
|
||||
*/
|
||||
void SetShortcutId(const std::string &shortcutId);
|
||||
|
||||
/**
|
||||
* Obtains the shortcut ID associated with this notification.
|
||||
* @return the shortcut ID of this notification.
|
||||
*/
|
||||
std::string GetShortcutId() const;
|
||||
|
||||
/**
|
||||
* Sets whether this notification is displayed as a floating icon on top of the screen.
|
||||
* @param floatingIcon Specifies whether a notification is displayed as a floating icon on top of the screen.
|
||||
*/
|
||||
void SetFloatingIcon(bool floatingIcon);
|
||||
|
||||
/**
|
||||
* Checks whether this notification is displayed as a floating icon on top of the screen.
|
||||
* @return true if this notification is displayed as a floating icon; returns false otherwise.
|
||||
*/
|
||||
bool IsFloatingIcon() const;
|
||||
|
||||
/**
|
||||
* Sets how the progress bar will be displayed for this notification.
|
||||
* A progress bar is usually used in notification scenarios such as download.
|
||||
* @param progress Indicates the current value displayed for the notification progress bar.
|
||||
* @param progressMax Indicates the maximum value displayed for the notification progress bar.
|
||||
* @param indeterminate Specifies whether the progress bar is indeterminate. The value true indicates that
|
||||
* the progress bar is indeterminate, and users cannot see its current and maximum values.
|
||||
*/
|
||||
void SetProgressBar(int32_t progress, int32_t progressMax, bool indeterminate);
|
||||
|
||||
/**
|
||||
* Obtains the maximum value displayed for the progress bar of this notification.
|
||||
* @return the maximum value of the notification progress bar.
|
||||
*/
|
||||
int32_t GetProgressMax() const;
|
||||
|
||||
/**
|
||||
* Obtains the current value displayed for the progress bar of this notification.
|
||||
* @return the current value of the notification progress bar.
|
||||
*/
|
||||
int32_t GetProgressValue() const;
|
||||
|
||||
/**
|
||||
* Checks whether the progress bar of this notification is indeterminate.
|
||||
* @return true if the notification progress bar is indeterminate; returns false otherwise.
|
||||
*/
|
||||
bool IsProgressIndeterminate() const;
|
||||
|
||||
/**
|
||||
* Sets the most recent NotificationUserInput records that have been sent through this notification.
|
||||
* The most recent input must be stored in index 0,
|
||||
* the second most recent input must be stored in index 1, and so on.
|
||||
* The system displays a maximum of five inputs.
|
||||
* @param text Indicates the list of inputs to set.
|
||||
*/
|
||||
void SetNotificationUserInputHistory(const std::vector<std::string> &text);
|
||||
|
||||
/**
|
||||
* Obtains the most recent NotificationUserInput records
|
||||
* @return the most recent NotificationUserInput records
|
||||
*/
|
||||
std::vector<std::string> GetNotificationUserInputHistory() const;
|
||||
|
||||
/**
|
||||
* Sets an alternative notification to be displayed on the lock screen for this notification.
|
||||
* The display effect (whether and how this alternative notification will be displayed) is subject to
|
||||
* the configuration in NotificationSlot::setLockscreenVisibleness(int).
|
||||
* @param other Indicates the alternative notification to be displayed on the lock screen.
|
||||
*/
|
||||
void SetPublicNotification(const std::shared_ptr<NotificationRequest> &other);
|
||||
|
||||
/**
|
||||
* Obtains the alternative notification to be displayed on the lock screen for this notification.
|
||||
* @return the alternative notification to be displayed on the lock screen for this notification.
|
||||
*/
|
||||
const std::shared_ptr<NotificationRequest> GetPublicNotification() const;
|
||||
|
||||
/**
|
||||
* Obtains the unique hash code of a notification in the current application.
|
||||
* To obtain a valid hash code, you must have subscribed to and received the notification.
|
||||
* A valid notification hash code is a string composed of multiple attributes separated by an underscore (_),
|
||||
* including the notification ID, creator bundle name, creator UID, and owner bundle name.
|
||||
* @return the hash code of the notification.
|
||||
*/
|
||||
std::string GetNotificationHashCode() const;
|
||||
|
||||
/**
|
||||
* Sets the bundle name of the notification owner.
|
||||
* The notification owner refers to the application that subscribes to the notification.
|
||||
* @param ownerName the bundle name of the notification owner.
|
||||
*/
|
||||
void SetOwnerBundleName(const std::string &ownerName);
|
||||
|
||||
/**
|
||||
* Obtains the bundle name of the notification owner.
|
||||
* The notification owner refers to the application that subscribes to the notification.
|
||||
* @return the bundle name of the notification owner.
|
||||
*/
|
||||
std::string GetOwnerBundleName() const;
|
||||
|
||||
/**
|
||||
* Sets the bundle name of the notification creator.
|
||||
* The notification creator refers to the application that publishes the notification.
|
||||
* @param creatorName the bundle name of the notification creator.
|
||||
*/
|
||||
void SetCreatorBundleName(const std::string &creatorName);
|
||||
|
||||
/**
|
||||
* Obtains the bundle name of the notification creator.
|
||||
* The notification creator refers to the application that publishes the notification.
|
||||
* @return the bundle name of the notification creator.
|
||||
*/
|
||||
std::string GetCreatorBundleName() const;
|
||||
|
||||
/**
|
||||
* Sets the PID of the notification creator.
|
||||
* @param pid the PID of the notification creator.
|
||||
*/
|
||||
void SetCreatorPid(pid_t pid);
|
||||
|
||||
/**
|
||||
* Obtains the PID of the notification creator.
|
||||
* @return the PID of the notification creator.
|
||||
*/
|
||||
pid_t GetCreatorPid() const;
|
||||
|
||||
/**
|
||||
* Sets the UID of the notification creator.
|
||||
* @param uid the UID of the notification creator.
|
||||
*/
|
||||
void SetCreatorUid(uid_t uid);
|
||||
|
||||
/**
|
||||
* Obtains the UID of the notification creator.
|
||||
* @return the UID of the notification creator.
|
||||
*/
|
||||
uid_t GetCreatorUid() const;
|
||||
|
||||
/**
|
||||
* Sets the label of this notification.
|
||||
* @param label the label of this notification.
|
||||
*/
|
||||
void SetLabel(const std::string &label);
|
||||
|
||||
/**
|
||||
* Obtains the label of this notification.
|
||||
* The label is set via NotificationHelper::publishNotification(string, NotificationRequest).
|
||||
* This method returns null if no specific label is set for this notification.
|
||||
* @return the label of this notification.
|
||||
*/
|
||||
std::string GetLabel() const;
|
||||
|
||||
/**
|
||||
* Returns a string representation of the object.
|
||||
* @return a string representation of the object.
|
||||
*/
|
||||
std::string Dump();
|
||||
|
||||
/**
|
||||
* Marshal a NotificationRequest object into a Parcel.
|
||||
* @param parcel the object into the parcel
|
||||
*/
|
||||
virtual bool Marshalling(Parcel &parcel) const override;
|
||||
|
||||
/**
|
||||
* Unmarshal object from a Parcel.
|
||||
* @return the NotificationRequest
|
||||
*/
|
||||
static NotificationRequest *Unmarshalling(Parcel &parcel);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Read a NotificationRequest object from a Parcel.
|
||||
* @param parcel the parcel
|
||||
*/
|
||||
bool ReadFromParcel(Parcel &parcel);
|
||||
|
||||
/**
|
||||
* Obtains the current system time in milliseconds.
|
||||
* @return the current system time in milliseconds.
|
||||
*/
|
||||
int64_t GetNowSysTime();
|
||||
|
||||
private:
|
||||
int32_t notificationId_{0};
|
||||
int32_t color_{NotificationRequest::COLOR_DEFAULT};
|
||||
int32_t badgeNumber_{0};
|
||||
int32_t progressValue_{0};
|
||||
int32_t progressMax_{0};
|
||||
int64_t createTime_{0};
|
||||
int64_t deliveryTime_{0};
|
||||
int64_t autoDeletedTime_{0};
|
||||
|
||||
pid_t creatorPid_{0};
|
||||
uid_t creatorUid_{0};
|
||||
|
||||
std::string settingsText_{};
|
||||
std::string creatorBundleName_{};
|
||||
std::string ownerBundleName_{};
|
||||
std::string groupValue_{};
|
||||
std::string statusBarText_{};
|
||||
std::string label_{};
|
||||
std::string shortcutId_{};
|
||||
std::string sortingKey_{};
|
||||
std::string classification_{};
|
||||
|
||||
NotificationConstant::SlotType slotType_{NotificationConstant::SlotType::OTHER};
|
||||
NotificationRequest::GroupAlertType groupAlertType_{NotificationRequest::GroupAlertType::ALL};
|
||||
NotificationConstant::VisiblenessType visiblenessType_{NotificationConstant::VisiblenessType::NO_OVERRIDE};
|
||||
NotificationRequest::BadgeStyle badgeStyle_{NotificationRequest::BadgeStyle::NONE};
|
||||
NotificationContent::Type notificationContentType_{NotificationContent::Type::NONE};
|
||||
|
||||
bool showDeliveryTime_{false};
|
||||
bool tapDismissed_{false};
|
||||
bool colorEnabled_{false};
|
||||
bool alertOneTime_{false};
|
||||
bool showStopwatch_{false};
|
||||
bool isCountdown_{false};
|
||||
bool inProgress_{false};
|
||||
bool groupOverview_{false};
|
||||
bool progressIndeterminate_{false};
|
||||
bool unremovable_{false};
|
||||
bool floatingIcon_{false};
|
||||
bool onlyLocal_{false};
|
||||
bool permitted_{true};
|
||||
|
||||
std::shared_ptr<AppExecFwk::Context> context_{};
|
||||
std::shared_ptr<WantAgent::WantAgent> wantAgent_{};
|
||||
std::shared_ptr<WantAgent::WantAgent> removalWantAgent_{};
|
||||
std::shared_ptr<WantAgent::WantAgent> maxScreenWantAgent_{};
|
||||
std::shared_ptr<AAFwk::WantParams> additionalParams_{};
|
||||
std::shared_ptr<PixelMap> littleIcon_{};
|
||||
std::shared_ptr<PixelMap> bigIcon_{};
|
||||
std::shared_ptr<NotificationContent> notificationContent_{};
|
||||
std::shared_ptr<ComponentProvider> customBigView_{};
|
||||
std::shared_ptr<ComponentProvider> customFloatView_{};
|
||||
std::shared_ptr<ComponentProvider> customView_{};
|
||||
std::shared_ptr<NotificationRequest> publicNotification_{};
|
||||
|
||||
std::vector<std::shared_ptr<NotificationActionButton>> actionButtons_{};
|
||||
std::vector<std::shared_ptr<MessageUser>> messageUsers_{};
|
||||
std::vector<std::string> userInputHistory_{};
|
||||
};
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_REQUEST_H
|
||||
@@ -0,0 +1,372 @@
|
||||
/*
|
||||
* 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_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_SLOT_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_SLOT_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "notification_content.h"
|
||||
#include "notification_request.h"
|
||||
#include "parcel.h"
|
||||
#include "uri.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
class NotificationSlot : public Parcelable {
|
||||
public:
|
||||
enum NotificationLevel {
|
||||
LEVEL_NONE, // the notification function is disabled.
|
||||
LEVEL_MIN, // the notifications function is disabled on the notification panel,
|
||||
// with no banner or prompt tone
|
||||
LEVEL_LOW, // the notifications are displayed on the notification panel,
|
||||
// with no banner or prompt tone
|
||||
LEVEL_DEFAULT, // the notification function is enabled and notifications are displayed
|
||||
// on the notification panel, with a banner and a prompt tone.
|
||||
LEVEL_HIGH, // the notifications are displayed on the notification panel,
|
||||
// with a banner and a prompt tone
|
||||
LEVEL_UNDEFINED, // the notification does not define an level.
|
||||
};
|
||||
|
||||
/**
|
||||
* A constructor used to initialize the type of a NotificationSlot object.
|
||||
*
|
||||
* @param type Specifies the type of the NotificationSlot object,
|
||||
*/
|
||||
NotificationSlot(NotificationConstant::SlotType type = NotificationConstant::SlotType::CUSTOM);
|
||||
|
||||
/**
|
||||
* Default deconstructor used to deconstruct.
|
||||
*/
|
||||
~NotificationSlot();
|
||||
|
||||
/**
|
||||
* Obtains whether the notification light is enabled in a NotificationSlot object,
|
||||
* which is set by SetEnableLight(bool).
|
||||
*
|
||||
* @return Returns true if the notification light is enabled; returns false otherwise.
|
||||
*/
|
||||
bool CanEnableLight() const;
|
||||
|
||||
/**
|
||||
* Specifies whether to enable the notification light when a notification is received on the device,
|
||||
* provided that this device has a notification light.
|
||||
* @note SetEnableLight must be set before the NotificationHelper:AddNotificationSlot(NotificationSlot) method is
|
||||
* called. Otherwise, the settings will not take effect.
|
||||
*
|
||||
* @param isLightEnabled Specifies whether to enable the pulse notification light.
|
||||
* The value true indicates to enable the notification light,
|
||||
* and the value false indicates not to enable it.
|
||||
*/
|
||||
void SetEnableLight(bool isLightEnabled);
|
||||
|
||||
/**
|
||||
* Obtains the vibration status of a NotificationSlot object,
|
||||
* which is set by SetEnableVibration(bool).
|
||||
*
|
||||
* @return Returns true if vibration is enabled; returns false otherwise.
|
||||
*/
|
||||
bool CanVibrate() const;
|
||||
|
||||
/**
|
||||
* Sets whether to enable vibration when a notification is received.
|
||||
* @note SetEnableVibration(bool) must be set before the NotificationHelper::AddNotificationSlot(NotificationSlot)
|
||||
* method is called. Otherwise, the settings will not take effect.
|
||||
*
|
||||
* @param vibration Indicates whether to enable vibration when a notification is received.
|
||||
* If the value is true, vibration is enabled; if the value is false, vibration is disabled.
|
||||
*/
|
||||
void SetEnableVibration(bool vibration);
|
||||
|
||||
/**
|
||||
* Obtains the description of a NotificationSlot object, which is set by SetDescription(string).
|
||||
*
|
||||
* @return Returns the description of the NotificationSlot object.
|
||||
*/
|
||||
std::string GetDescription() const;
|
||||
|
||||
/**
|
||||
* Sets the description for a NotificationSlot object.
|
||||
* @note The setting of setDescription is effective regardless of whether a NotificationSlot object has been created
|
||||
* by NotificationHelper::AddNotificationSlot(NotificationSlot).
|
||||
*
|
||||
* @param description Describes the NotificationSlot object.
|
||||
* The description is visible to users and its length must not exceed 1000 characters
|
||||
* (the excessive part is automatically truncated).
|
||||
*/
|
||||
void SetDescription(const std::string &description);
|
||||
|
||||
/**
|
||||
* Obtains the ID of a NotificationSlot object.
|
||||
*
|
||||
* @return Returns the ID of the NotificationSlot object,
|
||||
* which is set by NotificationSlot(string, string, NotificationLevel).
|
||||
*/
|
||||
std::string GetId() const;
|
||||
|
||||
/**
|
||||
* Obtains the color of the notification light in a NotificationSlot object,
|
||||
* which is set by SetLedLightColor(int32_t).
|
||||
*
|
||||
* @return Returns the color of the notification light.
|
||||
*/
|
||||
int32_t GetLedLightColor() const;
|
||||
|
||||
/**
|
||||
* Sets the color of the notification light to flash when a notification is received on the device,
|
||||
* provided that this device has a notification light and setEnableLight is called with the value true.
|
||||
* @note SetLedLightColor must be set before the NotificationHelper::AddNotificationSlot(NotificationSlot) method is
|
||||
* called. Otherwise, the settings will not take effect.
|
||||
*
|
||||
* @param color Indicates the color of the notification light.
|
||||
*/
|
||||
void SetLedLightColor(int32_t color);
|
||||
|
||||
/**
|
||||
* Obtains the level of a NotificationSlot object, which is set by SetLevel(NotificationLevel).
|
||||
*
|
||||
* @return Returns the level of the NotificationSlot object.
|
||||
*/
|
||||
NotificationLevel GetLevel() const;
|
||||
|
||||
/**
|
||||
* Sets the level of a NotificationSlot object.
|
||||
* @note SetLevel must be set before the NotificationHelper::AddNotificationSlot(NotificationSlot) method is called.
|
||||
* Otherwise, the settings will not take effect.
|
||||
*
|
||||
* @param level Specifies the level of the NotificationSlot object, which determines the notification display
|
||||
* effect. The value can be LEVEL_NONE, LEVEL_MIN, LEVEL_LOW, LEVEL_DEFAULT, or LEVEL_HIGH.
|
||||
*/
|
||||
void SetLevel(NotificationLevel level);
|
||||
|
||||
/**
|
||||
* Obtains the type of a NotificationSlot object, which is set by SetType(SlotType).
|
||||
*
|
||||
* @return Returns the Type of the NotificationSlot object.
|
||||
*/
|
||||
NotificationConstant::SlotType GetType() const;
|
||||
|
||||
/**
|
||||
* Sets the type of a NotificationSlot object.
|
||||
* @note Settype must be set before the NotificationHelper::AddNotificationSlot(NotificationSlot) method is called.
|
||||
* Otherwise, the settings will not take effect.
|
||||
*
|
||||
* @param type Specifies the type of the NotificationSlot object, which determines the notification remind mode.
|
||||
* The value can be DEFAULT, SOCIAL_COMMUNICATION, SERVICE_REMINDER, CONTENT_INFORMATION, or OTHER.
|
||||
*/
|
||||
void SetType(NotificationConstant::SlotType type);
|
||||
|
||||
/**
|
||||
* Obtains the notification display effect of a NotificationSlot object on the lock screen,
|
||||
* which is set by SetLockscreenVisibleness(int32_t).
|
||||
* @note This method specifies different effects for displaying notifications on the lock screen in order to protect
|
||||
* user privacy. The setting takes effect only when the lock screen notifications function is enabled for an
|
||||
* application in system notification settings.
|
||||
*
|
||||
* @return Returns the notification display effect of the NotificationSlot object on the lock screen.
|
||||
*/
|
||||
NotificationConstant::VisiblenessType GetLockScreenVisibleness() const;
|
||||
|
||||
/**
|
||||
* Sets whether and how to display notifications on the lock screen.
|
||||
*
|
||||
* @param visibleness Specifies the notification display effect on the lock screen, which can be set to
|
||||
* NO_OVERRIDE, PUBLIC, PRIVATE, or SECRET.
|
||||
*/
|
||||
void SetLockscreenVisibleness(NotificationConstant::VisiblenessType visibleness);
|
||||
|
||||
/**
|
||||
* Obtains the name of a NotificationSlot object.
|
||||
*
|
||||
* @return Returns the name of the NotificationSlot object, which is set by SetName(string).
|
||||
*/
|
||||
std::string GetName() const;
|
||||
|
||||
/**
|
||||
* Obtains the ID of the NotificationSlotGroup object to which this NotificationSlot object belongs,
|
||||
* which is set by SetSlotGroup(string).
|
||||
*
|
||||
* @return Returns the ID of the NotificationSlotGroup to which this NotificationSlot object belongs.
|
||||
*/
|
||||
std::string GetSlotGroup() const;
|
||||
|
||||
/**
|
||||
* Binds a NotificationSlot object to a specified NotificationSlotGroup.
|
||||
* @note SetSlotGroup must be called before the NotificationHelper::AddNotificationSlot(NotificationSlot) method is
|
||||
* called. Otherwise, this method will not take effect.
|
||||
* @param groupId Indicates the ID of the NotificationSlotGroup object to bind,
|
||||
* which must have been created by calling
|
||||
* NotificationHelper::AddNotificationSlotGroup(NotificationSlotGroup).
|
||||
*/
|
||||
void SetSlotGroup(const std::string &groupId);
|
||||
|
||||
/**
|
||||
* Obtains the prompt tone of a NotificationSlot object, which is set by SetSound(Uri).
|
||||
*
|
||||
* @return Returns the prompt tone of the NotificationSlot object.
|
||||
*/
|
||||
Uri GetSound() const;
|
||||
|
||||
/**
|
||||
* Sets a prompt tone for a NotificationSlot object, which will be played after a notification is received.
|
||||
* @note SetSound must be set before the NotificationHelper:AddNotificationSlot(NotificationSlot) method is called.
|
||||
* Otherwise, the settings will not take effect.
|
||||
*
|
||||
* @param sound Specifies the path for the prompt tone.
|
||||
*/
|
||||
void SetSound(const Uri &sound);
|
||||
|
||||
/**
|
||||
* Obtains the vibration style of notifications in this NotificationSlot.
|
||||
*
|
||||
* @return Returns the vibration style of this NotificationSlot.
|
||||
*/
|
||||
std::vector<int64_t> GetVibrationStyle() const;
|
||||
|
||||
/**
|
||||
* Sets the vibration style for notifications in this NotificationSlot.
|
||||
* @note If an empty array or null is passed to this method, the system then calls
|
||||
* SetEnableVibration(bool) with the input parameter set to false.
|
||||
* If a valid value is passed to this method, the system calls SetEnableVibration(bool) with the input
|
||||
* parameter set to true. This method takes effect only before
|
||||
* NotificationHelper::AddNotificationSlot(NotificationSlot) is called.
|
||||
*
|
||||
* @param vibration Indicates the vibration style to set.
|
||||
*/
|
||||
void SetVibrationStyle(const std::vector<int64_t> &vibration);
|
||||
|
||||
/**
|
||||
* Obtains whether DND mode is bypassed for a NotificationSlot object,
|
||||
* which is set by EnableBypassDnd(bool).
|
||||
*
|
||||
* @return Returns true if DND mode is bypassed; returns false otherwise.
|
||||
*/
|
||||
bool IsEnableBypassDnd() const;
|
||||
|
||||
/**
|
||||
* Sets whether to bypass Do not disturb (DND) mode in the system.
|
||||
* @note The setting of EnableBypassDnd takes effect only when the Allow interruptions function
|
||||
* is enabled for an application in system notification settings.
|
||||
*
|
||||
* @param isBypassDnd Specifies whether to bypass DND mode for an application.
|
||||
* If the value is true, DND mode is bypassed;
|
||||
* if the value is false, DND mode is not bypassed.
|
||||
*/
|
||||
void EnableBypassDnd(bool isBypassDnd);
|
||||
|
||||
/**
|
||||
* Obtains the application icon badge status of a NotificationSlot object,
|
||||
* which is set by EnableBadge(bool).
|
||||
*
|
||||
* @return Returns true if the application icon badge is enabled; returns false otherwise.
|
||||
*/
|
||||
bool IsShowBadge() const;
|
||||
|
||||
/**
|
||||
* Sets whether to display application icon badges (digits or dots in the corner of the application icon)
|
||||
* on the home screen after a notification is received.
|
||||
* @note EnableBadge must be set before the NotificationHelper:AddNotificationSlot(NotificationSlot) method is
|
||||
* called. Otherwise, the settings will not take effect.
|
||||
*
|
||||
* @param isShowBadge Specifies whether to display the application icon badge.
|
||||
* If the value is true, the application icon badge is enabled;
|
||||
* if the value is false, the application icon badge is disabled..
|
||||
*/
|
||||
void EnableBadge(bool isShowBadge);
|
||||
|
||||
/**
|
||||
* Dumps a string representation of the object.
|
||||
*
|
||||
* @return A string representation of the object.
|
||||
*/
|
||||
std::string Dump() const;
|
||||
|
||||
/**
|
||||
* Marshals a NotificationSlot object into a Parcel.
|
||||
*
|
||||
* @param parcel Indicates the Parcel object for marshalling.
|
||||
* @return Returns true if the marshalling is successful; returns false otherwise.
|
||||
*/
|
||||
virtual bool Marshalling(Parcel &parcel) const override;
|
||||
|
||||
/**
|
||||
* Unmarshals a NotificationSlot object from a Parcel.
|
||||
*
|
||||
* @param parcel Indicates the Parcel object for unmarshalling.
|
||||
* @return Returns true if the unmarshalling is successful; returns false otherwise.
|
||||
*/
|
||||
static NotificationSlot *Unmarshalling(Parcel &parcel);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Read NotificationSlot object from a Parcel.
|
||||
*
|
||||
* @param parcel the parcel
|
||||
* @return read from parcel success or fail
|
||||
*/
|
||||
bool ReadFromParcel(Parcel &parcel);
|
||||
|
||||
/**
|
||||
* Merge the contents of vector and output a string
|
||||
*
|
||||
* @param mergeVector The vector which will be merged
|
||||
* @return Returns the string that has contents of the vector
|
||||
*/
|
||||
std::string MergeVectorToString(const std::vector<int64_t> &mergeVector) const;
|
||||
|
||||
/**
|
||||
* If string length exceed 1000 characters, the excessive part is automatically truncated.
|
||||
*
|
||||
* @param in The sting which will be truncated
|
||||
* @return Returns the string that has been truncated.
|
||||
*/
|
||||
std::string TruncateString(const std::string &in);
|
||||
|
||||
/**
|
||||
* Sets the name of a NotificationSlot object.
|
||||
* @note The setting of SetName is effective regardless of whether a NotificationSlot object has been created by
|
||||
* NotificationHelper:AddNotificationSlot(NotificationSlot).
|
||||
*
|
||||
* @param name Specifies the name of the NotificationSlot object.
|
||||
* The name is visible to users, and its length must not exceed 1000 characters
|
||||
* (the excessive part is automatically truncated).
|
||||
*/
|
||||
void SetName(const std::string &name);
|
||||
|
||||
private:
|
||||
std::string id_;
|
||||
std::string name_;
|
||||
bool isLightEnabled_;
|
||||
bool isVibrationEnabled_;
|
||||
bool isShowBadge_ = true;
|
||||
bool isBypassDnd_;
|
||||
std::string description_;
|
||||
int32_t lightColor_ = 0;
|
||||
NotificationLevel level_;
|
||||
NotificationConstant::SlotType type_;
|
||||
NotificationConstant::VisiblenessType lockScreenVisibleness_{NotificationConstant::VisiblenessType::NO_OVERRIDE};
|
||||
std::string groupId_;
|
||||
Uri sound_;
|
||||
std::vector<int64_t> vibrationValues_;
|
||||
|
||||
// no object in parcel
|
||||
static constexpr int VALUE_NULL = -1;
|
||||
// object exist in parcel
|
||||
static constexpr int VALUE_OBJECT = 1;
|
||||
};
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_SLOT_H
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
#ifndef BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_SLOT_GROUP_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_SLOT_GROUP_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "notification_slot.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
class NotificationSlotGroup : public Parcelable {
|
||||
public:
|
||||
/**
|
||||
* Default constructor used to create a NotificationSlotGroup instance.
|
||||
*/
|
||||
NotificationSlotGroup();
|
||||
|
||||
/**
|
||||
* A constructor used to create a NotificationSlotGroup instance with the group ID and name initialized.
|
||||
*
|
||||
* @param id Indicates the ID of the NotificationSlotGroup.
|
||||
* The ID must be unique and its length must not exceed 1000 characters (the excess part is automatically
|
||||
* truncated).
|
||||
* @param name Indicates the name of the NotificationSlotGroup.
|
||||
* Its length must not exceed 1000 characters (the excess part is automatically truncated).
|
||||
*/
|
||||
NotificationSlotGroup(const std::string &id, const std::string &name);
|
||||
|
||||
/**
|
||||
* Default deconstructor used to deconstruct.
|
||||
*/
|
||||
~NotificationSlotGroup();
|
||||
|
||||
/**
|
||||
* Obtains the description of this NotificationSlotGroup object, which is set by SetDescription(string).
|
||||
*
|
||||
* @return Returns the description of this NotificationSlotGroup.
|
||||
*/
|
||||
std::string GetDescription() const;
|
||||
|
||||
/**
|
||||
* Obtains the ID of this NotificationSlotGroup object, which is set by NotificationSlotGroup(string, string).
|
||||
*
|
||||
* @return Returns the ID of this NotificationSlotGroup.
|
||||
*/
|
||||
std::string GetId() const;
|
||||
|
||||
/**
|
||||
* Obtains the name of this NotificationSlotGroup object, which is set by NotificationSlotGroup(string, string).
|
||||
*
|
||||
* @return Returns the name of this NotificationSlotGroup.
|
||||
*/
|
||||
std::string GetName() const;
|
||||
|
||||
/**
|
||||
* Obtains a list of notification slots bound to this NotificationSlotGroup object.
|
||||
* @note NotificationSlot::SetSlotGroup(string) is used to bind a notification slot to a notification slot group.
|
||||
*
|
||||
* @return Returns the list of notification slots bound to this NotificationSlotGroup.
|
||||
*/
|
||||
std::vector<NotificationSlot> GetSlots() const;
|
||||
|
||||
/**
|
||||
* Checks whether this NotificationSlotGroup is disabled.
|
||||
*
|
||||
* @return Returns true if this NotificationSlotGroup is disabled; returns false otherwise.
|
||||
*/
|
||||
bool IsDisabled() const;
|
||||
|
||||
/**
|
||||
* Sets the description for this NotificationSlotGroup object.
|
||||
*
|
||||
* @param description Describes this NotificationSlotGroup object.
|
||||
* Its length must not exceed 1000 characters (the excess part is automatically truncated).
|
||||
*/
|
||||
void SetDescription(const std::string &description);
|
||||
|
||||
/**
|
||||
* Dumps a string representation of the object.
|
||||
*
|
||||
* @return A string representation of the object.
|
||||
*/
|
||||
std::string Dump() const;
|
||||
|
||||
/**
|
||||
* Marshals NotificationSlotGroup objects and writes them into Parcel.
|
||||
*
|
||||
* @param parcel Indicates the Parcel object for marshalling.
|
||||
* @return Returns true if the marshalling is successful; returns false otherwise.
|
||||
*/
|
||||
virtual bool Marshalling(Parcel &parcel) const override;
|
||||
|
||||
/**
|
||||
* Unmarshals a NotificationSlotGroup object from a Parcel.
|
||||
*
|
||||
* @param parcel Indicates the Parcel object for unmarshalling.
|
||||
* @return Returns true if the unmarshalling is successful; returns false otherwise.
|
||||
*/
|
||||
static NotificationSlotGroup *Unmarshalling(Parcel &parcel);
|
||||
|
||||
/**
|
||||
* If string length exceed 1000 characters, the excessive part is automatically truncated.
|
||||
*
|
||||
* @param truncatedString The sting which will be truncated
|
||||
* @return Returns the string that has been truncated.
|
||||
*/
|
||||
std::string TruncateString(const std::string &inPutString);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Read NotificationSlotGroup object from a Parcel.
|
||||
*
|
||||
* @param parcel the parcel
|
||||
* @return read from parcel success or fail
|
||||
*/
|
||||
bool ReadFromParcel(Parcel &parcel);
|
||||
|
||||
private:
|
||||
std::string id_;
|
||||
std::string name_;
|
||||
std::string description_;
|
||||
std::vector<NotificationSlot> slots_;
|
||||
bool isDisabled_;
|
||||
};
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_SLOT_GROUP_H
|
||||
@@ -0,0 +1,185 @@
|
||||
/*
|
||||
* 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_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_SORTING_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_SORTING_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "ans_log_wrapper.h"
|
||||
#include "notification_slot.h"
|
||||
#include "parcel.h"
|
||||
#include "uri.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
|
||||
class NotificationSorting final : public Parcelable {
|
||||
public:
|
||||
/**
|
||||
* @brief Default constructor used to create an empty NotificationSorting instance.
|
||||
*/
|
||||
NotificationSorting();
|
||||
|
||||
/**
|
||||
* @brief Default deconstructor used to deconstruct.
|
||||
*/
|
||||
~NotificationSorting();
|
||||
|
||||
/**
|
||||
* @brief A constructor used to create a NotificationSorting instance by copying parameters from an existing one.
|
||||
*
|
||||
* @param sorting Indicates the NotificationSorting object.
|
||||
*/
|
||||
NotificationSorting(const NotificationSorting &sorting);
|
||||
|
||||
/**
|
||||
* @brief Obtains the sequence number of a notification among all the active notifications.
|
||||
*
|
||||
* @return Returns the sequence number of the notification.
|
||||
*/
|
||||
inline int32_t GetRanking() const
|
||||
{
|
||||
return ranking_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Obtains the notification hash code, which is unique in the current application.
|
||||
* Generally, the notification hash code is a string in the format
|
||||
* Notification ID_Creator package name_Creator UID_Owner package name.
|
||||
*
|
||||
* @return Returns the notification hash code.
|
||||
*/
|
||||
inline std::string GetKey() const
|
||||
{
|
||||
return key_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Obtains the importance level of the current notification set in the corresponding NotificationSlot.
|
||||
*
|
||||
* @return Returns the importance level of the notification.
|
||||
*/
|
||||
inline int32_t GetImportance() const
|
||||
{
|
||||
return importance_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Obtains the NotificationSlot the current notification belongs to.
|
||||
* Each notification must be in a particular NotificationSlot.
|
||||
*
|
||||
* @return Returns the NotificationSlot of the notification.
|
||||
*/
|
||||
inline NotificationSlot GetSlot() const
|
||||
{
|
||||
return *slot_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Obtains the visibility of the current notification on the lock screen set.
|
||||
*
|
||||
* @return Returns the visibility of the notification on the lock screen.
|
||||
*/
|
||||
inline int32_t GetVisiblenessOverride() const
|
||||
{
|
||||
return visiblenessOverride_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Checks whether the badge is displayed for the current notification.
|
||||
*
|
||||
* @return Returns true if the badge is displayed; returns false otherwise.
|
||||
*/
|
||||
inline bool IsDisplayBadge() const
|
||||
{
|
||||
return isDisplayBadge_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Checks whether the current notification is hidden.
|
||||
* A notification should be hidden if the application sending the notification is suspended.
|
||||
*
|
||||
* @return Returns true if the notification is hidden; returns false otherwise.
|
||||
*/
|
||||
inline bool IsHiddenNotification() const
|
||||
{
|
||||
return isHiddenNotification_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Obtains the overridden notification group key. If the system has overridden the group key,
|
||||
* a non-null value will be returned.
|
||||
*
|
||||
* @return Returns the overridden notification group key used to bind notifications.
|
||||
*/
|
||||
inline std::string GetGroupKeyOverride() const
|
||||
{
|
||||
return groupKeyOverride_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Marshals a NotificationSorting object into a Parcel.
|
||||
*
|
||||
* @param parcel Indicates the Parcel object for marshalling.
|
||||
*
|
||||
* @return Returns true if the marshalling is successful; returns false otherwise.
|
||||
*/
|
||||
bool Marshalling(Parcel &parcel) const override;
|
||||
|
||||
/**
|
||||
* @brief Unmarshals a NotificationSorting object from a Parcel.
|
||||
*
|
||||
* @param Indicates the Parcel object for unmarshalling.
|
||||
*
|
||||
* @return Returns true if the unmarshalling is successful; returns false otherwise.
|
||||
*/
|
||||
static NotificationSorting *Unmarshalling(Parcel &parcel);
|
||||
|
||||
/**
|
||||
* @brief Dump sorting info
|
||||
*
|
||||
* @return Sorting info
|
||||
*/
|
||||
std::string Dump() const;
|
||||
|
||||
private:
|
||||
void SetGroupKeyOverride(const std::string &str);
|
||||
void SetKey(const std::string &key);
|
||||
void SetImportance(const int32_t &importance);
|
||||
void SetRanking(const int32_t &ranking);
|
||||
void SetSlot(const sptr<NotificationSlot> &slot);
|
||||
void SetVisiblenessOverride(const int32_t &visibleness);
|
||||
void SetDisplayBadge(const bool &isDisplayBadge);
|
||||
void SetHiddenNotification(const bool &isHiddenNotfication);
|
||||
bool ReadFromParcel(Parcel &parcel);
|
||||
|
||||
private:
|
||||
std::string key_{};
|
||||
int32_t ranking_{-1};
|
||||
int32_t importance_{-1};
|
||||
bool isDisplayBadge_{true};
|
||||
bool isHiddenNotification_{};
|
||||
std::string groupKeyOverride_{};
|
||||
int32_t visiblenessOverride_{};
|
||||
sptr<NotificationSlot> slot_{nullptr};
|
||||
|
||||
friend class AdvancedNotificationService;
|
||||
};
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_SORTING_H
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* 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_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_SORTING_MAP_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_SORTING_MAP_H
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "notification_sorting.h"
|
||||
#include "parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
|
||||
class NotificationSortingMap final : public Parcelable {
|
||||
public:
|
||||
/**
|
||||
* @brief Default constructor used to create an empty NotificationMap instance.
|
||||
*/
|
||||
NotificationSortingMap();
|
||||
|
||||
/**
|
||||
* @brief Default deconstructor used to deconstruct.
|
||||
*/
|
||||
~NotificationSortingMap();
|
||||
|
||||
/**
|
||||
* @brief A constructor used to create a NotificationSortingMap instance by copying parameters from an existing one.
|
||||
*
|
||||
* @param Indicates the NotificationSortingMap object.
|
||||
*/
|
||||
NotificationSortingMap(const std::vector<NotificationSorting> &sortingList);
|
||||
|
||||
/**
|
||||
* @brief Obtains the list of sorted hash codes.
|
||||
*
|
||||
* @return Returns the list of sorted hash codes.
|
||||
*/
|
||||
inline std::vector<std::string> GetKey()
|
||||
{
|
||||
return sortedKey_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Obtains NotificationSorting based on the hash codes.
|
||||
*
|
||||
* @param key Indicates the hash codes obtained by using getkey().
|
||||
*
|
||||
* @param sorting Indicates the sorting information about the hash codes.
|
||||
*
|
||||
*/
|
||||
bool GetNotificationSorting(const std::string &key, NotificationSorting &sorting) const;
|
||||
|
||||
/**
|
||||
* @brief Marshals a NotificationSortingMap object into a Parcel.
|
||||
*
|
||||
* @param parcel Indicates the Parcel object for marshalling.
|
||||
*
|
||||
* @return Returns true if the marshalling is successful; returns false otherwise.
|
||||
*/
|
||||
bool Marshalling(Parcel &parcel) const override;
|
||||
|
||||
/**
|
||||
* @brief Unmarshals a NotificationSortingMap object from a Parcel.
|
||||
*
|
||||
* @param Indicates the Parcel object for unmarshalling.
|
||||
*/
|
||||
static NotificationSortingMap *Unmarshalling(Parcel &parcel);
|
||||
|
||||
/**
|
||||
* @brief Dump sorting map info
|
||||
*
|
||||
* @return Return sorting map info to string.
|
||||
*/
|
||||
std::string Dump() const;
|
||||
|
||||
private:
|
||||
void SetKey(const std::string &key);
|
||||
void SetNotificationSorting(const std::vector<NotificationSorting> &sortingList);
|
||||
|
||||
private:
|
||||
std::vector<std::string> sortedKey_{};
|
||||
std::map<std::string, NotificationSorting> sortings_{};
|
||||
};
|
||||
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_SORTING_MAP_H
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATIN_SUBSCRIBER_INFO_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATIN_SUBSCRIBER_INFO_H
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
|
||||
class NotificationSubscribeInfo final : public Parcelable {
|
||||
public:
|
||||
/**
|
||||
* @brief Default constructor used to create a instance.
|
||||
*/
|
||||
NotificationSubscribeInfo();
|
||||
|
||||
/**
|
||||
* @brief Default deconstructor used to deconstruct.
|
||||
*/
|
||||
~NotificationSubscribeInfo();
|
||||
|
||||
/**
|
||||
* @brief A constructor used to create a NotificationSubscribeInfo instance by copying parameters from an existing
|
||||
* one.
|
||||
*
|
||||
* @param Indicates the NotificationSubscribeInfo object.
|
||||
*/
|
||||
NotificationSubscribeInfo(const NotificationSubscribeInfo &subscribeInfo);
|
||||
|
||||
/**
|
||||
* @brief Sets a single application name as the filter criterion,
|
||||
* which means to subscribe to notifications of this application.
|
||||
*
|
||||
* @param appName Indicates the application name.
|
||||
**/
|
||||
void AddAppName(const std::string appName);
|
||||
|
||||
/**
|
||||
* @brief Sets multiple application names as the filter criteria,
|
||||
* which means to subscribe to notifications of these applications.
|
||||
*
|
||||
* @param appNames Indicates the set of application names.
|
||||
**/
|
||||
void AddAppNames(const std::vector<std::string> &appNames);
|
||||
|
||||
/**
|
||||
* @brief Obtains the application names in the current NotificationSubscribeInfo object.
|
||||
* The application names can be set by calling AddAppNames.
|
||||
*
|
||||
* @return Returns the set of application names.
|
||||
**/
|
||||
std::vector<std::string> GetAppNames() const;
|
||||
|
||||
/**
|
||||
* @brief Marshals a NotificationSubscribeInfo object into a Parcel.
|
||||
*
|
||||
* @param parcel Indicates the Parcel object for marshalling.
|
||||
*/
|
||||
bool Marshalling(Parcel &parcel) const override;
|
||||
|
||||
/**
|
||||
* @brief Unmarshals a NotificationSubscribeInfo object from a Parcel.
|
||||
*
|
||||
* @param parcel Indicates the Parcel object for unmarshalling.
|
||||
*/
|
||||
static NotificationSubscribeInfo *Unmarshalling(Parcel &parcel);
|
||||
|
||||
/**
|
||||
* @brief Dump subscribe info.
|
||||
*
|
||||
* @return Return subscribe info.
|
||||
*/
|
||||
std::string Dump();
|
||||
|
||||
private:
|
||||
bool ReadFromParcel(Parcel &parcel);
|
||||
|
||||
private:
|
||||
std::vector<std::string> appNames_{};
|
||||
};
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATIN_SUBSCRIBER_INFO_H
|
||||
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* 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_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_SUBSCRIBER_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_SUBSCRIBER_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "ans_manager_interface.h"
|
||||
#include "ans_subscriber_stub.h"
|
||||
#include "notification_constant.h"
|
||||
#include "notification_request.h"
|
||||
#include "notification_sorting.h"
|
||||
#include "notification_sorting_map.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
|
||||
class NotificationSubscriber {
|
||||
public:
|
||||
/**
|
||||
* @brief Default constructor used to create a instance.
|
||||
*/
|
||||
NotificationSubscriber()
|
||||
{
|
||||
impl_ = new SubscriberImpl(*this);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Called back when a notification is canceled.
|
||||
*
|
||||
* @param request Indicates the canceled Notification object.
|
||||
**/
|
||||
virtual void OnCanceled(const std::shared_ptr<Notification> &request) = 0;
|
||||
|
||||
/**
|
||||
* @brief Called back when a notification is canceled.
|
||||
*
|
||||
* @param request Indicates the canceled Notification object.
|
||||
* @param sortingMap Indicates the sorting map used by the current subscriber
|
||||
* to obtain notification ranking information.
|
||||
* @param deleteReason Indicates the reason for the deletion. For details, see NotificationConstant.
|
||||
**/
|
||||
virtual void OnCanceled(const std::shared_ptr<Notification> &request,
|
||||
const std::shared_ptr<NotificationSortingMap> &sortingMap, int deleteReason) = 0;
|
||||
|
||||
/**
|
||||
* @brief Called back when the subscriber is connected to the Advanced Notification Service (ANS).
|
||||
*
|
||||
* @param result Indicates subscribe result.
|
||||
**/
|
||||
virtual void OnSubscribeResult(NotificationConstant::SubscribeResult result) = 0;
|
||||
|
||||
/**
|
||||
* @brief Called back when the subscriber receives a new notification.
|
||||
*
|
||||
* @param request Indicates the received Notification object.
|
||||
**/
|
||||
virtual void OnConsumed(const std::shared_ptr<Notification> &request) = 0;
|
||||
|
||||
/**
|
||||
* @brief Called back when the subscriber receives a new notification.
|
||||
*
|
||||
* @param request Indicates the received Notification object.
|
||||
* @param sortingMap Indicates the sorting map used by the current subscriber to obtain
|
||||
* notification ranking information.
|
||||
**/
|
||||
virtual void OnConsumed(
|
||||
const std::shared_ptr<Notification> &request, const std::shared_ptr<NotificationSortingMap> &sortingMap) = 0;
|
||||
|
||||
/**
|
||||
* @brief Called back when the subscriber is disconnected from the ANS.
|
||||
*
|
||||
* @param result Indicates unsubscribe result.
|
||||
**/
|
||||
virtual void OnUnsubscribeResult(NotificationConstant::SubscribeResult result) = 0;
|
||||
|
||||
/**
|
||||
* @brief Called back when the ranking information about the current notification changes.
|
||||
*
|
||||
* @param sortingMap Indicates the sorting map used to obtain notification ranking information.
|
||||
**/
|
||||
virtual void OnUpdate(const std::shared_ptr<NotificationSortingMap> &sortingMap) = 0;
|
||||
|
||||
/**
|
||||
* @brief Called back when connection to the ANS has died.
|
||||
**/
|
||||
virtual void OnDied() = 0;
|
||||
|
||||
/**
|
||||
* @brief Called when the Do Not Disturb mode type changes.
|
||||
*
|
||||
* @param disturbMode Indicates the current Do Not Disturb mode type.
|
||||
**/
|
||||
virtual void OnDisturbModeChanged(int disturbMode) = 0;
|
||||
|
||||
private:
|
||||
class SubscriberImpl final : public AnsSubscriberStub {
|
||||
public:
|
||||
class DeathRecipient final : public IRemoteObject::DeathRecipient {
|
||||
public:
|
||||
DeathRecipient(SubscriberImpl &subscriberImpl);
|
||||
|
||||
~DeathRecipient();
|
||||
|
||||
void OnRemoteDied(const wptr<IRemoteObject> &object) override;
|
||||
|
||||
private:
|
||||
SubscriberImpl &subscriberImpl_;
|
||||
};
|
||||
|
||||
public:
|
||||
SubscriberImpl(NotificationSubscriber &subscriber);
|
||||
|
||||
void OnSubscribeResult(NotificationConstant::SubscribeResult result) override;
|
||||
|
||||
void OnUnsubscribeResult(NotificationConstant::SubscribeResult result) override;
|
||||
|
||||
void OnConsumed(const sptr<Notification> ¬ification) override;
|
||||
|
||||
void OnConsumed(
|
||||
const sptr<Notification> ¬ification, const sptr<NotificationSortingMap> ¬ificationMap) override;
|
||||
|
||||
void OnCanceled(const sptr<Notification> ¬ification) override;
|
||||
|
||||
void OnCanceled(const sptr<Notification> ¬ification, const sptr<NotificationSortingMap> ¬ificationMap,
|
||||
int deleteReason) override;
|
||||
|
||||
void OnUpdated(const sptr<NotificationSortingMap> ¬ificationMap) override;
|
||||
|
||||
void OnDisturbModeChanged(NotificationConstant::DisturbMode mode) override;
|
||||
|
||||
bool GetAnsManagerProxy();
|
||||
|
||||
public:
|
||||
NotificationSubscriber &subscriber_;
|
||||
sptr<DeathRecipient> recipient_{nullptr};
|
||||
sptr<IAnsManager> proxy_{nullptr};
|
||||
std::mutex mutex_{};
|
||||
};
|
||||
|
||||
private:
|
||||
const sptr<SubscriberImpl> GetImpl() const;
|
||||
|
||||
private:
|
||||
sptr<SubscriberImpl> impl_ = nullptr;
|
||||
|
||||
friend class AnsNotification;
|
||||
};
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,281 @@
|
||||
/*
|
||||
* 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_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_USER_INPUT_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_USER_INPUT_H
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "notification_constant.h"
|
||||
#include "pac_map.h"
|
||||
#include "want.h"
|
||||
#include "parcel.h"
|
||||
#include "uri.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
class PixelMap;
|
||||
|
||||
class NotificationUserInput : public Parcelable {
|
||||
public:
|
||||
/**
|
||||
* Sets the input source of this NotificationUserInput object.
|
||||
* @param want Indicates the Want to which the input result is to be added.
|
||||
* @param source Indicates the input source. For available values, see NotificationConstant::InputSource.
|
||||
*/
|
||||
static void SetInputsSource(AAFwk::Want &want, NotificationConstant::InputsSource source);
|
||||
|
||||
/**
|
||||
* Obtains the input source of this NotificationUserInput object.
|
||||
* @param want Indicates the Want containing the input result.
|
||||
* @return the input source of this NotificationUserInput object,
|
||||
* as enumerated in NotificationConstant::InputSource.
|
||||
*/
|
||||
static NotificationConstant::InputsSource GetInputsSource(const AAFwk::Want &want);
|
||||
|
||||
/**
|
||||
* Adds a list of NotificationUserInput objects to a Want. This method should only be called by user input
|
||||
* collection services when sending input results to an WantAgent.
|
||||
* @param userInputs Indicates the list of NotificationUserInput objects for which the input results are provided.
|
||||
* @param want Indicates the Want to which the input results are to be added.
|
||||
* @param pacMap Indicates the PacMap object holding the input results.
|
||||
* The PacMap key must match the keys contained in the objects specified in userInputs.
|
||||
*/
|
||||
static void AddInputsToWant(const std::vector<std::shared_ptr<NotificationUserInput>> &userInputs,
|
||||
AAFwk::Want &want, const AppExecFwk::PacMap &pacMap);
|
||||
|
||||
/**
|
||||
* Obtains the input text results from a specified Want.
|
||||
* @param want Indicates the Want object containing one or more user input results.
|
||||
* @return the PacMap object containing the input text results.
|
||||
*/
|
||||
static std::shared_ptr<AppExecFwk::PacMap> GetInputsFromWant(const AAFwk::Want &want);
|
||||
|
||||
/**
|
||||
* Adds the given NotificationUserInput object of a specified MIME type to an Want. This method is similar to
|
||||
* addInputsToWant(NotificationUserInput, Want, PacMap) except that the MIME type must be specified.
|
||||
* @param userInput Indicates the NotificationUserInput object for which the input results are provided.
|
||||
* @param want Indicates the Want to which the input results are to be added.
|
||||
* @param results Indicates a map containing the MIME type and its URI result.
|
||||
*/
|
||||
static void AddMimeInputToWant(const NotificationUserInput &userInput, AAFwk::Want &want,
|
||||
const std::map<std::string, std::shared_ptr<Uri>> &results);
|
||||
|
||||
/**
|
||||
* Obtains the input results of a particular MIME type from a specified Want. This method is similar to
|
||||
* GetInputsFromWant(Want) but uses the key of the NotificationUserInput.
|
||||
* @param want Indicates the Want object containing one or more user input results.
|
||||
* @param inputKey Indicates the key of the NotificationUserInput results to obtain.
|
||||
* @return a map containing the MIME type and its URI result.
|
||||
*/
|
||||
static std::map<std::string, std::shared_ptr<Uri>> GetMimeInputsFromWant(
|
||||
const AAFwk::Want &want, const std::string &inputKey);
|
||||
|
||||
public:
|
||||
/**
|
||||
* A static function used to create a NotificationUserInput instance with the input parameters passed.
|
||||
* @param inputKey Indicates the PacMap key used to identify this input when the input is collected from the user.
|
||||
* @return the shared_ptr object owns the created NotificationUserInput object otherwise return empty object if
|
||||
* inputKey is empty.
|
||||
*/
|
||||
static std::shared_ptr<NotificationUserInput> Create(const std::string &inputKey);
|
||||
|
||||
/**
|
||||
* A static function used to create a NotificationUserInput instance with the input parameters passed.
|
||||
* @param inputKey Indicates the PacMap key used to identify this input when the input is collected from the user.
|
||||
* @param tag Indicates the tag to be displayed.
|
||||
* @param options Indicates the list of predefined options to be provided for user input.
|
||||
* @param permitFreeFormInput Specifies whether to allow arbitrary text values. The default value is true,
|
||||
* indicating that arbitrary text values are allowed. If this parameter is set to false, you must pass a non-empty
|
||||
* std::vector of options or a non-empty std::set of permitMimeTypes. Otherwise, return empty object.
|
||||
* @param permitMimeTypes Indicates the MIME type allowed.
|
||||
* @param pacMap Indicates the PacMap object containing the additional data.
|
||||
* @param editType Indicates the edit type to set. For details about available values, see
|
||||
* NotificationConstant::InputEditType.
|
||||
* @return the shared_ptr object owns the created NotificationUserInput object otherwise return empty object if
|
||||
* permitFreeFormInput is false but editType is InputEditType::EDIT_ENABLED.
|
||||
*/
|
||||
static std::shared_ptr<NotificationUserInput> Create(const std::string &inputKey, const std::string &tag,
|
||||
const std::vector<std::string> &options, bool permitFreeFormInput, const std::set<std::string> &permitMimeTypes,
|
||||
const std::shared_ptr<AppExecFwk::PacMap> &pacMap, NotificationConstant::InputEditType editType);
|
||||
|
||||
/**
|
||||
* Default deconstructor used to deconstruct.
|
||||
*/
|
||||
~NotificationUserInput() = default;
|
||||
|
||||
/**
|
||||
* Obtains the key of this NotificationUserInput object.
|
||||
* @return the key of this NotificationUserInput object.
|
||||
*/
|
||||
std::string GetInputKey() const;
|
||||
|
||||
/**
|
||||
* Adds additional data to this Builder.
|
||||
* The value of pacMap will replace the existing extras value in this Builder.
|
||||
* @param pacMap Indicates the PacMap object containing the additional data.
|
||||
*/
|
||||
void AddAdditionalData(AppExecFwk::PacMap &pacMap);
|
||||
|
||||
/**
|
||||
* Obtains the additional data included in this NotificationUserInput object.
|
||||
* @return the additional data in this NotificationUserInput object.
|
||||
*/
|
||||
const std::shared_ptr<AppExecFwk::PacMap> GetAdditionalData() const;
|
||||
|
||||
/**
|
||||
* Sets the edit type of the options provided by this NotificationUserInput object.
|
||||
* The edit type determines whether an option can be edited when the user taps the option.
|
||||
* @param inputEditType Indicates the edit type to set. For details about available values,
|
||||
* see NotificationConstant::InputEditType.
|
||||
*/
|
||||
void SetEditType(NotificationConstant::InputEditType inputEditType);
|
||||
|
||||
/**
|
||||
* Obtains the edit type of the options provided by this NotificationUserInput object.
|
||||
* @return the edit type of options.
|
||||
*/
|
||||
NotificationConstant::InputEditType GetEditType() const;
|
||||
|
||||
/**
|
||||
* Sets the options provided to users to satisfy user input needs. All options are displayed in a single line.
|
||||
* Due to limited space, some or all of the options may be hidden if the options are too long or
|
||||
* there are too many options.
|
||||
* @param options Indicates the list of predefined options to be provided for user input.
|
||||
*/
|
||||
void SetOptions(const std::vector<std::string> &options);
|
||||
|
||||
/**
|
||||
* Obtains the options provided to the user to satisfy user input needs.
|
||||
* @return the list of predefined options.
|
||||
*/
|
||||
std::vector<std::string> GetOptions() const;
|
||||
|
||||
/**
|
||||
* Sets whether users can input values of the given MIME type.
|
||||
* @param mimeType Indicates the MIME type allowed.
|
||||
* @param doPermit Specifies whether to allow the given MIME type.
|
||||
* The value true means to allow it, and the value false means not.
|
||||
*/
|
||||
void SetPermitMimeTypes(const std::string &mimeType, bool doPermit);
|
||||
|
||||
/**
|
||||
* Obtains the MIME types allowed by this NotificationUserInput object.
|
||||
* @return the list of allowed MIME types.
|
||||
*/
|
||||
std::set<std::string> GetPermitMimeTypes() const;
|
||||
|
||||
/**
|
||||
* Checks whether this NotificationUserInput object allows only values of particular MIME types.
|
||||
* @return true if this object allows only values of particular MIME types; returns false otherwise.
|
||||
*/
|
||||
bool IsMimeTypeOnly() const;
|
||||
|
||||
/**
|
||||
* Sets the tag to be displayed to the user when collecting this input from the user.
|
||||
* @param tag Indicates the tag to be displayed.
|
||||
*/
|
||||
void SetTag(const std::string tag);
|
||||
|
||||
/**
|
||||
* Obtains the tag to be displayed to the user when collecting this input from the user.
|
||||
* @return the tag to be displayed to the user.
|
||||
*/
|
||||
std::string GetTag() const;
|
||||
|
||||
/**
|
||||
* Sets whether users can input arbitrary text values.
|
||||
* @param permitFreeFormInput Specifies whether to allow arbitrary text values. The default value is true,
|
||||
* indicating that arbitrary text values are allowed. If this parameter is set to false, you must either call
|
||||
* SetOptions(std::vector<std::string>) to set a non-null and non-empty list or call
|
||||
* SetPermitMimeTypes(std::string, bool) to allow a MIME type.
|
||||
*/
|
||||
void SetPermitFreeFormInput(bool permitFreeFormInput);
|
||||
|
||||
/**
|
||||
* Checks whether users can provide arbitrary values for this NotificationUserInput object.
|
||||
* @return true if this object allows arbitrary values; returns false otherwise.
|
||||
*/
|
||||
bool IsPermitFreeFormInput() const;
|
||||
|
||||
/**
|
||||
* Returns a string representation of the object.
|
||||
* @return a string representation of the object.
|
||||
*/
|
||||
std::string Dump();
|
||||
|
||||
/**
|
||||
* Marshal a object into a Parcel.
|
||||
* @param parcel the object into the parcel
|
||||
*/
|
||||
virtual bool Marshalling(Parcel &parcel) const override;
|
||||
|
||||
/**
|
||||
* Unmarshal object from a Parcel.
|
||||
* @return the NotificationUserInput
|
||||
*/
|
||||
static NotificationUserInput *Unmarshalling(Parcel &parcel);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Default constructor used to create a NotificationUserInput instance.
|
||||
*/
|
||||
NotificationUserInput() = default;
|
||||
|
||||
/**
|
||||
* A constructor used to create a NotificationUserInput instance with the input parameters passed.
|
||||
* @param inputKey Indicates the PacMap key used to identify this input when the input is collected from the user.
|
||||
*/
|
||||
explicit NotificationUserInput(const std::string &inputKey);
|
||||
|
||||
/**
|
||||
* A constructor used to create a NotificationUserInput instance with the input parameters passed.
|
||||
* @param inputKey Indicates the PacMap key used to identify this input when the input is collected from the user.
|
||||
* @param tag Indicates the tag to be displayed.
|
||||
* @param options Indicates the list of predefined options to be provided for user input.
|
||||
* @param permitFreeFormInput Specifies whether to allow arbitrary text values. The default value is true,
|
||||
* indicating that arbitrary text values are allowed. If this parameter is set to false, you must either call
|
||||
* setOptions(const std::vector<std::string> &) to set a non-empty list or call
|
||||
* setPermitMimeTypes(std::string, bool) to allow a MIME type.
|
||||
* @param permitMimeTypes Indicates the MIME type allowed.
|
||||
* @param pacMap Indicates the PacMap object containing the additional data.
|
||||
* @param editType Indicates the edit type to set. For details about available values, see
|
||||
* NotificationConstant::InputEditType.
|
||||
*/
|
||||
NotificationUserInput(const std::string &inputKey, const std::string &tag, const std::vector<std::string> &options,
|
||||
bool permitFreeFormInput, const std::set<std::string> &permitMimeTypes,
|
||||
const std::shared_ptr<AppExecFwk::PacMap> &pacMap, NotificationConstant::InputEditType editType);
|
||||
|
||||
/**
|
||||
* Read a NotificationUserInput object from a Parcel.
|
||||
* @param parcel the parcel
|
||||
*/
|
||||
bool ReadFromParcel(Parcel &parcel);
|
||||
|
||||
private:
|
||||
std::string inputKey_{};
|
||||
std::string tag_{};
|
||||
std::vector<std::string> options_{};
|
||||
bool permitFreeFormInput_{true};
|
||||
std::set<std::string> permitMimeTypes_{};
|
||||
std::shared_ptr<AppExecFwk::PacMap> pacMap_{};
|
||||
NotificationConstant::InputEditType editType_{NotificationConstant::InputEditType::EDIT_AUTO};
|
||||
};
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_USER_INPUT_H
|
||||
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
* 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 "message_user.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
|
||||
MessageUser::MessageUser()
|
||||
: uri_("")
|
||||
{}
|
||||
|
||||
MessageUser::~MessageUser()
|
||||
{}
|
||||
|
||||
void MessageUser::SetKey(const std::string &key)
|
||||
{
|
||||
key_ = key;
|
||||
}
|
||||
|
||||
std::string MessageUser::GetKey() const
|
||||
{
|
||||
return key_;
|
||||
}
|
||||
|
||||
void MessageUser::SetName(const std::string &name)
|
||||
{
|
||||
name_ = name;
|
||||
}
|
||||
|
||||
std::string MessageUser::GetName() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
void MessageUser::SetPixelMap(const std::shared_ptr<PixelMap> &pixelMap)
|
||||
{
|
||||
pixelMap_ = pixelMap;
|
||||
}
|
||||
|
||||
const std::shared_ptr<PixelMap> MessageUser::GetPixelMap() const
|
||||
{
|
||||
return pixelMap_;
|
||||
}
|
||||
|
||||
void MessageUser::SetUri(const Uri &uri)
|
||||
{
|
||||
uri_ = uri;
|
||||
}
|
||||
|
||||
Uri MessageUser::GetUri() const
|
||||
{
|
||||
return uri_;
|
||||
}
|
||||
|
||||
void MessageUser::SetMachine(bool machine)
|
||||
{
|
||||
isMachine_ = machine;
|
||||
}
|
||||
|
||||
bool MessageUser::IsMachine() const
|
||||
{
|
||||
return isMachine_;
|
||||
}
|
||||
|
||||
void MessageUser::SetUserAsImportant(bool userImportant)
|
||||
{
|
||||
isUserImportant_ = userImportant;
|
||||
}
|
||||
|
||||
bool MessageUser::IsUserImportant() const
|
||||
{
|
||||
return isUserImportant_;
|
||||
}
|
||||
|
||||
std::string MessageUser::Dump() const
|
||||
{
|
||||
return "MessageUser[key = " + key_ +
|
||||
", name = " + name_ +
|
||||
", pixelMap = " + (pixelMap_ ? "not null" : "null") +
|
||||
", uri = " + uri_.ToString() +
|
||||
", isMachine = " + std::to_string(isMachine_) +
|
||||
", isUserImportant = " + std::to_string(isUserImportant_) + "]";
|
||||
}
|
||||
|
||||
bool MessageUser::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
if (!parcel.WriteString(key_)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteString(name_)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteBool(isMachine_)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteBool(isUserImportant_)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (uri_.ToString().empty()) {
|
||||
if (!parcel.WriteInt32(VALUE_NULL)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!parcel.WriteInt32(VALUE_OBJECT)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteString((uri_.ToString()))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MessageUser::ReadFromParcel(Parcel &parcel)
|
||||
{
|
||||
key_ = parcel.ReadString();
|
||||
name_ = parcel.ReadString();
|
||||
isMachine_ = parcel.ReadBool();
|
||||
isUserImportant_ = parcel.ReadBool();
|
||||
|
||||
int empty = VALUE_NULL;
|
||||
if (!parcel.ReadInt32(empty)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (empty == VALUE_OBJECT) {
|
||||
uri_ = Uri((parcel.ReadString()));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
MessageUser *MessageUser::Unmarshalling(Parcel &parcel)
|
||||
{
|
||||
MessageUser *messageUser = new MessageUser();
|
||||
|
||||
if (messageUser && !messageUser->ReadFromParcel(parcel)) {
|
||||
delete messageUser;
|
||||
messageUser = nullptr;
|
||||
}
|
||||
|
||||
return messageUser;
|
||||
}
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,287 @@
|
||||
/*
|
||||
* 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 "notification.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "ans_log_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
Notification::Notification(){};
|
||||
|
||||
Notification::Notification(const sptr<NotificationRequest> &request)
|
||||
{
|
||||
request_ = request;
|
||||
key_ = GenerateNotificationKey(GetUid(), GetLabel(), GetId());
|
||||
}
|
||||
|
||||
Notification::Notification(const Notification &other)
|
||||
{
|
||||
key_ = other.key_;
|
||||
ledLightColor_ = other.ledLightColor_;
|
||||
lockscreenVisibleness_ = other.lockscreenVisibleness_;
|
||||
request_ = other.request_;
|
||||
postTime_ = other.postTime_;
|
||||
sound_ = other.sound_;
|
||||
vibrationStyle_ = other.vibrationStyle_;
|
||||
}
|
||||
|
||||
bool Notification::EnableLight() const
|
||||
{
|
||||
if (ledLightColor_ == -1) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Notification::EnableSound() const
|
||||
{
|
||||
if (sound_ == nullptr) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Notification::EnableVibrate() const
|
||||
{
|
||||
if (!vibrationStyle_.size()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string Notification::GetBundleName() const
|
||||
{
|
||||
if (request_ == nullptr) {
|
||||
return "";
|
||||
}
|
||||
return request_->GetOwnerBundleName();
|
||||
}
|
||||
|
||||
std::string Notification::GetCreateBundle() const
|
||||
{
|
||||
if (request_ == nullptr) {
|
||||
return "";
|
||||
}
|
||||
return request_->GetCreatorBundleName();
|
||||
}
|
||||
|
||||
std::string Notification::GetLabel() const
|
||||
{
|
||||
if (request_ == nullptr) {
|
||||
return "";
|
||||
}
|
||||
return request_->GetLabel();
|
||||
}
|
||||
|
||||
int32_t Notification::GetLedLightColor() const
|
||||
{
|
||||
return ledLightColor_;
|
||||
}
|
||||
|
||||
int32_t Notification::GetLockscreenVisibleness() const
|
||||
{
|
||||
return lockscreenVisibleness_;
|
||||
}
|
||||
|
||||
std::string Notification::GetGroup() const
|
||||
{
|
||||
if (request_ == nullptr) {
|
||||
return "";
|
||||
}
|
||||
return request_->GetGroupValue();
|
||||
}
|
||||
|
||||
int32_t Notification::GetId() const
|
||||
{
|
||||
if (request_ == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
return request_->GetNotificationId();
|
||||
}
|
||||
|
||||
std::string Notification::GetKey() const
|
||||
{
|
||||
return key_;
|
||||
}
|
||||
|
||||
NotificationRequest Notification::GetNotificationRequest() const
|
||||
{
|
||||
return *request_;
|
||||
}
|
||||
|
||||
int64_t Notification::GetPostTime() const
|
||||
{
|
||||
return postTime_;
|
||||
}
|
||||
|
||||
Uri Notification::GetSound() const
|
||||
{
|
||||
return *sound_;
|
||||
}
|
||||
|
||||
int32_t Notification::GetUid() const
|
||||
{
|
||||
if (request_ == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
return request_->GetCreatorUid();
|
||||
}
|
||||
|
||||
std::vector<int64_t> Notification::GetVibrationStyle() const
|
||||
{
|
||||
return vibrationStyle_;
|
||||
}
|
||||
|
||||
bool Notification::IsGroup() const
|
||||
{
|
||||
if (request_ == nullptr) {
|
||||
return false;
|
||||
}
|
||||
return !(request_->GetGroupValue() == "");
|
||||
}
|
||||
|
||||
bool Notification::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
if (!parcel.WriteString(key_)) {
|
||||
ANS_LOGE("Can't wirte key");
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteInt32(ledLightColor_)) {
|
||||
ANS_LOGE("Can't write ledLigthColor");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteInt32(lockscreenVisibleness_)) {
|
||||
ANS_LOGE("Can't write visbleness");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteStrongParcelable(request_)) {
|
||||
ANS_LOGE("Can't write request");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteInt64(postTime_)) {
|
||||
ANS_LOGE("Can't write postTime");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteString(sound_->ToString())) {
|
||||
ANS_LOGE("Can't write sound");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteInt64Vector(vibrationStyle_)) {
|
||||
ANS_LOGE("Can't write vibrationStyle");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Notification::ReadFromParcel(Parcel &parcel)
|
||||
{
|
||||
// Read key_
|
||||
key_ = parcel.ReadString();
|
||||
|
||||
// Read ledLightColor_
|
||||
ledLightColor_ = parcel.ReadInt32();
|
||||
|
||||
// Read lockscreenVisibleness_
|
||||
lockscreenVisibleness_ = parcel.ReadInt32();
|
||||
|
||||
// Read request_
|
||||
request_ = parcel.ReadStrongParcelable<NotificationRequest>();
|
||||
|
||||
// Read postTime_
|
||||
postTime_ = parcel.ReadInt64();
|
||||
|
||||
// Read sound_
|
||||
sound_ = std::make_shared<Uri>(parcel.ReadString());
|
||||
|
||||
// Read vibrationStyle_
|
||||
parcel.ReadInt64Vector(&vibrationStyle_);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Notification *Notification::Unmarshalling(Parcel &parcel)
|
||||
{
|
||||
Notification *n = new Notification();
|
||||
if (n && !n->ReadFromParcel(parcel)) {
|
||||
ANS_LOGE("Read from parcel error");
|
||||
delete n;
|
||||
n = nullptr;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
void Notification::SetLedLightColor(const int32_t &color)
|
||||
{
|
||||
ledLightColor_ = color;
|
||||
}
|
||||
|
||||
void Notification::SetLockScreenVisbleness(const int32_t &visbleness)
|
||||
{
|
||||
lockscreenVisibleness_ = visbleness;
|
||||
}
|
||||
|
||||
void Notification::SetPostTime(const int64_t &time)
|
||||
{
|
||||
postTime_ = time;
|
||||
}
|
||||
|
||||
void Notification::SetSound(const Uri &sound)
|
||||
{
|
||||
sound_ = std::make_shared<Uri>(sound.ToString());
|
||||
}
|
||||
|
||||
void Notification::SetVibrationStyle(const std::vector<int64_t> &style)
|
||||
{
|
||||
vibrationStyle_ = style;
|
||||
}
|
||||
|
||||
std::string Notification::GenerateNotificationKey(int32_t uid, const std::string &label, int32_t id)
|
||||
{
|
||||
const char *KEY_SPLITER = "_";
|
||||
|
||||
std::stringstream stream;
|
||||
stream << uid << KEY_SPLITER << label << KEY_SPLITER << id;
|
||||
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
std::string Notification::Dump() const
|
||||
{
|
||||
std::string dump = "Notification{ key = " + key_ + ", ledLightColor = " + std::to_string(ledLightColor_) +
|
||||
", lockscreenVisbleness = " + std::to_string(lockscreenVisibleness_) + ",request = ";
|
||||
if (request_ == nullptr) {
|
||||
dump += "nullptr";
|
||||
} else {
|
||||
dump += request_->Dump();
|
||||
}
|
||||
dump = dump + ",postTime = " + std::to_string(postTime_) + ",sound = " + sound_->ToString() + "vibrationStyle = ";
|
||||
for (auto &style : vibrationStyle_) {
|
||||
dump += std::to_string(style);
|
||||
dump += ",";
|
||||
}
|
||||
return dump;
|
||||
}
|
||||
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,302 @@
|
||||
/*
|
||||
* 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 "notification_action_button.h"
|
||||
|
||||
#include <new>
|
||||
#include "ans_log_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
std::shared_ptr<NotificationActionButton> NotificationActionButton::Create(const std::shared_ptr<PixelMap> &icon,
|
||||
const std::string &title, const std::shared_ptr<WantAgent::WantAgent> &wantAgent,
|
||||
const std::shared_ptr<AppExecFwk::PacMap> &extras, NotificationConstant::SemanticActionButton semanticActionButton,
|
||||
bool autoCreatedReplies, const std::vector<std::shared_ptr<NotificationUserInput>> &userInputs, bool isContextual)
|
||||
{
|
||||
if (isContextual && (!icon || !wantAgent)) {
|
||||
ANS_LOGE("icon or wantAgent can not be null when isContextual is true");
|
||||
return {};
|
||||
}
|
||||
|
||||
auto realExtras = extras;
|
||||
if (!realExtras) {
|
||||
realExtras = std::make_shared<AppExecFwk::PacMap>();
|
||||
}
|
||||
|
||||
auto pActionButton = new (std::nothrow) NotificationActionButton(
|
||||
icon, title, wantAgent, realExtras, semanticActionButton, autoCreatedReplies, userInputs, isContextual);
|
||||
if (pActionButton == nullptr) {
|
||||
ANS_LOGE("create NotificationActionButton object failed");
|
||||
return {};
|
||||
}
|
||||
|
||||
return std::shared_ptr<NotificationActionButton>(pActionButton);
|
||||
}
|
||||
|
||||
NotificationActionButton::NotificationActionButton(const std::shared_ptr<PixelMap> &icon, const std::string &title,
|
||||
const std::shared_ptr<WantAgent::WantAgent> &wantAgent, const std::shared_ptr<AppExecFwk::PacMap> &extras,
|
||||
NotificationConstant::SemanticActionButton semanticActionButton, bool autoCreatedReplies,
|
||||
const std::vector<std::shared_ptr<NotificationUserInput>> &userInputs, bool isContextual)
|
||||
: icon_(icon),
|
||||
title_(title),
|
||||
wantAgent_(wantAgent),
|
||||
extras_(extras),
|
||||
semanticActionButton_(semanticActionButton),
|
||||
autoCreatedReplies_(autoCreatedReplies),
|
||||
userInputs_(userInputs),
|
||||
isContextual_(isContextual)
|
||||
{}
|
||||
|
||||
void NotificationActionButton::AddAdditionalData(AppExecFwk::PacMap &pacMap)
|
||||
{
|
||||
extras_->PutAll(pacMap);
|
||||
}
|
||||
|
||||
const std::shared_ptr<AppExecFwk::PacMap> NotificationActionButton::GetAdditionalData() const
|
||||
{
|
||||
return extras_;
|
||||
}
|
||||
|
||||
const std::shared_ptr<PixelMap> NotificationActionButton::GetIcon() const
|
||||
{
|
||||
return icon_;
|
||||
}
|
||||
|
||||
const std::shared_ptr<WantAgent::WantAgent> NotificationActionButton::GetWantAgent() const
|
||||
{
|
||||
return wantAgent_;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<NotificationUserInput>> NotificationActionButton::GetMimeTypeOnlyUserInputs() const
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
void NotificationActionButton::SetSemanticActionButton(NotificationConstant::SemanticActionButton semanticActionButton)
|
||||
{
|
||||
semanticActionButton_ = semanticActionButton;
|
||||
}
|
||||
|
||||
NotificationConstant::SemanticActionButton NotificationActionButton::GetSemanticActionButton() const
|
||||
{
|
||||
return semanticActionButton_;
|
||||
}
|
||||
|
||||
std::string NotificationActionButton::GetTitle() const
|
||||
{
|
||||
return title_;
|
||||
}
|
||||
|
||||
void NotificationActionButton::AddNotificationUserInput(const std::shared_ptr<NotificationUserInput> &userInput)
|
||||
{
|
||||
if (!userInput) {
|
||||
ANS_LOGE("The userInput is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
userInputs_.emplace_back(userInput);
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<NotificationUserInput>> NotificationActionButton::GetUserInputs() const
|
||||
{
|
||||
return userInputs_;
|
||||
}
|
||||
|
||||
bool NotificationActionButton::IsAutoCreatedReplies() const
|
||||
{
|
||||
return autoCreatedReplies_;
|
||||
}
|
||||
|
||||
void NotificationActionButton::SetAutoCreatedReplies(bool autoCreatedReplies)
|
||||
{
|
||||
autoCreatedReplies_ = autoCreatedReplies;
|
||||
}
|
||||
|
||||
bool NotificationActionButton::IsContextDependent() const
|
||||
{
|
||||
return isContextual_;
|
||||
}
|
||||
|
||||
void NotificationActionButton::SetContextDependent(bool isContextual)
|
||||
{
|
||||
isContextual_ = isContextual;
|
||||
}
|
||||
|
||||
std::string NotificationActionButton::Dump()
|
||||
{
|
||||
return "NotificationActionButton[ title = " + title_ +
|
||||
", semanticActionButton = " + std::to_string(static_cast<int32_t>(semanticActionButton_)) +
|
||||
", autoCreatedReplies = " + (autoCreatedReplies_ ? "true" : "false") +
|
||||
", isContextual = " + (isContextual_ ? "true" : "false") + " ]";
|
||||
}
|
||||
|
||||
bool NotificationActionButton::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
if (!parcel.WriteString(title_)) {
|
||||
ANS_LOGE("Failed to write title");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteBool(autoCreatedReplies_)) {
|
||||
ANS_LOGE("Failed to write flag autoCreatedReplies");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteBool(isContextual_)) {
|
||||
ANS_LOGE("Failed to write flag isContextual");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteInt32(static_cast<int32_t>(semanticActionButton_))) {
|
||||
ANS_LOGE("Failed to write semanticActionButton");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool valid{false};
|
||||
|
||||
// valid = icon_ ? true : false;
|
||||
// if (!parcel.WriteBool(valid)) {
|
||||
// ANS_LOGE("Failed to write the flag which indicate whether icon is null");
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// if (valid) {
|
||||
// if (!parcel.WriteParcelable(icon_.get())) {
|
||||
// ANS_LOGE("Failed to write icon");
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
valid = wantAgent_ ? true : false;
|
||||
if (!parcel.WriteBool(valid)) {
|
||||
ANS_LOGE("Failed to write the flag which indicate whether wantAgent is null");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (valid) {
|
||||
if (!parcel.WriteParcelable(wantAgent_.get())) {
|
||||
ANS_LOGE("Failed to write wantAgent");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
valid = extras_ ? true : false;
|
||||
if (!parcel.WriteBool(valid)) {
|
||||
ANS_LOGE("Failed to write the flag which indicate whether extras is null");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (valid) {
|
||||
if (!parcel.WriteParcelable(extras_.get())) {
|
||||
ANS_LOGE("Failed to write extras");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!parcel.WriteInt32(static_cast<int32_t>(userInputs_.size()))) {
|
||||
ANS_LOGE("Failed to write the size of userInputs");
|
||||
return false;
|
||||
}
|
||||
|
||||
for (auto it = userInputs_.begin(); it != userInputs_.end(); ++it) {
|
||||
valid = (*it) ? true : false;
|
||||
if (!parcel.WriteBool(valid)) {
|
||||
ANS_LOGE("Failed to write the flag which indicate whether userInput is null");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (valid) {
|
||||
if (!parcel.WriteParcelable(it->get())) {
|
||||
ANS_LOGE("Failed to write userInput");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
NotificationActionButton *NotificationActionButton::Unmarshalling(Parcel &parcel)
|
||||
{
|
||||
auto pButton = new NotificationActionButton();
|
||||
if ((nullptr != pButton) && !pButton->ReadFromParcel(parcel)) {
|
||||
delete pButton;
|
||||
pButton = nullptr;
|
||||
}
|
||||
|
||||
return pButton;
|
||||
}
|
||||
|
||||
bool NotificationActionButton::ReadFromParcel(Parcel &parcel)
|
||||
{
|
||||
if (!parcel.ReadString(title_)) {
|
||||
ANS_LOGE("Failed to read title");
|
||||
return false;
|
||||
}
|
||||
|
||||
autoCreatedReplies_ = parcel.ReadBool();
|
||||
|
||||
isContextual_ = parcel.ReadBool();
|
||||
|
||||
semanticActionButton_ = static_cast<NotificationConstant::SemanticActionButton>(parcel.ReadInt32());
|
||||
|
||||
bool valid{false};
|
||||
|
||||
// valid = parcel.ReadBool();
|
||||
// if (valid) {
|
||||
// icon_ = std::shared_ptr<PixelMap>(parcel.ReadParcelable<PixelMap>());
|
||||
// if (!icon_) {
|
||||
// ANS_LOGE("Failed to read icon");
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
valid = parcel.ReadBool();
|
||||
if (valid) {
|
||||
wantAgent_ = std::shared_ptr<WantAgent::WantAgent>(parcel.ReadParcelable<WantAgent::WantAgent>());
|
||||
if (!wantAgent_) {
|
||||
ANS_LOGE("Failed to read wantAgent");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
valid = parcel.ReadBool();
|
||||
if (valid) {
|
||||
extras_ = std::shared_ptr<AppExecFwk::PacMap>(parcel.ReadParcelable<AppExecFwk::PacMap>());
|
||||
if (!extras_) {
|
||||
ANS_LOGE("Failed to read extras");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
auto vsize = parcel.ReadInt32();
|
||||
for (auto it = 0; it < vsize; ++it) {
|
||||
valid = parcel.ReadBool();
|
||||
NotificationUserInput *member{nullptr};
|
||||
if (valid) {
|
||||
member = parcel.ReadParcelable<NotificationUserInput>();
|
||||
if (nullptr == member) {
|
||||
ANS_LOGE("Failed to read userInput");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
userInputs_.emplace_back(member);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* 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 "notification_basic_content.h"
|
||||
#include "ans_log_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
NotificationBasicContent::~NotificationBasicContent()
|
||||
{}
|
||||
|
||||
void NotificationBasicContent::SetAdditionalText(const std::string &additionalText)
|
||||
{
|
||||
additionalText_ = additionalText;
|
||||
}
|
||||
|
||||
std::string NotificationBasicContent::GetAdditionalText() const
|
||||
{
|
||||
return additionalText_;
|
||||
}
|
||||
|
||||
void NotificationBasicContent::SetText(const std::string &text)
|
||||
{
|
||||
text_ = text;
|
||||
}
|
||||
|
||||
std::string NotificationBasicContent::GetText() const
|
||||
{
|
||||
return text_;
|
||||
}
|
||||
|
||||
void NotificationBasicContent::SetTitle(const std::string &title)
|
||||
{
|
||||
title_ = title;
|
||||
}
|
||||
|
||||
std::string NotificationBasicContent::GetTitle() const
|
||||
{
|
||||
return title_;
|
||||
}
|
||||
|
||||
std::string NotificationBasicContent::Dump()
|
||||
{
|
||||
return "title = " + title_ + ", text = " + text_ + ", additionalText = " + additionalText_;
|
||||
}
|
||||
|
||||
bool NotificationBasicContent::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
if (!parcel.WriteString(text_)) {
|
||||
ANS_LOGE("Failed to write text");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteString(title_)) {
|
||||
ANS_LOGE("Failed to write title");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteString(additionalText_)) {
|
||||
ANS_LOGE("Failed to write additional text");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NotificationBasicContent::ReadFromParcel(Parcel &parcel)
|
||||
{
|
||||
if (!parcel.ReadString(text_)) {
|
||||
ANS_LOGE("Failed to read text");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.ReadString(title_)) {
|
||||
ANS_LOGE("Failed to read title");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.ReadString(additionalText_)) {
|
||||
ANS_LOGE("Failed to read additional text");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
@@ -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 "notification_constant.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
const std::string NotificationConstant::EXTRA_INPUTS_SOURCE{"notification_user_input_source"};
|
||||
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,218 @@
|
||||
/*
|
||||
* 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 "notification_content.h"
|
||||
#include "ans_log_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
NotificationContent::NotificationContent(const std::shared_ptr<NotificationNormalContent> &normalContent)
|
||||
{
|
||||
if (!normalContent) {
|
||||
ANS_LOGE("NotificationNormalContent can not be null");
|
||||
return;
|
||||
}
|
||||
|
||||
contentType_ = NotificationContent::Type::BASIC_TEXT;
|
||||
content_ = normalContent;
|
||||
}
|
||||
|
||||
NotificationContent::NotificationContent(const std::shared_ptr<NotificationLongTextContent> &longTextContent)
|
||||
{
|
||||
if (!longTextContent) {
|
||||
ANS_LOGE("NotificationLongTextContent can not be null");
|
||||
return;
|
||||
}
|
||||
|
||||
contentType_ = NotificationContent::Type::LONG_TEXT;
|
||||
content_ = longTextContent;
|
||||
}
|
||||
|
||||
NotificationContent::NotificationContent(const std::shared_ptr<NotificationPictureContent> &pictureContent)
|
||||
{
|
||||
if (!pictureContent) {
|
||||
ANS_LOGE("NotificationPictureContent can not be null");
|
||||
return;
|
||||
}
|
||||
|
||||
contentType_ = NotificationContent::Type::PICTURE;
|
||||
content_ = pictureContent;
|
||||
}
|
||||
|
||||
NotificationContent::NotificationContent(const std::shared_ptr<NotificationConversationalContent> &conversationContent)
|
||||
{
|
||||
if (!conversationContent) {
|
||||
ANS_LOGE("NotificationConversationalContent can not be null");
|
||||
return;
|
||||
}
|
||||
|
||||
contentType_ = NotificationContent::Type::CONVERSATION;
|
||||
content_ = conversationContent;
|
||||
}
|
||||
|
||||
NotificationContent::NotificationContent(const std::shared_ptr<NotificationMultiLineContent> &multiLineContent)
|
||||
{
|
||||
if (!multiLineContent) {
|
||||
ANS_LOGE("NotificationMultiLineContent can not be null");
|
||||
return;
|
||||
}
|
||||
|
||||
contentType_ = NotificationContent::Type::MULTILINE;
|
||||
content_ = multiLineContent;
|
||||
}
|
||||
|
||||
NotificationContent::NotificationContent(const std::shared_ptr<NotificationMediaContent> &mediaContent)
|
||||
{
|
||||
if (!mediaContent) {
|
||||
ANS_LOGE("NotificationMediaContent can not be null");
|
||||
return;
|
||||
}
|
||||
|
||||
contentType_ = NotificationContent::Type::MEDIA;
|
||||
content_ = mediaContent;
|
||||
}
|
||||
|
||||
NotificationContent::~NotificationContent()
|
||||
{}
|
||||
|
||||
NotificationContent::Type NotificationContent::GetContentType() const
|
||||
{
|
||||
return contentType_;
|
||||
}
|
||||
|
||||
std::shared_ptr<NotificationBasicContent> NotificationContent::GetNotificationContent() const
|
||||
{
|
||||
return content_;
|
||||
}
|
||||
|
||||
std::string NotificationContent::Dump()
|
||||
{
|
||||
std::string contentTypeStr = (contentType_ == NotificationContent::Type::BASIC_TEXT) ? "BASIC_TEXT"
|
||||
: (contentType_ == NotificationContent::Type::CONVERSATION) ? "CONVERSATION"
|
||||
: (contentType_ == NotificationContent::Type::LONG_TEXT) ? "LONG_TEXT"
|
||||
: (contentType_ == NotificationContent::Type::MEDIA) ? "MEDIA"
|
||||
: (contentType_ == NotificationContent::Type::MULTILINE) ? "MULTILINE"
|
||||
: (contentType_ == NotificationContent::Type::PICTURE) ? "PICTURE" : "NONE";
|
||||
|
||||
return "NotificationContent[ contentType = " + contentTypeStr +
|
||||
", content = " + (content_ ? "not null" : "null") + "]";
|
||||
}
|
||||
|
||||
bool NotificationContent::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
if (!parcel.WriteInt32(static_cast<int32_t>(contentType_))) {
|
||||
ANS_LOGE("Failed to write contentType");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto valid = content_ ? true : false;
|
||||
if (!parcel.WriteBool(valid)) {
|
||||
ANS_LOGE("Failed to write the flag which indicate whether content is null");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (valid) {
|
||||
if (!parcel.WriteParcelable(content_.get())) {
|
||||
ANS_LOGE("Failed to write content");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
NotificationContent *NotificationContent::Unmarshalling(Parcel &parcel)
|
||||
{
|
||||
auto pContent = new NotificationContent();
|
||||
if ((nullptr != pContent) && !pContent->ReadFromParcel(parcel)) {
|
||||
delete pContent;
|
||||
pContent = nullptr;
|
||||
}
|
||||
|
||||
return pContent;
|
||||
}
|
||||
|
||||
bool NotificationContent::ReadFromParcel(Parcel &parcel)
|
||||
{
|
||||
contentType_ = static_cast<NotificationContent::Type>(parcel.ReadInt32());
|
||||
|
||||
auto valid = parcel.ReadBool();
|
||||
if (!valid) {
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (contentType_) {
|
||||
case NotificationContent::Type::BASIC_TEXT: {
|
||||
std::shared_ptr<NotificationNormalContent> normalContent(
|
||||
parcel.ReadParcelable<NotificationNormalContent>());
|
||||
if (!normalContent) {
|
||||
ANS_LOGE("Failed to read normal content");
|
||||
return false;
|
||||
}
|
||||
content_ = std::dynamic_pointer_cast<NotificationBasicContent>(normalContent);
|
||||
} break;
|
||||
case NotificationContent::Type::CONVERSATION: {
|
||||
std::shared_ptr<NotificationConversationalContent> conversationalContent(
|
||||
parcel.ReadParcelable<NotificationConversationalContent>());
|
||||
if (!conversationalContent) {
|
||||
ANS_LOGE("Failed to read conversational content");
|
||||
return false;
|
||||
}
|
||||
content_ = std::dynamic_pointer_cast<NotificationBasicContent>(conversationalContent);
|
||||
} break;
|
||||
case NotificationContent::Type::LONG_TEXT: {
|
||||
std::shared_ptr<NotificationLongTextContent> longTextContent(
|
||||
parcel.ReadParcelable<NotificationLongTextContent>());
|
||||
if (!longTextContent) {
|
||||
ANS_LOGE("Failed to read long text content");
|
||||
return false;
|
||||
}
|
||||
content_ = std::dynamic_pointer_cast<NotificationBasicContent>(longTextContent);
|
||||
} break;
|
||||
case NotificationContent::Type::MEDIA: {
|
||||
std::shared_ptr<NotificationMediaContent> mediaContent(parcel.ReadParcelable<NotificationMediaContent>());
|
||||
if (!mediaContent) {
|
||||
ANS_LOGE("Failed to read media content");
|
||||
return false;
|
||||
}
|
||||
content_ = std::dynamic_pointer_cast<NotificationBasicContent>(mediaContent);
|
||||
} break;
|
||||
case NotificationContent::Type::MULTILINE: {
|
||||
std::shared_ptr<NotificationMultiLineContent> multiLineContent(
|
||||
parcel.ReadParcelable<NotificationMultiLineContent>());
|
||||
if (!multiLineContent) {
|
||||
ANS_LOGE("Failed to read multiLine content");
|
||||
return false;
|
||||
}
|
||||
content_ = std::dynamic_pointer_cast<NotificationBasicContent>(multiLineContent);
|
||||
} break;
|
||||
case NotificationContent::Type::PICTURE: {
|
||||
std::shared_ptr<NotificationPictureContent> pictureContent(
|
||||
parcel.ReadParcelable<NotificationPictureContent>());
|
||||
if (!pictureContent) {
|
||||
ANS_LOGE("Failed to read picture content");
|
||||
return false;
|
||||
}
|
||||
content_ = std::dynamic_pointer_cast<NotificationBasicContent>(pictureContent);
|
||||
} break;
|
||||
default: {
|
||||
return false;
|
||||
} break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,185 @@
|
||||
/*
|
||||
* 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 "notification_conversational_content.h"
|
||||
#include "ans_log_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
NotificationConversationalContent::NotificationConversationalContent(const MessageUser &messageUser)
|
||||
: messageUser_(messageUser)
|
||||
{}
|
||||
|
||||
MessageUser NotificationConversationalContent::GetMessageUser() const
|
||||
{
|
||||
return messageUser_;
|
||||
}
|
||||
|
||||
void NotificationConversationalContent::SetConversationTitle(const std::string &conversationTitle)
|
||||
{
|
||||
conversationTitle_ = conversationTitle;
|
||||
}
|
||||
|
||||
std::string NotificationConversationalContent::GetConversationTitle() const
|
||||
{
|
||||
return conversationTitle_;
|
||||
}
|
||||
|
||||
bool NotificationConversationalContent::IsConversationGroup() const
|
||||
{
|
||||
return isGroup_;
|
||||
}
|
||||
|
||||
void NotificationConversationalContent::SetConversationGroup(bool isGroup)
|
||||
{
|
||||
isGroup_ = isGroup;
|
||||
}
|
||||
|
||||
void NotificationConversationalContent::AddConversationalMessage(
|
||||
const std::string &text, int64_t timestamp, const MessageUser &sender)
|
||||
{
|
||||
auto message = std::make_shared<NotificationConversationalMessage>(text, timestamp, sender);
|
||||
if (!message) {
|
||||
ANS_LOGE("Failed to create message");
|
||||
return;
|
||||
}
|
||||
|
||||
messages_.emplace_back(message);
|
||||
}
|
||||
|
||||
void NotificationConversationalContent::AddConversationalMessage(const MessagePtr &message)
|
||||
{
|
||||
if (!message) {
|
||||
ANS_LOGE("Message can not be null");
|
||||
return;
|
||||
}
|
||||
|
||||
messages_.emplace_back(message);
|
||||
}
|
||||
|
||||
NotificationConversationalContent::MessageVector NotificationConversationalContent::GetAllConversationalMessages() const
|
||||
{
|
||||
return messages_;
|
||||
}
|
||||
|
||||
std::string NotificationConversationalContent::Dump()
|
||||
{
|
||||
return "NotificationConversationalContent[ " + NotificationBasicContent::Dump() +
|
||||
", conversationTitle = " + conversationTitle_ + ", isGroup = " + (isGroup_ ? "true" : "false") +
|
||||
", messageUser = " + messageUser_.Dump() +
|
||||
", messages = " + (!messages_.empty() ? "not empty" : "empty") + " ]";
|
||||
}
|
||||
|
||||
bool NotificationConversationalContent::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
if (!NotificationBasicContent::Marshalling(parcel)) {
|
||||
ANS_LOGE("Failed to write basic");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteString(conversationTitle_)) {
|
||||
ANS_LOGE("Failed to write conversation title");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteBool(isGroup_)) {
|
||||
ANS_LOGE("Failed to write flag group");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteParcelable(&messageUser_)) {
|
||||
ANS_LOGE("Failed to write messageUser");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteInt32(static_cast<int32_t>(messages_.size()))) {
|
||||
ANS_LOGE("Failed to write the size of messages");
|
||||
return false;
|
||||
}
|
||||
|
||||
for (auto it = messages_.begin(); it != messages_.end(); ++it) {
|
||||
auto valid = (*it) ? true : false;
|
||||
if (!parcel.WriteBool(valid)) {
|
||||
ANS_LOGE("Failed to write the flag which indicate whether message is null");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!valid) {
|
||||
ANS_LOGE("Invalid message, write to parcel failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteParcelable(it->get())) {
|
||||
ANS_LOGE("Failed to write message");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
NotificationConversationalContent *NotificationConversationalContent::Unmarshalling(Parcel &parcel)
|
||||
{
|
||||
auto pContent = new NotificationConversationalContent();
|
||||
if ((nullptr != pContent) && !pContent->ReadFromParcel(parcel)) {
|
||||
delete pContent;
|
||||
pContent = nullptr;
|
||||
}
|
||||
|
||||
return pContent;
|
||||
}
|
||||
|
||||
bool NotificationConversationalContent::ReadFromParcel(Parcel &parcel)
|
||||
{
|
||||
if (!NotificationBasicContent::ReadFromParcel(parcel)) {
|
||||
ANS_LOGE("Failed to read basic");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.ReadString(conversationTitle_)) {
|
||||
ANS_LOGE("Failed to read conversation title");
|
||||
return false;
|
||||
}
|
||||
|
||||
isGroup_ = parcel.ReadBool();
|
||||
|
||||
auto pUser = parcel.ReadParcelable<MessageUser>();
|
||||
if (pUser == nullptr) {
|
||||
ANS_LOGE("Failed to read messageUser");
|
||||
return false;
|
||||
}
|
||||
messageUser_ = *pUser;
|
||||
|
||||
auto vsize = parcel.ReadInt32();
|
||||
for (auto it = 0; it < vsize; ++it) {
|
||||
auto valid = parcel.ReadBool();
|
||||
if (!valid) {
|
||||
ANS_LOGE("Invalid message, read from parcel failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto member = parcel.ReadParcelable<NotificationConversationalMessage>();
|
||||
if (member == nullptr) {
|
||||
ANS_LOGE("Failed to read message");
|
||||
return false;
|
||||
}
|
||||
|
||||
messages_.emplace_back(member);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* 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 "notification_conversational_message.h"
|
||||
#include "ans_log_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
NotificationConversationalMessage::NotificationConversationalMessage(
|
||||
const std::string &text, int64_t timestamp, const MessageUser &sender)
|
||||
: arrivedTime_(timestamp), text_(text), sender_(sender)
|
||||
{}
|
||||
|
||||
std::string NotificationConversationalMessage::GetText() const
|
||||
{
|
||||
return text_;
|
||||
}
|
||||
|
||||
int64_t NotificationConversationalMessage::GetArrivedTime() const
|
||||
{
|
||||
return arrivedTime_;
|
||||
}
|
||||
|
||||
MessageUser NotificationConversationalMessage::GetSender() const
|
||||
{
|
||||
return sender_;
|
||||
}
|
||||
|
||||
void NotificationConversationalMessage::SetData(const std::string &mimeType, const std::shared_ptr<Uri> &uri)
|
||||
{
|
||||
mimeType_ = mimeType;
|
||||
uri_ = uri;
|
||||
}
|
||||
|
||||
std::string NotificationConversationalMessage::GetMimeType() const
|
||||
{
|
||||
return mimeType_;
|
||||
}
|
||||
|
||||
const std::shared_ptr<Uri> NotificationConversationalMessage::GetUri() const
|
||||
{
|
||||
return uri_;
|
||||
}
|
||||
|
||||
std::string NotificationConversationalMessage::Dump()
|
||||
{
|
||||
return "NotificationConversationalMessage[ text = " + text_ + ", arrivedTime = " + std::to_string(arrivedTime_) +
|
||||
", mimeType = " + mimeType_ + ", uri = " + (uri_ ? uri_->ToString() : "null") +
|
||||
", sender = " + sender_.Dump() + " ]";
|
||||
}
|
||||
|
||||
bool NotificationConversationalMessage::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
if (!parcel.WriteInt64(arrivedTime_)) {
|
||||
ANS_LOGE("Failed to write arrived time");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteString(text_)) {
|
||||
ANS_LOGE("Failed to write text");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteParcelable(&sender_)) {
|
||||
ANS_LOGE("Failed to write sender");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto valid = uri_ ? true : false;
|
||||
if (!parcel.WriteBool(valid)) {
|
||||
ANS_LOGE("Failed to write the flag which indicate whether uri is null");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (valid) {
|
||||
if (!parcel.WriteParcelable(uri_.get())) {
|
||||
ANS_LOGE("Failed to write uri");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!parcel.WriteString(mimeType_)) {
|
||||
ANS_LOGE("Failed to write MIME type");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
NotificationConversationalMessage *NotificationConversationalMessage::Unmarshalling(Parcel &parcel)
|
||||
{
|
||||
auto pMessage = new NotificationConversationalMessage();
|
||||
if ((nullptr != pMessage) && !pMessage->ReadFromParcel(parcel)) {
|
||||
delete pMessage;
|
||||
pMessage = nullptr;
|
||||
}
|
||||
|
||||
return pMessage;
|
||||
}
|
||||
|
||||
bool NotificationConversationalMessage::ReadFromParcel(Parcel &parcel)
|
||||
{
|
||||
arrivedTime_ = parcel.ReadInt64();
|
||||
|
||||
if (!parcel.ReadString(text_)) {
|
||||
ANS_LOGE("Failed to read text");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto pUser = parcel.ReadParcelable<MessageUser>();
|
||||
if (pUser == nullptr) {
|
||||
ANS_LOGE("Failed to read sender");
|
||||
return false;
|
||||
}
|
||||
sender_ = *pUser;
|
||||
|
||||
auto valid = parcel.ReadBool();
|
||||
if (valid) {
|
||||
uri_ = std::shared_ptr<Uri>(parcel.ReadParcelable<Uri>());
|
||||
if (!uri_) {
|
||||
ANS_LOGE("Failed to read uri");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!parcel.ReadString(mimeType_)) {
|
||||
ANS_LOGE("Failed to read MIME type");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,256 @@
|
||||
/*
|
||||
* 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 "notification_helper.h"
|
||||
#include "ans_notification.h"
|
||||
#include "singleton.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
ErrCode NotificationHelper::AddNotificationSlot(const NotificationSlot &slot)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->AddNotificationSlot(slot);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::AddNotificationSlots(const std::vector<NotificationSlot> &slots)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->AddNotificationSlots(slots);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::RemoveNotificationSlot(const NotificationConstant::SlotType &slotType)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->RemoveNotificationSlot(slotType);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::GetNotificationSlot(
|
||||
const NotificationConstant::SlotType &slotType, sptr<NotificationSlot> &slot)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->GetNotificationSlot(slotType, slot);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::GetNotificationSlots(std::vector<sptr<NotificationSlot>> &slots)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->GetNotificationSlots(slots);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::AddNotificationSlotGroup(const NotificationSlotGroup &slotGroup)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->AddNotificationSlotGroup(slotGroup);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::AddNotificationSlotGroups(const std::vector<NotificationSlotGroup> &slotGroups)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->AddNotificationSlotGroups(slotGroups);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::RemoveNotificationSlotGroup(const std::string &slotGroupId)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->RemoveNotificationSlotGroup(slotGroupId);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::GetNotificationSlotGroup(const std::string &groupId, sptr<NotificationSlotGroup> &group)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->GetNotificationSlotGroup(groupId, group);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::GetNotificationSlotGroups(std::vector<sptr<NotificationSlotGroup>> &groups)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->GetNotificationSlotGroups(groups);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::PublishNotification(const NotificationRequest &request)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->PublishNotification(request);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::PublishNotification(const std::string &label, const NotificationRequest &request)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->PublishNotification(label, request);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::PublishNotification(const NotificationRequest &request, const std::string &deviceId)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->PublishNotification(request, deviceId);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::CancelNotification(int32_t notificationId)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->CancelNotification(notificationId);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::CancelNotification(const std::string &label, int32_t notificationId)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->CancelNotification(label, notificationId);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::CancelAllNotifications()
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->CancelAllNotifications();
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::GetActiveNotificationNums(int32_t &num)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->GetActiveNotificationNums(num);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::GetActiveNotifications(std::vector<sptr<NotificationRequest>> &request)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->GetActiveNotifications(request);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::GetCurrentAppSorting(sptr<NotificationSortingMap> &sortingMap)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->GetCurrentAppSorting(sortingMap);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::SetNotificationAgent(const std::string &agent)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->SetNotificationAgent(agent);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::GetNotificationAgent(std::string &agent)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->GetNotificationAgent(agent);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::CanPublishNotificationAsBundle(const std::string &representativeBundle, bool &canPublish)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->CanPublishNotificationAsBundle(
|
||||
representativeBundle, canPublish);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::PublishNotificationAsBundle(
|
||||
const std::string &representativeBundle, const NotificationRequest &request)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->PublishNotificationAsBundle(representativeBundle, request);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::SetNotificationBadgeNum()
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->SetNotificationBadgeNum();
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::SetNotificationBadgeNum(int32_t num)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->SetNotificationBadgeNum(num);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::IsAllowedNotify(bool &allowed)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->IsAllowedNotify(allowed);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::AreNotificationsSuspended(bool &suspended)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->AreNotificationsSuspended(suspended);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::HasNotificationPolicyAccessPermission(bool &hasPermission)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->HasNotificationPolicyAccessPermission(hasPermission);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::GetBundleImportance(NotificationSlot::NotificationLevel &importance)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->GetBundleImportance(importance);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::SubscribeNotification(const NotificationSubscriber &subscriber)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->SubscribeNotification(subscriber);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::SubscribeNotification(
|
||||
const NotificationSubscriber &subscriber, const NotificationSubscribeInfo &subscribeInfo)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->SubscribeNotification(subscriber, subscribeInfo);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::UnSubscribeNotification(NotificationSubscriber &subscriber)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->UnSubscribeNotification(subscriber);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::UnSubscribeNotification(
|
||||
NotificationSubscriber &subscriber, NotificationSubscribeInfo subscribeInfo)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->UnSubscribeNotification(subscriber, subscribeInfo);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::RemoveNotification(const std::string &key)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->RemoveNotification(key);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::RemoveNotifications(const std::string &bundleName)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->RemoveNotifications(bundleName);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::RemoveNotifications()
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->RemoveNotifications();
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::GetNotificationSlotsForBundle(
|
||||
const std::string &bundleName, std::vector<sptr<NotificationSlot>> &slots)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->GetNotificationSlotsForBundle(bundleName, slots);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::GetAllActiveNotifications(std::vector<sptr<Notification>> ¬ification)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->GetAllActiveNotifications(notification);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::GetAllActiveNotifications(
|
||||
const std::vector<std::string> key, std::vector<sptr<Notification>> ¬ification)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->GetAllActiveNotifications(key, notification);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::IsAllowedNotify(const std::string &bundle, bool &allowed)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->IsAllowedNotify(bundle, allowed);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::SetNotificationsEnabledForAllBundles(const std::string &deviceId, bool enabled)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->SetNotificationsEnabledForAllBundles(deviceId, enabled);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::SetNotificationsEnabledForDefaultBundle(const std::string &deviceId, bool enabled)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->SetNotificationsEnabledForDefaultBundle(deviceId, enabled);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::SetNotificationsEnabledForSpecifiedBundle(
|
||||
const std::string &bundle, std::string &deviceId, bool enabled)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->SetNotificationsEnabledForSpecifiedBundle(
|
||||
bundle, deviceId, enabled);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::SetDisturbMode(NotificationConstant::DisturbMode mode)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->SetDisturbMode(mode);
|
||||
}
|
||||
|
||||
ErrCode NotificationHelper::GetDisturbMode(NotificationConstant::DisturbMode &disturbMode)
|
||||
{
|
||||
return DelayedSingleton<AnsNotification>::GetInstance()->GetDisturbMode(disturbMode);
|
||||
}
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* 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 <algorithm>
|
||||
#include "notification_long_text_content.h"
|
||||
#include "ans_log_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
const std::size_t NotificationLongTextContent::MAX_LONGTEXT_LENGTH{1024};
|
||||
|
||||
NotificationLongTextContent::NotificationLongTextContent(const std::string &longText)
|
||||
{
|
||||
SetLongText(longText);
|
||||
}
|
||||
|
||||
void NotificationLongTextContent::SetExpandedTitle(const std::string &exTitle)
|
||||
{
|
||||
expandedTitle_ = exTitle;
|
||||
}
|
||||
|
||||
std::string NotificationLongTextContent::GetExpandedTitle() const
|
||||
{
|
||||
return expandedTitle_;
|
||||
}
|
||||
|
||||
void NotificationLongTextContent::SetBriefText(const std::string &briefText)
|
||||
{
|
||||
briefText_ = briefText;
|
||||
}
|
||||
|
||||
std::string NotificationLongTextContent::GetBriefText() const
|
||||
{
|
||||
return briefText_;
|
||||
}
|
||||
|
||||
void NotificationLongTextContent::SetLongText(const std::string &longText)
|
||||
{
|
||||
if (longText.empty()) {
|
||||
longText_.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
auto length = std::min(NotificationLongTextContent::MAX_LONGTEXT_LENGTH, longText.length());
|
||||
longText_.assign(longText.begin(), longText.begin() + length);
|
||||
}
|
||||
|
||||
std::string NotificationLongTextContent::GetLongText() const
|
||||
{
|
||||
return longText_;
|
||||
}
|
||||
|
||||
std::string NotificationLongTextContent::Dump()
|
||||
{
|
||||
return "NotificationLongTextContent[ " + NotificationBasicContent::Dump() +
|
||||
" longText = " + longText_ + " briefText = " + briefText_ +
|
||||
" expandedTitle = " + expandedTitle_ + " ]";
|
||||
}
|
||||
|
||||
bool NotificationLongTextContent::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
if (!NotificationBasicContent::Marshalling(parcel)) {
|
||||
ANS_LOGE("Failed to write basic");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteString(expandedTitle_)) {
|
||||
ANS_LOGE("Failed to write expanded title");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteString(briefText_)) {
|
||||
ANS_LOGE("Failed to write brief text");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteString(longText_)) {
|
||||
ANS_LOGE("Failed to write longText");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
NotificationLongTextContent *NotificationLongTextContent::Unmarshalling(Parcel &parcel)
|
||||
{
|
||||
auto pContent = new NotificationLongTextContent();
|
||||
if ((nullptr != pContent) && !pContent->ReadFromParcel(parcel)) {
|
||||
delete pContent;
|
||||
pContent = nullptr;
|
||||
}
|
||||
|
||||
return pContent;
|
||||
}
|
||||
|
||||
bool NotificationLongTextContent::ReadFromParcel(Parcel &parcel)
|
||||
{
|
||||
if (!NotificationBasicContent::ReadFromParcel(parcel)) {
|
||||
ANS_LOGE("Failed to read basic");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.ReadString(expandedTitle_)) {
|
||||
ANS_LOGE("Failed to read expanded title");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.ReadString(briefText_)) {
|
||||
ANS_LOGE("Failed to read brief text");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.ReadString(longText_)) {
|
||||
ANS_LOGE("Failed to read longtext");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* 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 <algorithm>
|
||||
#include "notification_media_content.h"
|
||||
#include "ans_log_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
void NotificationMediaContent::SetAVToken(const std::shared_ptr<AVToken> &avToken)
|
||||
{
|
||||
avToken_ = avToken;
|
||||
}
|
||||
|
||||
const std::shared_ptr<AVToken> NotificationMediaContent::GetAVToken() const
|
||||
{
|
||||
return avToken_;
|
||||
}
|
||||
|
||||
void NotificationMediaContent::SetShownActions(const std::vector<uint32_t> &actions)
|
||||
{
|
||||
sequenceNumbers_ = actions;
|
||||
}
|
||||
|
||||
std::vector<uint32_t> NotificationMediaContent::GetShownActions() const
|
||||
{
|
||||
return sequenceNumbers_;
|
||||
}
|
||||
|
||||
std::string NotificationMediaContent::Dump()
|
||||
{
|
||||
std::string numbers{};
|
||||
std::for_each(sequenceNumbers_.begin(), sequenceNumbers_.end(), [&numbers](int32_t num) {
|
||||
numbers += std::to_string(num) + " ";
|
||||
});
|
||||
|
||||
return "NotificationMediaContent[ " + NotificationBasicContent::Dump() +
|
||||
", avToken = " + (avToken_ ? "not null" : "null") + ", sequenceNumbers = " + numbers + " ]";
|
||||
}
|
||||
|
||||
bool NotificationMediaContent::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
if (!NotificationBasicContent::Marshalling(parcel)) {
|
||||
ANS_LOGE("Failed to write basic");
|
||||
return false;
|
||||
}
|
||||
|
||||
// auto valid = avToken_ ? true : false;
|
||||
// if (!parcel.WriteBool(valid)) {
|
||||
// ANS_LOGE("Failed to write the flag which indicate whether avToken is null");
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// if (valid) {
|
||||
// if (!parcel.WriteParcelable(avToken_.get())) {
|
||||
// ANS_LOGE("Failed to write avToken");
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
if (!parcel.WriteUInt32Vector(sequenceNumbers_)) {
|
||||
ANS_LOGE("Failed to write sequence numbers");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
NotificationMediaContent *NotificationMediaContent::Unmarshalling(Parcel &parcel)
|
||||
{
|
||||
auto pContent = new NotificationMediaContent();
|
||||
if ((nullptr != pContent) && !pContent->ReadFromParcel(parcel)) {
|
||||
delete pContent;
|
||||
pContent = nullptr;
|
||||
}
|
||||
|
||||
return pContent;
|
||||
}
|
||||
|
||||
bool NotificationMediaContent::ReadFromParcel(Parcel &parcel)
|
||||
{
|
||||
if (!NotificationBasicContent::ReadFromParcel(parcel)) {
|
||||
ANS_LOGE("Failed to read basic");
|
||||
return false;
|
||||
}
|
||||
|
||||
// auto valid = parcel.ReadBool();
|
||||
// if (valid) {
|
||||
// avToken_ = std::shared_ptr<AVToken>(parcel.ReadParcelable<AVToken>());
|
||||
// if (!avToken_) {
|
||||
// ANS_LOGE("Failed to read avToken");
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
if (!parcel.ReadUInt32Vector(&sequenceNumbers_)) {
|
||||
ANS_LOGE("Failed to read sequence numbers");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* 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 <algorithm>
|
||||
#include "notification_multiline_content.h"
|
||||
#include "ans_log_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
const std::vector<std::string>::size_type NotificationMultiLineContent::MAX_LINES{7};
|
||||
|
||||
void NotificationMultiLineContent::SetExpandedTitle(const std::string &exTitle)
|
||||
{
|
||||
expandedTitle_ = exTitle;
|
||||
}
|
||||
|
||||
std::string NotificationMultiLineContent::GetExpandedTitle() const
|
||||
{
|
||||
return expandedTitle_;
|
||||
}
|
||||
|
||||
void NotificationMultiLineContent::SetBriefText(const std::string &briefText)
|
||||
{
|
||||
briefText_ = briefText;
|
||||
}
|
||||
|
||||
std::string NotificationMultiLineContent::GetBriefText() const
|
||||
{
|
||||
return briefText_;
|
||||
}
|
||||
|
||||
void NotificationMultiLineContent::AddSingleLine(const std::string &oneLine)
|
||||
{
|
||||
if (allLines_.size() >= NotificationMultiLineContent::MAX_LINES) {
|
||||
ANS_LOGW("already added seven lines");
|
||||
return;
|
||||
}
|
||||
|
||||
allLines_.emplace_back(oneLine);
|
||||
}
|
||||
|
||||
std::vector<std::string> NotificationMultiLineContent::GetAllLines() const
|
||||
{
|
||||
return allLines_;
|
||||
}
|
||||
|
||||
std::string NotificationMultiLineContent::Dump()
|
||||
{
|
||||
std::string lines{};
|
||||
std::for_each(
|
||||
allLines_.begin(), allLines_.end(), [&lines](const std::string &line) { lines += " " + line + ","; });
|
||||
lines.pop_back();
|
||||
|
||||
return "NotificationMultiLineContent[ " + NotificationBasicContent::Dump() + ", briefText = " + briefText_ +
|
||||
", expandedTitle = " + expandedTitle_ + ", allLines = [" + lines + " ] ]";
|
||||
}
|
||||
|
||||
bool NotificationMultiLineContent::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
if (!NotificationBasicContent::Marshalling(parcel)) {
|
||||
ANS_LOGE("Failed to write basic");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteString(expandedTitle_)) {
|
||||
ANS_LOGE("Failed to write expanded title");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteString(briefText_)) {
|
||||
ANS_LOGE("Failed to write brief text");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteStringVector(allLines_)) {
|
||||
ANS_LOGE("Failed to write all lines");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
NotificationMultiLineContent *NotificationMultiLineContent::Unmarshalling(Parcel &parcel)
|
||||
{
|
||||
auto pContent = new NotificationMultiLineContent();
|
||||
if ((nullptr != pContent) && !pContent->ReadFromParcel(parcel)) {
|
||||
delete pContent;
|
||||
pContent = nullptr;
|
||||
}
|
||||
|
||||
return pContent;
|
||||
}
|
||||
|
||||
bool NotificationMultiLineContent::ReadFromParcel(Parcel &parcel)
|
||||
{
|
||||
if (!NotificationBasicContent::ReadFromParcel(parcel)) {
|
||||
ANS_LOGE("Failed to read basic");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.ReadString(expandedTitle_)) {
|
||||
ANS_LOGE("Failed to read expanded title");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.ReadString(briefText_)) {
|
||||
ANS_LOGE("Failed to read brief text");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.ReadStringVector(&allLines_)) {
|
||||
ANS_LOGE("Failed to read all lines");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
#include "notification_normal_content.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
std::string NotificationNormalContent::Dump()
|
||||
{
|
||||
return "NotificationNormalContent[ " + NotificationBasicContent::Dump() + " ]";
|
||||
}
|
||||
|
||||
bool NotificationNormalContent::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
return NotificationBasicContent::Marshalling(parcel);
|
||||
}
|
||||
|
||||
NotificationNormalContent *NotificationNormalContent::Unmarshalling(Parcel &parcel)
|
||||
{
|
||||
auto pContent = new NotificationNormalContent();
|
||||
if ((nullptr != pContent) && !pContent->ReadFromParcel(parcel)) {
|
||||
delete pContent;
|
||||
pContent = nullptr;
|
||||
}
|
||||
|
||||
return pContent;
|
||||
}
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* 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 "notification_picture_content.h"
|
||||
#include "ans_log_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
void NotificationPictureContent::SetExpandedTitle(const std::string &exTitle)
|
||||
{
|
||||
expandedTitle_ = exTitle;
|
||||
}
|
||||
|
||||
std::string NotificationPictureContent::GetExpandedTitle() const
|
||||
{
|
||||
return expandedTitle_;
|
||||
}
|
||||
|
||||
void NotificationPictureContent::SetBriefText(const std::string &briefText)
|
||||
{
|
||||
briefText_ = briefText;
|
||||
}
|
||||
|
||||
std::string NotificationPictureContent::GetBriefText() const
|
||||
{
|
||||
return briefText_;
|
||||
}
|
||||
|
||||
void NotificationPictureContent::SetBigPicture(const std::shared_ptr<PixelMap> &bigPicture)
|
||||
{
|
||||
bigPicture_ = bigPicture;
|
||||
}
|
||||
|
||||
const std::shared_ptr<PixelMap> NotificationPictureContent::GetBigPicture() const
|
||||
{
|
||||
return bigPicture_;
|
||||
}
|
||||
|
||||
std::string NotificationPictureContent::Dump()
|
||||
{
|
||||
return "NotificationPictureContent[ " + NotificationBasicContent::Dump() + ", briefText = " + briefText_ +
|
||||
", expandedTitle = " + expandedTitle_ + ", bigPicture = " + (bigPicture_ ? "not null" : "null") + " ]";
|
||||
}
|
||||
|
||||
bool NotificationPictureContent::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
if (!NotificationBasicContent::Marshalling(parcel)) {
|
||||
ANS_LOGE("Failed to write basic");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteString(expandedTitle_)) {
|
||||
ANS_LOGE("Failed to write expanded title");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteString(briefText_)) {
|
||||
ANS_LOGE("Failed to write brief text");
|
||||
return false;
|
||||
}
|
||||
|
||||
// auto valid = bigPicture_ ? true : false;
|
||||
// if (!parcel.WriteBool(valid)) {
|
||||
// ANS_LOGE("Failed to write the flag which indicate whether bigPicture is null");
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// if (valid) {
|
||||
// if (!parcel.WriteParcelable(bigPicture_.get())) {
|
||||
// ANS_LOGE("Failed to write bigPicture");
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
NotificationPictureContent *NotificationPictureContent::Unmarshalling(Parcel &parcel)
|
||||
{
|
||||
auto pContent = new NotificationPictureContent();
|
||||
if ((nullptr != pContent) && !pContent->ReadFromParcel(parcel)) {
|
||||
delete pContent;
|
||||
pContent = nullptr;
|
||||
}
|
||||
|
||||
return pContent;
|
||||
}
|
||||
|
||||
bool NotificationPictureContent::ReadFromParcel(Parcel &parcel)
|
||||
{
|
||||
if (!NotificationBasicContent::ReadFromParcel(parcel)) {
|
||||
ANS_LOGE("Failed to read basic");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.ReadString(expandedTitle_)) {
|
||||
ANS_LOGE("Failed to read expanded title");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.ReadString(briefText_)) {
|
||||
ANS_LOGE("Failed to read brief text");
|
||||
return false;
|
||||
}
|
||||
|
||||
// auto valid = parcel.ReadBool();
|
||||
// if (valid) {
|
||||
// bigPicture_ = std::shared_ptr<PixelMap>(parcel.ReadParcelable<PixelMap>());
|
||||
// if (!bigPicture_) {
|
||||
// ANS_LOGE("Failed to read bigPicture");
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
return true;
|
||||
}
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,341 @@
|
||||
/*
|
||||
* 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 "notification_slot.h"
|
||||
#include "ans_log_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
|
||||
const int MAX_TEXT_LENGTH = 1000;
|
||||
|
||||
NotificationSlot::NotificationSlot(NotificationConstant::SlotType type) : sound_("")
|
||||
{
|
||||
SetType(type);
|
||||
}
|
||||
|
||||
NotificationSlot::~NotificationSlot()
|
||||
{}
|
||||
|
||||
bool NotificationSlot::CanEnableLight() const
|
||||
{
|
||||
return isLightEnabled_;
|
||||
}
|
||||
|
||||
void NotificationSlot::SetEnableLight(bool isLightEnabled)
|
||||
{
|
||||
isLightEnabled_ = isLightEnabled;
|
||||
}
|
||||
|
||||
bool NotificationSlot::CanVibrate() const
|
||||
{
|
||||
return isVibrationEnabled_;
|
||||
}
|
||||
|
||||
void NotificationSlot::SetEnableVibration(bool vibration)
|
||||
{
|
||||
isVibrationEnabled_ = vibration;
|
||||
}
|
||||
|
||||
std::string NotificationSlot::GetDescription() const
|
||||
{
|
||||
return description_;
|
||||
}
|
||||
|
||||
void NotificationSlot::SetDescription(const std::string &description)
|
||||
{
|
||||
description_ = TruncateString(description);
|
||||
}
|
||||
|
||||
std::string NotificationSlot::GetId() const
|
||||
{
|
||||
return id_;
|
||||
}
|
||||
|
||||
int32_t NotificationSlot::GetLedLightColor() const
|
||||
{
|
||||
return lightColor_;
|
||||
}
|
||||
|
||||
void NotificationSlot::SetLedLightColor(int32_t color)
|
||||
{
|
||||
lightColor_ = color;
|
||||
}
|
||||
|
||||
NotificationSlot::NotificationLevel NotificationSlot::GetLevel() const
|
||||
{
|
||||
return level_;
|
||||
}
|
||||
|
||||
void NotificationSlot::SetLevel(NotificationLevel level)
|
||||
{
|
||||
level_ = level;
|
||||
}
|
||||
|
||||
NotificationConstant::SlotType NotificationSlot::GetType() const
|
||||
{
|
||||
return type_;
|
||||
}
|
||||
|
||||
void NotificationSlot::SetType(NotificationConstant::SlotType type)
|
||||
{
|
||||
type_ = NotificationConstant::SlotType::CUSTOM;
|
||||
switch (type) {
|
||||
case NotificationConstant::SlotType::SOCIAL_COMMUNICATION:
|
||||
id_ = "SOCIAL_COMMUNICATION";
|
||||
SetName("SOCIAL_COMMUNICATION");
|
||||
SetLockscreenVisibleness(NotificationConstant::VisiblenessType::PUBLIC);
|
||||
SetEnableVibration(true);
|
||||
break;
|
||||
case NotificationConstant::SlotType::SERVICE_REMINDER:
|
||||
id_ = "SERVICE_REMINDER";
|
||||
SetName("SERVICE_REMINDER");
|
||||
SetLockscreenVisibleness(NotificationConstant::VisiblenessType::PUBLIC);
|
||||
SetEnableVibration(true);
|
||||
break;
|
||||
case NotificationConstant::SlotType::CONTENT_INFORMATION:
|
||||
id_ = "CONTENT_INFORMATION";
|
||||
SetName("CONTENT_INFORMATION");
|
||||
SetLockscreenVisibleness(NotificationConstant::VisiblenessType::PRIVATE);
|
||||
SetEnableVibration(false);
|
||||
break;
|
||||
case NotificationConstant::SlotType::OTHER:
|
||||
id_ = "OTHER";
|
||||
SetName("OTHER");
|
||||
SetLockscreenVisibleness(NotificationConstant::VisiblenessType::PRIVATE);
|
||||
SetEnableVibration(false);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
type_ = type;
|
||||
}
|
||||
|
||||
NotificationConstant::VisiblenessType NotificationSlot::GetLockScreenVisibleness() const
|
||||
{
|
||||
return lockScreenVisibleness_;
|
||||
}
|
||||
|
||||
void NotificationSlot::SetLockscreenVisibleness(NotificationConstant::VisiblenessType visibleness)
|
||||
{
|
||||
lockScreenVisibleness_ = visibleness;
|
||||
}
|
||||
|
||||
std::string NotificationSlot::GetName() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
void NotificationSlot::SetName(const std::string &name)
|
||||
{
|
||||
name_ = TruncateString(name);
|
||||
}
|
||||
|
||||
std::string NotificationSlot::GetSlotGroup() const
|
||||
{
|
||||
return groupId_;
|
||||
}
|
||||
|
||||
void NotificationSlot::SetSlotGroup(const std::string &groupId)
|
||||
{
|
||||
groupId_ = groupId;
|
||||
}
|
||||
|
||||
Uri NotificationSlot::GetSound() const
|
||||
{
|
||||
return sound_;
|
||||
}
|
||||
|
||||
void NotificationSlot::SetSound(const Uri &sound)
|
||||
{
|
||||
sound_ = sound;
|
||||
}
|
||||
|
||||
std::vector<int64_t> NotificationSlot::GetVibrationStyle() const
|
||||
{
|
||||
return vibrationValues_;
|
||||
}
|
||||
|
||||
void NotificationSlot::SetVibrationStyle(const std::vector<int64_t> &vibrationValues)
|
||||
{
|
||||
isVibrationEnabled_ = (vibrationValues.size() > 0);
|
||||
vibrationValues_ = vibrationValues;
|
||||
}
|
||||
|
||||
bool NotificationSlot::IsEnableBypassDnd() const
|
||||
{
|
||||
return isBypassDnd_;
|
||||
}
|
||||
|
||||
void NotificationSlot::EnableBypassDnd(bool isBypassDnd)
|
||||
{
|
||||
isBypassDnd_ = isBypassDnd;
|
||||
}
|
||||
|
||||
bool NotificationSlot::IsShowBadge() const
|
||||
{
|
||||
return isShowBadge_;
|
||||
}
|
||||
|
||||
void NotificationSlot::EnableBadge(bool isShowBadge)
|
||||
{
|
||||
isShowBadge_ = isShowBadge;
|
||||
}
|
||||
|
||||
std::string NotificationSlot::Dump() const
|
||||
{
|
||||
return "NotificationSlot[id = " + id_ + ", name = " + name_ + ", description = " + description_ +
|
||||
", type = " + std::to_string(static_cast<int32_t>(type_)) +
|
||||
", level = " + std::to_string(static_cast<int32_t>(level_)) +
|
||||
", isBypassDnd = " + std::to_string(isBypassDnd_) +
|
||||
", visibleness = " + std::to_string(static_cast<int32_t>(lockScreenVisibleness_)) +
|
||||
", sound = " + sound_.ToString() + ", isLightEnabled = " + std::to_string(isLightEnabled_) +
|
||||
", lightColor = " + std::to_string(lightColor_) + ", isVibrate = " + std::to_string(isVibrationEnabled_) +
|
||||
", vibration = " + MergeVectorToString(vibrationValues_) +
|
||||
", isShowBadge = " + std::to_string(isShowBadge_) + ", groupId = " + groupId_ + "]";
|
||||
}
|
||||
|
||||
bool NotificationSlot::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
if (!parcel.WriteString(id_)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteString(name_)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteBool(isLightEnabled_)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteBool(isVibrationEnabled_)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteBool(isShowBadge_)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteBool(isBypassDnd_)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteString(description_)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteInt32(lightColor_)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteInt32(static_cast<int32_t>(level_))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteInt32(static_cast<int32_t>(type_))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteInt32(static_cast<int32_t>(lockScreenVisibleness_))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteString(groupId_)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (sound_.ToString().empty()) {
|
||||
if (!parcel.WriteInt32(VALUE_NULL)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!parcel.WriteInt32(VALUE_OBJECT)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteString((sound_.ToString()))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!parcel.WriteInt64Vector(vibrationValues_)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NotificationSlot::ReadFromParcel(Parcel &parcel)
|
||||
{
|
||||
id_ = parcel.ReadString();
|
||||
name_ = parcel.ReadString();
|
||||
isLightEnabled_ = parcel.ReadBool();
|
||||
isVibrationEnabled_ = parcel.ReadBool();
|
||||
isShowBadge_ = parcel.ReadBool();
|
||||
isBypassDnd_ = parcel.ReadBool();
|
||||
description_ = parcel.ReadString();
|
||||
lightColor_ = parcel.ReadInt32();
|
||||
level_ = static_cast<NotificationLevel>(parcel.ReadInt32());
|
||||
type_ = static_cast<NotificationConstant::SlotType>(parcel.ReadInt32());
|
||||
lockScreenVisibleness_ = static_cast<NotificationConstant::VisiblenessType>(parcel.ReadInt32());
|
||||
groupId_ = parcel.ReadString();
|
||||
|
||||
int empty = VALUE_NULL;
|
||||
if (!parcel.ReadInt32(empty)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (empty == VALUE_OBJECT) {
|
||||
sound_ = Uri((parcel.ReadString()));
|
||||
}
|
||||
|
||||
parcel.ReadInt64Vector(&vibrationValues_);
|
||||
return true;
|
||||
}
|
||||
|
||||
NotificationSlot *NotificationSlot::Unmarshalling(Parcel &parcel)
|
||||
{
|
||||
NotificationSlot *notificationSlot = new NotificationSlot(NotificationConstant::SlotType::CUSTOM);
|
||||
|
||||
if (notificationSlot && !notificationSlot->ReadFromParcel(parcel)) {
|
||||
delete notificationSlot;
|
||||
notificationSlot = nullptr;
|
||||
}
|
||||
|
||||
return notificationSlot;
|
||||
}
|
||||
|
||||
std::string NotificationSlot::MergeVectorToString(const std::vector<int64_t> &mergeVector) const
|
||||
{
|
||||
std::string contents;
|
||||
for (auto it = mergeVector.begin(); it != mergeVector.end(); ++it) {
|
||||
contents += std::to_string(*it);
|
||||
if (it != mergeVector.end() - 1) {
|
||||
contents += ", ";
|
||||
}
|
||||
}
|
||||
return contents;
|
||||
}
|
||||
|
||||
std::string NotificationSlot::TruncateString(const std::string &in)
|
||||
{
|
||||
std::string temp = in;
|
||||
if (in.length() > MAX_TEXT_LENGTH) {
|
||||
temp = in.substr(0, MAX_TEXT_LENGTH);
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* 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 "notification_slot_group.h"
|
||||
|
||||
#include "string_ex.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
const int MAX_TEXT_LENGTH = 1000;
|
||||
const std::string LINE_SEPARATOR = "\n";
|
||||
|
||||
NotificationSlotGroup::NotificationSlotGroup()
|
||||
{}
|
||||
|
||||
NotificationSlotGroup::NotificationSlotGroup(const std::string &id, const std::string &name) : id_(id), name_(name)
|
||||
{
|
||||
id_ = TruncateString(id);
|
||||
name_ = TruncateString(name);
|
||||
}
|
||||
|
||||
NotificationSlotGroup::~NotificationSlotGroup()
|
||||
{}
|
||||
|
||||
std::string NotificationSlotGroup::GetDescription() const
|
||||
{
|
||||
return description_;
|
||||
}
|
||||
|
||||
std::string NotificationSlotGroup::GetId() const
|
||||
{
|
||||
return id_;
|
||||
}
|
||||
|
||||
std::string NotificationSlotGroup::GetName() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
std::vector<NotificationSlot> NotificationSlotGroup::GetSlots() const
|
||||
{
|
||||
return slots_;
|
||||
}
|
||||
|
||||
bool NotificationSlotGroup::IsDisabled() const
|
||||
{
|
||||
return isDisabled_;
|
||||
}
|
||||
|
||||
void NotificationSlotGroup::SetDescription(const std::string &description)
|
||||
{
|
||||
description_ = TruncateString(description);
|
||||
}
|
||||
|
||||
std::string NotificationSlotGroup::Dump() const
|
||||
{
|
||||
std::string contents;
|
||||
for (auto it = slots_.begin(); it != slots_.end(); ++it) {
|
||||
contents += it->Dump();
|
||||
if (it != slots_.end() - 1) {
|
||||
contents += ",";
|
||||
}
|
||||
}
|
||||
return "NotificationSlotGroup[id = " + id_ +
|
||||
", name = " + name_ +
|
||||
", description = " + description_ +
|
||||
", slots = " + contents +
|
||||
", isDisabled = " + std::to_string(isDisabled_) + "]";
|
||||
}
|
||||
|
||||
bool NotificationSlotGroup::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
if (!parcel.WriteString(id_)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteString(name_)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteString(description_)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (slots_.size() == 0) {
|
||||
if (!parcel.WriteInt32(0)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!parcel.WriteInt32(slots_.size())) {
|
||||
return false;
|
||||
}
|
||||
for (auto it = slots_.begin(); it != slots_.end(); ++it) {
|
||||
if (!it->Marshalling(parcel)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!parcel.WriteBool(isDisabled_)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NotificationSlotGroup::ReadFromParcel(Parcel &parcel)
|
||||
{
|
||||
id_ = parcel.ReadString();
|
||||
name_ = parcel.ReadString();
|
||||
description_ = parcel.ReadString();
|
||||
|
||||
if (slots_.size() == 0) {
|
||||
if (!parcel.ReadInt32()) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!parcel.ReadInt32()) {
|
||||
return false;
|
||||
}
|
||||
for (auto it = slots_.begin(); it != slots_.end(); ++it) {
|
||||
slots_.emplace_back(*it->Unmarshalling(parcel));
|
||||
}
|
||||
}
|
||||
|
||||
isDisabled_ = parcel.ReadBool();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
NotificationSlotGroup *NotificationSlotGroup::Unmarshalling(Parcel &parcel)
|
||||
{
|
||||
NotificationSlotGroup *notificationSlotGroup = new NotificationSlotGroup();
|
||||
|
||||
if (!notificationSlotGroup && !notificationSlotGroup->ReadFromParcel(parcel)) {
|
||||
delete notificationSlotGroup;
|
||||
notificationSlotGroup = nullptr;
|
||||
}
|
||||
|
||||
return notificationSlotGroup;
|
||||
}
|
||||
|
||||
std::string NotificationSlotGroup::TruncateString(const std::string &inPutString)
|
||||
{
|
||||
std::string temp = inPutString;
|
||||
if (inPutString.length() > MAX_TEXT_LENGTH) {
|
||||
temp = inPutString.substr(0, MAX_TEXT_LENGTH);
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* 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 "notification_sorting.h"
|
||||
|
||||
#include "string_ex.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
NotificationSorting::NotificationSorting()
|
||||
{}
|
||||
|
||||
NotificationSorting::~NotificationSorting()
|
||||
{}
|
||||
|
||||
NotificationSorting::NotificationSorting(const NotificationSorting &sorting)
|
||||
{
|
||||
key_ = sorting.key_;
|
||||
ranking_ = sorting.ranking_;
|
||||
importance_ = sorting.importance_;
|
||||
isDisplayBadge_ = sorting.isDisplayBadge_;
|
||||
isHiddenNotification_ = sorting.isHiddenNotification_;
|
||||
visiblenessOverride_ = sorting.visiblenessOverride_;
|
||||
groupKeyOverride_ = sorting.groupKeyOverride_;
|
||||
slot_ = sorting.slot_;
|
||||
}
|
||||
|
||||
void NotificationSorting::SetSlot(const sptr<NotificationSlot> &slot)
|
||||
{
|
||||
slot_ = slot;
|
||||
}
|
||||
|
||||
void NotificationSorting::SetGroupKeyOverride(const std::string &groupKeyOverride)
|
||||
{
|
||||
groupKeyOverride_ = groupKeyOverride;
|
||||
}
|
||||
|
||||
std::string NotificationSorting::Dump() const
|
||||
{
|
||||
std::string contents{""};
|
||||
if (slot_ != nullptr) {
|
||||
contents = slot_->Dump();
|
||||
} else {
|
||||
contents = "nullptr";
|
||||
}
|
||||
return "NotificationSorting[key =" + key_ + ", ranking =" + std::to_string(ranking_) +
|
||||
", importance =" + std::to_string(importance_) +
|
||||
", visiblenessOverride =" + std::to_string(visiblenessOverride_) +
|
||||
", isDisplayBadge =" + std::to_string(isDisplayBadge_) +
|
||||
", isHiddenNotification =" + std::to_string(isHiddenNotification_) +
|
||||
", groupKeyOverride =" + groupKeyOverride_ + ", slot_ =" + contents + "]";
|
||||
}
|
||||
|
||||
bool NotificationSorting::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
if (!parcel.WriteString(key_)) {
|
||||
ANS_LOGE("Can't write key");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteInt32(ranking_)) {
|
||||
ANS_LOGE("Can't write ranking");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteInt32(importance_)) {
|
||||
ANS_LOGE("Can't write importance");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteInt32(visiblenessOverride_)) {
|
||||
ANS_LOGE("Can't write importance");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteBool(isDisplayBadge_)) {
|
||||
ANS_LOGE("Can't write isDisplayBadge");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteBool(isHiddenNotification_)) {
|
||||
ANS_LOGE("Can't write is HiddenNotification");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteString(groupKeyOverride_)) {
|
||||
ANS_LOGE("Can't write groupKey groupKeyOverride");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteStrongParcelable(slot_)) {
|
||||
ANS_LOGE("Can't write slot");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NotificationSorting::ReadFromParcel(Parcel &parcel)
|
||||
{
|
||||
// read key_
|
||||
key_ = parcel.ReadString();
|
||||
|
||||
// read ranking_
|
||||
ranking_ = parcel.ReadInt32();
|
||||
|
||||
// read importance_
|
||||
importance_ = parcel.ReadInt32();
|
||||
|
||||
// read visiblenessOverride_
|
||||
visiblenessOverride_ = parcel.ReadInt32();
|
||||
|
||||
// read isDisplayBadge_
|
||||
isDisplayBadge_ = parcel.ReadBool();
|
||||
|
||||
// read isHiddenNotification_
|
||||
isHiddenNotification_ = parcel.ReadBool();
|
||||
|
||||
// read groupKeyOverride_
|
||||
groupKeyOverride_ = parcel.ReadString();
|
||||
|
||||
// read slot_
|
||||
slot_ = parcel.ReadStrongParcelable<NotificationSlot>();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
NotificationSorting *NotificationSorting::Unmarshalling(Parcel &parcel)
|
||||
{
|
||||
NotificationSorting *sorting = new NotificationSorting();
|
||||
if (sorting && !sorting->ReadFromParcel(parcel)) {
|
||||
delete sorting;
|
||||
sorting = nullptr;
|
||||
}
|
||||
return sorting;
|
||||
}
|
||||
|
||||
void NotificationSorting::SetKey(const std::string &key)
|
||||
{
|
||||
key_ = key;
|
||||
}
|
||||
|
||||
void NotificationSorting::SetImportance(const int32_t &importance)
|
||||
{
|
||||
importance_ = importance;
|
||||
}
|
||||
|
||||
void NotificationSorting::SetRanking(const int32_t &ranking)
|
||||
{
|
||||
ranking_ = ranking;
|
||||
}
|
||||
|
||||
void NotificationSorting::SetVisiblenessOverride(const int32_t &visibleness)
|
||||
{
|
||||
visiblenessOverride_ = visibleness;
|
||||
}
|
||||
|
||||
void NotificationSorting::SetDisplayBadge(const bool &isDisplayBadge)
|
||||
{
|
||||
isDisplayBadge_ = isDisplayBadge;
|
||||
}
|
||||
|
||||
void NotificationSorting::SetHiddenNotification(const bool &isHiddenNotification)
|
||||
{
|
||||
isHiddenNotification_ = isHiddenNotification;
|
||||
}
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* 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 "notification_sorting_map.h"
|
||||
|
||||
#include "parcel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
NotificationSortingMap::NotificationSortingMap()
|
||||
{}
|
||||
|
||||
NotificationSortingMap::~NotificationSortingMap()
|
||||
{}
|
||||
|
||||
NotificationSortingMap::NotificationSortingMap(const std::vector<NotificationSorting> &sortingList)
|
||||
{
|
||||
for (auto item : sortingList) {
|
||||
sortedKey_.push_back(item.GetKey());
|
||||
sortings_[item.GetKey()] = item;
|
||||
}
|
||||
}
|
||||
|
||||
void NotificationSortingMap::SetKey(const std::string &key)
|
||||
{
|
||||
auto it = std::find(sortedKey_.cbegin(), sortedKey_.cend(), key);
|
||||
if (it == sortedKey_.cend()) {
|
||||
sortedKey_.emplace_back(key);
|
||||
}
|
||||
}
|
||||
|
||||
bool NotificationSortingMap::GetNotificationSorting(const std::string &key, NotificationSorting &sorting) const
|
||||
{
|
||||
for (auto item : sortings_) {
|
||||
if (item.first == key) {
|
||||
sorting = item.second;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void NotificationSortingMap::SetNotificationSorting(const std::vector<NotificationSorting> &sortingList)
|
||||
{
|
||||
for (auto item : sortingList) {
|
||||
sortedKey_.push_back(item.GetKey());
|
||||
sortings_[item.GetKey()] = item;
|
||||
}
|
||||
}
|
||||
|
||||
bool NotificationSortingMap::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
bool ret = true;
|
||||
if (!parcel.WriteInt32(sortings_.size())) {
|
||||
ANS_LOGE("Can't write sorting size");
|
||||
return false;
|
||||
}
|
||||
for_each(sortings_.begin(), sortings_.end(), [&](std::pair<std::string, NotificationSorting> sorting) {
|
||||
if (!parcel.WriteParcelable(&sorting.second)) {
|
||||
ANS_LOGE("Can't write sorting");
|
||||
ret = false;
|
||||
}
|
||||
});
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
NotificationSortingMap *NotificationSortingMap::Unmarshalling(Parcel &parcel)
|
||||
{
|
||||
std::vector<NotificationSorting> sortings;
|
||||
// read sorting num
|
||||
int32_t size;
|
||||
parcel.ReadInt32(size);
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
// read sorting
|
||||
NotificationSorting a = *parcel.ReadParcelable<NotificationSorting>();
|
||||
sortings.push_back(a);
|
||||
}
|
||||
|
||||
NotificationSortingMap *sortingMap = new NotificationSortingMap(sortings);
|
||||
return sortingMap;
|
||||
}
|
||||
std::string NotificationSortingMap::Dump() const
|
||||
{
|
||||
int keyNum = 0;
|
||||
std::string separator;
|
||||
std::string keys = " sortedkey = ";
|
||||
for (auto item : sortedKey_) {
|
||||
if (keyNum == 0) {
|
||||
separator = "";
|
||||
} else {
|
||||
separator = ", ";
|
||||
}
|
||||
keys = keys + separator + item;
|
||||
keyNum++;
|
||||
}
|
||||
return "NotificationSortingMap[" + keys + "]";
|
||||
}
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
#include "notification_subscribe_info.h"
|
||||
|
||||
#include "ans_log_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
|
||||
NotificationSubscribeInfo::NotificationSubscribeInfo()
|
||||
{}
|
||||
|
||||
NotificationSubscribeInfo::~NotificationSubscribeInfo()
|
||||
{}
|
||||
|
||||
NotificationSubscribeInfo::NotificationSubscribeInfo(const NotificationSubscribeInfo &subscribeInfo)
|
||||
{
|
||||
appNames_ = subscribeInfo.GetAppNames();
|
||||
}
|
||||
|
||||
void NotificationSubscribeInfo::AddAppName(const std::string appName)
|
||||
{
|
||||
appNames_.push_back(appName);
|
||||
}
|
||||
|
||||
void NotificationSubscribeInfo::AddAppNames(const std::vector<std::string> &appNames)
|
||||
{
|
||||
appNames_.insert(appNames_.end(), appNames.begin(), appNames.end());
|
||||
}
|
||||
|
||||
std::vector<std::string> NotificationSubscribeInfo::GetAppNames() const
|
||||
{
|
||||
return appNames_;
|
||||
}
|
||||
|
||||
bool NotificationSubscribeInfo::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
// write appNames_
|
||||
if (!parcel.WriteStringVector(appNames_)) {
|
||||
ANS_LOGE("Can't write appNames_");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
NotificationSubscribeInfo *NotificationSubscribeInfo::Unmarshalling(Parcel &parcel)
|
||||
{
|
||||
NotificationSubscribeInfo *info = new NotificationSubscribeInfo();
|
||||
if (info && !info->ReadFromParcel(parcel)) {
|
||||
delete info;
|
||||
info = nullptr;
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
bool NotificationSubscribeInfo::ReadFromParcel(Parcel &parcel)
|
||||
{
|
||||
parcel.ReadStringVector(&appNames_);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string NotificationSubscribeInfo::Dump()
|
||||
{
|
||||
return "Dump";
|
||||
}
|
||||
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
@@ -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 "notification_subscriber.h"
|
||||
|
||||
#include "iservice_registry.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
|
||||
const sptr<NotificationSubscriber::SubscriberImpl> NotificationSubscriber::GetImpl() const
|
||||
{
|
||||
return impl_;
|
||||
}
|
||||
|
||||
NotificationSubscriber::SubscriberImpl::SubscriberImpl(NotificationSubscriber &subscriber) : subscriber_(subscriber)
|
||||
{
|
||||
recipient_ = new DeathRecipient(*this);
|
||||
};
|
||||
|
||||
void NotificationSubscriber::SubscriberImpl::OnSubscribeResult(NotificationConstant::SubscribeResult result)
|
||||
{
|
||||
if (result == 0 && GetAnsManagerProxy()) {
|
||||
proxy_->AsObject()->AddDeathRecipient(recipient_);
|
||||
ANS_LOGD("%s, Add death recipient.", __func__);
|
||||
}
|
||||
subscriber_.OnSubscribeResult(result);
|
||||
}
|
||||
|
||||
void NotificationSubscriber::SubscriberImpl::OnUnsubscribeResult(NotificationConstant::SubscribeResult result)
|
||||
{
|
||||
if (result == 0 && GetAnsManagerProxy()) {
|
||||
proxy_->AsObject()->RemoveDeathRecipient(recipient_);
|
||||
ANS_LOGD("%s, Remove death recipient.", __func__);
|
||||
}
|
||||
subscriber_.OnUnsubscribeResult(result);
|
||||
}
|
||||
|
||||
void NotificationSubscriber::SubscriberImpl::OnConsumed(const sptr<Notification> ¬ification)
|
||||
{
|
||||
subscriber_.OnConsumed(std::make_shared<Notification>(*notification));
|
||||
}
|
||||
|
||||
void NotificationSubscriber::SubscriberImpl::OnConsumed(
|
||||
const sptr<Notification> ¬ification, const sptr<NotificationSortingMap> ¬ificationMap)
|
||||
{
|
||||
subscriber_.OnConsumed(
|
||||
std::make_shared<Notification>(*notification), std::make_shared<NotificationSortingMap>(*notificationMap));
|
||||
}
|
||||
|
||||
void NotificationSubscriber::SubscriberImpl::OnCanceled(const sptr<Notification> ¬ification)
|
||||
{
|
||||
subscriber_.OnCanceled(std::make_shared<Notification>(*notification));
|
||||
}
|
||||
|
||||
void NotificationSubscriber::SubscriberImpl::OnCanceled(
|
||||
const sptr<Notification> ¬ification, const sptr<NotificationSortingMap> ¬ificationMap, int deleteReason)
|
||||
{
|
||||
subscriber_.OnCanceled(std::make_shared<Notification>(*notification),
|
||||
std::make_shared<NotificationSortingMap>(*notificationMap),
|
||||
deleteReason);
|
||||
}
|
||||
|
||||
void NotificationSubscriber::SubscriberImpl::OnUpdated(const sptr<NotificationSortingMap> ¬ificationMap)
|
||||
{
|
||||
subscriber_.OnUpdate(std::make_shared<NotificationSortingMap>(*notificationMap));
|
||||
}
|
||||
|
||||
void NotificationSubscriber::SubscriberImpl::OnDisturbModeChanged(NotificationConstant::DisturbMode mode)
|
||||
{
|
||||
subscriber_.OnDisturbModeChanged(mode);
|
||||
}
|
||||
|
||||
bool NotificationSubscriber::SubscriberImpl::GetAnsManagerProxy()
|
||||
{
|
||||
if (nullptr == proxy_) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (nullptr == proxy_) {
|
||||
sptr<ISystemAbilityManager> systemAbilityManager =
|
||||
SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (!systemAbilityManager) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> remoteObject =
|
||||
systemAbilityManager->GetSystemAbility(ADVANCED_NOTIFICATION_SERVICE_ABILITY_ID);
|
||||
if (!remoteObject) {
|
||||
return false;
|
||||
}
|
||||
|
||||
proxy_ = iface_cast<IAnsManager>(remoteObject);
|
||||
if ((nullptr == proxy_) || (nullptr == proxy_->AsObject())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
NotificationSubscriber::SubscriberImpl::DeathRecipient::DeathRecipient(SubscriberImpl &subscriberImpl)
|
||||
: subscriberImpl_(subscriberImpl){};
|
||||
|
||||
NotificationSubscriber::SubscriberImpl::DeathRecipient::~DeathRecipient(){};
|
||||
|
||||
void NotificationSubscriber::SubscriberImpl::DeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &object)
|
||||
{
|
||||
subscriberImpl_.proxy_ = nullptr;
|
||||
subscriberImpl_.subscriber_.OnDied();
|
||||
}
|
||||
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,320 @@
|
||||
/*
|
||||
* 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 "notification_user_input.h"
|
||||
|
||||
#include <new>
|
||||
#include "ans_log_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Notification {
|
||||
void NotificationUserInput::SetInputsSource(AAFwk::Want &want, NotificationConstant::InputsSource source)
|
||||
{
|
||||
want.SetParam(NotificationConstant::EXTRA_INPUTS_SOURCE, static_cast<int32_t>(source));
|
||||
}
|
||||
|
||||
NotificationConstant::InputsSource NotificationUserInput::GetInputsSource(const AAFwk::Want &want)
|
||||
{
|
||||
auto inputsSource = want.GetIntParam(NotificationConstant::EXTRA_INPUTS_SOURCE,
|
||||
static_cast<int32_t>(NotificationConstant::InputsSource::FREE_FORM_INPUT));
|
||||
return static_cast<NotificationConstant::InputsSource>(inputsSource);
|
||||
}
|
||||
|
||||
void NotificationUserInput::AddInputsToWant(const std::vector<std::shared_ptr<NotificationUserInput>> &userInputs,
|
||||
AAFwk::Want &want, const AppExecFwk::PacMap &pacMap)
|
||||
{}
|
||||
|
||||
std::shared_ptr<AppExecFwk::PacMap> NotificationUserInput::GetInputsFromWant(const AAFwk::Want &want)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
void NotificationUserInput::AddMimeInputToWant(const NotificationUserInput &userInput, AAFwk::Want &want,
|
||||
const std::map<std::string, std::shared_ptr<Uri>> &results)
|
||||
{}
|
||||
|
||||
std::map<std::string, std::shared_ptr<Uri>> NotificationUserInput::GetMimeInputsFromWant(
|
||||
const AAFwk::Want &want, const std::string &inputKey)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
std::shared_ptr<NotificationUserInput> NotificationUserInput::Create(const std::string &inputKey)
|
||||
{
|
||||
if (inputKey.empty()) {
|
||||
ANS_LOGE("The param of inputKey is empty");
|
||||
return {};
|
||||
}
|
||||
|
||||
auto pUserInput = new (std::nothrow) NotificationUserInput(inputKey);
|
||||
if (pUserInput == nullptr) {
|
||||
ANS_LOGE("create NotificationUserInput object failed");
|
||||
return {};
|
||||
}
|
||||
|
||||
return std::shared_ptr<NotificationUserInput>(pUserInput);
|
||||
}
|
||||
|
||||
std::shared_ptr<NotificationUserInput> NotificationUserInput::Create(const std::string &inputKey,
|
||||
const std::string &tag, const std::vector<std::string> &options, bool permitFreeFormInput,
|
||||
const std::set<std::string> &permitMimeTypes, const std::shared_ptr<AppExecFwk::PacMap> &pacMap,
|
||||
NotificationConstant::InputEditType editType)
|
||||
{
|
||||
if (inputKey.empty()) {
|
||||
ANS_LOGE("The param of inputKey is empty");
|
||||
return {};
|
||||
}
|
||||
|
||||
if (!permitFreeFormInput) {
|
||||
if (editType == NotificationConstant::InputEditType::EDIT_ENABLED) {
|
||||
ANS_LOGE("Setting editType to enable requires permitFreeFormInput to be set to true");
|
||||
return {};
|
||||
}
|
||||
|
||||
if (options.empty() && permitMimeTypes.empty()) {
|
||||
ANS_LOGE("options and permitMimeTypes cannot be empty at the same time");
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
auto realPacMap = pacMap;
|
||||
if (!realPacMap) {
|
||||
realPacMap = std::make_shared<AppExecFwk::PacMap>();
|
||||
}
|
||||
|
||||
auto pUserInput = new (std::nothrow)
|
||||
NotificationUserInput(inputKey, tag, options, permitFreeFormInput, permitMimeTypes, realPacMap, editType);
|
||||
if (pUserInput == nullptr) {
|
||||
ANS_LOGE("create NotificationUserInput object failed");
|
||||
return {};
|
||||
}
|
||||
|
||||
return std::shared_ptr<NotificationUserInput>(pUserInput);
|
||||
}
|
||||
|
||||
NotificationUserInput::NotificationUserInput(const std::string &inputKey)
|
||||
: inputKey_(inputKey), pacMap_(std::make_shared<AppExecFwk::PacMap>())
|
||||
{}
|
||||
|
||||
NotificationUserInput::NotificationUserInput(const std::string &inputKey, const std::string &tag,
|
||||
const std::vector<std::string> &options, bool permitFreeFormInput, const std::set<std::string> &permitMimeTypes,
|
||||
const std::shared_ptr<AppExecFwk::PacMap> &pacMap, NotificationConstant::InputEditType editType)
|
||||
: inputKey_(inputKey),
|
||||
tag_(tag),
|
||||
options_(options),
|
||||
permitFreeFormInput_(permitFreeFormInput),
|
||||
permitMimeTypes_(permitMimeTypes),
|
||||
pacMap_(pacMap),
|
||||
editType_(editType)
|
||||
{}
|
||||
|
||||
std::string NotificationUserInput::GetInputKey() const
|
||||
{
|
||||
return inputKey_;
|
||||
}
|
||||
|
||||
void NotificationUserInput::AddAdditionalData(AppExecFwk::PacMap &pacMap)
|
||||
{
|
||||
pacMap_->PutAll(pacMap);
|
||||
}
|
||||
|
||||
const std::shared_ptr<AppExecFwk::PacMap> NotificationUserInput::GetAdditionalData() const
|
||||
{
|
||||
return pacMap_;
|
||||
}
|
||||
|
||||
void NotificationUserInput::SetEditType(NotificationConstant::InputEditType inputEditType)
|
||||
{
|
||||
editType_ = inputEditType;
|
||||
}
|
||||
|
||||
NotificationConstant::InputEditType NotificationUserInput::GetEditType() const
|
||||
{
|
||||
return editType_;
|
||||
}
|
||||
|
||||
void NotificationUserInput::SetOptions(const std::vector<std::string> &options)
|
||||
{
|
||||
options_ = options;
|
||||
}
|
||||
|
||||
std::vector<std::string> NotificationUserInput::GetOptions() const
|
||||
{
|
||||
return options_;
|
||||
}
|
||||
|
||||
void NotificationUserInput::SetPermitMimeTypes(const std::string &mimeType, bool doPermit)
|
||||
{
|
||||
if (mimeType.empty()) {
|
||||
ANS_LOGE("The mimeType is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (doPermit) {
|
||||
permitMimeTypes_.emplace(mimeType);
|
||||
return;
|
||||
}
|
||||
|
||||
permitMimeTypes_.erase(mimeType);
|
||||
}
|
||||
|
||||
std::set<std::string> NotificationUserInput::GetPermitMimeTypes() const
|
||||
{
|
||||
return permitMimeTypes_;
|
||||
}
|
||||
|
||||
bool NotificationUserInput::IsMimeTypeOnly() const
|
||||
{
|
||||
return !permitFreeFormInput_ && options_.empty() && !permitMimeTypes_.empty();
|
||||
}
|
||||
|
||||
void NotificationUserInput::SetTag(const std::string tag)
|
||||
{
|
||||
tag_ = tag;
|
||||
}
|
||||
|
||||
std::string NotificationUserInput::GetTag() const
|
||||
{
|
||||
return tag_;
|
||||
}
|
||||
|
||||
void NotificationUserInput::SetPermitFreeFormInput(bool permitFreeFormInput)
|
||||
{
|
||||
permitFreeFormInput_ = permitFreeFormInput;
|
||||
}
|
||||
|
||||
bool NotificationUserInput::IsPermitFreeFormInput() const
|
||||
{
|
||||
return permitFreeFormInput_;
|
||||
}
|
||||
|
||||
std::string NotificationUserInput::Dump()
|
||||
{
|
||||
return "NotificationUserInput[ inputKey = " + inputKey_ + " tag = " + tag_ +
|
||||
" permitFreeFormInput = " + (permitFreeFormInput_ ? "true" : "false") +
|
||||
" editType = " + std::to_string(static_cast<int32_t>(editType_)) + " ]";
|
||||
}
|
||||
|
||||
bool NotificationUserInput::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
if (!parcel.WriteString(inputKey_)) {
|
||||
ANS_LOGE("Failed to write inputKey");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteString(tag_)) {
|
||||
ANS_LOGE("Failed to write tag");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteBool(permitFreeFormInput_)) {
|
||||
ANS_LOGE("Failed to write flag permitFreeFormInput");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteInt32(static_cast<int32_t>(editType_))) {
|
||||
ANS_LOGE("Failed to write editType");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto valid = pacMap_ ? true : false;
|
||||
if (!parcel.WriteBool(valid)) {
|
||||
ANS_LOGE("Failed to write the flag which indicate whether pacMap is null");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (valid) {
|
||||
if (!parcel.WriteParcelable(pacMap_.get())) {
|
||||
ANS_LOGE("Failed to write pacMap");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!parcel.WriteStringVector(options_)) {
|
||||
ANS_LOGE("Failed to write options");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteInt32(static_cast<int32_t>(permitMimeTypes_.size()))) {
|
||||
ANS_LOGE("Failed to write the size of permitMimeTypes");
|
||||
return false;
|
||||
}
|
||||
|
||||
for (auto it = permitMimeTypes_.begin(); it != permitMimeTypes_.end(); ++it) {
|
||||
if (!parcel.WriteString(*it)) {
|
||||
ANS_LOGE("Failed to write permitMimeTypes");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
NotificationUserInput *NotificationUserInput::Unmarshalling(Parcel &parcel)
|
||||
{
|
||||
auto pUserInput = new NotificationUserInput();
|
||||
if ((nullptr != pUserInput) && !pUserInput->ReadFromParcel(parcel)) {
|
||||
delete pUserInput;
|
||||
pUserInput = nullptr;
|
||||
}
|
||||
|
||||
return pUserInput;
|
||||
}
|
||||
|
||||
bool NotificationUserInput::ReadFromParcel(Parcel &parcel)
|
||||
{
|
||||
if (!parcel.ReadString(inputKey_)) {
|
||||
ANS_LOGE("Failed to read inputKey");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.ReadString(tag_)) {
|
||||
ANS_LOGE("Failed to read tag");
|
||||
return false;
|
||||
}
|
||||
|
||||
permitFreeFormInput_ = parcel.ReadBool();
|
||||
|
||||
editType_ = static_cast<NotificationConstant::InputEditType>(parcel.ReadInt32());
|
||||
|
||||
auto valid = parcel.ReadBool();
|
||||
if (valid) {
|
||||
pacMap_ = std::shared_ptr<AppExecFwk::PacMap>(parcel.ReadParcelable<AppExecFwk::PacMap>());
|
||||
if (!pacMap_) {
|
||||
ANS_LOGE("Failed to read pacMap");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!parcel.ReadStringVector(&options_)) {
|
||||
ANS_LOGE("Failed to read options");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto ssize = parcel.ReadInt32();
|
||||
for (auto it = 0; it < ssize; ++it) {
|
||||
std::string member{};
|
||||
if (!parcel.ReadString(member)) {
|
||||
ANS_LOGE("Failed to read permitMimeTypes");
|
||||
return false;
|
||||
}
|
||||
|
||||
permitMimeTypes_.emplace(member);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} // namespace Notification
|
||||
} // namespace OHOS
|
||||
@@ -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.
|
||||
|
||||
import("//base/notification/ans_standard/notification.gni")
|
||||
import("//build/ohos.gni")
|
||||
|
||||
group("native_wantagent") {
|
||||
deps = [ ":wantagent_kits" ]
|
||||
}
|
||||
|
||||
config("wantagent_kit_public_config") {
|
||||
visibility = [ ":*" ]
|
||||
|
||||
include_dirs = [
|
||||
"${innerkits_path}/core/include",
|
||||
"${innerkits_path}/base/include",
|
||||
"${kits_path}/native/wantagent/include",
|
||||
"//base/global/resmgr_standard/interfaces/innerkits/include",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/native/include",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/want/include",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content",
|
||||
"//foundation/aafwk/standard/services/abilitymgr/include",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core/include/appmgr",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core/include/bundlemgr",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler/include",
|
||||
"//foundation/appexecfwk/standard/kits/appkit/native/app/include",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_shared_library("wantagent_kits") {
|
||||
include_dirs = [
|
||||
"//utils/native/base/include",
|
||||
"//foundation/aafwk/standard/services/common/include",
|
||||
"//foundation/distributedschedule/safwk/services/safwk/include",
|
||||
"//base/notification/ces_standard/cesfwk/innerkits/include",
|
||||
"//base/notification/ces_standard/cesfwk/kits/native/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"src/completed_dispatcher.cpp",
|
||||
"src/pending_want.cpp",
|
||||
"src/trigger_info.cpp",
|
||||
"src/want_agent.cpp",
|
||||
"src/want_agent_helper.cpp",
|
||||
"src/want_agent_info.cpp",
|
||||
"src/want_agent_log_wrapper.cpp",
|
||||
]
|
||||
|
||||
configs = [ "//utils/native/base:utils_config" ]
|
||||
|
||||
public_configs = [ ":wantagent_kit_public_config" ]
|
||||
|
||||
deps = [
|
||||
"//base/notification/ces_standard/cesfwk/innerkits:cesfwk_innerkits",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/want:want",
|
||||
"//foundation/aafwk/standard/services/abilitymgr:abilityms",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core",
|
||||
"//foundation/appexecfwk/standard/kits:appkit_native",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"samgr_L2:samgr_proxy",
|
||||
]
|
||||
|
||||
if (is_double_framework) {
|
||||
cflags = [ "-DCONFIG_DUAL_FRAMEWORK" ]
|
||||
}
|
||||
|
||||
subsystem_name = "notification"
|
||||
part_name = "ans_standard"
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
#ifndef BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_CANCEL_LISTENER_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_CANCEL_LISTENER_H
|
||||
|
||||
namespace OHOS::Notification::WantAgent {
|
||||
class CancelListener {
|
||||
/**
|
||||
* Called when a Cancel operation as completed.
|
||||
*
|
||||
* @param resultCode The final result code determined by the Send.
|
||||
*/
|
||||
public:
|
||||
virtual void OnCancelled(int resultCode) = 0;
|
||||
virtual ~CancelListener() = default;
|
||||
};
|
||||
} // namespace OHOS::Notification::WantAgent
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_CANCEL_LISTENER_H
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
#ifndef BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_COMPLETED_CALLBACK_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_COMPLETED_CALLBACK_H
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include "want.h"
|
||||
#include "want_params.h"
|
||||
|
||||
namespace OHOS::Notification::WantAgent {
|
||||
class CompletedCallback {
|
||||
|
||||
/**
|
||||
* Called when a Send operation as completed.
|
||||
*
|
||||
* @param want The original Want that was sent.
|
||||
* @param resultCode The final result code determined by the Send.
|
||||
* @param resultData The final data collected by a broadcast.
|
||||
* @param resultExtras The final extras collected by a broadcast.
|
||||
*/
|
||||
public:
|
||||
virtual ~CompletedCallback() = default;
|
||||
virtual void OnSendFinished(const AAFwk::Want &want, int resultCode, const std::string &resultData,
|
||||
const AAFwk::WantParams &resultExtras) = 0;
|
||||
};
|
||||
} // namespace OHOS::Notification::WantAgent
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_COMPLETED_CALLBACK_H
|
||||
@@ -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_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_COMPLETED_DISPATCHER_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_COMPLETED_DISPATCHER_H
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include "completed_callback.h"
|
||||
#include "event_handler.h"
|
||||
#include "want.h"
|
||||
#include "want_params.h"
|
||||
#include "want_receiver_stub.h"
|
||||
|
||||
namespace OHOS::Notification::WantAgent {
|
||||
class PendingWant;
|
||||
class CompletedDispatcher : public AAFwk::WantReceiverStub {
|
||||
private:
|
||||
const std::shared_ptr<PendingWant> pendingWant_;
|
||||
const std::shared_ptr<CompletedCallback> callback_;
|
||||
const std::shared_ptr<AppExecFwk::EventHandler> handler_;
|
||||
AAFwk::Want want_;
|
||||
int resultCode_ = 0;
|
||||
std::string resultData_;
|
||||
AAFwk::WantParams resultExtras_;
|
||||
|
||||
public:
|
||||
CompletedDispatcher(const std::shared_ptr<PendingWant> &pendingWant,
|
||||
const std::shared_ptr<CompletedCallback> &callback, const std::shared_ptr<AppExecFwk::EventHandler> &handler);
|
||||
virtual ~CompletedDispatcher() = default;
|
||||
|
||||
void Send(const int32_t resultCode) override;
|
||||
|
||||
void PerformReceive(const AAFwk::Want &want, int resultCode, const std::string &data,
|
||||
const AAFwk::WantParams &extras, bool serialized, bool sticky, int sendingUser) override;
|
||||
|
||||
void Run();
|
||||
};
|
||||
} // namespace OHOS::Notification::WantAgent
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_COMPLETED_DISPATCHER_H
|
||||
@@ -0,0 +1,275 @@
|
||||
/*
|
||||
* 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_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_INCLUDE_PENDING_WANT_H
|
||||
#define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_INCLUDE_PENDING_WANT_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
#include <memory>
|
||||
#include "cancel_listener.h"
|
||||
#include "context.h"
|
||||
#include "completed_dispatcher.h"
|
||||
#include "event_handler.h"
|
||||
#include "want.h"
|
||||
#include "want_agent_constant.h"
|
||||
#include "want_receiver_stub.h"
|
||||
#include "want_params.h"
|
||||
|
||||
namespace OHOS::Notification::WantAgent {
|
||||
class PendingWant final : public std::enable_shared_from_this<PendingWant>, public Parcelable {
|
||||
public:
|
||||
PendingWant(){};
|
||||
PendingWant(const sptr<AAFwk::IWantSender> &target);
|
||||
PendingWant(const sptr<AAFwk::IWantSender> &target, const sptr<IRemoteObject> whitelistToken);
|
||||
virtual ~PendingWant() = default;
|
||||
|
||||
WantAgentConstant::OperationType GetType(const sptr<AAFwk::IWantSender> &target);
|
||||
|
||||
/**
|
||||
* Retrieve a PendingWant that will start a new ability.
|
||||
*
|
||||
* @param context The Context in which this PendingWant should start
|
||||
* the ability.
|
||||
* @param requestCode Private request code for the sender
|
||||
* @param want Want of the ability to be launched.
|
||||
* @param flags May be FLAG_ONE_SHOT, FLAG_NO_CREATE},
|
||||
* FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT.
|
||||
*
|
||||
* @return Returns an existing or new PendingWant matching the given
|
||||
* parameters. May return null only if FLAG_NO_CREATE has been
|
||||
* supplied.
|
||||
*/
|
||||
static std::shared_ptr<PendingWant> GetAbility(const std::shared_ptr<AppExecFwk::Context> &context, int requestCode,
|
||||
const std::shared_ptr<AAFwk::Want> &want, unsigned int flags);
|
||||
|
||||
/**
|
||||
* Retrieve a PendingWant that will start a new ability
|
||||
*
|
||||
* @param context The Context in which this PendingWant should start
|
||||
* the ability.
|
||||
* @param requestCode Private request code for the sender
|
||||
* @param want Want of the ability to be launched.
|
||||
* @param flags May be FLAG_ONE_SHOT, FLAG_NO_CREATE,
|
||||
* FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT.
|
||||
* @param options Additional options for how the ability should be started.
|
||||
* May be null if there are no options.
|
||||
*
|
||||
* @return Returns an existing or new PendingWant matching the given
|
||||
* parameters. May return null only if FLAG_NO_CREATE has been
|
||||
* supplied.
|
||||
*/
|
||||
static std::shared_ptr<PendingWant> GetAbility(const std::shared_ptr<AppExecFwk::Context> &context, int requestCode,
|
||||
const std::shared_ptr<AAFwk::Want> &want, unsigned int flags,
|
||||
const std::shared_ptr<AAFwk::WantParams> &options);
|
||||
|
||||
/**
|
||||
* Like GetAbility(Context, int, Want, int)}, but allows an
|
||||
* array of Wants to be supplied. The last Want in the array is
|
||||
* taken as the primary key for the PendingWant, like the single Want
|
||||
* given to GetAbility(Context, int, Want, int).
|
||||
*
|
||||
* @param context The Context in which this PendingWant should start
|
||||
* the ability.
|
||||
* @param requestCode Private request code for the sender
|
||||
* @param wants Array of Wants of the abilities to be launched.
|
||||
* @param flags May be FLAG_ONE_SHOT, FLAG_NO_CREATE,
|
||||
* FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT.
|
||||
*
|
||||
* @return Returns an existing or new PendingWant matching the given
|
||||
* parameters. May return null only if FLAG_NO_CREATE has been
|
||||
* supplied.
|
||||
*/
|
||||
static std::shared_ptr<PendingWant> GetAbilities(const std::shared_ptr<AppExecFwk::Context> &context,
|
||||
int requestCode, std::vector<std::shared_ptr<AAFwk::Want>> &wants, unsigned int flags);
|
||||
|
||||
/**
|
||||
* Like GetAbility(Context, int, Want, int)}, but allows an
|
||||
* array of Wants to be supplied. The last Want in the array is
|
||||
* taken as the primary key for the PendingWant, like the single Want
|
||||
* given to GetAbility(Context, int, Want, int).
|
||||
*
|
||||
* @param context The Context in which this PendingWant should start
|
||||
* the ability.
|
||||
* @param requestCode Private request code for the sender
|
||||
* @param wants Array of Wants of the abilities to be launched.
|
||||
* @param flags May be FLAG_ONE_SHOT, FLAG_NO_CREATE,
|
||||
* FLAG_CANCEL_CURRENT} link #FLAG_UPDATE_CURRENT,
|
||||
* FLAG_IMMUTABLE.
|
||||
*
|
||||
* @return Returns an existing or new PendingWant matching the given
|
||||
* parameters. May return null only if FLAG_NO_CREATE has been
|
||||
* supplied.
|
||||
*/
|
||||
static std::shared_ptr<PendingWant> GetAbilities(const std::shared_ptr<AppExecFwk::Context> &context,
|
||||
int requestCode, std::vector<std::shared_ptr<AAFwk::Want>> &wants, unsigned int flags,
|
||||
const std::shared_ptr<AAFwk::WantParams> &options);
|
||||
|
||||
/**
|
||||
* Retrieve a PendingWant that will perform a common event.
|
||||
*
|
||||
* @param context The Context in which this PendingWant should perform
|
||||
* the common event.
|
||||
* @param requestCode Private request code for the sender
|
||||
* @param want The Want to be common event.
|
||||
* @param flags May be FLAG_ONE_SHOT, FLAG_NO_CREATE,
|
||||
* FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT,
|
||||
* FLAG_IMMUTABLE.
|
||||
*
|
||||
* @return Returns an existing or new PendingWant matching the given
|
||||
* parameters. May return null only if FLAG_NO_CREATE has been
|
||||
* supplied.
|
||||
*/
|
||||
static std::shared_ptr<PendingWant> GetCommonEvent(const std::shared_ptr<AppExecFwk::Context> &context,
|
||||
int requestCode, const std::shared_ptr<AAFwk::Want> &want, unsigned int flags);
|
||||
|
||||
/**
|
||||
* Note that current user will be interpreted at the time the
|
||||
* common event is sent, not when the pending want is created.
|
||||
*/
|
||||
static std::shared_ptr<PendingWant> GetCommonEventAsUser(const std::shared_ptr<AppExecFwk::Context> &context,
|
||||
int requestCode, const std::shared_ptr<AAFwk::Want> &want, unsigned int flags, int uid);
|
||||
|
||||
/**
|
||||
* Retrieve a PendingWant that will start a service.
|
||||
*
|
||||
* @param context The Context in which this PendingWant should start
|
||||
* the service.
|
||||
* @param requestCode Private request code for the sender
|
||||
* @param want An Want describing the service to be started.
|
||||
* @param flags May be FLAG_ONE_SHOT, FLAG_NO_CREATE,
|
||||
* FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT,
|
||||
*FLAG_IMMUTABLE.
|
||||
*
|
||||
* @return Returns an existing or new PendingWant matching the given
|
||||
* parameters. May return null only if FLAG_NO_CREATE has been
|
||||
* supplied.
|
||||
*/
|
||||
static std::shared_ptr<PendingWant> GetService(const std::shared_ptr<AppExecFwk::Context> &context, int requestCode,
|
||||
const std::shared_ptr<AAFwk::Want> &want, unsigned int flags);
|
||||
|
||||
/**
|
||||
* Retrieve a PendingWant that will start a foreground service.
|
||||
*
|
||||
* @param context The Context in which this PendingWant should start
|
||||
* the service.
|
||||
* @param requestCode Private request code for the sender
|
||||
* @param want An Want describing the service to be started.
|
||||
* @param flags May be FLAG_ONE_SHOT, FLAG_NO_CREATE,
|
||||
* FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT,
|
||||
* FLAG_IMMUTABLE .
|
||||
*
|
||||
* @return Returns an existing or new PendingWant matching the given
|
||||
* parameters. May return null only if FLAG_NO_CREATE has been
|
||||
* supplied.
|
||||
*/
|
||||
static std::shared_ptr<PendingWant> GetForegroundService(const std::shared_ptr<AppExecFwk::Context> &context,
|
||||
int requestCode, const std::shared_ptr<AAFwk::Want> &want, unsigned int flags);
|
||||
|
||||
/**
|
||||
* @description: Marshals a Want into a Parcel.
|
||||
* Fields in the Want are marshalled separately. If any field fails to be marshalled, false is returned.
|
||||
* @param parcel Indicates the Parcel object for marshalling.
|
||||
* @return Returns true if the marshalling is successful; returns false otherwise.
|
||||
*/
|
||||
virtual bool Marshalling(Parcel &parcel) const;
|
||||
|
||||
/**
|
||||
* @description: Unmarshals a Want from a Parcel.
|
||||
* Fields in the Want are unmarshalled separately. If any field fails to be unmarshalled, false is returned.
|
||||
* @param parcel Indicates the Parcel object for unmarshalling.
|
||||
* @return Returns true if the unmarshalling is successful; returns false otherwise.
|
||||
*/
|
||||
static PendingWant *Unmarshalling(Parcel &parcel);
|
||||
|
||||
static bool Equals(
|
||||
const std::shared_ptr<PendingWant> &targetPendingWant, const std::shared_ptr<PendingWant> &otherPendingWant);
|
||||
|
||||
void Cancel(const sptr<AAFwk::IWantSender> &target);
|
||||
|
||||
void Send(const sptr<AAFwk::IWantSender> &target);
|
||||
|
||||
void Send(int resultCode, const sptr<AAFwk::IWantSender> &target);
|
||||
|
||||
void Send(const std::shared_ptr<AppExecFwk::Context> &context, int resultCode,
|
||||
const std::shared_ptr<AAFwk::Want> &want, const sptr<AAFwk::IWantSender> &target);
|
||||
|
||||
void Send(int resultCode, const sptr<CompletedDispatcher> &onCompleted, const sptr<AAFwk::IWantSender> &target);
|
||||
|
||||
void Send(const std::shared_ptr<AppExecFwk::Context> &context, int resultCode,
|
||||
const std::shared_ptr<AAFwk::Want> &want, const sptr<CompletedDispatcher> &onCompleted,
|
||||
const sptr<AAFwk::IWantSender> &target);
|
||||
|
||||
void Send(const std::shared_ptr<AppExecFwk::Context> &context, int resultCode,
|
||||
const std::shared_ptr<AAFwk::Want> &want, const sptr<CompletedDispatcher> &onCompleted,
|
||||
const std::string &requiredPermission, const sptr<AAFwk::IWantSender> &target);
|
||||
|
||||
void Send(const std::shared_ptr<AppExecFwk::Context> &context, int resultCode,
|
||||
const std::shared_ptr<AAFwk::Want> &want, const sptr<CompletedDispatcher> &onCompleted,
|
||||
const std::string &requiredPermission, const std::shared_ptr<AAFwk::WantParams> &options,
|
||||
const sptr<AAFwk::IWantSender> &target);
|
||||
|
||||
int SendAndReturnResult(const std::shared_ptr<AppExecFwk::Context> &context, int resultCode,
|
||||
const std::shared_ptr<AAFwk::Want> &want, const sptr<CompletedDispatcher> &onCompleted,
|
||||
const std::string &requiredPermission, const std::shared_ptr<AAFwk::WantParams> &options,
|
||||
const sptr<AAFwk::IWantSender> &target);
|
||||
|
||||
std::string GetBundleName(const sptr<AAFwk::IWantSender> &target);
|
||||
|
||||
int GetUid(const sptr<AAFwk::IWantSender> &target);
|
||||
|
||||
sptr<AAFwk::IWantSender> GetTarget();
|
||||
|
||||
void SetTarget(const sptr<AAFwk::IWantSender> &target);
|
||||
|
||||
void RegisterCancelListener(
|
||||
const std::shared_ptr<CancelListener> &cancelListener, const sptr<AAFwk::IWantSender> &target);
|
||||
|
||||
void NotifyCancelListeners(int32_t resultCode);
|
||||
|
||||
void UnregisterCancelListener(
|
||||
const std::shared_ptr<CancelListener> &cancelListener, const sptr<AAFwk::IWantSender> &target);
|
||||
|
||||
int GetHashCode(const sptr<AAFwk::IWantSender> &target);
|
||||
|
||||
std::shared_ptr<AAFwk::Want> GetWant(const sptr<AAFwk::IWantSender> &target);
|
||||
|
||||
private:
|
||||
std::mutex lock_object;
|
||||
sptr<AAFwk::IWantSender> target_;
|
||||
sptr<AAFwk::IWantReceiver> cancelReceiver_;
|
||||
sptr<IRemoteObject> whitelistToken_;
|
||||
std::vector<std::shared_ptr<CancelListener>> cancelListeners_;
|
||||
|
||||
class CancelReceiver : public AAFwk::WantReceiverStub {
|
||||
private:
|
||||
std::weak_ptr<PendingWant> outerInstance_;
|
||||
|
||||
public:
|
||||
explicit CancelReceiver(const std::weak_ptr<PendingWant> &outerInstance);
|
||||
virtual ~CancelReceiver() = default;
|
||||
|
||||
void Send(const int32_t resultCode) override;
|
||||
void PerformReceive(const AAFwk::Want &want, int resultCode, const std::string &data,
|
||||
const AAFwk::WantParams &extras, bool serialized, bool sticky, int sendingUser) override;
|
||||
};
|
||||
|
||||
static std::shared_ptr<PendingWant> BuildServicePendingWant(const std::shared_ptr<AppExecFwk::Context> &context,
|
||||
int requestCode, const std::shared_ptr<AAFwk::Want> &want, unsigned int flags,
|
||||
WantAgentConstant::OperationType serviceKind);
|
||||
};
|
||||
} // namespace OHOS::Notification::WantAgent
|
||||
#endif // BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_WANTAGENT_INCLUDE_PENDING_WANT_H
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user