修改GlobalContext

Signed-off-by: swg3156201044 <shiweigang2@huawei.com>
This commit is contained in:
swg3156201044 2023-09-27 16:20:58 +08:00
parent e8a3aa6f25
commit c108f200a3
15 changed files with 237 additions and 227 deletions

View File

@ -23,8 +23,8 @@ const TAG = '[DLPManager_Alert]';
export default class AlertAbility extends UIAbility {
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
console.info(TAG, 'onCreate');
GlobalContext.getContext().setObject('abilityWant', want);
GlobalContext.getContext().setObject('alertContext', this.context)
GlobalContext.store('abilityWant', want);
GlobalContext.store('alertContext', this.context)
}
onDestroy(): void {

View File

@ -34,7 +34,7 @@ export default class DataAbility extends ServiceExtensionAbility {
let sandboxAppIndex: number = data.appIndex;
let key: string = bundleName + sandboxAppIndex;
let authPerm2Sandbox:Map<dlpPermission.DLPFileAccess, (number | string)[]> = GlobalContext.getContext().getObject('authPerm2Sandbox') as Map<dlpPermission.DLPFileAccess, (number | string)[]>;
let authPerm2Sandbox:Map<dlpPermission.DLPFileAccess, (number | string)[]> = GlobalContext.load('authPerm2Sandbox') as Map<dlpPermission.DLPFileAccess, (number | string)[]>;
for (let item of Array.from<(dlpPermission.DLPFileAccess|(number | string)[])[]>(authPerm2Sandbox)) {
let itemKey = item[0];
let itemValue = item[1];
@ -44,7 +44,7 @@ export default class DataAbility extends ServiceExtensionAbility {
}
}
let token2File:Map<number, (number | string | dlpPermission.DLPFile)[]> = GlobalContext.getContext().getObject('token2File') as Map<number, (number | string | dlpPermission.DLPFile)[]>;
let token2File:Map<number, (number | string | dlpPermission.DLPFile)[]> = GlobalContext.load('token2File') as Map<number, (number | string | dlpPermission.DLPFile)[]>;
for (let item of Array.from<(number|(number | string | dlpPermission.DLPFile)[])[]>(token2File)) {
let itemKey = item[0];
let itemValue = item[1];
@ -54,7 +54,7 @@ export default class DataAbility extends ServiceExtensionAbility {
}
}
try {
let sandbox2linkFile: Map<string, (number | string | dlpPermission.DLPFile)[][]> = GlobalContext.getContext().getObject('sandbox2linkFile') as Map<string, (number | string | dlpPermission.DLPFile)[][]>;
let sandbox2linkFile: Map<string, (number | string | dlpPermission.DLPFile)[][]> = GlobalContext.load('sandbox2linkFile') as Map<string, (number | string | dlpPermission.DLPFile)[][]>;
if (sandbox2linkFile.has(key)) {
let fileArray: (number | string | dlpPermission.DLPFile)[][] = sandbox2linkFile.get(key) as (number | string | dlpPermission.DLPFile)[][];
for (let i of fileArray) {
@ -79,21 +79,21 @@ export default class DataAbility extends ServiceExtensionAbility {
}
sandbox2linkFile.delete(key);
let fileOpenHistory:Map<string, (number | string)[]> = GlobalContext.getContext().getObject('fileOpenHistory') as Map<string, (number | string)[]>;
let fileOpenHistory:Map<string, (number | string)[]> = GlobalContext.load('fileOpenHistory') as Map<string, (number | string)[]>;
for (let item of Array.from<(string|(number | string)[])[]>(fileOpenHistory)) {
let itemKey = item[0];
let itemValue = item[1];
let tmp: string = (itemValue[0] as string) + (itemValue[1] as number);
if (tmp === key) {
let linkUri: string = itemValue[INDEX_THREE] as string;
(GlobalContext.getContext().getObject('linkSet') as Set<string>).delete(linkUri);
(GlobalContext.load('linkSet') as Set<string>).delete(linkUri);
fileOpenHistory.delete(itemKey as string);
}
}
if (sandbox2linkFile.size === 0) {
console.info(TAG, 'sandbox2linkFile empty');
(GlobalContext.getContext().getObject('dataContext') as common.ServiceExtensionContext).terminateSelf();
(GlobalContext.load('dataContext') as common.ServiceExtensionContext).terminateSelf();
}
}
} catch (err) {
@ -113,7 +113,7 @@ export default class DataAbility extends ServiceExtensionAbility {
onCreate(want: Want): void {
const context = this.context;
GlobalContext.getContext().setObject('dataContext', context);
GlobalContext.store('dataContext', context);
}
onRequest(want: Want, startId: number): void {

View File

@ -47,19 +47,19 @@ export default class MainAbility extends UIAbility {
async onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): Promise<void> {
console.info(TAG, 'onCreate');
GlobalContext.getContext().setObject('abilityWant', want);
GlobalContext.getContext().setObject('context', this.context);
GlobalContext.getContext().setObject('domainAccount', deviceInfo.deviceType === PHONE ? false : true);
GlobalContext.getContext().setObject('uri', want.uri ?? '');
GlobalContext.store('abilityWant', want);
GlobalContext.store('context', this.context);
GlobalContext.store('domainAccount', deviceInfo.deviceType === PHONE ? false : true);
GlobalContext.store('uri', want.uri ?? '');
GlobalContext.getContext().setObject('dsHelper', datafile.createFileAccessHelper(this.context));
GlobalContext.store('dsHelper', datafile.createFileAccessHelper(this.context));
direction = this.context.config.direction ?? -1;
languageValue = this.context.config.language ?? 'zh';
if (!GlobalContext.getContext().getObject('fileOpenHistoryFromMain')) {
GlobalContext.getContext().setObject('fileOpenHistoryFromMain', new Map<string, (string | number)[]>());
if (!GlobalContext.load('fileOpenHistoryFromMain')) {
GlobalContext.store('fileOpenHistoryFromMain', new Map<string, (string | number)[]>());
}
if (!GlobalContext.getContext().getObject('linkSet')) {
GlobalContext.getContext().setObject('linkSet', new Set<string>());
if (!GlobalContext.load('linkSet')) {
GlobalContext.store('linkSet', new Set<string>());
}
}
onConfigurationUpdate(newConfig: Configuration): void {
@ -96,21 +96,21 @@ export default class MainAbility extends UIAbility {
onNewWant(want: Want) {
console.log(TAG, 'onNewWant', JSON.stringify(want));
GlobalContext.getContext().setObject('newWant', want);
GlobalContext.getContext().setObject('uri', (GlobalContext.getContext().getObject('abilityWant') as Want).uri as string);
GlobalContext.store('abilityWant', want);
GlobalContext.store('uri', (GlobalContext.load('abilityWant') as Want).uri as string);
this.getNewWantPage();
}
async showErrorDialogAndExit(error: BusinessError): Promise<void> {
//<!!!>
let abilityWant = GlobalContext.getContext().getObject('abilityWant') as Want;
let abilityWant = GlobalContext.load('abilityWant') as Want;
if (abilityWant.parameters) {
abilityWant.parameters.error = error;
}
let context: common.UIAbilityContext = GlobalContext.getContext().getObject('context') as common.UIAbilityContext;
GlobalContext.getContext().setObject('alertContext', context);
(GlobalContext.getContext().getObject('windowStage') as window.WindowStage).loadContent('pages/alert', (err: BusinessError) => {
let context: common.UIAbilityContext = GlobalContext.load('context') as common.UIAbilityContext;
GlobalContext.store('alertContext', context);
(GlobalContext.load('windowStage') as window.WindowStage).loadContent('pages/alert', (err: BusinessError) => {
if (err.code !== 0) {
console.error(TAG, 'loadContent failed', err.code, err.message);
}
@ -118,12 +118,12 @@ export default class MainAbility extends UIAbility {
}
async gotoPage(windowStage: window.WindowStage, accountInfo: osAccount.OsAccountInfo): Promise<void> {
let accountName: string = (GlobalContext.getContext().getObject('domainAccount') as boolean) ? accountInfo.domainInfo.accountName : accountInfo.distributedInfo.name;
this.authPerm = getAuthPerm(accountName, (GlobalContext.getContext().getObject('dlpFile') as dlpPermission.DLPFile).dlpProperty);
let accountName: string = (GlobalContext.load('domainAccount') as boolean) ? accountInfo.domainInfo.accountName : accountInfo.distributedInfo.name;
this.authPerm = getAuthPerm(accountName, (GlobalContext.load('dlpFile') as dlpPermission.DLPFile).dlpProperty);
console.info(TAG, accountName, 'has dlp access', JSON.stringify(this.authPerm));
AppStorage.SetOrCreate('authPerm', this.authPerm);
AppStorage.SetOrCreate<string>('contactAccount', (GlobalContext.getContext().getObject('dlpFile') as dlpPermission.DLPFile).dlpProperty.contactAccount);
AppStorage.SetOrCreate<string>('contactAccount', (GlobalContext.load('dlpFile') as dlpPermission.DLPFile).dlpProperty.contactAccount);
if (this.authPerm < dlpPermission.DLPFileAccess.READ_ONLY ||
this.authPerm > dlpPermission.DLPFileAccess.FULL_CONTROL) {
await this.showErrorDialogAndExit({ code: Constants.ERR_JS_APP_INSIDE_ERROR } as BusinessError);
@ -149,9 +149,9 @@ export default class MainAbility extends UIAbility {
async findDlpFile(): Promise<void> {
return new Promise(async (resolve, reject) => {
let abilityWant: Want = GlobalContext.getContext().getObject('abilityWant') as Want;
let abilityWant: Want = GlobalContext.load('abilityWant') as Want;
const linkFileName: string = (abilityWant.parameters?.linkFileName as Record<string, string>)?.name;
let sandbox2linkFile:Map<string, (number | string | dlpPermission.DLPFile)[][]> = GlobalContext.getContext().getObject('sandbox2linkFile') as Map<string, (number | string | dlpPermission.DLPFile)[][]>;
let sandbox2linkFile:Map<string, (number | string | dlpPermission.DLPFile)[][]> = GlobalContext.load('sandbox2linkFile') as Map<string, (number | string | dlpPermission.DLPFile)[][]>;
for (let value of Array.from<(number | string | dlpPermission.DLPFile)[][]>(sandbox2linkFile.values())) {
for (let linkFile of value) {
if (linkFile[Constants.FILE_OPEN_HISTORY_ONE] === linkFileName) {
@ -161,12 +161,12 @@ export default class MainAbility extends UIAbility {
reject();
return;
}
GlobalContext.getContext().setObject('dlpFile', linkFile[Constants.FILE_OPEN_HISTORY_ZERO]);
GlobalContext.getContext().setObject('dlpFd', linkFile[Constants.FILE_OPEN_HISTORY_TWO]);
GlobalContext.store('dlpFile', linkFile[Constants.FILE_OPEN_HISTORY_ZERO]);
GlobalContext.store('dlpFd', linkFile[Constants.FILE_OPEN_HISTORY_TWO]);
let dlpFileName: string = (abilityWant.parameters?.fileName as Record<string, string>)?.name;
GlobalContext.getContext().setObject('dlpFileName', dlpFileName);
GlobalContext.getContext().setObject('linkFileName', linkFileName);
console.info(TAG, 'find dlp file', dlpFileName, GlobalContext.getContext().getObject('dlpFd'));
GlobalContext.store('dlpFileName', dlpFileName);
GlobalContext.store('linkFileName', linkFileName);
console.info(TAG, 'find dlp file', dlpFileName, GlobalContext.load('dlpFd'));
resolve();
return;
}
@ -181,15 +181,15 @@ export default class MainAbility extends UIAbility {
async openDlpFile(): Promise<void> {
return new Promise(async (resolve, reject) => {
try {
let dlpFileName: string = ((GlobalContext.getContext().getObject('abilityWant')as Want).parameters?.fileName as Record<string, string>)?.name;
GlobalContext.getContext().setObject('dlpFileName', dlpFileName);
let dlpFd: number = getFileFd(GlobalContext.getContext().getObject('uri') as string);
GlobalContext.getContext().setObject('dlpFd', dlpFd);
let dlpFileName: string = ((GlobalContext.load('abilityWant')as Want).parameters?.fileName as Record<string, string>)?.name;
GlobalContext.store('dlpFileName', dlpFileName);
let dlpFd: number = getFileFd(GlobalContext.load('uri') as string);
GlobalContext.store('dlpFd', dlpFd);
console.info(TAG, 'openDLPFile', dlpFileName, dlpFd);
GlobalContext.getContext().setObject('dlpFile', await dlpPermission.openDLPFile(dlpFd));
GlobalContext.store('dlpFile', await dlpPermission.openDLPFile(dlpFd));
resolve();
} catch (err) {
console.error(TAG, 'openDLPFile', GlobalContext.getContext().getObject('dlpFileName') as string, 'failed', (err as BusinessError).code, (err as BusinessError).message);
console.error(TAG, 'openDLPFile', GlobalContext.load('dlpFileName') as string, 'failed', (err as BusinessError).code, (err as BusinessError).message);
await this.showErrorDialogAndExit(err as BusinessError);
reject(err);
}
@ -197,7 +197,7 @@ export default class MainAbility extends UIAbility {
}
checkValidWant(): boolean {
let parameters = (GlobalContext.getContext().getObject('abilityWant') as Want).parameters;
let parameters = (GlobalContext.load('abilityWant') as Want).parameters;
if (parameters === undefined) {
console.error(TAG, 'need parameters in want');
return false;
@ -210,7 +210,7 @@ export default class MainAbility extends UIAbility {
console.error(TAG, 'need name in want.parameters.fileName');
return false;
}
if ((GlobalContext.getContext().getObject('abilityWant') as Want).uri === undefined) {
if ((GlobalContext.load('abilityWant') as Want).uri === undefined) {
console.error(TAG, 'need uri in want');
return false;
}
@ -220,8 +220,8 @@ export default class MainAbility extends UIAbility {
console.error(TAG, 'need caller info in want.parameters');
return false;
}
let uri = String((GlobalContext.getContext().getObject('abilityWant') as Want).uri);
if ((GlobalContext.getContext().getObject('linkSet') as Set<string>).has(uri)) {
let uri = String((GlobalContext.load('abilityWant') as Want).uri);
if ((GlobalContext.load('linkSet') as Set<string>).has(uri)) {
console.error(TAG, 'invalid uri for opened link uri');
return false;
}
@ -235,7 +235,7 @@ export default class MainAbility extends UIAbility {
async getNewWantPage(): Promise<void> {
console.log(TAG, 'getNewWantPage start');
let windowStage: window.WindowStage = GlobalContext.getContext().getObject('windowStage') as window.WindowStage;
let windowStage: window.WindowStage = GlobalContext.load('windowStage') as window.WindowStage;
if (!this.checkValidWant()) {
await this.showErrorDialogAndExit({ code: Constants.ERR_JS_APP_PARAM_ERROR } as BusinessError);
return;
@ -253,7 +253,7 @@ export default class MainAbility extends UIAbility {
return;
}
let requestIsFromSandBox: boolean = await judgeIsSandBox();
GlobalContext.getContext().setObject('requestIsFromSandBox', requestIsFromSandBox);
GlobalContext.store('requestIsFromSandBox', requestIsFromSandBox);
console.info(TAG, 'request is from sandbox', requestIsFromSandBox);
if (requestIsFromSandBox) {
try {
@ -262,12 +262,12 @@ export default class MainAbility extends UIAbility {
return;
}
} else {
let fileName: string = ((GlobalContext.getContext().getObject('abilityWant') as Want).parameters?.fileName as Record<string, string>)?.name;
let fileName: string = ((GlobalContext.load('abilityWant') as Want).parameters?.fileName as Record<string, string>)?.name;
let isDlpSuffix: boolean = fileName.endsWith('.dlp');
if (!isDlpSuffix) {
console.info(TAG, fileName, 'is not a dlp file');
GlobalContext.getContext().setObject('originFileName', fileName);
GlobalContext.getContext().setObject('originFd', getFileFd(GlobalContext.getContext().getObject('uri') as string));
GlobalContext.store('originFileName', fileName);
GlobalContext.store('originFd', getFileFd(GlobalContext.load('uri') as string));
windowStage.loadContent('pages/encryptionProtection', (err: BusinessError) =>{
if (err.code !== 0) {
console.error(TAG, 'loadContent failed', err.code, err.message);
@ -278,8 +278,8 @@ export default class MainAbility extends UIAbility {
});
return;
} else {
let uri: string = GlobalContext.getContext().getObject('uri') as string;
if ((GlobalContext.getContext().getObject('fileOpenHistory') as Map<string, (number | string)[]>)?.has(uri)) {
let uri: string = GlobalContext.load('uri') as string;
if ((GlobalContext.load('fileOpenHistory') as Map<string, (number | string)[]>)?.has(uri)) {
await this.showErrorDialogAndExit({ code: Constants.ERR_JS_APP_OPEN_REJECTED } as BusinessError);
return;
}
@ -288,8 +288,8 @@ export default class MainAbility extends UIAbility {
} catch {
return;
}
let fileOpenHistoryFromMain: Map<string, (string | number)[]> = GlobalContext.getContext().getObject('fileOpenHistoryFromMain') as Map<string, (string | number)[]>;
fileOpenHistoryFromMain.set(uri, [uri, GlobalContext.getContext().getObject('dlpFileName') as string, GlobalContext.getContext().getObject('dlpFd') as number]);
let fileOpenHistoryFromMain: Map<string, (string | number)[]> = GlobalContext.load('fileOpenHistoryFromMain') as Map<string, (string | number)[]>;
fileOpenHistoryFromMain.set(uri, [uri, GlobalContext.load('dlpFileName') as string, GlobalContext.load('dlpFd') as number]);
console.log(TAG, 'fileOpenHistoryFromMain add', JSON.stringify(fileOpenHistoryFromMain));
}
}
@ -298,10 +298,10 @@ export default class MainAbility extends UIAbility {
async onWindowStageCreate(windowStage: window.WindowStage): Promise<void> {
console.info(TAG, 'onWindowStageCreate');
GlobalContext.getContext().setObject('windowStage', windowStage);
GlobalContext.store('windowStage', windowStage);
try {
let atManager = abilityAccessCtrl.createAtManager();
await atManager.requestPermissionsFromUser(GlobalContext.getContext().getObject('context') as common.UIAbilityContext, permissionList);
await atManager.requestPermissionsFromUser(GlobalContext.load('context') as common.UIAbilityContext, permissionList);
} catch (err) {
console.error(TAG, 'requestPermissionsFromUser failed', err.code, err.message);
return;

View File

@ -49,7 +49,7 @@ class option_ {
let defaultDlpFile: dlpPermission.DLPFile = {
dlpProperty: {
ownerAccount: '',
ownerAccountType: GlobalContext.getContext().getObject('domainAccount') as Boolean
ownerAccountType: GlobalContext.load('domainAccount') as Boolean
? dlpPermission.AccountType.DOMAIN_ACCOUNT : dlpPermission.AccountType.CLOUD_ACCOUNT,
authUserList: [],
contactAccount: '',
@ -123,15 +123,15 @@ export default class SaveAsAbility extends UIAbility {
async onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): Promise<void> {
console.info(TAG, 'onCreate');
GlobalContext.getContext().setObject('abilityWant', want);
GlobalContext.getContext().setObject('context', this.context);
GlobalContext.getContext()
.setObject('dsHelper', await datafile.createFileAccessHelper(GlobalContext.getContext()
.getObject('context') as common.UIAbilityContext));
GlobalContext.store('abilityWant', want);
GlobalContext.store('context', this.context);
GlobalContext
.store('dsHelper', await datafile.createFileAccessHelper(GlobalContext
.load('context') as common.UIAbilityContext));
try {
let atManager = abilityAccessCtrl.createAtManager();
await atManager.requestPermissionsFromUser(GlobalContext.getContext()
.getObject('context') as common.UIAbilityContext, permissionList);
await atManager.requestPermissionsFromUser(GlobalContext
.load('context') as common.UIAbilityContext, permissionList);
} catch (err) {
console.error(TAG, 'requestPermissionsFromUser failed', err.code, err.message);
return;
@ -143,7 +143,7 @@ export default class SaveAsAbility extends UIAbility {
console.error(TAG, 'notifySaveAsResult failed ', (err as BusinessError).code, (err as BusinessError).message);
}
if (this.isOK === true) {
(GlobalContext.getContext().getObject('context') as common.UIAbilityContext).terminateSelf();
(GlobalContext.load('context') as common.UIAbilityContext).terminateSelf();
}
}
@ -153,8 +153,8 @@ export default class SaveAsAbility extends UIAbility {
async onWindowStageCreate(windowStage: window.WindowStage): Promise<void> {
// Main window is created, set main page for this ability
console.info(TAG, 'onWindowStageCreate: ', GlobalContext.getContext()
.getObject('context') as common.UIAbilityContext);
console.info(TAG, 'onWindowStageCreate: ', GlobalContext
.load('context') as common.UIAbilityContext);
}
@ -174,27 +174,27 @@ export default class SaveAsAbility extends UIAbility {
}
async parseParams(): Promise<boolean | void> {
if (GlobalContext.getContext().getObject('abilityWant') === undefined ||
(GlobalContext.getContext().getObject('abilityWant') as Want).parameters === undefined) {
if (GlobalContext.load('abilityWant') === undefined ||
(GlobalContext.load('abilityWant') as Want).parameters === undefined) {
console.error(TAG, 'invalid abilityWant');
return false;
}
this.requestCode = (GlobalContext.getContext().getObject('abilityWant') as Want)
this.requestCode = (GlobalContext.load('abilityWant') as Want)
.parameters?.['requestCode'] as number;
if (this.requestCode === undefined) {
console.error(TAG, 'invalid requestCode');
return false;
}
this.tokenId = (GlobalContext.getContext().getObject('abilityWant') as Want)
this.tokenId = (GlobalContext.load('abilityWant') as Want)
.parameters?.['ohos.aafwk.param.callerToken'] as number;
if (this.tokenId === undefined) {
console.error(TAG, 'invalid tokenId');
return false;
}
this.authPerm = (GlobalContext.getContext().getObject('token2File') as
this.authPerm = (GlobalContext.load('token2File') as
Map<number, (number | string | dlpPermission.DLPFile | dlpPermission.DLPFileAccess)[]>)
.get(this.tokenId)?.[3] as dlpPermission.DLPFileAccess;
@ -202,18 +202,18 @@ export default class SaveAsAbility extends UIAbility {
&& this.authPerm != dlpPermission.DLPFileAccess.FULL_CONTROL) {
console.error(TAG, 'invalid authPerm ', this.authPerm);
this.isOK = false;
await startAlertAbility(GlobalContext.getContext().getObject('context') as common.UIAbilityContext,
await startAlertAbility(GlobalContext.load('context') as common.UIAbilityContext,
{
code: Constants.ERR_JS_DLP_FILE_READ_ONLY
} as BusinessError);
return false;
}
if (!(GlobalContext.getContext().getObject('token2File') as Map<number, Object[]>).has(this.tokenId)) {
if (!(GlobalContext.load('token2File') as Map<number, Object[]>).has(this.tokenId)) {
console.error(TAG, 'invalid token2File');
return;
}
this.fileName = (GlobalContext.getContext().getObject('abilityWant') as Want)
this.fileName = (GlobalContext.load('abilityWant') as Want)
.parameters?.['key_pick_file_name'] as string;
if (this.fileName === undefined) {
console.error(TAG, 'invalid fileName');
@ -315,7 +315,7 @@ export default class SaveAsAbility extends UIAbility {
return {code: errCode, message: ERRCODE_MAP.get(errCode)};
}
async documentPickerSave(...args) {
let context = GlobalContext.getContext().getObject('context') as common.UIAbilityContext;
let context = GlobalContext.load('context') as common.UIAbilityContext;
let config = undefined;
let result = undefined;
try {
@ -349,7 +349,7 @@ export default class SaveAsAbility extends UIAbility {
}
async prepareDlpFile(): Promise<void> {
console.info(TAG, 'getFile start:', JSON.stringify(GlobalContext.getContext().getObject('abilityWant')));
console.info(TAG, 'getFile start:', JSON.stringify(GlobalContext.load('abilityWant')));
let uri = '';
let displayName = '';
@ -383,9 +383,9 @@ export default class SaveAsAbility extends UIAbility {
} catch (err) {
console.log(TAG, 'close fail', (err as BusinessError).code, (err as BusinessError).message);
}
await (GlobalContext.getContext().getObject('dsHelper') as fileAccess.FileAccessHelper).delete(uri);
await (GlobalContext.load('dsHelper') as fileAccess.FileAccessHelper).delete(uri);
this.isOK = false;
await startAlertAbility(GlobalContext.getContext().getObject('context') as common.UIAbilityContext,
await startAlertAbility(GlobalContext.load('context') as common.UIAbilityContext,
{
code: Constants.ERR_JS_APP_INSIDE_ERROR
} as BusinessError);
@ -393,8 +393,8 @@ export default class SaveAsAbility extends UIAbility {
}
let token2File_value: (number | string | dlpPermission.DLPFile | dlpPermission.DLPFileAccess)[]
= (GlobalContext.getContext()
.getObject('token2File') as Map<number, (number | string | dlpPermission.DLPFile | dlpPermission.DLPFileAccess)[]>)
= (GlobalContext
.load('token2File') as Map<number, (number | string | dlpPermission.DLPFile | dlpPermission.DLPFileAccess)[]>)
.get(this.tokenId) as (number | string | dlpPermission.DLPFile | dlpPermission.DLPFileAccess)[];
this.dlpFile = token2File_value[0] as dlpPermission.DLPFile;
this.sandboxBundleName = token2File_value[1] as string;
@ -409,10 +409,10 @@ export default class SaveAsAbility extends UIAbility {
} catch (err) {
console.log(TAG, 'close fail', (err as BusinessError).code, (err as BusinessError).message);
}
await (GlobalContext.getContext().getObject('dsHelper') as fileAccess.FileAccessHelper).delete(uri);
await (GlobalContext.load('dsHelper') as fileAccess.FileAccessHelper).delete(uri);
fs.closeSync(srcFd);
this.isOK = false;
await startAlertAbility(GlobalContext.getContext().getObject('context') as common.UIAbilityContext,
await startAlertAbility(GlobalContext.load('context') as common.UIAbilityContext,
{
code: Constants.ERR_JS_APP_INSIDE_ERROR
} as BusinessError);
@ -428,7 +428,7 @@ export default class SaveAsAbility extends UIAbility {
} catch (err) {
console.log(TAG, 'close fail', (err as BusinessError).code, (err as BusinessError).message);
}
await (GlobalContext.getContext().getObject('dsHelper') as fileAccess.FileAccessHelper).delete(uri);
await (GlobalContext.load('dsHelper') as fileAccess.FileAccessHelper).delete(uri);
fs.closeSync(srcFd);
return;
}
@ -455,10 +455,10 @@ export default class SaveAsAbility extends UIAbility {
} catch (err) {
console.log(TAG, 'close fail', (err as BusinessError).code, (err as BusinessError).message);
}
await (GlobalContext.getContext().getObject('dsHelper') as fileAccess.FileAccessHelper).delete(uri);
await (GlobalContext.load('dsHelper') as fileAccess.FileAccessHelper).delete(uri);
fs.closeSync(srcFd);
this.isOK = false;
await startAlertAbility(GlobalContext.getContext().getObject('context') as common.UIAbilityContext,
await startAlertAbility(GlobalContext.load('context') as common.UIAbilityContext,
{
code: Constants.ERR_JS_APP_INSIDE_ERROR
} as BusinessError);
@ -467,17 +467,17 @@ export default class SaveAsAbility extends UIAbility {
let linkFilePath = Constants.FUSE_PATH + linkFileName;
let linkUri = getFileUriByPath(linkFilePath);
(GlobalContext.getContext().getObject("token2File") as Map<number, Object[]>)
(GlobalContext.load("token2File") as Map<number, Object[]>)
.set(this.tokenId, [this.dlpFile, this.sandboxBundleName, appId, this.authPerm, srcUri]);
let sandbox2linkFile: Map<string, (number | string | dlpPermission.DLPFile)[][]>
= GlobalContext.getContext()
.getObject('sandbox2linkFile') as Map<string, (number | string | dlpPermission.DLPFile)[][]>;
= GlobalContext
.load('sandbox2linkFile') as Map<string, (number | string | dlpPermission.DLPFile)[][]>;
sandbox2linkFile.get(this.sandboxBundleName + appId)?.push([newDlpFile, linkFileName, dstFd, this.tokenId]);
(GlobalContext.getContext().getObject("fileOpenHistory") as Map<string, Object[]>)
(GlobalContext.load("fileOpenHistory") as Map<string, Object[]>)
.set(uri, [this.sandboxBundleName, appId, linkFileName, linkUri]);
(GlobalContext.getContext().getObject("linkSet") as Set<string>).add(linkUri);
(GlobalContext.load("linkSet") as Set<string>).add(linkUri);
this.resultUri = getFileUriByPath(linkFilePath);
@ -494,9 +494,9 @@ export default class SaveAsAbility extends UIAbility {
} catch (err) {
console.log(TAG, 'close fail', (err as BusinessError).code, (err as BusinessError).message);
}
await (GlobalContext.getContext().getObject('dsHelper') as fileAccess.FileAccessHelper).delete(uri);
await (GlobalContext.load('dsHelper') as fileAccess.FileAccessHelper).delete(uri);
this.isOK = false;
await startAlertAbility(GlobalContext.getContext().getObject('context') as common.UIAbilityContext,
await startAlertAbility(GlobalContext.load('context') as common.UIAbilityContext,
{
code: Constants.ERR_JS_APP_INSIDE_ERROR
} as BusinessError);

View File

@ -45,7 +45,7 @@ const SUFFIX_INDEX = 2;
let defaultDlpFile: dlpPermission.DLPFile = {
dlpProperty: {
ownerAccount: '',
ownerAccountType: (GlobalContext.getContext().getObject('domainAccount') as boolean) ? dlpPermission.AccountType.DOMAIN_ACCOUNT : dlpPermission.AccountType.CLOUD_ACCOUNT,
ownerAccountType: (GlobalContext.load('domainAccount') as boolean) ? dlpPermission.AccountType.DOMAIN_ACCOUNT : dlpPermission.AccountType.CLOUD_ACCOUNT,
authUserList: [],
contactAccount: '',
offlineAccess: true,
@ -87,22 +87,22 @@ export default class ViewAbility extends ServiceExtensionAbility {
linkFileWriteable: boolean = false;
async onCreate(want: Want): Promise<void> {
GlobalContext.getContext().setObject('viewContext', this.context);
if (!GlobalContext.getContext().getObject('sandbox2linkFile')) {
GlobalContext.getContext().setObject('sandbox2linkFile', new Map<string, (number | string | dlpPermission.DLPFile)[][]>());
GlobalContext.store('viewContext', this.context);
if (!GlobalContext.load('sandbox2linkFile')) {
GlobalContext.store('sandbox2linkFile', new Map<string, (number | string | dlpPermission.DLPFile)[][]>());
}
if (!GlobalContext.getContext().getObject('fileOpenHistory')) {
GlobalContext.getContext().setObject('fileOpenHistory', new Map<string, (number | string)[]>());
if (!GlobalContext.load('fileOpenHistory')) {
GlobalContext.store('fileOpenHistory', new Map<string, (number | string)[]>());
}
if (!GlobalContext.getContext().getObject('authPerm2Sandbox')) {
GlobalContext.getContext().setObject('authPerm2Sandbox', new Map<dlpPermission.DLPFileAccess, (number | string)[]>());
if (!GlobalContext.load('authPerm2Sandbox')) {
GlobalContext.store('authPerm2Sandbox', new Map<dlpPermission.DLPFileAccess, (number | string)[]>());
}
GlobalContext.getContext().setObject('domainAccount', deviceInfo.deviceType === PHONE ? false : true);
if (!GlobalContext.getContext().getObject('token2File')) {
GlobalContext.getContext().setObject('token2File', new Map<number, (number | string | dlpPermission.DLPFile)[]>());
GlobalContext.store('domainAccount', deviceInfo.deviceType === PHONE ? false : true);
if (!GlobalContext.load('token2File')) {
GlobalContext.store('token2File', new Map<number, (number | string | dlpPermission.DLPFile)[]>());
}
if (!GlobalContext.getContext().getObject('linkSet')) {
GlobalContext.getContext().setObject('linkSet', new Set<string>());
if (!GlobalContext.load('linkSet')) {
GlobalContext.store('linkSet', new Set<string>());
}
}
@ -111,11 +111,11 @@ export default class ViewAbility extends ServiceExtensionAbility {
bundleName: 'com.ohos.dlpmanager',
abilityName: 'DataAbility'
};
await (GlobalContext.getContext().getObject('viewContext') as common.ServiceExtensionContext).startAbility(want);
await (GlobalContext.load('viewContext') as common.ServiceExtensionContext).startAbility(want);
}
startAbility(want: Want, startId: number): void {
(GlobalContext.getContext().getObject('viewContext') as common.ServiceExtensionContext).startAbility(want, async (err) => {
(GlobalContext.load('viewContext') as common.ServiceExtensionContext).startAbility(want, async (err) => {
hiTraceMeter.finishTrace('DlpStartSandboxJs', startId);
if (err && err.code !== 0) {
console.error(TAG, 'startSandboxApp failed', err.code, err.message);
@ -130,26 +130,26 @@ export default class ViewAbility extends ServiceExtensionAbility {
console.error(TAG, 'dlpFile closeDLPFile failed', (err as BusinessError).code, (err as BusinessError).message);
}
opening = false;
await startAlertAbility(GlobalContext.getContext().getObject('viewContext') as common.ServiceExtensionContext, { code: Constants.ERR_JS_APP_INSIDE_ERROR } as BusinessError);
await startAlertAbility(GlobalContext.load('viewContext') as common.ServiceExtensionContext, { code: Constants.ERR_JS_APP_INSIDE_ERROR } as BusinessError);
await this.sendDlpFileOpenFault(Constants.DLP_START_SANDBOX_ERROR, this.sandboxBundleName, this.appIndex, undefined); // 105: DLP_START_SANDBOX_ERROR
} else {
await this.sendDlpFileOpenEvent(Constants.DLP_START_SANDBOX_SUCCESS, this.sandboxBundleName, this.appIndex); // 203: DLP_START_SANDBOX_SUCCESS
let sandbox2linkFile: Map<string, (number | string | dlpPermission.DLPFile)[][]> = GlobalContext.getContext().getObject('sandbox2linkFile') as Map<string, (number | string | dlpPermission.DLPFile)[][]>;
let sandbox2linkFile: Map<string, (number | string | dlpPermission.DLPFile)[][]> = GlobalContext.load('sandbox2linkFile') as Map<string, (number | string | dlpPermission.DLPFile)[][]>;
if (!sandbox2linkFile.has(this.sandboxBundleName + this.appIndex)) {
sandbox2linkFile.set(this.sandboxBundleName + this.appIndex, new Array);
}
if (!this.alreadyOpen) {
sandbox2linkFile.get(this.sandboxBundleName + this.appIndex)?.push([this.dlpFile, this.linkFileName, this.dlpFd, this.tokenId]);
(GlobalContext.getContext().getObject('fileOpenHistory') as Map<string, (number | string)[]>).set(this.uri, [this.sandboxBundleName, this.appIndex, this.linkFileName, this.linkUri]);
(GlobalContext.getContext().getObject('authPerm2Sandbox') as Map<dlpPermission.DLPFileAccess, (number | string)[]>).set(this.authPerm, [this.sandboxBundleName, this.appIndex]);
(GlobalContext.getContext().getObject('token2File') as Map<number, (number | string | dlpPermission.DLPFile |dlpPermission.DLPFileAccess | null)[]>).set(this.tokenId, [this.dlpFile, this.sandboxBundleName, this.appIndex, this.authPerm, this.uri, null, -1]);
(GlobalContext.getContext().getObject('linkSet') as Set<string>).add(this.linkUri);
(GlobalContext.load('fileOpenHistory') as Map<string, (number | string)[]>).set(this.uri, [this.sandboxBundleName, this.appIndex, this.linkFileName, this.linkUri]);
(GlobalContext.load('authPerm2Sandbox') as Map<dlpPermission.DLPFileAccess, (number | string)[]>).set(this.authPerm, [this.sandboxBundleName, this.appIndex]);
(GlobalContext.load('token2File') as Map<number, (number | string | dlpPermission.DLPFile |dlpPermission.DLPFileAccess | null)[]>).set(this.tokenId, [this.dlpFile, this.sandboxBundleName, this.appIndex, this.authPerm, this.uri, null, -1]);
(GlobalContext.load('linkSet') as Set<string>).add(this.linkUri);
}
await this.startDataAbility();
opening = false;
console.debug(TAG, 'startDataAbility success');
}
(GlobalContext.getContext().getObject('viewContext') as common.ServiceExtensionContext).terminateSelf();
(GlobalContext.load('viewContext') as common.ServiceExtensionContext).terminateSelf();
});
}
@ -252,7 +252,7 @@ export default class ViewAbility extends ServiceExtensionAbility {
hiTraceMeter.finishTrace('DlpGetOsAccountJs', startId);
hiTraceMeter.finishTrace('DlpOpenFileJs', startId);
opening = false;
await startAlertAbility(GlobalContext.getContext().getObject('viewContext') as common.ServiceExtensionContext, { code: Constants.ERR_JS_GET_ACCOUNT_ERROR } as BusinessError);
await startAlertAbility(GlobalContext.load('viewContext') as common.ServiceExtensionContext, { code: Constants.ERR_JS_GET_ACCOUNT_ERROR } as BusinessError);
fileio.closeSync(this.dlpFd);
reject(err); return;
}
@ -260,7 +260,7 @@ export default class ViewAbility extends ServiceExtensionAbility {
if (!checkAccountLogin(this.accountInfo)) {
hiTraceMeter.finishTrace('DlpOpenFileJs', startId);
opening = false;
await startAlertAbility(GlobalContext.getContext().getObject('viewContext') as common.ServiceExtensionContext, { code: Constants.ERR_JS_APP_NO_ACCOUNT_ERROR } as BusinessError);
await startAlertAbility(GlobalContext.load('viewContext') as common.ServiceExtensionContext, { code: Constants.ERR_JS_APP_NO_ACCOUNT_ERROR } as BusinessError);
fileio.closeSync(this.dlpFd);
reject();
return;
@ -282,7 +282,7 @@ export default class ViewAbility extends ServiceExtensionAbility {
hiTraceMeter.finishTrace('DlpOpenFileJs', startId);
opening = false;
await this.sendDlpFileOpenFault(Constants.DLP_FILE_PARSE_ERROR, this.sandboxBundleName, -1, (err as BusinessError<string>).data); // 103:DLP_FILE_PARSE_ERROR
await startAlertAbility(GlobalContext.getContext().getObject('viewContext') as common.ServiceExtensionContext, err);
await startAlertAbility(GlobalContext.load('viewContext') as common.ServiceExtensionContext, err);
} catch (e) {
console.error(TAG, 'openDLPFile2', this.fileName, 'failed', (e as BusinessError).code, (e as BusinessError).message, e);
}
@ -303,7 +303,7 @@ export default class ViewAbility extends ServiceExtensionAbility {
async dlpGetAuthPerm(): Promise<void> {
return new Promise(async (resolve, reject) => {
if (GlobalContext.getContext().getObject('domainAccount') as boolean) {
if (GlobalContext.load('domainAccount') as boolean) {
this.authPerm = getAuthPerm(this.accountInfo?.domainInfo.accountName ?? '', this.dlpFile.dlpProperty);
} else {
this.authPerm = getAuthPerm(this.accountInfo?.distributedInfo.name ?? '', this.dlpFile.dlpProperty);
@ -311,7 +311,7 @@ export default class ViewAbility extends ServiceExtensionAbility {
if (this.authPerm < dlpPermission.DLPFileAccess.READ_ONLY ||
this.authPerm > dlpPermission.DLPFileAccess.FULL_CONTROL) {
opening = false;
await startAlertAbility(GlobalContext.getContext().getObject('viewContext') as common.ServiceExtensionContext, { code: Constants.ERR_JS_APP_INSIDE_ERROR } as BusinessError);
await startAlertAbility(GlobalContext.load('viewContext') as common.ServiceExtensionContext, { code: Constants.ERR_JS_APP_INSIDE_ERROR } as BusinessError);
await this.closeFile();
reject();
return;
@ -325,7 +325,7 @@ export default class ViewAbility extends ServiceExtensionAbility {
this.alreadyOpen = false;
try {
this.gatheringType = await dlpPermission.getDLPGatheringPolicy();
let fileOpenHistory: Map<string, (number | string)[]> = GlobalContext.getContext().getObject('fileOpenHistory') as Map<string, (number | string)[]>;
let fileOpenHistory: Map<string, (number | string)[]> = GlobalContext.load('fileOpenHistory') as Map<string, (number | string)[]>;
if (fileOpenHistory.has(this.uri)) {
console.info(TAG, 'file', this.fileName, 'already open');
let value: (number | string)[] = fileOpenHistory.get(this.uri) as (number | string)[];
@ -338,7 +338,7 @@ export default class ViewAbility extends ServiceExtensionAbility {
await this.getOpenDLPFile(startId);
}
let authPerm2Sandbox: Map<dlpPermission.DLPFileAccess, (number | string)[]> = GlobalContext.getContext().getObject('authPerm2Sandbox') as Map<dlpPermission.DLPFileAccess, (number | string)[]>;
let authPerm2Sandbox: Map<dlpPermission.DLPFileAccess, (number | string)[]> = GlobalContext.load('authPerm2Sandbox') as Map<dlpPermission.DLPFileAccess, (number | string)[]>;
if (authPerm2Sandbox.has(this.authPerm) &&
this.gatheringType === dlpPermission.GatheringPolicyType.GATHERING) {
this.appIndex = authPerm2Sandbox.get(this.authPerm)?.[1] as number;
@ -357,7 +357,7 @@ export default class ViewAbility extends ServiceExtensionAbility {
hiTraceMeter.finishTrace('DlpOpenFileJs', startId);
opening = false;
await this.sendDlpFileOpenFault(Constants.DLP_INSTALL_SANDBOX_ERROR, this.sandboxBundleName, -1, (err as BusinessError<string>).data); // 104:DLP_INSTALL_SANDBOX_ERROR
await startAlertAbility(GlobalContext.getContext().getObject('viewContext') as common.ServiceExtensionContext, { code: Constants.ERR_JS_APP_INSIDE_ERROR }as BusinessError);
await startAlertAbility(GlobalContext.load('viewContext') as common.ServiceExtensionContext, { code: Constants.ERR_JS_APP_INSIDE_ERROR }as BusinessError);
await this.closeFile();
reject(); return;
}
@ -382,7 +382,7 @@ export default class ViewAbility extends ServiceExtensionAbility {
if (splitNames.length <= SUFFIX_INDEX) {
hiTraceMeter.finishTrace('DlpOpenFileJs', startId);
opening = false;
await startAlertAbility(GlobalContext.getContext().getObject('viewContext') as common.ServiceExtensionContext, { code: Constants.ERR_JS_APP_INSIDE_ERROR } as BusinessError);
await startAlertAbility(GlobalContext.load('viewContext') as common.ServiceExtensionContext, { code: Constants.ERR_JS_APP_INSIDE_ERROR } as BusinessError);
await this.closeFile();
reject(); return;
}
@ -409,13 +409,13 @@ export default class ViewAbility extends ServiceExtensionAbility {
} catch (e) {
console.error(TAG, 'file error', e);
opening = false;
(GlobalContext.getContext().getObject('viewContext') as common.ServiceExtensionContext).terminateSelf();
(GlobalContext.load('viewContext') as common.ServiceExtensionContext).terminateSelf();
}
this.linkUri = getFileUriByPath(this.linkFilePath);
if (this.linkUri === '') {
console.error(TAG, 'get linkUri ByPath fail', this.linkFilePath);
opening = false;
(GlobalContext.getContext().getObject('viewContext') as common.ServiceExtensionContext).terminateSelf();
(GlobalContext.load('viewContext') as common.ServiceExtensionContext).terminateSelf();
}
resolve();
});
@ -432,7 +432,7 @@ export default class ViewAbility extends ServiceExtensionAbility {
console.error(TAG, 'closeDLPFile failed', (err as BusinessError).code, (err as BusinessError).message);
}
opening = false;
await startAlertAbility(GlobalContext.getContext().getObject('viewContext') as common.ServiceExtensionContext, error);
await startAlertAbility(GlobalContext.load('viewContext') as common.ServiceExtensionContext, error);
hiTraceMeter.finishTrace('DlpAddLinkFileJs', startId);
hiTraceMeter.finishTrace('DlpOpenFileJs', startId);
await this.closeFile();
@ -449,7 +449,7 @@ export default class ViewAbility extends ServiceExtensionAbility {
} catch (error) {
hiTraceMeter.finishTrace('DlpOpenFileJs', startId);
opening = false;
await startAlertAbility(GlobalContext.getContext().getObject('viewContext') as common.ServiceExtensionContext, { code: Constants.ERR_JS_APP_GET_FILE_ASSET_ERROR } as BusinessError);
await startAlertAbility(GlobalContext.load('viewContext') as common.ServiceExtensionContext, { code: Constants.ERR_JS_APP_GET_FILE_ASSET_ERROR } as BusinessError);
await this.closeFile();
console.error(TAG, 'open', this.uri, 'failed', (error as BusinessError).code, (error as BusinessError).message);
reject();
@ -467,8 +467,8 @@ export default class ViewAbility extends ServiceExtensionAbility {
async onRequest(want: Want, startId: number): Promise<void> {
console.debug(TAG, 'enter onRequest');
//<!!!>
if ((GlobalContext.getContext().getObject('fileOpenHistoryFromMain') as Map<string, (string | number)[]>)?.has(want.uri ?? '')) {
await startAlertAbility(GlobalContext.getContext().getObject('viewContext') as common.ServiceExtensionContext, { code: Constants.ERR_JS_APP_ENCRYPTION_REJECTED } as BusinessError);
if ((GlobalContext.load('fileOpenHistoryFromMain') as Map<string, (string | number)[]>)?.has(want.uri ?? '')) {
await startAlertAbility(GlobalContext.load('viewContext') as common.ServiceExtensionContext, { code: Constants.ERR_JS_APP_ENCRYPTION_REJECTED } as BusinessError);
return;
}
if (opening) {
@ -487,7 +487,7 @@ export default class ViewAbility extends ServiceExtensionAbility {
console.debug(TAG, 'dlpFd:', this.dlpFd);
if (this.dlpFd === -1) {
opening = false;
(GlobalContext.getContext().getObject('viewContext') as common.ServiceExtensionContext).terminateSelf();
(GlobalContext.load('viewContext') as common.ServiceExtensionContext).terminateSelf();
}
this.sandboxBundleName = want.parameters?.['ohos.dlp.params.bundleName'] as string;
this.sandboxAbilityName = want.parameters?.['ohos.dlp.params.abilityName'] as string;
@ -497,7 +497,7 @@ export default class ViewAbility extends ServiceExtensionAbility {
this.sandboxModuleName === undefined) {
opening = false;
console.error(TAG, 'get parameters failed');
(GlobalContext.getContext().getObject('viewContext') as common.ServiceExtensionContext).terminateSelf();
(GlobalContext.load('viewContext') as common.ServiceExtensionContext).terminateSelf();
}
try {
await this.getAccountAndOpenDLPFile(startId);

View File

@ -24,6 +24,14 @@ export default class GlobalContext {
return GlobalContext.instance;
}
static load(name: string): any {
return globalThis[name];
}
static store(name: string, obj: Object): void {
globalThis[name] = obj;
}
getObject(key: string): Object | undefined {
return this._objects.get(key);
}

View File

@ -64,7 +64,7 @@ struct DlpAlertDialog {
if (this.action != null) {
this.action()
} else {
(GlobalContext.getContext().getObject('alertContext') as common.UIAbilityContext).terminateSelf();
(GlobalContext.load('alertContext') as common.UIAbilityContext).terminateSelf();
}
})
}

View File

@ -104,7 +104,7 @@ struct staffInput {
TextInput({
text: this.inputId,
placeholder: !this.staffArray.length ?
((GlobalContext.getContext().getObject('domainAccount') as boolean)
((GlobalContext.load('domainAccount') as boolean)
? $r('app.string.enter_a_complete_work_ID')
: $r('app.string.enter_a_complete_account')) : undefined,
})
@ -145,7 +145,7 @@ struct staffInput {
domain: 'china',
accountName: this.inputId.toLocaleLowerCase()
}
if (GlobalContext.getContext().getObject('domainAccount')) {
if (GlobalContext.load('domainAccount')) {
this.isAccountCheckSuccess = false;
account_osAccount.DomainAccountManager.hasAccount(domainAccountInfo, (err, isExist) => {
this.isAccountCheckSuccess = true;
@ -194,13 +194,13 @@ struct staffInput {
Flex({ direction: FlexDirection.Row }) {
if (this.isInputInvalid) {
Text((GlobalContext.getContext()
.getObject('domainAccount') as boolean) ? $r('app.string.incorrect_work_ID') : $r('app.string.incorrect_account'))
Text((GlobalContext
.load('domainAccount') as boolean) ? $r('app.string.incorrect_work_ID') : $r('app.string.incorrect_account'))
.inputMessageText()
}
if (this.isNetworkInvalid) {
Text((GlobalContext.getContext()
.getObject('domainAccount') as boolean) ? $r('app.string.network_invalid') : $r('app.string.incorrect_account'))
Text((GlobalContext
.load('domainAccount') as boolean) ? $r('app.string.network_invalid') : $r('app.string.incorrect_account'))
.inputMessageText()
}
Blank()

View File

@ -59,8 +59,8 @@ struct permissionTypeSelect {
this.selectedItem = this.permissionTypes[Constants.ENCRYPTION_TYPE_SELECT];
this.index = Constants.ENCRYPTION_TYPE_SELECT;
try {
(GlobalContext.getContext()
.getObject('context') as common.UIAbilityContext).resourceManager.getStringValue($r('app.string.PERMISSION_TYPE_SELECT_ALL')
(GlobalContext
.load('context') as common.UIAbilityContext).resourceManager.getStringValue($r('app.string.PERMISSION_TYPE_SELECT_ALL')
.id, (error: BusinessError, value: string) => {
if (error != null) {
console.log("error is " + error);
@ -75,8 +75,8 @@ struct permissionTypeSelect {
this.selectedItem = this.permissionTypes[Constants.ENCRYPTION_TYPE_SELECT_INDEX];
this.index = Constants.ENCRYPTION_TYPE_SELECT_INDEX;
try {
(GlobalContext.getContext()
.getObject('context') as common.UIAbilityContext).resourceManager.getStringValue($r('app.string.PERMISSION_TYPE_SELECT_TARGET')
(GlobalContext
.load('context') as common.UIAbilityContext).resourceManager.getStringValue($r('app.string.PERMISSION_TYPE_SELECT_TARGET')
.id, (error: BusinessError, value: string) => {
if (error != null) {
console.log("error is " + error);
@ -94,8 +94,8 @@ struct permissionTypeSelect {
selectedItemUpdated(selectedItem: object): void {
this.index = this.selectedItem.index;
try {
(GlobalContext.getContext()
.getObject('context') as common.UIAbilityContext).resourceManager.getStringValue(this.selectedItem.value?.id!, (error: BusinessError, value: string) => {
(GlobalContext
.load('context') as common.UIAbilityContext).resourceManager.getStringValue(this.selectedItem.value?.id!, (error: BusinessError, value: string) => {
if (error != null) {
console.log("error is " + error);
} else {
@ -114,8 +114,8 @@ struct permissionTypeSelect {
})
}
try {
(GlobalContext.getContext()
.getObject('context') as common.UIAbilityContext).resourceManager.getStringValue(this.permissionTypes[this.index].value?.id!, (error: BusinessError, value: string) => {
(GlobalContext
.load('context') as common.UIAbilityContext).resourceManager.getStringValue(this.permissionTypes[this.index].value?.id!, (error: BusinessError, value: string) => {
if (error != null) {
console.log("error is " + error);
} else {
@ -130,8 +130,8 @@ struct permissionTypeSelect {
};
let callback = (eventData: emitter.EventData) => {
try {
(GlobalContext.getContext()
.getObject('context') as common.UIAbilityContext).resourceManager.getStringValue(this.permissionTypes[this.index].value?.id!, (error: BusinessError, value: string) => {
(GlobalContext
.load('context') as common.UIAbilityContext).resourceManager.getStringValue(this.permissionTypes[this.index].value?.id!, (error: BusinessError, value: string) => {
if (error != null) {
console.log("error is " + error);
} else {

View File

@ -65,7 +65,7 @@ async function getOsAccountInfo(): Promise<account_osAccount.OsAccountInfo> {
}
function checkAccountLogin(accountInfo: account_osAccount.OsAccountInfo): boolean {
if (GlobalContext.getContext().getObject('domainAccount') as boolean) {
if (GlobalContext.load('domainAccount') as boolean) {
if (accountInfo.domainInfo.accountName === '' &&
accountInfo.domainInfo.accountId === '') {
return false;
@ -111,7 +111,7 @@ function terminateSelfWithResult(resultCode: number, result: string): void {
}
}
};
(GlobalContext.getContext().getObject('context') as common.UIAbilityContext).terminateSelfWithResult(abilityResult);
(GlobalContext.load('context') as common.UIAbilityContext).terminateSelfWithResult(abilityResult);
}
function getAlertMessage(err: BusinessError, defaultTitle?: Resource, defaultMessage?: Resource) {
@ -176,12 +176,12 @@ async function startAlertAbility(context: common.UIAbilityContext | common.Servi
function judgeIsSandBox() {
return new Promise<boolean>(async resolve => {
let abilityWant: Want = GlobalContext.getContext().getObject('abilityWant') as Want;
let abilityWant: Want = GlobalContext.load('abilityWant') as Want;
let callerToken: number = abilityWant.parameters?.['ohos.aafwk.param.callerToken'] as number;
let callerBundleName: string = abilityWant.parameters?.['ohos.aafwk.param.callerBundleName'] as string;
GlobalContext.getContext().setObject('applicationInfo', await bundleManager.getApplicationInfo(
GlobalContext.store('applicationInfo', await bundleManager.getApplicationInfo(
callerBundleName, bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT));
if (callerToken === (GlobalContext.getContext().getObject('applicationInfo') as bundleManager.ApplicationInfo).accessTokenId) {
if (callerToken === (GlobalContext.load('applicationInfo') as bundleManager.ApplicationInfo).accessTokenId) {
resolve(false);
}
resolve(true);

View File

@ -35,7 +35,7 @@ struct Index {
}),
autoCancel: false,
cancel: () => {
(GlobalContext.getContext().getObject('context') as common.UIAbilityContext).terminateSelf();
(GlobalContext.load('context') as common.UIAbilityContext).terminateSelf();
},
alignment: DialogAlignment.Center,
customStyle: true,
@ -46,7 +46,7 @@ struct Index {
async aboutToAppear() {
try {
let errInfo = getAlertMessage(
(GlobalContext.getContext().getObject('abilityWant') as Want)
(GlobalContext.load('abilityWant') as Want)
.parameters?.error as BusinessError);
this.showErrorDialogAndExit(errInfo.title as Resource, errInfo.msg as Resource);
} catch (err) {

View File

@ -53,7 +53,7 @@ interface AuthAccount {
let defaultDlpProperty: dlpPermission.DLPProperty = {
ownerAccount: '',
ownerAccountType: GlobalContext.getContext().getObject('domainAccount') as Boolean
ownerAccountType: GlobalContext.load('domainAccount') as Boolean
? dlpPermission.AccountType.DOMAIN_ACCOUNT : dlpPermission.AccountType.CLOUD_ACCOUNT,
authUserList: [],
contactAccount: '',
@ -178,7 +178,7 @@ struct changeEncryption {
}
async catchProcess() {
if (GlobalContext.getContext().getObject('requestIsFromSandBox')) {
if (GlobalContext.load('requestIsFromSandBox')) {
try {
console.info(TAG, 'resumeFuseLink', this.srcFileName);
await this.dlpFile.resumeFuseLink();
@ -190,7 +190,7 @@ struct changeEncryption {
async unEncrypt() {
let plaintextFile = this.srcFileName.split('.')[0] + '.' + this.srcFileName.split('.')[1];
if (GlobalContext.getContext().getObject('requestIsFromSandBox') as boolean) {
if (GlobalContext.load('requestIsFromSandBox') as boolean) {
try {
console.info(TAG, 'stopFuseLink', this.srcFileName);
await this.dlpFile.stopFuseLink();
@ -262,7 +262,7 @@ struct changeEncryption {
} catch (err) {
console.log(TAG, 'close fail', (err as BusinessError).code, (err as BusinessError).message);
}
if (GlobalContext.getContext().getObject('requestIsFromSandBox') as boolean) { //no need close dlp file in sandbox
if (GlobalContext.load('requestIsFromSandBox') as boolean) { //no need close dlp file in sandbox
try {
console.info(TAG, 'resumeFuseLink', this.srcFileName);
await this.dlpFile.resumeFuseLink();
@ -277,12 +277,12 @@ struct changeEncryption {
console.error(TAG, 'closeDLPFile', this.srcFileName, 'failed', (err as BusinessError).code, (err as BusinessError).message);
}
}
if (GlobalContext.getContext().getObject('fileOpenHistoryFromMain') as Map<string, (string | number)[]>) {
(GlobalContext.getContext().getObject('fileOpenHistoryFromMain') as Map<string, (string | number)[]>).delete(GlobalContext.getContext().getObject('uri') as string);
if (GlobalContext.load('fileOpenHistoryFromMain') as Map<string, (string | number)[]>) {
(GlobalContext.load('fileOpenHistoryFromMain') as Map<string, (string | number)[]>).delete(GlobalContext.load('uri') as string);
}
abilityResult.resultCode = 0;
(GlobalContext.getContext()
.getObject('context') as common.UIAbilityContext).terminateSelfWithResult(abilityResult);
(GlobalContext
.load('context') as common.UIAbilityContext).terminateSelfWithResult(abilityResult);
}).catch((err: number) => {
console.error(TAG, 'DocumentViewPicker save failed', JSON.stringify(err));
});
@ -293,8 +293,8 @@ struct changeEncryption {
async showData(defaultDlpProperty: dlpPermission.DLPProperty) {
this.permissionDict.forEach(async (item, index) => {
this.permissionDict[index].value = $r(await (GlobalContext.getContext()
.getObject('context') as common.UIAbilityContext).resourceManager.getString(item.value!.id))
this.permissionDict[index].value = $r(await (GlobalContext
.load('context') as common.UIAbilityContext).resourceManager.getString(item.value!.id))
})
let readOnlyData = (defaultDlpProperty.authUserList?.filter((item: dlpPermission.AuthUser) => {
return item.dlpFileAccess === 1;
@ -334,36 +334,36 @@ struct changeEncryption {
async aboutToAppear() {
this.prepareData = true;
try {
GlobalContext.getContext().setObject("accountInfo", await getOsAccountInfo());
GlobalContext.store("accountInfo", await getOsAccountInfo());
} catch (err) {
console.error(TAG, 'getOsAccountInfo failed', (err as BusinessError).code, (err as BusinessError).message);
this.showErrorDialogAndExit($r('app.string.TITLE_APP_ERROR'), $r('app.string.MESSAGE_APP_GET_ACCOUNT_ERROR'))
return;
}
if (!checkAccountLogin(GlobalContext.getContext().getObject('accountInfo') as osAccount.OsAccountInfo)) {
if (!checkAccountLogin(GlobalContext.load('accountInfo') as osAccount.OsAccountInfo)) {
this.showErrorDialogAndExit($r('app.string.TITLE_APP_ERROR'), $r('app.string.MESSAGE_APP_NO_ACCOUNT_ERROR'));
return;
}
if (GlobalContext.getContext().getObject('requestIsFromSandBox') as boolean) {
if (GlobalContext.load('requestIsFromSandBox') as boolean) {
console.info(TAG, 'request from sandbox');
this.linkFileName = GlobalContext.getContext().getObject('linkFileName') as string;
this.dlpFd = GlobalContext.getContext().getObject('dlpFd') as number;
this.srcFileName = GlobalContext.getContext().getObject('dlpFileName') as string;
this.dlpFile = GlobalContext.getContext().getObject('dlpFile') as dlpPermission.DLPFile;
this.linkFileName = GlobalContext.load('linkFileName') as string;
this.dlpFd = GlobalContext.load('dlpFd') as number;
this.srcFileName = GlobalContext.load('dlpFileName') as string;
this.dlpFile = GlobalContext.load('dlpFile') as dlpPermission.DLPFile;
} else {
console.info(TAG, 'request from normal');
this.dlpFd = GlobalContext.getContext().getObject('dlpFd') as number;
this.srcFileName = GlobalContext.getContext().getObject('dlpFileName') as string;
this.dlpFile = GlobalContext.getContext().getObject('dlpFile') as dlpPermission.DLPFile;
this.dlpFd = GlobalContext.load('dlpFd') as number;
this.srcFileName = GlobalContext.load('dlpFileName') as string;
this.dlpFile = GlobalContext.load('dlpFile') as dlpPermission.DLPFile;
}
await this.showData(this.dlpFile.dlpProperty);
setTimeout(() => {
this.prepareData = false;
}, Constants.ENCRYPTION_SET_TIMEOUT_TIME)
this.directionStatus = (GlobalContext.getContext()
.getObject('context') as common.UIAbilityContext).config.direction ?? -1;
this.directionStatus = (GlobalContext
.load('context') as common.UIAbilityContext).config.direction ?? -1;
directionStatus((counter) => {
this.directionStatus = counter;
})
@ -549,6 +549,7 @@ struct changeEncryption {
let showValue = toggleShow(this.staffDataArrayReadOnly, this.showNamesArrReadOnly, this.ReadOnlyFlag, this.rowNamesLenReadOnly);
this.showNamesArrReadOnly = showValue.showNamesArr as AuthAccount[];
this.ReadOnlyFlag = showValue.showFlag as boolean;
this.ReadOnlyFlag = false;
})
}
}
@ -699,6 +700,7 @@ struct changeEncryption {
this.rowNamesLenEdit = nameValue.rowNamesLen as number;
this.showNamesArrEdit = nameValue.showNamesArr as AuthAccount[];
this.hideNamesNumEdit = nameValue.hideNamesNum as string;
this.editFlag = false;
}
})
.margin({
@ -754,7 +756,7 @@ struct changeEncryption {
.height(Constants.FOOTER_HEIGHT)
.onClick(async (event) => {
// update the global resource;
GlobalContext.getContext().setObject('dlpFile', this.dlpFile);
GlobalContext.store('dlpFile', this.dlpFile);
router.replaceUrl({
url: 'pages/encryptionProtection',
params: this.routerData

View File

@ -52,7 +52,7 @@ let abilityResult: ability.AbilityResult = {
let defaultDlpProperty: dlpPermission.DLPProperty = {
ownerAccount: '',
ownerAccountType: (GlobalContext.getContext().getObject('domainAccount') as boolean) ? dlpPermission.AccountType.DOMAIN_ACCOUNT : dlpPermission.AccountType.CLOUD_ACCOUNT,
ownerAccountType: (GlobalContext.load('domainAccount') as boolean) ? dlpPermission.AccountType.DOMAIN_ACCOUNT : dlpPermission.AccountType.CLOUD_ACCOUNT,
authUserList: [],
contactAccount: '',
offlineAccess: true,
@ -85,7 +85,7 @@ struct DlpDialog {
@State handlePopupEdit: boolean = false;
@State processing: boolean = false;
@State prepareData: boolean = false;
@State domainOrCloudAccount: number = (GlobalContext.getContext().getObject('domainAccount') as boolean) ? dlpPermission.AccountType.DOMAIN_ACCOUNT : dlpPermission.AccountType.CLOUD_ACCOUNT
@State domainOrCloudAccount: number = (GlobalContext.load('domainAccount') as boolean) ? dlpPermission.AccountType.DOMAIN_ACCOUNT : dlpPermission.AccountType.CLOUD_ACCOUNT
@State permissionDict: PermissionType[] = [
{
value: $r('app.string.PERMISSION_TYPE_SELECT_TARGET'), data: 'target', index: 0
@ -201,7 +201,7 @@ struct DlpDialog {
async catchProcess() {
this.processing = false;
if (GlobalContext.getContext().getObject('requestIsFromSandBox') as boolean) {
if (GlobalContext.load('requestIsFromSandBox') as boolean) {
try {
console.info(TAG, 'resumeFuseLink', this.srcFileName);
await this.dlpFile.resumeFuseLink();
@ -214,7 +214,7 @@ struct DlpDialog {
async changeEncrypt() {
console.info(TAG, 'Change encryption for', this.srcFd);
this.processing = true;
if (GlobalContext.getContext().getObject('requestIsFromSandBox') as boolean) {
if (GlobalContext.load('requestIsFromSandBox') as boolean) {
try {
console.info(TAG, 'stopFuseLink', this.srcFileName);
await this.dlpFile.stopFuseLink();
@ -225,7 +225,7 @@ struct DlpDialog {
return;
}
}
let filePath = (GlobalContext.getContext().getObject('context') as common.UIAbilityContext).filesDir + '/' + (new Date().getTime());
let filePath = (GlobalContext.load('context') as common.UIAbilityContext).filesDir + '/' + (new Date().getTime());
let tempFd: number = 0;
try {
tempFd = fileio.openSync(filePath, 0o102, 0o660);
@ -278,7 +278,7 @@ struct DlpDialog {
this.staffDataArrayReadOnly = removeDuplicate(this.staffDataArrayReadOnly, 'authAccount');
this.staffDataArrayEdit = removeDuplicate(this.staffDataArrayEdit, 'authAccount');
this.staffDataArrayReadOnly = this.staffDataArrayReadOnly.filter((item) =>!this.staffDataArrayEdit.some((ele) => ele.authAccount === item.authAccount))
if (GlobalContext.getContext().getObject('domainAccount') as boolean) {
if (GlobalContext.load('domainAccount') as boolean) {
property.ownerAccount = accountInfo.domainInfo.accountName;
property.ownerAccountID = accountInfo.domainInfo.accountId ?? '';
} else {
@ -334,8 +334,8 @@ struct DlpDialog {
await this.catchProcess();
return;
}
if (GlobalContext.getContext().getObject('requestIsFromSandBox') as boolean) {
let sandbox2linkFile: Map<string, (number | string | dlpPermission.DLPFile)[][]> = GlobalContext.getContext().getObject('sandbox2linkFile') as Map<string, (number | string | dlpPermission.DLPFile)[][]>;
if (GlobalContext.load('requestIsFromSandBox') as boolean) {
let sandbox2linkFile: Map<string, (number | string | dlpPermission.DLPFile)[][]> = GlobalContext.load('sandbox2linkFile') as Map<string, (number | string | dlpPermission.DLPFile)[][]>;
for (let key of Array.from<(number | string | dlpPermission.DLPFile)[][]>(sandbox2linkFile.values())) {
for (let j of key) {
if (j[1] === this.linkFileName) {
@ -355,9 +355,9 @@ struct DlpDialog {
await this.catchProcess();
this.processing = false;
// update global dlp resource
GlobalContext.getContext().setObject('dlpFileName', this.srcFileName);
GlobalContext.getContext().setObject('dlpFile', this.dlpFile);
GlobalContext.getContext().setObject('dlpFd', this.srcFd);
GlobalContext.store('dlpFileName', this.srcFileName);
GlobalContext.store('dlpFile', this.dlpFile);
GlobalContext.store('dlpFd', this.srcFd);
router.replaceUrl({
url: 'pages/encryptionSuccess',
params: {
@ -474,10 +474,10 @@ struct DlpDialog {
this.processing = false;
// update global dlp resource
GlobalContext.getContext().setObject('dlpFileName', uriInfo.name);
GlobalContext.store('dlpFileName', uriInfo.name);
GlobalContext.getContext().setObject('dlpFile', this.dlpFile);
GlobalContext.getContext().setObject('dlpFd', dstFd);
GlobalContext.store('dlpFile', this.dlpFile);
GlobalContext.store('dlpFd', dstFd);
router.replaceUrl({
url: 'pages/encryptionSuccess',
params: {
@ -502,13 +502,13 @@ struct DlpDialog {
}
async prepareDlpProperty() {
if (GlobalContext.getContext().getObject('domainAccount') as boolean) {
let accountInfo: osAccount.OsAccountInfo = GlobalContext.getContext().getObject('accountInfo') as osAccount.OsAccountInfo;
if (GlobalContext.load('domainAccount') as boolean) {
let accountInfo: osAccount.OsAccountInfo = GlobalContext.load('accountInfo') as osAccount.OsAccountInfo;
this.dlpFile.dlpProperty.ownerAccount = accountInfo.domainInfo.accountName;
this.dlpFile.dlpProperty.contactAccount = accountInfo.domainInfo.accountName;
this.dlpFile.dlpProperty.ownerAccountID = accountInfo.domainInfo.accountId ?? '';
} else {
let accountInfo: osAccount.OsAccountInfo = GlobalContext.getContext().getObject('accountInfo') as osAccount.OsAccountInfo;
let accountInfo: osAccount.OsAccountInfo = GlobalContext.load('accountInfo') as osAccount.OsAccountInfo;
this.dlpFile.dlpProperty.ownerAccount = accountInfo.distributedInfo.name;
this.dlpFile.dlpProperty.contactAccount = accountInfo.distributedInfo.name;
this.dlpFile.dlpProperty.ownerAccountID = accountInfo.distributedInfo.id;
@ -525,7 +525,7 @@ struct DlpDialog {
async showData(defaultDlpProperty: dlpPermission.DLPProperty) {
this.permissionDict.forEach(async (item, index) => {
this.permissionDict[index].value = $r(await (GlobalContext.getContext().getObject('context') as common.UIAbilityContext).resourceManager.getString(item.value.id))
this.permissionDict[index].value = $r(await (GlobalContext.load('context') as common.UIAbilityContext).resourceManager.getString(item.value.id))
})
let readOnlyData: dlpPermission.AuthUser[] = defaultDlpProperty.authUserList?.filter((item: dlpPermission.AuthUser) => {
return item.dlpFileAccess === 1;
@ -558,13 +558,13 @@ struct DlpDialog {
async checkAccount() {
try {
GlobalContext.getContext().setObject('accountInfo', await getOsAccountInfo());
GlobalContext.store('accountInfo', await getOsAccountInfo());
} catch (err) {
console.error(TAG, 'getOsAccountInfo failed:', JSON.stringify(err));
this.showErrorDialogAndExit($r('app.string.TITLE_APP_ERROR'), $r('app.string.MESSAGE_APP_GET_ACCOUNT_ERROR'))
return;
}
if (!checkAccountLogin(GlobalContext.getContext().getObject('accountInfo') as osAccount.OsAccountInfo)) {
if (!checkAccountLogin(GlobalContext.load('accountInfo') as osAccount.OsAccountInfo)) {
this.showErrorDialogAndExit($r('app.string.TITLE_APP_ERROR'), $r('app.string.MESSAGE_APP_NO_ACCOUNT_ERROR'));
return;
}
@ -573,12 +573,12 @@ struct DlpDialog {
async aboutToAppear() {
this.prepareData = true;
await this.checkAccount();
if (GlobalContext.getContext().getObject('requestIsFromSandBox') as boolean) {
if (GlobalContext.load('requestIsFromSandBox') as boolean) {
console.info(TAG, 'encryption request from sandbox');
this.linkFileName = GlobalContext.getContext().getObject('linkFileName') as string;
this.srcFileName = GlobalContext.getContext().getObject('dlpFileName') as string;
this.dlpFile = GlobalContext.getContext().getObject('dlpFile') as dlpPermission.DLPFile;
this.srcFd = GlobalContext.getContext().getObject('dlpFd') as number;
this.linkFileName = GlobalContext.load('linkFileName') as string;
this.srcFileName = GlobalContext.load('dlpFileName') as string;
this.dlpFile = GlobalContext.load('dlpFile') as dlpPermission.DLPFile;
this.srcFd = GlobalContext.load('dlpFd') as number;
setTimeout(() => {
this.showData(this.dlpFile.dlpProperty);
}, Constants.ENCRYPTION_SET_TIMEOUT_TIME)
@ -591,12 +591,12 @@ struct DlpDialog {
let routerParams = router.getParams();
if (routerParams !== undefined) { // is a dlp file
console.info(TAG, 'encryption request from router');
this.srcFileName = GlobalContext.getContext().getObject('dlpFileName') as string;
this.srcFd = GlobalContext.getContext().getObject('dlpFd') as number;
this.srcFileName = GlobalContext.load('dlpFileName') as string;
this.srcFd = GlobalContext.load('dlpFd') as number;
} else { // not a dlp file
console.info(TAG, 'encryption request from ability');
this.srcFileName = GlobalContext.getContext().getObject('originFileName') as string;
this.srcFd = GlobalContext.getContext().getObject('originFd') as number;
this.srcFileName = GlobalContext.load('originFileName') as string;
this.srcFd = GlobalContext.load('originFd') as number;
}
}
@ -605,7 +605,7 @@ struct DlpDialog {
await this.prepareDlpProperty();
this.isDlpFile = false;
} else {
this.dlpFile = GlobalContext.getContext().getObject('dlpFile') as dlpPermission.DLPFile;
this.dlpFile = GlobalContext.load('dlpFile') as dlpPermission.DLPFile;
setTimeout(() => {
this.showData(this.dlpFile.dlpProperty);
}, Constants.ENCRYPTION_SET_TIMEOUT_TIME)
@ -615,7 +615,7 @@ struct DlpDialog {
this.prepareData = false;
}, Constants.ENCRYPTION_SET_TIMEOUT_TIME)
this.directionStatus = (GlobalContext.getContext().getObject('context') as common.UIAbilityContext).config.direction ?? -1;
this.directionStatus = (GlobalContext.load('context') as common.UIAbilityContext).config.direction ?? -1;
directionStatus((counter) => {
this.directionStatus = counter;
})
@ -766,7 +766,7 @@ struct DlpDialog {
.fontColor($r('app.color.encryption_cancel'))
.height(Constants.FOOTER_HEIGHT)
.onClick(async (event) => {
if (this.isDlpFile && !(GlobalContext.getContext().getObject('requestIsFromSandBox') as boolean)) {
if (this.isDlpFile && !(GlobalContext.load('requestIsFromSandBox') as boolean)) {
try {
console.info(TAG, 'closeDLPFile', this.srcFileName, this.srcFd);
await this.dlpFile.closeDLPFile();
@ -774,17 +774,17 @@ struct DlpDialog {
console.error(TAG, 'closeDLPFile', this.srcFileName, 'failed', (err as BusinessError).code, (err as BusinessError).message);
}
try {
console.info(TAG, 'refresh dlp file', GlobalContext.getContext().getObject('dlpFileName') as string, GlobalContext.getContext().getObject('dlpFd') as number);
await fs.close(GlobalContext.getContext().getObject('dlpFd') as number); // refresh file info
console.info(TAG, 'refresh dlp file', GlobalContext.load('dlpFileName') as string, GlobalContext.load('dlpFd') as number);
await fs.close(GlobalContext.load('dlpFd') as number); // refresh file info
} catch (err) {
console.error(TAG, 'refresh dlp file failed', (err as BusinessError).code, (err as BusinessError).message);
}
}
if (GlobalContext.getContext().getObject('fileOpenHistoryFromMain')) {
(GlobalContext.getContext().getObject('fileOpenHistoryFromMain') as Map<string, Object>).delete(GlobalContext.getContext().getObject('uri') as string)
if (GlobalContext.load('fileOpenHistoryFromMain')) {
(GlobalContext.load('fileOpenHistoryFromMain') as Map<string, Object>).delete(GlobalContext.load('uri') as string)
}
abilityResult.resultCode = 0;
(GlobalContext.getContext().getObject('context') as common.UIAbilityContext).terminateSelfWithResult(abilityResult);
(GlobalContext.load('context') as common.UIAbilityContext).terminateSelfWithResult(abilityResult);
})
.margin({ right: Constants.ENCRYPTION_PROTECTION_BUTTON_MARGIN })
Button($r('app.string.sure'), {

View File

@ -97,7 +97,7 @@ struct encryptionSuccess {
aboutToAppear() {
console.info(TAG, 'aboutToAppear, encrypt success');
this.directionStatus = (GlobalContext.getContext().getObject('context') as common.UIAbilityContext).config.direction ?? -1;
this.directionStatus = (GlobalContext.load('context') as common.UIAbilityContext).config.direction ?? -1;
directionStatus((counter) => {
this.directionStatus = counter;
})
@ -167,7 +167,7 @@ struct encryptionSuccess {
.width(Constants.HEADER_COLUMN_WIDTH)
Row() {
Text(`${GlobalContext.getContext().getObject('dlpFileName') as string}`)
Text(`${GlobalContext.load('dlpFileName') as string}`)
.fontSize($r('sys.float.ohos_id_text_size_body2'))
.fontColor($r('sys.color.ohos_id_color_secondary'))
.fontWeight(FontWeight.Regular)
@ -541,10 +541,10 @@ struct encryptionSuccess {
.width(Constants.FOOTER_WIDTH_BUTTON)
.height(Constants.FOOTER_HEIGHT)
.onClick(async (event) => {
if (!(GlobalContext.getContext().getObject('requestIsFromSandBox') as boolean)) {
let dlpFileName: string = GlobalContext.getContext().getObject('dlpFileName') as string;
let dlpFd: number = GlobalContext.getContext().getObject('dlpFd') as number;
let dlpFile: dlpPermission.DLPFile = GlobalContext.getContext().getObject('dlpFile') as dlpPermission.DLPFile;
if (!(GlobalContext.load('requestIsFromSandBox') as boolean)) {
let dlpFileName: string = GlobalContext.load('dlpFileName') as string;
let dlpFd: number = GlobalContext.load('dlpFd') as number;
let dlpFile: dlpPermission.DLPFile = GlobalContext.load('dlpFile') as dlpPermission.DLPFile;
try {
console.info(TAG, 'closeDLPFile', dlpFileName, dlpFd);
await dlpFile.closeDLPFile();
@ -558,11 +558,11 @@ struct encryptionSuccess {
console.error(TAG, 'refresh dlp file', dlpFileName, 'failed', (err as BusinessError).code, (err as BusinessError).message);
}
}
if (GlobalContext.getContext().getObject('fileOpenHistoryFromMain')) {
(GlobalContext.getContext().getObject('fileOpenHistoryFromMain') as Map<string, Object>).delete(GlobalContext.getContext().getObject('uri') as string)
if (GlobalContext.load('fileOpenHistoryFromMain')) {
(GlobalContext.load('fileOpenHistoryFromMain') as Map<string, Object>).delete(GlobalContext.load('uri') as string)
}
abilityResult.resultCode = 0;
(GlobalContext.getContext().getObject('context') as common.UIAbilityContext).terminateSelfWithResult(abilityResult);
(GlobalContext.load('context') as common.UIAbilityContext).terminateSelfWithResult(abilityResult);
})
}
.justifyContent(FlexAlign.Center)

View File

@ -142,8 +142,8 @@ struct PermissionStatus {
console.info(TAG, 'aboutToAppear');
this.authPerm = AppStorage.Get('authPerm') ?? 1;
this.accountId = AppStorage.Get('contactAccount') ?? '';
this.directionStatus = (GlobalContext.getContext()
.getObject('context') as common.UIAbilityContext).config.direction ?? -1;
this.directionStatus = (GlobalContext
.load('context') as common.UIAbilityContext).config.direction ?? -1;
directionStatus((counter) => {
this.directionStatus = counter;
})
@ -278,7 +278,7 @@ struct PermissionStatus {
.width(Constants.ENCRYPTION_PERMISSION_STATUS_WIDTH)
.height(Constants.FOOTER_BUTTON_HEIGHT)
.onClick(() => {
(GlobalContext.getContext().getObject('context') as common.UIAbilityContext).terminateSelf()
(GlobalContext.load('context') as common.UIAbilityContext).terminateSelf()
})
}
.justifyContent(FlexAlign.Center)