1/* 2 * Copyright (c) 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 bundle from '@ohos.bundle.bundleManager'; 17import baseData from '../../../common/baseData' 18import logger from '../../../common/logger' 19import resetFactory from '../../../common/resetFactory' 20import utils from '../../../common/utils' 21import Want from '@ohos.app.ability.Want'; 22import common from '@ohos.app.ability.common'; 23 24const TAG = 'DoubleButtonComponent'; 25 26@Component 27export default struct DoubleButtonComponent { 28 private nextFlag: boolean = false; 29 private returnDialogFlag: boolean = true; 30 @StorageLink('manageBundleName') nextBundleName: string = ''; 31 buttonDialog: CustomDialogController = new CustomDialogController({ 32 builder: DialogButtonLayout(), 33 autoCancel: false, 34 alignment: DialogAlignment.Center, 35 gridCount: 4, 36 }) 37 38 build() { 39 Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { 40 Row() { 41 Image($r('app.media.ic_public_arrow_left')) 42 .width($r('app.float.wh_value_24')) 43 .height($r('app.float.wh_value_24')) 44 .margin({ 45 right: $r('app.float.wh_value_8') 46 }) 47 .objectFit(ImageFit.Contain) 48 49 Text($r('app.string.returnVal')) 50 .fontSize($r('app.float.font_vp_16')) 51 .fontFamily('HarmonyHeiTi') 52 .fontWeight(FontWeight.Medium) 53 .lineHeight($r('app.float.lineHeight_vp_22')) 54 .textAlign(TextAlign.Start) 55 .onClick(() => { 56 if (this.returnDialogFlag) { 57 this.buttonDialog.open(); 58 } else { 59 (getContext(this) as common.UIAbilityContext).terminateSelf(); 60 } 61 }) 62 } 63 .justifyContent(FlexAlign.Center) 64 .align(Alignment.Start) 65 66 Row() { 67 Text($r('app.string.nextVal')) 68 .fontSize($r('app.float.font_vp_16')) 69 .fontFamily('HarmonyHeiTi') 70 .fontWeight(FontWeight.Medium) 71 .lineHeight($r('app.float.lineHeight_vp_22')) 72 .textAlign(TextAlign.End) 73 .visibility(this.nextFlag ? Visibility.None : Visibility.Visible) 74 .onClick(() => { 75 this.startSpecificActionAbility(); 76 }) 77 78 Image($r('app.media.ic_public_arrow_right')) 79 .width($r('app.float.wh_value_24')) 80 .height($r('app.float.wh_value_24')) 81 .margin({ 82 left: $r('app.float.wh_value_8') 83 }) 84 .visibility(this.nextFlag ? Visibility.None : Visibility.Visible) 85 .objectFit(ImageFit.Contain) 86 } 87 .justifyContent(FlexAlign.Center) 88 .align(Alignment.End) 89 } 90 .width('100%') 91 .height('48vp') 92 } 93 94 async startSpecificActionAbility() { 95 let actionVal = 'ohos.action.ENTERPRISE_DEVICE_ADMIN_POLICY_COMPLIANCE'; 96 let queryWant: Want = { action: actionVal, bundleName: this.nextBundleName }; 97 logger.info(TAG, 'startSpecificActionAbility startAbility in:'); 98 99 let data: bundle.AbilityInfo[] = []; 100 try { 101 data = await bundle.queryAbilityInfo(queryWant, bundle.AbilityFlag.GET_ABILITY_INFO_DEFAULT, 102 baseData.DEFAULT_USER_ID); 103 } catch (e) { 104 logger.error(TAG, 'startSpecificActionAbility queryAbilityByWant try fail! ' + JSON.stringify(e)); 105 } 106 107 if (utils.isValid(data) && data.length > 0) { 108 logger.info(TAG, 'startSpecificActionAbility data len=' + data.length + ' | data content=' + data[0].name) 109 try { 110 await (getContext(this) as common.UIAbilityContext).startAbility({ 111 bundleName: this.nextBundleName, 112 abilityName: data[0].name 113 }); 114 } catch (e) { 115 logger.error(TAG, 'startSpecificActionAbility startAbility fail! ' + e) 116 } 117 } 118 await (getContext(this) as common.UIAbilityContext).terminateSelf(); 119 } 120} 121 122@CustomDialog 123struct DialogButtonLayout { 124 controller?: CustomDialogController 125 126 build() { 127 Column() { 128 Column() { 129 Text($r('app.string.tips')) 130 .fontFamily('HarmonyHeiTi') 131 .fontWeight(FontWeight.Medium) 132 .lineHeight('28vp') 133 .fontSize('20vp') 134 .height('28vp') 135 .width('100%') 136 .margin({ 137 left: '23vp', 138 right: '23vp', 139 top: '37vp', 140 bottom: '17.5vp' 141 }) 142 } 143 .width('100%') 144 .padding({ 145 left: '23vp', 146 right: '23vp', 147 }) 148 149 Column() { 150 Text($r('app.string.tipsInfo')) 151 .fontFamily('PingFang SC') 152 .fontWeight(FontWeight.Regular) 153 .lineHeight('22.5vp') 154 .fontSize('16vp') 155 .width('100%') 156 .margin({ 157 left: '23vp', 158 right: '23vp', 159 bottom: '9vp', 160 }) 161 162 Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { 163 Button() { 164 Text($r('app.string.returnVal')) 165 .fontFamily('HarmonyHeiTi') 166 .fontWeight(FontWeight.Medium) 167 .lineHeight('22vp') 168 .fontSize('16vp') 169 .fontColor(0x007DFF) 170 } 171 .backgroundColor('#FFFFFF') 172 .height('40vp') 173 .flexGrow(1) 174 .onClick(() => { 175 this.controller?.close(); 176 }) 177 178 Divider() 179 .height('24vp') 180 .strokeWidth('1vp') 181 .vertical(true) 182 .color('#E3E3E3') 183 184 Button() { 185 Text($r('app.string.CancelSetting')) 186 .fontFamily('HarmonyHeiTi') 187 .fontWeight(FontWeight.Medium) 188 .lineHeight('22vp') 189 .fontSize('16vp') 190 .fontColor(0x007DFF) 191 } 192 .backgroundColor('#FFFFFF') 193 .height('40vp') 194 .flexGrow(1) 195 .onClick(() => { 196 this.controller?.close(); 197 resetFactory.rebootAndCleanUserData(); 198 }) 199 } 200 .width('100%') 201 .height('56vp') 202 } 203 .padding({ 204 left: '23vp', 205 right: '23vp' 206 }) 207 .width('100%') 208 } 209 .width('100%') 210 } 211}