• 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 UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession';
17import ability from '@ohos.ability.ability';
18import router from '@ohos.router';
19import dlpPermission from '@ohos.dlpPermission';
20import picker from '@ohos.file.picker';
21import fs from '@ohos.file.fs';
22import fileUri from '@ohos.file.fileuri';
23import { BusinessError } from '@ohos.base';
24import osAccount from '@ohos.account.osAccount';
25import common from '@ohos.app.ability.common';
26import { staffItem } from '../common/encryptionComponents/staff';
27import Constants from '../common/constant';
28import {
29  AuthAccount,
30  checkDomainAccountInfo,
31  getOsAccountInfo,
32  calculate,
33  toggleShow,
34  directionStatus,
35  getTime,
36  sendDlpManagerFileConfiguration
37} from '../common/utils';
38import { DlpAlertDialog } from '../common/components/dlp_alert_dialog';
39import GlobalContext from '../common/GlobalContext';
40import HomeFeature from '../feature/HomeFeature';
41import { AccountTipsConfig } from '../common/AccountTipsConfig';
42import { EncryptingPanel } from '../common/encryptionComponents/encrypting';
43import { GetAlertMessage } from '../common/GetAlertMessage';
44import { HiLog } from '../common/HiLog';
45import FileUtils, { FileMsg } from '../common/FileUtils';
46
47const TAG = 'ModEnc';
48
49class PermissionValue {
50  public value: Resource | undefined
51  public data: string = ''
52  public index: number = 0
53}
54
55let abilityResult: ability.AbilityResult = {
56  'resultCode': 0,
57  'want': {}
58};
59
60@Extend(Text)
61function customizeText() {
62  .fontColor($r('sys.color.ohos_id_color_text_primary_activated'))
63  .fontSize($r('sys.float.ohos_id_text_size_button2'))
64  .fontWeight(FontWeight.Medium)
65}
66
67let storage = LocalStorage.getShared();
68@Entry(storage)
69@Component
70struct changeEncryption {
71  private homeFeature: HomeFeature = GlobalContext.load('homeFeature');
72  @State session: UIExtensionContentSession | undefined =
73    storage === undefined ? undefined : storage.get<UIExtensionContentSession>('session');
74  dlpAlertDialog?: CustomDialogController;
75  srcFileName: string = '';
76  linkFileName: string = '';
77  @State directionStatus: number = 0;
78  @State handlePopup: boolean = false;
79  @State handlePopupReadOnly: boolean = false;
80  @State handlePopupEdit: boolean = false;
81  @State authPerm: number = 2;
82  @State routerFlag: boolean = false;
83  @State editFlag: boolean = false;
84  @State readOnlyFlag: boolean = false;
85  @State rowNamesLenEdit: number = 0;
86  @State rowNamesLenReadOnly: number = 0;
87  @State hideNamesNumEdit: string = '0';
88  @State hideNamesNumReadOnly: string = '0';
89  @State prepareData: boolean = false;
90  @State showNamesArrEdit: AuthAccount[] = [];
91  @State showNamesArrReadOnly: AuthAccount[] = [];
92  @State staffDataArrayReadOnly: AuthAccount[] = [];
93  @State staffDataArrayEdit: AuthAccount[] = [];
94  private routerData: Record<string, AuthAccount[]> = {};
95  @State permissionDict: PermissionValue[] = [
96    {
97      value: $r('app.string.PERMISSION_TYPE_SELECT_TARGET') as Resource, data: 'target', index: 0
98    },
99    {
100      value: $r('app.string.PERMISSION_TYPE_SELECT_ALL') as Resource, data: 'all', index: 1
101    },
102    {
103      value: $r('app.string.PERMISSION_TYPE_SELECT_SELF') as Resource, data: 'self', index: 2
104    }
105  ];
106  @State selectedPermissionTypeReadOnly: PermissionValue = {
107    data: '',
108    value: $r('app.string.PERMISSION_TYPE_SELECT_ALL'),
109    index: 0
110  }
111  @State selectedPermissionTypeEdit: PermissionValue = {
112    data: '',
113    value: $r('app.string.PERMISSION_TYPE_SELECT_ALL'),
114    index: 1
115  }
116
117  @Builder popupBuilderReadOnly() {
118    Row() {
119      Text($r('app.string.header_title_readonly_tips'))
120        .fontFamily('HarmonyHeiTi')
121        .fontSize($r('sys.float.ohos_id_text_size_body2'))
122        .fontColor($r('sys.color.ohos_id_color_text_primary'))
123    }
124    .width(Constants.HEADER_COLUMN_MESSAGE_TIPS)
125    .padding({
126      left: Constants.ROW_FONT_SIZE,
127      right: Constants.ROW_FONT_SIZE,
128      top: Constants.DA_MARGIN_TOP,
129      bottom: Constants.DA_MARGIN_TOP
130    })
131  }
132
133  @Builder popupBuilderEdit() {
134    Row() {
135      Text($r('app.string.header_title_edit_tips'))
136        .fontSize($r('sys.float.ohos_id_text_size_body2'))
137        .fontColor($r('sys.color.ohos_id_color_text_primary'))
138    }
139    .width(Constants.HEADER_COLUMN_MESSAGE_TIPS)
140    .padding({
141      left: Constants.ROW_FONT_SIZE,
142      right: Constants.ROW_FONT_SIZE,
143      top: Constants.DA_MARGIN_TOP,
144      bottom: Constants.DA_MARGIN_TOP
145    })
146  }
147
148  showErrorDialog(title: string | Resource, message: string | Resource) {
149    this.dlpAlertDialog = new CustomDialogController({
150      builder: DlpAlertDialog({
151        title: title,
152        message: message,
153        action: () => {
154        }
155      }),
156      autoCancel: false,
157      customStyle: true,
158      maskColor: Constants.TRANSPARENT_BACKGROUND_COLOR
159    });
160    this.dlpAlertDialog.open();
161  }
162
163  async catchProcess() {
164    if (GlobalContext.load('requestIsFromSandBox') as boolean) {
165      HiLog.info(TAG, `resumeFuseLink: ${this.srcFileName}`);
166      this.homeFeature.resumeFuseLinkHome(GlobalContext.load('uri'), (err: number) => {
167        if (err !== 0) {
168          HiLog.error(TAG, `resumeFuseLink failed: ${err}`);
169        }
170      });
171    }
172  }
173
174  stopFuseLinkHome() {
175    return new Promise<void>((resolve, reject) => {
176      this.homeFeature.stopFuseLinkHome(GlobalContext.load('uri'), (err: number) => {
177        if (err !== 0) {
178          HiLog.error(TAG, `stopFuseLink failed: ${err}`);
179          this.showErrorDialog($r('app.string.TITLE_APP_ERROR') as Resource,
180            $r('app.string.MESSAGE_SERVICE_INSIDE_ERROR') as Resource);
181          reject();
182        }
183        resolve();
184      });
185    })
186  }
187
188  recoverDLPFileHome(plainUri: string) {
189    return new Promise<void>((resolve, reject) => {
190      this.homeFeature.recoverDLPFileHome(GlobalContext.load('uri'), plainUri, async (err: number) => {
191        if (err !== 0) {
192          HiLog.error(TAG, `recoverDLPFile: ${this.srcFileName}, failed: ${err}`);
193          let errorInfo =
194            {'title': '', 'msg': $r('app.string.MESSAGE_RECOVER_DLP_ERROR') } as Record<string, string | Resource>;
195          this.showErrorDialog(errorInfo.title, errorInfo.msg);
196          await this.catchProcess();
197          reject();
198        }
199        resolve();
200      });
201    })
202  }
203
204  async unEncrypt() {
205    let plaintextFile = FileUtils.getFileMsgByFileName(this.srcFileName);
206    if (GlobalContext.load('requestIsFromSandBox') as boolean) {
207      try {
208        await this.stopFuseLinkHome();
209      } catch {
210        return;
211      }
212    }
213    HiLog.info(TAG, `Decrypt DLP file: ${this.srcFileName}`);
214    try {
215      let srcFileUri: string = GlobalContext.load('uri');
216      let srcFileMsg: FileMsg = FileUtils.getAllSuffixByUri(srcFileUri);
217      let documentSaveOptions = new picker.DocumentSaveOptions();
218      documentSaveOptions.newFileNames = [decodeURIComponent(plaintextFile)];
219      documentSaveOptions.fileSuffixChoices = [`.${srcFileMsg.fileType}`];
220      documentSaveOptions.defaultFilePathUri = srcFileUri.substring(0,
221        srcFileUri.length - srcFileMsg.fileType.length - srcFileMsg.fileName.length - 5);
222      let documentPicker = new picker.DocumentViewPicker();
223      documentPicker.save(documentSaveOptions).then(async (saveRes) => {
224        if (saveRes === undefined || saveRes.length === 0) {
225          HiLog.error(TAG, `fail to get uri`);
226          await this.catchProcess();
227          return;
228        }
229        HiLog.info(TAG, `get uri success`);
230        try {
231          await this.fileDecryption(saveRes);
232        } catch {
233          HiLog.info(TAG, `file decryption fail`);
234        }
235      }).catch((err: number) => {
236        HiLog.error(TAG, `DocumentViewPicker save failed: ${JSON.stringify(err)}`);
237      });
238    } catch (err) {
239      HiLog.error(TAG, `Decrypt DLP file: ${this.srcFileName}, failed: ${JSON.stringify(err)}`);
240    }
241  }
242
243  async fileDecryption(saveRes: Array<string>): Promise<void> {
244    let plainUri = saveRes[0];
245    let uriInfo: fileUri.FileUri | undefined = undefined;
246    let file: fs.File | undefined = undefined;
247    try {
248      uriInfo = new fileUri.FileUri(plainUri);
249    } catch (err) {
250      HiLog.info(TAG, `fileUri fail: ${JSON.stringify(err)}`);
251    }
252    try {
253      file = await fs.open(plainUri, fs.OpenMode.READ_WRITE);
254      await this.recoverDLPFileHome(plainUri);
255    } catch (err) {
256      HiLog.error(TAG, `recoverDLPFile: ${this.srcFileName}, failed: ${JSON.stringify(err)}`);
257      try {
258        await fs.unlink(uriInfo!.path);
259      } catch (err) {
260        HiLog.info(TAG, `unlink fail: ${JSON.stringify(err)}`);
261      }
262      let errorInfo =
263        {'title': '', 'msg': $r('app.string.MESSAGE_RECOVER_DLP_ERROR') } as Record<string, string | Resource>;
264      this.showErrorDialog(errorInfo.title as Resource, errorInfo.msg as Resource);
265      await this.catchProcess();
266      return;
267    } finally {
268      if (file) {
269        fs.closeSync(file);
270      }
271    }
272    await this.terminateSelfWithResult();
273  }
274
275  async terminateSelfWithResult() {
276    if (GlobalContext.load('requestIsFromSandBox') as boolean) { //no need close dlp file in sandbox
277      HiLog.info(TAG, `resumeFuseLink: ${this.srcFileName}`);
278      this.homeFeature.resumeFuseLinkHome(GlobalContext.load('uri'), (err: number) => {
279        if (err !== 0) {
280          HiLog.error(TAG, `resumeFuseLink failed: ${err}`);
281        }
282      });
283    } else {
284      HiLog.info(TAG, `closeDLPFile: ${this.srcFileName}`);
285      this.homeFeature.closeDLPFileHome(GlobalContext.load('uri'), (err: number) => {
286        if (err !== 0) {
287          HiLog.error(TAG, `closeDLPFile failed: ${err}`);
288        }
289      });
290    }
291    if (this.session !== undefined) {
292      this.session.terminateSelfWithResult({
293        'resultCode': 0,
294        'want': {
295          'bundleName': Constants.DLP_MANAGER_BUNDLE_NAME,
296        },
297      });
298    } else {
299      if (GlobalContext.load('fileOpenHistoryFromMain')) {
300        (GlobalContext.load('fileOpenHistoryFromMain') as Map<string, Object>)
301          .delete(GlobalContext.load('uri') as string)
302      }
303      abilityResult.resultCode = 0;
304      (getContext(this) as common.UIAbilityContext).terminateSelfWithResult(abilityResult);
305    }
306  }
307
308  async showData(defaultDlpProperty: dlpPermission.DLPProperty) {
309    this.permissionDict.forEach(async (item, index) => {
310      this.permissionDict[index].value = $r(getContext(this).resourceManager.getStringSync(item.value!.id))
311    });
312    let readOnlyData = (defaultDlpProperty.authUserList?.filter((item: dlpPermission.AuthUser) => {
313      return item.dlpFileAccess === 1;
314    })) ?? [];
315    let editData = defaultDlpProperty.authUserList?.filter((item: dlpPermission.AuthUser) => {
316      return item.dlpFileAccess === 2;
317    }) ?? [];
318    const filterEditFilter = () => {
319      if (editData.length === 0) {
320        this.selectedPermissionTypeEdit = this.permissionDict[2];
321        AppStorage.setOrCreate('hiWriteScope', 'Onlyme');
322      } else {
323        this.staffDataArrayEdit = editData;
324        this.selectedPermissionTypeEdit = this.permissionDict[0];
325        AppStorage.setOrCreate('hiWriteScope', 'User');
326      }
327    };
328    if ((defaultDlpProperty.everyoneAccessList !== undefined) && (defaultDlpProperty.everyoneAccessList.length > 0)) {
329      let perm = Math.max(...defaultDlpProperty.everyoneAccessList);
330      if (perm === dlpPermission.DLPFileAccess.CONTENT_EDIT) {
331        this.selectedPermissionTypeReadOnly = this.permissionDict[1];
332        AppStorage.setOrCreate('hiReadScope', 'Everyone');
333        this.selectedPermissionTypeEdit = this.permissionDict[1];
334        AppStorage.setOrCreate('hiWriteScope', 'Everyone');
335        this.staffDataArrayReadOnly = readOnlyData;
336      } else if (perm === dlpPermission.DLPFileAccess.READ_ONLY) {
337        this.selectedPermissionTypeReadOnly = this.permissionDict[1];
338        AppStorage.setOrCreate('hiReadScope', 'Everyone');
339        this.staffDataArrayReadOnly = [];
340        filterEditFilter();
341      } else {
342        AppStorage.setOrCreate('hiReadScope', 'User');
343      }
344    } else {
345      AppStorage.setOrCreate('hiReadScope', 'User');
346      this.staffDataArrayReadOnly = readOnlyData;
347      filterEditFilter();
348    }
349    try {
350      await this.getRouterParams();
351    } catch (err) {
352      HiLog.error(TAG, `fail to get routerParams`);
353    }
354  }
355
356  async getRouterParams() {
357    let routerParams: Record<string, AuthAccount[]> = router.getParams() as Record<string, AuthAccount[]>;
358    if (routerParams !== undefined) { // router
359      this.staffDataArrayReadOnly = routerParams.staffDataArrayReadOnly as AuthAccount[];
360      this.staffDataArrayEdit = routerParams.staffDataArrayEdit as AuthAccount[];
361
362      this.routerData = {
363        'staffDataArrayReadOnly': this.staffDataArrayReadOnly,
364        'staffDataArrayEdit': this.staffDataArrayEdit,
365      } as Record<string, AuthAccount[]>;
366    } else { // ability
367      await AccountTipsConfig.getConfigTips();
368      await this.getTextContent();
369
370      this.routerData = {
371        'staffDataArrayReadOnly': this.staffDataArrayReadOnly,
372        'staffDataArrayEdit': this.staffDataArrayEdit,
373      } as Record<string, AuthAccount[]>;
374    }
375  }
376
377  async getTextContent(): Promise<void> {
378    let tempStaffDataArray = [...this.staffDataArrayReadOnly, ...this.staffDataArrayEdit];
379    for (let index = 0; index < tempStaffDataArray['length']; index++) {
380      try {
381        let result: osAccount.DomainAccountInfo = await AccountTipsConfig
382          .getAccountInfo(tempStaffDataArray[index].authAccount);
383        tempStaffDataArray[index].textContent = result[AccountTipsConfig.showContentKey];
384
385        if (index === tempStaffDataArray['length'] - 1) {
386          return Promise.resolve();
387        }
388      } catch (err) {
389        let session: UIExtensionContentSession = GlobalContext.load('session') as UIExtensionContentSession;
390        await GetAlertMessage.startAlertAbility(getContext(this) as common.UIExtensionContext,
391          err as BusinessError, session);
392        return Promise.reject();
393      }
394    }
395  }
396
397  async aboutToAppear() {
398    this.prepareData = true;
399    try {
400      GlobalContext.store('accountInfo', await getOsAccountInfo());
401    } catch (err) {
402      HiLog.error(TAG, `getOsAccountInfo failed: ${JSON.stringify(err)}`);
403      if (this.session !== undefined) {
404        let errorInfo = GetAlertMessage.getAlertMessage({ code: Constants.ERR_JS_GET_ACCOUNT_ERROR } as BusinessError);
405        this.showErrorDialog(errorInfo.title, errorInfo.msg);
406      } else {
407        await GetAlertMessage.startAlertAbility(getContext(this) as common.UIExtensionContext,
408          { code: Constants.ERR_JS_GET_ACCOUNT_ERROR } as BusinessError);
409      }
410      return;
411    }
412    let codeMessage = checkDomainAccountInfo(GlobalContext.load('accountInfo') as osAccount.OsAccountInfo);
413    if (codeMessage) {
414      if (this.session !== undefined) {
415        let errorInfo = GetAlertMessage.getAlertMessage(
416          { code: codeMessage } as BusinessError);
417        this.showErrorDialog(errorInfo.title, errorInfo.msg);
418      } else {
419        await GetAlertMessage.startAlertAbility(getContext(this) as common.UIExtensionContext,
420          { code: codeMessage } as BusinessError);
421      }
422      return;
423    }
424    if (GlobalContext.load('requestIsFromSandBox') as boolean) {
425      HiLog.info(TAG, `request from sandbox`);
426      this.linkFileName = GlobalContext.load('linkFileName') as string;
427      this.srcFileName = GlobalContext.load('dlpFileName') as string;
428    } else {
429      HiLog.info(TAG, `request from normal`);
430      this.srcFileName = GlobalContext.load('dlpFileName') as string;
431    }
432    await this.showData(GlobalContext.load('dlpProperty'));
433    setTimeout(() => {
434      this.prepareData = false;
435    }, Constants.ENCRYPTION_SET_TIMEOUT_TIME)
436
437    this.directionStatus = (getContext(this) as common.UIExtensionContext).config.direction ?? -1;
438    directionStatus((counter) => {
439      this.directionStatus = counter;
440    })
441  }
442
443  build() {
444    GridRow({
445      columns: {
446        xs: Constants.XS_COLUMNS,
447        sm: Constants.SM_COLUMNS,
448        md: Constants.MD_COLUMNS,
449        lg: Constants.LG_COLUMNS
450      },
451      gutter: Constants.DIALOG_GUTTER
452    }) {
453      GridCol({
454        span: {
455          xs: Constants.XS_SPAN,
456          sm: Constants.SM_SPAN,
457          md: Constants.DIALOG_MD_SPAN,
458          lg: Constants.DIALOG_LG_SPAN
459        },
460        offset: {
461          xs: Constants.XS_OFFSET,
462          sm: Constants.SM_OFFSET,
463          md: Constants.DIALOG_MD_OFFSET,
464          lg: Constants.DIALOG_LG_OFFSET
465        }
466      }) {
467        Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center,
468          direction: FlexDirection.Column }) {
469          Flex({ alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
470            EncryptingPanel({ processing: $prepareData, loadingType: Constants.LOAD_TYPE_CE })
471            if (!this.prepareData) {
472              Column() {
473                Row() {
474                  Text($r('app.string.header_title'))
475                    .fontWeight(FontWeight.Bold)
476                    .fontFamily($r('app.string.typeface'))
477                    .fontColor($r('sys.color.ohos_id_color_text_primary'))
478                    .fontSize($r('sys.float.ohos_id_text_size_dialog_tittle'))
479                    .lineHeight(Constants.HEADER_TEXT_LINE_HEIGHT)
480                    .width(Constants.HEADER_TEXT_WIDTH)
481                    .align(Alignment.Start)
482                }
483                .width(Constants.HEADER_COLUMN_WIDTH)
484                .height(Constants.HEADER_COLUMN_HEIGHT)
485                .padding({
486                  left: Constants.HEADER_COLUMN_PADDING_LEFT,
487                  right: Constants.HEADER_COLUMN_PADDING_RIGHT
488                })
489                .margin({ bottom: Constants.HEADER_COLUMN_MARGIN_BOTTOM });
490
491                Scroll() {
492                  Column() {
493                    Row() {
494                      Text($r('app.string.permissions_are_restricted'))
495                        .fontWeight(FontWeight.Regular)
496                        .fontColor($r('sys.color.ohos_id_color_text_secondary'))
497                        .fontSize($r('sys.float.ohos_id_text_size_body1'))
498                        .width(Constants.HEADER_TEXT_WIDTH)
499                        .align(Alignment.Start)
500                    }
501                    .width(Constants.HEADER_COLUMN_WIDTH)
502                    .margin({ bottom: Constants.ENCRYPTION_CHANGE_TIPS_MARGIN_BOTTOM })
503
504                    Column() {
505                      if (this.selectedPermissionTypeReadOnly.data === 'all') {
506                        Row() {
507                          Text($r('app.string.header_title_readonly'))
508                            .fontWeight(FontWeight.Medium)
509                            .fontColor($r('sys.color.ohos_id_color_text_primary'))
510                            .fontSize($r('sys.float.ohos_id_text_size_body2'))
511                          Text(' : ')
512                            .fontFamily($r('app.string.typeface'))
513                            .fontWeight(FontWeight.Regular)
514                            .fontColor($r('sys.color.ohos_id_color_text_primary'))
515                            .fontSize($r('sys.float.ohos_id_text_size_body2'))
516                          Text($r('app.string.PERMISSION_TYPE_SELECT_ALL'))
517                            .fontFamily($r('app.string.typeface'))
518                            .fontWeight(FontWeight.Regular)
519                            .fontColor($r('sys.color.ohos_id_color_text_primary'))
520                            .fontSize($r('sys.float.ohos_id_text_size_body2'))
521                          Image($r('app.media.ic_public_detail'))
522                            .width(Constants.FOOTER_ROW_PAD_RIGHT)
523                            .height(Constants.FOOTER_ROW_PAD_RIGHT)
524                            .margin({ left: Constants.AP_TEXT_PAD_RIGHT })
525                            .fillColor($r('sys.color.icon_secondary'))
526                            .onClick(() => {
527                              this.handlePopupReadOnly = !this.handlePopupReadOnly
528                            })
529                            .draggable(false)
530                            .bindPopup(this.handlePopupReadOnly, {
531                              builder: this.popupBuilderReadOnly,
532                              placement: Placement.BottomLeft,
533                              offset: { x: Constants.POPUP_OFFSET_X },
534                              enableArrow: true,
535                              showInSubWindow: false,
536                              onStateChange: (e) => {
537                                if (!e.isVisible) {
538                                  this.handlePopupReadOnly = false
539                                }
540                              }
541                            })
542                        }
543                        .width(Constants.FOOTER_ROW_WIDTH)
544                        .height(Constants.ENCRYPTION_READ_ONLY_EDIT_HEIGHT)
545                        .margin({
546                          top: Constants.ENCRYPTION_SUCCESS_ADD_STAFF_MARGIN_TOP,
547                          bottom: Constants.ENCRYPTION_SUCCESS_ADD_STAFF_MARGIN_BOTTOM
548                        })
549                      } else {
550                        if (this.staffDataArrayReadOnly['length']) {
551                          Row() {
552                            Text($r('app.string.header_title_readonly'))
553                              .fontWeight(FontWeight.Medium)
554                              .fontColor($r('sys.color.ohos_id_color_text_primary'))
555                              .fontSize($r('sys.float.ohos_id_text_size_body2'))
556                            Text(` (${this.staffDataArrayReadOnly['length']}):`)
557                              .fontFamily($r('app.string.typeface'))
558                              .fontWeight(FontWeight.Regular)
559                              .fontColor($r('sys.color.ohos_id_color_text_primary'))
560                              .fontSize($r('sys.float.ohos_id_text_size_body2'))
561                            Image($r('app.media.ic_public_detail'))
562                              .width(Constants.FOOTER_ROW_PAD_RIGHT)
563                              .height(Constants.FOOTER_ROW_PAD_RIGHT)
564                              .margin({ left: Constants.AP_TEXT_PAD_RIGHT })
565                              .fillColor($r('sys.color.icon_secondary'))
566                              .onClick(() => {
567                                this.handlePopupReadOnly = !this.handlePopupReadOnly
568                              })
569                              .draggable(false)
570                              .bindPopup(this.handlePopupReadOnly, {
571                                builder: this.popupBuilderReadOnly,
572                                placement: Placement.BottomLeft,
573                                offset: { x: Constants.POPUP_OFFSET_X },
574                                enableArrow: true,
575                                showInSubWindow: false,
576                                onStateChange: (e) => {
577                                  if (!e.isVisible) {
578                                    this.handlePopupReadOnly = false
579                                  }
580                                }
581                              })
582                          }
583                          .width(Constants.FOOTER_ROW_WIDTH)
584                          .height(Constants.ENCRYPTION_READ_ONLY_EDIT_HEIGHT)
585                          .margin({ top: Constants.FOOTER_ROW_MARGIN })
586
587                          Flex({
588                            direction: FlexDirection.Row,
589                            wrap: FlexWrap.Wrap,
590                          }) {
591                            if (this.staffDataArrayReadOnly['length'] > 0) {
592                              ForEach(
593                                this.showNamesArrReadOnly,
594                                (item: AuthAccount, index) => {
595                                  staffItem({
596                                    authAccount: item.authAccount,
597                                    textContent: item.textContent,
598                                    isActive: false,
599                                    changeIndex: Number(index),
600                                  })
601                                },
602                                (item: AuthAccount) => item.authAccount
603                              )
604                              if (Number(this.hideNamesNumReadOnly) > 0) {
605                                Row() {
606                                  if (this.showNamesArrReadOnly.length !== this.staffDataArrayReadOnly['length']) {
607                                    Text() {
608                                      Span('+')
609                                      Span(this.hideNamesNumReadOnly)
610                                    }
611                                    .customizeText()
612                                  }
613                                  Image($r('app.media.icon_change'))
614                                    .draggable(false)
615                                    .width(Constants.PP_IMAGE_HEIGHT)
616                                    .height(Constants.PP_TEXT_FONT_SIZE2)
617                                    .objectFit(ImageFit.Contain)
618                                    .fillColor($r('sys.color.ohos_id_color_secondary'))
619                                    .rotate({
620                                      angle: !this.readOnlyFlag ?
621                                        Constants.PP_BUTTON_PAD : Constants.ENCRYPTION_SUCCESS_TRANSLATE
622                                    })
623                                    .transition({ type: TransitionType.All, opacity: Constants.PP_BUTTON_PAD })
624                                }
625                                .height(Constants.ENCRYPTION_SUCCESS_TOGGLE_HEIGHT)
626                                .onClick(() => {
627                                  let showValue = toggleShow(
628                                    this.staffDataArrayReadOnly,
629                                    this.showNamesArrReadOnly,
630                                    this.readOnlyFlag,
631                                    this.rowNamesLenReadOnly
632                                  );
633                                  this.showNamesArrReadOnly = showValue.showNamesArr as AuthAccount[];
634                                  this.readOnlyFlag = showValue.showFlag as boolean;
635                                })
636                              }
637                            }
638                          }
639                          .onAreaChange((oldValue: Area, newValue: Area) => {
640                            if (oldValue.width ===
641                              Constants.ENCRYPTION_ON_AREA_CHANGE_WIDTH || newValue.width !== oldValue.width) {
642                              let nameValue = calculate(newValue, this.staffDataArrayReadOnly);
643                              this.rowNamesLenReadOnly = nameValue.rowNamesLen as number;
644                              this.showNamesArrReadOnly = nameValue.showNamesArr as AuthAccount[];
645                              this.hideNamesNumReadOnly = nameValue.hideNamesNum as string;
646                              this.readOnlyFlag = false;
647                            }
648                          })
649                          .margin({
650                            top: Constants.ENCRYPTION_SUCCESS_ADD_STAFF_MARGIN_TOP,
651                            bottom: Constants.ENCRYPTION_SUCCESS_ADD_STAFF_MARGIN_BOTTOM
652                          })
653                        }
654                      }
655                      if (['all', 'self'].includes(this.selectedPermissionTypeEdit.data)) {
656                        Row() {
657                          Text($r('app.string.header_title_edit'))
658                            .fontWeight(FontWeight.Medium)
659                            .fontColor($r('sys.color.ohos_id_color_text_primary'))
660                            .fontSize($r('sys.float.ohos_id_text_size_body2'))
661                          Text(' : ')
662                            .fontFamily($r('app.string.typeface'))
663                            .fontWeight(FontWeight.Regular)
664                            .fontColor($r('sys.color.ohos_id_color_text_primary'))
665                            .fontSize($r('sys.float.ohos_id_text_size_body2'))
666                          Text(this.selectedPermissionTypeEdit.data === 'all' ? $r('app.string.PERMISSION_TYPE_SELECT_ALL') : $r('app.string.PERMISSION_TYPE_SELECT_SELF'))
667                            .fontFamily($r('app.string.typeface'))
668                            .fontWeight(FontWeight.Regular)
669                            .fontColor($r('sys.color.ohos_id_color_text_primary'))
670                            .fontSize($r('sys.float.ohos_id_text_size_body2'))
671                          Image($r('app.media.ic_public_detail'))
672                            .width(Constants.FOOTER_ROW_PAD_RIGHT)
673                            .height(Constants.FOOTER_ROW_PAD_RIGHT)
674                            .margin({ left: Constants.AP_TEXT_PAD_RIGHT })
675                            .fillColor($r('sys.color.icon_secondary'))
676                            .onClick(() => {
677                              this.handlePopupEdit = !this.handlePopupEdit
678                            })
679                            .draggable(false)
680                            .bindPopup(this.handlePopupEdit, {
681                              builder: this.popupBuilderEdit,
682                              placement: Placement.BottomLeft,
683                              offset: { x: Constants.POPUP_OFFSET_X },
684                              enableArrow: true,
685                              showInSubWindow: false,
686                              onStateChange: (e) => {
687                                if (!e.isVisible) {
688                                  this.handlePopupEdit = false
689                                }
690                              }
691                            })
692                        }
693                        .justifyContent(FlexAlign.Start)
694                        .width(Constants.FOOTER_ROW_WIDTH)
695                        .height(Constants.ENCRYPTION_READ_ONLY_EDIT_HEIGHT)
696                        .margin({
697                          top: Constants.ENCRYPTION_SUCCESS_ADD_STAFF_MARGIN_TOP,
698                          bottom: Constants.ENCRYPTION_SUCCESS_ADD_STAFF_MARGIN_BOTTOM
699                        })
700                      } else {
701                        if (this.staffDataArrayEdit['length']) {
702                          Row() {
703                            Text($r('app.string.header_title_edit'))
704                              .fontWeight(FontWeight.Medium)
705                              .fontColor($r('sys.color.ohos_id_color_text_primary'))
706                              .fontSize($r('sys.float.ohos_id_text_size_body2'))
707                            Text(` (${this.staffDataArrayEdit['length']}):`)
708                              .fontFamily($r('app.string.typeface'))
709                              .fontWeight(FontWeight.Regular)
710                              .fontColor($r('sys.color.ohos_id_color_text_primary'))
711                              .fontSize($r('sys.float.ohos_id_text_size_body2'))
712                            Image($r('app.media.ic_public_detail'))
713                              .width(Constants.FOOTER_ROW_PAD_RIGHT)
714                              .height(Constants.FOOTER_ROW_PAD_RIGHT)
715                              .margin({ left: Constants.AP_TEXT_PAD_RIGHT })
716                              .fillColor($r('sys.color.icon_secondary'))
717                              .onClick(() => {
718                                this.handlePopupEdit = !this.handlePopupEdit
719                              })
720                              .draggable(false)
721                              .bindPopup(this.handlePopupEdit, {
722                                builder: this.popupBuilderEdit,
723                                placement: Placement.BottomLeft,
724                                offset: { x: Constants.POPUP_OFFSET_X },
725                                enableArrow: true,
726                                showInSubWindow: false,
727                                onStateChange: (e) => {
728                                  if (!e.isVisible) {
729                                    this.handlePopupEdit = false
730                                  }
731                                }
732                              })
733                          }
734                          .justifyContent(FlexAlign.Start)
735                          .width(Constants.FOOTER_ROW_WIDTH)
736                          .height(Constants.ENCRYPTION_READ_ONLY_EDIT_HEIGHT)
737
738                          Flex({
739                            direction: FlexDirection.Row,
740                            wrap: FlexWrap.Wrap,
741                          }) {
742                            if (this.staffDataArrayEdit['length'] > 0) {
743                              ForEach(
744                                this.showNamesArrEdit,
745                                (item: AuthAccount, index) => {
746                                  staffItem({
747                                    authAccount: item.authAccount,
748                                    textContent: item.textContent,
749                                    isActive: false,
750                                    changeIndex: Number(index),
751                                  })
752                                },
753                                (item: AuthAccount) => item.authAccount
754                              )
755                              if (Number(this.hideNamesNumEdit) > 0) {
756                                Row() {
757                                  if (this.showNamesArrEdit.length !== this.staffDataArrayEdit['length']) {
758                                    Text() {
759                                      Span('+')
760                                      Span(this.hideNamesNumEdit)
761                                    }
762                                    .customizeText()
763                                  }
764                                  Image($r('app.media.icon_change'))
765                                    .draggable(false)
766                                    .width(Constants.PP_IMAGE_HEIGHT)
767                                    .height(Constants.PP_TEXT_FONT_SIZE2)
768                                    .objectFit(ImageFit.Contain)
769                                    .fillColor($r('sys.color.ohos_id_color_secondary'))
770                                    .rotate({
771                                      angle: !this.editFlag ?
772                                        Constants.PP_BUTTON_PAD : Constants.ENCRYPTION_SUCCESS_TRANSLATE
773                                    })
774                                    .transition({ type: TransitionType.All, opacity: Constants.PP_BUTTON_PAD })
775                                }
776                                .height(Constants.ENCRYPTION_SUCCESS_TOGGLE_HEIGHT)
777                                .onClick(() => {
778                                  let showValue = toggleShow(
779                                    this.staffDataArrayEdit,
780                                    this.showNamesArrEdit,
781                                    this.editFlag,
782                                    this.rowNamesLenEdit
783                                  );
784                                  this.showNamesArrEdit = showValue.showNamesArr as AuthAccount[];
785                                  this.editFlag = showValue.showFlag as boolean;
786                                })
787                              }
788                            }
789                          }
790                          .onAreaChange((oldValue: Area, newValue: Area) => {
791                            if (oldValue.width ===
792                              Constants.ENCRYPTION_ON_AREA_CHANGE_WIDTH || newValue.width !== oldValue.width) {
793                              let nameValue = calculate(newValue, this.staffDataArrayEdit);
794                              this.rowNamesLenEdit = nameValue.rowNamesLen as number;
795                              this.showNamesArrEdit = nameValue.showNamesArr as AuthAccount[];
796                              this.hideNamesNumEdit = nameValue.hideNamesNum as string;
797                              this.editFlag = false;
798                            }
799                          })
800                          .margin({
801                            top: Constants.ENCRYPTION_SUCCESS_ADD_STAFF_MARGIN_TOP,
802                            bottom: Constants.ENCRYPTION_SUCCESS_ADD_STAFF_MARGIN_BOTTOM
803                          })
804                        }
805                      }
806                      Column({ space: Constants.HEADER_ROW_FONT_SIZE }) {
807                        Row() {
808                          Text($r('app.string.Document_valid_until'))
809                            .fontSize($r('sys.float.ohos_id_text_size_body2'))
810                            .fontColor($r('sys.color.ohos_id_color_text_primary'))
811                            .fontWeight(FontWeight.Medium)
812                            .textAlign(TextAlign.Start)
813                          Text(' : ')
814                            .fontFamily($r('app.string.typeface'))
815                            .fontWeight(FontWeight.Regular)
816                            .fontColor($r('sys.color.ohos_id_color_text_primary'))
817                            .fontSize($r('sys.float.ohos_id_text_size_body2'))
818                          Text(getTime())
819                            .fontSize($r('sys.float.ohos_id_text_size_body2'))
820                            .fontColor($r('sys.color.ohos_id_color_text_secondary'))
821                            .fontWeight(FontWeight.Regular)
822                            .width(Constants.HEADER_COLUMN_WIDTH)
823                            .textAlign(TextAlign.Start)
824                            .margin({ left: Constants.AP_TEXT_PAD_RIGHT })
825                        }
826                        .width(Constants.HEADER_COLUMN_WIDTH)
827                        .height(Constants.AP_MARGIN_TOP)
828                      }
829                      .padding({
830                        bottom: Constants.ENCRYPTION_CHANGE_VALID_UNTIL_MARGIN_BOTTOM
831                      })
832                    }
833                  }
834                }.constraintSize({
835                  maxHeight: this.directionStatus ===
836                    0 ? Constants.CHANGE_MAX_HEIGHT : Constants.ENCRYPTION_SUCCESS_MAX_HEIGHT
837                })
838                .padding({
839                  left: Constants.HEADER_COLUMN_PADDING_LEFT,
840                  right: Constants.HEADER_COLUMN_PADDING_RIGHT
841                })
842                .margin({ bottom: Constants.ENCRYPTION_CHANGE_VALID_UNTIL_MARGIN_BOTTOM });
843                Flex({ direction: FlexDirection.Row }) {
844                  Button($r('app.string.unencrypted'), { type: ButtonType.Capsule, stateEffect: true })
845                    .backgroundColor($r('sys.color.ohos_id_color_button_normal'))
846                    .width(Constants.HEADER_TEXT_WIDTH)
847                    .height(Constants.FOOTER_HEIGHT)
848                    .fontColor($r('sys.color.ohos_id_color_text_primary_activated'))
849                    .onClick(async (event) => {
850                      AppStorage.setOrCreate('hiOperation', 'Delete_policy');
851                      AppStorage.setOrCreate('hiAdvancedSettings', false);
852                      AppStorage.setOrCreate('hiStorePath', false);
853                      AppStorage.setOrCreate('hiValidDate', false);
854                      AppStorage.setOrCreate('hiAccountVerifySucc', 0);
855                      AppStorage.setOrCreate('hiAccountVerifyFail', 0);
856                      this.unEncrypt();
857                      sendDlpManagerFileConfiguration();
858                    })
859                    .margin({ right: Constants.ENCRYPTION_PROTECTION_BUTTON_MARGIN })
860                  Button($r('app.string.change_encryption'), { type: ButtonType.Capsule, stateEffect: true })
861                    .backgroundColor($r('sys.color.ohos_id_color_button_normal'))
862                    .width(Constants.HEADER_TEXT_WIDTH)
863                    .fontColor($r('sys.color.ohos_id_color_text_primary_activated'))
864                    .height(Constants.FOOTER_HEIGHT)
865                    .onClick(async (event) => {
866                      router.replaceUrl({
867                        url: 'pages/encryptionProtection',
868                        params: this.routerData
869                      })
870                    })
871                    .margin({ left: Constants.ENCRYPTION_PROTECTION_BUTTON_MARGIN })
872                }
873                .margin({
874                  left: Constants.ENCRYPTION_BUTTON_TO_BUTTON_WIDTH,
875                  right: Constants.ENCRYPTION_BUTTON_TO_BUTTON_WIDTH,
876                  bottom: Constants.ENCRYPTION_BUTTON_MARGIN_BOTTOM,
877                  top: Constants.ENCRYPTION_BUTTON_TO_BUTTON_WIDTH
878                })
879              }
880              .visibility(this.prepareData ? Visibility.Hidden : Visibility.Visible)
881              .width(Constants.ENCRYPTION_PC_FIXING_WIDTH)
882              .backgroundColor($r('sys.color.ohos_id_color_dialog_bg'))
883              .borderRadius($r('sys.float.ohos_id_corner_radius_dialog'))
884              .constraintSize({
885                minWidth: Constants.ENCRYPTION_PC_FIXING_WIDTH
886              })
887              .backgroundBlurStyle(BlurStyle.COMPONENT_ULTRA_THICK);
888            }
889          }
890        }
891      }
892    }
893    .backgroundColor($r('sys.color.mask_fourth'))
894  }
895}
896