• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 */
15
16import Want from '@ohos.app.ability.Want';
17import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession';
18import { GlobalContext, PwdStore } from '../common/GlobalContext';
19import UIExtensionAbility from '@ohos.app.ability.UIExtensionAbility';
20
21export default class MainExtensionAbility extends UIExtensionAbility {
22  onCreate(): void {
23    console.info('[CertManager] MainExtensionAbility onCreate');
24  }
25
26  onDestroy(): void {
27    console.info('[CertManager] MainExtensionAbility onDestroy');
28  }
29
30  onSessionCreate(want: Want, session: UIExtensionContentSession): void {
31    console.info('[CertManager] MainExtensionAbility onSessionCreate');
32
33    if (want === null || want === undefined) {
34      console.error('[CertManager] invalid want param');
35      return;
36    }
37    let param: Record<string, Object> = {
38      'session': session,
39      'want': want
40    }
41    let storage: LocalStorage = new LocalStorage(param);
42    let pullType: string = want.parameters.pullType as string;
43
44    if (pullType === 'systemCredInstall' || pullType === 'specifyInstall') {
45      session.loadContent('pages/certInstallFromStorage', storage);
46    } else {
47      session.loadContent('pages/certManagerFa', storage);
48    }
49    GlobalContext.getContext().setAbilityWant(want);
50    GlobalContext.getContext().setSession(session);
51    let pwdStore = new PwdStore();
52    GlobalContext.getContext().setPwdStore(pwdStore);
53    GlobalContext.getContext().setFlag(true);
54  }
55
56  onSessionDestroy(): void {
57    // Main window is destroyed, release UI related resources
58    GlobalContext.getContext().clearSession();
59    console.info('[CertManager] MainExtensionAbility onSessionDestroy');
60  }
61
62  onForeground(): void {
63    // Ability has brought to foreground
64    console.info('[CertManager] MainExtensionAbility onForeground');
65  }
66
67  onBackground(): void {
68    // Ability has back to background
69    console.info('[CertManager] MainExtensionAbility onBackground');
70  }
71}
72