1/*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15import UIExtensionAbility from '@ohos.app.ability.UIExtensionAbility';
16import media from '@ohos.multimedia.media';
17import Log from '../../../../../../common/src/main/ets/default/Log';
18import Want from '@ohos.app.ability.Want';
19import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession';
20import { BusinessError } from '@ohos.base';
21
22const TAG = 'AVScreenCapture-DiaLogUIExtensionAbility';
23
24export default class DialogAbility extends UIExtensionAbility {
25  onCreate(): void {
26    Log.showInfo(TAG, 'DialogAbility onCreate');
27    globalThis.sessionId = -1;
28    globalThis.userChoice = 'false';
29  }
30
31  onForeground(): void {
32    Log.showInfo(TAG, 'DialogAbility onForeground');
33  }
34
35  onBackground(): void {
36    Log.showInfo(TAG, 'DialogAbility onBackground');
37  }
38
39  onDestroy(): void {
40    Log.showInfo(TAG, `Report user choice sessionId(${globalThis.sessionId}), userChoice(${globalThis.userChoice})`);
41    media.reportAVScreenCaptureUserChoice(Number(globalThis.sessionId), globalThis.userChoice);
42  }
43
44  onSessionCreate(want: Want, session: UIExtensionContentSession): void {
45    Log.showInfo(TAG, 'onSessionCreate');
46    globalThis.dialogContext = this.context;
47    globalThis.dialogWant = want;
48    globalThis.dialogSession = session;
49    globalThis.sessionId = want.parameters?.sessionId as number;
50    let param: Record<string, UIExtensionContentSession> = {
51      'session': session
52    }
53    let storage: LocalStorage = new LocalStorage(param);
54    try {
55      session.loadContent('PrivacyDialog/DialogPage', storage);
56    } catch (err) {
57      Log.showError(TAG, 'session loadContent error: ' + (err as BusinessError).message);
58    }
59    session.setWindowBackgroundColor('#00ffffff');
60  }
61
62  onSessionDestroy(session: UIExtensionContentSession): void {
63    Log.showInfo(TAG, 'UIExtAbility onSessionDestroy');
64  }
65}