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