1/** 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import deviceAttest from '@ohos.deviceAttest' 17import ConfigData from '../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData'; 18import HeadComponent from '../../../../../../common/component/src/main/ets/default/headComponent'; 19import LogUtil from '../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil'; 20import { BusinessError } from '@ohos.base'; 21 22const MODULE_TAG = ConfigData.TAG + '.compatibilityAssessment -> '; 23/** 24 * Compatibility Assessment 25 */ 26@Entry 27@Component 28struct compatibilityAssessment { 29 @State assessmentImage: string = ""; 30 @State assessmentResult: string = "" 31 @State assessmentResultText: string = "" 32 @State assessmentIntroduction: string = "" 33 build() { 34 Column() { 35 GridContainer({ gutter: ConfigData.GRID_CONTAINER_GUTTER_24, margin: ConfigData.GRID_CONTAINER_MARGIN_24 }) { 36 Column() { 37 HeadComponent({ headName: $r("app.string.OpenHarmony_Compatibility_Assessment"), isActive: true }); 38 Column() { 39 Image(this.assessmentImage) 40 .height($r("app.float.wh_value_64")) 41 .width($r("app.float.wh_value_64")) 42 .margin({top: $r("app.float.wh_value_32")}) 43 Text(this.assessmentResult) 44 .fontFamily('HarmonyHeiTi') 45 .fontSize($r("app.float.font_20")) 46 .fontColor($r("sys.color.ohos_id_color_primary")) 47 .fontWeight(FontWeight.Medium) 48 .margin({ 49 top: $r("app.float.wh_value_8"), 50 }) 51 Text(this.assessmentResultText) 52 .fontFamily('HarmonyHeiTi') 53 .fontSize($r("app.float.font_14")) 54 .fontColor($r('sys.color.ohos_id_color_text_secondary')) 55 .fontWeight(FontWeight.Medium) 56 .margin({ 57 top: $r("app.float.wh_value_4") 58 }) 59 .align(Alignment.Center) 60 Column() { 61 Text(this.assessmentIntroduction) 62 .fontFamily('HarmonyHeiTi') 63 .fontSize($r("app.float.font_14")) 64 .fontWeight(FontWeight.Medium) 65 .lineHeight("app.float.lineHeight_19") 66 .padding({ 67 top:$r('app.float.wh_value_12'), 68 left:$r('app.float.wh_value_12'), 69 right:$r('app.float.wh_value_12'), 70 bottom:$r('app.float.wh_value_18') 71 }) 72 .fontColor($r('sys.color.ohos_id_color_text_secondary')) 73 } 74 .align(Alignment.Start) 75 .borderRadius($r('app.float.radius_16')) 76 .backgroundColor($r("sys.color.ohos_id_color_foreground_contrary")) 77 .margin({ 78 top: $r("app.float.wh_value_24"), 79 }) 80 } 81 } 82 .useSizeType({ 83 sm: { span: 4, offset: 0 }, 84 md: { span: 6, offset: 1 }, 85 lg: { span: 8, offset: 2 } 86 }) 87 } 88 .width(ConfigData.WH_100_100) 89 .height(ConfigData.WH_100_100) 90 } 91 .backgroundColor($r("sys.color.ohos_id_color_sub_background")) 92 .width(ConfigData.WH_100_100) 93 .height(ConfigData.WH_100_100) 94 } 95 96 aboutToAppear(): void{ 97 this.assessmentIntroduction = JSON.parse(JSON.stringify($r("app.string.assessmentIntroduction"))) 98 try { 99 deviceAttest.getAttestStatus().then((attestResultInfo) => { 100 let authResult = attestResultInfo.authResult 101 let softwareResult = attestResultInfo.softwareResult 102 if(authResult == 0&&softwareResult == 0){ 103 this.assessmentResult = JSON.parse(JSON.stringify($r("app.string.assessmentPassed"))) 104 this.assessmentImage = '/res/image/assessmentPassed-light.svg' 105 this.assessmentResultText = JSON.parse(JSON.stringify($r("app.string.assessmentPassedText"))) 106 }else if(authResult == -2&&softwareResult == -2){ 107 this.assessmentResult =JSON.parse(JSON.stringify($r("app.string.assessmentQueryFailed"))) 108 this.assessmentImage = '/res/image/assessmentQueryFailed-light.svg' 109 this.assessmentResultText = JSON.parse(JSON.stringify($r("app.string.assessmentQueryFailedText"))) 110 }else{ 111 this.assessmentResult =JSON.parse(JSON.stringify($r("app.string.assessmentPassFailed"))) 112 this.assessmentImage = '/res/image/assessmentPassFailed-light.svg' 113 this.assessmentResultText = JSON.parse(JSON.stringify($r("app.string.assessmentPassFailedText"))) 114 } 115 LogUtil.info(MODULE_TAG + "attestResultInfo success"+JSON.stringify(attestResultInfo)); 116 }) 117 .catch((error: BusinessError) => { 118 this.assessmentResult =JSON.parse(JSON.stringify($r("app.string.assessmentQueryFailed"))) 119 this.assessmentImage = '/res/image/assessmentQueryFailed-light.svg' 120 this.assessmentResultText = JSON.parse(JSON.stringify($r("app.string.assessmentQueryFailedText"))) 121 LogUtil.info(MODULE_TAG + "assessmentQueryFailed"+error); 122 }); 123 }catch (error){ 124 this.assessmentResult =JSON.parse(JSON.stringify($r("app.string.assessmentQueryFailed"))) 125 this.assessmentImage = '/res/image/assessmentQueryFailed-light.svg' 126 this.assessmentResultText = JSON.parse(JSON.stringify($r("app.string.assessmentQueryFailedText"))) 127 LogUtil.info(MODULE_TAG + "assessmentQueryFailed"+error); 128 } 129 } 130 131}