mirror of
https://github.com/openharmony/miscservices_wallpaper.git
synced 2026-07-01 06:42:05 -04:00
@@ -0,0 +1,25 @@
|
||||
# Copyright (C) 2022 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")
|
||||
|
||||
################################################################################
|
||||
group("wallpaper_native_packages") {
|
||||
if (is_standard_system) {
|
||||
deps = [
|
||||
"etc/init:wallpaperservice.rc",
|
||||
"profile:wallpaper_sa_profiles",
|
||||
"services:wallpaper_service",
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
# miscservices_wallpaper
|
||||
|
||||
#### 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 +1,61 @@
|
||||
# miscservices_wallpaper
|
||||
# wallpaper service
|
||||
|
||||
#### 介绍
|
||||
{**以下是 Gitee 平台说明,您可以替换此简介**
|
||||
Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台
|
||||
无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)}
|
||||
#### Introduction
|
||||
1、Provide wallpaper service capability for the system, and support wallpaper display, setting, switching wallpaper and other functions;
|
||||
|
||||
#### 软件架构
|
||||
软件架构说明
|
||||
2、Provide the framework and interface for developers to develop wallpaper, and develop wallpaper applications;
|
||||
|
||||
|
||||
#### 安装教程
|
||||
#### Interface Introduction
|
||||
**Table 1** Main method of wallpaper service
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
|
||||
#### 使用说明
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
|
||||
#### 参与贡献
|
||||
|
||||
1. Fork 本仓库
|
||||
2. 新建 Feat_xxx 分支
|
||||
3. 提交代码
|
||||
4. 新建 Pull Request
|
||||
<a name="table033515471012"></a>
|
||||
<table><thead align="left"><tr id="row143351854201012"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p103351154121010"><a name="p103351154121010"></a><a name="p103351154121010"></a>Interface Name</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p1033585416105"><a name="p1033585416105"></a><a name="p1033585416105"></a>Description</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>function getColors(wallpaperType: WallpaperType): Promise<Array<RgbaColor>></p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>Obtains the wallpaper colors for the wallpaper of the specified type(system screen or lockscreen),Promise </p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function getId(wallpaperType: WallpaperType): Promise<number></p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>Obtains the ID of the wallpaper of the specified type(system screen or lockscreen),Promise </p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>function getPixelMap(wallpaperType: WallpaperType): Promise<image.PixelMap></p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>Obtains the default pixel map of a wallpaper of the specified type(system screen or lockscreen),Promise</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>function setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType): Promise<void></p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>Sets a wallpaper of the specified type based on the uri path from a JPEG or PNG file or the pixel map of a PNG file(wallpaper path or pixelmap),Promise</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>function on(type: 'colorChange', callback: (colors: Array<RgbaColor>, wallpaperType: WallpaperType) => void): void;
|
||||
</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>Registers a listener for wallpaper color changes to receive notifications about the changes,callback</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>function off(type: 'colorChange', callback?: (colors: Array<RgbaColor>, wallpaperType: WallpaperType) => void): void;
|
||||
</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>Unregisters a listener for wallpaper color changes,callback</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
#### 特技
|
||||
#### Participation contribution
|
||||
|
||||
1. Fork warehouse
|
||||
2. Submission code
|
||||
3. Create a new pull request
|
||||
4. Commit is complete
|
||||
|
||||
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,59 @@
|
||||
# 壁纸服务
|
||||
|
||||
#### 介绍
|
||||
1、为系统提供壁纸服务能力,支持系统显示、设置、切换壁纸等功能;
|
||||
2、为开发者提供开发壁纸的框架和接口,支持开发者开发壁纸应用;
|
||||
|
||||
#### 接口说明
|
||||
**表 1** 壁纸服务开放的主要方法
|
||||
|
||||
<a name="table033515471012"></a>
|
||||
<table><thead align="left"><tr id="row143351854201012"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p103351154121010"><a name="p103351154121010"></a><a name="p103351154121010"></a>接口名</p>
|
||||
</th>
|
||||
<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p1033585416105"><a name="p1033585416105"></a><a name="p1033585416105"></a>描述</p>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>function getColors(wallpaperType: WallpaperType): Promise<Array<RgbaColor>></p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>获取壁纸图片主颜色(桌面或者锁屏壁纸),Promise方式</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function getId(wallpaperType: WallpaperType): Promise<number></p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>获取壁纸id(桌面或者锁屏壁纸),Promise方式</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>function getPixelMap(wallpaperType: WallpaperType): Promise<image.PixelMap></p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>获取壁纸图片的pixelmap(桌面或者锁屏壁纸),Promise方式</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>function setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType): Promise<void></p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>设置壁纸(图片路径或pixelmap),Promise方式</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>function on(type: 'colorChange', callback: (colors: Array<RgbaColor>, wallpaperType: WallpaperType) => void): void;
|
||||
</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>监听壁纸图片主颜色变化,callback方式</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>function off(type: 'colorChange', callback?: (colors: Array<RgbaColor>, wallpaperType: WallpaperType) => void): void;
|
||||
</p>
|
||||
</td>
|
||||
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>取消监听壁纸图片主颜色变化,callback方式</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
#### 参与贡献
|
||||
|
||||
1. Fork 本仓库
|
||||
2. 新建 Feat_xxx 分支
|
||||
3. 提交代码
|
||||
4. 新建 Pull Request
|
||||
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
{
|
||||
"name": "@ohos/wallpaper",
|
||||
"description": "Allowing apps to use OS wallpaper get/set functions",
|
||||
"version": "3.1",
|
||||
"license": "Apache License 2.0",
|
||||
"publishAs": "code-segment",
|
||||
"segment": {
|
||||
"destPath": "base/miscservices/wallpaper"
|
||||
},
|
||||
"dirs": {},
|
||||
"scripts": {},
|
||||
"component": {
|
||||
"name": "wallpaper_native",
|
||||
"subsystem": "miscservices",
|
||||
"syscap": [
|
||||
"SystemCapability.Miscservices.WallpaperFrameworks"
|
||||
],
|
||||
"features": [
|
||||
],
|
||||
"adapted_system_type": [
|
||||
"standard"
|
||||
],
|
||||
"rom":"60MB",
|
||||
"ram":"128MB",
|
||||
"deps": {
|
||||
"components": [
|
||||
"ability_manager",
|
||||
"aafwk_standard",
|
||||
"appexecfwk_standard",
|
||||
"ans_standard",
|
||||
"ces_standard",
|
||||
"distributeddatamgr",
|
||||
"hisysevent_native",
|
||||
"hiviewdfx_hilog_native",
|
||||
"ipc",
|
||||
"permission_standard",
|
||||
"safwk",
|
||||
"samgr_standard",
|
||||
"startup_l2",
|
||||
"utils_base"
|
||||
],
|
||||
"third_party": [
|
||||
"jsoncpp"
|
||||
]
|
||||
},
|
||||
"build": {
|
||||
"sub_component": [
|
||||
"//base/miscservices/wallpaper:wallpaper_native_packages",
|
||||
"//base/miscservices/wallpaper/frameworks/innerkitsimpl/wallpaper_manager:wallpapermanager",
|
||||
"//base/miscservices/wallpaper/frameworks/kits/extension:wallpaperextension",
|
||||
"//base/miscservices/wallpaper/frameworks/kits/extension:wallpaper_extension_module",
|
||||
"//base/miscservices/wallpaper/interfaces/kits/napi/wallpaperextension:wallpaperextension_napi",
|
||||
"//base/miscservices/wallpaper/interfaces/kits/napi/wallpaper_extension_context:wallpaperextensioncontext_napi",
|
||||
"//base/miscservices/wallpaper/interfaces/kits/napi:wallpaperability",
|
||||
"//base/miscservices/wallpaper/utils:wallpaper_utils",
|
||||
"//base/miscservices/wallpaper/frameworks/innerkitsimpl/wallpaper_manager:wallpaperdefault.jpeg",
|
||||
"//base/miscservices/wallpaper/frameworks/innerkitsimpl/wallpaper_manager:wallpaperlockdefault.jpeg"
|
||||
],
|
||||
"test": [
|
||||
"//base/miscservices/wallpaper/test:wallpaper_test"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
# Copyright (C) 2022 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")
|
||||
|
||||
################################################################################
|
||||
|
||||
ohos_prebuilt_etc("wallpaperservice.rc") {
|
||||
source = "wallpaperservice.cfg"
|
||||
relative_install_dir = "init"
|
||||
part_name = "wallpaper_native"
|
||||
subsystem_name = "miscservices"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"jobs" : [{
|
||||
"name" : "boot",
|
||||
"cmds" : [
|
||||
"start wallpaper_service"
|
||||
]
|
||||
}
|
||||
],
|
||||
"services" : [{
|
||||
"name" : "wallpaper_service",
|
||||
"path" : ["/system/bin/sa_main", "/system/profile/wallpaper_service.xml"],
|
||||
"uid" : "system",
|
||||
"gid" : ["system", "shell"]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
# Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
on boot
|
||||
start wallpaper_service
|
||||
service wallpaper_service /system/bin/sa_main /system/profile/wallpaper_service.xml
|
||||
class z_core
|
||||
user system
|
||||
group system shell
|
||||
seclabel u:r:wallpaper_service:s0
|
||||
@@ -0,0 +1,72 @@
|
||||
# Copyright (C) 2022 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")
|
||||
import("//base/miscservices/wallpaper/wallpaper.gni")
|
||||
|
||||
config("wallpaper_manager_config") {
|
||||
visibility = [ ":*" ]
|
||||
include_dirs = [
|
||||
"include",
|
||||
"//base/miscservices/wallpaper/services/include",
|
||||
"//base/miscservices/wallpaper/utils/include",
|
||||
"//base/security/permission/interfaces/innerkits/permission_standard/permissionsdk/main/cpp/include/permission",
|
||||
]
|
||||
cflags_cc = [ "-fexceptions" ]
|
||||
}
|
||||
|
||||
ohos_shared_library("wallpapermanager") {
|
||||
sources = [
|
||||
"src/wallpaper_manager.cpp",
|
||||
"src/wallpaper_service_proxy.cpp",
|
||||
"src/wallpaper_service_cb_stub.cpp",
|
||||
"src/wallpaper_manager_kits.cpp",
|
||||
"src/iwallpaper_color_change_listener.cpp",
|
||||
"src/wallpaper_color_change_listener_client.cpp",
|
||||
#"src/wallpaper_callback_stub.cpp",
|
||||
]
|
||||
public_configs = [
|
||||
":wallpaper_manager_config",
|
||||
]
|
||||
include_dirs = [
|
||||
]
|
||||
deps = [
|
||||
"//base/miscservices/wallpaper/services:wallpaper_service",
|
||||
"//utils/native/base:utils",
|
||||
"//foundation/multimedia/image_standard/interfaces/innerkits:image",
|
||||
"//foundation/multimedia/image_standard/interfaces/innerkits:image_native",
|
||||
"//third_party/zlib:libz",
|
||||
"//third_party/libuv:uv_static",
|
||||
"${utils_path}:wallpaper_utils",
|
||||
"//base/hiviewdfx/hiview/adapter/utility:hiview_adapter_utility",
|
||||
]
|
||||
external_deps = [
|
||||
"ipc:ipc_core",
|
||||
"safwk:system_ability_fwk",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"samgr_standard:samgr_proxy",
|
||||
]
|
||||
subsystem_name = "miscservices"
|
||||
part_name = "wallpaper_native"
|
||||
}
|
||||
|
||||
ohos_prebuilt_etc("wallpaperdefault.jpeg") {
|
||||
source = "data/wallpaperdefault.jpeg"
|
||||
part_name = "wallpaper_native"
|
||||
subsystem_name = "miscservices"
|
||||
}
|
||||
ohos_prebuilt_etc("wallpaperlockdefault.jpeg") {
|
||||
source = "data/wallpaperlockdefault.jpeg"
|
||||
part_name = "wallpaper_native"
|
||||
subsystem_name = "miscservices"
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 56 KiB |
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 I_WALLPAPER_COLOR_CHANGE_LISTENER_H
|
||||
#define I_WALLPAPER_COLOR_CHANGE_LISTENER_H
|
||||
|
||||
#include "wallpaper_color_change_listener.h"
|
||||
#include "iremote_broker.h"
|
||||
#include "iremote_proxy.h"
|
||||
#include "iremote_stub.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace WallpaperMgrService {
|
||||
class IWallpaperColorChangeListener : public IRemoteBroker {
|
||||
public:
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.WallpaperMgrService.IWallpaperColorChangeListener");
|
||||
virtual void onColorsChange(std::vector<RgbaColor> color, int wallpaperType) = 0;
|
||||
};
|
||||
|
||||
class WallpaperColorChangeListenerStub : public IRemoteStub<IWallpaperColorChangeListener> {
|
||||
public:
|
||||
virtual int OnRemoteRequest(uint32_t code, MessageParcel &data,
|
||||
MessageParcel &reply, MessageOption &option) override;
|
||||
};
|
||||
|
||||
class WallpaperColorChangeListenerProxy : public IRemoteProxy<IWallpaperColorChangeListener> {
|
||||
public:
|
||||
explicit WallpaperColorChangeListenerProxy(const sptr<IRemoteObject> &impl);
|
||||
~WallpaperColorChangeListenerProxy() = default;
|
||||
void onColorsChange(std::vector<RgbaColor> color, int wallpaperType) override;
|
||||
};
|
||||
} // namespace WallpaperMgrService
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // I_WALLPAPER_COLOR_CHANGE_LISTENER_H
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 WALLPAPER_COLOR_CHANGE_LISTENER_H
|
||||
#define WALLPAPER_COLOR_CHANGE_LISTENER_H
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include "wallpaper_manager_common_info.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace WallpaperMgrService {
|
||||
class WallpaperColorChangeListener {
|
||||
public:
|
||||
WallpaperColorChangeListener() = default;
|
||||
|
||||
virtual ~WallpaperColorChangeListener()
|
||||
{}
|
||||
|
||||
virtual void onColorsChange(std::vector<RgbaColor> color, int wallpaperType)
|
||||
{}
|
||||
};
|
||||
} // namespace WallpaperMgrService
|
||||
} // namespace OHOS
|
||||
#endif // WALLPAPER_COLOR_CHANGE_LISTENER_H
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 WALLPAPER_COLOR_CHANGE_LISTENER_CLIENT_H
|
||||
#define WALLPAPER_COLOR_CHANGE_LISTENER_CLIENT_H
|
||||
|
||||
#include <memory>
|
||||
#include "iwallpaper_color_change_listener.h"
|
||||
#include "wallpaper_color_change_listener.h"
|
||||
#include "refbase.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace WallpaperMgrService {
|
||||
class WallpaperColorChangeListenerClient : public WallpaperColorChangeListenerStub {
|
||||
public:
|
||||
WallpaperColorChangeListenerClient(
|
||||
std::shared_ptr<WallpaperColorChangeListener> wallpaperColorChangerListener);
|
||||
|
||||
~WallpaperColorChangeListenerClient();
|
||||
|
||||
void onColorsChange(std::vector<RgbaColor> color, int wallpaperType) override;
|
||||
|
||||
const std::shared_ptr<WallpaperColorChangeListener> GetColorChangeListener() const;
|
||||
private:
|
||||
// client is responsible for free it when call UnSubscribeKvStore.
|
||||
std::shared_ptr<WallpaperColorChangeListener> wallpaperColorChangerListener_;
|
||||
};
|
||||
} // namespace WallpaperMgrService
|
||||
} // namespace OHOS
|
||||
#endif // WALLPAPER_COLOR_CHANGE_LISTENER_CLIENT_H
|
||||
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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 INNERKITS_WALLPAPER_MANAGER_H
|
||||
#define INNERKITS_WALLPAPER_MANAGER_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <mutex>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include "ipc_skeleton.h"
|
||||
#include "wallpaper_manager_kits.h"
|
||||
#include "singleton.h"
|
||||
|
||||
using JScallback = bool (*) (int);
|
||||
namespace OHOS {
|
||||
namespace WallpaperMgrService {
|
||||
class WallpaperManager final : public WallpaperManagerkits, public DelayedRefSingleton<WallpaperManager> {
|
||||
DECLARE_DELAYED_REF_SINGLETON(WallpaperManager);
|
||||
public:
|
||||
DISALLOW_COPY_AND_MOVE(WallpaperManager);
|
||||
|
||||
/**
|
||||
* Wallpaper set.
|
||||
* @param uriOrPixelMap Wallpaper picture; wallpaperType Wallpaper type,
|
||||
* values for WALLPAPER_SYSTEM or WALLPAPER_LOCKSCREEN
|
||||
* @return true or false
|
||||
*/
|
||||
bool SetWallpaper(std::string url, int wallpaperType) final;
|
||||
|
||||
/**
|
||||
* Wallpaper set.
|
||||
* @param pixelMap:picture pixelMap struct; wallpaperType Wallpaper type,
|
||||
* values for WALLPAPER_SYSTEM or WALLPAPER_LOCKSCREEN
|
||||
* @return true or false
|
||||
*/
|
||||
bool SetWallpaper(std::unique_ptr<OHOS::Media::PixelMap> &pixelMap, int wallpaperType) final;
|
||||
|
||||
/**
|
||||
*Obtains the default pixel map of a wallpaper of the specified type.
|
||||
* @param wallpaperType Wallpaper type, values for WALLPAPER_SYSTEM or WALLPAPER_LOCKSCREEN
|
||||
* @return image.PixelMap png type The bitmap file of wallpaper
|
||||
* @permission ohos.permission.GET_WALLPAPER
|
||||
* @permission ohos.permission.READ_USER_STORAGE
|
||||
* @systemapi Hide this for inner system use.
|
||||
*/
|
||||
std::shared_ptr<OHOS::Media::PixelMap> GetPixelMap(int wallpaperType) final;
|
||||
|
||||
/**
|
||||
* Obtains the WallpaperColorsCollection instance for the wallpaper of the specified type.
|
||||
* @param wallpaperType Wallpaper type, values for WALLPAPER_SYSTEM or WALLPAPER_LOCKSCREEN
|
||||
* @return RgbaColor type of array callback function
|
||||
*/
|
||||
std::vector<RgbaColor> GetColors(int wallpaperType) final;
|
||||
|
||||
/**
|
||||
* Obtains the ID of the wallpaper of the specified type.
|
||||
* @param wallpaperType Wallpaper type, values for WALLPAPER_SYSTEM or WALLPAPER_LOCKSCREEN
|
||||
* @return number type of callback function
|
||||
*/
|
||||
int GetWallpaperId(int wallpaperType) final;
|
||||
|
||||
/**
|
||||
* Obtains the minimum height of the wallpaper.
|
||||
* @return number type of callback function
|
||||
*/
|
||||
int GetWallpaperMinHeight() final;
|
||||
|
||||
/**
|
||||
* Obtains the minimum width of the wallpaper.
|
||||
* @return number type of callback function
|
||||
*/
|
||||
int GetWallpaperMinWidth() final;
|
||||
|
||||
/**
|
||||
* Checks whether to allow the application to change the wallpaper for the current user.
|
||||
* @return boolean type of callback function
|
||||
*/
|
||||
bool IsChangePermitted() final;
|
||||
|
||||
/**
|
||||
* Checks whether a user is allowed to set wallpapers.
|
||||
* @return boolean type of callback function
|
||||
*/
|
||||
bool IsOperationAllowed() final;
|
||||
|
||||
/**
|
||||
* Removes a wallpaper of the specified type and restores the default one.
|
||||
* @param wallpaperType Wallpaper type, values for WALLPAPER_SYSTEM or WALLPAPER_LOCKSCREEN
|
||||
* @permission ohos.permission.SET_WALLPAPER
|
||||
*/
|
||||
bool ResetWallpaper(std::int32_t wallpaperType) final;
|
||||
|
||||
/**
|
||||
* Screen shot live wallpaper
|
||||
* @param scale
|
||||
* @param pixelFormat
|
||||
* @return image.PixelMap png type The bitmap file of wallpaper
|
||||
* @permission ohos.permission.CAPTURE_SCREEN
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @return true or false
|
||||
*/
|
||||
bool ScreenshotLiveWallpaper(int wallpaperType, OHOS::Media::PixelMap pixelMap) final;
|
||||
|
||||
/**
|
||||
* Registers a listener for wallpaper color changes to receive notifications about the changes.
|
||||
* @param type The incoming colorChange table open receiver pick a color change wallpaper wallpaper color changes
|
||||
* @param callback Provides dominant colors of the wallpaper.
|
||||
* @return true or false
|
||||
*/
|
||||
bool On(std::shared_ptr<WallpaperColorChangeListener> listener) final;
|
||||
|
||||
/**
|
||||
* Registers a listener for wallpaper color changes to receive notifications about the changes.
|
||||
* @param type Incoming 'colorChange' table delete receiver to pick up a color change wallpaper wallpaper color
|
||||
* changes
|
||||
* @param callback Provides dominant colors of the wallpaper.
|
||||
*/
|
||||
bool Off(std::shared_ptr<WallpaperColorChangeListener> listener) final;
|
||||
|
||||
bool RegisterWallpaperCallback(bool (*callback) (int)) final;
|
||||
|
||||
JScallback GetCallback() final;
|
||||
|
||||
void SetCallback(bool (*cb) (int)) final;
|
||||
|
||||
private:
|
||||
class DeathRecipient final : public IRemoteObject::DeathRecipient {
|
||||
public:
|
||||
DeathRecipient() = default;
|
||||
~DeathRecipient() final = default;
|
||||
DISALLOW_COPY_AND_MOVE(DeathRecipient);
|
||||
|
||||
void OnRemoteDied(const wptr<IRemoteObject>& remote) final;
|
||||
};
|
||||
|
||||
template<typename F, typename... Args>
|
||||
ErrCode CallService(F func, Args&&... args);
|
||||
|
||||
void ResetService(const wptr<IRemoteObject>& remote);
|
||||
sptr<IWallpaperService> GetService();
|
||||
int64_t WritePixelMapToFile(const std::string &filePath, std::unique_ptr< OHOS::Media::PixelMap> pixelMap);
|
||||
int64_t WritePixelMapToStream(std::ostream &outputStream, std::unique_ptr< OHOS::Media::PixelMap> pixelMap);
|
||||
|
||||
sptr<IWallpaperService> wpProxy_ {};
|
||||
sptr<IRemoteObject::DeathRecipient> deathRecipient_ {};
|
||||
std::mutex wpProxyLock_;
|
||||
std::map<WallpaperColorChangeListener *, sptr<IWallpaperColorChangeListener>> registeredListeners_;
|
||||
std::mutex listenerMapMutex_;
|
||||
bool (*callback) (int);
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 INNERKITS_WALLPAPER_MANAGER_KITS_H
|
||||
#define INNERKITS_WALLPAPER_MANAGER_KITS_H
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include<list>
|
||||
#include<map>
|
||||
|
||||
#include "i_wallpaper_service.h"
|
||||
#include "pixel_map.h"
|
||||
#include "refbase.h"
|
||||
#include "wallpaper_manager_common_info.h"
|
||||
#include "wallpaper_color_change_listener.h"
|
||||
#include "iwallpaper_color_change_listener.h"
|
||||
#include "wallpaper_color_change_listener_client.h"
|
||||
|
||||
/**
|
||||
* Interfaces for ohos account subsystem.
|
||||
*/
|
||||
namespace OHOS {
|
||||
namespace WallpaperMgrService {
|
||||
class WallpaperManagerkits {
|
||||
public:
|
||||
virtual ~WallpaperManagerkits() = default;
|
||||
DISALLOW_COPY_AND_MOVE(WallpaperManagerkits);
|
||||
|
||||
/**
|
||||
* Get instance of ohos Wallpaper manager.
|
||||
*
|
||||
* @return Instance of ohos Wallpaper manager.
|
||||
*/
|
||||
static WallpaperManagerkits& GetInstance();
|
||||
|
||||
/**
|
||||
* Wallpaper set.
|
||||
* @param uriOrPixelMap Wallpaper picture; wallpaperType Wallpaper type, values for WALLPAPER_SYSTEM or
|
||||
* WALLPAPER_LOCKSCREEN
|
||||
* @return true or false
|
||||
*/
|
||||
virtual bool SetWallpaper(std::string url, int wallpaperType) = 0;
|
||||
|
||||
/**
|
||||
* Wallpaper set.
|
||||
* @param pixelMap:picture pixelMap struct; wallpaperType Wallpaper type, values for WALLPAPER_SYSTEM or
|
||||
* WALLPAPER_LOCKSCREEN
|
||||
* @return true or false
|
||||
*/
|
||||
virtual bool SetWallpaper(std::unique_ptr<OHOS::Media::PixelMap> &pixelMap, int wallpaperType) = 0;
|
||||
|
||||
/**
|
||||
*Obtains the default pixel map of a wallpaper of the specified type.
|
||||
* @param wallpaperType Wallpaper type, values for WALLPAPER_SYSTEM or WALLPAPER_LOCKSCREEN
|
||||
* @return image.PixelMap png type The bitmap file of wallpaper
|
||||
* @permission ohos.permission.GET_WALLPAPER
|
||||
* @permission ohos.permission.READ_USER_STORAGE
|
||||
* @systemapi Hide this for inner system use.
|
||||
*/
|
||||
virtual std::shared_ptr<OHOS::Media::PixelMap> GetPixelMap(int wallpaperType) = 0;
|
||||
|
||||
/**
|
||||
* Obtains the WallpaperColorsCollection instance for the wallpaper of the specified type.
|
||||
* @param wallpaperType Wallpaper type, values for WALLPAPER_SYSTEM or WALLPAPER_LOCKSCREEN
|
||||
* @return RgbaColor type of array callback function
|
||||
*/
|
||||
virtual std::vector<RgbaColor> GetColors(int wallpaperType) = 0;
|
||||
|
||||
/**
|
||||
* Obtains the ID of the wallpaper of the specified type.
|
||||
* @param wallpaperType Wallpaper type, values for WALLPAPER_SYSTEM or WALLPAPER_LOCKSCREEN
|
||||
* @return number type of callback function
|
||||
*/
|
||||
virtual int GetWallpaperId(int wallpaperType) = 0;
|
||||
|
||||
/**
|
||||
* Obtains the minimum height of the wallpaper.
|
||||
* @return number type of callback function
|
||||
*/
|
||||
virtual int GetWallpaperMinHeight() = 0;
|
||||
|
||||
/**
|
||||
* Obtains the minimum width of the wallpaper.
|
||||
* @return number type of callback function
|
||||
*/
|
||||
virtual int GetWallpaperMinWidth() = 0;
|
||||
|
||||
/**
|
||||
* Checks whether to allow the application to change the wallpaper for the current user.
|
||||
* @return boolean type of callback function
|
||||
*/
|
||||
virtual bool IsChangePermitted() = 0;
|
||||
|
||||
/**
|
||||
* Checks whether a user is allowed to set wallpapers.
|
||||
* @return boolean type of callback function
|
||||
*/
|
||||
virtual bool IsOperationAllowed() = 0;
|
||||
|
||||
/**
|
||||
* Removes a wallpaper of the specified type and restores the default one.
|
||||
* @param wallpaperType Wallpaper type, values for WALLPAPER_SYSTEM or WALLPAPER_LOCKSCREEN
|
||||
* @permission ohos.permission.SET_WALLPAPER
|
||||
*/
|
||||
virtual bool ResetWallpaper(std::int32_t wallpaperType) = 0;
|
||||
|
||||
/**
|
||||
* Screen shot live wallpaper
|
||||
* @param scale
|
||||
* @param pixelFormat
|
||||
* @return image.PixelMap png type The bitmap file of wallpaper
|
||||
* @permission ohos.permission.CAPTURE_SCREEN
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @return true or false
|
||||
*/
|
||||
virtual bool ScreenshotLiveWallpaper(int wallpaperType, OHOS::Media::PixelMap pixelMap) = 0;
|
||||
|
||||
/**
|
||||
* Registers a listener for wallpaper color changes to receive notifications about the changes.
|
||||
* @param type The incoming colorChange table open receiver pick a color change wallpaper wallpaper color changes
|
||||
* @param callback Provides dominant colors of the wallpaper.
|
||||
* @return true or false
|
||||
*/
|
||||
virtual bool On(std::shared_ptr<WallpaperColorChangeListener> listener) = 0;
|
||||
|
||||
/**
|
||||
* Registers a listener for wallpaper color changes to receive notifications about the changes.
|
||||
* @param type Incoming 'colorChange' table delete receiver to pick up a color change wallpaper wallpaper color
|
||||
* changes
|
||||
* @param callback Provides dominant colors of the wallpaper.
|
||||
*/
|
||||
virtual bool Off(std::shared_ptr<WallpaperColorChangeListener> listener) = 0;
|
||||
|
||||
virtual bool RegisterWallpaperCallback(bool (*callback) (int)) = 0;
|
||||
using JScallback = bool (*) (int);
|
||||
|
||||
virtual JScallback GetCallback() = 0;
|
||||
|
||||
virtual void SetCallback(bool (*cb) (int)) = 0;
|
||||
|
||||
protected:
|
||||
WallpaperManagerkits() = default;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 SERVICES_INCLUDE_WALLPAPER_SERVICE_CB_STUB_H
|
||||
#define SERVICES_INCLUDE_WALLPAPER_SERVICE_CB_STUB_H
|
||||
|
||||
#include<map>
|
||||
#include "iremote_stub.h"
|
||||
#include "i_wallpaper_callback.h"
|
||||
#include "ipc_skeleton.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace WallpaperMgrService {
|
||||
class WallpaperManager;
|
||||
class WallpaperServiceCbStub : public IRemoteStub<IWallpaperCallback> {
|
||||
public:
|
||||
WallpaperServiceCbStub();
|
||||
~WallpaperServiceCbStub() = default;
|
||||
int32_t OnRemoteRequest(
|
||||
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
||||
int32_t OnCall(const int32_t num) override;
|
||||
private:
|
||||
int32_t HandleOnCall(MessageParcel &data, MessageParcel &reply);
|
||||
using WallpaperCallbackFunc = int32_t (WallpaperServiceCbStub::*)(MessageParcel &data, MessageParcel &reply);
|
||||
std::map<uint32_t, WallpaperCallbackFunc> memberFuncMap_;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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 SERVICES_INCLUDE_WALLPAPER_SERVICE_PROXY_H
|
||||
#define SERVICES_INCLUDE_WALLPAPER_SERVICE_PROXY_H
|
||||
|
||||
|
||||
#include <mutex>
|
||||
#include "iremote_proxy.h"
|
||||
#include "i_wallpaper_service.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace WallpaperMgrService {
|
||||
class WallpaperServiceProxy : public IRemoteProxy<IWallpaperService> {
|
||||
public:
|
||||
explicit WallpaperServiceProxy(const sptr<IRemoteObject> &object) : IRemoteProxy<IWallpaperService>(object) {}
|
||||
~WallpaperServiceProxy() {}
|
||||
DISALLOW_COPY_AND_MOVE(WallpaperServiceProxy);
|
||||
bool SetWallpaperByFD(int fd, int wallpaperType, int length) override;
|
||||
bool SetWallpaperByMap(int fd, int wallpaperType, int length) override;
|
||||
IWallpaperService::mapFD GetPixelMap(int wallpaperType) override;
|
||||
std::vector<RgbaColor> GetColors(int wallpaperType) override;
|
||||
int GetWallpaperId(int wallpaperType) override;
|
||||
int GetWallpaperMinHeight() override;
|
||||
int GetWallpaperMinWidth() override;
|
||||
bool IsChangePermitted() override;
|
||||
bool IsOperationAllowed() override;
|
||||
bool ResetWallpaper(int wallpaperType) override;
|
||||
bool ScreenshotLiveWallpaper(int sacleNumber, OHOS::Media::PixelMap pixelMap) override;
|
||||
bool On(sptr<IWallpaperColorChangeListener> listener) override;
|
||||
bool Off(sptr<IWallpaperColorChangeListener> listener) override;
|
||||
bool RegisterWallpaperCallback(const sptr<IWallpaperCallback> callback) override;
|
||||
std::string getUrl();
|
||||
|
||||
private:
|
||||
bool StartSocket(std::string url, std::string name);
|
||||
static inline BrokerDelegator<WallpaperServiceProxy> delegator_;
|
||||
sptr<OHOS::Media::PixelMap> Pmdata_;
|
||||
std::string FWReadUrl = "";
|
||||
int32_t mapSize;
|
||||
};
|
||||
}
|
||||
} // namespace OHOS
|
||||
#endif // SERVICES_INCLUDE_WALLPAPER_SERVICE_PROXY_H
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "WallpaperColorChangeListenerProxy"
|
||||
|
||||
#include "hilog_wrapper.h"
|
||||
#include "message_parcel.h"
|
||||
#include "iwallpaper_color_change_listener.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace WallpaperMgrService {
|
||||
constexpr int ONCOLORSCHANGE = 0;
|
||||
using namespace std::chrono;
|
||||
|
||||
WallpaperColorChangeListenerProxy::WallpaperColorChangeListenerProxy(
|
||||
const sptr<IRemoteObject> &impl) : IRemoteProxy<IWallpaperColorChangeListener>(impl)
|
||||
{}
|
||||
|
||||
void WallpaperColorChangeListenerProxy::onColorsChange(std::vector<RgbaColor> color, int wallpaperType)
|
||||
{
|
||||
HILOG_DEBUG("WallpaperColorChangeListenerProxy::onColorsChange Start");
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(WallpaperColorChangeListenerProxy::GetDescriptor())) {
|
||||
HILOG_ERROR("write descriptor failed");
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned int size = color.size();
|
||||
if (!data.WriteInt32(size)) {
|
||||
HILOG_ERROR("write color size failed");
|
||||
return;
|
||||
}
|
||||
for (unsigned int i = 0; i < size; ++i) {
|
||||
if (!(data.WriteInt32(color[i].red) && data.WriteInt32(color[i].green) &&
|
||||
data.WriteInt32(color[i].blue) && data.WriteInt32(color[i].alpha))) {
|
||||
HILOG_ERROR("write color failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!data.WriteInt32(wallpaperType)) {
|
||||
HILOG_ERROR("write wallpaperType failed");
|
||||
return;
|
||||
}
|
||||
|
||||
int error = Remote()->SendRequest(ONCOLORSCHANGE, data, reply, option);
|
||||
if (error != 0) {
|
||||
HILOG_ERROR("SendRequest failed, error %d", error);
|
||||
}
|
||||
HILOG_DEBUG("WallpaperColorChangeListenerProxy::onColorsChange End");
|
||||
}
|
||||
|
||||
int32_t WallpaperColorChangeListenerStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
|
||||
MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
HILOG_DEBUG("WallpaperColorChangeListenerStub::OnRemoteRequest Start");
|
||||
HILOG_DEBUG("%d", code);
|
||||
std::u16string descriptor = WallpaperColorChangeListenerStub::GetDescriptor();
|
||||
std::u16string remoteDescriptor = data.ReadInterfaceToken();
|
||||
if (descriptor != remoteDescriptor) {
|
||||
HILOG_ERROR("local descriptor is not equal to remote");
|
||||
return -1;
|
||||
}
|
||||
switch (code) {
|
||||
case ONCOLORSCHANGE: {
|
||||
std::vector<RgbaColor> color;
|
||||
unsigned int size = data.ReadInt32();
|
||||
for (unsigned int i = 0; i < size; ++i) {
|
||||
RgbaColor colorInfo;
|
||||
colorInfo.red = data.ReadInt32();
|
||||
colorInfo.blue = data.ReadInt32();
|
||||
colorInfo.green = data.ReadInt32();
|
||||
colorInfo.alpha = data.ReadInt32();
|
||||
color.emplace_back(colorInfo);
|
||||
}
|
||||
int wallpaperType = data.ReadInt32();
|
||||
onColorsChange(color, wallpaperType);
|
||||
HILOG_DEBUG("WallpaperColorChangeListenerStub::OnRemoteRequest End");
|
||||
return 0;
|
||||
}
|
||||
default:
|
||||
HILOG_DEBUG("code error, WallpaperColorChangeListenerStub::OnRemoteRequest End");
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
}
|
||||
} // namespace WallpaperMgrService
|
||||
} // namespace OHOS
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "WallpaperColorChangeListenerClient"
|
||||
|
||||
#include "hilog_wrapper.h"
|
||||
#include "wallpaper_color_change_listener_client.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace WallpaperMgrService {
|
||||
WallpaperColorChangeListenerClient::WallpaperColorChangeListenerClient(
|
||||
std::shared_ptr<WallpaperMgrService::WallpaperColorChangeListener> wallpaperColorChangerListener)
|
||||
: wallpaperColorChangerListener_(wallpaperColorChangerListener)
|
||||
{
|
||||
HILOG_INFO("start");
|
||||
}
|
||||
|
||||
WallpaperColorChangeListenerClient::~WallpaperColorChangeListenerClient()
|
||||
{
|
||||
HILOG_INFO("start");
|
||||
}
|
||||
|
||||
void WallpaperColorChangeListenerClient::onColorsChange(std::vector<RgbaColor> color, int wallpaperType)
|
||||
{
|
||||
HILOG_INFO("start");
|
||||
if (wallpaperColorChangerListener_ != nullptr) {
|
||||
wallpaperColorChangerListener_->onColorsChange(color, wallpaperType);
|
||||
}
|
||||
}
|
||||
|
||||
const std::shared_ptr<WallpaperColorChangeListener> WallpaperColorChangeListenerClient::GetColorChangeListener() const
|
||||
{
|
||||
return wallpaperColorChangerListener_;
|
||||
}
|
||||
} // namespace WallpaperMgrService
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,454 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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 <mutex>
|
||||
#include <fstream>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <cerrno>
|
||||
#include "hilog_wrapper.h"
|
||||
#include "wallpaper_service_proxy.h"
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "system_ability_definition.h"
|
||||
#include "i_wallpaper_service.h"
|
||||
#include "permission.h"
|
||||
#include "image_source.h"
|
||||
#include "image_type.h"
|
||||
#include "image_packer.h"
|
||||
#include "file_ex.h"
|
||||
#include "file_deal.h"
|
||||
#include "file_util.h"
|
||||
#include "wallpaper_service_cb_stub.h"
|
||||
#include "wallpaper_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace WallpaperMgrService {
|
||||
constexpr int OPTION_QUALITY = 100;
|
||||
WallpaperManager::WallpaperManager() {}
|
||||
WallpaperManager::~WallpaperManager() {}
|
||||
|
||||
void WallpaperManager::ResetService(const wptr<IRemoteObject>& remote)
|
||||
{
|
||||
HILOG_INFO("Remote is dead, reset service instance");
|
||||
std::lock_guard<std::mutex> lock(wpProxyLock_);
|
||||
if (wpProxy_ != nullptr) {
|
||||
sptr<IRemoteObject> object = wpProxy_->AsObject();
|
||||
if ((object != nullptr) && (remote == object)) {
|
||||
object->RemoveDeathRecipient(deathRecipient_);
|
||||
wpProxy_ = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sptr<IWallpaperService> WallpaperManager::GetService()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(wpProxyLock_);
|
||||
if (wpProxy_ != nullptr) {
|
||||
return wpProxy_;
|
||||
}
|
||||
|
||||
sptr<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (samgr == nullptr) {
|
||||
HILOG_ERROR("Get samgr failed");
|
||||
return nullptr;
|
||||
}
|
||||
sptr<IRemoteObject> object = samgr->GetSystemAbility(WALLPAPER_MANAGER_SERVICE_ID);
|
||||
if (object == nullptr) {
|
||||
HILOG_ERROR("Get wallpaper object from samgr failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (deathRecipient_ == nullptr) {
|
||||
deathRecipient_ = new DeathRecipient();
|
||||
}
|
||||
|
||||
if ((object->IsProxyObject()) && (!object->AddDeathRecipient(deathRecipient_))) {
|
||||
HILOG_ERROR("Failed to add death recipient");
|
||||
}
|
||||
|
||||
HILOG_INFO("get remote object ok");
|
||||
wpProxy_ = iface_cast<WallpaperServiceProxy>(object);
|
||||
if (wpProxy_ == nullptr) {
|
||||
HILOG_ERROR("iface_cast failed");
|
||||
}
|
||||
return wpProxy_;
|
||||
}
|
||||
|
||||
void WallpaperManager::DeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& remote)
|
||||
{
|
||||
DelayedRefSingleton<WallpaperManager>::GetInstance().ResetService(remote);
|
||||
}
|
||||
|
||||
template<typename F, typename... Args>
|
||||
ErrCode WallpaperManager::CallService(F func, Args&&... args)
|
||||
{
|
||||
auto service = GetService();
|
||||
if (service == nullptr) {
|
||||
HILOG_ERROR("get service failed");
|
||||
return ERR_DEAD_OBJECT;
|
||||
}
|
||||
|
||||
ErrCode result = (service->*func)(std::forward<Args>(args)...);
|
||||
if (SUCCEEDED(result)) {
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
// Reset service instance if 'ERR_DEAD_OBJECT' happened.
|
||||
if (result == ERR_DEAD_OBJECT) {
|
||||
ResetService(service);
|
||||
}
|
||||
|
||||
HILOG_ERROR("Callservice failed with: %{public}d", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<RgbaColor> WallpaperManager::GetColors(int wallpaperType)
|
||||
{
|
||||
std::vector<RgbaColor> tmp;
|
||||
auto wpServerProxy = GetService();
|
||||
if (wpServerProxy == nullptr) {
|
||||
HILOG_ERROR("Get proxy failed");
|
||||
return tmp;
|
||||
}
|
||||
return wpServerProxy->GetColors(wallpaperType);
|
||||
}
|
||||
|
||||
bool WallpaperManager::SetWallpaper(std::string url, int wallpaperType)
|
||||
{
|
||||
auto wpServerProxy = GetService();
|
||||
if (wpServerProxy == nullptr) {
|
||||
HILOG_ERROR("Get proxy failed");
|
||||
return false;
|
||||
}
|
||||
if (!OHOS::FileExists(url)) {
|
||||
HILOG_ERROR("file is not exist!");
|
||||
HILOG_ERROR("file is not exist! %{public}s", url.c_str());
|
||||
return false;
|
||||
}
|
||||
FILE *pixMap = std::fopen(url.c_str(), "rb");
|
||||
if (pixMap == nullptr) {
|
||||
HILOG_ERROR("fopen faild, %{public}s", strerror(errno));
|
||||
HILOG_ERROR("fopen faild, %{public}s", url.c_str());
|
||||
return false;
|
||||
}
|
||||
int fend = fseek(pixMap, 0, SEEK_END);
|
||||
if (fend != 0) {
|
||||
HILOG_ERROR("fseek faild");
|
||||
return false;
|
||||
}
|
||||
int length = ftell(pixMap);
|
||||
if (length <= 0) {
|
||||
HILOG_ERROR("ftell faild");
|
||||
return false;
|
||||
}
|
||||
int fset = fseek(pixMap, 0, SEEK_SET);
|
||||
if (fset != 0) {
|
||||
HILOG_ERROR("fseek faild");
|
||||
return false;
|
||||
}
|
||||
int closeRes = fclose(pixMap);
|
||||
if (closeRes != 0) {
|
||||
HILOG_ERROR("fclose faild");
|
||||
return false;
|
||||
}
|
||||
|
||||
int fd = open(url.c_str(), O_RDONLY, 0770);
|
||||
if (fd < 0) {
|
||||
HILOG_ERROR("open file failed");
|
||||
return false;
|
||||
}
|
||||
return wpServerProxy->SetWallpaperByFD(fd, wallpaperType, length);
|
||||
}
|
||||
|
||||
bool WallpaperManager::SetWallpaper(std::unique_ptr<OHOS::Media::PixelMap> &pixelMap, int wallpaperType)
|
||||
{
|
||||
auto wpServerProxy = GetService();
|
||||
std::string urlRet = "";
|
||||
if (wpServerProxy == nullptr) {
|
||||
HILOG_ERROR("Get proxy failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::stringbuf* stringBuf = new std::stringbuf();
|
||||
std::ostream ostream(stringBuf);
|
||||
int mapSize = WritePixelMapToStream(ostream, std::move(pixelMap));
|
||||
if (mapSize <= 0) {
|
||||
HILOG_ERROR("WritePixelMapToStream faild");
|
||||
return false;
|
||||
}
|
||||
char* buffer = new char[mapSize];
|
||||
stringBuf->sgetn(buffer, mapSize);
|
||||
|
||||
int fd[2];
|
||||
pipe(fd);
|
||||
fcntl(fd[1], F_SETPIPE_SZ, mapSize);
|
||||
fcntl(fd[0], F_SETPIPE_SZ, mapSize);
|
||||
int32_t writeSize = write(fd[1], buffer, mapSize);
|
||||
if (writeSize != mapSize) {
|
||||
HILOG_ERROR("write to fd faild");
|
||||
return false;
|
||||
}
|
||||
close(fd[1]);
|
||||
return wpServerProxy->SetWallpaperByMap(fd[0], wallpaperType, mapSize);
|
||||
}
|
||||
int64_t WallpaperManager::WritePixelMapToStream(std::ostream &outputStream,
|
||||
std::unique_ptr< OHOS::Media::PixelMap> pixelMap)
|
||||
{
|
||||
OHOS::Media::ImagePacker imagePacker;
|
||||
OHOS::Media::PackOption option;
|
||||
option.format = "image/jpeg";
|
||||
option.quality = OPTION_QUALITY;
|
||||
option.numberHint = 1;
|
||||
std::set<std::string> formats;
|
||||
uint32_t ret = imagePacker.GetSupportedFormats(formats);
|
||||
if (ret != 0) {
|
||||
HILOG_ERROR("image packer get supported format failed, ret=%{public}u.", ret);
|
||||
}
|
||||
|
||||
imagePacker.StartPacking(outputStream, option);
|
||||
imagePacker.AddImage(*pixelMap);
|
||||
int64_t packedSize = 0;
|
||||
imagePacker.FinalizePacking(packedSize);
|
||||
HILOG_INFO("FrameWork WritePixelMapToFile End! packedSize=%{public}lld.", static_cast<long long>(packedSize));
|
||||
return packedSize;
|
||||
}
|
||||
|
||||
int64_t WallpaperManager::WritePixelMapToFile(const std::string &filePath,
|
||||
std::unique_ptr< OHOS::Media::PixelMap> pixelMap)
|
||||
{
|
||||
OHOS::Media::ImagePacker imagePacker;
|
||||
OHOS::Media::PackOption option;
|
||||
option.format = "image/jpeg";
|
||||
option.quality = OPTION_QUALITY;
|
||||
option.numberHint = 1;
|
||||
std::set<std::string> formats;
|
||||
uint32_t ret = imagePacker.GetSupportedFormats(formats);
|
||||
if (ret != 0) {
|
||||
HILOG_ERROR("image packer get supported format failed, ret=%{public}u.", ret);
|
||||
}
|
||||
imagePacker.StartPacking(filePath, option);
|
||||
imagePacker.AddImage(*pixelMap);
|
||||
int64_t packedSize = 0;
|
||||
imagePacker.FinalizePacking(packedSize);
|
||||
HILOG_INFO("FrameWork WritePixelMapToFile End! packedSize=%{public}lld.", static_cast<long long>(packedSize));
|
||||
return packedSize;
|
||||
}
|
||||
std::shared_ptr<OHOS::Media::PixelMap> WallpaperManager::GetPixelMap(int wallpaperType)
|
||||
{
|
||||
std::unique_ptr<OHOS::Media::PixelMap> tmp = std::make_unique<OHOS::Media::PixelMap>();
|
||||
HILOG_INFO("FrameWork GetPixelMap Start by FD");
|
||||
auto wpServerProxy = GetService();
|
||||
if (wpServerProxy == nullptr) {
|
||||
HILOG_ERROR("Get proxy failed");
|
||||
return nullptr;
|
||||
}
|
||||
IWallpaperService::mapFD mapFd = wpServerProxy->GetPixelMap(wallpaperType);
|
||||
uint32_t errorCode = 0;
|
||||
OHOS::Media::SourceOptions opts;
|
||||
opts.formatHint = "image/jpeg";
|
||||
HILOG_INFO(" CreateImageSource by FD");
|
||||
std::unique_ptr<OHOS::Media::ImageSource> imageSource =
|
||||
OHOS::Media::ImageSource::CreateImageSource(mapFd.fd, opts, errorCode);
|
||||
if (errorCode != 0) {
|
||||
HILOG_ERROR("ImageSource::CreateImageSource failed,errcode= %{public}d", errorCode);
|
||||
return nullptr;
|
||||
}
|
||||
OHOS::Media::DecodeOptions decodeOpts;
|
||||
HILOG_INFO(" CreatePixelMap");
|
||||
tmp = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
if (errorCode != 0) {
|
||||
HILOG_ERROR("ImageSource::CreatePixelMap failed,errcode= %{public}d", errorCode);
|
||||
return nullptr;
|
||||
}
|
||||
close(mapFd.fd);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
int WallpaperManager::GetWallpaperId(int wallpaperType)
|
||||
{
|
||||
auto wpServerProxy = GetService();
|
||||
if (wpServerProxy == nullptr) {
|
||||
HILOG_ERROR("Get proxy failed");
|
||||
return -1;
|
||||
}
|
||||
return wpServerProxy->GetWallpaperId(wallpaperType);
|
||||
}
|
||||
|
||||
int WallpaperManager::GetWallpaperMinHeight()
|
||||
{
|
||||
auto wpServerProxy = GetService();
|
||||
if (wpServerProxy == nullptr) {
|
||||
HILOG_ERROR("Get proxy failed");
|
||||
return -1;
|
||||
}
|
||||
return wpServerProxy->GetWallpaperMinHeight();
|
||||
}
|
||||
|
||||
int WallpaperManager::GetWallpaperMinWidth()
|
||||
{
|
||||
auto wpServerProxy = GetService();
|
||||
if (wpServerProxy == nullptr) {
|
||||
HILOG_ERROR("Get proxy failed");
|
||||
return -1;
|
||||
}
|
||||
return wpServerProxy->GetWallpaperMinWidth();
|
||||
}
|
||||
|
||||
bool WallpaperManager::IsChangePermitted()
|
||||
{
|
||||
auto wpServerProxy = GetService();
|
||||
if (wpServerProxy == nullptr) {
|
||||
HILOG_ERROR("Get proxy failed");
|
||||
return false;
|
||||
}
|
||||
return wpServerProxy->IsChangePermitted();
|
||||
}
|
||||
|
||||
bool WallpaperManager::IsOperationAllowed()
|
||||
{
|
||||
auto wpServerProxy = GetService();
|
||||
if (wpServerProxy == nullptr) {
|
||||
HILOG_ERROR("Get proxy failed");
|
||||
return false;
|
||||
}
|
||||
return wpServerProxy->IsOperationAllowed();
|
||||
}
|
||||
bool WallpaperManager::ResetWallpaper(std::int32_t wallpaperType)
|
||||
{
|
||||
auto wpServerProxy = GetService();
|
||||
if (wpServerProxy == nullptr) {
|
||||
HILOG_ERROR("Get proxy failed");
|
||||
return false;
|
||||
}
|
||||
return wpServerProxy->ResetWallpaper(wallpaperType);
|
||||
}
|
||||
bool WallpaperManager::ScreenshotLiveWallpaper(int wallpaperType, OHOS::Media::PixelMap pixelMap)
|
||||
{
|
||||
auto wpServerProxy = GetService();
|
||||
if (wpServerProxy == nullptr) {
|
||||
HILOG_ERROR("Get proxy failed");
|
||||
return false;
|
||||
}
|
||||
return wpServerProxy->ScreenshotLiveWallpaper(wallpaperType, pixelMap);
|
||||
}
|
||||
|
||||
bool WallpaperManager::On(std::shared_ptr<WallpaperColorChangeListener> listener)
|
||||
{
|
||||
HILOG_DEBUG("WallpaperManager::On in");
|
||||
auto wpServerProxy = GetService();
|
||||
if (wpServerProxy == nullptr) {
|
||||
HILOG_ERROR("Get proxy failed");
|
||||
return false;
|
||||
}
|
||||
if (listener == nullptr) {
|
||||
HILOG_ERROR("listener is nullptr.");
|
||||
return false;
|
||||
}
|
||||
std::lock_guard<std::mutex> lck(listenerMapMutex_);
|
||||
|
||||
if (registeredListeners_.count(listener.get()) == 1) {
|
||||
HILOG_ERROR("already listened");
|
||||
return false;
|
||||
}
|
||||
|
||||
sptr<WallpaperColorChangeListenerClient> ipcListener =
|
||||
new (std::nothrow) WallpaperColorChangeListenerClient(listener);
|
||||
if (ipcListener == nullptr) {
|
||||
HILOG_ERROR("new WallpaperColorChangeListenerClient failed");
|
||||
return false;
|
||||
}
|
||||
bool status = wpServerProxy->On(ipcListener);
|
||||
if (status == false) {
|
||||
const auto temp = registeredListeners_.insert({listener.get(), ipcListener});
|
||||
if (!temp.second) {
|
||||
HILOG_ERROR("local insert error");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
HILOG_DEBUG("WallpaperManager::On out");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WallpaperManager::Off(std::shared_ptr<WallpaperColorChangeListener> listener)
|
||||
{
|
||||
HILOG_DEBUG("WallpaperManager::Off in");
|
||||
auto wpServerProxy = GetService();
|
||||
if (wpServerProxy == nullptr) {
|
||||
HILOG_ERROR("Get proxy failed");
|
||||
return false;
|
||||
}
|
||||
if (listener == nullptr) {
|
||||
HILOG_ERROR("listener is nullptr.");
|
||||
return false;
|
||||
}
|
||||
std::lock_guard<std::mutex> lck(listenerMapMutex_);
|
||||
auto it = registeredListeners_.find(listener.get());
|
||||
if (it == registeredListeners_.end()) {
|
||||
HILOG_ERROR("never listened");
|
||||
return true;
|
||||
}
|
||||
bool status = wpServerProxy->Off(it->second);
|
||||
if (status == false) {
|
||||
HILOG_ERROR("off failed code=%d.", ERR_NONE);
|
||||
return false;
|
||||
}
|
||||
registeredListeners_.erase(it);
|
||||
HILOG_DEBUG("WallpaperManager::Off out");
|
||||
return true;
|
||||
}
|
||||
|
||||
JScallback WallpaperManager::GetCallback()
|
||||
{
|
||||
return callback;
|
||||
}
|
||||
|
||||
void WallpaperManager::SetCallback(bool (*cb) (int))
|
||||
{
|
||||
callback = cb;
|
||||
}
|
||||
|
||||
bool WallpaperManager::RegisterWallpaperCallback(bool (*callback) (int))
|
||||
{
|
||||
HILOG_ERROR(" WallpaperManager::RegisterWallpaperCallback statrt");
|
||||
SetCallback(callback);
|
||||
auto wpServerProxy = GetService();
|
||||
if (wpServerProxy == nullptr) {
|
||||
HILOG_ERROR("Get proxy failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (callback == NULL) {
|
||||
HILOG_ERROR("callback is NULL.");
|
||||
return false;
|
||||
}
|
||||
HILOG_INFO(" WallpaperManager::RegisterWallpaperCallback");
|
||||
|
||||
bool status = wpServerProxy->RegisterWallpaperCallback(new WallpaperServiceCbStub());
|
||||
if (status == false) {
|
||||
HILOG_ERROR("off failed code=%d.", ERR_NONE);
|
||||
return false;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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.2
|
||||
*
|
||||
* 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 "wallpaper_manager_kits.h"
|
||||
#include "wallpaper_manager.h"
|
||||
namespace OHOS {
|
||||
namespace WallpaperMgrService {
|
||||
WallpaperManagerkits& WallpaperManagerkits::GetInstance()
|
||||
{
|
||||
return DelayedRefSingleton<WallpaperManager>::GetInstance();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 "wallpaper_service_cb_stub.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "wallpaper_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace WallpaperMgrService {
|
||||
WallpaperServiceCbStub::WallpaperServiceCbStub()
|
||||
{
|
||||
memberFuncMap_[ONCALL] = &WallpaperServiceCbStub::HandleOnCall;
|
||||
}
|
||||
|
||||
int32_t WallpaperServiceCbStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option)
|
||||
{
|
||||
HILOG_INFO(" WallpaperServiceCbStub::OnRemoteRequest");
|
||||
HILOG_INFO(" start##ret = %{public}u", code);
|
||||
std::u16string myDescripter = WallpaperServiceCbStub::GetDescriptor();
|
||||
std::u16string remoteDescripter = data.ReadInterfaceToken();
|
||||
if (myDescripter != remoteDescripter) {
|
||||
HILOG_ERROR(" end##descriptor checked fail");
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
auto itFunc = memberFuncMap_.find(code);
|
||||
if (itFunc != memberFuncMap_.end()) {
|
||||
auto memberFunc = itFunc->second;
|
||||
if (memberFunc != nullptr) {
|
||||
return (this->*memberFunc)(data, reply);
|
||||
}
|
||||
}
|
||||
int ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
HILOG_INFO(" end##ret = %{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t WallpaperServiceCbStub::HandleOnCall(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
HILOG_INFO(" WallpaperServiceCbStub::HandleOnCall");
|
||||
int wallpaperType = data.ReadInt32();
|
||||
OnCall(wallpaperType);
|
||||
HILOG_INFO("wallpaperType = %{public}d", wallpaperType);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t WallpaperServiceCbStub::OnCall(const int32_t num)
|
||||
{
|
||||
HILOG_INFO(" WallpaperServiceCbStub::OnCall");
|
||||
WallpaperMgrService::WallpaperManagerkits::GetInstance().GetCallback()(num);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,391 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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 "file_deal.h"
|
||||
#include "iremote_broker.h"
|
||||
#include "i_wallpaper_service.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "wallpaper_service_proxy.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace WallpaperMgrService {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
|
||||
std::vector<RgbaColor> WallpaperServiceProxy::GetColors(int wallpaperType)
|
||||
{
|
||||
std::vector<RgbaColor> Colors;
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
HILOG_ERROR(" Failed to write parcelable ");
|
||||
return Colors;
|
||||
}
|
||||
if (!data.WriteInt32(wallpaperType)) {
|
||||
HILOG_ERROR(" Failed to WriteInt32 ");
|
||||
return Colors;
|
||||
}
|
||||
|
||||
int32_t result = Remote()->SendRequest(GET_COLORS, data, reply, option);
|
||||
if (result != ERR_NONE) {
|
||||
HILOG_ERROR(" get colors result = %{public}d ", result);
|
||||
}
|
||||
|
||||
int tmpsize = reply.ReadInt32();
|
||||
for (int i = 0; i < tmpsize; ++i) {
|
||||
RgbaColor colorInfo;
|
||||
colorInfo.red = reply.ReadInt32();
|
||||
colorInfo.blue = reply.ReadInt32();
|
||||
colorInfo.green = reply.ReadInt32();
|
||||
colorInfo.alpha = reply.ReadInt32();
|
||||
Colors.emplace_back(colorInfo);
|
||||
}
|
||||
return Colors;
|
||||
}
|
||||
|
||||
std::string WallpaperServiceProxy::getUrl()
|
||||
{
|
||||
return FWReadUrl;
|
||||
HILOG_INFO("return FWReadUrl= %{public}s ", FWReadUrl.c_str());
|
||||
}
|
||||
bool WallpaperServiceProxy::SetWallpaperByMap(int fd, int wallpaperType, int length)
|
||||
{
|
||||
HILOG_INFO(" SetWallpaperByMap ");
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
HILOG_ERROR(" Failed to write parcelable ");
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteFileDescriptor(fd)) {
|
||||
HILOG_ERROR(" Failed to WriteFileDescriptor ");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!data.WriteInt32(wallpaperType)) {
|
||||
HILOG_ERROR(" Failed to WriteInt32 ");
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteInt32(length)) {
|
||||
HILOG_ERROR(" Failed to WriteInt32 ");
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t result = Remote()->SendRequest(SET_WALLPAPER_MAP, data, reply, option);
|
||||
if (result != ERR_NONE) {
|
||||
HILOG_ERROR(" WallpaperCalbackProxy::SetWallpaperfail, result = %{public}d ", result);
|
||||
return false;
|
||||
}
|
||||
|
||||
return reply.ReadBool();
|
||||
}
|
||||
bool WallpaperServiceProxy::SetWallpaperByFD(int fd, int wallpaperType, int length)
|
||||
{
|
||||
HILOG_INFO(" SetWallpaperByFD ");
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
HILOG_ERROR(" Failed to write parcelable ");
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteFileDescriptor(fd)) {
|
||||
HILOG_ERROR(" Failed to WriteFileDescriptor ");
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteInt32(wallpaperType)) {
|
||||
HILOG_ERROR(" Failed to WriteInt32 ");
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteInt32(length)) {
|
||||
HILOG_ERROR(" Failed to WriteInt32 ");
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t result = Remote()->SendRequest(SET_WALLPAPER_URI_FD, data, reply, option);
|
||||
if (result != ERR_NONE) {
|
||||
HILOG_ERROR(" WallpaperCalbackProxy::SetWallpaperfail, result = %{public}d ", result);
|
||||
return false;
|
||||
}
|
||||
return reply.ReadBool();
|
||||
}
|
||||
|
||||
IWallpaperService::mapFD WallpaperServiceProxy::GetPixelMap(int wallpaperType)
|
||||
{
|
||||
mapFD mapFd;
|
||||
HILOG_INFO(" WallpaperServiceProxy::getPixelMap --> start ");
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
HILOG_ERROR(" Failed to write parcelable ");
|
||||
return mapFd;
|
||||
}
|
||||
|
||||
if (!data.WriteInt32(wallpaperType)) {
|
||||
HILOG_ERROR(" Failed to WriteInt32 ");
|
||||
return mapFd;
|
||||
}
|
||||
int32_t result = Remote()->SendRequest(GET_PIXELMAP, data, reply, option);
|
||||
if (result != ERR_NONE) {
|
||||
HILOG_ERROR(" WallpaperServiceProxy::GetPixelMap fail, result = %{public}d ", result);
|
||||
return mapFd;
|
||||
}
|
||||
mapFd.size = reply.ReadInt32();
|
||||
mapFd.fd = reply.ReadFileDescriptor();
|
||||
return mapFd;
|
||||
}
|
||||
|
||||
int WallpaperServiceProxy::GetWallpaperId(int wallpaperType)
|
||||
{
|
||||
int iWallpaperId = 1;
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
HILOG_ERROR(" Failed to write parcelable ");
|
||||
return false;
|
||||
}
|
||||
|
||||
data.WriteInt32(wallpaperType);
|
||||
int32_t result = Remote()->SendRequest(GET_WALLPAPER_ID, data, reply, option);
|
||||
if (result != ERR_NONE) {
|
||||
HILOG_ERROR(" WallpaperServiceProxy::GetWallpaperId fail, result = %{public}d ", result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
iWallpaperId = reply.ReadInt32();
|
||||
HILOG_INFO(" End => iWallpaperId[%{public}d]", iWallpaperId);
|
||||
return iWallpaperId;
|
||||
}
|
||||
int WallpaperServiceProxy::GetWallpaperMinHeight()
|
||||
{
|
||||
int iWallpaperMinHeight = 0;
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
HILOG_ERROR(" Failed to write parcelable ");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t result = Remote()->SendRequest(GET_WALLPAPER_MIN_HEIGHT, data, reply, option);
|
||||
if (result != ERR_NONE) {
|
||||
HILOG_ERROR(" WallpaperServiceProxy::GetWallpaperMinHeight fail, result = %{public}d ", result);
|
||||
return 0;
|
||||
}
|
||||
|
||||
iWallpaperMinHeight = reply.ReadInt32();
|
||||
HILOG_INFO(" End => iWallpaperMinHeight[%{public}d]", iWallpaperMinHeight);
|
||||
return iWallpaperMinHeight;
|
||||
}
|
||||
|
||||
int WallpaperServiceProxy::GetWallpaperMinWidth()
|
||||
{
|
||||
int iWallpaperMinWidth = 0;
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
HILOG_ERROR(" Failed to write parcelable ");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t result = Remote()->SendRequest(GET_WALLPAPER_MIN_WIDTH, data, reply, option);
|
||||
if (result != ERR_NONE) {
|
||||
HILOG_ERROR(" WallpaperServiceProxy::GetWallpaperMinWidth fail, result = %{public}d ", result);
|
||||
return 0;
|
||||
}
|
||||
|
||||
iWallpaperMinWidth = reply.ReadInt32();
|
||||
HILOG_INFO(" End => iWallpaperMinWidth[%{public}d]", iWallpaperMinWidth);
|
||||
return iWallpaperMinWidth;
|
||||
}
|
||||
|
||||
bool WallpaperServiceProxy::IsChangePermitted()
|
||||
{
|
||||
bool bFlag = false;
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
HILOG_ERROR(" Failed to write parcelable ");
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t result = Remote()->SendRequest(IS_CHANGE_PERMITTED, data, reply, option);
|
||||
if (result != ERR_NONE) {
|
||||
HILOG_ERROR(" WallpaperServiceProxy::IsChangePermitted fail, result = %{public}d ", result);
|
||||
return false;
|
||||
}
|
||||
|
||||
bFlag = reply.ReadBool();
|
||||
return bFlag;
|
||||
}
|
||||
|
||||
bool WallpaperServiceProxy::IsOperationAllowed()
|
||||
{
|
||||
bool bFlag = false;
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
HILOG_ERROR(" Failed to write parcelable ");
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t result = Remote()->SendRequest(IS_OPERATION_ALLOWED, data, reply, option);
|
||||
if (result != ERR_NONE) {
|
||||
HILOG_ERROR(" WallpaperServiceProxyIsOperationAllowed fail, result = %{public}d ", result);
|
||||
return false;
|
||||
}
|
||||
|
||||
bFlag = reply.ReadBool();
|
||||
return bFlag;
|
||||
}
|
||||
|
||||
bool WallpaperServiceProxy::ResetWallpaper(int wallpaperType)
|
||||
{
|
||||
bool bFlag = false;
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
HILOG_ERROR(" Failed to write parcelable ");
|
||||
return false;
|
||||
}
|
||||
|
||||
data.WriteInt32(wallpaperType);
|
||||
int32_t result = Remote()->SendRequest(RESET_WALLPAPER, data, reply, option);
|
||||
if (result != ERR_NONE) {
|
||||
HILOG_ERROR(" WallpaperServiceProxy::ResetWallpaper fail, result = %{public}d ", result);
|
||||
return false;
|
||||
}
|
||||
|
||||
bFlag = reply.ReadBool();
|
||||
return bFlag;
|
||||
}
|
||||
|
||||
bool WallpaperServiceProxy::ScreenshotLiveWallpaper(int sacleNumber, OHOS::Media::PixelMap pixelMap)
|
||||
{
|
||||
bool bFlag = false;
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
HILOG_ERROR(" Failed to write parcelable ");
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t result = Remote()->SendRequest(SCREEN_SHOT_LIVE_WALLPAPER, data, reply, option);
|
||||
if (result != ERR_NONE) {
|
||||
HILOG_ERROR(" WallpaperServiceProxy::ScreenshotLiveWallpaper fail, result = %{public}d ", result);
|
||||
return false;
|
||||
}
|
||||
|
||||
bFlag = true;
|
||||
return bFlag;
|
||||
}
|
||||
|
||||
bool WallpaperServiceProxy::On(sptr<IWallpaperColorChangeListener> listener)
|
||||
{
|
||||
HILOG_DEBUG("WallpaperServiceProxy::On in");
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
HILOG_ERROR(" Failed to write parcelable ");
|
||||
return false;
|
||||
}
|
||||
if (listener == nullptr) {
|
||||
HILOG_ERROR("listener is nullptr");
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteParcelable(listener->AsObject())) {
|
||||
HILOG_ERROR("write subscribe type or parcel failed.");
|
||||
return false;
|
||||
}
|
||||
int32_t result = Remote()->SendRequest(ON, data, reply, option);
|
||||
if (result != ERR_NONE) {
|
||||
HILOG_ERROR(" WallpaperServiceProxy::On fail, result = %{public}d ", result);
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t status = reply.ReadInt32();
|
||||
bool ret = (status == 0) ? true : false;
|
||||
HILOG_DEBUG("WallpaperServiceProxy::On out");
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool WallpaperServiceProxy::Off(sptr<IWallpaperColorChangeListener> listener)
|
||||
{
|
||||
HILOG_DEBUG("WallpaperServiceProxy::Off in");
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
HILOG_ERROR(" Failed to write parcelable ");
|
||||
return false;
|
||||
}
|
||||
if (listener == nullptr) {
|
||||
HILOG_ERROR("listener is nullptr");
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteParcelable(listener->AsObject())) {
|
||||
HILOG_ERROR("write subscribe type or parcel failed.");
|
||||
return false;
|
||||
}
|
||||
int32_t result = Remote()->SendRequest(OFF, data, reply, option);
|
||||
if (result != ERR_NONE) {
|
||||
HILOG_ERROR(" WallpaperServiceProxy::Off fail, result = %{public}d ", result);
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t status = reply.ReadInt32();
|
||||
bool ret = (status == 0) ? true : false;
|
||||
HILOG_DEBUG("WallpaperServiceProxy::Off out");
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool WallpaperServiceProxy::RegisterWallpaperCallback(const sptr<IWallpaperCallback> callback)
|
||||
{
|
||||
HILOG_DEBUG("WallpaperServiceProxy::RegisterWallpaperCallback in");
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
HILOG_ERROR(" Failed to write parcelable ");
|
||||
return false;
|
||||
}
|
||||
if (callback == nullptr) {
|
||||
HILOG_ERROR("callback is nullptr");
|
||||
return false;
|
||||
}
|
||||
if (!data.WriteParcelable(callback->AsObject())) {
|
||||
HILOG_ERROR("write subscribe type or parcel failed.");
|
||||
return false;
|
||||
}
|
||||
HILOG_INFO(" Remote()->SendRequest");
|
||||
int32_t result = Remote()->SendRequest(REGISTER_CALLBACK, data, reply, option);
|
||||
if (result != ERR_NONE) {
|
||||
HILOG_ERROR(" WallpaperServiceProxy::REGISTER_CALLBACK fail, result = %{public}d ", result);
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t status = reply.ReadInt32();
|
||||
bool ret = (status == 0) ? true : false;
|
||||
HILOG_DEBUG("WallpaperServiceProxy::REGISTER_CALLBACK out");
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
# 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")
|
||||
SUBSYSTEM_DIR = "//foundation/aafwk/standard/frameworks/kits/ability/native"
|
||||
INNERKITS_PATH = "//foundation/aafwk/standard/interfaces/innerkits"
|
||||
|
||||
config("ability_config") {
|
||||
visibility = [ ":*" ]
|
||||
include_dirs = [
|
||||
"//base/miscservices/wallpaper/frameworks/innerkitsimpl/wallpaper_manager/include",
|
||||
"//base/miscservices/wallpaper/frameworks/kits/extension/include",
|
||||
"${INNERKITS_PATH}/base/include",
|
||||
"//utils/native/base/include",
|
||||
"${SUBSYSTEM_DIR}/include",
|
||||
"//foundation/aafwk/standard/frameworks/kits/appkit/native/app/include",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/app_manager/include/appmgr",
|
||||
"${INNERKITS_PATH}/want/include/ohos/aafwk/content",
|
||||
"${INNERKITS_PATH}/ability_manager/include",
|
||||
"//foundation/aafwk/standard/services/abilitymgr/include",
|
||||
"//foundation/appexecfwk/standard/common/log/include",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core/include/bundlemgr",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include/",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/form_manager/include",
|
||||
"//foundation/aafwk/standard/frameworks/kits/appkit/native/ability_runtime/app",
|
||||
"//foundation/aafwk/standard/frameworks/kits/appkit/native/app/include",
|
||||
"//foundation/aafwk/standard/frameworks/kits/fmskit/native/include",
|
||||
"//foundation/aafwk/standard/frameworks/kits/app/native/app/include",
|
||||
"//foundation/aafwk/standard/services/common/include",
|
||||
"//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include",
|
||||
"//base/global/resmgr_standard/interfaces/innerkits/include",
|
||||
"//foundation/aafwk/standard/interfaces/kits/napi/aafwk/featureAbility",
|
||||
"//foundation/ace/napi/interfaces/kits",
|
||||
"//third_party/node/src",
|
||||
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/native/include/continuation/remote_register_service",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/native/include/continuation/distributed",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/native/include/distributed_ability_runtime",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include/continuation",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/native/include/continuation/kits",
|
||||
"//base/security/permission/interfaces/innerkits/permission_standard/permissionsdk/main/cpp/include",
|
||||
"//foundation/aafwk/standard/common/task_dispatcher/include/dispatcher",
|
||||
"//foundation/aafwk/standard/common/task_dispatcher/include/task",
|
||||
"//foundation/aafwk/standard/common/task_dispatcher/include/threading",
|
||||
"//foundation/aafwk/standard/frameworks/kits/appkit/native/app/include/task",
|
||||
"//foundation/aafwk/standard/interfaces/kits/napi/aafwk/inner/napi_common",
|
||||
]
|
||||
|
||||
cflags = []
|
||||
if (target_cpu == "arm") {
|
||||
cflags += [ "-DBINDER_IPC_32BIT" ]
|
||||
}
|
||||
defines = [
|
||||
"APP_LOG_TAG = \"Ability\"",
|
||||
"LOG_DOMAIN = 0xD002200",
|
||||
]
|
||||
}
|
||||
|
||||
config("ability_public_config") {
|
||||
visibility = [ ":*" ]
|
||||
include_dirs = [
|
||||
"//base/miscservices/wallpaper/frameworks/innerkitsimpl/wallpaper_manager/include",
|
||||
"//base/miscservices/wallpaper/frameworks/kits/extension/include",
|
||||
"${INNERKITS_PATH}/base/include",
|
||||
"//foundation/aafwk/standard/frameworks/kits/appkit/native",
|
||||
"//foundation/aafwk/standard/frameworks/kits/appkit/native/ability_runtime/app",
|
||||
"//foundation/aafwk/standard/frameworks/kits/appkit/native/app/include",
|
||||
"//foundation/aafwk/standard/frameworks/kits/appkit/native/ability_runtime",
|
||||
"${SUBSYSTEM_DIR}/include",
|
||||
"//third_party/libuv/include",
|
||||
"//foundation/aafwk/standard/frameworks/kits/appkit/native/ability_runtime/context",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/base/include/ohos/aafwk/base",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/native/include/continuation/remote_register_service",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/native/include/continuation/distributed",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/native/include/distributed_ability_runtime",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include/continuation",
|
||||
"//base/global/resmgr_standard/interfaces/innerkits/include",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/native/include/continuation/kits",
|
||||
"//foundation/aafwk/standard/frameworks/kits/fmskit/native/include",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/form_manager/include",
|
||||
"//foundation/windowmanager/interfaces/innerkits/wm",
|
||||
"//foundation/windowmanager/interfaces/kits/napi/window_runtime/window_stage_napi",
|
||||
"//third_party/jsoncpp/include",
|
||||
"//third_party/json/include",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_shared_library("wallpaperextension") {
|
||||
include_dirs = [
|
||||
"//base/miscservices/wallpaper/frameworks/innerkitsimpl/wallpaper_manager/include",
|
||||
"//base/miscservices/wallpaper/frameworks/kits/extension/include",
|
||||
"//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/napi_rdb/include",
|
||||
"//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/common/include",
|
||||
"//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/napi_dataability/include",
|
||||
"//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/napi_resultset/include",
|
||||
"//base/global/i18n_standard/frameworks/intl/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"//base/miscservices/wallpaper/frameworks/kits/extension/src/js_wallpaper_extension_context.cpp",
|
||||
"//base/miscservices/wallpaper/frameworks/kits/extension/src/js_wallpaper_extension.cpp",
|
||||
"//base/miscservices/wallpaper/frameworks/kits/extension/src/wallpaper_extension_context.cpp",
|
||||
"//base/miscservices/wallpaper/frameworks/kits/extension/src/wallpaper_extension.cpp",
|
||||
|
||||
]
|
||||
configs = [ ":ability_config" ]
|
||||
public_configs = [
|
||||
":ability_public_config",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/ability_runtime:ability_context_public_config",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//base/miscservices/wallpaper/frameworks/innerkitsimpl/wallpaper_manager:wallpapermanager",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/native:static_subscriber_ipc",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
|
||||
"${INNERKITS_PATH}/base:base",
|
||||
"${INNERKITS_PATH}/want:want",
|
||||
"//base/security/permission/interfaces/innerkits/permission_standard/permissionsdk:libpermissionsdk_standard",
|
||||
"//foundation/aafwk/standard/common/task_dispatcher:task_dispatcher",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/ability_runtime:ability_context_native",
|
||||
"//foundation/aafwk/standard/frameworks/kits/appkit:app_context",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/app_manager:app_manager",
|
||||
"//foundation/aafwk/standard/interfaces/innerkits/dataobs_manager:dataobs_manager",
|
||||
"//foundation/ace/napi:ace_napi",
|
||||
"//foundation/appexecfwk/standard/common:libappexecfwk_common",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core",
|
||||
"//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
"//foundation/multimodalinput/input/frameworks/proxy:libmmi-common",
|
||||
"//third_party/icu/icu4c:shared_icuuc",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_runtime:ability_context_native",
|
||||
"ability_runtime:app_manager",
|
||||
"ability_runtime:napi_base_context",
|
||||
"ability_runtime:runtime",
|
||||
"bytrace_standard:bytrace_core",
|
||||
"ces_standard:cesfwk_innerkits",
|
||||
"form_runtime:fmskit_native",
|
||||
"form_runtime:form_manager",
|
||||
"ipc:ipc_core",
|
||||
"ipc_js:rpc",
|
||||
"multimodalinput_base:libmmi-client",
|
||||
"native_appdatamgr:native_appdatafwk",
|
||||
"native_appdatamgr:native_dataability",
|
||||
"native_appdatamgr:native_rdb",
|
||||
"utils_base:utils",
|
||||
]
|
||||
|
||||
public_deps = [
|
||||
"//base/global/i18n_standard/frameworks/intl:intl_util",
|
||||
"//base/global/resmgr_standard/frameworks/resmgr:global_resmgr",
|
||||
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
|
||||
"//foundation/ace/napi:ace_napi",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
|
||||
"//foundation/graphic/standard:libwmclient",
|
||||
"//foundation/windowmanager/interfaces/kits/napi/window_runtime:windowstage_kit",
|
||||
"//foundation/windowmanager/wm:libwm",
|
||||
]
|
||||
|
||||
subsystem_name = "miscservices"
|
||||
part_name = "wallpaper_native"
|
||||
}
|
||||
|
||||
|
||||
ohos_shared_library("wallpaper_extension_module") {
|
||||
include_dirs =
|
||||
[ "//foundation/aafwk/standard/frameworks/kits/ability/native/include",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/native/include/ability_runtime",
|
||||
]
|
||||
|
||||
sources = [ "//base/miscservices/wallpaper/frameworks/kits/extension/src/wallpaper_extension_module_loader.cpp" ]
|
||||
|
||||
configs = [ ":ability_config" ]
|
||||
public_configs = [ ":ability_public_config" ]
|
||||
|
||||
deps = [
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
|
||||
":wallpaperextension",
|
||||
"//foundation/appexecfwk/standard/common:libappexecfwk_common",
|
||||
"//utils/native/base:utils",
|
||||
"//foundation/windowmanager/wm:libwm",
|
||||
"//foundation/windowmanager/utils:libwmutil",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_runtime:runtime",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
]
|
||||
|
||||
subsystem_name = "miscservices"
|
||||
part_name = "wallpaper_native"
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* 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 FOUNDATION_ABILITYRUNTIME_OHOS_JS_WALLPAPER_EXTENSION_H
|
||||
#define FOUNDATION_ABILITYRUNTIME_OHOS_JS_WALLPAPER_EXTENSION_H
|
||||
|
||||
#include "wallpaper_extension.h"
|
||||
|
||||
class NativeReference;
|
||||
class NativeValue;
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
class WallpaperExtension;
|
||||
class JsRuntime;
|
||||
|
||||
/**
|
||||
* @brief Basic wallpaper components.
|
||||
*/
|
||||
class JsWallpaperExtension : public WallpaperExtension,
|
||||
public std::enable_shared_from_this<JsWallpaperExtension> {
|
||||
public:
|
||||
JsWallpaperExtension(JsRuntime& jsRuntime);
|
||||
virtual ~JsWallpaperExtension() override;
|
||||
static JsWallpaperExtension* jsWallpaperExtension;
|
||||
/**
|
||||
* @brief Create JsWallpaperExtension.
|
||||
*
|
||||
* @param runtime The runtime.
|
||||
* @return The JsWallpaperExtension instance.
|
||||
*/
|
||||
static JsWallpaperExtension* Create(const std::unique_ptr<Runtime>& runtime);
|
||||
|
||||
/**
|
||||
* @brief Init the extension.
|
||||
*
|
||||
* @param record the extension record.
|
||||
* @param application the application info.
|
||||
* @param handler the extension handler.
|
||||
* @param token the remote token.
|
||||
*/
|
||||
virtual void Init(const std::shared_ptr<AppExecFwk::AbilityLocalRecord> &record,
|
||||
const std::shared_ptr<AppExecFwk::OHOSApplication> &application,
|
||||
std::shared_ptr<AppExecFwk::AbilityHandler> &handler,
|
||||
const sptr<IRemoteObject> &token) override;
|
||||
|
||||
/**
|
||||
* @brief Called when this extension is started. You must override this function if you want to perform some
|
||||
* initialization operations during extension startup.
|
||||
*
|
||||
* This function can be called only once in the entire lifecycle of an extension.
|
||||
* @param Want Indicates the {@link Want} structure containing startup information about the extension.
|
||||
*/
|
||||
virtual void OnStart(const AAFwk::Want &want) override;
|
||||
|
||||
/**
|
||||
* @brief Called when this Wallpaper extension is connected for the first time.
|
||||
*
|
||||
* You can override this function to implement your own processing logic.
|
||||
*
|
||||
* @param want Indicates the {@link Want} structure containing connection information about the Wallpaper extension.
|
||||
* @return Returns a pointer to the <b>sid</b> of the connected Wallpaper extension.
|
||||
*/
|
||||
virtual sptr<IRemoteObject> OnConnect(const AAFwk::Want &want) override;
|
||||
|
||||
/**
|
||||
* @brief Called when all abilities connected to this Wallpaper extension are disconnected.
|
||||
*
|
||||
* You can override this function to implement your own processing logic.
|
||||
*
|
||||
*/
|
||||
virtual void OnDisconnect(const AAFwk::Want &want) override;
|
||||
|
||||
/**
|
||||
* @brief Called back when Wallpaper is started.
|
||||
* This method can be called only by Wallpaper. You can use the StartAbility(ohos.aafwk.content.Want) method to start
|
||||
* Wallpaper. Then the system calls back the current method to use the transferred want parameter to execute its own
|
||||
* logic.
|
||||
*
|
||||
* @param want Indicates the want of Wallpaper to start.
|
||||
* @param restart Indicates the startup mode. The value true indicates that Wallpaper is restarted after being
|
||||
* destroyed, and the value false indicates a normal startup.
|
||||
* @param startId Indicates the number of times the Wallpaper extension has been started. The startId is incremented
|
||||
* by 1 every time the extension is started. For example, if the extension has been started for six times, the
|
||||
* value of startId is 6.
|
||||
*/
|
||||
virtual void OnCommand(const AAFwk::Want &want, bool restart, int startId) override;
|
||||
|
||||
/**
|
||||
* @brief Called when this extension enters the <b>STATE_STOP</b> state.
|
||||
*
|
||||
* The extension in the <b>STATE_STOP</b> is being destroyed.
|
||||
* You can override this function to implement your own processing logic.
|
||||
*/
|
||||
virtual void OnStop() override;
|
||||
|
||||
private:
|
||||
NativeValue* CallObjectMethod(const char* name, NativeValue* const* argv = nullptr, size_t argc = 0);
|
||||
|
||||
void GetSrcPath(std::string &srcPath);
|
||||
|
||||
JsRuntime& jsRuntime_;
|
||||
std::unique_ptr<NativeReference> jsObj_;
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // FOUNDATION_ABILITYRUNTIME_OHOS_JS_WALLPAPER_EXTENSION_H
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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 ABILITY_RUNTIME_JS_WALLPAPER_EXTENSION_CONTEXT_H
|
||||
#define ABILITY_RUNTIME_JS_WALLPAPER_EXTENSION_CONTEXT_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "ability_connect_callback.h"
|
||||
#include "wallpaper_extension_context.h"
|
||||
#include "event_handler.h"
|
||||
|
||||
class NativeEngine;
|
||||
class NativeValue;
|
||||
class NativeReference;
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
NativeValue* CreateJsWallpaperExtensionContext(NativeEngine& engine, std::shared_ptr<WallpaperExtensionContext> context);
|
||||
|
||||
class JSWallpaperExtensionConnection : public AbilityConnectCallback {
|
||||
public:
|
||||
explicit JSWallpaperExtensionConnection(NativeEngine& engine);
|
||||
~JSWallpaperExtensionConnection();
|
||||
void OnAbilityConnectDone(
|
||||
const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode) override;
|
||||
void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override;
|
||||
void HandleOnAbilityConnectDone(
|
||||
const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode);
|
||||
void HandleOnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode);
|
||||
void SetJsConnectionObject(NativeValue* jsConnectionObject);
|
||||
void CallJsFailed(int32_t errorCode);
|
||||
private:
|
||||
NativeEngine& engine_;
|
||||
std::unique_ptr<NativeReference> jsConnectionObject_ = nullptr;
|
||||
};
|
||||
|
||||
struct ConnecttionKey {
|
||||
AAFwk::Want want;
|
||||
int64_t id;
|
||||
};
|
||||
|
||||
struct key_compare {
|
||||
bool operator()(const ConnecttionKey &key1, const ConnecttionKey &key2) const
|
||||
{
|
||||
if (key1.id < key2.id) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
static std::map<ConnecttionKey, sptr<JSWallpaperExtensionConnection>, key_compare> connects_;
|
||||
static int64_t serialNumber_ = 0;
|
||||
static std::shared_ptr<AppExecFwk::EventHandler> handler_ = nullptr;
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // ABILITY_RUNTIME_JS_WALLPAPER_EXTENSION_CONTEXT_H
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FOUNDATION_ABILITYRUNTIME_OHOS_WALLPAPER_EXTENSION_H
|
||||
#define FOUNDATION_ABILITYRUNTIME_OHOS_WALLPAPER_EXTENSION_H
|
||||
|
||||
#include "extension_base.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
class WallpaperExtensionContext;
|
||||
class Runtime;
|
||||
/**
|
||||
* @brief Basic wallpaper components.
|
||||
*/
|
||||
class WallpaperExtension : public ExtensionBase<WallpaperExtensionContext>,
|
||||
public std::enable_shared_from_this<WallpaperExtension> {
|
||||
public:
|
||||
WallpaperExtension() = default;
|
||||
virtual ~WallpaperExtension() = default;
|
||||
|
||||
/**
|
||||
* @brief Create and init context.
|
||||
*
|
||||
* @param record the extension record.
|
||||
* @param application the application info.
|
||||
* @param handler the extension handler.
|
||||
* @param token the remote token.
|
||||
* @return The created context.
|
||||
*/
|
||||
virtual std::shared_ptr<WallpaperExtensionContext> CreateAndInitContext(
|
||||
const std::shared_ptr<AbilityLocalRecord> &record,
|
||||
const std::shared_ptr<OHOSApplication> &application,
|
||||
std::shared_ptr<AbilityHandler> &handler,
|
||||
const sptr<IRemoteObject> &token) override;
|
||||
|
||||
/**
|
||||
* @brief Init the extension.
|
||||
*
|
||||
* @param record the extension record.
|
||||
* @param application the application info.
|
||||
* @param handler the extension handler.
|
||||
* @param token the remote token.
|
||||
*/
|
||||
virtual void Init(const std::shared_ptr<AbilityLocalRecord> &record,
|
||||
const std::shared_ptr<OHOSApplication> &application,
|
||||
std::shared_ptr<AbilityHandler> &handler,
|
||||
const sptr<IRemoteObject> &token) override;
|
||||
|
||||
/**
|
||||
* @brief Create Extension.
|
||||
*
|
||||
* @param runtime The runtime.
|
||||
* @return The WallpaperExtension instance.
|
||||
*/
|
||||
static WallpaperExtension* Create(const std::unique_ptr<Runtime>& runtime);
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // FOUNDATION_ABILITYRUNTIME_OHOS_WALLPAPER_EXTENSION_H
|
||||
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef WALLPAPER_EXTENSION_CONTEXT_H
|
||||
#define WALLPAPER_EXTENSION_CONTEXT_H
|
||||
|
||||
#include "extension_context.h"
|
||||
|
||||
#include "ability_connect_callback.h"
|
||||
#include "connection_manager.h"
|
||||
#include "start_options.h"
|
||||
#include "want.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
/**
|
||||
* @brief context supply for wallpaper
|
||||
*
|
||||
*/
|
||||
class WallpaperExtensionContext : public ExtensionContext {
|
||||
public:
|
||||
WallpaperExtensionContext() = default;
|
||||
virtual ~WallpaperExtensionContext() = default;
|
||||
|
||||
/**
|
||||
* @brief Starts a new ability.
|
||||
* An ability using the AbilityInfo.AbilityType.WALLPAPER or AbilityInfo.AbilityType.PAGE template uses this method
|
||||
* to start a specific ability. The system locates the target ability from installed abilities based on the value
|
||||
* of the want parameter and then starts it. You can specify the ability to start using the want parameter.
|
||||
*
|
||||
* @param want Indicates the Want containing information about the target ability to start.
|
||||
*
|
||||
* @return errCode ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode StartAbility(const AAFwk::Want &want) const;
|
||||
|
||||
ErrCode StartAbility(const AAFwk::Want &want, const AAFwk::StartOptions &startOptions) const;
|
||||
|
||||
/**
|
||||
* @brief Connects the current ability to an ability using the AbilityInfo.AbilityType.WALLPAPER template.
|
||||
*
|
||||
* @param want Indicates the want containing information about the ability to connect
|
||||
*
|
||||
* @param conn Indicates the callback object when the target ability is connected.
|
||||
*
|
||||
* @return True means success and false means failure
|
||||
*/
|
||||
bool ConnectAbility(
|
||||
const AAFwk::Want &want, const sptr<AbilityConnectCallback> &connectCallback) const;
|
||||
|
||||
/**
|
||||
* @brief Starts a new ability.
|
||||
* An ability using the AbilityInfo.AbilityType.WALLPAPER or AbilityInfo.AbilityType.PAGE template uses this method
|
||||
* to start a specific ability. The system locates the target ability from installed abilities based on the value
|
||||
* of the want parameter and then starts it. You can specify the ability to start using the want parameter.
|
||||
*
|
||||
* @param want Indicates the Want containing information about the target ability to start.
|
||||
* @param accountId caller user.
|
||||
*
|
||||
* @return errCode ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode StartAbilityWithAccount(const AAFwk::Want &want, int accountId) const;
|
||||
|
||||
ErrCode StartAbilityWithAccount(
|
||||
const AAFwk::Want &want, int accountId, const AAFwk::StartOptions &startOptions) const;
|
||||
|
||||
/**
|
||||
* @brief Connects the current ability to an ability using the AbilityInfo.AbilityType.WALLPAPER template.
|
||||
*
|
||||
* @param want Indicates the want containing information about the ability to connect.
|
||||
*
|
||||
* @param accountId caller user.
|
||||
*
|
||||
* @param conn Indicates the callback object when the target ability is connected.
|
||||
*
|
||||
* @return True means success and false means failure.
|
||||
*/
|
||||
bool ConnectAbilityWithAccount(
|
||||
const AAFwk::Want &want, int accountId, const sptr<AbilityConnectCallback> &connectCallback) const;
|
||||
|
||||
/**
|
||||
* @brief Disconnects the current ability from an ability.
|
||||
*
|
||||
* @param conn Indicates the IAbilityConnection callback object passed by connectAbility after the connection
|
||||
* is set up. The IAbilityConnection object uniquely identifies a connection between two abilities.
|
||||
*
|
||||
* @return errCode ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode DisconnectAbility(
|
||||
const AAFwk::Want &want, const sptr<AbilityConnectCallback> &connectCallback) const;
|
||||
|
||||
/**
|
||||
* @brief Destroys the current ability.
|
||||
*
|
||||
* @return errCode ERR_OK on success, others on failure.
|
||||
*/
|
||||
ErrCode TerminateAbility();
|
||||
|
||||
using SelfType = WallpaperExtensionContext;
|
||||
static const size_t CONTEXT_TYPE_ID;
|
||||
|
||||
protected:
|
||||
bool IsContext(size_t contextTypeId) override
|
||||
{
|
||||
return contextTypeId == CONTEXT_TYPE_ID || ExtensionContext::IsContext(contextTypeId);
|
||||
}
|
||||
|
||||
private:
|
||||
static int ILLEGAL_REQUEST_CODE;
|
||||
|
||||
/**
|
||||
* @brief Get Current Ability Type
|
||||
*
|
||||
* @return Current Ability Type
|
||||
*/
|
||||
OHOS::AppExecFwk::AbilityType GetAbilityInfoType() const;
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // WALLPAPER_EXTENSION_CONTEXT_H
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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 FOUNDATION_ABILITYRUTIME_WALLPAPER_EXTENSION_MODULE_LOADER_H
|
||||
#define FOUNDATION_ABILITYRUTIME_WALLPAPER_EXTENSION_MODULE_LOADER_H
|
||||
|
||||
#include "extension_module_loader.h"
|
||||
|
||||
namespace OHOS::AbilityRuntime {
|
||||
class WallpaperExtensionModuleLoader : public ExtensionModuleLoader, public Singleton<WallpaperExtensionModuleLoader> {
|
||||
DECLARE_SINGLETON(WallpaperExtensionModuleLoader);
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Create Extension.
|
||||
*
|
||||
* @param runtime The runtime.
|
||||
* @return The Extension instance.
|
||||
*/
|
||||
virtual Extension *Create(const std::unique_ptr<Runtime>& runtime) const override;
|
||||
};
|
||||
}
|
||||
#endif // FOUNDATION_ABILITYRUTIME_WALLPAPER_EXTENSION_MODULE_LOADER_H
|
||||
@@ -0,0 +1,291 @@
|
||||
/*
|
||||
* 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 "js_wallpaper_extension.h"
|
||||
|
||||
#include "ability_info.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "js_runtime.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "js_wallpaper_extension_context.h"
|
||||
#include "napi/native_api.h"
|
||||
#include "napi/native_node_api.h"
|
||||
#include "napi_common_want.h"
|
||||
#include "napi_remote_object.h"
|
||||
#include "wallpaper_manager.h"
|
||||
#include "napi_common_util.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
namespace {
|
||||
constexpr size_t ARGC_ONE = 1;
|
||||
constexpr size_t ARGC_TWO = 2;
|
||||
}
|
||||
JsWallpaperExtension* JsWallpaperExtension::jsWallpaperExtension = NULL;
|
||||
using namespace OHOS::AppExecFwk;
|
||||
JsWallpaperExtension* JsWallpaperExtension::Create(const std::unique_ptr<Runtime>& runtime)
|
||||
{
|
||||
HILOG_INFO("jws JsWallpaperExtension begin Create");
|
||||
jsWallpaperExtension = new JsWallpaperExtension(static_cast<JsRuntime&>(*runtime));
|
||||
return jsWallpaperExtension;
|
||||
}
|
||||
|
||||
JsWallpaperExtension::JsWallpaperExtension(JsRuntime& jsRuntime) : jsRuntime_(jsRuntime) {}
|
||||
JsWallpaperExtension::~JsWallpaperExtension() = default;
|
||||
|
||||
void JsWallpaperExtension::Init(const std::shared_ptr<AbilityLocalRecord> &record,
|
||||
const std::shared_ptr<OHOSApplication> &application, std::shared_ptr<AbilityHandler> &handler,
|
||||
const sptr<IRemoteObject> &token)
|
||||
{
|
||||
HILOG_INFO("jws JsWallpaperExtension begin Init");
|
||||
WallpaperExtension::Init(record, application, handler, token);
|
||||
std::string srcPath = "";
|
||||
GetSrcPath(srcPath);
|
||||
if (srcPath.empty()) {
|
||||
HILOG_ERROR("Failed to get srcPath");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string moduleName(Extension::abilityInfo_->moduleName);
|
||||
moduleName.append("::").append(abilityInfo_->name);
|
||||
HILOG_INFO("JsWallpaperExtension::Init module:%{public}s,srcPath:%{public}s.", moduleName.c_str(), srcPath.c_str());
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
auto& engine = jsRuntime_.GetNativeEngine();
|
||||
|
||||
jsObj_ = jsRuntime_.LoadModule(moduleName, srcPath);
|
||||
if (jsObj_ == nullptr) {
|
||||
HILOG_ERROR("Failed to get jsObj_");
|
||||
return;
|
||||
}
|
||||
HILOG_INFO("JsWallpaperExtension::Init ConvertNativeValueTo.");
|
||||
NativeObject* obj = ConvertNativeValueTo<NativeObject>(jsObj_->Get());
|
||||
if (obj == nullptr) {
|
||||
HILOG_ERROR("Failed to get JsWallpaperExtension object");
|
||||
return;
|
||||
}
|
||||
|
||||
auto context = GetContext();
|
||||
if (context == nullptr) {
|
||||
HILOG_ERROR("Failed to get context");
|
||||
return;
|
||||
}
|
||||
HILOG_INFO("JsWallpaperExtension::Init CreateJsWallpaperExtensionContext.");
|
||||
NativeValue* contextObj = CreateJsWallpaperExtensionContext(engine, context);
|
||||
auto shellContextRef = jsRuntime_.LoadSystemModule("application.WallpaperExtensionContext", &contextObj, ARGC_ONE);
|
||||
contextObj = shellContextRef->Get();
|
||||
HILOG_INFO("JsWallpaperExtension::Init Bind.");
|
||||
context->Bind(jsRuntime_, shellContextRef.release());
|
||||
HILOG_INFO("JsWallpaperExtension::SetProperty.");
|
||||
obj->SetProperty("context", contextObj);
|
||||
|
||||
auto nativeObj = ConvertNativeValueTo<NativeObject>(contextObj);
|
||||
if (nativeObj == nullptr) {
|
||||
HILOG_ERROR("Failed to get wallpaper extension native object");
|
||||
return;
|
||||
}
|
||||
|
||||
HILOG_INFO("Set wallpaper extension context pointer: %{public}p", context.get());
|
||||
|
||||
nativeObj->SetNativePointer(new std::weak_ptr<AbilityRuntime::Context>(context),
|
||||
[](NativeEngine*, void* data, void*) {
|
||||
HILOG_INFO("Finalizer for weak_ptr wallpaper extension context is called");
|
||||
delete static_cast<std::weak_ptr<AbilityRuntime::Context>*>(data);
|
||||
}, nullptr);
|
||||
|
||||
HILOG_INFO("JsWallpaperExtension::Init end.");
|
||||
}
|
||||
|
||||
void JsWallpaperExtension::OnStart(const AAFwk::Want &want)
|
||||
{
|
||||
Extension::OnStart(want);
|
||||
HILOG_INFO("jws JsWallpaperExtension OnStart begin..");
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
NativeEngine* nativeEngine = &jsRuntime_.GetNativeEngine();
|
||||
napi_value napiWant = OHOS::AppExecFwk::WrapWant(reinterpret_cast<napi_env>(nativeEngine), want);
|
||||
NativeValue* nativeWant = reinterpret_cast<NativeValue*>(napiWant);
|
||||
NativeValue* argv[] = {nativeWant};
|
||||
CallObjectMethod("onCreated", argv, ARGC_ONE);
|
||||
CallObjectMethod("createWallpaperWin");
|
||||
WallpaperMgrService::WallpaperManagerkits::GetInstance().RegisterWallpaperCallback
|
||||
([](int WallpaperType)->bool
|
||||
{
|
||||
HILOG_INFO(" jsWallpaperExtension->CallObjectMethod");
|
||||
HandleScope handleScope(jsWallpaperExtension->jsRuntime_);
|
||||
NativeEngine* nativeEng = &(jsWallpaperExtension->jsRuntime_).GetNativeEngine();
|
||||
napi_value type = OHOS::AppExecFwk::WrapInt32ToJS(reinterpret_cast<napi_env>(nativeEng), WallpaperType);
|
||||
NativeValue* nativeType = reinterpret_cast<NativeValue*>(type);
|
||||
NativeValue* arg[] = {nativeType};
|
||||
jsWallpaperExtension->CallObjectMethod("onWallpaperChanged", arg, ARGC_ONE);
|
||||
return true;
|
||||
});
|
||||
HILOG_INFO("%{public}s end.", __func__);
|
||||
}
|
||||
|
||||
void JsWallpaperExtension::OnStop()
|
||||
{
|
||||
WallpaperExtension::OnStop();
|
||||
HILOG_INFO("jws JsWallpaperExtension OnStop begin.");
|
||||
CallObjectMethod("onDestroy");
|
||||
bool ret = ConnectionManager::GetInstance().DisconnectCaller(GetContext()->GetToken());
|
||||
if (ret) {
|
||||
HILOG_INFO("The wallpaper extension connection is not disconnected.");
|
||||
}
|
||||
HILOG_INFO("%{public}s end.", __func__);
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> JsWallpaperExtension::OnConnect(const AAFwk::Want &want)
|
||||
{
|
||||
HILOG_INFO("jws JsWallpaperExtension OnConnect begin.");
|
||||
Extension::OnConnect(want);
|
||||
HILOG_INFO("%{public}s begin.", __func__);
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
NativeEngine* nativeEngine = &jsRuntime_.GetNativeEngine();
|
||||
napi_value napiWant = OHOS::AppExecFwk::WrapWant(reinterpret_cast<napi_env>(nativeEngine), want);
|
||||
NativeValue* nativeWant = reinterpret_cast<NativeValue*>(napiWant);
|
||||
NativeValue* argv[] = {nativeWant};
|
||||
if (!jsObj_) {
|
||||
HILOG_WARN("Not found WallpaperExtension.js");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue* value = jsObj_->Get();
|
||||
NativeObject* obj = ConvertNativeValueTo<NativeObject>(value);
|
||||
if (obj == nullptr) {
|
||||
HILOG_ERROR("Failed to get WallpaperExtension object");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue* method = obj->GetProperty("onConnect");
|
||||
if (method == nullptr) {
|
||||
HILOG_ERROR("Failed to get onConnect from WallpaperExtension object");
|
||||
return nullptr;
|
||||
}
|
||||
HILOG_INFO("JsWallpaperExtension::CallFunction onConnect, success");
|
||||
NativeValue* remoteNative = nativeEngine->CallFunction(value, method, argv, ARGC_ONE);
|
||||
if (remoteNative == nullptr) {
|
||||
HILOG_ERROR("remoteNative nullptr.");
|
||||
}
|
||||
auto remoteObj = NAPI_ohos_rpc_getNativeRemoteObject(
|
||||
reinterpret_cast<napi_env>(nativeEngine), reinterpret_cast<napi_value>(remoteNative));
|
||||
if (remoteObj == nullptr) {
|
||||
HILOG_ERROR("remoteObj nullptr.");
|
||||
}
|
||||
return remoteObj;
|
||||
}
|
||||
|
||||
void JsWallpaperExtension::OnDisconnect(const AAFwk::Want &want)
|
||||
{
|
||||
HILOG_INFO("jws JsWallpaperExtension OnDisconnect begin.");
|
||||
Extension::OnDisconnect(want);
|
||||
HILOG_INFO("%{public}s begin.", __func__);
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
NativeEngine* nativeEngine = &jsRuntime_.GetNativeEngine();
|
||||
napi_value napiWant = OHOS::AppExecFwk::WrapWant(reinterpret_cast<napi_env>(nativeEngine), want);
|
||||
NativeValue* nativeWant = reinterpret_cast<NativeValue*>(napiWant);
|
||||
NativeValue* argv[] = {nativeWant};
|
||||
if (!jsObj_) {
|
||||
HILOG_WARN("Not found WallpaperExtension.js");
|
||||
return;
|
||||
}
|
||||
|
||||
NativeValue* value = jsObj_->Get();
|
||||
NativeObject* obj = ConvertNativeValueTo<NativeObject>(value);
|
||||
if (obj == nullptr) {
|
||||
HILOG_ERROR("Failed to get WallpaperExtension object");
|
||||
return;
|
||||
}
|
||||
|
||||
NativeValue* method = obj->GetProperty("onDisconnect");
|
||||
if (method == nullptr) {
|
||||
HILOG_ERROR("Failed to get onDisconnect from WallpaperExtension object");
|
||||
return;
|
||||
}
|
||||
nativeEngine->CallFunction(value, method, argv, ARGC_ONE);
|
||||
HILOG_INFO("%{public}s end.", __func__);
|
||||
}
|
||||
|
||||
void JsWallpaperExtension::OnCommand(const AAFwk::Want &want, bool restart, int startId)
|
||||
{
|
||||
HILOG_INFO("jws JsWallpaperExtension OnCommand begin.");
|
||||
Extension::OnCommand(want, restart, startId);
|
||||
HILOG_INFO("%{public}s begin restart=%{public}s,startId=%{public}d.",
|
||||
__func__,
|
||||
restart ? "true" : "false",
|
||||
startId);
|
||||
// wrap want
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
NativeEngine* nativeEngine = &jsRuntime_.GetNativeEngine();
|
||||
napi_value napiWant = OHOS::AppExecFwk::WrapWant(reinterpret_cast<napi_env>(nativeEngine), want);
|
||||
NativeValue* nativeWant = reinterpret_cast<NativeValue*>(napiWant);
|
||||
// wrap startId
|
||||
napi_value napiStartId = nullptr;
|
||||
napi_create_int32(reinterpret_cast<napi_env>(nativeEngine), startId, &napiStartId);
|
||||
NativeValue* nativeStartId = reinterpret_cast<NativeValue*>(napiStartId);
|
||||
NativeValue* argv[] = {nativeWant, nativeStartId};
|
||||
CallObjectMethod("onRequest", argv, ARGC_TWO);
|
||||
HILOG_INFO("%{public}s end.", __func__);
|
||||
}
|
||||
|
||||
NativeValue* JsWallpaperExtension::CallObjectMethod(const char* name, NativeValue* const* argv, size_t argc)
|
||||
{
|
||||
HILOG_INFO("jws JsWallpaperExtension::CallObjectMethod(%{public}s), begin", name);
|
||||
|
||||
if (!jsObj_) {
|
||||
HILOG_WARN("Not found WallpaperExtension.js");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
HandleScope handleScope(jsRuntime_);
|
||||
auto& nativeEngine = jsRuntime_.GetNativeEngine();
|
||||
|
||||
NativeValue* value = jsObj_->Get();
|
||||
NativeObject* obj = ConvertNativeValueTo<NativeObject>(value);
|
||||
if (obj == nullptr) {
|
||||
HILOG_ERROR("Failed to get WallpaperExtension object");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue* method = obj->GetProperty(name);
|
||||
if (method == nullptr) {
|
||||
HILOG_ERROR("Failed to get '%{public}s' from WallpaperExtension object", name);
|
||||
return nullptr;
|
||||
}
|
||||
HILOG_INFO("JsWallpaperExtension::CallFunction(%{public}s), success", name);
|
||||
return nativeEngine.CallFunction(value, method, argv, argc);
|
||||
}
|
||||
|
||||
void JsWallpaperExtension::GetSrcPath(std::string &srcPath)
|
||||
{
|
||||
HILOG_INFO("jws JsWallpaperExtension GetSrcPath begin.");
|
||||
if (!Extension::abilityInfo_->isModuleJson) {
|
||||
/* temporary compatibility api8 + config.json */
|
||||
srcPath.append(Extension::abilityInfo_->package);
|
||||
srcPath.append("/assets/js/");
|
||||
if (!Extension::abilityInfo_->srcPath.empty()) {
|
||||
srcPath.append(Extension::abilityInfo_->srcPath);
|
||||
}
|
||||
srcPath.append("/").append(Extension::abilityInfo_->name).append(".abc");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Extension::abilityInfo_->srcEntrance.empty()) {
|
||||
srcPath.append(Extension::abilityInfo_->moduleName + "/");
|
||||
srcPath.append(Extension::abilityInfo_->srcEntrance);
|
||||
srcPath.erase(srcPath.rfind('.'));
|
||||
srcPath.append(".abc");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,669 @@
|
||||
/*
|
||||
* 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 "js_wallpaper_extension_context.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "hilog_wrapper.h"
|
||||
#include "js_extension_context.h"
|
||||
#include "js_data_struct_converter.h"
|
||||
#include "js_runtime.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "napi/native_api.h"
|
||||
#include "napi_common_want.h"
|
||||
#include "napi_common_util.h"
|
||||
#include "napi_remote_object.h"
|
||||
#include "napi_common_start_options.h"
|
||||
#include "start_options.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
namespace {
|
||||
constexpr int32_t INDEX_ZERO = 0;
|
||||
constexpr int32_t INDEX_ONE = 1;
|
||||
constexpr int32_t INDEX_TWO = 2;
|
||||
constexpr int32_t ERROR_CODE_ONE = 1;
|
||||
constexpr int32_t ERROR_CODE_TWO = 2;
|
||||
constexpr size_t ARGC_ZERO = 0;
|
||||
constexpr size_t ARGC_ONE = 1;
|
||||
constexpr size_t ARGC_TWO = 2;
|
||||
constexpr size_t ARGC_THREE = 3;
|
||||
constexpr size_t ARGC_FOUR = 4;
|
||||
|
||||
class JsWallpaperExtensionContext final {
|
||||
public:
|
||||
JsWallpaperExtensionContext(const std::shared_ptr<WallpaperExtensionContext>& context) : context_(context) {}
|
||||
~JsWallpaperExtensionContext() = default;
|
||||
|
||||
static void Finalizer(NativeEngine* engine, void* data, void* hint)
|
||||
{
|
||||
HILOG_INFO("JsAbilityContext::Finalizer is called");
|
||||
std::unique_ptr<JsWallpaperExtensionContext>(static_cast<JsWallpaperExtensionContext*>(data));
|
||||
}
|
||||
|
||||
static NativeValue* StartAbility(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsWallpaperExtensionContext* me = CheckParamsAndGetThis<JsWallpaperExtensionContext>(engine, info);
|
||||
return (me != nullptr) ? me->OnStartAbility(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
static NativeValue* StartAbilityWithAccount(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsWallpaperExtensionContext* me = CheckParamsAndGetThis<JsWallpaperExtensionContext>(engine, info);
|
||||
return (me != nullptr) ? me->OnStartAbilityWithAccount(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
static NativeValue* ConnectAbilityWithAccount(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsWallpaperExtensionContext* me = CheckParamsAndGetThis<JsWallpaperExtensionContext>(engine, info);
|
||||
return (me != nullptr) ? me->OnConnectAbilityWithAccount(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
static NativeValue* TerminateAbility(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsWallpaperExtensionContext* me = CheckParamsAndGetThis<JsWallpaperExtensionContext>(engine, info);
|
||||
return (me != nullptr) ? me->OnTerminateAbility(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
static NativeValue* ConnectAbility(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsWallpaperExtensionContext* me = CheckParamsAndGetThis<JsWallpaperExtensionContext>(engine, info);
|
||||
return (me != nullptr) ? me->OnConnectAbility(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
static NativeValue* DisconnectAbility(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsWallpaperExtensionContext* me = CheckParamsAndGetThis<JsWallpaperExtensionContext>(engine, info);
|
||||
return (me != nullptr) ? me->OnDisconnectAbility(*engine, *info) : nullptr;
|
||||
}
|
||||
private:
|
||||
std::weak_ptr<WallpaperExtensionContext> context_;
|
||||
|
||||
NativeValue* OnStartAbility(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
HILOG_INFO("OnStartAbility is called");
|
||||
// only support one or two or three params
|
||||
if (info.argc != ARGC_ONE && info.argc != ARGC_TWO && info.argc != ARGC_THREE) {
|
||||
HILOG_ERROR("Not enough params");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
decltype(info.argc) unwrapArgc = 0;
|
||||
AAFwk::Want want;
|
||||
OHOS::AppExecFwk::UnwrapWant(reinterpret_cast<napi_env>(&engine),
|
||||
reinterpret_cast<napi_value>(info.argv[INDEX_ZERO]), want);
|
||||
HILOG_INFO("%{public}s bundlename:%{public}s abilityname:%{public}s",
|
||||
__func__,
|
||||
want.GetBundle().c_str(),
|
||||
want.GetElement().GetAbilityName().c_str());
|
||||
unwrapArgc++;
|
||||
|
||||
AAFwk::StartOptions startOptions;
|
||||
if (info.argc > ARGC_ONE && info.argv[INDEX_ONE]->TypeOf() == NATIVE_OBJECT) {
|
||||
HILOG_INFO("OnStartAbility start options is used.");
|
||||
AppExecFwk::UnwrapStartOptions(reinterpret_cast<napi_env>(&engine),
|
||||
reinterpret_cast<napi_value>(info.argv[INDEX_ONE]), startOptions);
|
||||
unwrapArgc++;
|
||||
}
|
||||
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[weak = context_, want, startOptions, unwrapArgc](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
HILOG_INFO("startAbility begin");
|
||||
auto context = weak.lock();
|
||||
if (!context) {
|
||||
HILOG_WARN("context is released");
|
||||
task.Reject(engine, CreateJsError(engine, ERROR_CODE_ONE, "Context is released"));
|
||||
return;
|
||||
}
|
||||
|
||||
ErrCode errcode = ERR_OK;
|
||||
(unwrapArgc == 1) ? errcode = context->StartAbility(want) :
|
||||
errcode = context->StartAbility(want, startOptions);
|
||||
if (errcode == 0) {
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
} else {
|
||||
task.Reject(engine, CreateJsError(engine, errcode, "Start Ability failed."));
|
||||
}
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc == unwrapArgc) ? nullptr : info.argv[unwrapArgc];
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue* OnStartAbilityWithAccount(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
HILOG_INFO("OnStartAbilityWithAccount is called");
|
||||
// only support two or three or four params
|
||||
if (info.argc != ARGC_TWO && info.argc != ARGC_THREE && info.argc != ARGC_FOUR) {
|
||||
HILOG_ERROR("Not enough params");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
decltype(info.argc) unwrapArgc = 0;
|
||||
AAFwk::Want want;
|
||||
OHOS::AppExecFwk::UnwrapWant(reinterpret_cast<napi_env>(&engine),
|
||||
reinterpret_cast<napi_value>(info.argv[INDEX_ZERO]), want);
|
||||
HILOG_INFO("%{public}s bundlename:%{public}s abilityname:%{public}s",
|
||||
__func__,
|
||||
want.GetBundle().c_str(),
|
||||
want.GetElement().GetAbilityName().c_str());
|
||||
unwrapArgc++;
|
||||
|
||||
int32_t accountId = 0;
|
||||
if (!OHOS::AppExecFwk::UnwrapInt32FromJS2(reinterpret_cast<napi_env>(&engine),
|
||||
reinterpret_cast<napi_value>(info.argv[INDEX_ONE]), accountId)) {
|
||||
HILOG_INFO("%{public}s called, the second parameter is invalid.", __func__);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
HILOG_INFO("%{public}d accountId:", accountId);
|
||||
unwrapArgc++;
|
||||
|
||||
AAFwk::StartOptions startOptions;
|
||||
if (info.argc > ARGC_TWO && info.argv[INDEX_TWO]->TypeOf() == NATIVE_OBJECT) {
|
||||
HILOG_INFO("OnStartAbilityWithAccount start options is used.");
|
||||
AppExecFwk::UnwrapStartOptions(reinterpret_cast<napi_env>(&engine),
|
||||
reinterpret_cast<napi_value>(info.argv[INDEX_TWO]), startOptions);
|
||||
unwrapArgc++;
|
||||
}
|
||||
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[weak = context_, want, accountId, startOptions, unwrapArgc](
|
||||
NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
HILOG_INFO("startAbility begin");
|
||||
auto context = weak.lock();
|
||||
if (!context) {
|
||||
HILOG_WARN("context is released");
|
||||
task.Reject(engine, CreateJsError(engine, ERROR_CODE_ONE, "Context is released"));
|
||||
return;
|
||||
}
|
||||
|
||||
ErrCode errcode = ERR_OK;
|
||||
(unwrapArgc == ARGC_TWO) ? errcode = context->StartAbilityWithAccount(want, accountId) :
|
||||
errcode = context->StartAbilityWithAccount(want, accountId, startOptions);
|
||||
if (errcode == 0) {
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
} else {
|
||||
task.Reject(engine, CreateJsError(engine, errcode, "Start Ability failed."));
|
||||
}
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc == unwrapArgc) ? nullptr : info.argv[unwrapArgc];
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue* OnTerminateAbility(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
HILOG_INFO("OnTerminateAbility is called");
|
||||
// only support one or zero params
|
||||
if (info.argc != ARGC_ZERO && info.argc != ARGC_ONE) {
|
||||
HILOG_ERROR("Not enough params");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[weak = context_](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
HILOG_INFO("TerminateAbility begin");
|
||||
auto context = weak.lock();
|
||||
if (!context) {
|
||||
HILOG_WARN("context is released");
|
||||
task.Reject(engine, CreateJsError(engine, ERROR_CODE_ONE, "Context is released"));
|
||||
return;
|
||||
}
|
||||
|
||||
auto errcode = context->TerminateAbility();
|
||||
if (errcode == 0) {
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
} else {
|
||||
task.Reject(engine, CreateJsError(engine, errcode, "Terminate Ability failed."));
|
||||
}
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc == ARGC_ZERO) ? nullptr : info.argv[INDEX_ZERO];
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue* OnConnectAbility(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
HILOG_INFO("OnConnectAbility is called");
|
||||
// only support two params
|
||||
if (info.argc != ARGC_TWO) {
|
||||
HILOG_ERROR("Not enough params");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
// unwrap want
|
||||
AAFwk::Want want;
|
||||
OHOS::AppExecFwk::UnwrapWant(reinterpret_cast<napi_env>(&engine),
|
||||
reinterpret_cast<napi_value>(info.argv[INDEX_ZERO]), want);
|
||||
HILOG_INFO("%{public}s bundlename:%{public}s abilityname:%{public}s",
|
||||
__func__,
|
||||
want.GetBundle().c_str(),
|
||||
want.GetElement().GetAbilityName().c_str());
|
||||
// unwarp connection
|
||||
sptr<JSWallpaperExtensionConnection> connection = new JSWallpaperExtensionConnection(engine);
|
||||
connection->SetJsConnectionObject(info.argv[1]);
|
||||
int64_t connectId = serialNumber_;
|
||||
ConnecttionKey key;
|
||||
key.id = serialNumber_;
|
||||
key.want = want;
|
||||
connects_.emplace(key, connection);
|
||||
if (serialNumber_ < INT64_MAX) {
|
||||
serialNumber_++;
|
||||
} else {
|
||||
serialNumber_ = 0;
|
||||
}
|
||||
HILOG_INFO("%{public}s not find connection, make new one:%{public}p.", __func__, connection.GetRefPtr());
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[weak = context_, want, connection, connectId](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
HILOG_INFO("OnConnectAbility begin");
|
||||
auto context = weak.lock();
|
||||
if (!context) {
|
||||
HILOG_WARN("context is released");
|
||||
task.Reject(engine, CreateJsError(engine, ERROR_CODE_ONE, "Context is released"));
|
||||
return;
|
||||
}
|
||||
HILOG_INFO("context->ConnectAbility connection:%{public}d", (int32_t)connectId);
|
||||
if (!context->ConnectAbility(want, connection)) {
|
||||
connection->CallJsFailed(ERROR_CODE_ONE);
|
||||
}
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
};
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, nullptr, nullptr, std::move(complete), &result));
|
||||
return engine.CreateNumber(connectId);
|
||||
}
|
||||
|
||||
NativeValue* OnConnectAbilityWithAccount(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
HILOG_INFO("OnConnectAbilityWithAccount is called");
|
||||
// only support three params
|
||||
if (info.argc != ARGC_THREE) {
|
||||
HILOG_ERROR("Not enough params");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
// unwrap want
|
||||
AAFwk::Want want;
|
||||
OHOS::AppExecFwk::UnwrapWant(reinterpret_cast<napi_env>(&engine),
|
||||
reinterpret_cast<napi_value>(info.argv[INDEX_ZERO]), want);
|
||||
HILOG_INFO("%{public}s bundlename:%{public}s abilityname:%{public}s",
|
||||
__func__,
|
||||
want.GetBundle().c_str(),
|
||||
want.GetElement().GetAbilityName().c_str());
|
||||
|
||||
int32_t accountId = 0;
|
||||
if (!OHOS::AppExecFwk::UnwrapInt32FromJS2(reinterpret_cast<napi_env>(&engine),
|
||||
reinterpret_cast<napi_value>(info.argv[INDEX_ONE]), accountId)) {
|
||||
HILOG_INFO("%{public}s called, the second parameter is invalid.", __func__);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
// unwarp connection
|
||||
sptr<JSWallpaperExtensionConnection> connection = new JSWallpaperExtensionConnection(engine);
|
||||
connection->SetJsConnectionObject(info.argv[1]);
|
||||
int64_t connectId = serialNumber_;
|
||||
ConnecttionKey key;
|
||||
key.id = serialNumber_;
|
||||
key.want = want;
|
||||
connects_.emplace(key, connection);
|
||||
if (serialNumber_ < INT64_MAX) {
|
||||
serialNumber_++;
|
||||
} else {
|
||||
serialNumber_ = 0;
|
||||
}
|
||||
HILOG_INFO("%{public}s not find connection, make new one:%{public}p.", __func__, connection.GetRefPtr());
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[weak = context_, want, accountId, connection, connectId](
|
||||
NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
HILOG_INFO("OnConnectAbilityWithAccount begin");
|
||||
auto context = weak.lock();
|
||||
if (!context) {
|
||||
HILOG_WARN("context is released");
|
||||
task.Reject(engine, CreateJsError(engine, ERROR_CODE_ONE, "Context is released"));
|
||||
return;
|
||||
}
|
||||
HILOG_INFO("context->ConnectAbilityWithAccount connection:%{public}d", (int32_t)connectId);
|
||||
if (!context->ConnectAbilityWithAccount(want, accountId, connection)) {
|
||||
connection->CallJsFailed(ERROR_CODE_ONE);
|
||||
}
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
};
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, nullptr, nullptr, std::move(complete), &result));
|
||||
return engine.CreateNumber(connectId);
|
||||
}
|
||||
|
||||
NativeValue* OnDisconnectAbility(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
HILOG_INFO("OnDisconnectAbility is called");
|
||||
// only support one or two params
|
||||
if (info.argc != ARGC_ONE && info.argc != ARGC_TWO) {
|
||||
HILOG_ERROR("Not enough params");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
// unwrap want
|
||||
AAFwk::Want want;
|
||||
// unwrap connectId
|
||||
int64_t connectId = -1;
|
||||
sptr<JSWallpaperExtensionConnection> connection = nullptr;
|
||||
napi_get_value_int64(reinterpret_cast<napi_env>(&engine),
|
||||
reinterpret_cast<napi_value>(info.argv[INDEX_ZERO]), &connectId);
|
||||
HILOG_INFO("OnDisconnectAbility connection:%{public}d", (int32_t)connectId);
|
||||
auto item = std::find_if(connects_.begin(), connects_.end(),
|
||||
[&connectId](
|
||||
const std::map<ConnecttionKey, sptr<JSWallpaperExtensionConnection>>::value_type &obj) {
|
||||
return connectId == obj.first.id;
|
||||
});
|
||||
if (item != connects_.end()) {
|
||||
// match id
|
||||
want = item->first.want;
|
||||
connection = item->second;
|
||||
HILOG_INFO("%{public}s find conn ability:%{public}p exist", __func__, item->second.GetRefPtr());
|
||||
} else {
|
||||
HILOG_INFO("%{public}s not find conn exist.", __func__);
|
||||
}
|
||||
// begin disconnect
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[weak = context_, want, connection](
|
||||
NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
HILOG_INFO("OnDisconnectAbility begin");
|
||||
auto context = weak.lock();
|
||||
if (!context) {
|
||||
HILOG_WARN("context is released");
|
||||
task.Reject(engine, CreateJsError(engine, ERROR_CODE_ONE, "Context is released"));
|
||||
return;
|
||||
}
|
||||
if (connection == nullptr) {
|
||||
HILOG_WARN("connection nullptr");
|
||||
task.Reject(engine, CreateJsError(engine, ERROR_CODE_TWO, "not found connection"));
|
||||
return;
|
||||
}
|
||||
HILOG_INFO("context->DisconnectAbility");
|
||||
auto errcode = context->DisconnectAbility(want, connection);
|
||||
errcode == 0 ? task.Resolve(engine, engine.CreateUndefined()) :
|
||||
task.Reject(engine, CreateJsError(engine, errcode, "Disconnect Ability failed."));
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc == ARGC_ONE) ? nullptr : info.argv[INDEX_ONE];
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
NativeValue* CreateJsMetadata(NativeEngine& engine, const AppExecFwk::Metadata &Info)
|
||||
{
|
||||
HILOG_INFO("CreateJsMetadata");
|
||||
NativeValue* objValue = engine.CreateObject();
|
||||
NativeObject* object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
|
||||
object->SetProperty("name", CreateJsValue(engine, Info.name));
|
||||
object->SetProperty("value", CreateJsValue(engine, Info.value));
|
||||
object->SetProperty("resource", CreateJsValue(engine, Info.resource));
|
||||
return objValue;
|
||||
}
|
||||
|
||||
NativeValue* CreateJsMetadataArray(NativeEngine& engine, const std::vector<AppExecFwk::Metadata> &info)
|
||||
{
|
||||
HILOG_INFO("CreateJsMetadataArray");
|
||||
NativeValue* arrayValue = engine.CreateArray(info.size());
|
||||
NativeArray* array = ConvertNativeValueTo<NativeArray>(arrayValue);
|
||||
uint32_t index = 0;
|
||||
for (const auto& item : info) {
|
||||
array->SetElement(index++, CreateJsMetadata(engine, item));
|
||||
}
|
||||
return arrayValue;
|
||||
}
|
||||
|
||||
NativeValue* CreateJsExtensionAbilityInfo(NativeEngine& engine, const AppExecFwk::ExtensionAbilityInfo& info)
|
||||
{
|
||||
HILOG_INFO("CreateJsExtensionAbilityInfo");
|
||||
NativeValue* objValue = engine.CreateObject();
|
||||
NativeObject* object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
object->SetProperty("bundleName", CreateJsValue(engine, info.bundleName));
|
||||
object->SetProperty("moduleName", CreateJsValue(engine, info.moduleName));
|
||||
object->SetProperty("name", CreateJsValue(engine, info.name));
|
||||
object->SetProperty("labelId", CreateJsValue(engine, info.labelId));
|
||||
object->SetProperty("descriptionId", CreateJsValue(engine, info.descriptionId));
|
||||
object->SetProperty("iconId", CreateJsValue(engine, info.iconId));
|
||||
object->SetProperty("isVisible", CreateJsValue(engine, info.visible));
|
||||
object->SetProperty("extensionAbilityType", CreateJsValue(engine, info.type));
|
||||
NativeValue *permissionArrayValue = engine.CreateArray(info.permissions.size());
|
||||
NativeArray *permissionArray = ConvertNativeValueTo<NativeArray>(permissionArrayValue);
|
||||
if (permissionArray != nullptr) {
|
||||
int index = 0;
|
||||
for (auto permission : info.permissions) {
|
||||
permissionArray->SetElement(index++, CreateJsValue(engine, permission));
|
||||
}
|
||||
}
|
||||
object->SetProperty("permissions", permissionArrayValue);
|
||||
object->SetProperty("applicationInfo", CreateJsApplicationInfo(engine, info.applicationInfo));
|
||||
object->SetProperty("metadata", CreateJsMetadataArray(engine, info.metadata));
|
||||
object->SetProperty("enabled", CreateJsValue(engine, info.enabled));
|
||||
object->SetProperty("readPermission", CreateJsValue(engine, info.readPermission));
|
||||
object->SetProperty("writePermission", CreateJsValue(engine, info.writePermission));
|
||||
return objValue;
|
||||
}
|
||||
|
||||
NativeValue* CreateJsWallpaperExtensionContext(NativeEngine& engine, std::shared_ptr<WallpaperExtensionContext> context)
|
||||
{
|
||||
HILOG_INFO("CreateJsWallpaperExtensionContext begin");
|
||||
NativeValue* objValue = CreateJsExtensionContext(engine, context);
|
||||
NativeObject* object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
|
||||
std::unique_ptr<JsWallpaperExtensionContext> jsContext = std::make_unique<JsWallpaperExtensionContext>(context);
|
||||
object->SetNativePointer(jsContext.release(), JsWallpaperExtensionContext::Finalizer, nullptr);
|
||||
|
||||
// make handler
|
||||
handler_ = std::make_shared<AppExecFwk::EventHandler>(AppExecFwk::EventRunner::GetMainEventRunner());
|
||||
|
||||
BindNativeFunction(engine, *object, "startAbility", JsWallpaperExtensionContext::StartAbility);
|
||||
BindNativeFunction(engine, *object, "terminateSelf", JsWallpaperExtensionContext::TerminateAbility);
|
||||
BindNativeFunction(engine, *object, "connectAbility", JsWallpaperExtensionContext::ConnectAbility);
|
||||
BindNativeFunction(engine, *object, "disconnectAbility", JsWallpaperExtensionContext::DisconnectAbility);
|
||||
BindNativeFunction(
|
||||
engine, *object, "startAbilityWithAccount", JsWallpaperExtensionContext::StartAbilityWithAccount);
|
||||
BindNativeFunction(
|
||||
engine, *object, "connectAbilityWithAccount", JsWallpaperExtensionContext::ConnectAbilityWithAccount);
|
||||
|
||||
if (context) {
|
||||
HILOG_INFO("Set ExtensionAbilityInfo Property");
|
||||
auto abilityInfo = context->GetAbilityInfo();
|
||||
auto hapModuleInfo = context->GetHapModuleInfo();
|
||||
if (abilityInfo && hapModuleInfo) {
|
||||
auto isExist = [&abilityInfo](const AppExecFwk::ExtensionAbilityInfo &info) {
|
||||
HILOG_INFO("%{public}s, %{public}s", info.bundleName.c_str(), info.name.c_str());
|
||||
return info.bundleName == abilityInfo->bundleName && info.name == abilityInfo->name;
|
||||
};
|
||||
auto infoIter = std::find_if(
|
||||
hapModuleInfo->extensionInfos.begin(), hapModuleInfo->extensionInfos.end(), isExist);
|
||||
if (infoIter == hapModuleInfo->extensionInfos.end()) {
|
||||
HILOG_INFO("Get target fail.");
|
||||
return objValue;
|
||||
}
|
||||
object->SetProperty("extensionAbilityInfo", CreateJsExtensionAbilityInfo(engine, *infoIter));
|
||||
}
|
||||
}
|
||||
|
||||
return objValue;
|
||||
}
|
||||
|
||||
JSWallpaperExtensionConnection::JSWallpaperExtensionConnection(NativeEngine& engine) : engine_(engine) {}
|
||||
|
||||
JSWallpaperExtensionConnection::~JSWallpaperExtensionConnection() = default;
|
||||
|
||||
void JSWallpaperExtensionConnection::OnAbilityConnectDone(const AppExecFwk::ElementName &element,
|
||||
const sptr<IRemoteObject> &remoteObject, int resultCode)
|
||||
{
|
||||
HILOG_INFO("OnAbilityConnectDone begin, resultCode:%{public}d", resultCode);
|
||||
if (handler_ == nullptr) {
|
||||
HILOG_INFO("handler_ nullptr");
|
||||
return;
|
||||
}
|
||||
wptr<JSWallpaperExtensionConnection> connection = this;
|
||||
auto task = [connection, element, remoteObject, resultCode]() {
|
||||
sptr<JSWallpaperExtensionConnection> connectionSptr = connection.promote();
|
||||
if (!connectionSptr) {
|
||||
HILOG_INFO("connectionSptr nullptr");
|
||||
return;
|
||||
}
|
||||
connectionSptr->HandleOnAbilityConnectDone(element, remoteObject, resultCode);
|
||||
};
|
||||
handler_->PostTask(task, "OnAbilityConnectDone");
|
||||
}
|
||||
|
||||
void JSWallpaperExtensionConnection::HandleOnAbilityConnectDone(const AppExecFwk::ElementName &element,
|
||||
const sptr<IRemoteObject> &remoteObject, int resultCode)
|
||||
{
|
||||
HILOG_INFO("HandleOnAbilityConnectDone begin, resultCode:%{public}d", resultCode);
|
||||
// wrap ElementName
|
||||
napi_value napiElementName = OHOS::AppExecFwk::WrapElementName(reinterpret_cast<napi_env>(&engine_), element);
|
||||
NativeValue* nativeElementName = reinterpret_cast<NativeValue*>(napiElementName);
|
||||
|
||||
// wrap RemoteObject
|
||||
HILOG_INFO("OnAbilityConnectDone begin NAPI_ohos_rpc_CreateJsRemoteObject");
|
||||
napi_value napiRemoteObject = NAPI_ohos_rpc_CreateJsRemoteObject(
|
||||
reinterpret_cast<napi_env>(&engine_), remoteObject);
|
||||
NativeValue* nativeRemoteObject = reinterpret_cast<NativeValue*>(napiRemoteObject);
|
||||
NativeValue* argv[] = {nativeElementName, nativeRemoteObject};
|
||||
if (jsConnectionObject_ == nullptr) {
|
||||
HILOG_ERROR("jsConnectionObject_ nullptr");
|
||||
return;
|
||||
}
|
||||
NativeValue* value = jsConnectionObject_->Get();
|
||||
NativeObject* obj = ConvertNativeValueTo<NativeObject>(value);
|
||||
if (obj == nullptr) {
|
||||
HILOG_ERROR("Failed to get object");
|
||||
return;
|
||||
}
|
||||
NativeValue* methodOnConnect = obj->GetProperty("onConnect");
|
||||
if (methodOnConnect == nullptr) {
|
||||
HILOG_ERROR("Failed to get onConnect from object");
|
||||
return;
|
||||
}
|
||||
HILOG_INFO("JSWallpaperExtensionConnection::CallFunction onConnect, success");
|
||||
engine_.CallFunction(value, methodOnConnect, argv, ARGC_TWO);
|
||||
HILOG_INFO("OnAbilityConnectDone end");
|
||||
}
|
||||
|
||||
void JSWallpaperExtensionConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode)
|
||||
{
|
||||
HILOG_INFO("OnAbilityDisconnectDone begin, resultCode:%{public}d", resultCode);
|
||||
if (handler_ == nullptr) {
|
||||
HILOG_INFO("handler_ nullptr");
|
||||
return;
|
||||
}
|
||||
wptr<JSWallpaperExtensionConnection> connection = this;
|
||||
auto task = [connection, element, resultCode]() {
|
||||
sptr<JSWallpaperExtensionConnection> connectionSptr = connection.promote();
|
||||
if (!connectionSptr) {
|
||||
HILOG_INFO("connectionSptr nullptr");
|
||||
return;
|
||||
}
|
||||
connectionSptr->HandleOnAbilityDisconnectDone(element, resultCode);
|
||||
};
|
||||
handler_->PostTask(task, "OnAbilityDisconnectDone");
|
||||
}
|
||||
|
||||
void JSWallpaperExtensionConnection::HandleOnAbilityDisconnectDone(const AppExecFwk::ElementName &element,
|
||||
int resultCode)
|
||||
{
|
||||
HILOG_INFO("HandleOnAbilityDisconnectDone begin, resultCode:%{public}d", resultCode);
|
||||
napi_value napiElementName = OHOS::AppExecFwk::WrapElementName(reinterpret_cast<napi_env>(&engine_), element);
|
||||
NativeValue* nativeElementName = reinterpret_cast<NativeValue*>(napiElementName);
|
||||
NativeValue* argv[] = {nativeElementName};
|
||||
if (jsConnectionObject_ == nullptr) {
|
||||
HILOG_ERROR("jsConnectionObject_ nullptr");
|
||||
return;
|
||||
}
|
||||
NativeValue* value = jsConnectionObject_->Get();
|
||||
NativeObject* obj = ConvertNativeValueTo<NativeObject>(value);
|
||||
if (obj == nullptr) {
|
||||
HILOG_ERROR("Failed to get object");
|
||||
return;
|
||||
}
|
||||
|
||||
NativeValue* method = obj->GetProperty("onDisconnect");
|
||||
if (method == nullptr) {
|
||||
HILOG_ERROR("Failed to get onDisconnect from object");
|
||||
return;
|
||||
}
|
||||
|
||||
// release connect
|
||||
HILOG_INFO("OnAbilityDisconnectDone connects_.size:%{public}zu", connects_.size());
|
||||
std::string bundleName = element.GetBundleName();
|
||||
std::string abilityName = element.GetAbilityName();
|
||||
auto item = std::find_if(connects_.begin(),
|
||||
connects_.end(),
|
||||
[bundleName, abilityName](
|
||||
const std::map<ConnecttionKey, sptr<JSWallpaperExtensionConnection>>::value_type &obj) {
|
||||
return (bundleName == obj.first.want.GetBundle()) &&
|
||||
(abilityName == obj.first.want.GetElement().GetAbilityName());
|
||||
});
|
||||
if (item != connects_.end()) {
|
||||
// match bundlename && abilityname
|
||||
connects_.erase(item);
|
||||
HILOG_INFO("OnAbilityDisconnectDone erase connects_.size:%{public}zu", connects_.size());
|
||||
}
|
||||
HILOG_INFO("OnAbilityDisconnectDone CallFunction success");
|
||||
engine_.CallFunction(value, method, argv, ARGC_ONE);
|
||||
}
|
||||
|
||||
void JSWallpaperExtensionConnection::SetJsConnectionObject(NativeValue* jsConnectionObject)
|
||||
{
|
||||
jsConnectionObject_ = std::unique_ptr<NativeReference>(engine_.CreateReference(jsConnectionObject, 1));
|
||||
}
|
||||
|
||||
void JSWallpaperExtensionConnection::CallJsFailed(int32_t errorCode)
|
||||
{
|
||||
HILOG_INFO("CallJsFailed begin");
|
||||
if (jsConnectionObject_ == nullptr) {
|
||||
HILOG_ERROR("jsConnectionObject_ nullptr");
|
||||
return;
|
||||
}
|
||||
NativeValue* value = jsConnectionObject_->Get();
|
||||
NativeObject* obj = ConvertNativeValueTo<NativeObject>(value);
|
||||
if (obj == nullptr) {
|
||||
HILOG_ERROR("Failed to get object");
|
||||
return;
|
||||
}
|
||||
|
||||
NativeValue* method = obj->GetProperty("onFailed");
|
||||
if (method == nullptr) {
|
||||
HILOG_ERROR("Failed to get onFailed from object");
|
||||
return;
|
||||
}
|
||||
NativeValue* argv[] = {engine_.CreateNumber(errorCode)};
|
||||
HILOG_INFO("CallJsFailed CallFunction success");
|
||||
engine_.CallFunction(value, method, argv, ARGC_ONE);
|
||||
HILOG_INFO("CallJsFailed end");
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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 "wallpaper_extension.h"
|
||||
|
||||
#include "ability_loader.h"
|
||||
#include "connection_manager.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "js_wallpaper_extension.h"
|
||||
#include "runtime.h"
|
||||
#include "wallpaper_extension_context.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
using namespace OHOS::AppExecFwk;
|
||||
WallpaperExtension* WallpaperExtension::Create(const std::unique_ptr<Runtime>& runtime)
|
||||
{
|
||||
HILOG_INFO("jws WallpaperExtension::Create runtime");
|
||||
if (!runtime) {
|
||||
return new WallpaperExtension();
|
||||
}
|
||||
HILOG_INFO("jws WallpaperExtension::Create runtime");
|
||||
switch (runtime->GetLanguage()) {
|
||||
case Runtime::Language::JS:
|
||||
return JsWallpaperExtension::Create(runtime);
|
||||
|
||||
default:
|
||||
return new WallpaperExtension();
|
||||
}
|
||||
}
|
||||
|
||||
void WallpaperExtension::Init(const std::shared_ptr<AbilityLocalRecord> &record,
|
||||
const std::shared_ptr<OHOSApplication> &application,
|
||||
std::shared_ptr<AbilityHandler> &handler,
|
||||
const sptr<IRemoteObject> &token)
|
||||
{ HILOG_INFO("jws WallpaperExtension begin init context");
|
||||
ExtensionBase<WallpaperExtensionContext>::Init(record, application, handler, token);
|
||||
HILOG_INFO("WallpaperExtension begin init context");
|
||||
}
|
||||
|
||||
std::shared_ptr<WallpaperExtensionContext> WallpaperExtension::CreateAndInitContext(
|
||||
const std::shared_ptr<AbilityLocalRecord> &record,
|
||||
const std::shared_ptr<OHOSApplication> &application,
|
||||
std::shared_ptr<AbilityHandler> &handler,
|
||||
const sptr<IRemoteObject> &token)
|
||||
{
|
||||
HILOG_INFO("jws WallpaperExtension begin init context");
|
||||
std::shared_ptr<WallpaperExtensionContext> context =
|
||||
ExtensionBase<WallpaperExtensionContext>::CreateAndInitContext(record, application, handler, token);
|
||||
if (context == nullptr) {
|
||||
HILOG_ERROR("WallpaperExtension::CreateAndInitContext context is nullptr");
|
||||
return context;
|
||||
}
|
||||
return context;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 "wallpaper_extension_context.h"
|
||||
|
||||
#include "ability_connection.h"
|
||||
#include "ability_manager_client.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
const size_t WallpaperExtensionContext::CONTEXT_TYPE_ID(std::hash<const char*> {} ("WallpaperExtensionContext"));
|
||||
int WallpaperExtensionContext::ILLEGAL_REQUEST_CODE(-1);
|
||||
|
||||
ErrCode WallpaperExtensionContext::StartAbility(const AAFwk::Want &want) const
|
||||
{
|
||||
HILOG_DEBUG("%{public}s begin.", __func__);
|
||||
ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want, token_, ILLEGAL_REQUEST_CODE);
|
||||
HILOG_DEBUG("%{public}s. End calling StartAbility. ret=%{public}d", __func__, err);
|
||||
if (err != ERR_OK) {
|
||||
HILOG_ERROR("WallpaperContext::StartAbility is failed %{public}d", err);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
ErrCode WallpaperExtensionContext::StartAbility(const AAFwk::Want &want, const AAFwk::StartOptions &startOptions) const
|
||||
{
|
||||
HILOG_DEBUG("%{public}s begin.", __func__);
|
||||
ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want, startOptions, token_,
|
||||
ILLEGAL_REQUEST_CODE);
|
||||
HILOG_DEBUG("%{public}s. End calling StartAbility. ret=%{public}d", __func__, err);
|
||||
if (err != ERR_OK) {
|
||||
HILOG_ERROR("WallpaperContext::StartAbility is failed %{public}d", err);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
bool WallpaperExtensionContext::ConnectAbility(
|
||||
const AAFwk::Want &want, const sptr<AbilityConnectCallback> &connectCallback) const
|
||||
{
|
||||
HILOG_INFO("%{public}s begin.", __func__);
|
||||
ErrCode ret =
|
||||
ConnectionManager::GetInstance().ConnectAbility(token_, want, connectCallback);
|
||||
HILOG_INFO("WallpaperExtensionContext::ConnectAbility ErrorCode = %{public}d", ret);
|
||||
return ret == ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode WallpaperExtensionContext::StartAbilityWithAccount(const AAFwk::Want &want, int accountId) const
|
||||
{
|
||||
HILOG_DEBUG("%{public}s begin.", __func__);
|
||||
HILOG_INFO("%{public}d accountId:", accountId);
|
||||
ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(
|
||||
want, token_, ILLEGAL_REQUEST_CODE, accountId);
|
||||
HILOG_DEBUG("%{public}s. End calling StartAbilityWithAccount. ret=%{public}d", __func__, err);
|
||||
if (err != ERR_OK) {
|
||||
HILOG_ERROR("WallpaperContext::StartAbilityWithAccount is failed %{public}d", err);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
ErrCode WallpaperExtensionContext::StartAbilityWithAccount(
|
||||
const AAFwk::Want &want, int accountId, const AAFwk::StartOptions &startOptions) const
|
||||
{
|
||||
HILOG_DEBUG("%{public}s begin.", __func__);
|
||||
ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want, startOptions, token_,
|
||||
ILLEGAL_REQUEST_CODE, accountId);
|
||||
HILOG_DEBUG("%{public}s. End calling StartAbilityWithAccount. ret=%{public}d", __func__, err);
|
||||
if (err != ERR_OK) {
|
||||
HILOG_ERROR("WallpaperContext::StartAbilityWithAccount is failed %{public}d", err);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
bool WallpaperExtensionContext::ConnectAbilityWithAccount(
|
||||
const AAFwk::Want &want, int accountId, const sptr<AbilityConnectCallback> &connectCallback) const
|
||||
{
|
||||
HILOG_INFO("%{public}s begin.", __func__);
|
||||
ErrCode ret =
|
||||
ConnectionManager::GetInstance().ConnectAbilityWithAccount(token_, want, accountId, connectCallback);
|
||||
HILOG_INFO("WallpaperExtensionContext::ConnectAbilityWithAccount ErrorCode = %{public}d", ret);
|
||||
return ret == ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode WallpaperExtensionContext::DisconnectAbility(
|
||||
const AAFwk::Want &want, const sptr<AbilityConnectCallback> &connectCallback) const
|
||||
{
|
||||
HILOG_INFO("%{public}s begin.", __func__);
|
||||
ErrCode ret =
|
||||
ConnectionManager::GetInstance().DisconnectAbility(token_, want.GetElement(), connectCallback);
|
||||
if (ret != ERR_OK) {
|
||||
HILOG_ERROR("%{public}s end DisconnectAbility error, ret=%{public}d", __func__, ret);
|
||||
}
|
||||
HILOG_INFO("%{public}s end DisconnectAbility", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ErrCode WallpaperExtensionContext::TerminateAbility()
|
||||
{
|
||||
HILOG_INFO("%{public}s begin.", __func__);
|
||||
ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->TerminateAbility(token_, -1, nullptr);
|
||||
if (err != ERR_OK) {
|
||||
HILOG_ERROR("WallpaperExtensionContext::TerminateAbility is failed %{public}d", err);
|
||||
}
|
||||
HILOG_INFO("%{public}s end.", __func__);
|
||||
return err;
|
||||
}
|
||||
|
||||
AppExecFwk::AbilityType WallpaperExtensionContext::GetAbilityInfoType() const
|
||||
{
|
||||
std::shared_ptr<AppExecFwk::AbilityInfo> info = GetAbilityInfo();
|
||||
if (info == nullptr) {
|
||||
HILOG_ERROR("WallpaperContext::GetAbilityInfoType info == nullptr");
|
||||
return AppExecFwk::AbilityType::UNKNOWN;
|
||||
}
|
||||
|
||||
return info->type;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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 "wallpaper_extension_module_loader.h"
|
||||
#include "wallpaper_extension.h"
|
||||
|
||||
namespace OHOS::AbilityRuntime {
|
||||
WallpaperExtensionModuleLoader::WallpaperExtensionModuleLoader() = default;
|
||||
WallpaperExtensionModuleLoader::~WallpaperExtensionModuleLoader() = default;
|
||||
|
||||
Extension *WallpaperExtensionModuleLoader::Create(const std::unique_ptr<Runtime>& runtime) const
|
||||
{
|
||||
HILOG_INFO("jws WallpaperExtension::Create runtime");
|
||||
return WallpaperExtension::Create(runtime);
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default"))) void* OHOS_EXTENSION_GetExtensionModule()
|
||||
{
|
||||
return &WallpaperExtensionModuleLoader::GetInstance();
|
||||
}
|
||||
} // namespace OHOS::AbilityRuntime
|
||||
+145
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 {AsyncCallback} from './basic';
|
||||
import image from './@ohos.multimedia.image'
|
||||
|
||||
/**
|
||||
* System wallpaper
|
||||
* @sysCap SystemCapability.Miscservices.Wallpaper
|
||||
* @devices phone, tablet, tv, wearable, car
|
||||
* @import import wallpaper from '@ohos.wallpaper';
|
||||
* @since 7
|
||||
*/
|
||||
declare namespace wallpaper {
|
||||
enum WallpaperType {
|
||||
/**
|
||||
* Indicates the home screen wallpaper.
|
||||
*/
|
||||
WALLPAPER_SYSTEM,
|
||||
/**
|
||||
* Indicates the lock screen wallpaper.
|
||||
*/
|
||||
WALLPAPER_LOCKSCREEN
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains the wallpaper colors for the wallpaper of the specified type.
|
||||
* @param wallpaperType Indicates the wallpaper type.
|
||||
* @return RgbaColor type of array callback function
|
||||
*/
|
||||
function getColors(wallpaperType: WallpaperType, callback: AsyncCallback<Array<RgbaColor>>): void;
|
||||
function getColors(wallpaperType: WallpaperType): Promise<Array<RgbaColor>>;
|
||||
|
||||
/**
|
||||
* Obtains the ID of the wallpaper of the specified type.
|
||||
* @param wallpaperType Indicates the wallpaper type.
|
||||
* @return an integer greater than or equal to {@code 0} representing the wallpaper ID
|
||||
* if the specified type of wallpaper has been set; returns {@code -1} otherwise.
|
||||
* The return value is an integer ranging from -1 to 2^31 - 1.
|
||||
*/
|
||||
function getId(wallpaperType: WallpaperType, callback: AsyncCallback<number>): void;
|
||||
function getId(wallpaperType: WallpaperType): Promise<number>;
|
||||
|
||||
/**
|
||||
* Obtains the minimum height of the wallpaper.
|
||||
* @return the minimum height, in pixels; returns {@code 0} if no wallpaper has been set.
|
||||
*/
|
||||
function getMinHeight(callback: AsyncCallback<number>): void;
|
||||
function getMinHeight(): Promise<number>;
|
||||
|
||||
/**
|
||||
* Obtains the minimum width of the wallpaper.
|
||||
* @return the minimum width, in pixels; returns {@code 0} if no wallpaper has been set.
|
||||
*/
|
||||
function getMinWidth(callback: AsyncCallback<number>): void;
|
||||
function getMinWidth(): Promise<number>;
|
||||
|
||||
/**
|
||||
* Checks whether to allow the application to change the wallpaper for the current user.
|
||||
* @return true if the application is allowed to set a wallpaper for the current user;
|
||||
*/
|
||||
function isChangePermitted(callback: AsyncCallback<boolean>): void;
|
||||
function isChangePermitted(): Promise<boolean>;
|
||||
|
||||
/**
|
||||
* Checks whether a user is allowed to set wallpapers.
|
||||
* @return true if a user is allowed to set wallpapers; returns false otherwise.
|
||||
*/
|
||||
function isOperationAllowed(callback: AsyncCallback<boolean>): void;
|
||||
function isOperationAllowed(): Promise<boolean>;
|
||||
|
||||
/**
|
||||
* Removes a wallpaper of the specified type and restores the default one.
|
||||
* @param wallpaperType Indicates the wallpaper type.
|
||||
* @permission ohos.permission.SET_WALLPAPER
|
||||
*/
|
||||
function reset(wallpaperType: WallpaperType, callback: AsyncCallback<void>): void;
|
||||
function reset(wallpaperType: WallpaperType): Promise<void>;
|
||||
|
||||
/**
|
||||
* Sets a wallpaper of the specified type based on the uri path from a JPEG or PNG file or the pixel map of a PNG file.
|
||||
* @param source Indicates the uri path from a JPEG or PNG file or the pixel map of the PNG file.
|
||||
* @param wallpaperType Indicates the wallpaper type.
|
||||
* @permission ohos.permission.SET_WALLPAPER
|
||||
*/
|
||||
function setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType, callback: AsyncCallback<void>): void;
|
||||
function setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType): Promise<void>;
|
||||
|
||||
/**
|
||||
* Obtains the default pixel map of a wallpaper of the specified type.
|
||||
* @param wallpaperType Indicates the wallpaper type.
|
||||
* @return the default pixel map.
|
||||
* @permission ohos.permission.GET_WALLPAPER
|
||||
* @permission ohos.permission.READ_USER_STORAGE
|
||||
* @systemapi Hide this for inner system use.
|
||||
*/
|
||||
function getPixelMap(wallpaperType: WallpaperType, callback: AsyncCallback<image.PixelMap>): void;
|
||||
function getPixelMap(wallpaperType: WallpaperType): Promise<image.PixelMap>;
|
||||
|
||||
/**
|
||||
* Registers a listener for wallpaper color changes to receive notifications about the changes.
|
||||
* @param type The incoming colorChange table open receiver pick a color change wallpaper wallpaper color changes
|
||||
* @param callback Provides dominant colors of the wallpaper.
|
||||
*/
|
||||
function on(type: 'colorChange', callback: (colors: Array<RgbaColor>, wallpaperType: WallpaperType) => void): void;
|
||||
|
||||
/**
|
||||
* Unregisters a listener for wallpaper color changes.
|
||||
* @param type Incoming 'colorChange' table delete receiver to pick up a color change wallpaper wallpaper color changes
|
||||
* @param callback Provides dominant colors of the wallpaper.
|
||||
*/
|
||||
function off(type: 'colorChange', callback?: (colors: Array<RgbaColor>, wallpaperType: WallpaperType) => void): void;
|
||||
|
||||
interface RgbaColor {
|
||||
/**
|
||||
* Said the red value, the range is 0 to 255.
|
||||
*/
|
||||
red: number;
|
||||
/**
|
||||
* Said the green value, the range is 0 to 255.
|
||||
*/
|
||||
green: number;
|
||||
/**
|
||||
* Said the blue value, the range is 0 to 255.
|
||||
*/
|
||||
blue: number;
|
||||
/**
|
||||
* Said the alpha value, the range is 0 to 255.
|
||||
*/
|
||||
alpha: number;
|
||||
}
|
||||
}
|
||||
|
||||
export default wallpaper;
|
||||
@@ -0,0 +1,65 @@
|
||||
# Copyright (c) 2022 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")
|
||||
import("//base/miscservices/wallpaper/wallpaper.gni")
|
||||
|
||||
ohos_shared_library("wallpaperability") {
|
||||
include_dirs = [
|
||||
"//foundation/ace/napi/interfaces/kits",
|
||||
"//third_party/node/src",
|
||||
"//foundation/aafwk/standard/services/common/include",
|
||||
"//utils/system/safwk/native/include",
|
||||
"//base/miscservices/wallpaper/interfaces/kits/napi",
|
||||
"//base/miscservices/wallpaper/frameworks/innerkitsimpl/wallpaper_manager/include",
|
||||
"//base/miscservices/wallpaper/utils/include",
|
||||
"//third_party/libuv/include",
|
||||
"//utils/native/base/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"napi_wallpaper_ability.cpp",
|
||||
"native_module.cpp",
|
||||
"async_call.cpp",
|
||||
"wallpaper_js_util.cpp",
|
||||
]
|
||||
ldflags = [ "-Wl,-rpath=/system/lib/module/multimedia/" ]
|
||||
deps = [
|
||||
"//base/miscservices/wallpaper/frameworks/innerkitsimpl/wallpaper_manager:wallpapermanager",
|
||||
"//foundation/ace/napi:ace_napi",
|
||||
"//foundation/appexecfwk/standard/common:libappexecfwk_common",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler",
|
||||
"//foundation/aafwk/standard/frameworks/kits/appkit:appkit_native",
|
||||
"//foundation/appexecfwk/standard/libs/libeventhandler:libeventhandler_target",
|
||||
"//foundation/aafwk/standard/services/appmgr:libams",
|
||||
"//foundation/distributeddatamgr/distributeddatamgr/interfaces/innerkits/distributeddata:distributeddata_inner",
|
||||
"//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
"//foundation/multimedia/image_standard/interfaces/innerkits:image",
|
||||
"//foundation/multimedia/image_standard/interfaces/innerkits:image_native",
|
||||
"//utils/native/base:utils",
|
||||
"//third_party/libuv:uv_static",
|
||||
"${utils_path}:wallpaper_utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
|
||||
relative_install_dir = "module/app"
|
||||
subsystem_name = "miscservices"
|
||||
part_name = "wallpaper_native"
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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.
|
||||
*/
|
||||
#define LOG_TAG "AsyncCall"
|
||||
#include "async_call.h"
|
||||
#include <utility>
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS::WallpaperNAPI {
|
||||
AsyncCall::AsyncCall(napi_env env, napi_callback_info info, std::shared_ptr<Context> context, size_t pos)
|
||||
: env_(env)
|
||||
{
|
||||
context_ = new AsyncContext();
|
||||
size_t argc = 6;
|
||||
napi_value self = nullptr;
|
||||
napi_value argv[6] = {nullptr};
|
||||
NAPI_CALL_RETURN_VOID(env, napi_get_cb_info(env, info, &argc, argv, &self, nullptr));
|
||||
NAPI_ASSERT_BASE(env, pos <= argc, " Invalid Args!", NAPI_RETVAL_NOTHING);
|
||||
pos = ((pos == ASYNC_DEFAULT_POS) ? (argc - 1) : pos);
|
||||
if (pos >= 0 && pos < argc) {
|
||||
napi_valuetype valueType = napi_undefined;
|
||||
napi_typeof(env, argv[pos], &valueType);
|
||||
if (valueType == napi_function) {
|
||||
napi_create_reference(env, argv[pos], 1, &context_->callback);
|
||||
argc = pos;
|
||||
}
|
||||
}
|
||||
NAPI_CALL_RETURN_VOID(env, (*context)(env, argc, argv, self));
|
||||
context_->ctx = std::move(context);
|
||||
napi_create_reference(env, self, 1, &context_->self);
|
||||
}
|
||||
|
||||
AsyncCall::~AsyncCall()
|
||||
{
|
||||
if (context_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
DeleteContext(env_, context_);
|
||||
}
|
||||
|
||||
napi_value AsyncCall::Call(napi_env env, Context::ExecAction exec)
|
||||
{
|
||||
if (context_ == nullptr) {
|
||||
HILOG_DEBUG("context_ is null");
|
||||
return nullptr;
|
||||
}
|
||||
if (context_->ctx == nullptr) {
|
||||
HILOG_DEBUG("context_->ctx is null");
|
||||
return nullptr;
|
||||
}
|
||||
HILOG_DEBUG("async call exec");
|
||||
context_->ctx->exec_ = std::move(exec);
|
||||
napi_value promise = nullptr;
|
||||
if (context_->callback == nullptr) {
|
||||
napi_create_promise(env, &context_->defer, &promise);
|
||||
} else {
|
||||
napi_get_undefined(env, &promise);
|
||||
}
|
||||
napi_async_work work = context_->work;
|
||||
napi_value resource = nullptr;
|
||||
napi_create_string_utf8(env, "AsyncCall", NAPI_AUTO_LENGTH, &resource);
|
||||
napi_create_async_work(env, nullptr, resource, AsyncCall::OnExecute, AsyncCall::OnComplete, context_, &work);
|
||||
context_->work = work;
|
||||
context_ = nullptr;
|
||||
napi_queue_async_work(env, work);
|
||||
HILOG_DEBUG("async call exec");
|
||||
return promise;
|
||||
}
|
||||
|
||||
napi_value AsyncCall::SyncCall(napi_env env, AsyncCall::Context::ExecAction exec)
|
||||
{
|
||||
if ((context_ == nullptr) || (context_->ctx == nullptr)) {
|
||||
HILOG_DEBUG("context_ or context_->ctx is null");
|
||||
return nullptr;
|
||||
}
|
||||
context_->ctx->exec_ = std::move(exec);
|
||||
napi_value promise = nullptr;
|
||||
if (context_->callback == nullptr) {
|
||||
napi_create_promise(env, &context_->defer, &promise);
|
||||
} else {
|
||||
napi_get_undefined(env, &promise);
|
||||
}
|
||||
AsyncCall::OnExecute(env, context_);
|
||||
AsyncCall::OnComplete(env, napi_ok, context_);
|
||||
return promise;
|
||||
}
|
||||
|
||||
void AsyncCall::OnExecute(napi_env env, void *data)
|
||||
{
|
||||
HILOG_DEBUG("run the async runnable");
|
||||
AsyncContext *context = reinterpret_cast<AsyncContext *>(data);
|
||||
context->ctx->Exec();
|
||||
}
|
||||
|
||||
void AsyncCall::OnComplete(napi_env env, napi_status status, void *data)
|
||||
{
|
||||
HILOG_DEBUG("run the js callback function");
|
||||
AsyncContext *context = reinterpret_cast<AsyncContext *>(data);
|
||||
napi_value output = nullptr;
|
||||
napi_status runStatus = (*context->ctx)(env, &output);
|
||||
napi_value result[ARG_BUTT] = { 0 };
|
||||
HILOG_DEBUG("run the js callback function:status[%{public}d]runStatus[%{public}d]", status, runStatus);
|
||||
if (status == napi_ok && runStatus == napi_ok) {
|
||||
napi_get_undefined(env, &result[ARG_ERROR]);
|
||||
if (output != nullptr) {
|
||||
HILOG_DEBUG("AsyncCall::OnComplete output != nullptr");
|
||||
result[ARG_DATA] = output;
|
||||
} else {
|
||||
HILOG_DEBUG("AsyncCall::OnComplete output == nullptr");
|
||||
napi_get_undefined(env, &result[ARG_DATA]);
|
||||
}
|
||||
} else {
|
||||
napi_value message = nullptr;
|
||||
napi_create_string_utf8(env, "async call failed", NAPI_AUTO_LENGTH, &message);
|
||||
napi_create_error(env, nullptr, message, &result[ARG_ERROR]);
|
||||
napi_get_undefined(env, &result[ARG_DATA]);
|
||||
}
|
||||
HILOG_DEBUG("run the js callback function:(context->defer != nullptr)?[%{public}d]", context->defer != nullptr);
|
||||
if (context->defer != nullptr) {
|
||||
// promise
|
||||
HILOG_DEBUG("Promise to do!");
|
||||
if (status == napi_ok && runStatus == napi_ok) {
|
||||
napi_resolve_deferred(env, context->defer, result[ARG_DATA]);
|
||||
} else {
|
||||
napi_reject_deferred(env, context->defer, result[ARG_ERROR]);
|
||||
}
|
||||
} else {
|
||||
// callback
|
||||
HILOG_DEBUG("Callback to do!");
|
||||
napi_value callback = nullptr;
|
||||
napi_get_reference_value(env, context->callback, &callback);
|
||||
napi_value returnValue;
|
||||
napi_call_function(env, nullptr, callback, ARG_BUTT, result, &returnValue);
|
||||
}
|
||||
DeleteContext(env, context);
|
||||
}
|
||||
void AsyncCall::DeleteContext(napi_env env, AsyncContext *context)
|
||||
{
|
||||
if (env != nullptr) {
|
||||
napi_delete_reference(env, context->callback);
|
||||
napi_delete_reference(env, context->self);
|
||||
napi_delete_async_work(env, context->work);
|
||||
}
|
||||
delete context;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 WALLPAPER_ASYNC_CALL_H
|
||||
#define WALLPAPER_ASYNC_CALL_H
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include "wallpaper_js_util.h"
|
||||
#include "napi/native_common.h"
|
||||
#include "napi/native_api.h"
|
||||
#include "napi/native_node_api.h"
|
||||
|
||||
namespace OHOS::WallpaperNAPI {
|
||||
class AsyncCall final {
|
||||
public:
|
||||
class Context {
|
||||
public:
|
||||
using InputAction = std::function<napi_status(napi_env, size_t, napi_value *, napi_value)>;
|
||||
using OutputAction = std::function<napi_status(napi_env, napi_value *)>;
|
||||
using ExecAction = std::function<void(Context *)>;
|
||||
Context(InputAction input, OutputAction output): input_(std::move(input)), output_(std::move(output)) {};
|
||||
virtual ~Context() {};
|
||||
void SetAction(InputAction input, OutputAction output = nullptr)
|
||||
{
|
||||
input_ = input;
|
||||
output_ = output;
|
||||
}
|
||||
|
||||
void SetAction(OutputAction output)
|
||||
{
|
||||
SetAction(nullptr, std::move(output));
|
||||
}
|
||||
|
||||
virtual napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self)
|
||||
{
|
||||
if (input_ == nullptr) {
|
||||
return napi_ok;
|
||||
}
|
||||
return input_(env, argc, argv, self);
|
||||
}
|
||||
|
||||
virtual napi_status operator()(napi_env env, napi_value *result)
|
||||
{
|
||||
if (output_ == nullptr) {
|
||||
*result = nullptr;
|
||||
return napi_ok;
|
||||
}
|
||||
return output_(env, result);
|
||||
}
|
||||
|
||||
virtual void Exec()
|
||||
{
|
||||
if (exec_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
exec_(this);
|
||||
};
|
||||
protected:
|
||||
friend class AsyncCall;
|
||||
InputAction input_ = nullptr;
|
||||
OutputAction output_ = nullptr;
|
||||
ExecAction exec_ = nullptr;
|
||||
};
|
||||
|
||||
// The default AsyncCallback in the parameters is at the end position.
|
||||
static constexpr size_t ASYNC_DEFAULT_POS = -1;
|
||||
AsyncCall(napi_env env, napi_callback_info info, std::shared_ptr<Context> context, size_t pos = ASYNC_DEFAULT_POS);
|
||||
~AsyncCall();
|
||||
napi_value Call(napi_env env, Context::ExecAction exec = nullptr);
|
||||
napi_value SyncCall(napi_env env, Context::ExecAction exec = nullptr);
|
||||
private:
|
||||
enum arg : int {
|
||||
ARG_ERROR,
|
||||
ARG_DATA,
|
||||
ARG_BUTT
|
||||
};
|
||||
static void OnExecute(napi_env env, void *data);
|
||||
static void OnComplete(napi_env env, napi_status status, void *data);
|
||||
struct AsyncContext {
|
||||
std::shared_ptr<Context> ctx = nullptr;
|
||||
napi_ref callback = nullptr;
|
||||
napi_ref self = nullptr;
|
||||
napi_deferred defer = nullptr;
|
||||
napi_async_work work = nullptr;
|
||||
};
|
||||
static void DeleteContext(napi_env env, AsyncContext *context);
|
||||
|
||||
AsyncContext *context_ = nullptr;
|
||||
napi_env env_ = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // WALLPAPER_ASYNC_CALL_H
|
||||
@@ -0,0 +1,474 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 <pthread.h>
|
||||
#include <unistd.h>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <uv.h>
|
||||
#include "hilog_wrapper.h"
|
||||
#include "wallpaper_manager.h"
|
||||
#include "wallpaper_manager_common_info.h"
|
||||
#include "napi_wallpaper_ability.h"
|
||||
|
||||
using namespace OHOS::Media;
|
||||
namespace OHOS {
|
||||
namespace WallpaperNAPI {
|
||||
const int32_t ONE = 1;
|
||||
const int32_t TWO = 2;
|
||||
const int32_t THREE = 3;
|
||||
|
||||
napi_value NAPI_GetColors(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_DEBUG("NAPI_GetColors in");
|
||||
auto context = std::make_shared<GetContextInfo>();
|
||||
auto input = [context](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
|
||||
NAPI_ASSERT_BASE(env, argc == 1 || argc == 2, " should 1 or 2 parameters!", napi_invalid_arg);
|
||||
HILOG_DEBUG("input ---- argc : %{public}d", argc);
|
||||
napi_valuetype valueType = napi_undefined;
|
||||
napi_typeof(env, argv[0], &valueType);
|
||||
NAPI_ASSERT_BASE(env, valueType == napi_number, "param type wrong!", napi_invalid_arg);
|
||||
napi_get_value_int32(env, argv[0], &context->wallpaperType);
|
||||
HILOG_DEBUG("input ---- wallpaperType : %{public}d", context->wallpaperType);
|
||||
return napi_ok;
|
||||
};
|
||||
auto output = [context](napi_env env, napi_value *result) -> napi_status {
|
||||
napi_value data = WallpaperJSUtil::Convert2JSRgbaArray(env, context->colors);
|
||||
HILOG_DEBUG("output ---- Convert2JSRgbaArray data != nullptr[%{public}d]", data != nullptr);
|
||||
*result = data;
|
||||
return napi_ok;
|
||||
};
|
||||
auto exec = [context](AsyncCall::Context *ctx) {
|
||||
HILOG_DEBUG("exec ---- GetColors");
|
||||
context->colors = WallpaperMgrService::WallpaperManagerkits::GetInstance().GetColors(context->wallpaperType);
|
||||
HILOG_DEBUG("exec ---- GetColors colors size : %{public}d", context->colors.size());
|
||||
if (!context->colors.empty()) {
|
||||
context->status = napi_ok;
|
||||
}
|
||||
};
|
||||
context->SetAction(std::move(input), std::move(output));
|
||||
AsyncCall asyncCall(env, info, std::dynamic_pointer_cast<AsyncCall::Context>(context), 1);
|
||||
return asyncCall.Call(env, exec);
|
||||
}
|
||||
|
||||
napi_value NAPI_GetId(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_DEBUG("NAPI_GetId in");
|
||||
auto context = std::make_shared<GetContextInfo>();
|
||||
auto input = [context](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
|
||||
NAPI_ASSERT_BASE(env, argc == 1 || argc == 2, " should 1 or 2 parameters!", napi_invalid_arg);
|
||||
HILOG_DEBUG("input ---- argc : %{public}d", argc);
|
||||
napi_valuetype valueType = napi_undefined;
|
||||
napi_typeof(env, argv[0], &valueType);
|
||||
NAPI_ASSERT_BASE(env, valueType == napi_number, "param type wrong!", napi_invalid_arg);
|
||||
napi_get_value_int32(env, argv[0], &context->wallpaperType);
|
||||
HILOG_DEBUG("input ---- wallpaperType : %{public}d", context->wallpaperType);
|
||||
return napi_ok;
|
||||
};
|
||||
auto output = [context](napi_env env, napi_value *result) -> napi_status {
|
||||
napi_status status = napi_create_int32(env, context->wallpaperId, result);
|
||||
HILOG_DEBUG("output ---- napi_create_int32[%{public}d]", status);
|
||||
return status;
|
||||
};
|
||||
auto exec = [context](AsyncCall::Context *ctx) {
|
||||
HILOG_DEBUG("exec ---- GetWallpaperId");
|
||||
context->wallpaperId = WallpaperMgrService::WallpaperManagerkits::GetInstance().GetWallpaperId(
|
||||
context->wallpaperType);
|
||||
HILOG_DEBUG("exec ---- GetWallpaperId wallpaperId : %{public}d", context->wallpaperId);
|
||||
context->status = napi_ok;
|
||||
};
|
||||
context->SetAction(std::move(input), std::move(output));
|
||||
AsyncCall asyncCall(env, info, std::dynamic_pointer_cast<AsyncCall::Context>(context), 1);
|
||||
return asyncCall.Call(env, exec);
|
||||
}
|
||||
|
||||
napi_value NAPI_GetPixelMap(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_DEBUG("NAPI_GetPixelMap in");
|
||||
auto context = std::make_shared<GetContextInfo>();
|
||||
auto input = [context](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
|
||||
NAPI_ASSERT_BASE(env, argc == 1 || argc == 2, " should 1 or 2 parameters!", napi_invalid_arg);
|
||||
HILOG_DEBUG("input ---- argc : %{public}d", argc);
|
||||
napi_valuetype valueType = napi_undefined;
|
||||
napi_typeof(env, argv[0], &valueType);
|
||||
NAPI_ASSERT_BASE(env, valueType == napi_number, "param type wrong!", napi_invalid_arg);
|
||||
napi_get_value_int32(env, argv[0], &context->wallpaperType);
|
||||
HILOG_DEBUG("input ---- wallpaperType : %{public}d", context->wallpaperType);
|
||||
return napi_ok;
|
||||
};
|
||||
auto output = [context](napi_env env, napi_value *result) -> napi_status {
|
||||
napi_value pixelVal = PixelMapNapi::CreatePixelMap(env, context->pixelMap);
|
||||
HILOG_DEBUG("output ---- PixelMapNapi::CreatePixelMap != nullptr[%{public}d]", pixelVal != nullptr);
|
||||
*result = pixelVal;
|
||||
return napi_ok;
|
||||
};
|
||||
auto exec = [context](AsyncCall::Context *ctx) {
|
||||
HILOG_DEBUG("exec ---- GetPixelMap");
|
||||
auto pixel =
|
||||
WallpaperMgrService::WallpaperManagerkits::GetInstance().GetPixelMap(context->wallpaperType);
|
||||
HILOG_DEBUG("exec ---- CreatPixelMap end");
|
||||
if (pixel != nullptr) {
|
||||
HILOG_DEBUG("exec ---- GetPixelMap pixel != nullptr");
|
||||
context->status = napi_ok;
|
||||
context->pixelMap = std::move(pixel);
|
||||
HILOG_DEBUG("exec ---- GetPixelMap pixel != nullptr");
|
||||
}
|
||||
};
|
||||
context->SetAction(std::move(input), std::move(output));
|
||||
AsyncCall asyncCall(env, info, std::dynamic_pointer_cast<AsyncCall::Context>(context), 1);
|
||||
return asyncCall.Call(env, exec);
|
||||
}
|
||||
|
||||
napi_value NAPI_GetMinHeight(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_DEBUG("NAPI_GetMinHeight in");
|
||||
auto context = std::make_shared<GetMinContextInfo>();
|
||||
auto input = [context](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
|
||||
NAPI_ASSERT_BASE(env, argc == 0 || argc == 1, " should 0 or 1 parameters!", napi_invalid_arg);
|
||||
return napi_ok;
|
||||
};
|
||||
auto output = [context](napi_env env, napi_value *result) -> napi_status {
|
||||
napi_status status = napi_create_int32(env, context->minHeight, result);
|
||||
HILOG_DEBUG("output ---- napi_create_int32[%{public}d]", status);
|
||||
return status;
|
||||
};
|
||||
auto exec = [context](AsyncCall::Context *ctx) {
|
||||
HILOG_DEBUG("exec ---- GetWallpaperMinHeight");
|
||||
context->minHeight = WallpaperMgrService::WallpaperManagerkits::GetInstance().GetWallpaperMinHeight();
|
||||
HILOG_DEBUG("exec ---- GetWallpaperMinHeight minHeight : %{public}d", context->minHeight);
|
||||
if (context->minHeight) {
|
||||
context->status = napi_ok;
|
||||
}
|
||||
};
|
||||
context->SetAction(std::move(input), std::move(output));
|
||||
AsyncCall asyncCall(env, info, std::dynamic_pointer_cast<AsyncCall::Context>(context), 0);
|
||||
return asyncCall.Call(env, exec);
|
||||
}
|
||||
|
||||
napi_value NAPI_GetMinWidth(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_DEBUG("NAPI_GetMinWidth in");
|
||||
auto context = std::make_shared<GetMinContextInfo>();
|
||||
auto input = [context](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
|
||||
NAPI_ASSERT_BASE(env, argc == 0 || argc == 1, " should 0 or 1 parameters!", napi_invalid_arg);
|
||||
return napi_ok;
|
||||
};
|
||||
auto output = [context](napi_env env, napi_value *result) -> napi_status {
|
||||
napi_status status = napi_create_int32(env, context->minWidth, result);
|
||||
HILOG_DEBUG("output ---- napi_create_int32[%{public}d]", status);
|
||||
return status;
|
||||
};
|
||||
auto exec = [context](AsyncCall::Context *ctx) {
|
||||
HILOG_DEBUG("exec ---- GetWallpaperMinWidth");
|
||||
context->minWidth = WallpaperMgrService::WallpaperManagerkits::GetInstance().GetWallpaperMinWidth();
|
||||
HILOG_DEBUG("exec ---- GetWallpaperMinWidth minWidth : %{public}d", context->minWidth);
|
||||
if (context->minWidth) {
|
||||
context->status = napi_ok;
|
||||
}
|
||||
};
|
||||
context->SetAction(std::move(input), std::move(output));
|
||||
AsyncCall asyncCall(env, info, std::dynamic_pointer_cast<AsyncCall::Context>(context), 0);
|
||||
return asyncCall.Call(env, exec);
|
||||
}
|
||||
|
||||
napi_value NAPI_IsChangePermitted(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_DEBUG("NAPI_IsChangePermitted in");
|
||||
auto context = std::make_shared<PermissionContextInfo>();
|
||||
auto input = [context](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
|
||||
NAPI_ASSERT_BASE(env, argc == 0 || argc == 1, " should 0 or 1 parameters!", napi_invalid_arg);
|
||||
return napi_ok;
|
||||
};
|
||||
auto output = [context](napi_env env, napi_value *result) -> napi_status {
|
||||
napi_status status = napi_get_boolean(env, context->isChangePermitted, result);
|
||||
HILOG_DEBUG("output ---- napi_get_boolean[%{public}d]", status);
|
||||
return status;
|
||||
};
|
||||
auto exec = [context](AsyncCall::Context *ctx) {
|
||||
HILOG_DEBUG("exec ---- IsChangePermitted");
|
||||
context->isChangePermitted = WallpaperMgrService::WallpaperManagerkits::GetInstance().IsChangePermitted();
|
||||
HILOG_DEBUG("exec ---- IsChangePermitted : %{public}d", context->isChangePermitted);
|
||||
context->status = napi_ok;
|
||||
};
|
||||
context->SetAction(std::move(input), std::move(output));
|
||||
AsyncCall asyncCall(env, info, std::dynamic_pointer_cast<AsyncCall::Context>(context), 0);
|
||||
return asyncCall.Call(env, exec);
|
||||
}
|
||||
|
||||
napi_value NAPI_IsOperationAllowed(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_DEBUG("NAPI_IsOperationAllowed in");
|
||||
auto context = std::make_shared<PermissionContextInfo>();
|
||||
auto input = [context](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
|
||||
NAPI_ASSERT_BASE(env, argc == 0 || argc == 1, " should 0 or 1 parameters!", napi_invalid_arg);
|
||||
return napi_ok;
|
||||
};
|
||||
auto output = [context](napi_env env, napi_value *result) -> napi_status {
|
||||
napi_status status = napi_get_boolean(env, context->isOperationAllowed, result);
|
||||
HILOG_DEBUG("output ---- napi_get_boolean[%{public}d]", status);
|
||||
return status;
|
||||
};
|
||||
auto exec = [context](AsyncCall::Context *ctx) {
|
||||
HILOG_DEBUG("exec ---- IsOperationAllowed");
|
||||
context->isOperationAllowed = WallpaperMgrService::WallpaperManagerkits::GetInstance().IsOperationAllowed();
|
||||
HILOG_DEBUG("exec ---- IsOperationAllowed[%{public}d]", context->isOperationAllowed);
|
||||
context->status = napi_ok;
|
||||
};
|
||||
context->SetAction(std::move(input), std::move(output));
|
||||
AsyncCall asyncCall(env, info, std::dynamic_pointer_cast<AsyncCall::Context>(context), 0);
|
||||
return asyncCall.Call(env, exec);
|
||||
}
|
||||
|
||||
napi_value NAPI_Reset(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_DEBUG("NAPI_Reset in");
|
||||
auto context = std::make_shared<SetContextInfo>();
|
||||
auto input = [context](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
|
||||
NAPI_ASSERT_BASE(env, argc == 1 || argc == 2, " should 1 or 2 parameters!", napi_invalid_arg);
|
||||
HILOG_DEBUG("input ---- argc : %{public}d", argc);
|
||||
napi_valuetype valueType = napi_undefined;
|
||||
napi_typeof(env, argv[0], &valueType);
|
||||
NAPI_ASSERT_BASE(env, valueType == napi_number, "param type wrong!", napi_invalid_arg);
|
||||
napi_get_value_int32(env, argv[0], &context->wallpaperType);
|
||||
HILOG_DEBUG("input ---- wallpaperType : %{public}d", context->wallpaperType);
|
||||
return napi_ok;
|
||||
};
|
||||
auto exec = [context](AsyncCall::Context *ctx) {
|
||||
HILOG_DEBUG("exec ---- ResetWallpaper");
|
||||
bool status = WallpaperMgrService::WallpaperManagerkits::GetInstance().ResetWallpaper(context->wallpaperType);
|
||||
HILOG_DEBUG("exec ---- ResetWallpaper[%{public}d]", status);
|
||||
if (status) {
|
||||
context->status = napi_ok;
|
||||
}
|
||||
HILOG_DEBUG("exec ---- status[%{public}d], context->status[%{public}d]", status, context->status);
|
||||
};
|
||||
context->SetAction(std::move(input));
|
||||
AsyncCall asyncCall(env, info, std::dynamic_pointer_cast<AsyncCall::Context>(context), 1);
|
||||
return asyncCall.Call(env, exec);
|
||||
}
|
||||
|
||||
napi_value NAPI_SetWallpaper(napi_env env, napi_callback_info info)
|
||||
{
|
||||
auto context = std::make_shared<SetContextInfo>();
|
||||
auto input = [context](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
|
||||
NAPI_ASSERT_BASE(env, argc == 2 || argc == 3, " should 2 or 3 parameters!", napi_invalid_arg);
|
||||
HILOG_DEBUG("input ---- argc : %{public}d", argc);
|
||||
napi_valuetype valueType = napi_undefined;
|
||||
napi_typeof(env, argv[0], &valueType);
|
||||
NAPI_ASSERT_BASE(env, valueType == napi_string || valueType == napi_object, "first param type wrong!",
|
||||
napi_invalid_arg);
|
||||
if (valueType == napi_string) {
|
||||
context->url = WallpaperJSUtil::Convert2String(env, argv[0]);
|
||||
} else {
|
||||
std::shared_ptr<PixelMap> tmpPixelMap = PixelMapNapi::GetPixelMap(env, argv[0]);
|
||||
if (tmpPixelMap == nullptr) {
|
||||
HILOG_ERROR("PixelMapNapi::GetPixelMap error");
|
||||
context->isPixelEmp = true;
|
||||
return napi_generic_failure;
|
||||
} else {
|
||||
context->isPixelEmp = false;
|
||||
}
|
||||
context->pixelMap = std::make_unique<PixelMap>(*tmpPixelMap);
|
||||
}
|
||||
valueType = napi_undefined;
|
||||
napi_typeof(env, argv[1], &valueType);
|
||||
NAPI_ASSERT_BASE(env, valueType == napi_number, "second param type wrong!", napi_invalid_arg);
|
||||
napi_get_value_int32(env, argv[1], &context->wallpaperType);
|
||||
HILOG_DEBUG("input ---- wallpaperType : %{public}d", context->wallpaperType);
|
||||
return napi_ok;
|
||||
};
|
||||
auto exec = [context](AsyncCall::Context *ctx) {
|
||||
bool urlret = false;
|
||||
if (context->url.length() == 0) {
|
||||
HILOG_DEBUG("exec ---- setWallpaper by pixelMap");
|
||||
if (!context->isPixelEmp) {
|
||||
urlret = WallpaperMgrService::WallpaperManagerkits::GetInstance().SetWallpaper(context->pixelMap,
|
||||
context->wallpaperType);
|
||||
}
|
||||
} else {
|
||||
HILOG_DEBUG("exec ---- setWallpaper by url");
|
||||
urlret = WallpaperMgrService::WallpaperManagerkits::GetInstance().SetWallpaper(context->url,
|
||||
context->wallpaperType);
|
||||
}
|
||||
if (urlret) {
|
||||
context->status = napi_ok;
|
||||
}
|
||||
HILOG_DEBUG("exec ---- context->status[%{public}d]", context->status);
|
||||
};
|
||||
context->SetAction(std::move(input));
|
||||
AsyncCall asyncCall(env, info, std::dynamic_pointer_cast<AsyncCall::Context>(context), TWO);
|
||||
return asyncCall.Call(env, exec);
|
||||
}
|
||||
|
||||
napi_value NAPI_ScreenshotLiveWallpaper(napi_env env, napi_callback_info info)
|
||||
{
|
||||
napi_value argv[3] = {nullptr};
|
||||
size_t argc = 3;
|
||||
napi_valuetype valuetype0 = napi_valuetype::napi_null;
|
||||
NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype0));
|
||||
NAPI_ASSERT(env, valuetype0 == napi_number, "Wrong argument type. Numbers expected.");
|
||||
int32_t value0 = 0;
|
||||
// wallpapertyepe WALLPAPER_SYSTEM:2 or WALLPAPER_LOCKSCREEN:1
|
||||
NAPI_CALL(env, napi_get_value_int32(env, argv[0], &value0));
|
||||
|
||||
bool callBackMode = false;
|
||||
if (argc >= THREE) {
|
||||
napi_valuetype valuetype = napi_valuetype::napi_null;
|
||||
NAPI_CALL(env, napi_typeof(env, argv[TWO], &valuetype));
|
||||
NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected.");
|
||||
callBackMode = true;
|
||||
}
|
||||
|
||||
napi_value ret = 0;
|
||||
NAPI_CALL(env, napi_create_int32(env, 0, &ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::shared_ptr<WallpaperMgrService::WallpaperColorChangeListener> colorChangeListener_;
|
||||
|
||||
napi_value NAPI_On(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_DEBUG("NAPI_On in");
|
||||
size_t argc = 2;
|
||||
napi_value argv[2] = {nullptr};
|
||||
napi_value thisVar = nullptr;
|
||||
void *data = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data));
|
||||
NAPI_ASSERT(env, argc == TWO, "Wrong number of arguments, requires 2");
|
||||
|
||||
napi_valuetype valuetype;
|
||||
NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype));
|
||||
NAPI_ASSERT(env, valuetype == napi_string, "type is not a string");
|
||||
std::string type = WallpaperJSUtil::Convert2String(env, argv[0]);
|
||||
HILOG_DEBUG("type : %{public}s", type.c_str());
|
||||
|
||||
valuetype = napi_undefined;
|
||||
napi_typeof(env, argv[1], &valuetype);
|
||||
NAPI_ASSERT(env, valuetype == napi_function, "callback is not a function");
|
||||
|
||||
std::shared_ptr<WallpaperMgrService::WallpaperColorChangeListener> listener =
|
||||
std::make_shared<NapiWallpaperAbility>(env, argv[1]);
|
||||
|
||||
bool status = WallpaperMgrService::WallpaperManagerkits::GetInstance().On(listener);
|
||||
if (!status) {
|
||||
HILOG_ERROR("WallpaperMgrService::WallpaperManagerkits::GetInstance().On failed!");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (colorChangeListener_ != nullptr) {
|
||||
HILOG_DEBUG("WallpaperMgrService::WallpaperManagerkits::GetInstance().Off");
|
||||
WallpaperMgrService::WallpaperManagerkits::GetInstance().Off(listener);
|
||||
}
|
||||
|
||||
colorChangeListener_ = std::move(listener);
|
||||
|
||||
napi_value result = nullptr;
|
||||
napi_get_undefined(env, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
napi_value NAPI_Off(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_DEBUG("NAPI_Off in");
|
||||
size_t argc = 2;
|
||||
napi_value argv[2] = {nullptr};
|
||||
napi_value thisVar = nullptr;
|
||||
void *data = nullptr;
|
||||
napi_get_cb_info(env, info, &argc, argv, &thisVar, &data);
|
||||
NAPI_ASSERT(env, argc == ONE || argc == TWO, "Wrong number of arguments, requires 1 or 2");
|
||||
|
||||
napi_valuetype valuetype;
|
||||
NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype));
|
||||
NAPI_ASSERT(env, valuetype == napi_string, "type is not a string");
|
||||
std::string type = WallpaperJSUtil::Convert2String(env, argv[0]);
|
||||
HILOG_DEBUG("type : %{public}s", type.c_str());
|
||||
|
||||
std::shared_ptr<WallpaperMgrService::WallpaperColorChangeListener> listener = nullptr;
|
||||
if (argc == TWO) {
|
||||
valuetype = napi_undefined;
|
||||
napi_typeof(env, argv[1], &valuetype);
|
||||
NAPI_ASSERT(env, valuetype == napi_function, "callback is not a function");
|
||||
listener = std::make_shared<NapiWallpaperAbility>(env, argv[1]);
|
||||
}
|
||||
|
||||
if (colorChangeListener_ != nullptr) {
|
||||
listener = std::move(colorChangeListener_);
|
||||
}
|
||||
|
||||
if (listener == nullptr) {
|
||||
HILOG_ERROR("listener is null");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool status = WallpaperMgrService::WallpaperManagerkits::GetInstance().Off(listener);
|
||||
if (!status) {
|
||||
HILOG_ERROR("WallpaperMgrService::WallpaperManagerkits::GetInstance().Off failed!");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
colorChangeListener_ = nullptr;
|
||||
|
||||
napi_value result = nullptr;
|
||||
napi_get_undefined(env, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
NapiWallpaperAbility::NapiWallpaperAbility(napi_env env, napi_value callback)
|
||||
: env_(env)
|
||||
{
|
||||
napi_create_reference(env, callback, 1, &callback_);
|
||||
napi_get_uv_event_loop(env, &loop_);
|
||||
}
|
||||
|
||||
NapiWallpaperAbility::~NapiWallpaperAbility()
|
||||
{
|
||||
napi_delete_reference(env_, callback_);
|
||||
}
|
||||
|
||||
void NapiWallpaperAbility::onColorsChange(std::vector<RgbaColor> color, int wallpaperType)
|
||||
{
|
||||
WallpaperMgrService::WallpaperColorChangeListener::onColorsChange(color, wallpaperType);
|
||||
EventDataWorker *eventDataWorker = new EventDataWorker(this, color, wallpaperType);
|
||||
uv_work_t *work = new uv_work_t;
|
||||
work->data = eventDataWorker;
|
||||
uv_queue_work(loop_, work,
|
||||
[](uv_work_t *work) {},
|
||||
[](uv_work_t *work, int status) {
|
||||
EventDataWorker *eventDataInner = reinterpret_cast<EventDataWorker *>(work->data);
|
||||
napi_value jsWallpaperType = nullptr;
|
||||
napi_create_int32(eventDataInner->listener->env_, eventDataInner->wallpaperType, &jsWallpaperType);
|
||||
napi_value jsRgbaArray = WallpaperJSUtil::Convert2JSRgbaArray(eventDataInner->listener->env_,
|
||||
eventDataInner->color);
|
||||
napi_value callback = nullptr;
|
||||
napi_value args[2] = {jsRgbaArray, jsWallpaperType};
|
||||
napi_get_reference_value(eventDataInner->listener->env_, eventDataInner->listener->callback_, &callback);
|
||||
napi_value global = nullptr;
|
||||
napi_get_global(eventDataInner->listener->env_, &global);
|
||||
napi_value result;
|
||||
napi_status callStatus = napi_call_function(eventDataInner->listener->env_, global, callback, 1, args,
|
||||
&result);
|
||||
if (callStatus != napi_ok) {
|
||||
HILOG_ERROR("notify data change failed callStatus:%{public}d callback:%{public}p", callStatus,
|
||||
callback);
|
||||
}
|
||||
delete eventDataInner;
|
||||
eventDataInner = nullptr;
|
||||
delete work;
|
||||
work = nullptr;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef NAPI_WALLPAPER_ABILITY_H
|
||||
#define NAPI_WALLPAPER_ABILITY_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include "napi/native_common.h"
|
||||
#include "napi/native_node_api.h"
|
||||
#include "napi/native_api.h"
|
||||
#include "pixel_map.h"
|
||||
#include "pixel_map_napi.h"
|
||||
#include "wallpaper_manager_common_info.h"
|
||||
#include "wallpaper_color_change_listener.h"
|
||||
#include "async_call.h"
|
||||
#include "wallpaper_js_util.h"
|
||||
|
||||
#define BUFFER_LENGTH_MAX (128)
|
||||
#define DEFAULT_STACK_ID (1)
|
||||
#define DEFAULT_LAST_MEMORY_LEVEL (-1)
|
||||
#define DEFAULT_WEIGHT (-1)
|
||||
|
||||
#define MAX_MISSION_NUM (65535)
|
||||
#define QUERY_RECENT_RUNNING_MISSION_INFO_TYPE (2)
|
||||
#define BUSINESS_ERROR_CODE_OK 0
|
||||
namespace OHOS {
|
||||
namespace WallpaperNAPI {
|
||||
struct GetContextInfo : public AsyncCall::Context {
|
||||
int wallpaperType;
|
||||
std::vector<RgbaColor> colors;
|
||||
int wallpaperId;
|
||||
std::shared_ptr<OHOS::Media::PixelMap> pixelMap;
|
||||
napi_status status = napi_generic_failure;
|
||||
GetContextInfo() : Context(nullptr, nullptr) { };
|
||||
GetContextInfo(InputAction input, OutputAction output) : Context(std::move(input), std::move(output)) { };
|
||||
|
||||
napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override
|
||||
{
|
||||
NAPI_ASSERT_BASE(env, self != nullptr, "self is nullptr", napi_invalid_arg);
|
||||
return Context::operator()(env, argc, argv, self);
|
||||
}
|
||||
napi_status operator()(napi_env env, napi_value *result) override
|
||||
{
|
||||
if (status != napi_ok) {
|
||||
return status;
|
||||
}
|
||||
return Context::operator()(env, result);
|
||||
}
|
||||
};
|
||||
|
||||
struct GetMinContextInfo : public AsyncCall::Context {
|
||||
int minHeight;
|
||||
int minWidth;
|
||||
napi_status status = napi_generic_failure;
|
||||
GetMinContextInfo() : Context(nullptr, nullptr) { };
|
||||
GetMinContextInfo(InputAction input, OutputAction output) : Context(std::move(input), std::move(output)) { };
|
||||
|
||||
napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override
|
||||
{
|
||||
NAPI_ASSERT_BASE(env, self != nullptr, "self is nullptr", napi_invalid_arg);
|
||||
return Context::operator()(env, argc, argv, self);
|
||||
}
|
||||
napi_status operator()(napi_env env, napi_value *result) override
|
||||
{
|
||||
if (status != napi_ok) {
|
||||
return status;
|
||||
}
|
||||
return Context::operator()(env, result);
|
||||
}
|
||||
};
|
||||
|
||||
struct PermissionContextInfo : public AsyncCall::Context {
|
||||
bool isChangePermitted;
|
||||
bool isOperationAllowed;
|
||||
napi_status status = napi_generic_failure;
|
||||
PermissionContextInfo() : Context(nullptr, nullptr) { };
|
||||
PermissionContextInfo(InputAction input, OutputAction output) : Context(std::move(input), std::move(output)) { };
|
||||
|
||||
napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override
|
||||
{
|
||||
NAPI_ASSERT_BASE(env, self != nullptr, "self is nullptr", napi_invalid_arg);
|
||||
return Context::operator()(env, argc, argv, self);
|
||||
}
|
||||
napi_status operator()(napi_env env, napi_value *result) override
|
||||
{
|
||||
if (status != napi_ok) {
|
||||
return status;
|
||||
}
|
||||
return Context::operator()(env, result);
|
||||
}
|
||||
};
|
||||
|
||||
struct SetContextInfo : public AsyncCall::Context {
|
||||
int wallpaperType;
|
||||
std::string url = "";
|
||||
std::unique_ptr<OHOS::Media::PixelMap> pixelMap;
|
||||
napi_status status = napi_generic_failure;
|
||||
bool isPixelEmp = false;
|
||||
SetContextInfo() : Context(nullptr, nullptr) { };
|
||||
SetContextInfo(InputAction input, OutputAction output) : Context(std::move(input), std::move(output)) { };
|
||||
|
||||
napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override
|
||||
{
|
||||
NAPI_ASSERT_BASE(env, self != nullptr, "self is nullptr", napi_invalid_arg);
|
||||
return Context::operator()(env, argc, argv, self);
|
||||
}
|
||||
napi_status operator()(napi_env env, napi_value *result) override
|
||||
{
|
||||
if (status != napi_ok) {
|
||||
return status;
|
||||
}
|
||||
return Context::operator()(env, result);
|
||||
}
|
||||
};
|
||||
|
||||
extern std::shared_ptr<WallpaperMgrService::WallpaperColorChangeListener> colorChangeListener_;
|
||||
|
||||
class NapiWallpaperAbility : public WallpaperMgrService::WallpaperColorChangeListener {
|
||||
public:
|
||||
NapiWallpaperAbility(napi_env env, napi_value callback);
|
||||
virtual ~NapiWallpaperAbility();
|
||||
void onColorsChange(std::vector<RgbaColor> color, int wallpaperType) override;
|
||||
private:
|
||||
struct EventDataWorker {
|
||||
const NapiWallpaperAbility *listener = nullptr;
|
||||
const std::vector<RgbaColor> color;
|
||||
const int wallpaperType;
|
||||
EventDataWorker(const NapiWallpaperAbility * const & listenerIn,
|
||||
const std::vector<RgbaColor> &colorIn,
|
||||
const int wallpaperTypeIn)
|
||||
: listener(listenerIn), color(colorIn), wallpaperType(wallpaperTypeIn) {}
|
||||
};
|
||||
napi_ref callback_ = nullptr;
|
||||
napi_env env_;
|
||||
uv_loop_s *loop_ = nullptr;
|
||||
};
|
||||
|
||||
napi_value NAPI_GetColors(napi_env env, napi_callback_info info);
|
||||
napi_value NAPI_GetId(napi_env env, napi_callback_info info);
|
||||
napi_value NAPI_GetMinHeight(napi_env env, napi_callback_info info);
|
||||
napi_value NAPI_GetMinWidth(napi_env env, napi_callback_info info);
|
||||
napi_value NAPI_IsChangePermitted(napi_env env, napi_callback_info info);
|
||||
napi_value NAPI_IsOperationAllowed(napi_env env, napi_callback_info info);
|
||||
napi_value NAPI_Reset(napi_env env, napi_callback_info info);
|
||||
napi_value NAPI_SetWallpaper(napi_env env, napi_callback_info info);
|
||||
napi_value NAPI_GetPixelMap(napi_env env, napi_callback_info info);
|
||||
napi_value NAPI_ScreenshotLiveWallpaper(napi_env env, napi_callback_info info);
|
||||
napi_value NAPI_On(napi_env env, napi_callback_info info);
|
||||
napi_value NAPI_Off(napi_env env, napi_callback_info info);
|
||||
}
|
||||
}
|
||||
#endif // NAPI_WALLPAPER_ABILITY_H
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 <pthread.h>
|
||||
#include <string>
|
||||
#include <unistd.h>
|
||||
#include <napi/native_api.h>
|
||||
#include "napi_wallpaper_ability.h"
|
||||
#include "napi/native_node_api.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace WallpaperNAPI {
|
||||
enum class WallpaperType {
|
||||
/**
|
||||
* Indicates the home screen wallpaper.
|
||||
*/
|
||||
WALLPAPER_SYSTEM,
|
||||
/**
|
||||
* Indicates the lock screen wallpaper.
|
||||
*/
|
||||
WALLPAPER_LOCKSCREEN
|
||||
};
|
||||
EXTERN_C_START
|
||||
static napi_value Init(napi_env env, napi_value exports)
|
||||
{
|
||||
HILOG_INFO("napi_moudule Init start...");
|
||||
napi_value wpType_system = nullptr;
|
||||
napi_value wpType_lockscreen = nullptr;
|
||||
napi_create_int32(env, static_cast<int32_t>(WALLPAPER_SYSTEM), &wpType_system);
|
||||
napi_create_int32(env, static_cast<int32_t>(WALLPAPER_LOCKSCREEN), &wpType_lockscreen);
|
||||
napi_property_descriptor desc[] = {
|
||||
DECLARE_NAPI_FUNCTION("getColors", NAPI_GetColors),
|
||||
DECLARE_NAPI_FUNCTION("getId", NAPI_GetId),
|
||||
DECLARE_NAPI_FUNCTION("getMinHeight", NAPI_GetMinHeight),
|
||||
DECLARE_NAPI_FUNCTION("getMinWidth", NAPI_GetMinWidth),
|
||||
DECLARE_NAPI_FUNCTION("isChangePermitted", NAPI_IsChangePermitted),
|
||||
DECLARE_NAPI_FUNCTION("isOperationAllowed", NAPI_IsOperationAllowed),
|
||||
DECLARE_NAPI_FUNCTION("reset", NAPI_Reset),
|
||||
DECLARE_NAPI_FUNCTION("setWallpaper", NAPI_SetWallpaper),
|
||||
DECLARE_NAPI_FUNCTION("getPixelMap", NAPI_GetPixelMap),
|
||||
DECLARE_NAPI_FUNCTION("screenshotLiveWallpaper", NAPI_ScreenshotLiveWallpaper),
|
||||
DECLARE_NAPI_FUNCTION("on", NAPI_On),
|
||||
DECLARE_NAPI_FUNCTION("off", NAPI_Off),
|
||||
DECLARE_NAPI_STATIC_PROPERTY("WALLPAPER_SYSTEM", wpType_system),
|
||||
DECLARE_NAPI_STATIC_PROPERTY("WALLPAPER_LOCKSCREEN", wpType_lockscreen),
|
||||
};
|
||||
|
||||
NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
|
||||
HILOG_INFO("napi_moudule Init end...");
|
||||
HILOG_INFO("OHOS::Media::PixelMapNapi::Init start...");
|
||||
OHOS::Media::PixelMapNapi::Init(env, exports);
|
||||
HILOG_INFO("OHOS::Media::PixelMapNapi::Init end...");
|
||||
return exports;
|
||||
}
|
||||
|
||||
EXTERN_C_END
|
||||
|
||||
/*
|
||||
* Module define
|
||||
*/
|
||||
static napi_module _module = {
|
||||
.nm_version = 1,
|
||||
.nm_flags = 0,
|
||||
.nm_filename = nullptr,
|
||||
.nm_register_func = Init,
|
||||
.nm_modname = "app.wallpapernapi",
|
||||
.nm_priv = ((void *)0),
|
||||
.reserved = {0},
|
||||
};
|
||||
|
||||
extern "C" __attribute__((constructor)) void RegisterModule(void)
|
||||
{
|
||||
napi_module_register(&_module);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
|
||||
import("//ark/ts2abc/ts2panda/ts2abc_config.gni")
|
||||
import("//build/ohos.gni")
|
||||
|
||||
ts2abc_gen_abc("gen_wallpaper_extension_context_abc") {
|
||||
src_js = rebase_path("wallpaper_extension_context.js")
|
||||
dst_file = rebase_path(target_out_dir + "/wallpaper_extension_context.abc")
|
||||
in_puts = [ "wallpaper_extension_context.js" ]
|
||||
out_puts = [ target_out_dir + "/wallpaper_extension_context.abc" ]
|
||||
extra_args = [ "--module" ]
|
||||
}
|
||||
|
||||
gen_js_obj("wallpaper_extension_context_js") {
|
||||
input = "wallpaper_extension_context.js"
|
||||
output = target_out_dir + "/wallpaper_extension_context.o"
|
||||
}
|
||||
|
||||
gen_js_obj("wallpaper_extension_context_abc") {
|
||||
input = get_label_info(":gen_wallpaper_extension_context_abc",
|
||||
"target_out_dir") + "/wallpaper_extension_context.abc"
|
||||
output = target_out_dir + "/wallpaper_extension_context_abc.o"
|
||||
dep = ":gen_wallpaper_extension_context_abc"
|
||||
}
|
||||
|
||||
ohos_shared_library("wallpaperextensioncontext_napi") {
|
||||
sources = [ "wallpaper_extension_context_module.cpp" ]
|
||||
|
||||
deps = [
|
||||
":wallpaper_extension_context_abc",
|
||||
":wallpaper_extension_context_js",
|
||||
]
|
||||
|
||||
external_deps = [ "napi:ace_napi" ]
|
||||
|
||||
relative_install_dir = "module/application"
|
||||
subsystem_name = "miscservices"
|
||||
part_name = "wallpaper_native"
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
var ExtensionContext = requireNapi("application.ExtensionContext")
|
||||
|
||||
class WallpaperExtensionContext extends ExtensionContext {
|
||||
constructor(obj) {
|
||||
super(obj);
|
||||
this.extensionAbilityInfo = obj.extensionAbilityInfo
|
||||
}
|
||||
|
||||
startAbility(want, options, callback) {
|
||||
console.log("startAbility");
|
||||
return this.__context_impl__.startAbility(want, options, callback);
|
||||
}
|
||||
|
||||
connectAbility(want, options) {
|
||||
console.log("connectAbility");
|
||||
return this.__context_impl__.connectAbility(want, options);
|
||||
}
|
||||
|
||||
startAbilityWithAccount(want, accountId, options, callback) {
|
||||
console.log("startAbilityWithAccount");
|
||||
return this.__context_impl__.startAbilityWithAccount(want, accountId, options, callback);
|
||||
}
|
||||
|
||||
connectAbilityWithAccount(want, accountId, options) {
|
||||
console.log("connectAbilityWithAccount");
|
||||
return this.__context_impl__.connectAbilityWithAccount(want, accountId, options);
|
||||
}
|
||||
|
||||
disconnectAbility(connection, callback) {
|
||||
console.log("disconnectAbility");
|
||||
return this.__context_impl__.disconnectAbility(connection, callback);
|
||||
}
|
||||
|
||||
terminateSelf(callback) {
|
||||
console.log("terminateSelf");
|
||||
return this.__context_impl__.terminateSelf(callback);
|
||||
}
|
||||
}
|
||||
|
||||
export default WallpaperExtensionContext
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "native_engine/native_engine.h"
|
||||
|
||||
extern const char _binary_wallpaper_extension_context_js_start[];
|
||||
extern const char _binary_wallpaper_extension_context_js_end[];
|
||||
extern const char _binary_wallpaper_extension_context_abc_start[];
|
||||
extern const char _binary_wallpaper_extension_context_abc_end[];
|
||||
|
||||
extern "C" __attribute__((constructor))
|
||||
void NAPI_application_WallpaperExtensionContext_AutoRegister()
|
||||
{
|
||||
auto moduleManager = NativeModuleManager::GetInstance();
|
||||
NativeModule newModuleInfo = {
|
||||
.name = "application.WallpaperExtensionContext",
|
||||
.fileName = "application/libwallpaperextensioncontext_napi.so/WallpaperExtensionContext.js",
|
||||
};
|
||||
|
||||
moduleManager->Register(&newModuleInfo);
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default")))
|
||||
void NAPI_application_WallpaperExtensionContext_GetJSCode(const char **buf, int *bufLen)
|
||||
{
|
||||
if (buf != nullptr) {
|
||||
*buf = _binary_wallpaper_extension_context_js_start;
|
||||
}
|
||||
|
||||
if (bufLen != nullptr) {
|
||||
*bufLen = _binary_wallpaper_extension_context_js_end - _binary_wallpaper_extension_context_js_start;
|
||||
}
|
||||
}
|
||||
|
||||
// ability_context JS register
|
||||
extern "C" __attribute__((visibility("default")))
|
||||
void NAPI_application_WallpaperExtensionContext_GetABCCode(const char **buf, int *buflen)
|
||||
{
|
||||
if (buf != nullptr) {
|
||||
*buf = _binary_wallpaper_extension_context_abc_start;
|
||||
}
|
||||
if (buflen != nullptr) {
|
||||
*buflen = _binary_wallpaper_extension_context_abc_end - _binary_wallpaper_extension_context_abc_start;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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.
|
||||
*/
|
||||
#define LOG_TAG "WallpaperJSUtil"
|
||||
#include "wallpaper_js_util.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS::WallpaperNAPI {
|
||||
const static int32_t ARRAY_LENGTH = 4;
|
||||
const static int32_t ZERO = 0;
|
||||
const static int32_t ONE = 1;
|
||||
const static int32_t TWO = 2;
|
||||
const static int32_t THREE = 3;
|
||||
|
||||
std::string WallpaperJSUtil::Convert2String(napi_env env, napi_value jsString)
|
||||
{
|
||||
size_t maxLen = WallpaperJSUtil::MAX_LEN;
|
||||
napi_status status = napi_get_value_string_utf8(env, jsString, NULL, 0, &maxLen);
|
||||
if (status != napi_ok) {
|
||||
GET_AND_THROW_LAST_ERROR((env));
|
||||
maxLen = WallpaperJSUtil::MAX_LEN;
|
||||
}
|
||||
if (maxLen <= 0) {
|
||||
return std::string();
|
||||
}
|
||||
char *buf = new char[maxLen + 1];
|
||||
if (buf == nullptr) {
|
||||
return std::string();
|
||||
}
|
||||
size_t len = 0;
|
||||
status = napi_get_value_string_utf8(env, jsString, buf, maxLen + 1, &len);
|
||||
if (status != napi_ok) {
|
||||
GET_AND_THROW_LAST_ERROR((env));
|
||||
}
|
||||
buf[len] = 0;
|
||||
std::string value(buf);
|
||||
delete[] buf;
|
||||
return value;
|
||||
}
|
||||
|
||||
napi_value WallpaperJSUtil::Convert2JSRgbaArray(napi_env env, const std::vector<RgbaColor> &color)
|
||||
{
|
||||
napi_value result = nullptr;
|
||||
napi_create_array_with_length(env, color.size(), &result);
|
||||
int index = 0;
|
||||
for (const auto it : color) {
|
||||
napi_value element = nullptr;
|
||||
napi_create_array_with_length(env, ARRAY_LENGTH, &element);
|
||||
napi_value jsRgba = nullptr;
|
||||
napi_create_int32(env, it.red, &jsRgba);
|
||||
napi_set_element(env, element, ZERO, jsRgba);
|
||||
jsRgba = nullptr;
|
||||
napi_create_int32(env, it.green, &jsRgba);
|
||||
napi_set_element(env, element, ONE, jsRgba);
|
||||
jsRgba = nullptr;
|
||||
napi_create_int32(env, it.blue, &jsRgba);
|
||||
napi_set_element(env, element, TWO, jsRgba);
|
||||
jsRgba = nullptr;
|
||||
napi_create_int32(env, it.alpha, &jsRgba);
|
||||
napi_set_element(env, element, THREE, jsRgba);
|
||||
napi_set_element(env, result, index++, element);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 WALLPAPER_JS_UTIL_H
|
||||
#define WALLPAPER_JS_UTIL_H
|
||||
|
||||
#include <cstdint>
|
||||
#include "napi/native_common.h"
|
||||
#include "napi/native_api.h"
|
||||
#include "napi/native_node_api.h"
|
||||
#include "wallpaper_manager_common_info.h"
|
||||
|
||||
namespace OHOS::WallpaperNAPI {
|
||||
class WallpaperJSUtil {
|
||||
public:
|
||||
static constexpr int32_t MAX_LEN = 4096;
|
||||
|
||||
static std::string Convert2String(napi_env env, napi_value jsString);
|
||||
static napi_value Convert2JSRgbaArray(napi_env env, const std::vector<RgbaColor> &color);
|
||||
};
|
||||
}
|
||||
#endif // WALLPAPER_JS_UTIL_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.
|
||||
|
||||
import("//ark/ts2abc/ts2panda/ts2abc_config.gni")
|
||||
import("//build/ohos.gni")
|
||||
|
||||
ts2abc_gen_abc("gen_wallpaper_extension_abc") {
|
||||
src_js = rebase_path("wallpaper_extension.js")
|
||||
dst_file = rebase_path(target_out_dir + "/wallpaper_extension.abc")
|
||||
in_puts = [ "wallpaper_extension.js" ]
|
||||
out_puts = [ target_out_dir + "/wallpaper_extension.abc" ]
|
||||
extra_args = [ "--module" ]
|
||||
}
|
||||
|
||||
gen_js_obj("wallpaper_extension_js") {
|
||||
input = "wallpaper_extension.js"
|
||||
output = target_out_dir + "/wallpaper_extension.o"
|
||||
}
|
||||
|
||||
gen_js_obj("wallpaper_extension_abc") {
|
||||
input = get_label_info(":gen_wallpaper_extension_abc", "target_out_dir") +
|
||||
"/wallpaper_extension.abc"
|
||||
output = target_out_dir + "/wallpaper_extension_abc.o"
|
||||
dep = ":gen_wallpaper_extension_abc"
|
||||
}
|
||||
|
||||
ohos_shared_library("wallpaperextension_napi") {
|
||||
sources = [ "wallpaper_extension_module.cpp" ]
|
||||
|
||||
deps = [
|
||||
":wallpaper_extension_abc",
|
||||
":wallpaper_extension_js",
|
||||
]
|
||||
|
||||
external_deps = [ "napi:ace_napi" ]
|
||||
|
||||
relative_install_dir = "module/application"
|
||||
subsystem_name = "miscservices"
|
||||
part_name = "wallpaper_native"
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var WindowManager = requireNapi("window")
|
||||
var WindowName = "wallpaper"
|
||||
var windowType = 2000
|
||||
var windowsCreated = false;
|
||||
|
||||
class WallpaperExtension {
|
||||
createWallpaperWin(){
|
||||
console.log(WindowName + " createWallpaperWin");
|
||||
console.log(this.context);
|
||||
console.log(WindowName + JSON.stringify(this.context));
|
||||
console.log(windowType);
|
||||
console.log(WindowName + JSON.stringify(windowType));
|
||||
|
||||
WindowManager.create(this.context, WindowName, windowType).then((win) => {
|
||||
console.log(WindowName + "wallpaperWindow");
|
||||
this.wallpaperWindow = win;
|
||||
console.log(WindowName + JSON.stringify(this.wallpaperWindow));
|
||||
console.log(this.wallpaperWindow);
|
||||
console.log(WindowName + "moveTo");
|
||||
this.wallpaperWindow.moveTo(0, 0).then(() => {
|
||||
console.log(WindowName + "resetSize");
|
||||
this.wallpaperWindow.resetSize(480, 960).then(() => {
|
||||
console.log(WindowName + " resetSize"+JSON.stringify(this.wallpaperURL));
|
||||
this.loadUiContent(this.wallpaperURL);
|
||||
console.log(WindowName + " window created");
|
||||
windowsCreated = true;
|
||||
})
|
||||
})
|
||||
}, (error) => {
|
||||
console.log(WindowName + " window createFailed, error.code = " + error.code);
|
||||
})
|
||||
}
|
||||
onCreated(want){
|
||||
console.log(WindowName + "onWallpaperExtensionCreated");
|
||||
}
|
||||
|
||||
setUiContent(url) {
|
||||
console.log(WindowName + " setUiContent");
|
||||
if (windowsCreated) {
|
||||
console.log(WindowName + " loadUiContent");
|
||||
loadUiContent(url);
|
||||
} else {
|
||||
console.log(WindowName + " save wallpaperURL");
|
||||
this.wallpaperURL = url;
|
||||
}
|
||||
}
|
||||
|
||||
loadUiContent(url){
|
||||
console.log(WindowName + "initUiContent"+url);
|
||||
console.log(WindowName + JSON.stringify(this.wallpaperWindow));
|
||||
console.log(WindowName + JSON.stringify(this.wallpaperWindow.loadContent));
|
||||
console.log(WindowName + JSON.stringify(this.wallpaperWindow.loadContent(url)));
|
||||
this.wallpaperWindow.loadContent(url).then(() => {
|
||||
console.log(WindowName + " loadContent");
|
||||
this.wallpaperWindow.show().then(() => {
|
||||
console.log(WindowName + " window is show");
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
onWallpaperChanged(wallpaperType){
|
||||
console.log(WindowName + "onWallpaperChanged"+JSON.stringify(wallpaperType));
|
||||
}
|
||||
|
||||
onDestroy(){
|
||||
console.log(WindowName + "onWallpaperExtensionDestroy");
|
||||
}
|
||||
}
|
||||
|
||||
export default WallpaperExtension
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "native_engine/native_engine.h"
|
||||
|
||||
extern const char _binary_wallpaper_extension_js_start[];
|
||||
extern const char _binary_wallpaper_extension_js_end[];
|
||||
extern const char _binary_wallpaper_extension_abc_start[];
|
||||
extern const char _binary_wallpaper_extension_abc_end[];
|
||||
|
||||
extern "C" __attribute__((constructor))
|
||||
void NAPI_application_WallpaperExtension_AutoRegister()
|
||||
{
|
||||
auto moduleManager = NativeModuleManager::GetInstance();
|
||||
NativeModule newModuleInfo = {
|
||||
.name = "application.WallpaperExtension",
|
||||
.fileName = "application/libwallpaperextension_napi.so/WallpaperExtension.js",
|
||||
};
|
||||
|
||||
moduleManager->Register(&newModuleInfo);
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default")))
|
||||
void NAPI_application_WallpaperExtension_GetJSCode(const char **buf, int *bufLen)
|
||||
{
|
||||
if (buf != nullptr) {
|
||||
*buf = _binary_wallpaper_extension_js_start;
|
||||
}
|
||||
|
||||
if (bufLen != nullptr) {
|
||||
*bufLen = _binary_wallpaper_extension_js_end - _binary_wallpaper_extension_js_start;
|
||||
}
|
||||
}
|
||||
|
||||
// wallpaper_extension JS register
|
||||
extern "C" __attribute__((visibility("default")))
|
||||
void NAPI_application_WallpaperExtension_GetABCCode(const char **buf, int *buflen)
|
||||
{
|
||||
if (buf != nullptr) {
|
||||
*buf = _binary_wallpaper_extension_abc_start;
|
||||
}
|
||||
if (buflen != nullptr) {
|
||||
*buflen = _binary_wallpaper_extension_abc_end - _binary_wallpaper_extension_abc_start;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<info>
|
||||
<process>wallpaper_service</process>
|
||||
<systemability>
|
||||
<name>3705</name>
|
||||
<libpath>libwallpaper_service.z.so</libpath>
|
||||
<run-on-create>true</run-on-create>
|
||||
<distributed>false</distributed>
|
||||
<dump-level>1</dump-level>
|
||||
</systemability>
|
||||
</info>
|
||||
@@ -0,0 +1,19 @@
|
||||
# Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos/sa_profile/sa_profile.gni")
|
||||
|
||||
ohos_sa_profile("wallpaper_sa_profiles") {
|
||||
sources = [ "3705.xml" ]
|
||||
part_name = "wallpaper_native"
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
# Copyright (C) 2022 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")
|
||||
import("//base/miscservices/wallpaper/wallpaper.gni")
|
||||
|
||||
config("wallpaper_service_config") {
|
||||
visibility = [ ":*" ]
|
||||
include_dirs = [
|
||||
"include",
|
||||
#"//foundation/multimodalinput/input/interfaces/native/innerkits/common/include",
|
||||
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core/include/bundlemgr",
|
||||
]
|
||||
|
||||
cflags_cc = [ "-fexceptions" ]
|
||||
}
|
||||
|
||||
ohos_shared_library("wallpaper_service") {
|
||||
sources = [
|
||||
"src/wallpaper_service.cpp",
|
||||
"src/wallpaper_service_stub.cpp",
|
||||
"src/wallpaper_service_cb_proxy.cpp",
|
||||
"src/wallpaper_data.cpp",
|
||||
"src/component_name.cpp",
|
||||
"src/wallpaper_common_event.cpp",
|
||||
]
|
||||
public_configs = [
|
||||
"//utils/native/base:utils_config",
|
||||
":wallpaper_service_config",
|
||||
]
|
||||
include_dirs = [
|
||||
#"//foundation/graphic/standard/interfaces/innerkits/surface",
|
||||
"//third_party/json/include",
|
||||
"//base/miscservices/wallpaper/frameworks/innerkitsimpl/wallpaper_manager/include",
|
||||
"//base/miscservices/wallpaper/utils/include",
|
||||
#"//foundation/graphic/standard/interfaces/innerkits/wmclient",
|
||||
#"//foundation/windowmanager/interfaces/innerkits/wm",
|
||||
"//foundation/graphic/standard/rosen/modules/2d_graphics/include",
|
||||
"//foundation/graphic/standard/rosen/modules/2d_graphics/src",
|
||||
#"//foundation/multimodalinput/input/service/window_manager/include",
|
||||
#"//foundation/graphic/ui/interfaces/kits/common",
|
||||
#"//foundation/graphic/utils/interfaces/kits",
|
||||
#"//foundation/graphic/utils/interfaces/innerkits",
|
||||
"//foundation/graphic/standard/rosen/modules/2d_graphics/include/draw",
|
||||
"//foundation/graphic/standard/rosen/modules/2d_graphics/src",
|
||||
"//foundation/graphic/standard/rosen/modules/render_service_client/core/ui",
|
||||
"//foundation/graphic/standard/rosen/modules/render_service_client/core",
|
||||
"//third_party/flutter/engine/flutter/lib/ui/painting",
|
||||
]
|
||||
ldflags = [ "-Wl,-rpath=/system/lib/module/graphic/" ]
|
||||
deps = [
|
||||
"//utils/native/base:utils",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
|
||||
"//foundation/multimedia/image_standard/interfaces/innerkits:image_native",
|
||||
"//base/hiviewdfx/hiview/adapter/utility:hiview_adapter_utility",
|
||||
"${utils_path}:wallpaper_utils",
|
||||
"//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client",
|
||||
#"//foundation/graphic/standard/frameworks/wm:libwmclient",
|
||||
"//foundation/windowmanager/wm:libwm",
|
||||
#"//foundation/windowmanager/interfaces/innerkits:wm_interface",
|
||||
"//foundation/windowmanager/utils:libwmutil",
|
||||
#"//foundation/graphic/ui:lite_ui",
|
||||
#"//foundation/graphic/ui:ui",
|
||||
#"//foundation/graphic/standard:libwms_client",
|
||||
"//foundation/multimedia/image_standard:image_framework",
|
||||
"//foundation/multimedia/image_standard/interfaces/innerkits:image",
|
||||
"//foundation/multimedia/image_standard/interfaces/innerkits:image_native",
|
||||
"//foundation/graphic/standard/frameworks/surface:surface",
|
||||
"//foundation/graphic/standard/rosen/modules/2d_graphics:2d_graphics",
|
||||
"//third_party/libxkbcommon:libxkbcommon",
|
||||
"//third_party/wayland_standard:libwayland_server",
|
||||
"//third_party/weston:libweston",
|
||||
"//foundation/aafwk/standard/services/abilitymgr:abilityms",
|
||||
|
||||
]
|
||||
external_deps = [
|
||||
"ability_runtime:ability_manager",
|
||||
"ability_base:want",
|
||||
#"appexecfwk_standard:appexecfwk_base",
|
||||
#"appexecfwk_standard:appexecfwk_core",
|
||||
#"appexecfwk_standard:libeventhandler",
|
||||
"eventhandler:libeventhandler",
|
||||
"permission_standard:libpermissionsdk_standard",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr_standard:samgr_proxy",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"ces_standard:cesfwk_innerkits",
|
||||
#"graphic:libwms_client",
|
||||
]
|
||||
subsystem_name = "miscservices"
|
||||
part_name = "wallpaper_native"
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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 SERVICES_INCLUDE_WALLPAPER_COMMONENT_NAME_H
|
||||
#define SERVICES_INCLUDE_WALLPAPER_COMMONENT_NAME_H
|
||||
#include <string>
|
||||
|
||||
namespace OHOS {
|
||||
namespace WallpaperMgrService {
|
||||
class ComponentName {
|
||||
public:
|
||||
ComponentName();
|
||||
ComponentName(std::string pkg, std::string cls);
|
||||
/**
|
||||
* * Return the package name of this component.
|
||||
*/
|
||||
std::string GetPackageName();
|
||||
|
||||
/**
|
||||
* Return the class name of this component.
|
||||
*/
|
||||
std::string GetClassName();
|
||||
bool equals(ComponentName& obj);
|
||||
void SetComponentInfo(std::string pkg, std::string cls);
|
||||
private:
|
||||
std::string mPackage;
|
||||
std::string mClass;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 SERVICES_INCLUDE_WALLPAPER_CALLBACK_INTERFACE_H
|
||||
#define SERVICES_INCLUDE_WALLPAPER_CALLBACK_INTERFACE_H
|
||||
|
||||
|
||||
#include "iremote_broker.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace WallpaperMgrService {
|
||||
class IWallpaperCallback : public IRemoteBroker {
|
||||
public:
|
||||
enum Message {
|
||||
ONCALL = 0
|
||||
};
|
||||
virtual int32_t OnCall(const int32_t num) = 0;
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.Wallpaper.IWallpaperCallback");
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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 SERVICES_INCLUDE_WALLPAPER_SERVICE_CALLBACK_INTERFACE_H
|
||||
#define SERVICES_INCLUDE_WALLPAPER_SERVICE_CALLBACK_INTERFACE_H
|
||||
#include <vector>
|
||||
#include "wallpaper_manager_common_info.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace WallpaperMgrService {
|
||||
using namespace std;
|
||||
class IWallpaperManagerCallback {
|
||||
public:
|
||||
virtual void OnWallpaperChanged();
|
||||
/**
|
||||
* Called when wallpaper colors change
|
||||
*/
|
||||
virtual void OnWallpaperColorsChanged(vector<RgbaColor> colors, int which, int userId);
|
||||
};
|
||||
}
|
||||
} // namespace OHOS
|
||||
#endif // SERVICES_INCLUDE_WALLPAPER_SERVICE_CALLBACK_INTERFACE_H
|
||||
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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 SERVICES_INCLUDE_WALLPAPER_SERVICE_INTERFACE_H
|
||||
#define SERVICES_INCLUDE_WALLPAPER_SERVICE_INTERFACE_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "iremote_broker.h"
|
||||
#include "pixel_map.h"
|
||||
#include "pixel_map_parcel.h"
|
||||
#include "wallpaper_manager_common_info.h"
|
||||
#include "wallpaper_color_change_listener.h"
|
||||
#include "iwallpaper_color_change_listener.h"
|
||||
#include "wallpaper_color_change_listener_client.h"
|
||||
#include "i_wallpaper_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace WallpaperMgrService {
|
||||
class IWallpaperService : public IRemoteBroker {
|
||||
public:
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.Wallpaper.IWallpaperService");
|
||||
enum {
|
||||
SET_WALLPAPER_URI_FD,
|
||||
SET_WALLPAPER_MAP,
|
||||
GET_PIXELMAP,
|
||||
GET_PIXELMAPFILE,
|
||||
GET_COLORS,
|
||||
GET_WALLPAPER_ID,
|
||||
GET_WALLPAPER_MIN_HEIGHT,
|
||||
GET_WALLPAPER_MIN_WIDTH,
|
||||
RESET_WALLPAPER,
|
||||
SCREEN_SHOT_LIVE_WALLPAPER,
|
||||
ON,
|
||||
OFF,
|
||||
IS_CHANGE_PERMITTED,
|
||||
IS_OPERATION_ALLOWED,
|
||||
REGISTER_CALLBACK
|
||||
};
|
||||
struct getPixelMap {
|
||||
std::string result;
|
||||
int fileLen;
|
||||
};
|
||||
|
||||
struct mapFD {
|
||||
int fd;
|
||||
int size;
|
||||
};
|
||||
|
||||
/**
|
||||
* Wallpaper set.
|
||||
* @param uriOrPixelMap Wallpaper picture; wallpaperType Wallpaper type, values for WALLPAPER_SYSTEM or
|
||||
* WALLPAPER_LOCKSCREEN
|
||||
* @return true or false
|
||||
*/
|
||||
virtual bool SetWallpaperByFD(int fd, int wallpaperType, int length) = 0;
|
||||
virtual bool SetWallpaperByMap(int fd, int wallpaperType, int length) = 0;
|
||||
virtual mapFD GetPixelMap(int wallpaperType) = 0;
|
||||
/**
|
||||
* Obtains the WallpaperColorsCollection instance for the wallpaper of the specified type.
|
||||
* @param wallpaperType Wallpaper type, values for WALLPAPER_SYSTEM or WALLPAPER_LOCKSCREEN
|
||||
* @return RgbaColor type of array callback function
|
||||
*/
|
||||
virtual std::vector<RgbaColor> GetColors(int wallpaperType)=0;
|
||||
|
||||
/**
|
||||
* Obtains the ID of the wallpaper of the specified type.
|
||||
* @param wallpaperType Wallpaper type, values for WALLPAPER_SYSTEM or WALLPAPER_LOCKSCREEN
|
||||
* @return number type of callback function
|
||||
*/
|
||||
virtual int GetWallpaperId(int wallpaperType)=0;
|
||||
|
||||
/**
|
||||
* Obtains the minimum height of the wallpaper.
|
||||
* @return number type of callback function
|
||||
*/
|
||||
virtual int GetWallpaperMinHeight()=0;
|
||||
|
||||
/**
|
||||
* Obtains the minimum width of the wallpaper.
|
||||
* @return number type of callback function
|
||||
*/
|
||||
virtual int GetWallpaperMinWidth()=0;
|
||||
|
||||
/**
|
||||
* Checks whether to allow the application to change the wallpaper for the current user.
|
||||
* @return boolean type of callback function
|
||||
*/
|
||||
virtual bool IsChangePermitted()=0;
|
||||
|
||||
/**
|
||||
* Checks whether a user is allowed to set wallpapers.
|
||||
* @return boolean type of callback function
|
||||
*/
|
||||
virtual bool IsOperationAllowed()=0;
|
||||
|
||||
/**
|
||||
* Removes a wallpaper of the specified type and restores the default one.
|
||||
* @param wallpaperType Wallpaper type, values for WALLPAPER_SYSTEM or WALLPAPER_LOCKSCREEN
|
||||
* @permission ohos.permission.SET_WALLPAPER
|
||||
*/
|
||||
virtual bool ResetWallpaper(int wallpaperType)=0;
|
||||
|
||||
/**
|
||||
* Screen shot live wallpaper
|
||||
* @param scale
|
||||
* @param pixelFormat
|
||||
* @return image.PixelMap png type The bitmap file of wallpaper
|
||||
* @permission ohos.permission.CAPTURE_SCREEN
|
||||
* @systemapi Hide this for inner system use.
|
||||
* @return true or false
|
||||
*/
|
||||
virtual bool ScreenshotLiveWallpaper(int sacleNumber, OHOS::Media::PixelMap pixelMap) = 0;
|
||||
|
||||
/**
|
||||
* Registers a listener for wallpaper color changes to receive notifications about the changes.
|
||||
* @param type The incoming colorChange table open receiver pick a color change wallpaper wallpaper color changes
|
||||
* @param callback Provides dominant colors of the wallpaper.
|
||||
* @return true or false
|
||||
*/
|
||||
virtual bool On(sptr<IWallpaperColorChangeListener> listener) = 0;
|
||||
|
||||
/**
|
||||
* Registers a listener for wallpaper color changes to receive notifications about the changes.
|
||||
* @param type Incoming 'colorChange' table delete receiver to pick up a color change wallpaper wallpaper color
|
||||
* changes
|
||||
* @param callback Provides dominant colors of the wallpaper.
|
||||
*/
|
||||
virtual bool Off(sptr<IWallpaperColorChangeListener> listener) = 0;
|
||||
|
||||
virtual bool RegisterWallpaperCallback(const sptr<IWallpaperCallback> callback) = 0;
|
||||
};
|
||||
}
|
||||
} // namespace OHOS
|
||||
#endif // SERVICES_INCLUDE_WALLPAPER_SERVICE_INTERFACE_H
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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 WALLPAPER_SERVICES_WALLPAPER_COMMON_EVENT_H
|
||||
#define WALLPAPER_SERVICES_WALLPAPER_COMMON_EVENT_H
|
||||
|
||||
#include <string>
|
||||
#include "common_event_subscriber.h"
|
||||
#include "common_event_support.h"
|
||||
#include "common_event_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace WallpaperMgrService {
|
||||
using CommonEventSubscriber = OHOS::EventFwk::CommonEventSubscriber;
|
||||
using CommonEventData = OHOS::EventFwk::CommonEventData;
|
||||
using CommonEventSubscribeInfo = OHOS::EventFwk::CommonEventSubscribeInfo;
|
||||
static const std::string WALLPAPER_LOCK_SETTING_SUCCESS_EVENT = "com.ohos.wallpaperlocksettingsuccess";
|
||||
static const std::string WALLPAPER_SYSTEM_SETTING_SUCCESS_EVENT = "com.ohos.wallpapersystemsettingsuccess";
|
||||
static const int WALLPAPER_LOCK_SETTING_SUCCESS_CODE = 11000;
|
||||
static const int WALLPAPER_SYSTEM_SETTING_SUCCESS_CODE = 21000;
|
||||
|
||||
class WallpaperCommonEvent : public OHOS::EventFwk::CommonEventSubscriber {
|
||||
public:
|
||||
WallpaperCommonEvent(const OHOS::EventFwk::CommonEventSubscribeInfo &subscriberInfo)
|
||||
: CommonEventSubscriber(subscriberInfo)
|
||||
{}
|
||||
~WallpaperCommonEvent() = default;
|
||||
static std::shared_ptr<WallpaperCommonEvent> subscriber;
|
||||
void OnReceiveEvent(const OHOS::EventFwk::CommonEventData &data) override;
|
||||
static bool PublishEvent(const OHOS::AAFwk::Want &want, int eventCode, const std::string &eventData);
|
||||
static void UnregisterSubscriber(std::shared_ptr<OHOS::EventFwk::CommonEventSubscriber> subscriber);
|
||||
static void RegisterSubscriber();
|
||||
static void SendWallpaperLockSettingMessage();
|
||||
static void SendWallpaperSystemSettingMessage();
|
||||
private:
|
||||
std::function<void(const EventFwk::CommonEventData &)> callback_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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 SERVICES_INCLUDE_WALLPAPER_DATA_H
|
||||
#define SERVICES_INCLUDE_WALLPAPER_DATA_H
|
||||
#include <vector>
|
||||
#include "wallpaper_manager_common_info.h"
|
||||
#include "i_wallpaper_manager_callback.h"
|
||||
#include "component_name.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace WallpaperMgrService {
|
||||
class WallpaperData {
|
||||
public:
|
||||
int userId_;
|
||||
std::string wallpaperFile_; // source image
|
||||
std::string cropFile_; // eventual destination
|
||||
IWallpaperManagerCallback* setComplete;
|
||||
std::string name_;
|
||||
int wallpaperId_;
|
||||
std::vector<RgbaColor> mMainColors_;
|
||||
bool allowBackup;
|
||||
/**
|
||||
* The component name of the currently set live wallpaper.
|
||||
*/
|
||||
ComponentName wallpaperComponent;
|
||||
|
||||
public:
|
||||
WallpaperData(int userId, std::string wallpaperFileName, std::string cropFileName);
|
||||
// Called during initialization of a given user's wallpaper bookkeeping
|
||||
bool cropExists();
|
||||
/* {
|
||||
return cropFile.exists();
|
||||
} */
|
||||
|
||||
bool sourceExists();
|
||||
/* {
|
||||
return wallpaperFile.exists();
|
||||
} */
|
||||
private:
|
||||
};
|
||||
}
|
||||
} // namespace OHOS
|
||||
#endif // SERVICES_INCLUDE_WALLPAPER_DATA_H
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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 INNERKITS_WALLPAPER_ON_COLORS_CHANGED_LISTENER_H
|
||||
#define INNERKITS_WALLPAPER_ON_COLORS_CHANGED_LISTENER_H
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "wallpaper_manager_common_info.h"
|
||||
|
||||
class WallpaperOnColorsChangedListener {
|
||||
public:
|
||||
virtual void onColorsChanged(std::vector<RgbaColor> color, int wallpaperType) = 0;
|
||||
};
|
||||
#endif
|
||||
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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 SERVICES_INCLUDE_WALLPAPER_SERVICES_H
|
||||
#define SERVICES_INCLUDE_WALLPAPER_SERVICES_H
|
||||
|
||||
#include <mutex>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include "system_ability.h"
|
||||
#include "wallpaper_service_stub.h"
|
||||
#include "wallpaper_common.h"
|
||||
#include "event_handler.h"
|
||||
#include "pixel_map.h"
|
||||
#include "wallpaper_manager_common_info.h"
|
||||
#include "wallpaper_color_change_listener.h"
|
||||
#include "wallpaper_data.h"
|
||||
#include "i_wallpaper_manager_callback.h"
|
||||
#include "component_name.h"
|
||||
#include "file_deal.h"
|
||||
#include "wm_common.h"
|
||||
#include "window_option.h"
|
||||
#include "surface_buffer.h"
|
||||
|
||||
|
||||
|
||||
namespace OHOS {
|
||||
namespace WallpaperMgrService {
|
||||
enum class ServiceRunningState {
|
||||
STATE_NOT_START,
|
||||
STATE_RUNNING
|
||||
};
|
||||
|
||||
class WallpaperService : public SystemAbility, public WallpaperServiceStub {
|
||||
DECLARE_SYSTEM_ABILITY(WallpaperService);
|
||||
|
||||
public:
|
||||
DISALLOW_COPY_AND_MOVE(WallpaperService);
|
||||
|
||||
WallpaperService(int32_t systemAbilityId, bool runOnCreate);
|
||||
WallpaperService();
|
||||
~WallpaperService();
|
||||
|
||||
static sptr<WallpaperService> GetInstance();
|
||||
bool SetWallpaperByFD(int fd, int wallpaperType, int length) override;
|
||||
bool SetWallpaperByMap(int fd, int wallpaperType, int length) override;
|
||||
mapFD GetPixelMap(int wallpaperType) override;
|
||||
std::vector<RgbaColor> GetColors(int wallpaperType) override;
|
||||
int GetWallpaperId(int wallpaperType) override;
|
||||
int GetWallpaperMinHeight() override;
|
||||
int GetWallpaperMinWidth() override;
|
||||
bool IsChangePermitted() override;
|
||||
bool IsOperationAllowed() override;
|
||||
bool ResetWallpaper(int wallpaperType) override;
|
||||
bool ScreenshotLiveWallpaper(int scaleNumber, OHOS::Media::PixelMap pixelMap) override;
|
||||
bool On(sptr<IWallpaperColorChangeListener> listener) override;
|
||||
bool Off(sptr<IWallpaperColorChangeListener> listener) override;
|
||||
bool RegisterWallpaperCallback(const sptr<IWallpaperCallback> callback) override;
|
||||
public:
|
||||
void WallpaperDump(int fd);
|
||||
bool SetLockWallpaperCallback(IWallpaperManagerCallback* cb);
|
||||
static void OnBootPhase();
|
||||
|
||||
protected:
|
||||
void OnStart() override;
|
||||
void OnStop() override;
|
||||
|
||||
private:
|
||||
/**
|
||||
* Get current user id.
|
||||
* @param none
|
||||
* @return userid
|
||||
*/
|
||||
int GetUserId();
|
||||
|
||||
/**
|
||||
* Get current Display Id.
|
||||
* @param none
|
||||
* @return displayid
|
||||
*/
|
||||
int GetDisplayId();
|
||||
|
||||
/**
|
||||
* initData ,such as dir,filename,and so on.
|
||||
* @param
|
||||
* @return none
|
||||
*/
|
||||
void InitData();
|
||||
int64_t WritePixelMapToFile(const std::string &filePath, std::unique_ptr< OHOS::Media::PixelMap> pixelMap);
|
||||
void LoadSettingsLocked(int userId, bool keepDimensionHints);
|
||||
std::string GetWallpaperDir(int userId);
|
||||
void NotifyLockWallpaperChanged();
|
||||
void MigrateFromOld();
|
||||
bool BindWallpaperComponentLocked(ComponentName& componentName, bool force, bool fromUser, WallpaperData wallpaper);
|
||||
bool GetWallpaperSafeLocked(int userId, int wpType, WallpaperData paperdata);
|
||||
void ClearWallpaperLocked(int userId, int wpType);
|
||||
bool SetDefaultDateForWallpaper(int userId, int wpType);
|
||||
int MakeWallpaperIdLocked();
|
||||
bool ChangingToSame(ComponentName componentName, WallpaperData wallpaper);
|
||||
bool WPCheckCallingPermission(const std::string &promissionName);
|
||||
bool WPGetBundleNameByUid(std::int32_t uid, std::string &bname);
|
||||
bool MakeCropWallpaper(int wallpaperType);
|
||||
bool SetWallpaperBackupData(std::string uriOrPixelMap, int wallpaperType);
|
||||
|
||||
private:
|
||||
void StartExt();
|
||||
int32_t Init();
|
||||
ServiceRunningState state_;
|
||||
void InitServiceHandler();
|
||||
static std::mutex instanceLock_;
|
||||
static sptr<WallpaperService> instance_;
|
||||
static std::shared_ptr<AppExecFwk::EventHandler> serviceHandler_;
|
||||
std::string wallpaperLockScreenFilePath_;
|
||||
std::string wallpaperSystemFilePath_;
|
||||
std::string wallpaperLockScreenFileFullPath_;
|
||||
std::string wallpaperSystemFileFullPath_;
|
||||
std::string wallpaperLockScreenCropFileFullPath_;
|
||||
std::string wallpaperSystemCropFileFullPath_;
|
||||
std::string wallpaperTmpFullPath_;
|
||||
std::string wallpaperCropPath;
|
||||
typedef std::map<int, WallpaperColorChangeListener*> DISPLAYIDCOLORSLISTENERMAP;
|
||||
typedef std::map<int, DISPLAYIDCOLORSLISTENERMAP> COLORSLISTENERMAP;
|
||||
typedef std::list<WallpaperColorChangeListener*> LISTENERLIST;
|
||||
LISTENERLIST colorListeners_;
|
||||
COLORSLISTENERMAP colorsChangedListeners_;
|
||||
std::map<int, WallpaperData> wallpaperMap_ ;
|
||||
std::map<int, WallpaperData> lockWallpaperMap_ ;
|
||||
int wallpaperId_;
|
||||
int userId_;
|
||||
IWallpaperManagerCallback *keyguardListener_;
|
||||
static const std::string WALLPAPER;
|
||||
static const std::string WALLPAPER_CROP;
|
||||
static const std::string WALLPAPER_LOCK_ORIG;
|
||||
static const std::string WALLPAPER_LOCK_CROP;
|
||||
sptr<IWallpaperCallback> callbackProxy = nullptr;
|
||||
|
||||
std::string name_;
|
||||
std::mutex mtx;
|
||||
};
|
||||
}
|
||||
} // OHOS
|
||||
#endif // SERVICES_INCLUDE_WALLPAPER_SERVICES_H
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 SERVICES_INCLUDE_WALLPAPER_SERVICE_CB_PROXY_H
|
||||
#define SERVICES_INCLUDE_WALLPAPER_SERVICE_CB_PROXY_H
|
||||
|
||||
|
||||
#include "iremote_proxy.h"
|
||||
#include "iremote_object.h"
|
||||
#include "i_wallpaper_callback.h"
|
||||
|
||||
|
||||
namespace OHOS {
|
||||
namespace WallpaperMgrService {
|
||||
|
||||
class WallpaperServiceCbProxy : public IRemoteProxy<IWallpaperCallback> {
|
||||
public:
|
||||
explicit WallpaperServiceCbProxy(const sptr<IRemoteObject> &object) : IRemoteProxy<IWallpaperCallback>(object) {}
|
||||
virtual ~WallpaperServiceCbProxy() {};
|
||||
|
||||
static inline BrokerDelegator<WallpaperServiceCbProxy> delegator_;
|
||||
|
||||
int32_t OnCall(const int32_t num) override;
|
||||
};
|
||||
|
||||
} // namespace WallpaperMgrService
|
||||
} // namespace OHOS
|
||||
#endif // SERVICES_INCLUDE_WALLPAPER_SERVICE_CB_PROXY_H
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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 SERVICES_INCLUDE_WALLPAPER_SERVICE_STUB_H
|
||||
#define SERVICES_INCLUDE_WALLPAPER_SERVICE_STUB_H
|
||||
|
||||
#include<map>
|
||||
#include "iremote_stub.h"
|
||||
#include "i_wallpaper_service.h"
|
||||
#include "ipc_skeleton.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace WallpaperMgrService {
|
||||
class WallpaperServiceStub : public IRemoteStub<IWallpaperService> {
|
||||
public:
|
||||
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
|
||||
WallpaperServiceStub();
|
||||
~WallpaperServiceStub();
|
||||
private:
|
||||
int32_t OnSetWallpaperUriByFD(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t OnSetWallpaperByMap(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t OnGetPixelMapFile(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t OnGetPixelMap(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t OnGetColors(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t OnGetWallpaperId(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t OnGetWallpaperMinHeight(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t OnGetWallpaperMinWidth(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t OnIsChangePermitted(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t OnIsOperationAllowed(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t OnResetWallpaper(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t OnScreenshotLiveWallpaper(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t OnWallpaperOn(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t OnWallpaperOff(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t OnRegisterWallpaperCallback(MessageParcel &data, MessageParcel &reply);
|
||||
using WallpaperServiceFunc = int32_t (WallpaperServiceStub::*)(MessageParcel &data, MessageParcel &reply);
|
||||
std::map<uint32_t, WallpaperServiceFunc> memberFuncMap_;
|
||||
};
|
||||
}
|
||||
} // namespace OHOS
|
||||
#endif // SERVICES_INCLUDE_WALLPAPER_SERVICE_STUB_H
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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 "component_name.h"
|
||||
namespace OHOS {
|
||||
namespace WallpaperMgrService {
|
||||
ComponentName::ComponentName()
|
||||
{}
|
||||
|
||||
ComponentName::ComponentName(std::string pkg, std::string cls)
|
||||
{
|
||||
mPackage = pkg;
|
||||
mClass = cls;
|
||||
}
|
||||
|
||||
void ComponentName::SetComponentInfo(std::string pkg, std::string cls)
|
||||
{
|
||||
mPackage = pkg;
|
||||
mClass = cls;
|
||||
}
|
||||
|
||||
std::string ComponentName::GetPackageName()
|
||||
{
|
||||
return mPackage;
|
||||
}
|
||||
std::string ComponentName::GetClassName()
|
||||
{
|
||||
return mClass;
|
||||
}
|
||||
|
||||
bool ComponentName::equals(ComponentName& obj)
|
||||
{
|
||||
try {
|
||||
// Note: no null checks, because mPackage and mClass can
|
||||
// never be null.
|
||||
return mPackage==obj.GetPackageName()
|
||||
&& mClass==obj.GetClassName();
|
||||
} catch (std::exception e) {
|
||||
// DO NOTHING
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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 "wallpaper_common_event.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "wallpaper_service.h"
|
||||
namespace OHOS {
|
||||
namespace WallpaperMgrService {
|
||||
constexpr int FIVETIMES = 5;
|
||||
std::shared_ptr<WallpaperCommonEvent> WallpaperCommonEvent::subscriber = nullptr;
|
||||
|
||||
void WallpaperCommonEvent::OnReceiveEvent(const OHOS::EventFwk::CommonEventData &data)
|
||||
{
|
||||
HILOG_INFO("WallpaperCommonEvent::OnReceiveEvent");
|
||||
WallpaperService::OnBootPhase();
|
||||
}
|
||||
|
||||
bool WallpaperCommonEvent::PublishEvent(const OHOS::AAFwk::Want &want, int eventCode, const std::string &eventData)
|
||||
{
|
||||
OHOS::EventFwk::CommonEventData data;
|
||||
data.SetWant(want);
|
||||
data.SetCode(eventCode);
|
||||
data.SetData(eventData);
|
||||
OHOS::EventFwk::CommonEventPublishInfo publishInfo;
|
||||
publishInfo.SetOrdered(true);
|
||||
bool publishResult = OHOS::EventFwk::CommonEventManager::PublishCommonEvent(data, publishInfo, nullptr);
|
||||
HILOG_INFO("PublishEvent end publishResult = %{public}d", publishResult);
|
||||
return publishResult;
|
||||
}
|
||||
|
||||
|
||||
void WallpaperCommonEvent::UnregisterSubscriber(std::shared_ptr<OHOS::EventFwk::CommonEventSubscriber> subscriber)
|
||||
{
|
||||
if (subscriber != nullptr) {
|
||||
bool subscribeResult = OHOS::EventFwk::CommonEventManager::UnSubscribeCommonEvent(subscriber);
|
||||
subscriber = nullptr;
|
||||
HILOG_INFO("WallpaperCommonEvent::UnregisterSubscriber end###subscribeResult = %{public}d", subscribeResult);
|
||||
}
|
||||
}
|
||||
|
||||
void WallpaperCommonEvent::RegisterSubscriber()
|
||||
{
|
||||
HILOG_INFO("WallpaperCommonEvent::RegisterSubscriber");
|
||||
OHOS::EventFwk::MatchingSkills matchingSkills;
|
||||
HILOG_INFO("WallpaperCommonEvent::AddEvent");
|
||||
matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED);
|
||||
HILOG_INFO("WallpaperCommonEvent::subscriberInfo");
|
||||
OHOS::EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
|
||||
subscriber = std::make_shared<WallpaperCommonEvent>(subscriberInfo);
|
||||
int time = 0;
|
||||
HILOG_INFO("WallpaperCommonEvent::SubscribeCommonEvent");
|
||||
bool subscribeResult = false;
|
||||
while (1) {
|
||||
subscribeResult = OHOS::EventFwk::CommonEventManager::SubscribeCommonEvent(subscriber);
|
||||
time++;
|
||||
if (subscribeResult || time >= FIVETIMES) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (subscribeResult) {
|
||||
HILOG_INFO("WallpaperCommonEvent::subscribeResult == true");
|
||||
} else {
|
||||
HILOG_INFO("WallpaperCommonEvent::time out");
|
||||
}
|
||||
}
|
||||
|
||||
void WallpaperCommonEvent::SendWallpaperLockSettingMessage()
|
||||
{
|
||||
OHOS::AAFwk::Want want;
|
||||
int32_t eventCode = WALLPAPER_LOCK_SETTING_SUCCESS_CODE;
|
||||
want.SetParam("WallpaperLockSettingMessage", true);
|
||||
want.SetAction(WALLPAPER_LOCK_SETTING_SUCCESS_EVENT);
|
||||
std::string eventData("WallpaperLockSettingMessage");
|
||||
PublishEvent(want, eventCode, eventData);
|
||||
}
|
||||
|
||||
void WallpaperCommonEvent::SendWallpaperSystemSettingMessage()
|
||||
{
|
||||
OHOS::AAFwk::Want want;
|
||||
int32_t eventCode = WALLPAPER_SYSTEM_SETTING_SUCCESS_CODE;
|
||||
want.SetParam("WallpaperSystemSettingMessage", true);
|
||||
want.SetAction(WALLPAPER_SYSTEM_SETTING_SUCCESS_EVENT);
|
||||
std::string eventData("WallpaperSystemSettingMessage");
|
||||
PublishEvent(want, eventCode, eventData);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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 "wallpaper_data.h"
|
||||
#include "file_ex.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace WallpaperMgrService {
|
||||
WallpaperData::WallpaperData(int userId, std::string wallpaperFileName, std::string cropFileName)
|
||||
{
|
||||
userId_ = userId;
|
||||
wallpaperFile_ = wallpaperFileName; // source image
|
||||
cropFile_ = cropFileName;
|
||||
}
|
||||
// Called during initialization of a given user's wallpaper bookkeeping
|
||||
bool WallpaperData::cropExists()
|
||||
{
|
||||
if (!OHOS::FileExists(cropFile_)) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool WallpaperData::sourceExists()
|
||||
{
|
||||
if (!OHOS::FileExists(wallpaperFile_)) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -0,0 +1,946 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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 <thread>
|
||||
#include <cerrno>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <sys/sendfile.h>
|
||||
#include <window_manager.h>
|
||||
#include <display_type.h>
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
#include <rs_surface_node.h>
|
||||
#include "hilog_wrapper.h"
|
||||
#include "system_ability_definition.h"
|
||||
#include "wallpaper_common_event.h"
|
||||
#include "image_utils.h"
|
||||
#include "file_ex.h"
|
||||
#include "directory_ex.h"
|
||||
#include "file_util.h"
|
||||
#include "time_util.h"
|
||||
#include "image_packer.h"
|
||||
#include "bundle_mgr_interface.h"
|
||||
#include "permission/permission_kit.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "image/bitmap.h"
|
||||
#include "pixel_map.h"
|
||||
#include "image_type.h"
|
||||
#include "image_utils.h"
|
||||
#include "image_source.h"
|
||||
#include "canvas.h"
|
||||
#include "pen.h"
|
||||
#include "wallpaper_service.h"
|
||||
#include "surface.h"
|
||||
#include "window.h"
|
||||
#include "wallpaper_service_cb_proxy.h"
|
||||
#include "ability_manager_client.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace WallpaperMgrService {
|
||||
REGISTER_SYSTEM_ABILITY_BY_ID(WallpaperService, WALLPAPER_MANAGER_SERVICE_ID, true);
|
||||
|
||||
using namespace OHOS::Media;
|
||||
using namespace OHOS::HiviewDFX::FileUtil;
|
||||
using namespace OHOS::HiviewDFX::TimeUtil;
|
||||
|
||||
const std::string WallpaperService::WALLPAPER = "wallpaper_orig";
|
||||
const std::string WallpaperService::WALLPAPER_CROP = "wallpaper";
|
||||
const std::string WallpaperService::WALLPAPER_LOCK_ORIG = "wallpaper_lock_orig";
|
||||
const std::string WallpaperService::WALLPAPER_LOCK_CROP = "wallpaper_lock";
|
||||
|
||||
const std::int64_t INIT_INTERVAL = 10000L;
|
||||
constexpr int SCREEN_WIDTH = 480;
|
||||
constexpr int SCREEN_HEIGHT = 960;
|
||||
|
||||
constexpr int HALF = 2;
|
||||
constexpr int DOUBLE = 2;
|
||||
constexpr int THREE = 3;
|
||||
constexpr int FORE = 4;
|
||||
constexpr int FIVE = 5;
|
||||
constexpr int six = 6;
|
||||
constexpr int TEN = 10;
|
||||
constexpr int FIFTY = 50;
|
||||
constexpr int HUNDRED = 100;
|
||||
constexpr int HUNDRED_FIFTY = 150;
|
||||
constexpr int FOO_MAX_LEN = 52428800;
|
||||
std::mutex WallpaperService::instanceLock_;
|
||||
|
||||
sptr<WallpaperService> WallpaperService::instance_;
|
||||
|
||||
std::shared_ptr<AppExecFwk::EventHandler> WallpaperService::serviceHandler_;
|
||||
|
||||
WallpaperService::WallpaperService(int32_t systemAbilityId, bool runOnCreate)
|
||||
: SystemAbility(systemAbilityId, runOnCreate), state_(ServiceRunningState::STATE_NOT_START)
|
||||
{
|
||||
}
|
||||
|
||||
WallpaperService::WallpaperService() : state_(ServiceRunningState::STATE_NOT_START)
|
||||
{
|
||||
InitData();
|
||||
}
|
||||
|
||||
WallpaperService::~WallpaperService()
|
||||
{
|
||||
}
|
||||
|
||||
sptr<WallpaperService> WallpaperService::GetInstance()
|
||||
{
|
||||
if (instance_ == nullptr) {
|
||||
std::lock_guard<std::mutex> autoLock(instanceLock_);
|
||||
if (instance_ == nullptr) {
|
||||
instance_ = new WallpaperService();
|
||||
}
|
||||
}
|
||||
return instance_;
|
||||
}
|
||||
|
||||
int32_t WallpaperService::Init()
|
||||
{
|
||||
bool ret = Publish(WallpaperService::GetInstance());
|
||||
if (!ret) {
|
||||
HILOG_ERROR("Publish failed.");
|
||||
return -1;
|
||||
}
|
||||
HILOG_INFO("Publish success.");
|
||||
state_ = ServiceRunningState::STATE_RUNNING;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void WallpaperService::OnStart()
|
||||
{
|
||||
HILOG_INFO("Enter OnStart.");
|
||||
if (state_ == ServiceRunningState::STATE_RUNNING) {
|
||||
HILOG_ERROR("WallpaperService is already running.");
|
||||
return;
|
||||
}
|
||||
|
||||
InitServiceHandler();
|
||||
if (Init() != 0) {
|
||||
auto callback = [=]() { Init(); };
|
||||
serviceHandler_->PostTask(callback, INIT_INTERVAL);
|
||||
HILOG_ERROR("Init failed. Try again 10s later");
|
||||
return;
|
||||
}
|
||||
HILOG_INFO("RegisterSubscriber");
|
||||
OHOS::EventFwk::MatchingSkills matchingSkills;
|
||||
HILOG_INFO("WallpaperCommonEvent::AddEvent");
|
||||
matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED);
|
||||
HILOG_INFO("WallpaperCommonEvent::subscriberInfo");
|
||||
OHOS::EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
|
||||
std::shared_ptr<EventFwk::CommonEventSubscriber> subscriberPtr_ = std::make_shared<WallpaperCommonEvent>(subscriberInfo);
|
||||
bool subRes = OHOS::EventFwk::CommonEventManager::SubscribeCommonEvent(subscriberPtr_);
|
||||
if (subRes == false) {
|
||||
HILOG_INFO("RegisterSubscriber failed");
|
||||
} else {
|
||||
HILOG_INFO("RegisterSubscriber success");
|
||||
}
|
||||
HILOG_INFO("RegisterSubscriber end");
|
||||
|
||||
std::thread(&WallpaperService::StartExt,this).detach();
|
||||
return;
|
||||
}
|
||||
|
||||
void WallpaperService::InitServiceHandler()
|
||||
{
|
||||
HILOG_INFO("InitServiceHandler started.");
|
||||
if (serviceHandler_ != nullptr) {
|
||||
HILOG_ERROR("InitServiceHandler already init.");
|
||||
return;
|
||||
}
|
||||
std::shared_ptr<AppExecFwk::EventRunner> runner =
|
||||
AppExecFwk::EventRunner::Create("WallpaperService");
|
||||
serviceHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
|
||||
|
||||
HILOG_INFO("InitServiceHandler succeeded.");
|
||||
}
|
||||
|
||||
void WallpaperService::OnStop()
|
||||
{
|
||||
HILOG_INFO("OnStop started.");
|
||||
if (state_ != ServiceRunningState::STATE_RUNNING) {
|
||||
return;
|
||||
}
|
||||
serviceHandler_ = nullptr;
|
||||
state_ = ServiceRunningState::STATE_NOT_START;
|
||||
HILOG_INFO("OnStop end.");
|
||||
}
|
||||
|
||||
|
||||
void WallpaperService::InitData()
|
||||
{
|
||||
HILOG_INFO("WallpaperService::initData --> start ");
|
||||
userId_ = 0;
|
||||
wallpaperId_ = 0;
|
||||
wallpaperMap_.clear();
|
||||
lockWallpaperMap_.clear();
|
||||
userId_ = GetUserId();
|
||||
std::string userIdPath = GetWallpaperDir(userId_);
|
||||
this->wallpaperLockScreenFilePath_ = userIdPath +
|
||||
"/" + WALLPAPER_DIRNAME + "/" + WALLPAPER_LOCKSCREEN_DIRNAME;
|
||||
this->wallpaperSystemFilePath_ = userIdPath +
|
||||
"/" + WALLPAPER_DIRNAME + "/" + WALLPAPER_SYSTEM_DIRNAME;
|
||||
wallpaperLockScreenFileFullPath_ = wallpaperLockScreenFilePath_ + "/" + WALLPAPER_LOCK_ORIG;
|
||||
wallpaperLockScreenCropFileFullPath_ = wallpaperLockScreenFilePath_ + "/" + WALLPAPER_LOCK_CROP;
|
||||
wallpaperSystemCropFileFullPath_ = wallpaperSystemFilePath_ + "/" + WALLPAPER_CROP;
|
||||
wallpaperSystemFileFullPath_ = wallpaperSystemFilePath_ + "/" + WALLPAPER;
|
||||
wallpaperTmpFullPath_ = wallpaperSystemFilePath_ + "/" + WALLPAPER_TMP_DIRNAME;
|
||||
wallpaperCropPath = wallpaperSystemFilePath_ + "/" + WALLPAPER_CROP_PICTURE;
|
||||
LoadSettingsLocked(userId_, true);
|
||||
HILOG_INFO("WallpaperService::initData --> end ");
|
||||
}
|
||||
void WallpaperService::StartExt()
|
||||
{
|
||||
HILOG_INFO("WallpaperService StartExt");
|
||||
int time = 0;
|
||||
ErrCode ret = 0;
|
||||
AAFwk::Want want;
|
||||
want.SetElementName("com.example.ohosproject.hmservice", "WallpaperExtAbility");
|
||||
AAFwk::AbilityManagerClient::GetInstance()->Connect();
|
||||
HILOG_INFO("WallpaperService::Startwhile");
|
||||
while (1)
|
||||
{
|
||||
HILOG_INFO("WallpaperService::StartAbility");
|
||||
time++;
|
||||
ret = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want);
|
||||
if (ret == 0 || time == TEN) {
|
||||
break;
|
||||
}
|
||||
sleep(six);
|
||||
HILOG_INFO("WallpaperService::StartAbility %{public}d",time);
|
||||
}
|
||||
if (ret != 0) {
|
||||
HILOG_INFO("WallpaperService::StartAbility --> faild ");
|
||||
}
|
||||
}
|
||||
void WallpaperService::OnBootPhase()
|
||||
{
|
||||
HILOG_INFO("WallpaperService OnBootPhase");
|
||||
AAFwk::Want want;
|
||||
want.SetElementName("com.example.ohosproject.hmservice", "WallpaperExtAbility");
|
||||
AAFwk::AbilityManagerClient::GetInstance()->Connect();
|
||||
ErrCode ret = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want);
|
||||
}
|
||||
|
||||
int WallpaperService::GetUserId()
|
||||
{
|
||||
userId_ = 0;
|
||||
return userId_;
|
||||
}
|
||||
|
||||
int WallpaperService::GetDisplayId()
|
||||
{
|
||||
int displayid = 0;
|
||||
return displayid;
|
||||
}
|
||||
|
||||
std::string WallpaperService::GetWallpaperDir(int userId)
|
||||
{
|
||||
std::string sWallpaperPath = "/data";
|
||||
sWallpaperPath = WALLPAPER_USERID_PATH + std::to_string(userId_);
|
||||
return sWallpaperPath;
|
||||
}
|
||||
|
||||
int WallpaperService::MakeWallpaperIdLocked()
|
||||
{
|
||||
do {
|
||||
++wallpaperId_;
|
||||
} while (wallpaperId_ == 0);
|
||||
return wallpaperId_;
|
||||
}
|
||||
|
||||
void WallpaperService::LoadSettingsLocked(int userId, bool keepDimensionHints)
|
||||
{
|
||||
HILOG_INFO("load Setting locked start.");
|
||||
std::map<int, WallpaperData>::iterator itr;
|
||||
std::map<int, WallpaperData>::iterator itrLock;
|
||||
itr = wallpaperMap_.find(userId);
|
||||
itrLock = lockWallpaperMap_.find(userId);
|
||||
|
||||
if (itr == wallpaperMap_.end()) {
|
||||
MigrateFromOld();
|
||||
WallpaperData wallpaper(userId, wallpaperSystemFileFullPath_, wallpaperSystemCropFileFullPath_);
|
||||
wallpaper.allowBackup = true;
|
||||
wallpaper.wallpaperId_ = MakeWallpaperIdLocked();
|
||||
wallpaperMap_.insert(std::pair<int, WallpaperData>(userId, wallpaper));
|
||||
}
|
||||
|
||||
if (itrLock == lockWallpaperMap_.end()) {
|
||||
WallpaperData wallpaperLock(userId, wallpaperLockScreenFileFullPath_, wallpaperLockScreenCropFileFullPath_);
|
||||
wallpaperLock.allowBackup = true;
|
||||
wallpaperLock.wallpaperId_ = MakeWallpaperIdLocked();
|
||||
lockWallpaperMap_.insert(std::pair<int, WallpaperData>(userId, wallpaperLock));
|
||||
}
|
||||
HILOG_INFO("load Setting locked end.");
|
||||
}
|
||||
|
||||
bool WallpaperService::ChangingToSame(ComponentName componentName, WallpaperData wallpaper)
|
||||
{
|
||||
if (wallpaper.wallpaperComponent.equals(componentName)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
bool WallpaperService::BindWallpaperComponentLocked(ComponentName& componentName,
|
||||
bool force, bool fromUser, WallpaperData wallpaper)
|
||||
{
|
||||
if (!force && ChangingToSame(componentName, wallpaper)) {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WallpaperService::SetLockWallpaperCallback(IWallpaperManagerCallback* cb)
|
||||
{
|
||||
keyguardListener_ = cb;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void WallpaperService::MigrateFromOld()
|
||||
{
|
||||
int ret = 0;
|
||||
if (!OHOS::FileExists(wallpaperLockScreenFilePath_)) {
|
||||
if (!OHOS::ForceCreateDirectory(wallpaperLockScreenFilePath_)) {
|
||||
return ;
|
||||
}
|
||||
}
|
||||
if (!OHOS::FileExists(wallpaperSystemFilePath_)) {
|
||||
if (!OHOS::ForceCreateDirectory(wallpaperSystemFilePath_)) {
|
||||
return ;
|
||||
}
|
||||
}
|
||||
if (OHOS::FileExists(wallpaperSystemCropFileFullPath_)) {
|
||||
if (!OHOS::FileExists(wallpaperSystemFileFullPath_)) {
|
||||
ret = OHOS::HiviewDFX::FileUtil::CopyFile(wallpaperSystemCropFileFullPath_,
|
||||
wallpaperSystemFileFullPath_);
|
||||
if (ret < 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if (OHOS::FileExists(WALLPAPER_DEFAULT_FILEFULLPATH)) {
|
||||
ret = OHOS::HiviewDFX::FileUtil::CopyFile(WALLPAPER_DEFAULT_FILEFULLPATH, wallpaperSystemCropFileFullPath_);
|
||||
if (ret < 0) {
|
||||
return;
|
||||
}
|
||||
ret = OHOS::HiviewDFX::FileUtil::CopyFile(WALLPAPER_DEFAULT_FILEFULLPATH,
|
||||
wallpaperSystemFileFullPath_);
|
||||
if (ret < 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (OHOS::FileExists(wallpaperLockScreenCropFileFullPath_)) {
|
||||
if (!OHOS::FileExists(wallpaperLockScreenFileFullPath_)) {
|
||||
ret = OHOS::HiviewDFX::FileUtil::CopyFile(wallpaperLockScreenCropFileFullPath_,
|
||||
wallpaperLockScreenFileFullPath_);
|
||||
if (ret < 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if (OHOS::FileExists(WALLPAPER_DEFAULT_LOCK_FILEFULLPATH)) {
|
||||
ret = OHOS::HiviewDFX::FileUtil::CopyFile(WALLPAPER_DEFAULT_LOCK_FILEFULLPATH,
|
||||
wallpaperLockScreenCropFileFullPath_);
|
||||
if (ret < 0) {
|
||||
return;
|
||||
}
|
||||
ret = OHOS::HiviewDFX::FileUtil::CopyFile(WALLPAPER_DEFAULT_LOCK_FILEFULLPATH,
|
||||
wallpaperLockScreenFileFullPath_);
|
||||
if (ret < 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<RgbaColor> WallpaperService::GetColors(int wallpaperType)
|
||||
{
|
||||
std::vector<RgbaColor> Colors;
|
||||
RgbaColor tmpColor;
|
||||
for (int32_t indx = 0; indx < FIVE; indx++) {
|
||||
tmpColor.red = HUNDRED + DOUBLE * indx;
|
||||
tmpColor.blue = FIFTY + THREE * indx;
|
||||
tmpColor.green = FIFTY + FORE * indx;
|
||||
tmpColor.alpha = HUNDRED_FIFTY + DOUBLE * indx;
|
||||
Colors.emplace_back(tmpColor);
|
||||
}
|
||||
HILOG_INFO(" Service End!");
|
||||
return Colors;
|
||||
}
|
||||
|
||||
int64_t WallpaperService::WritePixelMapToFile(const std::string &filePath, std::unique_ptr<PixelMap> pixelMap)
|
||||
{
|
||||
ImagePacker imagePacker;
|
||||
PackOption option;
|
||||
option.format = "image/jpeg";
|
||||
option.quality = HUNDRED;
|
||||
option.numberHint = 1;
|
||||
std::set<std::string> formats;
|
||||
uint32_t ret = imagePacker.GetSupportedFormats(formats);
|
||||
if (ret != 0) {
|
||||
return 0;
|
||||
}
|
||||
imagePacker.StartPacking(filePath, option);
|
||||
HILOG_INFO("AddImage start");
|
||||
imagePacker.AddImage(*pixelMap);
|
||||
int64_t packedSize = 0;
|
||||
HILOG_INFO("FinalizePacking start");
|
||||
imagePacker.FinalizePacking(packedSize);
|
||||
return packedSize;
|
||||
}
|
||||
|
||||
bool WallpaperService::MakeCropWallpaper(int wallpaperType)
|
||||
{
|
||||
uint32_t errorCode = 0;
|
||||
bool ret = false;
|
||||
OHOS::Media::SourceOptions opts;
|
||||
opts.formatHint = "image/jpeg";
|
||||
|
||||
std::unique_ptr<OHOS::Media::ImageSource> imageSource =
|
||||
OHOS::Media::ImageSource::CreateImageSource((wallpaperType == WALLPAPER_SYSTEM ?
|
||||
wallpaperSystemFileFullPath_: wallpaperLockScreenFileFullPath_), opts, errorCode);
|
||||
if (errorCode != 0) {
|
||||
return ret;
|
||||
}
|
||||
OHOS::Media::DecodeOptions decodeOpts;
|
||||
std::unique_ptr<PixelMap> wallpaperPixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
if (errorCode != 0) {
|
||||
return ret;
|
||||
}
|
||||
int32_t pictrueHeight = wallpaperPixelMap->GetHeight();
|
||||
int32_t pictrueWidth = wallpaperPixelMap->GetWidth();
|
||||
if (pictrueHeight > SCREEN_HEIGHT && pictrueWidth > SCREEN_WIDTH) {
|
||||
decodeOpts.CropRect.top = (pictrueHeight - SCREEN_HEIGHT)/HALF;
|
||||
decodeOpts.CropRect.width = SCREEN_WIDTH;
|
||||
decodeOpts.CropRect.left = (pictrueWidth - SCREEN_WIDTH)/HALF;
|
||||
decodeOpts.CropRect.height = SCREEN_HEIGHT;
|
||||
decodeOpts.desiredSize.width = SCREEN_WIDTH;
|
||||
decodeOpts.desiredSize.height = SCREEN_HEIGHT;
|
||||
}
|
||||
wallpaperPixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
if (errorCode != 0) {
|
||||
ret = false;
|
||||
} else {
|
||||
std::string tmpPath = wallpaperCropPath;
|
||||
int64_t packedSize = WritePixelMapToFile(tmpPath, std::move(wallpaperPixelMap));
|
||||
if (packedSize != 0) {
|
||||
ret = CopyFile(tmpPath, (wallpaperType == WALLPAPER_SYSTEM ? wallpaperSystemCropFileFullPath_:
|
||||
wallpaperLockScreenCropFileFullPath_));
|
||||
if (remove(tmpPath.c_str()) < 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
HILOG_INFO("End Crop wallpaper: ret= %{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool WallpaperService::SetWallpaperByMap(int fd, int wallpaperType, int length)
|
||||
{
|
||||
mtx.lock();
|
||||
HILOG_INFO("SetWallpaperByMap");
|
||||
std::unique_ptr<OHOS::Media::PixelMap> tmp;
|
||||
std::string url = wallpaperTmpFullPath_;
|
||||
if (length == 0 || length > FOO_MAX_LEN) {
|
||||
return false;
|
||||
}
|
||||
char* paperBuf = new char[length];
|
||||
int32_t bufsize = read(fd, paperBuf, length);
|
||||
if (bufsize <= 0) {
|
||||
HILOG_ERROR("read fd faild");
|
||||
return false;
|
||||
}
|
||||
close(fd);
|
||||
std::stringbuf *stringBuf = new std::stringbuf();
|
||||
stringBuf->sputn(paperBuf, length);
|
||||
std::istream pixelmapStream(stringBuf);
|
||||
std::unique_ptr<std::istream> tmpStream(&pixelmapStream);
|
||||
|
||||
uint32_t errorCode = 0;
|
||||
OHOS::Media::SourceOptions opts;
|
||||
opts.formatHint = "image/jpeg";
|
||||
HILOG_INFO(" CreateImageSource");
|
||||
std::unique_ptr<OHOS::Media::ImageSource> imageSource =
|
||||
OHOS::Media::ImageSource::CreateImageSource(std::move(tmpStream), opts, errorCode);
|
||||
|
||||
if (errorCode != 0) {
|
||||
HILOG_ERROR("ImageSource::CreateImageSource failed,errcode= %{public}d", errorCode);
|
||||
return false;
|
||||
}
|
||||
|
||||
OHOS::Media::DecodeOptions decodeOpts;
|
||||
HILOG_INFO(" CreatePixelMap");
|
||||
tmp = imageSource->CreatePixelMap(decodeOpts, errorCode);
|
||||
if (errorCode != 0) {
|
||||
HILOG_ERROR("ImageSource::CreatePixelMap failed,errcode= %{public}d", errorCode);
|
||||
return false;
|
||||
}
|
||||
int64_t packedSize = WritePixelMapToFile(url, std::move(tmp));
|
||||
if (packedSize <= 0) {
|
||||
HILOG_ERROR("WritePixelMapToFile faild");
|
||||
return false;
|
||||
}
|
||||
mtx.unlock();
|
||||
return SetWallpaperBackupData(url, wallpaperType);
|
||||
}
|
||||
bool WallpaperService::SetWallpaperByFD(int fd, int wallpaperType, int length)
|
||||
{
|
||||
mtx.lock();
|
||||
HILOG_INFO("SetWallpaperByFD");
|
||||
std::string url = wallpaperTmpFullPath_;
|
||||
if (length == 0 || length > FOO_MAX_LEN) {
|
||||
return false;
|
||||
}
|
||||
char* paperBuf = new char[length];
|
||||
int readSize = read(fd, paperBuf, length);
|
||||
if (readSize <= 0) {
|
||||
HILOG_ERROR("read from fd fail");
|
||||
return false;
|
||||
}
|
||||
|
||||
int fdw = open(url.c_str(), O_WRONLY | O_CREAT, 0770);
|
||||
if (fdw == -1) {
|
||||
HILOG_ERROR("WallpaperService:: fdw fail");
|
||||
return false;
|
||||
}
|
||||
int writeSize = write(fdw, paperBuf, length);
|
||||
if (writeSize <= 0) {
|
||||
HILOG_ERROR("write to fdw fail");
|
||||
return false;
|
||||
}
|
||||
close(fd);
|
||||
close(fdw);
|
||||
mtx.unlock();
|
||||
return SetWallpaperBackupData(url, wallpaperType);
|
||||
}
|
||||
|
||||
|
||||
bool WallpaperService::SetWallpaperBackupData(std::string uriOrPixelMap, int wallpaperType)
|
||||
{
|
||||
mtx.lock();
|
||||
HILOG_INFO("set wallpaper and backup data Start.");
|
||||
if (wallpaperType != WALLPAPER_LOCKSCREEN && wallpaperType != WALLPAPER_SYSTEM) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!OHOS::FileExists(uriOrPixelMap)) {
|
||||
return false;
|
||||
}
|
||||
WallpaperData tmpWP(userId_,
|
||||
(wallpaperType == WALLPAPER_SYSTEM ? wallpaperSystemFileFullPath_:
|
||||
wallpaperLockScreenFileFullPath_),
|
||||
(wallpaperType == WALLPAPER_SYSTEM ? wallpaperSystemCropFileFullPath_:
|
||||
wallpaperLockScreenCropFileFullPath_));
|
||||
|
||||
bool ret = GetWallpaperSafeLocked(userId_, wallpaperType, tmpWP);
|
||||
if (!ret) {
|
||||
HILOG_ERROR("GetWallpaperSafeLocked failed !");
|
||||
return false;
|
||||
}
|
||||
|
||||
tmpWP.wallpaperId_ = MakeWallpaperIdLocked();
|
||||
|
||||
bool retFileCp = CopyFile(uriOrPixelMap, (wallpaperType ==
|
||||
WALLPAPER_SYSTEM ? wallpaperSystemFileFullPath_:wallpaperLockScreenFileFullPath_));
|
||||
bool retCropFileCp = MakeCropWallpaper(wallpaperType);
|
||||
if (wallpaperType == WALLPAPER_SYSTEM) {
|
||||
wallpaperMap_.insert(std::pair<int, WallpaperData>(userId_, tmpWP));
|
||||
WallpaperCommonEvent::SendWallpaperSystemSettingMessage();
|
||||
HILOG_INFO(" SetWallpaperBackupData callbackProxy->OnCall start");
|
||||
if (callbackProxy != nullptr) {
|
||||
callbackProxy->OnCall(wallpaperType);
|
||||
}
|
||||
} else if (wallpaperType == WALLPAPER_LOCKSCREEN) {
|
||||
lockWallpaperMap_.insert(std::pair<int, WallpaperData>(userId_, tmpWP));
|
||||
WallpaperCommonEvent::SendWallpaperLockSettingMessage();
|
||||
HILOG_INFO(" SetWallpaperBackupData callbackProxy->OnCall start");
|
||||
if (callbackProxy != nullptr) {
|
||||
callbackProxy->OnCall(wallpaperType);
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (remove(uriOrPixelMap.c_str()) < 0) {
|
||||
return false;
|
||||
}
|
||||
mtx.unlock();
|
||||
return !retFileCp && !retCropFileCp;
|
||||
}
|
||||
IWallpaperService::mapFD WallpaperService::GetPixelMap(int wallpaperType)
|
||||
{
|
||||
mtx.lock();
|
||||
mapFD mapFd;
|
||||
HILOG_INFO("WallpaperService::getPixelMap --> start ");
|
||||
|
||||
std::string filePath = "";
|
||||
|
||||
if (wallpaperType == WALLPAPER_LOCKSCREEN) {
|
||||
filePath = lockWallpaperMap_.find(userId_)->second.cropFile_;
|
||||
} else if (wallpaperType == WALLPAPER_SYSTEM) {
|
||||
filePath = wallpaperMap_.find(userId_)->second.cropFile_;
|
||||
}
|
||||
|
||||
if (!OHOS::FileExists(filePath)) {
|
||||
HILOG_ERROR("file is not exist!");
|
||||
return mapFd;
|
||||
}
|
||||
FILE *pixmap = fopen(filePath.c_str(), "rb");
|
||||
if (pixmap == nullptr) {
|
||||
HILOG_ERROR("fopen faild");
|
||||
return mapFd;
|
||||
}
|
||||
int fend = fseek(pixmap, 0, SEEK_END);
|
||||
if (fend != 0) {
|
||||
HILOG_ERROR("fseek faild");
|
||||
return mapFd;
|
||||
}
|
||||
int length = ftell(pixmap);
|
||||
if (length <= 0) {
|
||||
HILOG_ERROR("ftell faild");
|
||||
return mapFd;
|
||||
}
|
||||
mapFd.size = length;
|
||||
int fset = fseek(pixmap, 0, SEEK_SET);
|
||||
if (fset != 0) {
|
||||
HILOG_ERROR("fseek faild");
|
||||
return mapFd;
|
||||
}
|
||||
int closeRes = fclose(pixmap);
|
||||
if (closeRes != 0) {
|
||||
HILOG_ERROR("fclose faild");
|
||||
return mapFd;
|
||||
}
|
||||
int fd = open(filePath.c_str(), O_RDONLY, 0770);
|
||||
if (fd < 0) {
|
||||
HILOG_ERROR("open faild");
|
||||
return mapFd;
|
||||
}
|
||||
mapFd.fd = fd;
|
||||
HILOG_INFO("mapFd.fd = %{public}d",mapFd.fd);
|
||||
mtx.unlock();
|
||||
return mapFd;
|
||||
}
|
||||
|
||||
int WallpaperService::GetWallpaperId(int wallpaperType)
|
||||
{
|
||||
HILOG_INFO("WallpaperService::GetWallpaperId --> start ");
|
||||
int iWallpaperId = 1;
|
||||
if (wallpaperType == WALLPAPER_LOCKSCREEN) {
|
||||
iWallpaperId = lockWallpaperMap_.find(userId_)->second.wallpaperId_;
|
||||
} else if (wallpaperType == WALLPAPER_SYSTEM) {
|
||||
iWallpaperId = wallpaperMap_.find(userId_)->second.wallpaperId_;
|
||||
}
|
||||
HILOG_INFO("WallpaperService::GetWallpaperId --> end ID[%{public}d]", iWallpaperId);
|
||||
return iWallpaperId;
|
||||
}
|
||||
int WallpaperService::GetWallpaperMinHeight()
|
||||
{
|
||||
HILOG_INFO("WallpaperService::GetWallpaperMinHeight --> start ");
|
||||
int iWallpaperMinHeight = 960;
|
||||
return iWallpaperMinHeight;
|
||||
}
|
||||
|
||||
int WallpaperService::GetWallpaperMinWidth()
|
||||
{
|
||||
HILOG_INFO("WallpaperService::GetWallpaperMinWidth --> start ");
|
||||
int iWallpaperMinWidth = 480;
|
||||
return iWallpaperMinWidth;
|
||||
}
|
||||
|
||||
bool WallpaperService::IsChangePermitted()
|
||||
{
|
||||
bool bFlag = false;
|
||||
string permissionName = WALLPAPER_PERMISSION_NAME_SET_WALLPAPER;
|
||||
std::int32_t uid = IPCSkeleton::GetCallingUid();
|
||||
std::string bundleName;
|
||||
if (!WPGetBundleNameByUid(uid, bundleName)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
HILOG_INFO("Check permission: %{public}s", permissionName.c_str());
|
||||
bFlag = Security::Permission::PermissionKit::CanRequestPermission(bundleName, permissionName, userId_);
|
||||
return bFlag;
|
||||
}
|
||||
|
||||
bool WallpaperService::IsOperationAllowed()
|
||||
{
|
||||
bool bFlag = WPCheckCallingPermission(WALLPAPER_PERMISSION_NAME_SET_WALLPAPER);
|
||||
return bFlag;
|
||||
}
|
||||
|
||||
bool WallpaperService::ResetWallpaper(int wallpaperType)
|
||||
{
|
||||
HILOG_INFO("reset wallpaper Start!");
|
||||
bool bFlag = false;
|
||||
if (wallpaperType != WALLPAPER_LOCKSCREEN && wallpaperType != WALLPAPER_SYSTEM) {
|
||||
HILOG_INFO("wallpaperType = %{public}d type not support ", wallpaperType);
|
||||
return bFlag;
|
||||
}
|
||||
|
||||
ClearWallpaperLocked(userId_, wallpaperType);
|
||||
bFlag = SetDefaultDateForWallpaper(userId_, wallpaperType);
|
||||
HILOG_INFO(" Set default data result[%{public}d]", bFlag);
|
||||
|
||||
std::map<int, WallpaperData>::iterator itr;
|
||||
if (wallpaperType == WALLPAPER_LOCKSCREEN) {
|
||||
itr = lockWallpaperMap_.find(userId_);
|
||||
} else {
|
||||
itr = wallpaperMap_.find(userId_);
|
||||
}
|
||||
|
||||
if (itr != lockWallpaperMap_.end()) {
|
||||
bFlag = true;
|
||||
}
|
||||
HILOG_INFO("reset wallpaper End!");
|
||||
return bFlag;
|
||||
}
|
||||
|
||||
bool WallpaperService::SetDefaultDateForWallpaper(int userId, int wpType)
|
||||
{
|
||||
std::string tmpPath = "";
|
||||
std::string tmpCropPath = "";
|
||||
bool ret = false;
|
||||
if (wpType == WALLPAPER_LOCKSCREEN) {
|
||||
if (!OHOS::FileExists(wallpaperLockScreenFilePath_)) {
|
||||
if (!OHOS::ForceCreateDirectory(wallpaperLockScreenFilePath_)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (OHOS::FileExists(WALLPAPER_DEFAULT_FILEFULLPATH)) {
|
||||
if (CopyFile(WALLPAPER_DEFAULT_FILEFULLPATH, wallpaperLockScreenCropFileFullPath_)) {
|
||||
return false;
|
||||
}
|
||||
ret = CopyFile(WALLPAPER_DEFAULT_FILEFULLPATH, wallpaperLockScreenFileFullPath_);
|
||||
if (ret == true) {
|
||||
return false;
|
||||
}
|
||||
WallpaperCommonEvent::SendWallpaperLockSettingMessage();
|
||||
HILOG_INFO("SetDefaultDateForWallpaper callbackProxy->OnCall start");
|
||||
if (callbackProxy != nullptr) {
|
||||
callbackProxy->OnCall(wpType);
|
||||
}
|
||||
}
|
||||
tmpPath = wallpaperLockScreenFileFullPath_;
|
||||
tmpCropPath = wallpaperLockScreenCropFileFullPath_;
|
||||
} else {
|
||||
if (!OHOS::FileExists(wallpaperSystemFilePath_)) {
|
||||
if (!OHOS::ForceCreateDirectory(wallpaperSystemFilePath_)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (OHOS::FileExists(WALLPAPER_DEFAULT_FILEFULLPATH)) {
|
||||
ret = CopyFile(WALLPAPER_DEFAULT_FILEFULLPATH, wallpaperSystemCropFileFullPath_);
|
||||
if (ret == true) {
|
||||
return false;
|
||||
}
|
||||
ret = CopyFile(WALLPAPER_DEFAULT_FILEFULLPATH, wallpaperSystemFileFullPath_);
|
||||
if (ret == true) {
|
||||
return false;
|
||||
}
|
||||
WallpaperCommonEvent::SendWallpaperSystemSettingMessage();
|
||||
HILOG_INFO("SetDefaultDateForWallpaper callbackProxy->OnCall start");
|
||||
if (callbackProxy != nullptr) {
|
||||
callbackProxy->OnCall(wpType);
|
||||
}
|
||||
}
|
||||
tmpPath = wallpaperSystemFileFullPath_;
|
||||
tmpCropPath = wallpaperSystemCropFileFullPath_;
|
||||
}
|
||||
WallpaperData sdwpdata(userId, tmpPath, tmpCropPath);
|
||||
sdwpdata.wallpaperId_ = 0;
|
||||
sdwpdata.allowBackup = true;
|
||||
if (wpType == WALLPAPER_LOCKSCREEN) {
|
||||
lockWallpaperMap_.insert(std::pair<int, WallpaperData>(userId, sdwpdata));
|
||||
} else {
|
||||
wallpaperMap_.insert(std::pair<int, WallpaperData>(userId, sdwpdata));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool WallpaperService::ScreenshotLiveWallpaper(int scaleNumber, OHOS::Media::PixelMap pixelMap)
|
||||
{
|
||||
bool bFlag = false;
|
||||
return bFlag;
|
||||
}
|
||||
|
||||
bool WallpaperService::On(sptr<IWallpaperColorChangeListener> listener)
|
||||
{
|
||||
std::vector<RgbaColor> Colors;
|
||||
RgbaColor tmpColor;
|
||||
for (int32_t indx = 0; indx < FIVE; indx++) {
|
||||
tmpColor.red = HUNDRED + DOUBLE * indx;
|
||||
tmpColor.blue = FIFTY + THREE * indx;
|
||||
tmpColor.green = FIFTY + FORE * indx;
|
||||
tmpColor.alpha = HUNDRED_FIFTY + DOUBLE * indx;
|
||||
Colors.emplace_back(tmpColor);
|
||||
}
|
||||
listener->onColorsChange(Colors, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WallpaperService::Off(sptr<IWallpaperColorChangeListener> listener)
|
||||
{
|
||||
HILOG_DEBUG("WallpaperService::Off in");
|
||||
std::vector<RgbaColor> Colors;
|
||||
HILOG_INFO(" Service Start!");
|
||||
RgbaColor tmpColor;
|
||||
for (int32_t indx = 0; indx < FIVE; indx++) {
|
||||
tmpColor.red = HUNDRED + DOUBLE * indx;
|
||||
tmpColor.blue = FIFTY + THREE * indx;
|
||||
tmpColor.green = FIFTY + FORE * indx;
|
||||
tmpColor.alpha = HUNDRED_FIFTY + DOUBLE * indx;
|
||||
Colors.emplace_back(tmpColor);
|
||||
}
|
||||
listener->onColorsChange(Colors, 0);
|
||||
HILOG_DEBUG("WallpaperService::Off out");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WallpaperService::RegisterWallpaperCallback(const sptr<IWallpaperCallback> callback)
|
||||
{
|
||||
HILOG_INFO(" WallpaperService::RegisterWallpaperCallback");
|
||||
callbackProxy = callback;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WallpaperService::GetWallpaperSafeLocked(int userId, int wpType, WallpaperData paperdata)
|
||||
{
|
||||
HILOG_INFO("function start.");
|
||||
bool ret = true;
|
||||
std::map<int, WallpaperData>::iterator itr;
|
||||
if (wpType == WALLPAPER_LOCKSCREEN) {
|
||||
itr = lockWallpaperMap_.find(userId);
|
||||
if (itr == lockWallpaperMap_.end()) {
|
||||
HILOG_INFO(" No Lock wallpaper? Not tracking for lock-only ");
|
||||
LoadSettingsLocked(userId, true);
|
||||
itr = lockWallpaperMap_.find(userId);
|
||||
if (itr == lockWallpaperMap_.end()) {
|
||||
ret = false;
|
||||
HILOG_INFO("default data is saved into mLockWallpaperMap failed.");
|
||||
}
|
||||
}
|
||||
if (ret) {
|
||||
paperdata.wallpaperId_ = itr->second.wallpaperId_;
|
||||
paperdata.allowBackup = itr->second.allowBackup;
|
||||
}
|
||||
} else {
|
||||
itr = wallpaperMap_.find(userId);
|
||||
if (itr == wallpaperMap_.end()) {
|
||||
HILOG_INFO(" No system wallpaper? Not tracking for lock-only ");
|
||||
LoadSettingsLocked(userId, true);
|
||||
itr = wallpaperMap_.find(userId);
|
||||
if (itr == wallpaperMap_.end()) {
|
||||
ret = false;
|
||||
HILOG_INFO("default data is saved into mWallpaperMap failed.");
|
||||
}
|
||||
}
|
||||
if (ret) {
|
||||
paperdata.wallpaperId_ = itr->second.wallpaperId_;
|
||||
paperdata.allowBackup = itr->second.allowBackup;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void WallpaperService::ClearWallpaperLocked(int userId, int wpType)
|
||||
{
|
||||
HILOG_INFO("Clear wallpaper Start!");
|
||||
std::map<int, WallpaperData>::iterator itr;
|
||||
if (wpType == WALLPAPER_LOCKSCREEN) {
|
||||
itr = lockWallpaperMap_.find(userId);
|
||||
if (itr == lockWallpaperMap_.end()) {
|
||||
HILOG_INFO("Lock wallpaper already cleared");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
itr = wallpaperMap_.find(userId);
|
||||
if (itr == wallpaperMap_.end()) {
|
||||
HILOG_INFO("system wallpaper already cleared");
|
||||
LoadSettingsLocked(userId, true);
|
||||
itr = wallpaperMap_.find(userId);
|
||||
}
|
||||
if (itr == wallpaperMap_.end()) {
|
||||
HILOG_INFO("system wallpaper already cleared too");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (itr->second.wallpaperFile_.size() != 0) {
|
||||
if (wpType == WALLPAPER_LOCKSCREEN) {
|
||||
lockWallpaperMap_.erase(itr);
|
||||
} else {
|
||||
wallpaperMap_.erase(itr);
|
||||
}
|
||||
}
|
||||
HILOG_INFO("Clear wallpaper End!");
|
||||
}
|
||||
|
||||
bool WallpaperService::WPCheckCallingPermission(const std::string &permissionName)
|
||||
{
|
||||
if (permissionName.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::int32_t uid = IPCSkeleton::GetCallingUid();
|
||||
std::string bundleName;
|
||||
if (!WPGetBundleNameByUid(uid, bundleName)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
HILOG_INFO("Check permission: %{public}s", permissionName.c_str());
|
||||
|
||||
return (Security::Permission::PermissionKit::VerifyPermission(bundleName, permissionName, userId_) ==
|
||||
Security::Permission::PermissionState::PERMISSION_GRANTED);
|
||||
}
|
||||
|
||||
bool WallpaperService::WPGetBundleNameByUid(std::int32_t uid, std::string &bname)
|
||||
{
|
||||
sptr<ISystemAbilityManager> systemMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (systemMgr == nullptr) {
|
||||
HILOG_ERROR("Fail to get system ability mgr");
|
||||
return false;
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> remoteObject = systemMgr->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
|
||||
if (remoteObject == nullptr) {
|
||||
HILOG_ERROR("Fail to get bundle manager proxy");
|
||||
return false;
|
||||
}
|
||||
|
||||
sptr<OHOS::AppExecFwk::IBundleMgr> bundleMgrProxy = iface_cast<OHOS::AppExecFwk::IBundleMgr>(remoteObject);
|
||||
if (bundleMgrProxy == nullptr) {
|
||||
HILOG_ERROR("Bundle mgr proxy is nullptr");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!bundleMgrProxy->GetBundleNameForUid(uid, bname)) {
|
||||
HILOG_ERROR("Get bundle name failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
void WallpaperService::WallpaperDump(int fd)
|
||||
{
|
||||
dprintf(fd, "\n - Wallpaper System State :\n");
|
||||
dprintf(fd, " * UserId = %d\n", userId_);
|
||||
dprintf(fd, " * WallpaperId = %d\n", wallpaperId_);
|
||||
int32_t height = GetWallpaperMinHeight();
|
||||
dprintf(fd, " * heigh = %d\n", height);
|
||||
int32_t width = GetWallpaperMinWidth();
|
||||
dprintf(fd, " * heigh = %d\n", width);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 "wallpaper_service_cb_proxy.h"
|
||||
#include "hilog_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace WallpaperMgrService {
|
||||
int32_t WallpaperServiceCbProxy::OnCall(const int32_t wallpaperType)
|
||||
{
|
||||
HILOG_INFO(" WallpaperServiceCbProxy::OnCall start");
|
||||
MessageParcel data, reply;
|
||||
MessageOption option;
|
||||
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
HILOG_ERROR(" Failed to write parcelable ");
|
||||
return -1;
|
||||
}
|
||||
if (!data.WriteInt32(wallpaperType)) {
|
||||
HILOG_ERROR(" Failed to WriteInt32 ");
|
||||
return -1;
|
||||
}
|
||||
HILOG_INFO(" WallpaperServiceCbProxy::Remote()->SendRequest");
|
||||
int32_t result = Remote()->SendRequest(ONCALL, data, reply, option);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,293 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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 "wallpaper_service_stub.h"
|
||||
#include "parcel.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "wallpaper_common.h"
|
||||
#include "pixel_map.h"
|
||||
#include "ashmem.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace WallpaperMgrService {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
using namespace OHOS::Media;
|
||||
|
||||
WallpaperServiceStub::WallpaperServiceStub()
|
||||
{
|
||||
memberFuncMap_[SET_WALLPAPER_URI_FD] = &WallpaperServiceStub::OnSetWallpaperUriByFD;
|
||||
memberFuncMap_[SET_WALLPAPER_MAP] = &WallpaperServiceStub::OnSetWallpaperByMap;
|
||||
memberFuncMap_[GET_PIXELMAP] = &WallpaperServiceStub::OnGetPixelMap;
|
||||
memberFuncMap_[GET_COLORS] = &WallpaperServiceStub::OnGetColors;
|
||||
memberFuncMap_[GET_WALLPAPER_ID] = &WallpaperServiceStub::OnGetWallpaperId;
|
||||
memberFuncMap_[GET_WALLPAPER_MIN_HEIGHT] = &WallpaperServiceStub::OnGetWallpaperMinHeight;
|
||||
memberFuncMap_[GET_WALLPAPER_MIN_WIDTH] = &WallpaperServiceStub::OnGetWallpaperMinWidth;
|
||||
memberFuncMap_[SCREEN_SHOT_LIVE_WALLPAPER] = &WallpaperServiceStub::OnScreenshotLiveWallpaper;
|
||||
memberFuncMap_[ON] = &WallpaperServiceStub::OnWallpaperOn;
|
||||
memberFuncMap_[OFF] = &WallpaperServiceStub::OnWallpaperOff;
|
||||
memberFuncMap_[IS_CHANGE_PERMITTED] = &WallpaperServiceStub::OnIsChangePermitted;
|
||||
memberFuncMap_[IS_OPERATION_ALLOWED] = &WallpaperServiceStub::OnIsOperationAllowed;
|
||||
memberFuncMap_[RESET_WALLPAPER] = &WallpaperServiceStub::OnResetWallpaper;
|
||||
memberFuncMap_[REGISTER_CALLBACK] = &WallpaperServiceStub::OnRegisterWallpaperCallback;
|
||||
}
|
||||
|
||||
WallpaperServiceStub::~WallpaperServiceStub()
|
||||
{
|
||||
memberFuncMap_.clear();
|
||||
}
|
||||
|
||||
int32_t WallpaperServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option)
|
||||
{
|
||||
HILOG_INFO(" start##ret = %{public}u", code);
|
||||
std::u16string myDescripter = WallpaperServiceStub::GetDescriptor();
|
||||
std::u16string remoteDescripter = data.ReadInterfaceToken();
|
||||
if (myDescripter != remoteDescripter) {
|
||||
HILOG_ERROR(" end##descriptor checked fail");
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
pid_t p = IPCSkeleton::GetCallingPid();
|
||||
pid_t p1 = IPCSkeleton::GetCallingUid();
|
||||
HILOG_INFO("CallingPid = %{public}d, CallingUid = %{public}d, code = %{public}u", p, p1, code);
|
||||
auto itFunc = memberFuncMap_.find(code);
|
||||
if (itFunc != memberFuncMap_.end()) {
|
||||
auto memberFunc = itFunc->second;
|
||||
if (memberFunc != nullptr) {
|
||||
return (this->*memberFunc)(data, reply);
|
||||
}
|
||||
}
|
||||
int ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
HILOG_INFO(" end##ret = %{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
int32_t WallpaperServiceStub::OnSetWallpaperByMap(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
int32_t ret = -1;
|
||||
HILOG_INFO("WallpaperServiceStub::SetWallpaperUri start.");
|
||||
|
||||
int fd = data.ReadFileDescriptor();
|
||||
int wallpaperType = data.ReadInt32();
|
||||
int length = data.ReadInt32();
|
||||
bool bFlag = SetWallpaperByMap(fd, wallpaperType, length);
|
||||
reply.WriteBool(bFlag);
|
||||
|
||||
ret = bFlag == true ? 0:-1;
|
||||
return ret;
|
||||
}
|
||||
int32_t WallpaperServiceStub::OnSetWallpaperUriByFD(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
int32_t ret = -1;
|
||||
HILOG_INFO("WallpaperServiceStub::SetWallpaperUri start.");
|
||||
|
||||
int fd = data.ReadFileDescriptor();
|
||||
int wallpaperType = data.ReadInt32();
|
||||
HILOG_INFO("wallpaperType= %{public}d", wallpaperType);
|
||||
int length = data.ReadInt32();
|
||||
HILOG_INFO("SetWallpaperByFD start");
|
||||
bool bFlag = SetWallpaperByFD(fd, wallpaperType, length);
|
||||
reply.WriteBool(bFlag);
|
||||
|
||||
ret = bFlag == true ? 0:-1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int32_t WallpaperServiceStub::OnGetPixelMap(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
int32_t ret = 0;
|
||||
HILOG_INFO("WallpaperServiceStub::GetPixelMap start.");
|
||||
|
||||
int wallpaperType = data.ReadInt32();
|
||||
IWallpaperService::mapFD mapFd = GetPixelMap(wallpaperType);
|
||||
if (!reply.WriteInt32(mapFd.size)) {
|
||||
HILOG_ERROR("WriteInt32 fail");
|
||||
ret = -1;
|
||||
}
|
||||
if (!reply.WriteFileDescriptor(mapFd.fd)) {
|
||||
HILOG_ERROR("WriteFileDescriptor fail");
|
||||
ret = -1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t WallpaperServiceStub::OnGetColors(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
int32_t ret = -1;
|
||||
HILOG_INFO("WallpaperServiceStub::OnGetColors start.");
|
||||
|
||||
int wallpaperType = data.ReadInt32();
|
||||
std::vector<RgbaColor> vecWallpaperColors = GetColors(wallpaperType);
|
||||
|
||||
unsigned int size = vecWallpaperColors.size();
|
||||
reply.WriteInt32(size);
|
||||
for (unsigned int i = 0; i < size; ++i) {
|
||||
reply.WriteInt32(vecWallpaperColors[i].red);
|
||||
reply.WriteInt32(vecWallpaperColors[i].blue);
|
||||
reply.WriteInt32(vecWallpaperColors[i].green);
|
||||
reply.WriteInt32(vecWallpaperColors[i].alpha);
|
||||
}
|
||||
HILOG_DEBUG("End. size[%{public}d]LastData[%{public}d][%{public}d][%{public}d][%{public}d]",
|
||||
size, vecWallpaperColors[size-1].red, vecWallpaperColors[size-1].blue,
|
||||
vecWallpaperColors[size-1].green, vecWallpaperColors[size-1].alpha);
|
||||
|
||||
ret = (size == 0) ? 0:-1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t WallpaperServiceStub::OnGetWallpaperId(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
HILOG_INFO("WallpaperServiceStub::OnGetWallpaperId start.");
|
||||
|
||||
int wallpaperType = data.ReadInt32();
|
||||
int wallpaerid = GetWallpaperId(wallpaperType);
|
||||
if (!reply.WriteInt32(wallpaerid)) {
|
||||
HILOG_ERROR("Write result data failed");
|
||||
}
|
||||
HILOG_INFO("End. Id[%{public}d]", wallpaerid);
|
||||
return wallpaerid;
|
||||
}
|
||||
|
||||
int32_t WallpaperServiceStub::OnGetWallpaperMinHeight(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
HILOG_INFO("WallpaperServiceStub::OnGetWallpaperMinHeight start.");
|
||||
int wallpaerMinHeight = GetWallpaperMinHeight();
|
||||
if (!reply.WriteInt32(wallpaerMinHeight)) {
|
||||
HILOG_ERROR("Write result data failed");
|
||||
}
|
||||
HILOG_INFO("End. height[%{public}d]", wallpaerMinHeight);
|
||||
return wallpaerMinHeight;
|
||||
}
|
||||
|
||||
int32_t WallpaperServiceStub::OnGetWallpaperMinWidth(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
HILOG_INFO("WallpaperServiceStub::OnGetWallpaperMinWidth start.");
|
||||
|
||||
int wallpaperMinWidth = GetWallpaperMinWidth();
|
||||
if (!reply.WriteInt32(wallpaperMinWidth)) {
|
||||
HILOG_ERROR("Write result data failed");
|
||||
}
|
||||
HILOG_INFO("End. width[%{public}d]", wallpaperMinWidth);
|
||||
return wallpaperMinWidth;
|
||||
}
|
||||
|
||||
int32_t WallpaperServiceStub::OnIsChangePermitted(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
int32_t ret = -1;
|
||||
HILOG_INFO("WallpaperServiceStub::OnIsChangePermitted start.");
|
||||
auto bResult = IsChangePermitted();
|
||||
if (!reply.WriteBool(bResult)) {
|
||||
HILOG_ERROR("Write result data failed");
|
||||
}
|
||||
ret = (bResult == true) ? 0:-1;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t WallpaperServiceStub::OnIsOperationAllowed(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
int32_t ret = -1;
|
||||
HILOG_INFO("WallpaperServiceStub::OnIsOperationAllowed start.");
|
||||
auto bResult = IsOperationAllowed();
|
||||
if (!reply.WriteBool(bResult)) {
|
||||
HILOG_ERROR("Write result data failed");
|
||||
}
|
||||
ret = (bResult == true) ? 0:-1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t WallpaperServiceStub::OnResetWallpaper(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
int32_t ret = -1;
|
||||
HILOG_INFO("WallpaperServiceStub::OnResetWallpaper start.");
|
||||
|
||||
int wallpaperType = data.ReadInt32();
|
||||
auto bFlag = ResetWallpaper(wallpaperType);
|
||||
if (!reply.WriteBool(bFlag)) {
|
||||
HILOG_ERROR("Write result data failed");
|
||||
}
|
||||
ret = (bFlag == true) ? 0:-1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t WallpaperServiceStub::OnScreenshotLiveWallpaper(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
int32_t ret = -1;
|
||||
HILOG_INFO("WallpaperServiceStub::OnScreenshotLiveWallpaper start.");
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t WallpaperServiceStub::OnWallpaperOn(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
HILOG_DEBUG("WallpaperServiceStub::OnWallpaperOn in");
|
||||
sptr<IRemoteObject> remote = data.ReadRemoteObject();
|
||||
if (remote == nullptr) {
|
||||
if (!reply.WriteInt32(ERR_NONE)) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
sptr<IWallpaperColorChangeListener> WallpaperListenerProxy = iface_cast<IWallpaperColorChangeListener>(remote);
|
||||
|
||||
bool status = On(std::move(WallpaperListenerProxy));
|
||||
int32_t ret = (status == true) ? 0 : -1;
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
HILOG_ERROR("WriteInt32 failed");
|
||||
return -1;
|
||||
}
|
||||
HILOG_DEBUG("WallpaperServiceStub::OnWallpaperOn out");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t WallpaperServiceStub::OnWallpaperOff(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
HILOG_DEBUG("WallpaperServiceStub::OnWallpaperOff in");
|
||||
sptr<IRemoteObject> remote = data.ReadRemoteObject();
|
||||
if (remote == nullptr) {
|
||||
HILOG_WARN("kvStoreObserverProxy nullptr after ipc");
|
||||
if (!reply.WriteInt32(ERR_NONE)) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
sptr<IWallpaperColorChangeListener> WallpaperListenerProxy = iface_cast<IWallpaperColorChangeListener>(remote);
|
||||
bool status = Off(std::move(WallpaperListenerProxy));
|
||||
int32_t ret = (status == true) ? 0 : -1;
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
return -1;
|
||||
}
|
||||
HILOG_DEBUG("WallpaperServiceStub::OnWallpaperOff out");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t WallpaperServiceStub::OnRegisterWallpaperCallback(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
HILOG_INFO(" WallpaperServiceStub::OnRegisterWallpaperCallback start");
|
||||
sptr<IRemoteObject> object = data.ReadParcelable<IRemoteObject>();
|
||||
|
||||
sptr<IWallpaperCallback> callbackProxy = iface_cast<IWallpaperCallback>(object);
|
||||
if (callbackProxy == nullptr) {
|
||||
HILOG_ERROR("RegisterWallpaperCallback failed");
|
||||
reply.WriteInt32(1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
RegisterWallpaperCallback(callbackProxy);
|
||||
reply.WriteInt32(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,67 @@
|
||||
# Copyright (c) 2020-2022 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/test.gni")
|
||||
|
||||
## UnitTest wallpaper_test {{{
|
||||
|
||||
ohos_unittest("wallpaper_test") {
|
||||
module_out_path = "wallpaper_native/wallpaper_test"
|
||||
sources = [
|
||||
"unittest/wallpaper_test.cpp"
|
||||
#"unittest/wallpaperpermissontest.cpp",
|
||||
#"unittest/image_source_picture_test.cpp",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"//third_party/json/include",
|
||||
"//base/miscservices/wallpaper/frameworks/innerkitsimpl/wallpaper_manager/include",
|
||||
"//base/miscservices/wallpaper/utils/include",
|
||||
"//base/miscservices/wallpaper/frameworks/innerkitsimpl/wallpaper_manager/include",
|
||||
"//foundation/graphic/standard/interfaces/innerkits/wm",
|
||||
|
||||
#"//foundation/multimedia/image_standard/interfaces/innerkits/include",
|
||||
]
|
||||
deps = [
|
||||
"//utils/native/base:utils",
|
||||
"//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
|
||||
"//foundation/multimedia/image_standard/interfaces/innerkits:image_native",
|
||||
"//base/hiviewdfx/hiview/adapter/utility:hiview_adapter_utility",
|
||||
"//foundation/windowmanager/wm:libwm",
|
||||
"//foundation/windowmanager/utils:libwmutil",
|
||||
"//foundation/multimedia/image_standard:image_framework",
|
||||
"//foundation/multimedia/image_standard/interfaces/innerkits:image",
|
||||
"//foundation/multimedia/image_standard/interfaces/innerkits:image_native",
|
||||
"//base/miscservices/wallpaper/frameworks/innerkitsimpl/wallpaper_manager:wallpapermanager",
|
||||
]
|
||||
external_deps = [
|
||||
|
||||
"ability_runtime:ability_manager",
|
||||
"ability_base:want",
|
||||
"permission_standard:libpermissionsdk_standard",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr_standard:samgr_proxy",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"ces_standard:cesfwk_innerkits",
|
||||
]
|
||||
}
|
||||
|
||||
## UnitTest wallpaper_test }}}
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
deps = [ ":wallpaper_test" ]
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,408 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "wallpaper_manager_kits.h"
|
||||
#include "wallpaper_manager.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "directory_ex.h"
|
||||
|
||||
|
||||
constexpr int SYSTYEM = 0;
|
||||
constexpr int LOCKSCREEN = 1;
|
||||
constexpr int HUNDRED = 100;
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::Media;
|
||||
using namespace OHOS::HiviewDFX;
|
||||
|
||||
namespace OHOS {
|
||||
namespace WallpaperMgrService {
|
||||
|
||||
class WallpaperTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
static void TearDownTestCase(void);
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
const std::string VALID_SCHEMA_STRICT_DEFINE = "{\"SCHEMA_VERSION\":\"1.0\","
|
||||
"\"SCHEMA_MODE\":\"STRICT\","
|
||||
"\"SCHEMA_SKIPSIZE\":0,"
|
||||
"\"SCHEMA_DEFINE\":{"
|
||||
"\"age\":\"INTEGER, NOT NULL\""
|
||||
"},"
|
||||
"\"SCHEMA_INDEXES\":[\"$.age\"]}";
|
||||
|
||||
void WallpaperTest::SetUpTestCase(void)
|
||||
{
|
||||
}
|
||||
|
||||
void WallpaperTest::TearDownTestCase(void)
|
||||
{
|
||||
}
|
||||
|
||||
void WallpaperTest::SetUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void WallpaperTest::TearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
class WallpaperColorChangeListenerTestImpl : public OHOS::WallpaperMgrService::WallpaperColorChangeListener {
|
||||
public:
|
||||
std::vector<RgbaColor> color_;
|
||||
int wallpaperType_;
|
||||
WallpaperColorChangeListenerTestImpl();
|
||||
~WallpaperColorChangeListenerTestImpl()
|
||||
{}
|
||||
|
||||
WallpaperColorChangeListenerTestImpl(const WallpaperColorChangeListenerTestImpl &) = delete;
|
||||
WallpaperColorChangeListenerTestImpl &operator=(const WallpaperColorChangeListenerTestImpl &) = delete;
|
||||
WallpaperColorChangeListenerTestImpl(WallpaperColorChangeListenerTestImpl &&) = delete;
|
||||
WallpaperColorChangeListenerTestImpl &operator=(WallpaperColorChangeListenerTestImpl &&) = delete;
|
||||
|
||||
// callback function will be called when the db data is changed.
|
||||
void onColorsChange(std::vector<RgbaColor> color, int wallpaperType);
|
||||
|
||||
// reset the callCount_ to zero.
|
||||
void ResetToZero();
|
||||
|
||||
unsigned long GetCallCount() const;
|
||||
|
||||
private:
|
||||
unsigned long callCount_;
|
||||
};
|
||||
|
||||
void WallpaperColorChangeListenerTestImpl::onColorsChange(std::vector<RgbaColor> color, int wallpaperType)
|
||||
{
|
||||
callCount_++;
|
||||
for (auto const &each : color) {
|
||||
color_.push_back(each);
|
||||
}
|
||||
wallpaperType_ = wallpaperType;
|
||||
}
|
||||
|
||||
|
||||
WallpaperColorChangeListenerTestImpl::WallpaperColorChangeListenerTestImpl()
|
||||
{
|
||||
callCount_ = 0;
|
||||
color_ = {};
|
||||
wallpaperType_ = -1;
|
||||
}
|
||||
|
||||
void WallpaperColorChangeListenerTestImpl::ResetToZero()
|
||||
{
|
||||
callCount_ = 0;
|
||||
}
|
||||
|
||||
unsigned long WallpaperColorChangeListenerTestImpl::GetCallCount() const
|
||||
{
|
||||
return callCount_;
|
||||
}
|
||||
|
||||
/********************* ResetWallpaper *********************/
|
||||
/**
|
||||
* @tc.name: Reset001
|
||||
* @tc.desc: Reset wallpaper with wallpaperType[0].
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(WallpaperTest, Reset001, TestSize.Level1)
|
||||
{
|
||||
int wallpaperType = 0;
|
||||
EXPECT_EQ(OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
|
||||
ResetWallpaper(wallpaperType), true) << "should reset successfully.";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Reset002
|
||||
* @tc.desc: Reset wallpaper with wallpaperType[1].
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(WallpaperTest, Reset002, TestSize.Level1)
|
||||
{
|
||||
int wallpaperType = 1;
|
||||
EXPECT_EQ(OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
|
||||
ResetWallpaper(wallpaperType), true) << "should reset successfully.";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Reset003
|
||||
* @tc.desc: Reset wallpaper with wallpaperType[2].
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(WallpaperTest, Reset003, TestSize.Level1)
|
||||
{
|
||||
int wallpaperType = 2;
|
||||
EXPECT_NE(OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
|
||||
ResetWallpaper(wallpaperType), true) << "shouldn't reset successfully.";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Reset004
|
||||
* @tc.desc: Reset wallpaper with wallpaperType[0] after resetting wallpaper[0].
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(WallpaperTest, Reset004, TestSize.Level1)
|
||||
{
|
||||
int wallpaperType = 0;
|
||||
EXPECT_EQ(OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
|
||||
ResetWallpaper(wallpaperType), true) << "should reset successfully.";
|
||||
/* duplicate reset */
|
||||
EXPECT_EQ(OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
|
||||
ResetWallpaper(wallpaperType), true) << "should reset successfully.";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Reset005
|
||||
* @tc.desc: Reset wallpaper with wallpaperType[1] after resetting wallpaper[1] and check whether Id is same one.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(WallpaperTest, Reset005, TestSize.Level1)
|
||||
{
|
||||
int wallpaperType = 1;
|
||||
EXPECT_EQ(OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
|
||||
ResetWallpaper(wallpaperType), true) << "should reset successfully.";
|
||||
int firstId = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
|
||||
GetWallpaperId(wallpaperType);
|
||||
/* duplicate reset */
|
||||
EXPECT_EQ(OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
|
||||
ResetWallpaper(wallpaperType), true) << "should reset successfully.";
|
||||
int secondId = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
|
||||
GetWallpaperId(wallpaperType);
|
||||
EXPECT_EQ(firstId, secondId) << "Id should be same one.";
|
||||
}
|
||||
|
||||
/********************* ResetWallpaper *********************/
|
||||
|
||||
/********************* IsChangePermitted *********************/
|
||||
|
||||
/**
|
||||
* @tc.name: IsChangePermitted001
|
||||
* @tc.desc: check permission.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(WallpaperTest, IsChangePermitted001, TestSize.Level1)
|
||||
{
|
||||
}
|
||||
|
||||
/********************* IsChangePermitted *********************/
|
||||
|
||||
/********************* IsOperationAllowed *********************/
|
||||
|
||||
/**
|
||||
* @tc.name: IsOperationAllowed001
|
||||
* @tc.desc: check permission.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(WallpaperTest, IsOperationAllowed001, TestSize.Level1)
|
||||
{
|
||||
}
|
||||
|
||||
/********************* IsOperationAllowed *********************/
|
||||
|
||||
/********************* On & Off *********************/
|
||||
|
||||
/**
|
||||
* @tc.name: On001
|
||||
* @tc.desc: set wallpaper and get callback.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(WallpaperTest, On001, TestSize.Level1)
|
||||
{
|
||||
auto listener = std::make_shared<WallpaperColorChangeListenerTestImpl>();
|
||||
auto onStatus = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
|
||||
On(listener);
|
||||
EXPECT_EQ(onStatus, true) << "subscribe wallpaper color change failed.";
|
||||
|
||||
auto offSubStatus = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
|
||||
Off(listener);
|
||||
EXPECT_EQ(offSubStatus, true) << "unsubscribe wallpaper color change failed.";
|
||||
}
|
||||
|
||||
/********************* On & Off *********************/
|
||||
|
||||
|
||||
/********************* GetColors *********************/
|
||||
/**
|
||||
* @tc.name: GetColors001
|
||||
* @tc.desc: GetColors with wallpaperType[0].
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(WallpaperTest, GetColors001, TestSize.Level0)
|
||||
{
|
||||
HILOG_INFO(" GetColors001 GetColors001 begin");
|
||||
|
||||
std::vector<RgbaColor> Color = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
|
||||
GetColors(SYSTYEM);
|
||||
bool result = Color.empty();
|
||||
EXPECT_FALSE(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetColors002
|
||||
* @tc.desc: GetColors with wallpaperType[1].
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(WallpaperTest, GetColors002, TestSize.Level0)
|
||||
{
|
||||
HILOG_INFO(" GetColors002 GetColors001 begin");
|
||||
std::vector<RgbaColor> Color = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
|
||||
GetColors(LOCKSCREEN);
|
||||
bool result = Color.empty();
|
||||
EXPECT_FALSE(result);
|
||||
}
|
||||
/********************* GetColors *********************/
|
||||
|
||||
/********************* GetId *********************/
|
||||
/**
|
||||
* @tc.name: GetId001
|
||||
* @tc.desc: GetId with wallpaperType[0].
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(WallpaperTest, GetId001, TestSize.Level0)
|
||||
{
|
||||
HILOG_INFO(" GetId001 GetId001 begin");
|
||||
bool result = false;
|
||||
int ida = HUNDRED;
|
||||
ida = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
|
||||
GetWallpaperId(SYSTYEM);
|
||||
if (ida != HUNDRED) {
|
||||
result = true;
|
||||
}
|
||||
EXPECT_TRUE(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetId002
|
||||
* @tc.desc: GetId with wallpaperType[1].
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(WallpaperTest, GetId002, TestSize.Level0)
|
||||
{
|
||||
HILOG_INFO(" GetId002 GetId002 begin");
|
||||
bool result = false;
|
||||
int ida = HUNDRED;
|
||||
ida = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
|
||||
GetWallpaperId(LOCKSCREEN);
|
||||
if (ida != HUNDRED) {
|
||||
result = true;
|
||||
}
|
||||
EXPECT_TRUE(result);
|
||||
}
|
||||
/********************* GetId *********************/
|
||||
|
||||
/********************* GetWallpaperMinHeight *********************/
|
||||
/**
|
||||
* @tc.name: getMinHeight001
|
||||
* @tc.desc: GetWallpaperMinHeight .
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(WallpaperTest, getMinHeight001, TestSize.Level0)
|
||||
{
|
||||
HILOG_INFO(" WallpaperReset001 begin");
|
||||
bool result = false;
|
||||
int hight = 0;
|
||||
hight = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
|
||||
GetWallpaperMinHeight();
|
||||
if (hight != 0) {
|
||||
result = true;
|
||||
}
|
||||
EXPECT_TRUE(result);
|
||||
}
|
||||
/********************* GetWallpaperMinHeight *********************/
|
||||
|
||||
/********************* GetWallpaperMinWidth *********************/
|
||||
/**
|
||||
* @tc.name: getMinWidth001
|
||||
* @tc.desc: GetWallpaperMinWidth .
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(WallpaperTest, getMinWidth001, TestSize.Level0)
|
||||
{
|
||||
HILOG_INFO(" getMinWidth001 begin");
|
||||
bool result = false;
|
||||
int width = 0;
|
||||
width = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
|
||||
GetWallpaperMinWidth();
|
||||
if (width != 0) {
|
||||
result = true;
|
||||
}
|
||||
EXPECT_TRUE(result);
|
||||
}
|
||||
/********************* GetWallpaperMinWidth *********************/
|
||||
|
||||
/********************* GetPiexlMap *********************/
|
||||
/**
|
||||
* @tc.name: GetPiexlMap001
|
||||
* @tc.desc: GetPixelMap with wallpaperType[0] .
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(WallpaperTest, GetPiexlMap001, TestSize.Level0)
|
||||
{
|
||||
HILOG_INFO(" SetWallpaper&GetPiexlMap001 begin");
|
||||
auto PixelMap = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
|
||||
GetPixelMap(SYSTYEM);
|
||||
EXPECT_TRUE(PixelMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetPiexlMap002
|
||||
* @tc.desc: GetPixelMap with wallpaperType[1].
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
* @tc.author:
|
||||
*/
|
||||
HWTEST_F(WallpaperTest, GetPiexlMap002, TestSize.Level0)
|
||||
{
|
||||
HILOG_INFO(" SetWallpaper&GetPiexlMap002 begin");
|
||||
auto PixelMap = OHOS::WallpaperMgrService::WallpaperManagerkits::GetInstance().
|
||||
GetPixelMap(LOCKSCREEN);
|
||||
EXPECT_TRUE(PixelMap);
|
||||
}
|
||||
/********************* GetPiexlMap *********************/
|
||||
} // wallpaperservice
|
||||
} // OHOS
|
||||
@@ -0,0 +1,35 @@
|
||||
# Copyright (C) 2022 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")
|
||||
ohos_shared_library("wallpaper_utils") {
|
||||
sources = [
|
||||
"src/file_deal.cpp",
|
||||
]
|
||||
include_dirs = [
|
||||
"include",
|
||||
]
|
||||
deps = [
|
||||
"//utils/native/base:utils",
|
||||
"//base/hiviewdfx/hiview/adapter/utility:hiview_adapter_utility",
|
||||
]
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
"samgr_standard:samgr_proxy",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"ces_standard:cesfwk_innerkits",
|
||||
]
|
||||
subsystem_name = "miscservices"
|
||||
part_name = "wallpaper_native"
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 WALLPAPER_SERVICES_FILE_DEAL_H
|
||||
#define WALLPAPER_SERVICES_FILE_DEAL_H
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
namespace OHOS {
|
||||
namespace WallpaperMgrService {
|
||||
class FileDeal {
|
||||
public:
|
||||
FileDeal();
|
||||
~FileDeal();
|
||||
bool DirIsExist(std::string path);
|
||||
bool Mkdir(std::string path);
|
||||
bool CopyFile(char* SourceFile, char* NewFile);
|
||||
int DeleteFile(char* SourceFile);
|
||||
bool FileIsExist (const std::string& name) ;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 HILOG_WRAPPER_H
|
||||
#define HILOG_WRAPPER_H
|
||||
|
||||
#define CONFIG_HILOG
|
||||
#ifdef CONFIG_HILOG
|
||||
#include "hilog/log.h"
|
||||
|
||||
#ifdef HILOG_FATAL
|
||||
#undef HILOG_FATAL
|
||||
#endif
|
||||
|
||||
#ifdef HILOG_ERROR
|
||||
#undef HILOG_ERROR
|
||||
#endif
|
||||
|
||||
#ifdef HILOG_WARN
|
||||
#undef HILOG_WARN
|
||||
#endif
|
||||
|
||||
#ifdef HILOG_INFO
|
||||
#undef HILOG_INFO
|
||||
#endif
|
||||
|
||||
#ifdef HILOG_DEBUG
|
||||
#undef HILOG_DEBUG
|
||||
#endif
|
||||
|
||||
#ifdef LOG_LABEL
|
||||
#undef LOG_LABEL
|
||||
#endif
|
||||
namespace OHOS {
|
||||
namespace WallpaperMgrService {
|
||||
static constexpr unsigned int WP_DOMAIN = 0xD001C00;
|
||||
static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = {LOG_CORE, WP_DOMAIN, "Wallpaper_OS"};
|
||||
}
|
||||
}
|
||||
|
||||
#define WALLFILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
|
||||
|
||||
#define HILOG_FATAL(fmt, ...) \
|
||||
(void)OHOS::HiviewDFX::HiLog::Fatal( \
|
||||
LOG_LABEL, "[%{public}s(%{public}s:%{public}d)]" fmt, WALLFILENAME__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
|
||||
#define HILOG_ERROR(fmt, ...) \
|
||||
(void)OHOS::HiviewDFX::HiLog::Error( \
|
||||
LOG_LABEL, "[%{public}s(%{public}s:%{public}d)]" fmt, WALLFILENAME__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
|
||||
#define HILOG_WARN(fmt, ...) \
|
||||
(void)OHOS::HiviewDFX::HiLog::Warn( \
|
||||
LOG_LABEL, "[%{public}s(%{public}s:%{public}d)]" fmt, WALLFILENAME__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
|
||||
#define HILOG_INFO(fmt, ...) \
|
||||
(void)OHOS::HiviewDFX::HiLog::Info( \
|
||||
LOG_LABEL, "[%{public}s(%{public}s:%{public}d)]" fmt, WALLFILENAME__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
|
||||
#define HILOG_DEBUG(fmt, ...) \
|
||||
(void)OHOS::HiviewDFX::HiLog::Debug( \
|
||||
LOG_LABEL, "[%{public}s(%{public}s:%{public}d)]" fmt, WALLFILENAME__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
|
||||
#else
|
||||
|
||||
#define HILOG_FATAL(...)
|
||||
#define HILOG_ERROR(...)
|
||||
#define HILOG_WARN(...)
|
||||
#define HILOG_INFO(...)
|
||||
#define HILOG_DEBUG(...)
|
||||
|
||||
#endif // CONFIG_HILOG
|
||||
|
||||
#endif // HILOG_WRAPPER_H
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 WALLPAPER_SERVICES_WALLPAPER_COMMON_H
|
||||
#define WALLPAPER_SERVICES_WALLPAPER_COMMON_H
|
||||
|
||||
#include <string>
|
||||
#include "errors.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace WallpaperMgrService {
|
||||
#define WALLPAPER_SERVICE_NAME "WallpaperMgrService"
|
||||
static const std::string WALLPAPER_BUNDLE_NAME = "ohos";
|
||||
static const std::string WALLPAPER_PERMISSION_NAME_GET_WALLPAPER = "ohos.permission.GET_WALLPAPER";
|
||||
static const std::string WALLPAPER_PERMISSION_NAME_SET_WALLPAPER = "ohos.permission.SET_WALLPAPER";
|
||||
static const std::string WALLPAPER_PERMISSION_NAME_READ_USER_STORAGE = "ohos.permission.READ_USER_STORAGE";
|
||||
static const std::string WALLPAPER_PERMISSION_NAME_CAPTURE_SCREEN = "ohos.permission.CAPTURE_SCREEN";
|
||||
|
||||
static const std::string TEST_LABEL = "test label";
|
||||
static const std::string TEST_DESCRIPTION = "test description";
|
||||
|
||||
static const int TEST_LABEL_ID = 9527;
|
||||
static const int TEST_DESCRIPTION_ID = 9528;
|
||||
static const int TEST_INVALID_USER_ID = -1;
|
||||
static const int TEST_USER_ID = 0;
|
||||
static const int TEST_SUB_USER_ID = 10;
|
||||
|
||||
enum WallpaperModule {
|
||||
WALLPAPER_MODULE_SERVICE_ID = 0x07,
|
||||
};
|
||||
// time error offset, used only in this file.
|
||||
constexpr ErrCode WALLPAPER_ERR_OFFSET = ErrCodeOffset(SUBSYS_SMALLSERVICES, WALLPAPER_MODULE_SERVICE_ID);
|
||||
|
||||
enum WallpaperError {
|
||||
E_WALLPAPER_OK = WALLPAPER_ERR_OFFSET,
|
||||
E_WALLPAPER_SA_DIED,
|
||||
E_WALLPAPER_READ_PARCEL_ERROR,
|
||||
E_WALLPAPER_WRITE_PARCEL_ERROR,
|
||||
E_WALLPAPER_PUBLISH_FAIL,
|
||||
E_WALLPAPER_TRANSACT_ERROR,
|
||||
E_WALLPAPER_DEAL_FAILED,
|
||||
E_WALLPAPER_PARAMETERS_INVALID,
|
||||
E_WALLPAPER_SET_RTC_FAILED,
|
||||
E_WALLPAPER_NOT_FOUND,
|
||||
E_WALLPAPER_NO_PERMISSION,
|
||||
};
|
||||
} // namespace
|
||||
} // names
|
||||
|
||||
#endif // WALLPAPER_SERVICES_WALLPAPER_COMMON_H
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 INNERKITSIMPL_WALLPAPER_MANAGER_COMMON_INFO_H
|
||||
#define INNERKITSIMPL_WALLPAPER_MANAGER_COMMON_INFO_H
|
||||
|
||||
#include <string>
|
||||
|
||||
static const std::string WALLPAPER_USERID_PATH = "/data/accounts/account_";
|
||||
static const std::string WALLPAPER_LOCKSCREEN_KVFILENAME = "wallpaper_lockscreen";
|
||||
static const std::string WALLPAPER_SYSTEM_KVFILENAME = "wallpaper_system";
|
||||
static const std::string WALLPAPER_DIRNAME = "wallpaper";
|
||||
static const std::string WALLPAPER_SYSTEM_DIRNAME = "system";
|
||||
static const std::string WALLPAPER_TMP_DIRNAME = "fwsettmp";
|
||||
static const std::string WALLPAPER_LOCKSCREEN_DIRNAME = "lockscreen";
|
||||
static const std::string WALLPAPER_DEFAULT_FILEFULLPATH = "/system/etc/wallpaperdefault.jpeg";
|
||||
static const std::string WALLPAPER_DEFAULT_LOCK_FILEFULLPATH = "/system/etc/wallpaperlockdefault.jpeg";
|
||||
static const std::string WALLPAPER_CROP_PICTURE = "crop_file";
|
||||
struct RgbaColor {
|
||||
int red;
|
||||
int blue;
|
||||
int green;
|
||||
int alpha;
|
||||
};
|
||||
enum WallpaperType {
|
||||
/**
|
||||
* Indicates the home screen wallpaper.
|
||||
*/
|
||||
WALLPAPER_SYSTEM,
|
||||
/**
|
||||
* Indicates the lock screen wallpaper.
|
||||
*/
|
||||
WALLPAPER_LOCKSCREEN
|
||||
};
|
||||
#endif
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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 <dirent.h>
|
||||
#include <sys/types.h>
|
||||
#include <cstdio>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include "hilog_wrapper.h"
|
||||
#include "file_deal.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace WallpaperMgrService {
|
||||
FileDeal::FileDeal(void)
|
||||
{
|
||||
}
|
||||
FileDeal::~FileDeal()
|
||||
{
|
||||
}
|
||||
bool FileDeal::DirIsExist(std::string path)
|
||||
{
|
||||
DIR* dp;
|
||||
if ((dp = opendir(path.c_str())) == NULL) {
|
||||
HILOG_INFO("FileDeal : opendir %{public}s is not exist", path.c_str());
|
||||
return false;
|
||||
}
|
||||
closedir(dp);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FileDeal::Mkdir(std::string path)
|
||||
{
|
||||
if (!DirIsExist(path)) {
|
||||
int isCreate = ::mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
|
||||
HILOG_INFO("FileDeal : mkdir result= %{public}d,errinfo=%{public}s ,path = %{public}s ",
|
||||
isCreate, strerror(errno), path.c_str());
|
||||
return isCreate == 0 ? true : false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FileDeal::CopyFile(char* SourceFile, char* NewFile)
|
||||
{
|
||||
HILOG_INFO("wallpaperservice Copy file Star:from [%{public}s] to [%{public}s]", SourceFile, NewFile);
|
||||
bool bFlag = false;
|
||||
std::ifstream in;
|
||||
std::ofstream out;
|
||||
|
||||
in.open(SourceFile, std::ios::binary);
|
||||
if (in.fail()) {
|
||||
HILOG_INFO("FileDeal : open file %{public}s failed", SourceFile);
|
||||
in.close();
|
||||
out.close();
|
||||
return bFlag;
|
||||
}
|
||||
out.open(NewFile, std::ios::binary);
|
||||
if (out.fail()) {
|
||||
HILOG_INFO("FileDeal : open file %{public}s failed", NewFile);
|
||||
out.close();
|
||||
in.close();
|
||||
return bFlag;
|
||||
} else {
|
||||
out << in.rdbuf();
|
||||
out.close();
|
||||
in.close();
|
||||
bFlag = true;
|
||||
HILOG_INFO("FileDeal : copy file %{public}s, new file=%{public}s,success", SourceFile, NewFile);
|
||||
return bFlag;
|
||||
}
|
||||
return bFlag;
|
||||
}
|
||||
|
||||
bool FileDeal::FileIsExist(const std::string& name)
|
||||
{
|
||||
bool bFlag = false;
|
||||
if (access(name.c_str(), F_OK) == 0) {
|
||||
bFlag = true;
|
||||
return bFlag;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
# Copyright (C) 2022 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.
|
||||
|
||||
wallpaper_path = "//base/miscservices/wallpaper"
|
||||
|
||||
adapter_path = "${wallpaper_path}/adapter"
|
||||
utils_path = "${wallpaper_path}/utils"
|
||||
Reference in New Issue
Block a user