• 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';
20import { BusinessError } from '@ohos.base';
21
22const PAGE_CA_INSTALL = 5;
23const TAG = 'CertPickerUiExtAbility';
24
25export default class CertPickerUiExtAbility extends UIExtensionAbility {
26  onCreate(): void {
27    console.info('[CertManager] CertPickerUiExtAbility onCreate');
28  }
29
30  onDestroy(): void {
31    console.info('[CertManager] CertPickerUiExtAbility onDestroy');
32  }
33
34  onSessionCreate(want: Want, session: UIExtensionContentSession): void {
35    console.info('[CertManager] CertPickerUiExtAbility onSessionCreate');
36
37    if (want === null || want === undefined) {
38      console.error('[CertManager] invalid want param');
39      return;
40    }
41    let param: Record<string, Object> = {
42      'session': session,
43      'want': want
44    }
45    let storage: LocalStorage = new LocalStorage(param);
46    try {
47      if (this.isStartToInstall(want.parameters)) {
48        session.loadContent('pages/CertificateInstallPage', storage);
49      } else {
50        session.loadContent('pages/picker/CertManagerSheetFa', storage);
51        let pwdStore = new PwdStore();
52        GlobalContext.getContext().setPwdStore(pwdStore);
53        GlobalContext.getContext().setAbilityWant(want);
54      }
55    } catch (err) {
56      let error = err as BusinessError;
57      console.error(TAG, `onSessionCreat load content failed: ${error?.code}, msg:${error?.message}`);
58      session.terminateSelf();
59      return;
60    }
61
62    try {
63      session.setWindowBackgroundColor('#00000000');
64    } catch (err) {
65      console.error('[CertManager] CertPickerUiExtAbility setWindowBackgroundColor');
66    }
67  }
68
69  private isStartToInstall(parameters: Record<string, Object> | undefined): boolean {
70    if(parameters === undefined) {
71      return false;
72    }
73    return parameters['pageType'] === PAGE_CA_INSTALL;
74  }
75  onSessionDestroy(): void {
76    // Main window is destroyed, release UI related resources
77    GlobalContext.getContext().clearSession();
78    console.info('[CertManager] CertPickerUiExtAbility onSessionDestroy');
79  }
80
81  onForeground(): void {
82    // Ability has brought to foreground
83    console.info('[CertManager] CertPickerUiExtAbility onForeground');
84  }
85
86  onBackground(): void {
87    // Ability has back to background
88    console.info('[CertManager] CertPickerUiExtAbility onBackground');
89  }
90}
91