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