1b0b2a9adSopenharmony_ci/*
2b0b2a9adSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
3b0b2a9adSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4b0b2a9adSopenharmony_ci * you may not use this file except in compliance with the License.
5b0b2a9adSopenharmony_ci * You may obtain a copy of the License at
6b0b2a9adSopenharmony_ci *
7b0b2a9adSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8b0b2a9adSopenharmony_ci *
9b0b2a9adSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10b0b2a9adSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11b0b2a9adSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12b0b2a9adSopenharmony_ci * See the License for the specific language governing permissions and
13b0b2a9adSopenharmony_ci * limitations under the License.
14b0b2a9adSopenharmony_ci */
15b0b2a9adSopenharmony_ci
16b0b2a9adSopenharmony_ciimport edmEnterpriseDeviceManager from '@ohos.enterprise.adminManager';
17b0b2a9adSopenharmony_ciimport router from '@ohos.router';
18b0b2a9adSopenharmony_ciimport appDetailData from '../common/appManagement/appDetailData'
19b0b2a9adSopenharmony_ciimport baseData from '../common/baseData';
20b0b2a9adSopenharmony_ciimport entryComponent from './component/entryComponent'
21b0b2a9adSopenharmony_ciimport headComponent from './component/headComponent';
22b0b2a9adSopenharmony_ciimport logger from '../common/logger'
23b0b2a9adSopenharmony_ciimport permissionListComponent from './component/permissionListComponent';
24b0b2a9adSopenharmony_ciimport utils from '../common/utils'
25b0b2a9adSopenharmony_ciimport { AppPermission, MyApplicationInfo } from '../common/myApplicationInfo'
26b0b2a9adSopenharmony_ciimport Want from '@ohos.app.ability.Want';
27b0b2a9adSopenharmony_ciimport adminManager from '@ohos.enterprise.adminManager';
28b0b2a9adSopenharmony_ciimport { BusinessError } from '@ohos.base';
29b0b2a9adSopenharmony_ciimport common from '@ohos.app.ability.common';
30b0b2a9adSopenharmony_ci
31b0b2a9adSopenharmony_cilet appInfo: MyApplicationInfo;
32b0b2a9adSopenharmony_cilet elementNameVal: Want;
33b0b2a9adSopenharmony_cilet isAdminTypeVal: adminManager.AdminType;
34b0b2a9adSopenharmony_cilet isActiveState: boolean;
35b0b2a9adSopenharmony_cilet enterInfo: adminManager.EnterpriseInfo;
36b0b2a9adSopenharmony_ciconst TAG = 'ApplicationInfo';
37b0b2a9adSopenharmony_ci
38b0b2a9adSopenharmony_ci@Entry
39b0b2a9adSopenharmony_ci@Component
40b0b2a9adSopenharmony_cistruct ApplicationInfo {
41b0b2a9adSopenharmony_ci  @StorageLink('applicationInfo') applicationInfo: MyApplicationInfo = {
42b0b2a9adSopenharmony_ci    appIcon: '',
43b0b2a9adSopenharmony_ci    appTitle: '',
44b0b2a9adSopenharmony_ci    appBundleName: '',
45b0b2a9adSopenharmony_ci    appPermissionList: []
46b0b2a9adSopenharmony_ci  };
47b0b2a9adSopenharmony_ci  @State isShowActive: boolean = false;
48b0b2a9adSopenharmony_ci  @State isEnableButton: boolean = false;
49b0b2a9adSopenharmony_ci  @StorageLink('activeType') isAdminType: number = 0;
50b0b2a9adSopenharmony_ci  @State deviceAdminActive: string = '';
51b0b2a9adSopenharmony_ci  @State deviceAdminDisActive: string = '';
52b0b2a9adSopenharmony_ci  @State enterpriseName: string = '';
53b0b2a9adSopenharmony_ci  @State enterpriseDescription: string = '';
54b0b2a9adSopenharmony_ci  private storage = LocalStorage.getShared();
55b0b2a9adSopenharmony_ci
56b0b2a9adSopenharmony_ci  build() {
57b0b2a9adSopenharmony_ci    Column() {
58b0b2a9adSopenharmony_ci      Column() {
59b0b2a9adSopenharmony_ci        GridContainer({
60b0b2a9adSopenharmony_ci          columns: utils.isLargeDevice(),
61b0b2a9adSopenharmony_ci          sizeType: SizeType.Auto,
62b0b2a9adSopenharmony_ci          gutter: '12vp',
63b0b2a9adSopenharmony_ci          margin: '12vp'
64b0b2a9adSopenharmony_ci        }) {
65b0b2a9adSopenharmony_ci          Column() {
66b0b2a9adSopenharmony_ci            headComponent({ headName: $r('app.string.adminprovisioning') });
67b0b2a9adSopenharmony_ci
68b0b2a9adSopenharmony_ci            Row() {
69b0b2a9adSopenharmony_ci              entryComponent({
70b0b2a9adSopenharmony_ci                appIcon: this.applicationInfo.appIcon,
71b0b2a9adSopenharmony_ci                appTitle: this.applicationInfo.appTitle,
72b0b2a9adSopenharmony_ci              })
73b0b2a9adSopenharmony_ci            }
74b0b2a9adSopenharmony_ci
75b0b2a9adSopenharmony_ci            Column() {
76b0b2a9adSopenharmony_ci              Text(this.enterpriseName)
77b0b2a9adSopenharmony_ci                .height($r('app.float.wh_value_21'))
78b0b2a9adSopenharmony_ci                .fontColor($r('sys.color.ohos_id_color_text_primary'))
79b0b2a9adSopenharmony_ci                .fontSize($r('app.float.font_16'))
80b0b2a9adSopenharmony_ci                .fontWeight(FontWeight.Medium)
81b0b2a9adSopenharmony_ci                .textAlign(TextAlign.Start)
82b0b2a9adSopenharmony_ci                .maxLines(3)
83b0b2a9adSopenharmony_ci                .textOverflow({ overflow: TextOverflow.Ellipsis })
84b0b2a9adSopenharmony_ci                .margin({
85b0b2a9adSopenharmony_ci                  left: $r('app.float.wh_value_36'),
86b0b2a9adSopenharmony_ci                  top: $r('app.float.wh_value_12'),
87b0b2a9adSopenharmony_ci                });
88b0b2a9adSopenharmony_ci
89b0b2a9adSopenharmony_ci              Text(this.enterpriseDescription)
90b0b2a9adSopenharmony_ci                .height($r('app.float.wh_value_19'))
91b0b2a9adSopenharmony_ci                .fontColor($r('sys.color.ohos_id_color_text_secondary'))
92b0b2a9adSopenharmony_ci                .fontSize($r('app.float.font_14'))
93b0b2a9adSopenharmony_ci                .fontWeight(FontWeight.Regular)
94b0b2a9adSopenharmony_ci                .textAlign(TextAlign.Start)
95b0b2a9adSopenharmony_ci                .maxLines(3)
96b0b2a9adSopenharmony_ci                .textOverflow({ overflow: TextOverflow.Ellipsis })
97b0b2a9adSopenharmony_ci                .margin({
98b0b2a9adSopenharmony_ci                  left: $r('app.float.wh_value_36'),
99b0b2a9adSopenharmony_ci                  top: $r('app.float.wh_value_2'),
100b0b2a9adSopenharmony_ci                });
101b0b2a9adSopenharmony_ci            }
102b0b2a9adSopenharmony_ci            .width('100%')
103b0b2a9adSopenharmony_ci            .alignItems(HorizontalAlign.Start)
104b0b2a9adSopenharmony_ci            .align(Alignment.Start)
105b0b2a9adSopenharmony_ci
106b0b2a9adSopenharmony_ci            Column() {
107b0b2a9adSopenharmony_ci              Text(this.isShowActive ? this.deviceAdminActive : this.deviceAdminDisActive)
108b0b2a9adSopenharmony_ci                .fontColor($r('sys.color.ohos_id_color_text_primary'))
109b0b2a9adSopenharmony_ci                .fontSize($r('app.float.font_16'))
110b0b2a9adSopenharmony_ci                .fontWeight(FontWeight.Medium)
111b0b2a9adSopenharmony_ci                .textAlign(TextAlign.Start)
112b0b2a9adSopenharmony_ci                .maxLines(3)
113b0b2a9adSopenharmony_ci                .textOverflow({ overflow: TextOverflow.Ellipsis })
114b0b2a9adSopenharmony_ci                .margin({
115b0b2a9adSopenharmony_ci                  left: $r('app.float.wh_value_36'),
116b0b2a9adSopenharmony_ci                  top: $r('app.float.wh_value_24'),
117b0b2a9adSopenharmony_ci                });
118b0b2a9adSopenharmony_ci
119b0b2a9adSopenharmony_ci              List() {
120b0b2a9adSopenharmony_ci                ForEach(this.applicationInfo.appPermissionList, (item: AppPermission) => {
121b0b2a9adSopenharmony_ci                  ListItem() {
122b0b2a9adSopenharmony_ci                    permissionListComponent({
123b0b2a9adSopenharmony_ci                      permissionName: item.permissionLabel,
124b0b2a9adSopenharmony_ci                      permissionDescription: item.permissionDescription,
125b0b2a9adSopenharmony_ci                    });
126b0b2a9adSopenharmony_ci                  }
127b0b2a9adSopenharmony_ci                }, (item: AppPermission) => JSON.stringify(item));
128b0b2a9adSopenharmony_ci              }
129b0b2a9adSopenharmony_ci            }
130b0b2a9adSopenharmony_ci            .alignItems(HorizontalAlign.Start)
131b0b2a9adSopenharmony_ci            .align(Alignment.Start)
132b0b2a9adSopenharmony_ci          }
133b0b2a9adSopenharmony_ci          .useSizeType({
134b0b2a9adSopenharmony_ci            xs: { span: 8, offset: 0 }, sm: { span: 8, offset: 0 },
135b0b2a9adSopenharmony_ci            md: { span: 8, offset: 0 }, lg: { span: 8, offset: 2 }
136b0b2a9adSopenharmony_ci          })
137b0b2a9adSopenharmony_ci        }
138b0b2a9adSopenharmony_ci      }
139b0b2a9adSopenharmony_ci      .layoutWeight(1)
140b0b2a9adSopenharmony_ci
141b0b2a9adSopenharmony_ci      Column() {
142b0b2a9adSopenharmony_ci        GridContainer({
143b0b2a9adSopenharmony_ci          columns: utils.isLargeDevice(),
144b0b2a9adSopenharmony_ci          sizeType: SizeType.Auto,
145b0b2a9adSopenharmony_ci          gutter: '12vp',
146b0b2a9adSopenharmony_ci          margin: '12vp'
147b0b2a9adSopenharmony_ci        }) {
148b0b2a9adSopenharmony_ci          Row() {
149b0b2a9adSopenharmony_ci            Row()
150b0b2a9adSopenharmony_ci              .useSizeType({
151b0b2a9adSopenharmony_ci                xs: { span: 1, offset: 0 }, sm: { span: 1, offset: 0 },
152b0b2a9adSopenharmony_ci                md: { span: 1, offset: 0 }, lg: { span: 3, offset: 0 }
153b0b2a9adSopenharmony_ci              })
154b0b2a9adSopenharmony_ci
155b0b2a9adSopenharmony_ci            Button() {
156b0b2a9adSopenharmony_ci              Text(this.isShowActive ? $r('app.string.deActivate') : $r('app.string.activation'))
157b0b2a9adSopenharmony_ci                .opacity(this.isEnableButton ? 1 : 0.38)
158b0b2a9adSopenharmony_ci                .fontSize($r('sys.float.ohos_id_text_size_button1'))
159b0b2a9adSopenharmony_ci                .fontColor($r('sys.color.ohos_id_color_text_primary_activated'))
160b0b2a9adSopenharmony_ci            }
161b0b2a9adSopenharmony_ci            .enabled(this.isEnableButton)
162b0b2a9adSopenharmony_ci            .backgroundColor($r('sys.color.ohos_id_color_button_normal'))
163b0b2a9adSopenharmony_ci            .height($r('app.float.button_height'))
164b0b2a9adSopenharmony_ci            .margin({
165b0b2a9adSopenharmony_ci              right: $r('app.float.wh_value_6'),
166b0b2a9adSopenharmony_ci              bottom: $r('app.float.wh_value_24')
167b0b2a9adSopenharmony_ci            })
168b0b2a9adSopenharmony_ci            .onClick(() => {
169b0b2a9adSopenharmony_ci              logger.info(TAG, 'button active:' + this.isShowActive);
170b0b2a9adSopenharmony_ci              this.activateAdmin(this.isAdminType);
171b0b2a9adSopenharmony_ci            })
172b0b2a9adSopenharmony_ci            .useSizeType({
173b0b2a9adSopenharmony_ci              xs: { span: 3, offset: 1 }, sm: { span: 3, offset: 1 },
174b0b2a9adSopenharmony_ci              md: { span: 3, offset: 1 }, lg: { span: 3, offset: 3 }
175b0b2a9adSopenharmony_ci            })
176b0b2a9adSopenharmony_ci
177b0b2a9adSopenharmony_ci            Button() {
178b0b2a9adSopenharmony_ci              Text($r('app.string.cancel'))
179b0b2a9adSopenharmony_ci                .fontSize($r('sys.float.ohos_id_text_size_button1'))
180b0b2a9adSopenharmony_ci                .fontColor($r('sys.color.ohos_id_color_text_primary_activated'))
181b0b2a9adSopenharmony_ci            }
182b0b2a9adSopenharmony_ci            .backgroundColor($r('sys.color.ohos_id_color_button_normal'))
183b0b2a9adSopenharmony_ci            .height($r('app.float.button_height'))
184b0b2a9adSopenharmony_ci            .margin({
185b0b2a9adSopenharmony_ci              left: $r('app.float.wh_value_6'),
186b0b2a9adSopenharmony_ci              bottom: $r('app.float.wh_value_24')
187b0b2a9adSopenharmony_ci            })
188b0b2a9adSopenharmony_ci            .onClick(() => {
189b0b2a9adSopenharmony_ci              logger.info(TAG, 'button cancel in isShowActive:' + this.isShowActive);
190b0b2a9adSopenharmony_ci              appDetailData.terminateAbilityPage();
191b0b2a9adSopenharmony_ci            })
192b0b2a9adSopenharmony_ci            .useSizeType({
193b0b2a9adSopenharmony_ci              xs: { span: 3, offset: 4 }, sm: { span: 3, offset: 4 },
194b0b2a9adSopenharmony_ci              md: { span: 3, offset: 4 }, lg: { span: 3, offset: 6 }
195b0b2a9adSopenharmony_ci            })
196b0b2a9adSopenharmony_ci
197b0b2a9adSopenharmony_ci            Row()
198b0b2a9adSopenharmony_ci              .useSizeType({
199b0b2a9adSopenharmony_ci                xs: { span: 1, offset: 7 }, sm: { span: 1, offset: 7 },
200b0b2a9adSopenharmony_ci                md: { span: 1, offset: 7 }, lg: { span: 3, offset: 9 }
201b0b2a9adSopenharmony_ci              })
202b0b2a9adSopenharmony_ci          }
203b0b2a9adSopenharmony_ci          .justifyContent(FlexAlign.Center)
204b0b2a9adSopenharmony_ci        }
205b0b2a9adSopenharmony_ci      }.width('100%')
206b0b2a9adSopenharmony_ci    }
207b0b2a9adSopenharmony_ci    .height('100%')
208b0b2a9adSopenharmony_ci    .width('100%')
209b0b2a9adSopenharmony_ci    .backgroundColor($r('sys.color.ohos_id_color_sub_background'))
210b0b2a9adSopenharmony_ci  }
211b0b2a9adSopenharmony_ci
212b0b2a9adSopenharmony_ci  async aboutToAppear(): Promise<void> {
213b0b2a9adSopenharmony_ci    elementNameVal = {
214b0b2a9adSopenharmony_ci      abilityName: '',
215b0b2a9adSopenharmony_ci      bundleName: '',
216b0b2a9adSopenharmony_ci    };
217b0b2a9adSopenharmony_ci
218b0b2a9adSopenharmony_ci    enterInfo = {
219b0b2a9adSopenharmony_ci      name: '',
220b0b2a9adSopenharmony_ci      description: '',
221b0b2a9adSopenharmony_ci    };
222b0b2a9adSopenharmony_ci
223b0b2a9adSopenharmony_ci    isAdminTypeVal = 0;
224b0b2a9adSopenharmony_ci    logger.info(TAG, 'aboutToAppear in');
225b0b2a9adSopenharmony_ci    await this.getCheckAbilityList(this.applicationInfo, elementNameVal, isAdminTypeVal);
226b0b2a9adSopenharmony_ci    logger.info(TAG, 'aboutToAppear out');
227b0b2a9adSopenharmony_ci  }
228b0b2a9adSopenharmony_ci
229b0b2a9adSopenharmony_ci  aboutToDisappear(): void {
230b0b2a9adSopenharmony_ci    logger.info(TAG, 'aboutToDisappear');
231b0b2a9adSopenharmony_ci  }
232b0b2a9adSopenharmony_ci
233b0b2a9adSopenharmony_ci  onPageShow(): void {
234b0b2a9adSopenharmony_ci    logger.info(TAG, 'onPageShow in');
235b0b2a9adSopenharmony_ci    this.isAdminActive();
236b0b2a9adSopenharmony_ci    logger.info(TAG, 'onPageShow isActiveState =' + isActiveState);
237b0b2a9adSopenharmony_ci    if (!utils.isValid(isActiveState)) {
238b0b2a9adSopenharmony_ci      return;
239b0b2a9adSopenharmony_ci    }
240b0b2a9adSopenharmony_ci    this.isShowActive = isActiveState;
241b0b2a9adSopenharmony_ci    logger.info(TAG, 'onPageShow out');
242b0b2a9adSopenharmony_ci  }
243b0b2a9adSopenharmony_ci
244b0b2a9adSopenharmony_ci  onPageHide() {
245b0b2a9adSopenharmony_ci    logger.info(TAG, 'onPageHide');
246b0b2a9adSopenharmony_ci  }
247b0b2a9adSopenharmony_ci
248b0b2a9adSopenharmony_ci  onBackPress() {
249b0b2a9adSopenharmony_ci    logger.info(TAG, 'onBackPress');
250b0b2a9adSopenharmony_ci    router.back();
251b0b2a9adSopenharmony_ci  }
252b0b2a9adSopenharmony_ci
253b0b2a9adSopenharmony_ci  async isAdminActive() {
254b0b2a9adSopenharmony_ci    let wantTemp: Want = {
255b0b2a9adSopenharmony_ci      bundleName: elementNameVal.bundleName,
256b0b2a9adSopenharmony_ci      abilityName: elementNameVal.abilityName,
257b0b2a9adSopenharmony_ci    };
258b0b2a9adSopenharmony_ci    let retAppState: boolean;
259b0b2a9adSopenharmony_ci    let retSuperState: boolean;
260b0b2a9adSopenharmony_ci    logger.info(TAG, 'isAdminActive elementNameVal.bundleName=' + elementNameVal.bundleName +
261b0b2a9adSopenharmony_ci    ' | elementNameVal.abilityName=' + elementNameVal.abilityName);
262b0b2a9adSopenharmony_ci    if (elementNameVal.bundleName === baseData.EMPTY_STR || elementNameVal.abilityName === baseData.EMPTY_STR) {
263b0b2a9adSopenharmony_ci      logger.info(TAG, 'isAdminActive elementNameVal is null');
264b0b2a9adSopenharmony_ci      return;
265b0b2a9adSopenharmony_ci    }
266b0b2a9adSopenharmony_ci
267b0b2a9adSopenharmony_ci    retAppState = await edmEnterpriseDeviceManager.isAdminEnabled(wantTemp);
268b0b2a9adSopenharmony_ci    let name: string = elementNameVal.bundleName;
269b0b2a9adSopenharmony_ci    retSuperState = await edmEnterpriseDeviceManager.isSuperAdmin(name);
270b0b2a9adSopenharmony_ci    if (!retAppState) {
271b0b2a9adSopenharmony_ci      this.isShowActive = false;
272b0b2a9adSopenharmony_ci      this.isEnableButton = true;
273b0b2a9adSopenharmony_ci    } else {
274b0b2a9adSopenharmony_ci      if (retSuperState) {
275b0b2a9adSopenharmony_ci        this.isEnableButton = false;
276b0b2a9adSopenharmony_ci      } else {
277b0b2a9adSopenharmony_ci        this.isEnableButton = true;
278b0b2a9adSopenharmony_ci      }
279b0b2a9adSopenharmony_ci      this.isShowActive = true;
280b0b2a9adSopenharmony_ci    }
281b0b2a9adSopenharmony_ci    logger.info(TAG, 'isAdminActive retAppState:' + retAppState + ' | retSuperState:' + retSuperState);
282b0b2a9adSopenharmony_ci    isActiveState = this.isShowActive;
283b0b2a9adSopenharmony_ci  }
284b0b2a9adSopenharmony_ci
285b0b2a9adSopenharmony_ci  async activateAdmin(adminType: adminManager.AdminType) {
286b0b2a9adSopenharmony_ci    logger.info(TAG, 'activateAdmin isShowActive:' + this.isShowActive);
287b0b2a9adSopenharmony_ci    let wantTemp: Want = {
288b0b2a9adSopenharmony_ci      bundleName: elementNameVal.bundleName,
289b0b2a9adSopenharmony_ci      abilityName: elementNameVal.abilityName,
290b0b2a9adSopenharmony_ci    };
291b0b2a9adSopenharmony_ci    await this.isAdminActive();
292b0b2a9adSopenharmony_ci    let ret = true;
293b0b2a9adSopenharmony_ci    if (!this.isShowActive) {
294b0b2a9adSopenharmony_ci      if (adminType === edmEnterpriseDeviceManager.AdminType.ADMIN_TYPE_NORMAL) {
295b0b2a9adSopenharmony_ci        await edmEnterpriseDeviceManager.enableAdmin(wantTemp,
296b0b2a9adSopenharmony_ci          { name: enterInfo.name, description: enterInfo.description },
297b0b2a9adSopenharmony_ci        edmEnterpriseDeviceManager.AdminType.ADMIN_TYPE_NORMAL)
298b0b2a9adSopenharmony_ci          .catch((error: BusinessError) => {
299b0b2a9adSopenharmony_ci            ret = false;
300b0b2a9adSopenharmony_ci            logger.info(TAG, 'errorCode : ' + error.code + 'errorMessage : ' + error.message);
301b0b2a9adSopenharmony_ci          });
302b0b2a9adSopenharmony_ci      } else {
303b0b2a9adSopenharmony_ci        logger.warn(TAG, 'not support AdminType.ADMIN_TYPE_SUPER enable Admin')
304b0b2a9adSopenharmony_ci      }
305b0b2a9adSopenharmony_ci      logger.info(TAG, 'activateAdmin Activate admin end');
306b0b2a9adSopenharmony_ci    } else {
307b0b2a9adSopenharmony_ci      if (this.isEnableButton) {
308b0b2a9adSopenharmony_ci        await edmEnterpriseDeviceManager.disableAdmin(wantTemp)
309b0b2a9adSopenharmony_ci          .catch((error: BusinessError) => {
310b0b2a9adSopenharmony_ci            ret = false;
311b0b2a9adSopenharmony_ci            logger.info(TAG, 'errorCode : ' + error.code + 'errorMessage : ' + error.message);
312b0b2a9adSopenharmony_ci          });
313b0b2a9adSopenharmony_ci      } else {
314b0b2a9adSopenharmony_ci        logger.info(TAG, 'activateAdmin not support super admin active');
315b0b2a9adSopenharmony_ci      }
316b0b2a9adSopenharmony_ci    }
317b0b2a9adSopenharmony_ci    logger.info(TAG, 'activateAdmin adminType:' + adminType + ' | ret:' + ret);
318b0b2a9adSopenharmony_ci    if (ret) {
319b0b2a9adSopenharmony_ci      appDetailData.terminateAbilityPage();
320b0b2a9adSopenharmony_ci    }
321b0b2a9adSopenharmony_ci  }
322b0b2a9adSopenharmony_ci
323b0b2a9adSopenharmony_ci  async getSelfResourceVal(resource: Resource) {
324b0b2a9adSopenharmony_ci    let resMgr = getContext().resourceManager;
325b0b2a9adSopenharmony_ci    logger.info(TAG, 'getSelfResourceVal in:');
326b0b2a9adSopenharmony_ci    let value = await resMgr.getString(resource.id);
327b0b2a9adSopenharmony_ci    logger.info(TAG, 'getSelfResourceVal finish value:' + value);
328b0b2a9adSopenharmony_ci    if (!utils.isValid(value) || value === baseData.EMPTY_STR) {
329b0b2a9adSopenharmony_ci      return baseData.EMPTY_STR;
330b0b2a9adSopenharmony_ci    }
331b0b2a9adSopenharmony_ci    return value;
332b0b2a9adSopenharmony_ci  }
333b0b2a9adSopenharmony_ci
334b0b2a9adSopenharmony_ci  async getAbilityWantVal(appInfo: MyApplicationInfo, elementNameVal: Want, adminType: adminManager.AdminType) {
335b0b2a9adSopenharmony_ci    logger.info(TAG, 'getAbilityWantVal in:');
336b0b2a9adSopenharmony_ci    this.storage = LocalStorage.getShared();
337b0b2a9adSopenharmony_ci    let data = this.storage.get<Want>('adminProvisioningWant');
338b0b2a9adSopenharmony_ci
339b0b2a9adSopenharmony_ci    if (!utils.checkObjPropertyValid(data, 'parameters.elementName.abilityName') ||
340b0b2a9adSopenharmony_ci    !utils.checkObjPropertyValid(data, 'parameters.enterprise.name') ||
341b0b2a9adSopenharmony_ci    !utils.isValid((data.parameters?.elementName as Record<string, string>).bundleName) ||
342b0b2a9adSopenharmony_ci    !utils.isValid(data.parameters?.activeType) ||
343b0b2a9adSopenharmony_ci    !utils.isValid((data.parameters?.enterprise as Record<string, string>).description)) {
344b0b2a9adSopenharmony_ci      logger.warn(TAG, 'data.parameters = ' + JSON.stringify(data.parameters));
345b0b2a9adSopenharmony_ci      (getContext(this) as common.UIAbilityContext).terminateSelf();
346b0b2a9adSopenharmony_ci      return;
347b0b2a9adSopenharmony_ci    }
348b0b2a9adSopenharmony_ci
349b0b2a9adSopenharmony_ci    elementNameVal.abilityName = (data.parameters?.elementName as Record<string, string>).abilityName;
350b0b2a9adSopenharmony_ci    elementNameVal.bundleName = (data.parameters?.elementName as Record<string, string>).bundleName;
351b0b2a9adSopenharmony_ci    appInfo.appBundleName = (data.parameters?.elementName as Record<string, string>).bundleName;
352b0b2a9adSopenharmony_ci    adminType = data.parameters?.activeType as adminManager.AdminType;
353b0b2a9adSopenharmony_ci    AppStorage.SetOrCreate('activeType', adminType);
354b0b2a9adSopenharmony_ci
355b0b2a9adSopenharmony_ci    enterInfo.name = (data.parameters?.enterprise as Record<string, string>).name.substring(0, baseData.MAX_LEN);
356b0b2a9adSopenharmony_ci    enterInfo.description =
357b0b2a9adSopenharmony_ci      (data.parameters?.enterprise as Record<string, string>).description.substring(0, baseData.MAX_LEN);
358b0b2a9adSopenharmony_ci    logger.info(TAG, 'getAbilityWantVal out isAdminTypeVal.admintype:' + isAdminTypeVal +
359b0b2a9adSopenharmony_ci    ' enter.name=' + enterInfo.name + ' enter.des=' + enterInfo.description);
360b0b2a9adSopenharmony_ci  }
361b0b2a9adSopenharmony_ci
362b0b2a9adSopenharmony_ci  async getCheckAbilityList(appInfo: MyApplicationInfo, elementNameVal: Want, adminType: adminManager.AdminType) {
363b0b2a9adSopenharmony_ci    let deviceActiveOne = '';
364b0b2a9adSopenharmony_ci    let deviceActiveTwo = '';
365b0b2a9adSopenharmony_ci    let deviceDeactivate = '';
366b0b2a9adSopenharmony_ci    let getName = '';
367b0b2a9adSopenharmony_ci    let getDescription = '';
368b0b2a9adSopenharmony_ci    logger.info(TAG, 'getCheckAbilityList in:');
369b0b2a9adSopenharmony_ci    await this.getAbilityWantVal(appInfo, elementNameVal, adminType);
370b0b2a9adSopenharmony_ci
371b0b2a9adSopenharmony_ci    let ret = await appDetailData.checkAppItem(elementNameVal);
372b0b2a9adSopenharmony_ci    if (!ret) {
373b0b2a9adSopenharmony_ci      logger.info(TAG, 'aboutToAppear not exist bundleName:' + appInfo.appBundleName);
374b0b2a9adSopenharmony_ci      appDetailData.terminateAbilityPage();
375b0b2a9adSopenharmony_ci      return;
376b0b2a9adSopenharmony_ci    }
377b0b2a9adSopenharmony_ci
378b0b2a9adSopenharmony_ci    await this.isAdminActive();
379b0b2a9adSopenharmony_ci
380b0b2a9adSopenharmony_ci    if (appInfo.appBundleName) {
381b0b2a9adSopenharmony_ci      await appDetailData.getBundleInfoItem(appInfo.appBundleName, appInfo);
382b0b2a9adSopenharmony_ci    }
383b0b2a9adSopenharmony_ci
384b0b2a9adSopenharmony_ci    this.deviceAdminActive = getContext()
385b0b2a9adSopenharmony_ci      .resourceManager
386b0b2a9adSopenharmony_ci      .getStringSync($r('app.string.textApplicationInfoActive').id, `${appInfo.appTitle}`);
387b0b2a9adSopenharmony_ci    this.deviceAdminDisActive = getContext()
388b0b2a9adSopenharmony_ci      .resourceManager
389b0b2a9adSopenharmony_ci      .getStringSync($r('app.string.textApplicationInfoInactive').id, `${appInfo.appTitle}`);
390b0b2a9adSopenharmony_ci
391b0b2a9adSopenharmony_ci    let want: Want = {
392b0b2a9adSopenharmony_ci      bundleName: elementNameVal.bundleName,
393b0b2a9adSopenharmony_ci      abilityName: elementNameVal.abilityName,
394b0b2a9adSopenharmony_ci    };
395b0b2a9adSopenharmony_ci    let getEnterInfo: adminManager.EnterpriseInfo = {
396b0b2a9adSopenharmony_ci      name: '',
397b0b2a9adSopenharmony_ci      description: '',
398b0b2a9adSopenharmony_ci    };
399b0b2a9adSopenharmony_ci    if (this.isShowActive) {
400b0b2a9adSopenharmony_ci      logger.info(TAG, 'getCheckAbilityList get getEnterInfo');
401b0b2a9adSopenharmony_ci      getEnterInfo = await edmEnterpriseDeviceManager.getEnterpriseInfo(want);
402b0b2a9adSopenharmony_ci    }
403b0b2a9adSopenharmony_ci
404b0b2a9adSopenharmony_ci    logger.info(TAG, 'getCheckAbilityList start enterpriseName=' + getEnterInfo.name +
405b0b2a9adSopenharmony_ci    ' enterpriseDescription=' + getEnterInfo.description);
406b0b2a9adSopenharmony_ci    if (utils.isValid(getEnterInfo.name)) {
407b0b2a9adSopenharmony_ci      getName = getEnterInfo.name.substring(0, baseData.MAX_LEN);
408b0b2a9adSopenharmony_ci    }
409b0b2a9adSopenharmony_ci    if (utils.isValid(getEnterInfo.description)) {
410b0b2a9adSopenharmony_ci      getDescription = getEnterInfo.description.substring(0, baseData.MAX_LEN);
411b0b2a9adSopenharmony_ci    }
412b0b2a9adSopenharmony_ci
413b0b2a9adSopenharmony_ci    if (this.isShowActive) {
414b0b2a9adSopenharmony_ci      this.enterpriseName = getContext().resourceManager.getStringSync($r('app.string.enterprise_name').id, getName);
415b0b2a9adSopenharmony_ci      this.enterpriseDescription = getContext()
416b0b2a9adSopenharmony_ci        .resourceManager
417b0b2a9adSopenharmony_ci        .getStringSync($r('app.string.enterprise_description').id, getDescription);
418b0b2a9adSopenharmony_ci    } else {
419b0b2a9adSopenharmony_ci      this.enterpriseName = getContext()
420b0b2a9adSopenharmony_ci        .resourceManager
421b0b2a9adSopenharmony_ci        .getStringSync($r('app.string.enterprise_name').id, enterInfo.name);
422b0b2a9adSopenharmony_ci      this.enterpriseDescription = getContext()
423b0b2a9adSopenharmony_ci        .resourceManager
424b0b2a9adSopenharmony_ci        .getStringSync($r('app.string.enterprise_description').id, enterInfo.description);
425b0b2a9adSopenharmony_ci    }
426b0b2a9adSopenharmony_ci    logger.info(TAG, 'getCheckAbilityList enterpriseName=' + this.enterpriseName + ' enterpriseDescription=' +
427b0b2a9adSopenharmony_ci    this.enterpriseDescription);
428b0b2a9adSopenharmony_ci  }
429b0b2a9adSopenharmony_ci}