@oniroproject/oniro-app 0.13.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -69,7 +69,7 @@ Install commands are idempotent (they skip when already present); pass `--force`
69
69
  | Command | Description |
70
70
  | --- | --- |
71
71
  | `cmdtools install [--from-zip <path>] [--force] [--tmp-dir <path>]` | Install the tools. `--from-zip` installs from a local archive instead of downloading (required on Windows/macOS — see [Configuration](#configuration)); `--tmp-dir` overrides where download/extract temporaries go (see [Temporary space](#temporary-space)). |
72
- | `cmdtools status [--json]` | Report whether the tools are installed and their version. Exits non-zero when not installed. |
72
+ | `cmdtools status [--json]` | Report whether the tools are installed, their version, their flavour (`HarmonyOS` when they bundle `sdk/default/hms`, as the Huawei developer-portal download does, else `OpenHarmony`), and the `hdc` binary every device command uses. Exits non-zero when not installed. |
73
73
  | `cmdtools remove` | Delete the configured command-line-tools directory. |
74
74
 
75
75
  #### `emulator` — manage the Oniro emulator (QEMU-based)
@@ -78,6 +78,7 @@ Install commands are idempotent (they skip when already present); pass `--force`
78
78
  | --- | --- |
79
79
  | `emulator install [--force] [--tmp-dir <path>]` | Download and install the emulator. `--tmp-dir` overrides where the downloaded ZIP goes (see [Temporary space](#temporary-space)). |
80
80
  | `emulator start [options]` | Start the emulator via the bundled launcher and detach, so the CLI can exit while it keeps running. |
81
+ | `emulator status [--address <host:port>] [--json]` | Report whether the emulator is installed, running, and connected to `hdc`, without starting it. Exits non-zero when not installed. DevEco Studio's HarmonyOS emulator is not covered; it shows up in `devices`. |
81
82
  | `emulator stop` | Kill running emulator processes. |
82
83
  | `emulator connect [--address <host:port>]` | Attempt an `hdc` connection (default `127.0.0.1:55555`). |
83
84
  | `emulator remove` | Delete the configured emulator directory. |
@@ -126,13 +127,14 @@ Only needed for HarmonyOS signing; see [HarmonyOS apps](#harmonyos-apps).
126
127
 
127
128
  #### `sign` — generate signing keys, certs, and `signingConfigs`
128
129
 
129
- `sign [project-dir]` (defaults to the current directory). Requires `java` on `PATH`. Rewrites only the `signingConfigs` block of `build-profile.json5` (other keys are preserved). The generated profile uses the SDK's built-in development cert (`issuer=pki_internal`) and its validity window — **dev/local builds only, not distribution.** See [Signing apps that need system permissions](#signing-apps-that-need-system-permissions) for `--apl` / `--acls`.
130
+ `sign [project-dir]` (defaults to the current directory). Requires `java` on `PATH`. Rewrites the `signingConfigs` block of `build-profile.json5`, and points any product that names no `signingConfig` at the generated one (other keys are preserved). The generated profile uses the SDK's built-in development cert (`issuer=pki_internal`) and its validity window — **dev/local builds only, not distribution.** See [Signing apps that need system permissions](#signing-apps-that-need-system-permissions) for `--apl` / `--acls`.
130
131
 
131
132
  | Flag | Description |
132
133
  | --- | --- |
133
134
  | `--apl <level>` | Ability Privilege Level: `normal` (default), `system_basic`, or `system_core`. |
134
135
  | `--app-feature <feature>` | `hos_normal_app` or `hos_system_app`. Defaults follow `--apl`. |
135
136
  | `--acls <list>` | Comma-separated permissions to write into the profile's `acls.allowed-acls`. |
137
+ | `--app-privilege-capabilities <list>` | Comma-separated privileges to write into the profile's `app-privilege-capabilities`, e.g. `AllowAppUsePrivilegeExtension` for an app with a privileged extension ability (without it, install fails with `9568344 not allow use privilege extension`). |
136
138
  | `--bootstrap` | No-op if signing material is already present; otherwise generate it. |
137
139
  | `--harmonyos` | Sign a HarmonyOS project via AppGallery Connect instead of the offline flow. See [HarmonyOS apps](#harmonyos-apps). |
138
140
  | `--team-id <id>` | With `--harmonyos`: AGC team to sign under. |
@@ -142,7 +144,7 @@ Only needed for HarmonyOS signing; see [HarmonyOS apps](#harmonyos-apps).
142
144
 
143
145
  #### `build` — build the app via `hvigorw`
144
146
 
145
- `build [project-dir]` (defaults to the current directory). Modules build in parallel by default.
147
+ `build [project-dir]` (defaults to the current directory). Modules build in parallel by default. An OpenHarmony project whose `compileSdkVersion` SDK is not installed fails before anything runs, naming the release to install. When the compiler output shows system-API errors (`'…' is not exported from Kit '…'`), the error adds a hint about the full SDK.
146
148
 
147
149
  | Flag | Description |
148
150
  | --- | --- |
@@ -152,34 +154,35 @@ Only needed for HarmonyOS signing; see [HarmonyOS apps](#harmonyos-apps).
152
154
  | `--task <task>` | hvigor task to run (default `assembleHap`). |
153
155
  | `--no-deps` | Skip the automatic `ohpm install --all` when `oh_modules/` is missing. |
154
156
  | `--no-parallel` | Build modules serially. |
157
+ | `--install-sdk` | Install the missing OpenHarmony SDK the project compiles against, then build. |
155
158
  | `--json` | Emit the result (discovered HAPs grouped by module, warnings) as JSON. |
156
159
 
157
160
  #### `lint` — run the OpenHarmony codelinter
158
161
 
159
- `lint [project-dir]` (defaults to the current directory). Exits with the codelinter's exit code.
162
+ `lint [project-dir]` (defaults to the current directory). Prints each finding as `file:line:col severity message [rule]`, then the totals (`N defects: E errors, W warnings, S suggestions.`). Exits 1 on error-severity findings or when codelinter fails to produce a report; warnings alone exit 0, although codelinter itself exits 1 for them. When codelinter says its report is incomplete, for example because the command-line tools' flavour (see `cmdtools status`) does not match the project's `runtimeOS`, a warning on stderr explains it: treat the counts as a lower bound.
160
163
 
161
164
  | Flag | Description |
162
165
  | --- | --- |
163
166
  | `--files <globs...>` | Specific files/globs to lint (default: the whole project). |
164
- | `--json` | Emit findings as JSON. |
167
+ | `--json` | Emit the report as JSON: `findings`, `summary` (codelinter's totals), `notices`, `incomplete`, `code`, and the cleaned `raw` output. |
165
168
 
166
169
  ### Device & app
167
170
 
168
- These commands target a connected device or emulator over `hdc`. Most accept `--device <serial>` to address a specific target; omit it to use the single connected device.
171
+ These commands target a connected device or emulator over `hdc`. Most accept `--device <serial>` to address a specific target. Without it they use `ONIRO_DEVICE_SERIAL`, then the single connected device. A TCP serial such as `127.0.0.1:5555` works like a USB one. hdc exits 0 even when it fails (`[Fail]ExecuteCommand need connect-key?` when several targets are connected and none was named); every command here reports that as an error.
169
172
 
170
173
  #### `devices` — list connected hdc devices
171
174
 
172
175
  | Command | Description |
173
176
  | --- | --- |
174
- | `devices [--json]` | List connected targets (`serial`, connection, status). |
177
+ | `devices [--long] [--json]` | List connected targets (`serial`, connection, status). `--long` also asks each connected one for its OS family and version (`os=HarmonyOS 6.1.0` / `os=OpenHarmony`), API level, CPU ABI, device type, model, and `const.ohos.fullname`. |
175
178
 
176
179
  #### `app` — install, launch, and manage built apps
177
180
 
178
181
  | Command | Description |
179
182
  | --- | --- |
180
- | `app install [project-dir] [--hap <path>] [--device <serial>]` | Install the signed `.hap` via `hdc`. `--hap` overrides the resolved path. |
183
+ | `app install [project-dir \| file.hap] [--hap <path>] [--device <serial>]` | Install a `.hap` via `hdc`: a given file, else the project's newest signed HAP, else its unsigned one (a `*-signed.hap` path that does not exist falls back to its `*-unsigned.hap`). Fails when the bundle manager rejects the HAP; when a target refuses an unsigned HAP, the error gives the bundle manager's reason and the `sign` command to run. |
181
184
  | `app launch [project-dir] [--module <m>] [--ability <name>] [--device <serial>]` | Launch the app. `--ability` defaults to the module's `mainElement` / first visible ability. |
182
- | `app apply [project-dir] --bundle <b> [options]` | Install a HAP **and verify the running process took the change** — handles sign-info mismatch, asset-cache invalidation, and persistent-bundle restart. |
185
+ | `app apply [project-dir] --bundle <b> [options]` | Install a HAP **and verify it took**: fails when the bundle manager rejects it or `bm dump` does not then list the bundle, and handles sign-info mismatch, asset-cache invalidation, and persistent-bundle restart. Uses the newest signed HAP, else the unsigned one, and explains a target's refusal of an unsigned HAP like `app install`. |
183
186
  | `app uninstall <bundle> [--device <serial>]` | Uninstall an app by bundle name. |
184
187
  | `app stop <bundle> [--device <serial>]` | Force-stop an app by bundle name. |
185
188
 
@@ -200,9 +203,72 @@ These commands target a connected device or emulator over `hdc`. Most accept `--
200
203
 
201
204
  | Command | Description |
202
205
  | --- | --- |
203
- | `file send <local> <remote> [--device <serial>]` | Push a local file to the device. |
206
+ | `file send <local> <remote> [--bundle <b>] [--device <serial>]` | Push a local file to the device and print the device path. With `--bundle`, `<remote>` may be relative to that app's sandbox (`files/x` is its application-level `filesDir`, `haps/entry/files/x` the entry module's), and the file is chowned to the app, which cannot read root-owned files. |
204
207
  | `file recv <remote> <local> [--device <serial>]` | Pull a file from the device. |
205
208
 
209
+ Local paths may be relative, or absolute with either slash. A device path that a Windows shell already rewrote (Git Bash turns `/data/local/tmp/x` into `C:/Program Files/Git/data/local/tmp/x`) is rejected: run the command with `MSYS_NO_PATHCONV=1`.
210
+
211
+ #### `logs` — capture hilog to a file for a whole session
212
+
213
+ `logs -o <file>` streams hilog into `<file>` until `--for` elapses or the process is interrupted, so start it in the background. The device's log buffer is small (256 KB per type by default) and chatty components such as ArkWeb wrap it within seconds, so a dump at the end of a session loses its start. Every line is written as it arrives, and the stream reconnects after a reboot.
214
+
215
+ | Flag | Description |
216
+ | --- | --- |
217
+ | `-o, --output <file>` | **Required.** File to append to. |
218
+ | `--for <ms>` | Stop after this long (default: until interrupted). |
219
+ | `--grep <regex>` | Keep only matching lines (default: all). |
220
+ | `--clear` | Clear the device log buffer first (`hilog -r`), so the file covers only this session. |
221
+ | `--domain <domain>` | hilog domain filter (e.g. `0xD003900`). |
222
+ | `--device <serial>` | Target device serial. |
223
+
224
+ #### `logs collect` — create a diagnostic bundle
225
+
226
+ ```bash
227
+ oniro-app logs collect --redact --package com.example.app
228
+ ```
229
+
230
+ The command requires exactly one connected device unless `--device` (or
231
+ `ONIRO_DEVICE_SERIAL`) selects one. It captures the current `hilog -x` buffer,
232
+ faultlog evidence, device information, process list, and memory/thread snapshots.
233
+ Because `hilog -x` has no duration argument, `--duration` filters recognized
234
+ HiLog timestamps locally using device clock readings before and after the snapshot.
235
+ If the clock or log format cannot be parsed reliably, the manifest records the
236
+ window as unapplied, the command exits non-zero, and the full snapshot is omitted
237
+ from the redacted archive (it remains only in the local raw bundle).
238
+ `--pid`, `--tag`, and `--level` create an additional filtered HiLog view from the
239
+ time-bounded records when their format can be parsed reliably. `--package`
240
+ targets `hidumper -e --print <bundle> -n 5` for faultlog evidence.
241
+
242
+ `--redact` creates a sibling `incident-...-redacted` directory and ZIP; the
243
+ archive is built only from that redacted copy. Without `--redact`, the archive
244
+ contains raw sensitive data. Redaction is heuristic, fails closed on binary or
245
+ unknown-encoding files, and does not guarantee that a bundle is safe to publish.
246
+ Collection continues after individual command failures and records each result
247
+ in `manifest.json`; the CLI exits non-zero for a partial bundle. The default
248
+ output is under `~/.oniro/incident-bundles`; bundle files are created with
249
+ owner-only permissions where the host OS supports POSIX modes.
250
+
251
+ | Flag | Description |
252
+ | --- | --- |
253
+ | `-o, --output <directory>` | Parent directory for bundles (default `~/.oniro/incident-bundles`). |
254
+ | `--device <serial>` | Target device serial. |
255
+ | `--package <bundle>` | Bundle name for package-specific faultlog collection. |
256
+ | `--pid <pid>` | Create an exact-PID filtered HiLog view. |
257
+ | `--tag <tag>` | Create an exact-tag filtered HiLog view. |
258
+ | `--level <level>` | Create a filtered view for `V`, `D`, `I`, `W`, `E`, or `F`. |
259
+ | `--duration <seconds>` | Include HiLog records from the last N seconds (default `600`; maximum `31536000`). |
260
+ | `--redact` | Redact text evidence; create the archive only from the redacted copy. |
261
+ | `--json` | Emit bundle paths and completion status as JSON. |
262
+
263
+ #### `hdc` — run the bundled hdc
264
+
265
+ `hdc [args...]` runs the `hdc` binary oniro-app itself uses (the one `cmdtools status` shows), with stdio passed through, so it needs nothing on `PATH`. Device commands are addressed at `--device` or `ONIRO_DEVICE_SERIAL` unless the arguments start with `-t`. `hdc --path` prints the binary's location. The exit code is hdc's own, which is 0 even for a `[Fail]` line.
266
+
267
+ ```bash
268
+ oniro-app hdc shell param get const.ohos.apiversion
269
+ oniro-app hdc --device 127.0.0.1:5555 shell aa dump -l
270
+ ```
271
+
206
272
  #### `reboot` — reboot the device
207
273
 
208
274
  | Flag | Description |
@@ -333,6 +399,7 @@ oniro-app gesture --waypoints '[{"x":200,"y":600,"t":0},{"x":200,"y":200,"t":400
333
399
  - **Results → stdout.** Plain text by default; `--json` (where supported) writes `JSON.stringify(..., null, 2)`. Read/observe commands (`sdk list`, `cmdtools status`, `templates list`, `devices`, `wait --log` / `--target`, `watch`, `lint`, `app apply`, `build`) accept `--json` (and `screenshot` with `--contact-sheet`); `dump` emits JSON unless `--flat`; action-only commands do not.
334
400
  - **Progress & logs → stderr.** stdout stays clean for machine consumers, so `oniro-app create … > path.txt` or `oniro-app devices --json | jq` work cleanly.
335
401
  - **Exit code.** `0` on success, non-zero on failure (the error message is written to stderr). Set `ONIRO_DEBUG=1` to also print full stack traces.
402
+ - **Global options go before the command** (`oniro-app --version`), so `hdc` can pass its arguments through untouched.
336
403
 
337
404
  ## Configuration
338
405
 
@@ -344,6 +411,8 @@ The CLI reads paths and URLs from environment variables. All are optional; defau
344
411
  | `ONIRO_CMD_TOOLS_PATH` | `~/command-line-tools` | Command-line tools install root |
345
412
  | `ONIRO_EMULATOR_DIR` | `~/oniro-emulator` | Emulator install root |
346
413
  | `ONIRO_HAP_PATH` | `entry/build/.../entry-default-signed.hap` | Default `.hap` used by `app install` (relative to the project) |
414
+ | `ONIRO_DEVICE_SERIAL` | (unset) | Device every device command addresses when `--device` is not given (also read as `DEVICE_SERIAL`) |
415
+ | `ONIRO_HDC` | the cmd-tools `hdc` | `hdc` binary to use instead, e.g. a wrapper for a remote device |
347
416
  | `ONIRO_SDK_URL_BASE` | `https://repo.huaweicloud.com/openharmony/os` | Base URL for SDK downloads (point at a private/CI mirror) |
348
417
  | `ONIRO_CMD_TOOLS_URL_LINUX` | Huawei mirror, x64 5.1.0.840 | Override the Linux cmd-tools URL |
349
418
  | `ONIRO_CMD_TOOLS_URL_WINDOWS` | (unset) | Self-hosted Windows cmd-tools URL |
@@ -502,7 +571,16 @@ oniro-app sign --apl system_core \
502
571
  --acls ohos.permission.REBOOT,ohos.permission.INJECT_INPUT_EVENT
503
572
  ```
504
573
 
505
- The `signingConfigs` block written to `build-profile.json5` mirrors the names used by the project's `products[*].signingConfig` (e.g. `applications/standard/systemui` uses `release`, `launcher` uses `default`). If the project has no products section, `default` is used.
574
+ An app that declares a privileged extension ability, such as an `AccessibilityExtensionAbility`, also needs `AllowAppUsePrivilegeExtension` in the profile's `app-privilege-capabilities`; without it the install fails with `9568344 not allow use privilege extension`. Pass it, and any other privilege (`AllowAppMultiProcess`, `AllowAppDesktopIconHide`, …), via `--app-privilege-capabilities`:
575
+
576
+ ```bash
577
+ oniro-app sign --apl system_core --acls ohos.permission.ACCESSIBILITY_EXTENSION_ABILITY \
578
+ --app-privilege-capabilities AllowAppUsePrivilegeExtension
579
+ ```
580
+
581
+ Apps like these usually also call system APIs (`@systemapi`), which the public SDK that `sdk install` downloads leaves out: the build fails with errors such as `'config' is not exported from Kit '@kit.AccessibilityKit'`. Build them against the full OpenHarmony SDK by unpacking its components into `<root>/<os>/<api>` of a separate SDK root and pointing `ONIRO_SDK_ROOT_DIR` at that root.
582
+
583
+ The `signingConfigs` block written to `build-profile.json5` mirrors the names used by the project's `products[*].signingConfig` (e.g. `applications/standard/systemui` uses `release`, `launcher` uses `default`). If the project has no products section, `default` is used, and a product that names no `signingConfig` is pointed at it.
506
584
 
507
585
  ## Programmatic use
508
586