• 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 enterpriseDeviceManager from '@ohos.enterprise.adminManager';
17import router from '@ohos.router';
18import accountManager from '../../common/accountManager'
19import appDetailData from '../../common/appManagement/appDetailData'
20import baseData from '../../common/baseData'
21import doubleButtonComponent from '../component/autoManager/doubleButtonComponent'
22import logger from '../../common/logger'
23import utils from '../../common/utils'
24
25const TAG = 'LoadingInfo';
26
27@Entry
28@Component
29struct LoadingInfo {
30  @StorageLink('manageAbilityName') manageAbilityName: string = '';
31  @StorageLink('manageBundleName') manageBundleName: string = '';
32  @StorageLink('manageEnterpriseName') manageEnterpriseName: string = '';
33  @StorageLink('manageEnterpriseDescription') manageEnterpriseDescription: string = '';
34
35  build() {
36    Column() {
37        Stack({ alignContent: Alignment.BottomEnd }) {
38          GridContainer({
39            columns: utils.isLargeDevice(),
40            sizeType: SizeType.Auto,
41            gutter: '12vp',
42            margin: '12vp'
43          }) {
44            Column() {
45              LoadingProgress()
46                .width('88vp')
47                .height('88vp')
48                .color(0x000000)
49                .opacity(0.6)
50                .margin({ bottom: '16vp' })
51
52              Text($r('app.string.loadingSearch'))
53                .fontWeight(FontWeight.Regular)
54                .fontSize('14vp')
55                .opacity(0.9)
56                .lineHeight('19.6vp')
57                .fontFamily('HarmonyHeiTi')
58                .height('19vp')
59            }
60            .useSizeType({
61              xs: { span: 8, offset: 0 }, sm: { span: 8, offset: 0 },
62              md: { span: 8, offset: 0 }, lg: { span: 8, offset: 2 }
63            })
64            .height('100%')
65            .justifyContent(FlexAlign.Center)
66          }
67
68          GridContainer({
69            columns: utils.isLargeDevice(),
70            sizeType: SizeType.Auto,
71            gutter: '12vp',
72            margin: '12vp'
73          }) {
74            Column() {
75              doubleButtonComponent({ nextFlag: true })
76            }
77            .justifyContent(FlexAlign.End)
78            .width('100%')
79            .margin({ bottom: '16vp' })
80            .useSizeType({
81              xs: { span: 8, offset: 0 }, sm: { span: 8, offset: 0 },
82              md: { span: 8, offset: 0 }, lg: { span: 12, offset: 0 }
83            })
84          }
85        }
86        .width('100%')
87        .height('100%')
88    }
89    .width('100%')
90    .height('100%')
91    .backgroundColor(0xF1F3F5)
92  }
93
94  aboutToAppear() {
95    this.checkAppValidAndActivate();
96  }
97
98  async checkAppValidAndActivate() {
99    let  admin = {
100      bundleName: this.manageBundleName,
101      abilityName: this.manageAbilityName
102    }
103
104    let enterpriseInfo = {
105      name: this.manageEnterpriseName,
106      description: this.manageEnterpriseDescription
107    }
108    logger.info(TAG, 'enter loadingInfo admin=' + JSON.stringify(admin)
109      + ' | enterpriseInfo=' + JSON.stringify(enterpriseInfo));
110
111    let ret = await appDetailData.checkAppItem(admin);
112    if (!(ret.val)) {
113      router.pushUrl({ url: 'pages/autoManager/setFinishFail' });
114      return;
115    }
116
117    let userId = { localId: 0 };
118    let retVal = await accountManager.getAccountUserId(userId);
119    if (!retVal || userId.localId !== baseData.DEFAULT_USER_ID) {
120      router.pushUrl({ url: 'pages/autoManager/setFinishFail' });
121      return;
122    }
123
124    logger.info(TAG, 'enter loadingInfo start enableAdmin!');
125    enterpriseDeviceManager.enableAdmin(admin, enterpriseInfo,
126      enterpriseDeviceManager.AdminType.ADMIN_TYPE_SUPER, baseData.DEFAULT_USER_ID, err => {
127        if (err !== null) {
128          logger.info(TAG, 'enter loadingInfo errCode : ' + err.code + ' errMessage : ' + err.message);
129          router.pushUrl({url: 'pages/autoManager/setFinishFail'});
130        } else {
131          router.pushUrl({url: 'pages/autoManager/setFinishSuccess'});
132        }
133      });
134  }
135}