mirror of
https://github.com/openharmony/applications_dlp_manager.git
synced 2026-07-01 13:20:42 -04:00
+3
-3
@@ -2,8 +2,8 @@
|
||||
"app": {
|
||||
"bundleName": "com.ohos.dlpmanager",
|
||||
"vendor": "ohos",
|
||||
"versionCode": 60010302,
|
||||
"versionName": "6.0.10.302",
|
||||
"versionCode": 60010303,
|
||||
"versionName": "6.0.10.303",
|
||||
"icon": "$media:app_icon",
|
||||
"label": "$string:app_name",
|
||||
"minAPIVersion": 12,
|
||||
@@ -12,4 +12,4 @@
|
||||
"apiReleaseType" : "Beta5",
|
||||
"configuration": "$profile:configuration"
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -16,8 +16,8 @@
|
||||
"app": {
|
||||
"bundleName": "com.ohos.dlpmanager",
|
||||
"vendor": "ohos",
|
||||
"versionCode": 60010302,
|
||||
"versionName": "6.0.10.302",
|
||||
"versionCode": 60010303,
|
||||
"versionName": "6.0.10.303",
|
||||
"icon": "$media:app_icon",
|
||||
"label": "$string:app_name",
|
||||
"minAPIVersion": 12,
|
||||
|
||||
@@ -18,7 +18,6 @@ import Constants from '../../../common/constant';
|
||||
export class OpenDlpFileError {
|
||||
public static readonly NOT_NEED_TOAST: Set<number> = new Set([
|
||||
Constants.ERR_CODE_FILE_IS_DECRYPTING_ERROR,
|
||||
Constants.ERR_JS_ACCOUNT_NOT_LOGIN,
|
||||
Constants.ERR_CODE_USER_STOP_DIALOG
|
||||
]);
|
||||
public static readonly NEED_DIALOG: Set<number> = new Set([
|
||||
@@ -26,6 +25,7 @@ export class OpenDlpFileError {
|
||||
Constants.ERR_JS_USER_NO_PERMISSION_2C,
|
||||
Constants.ERR_JS_NETWORK_INVALID,
|
||||
Constants.ERR_JS_APP_NETWORK_INVALID,
|
||||
Constants.ERR_JS_ACCOUNT_NOT_LOGIN,
|
||||
Constants.ERR_JS_OFFLINE
|
||||
]);
|
||||
}
|
||||
@@ -59,37 +59,12 @@ class CloudAccountHandle extends AccountHandlerBase {
|
||||
if (this.accountInfo.distributedInfo.name === 'ohosAnonymousName' &&
|
||||
this.accountInfo.distributedInfo.id === 'ohosAnonymousUid') {
|
||||
HiLog.info(TAG, 'Cloud account not login');
|
||||
const lunchLoginRet = await this.launchLogin(context);
|
||||
if (lunchLoginRet.errcode !== Constants.ERR_CODE_SUCCESS) {
|
||||
HiLog.error(TAG, 'lunchLogin error');
|
||||
return ResultMsg.buildMsg(lunchLoginRet.errcode, lunchLoginRet.errmsg);
|
||||
} else {
|
||||
HiLog.info(TAG, 'lunchLogin success');
|
||||
return ResultMsg.getErrMsg(Constants.ERR_JS_ACCOUNT_NOT_LOGIN);
|
||||
}
|
||||
return ResultMsg.buildMsg(Constants.ERR_JS_ACCOUNT_NOT_LOGIN);
|
||||
}
|
||||
decryptContent.distributedInfoId = this.accountInfo.distributedInfo.id;
|
||||
decryptContent.userId = this.userId;
|
||||
return ResultMsg.buildSuccess();
|
||||
}
|
||||
|
||||
private async launchLogin(context: common.ServiceExtensionContext): Promise<Result<void>> {
|
||||
let accountWant: Want = {
|
||||
bundleName: Constants.DLP_CREDMGR_BUNDLE_NAME,
|
||||
abilityName: Constants.DLP_CREDMGR_LOGIN_ABILITY_NAME,
|
||||
};
|
||||
if (!(await getConnectionStatus())) {
|
||||
HiLog.error(TAG, 'getConnectionStatus error');
|
||||
return ResultMsg.getErrMsg(Constants.ERR_JS_NETWORK_INVALID);
|
||||
}
|
||||
try {
|
||||
await context.startAbility(accountWant);
|
||||
} catch (error) {
|
||||
HiLog.wrapError(TAG, error, 'Failed to invoke startAbility');
|
||||
return ResultMsg.getErrMsg(Constants.ERR_CODE_START_ABILITY_ERROR);
|
||||
}
|
||||
return ResultMsg.buildSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
class DomainAccountHandle extends AccountHandlerBase {
|
||||
@@ -115,14 +90,6 @@ class DomainAccountHandle extends AccountHandlerBase {
|
||||
}
|
||||
}
|
||||
|
||||
class EnterpriseAccountHandle extends AccountHandlerBase {
|
||||
public async handle(decryptContent: DecryptContent, context: common.ServiceExtensionContext):
|
||||
Promise<Result<void>> {
|
||||
decryptContent.userId = this.userId;
|
||||
return ResultMsg.buildSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
class PluginAccountHandle extends AccountHandlerBase {
|
||||
public async handle(decryptContent: DecryptContent, context: common.ServiceExtensionContext):
|
||||
Promise<Result<void>> {
|
||||
@@ -154,10 +121,6 @@ export class AccountHandlerFactory {
|
||||
HiLog.info(TAG, 'create DomainAccountHandle');
|
||||
return ResultMsg.buildSuccess(new DomainAccountHandle());
|
||||
}
|
||||
if (decryptContent.fileMetaInfo.accountType === dlpPermission.AccountType.ENTERPRISE_ACCOUNT) {
|
||||
HiLog.info(TAG, 'create EnterpriseAccountHandle');
|
||||
return ResultMsg.buildSuccess(new EnterpriseAccountHandle());
|
||||
}
|
||||
HiLog.error(TAG, 'not found AccountHandler');
|
||||
return ResultMsg.getErrMsg(Constants.ERR_JS_NOT_DLP_FILE);
|
||||
}
|
||||
|
||||
@@ -110,7 +110,6 @@ export default class Constants {
|
||||
public static DLP_MANAGER_BUNDLE_NAME = 'com.ohos.dlpmanager';
|
||||
public static DLP_CREDMGR_BUNDLE_NAME = 'com.huawei.hmos.dlpcredmgr';
|
||||
public static DLP_CREDMGR_DATA_ABILITY_NAME = 'DlpCredDataExtAbility';
|
||||
public static DLP_CREDMGR_LOGIN_ABILITY_NAME = 'DlpCredLoginAbility';
|
||||
public static DLP_CREDMGR_ACCOUNT_ABILITY_NAME = 'DlpCredAccountAbility';
|
||||
public static DLP_CREDMGR_INTERFACE_TOKEN = 'OHOS.HapDlpCredAbilityServiceStub';
|
||||
public static DLP_MGR_INTERFACE_TOKEN = 'OHOS.HapDlpMgrAbilityServiceStub';
|
||||
@@ -371,5 +370,4 @@ export default class Constants {
|
||||
|
||||
public static readonly DEFAULT_ERROR_CODE = -1;
|
||||
public static readonly VALID_URI_PREFIX = 'file://';
|
||||
public static readonly MSG_CONTACT = ', contact:';
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import { BusinessError } from '@ohos.base';
|
||||
import { HiLog } from '../common/HiLog';
|
||||
import { AlertDialog } from '@kit.ArkUI';
|
||||
import Constants from '../common/constant';
|
||||
import { common } from '@kit.AbilityKit';
|
||||
|
||||
const TAG = 'PhoneDialog';
|
||||
|
||||
@@ -29,6 +30,52 @@ struct Index {
|
||||
private want = AppStorage.get('PhoneDialogUIExtWant') as Want | undefined;
|
||||
private session = AppStorage.get('PhoneDialogUIExtSession') as UIExtensionContentSession | undefined;
|
||||
private errorDialog: CustomDialogController | null = null;
|
||||
private context: common.UIExtensionContext = this.getUIContext().getHostContext() as common.UIExtensionContext;
|
||||
private loginDialogTitle: ResourceStr = '';
|
||||
private loginButtonContent: ResourceStr = '';
|
||||
private loginDialog: CustomDialogController = new CustomDialogController({
|
||||
builder: AlertDialog({
|
||||
primaryTitle: this.loginDialogTitle,
|
||||
content: $r('app.string.MESSAGE_APP_NO_ACCOUNT_ERROR'),
|
||||
primaryButton: {
|
||||
value: $r('app.string.ban'),
|
||||
action: async () => {
|
||||
this.cancelAction();
|
||||
},
|
||||
},
|
||||
secondaryButton: {
|
||||
value: this.loginButtonContent,
|
||||
action: async () => {
|
||||
const ctx = this.getUIContext()?.getHostContext() as common.UIAbilityContext;
|
||||
if (!ctx) {
|
||||
return;
|
||||
}
|
||||
ctx.startAbility({
|
||||
bundleName: 'com.huawei.hmos.settings',
|
||||
abilityName: 'com.huawei.hmos.settings.MainAbility',
|
||||
uri: 'hms_account_home_settings'
|
||||
});
|
||||
this.cancelAction();
|
||||
}
|
||||
},
|
||||
}),
|
||||
cancel: (() => {
|
||||
this.cancelAction();
|
||||
})
|
||||
})
|
||||
|
||||
getExternalResourceString(bundle: string, module: string, resourceName: string): string {
|
||||
try {
|
||||
let ctx = this.context.createModuleContext(bundle, module);
|
||||
HiLog.info(TAG, 'getExternalResourceString get context from: ' + ctx.applicationInfo.name);
|
||||
let str = ctx.resourceManager.getStringByNameSync(resourceName);
|
||||
return str;
|
||||
} catch (e) {
|
||||
let error = e as BusinessError;
|
||||
HiLog.error(TAG, 'getExternalResourceString error: ' + error.code + ' ' + error.message);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
private cancelAction(): void {
|
||||
HiLog.info(TAG, 'cancelAction');
|
||||
@@ -68,6 +115,10 @@ struct Index {
|
||||
const errorMessage = this.want?.parameters?.errorMessage ?? '';
|
||||
errorMsg.code = errorCode as number;
|
||||
errorMsg.message = errorMessage as string;
|
||||
if (errorMsg.code === Constants.ERR_JS_ACCOUNT_NOT_LOGIN) {
|
||||
this.loginDialog.open();
|
||||
return;
|
||||
}
|
||||
const errInfo: Record<string, Resource> = GetAlertMessage.getAlertMessage(errorMsg);
|
||||
const msg = errInfo.msg ?? '';
|
||||
this.getDialogConfig(msg);
|
||||
@@ -81,6 +132,10 @@ struct Index {
|
||||
aboutToAppear() {
|
||||
HiLog.info(TAG, 'PhoneDialog aboutToAppear');
|
||||
this.showErrorDialog();
|
||||
let str_1 = this.getExternalResourceString(Constants.DLP_CREDMGR_BUNDLE_NAME, 'entry', 'encrypt_page_login_title');
|
||||
this.loginDialogTitle = str_1.length > 0 ? str_1 : '';
|
||||
let str_2 = this.getExternalResourceString(Constants.DLP_CREDMGR_BUNDLE_NAME, 'entry', 'encrypt_page_login_action');
|
||||
this.loginButtonContent = str_2.length > 0 ? str_2 : '';
|
||||
}
|
||||
|
||||
aboutToDisappear() {
|
||||
|
||||
@@ -34,6 +34,7 @@ let abilityResult: ability.AbilityResult = {
|
||||
};
|
||||
|
||||
let storage = LocalStorage.getShared();
|
||||
|
||||
@Entry(storage)
|
||||
@Component
|
||||
struct Index {
|
||||
@@ -45,7 +46,9 @@ struct Index {
|
||||
@State cancel: ResourceStr = '';
|
||||
@State actionButton: ResourceStr = '';
|
||||
@State buttonOptions: ButtonOptions[] = [];
|
||||
|
||||
private context: common.UIExtensionContext = this.getUIContext().getHostContext() as common.UIExtensionContext;
|
||||
private loginDialogTitle: ResourceStr = '';
|
||||
private loginButtonContent: ResourceStr = '';
|
||||
dialogControllerButton: CustomDialogController | null = new CustomDialogController({
|
||||
builder: CustomContentDialog({
|
||||
primaryTitle: this.title,
|
||||
@@ -73,11 +76,13 @@ struct Index {
|
||||
background: $r('sys.color.ohos_id_color_button_normal'), action: () => {
|
||||
abilityResult.resultCode = 0;
|
||||
(getContext(this) as common.UIAbilityContext).terminateSelfWithResult(abilityResult);
|
||||
}}];
|
||||
}
|
||||
}];
|
||||
this.dialogControllerButton?.open();
|
||||
HiLog.error(TAG, 'network failed');
|
||||
return;
|
||||
};
|
||||
}
|
||||
;
|
||||
try {
|
||||
account_osAccount.DomainAccountManager.authWithPopup({
|
||||
onResult: async (resultCode: number, authResult: account_osAccount.AuthResult) => {
|
||||
@@ -111,6 +116,13 @@ struct Index {
|
||||
errInfo = GetAlertMessage.getAlertTitleMessage(errorMsg);
|
||||
} else if ([Constants.ERR_JS_USER_NO_PERMISSION_2C].includes(messageCode)) {
|
||||
errInfo = GetAlertMessage.getAlertMessage(errorMsg);
|
||||
} else if ([Constants.ERR_JS_ACCOUNT_NOT_LOGIN].includes(messageCode)) {
|
||||
errInfo = {
|
||||
'title': this.loginDialogTitle,
|
||||
'msg': $r('app.string.MESSAGE_APP_NO_ACCOUNT_ERROR'),
|
||||
'cancel': $r('app.string.ban'),
|
||||
'ok': this.loginButtonContent
|
||||
} as Record<string, Resource>;
|
||||
} else {
|
||||
errInfo = GetAlertMessage.getAlertMessage(errorMsg);
|
||||
}
|
||||
@@ -123,18 +135,66 @@ struct Index {
|
||||
background: $r('sys.color.ohos_id_color_button_normal'), action: () => {
|
||||
abilityResult.resultCode = 0;
|
||||
(getContext(this) as common.UIExtensionContext).terminateSelfWithResult(abilityResult);
|
||||
}}];
|
||||
}
|
||||
}];
|
||||
if (errInfo.ok) {
|
||||
this.buttonOptions.push({ value: this.actionButton, background: $r('sys.color.ohos_id_color_text_primary_activated'),
|
||||
fontColor: $r('sys.color.font_on_primary'), action: () => {
|
||||
this.authWithPop();
|
||||
}});
|
||||
this.buttonOptions.push({
|
||||
value: this.actionButton,
|
||||
background: $r('sys.color.ohos_id_color_text_primary_activated'),
|
||||
fontColor: $r('sys.color.font_on_primary'),
|
||||
action: () => {
|
||||
if ([Constants.ERR_JS_ACCOUNT_NOT_LOGIN].includes(messageCode)) {
|
||||
const ctx = this.getUIContext()?.getHostContext() as common.UIAbilityContext;
|
||||
if (!ctx) {
|
||||
return;
|
||||
}
|
||||
ctx.startAbility({
|
||||
bundleName: 'com.huawei.hmos.settings',
|
||||
abilityName: 'com.huawei.hmos.settings.MainAbility',
|
||||
uri: 'hms_account_home_settings'
|
||||
});
|
||||
this.cancelAction();
|
||||
} else {
|
||||
this.authWithPop();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
this.dialogControllerButton?.open();
|
||||
}
|
||||
|
||||
private cancelAction(): void {
|
||||
HiLog.info(TAG, 'cancelAction');
|
||||
if (!this.session) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
this.session.terminateSelfWithResult({ resultCode: 0 });
|
||||
} catch (error) {
|
||||
HiLog.wrapError(TAG, error, 'alert terminateSelfWithResult failed');
|
||||
}
|
||||
}
|
||||
|
||||
getExternalResourceString(bundle: string, module: string, resourceName: string): string {
|
||||
try {
|
||||
let ctx = this.context.createModuleContext(bundle, module);
|
||||
HiLog.info(TAG, 'getExternalResourceString get context from: ' + ctx.applicationInfo.name);
|
||||
let str = ctx.resourceManager.getStringByNameSync(resourceName);
|
||||
return str;
|
||||
} catch (e) {
|
||||
let error = e as BusinessError;
|
||||
HiLog.error(TAG, 'getExternalResourceString error: ' + error.code + ' ' + error.message);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
async aboutToAppear() {
|
||||
HiLog.info(TAG, 'alert aboutToAppear start');
|
||||
HiLog.info(TAG, `alert aboutToAppear start`);
|
||||
let str_1 = this.getExternalResourceString(Constants.DLP_CREDMGR_BUNDLE_NAME, 'entry', 'encrypt_page_login_title');
|
||||
this.loginDialogTitle = str_1.length > 0 ? str_1 : '';
|
||||
let str_2 = this.getExternalResourceString(Constants.DLP_CREDMGR_BUNDLE_NAME, 'entry', 'encrypt_page_login_action');
|
||||
this.loginButtonContent = str_2.length > 0 ? str_2 : '';
|
||||
try {
|
||||
let messageCode = -1;
|
||||
let errorMsg = {} as BusinessError;
|
||||
|
||||
Reference in New Issue
Block a user