diff --git a/README.en.md b/README.en.md index 0bf8807..b814a5f 100644 --- a/README.en.md +++ b/README.en.md @@ -1,4 +1,4 @@ -# Spooler +# PrintSpooler - [Introduction](#section11660541593) - [Architecture](#section125101832114213) @@ -8,7 +8,7 @@ ## Introduction -Spooler is a system app preinstalled in OpenHarmony. It provides users with functions such as print preview, discovering and connecting printers, setting print parameters, issuing print tasks, and managing print tasks. +PrintSpooler is a system app preinstalled in OpenHarmony. It provides users with functions such as print preview, discovering and connecting printers, setting print parameters, issuing print tasks, and managing print tasks. ### Architecture @@ -18,12 +18,12 @@ Spooler is a system app preinstalled in OpenHarmony. It provides users with func ``` /applications/standard/print_spooler - figures # Architecture figures - entry # Main entry module code - signature # Certificate files - LICENSE # License files - features - ippPrint # ipp print +├── figures # Architecture figures +├── entry # Main entry module code +├── signature # Certificate files +├── LICENSE # License files +├── features + ├── ippPrint # ipp print ``` diff --git a/README.md b/README.md index 560431b..a1ecf5d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Spooler +# PrintSpooler - [简介](#section11660541593) - [架构图](#section125101832114213) @@ -8,7 +8,7 @@ ## 简介 -Spooler应用是OpenHarmony中预置的系统应用,为用户提供打印预览、发现和连接打印机、打印参数设置、下发打印任务以及打印任务状态的管理等功能。 +PrintSpooler应用是OpenHarmony中预置的系统应用,为用户提供打印预览、发现和连接打印机、打印参数设置、下发打印任务以及打印任务状态的管理等功能。 ### 架构图 @@ -26,5 +26,182 @@ Spooler应用是OpenHarmony中预置的系统应用,为用户提供打印预 │ ├── ippPrint # 局域网打印组件 ``` +### + +## 基础开发说明 +### 资源引用 +#### 定义资源文件 +- 在 `src/main/resources/`目录下,根据不同的资源类型,定义资源文件。 + + ```json + { + "name": "default_background_color", + "value": "#F1F3F5" + }, + ``` +#### 引用资源 +- 在有对应page的ets文件中,可直接通过`$r()`引用。 + ```` JavaScript + @Provide backgroundColor: Resource = $r('app.color.default_background_color'); + ```` +## 典型接口的使用 +打印框架启动打印界面 + + ``` + std::string jobId = GetPrintJobId(); + auto printJob = std::make_shared(); + if (printJob == nullptr) { + return E_PRINT_GENERIC_FAILURE; + } + printJob->SetFdList(fdList); + printJob->SetJobId(jobId); + printJob->SetJobState(PRINT_JOB_PREPARED); + AAFwk::Want want; + want.SetElementName(SPOOLER_BUNDLE_NAME, SPOOLER_ABILITY_NAME); + want.SetParam(LAUNCH_PARAMETER_JOB_ID, jobId); + want.SetParam(LAUNCH_PARAMETER_FILE_LIST, fileList); + BuildFDParam(fdList, want); + int32_t callerTokenId = static_cast(IPCSkeleton::GetCallingTokenID()); + std::string callerPkg = DelayedSingleton::GetInstance()->QueryCallerBundleName(); + ingressPackage = callerPkg; + int32_t callerUid = IPCSkeleton::GetCallingUid(); + int32_t callerPid = IPCSkeleton::GetCallingPid(); + want.SetParam(AAFwk::Want::PARAM_RESV_CALLER_TOKEN, callerTokenId); + want.SetParam(AAFwk::Want::PARAM_RESV_CALLER_UID, callerUid); + want.SetParam(AAFwk::Want::PARAM_RESV_CALLER_PID, callerPid); + want.SetParam(CALLER_PKG_NAME, callerPkg); + if (!StartAbility(want)) { + PRINT_HILOGE("Failed to start spooler ability"); + return E_PRINT_SERVER_FAILURE; + } + ``` +## 签名打包 +### 签名 +#### 签名文件的获取 +1. 拷贝OpenHarmony标准版 工程的 OpenHarmony\signcenter_tool 目录到操作目录 +2. 拷贝SystemUI 工程的 signature\spooler.p7b 到该目录下 +#### 签名文件的配置 +打开项目工程,选择 File → Project Structure + +![](figures/signature_1.png) + +选择 Project → Signing Configs,将对应的签名文件配置如下,完成后点击Apply,再点击OK。 + +![](figures/signature_2.png) + +## 安装、运行、调试 +## 应用安装 +配置 hdc: +进入SDK目录中的toolchains文件夹下,获取文件路径: + +![](figures/screenshot-20210521-105407.png) + +> 注意,此处的hdc.exe如果版本较老,可能不能正常使用,需要获取新的hdc.exe文件 +> hdc命令介绍与下载详见:[hdc仓库地址](https://gitee.com/openharmony/developtools_hdc_standard) +并将此路径配置到环境变量中: + +![](figures/screenshot-20210521-111223.png) + +重启电脑使环境变量生效 + +连接开发板,打开cmd命令窗口,执行hdc list targets,弹出窗口如下: + +![](figures/cmd1.png) + +等待一段时间后,窗口出现如下打印,可回到输入 hdc list targets 的命令窗口继续操作: + +![](figures/cmd2.png) + +再次输入hdc list targets,出现如下结果,说明hdc连接成功 + +![](figures/cmd3.png) + +获取读写权限: + +``` +hdc target mount +``` +将签名好的 hap 包放入设备的 `/system/app/com.ohos.spooler` 目录下,并修改hap包的权限 + +``` +hdc file send 本地路径 /system/app/com.ohos.spooler/hap包名称 +例如:hdc file send Spooler.hap /system/app/com.ohos.spooler/Spooler.hap +``` +## 应用运行 +Spooler属于系统应用,在将签名的 hap 包放入 `/system/app/com.ohos.spooler` 目录后,重启系统,应用会自动拉起。 +``` +hdc shell +reboot +(不可以直接执行hdc reboot,命令是无效的) +``` +> 注意,如果设备之前安装过系统应用,则需要执行如下两条命令清除设备中存储的应用信息才能够在设备重启的时候将我们装入设备的新 hap 包正常拉起。 +> ``` +> hdc shell rm -rf /data/misc_de/0/mdds/0/default/bundle_manager_service +> hdc shell rm -rf /data/accounts +> ``` +## 应用调试 +### log打印 +- 在程序中添加 log +```JS +import hilog from '@ohos.hilog'; +hilog.info(0x0001, "Spooler", "%{public}s World %{private}d", "hello", 3); +``` +### log获取及过滤 +- log获取 + + +将log输出至文件 +``` +hdc shell hilog > 输出文件名称 +``` + +例: +在真实环境查看log,将全log输出到当前目录的hilog.log文件中 +``` +hdc shell hilog > hilog.log +``` + +- log过滤 + +在命令行窗口中过滤log +``` +hilog │ grep 过滤信息 +``` + +例:过滤包含信息 Label 的 hilog +``` +hilog │ grep Label +``` +## 贡献代码 +### Fork 代码仓库 +1. 在码云上打开 SystemUI 代码仓库([仓库地址](https://gitee.com/openharmony/applications_print_spooler))。 + +2. 点击仓库右上角的 Forked 按钮,在弹出的画面中,选择将仓库 fork 到哪里,点击确认。 + +3. Fork 成功之后,会在自己的账号下看见 fork 的代码仓库。 + +### 提交代码 +1. 访问我们自己在码云账号上 fork 的代码仓库,点击“克隆/下载”按钮,选择 SSH/HTTPS,点击“复制”按钮。 + +2. 在本地新建 SystemUI 目录,在 SystemUI 目录中执行如下命令 + ``` + git clone 步骤1中复制的地址 + ``` + +3. 修改代码。 + + > 将代码引入工程,以及编译工程等相关内容请参见 **3. 代码使用** 部分的相关内容。 +4. 提交代码到 fork 仓库。 + > 修改后的代码,首先执行 `git add` 命令,然后执行 `git commit` 命令与 `git push` 命令,将代码 push 到我们自己的 fork 仓中。 + > 关于代码提交的这部分内容涉及 git 的使用,可以参照 [git官网](https://git-scm.com/) 的内容,在此不再赘述。 + +### 发起 Pull Request (PR) +在将代码提交到 fork 仓之后,我们可以通过发起 Pull Request(PR)的方式来为 OpenHarmony 的相关项目贡献代码。 + +1. 打开 fork 仓库。选择 `Pull Requests` → `新建 Pull Request` + +2. 在 `新建 Pull Request` 画面填入标题与说明,点击 `创建` 按钮。 + +3. 创建 Pull Request 完成。 PR 创建完成后,会有专门的代码审查人员对代码进行评审,评审通过之后会合入相应的代码库。 diff --git a/figures/cmd1.png b/figures/cmd1.png new file mode 100644 index 0000000..43cec74 Binary files /dev/null and b/figures/cmd1.png differ diff --git a/figures/cmd2.png b/figures/cmd2.png new file mode 100644 index 0000000..b771fda Binary files /dev/null and b/figures/cmd2.png differ diff --git a/figures/cmd3.png b/figures/cmd3.png new file mode 100644 index 0000000..75cc11c Binary files /dev/null and b/figures/cmd3.png differ diff --git a/figures/screenshot-20210521-111223.png b/figures/screenshot-20210521-111223.png new file mode 100644 index 0000000..789beda Binary files /dev/null and b/figures/screenshot-20210521-111223.png differ diff --git a/figures/signature_1.png b/figures/signature_1.png new file mode 100644 index 0000000..2e8ecf3 Binary files /dev/null and b/figures/signature_1.png differ diff --git a/figures/signature_2.png b/figures/signature_2.png new file mode 100644 index 0000000..c224c52 Binary files /dev/null and b/figures/signature_2.png differ diff --git a/figures/signature_3.png b/figures/signature_3.png new file mode 100644 index 0000000..a29b648 Binary files /dev/null and b/figures/signature_3.png differ diff --git a/signature/spooler.p7b b/signature/spooler.p7b new file mode 100644 index 0000000..0e8b155 Binary files /dev/null and b/signature/spooler.p7b differ