• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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: Array<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! '
105        + JSON.stringify(e));
106    }
107
108    if (utils.isValid(data) && data.length > 0) {
109      logger.info(TAG, 'startSpecificActionAbility data len='
110        + data.length + ' | data content=' + data[0].name)
111      try {
112        await (getContext(this) as common.UIAbilityContext).startAbility({
113          bundleName: this.nextBundleName,
114          abilityName: data[0].name
115        });
116      } catch (e) {
117        logger.error(TAG, "startSpecificActionAbility startAbility fail! " + e)
118      }
119    }
120    await (getContext(this) as common.UIAbilityContext).terminateSelf();
121  }
122}
123
124@CustomDialog
125struct DialogButtonLayout {
126  controller?: CustomDialogController
127
128  build() {
129    Column() {
130      Column() {
131        Text($r('app.string.tips'))
132          .fontFamily('HarmonyHeiTi')
133          .fontWeight(FontWeight.Medium)
134          .lineHeight('28vp')
135          .fontSize('20vp')
136          .height('28vp')
137          .width('100%')
138          .margin({
139            left: '23vp',
140            right: '23vp',
141            top: '37vp',
142            bottom: '17.5vp'
143          })
144      }
145      .width('100%')
146      .padding({
147        left: '23vp',
148        right: '23vp',
149      })
150
151      Column() {
152        Text($r('app.string.tipsInfo'))
153          .fontFamily('PingFang SC')
154          .fontWeight(FontWeight.Regular)
155          .lineHeight('22.5vp')
156          .fontSize('16vp')
157          .width('100%')
158          .margin({
159            left: '23vp',
160            right: '23vp',
161            bottom: '9vp',
162          })
163
164        Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) {
165          Button() {
166            Text($r('app.string.returnVal'))
167              .fontFamily('HarmonyHeiTi')
168              .fontWeight(FontWeight.Medium)
169              .lineHeight('22vp')
170              .fontSize('16vp')
171              .fontColor(0x007DFF)
172          }
173          .backgroundColor('#FFFFFF')
174          .height('40vp')
175          .flexGrow(1)
176          .onClick(() => {
177            this.controller?.close();
178          })
179
180          Divider()
181            .height('24vp')
182            .strokeWidth('1vp')
183            .vertical(true)
184            .color('#E3E3E3')
185
186          Button() {
187            Text($r('app.string.CancelSetting'))
188              .fontFamily('HarmonyHeiTi')
189              .fontWeight(FontWeight.Medium)
190              .lineHeight('22vp')
191              .fontSize('16vp')
192              .fontColor(0x007DFF)
193          }
194          .backgroundColor('#FFFFFF')
195          .height('40vp')
196          .flexGrow(1)
197          .onClick(() => {
198            this.controller?.close();
199            resetFactory.rebootAndCleanUserData();
200          })
201        }
202        .width('100%')
203        .height('56vp')
204      }
205      .padding({
206        left: '23vp',
207        right: '23vp'
208      })
209      .width('100%')
210    }
211    .width('100%')
212  }
213}