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