update openharmony 1.0.1

This commit is contained in:
mamingshuai
2021-03-11 18:41:24 +08:00
parent 5f159aeaf3
commit 4881020ec6
135 changed files with 1662 additions and 2898 deletions
-13
View File
@@ -1,13 +0,0 @@
### 该问题是怎么引起的?
### 重现步骤
### 报错信息
-15
View File
@@ -1,15 +0,0 @@
### 相关的Issue
### 原因(目的、解决的问题等)
### 描述(做了什么,变更了什么)
### 测试用例(新增、改动、可能影响的功能)
+2
View File
@@ -0,0 +1,2 @@
communication
screensaver
Executable → Regular
+176 -176
View File
@@ -1,177 +1,177 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
+53
View File
@@ -0,0 +1,53 @@
# CAMERA\_SAMPLE\_APP<a name="EN-US_TOPIC_0000001080462608"></a>
- [Introduction](#section11660541593)
- [Directory Structure](#section176641621345)
- [Usage](#section1648194512427)
- [Constraints](#section722512541395)
- [Repositories Involved](#section16511040154318)
## Introduction<a name="section11660541593"></a>
This repository provides media-related applications, such as the home screen and settings.
**Figure 1** Position of this repository \(in the dotted blue box\) in the multimedia subsystem<a name="fig189881143114217"></a>
![](figures/position-of-this-repository-(in-the-dotted-blue-box)-in-the-multimedia-subsystem.png "position-of-this-repository-(in-the-dotted-blue-box)-in-the-multimedia-subsystem")
## Directory Structure<a name="section176641621345"></a>
```
applications/sample/camera
├── cameraApp # Camera app
├── gallery # Photo gallery
├── launcher # Home screen
├── media # Apps of photographing, video recording, and audio and video playback
└── setting # Settings
```
## Usage<a name="section1648194512427"></a>
Build a single repository in the root directory.
```
# Select the development board.
hb set
# Build this repository.
hb build camera_lite
```
## Constraints<a name="section722512541395"></a>
C++ 11 or later
## Repositories Involved<a name="section16511040154318"></a>
/hmf/multimedia/camera\_lite
/hmf/multimedia/audio\_lite
/hmf/multimedia/media\_lite
/hmf/multimedia/utils\_lite
/hmf/multimedia/service\_lite
+53
View File
@@ -0,0 +1,53 @@
# 媒体子系统CAMERA\_SAMPLE\_APP组件<a name="ZH-CN_TOPIC_0000001080462608"></a>
- [简介](#section11660541593)
- [目录](#section176641621345)
- [使用说明](#section1648194512427)
- [约束](#section722512541395)
- [相关仓](#section16511040154318)
## 简介<a name="section11660541593"></a>
CAMERA\_SAMPLE\_APP组件,提供媒体能力开发的相关应用,提供桌面应用和设置应用。
**图 1** 媒体子系统架构(蓝色虚线框是sample\_app<a name="fig189881143114217"></a>
![](figures/媒体子系统架构(蓝色虚线框是sample_app).png "媒体子系统架构(蓝色虚线框是sample_app")
## 目录<a name="section176641621345"></a>
```
applications/sample/camera
├── cameraApp 相机应用
├── gallery 图库应用
├── launcher 桌面应用
├── media 拍照录像应用和音视频播放应用
└── setting 设置
```
## 使用说明<a name="section1648194512427"></a>
单仓的编译构建,在根目录下进行单仓的构建和编译
```
# 开发板选择
hb set
# 单仓构建和编译
hb build camera_lite
```
## 约束<a name="section722512541395"></a>
C++11版本或以上
## 相关仓<a name="section16511040154318"></a>
/hmf/multimedia/camera\_lite
/hmf/multimedia/audio\_lite
/hmf/multimedia/media\_lite
/hmf/multimedia/utils\_lite
/hmf/multimedia/service\_lite
-43
View File
@@ -1,43 +0,0 @@
# Copyright (c) 2020 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/lite/config/component/lite_component.gni")
import("//build/lite/ndk/ndk.gni")
static_library("hello_world") {
sources = [
"src/helloworld.c",
"src/los_sample.c"
]
include_dirs = [
"include",
]
}
lite_component("camera_app") {
target_type = "executable"
features = [
":hello_world",
]
}
ndk_lib("app_sample") {
deps = [
":hello_world"
]
head_files = [
"include"
]
}
-31
View File
@@ -1,31 +0,0 @@
/*
* Copyright (c) 2020 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 _LOS_SAMPLE_H
#define _LOS_SAMPLE_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
extern int g_num;
extern void LOS_Sample(int param);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _LOS_SAMPLE_H */
-28
View File
@@ -1,28 +0,0 @@
/*
* Copyright (c) 2020 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 <stdio.h>
#include "los_sample.h"
int main(int argc, char **argv)
{
printf("\n************************************************\n");
printf("\n\t\tHello OHOS!\n");
printf("\n************************************************\n\n");
LOS_Sample(g_num);
return 0;
}
-22
View File
@@ -1,22 +0,0 @@
/*
* Copyright (c) 2020 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 <stdio.h>
int g_num = 81;
void LOS_Sample(int param)
{
printf("This is a sample: Param = %d\n", param);
}
Regular → Executable
+48 -57
View File
@@ -11,68 +11,59 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/lite/config/component/lite_component.gni")
import("//build/lite/config/hap_pack.gni")
shared_library("cameraApp") {
sources = [
"cameraApp/src/main/cpp/camera_ability.cpp",
"cameraApp/src/main/cpp/camera_ability_slice.cpp",
"cameraApp/src/main/cpp/camera_manager.cpp"
]
sources = [
"cameraApp/src/main/cpp/camera_ability.cpp",
"cameraApp/src/main/cpp/camera_ability_slice.cpp",
"cameraApp/src/main/cpp/camera_manager.cpp",
]
deps = [
"//foundation/aafwk/frameworks/ability_lite:aafwk_abilitykit_lite",
"//foundation/appexecfwk/frameworks/bundle_lite:bundle",
"//foundation/communication/frameworks/ipc_lite:liteipc_adapter",
"//foundation/distributedschedule/services/samgr_lite/samgr:samgr",
"//utils/native/lite/kv_store:kv_store",
"//foundation/graphic/lite/frameworks/ui:ui",
"//foundation/graphic/lite/utils:graphic_utils",
"//foundation/graphic/lite/frameworks/surface",
"//foundation/multimedia/frameworks/camera_lite:camera",
"//foundation/multimedia/frameworks/recorder_lite:recorder",
]
deps = [
"${aafwk_lite_path}/frameworks/ability_lite:aafwk_abilitykit_lite",
"${appexecfwk_lite_path}/frameworks/bundle_lite:bundle",
"//foundation/communication/ipc_lite:liteipc_adapter",
"//foundation/distributedschedule/samgr_lite/samgr:samgr",
"//foundation/graphic/surface",
"//foundation/graphic/ui:lite_ui",
"//foundation/graphic/utils:lite_graphic_utils",
"//foundation/multimedia/camera_lite/frameworks:camera_lite",
"//foundation/multimedia/media_lite/frameworks/recorder_lite:recorder_lite",
"//utils/native/lite/kv_store:kv_store",
]
include_dirs = [
"cameraApp/src/main/cpp",
"//foundation/aafwk/interfaces/kits/ability_lite",
"//foundation/graphic/lite/interfaces/kits/ui/components",
"//foundation/graphic/lite/interfaces/kits/ui",
"//foundation/graphic/lite/interfaces/kits/utils",
"//foundation/graphic/lite/interfaces/kits/config",
"//foundation/appexecfwk/interfaces/kits/bundle_lite",
"//foundation/aafwk/interfaces/kits/want_lite",
"//base/startup/interfaces/kits/syspara_lite",
"//foundation/multimedia/interfaces/kits/camera_lite",
"//foundation/multimedia/interfaces/kits/camera_lite"
]
ldflags = [
"-L$ohos_root_path/sysroot/usr/lib",
"-Wl,-rpath-link=$ohos_root_path/sysroot/usr/lib",
"-lstdc++", "-lcamera", "-lsurface", "-lrecorder"
]
defines = [
"ENABLE_WINDOW=1",
"ABILITY_WINDOW_SUPPORT"
]
include_dirs = [
"cameraApp/src/main/cpp",
"${aafwk_lite_path}/interfaces/kits/ability_lite",
"${appexecfwk_lite_path}/interfaces/kits/bundle_lite",
"${aafwk_lite_path}/interfaces/kits/want_lite",
"//base/startup/syspara_lite/interfaces/kits",
"//foundation/multimedia/camera_lite/interfaces/kits",
"//foundation/multimedia/camera_lite/interfaces/kits",
]
ldflags = [
"-L$ohos_root_path/sysroot/usr/lib",
"-Wl,-rpath-link=$ohos_root_path/sysroot/usr/lib",
"-lstdc++",
"-lcamera_lite",
"-lsurface",
"-lrecorder_lite",
]
defines = [
"ENABLE_WINDOW=1",
"ABILITY_WINDOW_SUPPORT",
]
}
lite_component("cameraApp_component") {
features = [
":cameraApp",
]
}
hap_pack("cameraApp_hap")
{
deps = [":cameraApp"]
mode = "hap"
json_path = "cameraApp/src/main/config.json"
ability_so_path = "$root_out_dir/libcameraApp.so"
force = "true"
cert_profile = "cert/camera_HarmonyAppProvision_Release.p7b"
resources_path = "cameraApp/src/main/resources"
hap_name = "cameraApp"
hap_pack("cameraApp_hap") {
deps = [ ":cameraApp" ]
mode = "hap"
json_path = "cameraApp/src/main/config.json"
ability_so_path = "$root_out_dir/libcameraApp.so"
force = "true"
cert_profile = "cert/camera_HarmonyAppProvision_Release.p7b"
resources_path = "cameraApp/src/main/resources"
hap_name = "cameraApp"
privatekey = "HOS Application Provision Release"
}
+99 -99
View File
@@ -1,99 +1,99 @@
{
"app": {
"bundleName": "com.huawei.camera",
"vendor": "huawei",
"version": {
"code": 2,
"name": "2"
},
"apiVersion": {
"compatible": 3,
"target": 4
}
},
"deviceConfig": {
"default": {
}
},
"module": {
"package": "com.huawei.camera",
"name": ".MyHarmonyAbilityPackage",
"deviceType": [
"phone",
"tv",
"tablet",
"pc",
"car",
"smartWatch",
"sportsWatch",
"smartVision"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "cameraApp",
"moduleType": "entry"
},
"abilities": [
{
"name": "CameraAbility",
"icon": "assets/cameraApp/resources/base/media/camera.png",
"label": "test app 1",
"launchType": "standard",
"type": "page",
"visible": true
}
],
"reqPermissions": [
{
"name": "ohos.permission.CAMERA",
"reason": "USER_GRANT",
"usedScene": {
"ability": [
".FormAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.MODIFY_AUDIO_SETTINGS",
"reason": "SYSTEM_GRANT",
"usedScene": {
"ability": [
".FormAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.READ_MEDIA",
"reason": "USER_GRANT",
"usedScene": {
"ability": [
".FormAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.MICROPHONE",
"reason": "USER_GRANT",
"usedScene": {
"ability": [
".FormAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.WRITE_MEDIA",
"reason": "USER_GRANT",
"usedScene": {
"ability": [
".FormAbility"
],
"when": "inuse"
}
}
]
}
}
{
"app": {
"bundleName": "com.huawei.camera",
"vendor": "huawei",
"version": {
"code": 2,
"name": "2"
},
"apiVersion": {
"compatible": 3,
"target": 4
}
},
"deviceConfig": {
"default": {
}
},
"module": {
"package": "com.huawei.camera",
"name": ".MyHarmonyAbilityPackage",
"deviceType": [
"phone",
"tv",
"tablet",
"pc",
"car",
"smartWatch",
"sportsWatch",
"smartVision"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "cameraApp",
"moduleType": "entry"
},
"abilities": [
{
"name": "CameraAbility",
"icon": "assets/cameraApp/resources/base/media/camera.png",
"label": "test app 1",
"launchType": "standard",
"type": "page",
"visible": true
}
],
"reqPermissions": [
{
"name": "ohos.permission.CAMERA",
"reason": "USER_GRANT",
"usedScene": {
"ability": [
".FormAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.MODIFY_AUDIO_SETTINGS",
"reason": "SYSTEM_GRANT",
"usedScene": {
"ability": [
".FormAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.READ_MEDIA",
"reason": "USER_GRANT",
"usedScene": {
"ability": [
".FormAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.MICROPHONE",
"reason": "USER_GRANT",
"usedScene": {
"ability": [
".FormAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.WRITE_MEDIA",
"reason": "USER_GRANT",
"usedScene": {
"ability": [
".FormAbility"
],
"when": "inuse"
}
}
]
}
}
View File
View File
+13 -12
View File
@@ -36,8 +36,8 @@ class SliderAnimator : public Animator, public AnimatorCallback {
public:
explicit SliderAnimator(UISlider *slider, UIImageView *backview, UISurfaceView *surface,
SampleCameraManager *cManager, uint16_t duration)
: Animator(this, slider, duration, true), slider_(slider), backgroundView_(backview), mSurfaceview(surface),
camManager(cManager), duration_(duration) {}
: Animator(this, slider, duration, true), backgroundView_(backview), mSurfaceview(surface),
camManager(cManager), ss(0), runType_(0), camRestart(false) {}
virtual ~SliderAnimator() {}
void Callback(UIView *view) override
@@ -92,12 +92,10 @@ public:
}
private:
UIImageView *backgroundView_;
UISlider *slider_;
UISurfaceView *mSurfaceview;
SampleCameraManager *camManager;
uint32_t duration_;
uint32_t ss = 0;
uint32_t runType_ = 0;
uint32_t ss;
uint32_t runType_;
bool camRestart;
void BackViewSetImage(const char *image)
@@ -115,7 +113,7 @@ private:
scaleHeight = static_cast<float>(SCREEN_HEIGHT) / imageHeight;
float scale = (scaleWidth < scaleHeight) ? scaleWidth : scaleHeight;
transMap.Scale(Vector2<float>(scale, scale), Vector2<int16_t>(0, 0));
transMap.Scale(Vector2<float>(scale, scale), Vector2<float>(0, 0));
backgroundView_->SetTransformMap(transMap);
backgroundView_->SetTransformAlgorithm(TransformAlgorithm::NEAREST_NEIGHBOR);
imageWidth = imageWidth * scale;
@@ -131,13 +129,16 @@ class CameraImageButtonOnClickListener : public UIView::OnClickListener {
public:
CameraImageButtonOnClickListener(UIView *uiView, UISurfaceView *surface,
UIImageView *iamgeview, TaskView *taskView, SliderAnimator *animator) : uiView_(uiView),
mSurfaceview(surface), backgroundView_(iamgeview), gTaskView_(taskView), animator_(animator)
backgroundView_(iamgeview), mSurfaceview(surface), animator_(animator), gTaskView_(taskView)
{
cManager_ = nullptr;
bttnLeft = nullptr;
bttnRight = nullptr;
bttnMidle = nullptr;
bttnRecord = nullptr;
recordImage = nullptr;
tmLabel = nullptr;
bttnIdx_ = 0;
}
virtual ~CameraImageButtonOnClickListener(){}
@@ -221,6 +222,7 @@ private:
UIImageView *backgroundView_;
UISurfaceView *mSurfaceview;
SliderAnimator *animator_;
TaskView *gTaskView_;
int16_t bttnIdx_;
SampleCameraManager *cManager_;
@@ -230,7 +232,6 @@ private:
UIImageView *bttnRecord;
UIImageView *recordImage;
UILabel *tmLabel;
TaskView *gTaskView_;
void StartGallery(void)
{
Want want1 = { nullptr };
@@ -327,7 +328,7 @@ private:
scaleHeight = static_cast<float>(SCREEN_HEIGHT) / imageHeight;
float scale = (scaleWidth < scaleHeight) ? scaleWidth : scaleHeight;
transMap.Scale(Vector2<float>(scale, scale), Vector2<int16_t>(0, 0));
transMap.Scale(Vector2<float>(scale, scale), Vector2<float>(0, 0));
backgroundView_->SetTransformMap(transMap);
backgroundView_->SetTransformAlgorithm(TransformAlgorithm::NEAREST_NEIGHBOR);
imageWidth = imageWidth * scale;
@@ -498,8 +499,8 @@ void CameraAbilitySlice::OnStart(const Want &want)
background_->SetVisible(true);
background_->Invalidate();
cam_manager = new SampleCameraManager(0);
cam_manager->SampleCameraCreate(0);
cam_manager = new SampleCameraManager();
cam_manager->SampleCameraCreate();
SetHead();
View File
+42 -31
View File
@@ -30,13 +30,15 @@ static constexpr int TEMP_BUF_LEN = 8;
static constexpr int MAX_THM_SIZE = (64 * PAGE_SIZE);
static constexpr int FILE_NAME_LEN = 128;
static constexpr int MILLI_SECONDS = 1000;
static constexpr int PIC_WIDTH = 1920;
static constexpr int PIC_HEIGHT = 1080;
char* g_dstBuf = nullptr;
static int32_t SampleDealThumb(char* psrc, uint32_t srcSize, uint32_t* dstSize, uint16_t u16THMLen)
{
int32_t endpos = 0;
int32_t s32I = 0;
uint32_t s32I = 0;
int32_t startpos = 0;
char tempbuf[TEMP_BUF_LEN] = { 0 };
int32_t bufpos = 0;
@@ -44,6 +46,9 @@ static int32_t SampleDealThumb(char* psrc, uint32_t srcSize, uint32_t* dstSize,
char endflag[2] = { 0xff, 0xd9 };
while (s32I < srcSize) {
if (bufpos >= TEMP_BUF_LEN) {
break;
}
tempbuf[bufpos] = psrc[s32I++];
if (bufpos > 0) {
if (0 == memcmp(tempbuf + bufpos - 1, startflag, sizeof(startflag))) {
@@ -55,15 +60,13 @@ static int32_t SampleDealThumb(char* psrc, uint32_t srcSize, uint32_t* dstSize,
if (0 == memcmp(tempbuf + bufpos - 1, endflag, sizeof(endflag))) {
if (u16THMLen == s32I) {
endpos = s32I;
break;
} else {
endpos = s32I;
break;
}
break;
}
}
bufpos++;
if (bufpos == (TEMP_BUF_LEN - 1)) {
if (++bufpos == (TEMP_BUF_LEN - 1)) {
if (tempbuf[bufpos - 1] != 0xFF) {
bufpos = 0;
}
@@ -72,7 +75,7 @@ static int32_t SampleDealThumb(char* psrc, uint32_t srcSize, uint32_t* dstSize,
}
}
if ((endpos - startpos <= 0) || (endpos - startpos >= srcSize)) {
if ((endpos - startpos <= 0) || (static_cast<uint32_t>(endpos - startpos) >= srcSize)) {
return -1;
}
@@ -93,9 +96,8 @@ static int32_t SampleDealThumb(char* psrc, uint32_t srcSize, uint32_t* dstSize,
return 0;
}
static int32_t SampleGetThmFromJpg(char* jpegPath, uint32_t* dstSize)
static int32_t SampleGetThmFromJpg(const char* jpegPath, uint32_t* dstSize)
{
int32_t s32RtnVal = 0;
FILE* fpJpg = nullptr;
fpJpg = fopen(jpegPath, "rb");
char* pszFile = nullptr;
@@ -111,6 +113,10 @@ static int32_t SampleGetThmFromJpg(char* jpegPath, uint32_t* dstSize)
pszFile = (char*)malloc(stStat.st_size);
if ((pszFile == nullptr) || (stStat.st_size < 6)) { /* 6 min size of thumb head */
fclose(fpJpg);
if (pszFile) {
free(pszFile);
pszFile = nullptr;
}
printf("memory malloc fail!\n");
return -1;
}
@@ -124,7 +130,8 @@ static int32_t SampleGetThmFromJpg(char* jpegPath, uint32_t* dstSize)
fclose(fpJpg);
// The fourth byte is shifted to the left by eight bits then the fifth byte is added.
uint16_t u16THMLen = (pszFile[4] << 8) + pszFile[5];
// the 4 byte is the length high 8 bit, and byte 5 is low 8bit;
uint16_t u16THMLen = (static_cast<uint16_t>(pszFile[4]) << 8) + pszFile[5];
if (SampleDealThumb(pszFile, stStat.st_size, dstSize, u16THMLen) < 0) {
printf("get jpg thumb failed! \n");
free(pszFile);
@@ -146,7 +153,7 @@ int32_t SampleGetdcfinfo(const char* srcJpgPath, const char* dstThmPath)
if (sprintf_s(jpegDesPath, sizeof(jpegDesPath), "%s", dstThmPath) < 0) {
return -1;
}
s32RtnVal = SampleGetThmFromJpg(jpegSrcPath, &dstSize);
s32RtnVal = SampleGetThmFromJpg(static_cast<const char *>(jpegSrcPath), &dstSize);
if ((s32RtnVal != 0) || (dstSize == 0)) {
printf("fail to get thm\n");
return -1;
@@ -156,7 +163,7 @@ int32_t SampleGetdcfinfo(const char* srcJpgPath, const char* dstThmPath)
printf("file to create file %s\n", jpegDesPath);
return -1;
}
int32_t u32WritenSize = 0;
uint32_t u32WritenSize = 0;
while (u32WritenSize < dstSize) {
s32RtnVal = fwrite(g_dstBuf + u32WritenSize, 1, dstSize, fpTHM);
if (s32RtnVal <= 0) {
@@ -176,12 +183,11 @@ int32_t SampleGetdcfinfo(const char* srcJpgPath, const char* dstThmPath)
return 0;
}
static void SampleSaveCapture(const char* p, uint32_t size, int type, char *timeStamp, int length)
static void SampleSaveCapture(const char* p, uint32_t size, int type, const char *timeStamp, int length)
{
char acFileDcf[FILE_NAME_LEN] = {0};
FILE *fp = nullptr;
char acFile[FILE_NAME_LEN] = { 0 };
int ws = 0;
if (type == 0) {
char tmpFile[FILE_NAME_LEN] = {0};
@@ -190,7 +196,7 @@ static void SampleSaveCapture(const char* p, uint32_t size, int type, char *time
}
fp = fopen(tmpFile, "w+");
if (fp) {
ws = fwrite(p, 1, size, fp);
fwrite(p, 1, size, fp);
fclose(fp);
}
}
@@ -204,7 +210,7 @@ static void SampleSaveCapture(const char* p, uint32_t size, int type, char *time
if (fp == NULL) {
return;
}
ws = fwrite(p, 1, size, fp);
fwrite(p, 1, size, fp);
fclose(fp);
if (type == 0) {
@@ -222,12 +228,16 @@ static void SampleSaveCapture(const char* p, uint32_t size, int type, char *time
SampleGetdcfinfo(static_cast<char *>(acFile), static_cast<char *>(acFileDcf));
}
static int CameraGetRecordFd(char* p)
static int CameraGetRecordFd(const char* p)
{
int fd = -1;
char pname[128] = {0};
char *pe = strrchr(p, '.');
char *ps = strrchr(p, '/');
char *ptr = const_cast<char *>(p);
char *pe = strrchr(ptr, '.');
char *ps = strrchr(ptr, '/');
if (pe == nullptr || ps == nullptr) {
return -1;
}
if (strcpy_s(static_cast<char *>(pname), sizeof(pname), VIDEO_PATH) != 0) {
return -1;
@@ -240,9 +250,8 @@ static int CameraGetRecordFd(char* p)
if (strcat_s(pname, sizeof(pname), ".mp4") < 0) {
return -1;
}
fd = open(pname, O_RDWR | O_CREAT | O_CLOEXEC | O_TRUNC, S_IRUSR | S_IWUSR);
if (fd <= 0) {
fd = open(pname, O_RDWR | O_CREAT | O_CLOEXEC | O_TRUNC, S_IROTH | S_IRUSR | S_IWUSR);
if (fd < 0) {
return -1;
}
@@ -318,7 +327,8 @@ void TestFrameStateCallback::OnFrameFinished(Camera &camera, FrameConfig &fc, Fr
if (buffer != nullptr) {
char *virtAddr = static_cast<char *>(buffer->GetVirAddr());
if (virtAddr != nullptr) {
SampleSaveCapture(virtAddr, buffer->GetSize(), gPhotoType_, timeStamp_, sizeof(timeStamp_));
SampleSaveCapture(virtAddr, buffer->GetSize(),
gPhotoType_, static_cast<const char *>(timeStamp_), sizeof(timeStamp_));
}
surface->ReleaseBuffer(buffer);
} else {
@@ -345,7 +355,7 @@ bool TestFrameStateCallback::IsFinish(void)
return gIsFinished_;
}
void TestFrameStateCallback::GetVideoName(char *pName, int length)
void TestFrameStateCallback::GetVideoName(char *pName, size_t length) const
{
if (strlen(videoName_) <= 0)
return;
@@ -575,10 +585,9 @@ SampleCameraManager::~SampleCameraManager()
}
}
int SampleCameraManager::SampleCameraCreate(int picMode)
int SampleCameraManager::SampleCameraCreate()
{
int retval = 0;
int timeout = 0;
printf("camera start init!!! \n");
camKit = CameraKit::GetInstance();
if (camKit == nullptr) {
@@ -592,9 +601,11 @@ int SampleCameraManager::SampleCameraCreate(int picMode)
const CameraAbility *ability = camKit->GetCameraAbility(cam);
/* find camera which fits user's ability */
list<CameraPicSize> sizeList = ability->GetSupportedSizes(0);
if (find(sizeList.begin(), sizeList.end(), CAM_PIC_1080P) != sizeList.end()) {
camId = cam;
break;
for (auto &pic : sizeList) {
if (pic.width == PIC_WIDTH && pic.height == PIC_HEIGHT) {
camId = cam;
break;
}
}
}
@@ -614,13 +625,13 @@ int SampleCameraManager::SampleCameraCreate(int picMode)
camKit->CreateCamera(camId, *CamStateMng, eventHdlr_);
printf("after CreateCamera \n");
if (!access("/userdata/", F_OK | R_OK | W_OK)) {
if (access(PHOTO_PATH, F_OK)) {
if (access(PHOTO_PATH, F_OK) != 0) {
mkdir(PHOTO_PATH, FILE_MODE);
}
if (access(THUMB_PATH, F_OK)) {
if (access(THUMB_PATH, F_OK) != 0) {
mkdir(THUMB_PATH, FILE_MODE);
}
if (access(VIDEO_PATH, F_OK)) {
if (access(VIDEO_PATH, F_OK) != 0) {
mkdir(VIDEO_PATH, FILE_MODE);
}
}
+26 -15
View File
@@ -48,26 +48,34 @@ typedef enum {
class TestFrameStateCallback : public FrameStateCallback {
public:
TestFrameStateCallback(){}
TestFrameStateCallback() : gPhotoType_(0), gIsFinished_(false) {}
~TestFrameStateCallback(){}
void OnFrameFinished(Camera &camera, FrameConfig &fc, FrameResult &result) override;
void SetPhotoType(int type);
bool IsFinish(void);
void GetVideoName(char *pName, int length);
void GetVideoName(char *pName, size_t length) const;
void InitVideoName();
void InitTimeStamp();
private:
int gPhotoType_;
bool gIsFinished_;
char videoName_[256];
char timeStamp_[256];
char videoName_[256] = {0};
char timeStamp_[256] = {0};
};
class SampleCameraStateMng : public CameraStateCallback {
public:
SampleCameraStateMng() = delete;
SampleCameraStateMng(EventHandler &eventHdlr) : eventHdlr_(eventHdlr) {}
SampleCameraStateMng(EventHandler &eventHdlr) : eventHdlr_(eventHdlr)
{
gRecordSta_ = 0;
gPreviewSta_ = 0;
gRecFd_ = -1;
cam_ = nullptr;
recorder_ = nullptr;
fc_ = nullptr;
}
~SampleCameraStateMng();
void OnCreated(Camera &c) override;
@@ -84,23 +92,27 @@ public:
bool IsCaptureOver(void);
private:
int gRecordSta_ = 0;
int gPreviewSta_ = 0;
int gRecFd_ = -1;
int gRecordSta_;
int gPreviewSta_;
int gRecFd_;
EventHandler &eventHdlr_;
Camera *cam_ = nullptr;
Recorder *recorder_ = nullptr;
Camera *cam_;
Recorder *recorder_;
TestFrameStateCallback fsCb_;
FrameConfig *fc_ = nullptr;
FrameConfig *fc_;
};
class SampleCameraManager {
public:
SampleCameraManager() = delete;
SampleCameraManager(int mode) : picMode(mode) {}
SampleCameraManager()
{
camKit = nullptr;
camId = "";
CamStateMng = nullptr;
}
~SampleCameraManager();
int SampleCameraCreate(int picMode);
int SampleCameraCreate();
bool SampleCameraExist(void);
int SampleCameraStart(Surface *surface);
int SampleCameraStop(void);
@@ -116,7 +128,6 @@ private:
CameraKit *camKit;
string camId;
SampleCameraStateMng *CamStateMng;
int picMode = 0;
EventHandler eventHdlr_;
};
+12 -4
View File
@@ -36,20 +36,28 @@ public:
onLongPress_ = std::move(onLongPress);
}
bool OnClick(UIView &view, const ClickEvent &event) override
bool OnClick(UIView& view, const ClickEvent &event) override
{
if (!onClick_) {
return false;
}
return onClick_(view, event);
UIView *currentView = &view;
if (currentView == nullptr) {
return false;
}
return onClick_(*currentView, event);
}
bool OnLongPress(UIView &view, const LongPressEvent &event) override
bool OnLongPress(UIView& view, const LongPressEvent &event) override
{
if (!onLongPress_) {
return false;
}
return onLongPress_(view, event);
UIView *currentView = &view;
if (currentView == nullptr) {
return false;
}
return onLongPress_(*currentView, event);
}
private:
View File
View File

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File
-27
View File
@@ -1,27 +0,0 @@
# Copyright (c) 2020 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/lite/config/component/lite_component.gni")
lite_component("sample") {
features = [
]
}
generate_notice_file("communication_sample") {
module_name = "communication_sample"
module_source_dir_list = [
"//third_party/wpa_supplicant/wpa_supplicant-2.9/hostapd",
"//third_party/wpa_supplicant/wpa_supplicant-2.9/wpa_supplicant",
]
}
-40
View File
@@ -1,40 +0,0 @@
# Copyright (c) 2020 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/lite/config/component/lite_component.gni")
sample_sources = [
"src/hostapd_sample.c",
]
config_file = [
"config/hostapd.conf"
]
executable("hostapd_sample_exe") {
output_name = "hostapd"
sources = sample_sources
}
group("hostapd_sample") {
deps = [
":hostapd_sample_exe",
]
}
copy("config") {
sources = config_file
outputs = [
"$root_out_dir/etc/hostapd.conf"
]
}
@@ -1,7 +0,0 @@
interface=wlan0
driver=hdf wifi
ctrl_interface=udp
ssid=testap
hw_mode=g
channel=1
ignore_broadcast_ssid=0
@@ -1,70 +0,0 @@
/*
* Copyright (c) 2020 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 <dlfcn.h>
#include <pthread.h>
#include <stdio.h>
#include <string.h>
pthread_t g_apThread;
char* g_apArg[20] = {0};
int g_apArgc = 0;
static void* ThreadMain()
{
printf("[HostapdSample]init hostapd.\n");
void *handleLibWpa = dlopen("/usr/lib/libwpa.so", RTLD_NOW | RTLD_LOCAL);
if (handleLibWpa == NULL) {
printf("[HostapdSample]dlopen libwpa failed.\n");
return NULL;
}
int (*func)(int, char **) = NULL;
func = dlsym(handleLibWpa, "ap_main");
if (func == NULL) {
dlclose(handleLibWpa);
printf("[HostapdSample]dlsym ap_main failed.\n");
return NULL;
}
int ret = func(g_apArgc, g_apArg);
printf("[HostapdSample]run ap_main failed, ret:%d.\n", ret);
for (int i = 0; i < g_apArgc; i++) {
printf("[HostapdSample]arg %d:%s.\n", i, g_apArg[i]);
}
if (dlclose(handleLibWpa) != 0) {
printf("[HostapdSample]dlclose libwpa failed.\n");
return NULL;
}
return NULL;
}
int main(int argc, char *argv[])
{
g_apArgc = argc;
for (int i = 0; i < g_apArgc; i++) {
g_apArg[i] = argv[i];
}
int ret = pthread_create(&g_apThread, NULL, ThreadMain, NULL);
if (ret != 0) {
printf("[HostapdSample]create thread failed error:%s.\n", strerror(ret));
return 1;
}
pthread_join(g_apThread, NULL);
return 0;
}
-44
View File
@@ -1,44 +0,0 @@
# Copyright (c) 2020 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/lite/config/component/lite_component.gni")
sample_sources = [
"src/wpa_cli_sample.c",
]
sample_include_dirs = [
"//third_party/wpa_supplicant/wpa_supplicant-2.9/src/",
"//third_party/bounds_checking_function:libsec_shared/include/"
]
executable("wpa_cli_exe") {
output_name = "wpa_cli"
sources = sample_sources
include_dirs = sample_include_dirs
out_dir = rebase_path(root_build_dir)
deps = [
"//third_party/wpa_supplicant/wpa_supplicant-2.9:wpa_supplicant",
"//third_party/bounds_checking_function:libsec_shared"
]
ldflags = [
"-L${out_dir}",
"-lwpa_client"
]
}
group("wpa_cli_sample") {
deps = [
":wpa_cli_exe",
]
}
-242
View File
@@ -1,242 +0,0 @@
/*
* Copyright (c) 2020 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 "utils/includes.h"
#include "pthread.h"
#include "common/wpa_ctrl.h"
#include "securec.h"
#define WPA_IFACE_NAME "wlan0"
#define WIFI_AUTH_FAILED_REASON_STR "WRONG_KEY"
#define WIFI_AUTH_FAILED_REASON_CODE "reason=2"
#define WPA_CTRL_REQUEST_OK "OK"
#define WPA_CTRL_REQUEST_FAIL "FAIL"
#define SAMPLE_INFO(format, args...) \
do { \
fprintf(stderr, "\033[1;32m WpaCliSample(%s:%d):\t\033[0m" format, __func__, __LINE__, ##args); \
printf("\n"); \
} while (0)
#define SAMPLE_ERROR(format, args...) \
do { \
fprintf(stderr, "\033[1;31m WpaCliSample(%s:%d):\t\033[0m" format, __func__, __LINE__, ##args); \
printf("\n"); \
} while (0)
static struct wpa_ctrl *g_monitorConn;
static struct wpa_ctrl *g_ctrlConn;
static pthread_t g_wpaThreadId;
static int g_scanAvailable = 0;
static void DumpString(const char *buf, int len, const char *tag)
{
SAMPLE_INFO("%s dump start.", tag);
for (int i = 0; i < len; i++) {
printf("%c", buf[i]);
}
printf("\n");
SAMPLE_INFO("%s dump end.", tag);
}
static int StrMatch(const char *a, const char *b)
{
return strncmp(a, b, strlen(b)) == 0;
}
static void WifiEventHandler(char *rawEvent, int len)
{
char *pos = rawEvent;
if (*pos == '<') {
pos = strchr(pos, '>');
if (pos) {
pos++;
} else {
pos = rawEvent;
}
}
if (StrMatch(pos, WPA_EVENT_CONNECTED)) {
SAMPLE_INFO("WIFI_EVENT_CONNECTED");
return;
}
if (StrMatch(pos, WPA_EVENT_SCAN_RESULTS)) {
SAMPLE_INFO("WIFI_EVENT_SCAN_DONE");
g_scanAvailable = 1;
return;
}
if (StrMatch(pos, WPA_EVENT_TEMP_DISABLED) && strstr(pos, WIFI_AUTH_FAILED_REASON_STR)) {
SAMPLE_INFO("WIFI_EVENT_WRONG_KEY");
return;
}
if (StrMatch(pos, WPA_EVENT_DISCONNECTED) && !strstr(pos, WIFI_AUTH_FAILED_REASON_CODE)) {
SAMPLE_INFO("WIFI_EVENT_DISCONNECTED");
return;
}
}
static void CliRecvPending(void)
{
while (wpa_ctrl_pending(g_monitorConn)) {
char buf[4096];
size_t len = sizeof(buf) - 1;
if (wpa_ctrl_recv(g_monitorConn, buf, &len) == 0) {
buf[len] = '\0';
SAMPLE_INFO("event received %s", buf);
WifiEventHandler(buf, len);
} else {
SAMPLE_INFO("could not read pending message.");
break;
}
}
}
static void* MonitorTask(void *args)
{
(void)args;
int fd, ret;
fd_set rfd;
while (1) {
fd = wpa_ctrl_get_fd(g_monitorConn);
FD_ZERO(&rfd);
FD_SET(fd, &rfd);
ret = select(fd + 1, &rfd, NULL, NULL, NULL);
if (ret <= 0) {
SAMPLE_INFO("select failed ret = %d\n", ret);
break;
}
CliRecvPending();
sleep(1);
}
return NULL;
}
static int SendCtrlCommand(const char *cmd, char *reply, size_t *replyLen)
{
size_t len = *replyLen - 1;
wpa_ctrl_request(g_ctrlConn, cmd, strlen(cmd), reply, &len, 0);
DumpString(reply, len, "SendCtrlCommand raw return");
if (len != 0 && !StrMatch(reply, WPA_CTRL_REQUEST_FAIL)) {
*replyLen = len;
return 0;
}
SAMPLE_ERROR("send ctrl request [%s] failed.", cmd);
return -1;
}
static void TestNetworkConfig(void)
{
char networkId[20] = {0};
size_t networkIdLen = sizeof(networkId);
int ret = SendCtrlCommand("DISCONNECT", networkId, &networkIdLen);
ret += SendCtrlCommand("ADD_NETWORK", networkId, &networkIdLen);
if (ret != 0) {
SAMPLE_ERROR("add network failed.");
return;
}
SAMPLE_INFO("add network success, network id [%.*s]", networkIdLen, networkId);
char reply[100] = {0};
size_t replyLen = sizeof(reply);
char cmd[200] = {0};
sprintf_s(cmd, sizeof(cmd), "SET_NETWORK %.*s ssid \"example\"", networkIdLen, networkId);
ret += SendCtrlCommand(cmd, reply, &replyLen);
replyLen = sizeof(reply);
sprintf_s(cmd, sizeof(cmd), "SET_NETWORK %.*s psk \"012345678\"", networkIdLen, networkId);
ret += SendCtrlCommand(cmd, reply, &replyLen);
replyLen = sizeof(reply);
sprintf_s(cmd, sizeof(cmd), "ENABLE_NETWORK %.*s", networkIdLen, networkId);
ret += SendCtrlCommand(cmd, reply, &replyLen);
replyLen = sizeof(reply);
ret += SendCtrlCommand("RECONNECT", reply, &replyLen);
replyLen = sizeof(reply);
if (ret == 0) {
SAMPLE_INFO("network config success.");
return;
}
sprintf_s(cmd, sizeof(cmd), "REMOVE_NETWORK %.*s", networkIdLen, networkId);
SendCtrlCommand(cmd, reply, &replyLen);
SAMPLE_ERROR("network config failed remove network [%.*s].", networkIdLen, networkId);
}
static void TestCliConnection(void)
{
char reply[100] = {0};
size_t replyLen = sizeof(reply);
int ret = SendCtrlCommand("PING", reply, &replyLen);
if (ret == 0 && StrMatch(reply, "PONG")) {
SAMPLE_INFO("connect to wpa success.");
return;
}
SAMPLE_INFO("connect to wpa failed, err = %s.", reply);
}
static void TestScan()
{
char reply[100] = {0};
size_t replyLen = sizeof(reply);
g_scanAvailable = 0;
SendCtrlCommand("SCAN", reply, &replyLen);
while (1) {
sleep(1);
if (g_scanAvailable == 1) {
SAMPLE_INFO("scan result received.");
break;
}
SAMPLE_INFO("waiting scan result.");
}
char scanResult[4096] = {0};
size_t scanLen = sizeof(scanResult);
int ret = SendCtrlCommand("SCAN_RESULTS", scanResult, &scanLen);
if (ret != 0) {
SAMPLE_ERROR("request scan results failed.");
return;
}
DumpString(scanResult, scanLen, "scan results");
}
static void StartTest()
{
TestCliConnection(); // test if wpa control interface connected successfully
TestScan(); // test scan and get scan results
TestNetworkConfig(); // test config network and connect
}
int InitControlInterface()
{
g_ctrlConn = wpa_ctrl_open(WPA_IFACE_NAME); // create control interface for send cmd
g_monitorConn = wpa_ctrl_open(WPA_IFACE_NAME); // create control interface for event monitor
if (!g_ctrlConn || !g_monitorConn) {
SAMPLE_ERROR("open wpa control interface failed.");
return -1;
}
if (wpa_ctrl_attach(g_monitorConn) == 0) { // start monitor
pthread_create(&g_wpaThreadId, NULL, MonitorTask, NULL); // create thread for read event
return 0;
}
return -1;
}
int main()
{
if (InitControlInterface() != 0) {
SAMPLE_ERROR("control interface init failed, exit client.");
return -1;
}
SAMPLE_INFO("control interface init success.");
StartTest();
pthread_join(g_wpaThreadId, NULL);
SAMPLE_INFO("test finished, exit client.");
}
-40
View File
@@ -1,40 +0,0 @@
# Copyright (c) 2020 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/lite/config/component/lite_component.gni")
sample_sources = [
"src/wpa_sample.c",
]
config_file = [
"config/wpa_supplicant.conf"
]
executable("wpa_sample_exe") {
output_name = "wpa_supplicant"
sources = sample_sources
}
group("wpa_sample") {
deps = [
":wpa_sample_exe",
]
}
copy("config") {
sources = config_file
outputs = [
"$root_out_dir/etc/wpa_supplicant.conf"
]
}
@@ -1,4 +0,0 @@
country=GB
ctrl_interface=udp
network={
}
@@ -1,70 +0,0 @@
/*
* Copyright (c) 2020 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 <dlfcn.h>
#include <pthread.h>
#include <stdio.h>
#include <string.h>
pthread_t g_wpaThread;
char* g_wpaArg[20] = {0};
int g_wpaArgc = 0;
static void* ThreadMain()
{
printf("[WpaSample]init wpa_supplicant.\n");
void *handleLibWpa = dlopen("/usr/lib/libwpa.so", RTLD_NOW | RTLD_LOCAL);
if (handleLibWpa == NULL) {
printf("[WpaSample]dlopen libwpa failed.\n");
return NULL;
}
int (*func)(int, char **) = NULL;
func = dlsym(handleLibWpa, "wpa_main");
if (func == NULL) {
dlclose(handleLibWpa);
printf("[WpaSample]dlsym wpa_main failed.\n");
return NULL;
}
int ret = func(g_wpaArgc, g_wpaArg);
printf("[WpaSample]run wpa_main failed, ret:%d.\n", ret);
for (int i = 0; i < g_wpaArgc; i++) {
printf("[WpaSample]arg %d:%s.\n", i, g_wpaArg[i]);
}
if (dlclose(handleLibWpa) != 0) {
printf("[WpaSample]dlclose libwpa failed.\n");
return NULL;
}
return NULL;
}
int main(int argc, char *argv[])
{
g_wpaArgc = argc;
for (int i = 0; i < g_wpaArgc; i++) {
g_wpaArg[i] = argv[i];
}
int ret = pthread_create(&g_wpaThread, NULL, ThreadMain, NULL);
if (ret != 0) {
printf("[WpaSample]create thread failed error:%s.\n", strerror(ret));
return 1;
}
pthread_join(g_wpaThread, NULL);
return 0;
}
-20
View File
@@ -1,20 +0,0 @@
# Copyright (c) 2020 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/lite/config/component/lite_component.gni")
lite_component("service_example") {
features = [
"consumer:consumer_service",
"provider:provider_service",
]
}
-49
View File
@@ -1,49 +0,0 @@
# Copyright (c) 2020 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/lite/config/component/lite_component.gni")
executable("consumer_proc") {
sources = [
"proc.c",
"client_example.c",
"default_call_test.c",
"feature_call_test.c",
]
ldflags = [
"-Wl,-Map=consumer_proc.map",
]
include_dirs = [
"include",
"//kernel/liteos_a/kernel/include",
"//kernel/liteos_a/kernel/common",
"//third_party/bounds_checking_function/include",
"//kernel/liteos_a/kernel/include",
"//kernel/liteos_a/kernel/common",
"//utils/native/lite/include",
"//foundation/distributedschedule/interfaces/kits/samgr_lite/registry",
"//foundation/distributedschedule/interfaces/kits/samgr_lite/samgr",
"//foundation/distributedschedule/interfaces/kits/samgr_lite/communication/broadcast",
]
deps = [
"//foundation/distributedschedule/services/samgr_lite/samgr:samgr",
]
}
lite_component("consumer_service") {
features = [
":consumer_proc",
]
}
-142
View File
@@ -1,142 +0,0 @@
/*
* Copyright (c) 2020 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 "example.h"
#include <pthread.h>
#include <securec.h>
#include <ohos_errno.h>
#include <log.h>
#include <iproxy_client.h>
#define MAX_DATA_LEN 0x100
enum FUNCID {
ID_ASYNCALL = 0,
ID_ASYNTIMECALL,
ID_SYNCCALL,
ID_ASYNCCALLBACK
};
typedef struct DemoClientProxy {
INHERIT_CLIENT_IPROXY;
BOOL (*AsyncCall)(IUnknown *iUnknown, const char *buff);
BOOL (*AsyncTimeCall)(IUnknown *iUnknown);
BOOL (*SyncCall)(IUnknown *iUnknown, struct Payload *payload);
BOOL (*AsyncCallBack)(IUnknown *iUnknown, const char *buff, IOwner notify, INotifyFunc handler);
} DemoClientProxy;
typedef struct DemoClientEntry {
INHERIT_IUNKNOWNENTRY(DemoClientProxy);
} DemoClientEntry;
static BOOL AsyncCall(IUnknown *iUnknown, const char *buff);
static BOOL AsyncTimeCall(IUnknown *iUnknown);
static BOOL SyncCall(IUnknown *iUnknown, struct Payload *payload);
static BOOL AsyncCallBack(IUnknown *iUnknown, const char *buff, IOwner notify, INotifyFunc handler);
void *DEMO_CreatClient(const char *service, const char *feature, uint32 size)
{
(void)service;
(void)feature;
uint32 len = size + sizeof(DemoClientEntry);
uint8 *client = malloc(len);
if (client == NULL) {
return NULL;
}
(void)memset_s(client, len, 0, len);
DemoClientEntry *entry = (DemoClientEntry *)&client[size];
entry->ver = ((uint16)CLIENT_PROXY_VER | (uint16)DEFAULT_VERSION);
entry->ref = 1;
entry->iUnknown.QueryInterface = IUNKNOWN_QueryInterface;
entry->iUnknown.AddRef = IUNKNOWN_AddRef;
entry->iUnknown.Release = IUNKNOWN_Release;
entry->iUnknown.Invoke = NULL;
entry->iUnknown.AsyncCall = AsyncCall;
entry->iUnknown.AsyncTimeCall = AsyncTimeCall;
entry->iUnknown.SyncCall = SyncCall;
entry->iUnknown.AsyncCallBack = AsyncCallBack;
return client;
}
void DEMO_DestroyClient(const char *service, const char *feature, void *iproxy)
{
free(iproxy);
}
static BOOL AsyncCall(IUnknown *iUnknown, const char *buff)
{
DemoClientProxy *proxy = (DemoClientProxy *)iUnknown;
IpcIo request;
char data[MAX_DATA_LEN];
IpcIoInit(&request, data, MAX_DATA_LEN, 0);
IpcIoPushString(&request, buff);
int ret = proxy->Invoke((IClientProxy *)proxy, ID_ASYNCALL, &request, NULL, NULL);
return ret == EC_SUCCESS;
}
static BOOL AsyncTimeCall(IUnknown *iUnknown)
{
DemoClientProxy *proxy = (DemoClientProxy *)iUnknown;
IpcIo request;
char data[MAX_DATA_LEN];
IpcIoInit(&request, data, MAX_DATA_LEN, 0);
int ret = proxy->Invoke((IClientProxy *)proxy, ID_ASYNTIMECALL, &request, NULL, NULL);
return ret == EC_SUCCESS;
}
static int Callback(IOwner owner, int code, IpcIo *reply)
{
size_t len = 0;
char *src = (char *)IpcIoPopString(reply, &len);
if (src == NULL) {
return EC_BADPTR;
}
return strcpy_s(owner, MAX_DATA_LEN, src);
}
static BOOL SyncCall(IUnknown *iUnknown, struct Payload *payload)
{
DemoClientProxy *proxy = (DemoClientProxy *)iUnknown;
IpcIo request;
char data[MAX_DATA_LEN];
IpcIoInit(&request, data, MAX_DATA_LEN, 0);
IpcIoPushInt32(&request, payload->id);
IpcIoPushInt32(&request, payload->value);
IpcIoPushString(&request, payload->name);
int ret = proxy->Invoke((IClientProxy *)proxy, ID_SYNCCALL, &request, data, Callback);
data[MAX_DATA_LEN - 1] = 0;
HILOG_INFO(HILOG_MODULE_APP, "[TID:0x%lx]Remote response is %s!", (unsigned long)pthread_self(), data);
return ret == EC_SUCCESS;
}
struct CurrentNotify {
IOwner notify;
INotifyFunc handler;
};
static int CurrentCallback(IOwner owner, int code, IpcIo *reply)
{
struct CurrentNotify *notify = (struct CurrentNotify *)owner;
size_t len = 0;
char *response = (char *)IpcIoPopString(reply, &len);
if (response == NULL) {
return EC_BADPTR;
}
HILOG_INFO(HILOG_MODULE_APP, "[TID:0x%lx]Notify Remote response is %s!", (unsigned long)pthread_self(), response);
notify->handler(notify->notify, response);
return EC_SUCCESS;
}
static BOOL AsyncCallBack(IUnknown *iUnknown, const char *buff, IOwner notify, INotifyFunc handler)
{
struct CurrentNotify owner = {notify, handler};
DemoClientProxy *proxy = (DemoClientProxy *)iUnknown;
IpcIo request;
char data[MAX_DATA_LEN];
IpcIoInit(&request, data, MAX_DATA_LEN, 0);
IpcIoPushString(&request, buff);
int ret = proxy->Invoke((IClientProxy *)proxy, ID_ASYNCCALLBACK, &request, &owner, CurrentCallback);
return ret == EC_SUCCESS;
}
-67
View File
@@ -1,67 +0,0 @@
/*
* Copyright (c) 2020 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 "example.h"
#include <iproxy_client.h>
#include <samgr_lite.h>
#include <log.h>
#include <pthread.h>
#define MAX_DATA_LEN 250
static IClientProxy *CASE_GetRemoteIUnknown(void)
{
IClientProxy *demoApi = NULL;
HILOG_INFO(HILOG_MODULE_APP, "[TID:0x%lx][GetDefaultFeatureApi S:%s]: BEGIN",
(unsigned long)pthread_self(), EXAMPLE_SERVICE);
IUnknown *iUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi(EXAMPLE_SERVICE);
if (iUnknown == NULL) {
HILOG_INFO(HILOG_MODULE_APP, "[TID:0x%lx][GetDefaultFeatureApi S:%s]: error is NULL",
(unsigned long)pthread_self(), EXAMPLE_SERVICE);
return NULL;
}
(void)iUnknown->QueryInterface(iUnknown, CLIENT_PROXY_VER, (void **)&demoApi);
HILOG_INFO(HILOG_MODULE_APP, "[TID:0x%lx][QueryInterface CLIENT_PROXY_VER S:%s]: is %p",
(unsigned long)pthread_self(), EXAMPLE_SERVICE, demoApi);
return demoApi;
}
static void CASE_SyncCall(IClientProxy *defaultApi)
{
HILOG_INFO(HILOG_MODULE_APP, "[TID:0x%lx][CASE_SyncCall api S:%s]: is %p",
(unsigned long)pthread_self(), EXAMPLE_SERVICE, defaultApi);
if (defaultApi == NULL) {
return;
}
IpcIo request;
char data[MAX_DATA_LEN];
IpcIoInit(&request, data, sizeof(data), 0);
defaultApi->Invoke(defaultApi, 0, &request, NULL, NULL);
}
static void CASE_ReleaseIUnknown(IUnknown *demoApi)
{
if (demoApi == NULL) {
return;
}
int32 ref = demoApi->Release((IUnknown *)demoApi);
HILOG_INFO(HILOG_MODULE_APP, "[TID:0x%lx][Release api S:%s]: is %p ref:%d",
(unsigned long)pthread_self(), EXAMPLE_SERVICE, demoApi, ref);
}
void RunServiceTestCase(void)
{
IClientProxy *remoteApi = CASE_GetRemoteIUnknown();
CASE_SyncCall(remoteApi);
CASE_ReleaseIUnknown((IUnknown *)remoteApi);
}
-58
View File
@@ -1,58 +0,0 @@
/*
* Copyright (c) 2020 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 LITE_EXAMPLE_H
#define LITE_EXAMPLE_H
#include <iunknown.h>
#include <iproxy_server.h>
#include <iproxy_client.h>
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif
#define EXAMPLE_SERVICE "ex_service"
#define EXAMPLE_FEATURE "ex_feature"
typedef struct DefaultFeatureApi {
INHERIT_SERVER_IPROXY;
void (*SyncCall)(IUnknown *iUnknown);
} DefaultFeatureApi;
struct Payload {
int id;
const char *name;
int value;
};
typedef void *IOwner;
typedef void (*INotifyFunc)(IOwner owner, const char *resp);
typedef struct ClientDemo {
INHERIT_CLIENT_IPROXY;
BOOL (*AsyncCall)(IUnknown *iUnknown, const char *buff);
BOOL (*AsyncTimeCall)(IUnknown *iUnknown);
BOOL (*SyncCall)(IUnknown *iUnknown, struct Payload *payload);
BOOL (*AsyncCallBack)(IUnknown *iUnknown, const char *buff, IOwner notify, INotifyFunc handler);
} ClientDemo;
void DEMO_DestroyClient(const char *service, const char *feature, void *iproxy);
void *DEMO_CreatClient(const char *service, const char *feature, uint32 size);
void RunServiceTestCase(void);
void RunFeatureTestCase(void);
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif
#endif // LITE_EXAMPLE_H
-110
View File
@@ -1,110 +0,0 @@
/*
* Copyright (c) 2020 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 "example.h"
#include <log.h>
#include <pthread.h>
#include <samgr_lite.h>
static ClientDemo *CASE_GetIUnknown(void)
{
ClientDemo *demoApi = NULL;
HILOG_INFO(HILOG_MODULE_APP, "[TID:0x%lx][GetFeatureApi S:%s F:%s]: BEGIN\n",
(unsigned long)pthread_self(), EXAMPLE_SERVICE, EXAMPLE_FEATURE);
IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(EXAMPLE_SERVICE, EXAMPLE_FEATURE);
if (iUnknown == NULL) {
HILOG_INFO(HILOG_MODULE_APP, "[TID:0x%lx][GetFeatureApi S:%s F:%s]: error is NULL\n",
(unsigned long)pthread_self(), EXAMPLE_SERVICE, EXAMPLE_FEATURE);
return NULL;
}
(void)iUnknown->QueryInterface(iUnknown, DEFAULT_VERSION, (void **)&demoApi);
HILOG_INFO(HILOG_MODULE_APP, "[TID:0x%lx][QueryInterface DEFAULT_VERSION S:%s, F:%s]: is %p\n",
(unsigned long)pthread_self(), EXAMPLE_SERVICE, EXAMPLE_FEATURE, demoApi);
return demoApi;
}
static void CASE_SyncCall(ClientDemo *demoApi)
{
if (demoApi == NULL || demoApi->SyncCall == NULL) {
return;
}
HILOG_INFO(HILOG_MODULE_APP, "[TID:0x%lx]SyncCall BEGIN\n", (unsigned long)pthread_self());
struct Payload payload = {
.id = 0,
.name = "I wanna sync call good result!",
.value = 1
};
BOOL ret = demoApi->SyncCall((IUnknown *)demoApi, &payload);
HILOG_INFO(HILOG_MODULE_APP, "[TID:0x%lx]SyncCall End(%d)\n", (unsigned long)pthread_self(), ret);
}
static void CASE_AsyncCall(ClientDemo *demoApi)
{
if (demoApi == NULL || demoApi->AsyncCall == NULL) {
return;
}
HILOG_INFO(HILOG_MODULE_APP, "[TID:0x%lx]AsyncCall BEGIN\n", (unsigned long)pthread_self());
BOOL ret = demoApi->AsyncCall((IUnknown *)demoApi, "I wanna async call good result!");
HILOG_INFO(HILOG_MODULE_APP, "[TID:0x%lx]AsyncCall End(%d)\n", (unsigned long)pthread_self(), ret);
}
static void CASE_AsyncTimeCall(ClientDemo *demoApi)
{
if (demoApi == NULL || demoApi->AsyncTimeCall == NULL) {
return;
}
HILOG_INFO(HILOG_MODULE_APP, "[TID:0x%lx]AsyncTimeCall BEGIN\n", (unsigned long)pthread_self());
BOOL ret = demoApi->AsyncTimeCall((IUnknown *)demoApi);
HILOG_INFO(HILOG_MODULE_APP, "[TID:0x%lx]AsyncTimeCall End(%d)\n", (unsigned long)pthread_self(), ret);
}
void AsyncHandler(IOwner owner, const char *resp)
{
HILOG_INFO(HILOG_MODULE_APP, "[TID:0x%lx]AsyncCallBack Owner:%p, Response:%s\n",
(unsigned long)pthread_self(), owner, resp);
}
static void CASE_AsyncCallBack(ClientDemo *demoApi)
{
if (demoApi == NULL || demoApi->AsyncCallBack == NULL) {
return;
}
HILOG_INFO(HILOG_MODULE_APP, "[TID:0x%lx]AsyncCallBack BEGIN\n", (unsigned long)pthread_self());
BOOL ret = demoApi->AsyncCallBack((IUnknown *)demoApi,
"I wanna async call callback good result!", NULL, AsyncHandler);
HILOG_INFO(HILOG_MODULE_APP, "[TID:0x%lx]AsyncCallBack End(%d)\n", (unsigned long)pthread_self(), ret);
}
static void CASE_ReleaseIUnknown(ClientDemo *demoApi)
{
if (demoApi == NULL) {
return;
}
int32 ref = demoApi->Release((IUnknown *)demoApi);
HILOG_INFO(HILOG_MODULE_APP, "[TID:0x%lx][Release api S:%s, F:%s]: is %p ref:%d\n",
(unsigned long)pthread_self(), EXAMPLE_SERVICE, EXAMPLE_FEATURE, demoApi, ref);
}
void RunFeatureTestCase(void)
{
ClientDemo *demoApi = CASE_GetIUnknown();
CASE_AsyncCall(demoApi);
CASE_AsyncTimeCall(demoApi);
CASE_SyncCall(demoApi);
CASE_AsyncCallBack(demoApi);
CASE_ReleaseIUnknown(demoApi);
}
-57
View File
@@ -1,57 +0,0 @@
/*
* Copyright (c) 2020 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 <unistd.h>
#include <securec.h>
#include "samgr_lite.h"
#include "registry.h"
#include "example.h"
const char FUN_ARG_S[] = "0123456I";
#define DEFAULT 0
#define INTERVAL 10
#define MAX_LEN 0x100
#define MAX_TEST_TIMES 3600
void __attribute__((weak)) OHOS_SystemInit(void)
{
SAMGR_Bootstrap();
};
void HiLogPrintf(unsigned char module, unsigned char level, const char *nums, const char *fmt, ...);
int main()
{
HiLogPrintf(DEFAULT, DEFAULT, NULL, "Start Consumer System Start");
SAMGR_RegisterFactory(EXAMPLE_SERVICE, EXAMPLE_FEATURE, DEMO_CreatClient, DEMO_DestroyClient);
OHOS_SystemInit();
HiLogPrintf(DEFAULT, DEFAULT, NULL, "Start Consumer System End");
int times = 0;
while (times < MAX_TEST_TIMES) {
sleep(INTERVAL);
RunServiceTestCase();
RunFeatureTestCase();
++times;
}
}
void __attribute__((weak)) HiLogPrintf(unsigned char module, unsigned char level,
const char *nums, const char *fmt, ...)
{
static char buf[MAX_LEN] = {0};
va_list args;
va_start(args, fmt);
int ret = vsprintf_s(buf, sizeof(buf), fmt, args);
va_end(args);
if (ret < 0) {
printf("Consumer fmt failed(%d)", ret);
}
printf("Consumer M:%d l:%d %s\n", module, level, buf);
}
-41
View File
@@ -1,41 +0,0 @@
# Copyright (c) 2020 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/lite/config/component/lite_component.gni")
executable("server_proc") {
sources = [
"proc.c",
]
ldflags = [
"-Wl,-Map=server_proc.map",
]
include_dirs = [
"include",
"//third_party/bounds_checking_function/include",
"//utils/native/lite/include",
"//foundation/distributedschedule/interfaces/kits/samgr_lite/samgr",
]
deps = [
"//foundation/distributedschedule/services/samgr_lite/samgr_server:server",
]
}
lite_component("samgr_server") {
features = [
":server_proc",
]
}
-46
View File
@@ -1,46 +0,0 @@
/*
* Copyright (c) 2020 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 <unistd.h>
#include <securec.h>
#include "samgr_lite.h"
const char FUN_ARG_S[] = "0123456I";
#define DEFAULT 0
#define MAX_LEN 0x100
void __attribute__((weak)) OHOS_SystemInit(void)
{
SAMGR_Bootstrap();
};
void HiLogPrintf(unsigned char module, unsigned char level, const char *nums, const char *fmt, ...);
int main()
{
HiLogPrintf(DEFAULT, DEFAULT, NULL, "Start Server System Start");
OHOS_SystemInit();
HiLogPrintf(DEFAULT, DEFAULT, NULL, "Start Server System End");
pause();
}
void __attribute__((weak)) HiLogPrintf(unsigned char module, unsigned char level,
const char *nums, const char *fmt, ...)
{
static char buf[MAX_LEN] = {0};
va_list args;
va_start(args, fmt);
int ret = vsprintf_s(buf, sizeof(buf), fmt, args);
va_end(args);
if (ret < 0) {
printf("Server fmt failed(%d)", ret);
}
printf("Server M:%d l:%d %s\n", module, level, buf);
}
-49
View File
@@ -1,49 +0,0 @@
# Copyright (c) 2020 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/lite/config/component/lite_component.gni")
executable("provider_proc") {
sources = [
"proc.c",
"feature_example.c",
"service_example.c",
]
ldflags = [
"-Wl,-Map=provider_proc.map",
]
include_dirs = [
"include",
"//third_party/bounds_checking_function/include",
"//kernel/liteos_a/kernel/include",
"//kernel/liteos_a/kernel/common",
"//utils/native/lite/include",
"//kernel/liteos_a/kernel/include",
"//kernel/liteos_a/kernel/common",
"//foundation/distributedschedule/interfaces/kits/samgr_lite/registry",
"//foundation/distributedschedule/interfaces/kits/samgr_lite/samgr",
"//foundation/distributedschedule/interfaces/kits/samgr_lite/communication/broadcast",
"//foundation/distributedschedule/services/samgr_lite/samgr/source",
]
deps = [
"//foundation/distributedschedule/services/samgr_lite/samgr:samgr",
]
}
lite_component("provider_service") {
features = [
":provider_proc",
]
}
-55
View File
@@ -1,55 +0,0 @@
/*
* Copyright (c) 2020 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 LITE_EXAMPLE_H
#define LITE_EXAMPLE_H
#include <iunknown.h>
#include <iproxy_server.h>
#include <iproxy_client.h>
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif
#define EXAMPLE_SERVICE "ex_service"
#define EXAMPLE_FEATURE "ex_feature"
typedef struct DefaultFeatureApi {
INHERIT_SERVER_IPROXY;
void (*SyncCall)(IUnknown *iUnknown);
} DefaultFeatureApi;
struct Payload {
int id;
const char *name;
int value;
};
typedef void *IOwner;
typedef void (*INotifyFunc)(IOwner owner, const char *resp);
typedef struct ClientDemo {
INHERIT_CLIENT_IPROXY;
BOOL (*AsyncCall)(IUnknown *iUnknown, const char *buff);
BOOL (*AsyncTimeCall)(IUnknown *iUnknown);
BOOL (*SyncCall)(IUnknown *iUnknown, struct Payload *payload);
BOOL (*AsyncCallBack)(IUnknown *iUnknown, const char *buff, IOwner notify, INotifyFunc handler);
} ClientDemo;
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif
#endif // LITE_EXAMPLE_H
-236
View File
@@ -1,236 +0,0 @@
/*
* Copyright (c) 2020 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 "example.h"
#include <ohos_init.h>
#include <securec.h>
#include <samgr_maintenance.h>
#include <log.h>
#include <unistd.h>
#include <pthread.h>
#include <ohos_errno.h>
#include "feature.h"
#include "service.h"
#include "samgr_lite.h"
#define WAIT_FEATURE_PROC 1000
enum MessageId {
MSG_PROC,
MSG_TIME_PROC,
};
typedef struct DemoFeatureApi {
INHERIT_SERVER_IPROXY;
BOOL (*AsyncCall)(IUnknown *iUnknown, const char *buff);
BOOL (*AsyncTimeCall)(IUnknown *iUnknown);
BOOL (*SyncCall)(IUnknown *iUnknown, struct Payload *payload);
BOOL (*AsyncCallBack)(IUnknown *iUnknown, const char *buff, IOwner notify, INotifyFunc handler);
} DemoFeatureApi;
typedef struct DemoFeature {
INHERIT_FEATURE;
INHERIT_IUNKNOWNENTRY(DemoFeatureApi);
Identity identity;
} DemoFeature;
static BOOL AsyncCall(IUnknown *iUnknown, const char *body);
static BOOL AsyncTimeCall(IUnknown *iUnknown);
static BOOL SyncCall(IUnknown *iUnknown, struct Payload *payload);
static BOOL AsyncCallBack(IUnknown *iUnknown, const char *body, IOwner notify, INotifyFunc handler);
static const char *FEATURE_GetName(Feature *feature);
static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity);
static void FEATURE_OnStop(Feature *feature, Identity identity);
static BOOL FEATURE_OnMessage(Feature *feature, Request *request);
static int32 Invoke(IServerProxy *iProxy, int funcId, void *origin, IpcIo *req, IpcIo *reply);
static DemoFeature g_example = {
.GetName = FEATURE_GetName,
.OnInitialize = FEATURE_OnInitialize,
.OnStop = FEATURE_OnStop,
.OnMessage = FEATURE_OnMessage,
SERVER_IPROXY_IMPL_BEGIN,
.Invoke = Invoke,
.AsyncCall = AsyncCall,
.AsyncTimeCall = AsyncTimeCall,
.SyncCall = SyncCall,
.AsyncCallBack = AsyncCallBack,
IPROXY_END,
.identity = {-1, -1, NULL},
};
static const char *FEATURE_GetName(Feature *feature)
{
(void)feature;
return EXAMPLE_FEATURE;
}
static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity)
{
DemoFeature *demoFeature = (DemoFeature *)feature;
demoFeature->identity = identity;
}
static void FEATURE_OnStop(Feature *feature, Identity identity)
{
(void)feature;
(void)identity;
g_example.identity.queueId = NULL;
g_example.identity.featureId = -1;
g_example.identity.serviceId = -1;
}
static BOOL FEATURE_OnMessage(Feature *feature, Request *msg)
{
HILOG_INFO(HILOG_MODULE_APP, "[TID:0x%lx]OnMessage(%s)! Request<%d, %d, %p>",
(unsigned long)pthread_self(), feature->GetName(feature), msg->msgId, msg->msgValue, msg->data);
if (msg->msgId == MSG_PROC) {
Response response;
response.data = "Yes, you did!";
response.len = 0;
SAMGR_SendResponse(msg, &response);
return TRUE;
}
if (msg->msgId == MSG_TIME_PROC) {
if (msg->msgValue) {
SAMGR_PrintServices();
} else {
SAMGR_PrintOperations();
}
return TRUE;
}
return FALSE;
}
static BOOL SyncCall(IUnknown *iUnknown, struct Payload *payload)
{
(void)iUnknown;
if (payload != NULL && payload->name != NULL) {
HILOG_INFO(HILOG_MODULE_APP, "[TID:0x%lx]SyncCall[%p, %p]! Payload<%s, %d, %d>",
(unsigned long)pthread_self(), iUnknown, payload, payload->name, payload->id, payload->value);
return TRUE;
}
HILOG_INFO(HILOG_MODULE_APP, "[TID:0x%lx]SyncCall[%p, %p]!", (unsigned long)pthread_self(), iUnknown, payload);
return FALSE;
}
static BOOL AsyncCall(IUnknown *iUnknown, const char *body)
{
Request request;
request.msgId = MSG_PROC;
request.msgValue = 0;
request.len = (uint32_t)(strlen(body) + 1);
request.data = malloc(request.len);
if (request.data == NULL) {
return FALSE;
}
if (strcpy_s(request.data, request.len, body) != EOK) {
free(request.data);
return FALSE;
}
DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown);
HILOG_INFO(HILOG_MODULE_APP, "[TID:0x%lx]AsyncCall[%p, %s]!", (unsigned long)pthread_self(), iUnknown, body);
return SAMGR_SendRequest(&feature->identity, &request, NULL);
}
static BOOL AsyncTimeCall(IUnknown *iUnknown)
{
static BOOL cnt = FALSE;
cnt = !cnt;
HILOG_INFO(HILOG_MODULE_APP, "[TID:0x%lx]AsyncTimeCall[%p] MSG_TIME_PROC count=%d!",
(unsigned long)pthread_self(), iUnknown, cnt);
Request request;
request.msgId = MSG_TIME_PROC;
request.msgValue = cnt;
request.len = 0;
request.data = NULL;
DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown);
return SAMGR_SendRequest(&feature->identity, &request, NULL);
}
typedef struct AsyncBody {
IOwner owner;
INotifyFunc handler;
char body[0];
} AsyncBody;
static void LocalHandler(const Request *request, const Response *response)
{
AsyncBody *body = (AsyncBody *)request->data;
body->handler(body->owner, response->data);
}
static BOOL AsyncCallBack(IUnknown *iUnknown, const char *body, IOwner notify, INotifyFunc handler)
{
int len = strlen(body) + 1;
Request request;
request.msgId = MSG_PROC;
request.msgValue = 0;
request.len = (uint32_t)(sizeof(struct AsyncBody) + len);
request.data = malloc(request.len);
if (request.data == NULL) {
return FALSE;
}
if (strcpy_s(((AsyncBody *)request.data)->body, len, body) != EOK) {
free(request.data);
return FALSE;
}
((AsyncBody *)request.data)->owner = notify;
((AsyncBody *)request.data)->handler = handler;
DemoFeature *feature = GET_OBJECT(iUnknown, DemoFeature, iUnknown);
HILOG_INFO(HILOG_MODULE_APP, "[TID:0x%lx]AsyncCallBack[%p, %s, %p, %p]!",
(unsigned long)pthread_self(), iUnknown, body, notify, handler);
return SAMGR_SendRequest(&feature->identity, &request, LocalHandler);
}
enum FUNCID {
ID_ASYNCALL = 0,
ID_ASYNTIMECALL,
ID_SYNCCALL,
ID_ASYNCCALLBACK
};
static int32 Invoke(IServerProxy *iProxy, int funcId, void *origin, IpcIo *req, IpcIo *reply)
{
HILOG_INFO(HILOG_MODULE_APP, "[TID:0x%lx]Feature Remote Invoke is called! <%p, %d, %p, %p, %p>",
(unsigned long)pthread_self(), iProxy, funcId, origin, req, reply);
DemoFeatureApi *api = (DemoFeatureApi *)iProxy;
BOOL ret;
size_t len = 0;
switch (funcId) {
case ID_ASYNCALL:
ret = api->AsyncCall((IUnknown *)iProxy, (char *)IpcIoPopString(req, &len));
IpcIoPushBool(reply, ret);
break;
case ID_ASYNTIMECALL:
ret = api->AsyncTimeCall((IUnknown *)iProxy);
IpcIoPushBool(reply, ret);
break;
case ID_SYNCCALL: {
struct Payload payload;
payload.id = IpcIoPopInt32(req);
payload.value = IpcIoPopInt32(req);
payload.name = (char *)IpcIoPopString(req, &len);
ret = api->SyncCall((IUnknown *)iProxy, &payload);
IpcIoPushString(reply, ret ? "TRUE" : "FALSE");
}
break;
case ID_ASYNCCALLBACK: { // convert to sync proxy
IpcIoPushString(reply, "Yes, you did!");
IpcIoPushBool(reply, TRUE);
}
break;
default:
IpcIoPushBool(reply, FALSE);
break;
}
return EC_SUCCESS;
}
static void Init(void)
{
SAMGR_GetInstance()->RegisterFeature(EXAMPLE_SERVICE, (Feature *)&g_example);
SAMGR_GetInstance()->RegisterFeatureApi(EXAMPLE_SERVICE, EXAMPLE_FEATURE, GET_IUNKNOWN(g_example));
}
SYSEX_FEATURE_INIT(Init);
-45
View File
@@ -1,45 +0,0 @@
/*
* Copyright (c) 2020 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 <unistd.h>
#include <securec.h>
#include "samgr_lite.h"
const char FUN_ARG_S[] = "0123456I";
#define DEFAULT 0
#define MAX_LEN 0x100
void __attribute__((weak)) OHOS_SystemInit(void)
{
SAMGR_Bootstrap();
};
void HiLogPrintf(unsigned char module, unsigned char level, const char *nums, const char *fmt, ...);
int main()
{
HiLogPrintf(DEFAULT, DEFAULT, NULL, "Start Provider System Start");
OHOS_SystemInit();
HiLogPrintf(DEFAULT, DEFAULT, NULL, "Start Provider System End");
pause();
}
void __attribute__((weak)) HiLogPrintf(unsigned char module, unsigned char level,
const char *nums, const char *fmt, ...)
{
static char buf[MAX_LEN] = {0};
va_list args;
va_start(args, fmt);
int ret = vsprintf_s(buf, sizeof(buf), fmt, args);
va_end(args);
if (ret < 0) {
printf("Provider fmt failed(%d)", ret);
}
printf("Provider M:%d l:%d %s\n", module, level, buf);
}
-89
View File
@@ -1,89 +0,0 @@
/*
* Copyright (c) 2020 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 "example.h"
#include <ohos_init.h>
#include <pthread.h>
#include <log.h>
#include <ohos_errno.h>
#include "iproxy_server.h"
#include "feature.h"
#include "service.h"
#include "samgr_lite.h"
typedef struct ExampleService {
INHERIT_SERVICE;
INHERIT_IUNKNOWNENTRY(DefaultFeatureApi);
Identity identity;
} ExampleService;
static const char *GetName(Service *service)
{
(void)service;
return EXAMPLE_SERVICE;
}
static BOOL Initialize(Service *service, Identity identity)
{
ExampleService *example = (ExampleService *)service;
example->identity = identity;
HILOG_DEBUG(HILOG_MODULE_APP, "[TID:0x%lx]Initialize(%s)! Identity<%d, %d, %p>", (unsigned long)pthread_self(),
EXAMPLE_SERVICE, identity.serviceId, identity.featureId, identity.queueId);
return TRUE;
}
static BOOL MessageHandle(Service *service, Request *msg)
{
HILOG_INFO(HILOG_MODULE_APP, "[TID:0x%lx]MessageHandle(%s)! Request<%d, %d, %p>",
(unsigned long)pthread_self(), service->GetName(service), msg->msgId, msg->msgValue, msg->data);
return FALSE;
}
static TaskConfig GetTaskConfig(Service *service)
{
(void)service;
TaskConfig config = {LEVEL_HIGH, PRI_BELOW_NORMAL, 0x800, 20, SHARED_TASK};
return config;
}
static void SyncCall(IUnknown *iUnknown)
{
HILOG_INFO(HILOG_MODULE_APP, "[TID:0x%lx]SyncCall is called! iUnknown[%p]",
(unsigned long)pthread_self(), iUnknown);
}
static int32 Invoke(IServerProxy *iProxy, int funcId, void *origin, IpcIo *req, IpcIo *reply)
{
HILOG_INFO(HILOG_MODULE_APP, "[TID:0x%lx]Service Remote Invoke is called! <%p, %d, %p, %p, %p>",
(unsigned long)pthread_self(), iProxy, funcId, origin, req, reply);
DefaultFeatureApi *defaultApi = (DefaultFeatureApi *)iProxy;
if (funcId == 0) {
defaultApi->SyncCall((IUnknown *)iProxy);
}
return EC_SUCCESS;
}
static ExampleService g_example = {
.GetName = GetName,
.Initialize = Initialize,
.MessageHandle = MessageHandle,
.GetTaskConfig = GetTaskConfig,
SERVER_IPROXY_IMPL_BEGIN,
.Invoke = Invoke,
.SyncCall = SyncCall,
IPROXY_END,
};
static void Init(void)
{
SAMGR_GetInstance()->RegisterService((Service *)&g_example);
SAMGR_GetInstance()->RegisterDefaultFeatureApi(EXAMPLE_SERVICE, GET_IUNKNOWN(g_example));
}
SYSEX_SERVICE_INIT(Init);
Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Regular → Executable
+52 -65
View File
@@ -11,79 +11,66 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/lite/config/component/lite_component.gni")
import("//build/lite/config/hap_pack.gni")
shared_library("gallery") {
sources = [
"src/gallery_ability.cpp",
"src/gallery_ability_slice.cpp",
"src/picture_ability_slice.cpp",
"src/player_ability_slice.cpp",
]
sources = [
"src/gallery_ability.cpp",
"src/gallery_ability_slice.cpp",
"src/picture_ability_slice.cpp",
"src/player_ability_slice.cpp",
]
include_dirs = [
"include",
"//foundation/aafwk/interfaces/kits/ability_lite",
"//foundation/graphic/lite/interfaces/kits/ui/components",
"//foundation/graphic/lite/interfaces/kits/ui",
"//foundation/graphic/lite/interfaces/kits/utils",
"//foundation/graphic/lite/interfaces/kits/config",
"//foundation/appexecfwk/interfaces/kits/bundle_lite",
"//foundation/aafwk/interfaces/kits/want_lite",
"//foundation/multimedia/interfaces/kits/player_lite",
"//base/startup/interfaces/kits/syspara_lite"
]
include_dirs = [
"include",
"${aafwk_lite_path}/interfaces/kits/ability_lite",
"${appexecfwk_lite_path}/interfaces/kits/bundle_lite",
"${aafwk_lite_path}/interfaces/kits/want_lite",
"//foundation/multimedia/media_lite/interfaces/kits/player_lite",
"//base/startup/syspara_lite/interfaces/kits",
]
deps = [
"//foundation/aafwk/frameworks/ability_lite:aafwk_abilitykit_lite",
"//foundation/appexecfwk/frameworks/bundle_lite:bundle",
"//foundation/communication/frameworks/ipc_lite:liteipc_adapter",
"//foundation/distributedschedule/services/samgr_lite/samgr:samgr",
"//utils/native/lite/kv_store:kv_store",
"//foundation/graphic/lite/frameworks/ui:ui",
"//foundation/graphic/lite/frameworks/surface",
"//foundation/graphic/lite/utils:graphic_utils",
"//foundation/multimedia/frameworks/recorder_lite:recorder",
"//foundation/multimedia/frameworks/player_lite:player"
]
deps = [
"${aafwk_lite_path}/frameworks/ability_lite:aafwk_abilitykit_lite",
"${appexecfwk_lite_path}/frameworks/bundle_lite:bundle",
"//foundation/communication/ipc_lite:liteipc_adapter",
"//foundation/distributedschedule/samgr_lite/samgr:samgr",
"//foundation/graphic/surface",
"//foundation/graphic/ui:lite_ui",
"//foundation/graphic/utils:lite_graphic_utils",
"//foundation/multimedia/media_lite/frameworks/player_lite:player_lite",
"//foundation/multimedia/media_lite/frameworks/recorder_lite:recorder_lite",
"//utils/native/lite/kv_store:kv_store",
]
ldflags = [
"-shared",
]
ldflags = [ "-shared" ]
ldflags += ["-lstdc++"]
ldflags += ["-lpthread"]
ldflags += ["-L$ohos_root_path/sysroot/usr/lib"]
ldflags += ["-Wl,-rpath-link=$ohos_root_path/sysroot/usr/lib"]
ldflags += ["-lui",
"-lsurface",
"-lplayer",
"-lability"
]
ldflags += [ "-lstdc++" ]
ldflags += [ "-lpthread" ]
ldflags += [ "-L$ohos_root_path/sysroot/usr/lib" ]
ldflags += [ "-Wl,-rpath-link=$ohos_root_path/sysroot/usr/lib" ]
ldflags += [
"-lui",
"-lsurface",
"-lplayer_lite",
"-lability",
]
defines = [
"OHOS_APPEXECFWK_BMS_BUNDLEMANAGER",
"ENABLE_WINDOW=1",
"ABILITY_WINDOW_SUPPORT"
]
defines = [
"OHOS_APPEXECFWK_BMS_BUNDLEMANAGER",
"ENABLE_WINDOW=1",
"ABILITY_WINDOW_SUPPORT",
]
}
lite_component("gallery_component") {
features = [
":gallery",
]
}
hap_pack("gallery_hap")
{
deps = [":gallery"]
mode = "hap"
json_path = "config.json"
ability_so_path = "$root_out_dir/libgallery.so"
force = "true"
cert_profile = "cert/gallery_HarmonyAppProvision_Release.p7b"
resources_path = "resources"
hap_name = "gallery"
hap_pack("gallery_hap") {
deps = [ ":gallery" ]
mode = "hap"
json_path = "config.json"
ability_so_path = "$root_out_dir/libgallery.so"
force = "true"
cert_profile = "cert/gallery_HarmonyAppProvision_Release.p7b"
resources_path = "resources"
hap_name = "gallery"
privatekey = "HOS Application Provision Release"
}
View File
Regular → Executable
+98 -98
View File
@@ -1,99 +1,99 @@
{
"app": {
"bundleName": "com.huawei.gallery",
"vendor": "huawei",
"version": {
"code": 1,
"name": "1.0"
},
"apiVersion": {
"compatible": 3,
"target": 4
}
},
"deviceConfig": {
"default": {
}
},
"module": {
"package": "com.huawei.gallery",
"name": ".MyHarmonyAbilityPackage",
"deviceType": [
"phone",
"tv",
"tablet",
"pc",
"car",
"smartWatch",
"sportsWatch",
"smartVision"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "gallery",
"moduleType": "entry"
},
"abilities": [
{
"name": "GalleryAbility",
"icon": "assets/gallery/resources/drawable/com.huawei.photos.png",
"label": "test app 1",
"launchType": "standard",
"type": "page",
"visible": true
}
],
"reqPermissions": [
{
"name": "ohos.permission.MODIFY_AUDIO_SETTINGS",
"reason": "SYSTEM_GRANT",
"usedScene": {
"ability": [
".FormAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.READ_MEDIA",
"reason": "USER_GRANT",
"usedScene": {
"ability": [
".FormAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.READ_MEDIA_AUDIO",
"reason": "USER_GRANT",
"usedScene": {
"ability": [
".FormAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.READ_MEDIA_IMAGES",
"reason": "USER_GRANT",
"usedScene": {
"ability": [
".FormAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.READ_MEDIA_VIDEO",
"reason": "USER_GRANT",
"usedScene": {
"ability": [
".FormAbility"
],
"when": "inuse"
}
}
]
}
{
"app": {
"bundleName": "com.huawei.gallery",
"vendor": "huawei",
"version": {
"code": 1,
"name": "1.0"
},
"apiVersion": {
"compatible": 3,
"target": 4
}
},
"deviceConfig": {
"default": {
}
},
"module": {
"package": "com.huawei.gallery",
"name": ".MyHarmonyAbilityPackage",
"deviceType": [
"phone",
"tv",
"tablet",
"pc",
"car",
"smartWatch",
"sportsWatch",
"smartVision"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "gallery",
"moduleType": "entry"
},
"abilities": [
{
"name": "GalleryAbility",
"icon": "assets/gallery/resources/drawable/com.huawei.photos.png",
"label": "test app 1",
"launchType": "standard",
"type": "page",
"visible": true
}
],
"reqPermissions": [
{
"name": "ohos.permission.MODIFY_AUDIO_SETTINGS",
"reason": "SYSTEM_GRANT",
"usedScene": {
"ability": [
".FormAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.READ_MEDIA",
"reason": "USER_GRANT",
"usedScene": {
"ability": [
".FormAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.READ_MEDIA_AUDIO",
"reason": "USER_GRANT",
"usedScene": {
"ability": [
".FormAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.READ_MEDIA_IMAGES",
"reason": "USER_GRANT",
"usedScene": {
"ability": [
".FormAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.READ_MEDIA_VIDEO",
"reason": "USER_GRANT",
"usedScene": {
"ability": [
".FormAbility"
],
"when": "inuse"
}
}
]
}
}
Regular → Executable
+12 -4
View File
@@ -36,20 +36,28 @@ public:
onLongPress_ = std::move(onLongPress);
}
bool OnClick(UIView &view, const ClickEvent &event) override
bool OnClick(UIView& view, const ClickEvent &event) override
{
if (!onClick_) {
return false;
}
return onClick_(view, event);
UIView *currentView = &view;
if (currentView == nullptr) {
return false;
}
return onClick_(*currentView, event);
}
bool OnLongPress(UIView &view, const LongPressEvent &event) override
bool OnLongPress(UIView& view, const LongPressEvent &event) override
{
if (!onLongPress_) {
return false;
}
return onLongPress_(view, event);
UIView *currentView = &view;
if (currentView == nullptr) {
return false;
}
return onLongPress_(*currentView, event);
}
private:
View File
+2
View File
@@ -59,6 +59,8 @@ private:
UIScrollView* picContainer_ { nullptr };
UIViewGroup* picList_ { nullptr };
char* pictureName_[MAX_PICTURE_COUNT] = { nullptr };
char backIconAbsolutePath[MAX_PATH_LENGTH] = { 0 };
char videoTagIconAbsolutePath[MAX_PATH_LENGTH] = { 0 };
uint16_t pictureOnClickListenerCount_ { 0 };
EventListener* pictureOnClickListener_[MAX_PICTURE_COUNT] = { nullptr };
};
Regular → Executable
-6
View File
@@ -25,8 +25,6 @@ static const char* const VIDEO_PAUSE_PATH = "/gallery/assets/gallery/resources/d
static constexpr int16_t MAX_PICTURE_COUNT = 256;
static constexpr uint16_t MAX_PATH_LENGTH = 512;
static char g_backIconAbsolutePath[MAX_PATH_LENGTH] = {0};
static char g_videoTagIconAbsolutePath[MAX_PATH_LENGTH] = {0};
/** thumb, photo, and video folder path */
static const char* const THUMBNAIL_DIRECTORY = "/userdata/thumb";
@@ -69,10 +67,6 @@ static const char* const PHOTO_PREFIX = "photo";
static const char* const AVAILABEL_SOURCE_TYPE = ".mp4";
static const char* const AVAILABEL_SOURCE_TYPE_MP4 = ".MP4";
/** player */
static char g_videoPlayAbsolutePath[MAX_PATH_LENGTH] = {0};
static char g_videoPauseAbsolutePath[MAX_PATH_LENGTH] = {0};
/** playback status bar */
static constexpr uint16_t STATUS_BAR_GROUP_HEIGHT = 96;
static constexpr uint16_t TOGGLE_BUTTON_OFFSET_X = 36;
+2
View File
@@ -20,6 +20,7 @@
#include "components/ui_image_view.h"
#include "components/ui_view_group.h"
#include "event_listener.h"
#include "gallery_config.h"
namespace OHOS {
class PictureAbilitySlice : public AbilitySlice {
@@ -43,6 +44,7 @@ private:
UIImageView* backIcon_ { nullptr };
EventListener* backIconListener_ { nullptr };
UIImageView* picture_ { nullptr };
char backIconAbsolutePath[MAX_PATH_LENGTH] = { 0 };
};
}
+4 -1
View File
@@ -52,7 +52,7 @@ public:
virtual ~ToggleBtnListener() {}
bool OnClick(UIView& view, const ClickEvent& event) override;
bool OnClick(UIView &view, const ClickEvent& event) override;
void SetCompleteFlag(bool state)
{
@@ -145,6 +145,9 @@ private:
UISlider* slider_ { nullptr };
UILabel* totalTimeLabel_ { nullptr };
UILabel* errorTips_ { nullptr };
char backIconAbsolutePath[MAX_PATH_LENGTH] = { 0 };
char videoPlayAbsolutePath[MAX_PATH_LENGTH] = { 0 };
char videoPauseAbsolutePath[MAX_PATH_LENGTH] = { 0 };
};
} // namespace OHOS
#endif // OHOS_PLAYER_ABILITY_SLICE_H
View File

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

View File

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Regular → Executable
View File
+21 -21
View File
@@ -121,7 +121,7 @@ void GalleryAbilitySlice::InitTitle()
printf("GalleryAbilitySlice::InitTitle | start \n");
backIcon_ = new UIImageView();
backIcon_->SetPosition(BACK_ICON_POSITION_X, BACK_ICON_POSITION_Y);
backIcon_->SetSrc(g_backIconAbsolutePath);
backIcon_->SetSrc(backIconAbsolutePath);
backIcon_->SetTouchable(true);
backArea_ = new UIViewGroup();
@@ -198,19 +198,19 @@ void GalleryAbilitySlice::AddAllPictures(const Point& pos, int16_t numInLine)
{
printf("GalleryAbilitySlice::AddAllPictures | start | %d\n", numInLine);
Point imagePos = pos;
void* drip = FileOpenDir(THUMBNAIL_DIRECTORY);
DIR* drip = opendir(THUMBNAIL_DIRECTORY);
if (drip == nullptr) {
return;
}
FileDirentInfo* info = new FileDirentInfo();
while (FileReadDir(drip, info) >= 0 && pictureCount_ < MAX_PICTURE_COUNT) {
uint16_t imageNameLen = static_cast<uint16_t>(strlen(info->name));
if (imageNameLen > MAX_PATH_LENGTH) {
struct dirent* info = nullptr;
while ((info = readdir(drip)) != nullptr && pictureCount_ < MAX_PICTURE_COUNT) {
uint16_t imageNameLen = static_cast<uint16_t>(strlen(info->d_name));
if (imageNameLen > MAX_PATH_LENGTH || (strcmp(info->d_name, ".") == 0) || (strcmp(info->d_name, "..") == 0)) {
printf("GalleryAbilitySlice::AddAllPictures | imageNameLen > MAX_PATH_LENGTH | %d\n", imageNameLen);
continue;
}
char* imageName = new char[imageNameLen + 1]();
memcpy_s(imageName, imageNameLen + 1, info->name, imageNameLen + 1);
memcpy_s(imageName, imageNameLen + 1, info->d_name, imageNameLen + 1);
pictureName_[pictureCount_] = imageName;
pictureCount_++;
@@ -220,7 +220,7 @@ void GalleryAbilitySlice::AddAllPictures(const Point& pos, int16_t numInLine)
continue;
}
char* imagePath = new char[pathLen + 1]();
if (sprintf_s(imagePath, pathLen + 1, "%s/%s", THUMBNAIL_DIRECTORY, info->name) < 0) {
if (sprintf_s(imagePath, pathLen + 1, "%s/%s", THUMBNAIL_DIRECTORY, info->d_name) < 0) {
printf("GalleryAbilitySlice::AddAllPictures | sprintf_s error\n");
delete[] imagePath;
continue;
@@ -237,7 +237,7 @@ void GalleryAbilitySlice::AddAllPictures(const Point& pos, int16_t numInLine)
}
}
delete info;
FileCloseDir(drip);
closedir(drip);
}
UIView* GalleryAbilitySlice::CreateImageItem(const Point& pos, const char* imageName, const char* imagePath)
@@ -264,7 +264,7 @@ UIView* GalleryAbilitySlice::CreateImageItem(const Point& pos, const char* image
UIImageView* videoTag = new UIImageView();
videoTag->SetPosition(VIDEO_TAG_POSITION_X, VIDEO_TAG_POSITION_Y);
videoTag->SetSrc(g_videoTagIconAbsolutePath);
videoTag->SetSrc(videoTagIconAbsolutePath);
videoTag->SetTouchable(true);
videoTag->SetOnClickListener(imageView->GetOnClickListener());
@@ -319,31 +319,31 @@ void GalleryAbilitySlice::DeleteAllData()
void GalleryAbilitySlice::DeleteAllFilesInDir(const char* path)
{
void* drip = FileOpenDir(path);
DIR* drip = opendir(path);
if (drip == nullptr) {
return;
}
FileDirentInfo* info = new FileDirentInfo();
while (FileReadDir(drip, info) >= 0) {
uint16_t fileNameLen = static_cast<uint16_t>(strlen(info->name));
struct dirent* info = nullptr;
while ((info = readdir(drip)) != nullptr) {
uint16_t fileNameLen = static_cast<uint16_t>(strlen(info->d_name));
uint16_t pathLen = static_cast<uint16_t>(strlen(path)) + fileNameLen + 1;
if (pathLen > MAX_PATH_LENGTH) {
printf("GalleryAbilitySlice::AddAllPictures | pathLen > MAX_PATH_LENGTH | %d\n", pathLen);
continue;
}
char* filePath = new char[pathLen + 1]();
if (sprintf_s(filePath, pathLen + 1, "%s/%s", path, info->name) < 0) {
if (sprintf_s(filePath, pathLen + 1, "%s/%s", path, info->d_name) < 0) {
printf("GalleryAbilitySlice::AddAllPictures | sprintf_s error\n");
delete[] filePath;
continue;
}
if (FileUnlink(filePath) != 0) {
if (unlink(filePath) != 0) {
printf("unlink file error | %s\n", filePath);
}
delete[] filePath;
}
delete info;
FileCloseDir(drip);
closedir(drip);
printf("GalleryAbilitySlice::DeleteAllFilesInDir() | success | %s\n", path);
}
@@ -357,12 +357,12 @@ void GalleryAbilitySlice::OnStart(const Want &want)
rootView_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
const char* pathHeader = GetSrcPath();
if (sprintf_s(g_backIconAbsolutePath, MAX_PATH_LENGTH, "%s%s", pathHeader, BACK_ICON_PATH) < 0) {
printf("GalleryAbilitySlice::OnStart | g_backIconAbsolutePath error");
if (sprintf_s(backIconAbsolutePath, MAX_PATH_LENGTH, "%s%s", pathHeader, BACK_ICON_PATH) < 0) {
printf("GalleryAbilitySlice::OnStart | backIconAbsolutePath error");
return;
}
if (sprintf_s(g_videoTagIconAbsolutePath, MAX_PATH_LENGTH, "%s%s", pathHeader, VIDEO_TAG_ICON_PATH) < 0) {
printf("GalleryAbilitySlice::OnStart | g_videoTagIconAbsolutePath error");
if (sprintf_s(videoTagIconAbsolutePath, MAX_PATH_LENGTH, "%s%s", pathHeader, VIDEO_TAG_ICON_PATH) < 0) {
printf("GalleryAbilitySlice::OnStart | videoTagIconAbsolutePath error");
return;
}
+9 -5
View File
@@ -58,7 +58,7 @@ void PictureAbilitySlice::InitTitle()
printf("PictureAbilitySlice::InitTitle | start \n");
backIcon_ = new UIImageView();
backIcon_->SetPosition(BACK_ICON_POSITION_X, BACK_ICON_POSITION_Y);
backIcon_->SetSrc(g_backIconAbsolutePath);
backIcon_->SetSrc(backIconAbsolutePath);
backIcon_->SetTouchable(true);
backArea_ = new UIViewGroup();
@@ -101,7 +101,7 @@ void PictureAbilitySlice::InitPicture(const char* path)
}
float scale = (scaleWidth < scaleHeight) ? scaleWidth : scaleHeight;
printf("########## scale: %f \n", scale);
transMap.Scale(Vector2<float>(scale, scale), Vector2<int16_t>(0, 0));
transMap.Scale(Vector2<float>(scale, scale), Vector2<float>(0, 0));
picture_->SetTransformMap(transMap);
picture_->SetTransformAlgorithm(TransformAlgorithm::NEAREST_NEIGHBOR);
imageWidth = imageWidth * scale;
@@ -134,12 +134,16 @@ void PictureAbilitySlice::OnStart(const Want &want)
char* imagePath = new char[imagePathLen + 1]();
if (sprintf_s(imagePath, imagePathLen + 1, "%s/%s", PHOTO_DIRECTORY, reinterpret_cast<char*>(want.data)) < 0) {
printf("PictureAbilitySlice::OnStart | imagePath\n");
delete[] imagePath;
imagePath = nullptr;
return;
}
const char* pathHeader = GetSrcPath();
if (sprintf_s(g_backIconAbsolutePath, MAX_PATH_LENGTH, "%s%s", pathHeader, BACK_ICON_PATH) < 0) {
printf("PictureAbilitySlice::OnStart | g_backIconAbsolutePath\n");
if (sprintf_s(backIconAbsolutePath, MAX_PATH_LENGTH, "%s%s", pathHeader, BACK_ICON_PATH) < 0) {
printf("PictureAbilitySlice::OnStart | backIconAbsolutePath\n");
delete[] imagePath;
imagePath = nullptr;
return;
}
@@ -174,4 +178,4 @@ void PictureAbilitySlice::OnStop()
AbilitySlice::OnStop();
Clear();
}
}
}
+9 -10
View File
@@ -134,11 +134,11 @@ void PlayerAbilitySlice::SetUpBackArea(const char* pathHeader)
backIcon_ = new UIImageView();
backIcon_->SetPosition(BACK_ICON_POSITION_X, BACK_ICON_POSITION_Y);
if (sprintf_s(g_backIconAbsolutePath, MAX_PATH_LENGTH, "%s%s", pathHeader, BACK_ICON_PATH) < 0) {
printf("PlayerAbilitySlice::OnStart | g_backIconAbsolutePath | %s\n", pathHeader);
if (sprintf_s(backIconAbsolutePath, MAX_PATH_LENGTH, "%s%s", pathHeader, BACK_ICON_PATH) < 0) {
printf("PlayerAbilitySlice::OnStart | backIconAbsolutePath | %s\n", pathHeader);
return;
}
backIcon_->SetSrc(g_backIconAbsolutePath);
backIcon_->SetSrc(backIconAbsolutePath);
backIcon_->SetTouchable(true);
backIconListener_ = new EventListener(onClick, nullptr);
backIcon_->SetOnClickListener(backIconListener_);
@@ -303,20 +303,19 @@ void PlayerAbilitySlice::SetUpToggleButton(const char* pathHeader)
TOGGLE_BUTTON_WIDTH, TOGGLE_BUTTON_HEIGHT);
toggleButton_->SetState(true);
if (sprintf_s(g_videoPlayAbsolutePath, MAX_PATH_LENGTH, "%s%s", pathHeader, VIDEO_PALY_PATH) < 0) {
printf("PlayerAbilitySlice::OnStart | g_videoPlayAbsolutePath\n");
if (sprintf_s(videoPlayAbsolutePath, MAX_PATH_LENGTH, "%s%s", pathHeader, VIDEO_PALY_PATH) < 0) {
printf("PlayerAbilitySlice::OnStart | videoPlayAbsolutePath\n");
return;
}
if (sprintf_s(g_videoPauseAbsolutePath, MAX_PATH_LENGTH, "%s%s", pathHeader, VIDEO_PAUSE_PATH) < 0) {
printf("PlayerAbilitySlice::OnStart | g_videoPauseAbsolutePath\n");
if (sprintf_s(videoPauseAbsolutePath, MAX_PATH_LENGTH, "%s%s", pathHeader, VIDEO_PAUSE_PATH) < 0) {
printf("PlayerAbilitySlice::OnStart | videoPauseAbsolutePath\n");
return;
}
toggleButton_->SetImages(g_videoPauseAbsolutePath, g_videoPlayAbsolutePath);
toggleButton_->SetImages(videoPauseAbsolutePath, videoPlayAbsolutePath);
onClickListener_ = new ToggleBtnListener(toggleButton_, videoPlayer_, animator_, surfaceView_);
toggleButtonArea_ = new UIViewGroup();
toggleButtonArea_->SetStyle(STYLE_BACKGROUND_OPA, 0);
toggleButtonArea_->SetPosition(0, 0, TOGGLE_BUTTON_OFFSET_X + TOGGLE_BUTTON_WIDTH, STATUS_BAR_GROUP_HEIGHT);
toggleButtonArea_->SetTouchable(true);
toggleButtonArea_->SetOnClickListener(onClickListener_);
@@ -428,7 +427,7 @@ void SliderAnimator::Callback(UIView* view)
}
}
bool ToggleBtnListener::OnClick(UIView& view, const ClickEvent& event)
bool ToggleBtnListener::OnClick(UIView &view, const ClickEvent& event)
{
button_->OnClickEvent(event);
if (completeFlag_) {
Regular → Executable
+43 -54
View File
@@ -10,66 +10,55 @@
# 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/lite/config/component/lite_component.gni")
import("//build/lite/config/hap_pack.gni")
shared_library("launcher") {
sources = [
"launcher/src/main/cpp/main_ability.cpp",
"launcher/src/main/cpp/main_ability_slice.cpp",
"launcher/src/main/cpp/swipe_view.cpp",
"launcher/src/main/cpp/app_info.cpp",
"launcher/src/main/cpp/long_press_view.cpp",
"launcher/src/main/cpp/app_manage.cpp",
"launcher/src/main/cpp/view_group_page.cpp",
"launcher/src/main/cpp/time_weather_view.cpp"
]
sources = [
"launcher/src/main/cpp/app_info.cpp",
"launcher/src/main/cpp/app_manage.cpp",
"launcher/src/main/cpp/long_press_view.cpp",
"launcher/src/main/cpp/main_ability.cpp",
"launcher/src/main/cpp/main_ability_slice.cpp",
"launcher/src/main/cpp/swipe_view.cpp",
"launcher/src/main/cpp/time_weather_view.cpp",
"launcher/src/main/cpp/view_group_page.cpp",
]
deps = [
"//foundation/aafwk/frameworks/ability_lite:aafwk_abilitykit_lite",
"//foundation/appexecfwk/frameworks/bundle_lite:bundle",
"//foundation/communication/frameworks/ipc_lite:liteipc_adapter",
"//foundation/distributedschedule/services/samgr_lite/samgr:samgr",
"//utils/native/lite/kv_store:kv_store",
"//foundation/graphic/lite/frameworks/ui:ui",
"//foundation/graphic/lite/utils:graphic_utils",
"//foundation/graphic/lite/frameworks/surface",
]
deps = [
"${aafwk_lite_path}/frameworks/ability_lite:aafwk_abilitykit_lite",
"${appexecfwk_lite_path}/frameworks/bundle_lite:bundle",
"//foundation/communication/ipc_lite:liteipc_adapter",
"//foundation/distributedschedule/samgr_lite/samgr:samgr",
"//foundation/graphic/surface",
"//foundation/graphic/ui:lite_ui",
"//foundation/graphic/utils:lite_graphic_utils",
"//utils/native/lite/kv_store:kv_store",
]
include_dirs = [
"launcher/src/main/cpp",
"//foundation/aafwk/interfaces/kits/ability_lite",
"//foundation/graphic/lite/interfaces/kits/ui/components",
"//foundation/graphic/lite/interfaces/kits/ui",
"//foundation/graphic/lite/interfaces/kits/utils",
"//foundation/graphic/lite/interfaces/kits/config",
"//foundation/appexecfwk/interfaces/kits/bundle_lite",
"//foundation/aafwk/interfaces/kits/want_lite",
"//base/startup/interfaces/kits/syspara_lite",
]
include_dirs = [
"launcher/src/main/cpp",
"${aafwk_lite_path}/interfaces/kits/ability_lite",
"${appexecfwk_lite_path}/interfaces/kits/bundle_lite",
"${aafwk_lite_path}/interfaces/kits/want_lite",
"//base/startup/syspara_lite/interfaces/kits",
]
defines = [
"ENABLE_WINDOW=1",
"ABILITY_WINDOW_SUPPORT",
"OHOS_APPEXECFWK_BMS_BUNDLEMANAGER"
]
defines = [
"ENABLE_WINDOW=1",
"ABILITY_WINDOW_SUPPORT",
"OHOS_APPEXECFWK_BMS_BUNDLEMANAGER",
]
}
lite_component("launcher_component") {
features = [
":launcher",
]
}
hap_pack("launcher_hap")
{
deps = [":launcher"]
mode = "hap"
json_path = "launcher/src/main/config.json"
ability_so_path = "$root_out_dir/liblauncher.so"
force = "true"
cert_profile = "cert/com.huawei.launcher_HarmonyAppProvision_release.p7b"
resources_path = "launcher/src/main/resources"
hap_name = "launcher"
hap_pack("launcher_hap") {
deps = [ ":launcher" ]
mode = "hap"
json_path = "launcher/src/main/config.json"
ability_so_path = "$root_out_dir/liblauncher.so"
force = "true"
cert_profile = "cert/com.huawei.launcher_HarmonyAppProvision_release.p7b"
resources_path = "launcher/src/main/resources"
hap_name = "launcher"
privatekey = "HOS Application Provision Release"
}
View File
+43 -43
View File
@@ -1,43 +1,43 @@
{
"app": {
"bundleName": "com.huawei.launcher",
"vendor": "huawei",
"version": {
"code": 1,
"name": "1.0"
},
"apiVersion": {
"compatible": 3,
"target": 4
}
},
"deviceConfig": {
"default": {
"keepAlive": true
},
"smartCamera": {
"keepAlive": true
}
},
"module": {
"package": "com.huawei.launcher",
"name": ".MyHarmonyAbilityPackage",
"deviceType": [
"phone", "tv","tablet", "pc","car","smartWatch","sportsWatch","smartVision"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "launcher",
"moduleType": "entry"
},
"abilities": [{
"name": "MainAbility",
"icon": "assets/launcher/resources/base/media/background.png",
"label": "launcher",
"launchType": "standard",
"type": "page",
"visible":true
}
]
}
}
{
"app": {
"bundleName": "com.huawei.launcher",
"vendor": "huawei",
"version": {
"code": 1,
"name": "1.0"
},
"apiVersion": {
"compatible": 3,
"target": 4
}
},
"deviceConfig": {
"default": {
"keepAlive": true
},
"smartCamera": {
"keepAlive": true
}
},
"module": {
"package": "com.huawei.launcher",
"name": ".MyHarmonyAbilityPackage",
"deviceType": [
"phone", "tv","tablet", "pc","car","smartWatch","sportsWatch","smartVision"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "launcher",
"moduleType": "entry"
},
"abilities": [{
"name": "MainAbility",
"icon": "assets/launcher/resources/base/media/background.png",
"label": "launcher",
"launchType": "standard",
"type": "page",
"visible":true
}
]
}
}
+6 -14
View File
@@ -39,10 +39,6 @@ void AppInfo::Release()
delete appLpListener_;
appLpListener_ = nullptr;
}
if (appDListener_) {
delete appDListener_;
appDListener_ = nullptr;
}
}
AppInfo::~AppInfo()
@@ -56,7 +52,6 @@ void AppInfo::ReSet()
lable_ = nullptr;
appClickListener_ = nullptr;
appLpListener_ = nullptr;
appDListener_ = nullptr;
}
void AppInfo::SetButton(UILabelButton* button)
@@ -92,16 +87,13 @@ void AppInfo::SetLable(UILabel* lable)
void AppInfo::SetListener(AppInfo* app)
{
AppClickListener* appClickListener = new AppClickListener(app->funcclick_, this);
button_->SetOnClickListener(appClickListener);
appClickListener_ = static_cast<UIView::OnClickListener*>(appClickListener);
AppLongPressListener* appLpListener = new AppLongPressListener(app->funclPress_, this);
button_->SetOnLongPressListener(appLpListener);
appLpListener_ = static_cast<UIView::OnLongPressListener*>(appLpListener);
AppDragListener* appDListener = new AppDragListener(this);
AppClickListener* clickListener = new AppClickListener(app->funcclick_, this);
button_->SetOnClickListener(clickListener);
appClickListener_ = static_cast<UIView::OnClickListener*>(clickListener);
AppLongPressListener* lPListener = new AppLongPressListener(app->funclPress_, this);
button_->SetOnLongPressListener(lPListener);
appLpListener_ = static_cast<UIView::OnLongPressListener*>(lPListener);
button_->SetDraggable(true);
button_->SetOnDragListener(appDListener);
appDListener_ = static_cast<UIView::OnDragListener*>(appDListener);
}
void AppInfo::SetLocation(int16_t r, int16_t c)
+7 -29
View File
@@ -26,10 +26,10 @@
namespace OHOS {
class AppInfo;
typedef bool (*funcLongPress)(AppInfo *app);
typedef bool (*funcClick)(AppInfo *app);
typedef bool (*UninstallApp)(AppInfo *app);
typedef bool (*AddApp)(AppInfo *app);
using funcLongPress = bool (*)(AppInfo *app);
using funcClick = bool (*)(AppInfo *app);
using UninstallApp = bool (*)(AppInfo *app);
using AddApp = bool (*)(AppInfo *app);
struct MyPoint {
int16_t x; // the x coordinate of the point
@@ -51,7 +51,6 @@ public:
UILabel* lable_ { nullptr };
UIView::OnLongPressListener* appLpListener_ { nullptr };
UIView::OnDragListener* appDListener_ { nullptr };
UIView::OnClickListener* appClickListener_ { nullptr };
funcClick funcclick_ { nullptr };
@@ -61,30 +60,9 @@ public:
MyPoint buttonXY_ { 0 };
MyPoint buttonHV_ { 0 };
MyPoint row_col_ { 0 };
char appName_[TMP_BUF_SIZE];
char abilityName_[TMP_BUF_SIZE];
char appIconDir_[TMP_BUF_SIZE];
};
class AppDragListener : public UIView::OnDragListener {
public:
AppDragListener(AppInfo* app) : appInfo_(app) {}
virtual ~AppDragListener() {}
bool OnDrag(UIView &view, const DragEvent &event) override
{
return true;
}
bool OnDragEnd(UIView& view, const DragEvent& event) override
{
return true;
}
bool OnDragStart(UIView& view, const DragEvent& event) override
{
return true;
}
private:
AppInfo* appInfo_ { nullptr };
char appName_[TMP_BUF_SIZE] = { 0 };
char abilityName_[TMP_BUF_SIZE] = { 0 };
char appIconDir_[TMP_BUF_SIZE] = { 0 };
};
class AppClickListener : public UIView::OnClickListener {
+5 -4
View File
@@ -13,7 +13,7 @@
* limitations under the License.
*/
#include <stdio.h>
#include <cstdio>
#include <securec.h>
#include "app_manage.h"
@@ -96,9 +96,10 @@ void AppManage::MyBundleStateCallback(
if (installType == 0) { // install update
if (resultCode == 0 && bundleName != nullptr) {
char tmpName[TMP_BUF_SIZE] = {0};
memcpy_s(tmpName, sizeof(tmpName), bundleName, strlen(bundleName));
tmpName[strlen(bundleName)] = 0;
GetAppInstallInfo(tmpName);
if (memcpy_s(tmpName, sizeof(tmpName), bundleName, strlen(bundleName)) == LAUNCHER_SUCCESS) {
tmpName[strlen(bundleName)] = 0;
GetAppInstallInfo(tmpName);
}
}
}
}
View File
+10 -2
View File
@@ -39,7 +39,11 @@ public:
if (!onClick_) {
return false;
}
return onClick_(view, event);
UIView *currentView = &view;
if (currentView == nullptr) {
return false;
}
return onClick_(*currentView, event);
}
bool OnLongPress(UIView& view, const LongPressEvent& event) override
@@ -47,7 +51,11 @@ public:
if (!onLongPress_) {
return false;
}
return onLongPress_(view, event);
UIView *currentView = &view;
if (currentView == nullptr) {
return false;
}
return onLongPress_(*currentView, event);
}
private:
+7 -3
View File
@@ -88,12 +88,16 @@ void LongPressView::Show(UIViewGroup* viewParent, AppInfo* pApp)
bool LongPressView::OnClick(UIView& view, const ClickEvent& event)
{
UIView *currentView = &view;
if (currentView == nullptr) {
return false;
}
UILabelButton* lbutt = nullptr;
lbutt = static_cast<UILabelButton*>(&view);
lbutt = static_cast<UILabelButton*>(currentView);
RemoveLview();
if (&view == buttUninstall_) {
if (currentView == buttUninstall_) {
uninstall_(app_);
}
return true;
}
} // namespace OHOS
} // namespace OHOS
+3 -3
View File
@@ -23,9 +23,9 @@
namespace OHOS {
class LongPressView : public UIView::OnClickListener, public NativeBase {
public:
LongPressView(UninstallApp uninstall);
explicit LongPressView(UninstallApp uninstall);
virtual ~LongPressView();
bool OnClick(UIView &view, const ClickEvent& event) override;
bool OnClick(UIView& view, const ClickEvent& event) override;
void RemoveLview();
void Show(UIViewGroup* viewParent, AppInfo* pApp);
void SetStatus(bool status)
@@ -33,7 +33,7 @@ public:
bStatus_ = status;
}
bool GetStatus()
bool GetStatus() const
{
return bStatus_;
}
View File
View File
+5 -6
View File
@@ -58,7 +58,7 @@ void MainAbilitySlice::SetHead()
sprintf_s(tmp, sizeof(tmp), "%02d : %02d", st->tm_hour, st->tm_min);
UILabel* label = new UILabel();
rootview_->Add(label);
label->SetPosition(0, 0, LA_HORIZONTAL_RESOLUTION, LABLE_TITLE_HEIGHT);
label->SetPosition(0, 0, Screen::GetInstance().GetWidth(), LABLE_TITLE_HEIGHT);
label->SetText(tmp);
label->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_TOP);
label->SetFont(FOND_PATH, LAUNCHER_FOND_ID);
@@ -72,7 +72,8 @@ void MainAbilitySlice::SetTail()
{
UILabel* label = new UILabel();
rootview_->Add(label);
label->SetPosition(0, LA_VERTICAL_RESOLUTION - LABLE_TAIL_HEIGHT, LA_HORIZONTAL_RESOLUTION, LABLE_TAIL_HEIGHT);
label->SetPosition(0, Screen::GetInstance().GetHeight() - LABLE_TAIL_HEIGHT,
Screen::GetInstance().GetWidth(), LABLE_TAIL_HEIGHT);
char buf[TMP_BUF_SIZE] = { 0 };
sprintf_s(buf, sizeof(buf), ".%d.", 1);
label->SetText(buf);
@@ -89,7 +90,7 @@ void MainAbilitySlice::SetImageView()
uiImageView_ = new UIImageView();
// modify image view height
uiImageView_->SetPosition(0, 0, LA_HORIZONTAL_RESOLUTION, LA_VERTICAL_RESOLUTION);
uiImageView_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
uiImageView_->SetStyle(STYLE_BACKGROUND_COLOR, Color::ColorTo32(Color::White()));
uiImageView_->SetSrc(TABLE_BACKGROUND);
uiImageView_->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY);
@@ -106,11 +107,9 @@ void MainAbilitySlice::SetSwipe()
void MainAbilitySlice::OnStart(const Want& want)
{
AbilitySlice::OnStart(want);
LA_HORIZONTAL_RESOLUTION = Screen::GetInstance().GetWidth();
LA_VERTICAL_RESOLUTION = Screen::GetInstance().GetHeight();
rootview_ = RootView::GetWindowRootView();
rootview_->SetPosition(0, 0);
rootview_->Resize(LA_HORIZONTAL_RESOLUTION, LA_VERTICAL_RESOLUTION);
rootview_->Resize(Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
rootview_->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY);
rootview_->SetStyle(STYLE_BACKGROUND_COLOR, Color::ColorTo32(Color::GetColorFromRGB(0x30, 0x30, 0x30)));
View File
+2
View File
@@ -21,6 +21,8 @@
namespace OHOS {
class NativeBase : public HeapBase {
public:
NativeBase() {}
virtual ~NativeBase() {}
void DeleteChildren(UIView *view)
{
if (view == nullptr) {
+19 -9
View File
@@ -45,11 +45,9 @@ SwipeView::~SwipeView()
void SwipeView::SetUpSwipe()
{
LA_HORIZONTAL_RESOLUTION = Screen::GetInstance().GetWidth();
LA_VERTICAL_RESOLUTION = Screen::GetInstance().GetHeight();
swipe_ = new UISwipeView();
swipe_->SetPosition(0, LABLE_TITLE_HEIGHT, LA_HORIZONTAL_RESOLUTION,
LA_VERTICAL_RESOLUTION - LABLE_TITLE_HEIGHT - LABLE_TAIL_HEIGHT);
swipe_->SetPosition(0, LABLE_TITLE_HEIGHT, Screen::GetInstance().GetWidth(),
Screen::GetInstance().GetHeight() - LABLE_TITLE_HEIGHT - LABLE_TAIL_HEIGHT);
swipe_->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY);
swipe_->SetLoopState(true);
swipe_->SetAnimatorTime(20); // set swipe view animator time 20s
@@ -61,8 +59,8 @@ UIViewGroup* SwipeView::AddViewGroup()
return nullptr;
}
UIViewGroup* viewGroup = new UIViewGroup();
viewGroup->SetPosition(0, LABLE_TITLE_HEIGHT, LA_HORIZONTAL_RESOLUTION,
LA_VERTICAL_RESOLUTION - LABLE_TITLE_HEIGHT - LABLE_TAIL_HEIGHT);
viewGroup->SetPosition(0, LABLE_TITLE_HEIGHT, Screen::GetInstance().GetWidth(),
Screen::GetInstance().GetHeight() - LABLE_TITLE_HEIGHT - LABLE_TAIL_HEIGHT);
viewGroup->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY);
groupCount_++;
ViewGroupPage* page = new ViewGroupPage(viewGroup);
@@ -74,8 +72,8 @@ UIViewGroup* SwipeView::AddViewGroup()
UIViewGroup* SwipeView::AddFirstViewGroup()
{
UIViewGroup* firstView = new UIViewGroup();
firstView->SetPosition(0, LABLE_TITLE_HEIGHT, LA_HORIZONTAL_RESOLUTION,
LA_VERTICAL_RESOLUTION - LABLE_TITLE_HEIGHT - LABLE_TAIL_HEIGHT);
firstView->SetPosition(0, LABLE_TITLE_HEIGHT, Screen::GetInstance().GetWidth(),
Screen::GetInstance().GetHeight() - LABLE_TITLE_HEIGHT - LABLE_TAIL_HEIGHT);
firstView->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY);
UIViewGroup* viewTimeWeather = new UIViewGroup();
@@ -129,6 +127,10 @@ void SwipeView::OnSetUpView()
if (memcmp(LAUNCHER_BUNDLE_NAME, pBundleInfos[j].bundleName, strlen(pBundleInfos[j].bundleName)) == 0) {
break;
}
if (memcmp(SCREENSAVER_BUNDLE_NAME, pBundleInfos[j].bundleName, strlen(pBundleInfos[j].bundleName)) == 0) {
break;
}
AppInfo* app = new AppInfo();
app->funcclick_ = AppEvent::ClickEvent;
app->funclPress_ = AppEvent::LongPressEvent;
@@ -188,13 +190,21 @@ void SwipeView::InstallApp(AppInfo* app)
{
appManage_->InstallApp(app);
AppInfo* pApp = new AppInfo();
if (pApp == nullptr) {
return;
}
app->funcclick_ = AppEvent::ClickEvent;
app->funclPress_ = AppEvent::LongPressEvent;
for (int16_t i = 0; i < groupCount_; i++) {
int16_t i;
for (i = 0; i < groupCount_; i++) {
if (arrPage_[i]->AddApp(pApp)) {
break;
}
}
if (i == groupCount_) {
delete pApp;
pApp = nullptr;
}
}
void SwipeView::OnStop()
+11 -7
View File
@@ -16,7 +16,7 @@
#ifndef OHOS_SWIPE_VIEW_H
#define OHOS_SWIPE_VIEW_H
#include <stdio.h>
#include <cstdio>
#include <securec.h>
#include <components/ui_label_button.h>
#include <components/ui_label.h>
@@ -36,7 +36,7 @@
namespace OHOS {
class ViewPageListener : public UIView::OnClickListener {
public:
ViewPageListener(LongPressView* view) : view_(view) {}
explicit ViewPageListener(LongPressView* view) : view_(view) {}
virtual ~ViewPageListener() {}
bool OnClick(UIView& view, const ClickEvent& event) override
{
@@ -62,9 +62,9 @@ public:
}
private:
LongPressView* view_ { nullptr };
UISwipeView* swipe_ { nullptr };
UILabel* lable_ { nullptr };
LongPressView* view_ { nullptr };
};
class SwipeView : public Task, public NativeBase {
@@ -82,12 +82,16 @@ public:
char tmp[TMP_BUF_SIZE] = { 0 };
time_t t = time(nullptr);
struct tm* st = localtime(&t);
sprintf_s(tmp, sizeof(tmp), "%02d : %02d", st->tm_hour, st->tm_min);
lableTitle_->SetText(tmp);
timeWeatherView_->SetUpTimeView();
if (st != nullptr) {
int ret = sprintf_s(tmp, sizeof(tmp), "%02d : %02d", st->tm_hour, st->tm_min);
if (ret != LAUNCHER_PARAMERROR) {
lableTitle_->SetText(tmp);
timeWeatherView_->SetUpTimeView();
}
}
}
UISwipeView* GetSwipeView()
UISwipeView* GetSwipeView() const
{
return swipe_;
}
+36 -39
View File
@@ -13,7 +13,7 @@
* limitations under the License.
*/
#include <time.h>
#include <ctime>
#include <securec.h>
#include "time_weather_view.h"
@@ -27,6 +27,7 @@ static constexpr int16_t BIGLABEL_H = 100;
static constexpr int16_t SMALLLABEL_H = 35;
static constexpr int16_t IMAGE_H = 40;
static constexpr int16_t IMAGE_W = 40;
const char* g_weekDate[WEEK_DAY_MAX] = {"星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
TimeWeatherView::TimeWeatherView(UIViewGroup* viewGroup)
{
@@ -65,10 +66,22 @@ void TimeWeatherView::SetUpTimeView()
const int16_t commonYear = 1970;
time_t t = time(nullptr);
struct tm* st = localtime(&t);
sprintf_s(hour_min, sizeof(hour_min), "%02d : %02d", st->tm_hour, st->tm_min);
sprintf_s(mont_day, sizeof(mont_day), "%02d月%02d日", st->tm_mon + january, st->tm_mday);
if (st == nullptr) {
return;
}
int ret = sprintf_s(hour_min, sizeof(hour_min), "%02d : %02d", st->tm_hour, st->tm_min);
if (ret == LAUNCHER_PARAMERROR) {
return;
}
ret = sprintf_s(mont_day, sizeof(mont_day), "%02d月%02d日", st->tm_mon + january, st->tm_mday);
if (ret == LAUNCHER_PARAMERROR) {
return;
}
GetWeekdayByYearday(st->tm_year + commonYear, st->tm_mon + january, st->tm_mday, week_day, sizeof(week_day));
sprintf_s(date, sizeof(date), "%s %s", mont_day, week_day);
ret = sprintf_s(date, sizeof(date), "%s %s", mont_day, week_day);
if (ret == LAUNCHER_PARAMERROR) {
return;
}
if (viewTime_ == nullptr) {
viewTime_ = new UIViewGroup();
viewTime_->SetPosition(BLANK_TW, BLANK_H, viewGroup_->GetWidth() - BLANK_W,
@@ -99,14 +112,24 @@ void TimeWeatherView::SetUpTimeView()
viewTime_->Add(lable2);
viewGroup_->Add(viewTime_);
} else {
static_cast<UILabel*>(viewTime_->GetChildById("labletime"))->SetText(hour_min);
static_cast<UILabel*>(viewTime_->GetChildById("labledate"))->SetText(date);
UILabel* label = nullptr;
label = static_cast<UILabel*>(viewTime_->GetChildById("labletime"));
if (label) {
label->SetText(hour_min);
}
label = static_cast<UILabel*>(viewTime_->GetChildById("labledate"));
if (label) {
label->SetText(date);
}
viewTime_->Invalidate();
}
}
void TimeWeatherView::GetWeekdayByYearday(int iY, int iM, int iD, char* date, int size)
{
if (date == nullptr) {
return;
}
const int16_t months = 12;
const int16_t january = 1;
const int16_t february = 2;
@@ -119,39 +142,13 @@ void TimeWeatherView::GetWeekdayByYearday(int iY, int iM, int iD, char* date, in
}
// 1 : MONDAY_LAUNCHER, 2 : TUESDAY_LAUNCHER, 3 : WEDNESDAY_LAUNCHER, 4 : , 5 : ect
iWeekDay = (iD + 1 + 2 * iM + 3 * (iM + 1) / 5 + iY + iY / 4 - iY / oneHundred + iY / fourHundred) % WEEKEND_LAUNCHER;
switch (iWeekDay) {
case SUNDAY_LAUNCHER:
memcpy_s(date, size, "星期天", strlen("星期天"));
date[strlen("星期天")] = 0;
break;
case MONDAY_LAUNCHER:
memcpy_s(date, size, "星期一", strlen("星期一"));
date[strlen("星期一")] = 0;
break;
case TUESDAY_LAUNCHER:
memcpy_s(date, size, "星期二", strlen("星期二"));
date[strlen("星期二")] = 0;
break;
case WEDNESDAY_LAUNCHER:
memcpy_s(date, size, "星期三", strlen("星期三"));
date[strlen("星期三")] = 0;
break;
case THURSDAY_LAUNCHER:
memcpy_s(date, size, "星期四", strlen("星期四"));
date[strlen("星期四")] = 0;
break;
case FRIDAY_LAUNCHER:
memcpy_s(date, size, "星期五", strlen("星期五"));
date[strlen("星期五")] = 0;
break;
case STAURDAY_LAUNCHER:
memcpy_s(date, size, "星期六", strlen("星期六"));
date[strlen("星期六")] = 0;
break;
default:
memcpy_s(date, size, "星期天", strlen("星期天"));
date[strlen("星期天")] = 0;
break;
for (int i = 0; i < WEEK_DAY_MAX; i++) {
if (iWeekDay == i) {
if (memcpy_s(date, size, g_weekDate[i], strlen(g_weekDate[i])) == LAUNCHER_SUCCESS) {
date[strlen(g_weekDate[i])] = 0;
break;
}
}
}
return;
}
+1 -1
View File
@@ -40,7 +40,7 @@ enum DATE_LAUNCHER {
class TimeWeatherView : public NativeBase {
public:
TimeWeatherView() = delete;
TimeWeatherView(UIViewGroup* viewGroup);
explicit TimeWeatherView(UIViewGroup* viewGroup);
virtual ~TimeWeatherView();
void SetStyle(Style sty);
void SetPosion(int16_t width, int16_t height, int16_t x, int16_t y);
+18 -2
View File
@@ -17,10 +17,9 @@
#define OHOS_UI_CONFIG_H
#include <cstdint>
#include <securec.h>
namespace OHOS {
static int16_t LA_HORIZONTAL_RESOLUTION = 960; // launcher table width
static int16_t LA_VERTICAL_RESOLUTION = 480; // launcher table height
static constexpr int16_t LABLE_TITLE_HEIGHT = 30; // tail lable height
static constexpr int16_t LABLE_TAIL_HEIGHT = 30;
static constexpr int16_t APP_WIDTH_COUNT = 7; // blank + app + blank + app + blank
@@ -38,11 +37,28 @@ static constexpr int16_t BUTTON_RADIUS = 20; // app icon radius
static constexpr int16_t LABLE_RADIUS = 0; // lable icon radius
static constexpr int16_t TITLE_LABLE_OPACITY = 255; // translucent
static constexpr int16_t GROUP_VIEW_RADIUS = 20; // view radius
#ifndef TMP_BUF_SIZE
#define TMP_BUF_SIZE 128
#endif
#define LAUNCHER_BUNDLE_NAME "com.huawei.launcher"
#define SCREENSAVER_BUNDLE_NAME "com.huawei.screensaver"
#define TABLE_BACKGROUND \
"/storage/app/run/com.huawei.launcher/launcher/assets/launcher/resources/base/media/background.png"
#define RES_WEATHER "/storage/app/run/com.huawei.launcher/launcher/assets/launcher/resources/base/media/weather.png"
#define FOND_PATH "SourceHanSansSC-Regular.otf"
#ifndef LAUNCHER_SUCCESS
#define LAUNCHER_SUCCESS 0
#endif
#ifndef LAUNCHER_PARAMERROR
#define LAUNCHER_PARAMERROR (-1)
#endif
#ifndef WEEK_DAY_MAX
#define WEEK_DAY_MAX 7
#endif
} // namespace OHOS
#endif
-1
View File
@@ -77,7 +77,6 @@ void ViewGroupPage::SetMatrix(int16_t rows, int16_t cols)
void ViewGroupPage::CalculateAppPosition(AppInfo* pAppInfo, int16_t row, int16_t col)
{
int16_t h = viewGroup_->GetHeight();
int16_t w = viewGroup_->GetWidth();
const double scale = scale_;

Some files were not shown because too many files have changed in this diff Show More