mirror of
https://gitee.com/openharmony/applications_dlp_manager
synced 2024-11-26 19:40:40 +00:00
commit
cc3b9dd08b
@ -2,8 +2,8 @@
|
||||
"app": {
|
||||
"bundleName": "com.ohos.dlpmanager",
|
||||
"vendor": "example",
|
||||
"versionCode": 1000115,
|
||||
"versionName": "1.0.1.15",
|
||||
"versionCode": 1000116,
|
||||
"versionName": "1.0.1.16",
|
||||
"icon": "$media:app_icon",
|
||||
"label": "$string:app_name",
|
||||
"minAPIVersion": 12,
|
||||
|
@ -16,8 +16,8 @@
|
||||
"app": {
|
||||
"bundleName": "com.ohos.dlpmanager",
|
||||
"vendor": "example",
|
||||
"versionCode": 1000115,
|
||||
"versionName": "1.0.1.15",
|
||||
"versionCode": 1000116,
|
||||
"versionName": "1.0.1.16",
|
||||
"icon": "$media:app_icon",
|
||||
"label": "$string:app_name",
|
||||
"minAPIVersion": 12,
|
||||
|
@ -1,114 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import UIAbility from '@ohos.app.ability.UIAbility';
|
||||
import Want from '@ohos.app.ability.Want';
|
||||
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
|
||||
import window from '@ohos.window';
|
||||
import { BusinessError } from '@ohos.base';
|
||||
import display from '@ohos.display';
|
||||
import GlobalContext from '../common/GlobalContext';
|
||||
import Constants from '../common/constant';
|
||||
import { HiLog } from '../common/HiLog';
|
||||
|
||||
const TAG = 'Alert';
|
||||
export default class AlertAbility extends UIAbility {
|
||||
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
|
||||
HiLog.info(TAG, `onCreate`);
|
||||
GlobalContext.store('alertWant', want);
|
||||
}
|
||||
|
||||
onDestroy(): void {
|
||||
HiLog.info(TAG, `onDestroy`);
|
||||
}
|
||||
|
||||
onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void {
|
||||
HiLog.info(TAG, `onNewWant start`);
|
||||
this.getNewWantPage();
|
||||
}
|
||||
|
||||
getNewWantPage(): void {
|
||||
HiLog.info(TAG, `getNewWantPage start`);
|
||||
let windowStage: window.WindowStage = GlobalContext.load('windowStage') as window.WindowStage;
|
||||
let dis = display.getDefaultDisplaySync();
|
||||
try {
|
||||
windowStage.loadContent('pages/alert');
|
||||
windowStage.disableWindowDecor();
|
||||
} catch (exception) {
|
||||
HiLog.error(TAG, `Failed to set the background color. Cause: ${JSON.stringify(exception)}`);
|
||||
}
|
||||
try {
|
||||
let mainWindow: window.Window | undefined = undefined;
|
||||
|
||||
windowStage.getMainWindow((err, data) => {
|
||||
if (err && err.code) {
|
||||
HiLog.error(TAG, `Failed to obtain the main window. Cause: ${JSON.stringify(err)}`);
|
||||
return;
|
||||
}
|
||||
mainWindow = data;
|
||||
try {
|
||||
mainWindow.setWindowBackgroundColor(Constants.TRANSPARENT_BACKGROUND_COLOR);
|
||||
} catch (exception) {
|
||||
HiLog.error(TAG, `Failed to set the background color. Cause: ${JSON.stringify(exception)}`);
|
||||
}
|
||||
try {
|
||||
let windowLimits = mainWindow.getWindowLimits();
|
||||
mainWindow.resize(windowLimits.minWidth, windowLimits.minHeight);
|
||||
let xNumber =
|
||||
windowLimits.minWidth ? windowLimits.minWidth : Constants.START_ABILITY_CUSTOM_CONTENT_DIALOG_WIDTH;
|
||||
let yNumber = windowLimits.minHeight ? windowLimits.minHeight :
|
||||
Constants.START_ABILITY_CUSTOM_CONTENT_DIALOG_HEIGHT;
|
||||
mainWindow.moveWindowTo(
|
||||
Math.floor((dis.width - xNumber) * Constants.RATIO_HALF),
|
||||
Math.floor((dis.height - yNumber) * Constants.RATIO_HALF)
|
||||
);
|
||||
} catch (exception) {
|
||||
HiLog.error(TAG, `Failed to obtain the window limits of window. Cause: ${JSON.stringify(exception)}`);
|
||||
}
|
||||
mainWindow.setResizeByDragEnabled(false, (err: BusinessError) => {
|
||||
if (err && err.code) {
|
||||
HiLog.error(TAG, `Failed to set the function of disabling the resize by dragg window. Cause: ${err.code}`);
|
||||
return;
|
||||
}
|
||||
HiLog.info(TAG, `Succeeded in setting the function of disabling the resize by dragg window.`);
|
||||
});
|
||||
})
|
||||
} catch (exception) {
|
||||
HiLog.error(TAG, `Failed to obtain the main window. Cause: ${JSON.stringify(exception)}`);
|
||||
};
|
||||
}
|
||||
|
||||
onWindowStageCreate(windowStage: window.WindowStage): void {
|
||||
// Main window is created, set main page for this ability
|
||||
HiLog.info(TAG, `onWindowStageCreate`);
|
||||
GlobalContext.store('windowStage', windowStage);
|
||||
this.getNewWantPage()
|
||||
}
|
||||
|
||||
onWindowStageDestroy(): void {
|
||||
// Main window is destroyed, release UI related resources
|
||||
HiLog.info(TAG, `onWindowStageDestroy`);
|
||||
}
|
||||
|
||||
onForeground(): void {
|
||||
// Ability has brought to foreground
|
||||
HiLog.info(TAG, `onForeground`);
|
||||
}
|
||||
|
||||
onBackground(): void {
|
||||
// Ability has back to background
|
||||
HiLog.info(TAG, `onBackground`);
|
||||
}
|
||||
};
|
@ -88,7 +88,7 @@ export default class SaveAsAbility extends UIAbility {
|
||||
private fileName: string = '';
|
||||
private suffix: string = '';
|
||||
private authPerm: dlpPermission.DLPFileAccess = dlpPermission.DLPFileAccess.READ_ONLY;
|
||||
private isOK: boolean = true; // use with startAlertAbility
|
||||
private isOK: boolean = true; // use with requestModalUIExtension
|
||||
private zipFlag: boolean = false;
|
||||
private random: string = String(Math.random()).substring(Constants.RAND_START, Constants.RAND_END);
|
||||
private filePath: string = '';
|
||||
@ -182,11 +182,11 @@ export default class SaveAsAbility extends UIAbility {
|
||||
AppStorage.setOrCreate('contactAccount', contactAccount);
|
||||
let accountFlag = await GetAlertMessage.checkAccountInfo(contactAccount);
|
||||
if (!accountFlag) {
|
||||
await GetAlertMessage.startAlertAbility(this.context, {
|
||||
await GetAlertMessage.requestModalUIExtension(this.context, {
|
||||
code: Constants.ERR_JS_APP_INSIDE_ERROR } as BusinessError);
|
||||
reject();
|
||||
}
|
||||
await GetAlertMessage.startAlertAbility(this.context,
|
||||
await GetAlertMessage.requestModalUIExtension(this.context,
|
||||
{ code: Constants.ERR_JS_DLP_FILE_READ_ONLY } as BusinessError);
|
||||
reject();
|
||||
}
|
||||
@ -514,7 +514,7 @@ export default class SaveAsAbility extends UIAbility {
|
||||
HiLog.info(TAG, `close fail: ${JSON.stringify(err)}`);
|
||||
}
|
||||
this.isOK = false;
|
||||
await GetAlertMessage.startAlertAbility(this.context,
|
||||
await GetAlertMessage.requestModalUIExtension(this.context,
|
||||
{ code: Constants.ERR_JS_APP_INSIDE_ERROR } as BusinessError);
|
||||
return;
|
||||
}
|
||||
@ -541,7 +541,7 @@ export default class SaveAsAbility extends UIAbility {
|
||||
}
|
||||
fs.closeSync(this.srcFdPicker);
|
||||
this.isOK = false;
|
||||
await GetAlertMessage.startAlertAbility(this.context,
|
||||
await GetAlertMessage.requestModalUIExtension(this.context,
|
||||
{ code: Constants.ERR_JS_APP_INSIDE_ERROR } as BusinessError);
|
||||
reject();
|
||||
}
|
||||
@ -587,7 +587,7 @@ export default class SaveAsAbility extends UIAbility {
|
||||
HiLog.info(TAG, `close fail: ${JSON.stringify(err)}`);
|
||||
}
|
||||
this.isOK = false;
|
||||
await GetAlertMessage.startAlertAbility(this.context,
|
||||
await GetAlertMessage.requestModalUIExtension(this.context,
|
||||
{ code: Constants.ERR_JS_APP_INSIDE_ERROR } as BusinessError);
|
||||
reject();
|
||||
}
|
||||
@ -609,7 +609,7 @@ export default class SaveAsAbility extends UIAbility {
|
||||
this.newDlpFile = await dlpPermission.openDLPFile(this.dstFdPicker, callerAppId);
|
||||
} catch (err) {
|
||||
HiLog.error(TAG, `generateDlpFile: ${this.dstFdPicker}, failed: ${JSON.stringify(err)}`);
|
||||
await GetAlertMessage.startAlertAbility(this.context, err);
|
||||
await GetAlertMessage.requestModalUIExtension(this.context, err);
|
||||
try {
|
||||
await fs.close(this.file);
|
||||
await this.deleteUri(uri);
|
||||
@ -650,7 +650,7 @@ export default class SaveAsAbility extends UIAbility {
|
||||
}
|
||||
fs.closeSync(this.srcFdPicker);
|
||||
this.isOK = false;
|
||||
await GetAlertMessage.startAlertAbility(this.context,
|
||||
await GetAlertMessage.requestModalUIExtension(this.context,
|
||||
{ code: Constants.ERR_JS_APP_INSIDE_ERROR } as BusinessError);
|
||||
reject();
|
||||
}
|
||||
|
@ -31,55 +31,6 @@ import CommonUtil from './CommonUtil';
|
||||
const TAG = 'AlertMessage';
|
||||
|
||||
export class GetAlertMessage {
|
||||
|
||||
public static async startAlertAbility(
|
||||
context: common.UIAbilityContext | common.ServiceExtensionContext | common.UIExtensionContext,
|
||||
error: BusinessError,
|
||||
session?: UIExtensionContentSession
|
||||
) {
|
||||
if (deviceInfo.deviceType !== '2in1') {
|
||||
GetAlertMessage.phoneHandle(context, error);
|
||||
return;
|
||||
}
|
||||
let dis = display.getDefaultDisplaySync();
|
||||
let xNumber = Math.floor(
|
||||
(dis.width - Constants.START_ABILITY_CUSTOM_CONTENT_DIALOG_WIDTH) * Constants.RATIO_HALF
|
||||
);
|
||||
let yNumber = Math.floor(
|
||||
(dis.height - Constants.START_ABILITY_CUSTOM_CONTENT_DIALOG_HEIGHT) * Constants.RATIO_HALF
|
||||
);
|
||||
let options: StartOptions = {
|
||||
withAnimation: true,
|
||||
windowLeft: xNumber,
|
||||
windowTop: yNumber,
|
||||
windowWidth: Constants.START_ABILITY_CUSTOM_CONTENT_DIALOG_WIDTH,
|
||||
windowHeight: Constants.START_ABILITY_CUSTOM_CONTENT_DIALOG_HEIGHT
|
||||
};
|
||||
HiLog.info(TAG, `set options: ${JSON.stringify(options)}`);
|
||||
context.startAbility({
|
||||
bundleName: Constants.DLP_MANAGER_BUNDLE_NAME,
|
||||
abilityName: 'AlertAbility',
|
||||
parameters: {
|
||||
error: error,
|
||||
accountType: GlobalContext.load('accountType')
|
||||
}
|
||||
}, options, async (err: BusinessError) => {
|
||||
if (err && err.code !== 0) {
|
||||
HiLog.error(TAG, `start AlertAbility failed: ${JSON.stringify(err)}`);
|
||||
}
|
||||
if (session) {
|
||||
session.terminateSelfWithResult({
|
||||
'resultCode': 0,
|
||||
'want': {
|
||||
'bundleName': Constants.DLP_MANAGER_BUNDLE_NAME,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
context.terminateSelf();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
public static async phoneHandle(
|
||||
context: common.UIAbilityContext | common.ServiceExtensionContext | common.UIExtensionContext,
|
||||
error: BusinessError
|
||||
|
@ -19,18 +19,6 @@
|
||||
}
|
||||
],
|
||||
"abilities": [
|
||||
{
|
||||
"name": "AlertAbility",
|
||||
"srcEntry": "./ets/AlertAbility/AlertAbility.ets",
|
||||
"description": "$string:MainAbility_desc",
|
||||
"icon": "$media:app_icon",
|
||||
"label": "$string:MainAbility_label",
|
||||
"startWindowIcon": "$media:icon",
|
||||
"startWindowBackground": "$color:white",
|
||||
"excludeFromMissions": true,
|
||||
"exported": true,
|
||||
"removeMissionAfterTerminate": true
|
||||
},
|
||||
{
|
||||
"name": "SaveAsAbility",
|
||||
"srcEntry": "./ets/SaveAsAbility/SaveAsAbility.ets",
|
||||
|
@ -33,18 +33,6 @@
|
||||
}
|
||||
],
|
||||
"abilities": [
|
||||
{
|
||||
"name": "AlertAbility",
|
||||
"srcEntry": "./ets/AlertAbility/AlertAbility.ets",
|
||||
"description": "$string:MainAbility_desc",
|
||||
"icon": "$media:app_icon",
|
||||
"label": "$string:MainAbility_label",
|
||||
"startWindowIcon": "$media:icon",
|
||||
"startWindowBackground": "$color:white",
|
||||
"excludeFromMissions": true,
|
||||
"exported": true,
|
||||
"removeMissionAfterTerminate": true
|
||||
},
|
||||
{
|
||||
"name": "SaveAsAbility",
|
||||
"srcEntry": "./ets/SaveAsAbility/SaveAsAbility.ets",
|
||||
|
Loading…
Reference in New Issue
Block a user