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