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 measure from '@ohos.measure'; 17import window from '@ohos.window'; 18import ability from '@ohos.ability.ability'; 19import account_osAccount from '@ohos.account.osAccount'; 20import emitter from '@ohos.events.emitter'; 21import dlpPermission from '@ohos.dlpPermission'; 22import bundleManager from '@ohos.bundle.bundleManager'; 23import fs from '@ohos.file.fs'; 24import zlib from '@ohos.zlib'; 25import util from '@ohos.util'; 26import fileUri from '@ohos.file.fileuri'; 27import { BusinessError, Callback } from '@ohos.base' 28import Want from '@ohos.app.ability.Want'; 29import common from '@ohos.app.ability.common'; 30import connection from '@ohos.net.connection'; 31import Constants from '../common/constant'; 32import GlobalContext from './GlobalContext'; 33import hiSysEvent from '@ohos.hiSysEvent'; 34import { HiLog } from '../common/HiLog'; 35import { systemDateTime } from '@kit.BasicServicesKit'; 36 37const TAG = 'Utils'; 38const HEAD_LENGTH_IN_BYTE = 28; 39const HEAD_LENGTH_IN_U32 = 7; 40const CERT_OFFSET = 5; 41const CERT_SIZE = 6; 42 43const NET_CAPABILITY_INTERNET: number = 12; 44const NET_CAPABILITY_VALIDATED: number = 16; 45const NET_CAPABILITY_CHECKING_CONNECTIVITY: number = 31; 46const TIME_OUT_SECONDS: number = 3; 47const SLEEP_MILLISECONDS: number = 200; 48 49const DAY_TO_MILLISECOND: number = 1000 * 60 * 60 * 24; 50const MINUTE_TO_MILLISECOND: number = 1000 * 60; 51const SECOND_TO_MILLISECOND: number = 1000; 52 53const enum UnitType { 54 DAY_UNIT = 1, 55 MINUTE_UNIT = 2, 56 SECOND_UNIT = 3, 57} 58 59const UNIT_MAP = new Map<number, number>([ 60 [UnitType.DAY_UNIT, DAY_TO_MILLISECOND], 61 [UnitType.MINUTE_UNIT, MINUTE_TO_MILLISECOND], 62 [UnitType.SECOND_UNIT, SECOND_TO_MILLISECOND], 63]); 64 65class ChangeOption { 66 public offset: number = 0 67 public length: number = 0 68} 69let defaultDlpProperty: dlpPermission.DLPProperty = { 70 ownerAccount: '', 71 ownerAccountType: dlpPermission.AccountType.DOMAIN_ACCOUNT, 72 authUserList: [], 73 contactAccount: '', 74 offlineAccess: true, 75 ownerAccountID: '', 76 everyoneAccessList: [] 77} 78 79let defaultDlpFile: dlpPermission.DLPFile = { 80 dlpProperty: defaultDlpProperty, 81 recoverDLPFile: async () => {}, 82 closeDLPFile: async () => {}, 83 addDLPLinkFile: async () => {}, 84 stopFuseLink: async () => {}, 85 resumeFuseLink: async () => {}, 86 replaceDLPLinkFile: async () => {}, 87 deleteDLPLinkFile: async () => {} 88}; 89 90interface AuthAccount { 91 authAccount: string; 92 textContent?: string; 93} 94 95interface PermissionType { 96 value: Resource; 97 data: string; 98 index: number; 99} 100 101interface DLPInfo { 102 name: string; 103 versionCode: string; 104} 105 106function getFileUriByPath(filePath: string): string { 107 try { 108 let uri = fileUri.getUriFromPath(filePath); 109 return uri; 110 } catch (err) { 111 HiLog.error(TAG, `getUriFromPath error: ${JSON.stringify(err)}`); 112 return ''; 113 } 114} 115 116function getFileFd(uri: string, mode?: number): number { 117 mode = mode || fs.OpenMode.READ_ONLY; 118 try { 119 let file = fs.openSync(uri, mode); 120 HiLog.info(TAG, `open: ${uri}, as: ${file.fd}`); 121 return file.fd; 122 } catch (err) { 123 HiLog.error(TAG, `openSync error: ${JSON.stringify(err)}`); 124 return -1; 125 } 126} 127 128async function getOsAccountInfo(): Promise<account_osAccount.OsAccountInfo> { 129 let accountMgr = account_osAccount.getAccountManager(); 130 return await accountMgr.queryOsAccount(); 131} 132 133function checkDomainAccountInfo(accountInfo: account_osAccount.OsAccountInfo): number { 134 AppStorage.setOrCreate('hiAccountType', dlpPermission.AccountType.DOMAIN_ACCOUNT); 135 if (accountInfo.domainInfo.accountName === '' && 136 accountInfo.domainInfo.accountId === '') { 137 AppStorage.setOrCreate('hiAccountStatus', 0); 138 return Constants.ERR_JS_APP_NO_ACCOUNT_ERROR; 139 } 140 if (!accountInfo.domainInfo.isAuthenticated) { 141 AppStorage.setOrCreate('hiAccountStatus', 0); 142 return Constants.ERR_JS_APP_SYSTEM_IS_AUTHENTICATED; 143 } 144 AppStorage.setOrCreate('hiAccountStatus', 1); 145 return Constants.ERR_JS_APP_ACCOUNT_INFO; 146} 147 148async function getUserId(): Promise<number> { 149 let accountMgr = account_osAccount.getAccountManager(); 150 return await accountMgr.getOsAccountLocalId(); 151} 152 153function getAuthPerm(accountName: string, dlpProperty: dlpPermission.DLPProperty): dlpPermission.DLPFileAccess { 154 let perm: dlpPermission.DLPFileAccess = dlpPermission.DLPFileAccess.NO_PERMISSION; 155 if (accountName === dlpProperty.ownerAccount) { 156 return dlpPermission.DLPFileAccess.FULL_CONTROL; 157 } 158 if ((dlpProperty.everyoneAccessList !== undefined) && (dlpProperty.everyoneAccessList.length > 0)) { 159 perm = Math.max(...dlpProperty.everyoneAccessList); 160 } 161 let authUserList = dlpProperty.authUserList ?? []; 162 for (let i = 0; i < authUserList.length; ++i) { 163 let authUser = authUserList[i]; 164 if (authUser.authAccount === accountName) { 165 return authUser.dlpFileAccess; 166 } 167 } 168 return perm; 169} 170 171function terminateSelfWithResult(resultCode: number, result: string): void { 172 let abilityResult: ability.AbilityResult = { 173 resultCode: resultCode, 174 want: { 175 parameters: { 176 result: result 177 } 178 } 179 }; 180 try { 181 (getContext() as common.UIAbilityContext).terminateSelfWithResult(abilityResult); 182 } catch (error) { 183 HiLog.error(TAG, `terminateSelfWithResult exception, error is ${JSON.stringify(error)}`); 184 } 185} 186 187function judgeIsSandBox(want: Want) { 188 return new Promise<boolean>(async resolve => { 189 let callerToken: number = want.parameters?.['ohos.aafwk.param.callerToken'] as number; 190 let callerBundleName: string = want.parameters?.['ohos.aafwk.param.callerBundleName'] as string; 191 try { 192 let applicationInfo = await bundleManager.getApplicationInfo( 193 callerBundleName, bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT); 194 if (callerToken === applicationInfo.accessTokenId) { 195 resolve(false); 196 return; 197 } 198 } catch (error) { 199 HiLog.error(TAG, `getApplicationInfo exception, error is ${JSON.stringify(error)}`); 200 resolve(false); 201 return; 202 } 203 resolve(true); 204 }) 205} 206 207let removeDuplicate = (arr: AuthAccount[], arg: string) => { 208 let map: Map<string, AuthAccount> = new Map(); 209 for (let item of arr) { 210 if (!map.has(item.authAccount)) { 211 map.set(item.authAccount, item); 212 } 213 } 214 return Array.from<AuthAccount>(map.values()); 215} 216 217 218let calculate = (newValue: Area, allNames: AuthAccount[]) => { 219 let editLength = allNames.length; 220 let screenWidth = Number(newValue['width']); 221 let nameChange = Constants.ENCRYPTION_STAFF_WIDTH_NAME; 222 let rowNamesLen = Math.floor(screenWidth / (nameChange + Constants.ENCRYPTION_ADD_STAFF_MARGIN_RIGHT)); 223 let showNamesArr = editLength > Constants.ENCRYPTION_DOUBLED_NUMBER * rowNamesLen 224 ? allNames.slice(0, 2 * rowNamesLen - 1) 225 : allNames.slice(0, 2 * rowNamesLen); 226 let hideNamesNum = editLength - showNamesArr.length > 0 227 ? String(editLength - showNamesArr.length) 228 : '0'; 229 return { 230 'rowNamesLen': rowNamesLen, 231 'showNamesArr': showNamesArr, 232 'hideNamesNum': hideNamesNum 233 } as Record<string, number | AuthAccount[] | string> 234} 235 236let toggleShow = (allNames: AuthAccount[], showNamesArr: AuthAccount[], editFlag: boolean, rowNamesLen: number) => { 237 if (showNamesArr.length < allNames.length) { 238 let showFlag = !editFlag; 239 let showNamesArr = allNames; 240 return { 241 'showNamesArr': showNamesArr, 242 'showFlag': showFlag 243 } as Record<string, AuthAccount[] | boolean>; 244 } else { 245 let showFlag = !editFlag; 246 let showNamesArr = allNames.length > Constants.ENCRYPTION_DOUBLED_NUMBER * rowNamesLen 247 ? allNames.slice(0, Constants.ENCRYPTION_DOUBLED_NUMBER * rowNamesLen - 1) 248 : allNames.slice(0, Constants.ENCRYPTION_DOUBLED_NUMBER * rowNamesLen); 249 return { 250 'showNamesArr': showNamesArr, 251 'showFlag': showFlag 252 } as Record<string, AuthAccount[] | boolean>; 253 } 254} 255 256function directionStatus(func: Callback<number>) { 257 let innerEvent: emitter.InnerEvent = { 258 eventId: Constants.ENCRYPTION_EMIT_DIRECTION_STATUS 259 }; 260 emitter.on(innerEvent, (eventData: emitter.EventData) => { 261 func(eventData.data?.direction); 262 }); 263} 264 265function getAppId(bundleName: string) { 266 return new Promise<string>(async (resolve, reject) => { 267 let bundleFlags: number = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO; 268 let userId = await getUserId(); 269 try { 270 let data = await bundleManager.getBundleInfo(bundleName, bundleFlags, userId); 271 if (data.signatureInfo.appId) { 272 resolve(data.signatureInfo.appId); 273 return; 274 } 275 reject(); 276 } catch (err) { 277 HiLog.error(TAG, `get appId failed: ${JSON.stringify(err)}`); 278 reject(); 279 } 280 }) 281} 282 283function getTime() { 284 let permanent: boolean | undefined = AppStorage.get('permanent'); 285 if (permanent) { 286 return $r('app.string.permanently'); 287 } 288 let dateTime: number | undefined = AppStorage.get('validity'); 289 if (dateTime !== undefined) { 290 let date = new Date(dateTime); 291 let year = date.getFullYear(); 292 let month = date.getMonth() + 1; 293 let day = date.getDate(); 294 let hour = date.getHours(); 295 let minute = date.getMinutes(); 296 return `${year}/${month}/${day} ${hour}:${minute}`; 297 } else { 298 return ''; 299 } 300} 301 302async function getFileSizeByUri(uri: string): Promise<number> { 303 let inFile: fs.File | undefined; 304 try { 305 inFile = await fs.open(uri, fs.OpenMode.READ_ONLY); 306 let stat = await fs.stat(inFile.fd); 307 HiLog.info(TAG, `get file info succeed, the size of file is: ${stat.size}`); 308 return stat.size; 309 } catch (err) { 310 HiLog.error(TAG, `open: ${uri}, failed: ${JSON.stringify(err)}`); 311 HiLog.error(TAG, `get file info failed with error message: ${JSON.stringify(err)}`); 312 return -1; 313 } finally { 314 if (inFile) { 315 fs.closeSync(inFile); 316 } 317 } 318} 319 320function getDLPInfo() { 321 return new Promise<DLPInfo>(async (resolve, reject) => { 322 let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT; 323 try { 324 bundleManager.getBundleInfoForSelf(bundleFlags, (err, data) => { 325 if (err) { 326 HiLog.error(TAG, `getBundleInfoForSelf failed. Cause: ${JSON.stringify(err)}`); 327 reject({name: '', versionCode: ''}); 328 } else { 329 resolve({name: data.name, versionCode: data.versionCode.toString()}); 330 } 331 }); 332 } catch (err) { 333 HiLog.error(TAG, `getBundleInfoForSelf failed. Cause: ${JSON.stringify(err)}`); 334 reject({name: '', versionCode: ''}); 335 } 336 }) 337} 338 339function sendDlpManagerAccountLogin(errorCode: number) { 340 let event: hiSysEvent.SysEventInfo = { 341 domain: 'DLP_UE', 342 name: 'DLP_MANAGER_ACCOUNT_LOGIN', 343 eventType: hiSysEvent?.EventType?.BEHAVIOR, 344 params: { 345 'PNAMEID': AppStorage.get('hiPNameId') ?? '', 346 'PVERSIONID': AppStorage.get('hiPVersionId') ?? '', 347 'ACCOUNT_TYPE': AppStorage.get('hiAccountType') ?? '', 348 'ACCOUNT_STATUS': AppStorage.get('hiAccountStatus') ?? -1, 349 'LOGIN_FAIL_CODE': errorCode ?? -1, 350 'PKG_NAME': AppStorage.get('hiPkgName') ?? '', 351 } as Record<string, number> 352 }; 353 354 try { 355 hiSysEvent.write(event); 356 } catch (err) { 357 HiLog.error(TAG, `sendDlpManagerAccountLogin failed`); 358 } 359} 360 361function sendDlpManagerFileConfiguration() { 362 let event: hiSysEvent.SysEventInfo = { 363 domain: 'DLP_UE', 364 name: 'DLP_MANAGER_FILE_CONFIGURATION', 365 eventType: hiSysEvent?.EventType?.BEHAVIOR, 366 params: { 367 'PNAMEID': AppStorage.get('hiPNameId') ?? '', 368 'PVERSIONID': AppStorage.get('hiPVersionId') ?? '', 369 'OPERATION': AppStorage.get('hiOperation') ?? '', 370 'READ_SCOPE': AppStorage.get('hiReadScope') ?? '', 371 'WRITE_SCOPE': AppStorage.get('hiWriteScope') ?? '', 372 'ADVANCED_SETTINGS': AppStorage.get('hiAdvancedSettings') ?? false, 373 'STORE_PATH': AppStorage.get('hiStorePath') ?? false, 374 'ACCOUNT_VERIFY_SUCC': AppStorage.get('hiAccountVerifySucc') ?? -1, 375 'ACCOUNT_VERIFY_FAIL': AppStorage.get('hiAccountVerifyFail') ?? -1, 376 'VALID_DATE': AppStorage.get('hiValidDate') ?? false, 377 } as Record<string, number> 378 }; 379 380 try { 381 hiSysEvent.write(event); 382 } catch (err) { 383 HiLog.error(TAG, `sendDlpManagerFileConfiguration failed`); 384 } 385} 386 387function sendDlpFileCreateProperties(accountType: number) { 388 let event: hiSysEvent.SysEventInfo = { 389 domain: 'DLP_UE', 390 name: 'DLP_FILE_CREATE_EVENT', 391 eventType: hiSysEvent?.EventType?.BEHAVIOR, 392 params: { 393 'ACCOUNT_TYPE': accountType, 394 'PNAMEID': AppStorage.get('hiPNameId') ?? '', 395 'PVERSIONID': AppStorage.get('hiPVersionId') ?? '', 396 'CODE': AppStorage.get('hiCode') ?? -1, 397 'FILE_SIZE': AppStorage.get('hiFileSize') ?? -1, 398 'FILE_TYPE': AppStorage.get('hiFileType') ?? '', 399 'POLICY_SIZE_ENC': AppStorage.get('hiPolicySizeEnc') ?? -1, 400 'PKG_NAME': AppStorage.get('hiPkgName') ?? '', 401 } as Record<string, number> 402 }; 403 404 try { 405 hiSysEvent.write(event); 406 } catch (err) { 407 HiLog.error(TAG, `sendDlpFileCreateProperties failed`); 408 } 409} 410 411function sendDlpFileOpenProperties() { 412 let event: hiSysEvent.SysEventInfo = { 413 domain: 'DLP_UE', 414 name: 'DLP_FILE_OPEN_EVENT', 415 eventType: hiSysEvent?.EventType?.BEHAVIOR, 416 params: { 417 'PNAMEID': AppStorage.get('hiPNameId') ?? '', 418 'PVERSIONID': AppStorage.get('hiPVersionId') ?? '', 419 'CODE': AppStorage.get('hiCode') ?? -1, 420 'SANDBOX_PKGNAME': AppStorage.get('hiSandboxPkgName') ?? '', 421 'SANDBOX_INDEX': AppStorage.get('hiSandboxIndex') ?? -1, 422 'ACCOUNT_TYPE': AppStorage.get('hiAccountType') ?? '', 423 'FILE_SIZE': AppStorage.get('hiFileSize') ?? -1, 424 'POLICY_SIZE_ENC': AppStorage.get('hiPolicySizeEnc') ?? -1, 425 } as Record<string, number> 426 }; 427 428 try { 429 hiSysEvent.write(event); 430 } catch (err) { 431 HiLog.error(TAG, `sendDlpFileOpenProperties failed`); 432 } 433} 434 435function isValidPath(path: string): Boolean { 436 if (path.indexOf('./') !== -1 || path.indexOf('../') !== -1) { 437 return false; 438 } 439 return true; 440} 441 442function getAccountType( 443 context: common.ServiceExtensionContext | common.UIExtensionContext, fd: number): Promise<number> { 444 return new Promise(async (resolve, reject) => { 445 let z = new ArrayBuffer(HEAD_LENGTH_IN_BYTE); 446 let option: ChangeOption = { offset: 0, length: HEAD_LENGTH_IN_BYTE }; 447 try { 448 fs.readSync(fd, z, option); 449 } catch (error) { 450 HiLog.error(TAG, `readSync exception, error is ${JSON.stringify(error)}`); 451 reject(); 452 return; 453 } 454 let buf = new Uint32Array(z, 0, HEAD_LENGTH_IN_U32); 455 if (buf && buf[0] === Constants.DLP_ZIP_MAGIC) { 456 let random = String(Math.random()).substring(Constants.RAND_START, Constants.RAND_END); 457 let filePath = context.filesDir + '/saveAs' + random; 458 let dirPath = context.filesDir + '/saveAsUnzip' + random; 459 let fileName = dirPath + '/dlp_cert'; 460 let ff: fs.File | undefined; 461 try { 462 fs.readSync(fd, z, option); 463 ff = await fs.open(filePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); 464 await fs.copyFile(fd, ff.fd); 465 await fs.mkdir(dirPath); 466 await zlib.decompressFile(filePath, dirPath); 467 let dlpInfo = fs.readTextSync(fileName); 468 let infoArray = dlpInfo.split('accountType'); 469 let type = infoArray[1].slice(Constants.TYPE_START, Constants.TYPE_END); 470 GlobalContext.store('accountType', Number(type)); 471 resolve(Number(type)); 472 } catch (err) { 473 HiLog.error(TAG, `decompressFile: ${JSON.stringify(err)}`); 474 reject(err); 475 } finally { 476 closeFile(ff); 477 deleteFile(filePath); 478 removeDir(dirPath); 479 } 480 } else { 481 let cert = new ArrayBuffer(buf[CERT_SIZE]); 482 option = { offset: buf[CERT_OFFSET], length: buf[CERT_SIZE] }; 483 try { 484 fs.readSync(fd, cert, option); 485 let textDecoder: util.TextDecoder = util.TextDecoder.create('utf-8'); 486 let fdString: string = textDecoder.decodeWithStream(new Uint8Array(cert), { stream: false }); 487 let infoArray = fdString.split('accountType'); 488 let type = infoArray[1].slice(Constants.TYPE_START, Constants.TYPE_END); 489 GlobalContext.store('accountType', Number(type)); 490 resolve(Number(type)); 491 } catch (err) { 492 HiLog.error(TAG, `getStringFromFd error: ${JSON.stringify(err)}`); 493 reject(); 494 } 495 } 496 }) 497} 498 499function closeFile(file: fs.File | undefined) { 500 try { 501 if (file) { 502 fs.closeSync(file); 503 } 504 } catch (err) { 505 HiLog.error(TAG, `closeSync: ${JSON.stringify(err)}`); 506 } 507} 508 509function deleteFile(file: string) { 510 try { 511 let res = fs.accessSync(file); 512 if (res) { 513 fs.unlinkSync(file); 514 } 515 } catch (err) { 516 HiLog.error(TAG, `deleteFile: ${JSON.stringify(err)}`); 517 } 518} 519 520function removeDir(file: string) { 521 try { 522 let res = fs.accessSync(file); 523 if (res) { 524 fs.rmdirSync(file); 525 } 526 } catch (err) { 527 HiLog.error(TAG, `rmdirSync: ${JSON.stringify(err)}`); 528 } 529} 530 531function getCurrentTime(isNano: boolean = false): number { 532 return systemDateTime.getTime(isNano); 533} 534 535function isExpire(timestamp: number, diff: number, unit: number): boolean { 536 if (isNaN(timestamp) || diff <= 0) { 537 return true; 538 } 539 let multipleMill = UNIT_MAP.get(unit); 540 if (!multipleMill) { 541 HiLog.error(TAG, 'Invalid unit'); 542 return false; 543 } 544 545 let currentTime = getCurrentTime(); 546 const diffMilliSecond = Number(currentTime) - Number(timestamp); 547 const compareDiffSec = diff * multipleMill; 548 return diffMilliSecond > compareDiffSec; 549} 550 551async function sleep(milliSeconds: number): Promise<void> { 552 return new Promise<void>(resolve => setTimeout(resolve, milliSeconds)); 553} 554 555async function getConnectionStatus(exactly: boolean = true): Promise<boolean> { 556 HiLog.info(TAG, `Enter getConnectionStatus, exactly mode: ${exactly}.`); 557 try { 558 const startTime = getCurrentTime(); 559 let net: connection.NetHandle = await connection.getDefaultNet(); 560 561 let capabilities: connection.NetCapabilities = await connection.getNetCapabilities(net); 562 HiLog.info(TAG, `Succeeded to get net capabilities, ${JSON.stringify(capabilities)}.`); 563 let networkCap = capabilities.networkCap; 564 565 while (exactly && networkCap?.includes(NET_CAPABILITY_CHECKING_CONNECTIVITY)) { 566 HiLog.info(TAG, `Checking connectivity...`); 567 if (isExpire(startTime, TIME_OUT_SECONDS, UnitType.SECOND_UNIT)) { 568 HiLog.error(TAG, 'Network connection check failed.'); 569 return false; 570 } 571 await sleep(SLEEP_MILLISECONDS); 572 net = await connection.getDefaultNet(); 573 capabilities = await connection.getNetCapabilities(net); 574 networkCap = capabilities.networkCap; 575 } 576 577 let internetExists = networkCap?.includes(NET_CAPABILITY_INTERNET); 578 let validatedExists = networkCap?.includes(NET_CAPABILITY_VALIDATED); 579 if (internetExists && validatedExists) { 580 HiLog.debug(TAG, 'Net connection is valid.'); 581 return true; 582 } else { 583 HiLog.error(TAG, 'Net connection is invalid.'); 584 } 585 } catch (error) { 586 HiLog.error(TAG, `GetConnectionStatus failed: ${JSON.stringify(error)}`); 587 } 588 return false; 589} 590 591function checkNetworkStatus(): Promise<void> { 592 return new Promise((resolve, reject) => { 593 try { 594 let netHandle = connection.getDefaultNetSync(); 595 connection.getNetCapabilities(netHandle, (error: BusinessError, data: connection.NetCapabilities) => { 596 if (error) { 597 HiLog.error(TAG, `checkNetworkStatus failed: ${JSON.stringify(error)}`); 598 reject(); 599 return; 600 } 601 HiLog.info(TAG, `network Succeeded to get data: ${JSON.stringify(data)}`); 602 const result = [connection.NetCap.NET_CAPABILITY_INTERNET, connection.NetCap.NET_CAPABILITY_VALIDATED] 603 .every(element => data.networkCap?.includes(element)); 604 if (result) { 605 resolve(); 606 return; 607 } 608 reject(); 609 }) 610 } catch (error) { 611 reject(); 612 } 613 }) 614} 615 616export { 617 AuthAccount, 618 PermissionType, 619 getOsAccountInfo, 620 checkDomainAccountInfo, 621 getUserId, 622 getAuthPerm, 623 terminateSelfWithResult, 624 judgeIsSandBox, 625 getFileFd, 626 getFileUriByPath, 627 removeDuplicate, 628 calculate, 629 toggleShow, 630 directionStatus, 631 getAppId, 632 getTime, 633 getFileSizeByUri, 634 getDLPInfo, 635 sendDlpManagerAccountLogin, 636 sendDlpManagerFileConfiguration, 637 sendDlpFileCreateProperties, 638 sendDlpFileOpenProperties, 639 DLPInfo, 640 isValidPath, 641 defaultDlpFile, 642 getAccountType, 643 checkNetworkStatus, 644 getConnectionStatus 645}; 646