• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 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 adminManager from '@ohos.enterprise.adminManager';
17import Want from '@ohos.app.ability.Want';
18import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession';
19import { BusinessError } from '@ohos.base';
20import deviceInfo from '@ohos.deviceInfo';
21import logger from '../../common/logger';
22import { PageComponent } from './PageComponent';
23import baseData from '../../common/baseData'
24
25const TAG: string = 'deployComponent';
26
27@Component
28export struct deployComponent {
29  private title: Resource = $r('app.string.unitManageDevice');
30  private autoDeployText: Resource = $r('app.string.AutoDeployText');
31  private storage = LocalStorage.getShared();
32  private abilityInfo: Want | undefined;
33  private enterpriseInfo: adminManager.EnterpriseInfo | undefined;
34  private adminType: adminManager.AdminType | undefined;
35  private session: UIExtensionContentSession | undefined;
36
37  build() {
38    PageComponent({
39      content: () => {
40        this.buildPageContent();
41      }
42    })
43  }
44
45  @Builder
46  buildPageContent() {
47    if (deviceInfo.deviceType === 'phone') {
48      this.phonePageContent();
49    } else {
50      this.pcPageContent();
51    }
52  }
53
54  @Builder
55  phonePageContent() {
56    Column() {
57      GridRow({ columns : 4, gutter: { x: 12 } }) {
58        GridCol({ span : 4}) {
59          Flex({
60            direction: FlexDirection.Column,
61            justifyContent: FlexAlign.Start,
62            alignItems: ItemAlign.Center
63          }) {
64            Column() {
65              Column() {
66                Column() {
67                  Image($r('app.media.ic_back'))
68                    .width($r('app.float.wh_value_24'))
69                    .height($r('app.float.wh_value_24'))
70                    .onClick(() => {
71                      this.terminateAbility(baseData.OOBE_PRE_STEP_CODE);
72                    })
73                }
74                .width('100%')
75                .margin({ top : $r('app.float.wh_value_36') })
76                .height($r('app.float.wh_value_56'))
77                .alignItems(HorizontalAlign.Start)
78                .justifyContent(FlexAlign.Center)
79
80                Image($r('app.media.mdm_start'))
81                  .width($r('app.float.wh_value_48'))
82                  .height($r('app.float.wh_value_48'))
83                  .margin({ top : $r('app.float.wh_value_12'), bottom : $r('app.float.wh_value_12') })
84                  .objectFit(ImageFit.Contain)
85                  .align(Alignment.Center)
86
87                Text(this.title)
88                  .fontWeight(FontWeight.Medium)
89                  .fontSize($r('sys.float.ohos_id_text_size_headline6'))
90                  .fontColor($r('sys.color.ohos_id_color_text_primary'))
91                  .maxLines(2)
92                  .height($r('app.float.wh_value_40'))
93              }
94              .alignItems(HorizontalAlign.Center)
95            }
96            .margin({ bottom: $r('app.float.wh_value_48')})
97            .flexShrink(0)
98            .width('100%')
99
100            Column() {
101              Text() {
102                Span(this.autoDeployText)
103                  .fontWeight(FontWeight.Medium)
104                  .lineHeight($r('app.float.lineHeight_vp_25'))
105                  .fontSize($r('sys.float.ohos_id_text_size_sub_title2'))
106                  .fontFamily('HarmonyHeiTi')
107              }
108              .width('100%')
109              .textAlign(TextAlign.Start)
110              .maxLines(2)
111              .align(Alignment.Center)
112            }
113            .flexGrow(1)
114            .width('100%')
115
116            Column() {
117              Button() {
118                Text($r('app.string.continue'))
119                  .fontSize($r('app.float.font_vp_16'))
120                  .fontFamily('HarmonyHeiTi')
121                  .fontWeight(FontWeight.Medium)
122                  .fontColor(0xFFFFFF)
123                  .lineHeight($r('app.float.wh_value_22'))
124              }
125              .backgroundColor(0x0A59F7)
126              .onClick(() => {
127                this.EnableAdmin();
128              })
129              .width($r('app.float.button_continue_width'))
130              .height($r('app.float.wh_value_40'))
131              .margin({ bottom: $r('app.float.value_100')})
132            }
133            .flexShrink(0)
134            .width('100%')
135            .padding({
136              top: $r('app.float.wh_value_16'),
137              bottom: $r('sys.float.ohos_id_default_padding_bottom_fixed')
138            })
139          }.size({ width: '100%', height: '100%' })
140        }.size({ width: '100%', height: '100%' })
141      }
142      .height('100%')
143      .width('100%')
144      .backgroundColor($r('sys.color.ohos_id_color_sub_background'))
145    }
146    .padding({
147      left: $r('sys.float.ohos_id_max_padding_start'),
148      right: $r('sys.float.ohos_id_max_padding_end')
149    })
150    .size({ width: '100%', height: '100%' })
151    .backgroundColor($r('sys.color.ohos_id_color_sub_background'))
152  }
153
154  @Builder
155  pcPageContent() {
156    Column() {
157      GridRow({ columns : 12, gutter: { x: 12 } }) {
158        GridCol({ span : 8, offset: 2 }) {
159          Column() {
160            Column() {
161              Column() {
162                Image($r('app.media.mdm_start'))
163                  .width($r('app.float.wh_value_48'))
164                  .height($r('app.float.wh_value_48'))
165                  .margin({ top : $r('app.float.value_100'), bottom : $r('app.float.wh_value_12') })
166                  .objectFit(ImageFit.Contain)
167                  .align(Alignment.Center)
168
169                Text(this.title)
170                  .textAlign(TextAlign.Center)
171                  .fontWeight(FontWeight.Medium)
172                  .lineHeight($r('app.float.value_35'))
173                  .fontSize($r('app.float.font_vp_30'))
174                  .maxLines(2)
175                  .fontFamily('HarmonyHeiTi')
176                  .height($r('app.float.wh_value_40'))
177              }
178              .width('100%')
179              .height('100%')
180              .margin({ bottom: $r('app.float.wh_value_48')})
181              .alignItems(HorizontalAlign.Center)
182            }
183            .width('100%')
184            .height($r('app.float.value_248'))
185
186            Column() {
187              Text() {
188                Span(this.autoDeployText)
189                  .fontWeight(FontWeight.Medium)
190                  .lineHeight($r('app.float.lineHeight_vp_25'))
191                  .fontSize($r('app.float.font_vp_18'))
192                  .fontFamily('HarmonyHeiTi')
193              }
194              .margin({top: $r('app.float.value_32')})
195              .textAlign(TextAlign.Start)
196              .maxLines(2)
197            }
198            .borderRadius($r('sys.float.ohos_id_corner_radius_default_l'))
199            .backgroundColor($r('sys.color.ohos_id_color_background'))
200            .width('100%')
201            .layoutWeight(1);
202
203            Column() {
204              Row() {
205                Button() {
206                  Text($r('app.string.PreviousStep'))
207                    .fontSize($r('app.float.font_vp_16'))
208                    .fontFamily('HarmonyHeiTi')
209                    .fontWeight(FontWeight.Medium)
210                    .fontColor(0x0A59F7)
211                    .lineHeight($r('app.float.lineHeight_vp_22'))
212                }
213                .backgroundColor(0xEEEEEE)
214                .onClick(() => {
215                  this.terminateAbility(baseData.OOBE_PRE_STEP_CODE);
216                })
217                .width($r('app.float.value_302'))
218                .height($r('app.float.wh_value_40'))
219                .margin({ right: $r('app.float.font_16'), bottom: $r('app.float.value_100') })
220
221                Button() {
222                  Text($r('app.string.continue'))
223                    .fontSize($r('app.float.font_vp_16'))
224                    .fontFamily('HarmonyHeiTi')
225                    .fontWeight(FontWeight.Medium)
226                    .fontColor(0xFFFFFF)
227                    .lineHeight($r('app.float.wh_value_22'))
228                }
229                .backgroundColor(0x0A59F7)
230                .onClick(() => {
231                  this.EnableAdmin();
232                })
233                .width($r('app.float.value_302'))
234                .height($r('app.float.wh_value_40'))
235                .margin({ bottom: $r('app.float.value_100')})
236              }
237              .margin({top: $r('app.float.wh_value_16')})
238              .alignItems(VerticalAlign.Bottom)
239              .justifyContent(FlexAlign.Center)
240              .width('100%')
241            }
242            .height($r('app.float.value_156'))
243          }
244        }
245      }
246    }
247    .size({ width: '100%', height: '100%' })
248    .backgroundColor($r('sys.color.ohos_id_color_sub_background'))
249  }
250
251  aboutToAppear() {
252    logger.info(TAG, 'aboutToAppear');
253    this.storage = LocalStorage.getShared();
254    this.abilityInfo = this.storage.get<Want>('adminInfo');
255    this.enterpriseInfo = this.storage.get<adminManager.EnterpriseInfo>('enterpriseInfo');
256    this.adminType = this.storage.get<adminManager.AdminType>('adminType');
257    this.session = this.storage.get<UIExtensionContentSession>('session');
258  }
259
260  private terminateAbility(flag: number) {
261    this.session?.terminateSelfWithResult({
262      resultCode: flag,
263      want: this.abilityInfo
264    });
265    this.storage.clear();
266  }
267
268  private EnableAdmin() {
269    let admin: Want = this.abilityInfo;
270    let entInfo: adminManager.EnterpriseInfo = this.enterpriseInfo;
271    try {
272      adminManager.enableAdmin(admin, entInfo, this.adminType).then(() => {
273        logger.info(TAG, 'enableAdmin success');
274        this.terminateAbility(baseData.OOBE_NEXT_STEP_CODE);
275      }).catch((err: BusinessError) => {
276        logger.error(TAG, `enableAdmin failed, errCode: ${err.code}, errMessage: ${err.message}`);
277        this.terminateAbility(baseData.ENABLE_ADMIN_FAILED);
278      })
279    } catch (err) {
280      logger.error(TAG, `enableAdmin failed, errCode: ${err.code}, errMessage: ${err.message}`);
281      this.terminateAbility(baseData.ENABLE_ADMIN_FAILED);
282    }
283  }
284}
285
286
287
288