Chatter3 engineering notes

Note 2 · ArkWeb · Permissions

The camera was granted, and the app still said it was denied

The reviewer had allowed the camera in the system settings and still got a screen saying the camera permission was denied. The permission was not the problem. The answer was.

Chatter3 1.0.7 → 1.0.8 · the second finding of the AppGallery review

The symptom

On the call screen the app asks for the camera and the microphone. In the HarmonyOS build the request never went anywhere, and the page reported the only thing it could report: that the permission had been denied. The user had granted it in the settings. The app still said no.

Two permissions, not one

A protected resource in a WebView passes through two separate gates, and they are easy to confuse because they have the same name:

  1. The system permission. ohos.permission.CAMERA and ohos.permission.MICROPHONE are declared in module.json5 and granted by the user in the system settings. This is the one the reviewer had granted.
  2. The page permission. Every time a page asks for a protected resource, ArkWeb asks the host app through onPermissionRequest. The host app decides whether the page may have it, per request.

Granting the first says nothing about the second. The page is not talking to the system; it is talking to the shell. And the shell had no answer to give, so the engine treated every request as a refusal.

Why this one is worth writing down

The failure is invisible in the code. There is no deny() anywhere, no permission list to inspect, no error to read. An unanswered callback is a refusal, and the refusal is indistinguishable from a user who said no.

The fix: answer the question when it is asked

The shell now answers onPermissionRequest, and it asks the system for the matching permission at that moment — not at start‑up.

private handleMediaPermission(request: PermissionRequest): void {
  const asked: string[] = request.getAccessibleResource();
  const wanted: string[] = [];
  const permissions: Permissions[] = [];
  if (asked.indexOf(ProtectedResourceType.VIDEO_CAPTURE) !== -1) {
    wanted.push(ProtectedResourceType.VIDEO_CAPTURE);
    permissions.push('ohos.permission.CAMERA');
  }
  if (asked.indexOf(ProtectedResourceType.AUDIO_CAPTURE) !== -1) {
    wanted.push(ProtectedResourceType.AUDIO_CAPTURE);
    permissions.push('ohos.permission.MICROPHONE');
  }
  if (wanted.length === 0) { request.deny(); return; }

  const context = this.getUIContext().getHostContext() as Context;
  const atManager = abilityAccessCtrl.createAtManager();
  atManager.requestPermissionsFromUser(context, permissions)
    .then((result: PermissionRequestResult) => {
      let granted: boolean = true;
      for (let i = 0; i < result.permissions.length; i++) {
        // 0 is PERMISSION_GRANTED. Anything else is a refusal.
        if (result.authResults[i] !== 0) { granted = false; }
      }
      if (granted) { request.grant(wanted); } else { request.deny(); }
    })
    .catch((err: BusinessError) => {
      try { request.deny(); } catch (ignore) {}
    });
}

Three decisions are in that code, and each of them was argued about:

  • The page is granted only what the system granted. Granting the page unconditionally would open the camera in a build whose manifest no longer asks for it, and would hide a real refusal from the user.
  • The system is asked at the moment the page asks. The obvious alternative is to ask for the camera at launch, which is simpler. It is also wrong for this app: the system dialog at launch delays the first frame, and the time to first frame is one of the things Huawei measures. Asking late has the side benefit that the user has already arrived at a screen where the camera makes sense — they pressed Start call.
  • An already‑granted permission produces no dialog. requestPermissionsFromUser answers immediately when the user has already allowed it, which is the case the reviewer was in.

What the user sees now

When the system refuses, the page says the camera was refused and offers a retry. When the system allows, the camera opens. The page never has to guess, because the shell always answers — even when the answer is no.

The same handler is attached to the second, sandboxed window of the first note, where it is deliberately limited: a window opened by a third‑party frame gets no camera and no microphone at all.


← All notes · Next: the Durable Object that forgot one of the two people →