• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * Copyright (c) 2024-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 { WidthPercent } from '../../common/util/ConfigData';
17import { CertificateComponent } from '../certManagerFa';
18import { NavEntryKey } from '../../common/NavEntryKey';
19import { CaCertPage } from './CaCertPage';
20import { CredListPage } from './CredListPage';
21import { InstallPage } from './InstallPage';
22import { CaSystemDetailPage } from './CaSystemDetailPage';
23import { CaUserDetailPage } from './CaUserDetailPage';
24import { CredSystemDetailPage } from './CredSystemDetailPage';
25import { CredUserDetailPage } from './CredUserDetailPage';
26import { AuthorizedAppManagementPage } from './AuthorizedAppManagementPage';
27import { CredPwdInputPage } from './CredPwdInputPage';
28import Want from '@ohos.app.ability.Want';
29import deviceInfo from '@ohos.deviceInfo';
30import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession';
31import { TrustedEvidence } from '../trustedCa';
32import { evidenceList } from '../cerEvidenceFa';
33import { CertInstallFromStorage } from '../certInstallFromStorage';
34
35const TAG: string = 'CertManagerSheetFa';
36
37let storage = LocalStorage.getShared();
38
39const PAGE_MAIN: number = 1;
40const PAGE_CA_CERTIFICATE: number = 2;
41const PAGE_CREDENTIAL: number = 3;
42const PAGE_INSTALL_CERTIFICATE: number = 4;
43const PAGE_TYPE: string = 'pageType';
44
45@Entry(storage)
46@Component
47export struct CertManagerSheetFa {
48  private session: UIExtensionContentSession =
49    storage.get<UIExtensionContentSession>('session') as UIExtensionContentSession;
50  private want: Want = storage.get<Want>('want') as Want;
51
52  @State private stack: NavPathStack = new NavPathStack();
53
54  @State private pageType: number = PAGE_MAIN;
55
56  aboutToAppear(): void {
57    const parameters = this.want?.parameters;
58    if (parameters === undefined || parameters[PAGE_TYPE] === undefined) {
59      console.warn(TAG + 'page type param is undefined');
60      return;
61    }
62    this.pageType = parameters[PAGE_TYPE] as number;
63    console.log(TAG + 'page type = ' + this.pageType);
64  }
65
66  @Builder
67  private routerMap(name: string, param?: Object) {
68    if (name === NavEntryKey.CA_CERTIFICATE_ENTRY) {
69      CaCertPage()
70    } else if (name === NavEntryKey.CREDENTIAL_LIST_ENTRY) {
71      CredListPage()
72    } else if (name === NavEntryKey.INSTALL_ENTRY) {
73      InstallPage()
74    } else if (name === NavEntryKey.CA_SYSTEM_DETAIL_ENTRY) {
75      CaSystemDetailPage()
76    } else if (name === NavEntryKey.CA_USER_DETAIL_ENTRY) {
77      CaUserDetailPage()
78    } else if (name === NavEntryKey.CRED_SYSTEM_DETAIL_ENTRY) {
79      CredSystemDetailPage()
80    } else if (name === NavEntryKey.CRED_USER_DETAIL_ENTRY) {
81      CredUserDetailPage()
82    } else if (name === NavEntryKey.AUTHORIZED_APP_ENTRY) {
83      AuthorizedAppManagementPage()
84    } else if (name === NavEntryKey.CRED_PWD_INPUT_ENTRY) {
85      CredPwdInputPage({
86        sheetSession: this.session
87      })
88    }
89  }
90
91  build() {
92    Column() {
93    }
94    .width(WidthPercent.WH_100_100)
95    .height(WidthPercent.WH_100_100)
96    .bindSheet(true, this.buildContent(), {
97      height: SheetSize.FIT_CONTENT,
98      preferType: ['2in1', 'tablet'].includes(deviceInfo.deviceType) ? SheetType.CENTER : null,
99      showClose: true,
100      shouldDismiss: ((sheetDismiss: SheetDismiss) => {
101        sheetDismiss.dismiss();
102        this.session?.sendData({'action': 'exit'})
103      })
104    })
105  }
106
107  @Builder
108  private buildContent() {
109    Navigation(this.stack) {
110      if (this.pageType === PAGE_CA_CERTIFICATE) {
111        this.buildCaCertPage()
112      } else if (this.pageType === PAGE_CREDENTIAL) {
113        this.buildCredListPage()
114      } else if (this.pageType === PAGE_INSTALL_CERTIFICATE) {
115        this.buildInstallPage()
116      } else {
117        this.buildHomePage()
118      }
119    }
120    .hideTitleBar(true)
121    .titleMode(NavigationTitleMode.Mini)
122    .mode(NavigationMode.Stack)
123    .navDestination(this.routerMap)
124    .width(WidthPercent.WH_100_100)
125    .height(WidthPercent.WH_100_100)
126    .backgroundColor($r('sys.color.background_secondary'))
127  }
128
129  @Builder
130  private buildHomePage() {
131    Column() {
132      CertificateComponent({
133        isStartBySheet: true,
134        selected: (path) => {
135          if (path === undefined || path === null || path.length === 0) {
136            console.warn(TAG + 'buildHomePage, empty path');
137            return;
138          }
139          this.stack.pushPath(new NavPathInfo(path, ''));
140        }
141      })
142    }
143    .width(WidthPercent.WH_100_100)
144    .height(WidthPercent.WH_100_100)
145  }
146
147  @Builder
148  private buildCaCertPage() {
149    Column() {
150      TrustedEvidence({
151        isStartBySheetFirst: true,
152        isStartBySheet: true,
153        selected: (path, param) => {
154          if (path === undefined || path === null || path.length === 0) {
155            console.warn(TAG + 'buildCaCertPage, empty path');
156            return;
157          }
158          if (path === NavEntryKey.POP) {
159            this.stack?.pop();
160          } else {
161            this.stack?.pushPath(new NavPathInfo(path, param));
162          }
163        }
164      })
165    }
166    .width(WidthPercent.WH_100_100)
167    .height(WidthPercent.WH_100_100)
168  }
169
170  @Builder
171  private buildCredListPage() {
172    Column() {
173      evidenceList({
174        isStartBySheetFirst: true,
175        isStartBySheet: true,
176        selected: (path, param) => {
177          if (path === undefined || path === null || path.length === 0) {
178            console.warn(TAG + 'buildCredListPage, empty path');
179            return;
180          }
181          if (path === NavEntryKey.POP) {
182            this.stack?.pop();
183          } else {
184            this.stack?.pushPath(new NavPathInfo(path, param));
185          }
186        }
187      })
188    }
189    .width(WidthPercent.WH_100_100)
190    .height(WidthPercent.WH_100_100)
191  }
192
193  @Builder
194  private buildInstallPage() {
195    Column() {
196      CertInstallFromStorage({
197        isStartBySheetFirst: true,
198        isStartBySheet: true,
199        selected: (path, param) => {
200          if (path === undefined || path === null || path.length === 0) {
201            console.warn(TAG + 'buildInstallPage, empty path');
202            return;
203          }
204          if (path === NavEntryKey.POP) {
205            this.stack?.pop();
206          } else {
207            this.stack?.pushPath(new NavPathInfo(path, param));
208          }
209        }
210      })
211    }
212    .width(WidthPercent.WH_100_100)
213    .height(WidthPercent.WH_100_100)
214  }
215}