From b948d60389c92a91130940415c8c4ad89d6a99b4 Mon Sep 17 00:00:00 2001 From: deng-bingcong Date: Thu, 7 Sep 2023 10:20:18 +0800 Subject: [PATCH] =?UTF-8?q?ArkTs=E8=AF=AD=E6=B3=95=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: deng-bingcong --- .../src/main/ets/MainAbility/MainAbility.ts | 28 +- .../src/main/ets/common/GlobalContext.ts | 75 +++ .../ets/common/component/headComponent.ets | 17 +- .../common/component/subEntryComponent.ets | 38 +- .../phone/src/main/ets/model/BundleModel.ets | 15 +- .../ets/model/CertManagerVo/AppInfoVo.ets | 19 + .../ets/model/CertManagerVo/CertInfoVo.ets | 8 +- .../ets/model/CertManagerVo/CredentialVo.ets | 2 +- .../src/main/ets/model/CertMangerModel.ets | 444 ++++++++++-------- .../phone/src/main/ets/model/FileIoModel.ets | 12 +- .../src/main/ets/pages/cerEvidenceFa.ets | 129 +++-- .../main/ets/pages/certInstallAliasInput.ets | 11 +- .../src/main/ets/pages/certManagerFa.ets | 59 ++- .../phone/src/main/ets/pages/certPwdInput.ets | 9 +- .../phone/src/main/ets/pages/requestAuth.ets | 28 +- .../phone/src/main/ets/pages/trustedCa.ets | 176 ++++--- .../ets/presenter/CmAppCredAuthPresenter.ets | 60 ++- .../src/main/ets/presenter/CmFaPresenter.ets | 22 +- .../main/ets/presenter/CmInstallPresenter.ets | 18 +- .../ets/presenter/CmShowAppCredPresenter.ets | 47 +- .../presenter/CmShowPrivateCredPresenter.ets | 18 +- .../ets/presenter/CmShowSysCaPresenter.ets | 29 +- .../ets/presenter/CmShowUserCaPresenter.ets | 34 +- 23 files changed, 806 insertions(+), 492 deletions(-) create mode 100755 CertificateManager/product/phone/src/main/ets/common/GlobalContext.ts create mode 100755 CertificateManager/product/phone/src/main/ets/model/CertManagerVo/AppInfoVo.ets diff --git a/CertificateManager/product/phone/src/main/ets/MainAbility/MainAbility.ts b/CertificateManager/product/phone/src/main/ets/MainAbility/MainAbility.ts index 208863a..e7fca88 100644 --- a/CertificateManager/product/phone/src/main/ets/MainAbility/MainAbility.ts +++ b/CertificateManager/product/phone/src/main/ets/MainAbility/MainAbility.ts @@ -16,31 +16,15 @@ import Ability from '@ohos.app.ability.UIAbility'; import type Want from '@ohos.app.ability.Want'; import type Window from '@ohos.window'; -import type UIAbilityContext from 'application/UIAbilityContext'; - -class PwdStore { - private certPwd: string = ''; - setCertPwd(pwd: string): void { - this.certPwd = pwd; - } - - getCertPwd(): string { - return this.certPwd; - } - - clearCertPwd(): void { - this.certPwd = ''; - } -} +import { GlobalContext, PwdStore } from '../common/GlobalContext'; export default class MainAbility extends Ability { onCreate(want: Want, launchParam): void { console.log('[Demo] MainAbility onCreate'); - let context: UIAbilityContext = this.context; - globalThis.certManagerAbilityContext = context; - globalThis.PwdStore = new PwdStore(); - globalThis.abilityWant = want; - globalThis.abilityContext = context; + let pwdStore = new PwdStore(); + GlobalContext.getContext().setCmContext(this.context); + GlobalContext.getContext().setPwdStore(pwdStore); + GlobalContext.getContext().setAbilityWant(want); } onDestroy(): void { @@ -75,6 +59,6 @@ export default class MainAbility extends Ability { onNewWant(want: Want): void { console.log('[Demo] MainAbility onNewWant'); - globalThis.abilityWant = want; + GlobalContext.getContext().setAbilityWant(want); } }; diff --git a/CertificateManager/product/phone/src/main/ets/common/GlobalContext.ts b/CertificateManager/product/phone/src/main/ets/common/GlobalContext.ts new file mode 100755 index 0000000..f653a4a --- /dev/null +++ b/CertificateManager/product/phone/src/main/ets/common/GlobalContext.ts @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import type Want from '@ohos.app.ability.Want'; +import type UIAbilityContext from 'application/UIAbilityContext'; + +export class PwdStore { + private certPwd: string = ''; + setCertPwd(pwd: string): void { + this.certPwd = pwd; + } + + getCertPwd(): string { + return this.certPwd; + } + + clearCertPwd(): void { + this.certPwd = ''; + } +} + +export class GlobalContext { + private constructor() {}; + private static instance: GlobalContext; + private context: UIAbilityContext; + private want: Want; + private pwdStore: PwdStore; + + public static getContext(): GlobalContext { + if (!GlobalContext.instance) { + GlobalContext.instance = new GlobalContext(); + } + return GlobalContext.instance; + } + + getCmContext(): UIAbilityContext { + return this.context; + } + + getPwdStore(): PwdStore { + return this.pwdStore; + } + + getAbilityWant(): Want { + return this.want; + } + + setCmContext(context: UIAbilityContext): void { + this.context = context; + } + + setPwdStore(pwdStore: PwdStore): void { + this.pwdStore = pwdStore; + } + + setAbilityWant(want: Want): void { + this.want = want; + } + + clearAbilityWantUri(): void { + this.want.uri = ''; + } +} \ No newline at end of file diff --git a/CertificateManager/product/phone/src/main/ets/common/component/headComponent.ets b/CertificateManager/product/phone/src/main/ets/common/component/headComponent.ets index 128bf3b..e15e5c0 100644 --- a/CertificateManager/product/phone/src/main/ets/common/component/headComponent.ets +++ b/CertificateManager/product/phone/src/main/ets/common/component/headComponent.ets @@ -14,6 +14,7 @@ */ import ComponentConfig from './ComponentConfig'; import Router from '@system.router'; +import { GlobalContext } from '../GlobalContext'; const TAG = "CertManager HeadComponent: "; @@ -40,14 +41,16 @@ export default struct HeadComponent { .onClick(() => { let length = Router.getLength(); console.log(TAG + "router length: " + Number(length)); - Number(length) == 1 ? globalThis.certManagerAbilityContext.terminateSelf() : Router.back(); + Number(length) == 1 ? GlobalContext.getContext().getCmContext().terminateSelf() : Router.back(); }) - .onTouch((event: TouchEvent) => { - if (event.type === TouchType.Down) { - this.isTouch = true; - } - if (event.type === TouchType.Up) { - this.isTouch = false; + .onTouch((event?: TouchEvent) => { + if (event !== undefined) { + if (event.type === TouchType.Down) { + this.isTouch = true; + } + if (event.type === TouchType.Up) { + this.isTouch = false; + } } }); diff --git a/CertificateManager/product/phone/src/main/ets/common/component/subEntryComponent.ets b/CertificateManager/product/phone/src/main/ets/common/component/subEntryComponent.ets index 1deb43d..b3fe50e 100644 --- a/CertificateManager/product/phone/src/main/ets/common/component/subEntryComponent.ets +++ b/CertificateManager/product/phone/src/main/ets/common/component/subEntryComponent.ets @@ -19,8 +19,8 @@ import ComponentConfig from './ComponentConfig'; */ @Component export struct SubEntryComponent { - private targetPage: string; - private title: string | Resource; + private targetPage: string = ''; + private title: string | Resource = ''; @State isTouched: boolean = false; build() { @@ -55,12 +55,14 @@ export struct SubEntryComponent { direction: GradientDirection.Right, colors: [[$r("sys.color.ohos_id_color_foreground_contrary"), 1], [$r("sys.color.ohos_id_color_foreground_contrary"), 1]] }) - .onTouch((event: TouchEvent) => { - if (event.type === TouchType.Down) { - this.isTouched = true; - } - if (event.type === TouchType.Up) { - this.isTouched = false; + .onTouch((event?: TouchEvent) => { + if (event !== undefined) { + if (event.type === TouchType.Down) { + this.isTouched = true; + } + if (event.type === TouchType.Up) { + this.isTouched = false; + } } }) } @@ -76,9 +78,9 @@ export struct SubEntryComponent { @Component export struct SubEntryComponentWithEndText { @State isTouched: boolean = false; - @Prop endText: string; - private targetPage: string; - private title: string | Resource; + @Prop endText: string = ''; + private targetPage: string = ''; + private title: string | Resource = ''; build() { Navigator({ target: this.targetPage }) { @@ -121,12 +123,14 @@ export struct SubEntryComponentWithEndText { direction: GradientDirection.Right, colors: [[$r("sys.color.ohos_id_color_foreground_contrary"), 1], [$r("sys.color.ohos_id_color_foreground_contrary"), 1]] }) - .onTouch((event: TouchEvent) => { - if (event.type === TouchType.Down) { - this.isTouched = true; - } - if (event.type === TouchType.Up) { - this.isTouched = false; + .onTouch((event?: TouchEvent) => { + if (event !== undefined) { + if (event.type === TouchType.Down) { + this.isTouched = true; + } + if (event.type === TouchType.Up) { + this.isTouched = false; + } } }); } diff --git a/CertificateManager/product/phone/src/main/ets/model/BundleModel.ets b/CertificateManager/product/phone/src/main/ets/model/BundleModel.ets index 3aaba48..178845a 100644 --- a/CertificateManager/product/phone/src/main/ets/model/BundleModel.ets +++ b/CertificateManager/product/phone/src/main/ets/model/BundleModel.ets @@ -15,14 +15,18 @@ import bundleManager from '@ohos.bundle.bundleManager'; import { CMModelErrorCode } from '../model/CertMangerModel'; +import { GlobalContext } from '../common/GlobalContext'; +import { AppInfoVo } from './CertManagerVo/AppInfoVo'; +import { BusinessError } from '@ohos.base'; +import Common from '@ohos.app.ability.common' const TAG = 'certManager BUNDLE:'; export class BundleNameModel { - async getAppInfoList(appUid, callback): Promise { + async getAppInfoList(appUid: number, callback: Function): Promise { console.log(TAG + 'getAppInfoList enter uid: ' + appUid); try { - let appInfo = { + let appInfo: AppInfoVo = { appImage: '', appName: '', }; @@ -30,7 +34,7 @@ export class BundleNameModel { let appBundleName = await bundleManager.getBundleNameByUid(appUid); console.log(TAG + 'appBundleName: ' + appBundleName); - let bundleContext = globalThis.certManagerAbilityContext.createBundleContext(appBundleName); + let bundleContext: Common.Context = GlobalContext.getContext().getCmContext().createBundleContext(appBundleName); let info = await bundleManager.getBundleInfo(appBundleName, bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION); console.log(TAG + 'appName: ' + appBundleName + ', iconId: ' + info.appInfo.iconId + @@ -42,8 +46,9 @@ export class BundleNameModel { callback(CMModelErrorCode.CM_MODEL_ERROR_SUCCESS, appInfo); } catch (err) { - console.error(TAG + 'getAppInfoList failed', JSON.stringify(err.code)); - callback(CMModelErrorCode.CM_MODEL_ERROR_EXCEPTION, null); + let e: BusinessError = err as BusinessError; + console.error(TAG + 'getAppInfoList failed, message: ' + e.message + ', code: ' + e.code); + callback(CMModelErrorCode.CM_MODEL_ERROR_EXCEPTION, undefined); } } } diff --git a/CertificateManager/product/phone/src/main/ets/model/CertManagerVo/AppInfoVo.ets b/CertificateManager/product/phone/src/main/ets/model/CertManagerVo/AppInfoVo.ets new file mode 100755 index 0000000..d0b5568 --- /dev/null +++ b/CertificateManager/product/phone/src/main/ets/model/CertManagerVo/AppInfoVo.ets @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export class AppInfoVo { + appImage: string = ''; + appName: string = ''; +} \ No newline at end of file diff --git a/CertificateManager/product/phone/src/main/ets/model/CertManagerVo/CertInfoVo.ets b/CertificateManager/product/phone/src/main/ets/model/CertManagerVo/CertInfoVo.ets index 7bbb34e..c3af9e2 100644 --- a/CertificateManager/product/phone/src/main/ets/model/CertManagerVo/CertInfoVo.ets +++ b/CertificateManager/product/phone/src/main/ets/model/CertManagerVo/CertInfoVo.ets @@ -67,10 +67,10 @@ export class CertInfoVo { this.notBefore = ''; this.notAfter = ''; this.fingerprintSha256 = ''; - this.cert = null; - this.subjectNameMap = null; - this.issuerNameMap = null; - this.dateMap = null; + this.cert = new Uint8Array(); + this.subjectNameMap.clear(); + this.issuerNameMap.clear(); + this.dateMap.clear(); } } \ No newline at end of file diff --git a/CertificateManager/product/phone/src/main/ets/model/CertManagerVo/CredentialVo.ets b/CertificateManager/product/phone/src/main/ets/model/CertManagerVo/CredentialVo.ets index fd74eb8..6e5e7eb 100644 --- a/CertificateManager/product/phone/src/main/ets/model/CertManagerVo/CredentialVo.ets +++ b/CertificateManager/product/phone/src/main/ets/model/CertManagerVo/CredentialVo.ets @@ -36,7 +36,7 @@ export class CredentialVo { this.keyUri = ''; this.certNum = 0; this.keyNum = 0; - this.credData = null; + this.credData = new Uint8Array(); } } \ No newline at end of file diff --git a/CertificateManager/product/phone/src/main/ets/model/CertMangerModel.ets b/CertificateManager/product/phone/src/main/ets/model/CertMangerModel.ets index ae3bb9e..4021b75 100644 --- a/CertificateManager/product/phone/src/main/ets/model/CertMangerModel.ets +++ b/CertificateManager/product/phone/src/main/ets/model/CertMangerModel.ets @@ -17,7 +17,7 @@ import { CertAbstractVo } from './CertManagerVo/CertAbstractVo'; import { CertInfoVo } from './CertManagerVo/CertInfoVo'; import { CredentialAbstractVo } from './CertManagerVo/CredentialAbstractVo'; import { CredentialVo } from './CertManagerVo/CredentialVo'; - +import { BusinessError } from '@ohos.base'; import CertManager from '@ohos.security.certManager'; const TAG = 'CertManager Model: '; @@ -50,78 +50,78 @@ export enum CertManagerStore { } export class CertMangerModel { - getCertOrCredList(optType, callback): void { + getCertOrCredList(optType: CMModelOptType, callback: Function): void { console.log(TAG + 'getCertOrCredList start'); switch (optType) { case CMModelOptType.CM_MODEL_OPT_SYSTEM_CA: - this.getSystemTrustedCertificateList((errCode, certList) => { + this.getSystemTrustedCertificateList((errCode:CMModelErrorCode, certList: Array) => { callback(errCode, certList); }); break; case CMModelOptType.CM_MODEL_OPT_USER_CA: - this.getUserTrustedCertificateList((errCode, certList) => { + this.getUserTrustedCertificateList((errCode: CMModelErrorCode, certList: Array) => { callback(errCode, certList); }); break; case CMModelOptType.CM_MODEL_OPT_APP_CRED: - this.getAppCredList((errCode, credList) => { + this.getAppCredList((errCode: CMModelErrorCode, credList: Array) => { callback(errCode, credList); }); break; case CMModelOptType.CM_MODEL_OPT_PRIVATE_CRED: - this.getPrivateCredList((errCode, credList) => { + this.getPrivateCredList((errCode: CMModelErrorCode, credList: Array) => { callback(errCode, credList); }); break; default: - callback(CMModelErrorCode.CM_MODEL_ERROR_UNKNOWN_OPT, null); + callback(CMModelErrorCode.CM_MODEL_ERROR_UNKNOWN_OPT, undefined); break; } } - getCertOrCred(optType, uri, callback): void { + getCertOrCred(optType: CMModelOptType, uri: string, callback: Function): void { console.log(TAG + 'getCertOrCred start'); switch (optType) { case CMModelOptType.CM_MODEL_OPT_SYSTEM_CA: - this.getSystemTrustedCertificate(uri, (errCode, certInfo) => { + this.getSystemTrustedCertificate(uri, (errCode: CMModelErrorCode, certInfo: CertInfoVo) => { console.info('getSystemTrustedCertificate certInfo is' + JSON.stringify(certInfo)); callback(errCode, certInfo); }); break; case CMModelOptType.CM_MODEL_OPT_USER_CA: - this.getUserTrustedCertificate(uri, (errCode, certInfo) => { + this.getUserTrustedCertificate(uri, (errCode: CMModelErrorCode, certInfo: CertInfoVo) => { callback(errCode, certInfo); }); break; case CMModelOptType.CM_MODEL_OPT_APP_CRED: - this.getAppCredential(uri, (errCode, credInfo) => { + this.getAppCredential(uri, (errCode: CMModelErrorCode, credInfo: CredentialVo) => { callback(errCode, credInfo); }); break; case CMModelOptType.CM_MODEL_OPT_PRIVATE_CRED: - this.getPrivateCred(uri, (errCode, credInfo) => { + this.getPrivateCred(uri, (errCode: CMModelErrorCode, credInfo: CredentialVo) => { callback(errCode, credInfo); }); break; default: - callback(CMModelErrorCode.CM_MODEL_ERROR_UNKNOWN_OPT, null); + callback(CMModelErrorCode.CM_MODEL_ERROR_UNKNOWN_OPT, undefined); break; } } - deleteCertOrCred(optType, uri, callback): void { + deleteCertOrCred(optType: CMModelOptType, uri: string, callback: Function): void { console.log(TAG + 'deleteCertOrCred start'); switch (optType) { case CMModelOptType.CM_MODEL_OPT_USER_CA: - this.deleteUserTrustedCertificate(uri, (errCode) => { + this.deleteUserTrustedCertificate(uri, (errCode: CMModelErrorCode) => { callback(errCode); }); break; case CMModelOptType.CM_MODEL_OPT_APP_CRED: - this.deleteAppCredential(uri, (errCode) => { + this.deleteAppCredential(uri, (errCode: CMModelErrorCode) => { callback(errCode); }); break; @@ -135,17 +135,19 @@ export class CertMangerModel { } } - setCertStatus(optType, uri, status, callback): void { + setCertStatus(optType: CMModelOptType, uri: string, status: boolean, callback: Function): void { console.log(TAG + 'setCertStatus start'); switch (optType) { case CMModelOptType.CM_MODEL_OPT_USER_CA: - this.setCertificateStatus(uri, CertManagerStore.CERT_MANAGER_USER_TRUSTED_STORE, status, (errCode) => { + this.setCertificateStatus(uri, CertManagerStore.CERT_MANAGER_USER_TRUSTED_STORE, status, + (errCode: CMModelErrorCode) => { callback(errCode); }); break; case CMModelOptType.CM_MODEL_OPT_SYSTEM_CA: - this.setCertificateStatus(uri, CertManagerStore.CERT_MANAGER_SYSTEM_TRUSTED_STORE, status, (errCode) => { + this.setCertificateStatus(uri, CertManagerStore.CERT_MANAGER_SYSTEM_TRUSTED_STORE, status, + (errCode: CMModelErrorCode) => { callback(errCode); }); break; @@ -159,17 +161,17 @@ export class CertMangerModel { } } - delAllCertOrCred(optType, callback): void { + delAllCertOrCred(optType: CMModelOptType, callback: Function): void { console.log(TAG + 'delAllCertOrCred start'); switch (optType) { case CMModelOptType.CM_MODEL_OPT_USER_CA: - this.delAllUserCertificate((errCode) => { + this.delAllUserCertificate((errCode: CMModelErrorCode) => { callback(errCode); }); break; case CMModelOptType.CM_MODEL_OPT_APP_CRED: - this.delAllAppCredential((errCode) => { + this.delAllAppCredential((errCode: CMModelErrorCode) => { callback(errCode); }); break; @@ -183,12 +185,12 @@ export class CertMangerModel { } } - getAuthAppList(optType, uri, callback): void { + getAuthAppList(optType: CMModelOptType, uri: string, callback: Function): void { console.log(TAG + 'getAuthAppList start'); switch (optType) { case CMModelOptType.CM_MODEL_OPT_APP_CRED: - this.getAuthorizedAppList(uri, (errCode, appUidList) => { + this.getAuthorizedAppList(uri, (errCode: CMModelErrorCode, appUidList: Array) => { callback(errCode, appUidList); }); break; @@ -203,12 +205,12 @@ export class CertMangerModel { } } - setAppAuthPromise(optType, uri, appUid, status): Promise { + setAppAuthPromise(optType: CMModelOptType, uri: string, appUid: string, status: boolean): Promise { console.log(TAG + 'setAppAuth start'); switch (optType) { case CMModelOptType.CM_MODEL_OPT_APP_CRED: return new Promise((resolve, reject)=>{ - this.setAuthorizedAppStatus(uri, appUid, status, (errCode, data) => { + this.setAuthorizedAppStatus(uri, appUid, status, (errCode: CMModelErrorCode, data: string) => { if (errCode === CMModelErrorCode.CM_MODEL_ERROR_SUCCESS) { resolve(void(data)); } else { @@ -223,12 +225,12 @@ export class CertMangerModel { } } - setAppAuth(optType, uri, appUid, status, callback): void { + setAppAuth(optType: CMModelOptType, uri: string, appUid: string, status: boolean, callback: Function): void { console.log(TAG + 'setAppAuth start'); switch (optType) { case CMModelOptType.CM_MODEL_OPT_APP_CRED: - this.setAuthorizedAppStatus(uri, appUid, status, (errCode, data) => { + this.setAuthorizedAppStatus(uri, appUid, status, (errCode: CMModelErrorCode, data: string) => { callback(errCode, data); }); break; @@ -243,17 +245,17 @@ export class CertMangerModel { } } - installCertOrCred(optType, alias, data, pwd, callback): void { + installCertOrCred(optType: CMModelOptType, alias: string, data: Uint8Array, pwd: string, callback: Function): void { console.log(TAG + 'installCertOrCred start'); console.info(TAG + 'installCert optType: ' + optType + ',alias: ' + alias); switch (optType) { case CMModelOptType.CM_MODEL_OPT_USER_CA: - this.installUserCertificate(data, alias, (errCode) => { + this.installUserCertificate(data, alias, (errCode: CMModelErrorCode) => { callback(errCode); }); break; case CMModelOptType.CM_MODEL_OPT_APP_CRED: - this.installAppCertificate(data, alias, pwd, (errCode) => { + this.installAppCertificate(data, alias, pwd, (errCode: CMModelErrorCode) => { callback(errCode); }); break; @@ -267,292 +269,356 @@ export class CertMangerModel { } } - private async getSystemTrustedCertificateList(callback): Promise { + private async getSystemTrustedCertificateList(callback: Function): Promise { console.log(TAG + 'getSystemTrustedCertificateList start'); try { - let subjectNameCN; + let subjectNameCN: string = ''; let result = await CertManager.getSystemTrustedCertificateList(); - let certList = new Array(); - console.log(TAG + 'certManager::getSystemTrustedCertificateList result: ' + JSON.stringify(result)); - for (let i = 0; i < result.certList.length; i++) { - if (result.certList[i].subjectName.length !== 0) { - subjectNameCN = result.certList[i].subjectName.match(/(?<=CN=).*?(?=,)/g).toString(); - console.info('subjectNameCN is:' + subjectNameCN); + let certList: Array = new Array(); + let regex: RegExp = new RegExp("(?<=CN=).*?(?=,)", "g"); + if (result.certList !== undefined) { + console.log(TAG + 'certManager::getSystemTrustedCertificateList result: ' + JSON.stringify(result)); + for (let i = 0; i < result.certList.length; i++) { + if (result.certList[i].subjectName.length !== 0) { + let temp = result.certList[i].subjectName.match(regex); + subjectNameCN = (temp !== undefined) ? String(temp) : ''; + console.info('subjectNameCN is:' + subjectNameCN); + } + certList.push(new CertAbstractVo(String(result.certList[i].uri), String(result.certList[i].certAlias), + Boolean(result.certList[i].status), String(result.certList[i].subjectName), String(subjectNameCN))); } - certList.push(new CertAbstractVo(String(result.certList[i].uri), String(result.certList[i].certAlias), - Boolean(result.certList[i].status), String(result.certList[i].subjectName), String(subjectNameCN))); + console.log(TAG + 'getSystemTrustedCertificateList end'); + callback(CMModelErrorCode.CM_MODEL_ERROR_SUCCESS, certList); + } else { + console.error(TAG + 'getSystemTrustedCertificateList failed, undefined'); + callback(CMModelErrorCode.CM_MODEL_ERROR_FAILED, undefined); } - console.log(TAG + 'getSystemTrustedCertificateList end'); - callback(CMModelErrorCode.CM_MODEL_ERROR_SUCCESS, certList); - } catch (err) { - console.log(TAG + 'getSystemTrustedCertificateList err: ' + JSON.stringify(err)); - callback(CMModelErrorCode.CM_MODEL_ERROR_EXCEPTION, null); + let e: BusinessError = err as BusinessError; + console.error(TAG + 'getSystemTrustedCertificateList err, message: ' + e.message + ', code: ' + e.code); + callback(CMModelErrorCode.CM_MODEL_ERROR_EXCEPTION, undefined); } } - private async getSystemTrustedCertificate(certUri, callback): Promise { + private async getSystemTrustedCertificate(certUri: string, callback: Function): Promise { console.log(TAG + 'getSystemTrustedCertificate start'); try { let result = await CertManager.getSystemTrustedCertificate(certUri); let subjectNameMap: Map = new Map(); let issuerNameMap: Map = new Map(); let dateMap: Map = new Map(); - if (result.certInfo.subjectName.length !== 0) { - let subjectNameCN = result.certInfo.subjectName.match(/(?<=CN=).*?(?=,)/g); - console.info('subjectNameCN is:' + subjectNameCN); - let subjectNameOU = result.certInfo.subjectName.match(/(?<=OU=).*?(?=,)/g); - console.info('subjectNameOU is:' + subjectNameOU); - let subjectNameO = result.certInfo.subjectName.match(/(?<=O=).*/g); - console.info('subjectNameO is:' + subjectNameO); - subjectNameMap.set('常用名称:', String(subjectNameCN)); - subjectNameMap.set('组织:', String(subjectNameO)); - subjectNameMap.set('组织单位:', String(subjectNameOU)); - subjectNameMap.set('序列号:', String(result.certInfo.serial)); + let regex1: RegExp = new RegExp("(?<=CN=).*?(?=,)", "g"); + let regex2: RegExp = new RegExp("(?<=OU=).*?(?=,)", "g"); + let regex3: RegExp = new RegExp("(?<=O=).*", "g"); + + if (result.certInfo !== undefined) { + if (result.certInfo.subjectName.length !== 0) { + let subjectNameCN = result.certInfo.subjectName.match(regex1); + console.info('subjectNameCN is:' + subjectNameCN); + let subjectNameOU = result.certInfo.subjectName.match(regex2); + console.info('subjectNameOU is:' + subjectNameOU); + let subjectNameO = result.certInfo.subjectName.match(regex3); + console.info('subjectNameO is:' + subjectNameO); + subjectNameMap.set('常用名称:', String(subjectNameCN)); + subjectNameMap.set('组织:', String(subjectNameO)); + subjectNameMap.set('组织单位:', String(subjectNameOU)); + subjectNameMap.set('序列号:', String(result.certInfo.serial)); + } + if (result.certInfo.issuerName.length !== 0) { + let issuerNameCN = result.certInfo.issuerName.match(regex1); + console.info('issuerNameCN is:' + issuerNameCN); + let issuerNameOU = result.certInfo.issuerName.match(regex2); + console.info('issuerNameOU is:' + issuerNameOU); + let issuerNameO = result.certInfo.issuerName.match(regex3); + console.info('issuerNameO is:' + issuerNameO); + issuerNameMap.set('常用名称:', String(issuerNameCN)); + issuerNameMap.set('组织:', String(issuerNameO)); + issuerNameMap.set('组织单位:', String(issuerNameOU)); + } + dateMap.set('颁发时间:', String(result.certInfo.notBefore)); + dateMap.set('有效期至:', String(result.certInfo.notAfter)); + + let certData: Uint8Array = result.certInfo.cert; + let certInfo = new CertInfoVo(String(result.certInfo.uri), String(result.certInfo.certAlias), + Boolean(result.certInfo.status), String(result.certInfo.issuerName), String(result.certInfo.subjectName), + String(result.certInfo.serial), String(result.certInfo.notBefore), + String(result.certInfo.notAfter), String(result.certInfo.fingerprintSha256), + certData, subjectNameMap, issuerNameMap, dateMap); + console.log(TAG + 'getSystemTrustedCertificate end'); + callback(CMModelErrorCode.CM_MODEL_ERROR_SUCCESS, certInfo); + } else { + console.error(TAG + 'getSystemTrustedCertificate failed, undefined'); + callback(CMModelErrorCode.CM_MODEL_ERROR_FAILED, undefined); } - if (result.certInfo.issuerName.length !== 0) { - let issuerNameCN = result.certInfo.issuerName.match(/(?<=CN=).*?(?=,)/g); - console.info('issuerNameCN is:' + issuerNameCN); - let issuerNameOU = result.certInfo.issuerName.match(/(?<=OU=).*?(?=,)/g); - console.info('issuerNameOU is:' + issuerNameOU); - let issuerNameO = result.certInfo.issuerName.match(/(?<=O=).*/g); - console.info('issuerNameO is:' + issuerNameO); - issuerNameMap.set('常用名称:', String(issuerNameCN)); - issuerNameMap.set('组织:', String(issuerNameO)); - issuerNameMap.set('组织单位:', String(issuerNameOU)); - } - dateMap.set('颁发时间:', String(result.certInfo.notBefore)); - dateMap.set('有效期至:', String(result.certInfo.notAfter)); - - let certData:Uint8Array = result.certInfo.cert; - let certInfo = new CertInfoVo(String(result.certInfo.uri), String(result.certInfo.certAlias), - Boolean(result.certInfo.status), String(result.certInfo.issuerName), String(result.certInfo.subjectName), - String(result.certInfo.serial), String(result.certInfo.notBefore), - String(result.certInfo.notAfter), String(result.certInfo.fingerprintSha256), - certData, subjectNameMap, issuerNameMap, dateMap); - - console.log(TAG + 'getSystemTrustedCertificate end'); - callback(CMModelErrorCode.CM_MODEL_ERROR_SUCCESS, certInfo); - } catch (err) { - console.log(TAG + 'getSystemTrustedCertificate err: ' + JSON.stringify(err)); - callback(CMModelErrorCode.CM_MODEL_ERROR_EXCEPTION, null); + let e: BusinessError = err as BusinessError; + console.error(TAG + 'getSystemTrustedCertificate err, message: ' + e.message + ', code: ' + e.code); + callback(CMModelErrorCode.CM_MODEL_ERROR_EXCEPTION, undefined); } } - private async getUserTrustedCertificateList(callback): Promise { + private async getUserTrustedCertificateList(callback: Function): Promise { console.log(TAG + 'getUserTrustedCertificateList start'); try { - let subjectNameCN; + let subjectNameCN: string = ''; let result = await CertManager.getUserTrustedCertificateList(); - let certList = new Array(); - console.log(TAG + 'getUserTrustedCertificateList result: ' + JSON.stringify(result)); - for (let i = 0; i < result.certList.length; i++) { - if (result.certList[i].subjectName.length !== 0) { - subjectNameCN = result.certList[i].subjectName.match(/(?<=CN=).*?(?=,)/g).toString(); - console.info('subjectNameCN is:' + subjectNameCN); - } - if (String(result.certList[i].uri).indexOf('u=0;') === -1) { - certList.push(new CertAbstractVo(String(result.certList[i].uri), String(result.certList[i].certAlias), - Boolean(result.certList[i].status), String(result.certList[i].subjectName), String(subjectNameCN))); + let certList: Array = new Array(); + let regex: RegExp = new RegExp("(?<=CN=).*?(?=,)", "g"); + if (result.certList !== undefined) { + console.log(TAG + 'getUserTrustedCertificateList result: ' + JSON.stringify(result)); + for (let i = 0; i < result.certList.length; i++) { + if (result.certList[i].subjectName.length !== 0) { + let temp = result.certList[i].subjectName.match(regex); + subjectNameCN = (temp !== undefined) ? String(temp) : ''; + console.info('subjectNameCN is:' + subjectNameCN); + } + if (String(result.certList[i].uri).indexOf('u=0;') === -1) { + certList.push(new CertAbstractVo(String(result.certList[i].uri), String(result.certList[i].certAlias), + Boolean(result.certList[i].status), String(result.certList[i].subjectName), String(subjectNameCN))); + } } + console.log(TAG + 'getUserTrustedCertificateList end'); + callback(CMModelErrorCode.CM_MODEL_ERROR_SUCCESS, certList); + } else { + console.error(TAG + 'getUserTrustedCertificateList failed, undefined'); + callback(CMModelErrorCode.CM_MODEL_ERROR_FAILED, undefined); } - console.log(TAG + 'getUserTrustedCertificateList end'); - callback(CMModelErrorCode.CM_MODEL_ERROR_SUCCESS, certList); } catch (err) { - console.log(TAG + 'getUserTrustedCertificateList err: ' + JSON.stringify(err)); + let e: BusinessError = err as BusinessError; + console.error(TAG + 'getUserTrustedCertificateList err, message: ' + e.message + ', code: ' + e.code); callback(CMModelErrorCode.CM_MODEL_ERROR_EXCEPTION); } } - private async getUserTrustedCertificate(certUri, callback): Promise { + private async getUserTrustedCertificate(certUri: string, callback: Function): Promise { console.log(TAG + 'getUserTrustedCertificate start'); try { let result = await CertManager.getUserTrustedCertificate(certUri); let subjectNameMap: Map = new Map(); let issuerNameMap: Map = new Map(); let dateMap: Map = new Map(); + let regex1: RegExp = new RegExp("(?<=CN=).*?(?=,)", "g"); + let regex2: RegExp = new RegExp("(?<=OU=).*?(?=,)", "g"); + let regex3: RegExp = new RegExp("(?<=O=).*", "g"); - if (result.certInfo.subjectName.length !== 0) { - let subjectNameCN = result.certInfo.subjectName.match(/(?<=CN=).*?(?=,)/g); - console.info('subjectNameCN is:' + subjectNameCN); - let subjectNameOU = result.certInfo.subjectName.match(/(?<=OU=).*?(?=,)/g); - console.info('subjectNameOU is:' + subjectNameOU); - let subjectNameO = result.certInfo.subjectName.match(/(?<=O=).*/g); - console.info('SubjectNameO is:' + subjectNameO); - subjectNameMap.set('常用名称:', String(subjectNameCN)); - subjectNameMap.set('组织:', String(subjectNameO)); - subjectNameMap.set('组织单位:', String(subjectNameOU)); - subjectNameMap.set('序列号:', String(result.certInfo.serial)); + if (result.certInfo !== undefined) { + if (result.certInfo.subjectName.length !== 0) { + let subjectNameCN = result.certInfo.subjectName.match(regex1); + console.info('subjectNameCN is:' + subjectNameCN); + let subjectNameOU = result.certInfo.subjectName.match(regex2); + console.info('subjectNameOU is:' + subjectNameOU); + let subjectNameO = result.certInfo.subjectName.match(regex3); + console.info('SubjectNameO is:' + subjectNameO); + subjectNameMap.set('常用名称:', String(subjectNameCN)); + subjectNameMap.set('组织:', String(subjectNameO)); + subjectNameMap.set('组织单位:', String(subjectNameOU)); + subjectNameMap.set('序列号:', String(result.certInfo.serial)); + } + if (result.certInfo.issuerName.length !== 0) { + let issuerNameCN = result.certInfo.issuerName.match(regex1); + console.info('issuerNameCN is:' + issuerNameCN); + let issuerNameOU = result.certInfo.issuerName.match(regex2); + console.info('issuerNameOU is:' + issuerNameOU); + let issuerNameO = result.certInfo.issuerName.match(regex3); + console.info('issuerNameO is:' + issuerNameO); + issuerNameMap.set('常用名称:', String(issuerNameCN)); + issuerNameMap.set('组织:', String(issuerNameO)); + issuerNameMap.set('组织单位:', String(issuerNameOU)); + } + dateMap.set('颁发时间:', String(result.certInfo.notBefore)); + dateMap.set('有效期至:', String(result.certInfo.notAfter)); + let certData:Uint8Array = result.certInfo.cert; + let certInfo = new CertInfoVo(String(result.certInfo.uri), String(result.certInfo.certAlias), + Boolean(result.certInfo.status), String(result.certInfo.issuerName), String(result.certInfo.subjectName), + String(result.certInfo.serial), String(result.certInfo.notBefore), + String(result.certInfo.notAfter), String(result.certInfo.fingerprintSha256), + certData, subjectNameMap, issuerNameMap, dateMap); + console.log(TAG + 'getUserTrustedCertificate end'); + callback(CMModelErrorCode.CM_MODEL_ERROR_SUCCESS, certInfo); + } else { + console.error(TAG + 'getUserTrustedCertificate failed, undefined'); + callback(CMModelErrorCode.CM_MODEL_ERROR_FAILED, undefined); } - if (result.certInfo.issuerName.length !== 0) { - let issuerNameCN = result.certInfo.issuerName.match(/(?<=CN=).*?(?=,)/g); - console.info('issuerNameCN is:' + issuerNameCN); - let issuerNameOU = result.certInfo.issuerName.match(/(?<=OU=).*?(?=,)/g); - console.info('issuerNameOU is:' + issuerNameOU); - let issuerNameO = result.certInfo.issuerName.match(/(?<=O=).*/g); - console.info('issuerNameO is:' + issuerNameO); - issuerNameMap.set('常用名称:', String(issuerNameCN)); - issuerNameMap.set('组织:', String(issuerNameO)); - issuerNameMap.set('组织单位:', String(issuerNameOU)); - } - dateMap.set('颁发时间:', String(result.certInfo.notBefore)); - dateMap.set('有效期至:', String(result.certInfo.notAfter)); - let certData:Uint8Array = result.certInfo.cert; - let certInfo = new CertInfoVo(String(result.certInfo.uri), String(result.certInfo.certAlias), - Boolean(result.certInfo.status), String(result.certInfo.issuerName), String(result.certInfo.subjectName), - String(result.certInfo.serial), String(result.certInfo.notBefore), - String(result.certInfo.notAfter), String(result.certInfo.fingerprintSha256), - certData, subjectNameMap, issuerNameMap, dateMap); - console.log(TAG + 'getUserTrustedCertificate end'); - callback(CMModelErrorCode.CM_MODEL_ERROR_SUCCESS, certInfo); } catch (err) { - console.log(TAG + 'getUserTrustedCertificate err: ' + JSON.stringify(err)); - callback(CMModelErrorCode.CM_MODEL_ERROR_EXCEPTION, null); + let e: BusinessError = err as BusinessError; + console.error(TAG + 'getUserTrustedCertificate err, message: ' + e.message + ', code: ' + e.code); + callback(CMModelErrorCode.CM_MODEL_ERROR_EXCEPTION, undefined); } } - private async deleteUserTrustedCertificate(certUri, callback): Promise { + private async deleteUserTrustedCertificate(certUri: string, callback: Function): Promise { console.log(TAG + 'deleteUserTrustedCertificate start'); try { await CertManager.uninstallUserTrustedCertificate(certUri); console.log(TAG + 'deleteUserTrustedCertificate end'); callback(CMModelErrorCode.CM_MODEL_ERROR_SUCCESS); } catch (err) { - console.log(TAG + 'deleteUserTrustedCertificate err: ' + JSON.stringify(err)); + let e: BusinessError = err as BusinessError; + console.error(TAG + 'deleteUserTrustedCertificate err, message: ' + e.message + ', code: ' + e.code); callback(CMModelErrorCode.CM_MODEL_ERROR_EXCEPTION); } } - private async setCertificateStatus(certUri, store, status, callback): Promise { + private async setCertificateStatus(certUri: string, store: number, + status: boolean, callback: Function): Promise { console.log(TAG + 'setCertificateStatus start'); try { await CertManager.setCertificateStatus(certUri, store, status); console.log(TAG + 'setCertificateStatus end'); callback(CMModelErrorCode.CM_MODEL_ERROR_SUCCESS); } catch (err) { - console.info(TAG + 'setCertificateStatus fail, err is' + err); + let e: BusinessError = err as BusinessError; + console.error(TAG + 'setCertificateStatus failed with err, message: ' + e.message + ', code: ' + e.code); callback(CMModelErrorCode.CM_MODEL_ERROR_EXCEPTION); } } - private async getAppCredList(callback): Promise { + private async getAppCredList(callback: Function): Promise { console.log(TAG + 'getAppCredList start'); try { let result = await CertManager.getAppCertificateList(); - let credList = new Array(); - for (let i = 0; i < result.credentialList.length; i++) { - credList.push(new CredentialAbstractVo(String(result.credentialList[i].type), - String(result.credentialList[i].alias), String(result.credentialList[i].keyUri))); + let credList: Array = new Array(); + if (result.credentialList !== undefined) { + for (let i = 0; i < result.credentialList.length; i++) { + credList.push(new CredentialAbstractVo(String(result.credentialList[i].type), + String(result.credentialList[i].alias), String(result.credentialList[i].keyUri))); + } + console.log(TAG + 'getAppCredList end credList: ' + JSON.stringify(credList)); + callback(CMModelErrorCode.CM_MODEL_ERROR_SUCCESS, credList); + } else { + console.error(TAG + 'getAppCredList failed, undefined.'); + callback(CMModelErrorCode.CM_MODEL_ERROR_FAILED, undefined); } - console.log(TAG + 'getAppCredList end credList: ' + JSON.stringify(credList)); - callback(CMModelErrorCode.CM_MODEL_ERROR_SUCCESS, credList); } catch (err) { - console.info(TAG + 'getAppCredList fail, err is ' + JSON.stringify(err)); + let e: BusinessError = err as BusinessError; + console.error(TAG + 'getAppCredList failed with err, message: ' + e.message + ', code: ' + e.code); callback(CMModelErrorCode.CM_MODEL_ERROR_EXCEPTION); } } - private async getAppCredential(certUri, callback): Promise { + private async getAppCredential(certUri: string, callback: Function): Promise { console.log(TAG + 'getAppCredential start'); try { let result = await CertManager.getAppCertificate(certUri); - let certData:Uint8Array = result.credential.credData; - let credInfo = new CredentialVo(String(result.credential.type), String(result.credential.alias), - String(result.credential.keyUri), Number(result.credential.certNum), - Number(result.credential.keyNum), certData); - console.log(TAG + 'getAppCredential end'); - callback(CMModelErrorCode.CM_MODEL_ERROR_SUCCESS, credInfo); + if (result.credential !== undefined) { + let certData:Uint8Array = result.credential.credData; + let credInfo = new CredentialVo(String(result.credential.type), String(result.credential.alias), + String(result.credential.keyUri), Number(result.credential.certNum), + Number(result.credential.keyNum), certData); + console.log(TAG + 'getAppCredential end'); + callback(CMModelErrorCode.CM_MODEL_ERROR_SUCCESS, credInfo); + } else { + console.error(TAG + 'getAppCredential failed, undefined'); + callback(CMModelErrorCode.CM_MODEL_ERROR_FAILED, undefined); + } } catch (err) { - console.info(TAG + 'getAppCredential fail, err is ' + JSON.stringify(err)); - callback(CMModelErrorCode.CM_MODEL_ERROR_EXCEPTION, null); + let e: BusinessError = err as BusinessError; + console.error(TAG + 'getAppCredential failed with err, message: ' + e.message + ', code: ' + e.code); + callback(CMModelErrorCode.CM_MODEL_ERROR_EXCEPTION, undefined); } } - private async deleteAppCredential(certUri, callback): Promise { + private async deleteAppCredential(certUri: string, callback: Function): Promise { console.log(TAG + 'deleteAppCredential start'); try { await CertManager.uninstallAppCertificate(certUri); console.log(TAG + 'deleteAppCredential end'); callback(CMModelErrorCode.CM_MODEL_ERROR_SUCCESS); } catch (err) { - console.info(TAG + 'deleteAppCredential fail, err is' + err); + let e: BusinessError = err as BusinessError; + console.error(TAG + 'deleteAppCredential failed with err, message: ' + e.message + ', code: ' + e.code); callback(CMModelErrorCode.CM_MODEL_ERROR_EXCEPTION); } } - private async getPrivateCredList(callback): Promise { + private async getPrivateCredList(callback: Function): Promise { console.log(TAG + 'getPrivateCredList start'); try { let result = await CertManager.getPrivateCertificateList(); - let credList = new Array(); - for (let i = 0; i < result.credentialList.length; i++) { - credList.push(new CredentialAbstractVo(String(result.credentialList[i].type), - String(result.credentialList[i].alias), String(result.credentialList[i].keyUri))); + let credList: Array = new Array(); + if (result.credentialList !== undefined) { + for (let i = 0; i < result.credentialList.length; i++) { + credList.push(new CredentialAbstractVo(String(result.credentialList[i].type), + String(result.credentialList[i].alias), String(result.credentialList[i].keyUri))); + } + console.log(TAG + 'getPrivateCredList end'); + callback(CMModelErrorCode.CM_MODEL_ERROR_SUCCESS, credList); + } else { + console.error(TAG + 'getPrivateCredList failed, undefined'); + callback(CMModelErrorCode.CM_MODEL_ERROR_FAILED); } - console.log(TAG + 'getPrivateCredList end'); - callback(CMModelErrorCode.CM_MODEL_ERROR_SUCCESS, credList); } catch (err) { - console.info(TAG + 'getPrivateCredList fail, err is' + err); + let e: BusinessError = err as BusinessError; + console.error(TAG + 'getPrivateCredList failed with err, message: ' + e.message + ', code: ' + e.code); callback(CMModelErrorCode.CM_MODEL_ERROR_EXCEPTION); } } - private async getPrivateCred(certUri, callback): Promise { + private async getPrivateCred(certUri: string, callback: Function): Promise { console.log(TAG + 'getPrivateCred start'); try { let result = await CertManager.getPrivateCertificate(String(certUri)); - let certData:Uint8Array = result.credential.credData; - let credInfo = new CredentialVo(String(result.credential.type), String(result.credential.alias), - String(result.credential.keyUri), Number(result.credential.certNum), - Number(result.credential.keyNum), certData); - console.log(TAG + 'getPrivateCred end'); - callback(CMModelErrorCode.CM_MODEL_ERROR_SUCCESS, credInfo); + if (result.credential !== undefined) { + let certData:Uint8Array = result.credential.credData; + let credInfo = new CredentialVo(String(result.credential.type), String(result.credential.alias), + String(result.credential.keyUri), Number(result.credential.certNum), + Number(result.credential.keyNum), certData); + console.log(TAG + 'getPrivateCred end'); + callback(CMModelErrorCode.CM_MODEL_ERROR_SUCCESS, credInfo); + } else { + console.error(TAG + 'getPrivateCred failed, undefined'); + callback(CMModelErrorCode.CM_MODEL_ERROR_EXCEPTION, undefined); + } } catch (err) { - console.info(TAG + 'getPrivateCred fail, err is' + err); - callback(CMModelErrorCode.CM_MODEL_ERROR_EXCEPTION, null); + let e: BusinessError = err as BusinessError; + console.error(TAG + 'getPrivateCred failed with err, message: ' + e.message + ', code: ' + e.code); + callback(CMModelErrorCode.CM_MODEL_ERROR_EXCEPTION, undefined); } } - private async delAllUserCertificate(callback): Promise { + private async delAllUserCertificate(callback: Function): Promise { console.log(TAG + 'delAllUserCertificate start'); try { await CertManager.uninstallAllUserTrustedCertificate(); console.log(TAG + 'delAllUserCertificate end'); callback(CMModelErrorCode.CM_MODEL_ERROR_SUCCESS); } catch (err) { - console.info(TAG + 'delAllUserCertificate fail, err is' + err); + let e: BusinessError = err as BusinessError; + console.error(TAG + 'delAllUserCertificate failed with err, message: ' + e.message + ', code: ' + e.code); callback(CMModelErrorCode.CM_MODEL_ERROR_EXCEPTION); } } - private async delAllAppCredential(callback): Promise { + private async delAllAppCredential(callback: Function): Promise { console.log(TAG + 'delAllAppCredential start'); try { await CertManager.uninstallAllAppCertificate(); console.log(TAG + 'delAllAppCredential end'); callback(CMModelErrorCode.CM_MODEL_ERROR_SUCCESS); } catch (err) { - console.info(TAG + 'delAllAppCredential fail, err is' + err); + let e: BusinessError = err as BusinessError; + console.error(TAG + 'delAllAppCredential failed with err, message: ' + e.message + ', code: ' + e.code); callback(CMModelErrorCode.CM_MODEL_ERROR_EXCEPTION); } } - private async getAuthorizedAppList(uri, callback): Promise { + private async getAuthorizedAppList(uri: string, callback: Function): Promise { console.log(TAG + 'getAuthorizedAppList start'); try { let result = await CertManager.getAuthorizedAppList(uri); console.log(TAG + 'getAuthorizedAppList end'); callback(CMModelErrorCode.CM_MODEL_ERROR_SUCCESS, result.appUidList); } catch (err) { - console.info(TAG + 'getAuthorizedAppList fail, err is' + err); - callback(CMModelErrorCode.CM_MODEL_ERROR_EXCEPTION, null); + let e: BusinessError = err as BusinessError; + console.error(TAG + 'getAuthorizedAppList failed with err, message: ' + e.message + ', code: ' + e.code); + callback(CMModelErrorCode.CM_MODEL_ERROR_EXCEPTION, undefined); } } - private async setAuthorizedAppStatus(uri, appUid, status, callback): Promise { + private async setAuthorizedAppStatus(uri: string, appUid: string, + status: boolean, callback: Function): Promise { console.log(TAG + 'setAuthorizedAppStatus start'); try { if (status) { @@ -566,12 +632,13 @@ export class CertMangerModel { callback(CMModelErrorCode.CM_MODEL_ERROR_SUCCESS); } } catch (err) { - console.info(TAG + 'setAuthorizedAppStatus fail, err is' + JSON.stringify(err)); + let e: BusinessError = err as BusinessError; + console.error(TAG + 'setAuthorizedAppStatus failed with err, message: ' + e.message + ', code: ' + e.code); callback(CMModelErrorCode.CM_MODEL_ERROR_EXCEPTION); } } - private async installUserCertificate(data, alias, callback): Promise { + private async installUserCertificate(data: Uint8Array, alias: string, callback: Function): Promise { console.info(TAG + 'installUserCertificate start alias: ' + alias + 'data' + JSON.stringify(data)); try { await CertManager.installUserTrustedCertificate({ @@ -582,19 +649,22 @@ export class CertMangerModel { console.info(TAG + 'installUserCertificate end'); callback(CMModelErrorCode.CM_MODEL_ERROR_SUCCESS); } catch (err) { - console.info(TAG + 'installUserCertificate fail, err is' + err); + let e: BusinessError = err as BusinessError; + console.error(TAG + 'installUserCertificate failed with err, message: ' + e.message + ', code: ' + e.code); callback(CMModelErrorCode.CM_MODEL_ERROR_EXCEPTION); } } - private async installAppCertificate(data, alias, pwd, callback): Promise { + private async installAppCertificate(data: Uint8Array, alias: string, + pwd: string, callback: Function): Promise { console.info(TAG + 'installAppCertificate start'); try { await CertManager.installAppCertificate(data, pwd, alias); console.info(TAG + 'installAppCertificate end'); callback(CMModelErrorCode.CM_MODEL_ERROR_SUCCESS); } catch (err) { - console.info(TAG + 'installAppCertificate fail, err is' + err); + let e: BusinessError = err as BusinessError; + console.error(TAG + 'installAppCertificate failed with err, message: ' + e.message + ', code: ' + e.code); callback(CMModelErrorCode.CM_MODEL_ERROR_EXCEPTION); } } diff --git a/CertificateManager/product/phone/src/main/ets/model/FileIoModel.ets b/CertificateManager/product/phone/src/main/ets/model/FileIoModel.ets index 985fa46..732a30e 100644 --- a/CertificateManager/product/phone/src/main/ets/model/FileIoModel.ets +++ b/CertificateManager/product/phone/src/main/ets/model/FileIoModel.ets @@ -15,9 +15,10 @@ import fileUri from '@ohos.file.fileuri'; import fs from '@ohos.file.fs'; +import { BusinessError } from '@ohos.base'; export class FileIoModel { - getMediaFileData(mediaUri, callback): void { + getMediaFileData(mediaUri: string, callback: Function): void { console.log('CertManager FA getMediaFile start'); try { let file = fs.openSync(mediaUri, fs.OpenMode.READ_ONLY); @@ -28,20 +29,21 @@ export class FileIoModel { console.log('CertManager FA getMediaFile success'); callback(new Uint8Array(buf)); } catch(err) { - console.error('CertManager FA getMediaFileData failed'); + let e: BusinessError = err as BusinessError; + console.error('CertManager FA getMediaFileData failed with err, message: ' + e.message + ', code: ' + e.code); callback(undefined); } } - getMediaFileSuffix(mediaUri, callback): void { + getMediaFileSuffix(mediaUri: string, callback: Function): void { try { console.log('CertManager FA getMediaFileSuffix start uri: ' + mediaUri); - // @ts-ignore let uri = new fileUri.FileUri(mediaUri); let suffix = uri.name.substring(uri.name.lastIndexOf('.') + 1); callback(suffix); } catch(err) { - console.error('CertManager FA getMediaFileSuffix failed'); + let e: BusinessError = err as BusinessError; + console.error('CertManager FA getMediaFileSuffix failed with err, message: ' + e.message + ', code: ' + e.code); callback(undefined); } } diff --git a/CertificateManager/product/phone/src/main/ets/pages/cerEvidenceFa.ets b/CertificateManager/product/phone/src/main/ets/pages/cerEvidenceFa.ets index fefe295..cf79df9 100644 --- a/CertificateManager/product/phone/src/main/ets/pages/cerEvidenceFa.ets +++ b/CertificateManager/product/phone/src/main/ets/pages/cerEvidenceFa.ets @@ -18,13 +18,16 @@ import HeadComponent from '../common/component/headComponent'; import CmShowAppCredPresenter from '../presenter/CmShowAppCredPresenter'; import CMShowPrivateCredPresenter from '../presenter/CmShowPrivateCredPresenter'; import CMFaPresenter from '../presenter/CmFaPresenter'; +import { GlobalContext } from '../common/GlobalContext'; +import { CredentialAbstractVo } from '../model/CertManagerVo/CredentialAbstractVo'; +import { AppAuthorVo } from '../model/CertManagerVo/AppAuthorVo'; @Component export struct DialogComponent { @Link uidItem: CmShowAppCredPresenter; - private AppName: string; - private AppImage: string; - private Index: number; + private AppName: string = ''; + private AppImage: string = ''; + private Index: number = 0; build() { Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { @@ -57,7 +60,7 @@ export struct DialogComponent { @CustomDialog @Component struct CustomDialogExampleAuthor { - controller: CustomDialogController; + controller?: CustomDialogController; @Link isShowAuthDialog: boolean; @Link AuthorInfo: CmShowAppCredPresenter; @State updateStatusList: boolean[] = []; @@ -95,9 +98,10 @@ struct CustomDialogExampleAuthor { Stack({ alignContent: Alignment.End }) { Scroll(this.authorScroller) { List() { - ForEach(this.AuthorInfo.appInfoList, (item, index) => { + ForEach(this.AuthorInfo.appInfoList, (item: AppAuthorVo, index) => { ListItem() { - DialogComponent({ AppImage: item.appImage, AppName: item.appName, Index: index, uidItem: $AuthorInfo }) + DialogComponent({ AppImage: item.appImage, AppName: item.appName, + Index: index, uidItem: $AuthorInfo }) } }) } @@ -113,7 +117,8 @@ struct CustomDialogExampleAuthor { left: $r('app.float.wh_value_24'), right: $r('app.float.wh_value_24') }) - ScrollBar({ scroller: this.authorScroller, direction: ScrollBarDirection.Vertical, state: BarState.Auto}) { + ScrollBar({ scroller: this.authorScroller, direction: ScrollBarDirection.Vertical, + state: BarState.Auto}) { Text() .width($r("app.float.wh_value_3")) .height($r("app.float.wh_value_50")) @@ -129,9 +134,10 @@ struct CustomDialogExampleAuthor { .height(WidthPercent.WH_50_100) } else { List() { - ForEach(this.AuthorInfo.appInfoList, (item, index) => { + ForEach(this.AuthorInfo.appInfoList, (item: AppAuthorVo, index) => { ListItem() { - DialogComponent({ AppImage: item.appImage, AppName: item.appName, Index: index, uidItem: $AuthorInfo }) + DialogComponent({ AppImage: item.appImage, AppName: item.appName, + Index: index, uidItem: $AuthorInfo }) } }) } @@ -147,11 +153,14 @@ struct CustomDialogExampleAuthor { .visibility(this.AuthorInfo.appInfoList.length > 0 ? Visibility.Visible : Visibility.None) } - Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceAround }) { + Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, + justifyContent: FlexAlign.SpaceAround }) { Button($r("app.string.cancelAuthApp")) .onClick(() => { this.isShowAuthDialog = false; - this.controller.close() + if (this.controller !== undefined) { + this.controller.close(); + } }) .backgroundColor($r("app.color.credentials_app_finish_backgroundColor")) .fontSize($r("sys.float.ohos_id_text_size_button1")) @@ -168,7 +177,9 @@ struct CustomDialogExampleAuthor { .onClick(() => { this.AuthorInfo.removeGrantedAppList(this.AuthorInfo.credInfo.keyUri).then(() => { this.isShowAuthDialog = false; - this.controller.close() + if (this.controller !== undefined) { + this.controller.close(); + } }) }) .backgroundColor($r("app.color.credentials_app_finish_backgroundColor")) @@ -216,7 +227,7 @@ struct CustomDialogExampleAuthor { @CustomDialog @Component struct CustomDialogExamplePrivate { - controller: CustomDialogController; + controller?: CustomDialogController; @State PriCerInfoPresenter: CMShowPrivateCredPresenter = CMShowPrivateCredPresenter.getInstance(); build() { @@ -291,10 +302,13 @@ struct CustomDialogExamplePrivate { .opacity($r('app.float.opacity_100_60')) .alignSelf(ItemAlign.Start) - Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceAround }) { + Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, + justifyContent: FlexAlign.SpaceAround }) { Button($r("app.string.privateDetailsClose")) .onClick(() => { - this.controller.close() + if (this.controller !== undefined) { + this.controller.close(); + } }) .backgroundColor($r("app.color.credentials_app_finish_backgroundColor")) .fontSize($r("sys.float.ohos_id_text_size_button1")) @@ -341,7 +355,7 @@ struct CustomDialogExamplePrivate { @CustomDialog @Component struct CustomDialogDeleteWarning { - controller: CustomDialogController; + controller?: CustomDialogController; @Link deleteWarn: CmShowAppCredPresenter; @Link isShowWarnDialog: boolean; @@ -384,11 +398,14 @@ struct CustomDialogDeleteWarning { }) .alignSelf(ItemAlign.Start) - Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceAround }) { + Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, + justifyContent: FlexAlign.SpaceAround }) { Button($r("app.string.deleteAllCredCancel")) .onClick(() => { this.isShowWarnDialog = false; - this.controller.close() + if (this.controller !== undefined) { + this.controller.close(); + } }) .backgroundColor($r("app.color.credentials_app_finish_backgroundColor")) .fontSize($r("sys.float.ohos_id_text_size_button1")) @@ -405,7 +422,9 @@ struct CustomDialogDeleteWarning { .onClick(() => { this.deleteWarn.deleteAppCred(this.deleteWarn.credInfo.keyUri); this.isShowWarnDialog = false; - this.controller.close() + if (this.controller !== undefined) { + this.controller.close(); + } }) .backgroundColor($r("app.color.credentials_app_finish_backgroundColor")) .fontSize($r("sys.float.ohos_id_text_size_button1")) @@ -452,7 +471,7 @@ struct CustomDialogDeleteWarning { @CustomDialog @Component struct CustomDialogExampleApp { - controller: CustomDialogController; + controller?: CustomDialogController; @Link mShowAppCaPresenter: CmShowAppCredPresenter; @Link isShowAuthDialog: boolean; @Link isShowWarnDialog: boolean; @@ -559,12 +578,15 @@ struct CustomDialogExampleApp { }) .height('48vp') - Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceAround }) { + Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, + justifyContent: FlexAlign.SpaceAround }) { Button($r("app.string.publicDetailsCancel")) .onClick(() => { this.isShowAuthDialog = false; this.isShowWarnDialog = false; - this.controller.close(); + if (this.controller !== undefined) { + this.controller.close(); + } }) .backgroundColor($r("app.color.credentials_app_finish_backgroundColor")) .fontSize($r("sys.float.ohos_id_text_size_button1")) @@ -581,7 +603,9 @@ struct CustomDialogExampleApp { .onClick(() => { this.isShowWarnDialog = true; this.isShowAuthDialog = false; - this.controller.close() + if (this.controller !== undefined) { + this.controller.close(); + } }) .backgroundColor($r("app.color.credentials_app_finish_backgroundColor")) .fontSize($r("sys.float.ohos_id_text_size_button1")) @@ -627,8 +651,8 @@ struct CustomDialogExampleApp { @Component export struct componentPublic { - private Alias: string; - private KeyUri: string; + private Alias: string = ''; + private KeyUri: string = ''; @Link mShowAppCaPresenter: CmShowAppCredPresenter; @State @Watch("onShowAuthMngChange") isShowAuthMng: boolean = false; @State @Watch("onShowDeleteWarnDialog") isShowWarning: boolean = false; @@ -700,8 +724,8 @@ export struct componentPublic { @Component export struct componentPrivate { - private Alias: string; - private KeyUri: string; + private Alias: string = ''; + private KeyUri: string = ''; @State PrivateCerPresenter: CMShowPrivateCredPresenter = CMShowPrivateCredPresenter.getInstance(); privateDetailDialog: CustomDialogController = new CustomDialogController({ builder: CustomDialogExamplePrivate(), @@ -777,13 +801,13 @@ struct evidenceList { } onPageShow() { - let uri = globalThis.abilityWant.uri; - globalThis.abilityWant.uri = ""; + let uri = GlobalContext.getContext().getAbilityWant().uri; + GlobalContext.getContext().clearAbilityWantUri(); if (uri === "certInstall") { this.mFaPresenter.startInstall(); } else if (uri === "requestAuthorize") { - this.mFaPresenter.startRequestAuth(globalThis.abilityWant.parameters.appUid); + this.mFaPresenter.startRequestAuth(GlobalContext.getContext().getAbilityWant().parameters?.appUid as string); } } @@ -808,7 +832,7 @@ struct evidenceList { Stack({ alignContent: Alignment.End }) { Scroll(this.publicScroller) { List() { - ForEach(this.mShowAppCaPresenter.credList, (item) => { + ForEach(this.mShowAppCaPresenter.credList, (item: CredentialAbstractVo) => { ListItem() { componentPublic({ Alias: item.alias, @@ -816,7 +840,7 @@ struct evidenceList { mShowAppCaPresenter: $mShowAppCaPresenter }) } - }, item => JSON.stringify(item)) + }, (item: CredentialAbstractVo) => JSON.stringify(item)) } .scrollBar(BarState.Off) .padding({ @@ -841,7 +865,8 @@ struct evidenceList { }) .borderRadius($r("app.float.Evidence_borderRadius")) .backgroundColor($r("app.color.credentials_app_finish_backgroundColor")) - ScrollBar({ scroller: this.publicScroller, direction: ScrollBarDirection.Vertical, state: BarState.Auto}) { + ScrollBar({ scroller: this.publicScroller, direction: ScrollBarDirection.Vertical, + state: BarState.Auto}) { Text() .width($r("app.float.wh_value_3")) .height($r("app.float.wh_value_50")) @@ -857,12 +882,14 @@ struct evidenceList { } } .tabBar(this.TabBuilder(0)) - .onTouch((event: TouchEvent) => { - if (event.type === TouchType.Down) { - this.isTouched = true; - } - if (event.type === TouchType.Up) { - this.isTouched = false; + .onTouch((event?: TouchEvent) => { + if (event !== undefined) { + if (event.type === TouchType.Down) { + this.isTouched = true; + } + if (event.type === TouchType.Up) { + this.isTouched = false; + } } }) @@ -870,11 +897,11 @@ struct evidenceList { Stack({ alignContent: Alignment.End }) { Scroll(this.privateScroller) { List() { - ForEach(this.mShowPrivateCaPresenter.credList, (item) => { + ForEach(this.mShowPrivateCaPresenter.credList, (item: CredentialAbstractVo) => { ListItem() { componentPrivate({ Alias: item.alias, KeyUri: item.keyUri }) } - }, item => JSON.stringify(item)) + }, (item: CredentialAbstractVo) => JSON.stringify(item)) } .scrollBar(BarState.Off) .padding({ @@ -890,7 +917,8 @@ struct evidenceList { }) .borderRadius($r("app.float.Evidence_borderRadius")) .backgroundColor($r("app.color.credentials_app_finish_backgroundColor")) - .visibility(this.mShowPrivateCaPresenter.credList.length > 0 ? Visibility.Visible : Visibility.None) + .visibility( + this.mShowPrivateCaPresenter.credList.length > 0 ? Visibility.Visible : Visibility.None) } .position({ y: 0 }) .scrollable(ScrollDirection.Vertical) @@ -917,16 +945,19 @@ struct evidenceList { .margin({ right: $r("app.float.wh_value_3") }) - .visibility(this.mShowPrivateCaPresenter.credList.length > 0 ? Visibility.Visible : Visibility.None) + .visibility( + this.mShowPrivateCaPresenter.credList.length > 0 ? Visibility.Visible : Visibility.None) } } .tabBar(this.TabBuilder(1)) - .onTouch((event: TouchEvent) => { - if (event.type === TouchType.Down) { - this.isTouched = true; - } - if (event.type === TouchType.Up) { - this.isTouched = false; + .onTouch((event?: TouchEvent) => { + if (event !== undefined) { + if (event.type === TouchType.Down) { + this.isTouched = true; + } + if (event.type === TouchType.Up) { + this.isTouched = false; + } } }); } diff --git a/CertificateManager/product/phone/src/main/ets/pages/certInstallAliasInput.ets b/CertificateManager/product/phone/src/main/ets/pages/certInstallAliasInput.ets index 1397945..c00d3eb 100644 --- a/CertificateManager/product/phone/src/main/ets/pages/certInstallAliasInput.ets +++ b/CertificateManager/product/phone/src/main/ets/pages/certInstallAliasInput.ets @@ -18,6 +18,7 @@ import { WidthPercent, LocationChoice, ConfigValue } from '../common/util/Config import router from '@system.router'; import CmInstallPresenter from '../presenter/CmInstallPresenter'; import CmFaPresenter from '../presenter/CmFaPresenter'; +import { GlobalContext } from '../common/GlobalContext'; @Entry @Component @@ -27,13 +28,13 @@ struct CertInstallAliasInput { @State certAlias: string = ""; onPageShow() { - let uri = globalThis.abilityWant.uri; - globalThis.abilityWant.uri = ""; + let uri = GlobalContext.getContext().getAbilityWant().uri; + GlobalContext.getContext().clearAbilityWantUri(); if (uri === "certInstall") { this.mFaPresenter.startInstall(); } else if (uri === "requestAuthorize") { - this.mFaPresenter.startRequestAuth(globalThis.abilityWant.parameters.appUid); + this.mFaPresenter.startRequestAuth(GlobalContext.getContext().getAbilityWant().parameters?.appUid as string); } } @@ -125,9 +126,9 @@ struct CertInstallAliasInput { right: $r('app.float.distance_24'), }) .onClick(() => { - this.mAppCredAuthPresenter.installCert(router.getParams().uri, + this.mAppCredAuthPresenter.installCert(router.getParams().uri as string, this.certAlias, - router.getParams().suffix); + router.getParams().suffix as string); }) } else { Button() { diff --git a/CertificateManager/product/phone/src/main/ets/pages/certManagerFa.ets b/CertificateManager/product/phone/src/main/ets/pages/certManagerFa.ets index ee36a73..bf1b1e5 100644 --- a/CertificateManager/product/phone/src/main/ets/pages/certManagerFa.ets +++ b/CertificateManager/product/phone/src/main/ets/pages/certManagerFa.ets @@ -17,6 +17,12 @@ import { WidthPercent, LocationChoice, ConfigValue } from '../common/util/Config import HeadComponent from '../common/component/headComponent'; import { SubEntryComponent } from '../common/component/subEntryComponent'; import CmFaPresenter from '../presenter/CmFaPresenter'; +import { GlobalContext } from '../common/GlobalContext'; + +class CertListItem { + targetPage: string = ''; + title: Resource = $r("app.string.trustedEvidence"); +}; @Entry @Component @@ -24,7 +30,7 @@ struct CertificateComponent { @State touchedItem: boolean = false; @State columnMargin: string = '12vp'; @State mFaPresenter: CmFaPresenter = CmFaPresenter.getInstance(); - private listItems = [ + private listItems: Array = [ { targetPage: "pages/trustedCa", title: $r("app.string.trustedEvidence") }, { targetPage: "pages/cerEvidenceFa", title: $r("app.string.userEvidence") } ]; @@ -50,11 +56,11 @@ struct CertificateComponent { HeadComponent({ headName: $r('app.string.certificateTab') }) Column({ space: this.columnMargin }) { List() { - ForEach(this.listItems, (item) => { + ForEach(this.listItems, (item: CertListItem) => { ListItem() { SubEntryComponent({ targetPage: item.targetPage, title: item.title}) } - }, item => JSON.stringify(item)) + }, (item: CertListItem) => JSON.stringify(item)) } .padding($r('app.float.wh_value_4')) .divider({ @@ -102,13 +108,13 @@ struct CertificateComponent { } onPageShow() { - let uri = globalThis.abilityWant.uri; - globalThis.abilityWant.uri = ""; + let uri = GlobalContext.getContext().getAbilityWant().uri; + GlobalContext.getContext().clearAbilityWantUri(); if (uri === "certInstall") { this.mFaPresenter.startInstall(); } else if (uri === "requestAuthorize") { - this.mFaPresenter.startRequestAuth(globalThis.abilityWant.parameters.appUid); + this.mFaPresenter.startRequestAuth(GlobalContext.getContext().getAbilityWant().parameters?.appUid as string); } } } @@ -116,7 +122,7 @@ struct CertificateComponent { @CustomDialog @Component struct CustomDialogExampleDeleteAll { - controller: CustomDialogController; + controller?: CustomDialogController; @Link deleteAll: CmFaPresenter; build() { @@ -158,10 +164,13 @@ struct CustomDialogExampleDeleteAll { }) .alignSelf(ItemAlign.Start) - Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceAround }) { + Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, + justifyContent: FlexAlign.SpaceAround }) { Button($r("app.string.deleteAllCredCancel")) .onClick(() => { - this.controller.close() + if (this.controller !== undefined) { + this.controller.close() + } }) .backgroundColor($r("app.color.credentials_app_finish_backgroundColor")) .fontSize($r("sys.float.ohos_id_text_size_button1")) @@ -177,7 +186,9 @@ struct CustomDialogExampleDeleteAll { Button($r("app.string.deleteAllCredDelete")) .onClick(() => { this.deleteAll.uninstallAllCert(); - this.controller.close() + if (this.controller !== undefined) { + this.controller.close() + } }) .backgroundColor($r("app.color.credentials_app_finish_backgroundColor")) .fontSize($r("sys.float.ohos_id_text_size_button1")) @@ -260,12 +271,14 @@ struct DeleteAll { .height($r('app.float.wh_value_56')) .width(WidthPercent.WH_100_100) .borderRadius($r('app.float.radius_24')) - .onTouch((event: TouchEvent) => { - if (event.type === TouchType.Down) { - this.isTouched = true; - } - if (event.type === TouchType.Up) { - this.isTouched = false; + .onTouch((event?: TouchEvent) => { + if (event !== undefined) { + if (event.type === TouchType.Down) { + this.isTouched = true; + } + if (event.type === TouchType.Up) { + this.isTouched = false; + } } }) .backgroundColor($r("sys.color.ohos_id_color_foreground_contrary")) @@ -312,12 +325,14 @@ export struct CertInstallComponent { colors: [[$r("sys.color.ohos_id_color_foreground_contrary"), 1], [$r("sys.color.ohos_id_color_foreground_contrary"), 1]] }) - .onTouch((event: TouchEvent) => { - if (event.type === TouchType.Down) { - this.isTouched = true; - } - if (event.type === TouchType.Up) { - this.isTouched = false; + .onTouch((event?: TouchEvent) => { + if (event !== undefined) { + if (event.type === TouchType.Down) { + this.isTouched = true; + } + if (event.type === TouchType.Up) { + this.isTouched = false; + } } }) } diff --git a/CertificateManager/product/phone/src/main/ets/pages/certPwdInput.ets b/CertificateManager/product/phone/src/main/ets/pages/certPwdInput.ets index 351e488..ecf750c 100644 --- a/CertificateManager/product/phone/src/main/ets/pages/certPwdInput.ets +++ b/CertificateManager/product/phone/src/main/ets/pages/certPwdInput.ets @@ -17,6 +17,7 @@ import HeadComponent from '../common/component/headComponent'; import { WidthPercent, LocationChoice, ConfigValue } from '../common/util/ConfigData'; import router from '@system.router'; import CmFaPresenter from '../presenter/CmFaPresenter'; +import { GlobalContext } from '../common/GlobalContext'; @Entry @Component @@ -25,13 +26,13 @@ struct CertPwdInput { @State mFaPresenter: CmFaPresenter = CmFaPresenter.getInstance(); onPageShow() { - let uri = globalThis.abilityWant.uri; - globalThis.abilityWant.uri = ""; + let uri = GlobalContext.getContext().getAbilityWant().uri; + GlobalContext.getContext().clearAbilityWantUri(); if (uri === "certInstall") { this.mFaPresenter.startInstall(); } else if (uri === "requestAuthorize") { - this.mFaPresenter.startRequestAuth(globalThis.abilityWant.parameters.appUid); + this.mFaPresenter.startRequestAuth(GlobalContext.getContext().getAbilityWant().parameters?.appUid as string); } } @@ -99,7 +100,7 @@ struct CertPwdInput { right: $r('app.float.distance_24'), }) .onClick(() => { - globalThis.PwdStore.setCertPwd(this.certPwd) + GlobalContext.getContext().getPwdStore().setCertPwd(this.certPwd) router.push({ uri: 'pages/certInstallAliasInput', params: { diff --git a/CertificateManager/product/phone/src/main/ets/pages/requestAuth.ets b/CertificateManager/product/phone/src/main/ets/pages/requestAuth.ets index 045f94c..95924f0 100644 --- a/CertificateManager/product/phone/src/main/ets/pages/requestAuth.ets +++ b/CertificateManager/product/phone/src/main/ets/pages/requestAuth.ets @@ -17,18 +17,19 @@ import LogUtil from '../common/util/LogUtil'; import CmAppCredAuthPresenter from '../presenter/CmAppCredAuthPresenter'; import router from '@system.router'; import { WidthPercent, LocationChoice, ConfigValue } from '../common/util/ConfigData'; +import { CredentialAbstractVo } from '../model/CertManagerVo/CredentialAbstractVo'; @CustomDialog @Component struct CustomDialogAuthForApp { - controller: CustomDialogController + controller?: CustomDialogController @State mAppCredAuthPresenter: CmAppCredAuthPresenter = CmAppCredAuthPresenter.getInstance(); - selectUri: string = ""; + selectUri: string = ''; private authScroller: Scroller = new Scroller(); aboutToAppear(): void { LogUtil.info('certPwdInput about to appear'); - this.mAppCredAuthPresenter.updateAppNameFromUid(router.getParams().appUid); + this.mAppCredAuthPresenter.updateAppNameFromUid(router.getParams().appUid as string); this.mAppCredAuthPresenter.updateAppCredList(); } @@ -76,7 +77,7 @@ struct CustomDialogAuthForApp { Stack({ alignContent: Alignment.End }) { Scroll(this.authScroller) { List() { - ForEach(this.mAppCredAuthPresenter.credList, (item) => { + ForEach(this.mAppCredAuthPresenter.credList, (item: CredentialAbstractVo) => { ListItem() { Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { @@ -105,7 +106,7 @@ struct CustomDialogAuthForApp { .width(WidthPercent.WH_100_100) } .height($r('app.float.wh_value_64')) - }, item => JSON.stringify(item)) + }, (item: CredentialAbstractVo) => JSON.stringify(item)) } .scrollBar(BarState.Off) .divider({ @@ -136,7 +137,7 @@ struct CustomDialogAuthForApp { .height(WidthPercent.WH_50_100) } else { List() { - ForEach(this.mAppCredAuthPresenter.credList, (item) => { + ForEach(this.mAppCredAuthPresenter.credList, (item: CredentialAbstractVo) => { ListItem() { Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { Column() { @@ -164,7 +165,7 @@ struct CustomDialogAuthForApp { .width(WidthPercent.WH_100_100) } .height($r('app.float.wh_value_64')) - }, item => JSON.stringify(item)) + }, (item: CredentialAbstractVo) => JSON.stringify(item)) ListItem() { Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { Column() { @@ -199,11 +200,14 @@ struct CustomDialogAuthForApp { .visibility(this.mAppCredAuthPresenter.credList.length > 0 ? Visibility.Visible : Visibility.None) } - Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceAround }) { + Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, + justifyContent: FlexAlign.SpaceAround }) { Button($r('app.string.requestAuthCancel')) .onClick(() => { this.mAppCredAuthPresenter.cancelProcess(); - this.controller.close(); + if (this.controller !== undefined) { + this.controller.close(); + } }) .backgroundColor($r('app.color.request_auth_background_color')) .fontColor($r('sys.color.ohos_id_color_text_hyperlink')) @@ -223,8 +227,10 @@ struct CustomDialogAuthForApp { LogUtil.info('requestAuthorize uri: ' + this.selectUri); if (router.getParams() && router.getParams().appUid) { LogUtil.info('requestAuthorize appUid: ' + router.getParams().appUid); - this.mAppCredAuthPresenter.requestAuthorize(this.selectUri, router.getParams().appUid); - this.controller.close(); + this.mAppCredAuthPresenter.requestAuthorize(this.selectUri, router.getParams().appUid as string); + if (this.controller !== undefined) { + this.controller.close(); + } } else { LogUtil.info('requestAuthorize fail'); } diff --git a/CertificateManager/product/phone/src/main/ets/pages/trustedCa.ets b/CertificateManager/product/phone/src/main/ets/pages/trustedCa.ets index 7993b19..19d1493 100644 --- a/CertificateManager/product/phone/src/main/ets/pages/trustedCa.ets +++ b/CertificateManager/product/phone/src/main/ets/pages/trustedCa.ets @@ -18,20 +18,37 @@ import HeadComponent from '../common/component/headComponent'; import CmShowSysCaPresenter from '../presenter/CmShowSysCaPresenter'; import CMShowUserCaPresenter from '../presenter/CmShowUserCaPresenter'; import CmFaPresenter from '../presenter/CmFaPresenter'; +import { GlobalContext } from '../common/GlobalContext'; +import { CertAbstractVo } from '../model/CertManagerVo/CertAbstractVo'; @Component struct DialogSubjectComponent { - private map: Map; + private map?: Map; private subjectNameCN: string = '' private subjectNameO: string = '' private subjectNameOU: string = '' private serial: string = '' aboutToAppear() { if (this.map != null) { - this.subjectNameCN = this.map.get('常用名称:') - this.subjectNameO = this.map.get('组织:') - this.subjectNameOU = this.map.get('组织单位:') - this.serial = this.map.get('序列号:') + let subjectNameCN = this.map.get('常用名称:'); + if (subjectNameCN !== undefined) { + this.subjectNameCN = subjectNameCN; + } + + let subjectNameO = this.map.get('组织:'); + if (subjectNameO !== undefined) { + this.subjectNameO = subjectNameO; + } + + let subjectNameOU = this.map.get('组织单位:'); + if (subjectNameOU !== undefined) { + this.subjectNameOU = subjectNameOU; + } + + let serial = this.map.get('序列号:'); + if (serial !== undefined) { + this.serial = serial; + } } } build() { @@ -86,15 +103,26 @@ struct DialogSubjectComponent { @Component struct DialogIssuerComponent { - private map: Map; + private map?: Map; private issuerNameCN: string = '' private issuerNameO: string = '' private issuerNameOU: string = '' aboutToAppear() { if (this.map != null) { - this.issuerNameCN = this.map.get('常用名称:') - this.issuerNameO = this.map.get('组织:') - this.issuerNameOU = this.map.get('组织单位:') + let issuerNameCN = this.map.get('常用名称:'); + if (issuerNameCN !== undefined) { + this.issuerNameCN = issuerNameCN; + } + + let issuerNameO = this.map.get('组织:'); + if (issuerNameO !== undefined) { + this.issuerNameO = issuerNameO; + } + + let issuerNameOU = this.map.get('组织单位:'); + if (issuerNameOU !== undefined) { + this.issuerNameOU = issuerNameOU; + } } } @@ -139,13 +167,20 @@ struct DialogIssuerComponent { @Component struct DialogDateComponent { - private map: Map; - private notBefore: string = '' - private notAfter: string = '' + private map?: Map; + private notBefore: string = ''; + private notAfter: string = ''; aboutToAppear() { if (this.map != null) { - this.notBefore = this.map.get('颁发时间:') - this.notAfter = this.map.get('有效期至:') + let notBefore = this.map.get('颁发时间:'); + if (notBefore != undefined) { + this.notBefore = notBefore; + } + + let notAfter = this.map.get('有效期至:'); + if (notAfter != undefined) { + this.notAfter = notAfter; + } } } @@ -179,7 +214,7 @@ struct DialogDateComponent { @Component struct DialogFingerPrintComponent { - private fingerprintSha256: string; + private fingerprintSha256: string = ''; build() { Column() { @@ -204,7 +239,7 @@ struct DialogFingerPrintComponent { @CustomDialog @Component struct CustomDialogDeleteWarning { - controller: CustomDialogController; + controller?: CustomDialogController; @Link deleteWarn: CMShowUserCaPresenter; @Link mShowUserListPresenter: CMShowUserCaPresenter; @Link isShowWarnDialog: boolean; @@ -248,11 +283,14 @@ struct CustomDialogDeleteWarning { }) .alignSelf(ItemAlign.Start) - Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceAround }) { + Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, + justifyContent: FlexAlign.SpaceAround }) { Button($r("app.string.deleteAllCredCancel")) .onClick(() => { this.isShowWarnDialog = false; - this.controller.close() + if (this.controller !== undefined) { + this.controller.close(); + } }) .backgroundColor($r("app.color.CustomDialogExample_Button_backgroundColor_FFFFFF")) .fontSize($r("sys.float.ohos_id_text_size_button1")) @@ -270,7 +308,9 @@ struct CustomDialogDeleteWarning { this.deleteWarn.deleteUserCertificate(this.deleteWarn.certInfo.uri, () => { this.mShowUserListPresenter.updateUserTrustedCertificateList(); this.isShowWarnDialog = false; - this.controller.close(); + if (this.controller !== undefined) { + this.controller.close(); + } }); }) .backgroundColor($r("app.color.CustomDialogExample_Button_backgroundColor_FFFFFF")) @@ -317,7 +357,7 @@ struct CustomDialogDeleteWarning { @CustomDialog @Component struct CustomDialogExampleUser { - controller: CustomDialogController; + controller?: CustomDialogController; @Link userInfoPresenter: CMShowUserCaPresenter; @Link userInfoPresenterForAbstractList: CMShowUserCaPresenter; @Link isShowWarnDialog: boolean; @@ -462,12 +502,15 @@ struct CustomDialogExampleUser { }) .scrollBar(BarState.Auto); - Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceAround }) { + Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, + justifyContent: FlexAlign.SpaceAround }) { Button($r("app.string.CustomDialogExampleUser_Flex_firButton_text")) .onClick(() => { this.userInfoPresenterForAbstractList.updateUserTrustedCertificateList(); this.isShowWarnDialog = false; - this.controller.close(); + if (this.controller !== undefined) { + this.controller.close(); + } }) .backgroundColor($r("app.color.CustomDialogExample_Button_backgroundColor_FFFFFF")) .fontSize($r("sys.float.ohos_id_text_size_button1")) @@ -483,7 +526,9 @@ struct CustomDialogExampleUser { Button($r("app.string.CustomDialogExampleUser_Flex_secButton_text")) .onClick(() => { this.isShowWarnDialog = true; - this.controller.close(); + if (this.controller !== undefined) { + this.controller.close(); + } }) .backgroundColor($r("app.color.CustomDialogExample_Button_backgroundColor_FFFFFF")) .fontSize($r("sys.float.ohos_id_text_size_button1")) @@ -529,7 +574,7 @@ struct CustomDialogExampleUser { @CustomDialog @Component struct CustomDialogExampleSystem { - controller: CustomDialogController; + controller?: CustomDialogController; @Link sysInfoPresenter: CmShowSysCaPresenter; private isTrueButton: string = ''; @@ -627,10 +672,13 @@ struct CustomDialogExampleSystem { .height($r("app.float.CustomDialogExample_list_height_value")) .scrollBar(BarState.Auto); - Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceAround }) { + Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, + justifyContent: FlexAlign.SpaceAround }) { Button($r("app.string.CustomDialogExample_Button_text")) .onClick(() => { - this.controller.close(); + if (this.controller !== undefined) { + this.controller.close(); + } }) .backgroundColor($r("app.color.CustomDialogExample_Button_backgroundColor_FFFFFF")) .fontSize($r("sys.float.ohos_id_text_size_button1")) @@ -647,7 +695,9 @@ struct CustomDialogExampleSystem { Button($r("app.string.CustomDialogExample_Button_off")) .onClick(() => { this.sysInfoPresenter.setSystemCertificateStatus(this.sysInfoPresenter.certInfo.uri, false); - this.controller.close(); + if (this.controller !== undefined) { + this.controller.close(); + } }) .backgroundColor($r("app.color.CustomDialogExample_Button_backgroundColor_FFFFFF")) .fontSize($r("sys.float.ohos_id_text_size_button1")) @@ -658,7 +708,9 @@ struct CustomDialogExampleSystem { Button($r("app.string.CustomDialogExample_Button_on")) .onClick(() => { this.sysInfoPresenter.setSystemCertificateStatus(this.sysInfoPresenter.certInfo.uri, true); - this.controller.close(); + if (this.controller !== undefined) { + this.controller.close(); + } }) .backgroundColor($r("app.color.CustomDialogExample_Button_backgroundColor_FFFFFF")) .fontSize($r("sys.float.ohos_id_text_size_button1")) @@ -706,11 +758,11 @@ struct CustomDialogExampleSystem { @Component struct ComponentSystem { - private certAlias: string; - private subjectName: string; - private Status: boolean; - private Index : number; - private Uri: string; + private certAlias: string = ''; + private subjectName: string = ''; + private Status: boolean = false; + private Index : number = 0; + private Uri: string = ''; isSwitchTouched : boolean = false; @State isTouched: boolean = false; @Link setStatus: CmShowSysCaPresenter; @@ -766,10 +818,10 @@ struct ComponentSystem { @Component struct ComponentUser { - private certAlias: string; - private subjectName: string; + private certAlias: string = ''; + private subjectName: string = ''; private Index : number = -1; - private Uri: string; + private Uri: string = ''; @State StatusText : Resource = $r("app.string.CustomDialogExampleUser_Status_false"); @State isTouched: boolean = false; @Link setStatus: CMShowUserCaPresenter; @@ -901,13 +953,13 @@ struct TrustedEvidence { } onPageShow() { - let uri = globalThis.abilityWant.uri; - globalThis.abilityWant.uri = ""; + let uri = GlobalContext.getContext().getAbilityWant().uri; + GlobalContext.getContext().clearAbilityWantUri(); if (uri === "certInstall") { this.mFaPresenter.startInstall(); } else if (uri === "requestAuthorize") { - this.mFaPresenter.startRequestAuth(globalThis.abilityWant.parameters.appUid); + this.mFaPresenter.startRequestAuth( GlobalContext.getContext().getAbilityWant().parameters?.appUid as string); } } @@ -928,12 +980,12 @@ struct TrustedEvidence { Stack({ alignContent: Alignment.End }) { Scroll(this.sysCaScroller) { List() { - ForEach(this.mShowSysCaPresenter.certList, (item, index) => { + ForEach(this.mShowSysCaPresenter.certList, (item: CertAbstractVo, index) => { ListItem() { - ComponentSystem({ certAlias: item.certAlias, subjectName: item.subjectNameCN, Status: item.status, - Uri: item.uri, setStatus: $mShowSysCaPresenter, Index: index }) + ComponentSystem({ certAlias: item.certAlias, subjectName: item.subjectNameCN, + Status: item.status, Uri: item.uri, setStatus: $mShowSysCaPresenter, Index: index }) } - }, item => JSON.stringify(item)) + }, (item: CertAbstractVo) => JSON.stringify(item)) } .scrollBar(BarState.Off) .padding({ @@ -958,7 +1010,8 @@ struct TrustedEvidence { }) .borderRadius($r("app.float.user_list_divider_borderRadius_value")) .backgroundColor($r("app.color.user_list_backgroundColor_FFFFFF")) - ScrollBar({ scroller: this.sysCaScroller, direction: ScrollBarDirection.Vertical, state: BarState.Auto}) { + ScrollBar({ scroller: this.sysCaScroller, direction: ScrollBarDirection.Vertical, + state: BarState.Auto}) { Text() .width($r("app.float.wh_value_3")) .height($r("app.float.wh_value_50")) @@ -974,12 +1027,14 @@ struct TrustedEvidence { } } .tabBar(this.TabBuilder(0)) - .onTouch((event: TouchEvent) => { - if (event.type === TouchType.Down) { - this.isTouched = true; - } - if (event.type === TouchType.Up) { - this.isTouched = false; + .onTouch((event?: TouchEvent) => { + if (event !== undefined) { + if (event.type === TouchType.Down) { + this.isTouched = true; + } + if (event.type === TouchType.Up) { + this.isTouched = false; + } } }); @@ -987,12 +1042,12 @@ struct TrustedEvidence { Stack({ alignContent: Alignment.End }) { Scroll(this.userCaScroller) { List() { - ForEach(this.mShowUserCaPresenter.certList, (item, index) => { + ForEach(this.mShowUserCaPresenter.certList, (item: CertAbstractVo, index) => { ListItem() { ComponentUser({ certAlias: item.certAlias, subjectName: item.subjectNameCN, Uri: item.uri, setStatus: $mShowUserCaPresenter, Index: index }) } - }, item => JSON.stringify(item)) + }, (item: CertAbstractVo) => JSON.stringify(item)) } .scrollBar(BarState.Off) .padding({ @@ -1017,7 +1072,8 @@ struct TrustedEvidence { }) .borderRadius($r("app.float.user_list_divider_borderRadius_value")) .backgroundColor($r("app.color.user_list_backgroundColor_FFFFFF")) - ScrollBar({ scroller: this.userCaScroller, direction: ScrollBarDirection.Vertical, state: BarState.Auto}) { + ScrollBar({ scroller: this.userCaScroller, direction: ScrollBarDirection.Vertical, + state: BarState.Auto}) { Text() .width($r("app.float.wh_value_3")) .height($r("app.float.wh_value_50")) @@ -1033,12 +1089,14 @@ struct TrustedEvidence { } } .tabBar(this.TabBuilder(1)) - .onTouch((event: TouchEvent) => { - if (event.type === TouchType.Down) { - this.isTouched = true; - } - if (event.type === TouchType.Up) { - this.isTouched = false; + .onTouch((event?: TouchEvent) => { + if (event !== undefined) { + if (event.type === TouchType.Down) { + this.isTouched = true; + } + if (event.type === TouchType.Up) { + this.isTouched = false; + } } }); } diff --git a/CertificateManager/product/phone/src/main/ets/presenter/CmAppCredAuthPresenter.ets b/CertificateManager/product/phone/src/main/ets/presenter/CmAppCredAuthPresenter.ets index 7a15aff..054914c 100644 --- a/CertificateManager/product/phone/src/main/ets/presenter/CmAppCredAuthPresenter.ets +++ b/CertificateManager/product/phone/src/main/ets/presenter/CmAppCredAuthPresenter.ets @@ -16,8 +16,12 @@ import certManagerModel from '../model/CertMangerModel'; import BundleModel from '../model/BundleModel'; import { CMModelErrorCode, CMModelOptType } from '../model/CertMangerModel'; -import type { CredentialAbstractVo } from '../model/CertManagerVo/CredentialAbstractVo'; +import { CredentialAbstractVo } from '../model/CertManagerVo/CredentialAbstractVo'; import router from '@system.router'; +import { GlobalContext } from '../common/GlobalContext'; +import { AppInfoVo } from '../model/CertManagerVo/AppInfoVo'; +import { BusinessError } from '@ohos.base'; +import Common from '@ohos.app.ability.common' const TAG = 'CMAppCredAuthPresenter Presenter: '; const SUCCESS = 0; @@ -45,10 +49,10 @@ export default class CmAppCredAuthPresenter { this.credList = []; } - updateAppNameFromUid(uid): void { + updateAppNameFromUid(uid: string): void { try { console.log('getAppNameFromUid start uid = ' + uid); - BundleModel.getAppInfoList(Number(uid), (errCode, appInfo) => { + BundleModel.getAppInfoList(Number(uid), (errCode: CMModelErrorCode, appInfo: AppInfoVo) => { if (errCode === CMModelErrorCode.CM_MODEL_ERROR_SUCCESS) { this.appName = appInfo.appName; console.log('getAppNameFromUid success, appName = ' + this.appName); @@ -57,41 +61,54 @@ export default class CmAppCredAuthPresenter { } }); } catch (err) { - console.error('updateAppNameFromUid failed'); + let e: BusinessError = err as BusinessError; + console.error('updateAppNameFromUid failed with err, message: ' + e.message + ', code: ' + e.code); } } updateAppCredList(): void { - certManagerModel.getCertOrCredList(CMModelOptType.CM_MODEL_OPT_APP_CRED, (errCode, credList) => { + certManagerModel.getCertOrCredList(CMModelOptType.CM_MODEL_OPT_APP_CRED, + (errCode: CMModelErrorCode, credList: Array) => { if (errCode === CMModelErrorCode.CM_MODEL_ERROR_SUCCESS) { this.credList = credList; - console.log('updateSystemTrustedCertificateList inin :' + JSON.stringify(credList)); + console.log('updateSystemTrustedCertificateList success, list: ' + JSON.stringify(credList)); } else { - console.log('updateSystemTrustedCertificateList fail'); + console.error('updateSystemTrustedCertificateList failed'); } }); } - requestAuthorize(uri, appUid): void { + requestAuthorize(uri: string, appUid: string): void { console.log(TAG + 'requestAuthorize start uri :' + uri + 'appUid: ' + appUid); - let want = globalThis.abilityWant; + let want = GlobalContext.getContext().getAbilityWant(); certManagerModel.setAppAuth(CMModelOptType.CM_MODEL_OPT_APP_CRED, uri, appUid, - true, (errCode, data) => { + true, (errCode: CMModelErrorCode, data: string) => { router.clear(); if (errCode === CMModelErrorCode.CM_MODEL_ERROR_SUCCESS) { console.log('requestAuthorize success data: ' + data); - want.parameters.authUri = data; - globalThis.certManagerAbilityContext.terminateSelfWithResult({ - resultCode: SUCCESS, - want: want - }); + if (want.parameters != undefined) { + want.parameters.authUri = data; + let ret1: Common.AbilityResult = { + resultCode: SUCCESS, + want: want + }; + GlobalContext.getContext().getCmContext().terminateSelfWithResult(ret1); + } else { + let ret2: Common.AbilityResult = { + resultCode: FAIL, + want: want + }; + console.error(TAG + 'requestAuthorize failed, undefined'); + GlobalContext.getContext().getCmContext().terminateSelfWithResult(ret2); + } } else { - console.log('requestAuthorize fail'); - globalThis.certManagerAbilityContext.terminateSelfWithResult({ + console.error('requestAuthorize fail'); + let ret3: Common.AbilityResult = { resultCode: FAIL, want: want - }); + }; + GlobalContext.getContext().getCmContext().terminateSelfWithResult(ret3); } }); } @@ -99,9 +116,10 @@ export default class CmAppCredAuthPresenter { cancelProcess(): void { console.log('cancelProcess start'); router.clear(); - globalThis.certManagerAbilityContext.terminateSelfWithResult({ + let ret: Common.AbilityResult = { resultCode: FAIL, - want: globalThis.abilityWant - }); + want: GlobalContext.getContext().getAbilityWant() + }; + GlobalContext.getContext().getCmContext().terminateSelfWithResult(ret); } } \ No newline at end of file diff --git a/CertificateManager/product/phone/src/main/ets/presenter/CmFaPresenter.ets b/CertificateManager/product/phone/src/main/ets/presenter/CmFaPresenter.ets index 80cb525..0de401d 100644 --- a/CertificateManager/product/phone/src/main/ets/presenter/CmFaPresenter.ets +++ b/CertificateManager/product/phone/src/main/ets/presenter/CmFaPresenter.ets @@ -18,6 +18,7 @@ import router from '@system.router'; import certManagerModel from '../model/CertMangerModel'; import FileIoModel from '../model/FileIoModel'; import { CMModelErrorCode, CMModelOptType } from '../model/CertMangerModel'; +import { BusinessError } from '@ohos.base'; const TAG = 'CMFaPresenter: '; const PAGE_URI_PWD_INPUT = 'pages/certPwdInput'; @@ -42,8 +43,8 @@ export default class CmFaPresenter { routeToNext(fileUri: string): void { console.info(TAG + 'routeToNext fileUri: ' + fileUri); - FileIoModel.getMediaFileSuffix(fileUri, (suffix) => { - if (suffix) { + FileIoModel.getMediaFileSuffix(fileUri, (suffix: string | undefined) => { + if (suffix !== undefined) { if ((suffix === 'cer') || (suffix === 'pem')) { router.push({ uri: PAGE_URI_ALIAS_INPUT, @@ -76,15 +77,16 @@ export default class CmFaPresenter { } else { console.error(TAG + 'documentPicker.select length invalid:' + documentSelectResult.length); } - }).catch((err) => { - console.error(TAG + 'documentPicker.select failed with err:' + err); + }).catch((err: BusinessError) => { + console.error(TAG + 'documentPicker.select failed with err, message: ' + err.message + ', code: ' + err.code); }); } catch (err) { - console.error(TAG + 'DocumentViewPicker failed with err:' + err); + let e: BusinessError = err as BusinessError; + console.error(TAG + 'DocumentViewPicker failed with err, message: ' + e.message + ', code: ' + e.code); } } - startRequestAuth(uri): void { + startRequestAuth(uri: string): void { router.replace({ uri: 'pages/requestAuth', params: { appUid: uri, @@ -93,19 +95,19 @@ export default class CmFaPresenter { } uninstallAllCert(): void { - certManagerModel.delAllCertOrCred(CMModelOptType.CM_MODEL_OPT_USER_CA, (errCode) => { + certManagerModel.delAllCertOrCred(CMModelOptType.CM_MODEL_OPT_USER_CA, (errCode: CMModelErrorCode) => { if (errCode === CMModelErrorCode.CM_MODEL_ERROR_SUCCESS) { console.log(TAG + 'uninstallAllCert CM_MODEL_OPT_USER_CA success'); } else { - console.log(TAG + 'uninstallAllCert CM_MODEL_OPT_USER_CA failed'); + console.error(TAG + 'uninstallAllCert CM_MODEL_OPT_USER_CA failed'); } }); - certManagerModel.delAllCertOrCred(CMModelOptType.CM_MODEL_OPT_APP_CRED, (errCode) => { + certManagerModel.delAllCertOrCred(CMModelOptType.CM_MODEL_OPT_APP_CRED, (errCode: CMModelErrorCode) => { if (errCode === CMModelErrorCode.CM_MODEL_ERROR_SUCCESS) { console.log(TAG + 'uninstallAllCert CM_MODEL_OPT_APP_CRED success'); } else { - console.log(TAG + 'uninstallAllCert CM_MODEL_OPT_APP_CRED failed'); + console.error(TAG + 'uninstallAllCert CM_MODEL_OPT_APP_CRED failed'); } }); } diff --git a/CertificateManager/product/phone/src/main/ets/presenter/CmInstallPresenter.ets b/CertificateManager/product/phone/src/main/ets/presenter/CmInstallPresenter.ets index b394ee9..0e034c3 100644 --- a/CertificateManager/product/phone/src/main/ets/presenter/CmInstallPresenter.ets +++ b/CertificateManager/product/phone/src/main/ets/presenter/CmInstallPresenter.ets @@ -17,6 +17,7 @@ import certManagerModel from '../model/CertMangerModel'; import FileIoModel from '../model/FileIoModel'; import { CMModelErrorCode, CMModelOptType } from '../model/CertMangerModel'; import router from '@system.router'; +import { GlobalContext } from '../common/GlobalContext'; const TAG = 'CMInstallPresenter: '; @@ -39,7 +40,7 @@ export default class CmInstallPresenter { this.optType = CMModelOptType.CM_MODEL_OPT_UNKNOWN; } - updateCertFileType(suffix): void { + updateCertFileType(suffix: string): void { console.info(TAG + 'updateCertFileType suffix: ' + suffix); if ((suffix === 'cer') || (suffix === 'pem')) { this.optType = CMModelOptType.CM_MODEL_OPT_USER_CA; @@ -48,23 +49,24 @@ export default class CmInstallPresenter { } } - getFileDataFromUri(uri, callback): void { - FileIoModel.getMediaFileData(uri, (data) => { + getFileDataFromUri(uri: string, callback: Function): void { + FileIoModel.getMediaFileData(uri, (data: Uint8Array) => { callback(data); }); } - installCert(uri, alias, suffix): void { + installCert(uri: string, alias: string, suffix: string): void { this.updateCertFileType(suffix); - this.getFileDataFromUri(uri, (data) => { - certManagerModel.installCertOrCred(this.optType, alias, data, globalThis.PwdStore.getCertPwd(), (errCode) => { + this.getFileDataFromUri(uri, (data: Uint8Array) => { + certManagerModel.installCertOrCred(this.optType, alias, data, + GlobalContext.getContext().getPwdStore().getCertPwd(), (errCode: CMModelErrorCode) => { console.info(TAG + 'installCertOrCred result: ' + JSON.stringify(errCode)); - globalThis.PwdStore.clearCertPwd(); + GlobalContext.getContext().getPwdStore().clearCertPwd(); if (errCode === CMModelErrorCode.CM_MODEL_ERROR_SUCCESS) { console.info(TAG + 'installCert success'); } else { - console.info(TAG + 'installCert failed'); + console.error(TAG + 'installCert failed'); } router.clear(); router.replace({ uri: 'pages/certManagerFa' }); diff --git a/CertificateManager/product/phone/src/main/ets/presenter/CmShowAppCredPresenter.ets b/CertificateManager/product/phone/src/main/ets/presenter/CmShowAppCredPresenter.ets index 2dc59ce..bad3f12 100644 --- a/CertificateManager/product/phone/src/main/ets/presenter/CmShowAppCredPresenter.ets +++ b/CertificateManager/product/phone/src/main/ets/presenter/CmShowAppCredPresenter.ets @@ -16,15 +16,17 @@ import certManagerModel from '../model/CertMangerModel'; import bundleModel from '../model/BundleModel'; import { CMModelErrorCode, CMModelOptType } from '../model/CertMangerModel'; -import type { CredentialAbstractVo } from '../model/CertManagerVo/CredentialAbstractVo'; +import { CredentialAbstractVo } from '../model/CertManagerVo/CredentialAbstractVo'; import { CredentialVo } from '../model/CertManagerVo/CredentialVo'; import { AppAuthorVo } from '../model/CertManagerVo/AppAuthorVo'; +import { AppInfoVo } from '../model/CertManagerVo/AppInfoVo'; +import { BusinessError } from '@ohos.base'; export default class CmShowAppCredPresenter { private static sInstance: CmShowAppCredPresenter; credList: CredentialAbstractVo[] = []; appInfoList: AppAuthorVo[] = []; - credInfo: CredentialVo = new CredentialVo('', '', '', 0, 0, null); + credInfo: CredentialVo = new CredentialVo('', '', '', 0, 0, new Uint8Array()); public static getInstance(): CmShowAppCredPresenter { if (CmShowAppCredPresenter.sInstance == null) { @@ -35,12 +37,13 @@ export default class CmShowAppCredPresenter { aboutToDisappear(): void { this.credList = []; - this.credInfo = new CredentialVo('', '', '', 0, 0, null); + this.credInfo = new CredentialVo('', '', '', 0, 0, new Uint8Array()); this.appInfoList = []; } - updateAppCredListCallback(callback): void { - certManagerModel.getCertOrCredList(CMModelOptType.CM_MODEL_OPT_APP_CRED, (errCode, credList) => { + updateAppCredListCallback(callback: Function): void { + certManagerModel.getCertOrCredList(CMModelOptType.CM_MODEL_OPT_APP_CRED, + (errCode: CMModelErrorCode, credList: Array) => { if (errCode === CMModelErrorCode.CM_MODEL_ERROR_SUCCESS) { credList.sort((certAbs, certAbsOther): number => { let certAlias = certAbs.alias; @@ -54,7 +57,7 @@ export default class CmShowAppCredPresenter { this.credList = credList; callback(); } else { - console.log('updateAppCredList error :' + JSON.stringify(errCode)); + console.error('updateAppCredList error :' + JSON.stringify(errCode)); this.credList = []; callback(); } @@ -62,7 +65,8 @@ export default class CmShowAppCredPresenter { } updateAppCredList(): void { - certManagerModel.getCertOrCredList(CMModelOptType.CM_MODEL_OPT_APP_CRED, (errCode, credList) => { + certManagerModel.getCertOrCredList(CMModelOptType.CM_MODEL_OPT_APP_CRED, + (errCode: CMModelErrorCode, credList: Array) => { if (errCode === CMModelErrorCode.CM_MODEL_ERROR_SUCCESS) { credList.sort((certAbs, certAbsOther): number => { let certAlias = certAbs.alias; @@ -75,40 +79,42 @@ export default class CmShowAppCredPresenter { }); this.credList = credList; } else { - console.log('updateAppCredList error :' + JSON.stringify(errCode)); + console.error('updateAppCredList error :' + JSON.stringify(errCode)); this.credList = []; } }); } - getAppCred(uri, callback): void { - certManagerModel.getCertOrCred(CMModelOptType.CM_MODEL_OPT_APP_CRED, uri, (errCode, credInfo) => { + getAppCred(uri: string, callback: Function): void { + certManagerModel.getCertOrCred(CMModelOptType.CM_MODEL_OPT_APP_CRED, uri, + (errCode: CMModelErrorCode, credInfo: CredentialVo) => { if (errCode === CMModelErrorCode.CM_MODEL_ERROR_SUCCESS) { this.credInfo = credInfo; } else { - console.log('getAppCred error :' + JSON.stringify(errCode)); + console.error('getAppCred error :' + JSON.stringify(errCode)); this.credInfo.clearCredentialVo(); } callback(); }); } - deleteAppCred(uri): void { - certManagerModel.deleteCertOrCred(CMModelOptType.CM_MODEL_OPT_APP_CRED, uri, (errCode) => { + deleteAppCred(uri: string): void { + certManagerModel.deleteCertOrCred(CMModelOptType.CM_MODEL_OPT_APP_CRED, uri, (errCode: CMModelErrorCode) => { if (errCode === CMModelErrorCode.CM_MODEL_ERROR_SUCCESS) { this.updateAppCredList(); } else { - console.log('deleteAppCred error :' + JSON.stringify(errCode)); + console.error('deleteAppCred error :' + JSON.stringify(errCode)); } }); } - getAuthorizedAppList(uri): void { + getAuthorizedAppList(uri: string): void { this.appInfoList = []; - certManagerModel.getAuthAppList(CMModelOptType.CM_MODEL_OPT_APP_CRED, uri, (errCode, appUidList) => { + certManagerModel.getAuthAppList(CMModelOptType.CM_MODEL_OPT_APP_CRED, uri, + (errCode: CMModelErrorCode, appUidList: Array) => { if (errCode === CMModelErrorCode.CM_MODEL_ERROR_SUCCESS) { for (let i = 0; i < appUidList.length; i++) { - bundleModel.getAppInfoList(Number(appUidList[i]), (errCode, appInfo) => { + bundleModel.getAppInfoList(Number(appUidList[i]), (errCode: CMModelErrorCode, appInfo: AppInfoVo) => { if (errCode === CMModelErrorCode.CM_MODEL_ERROR_SUCCESS) { this.appInfoList.push( new AppAuthorVo(String(appInfo.appImage), String(appUidList[i]), String(appInfo.appName), true)); @@ -117,13 +123,13 @@ export default class CmShowAppCredPresenter { }); } } else { - console.log('getAuthorizedAppList error :' + JSON.stringify(errCode)); + console.error('getAuthorizedAppList error :' + JSON.stringify(errCode)); this.appInfoList = []; } }); } - async removeGrantedAppList(uri): Promise { + async removeGrantedAppList(uri: string): Promise { console.log('enter removeGrantedAppList'); for (let i = 0; i < this.appInfoList.length; i++) { if (!this.appInfoList[i].status) { @@ -132,7 +138,8 @@ export default class CmShowAppCredPresenter { this.appInfoList[i].uid, false); console.log('removeGrantedAppList succeed' + JSON.stringify(res)); } catch (error) { - console.log('removeGrantedAppList error :' + JSON.stringify(error)); + let e: BusinessError = error as BusinessError; + console.error('removeGrantedAppList error, message: ' + e.message + ', code: ' + e.code); } } } diff --git a/CertificateManager/product/phone/src/main/ets/presenter/CmShowPrivateCredPresenter.ets b/CertificateManager/product/phone/src/main/ets/presenter/CmShowPrivateCredPresenter.ets index 0444164..4805781 100644 --- a/CertificateManager/product/phone/src/main/ets/presenter/CmShowPrivateCredPresenter.ets +++ b/CertificateManager/product/phone/src/main/ets/presenter/CmShowPrivateCredPresenter.ets @@ -15,13 +15,13 @@ import certManagerModel from '../model/CertMangerModel'; import { CMModelErrorCode, CMModelOptType } from '../model/CertMangerModel'; -import type { CredentialAbstractVo } from '../model/CertManagerVo/CredentialAbstractVo'; +import { CredentialAbstractVo } from '../model/CertManagerVo/CredentialAbstractVo'; import { CredentialVo } from '../model/CertManagerVo/CredentialVo'; export default class CmShowPrivateCredPresenter { private static sInstance: CmShowPrivateCredPresenter; credList: CredentialAbstractVo[] = []; - credInfo: CredentialVo = new CredentialVo('', '', '', 0, 0, null); + credInfo: CredentialVo = new CredentialVo('', '', '', 0, 0, new Uint8Array()); public static getInstance(): CmShowPrivateCredPresenter { if (CmShowPrivateCredPresenter.sInstance == null) { @@ -32,11 +32,12 @@ export default class CmShowPrivateCredPresenter { aboutToDisappear(): void { this.credList = []; - this.credInfo = new CredentialVo('', '', '', 0, 0, null); + this.credInfo = new CredentialVo('', '', '', 0, 0, new Uint8Array()); } updatePrivateCredList(): void { - certManagerModel.getCertOrCredList(CMModelOptType.CM_MODEL_OPT_PRIVATE_CRED, (errCode, credList) => { + certManagerModel.getCertOrCredList(CMModelOptType.CM_MODEL_OPT_PRIVATE_CRED, + (errCode: CMModelErrorCode, credList: Array) => { if (errCode === CMModelErrorCode.CM_MODEL_ERROR_SUCCESS) { credList.sort((certAbs, certAbsOther) => { let certAlias = certAbs.alias; @@ -49,18 +50,19 @@ export default class CmShowPrivateCredPresenter { }); this.credList = credList; } else { - console.log('updatePrivateCredList error :' + JSON.stringify(errCode)); + console.error('updatePrivateCredList error :' + JSON.stringify(errCode)); this.credList = []; } }); } - getPrivateCred(uri, callback): void { - certManagerModel.getCertOrCred(CMModelOptType.CM_MODEL_OPT_PRIVATE_CRED, uri, (errCode, credInfo) => { + getPrivateCred(uri: string, callback: Function): void { + certManagerModel.getCertOrCred(CMModelOptType.CM_MODEL_OPT_PRIVATE_CRED, uri, + (errCode: CMModelErrorCode, credInfo: CredentialVo) => { if (errCode === CMModelErrorCode.CM_MODEL_ERROR_SUCCESS) { this.credInfo = credInfo; } else { - console.log('getPrivateCred error :' + JSON.stringify(errCode)); + console.error('getPrivateCred error :' + JSON.stringify(errCode)); this.credInfo.clearCredentialVo(); } callback(); diff --git a/CertificateManager/product/phone/src/main/ets/presenter/CmShowSysCaPresenter.ets b/CertificateManager/product/phone/src/main/ets/presenter/CmShowSysCaPresenter.ets index 3d325fd..a1ef601 100644 --- a/CertificateManager/product/phone/src/main/ets/presenter/CmShowSysCaPresenter.ets +++ b/CertificateManager/product/phone/src/main/ets/presenter/CmShowSysCaPresenter.ets @@ -15,7 +15,7 @@ import certManagerModel from '../model/CertMangerModel'; import { CMModelErrorCode, CMModelOptType } from '../model/CertMangerModel'; -import type { CertAbstractVo } from '../model/CertManagerVo/CertAbstractVo'; +import { CertAbstractVo } from '../model/CertManagerVo/CertAbstractVo'; import { CertInfoVo } from '../model/CertManagerVo/CertInfoVo'; const TAG = 'CMShowSysCa Presenter: '; @@ -23,7 +23,8 @@ const TAG = 'CMShowSysCa Presenter: '; export default class CmShowSysCaPresenter { private static sInstance: CmShowSysCaPresenter; certList: CertAbstractVo[] = []; - certInfo: CertInfoVo = new CertInfoVo('', '', false, '', '', '', '', '', '', null, null, null, null); + certInfo: CertInfoVo = new CertInfoVo('', '', false, '', '', '', '', '', '', + new Uint8Array(), new Map(), new Map(), new Map()); public static getInstance(): CmShowSysCaPresenter { if (CmShowSysCaPresenter.sInstance == null) { @@ -38,11 +39,13 @@ export default class CmShowSysCaPresenter { aboutToDisappear(): void { this.certList = []; - this.certInfo = new CertInfoVo('', '', false, '', '', '', '', '', '', null, null, null, null); + this.certInfo = new CertInfoVo('', '', false, '', '', '', '', '', '', + new Uint8Array(), new Map(), new Map(), new Map()); } updateSystemTrustedCertificateList(): void { - certManagerModel.getCertOrCredList(CMModelOptType.CM_MODEL_OPT_SYSTEM_CA, (errCode, certList) => { + certManagerModel.getCertOrCredList(CMModelOptType.CM_MODEL_OPT_SYSTEM_CA, + (errCode: CMModelErrorCode, certList: Array) => { if (errCode === CMModelErrorCode.CM_MODEL_ERROR_SUCCESS) { certList.sort((certAbs, certAbsOther): number => { let certAlias = certAbs.certAlias; @@ -54,36 +57,38 @@ export default class CmShowSysCaPresenter { } }); this.certList = certList; - console.log('updateSystemTrustedCertificateList inin :' + JSON.stringify(certList)); + console.log('updateSystemTrustedCertificateList success, list: ' + JSON.stringify(certList)); } else { - console.info(TAG + 'updateSystemTrustedCertificateList fail,errCode is' + errCode); + console.error(TAG + 'updateSystemTrustedCertificateList fail,errCode is' + errCode); this.certList = []; } }); } - getSystemTrustedCertificate(uri, callback): void { - certManagerModel.getCertOrCred(CMModelOptType.CM_MODEL_OPT_SYSTEM_CA, uri, (errCode, certInfo) => { + getSystemTrustedCertificate(uri: string, callback: Function): void { + certManagerModel.getCertOrCred(CMModelOptType.CM_MODEL_OPT_SYSTEM_CA, uri, + (errCode: CMModelErrorCode, certInfo: CertInfoVo) => { if (errCode === CMModelErrorCode.CM_MODEL_ERROR_SUCCESS) { console.info(TAG + 'getSystemTrustedCertificate success,errCode is ' + errCode + ' certInfo is' + JSON.stringify(certInfo)); this.certInfo = certInfo; callback(); } else { - console.info(TAG + 'getSystemTrustedCertificate fail,errCode is' + errCode); + console.error(TAG + 'getSystemTrustedCertificate fail,errCode is' + errCode); this.certInfo.clearCertInfoVo(); callback(); } }); } - setSystemCertificateStatus(uri, status): void { - certManagerModel.setCertStatus(CMModelOptType.CM_MODEL_OPT_SYSTEM_CA, uri, status, (errCode) => { + setSystemCertificateStatus(uri: string, status: boolean): void { + certManagerModel.setCertStatus(CMModelOptType.CM_MODEL_OPT_SYSTEM_CA, uri, status, + (errCode: CMModelErrorCode) => { if (errCode === CMModelErrorCode.CM_MODEL_ERROR_SUCCESS) { console.info(TAG + 'setSystemCertificateStatus success,errCode is' + errCode); this.updateSystemTrustedCertificateList(); } else { - console.info(TAG + 'setSystemCertificateStatus fail,errCode is' + errCode); + console.error(TAG + 'setSystemCertificateStatus fail,errCode is' + errCode); } }); } diff --git a/CertificateManager/product/phone/src/main/ets/presenter/CmShowUserCaPresenter.ets b/CertificateManager/product/phone/src/main/ets/presenter/CmShowUserCaPresenter.ets index 8a3711d..6a22c1f 100644 --- a/CertificateManager/product/phone/src/main/ets/presenter/CmShowUserCaPresenter.ets +++ b/CertificateManager/product/phone/src/main/ets/presenter/CmShowUserCaPresenter.ets @@ -15,7 +15,7 @@ import certManagerModel from '../model/CertMangerModel'; import { CMModelErrorCode, CMModelOptType } from '../model/CertMangerModel'; -import type { CertAbstractVo } from '../model/CertManagerVo/CertAbstractVo'; +import { CertAbstractVo } from '../model/CertManagerVo/CertAbstractVo'; import { CertInfoVo } from '../model/CertManagerVo/CertInfoVo'; const TAG = 'CMFaShowUserCa Presenter: '; @@ -23,7 +23,8 @@ const TAG = 'CMFaShowUserCa Presenter: '; export default class CmShowUserCaPresenter { private static sInstance: CmShowUserCaPresenter; certList: CertAbstractVo[] = []; - certInfo: CertInfoVo = new CertInfoVo('', '', false, '', '', '', '', '', '', null, null, null, null); + certInfo: CertInfoVo = new CertInfoVo('', '', false, '', '', '', '', '', '', + new Uint8Array(), new Map(), new Map(), new Map()); public static getInstance(): CmShowUserCaPresenter { if (CmShowUserCaPresenter.sInstance == null) { @@ -38,11 +39,13 @@ export default class CmShowUserCaPresenter { aboutToDisappear(): void { this.certList = []; - this.certInfo = new CertInfoVo('', '', false, '', '', '', '', '', '', null, null, null, null); + this.certInfo = new CertInfoVo('', '', false, '', '', '', '', '', '', + new Uint8Array(), new Map(), new Map(), new Map()); } updateUserTrustedCertificateList(): void { - certManagerModel.getCertOrCredList(CMModelOptType.CM_MODEL_OPT_USER_CA, (errCode, certList) => { + certManagerModel.getCertOrCredList(CMModelOptType.CM_MODEL_OPT_USER_CA, + (errCode: CMModelErrorCode, certList: Array) => { if (errCode === CMModelErrorCode.CM_MODEL_ERROR_SUCCESS) { certList.sort((certAbs, certAbsOther): number => { let certAlias = certAbs.certAlias; @@ -54,47 +57,48 @@ export default class CmShowUserCaPresenter { } }); this.certList = certList; - console.log('updateUserTrustedCertificateList inin :' + JSON.stringify(certList)); + console.log('updateUserTrustedCertificateList success, list: ' + JSON.stringify(certList)); } else { - console.info(TAG + 'updateUserTrustedCertificateList fail,errCode is ' + errCode); + console.error(TAG + 'updateUserTrustedCertificateList fail,errCode is ' + errCode); this.certList = []; } }); } - getUserTrustedCertificate(uri, callback): void { - certManagerModel.getCertOrCred(CMModelOptType.CM_MODEL_OPT_USER_CA, uri, (errCode, certInfo) => { + getUserTrustedCertificate(uri: string, callback: Function): void { + certManagerModel.getCertOrCred(CMModelOptType.CM_MODEL_OPT_USER_CA, uri, + (errCode: CMModelErrorCode, certInfo: CertInfoVo) => { if (errCode === CMModelErrorCode.CM_MODEL_ERROR_SUCCESS) { console.info(TAG + 'getUserTrustedCertificate success, errCode is ' + errCode + ' certInfo is' + JSON.stringify(certInfo)); this.certInfo = certInfo; callback(); } else { - console.info(TAG + 'getUserTrustedCertificate fail, errCode is ' + errCode); + console.error(TAG + 'getUserTrustedCertificate fail, errCode is ' + errCode); this.certInfo.clearCertInfoVo(); callback(); } }); } - setUserCertificateStatus(uri, status): void { - certManagerModel.setCertStatus(CMModelOptType.CM_MODEL_OPT_USER_CA, uri, status, (errCode) => { + setUserCertificateStatus(uri: string, status: boolean): void { + certManagerModel.setCertStatus(CMModelOptType.CM_MODEL_OPT_USER_CA, uri, status, (errCode: CMModelErrorCode) => { if (errCode === CMModelErrorCode.CM_MODEL_ERROR_SUCCESS) { this.getUserTrustedCertificate(uri, () => { console.info(TAG + 'setCerStatus then getUserTrustedCertificate,errCode is' + errCode); }); } else { - console.info(TAG + 'setUserCertificateStatus fail,errCode is ' + errCode); + console.error(TAG + 'setUserCertificateStatus fail,errCode is ' + errCode); } }); } - deleteUserCertificate(uri, callback): void { - certManagerModel.deleteCertOrCred(CMModelOptType.CM_MODEL_OPT_USER_CA, uri, (errCode) => { + deleteUserCertificate(uri: string, callback: Function): void { + certManagerModel.deleteCertOrCred(CMModelOptType.CM_MODEL_OPT_USER_CA, uri, (errCode: CMModelErrorCode) => { if (errCode === CMModelErrorCode.CM_MODEL_ERROR_SUCCESS) { this.updateUserTrustedCertificateList(); } else { - console.info(TAG + 'deleteUserCertificate fail,errCode is ' + errCode); + console.error(TAG + 'deleteUserCertificate fail,errCode is ' + errCode); } callback(); });