1/*
2 * Copyright (c) 2023 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 Want from '@ohos.app.ability.Want';
17import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession';
18import Logger from '../log/HiAdLog';
19
20const TAG: string = '[AdsUIExtensionAbility]';
21
22/**
23 * UEA入口
24 */
25export default class AdsUIExtensionAbility extends UIExtensionAbility {
26  onCreate() {
27    Logger.i(TAG, `AdsUIExtensionAbility test onCreate`);
28    Logger.i(TAG, `AdsUIExtensionAbility test onCreate dir :${this.context.cacheDir}`);
29  }
30
31  onSessionCreate(want: Want, session: UIExtensionContentSession) {
32    Logger.i(TAG, `AdsUIExtensionAbility test onSessionCreate`);
33    const storage = new LocalStorage();
34    storage.setOrCreate('session', session);
35    storage.setOrCreate('want', want);
36    let parameters = want?.parameters;
37    Logger.i(TAG, `AdsUIExtensionAbility AdDisplayOptions: ${JSON.stringify(parameters)}`);
38    let AdDisplayOptions = want?.parameters["displayOptions"];
39    if (AdDisplayOptions["refreshTime"]) {
40      Logger.i(TAG, `AdsUIExtensionAbility refreshTime: ${AdDisplayOptions["refreshTime"]}`);
41      session.loadContent("pages/AutoRefreshPage", storage);
42    } else {
43      session.loadContent("pages/UIExtensionAbilityPage", storage);
44    }
45
46  }
47
48  onForeground() {
49    Logger.i(TAG, `AdsUIExtensionAbility test onForeground`);
50  }
51
52  onBackground() {
53    Logger.i(TAG, `AdsUIExtensionAbility test onBackground`);
54  }
55
56  onDestroy() {
57    Logger.i(TAG, `AdsUIExtensionAbility test onDestroy`);
58  }
59}