From 4d74c0bea707ab232273cd03865be453893023de Mon Sep 17 00:00:00 2001 From: fanchenxuan Date: Wed, 27 Nov 2024 09:40:17 +0800 Subject: [PATCH] AIreview Signed-off-by: fanchenxuan --- .../main/ets/common/components/backBar.ets | 4 ++ .../main/ets/pages/application-tertiary.ets | 42 +++++++++---------- .../main/ets/pages/authority-secondary.ets | 3 ++ .../ets/pages/authority-tertiary-groups.ets | 6 +-- .../src/main/ets/pages/dialogPlus.ets | 21 ++++++---- .../src/main/ets/pages/globalSwitch.ets | 17 +++++--- .../src/main/ets/pages/other-permissions.ets | 9 ++-- 7 files changed, 60 insertions(+), 42 deletions(-) diff --git a/permissionmanager/src/main/ets/common/components/backBar.ets b/permissionmanager/src/main/ets/common/components/backBar.ets index 79aab9c..759f6fd 100644 --- a/permissionmanager/src/main/ets/common/components/backBar.ets +++ b/permissionmanager/src/main/ets/common/components/backBar.ets @@ -16,6 +16,7 @@ import router from '@ohos.router'; import common from '@ohos.app.ability.common'; import Constants from '../utils/constant'; +import { Log } from '../utils/utils'; @Component export struct backBar { @@ -45,6 +46,7 @@ export struct backBar { .backgroundColor(this.isBack ? $r('sys.color.interactive_click') : '') .onTouch(event => { if (event === undefined) { + Log.info('touch event is undefined.'); return; } if (event.type === TouchType.Down) { @@ -84,6 +86,7 @@ export struct backBar { .backgroundColor(this.isMore ? $r('sys.color.interactive_click') : '') .onTouch(event => { if (event === undefined) { + Log.info('touch event is undefined.'); return; } if (event.type === TouchType.Down) { @@ -126,6 +129,7 @@ export struct backBar { }) .onTouch(event => { if (event === undefined) { + Log.info('touch event is undefined.'); return; } if (event.type === TouchType.Down) { diff --git a/permissionmanager/src/main/ets/pages/application-tertiary.ets b/permissionmanager/src/main/ets/pages/application-tertiary.ets index bcf2c0c..1321c33 100644 --- a/permissionmanager/src/main/ets/pages/application-tertiary.ets +++ b/permissionmanager/src/main/ets/pages/application-tertiary.ets @@ -322,29 +322,27 @@ struct mediaDocumentItem { this.getMediaDocList(); this.getReason(); - bundleManager.getBundleInfo(this.bundleName, bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION) - .then(res => { - this.version = res.versionName; - accessTokenId = res.appInfo.accessTokenId; - let acManager = abilityAccessCtrl.createAtManager(); - let accurateStatus = acManager.verifyAccessTokenSync(res.appInfo.accessTokenId, Permission.LOCATION); - this.accurateIsOn = (accurateStatus == abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED) ? true : false; - try { - let getFlagPermission = - this.currentGroup === 'LOCATION' ? Permission.APPROXIMATELY_LOCATION : this.permissions[0]; - acManager.getPermissionFlags(res.appInfo.accessTokenId, getFlagPermission).then((flag) => { - Log.info(`getPermissionFlags success, data->${JSON.stringify(flag)}`); - this.isRisk = (flag == Constants.PERMISSION_POLICY_FIXED) ? true : false; - if (flag === Constants.PERMISSION_ALLOW_THIS_TIME) { - this.selected = Constants.PERMISSION_ONLY_THIS_TIME; - } + try { + bundleManager.getBundleInfo(this.bundleName, bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION) + .then(res => { + this.version = res.versionName; + accessTokenId = res.appInfo.accessTokenId; + let acManager = abilityAccessCtrl.createAtManager(); + let accurateStatus = acManager.verifyAccessTokenSync(res.appInfo.accessTokenId, Permission.LOCATION); + this.accurateIsOn = (accurateStatus == abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED) ? true : false; + let getFlagPermission = + this.currentGroup === 'LOCATION' ? Permission.APPROXIMATELY_LOCATION : this.permissions[0]; + acManager.getPermissionFlags(res.appInfo.accessTokenId, getFlagPermission).then((flag) => { + Log.info(`getPermissionFlags success, data->${JSON.stringify(flag)}`); + this.isRisk = (flag == Constants.PERMISSION_POLICY_FIXED) ? true : false; + flag === Constants.PERMISSION_ALLOW_THIS_TIME ? this.selected = Constants.PERMISSION_ONLY_THIS_TIME : null; + }) + }).catch((error: BusinessError) => { + Log.error('bundle.getBundleInfo failed. Cause: ' + JSON.stringify(error)); }) - } catch (err) { - Log.error('acManager.getPermissionFlags failed. Cause: ' + JSON.stringify(err)); - } - }).catch((error: BusinessError) => { - Log.error('bundle.getBundleInfo failed. Cause: ' + JSON.stringify(error)); - }) + } catch (err) { + Log.error('bundle.getBundleInfo failed. Cause: ' + JSON.stringify(err)); + } } build() { diff --git a/permissionmanager/src/main/ets/pages/authority-secondary.ets b/permissionmanager/src/main/ets/pages/authority-secondary.ets index 053f854..d7741a4 100644 --- a/permissionmanager/src/main/ets/pages/authority-secondary.ets +++ b/permissionmanager/src/main/ets/pages/authority-secondary.ets @@ -122,6 +122,9 @@ struct appNameItem { let permissionsList = groups.filter((item) => { return item.name === this.group; }) + if (!permissionsList.length) { + return; + } for (let i = 0; i < permissionsList[0].permissions.length; i++) { permissionGroups.forEach((item) => { if (item.permissionName === permissionsList[0].permissions[i]) { diff --git a/permissionmanager/src/main/ets/pages/authority-tertiary-groups.ets b/permissionmanager/src/main/ets/pages/authority-tertiary-groups.ets index ac58bfb..b41ddf0 100644 --- a/permissionmanager/src/main/ets/pages/authority-tertiary-groups.ets +++ b/permissionmanager/src/main/ets/pages/authority-tertiary-groups.ets @@ -196,15 +196,15 @@ struct applicationItem { Log.info('global accept'); if (this.currentGroup == PermissionGroup.MICROPHONE) { let audioManager = audio.getAudioManager(); - let audioVolumeManager = audioManager.getVolumeManager(); - audioVolumeManager.getVolumeGroupManager(audio.DEFAULT_VOLUME_GROUP_ID).then(audioVolumeGroupManager => { + let audioVolumeManager = audioManager?.getVolumeManager(); + audioVolumeManager?.getVolumeGroupManager(audio.DEFAULT_VOLUME_GROUP_ID).then(audioVolumeGroupManager => { audioVolumeGroupManager.setMicMutePersistent(true, audio.PolicyType.PRIVACY).then(() => { this.dialogController?.close(); }) }) } else { let cameraManager = camera.getCameraManager(GlobalContext.load('context')); - cameraManager.muteCameraPersistent(true, camera.PolicyType.PRIVACY); + cameraManager?.muteCameraPersistent(true, camera.PolicyType.PRIVACY); this.dialogController?.close(); } } diff --git a/permissionmanager/src/main/ets/pages/dialogPlus.ets b/permissionmanager/src/main/ets/pages/dialogPlus.ets index b180c4a..d03003f 100644 --- a/permissionmanager/src/main/ets/pages/dialogPlus.ets +++ b/permissionmanager/src/main/ets/pages/dialogPlus.ets @@ -367,16 +367,21 @@ struct dialogPlusPage { this.result = new Array(this.reqPerms.length).fill(-1); this.getPasteBoardInfo(); let bundleName: string = this.want.parameters['ohos.aafwk.param.callerBundleName']; - bundleManager.getBundleInfo(bundleName, bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION) - .then(bundleInfo => { - this.reqPermissionDetails = bundleInfo.reqPermissionDetails; - this.getGrantGroups(this.want.parameters['ohos.user.grant.permission.state']); - this.getApplicationName(bundleName); - this.dialogController?.open(); - }).catch((err: BusinessError) => { + try { + bundleManager.getBundleInfo(bundleName, bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION) + .then(bundleInfo => { + this.reqPermissionDetails = bundleInfo.reqPermissionDetails; + this.getGrantGroups(this.want.parameters['ohos.user.grant.permission.state']); + this.getApplicationName(bundleName); + this.dialogController?.open(); + }).catch((err: BusinessError) => { + Log.error('getBundleInfo error :' + JSON.stringify(err)); + this.initStatus = Constants.INIT_NEED_TO_TERMINATED; + }) + } catch (err) { Log.error('getBundleInfo error :' + JSON.stringify(err)); this.initStatus = Constants.INIT_NEED_TO_TERMINATED; - }) + } } aboutToDisappear() { diff --git a/permissionmanager/src/main/ets/pages/globalSwitch.ets b/permissionmanager/src/main/ets/pages/globalSwitch.ets index d5ef035..ecf7f7e 100644 --- a/permissionmanager/src/main/ets/pages/globalSwitch.ets +++ b/permissionmanager/src/main/ets/pages/globalSwitch.ets @@ -20,6 +20,7 @@ import common from '@ohos.app.ability.common'; import { CustomContentDialog } from '@ohos.arkui.advanced.Dialog'; import { Log } from '../common/utils/utils'; import { GlobalContext } from '../common/utils/globalContext'; +import { BusinessError } from '@kit.BasicServicesKit'; const MICROPHONE = 'microphone'; const CAMERA = 'camera'; @@ -54,10 +55,12 @@ struct globalSwitch { let audioManager = audio.getAudioManager(); let audioVolumeManager = audioManager.getVolumeManager(); audioVolumeManager.getVolumeGroupManager(audio.DEFAULT_VOLUME_GROUP_ID).then(audioVolumeGroupManager => { - audioVolumeGroupManager.setMicMutePersistent(false, audio.PolicyType.PRIVACY).then(() => { - this.context.terminateSelf(); + audioVolumeGroupManager.setMicMutePersistent(false, audio.PolicyType.PRIVACY).then(() => { + this.context.terminateSelf(); + }) + }).catch((err: BusinessError) => { + Log.error(`getVolumeGroupManager failed: ${JSON.stringify(err)}`); }) - }) } else if (this.globalState == CAMERA) { let cameraManager = camera.getCameraManager(GlobalContext.load('context')); cameraManager.muteCameraPersistent(false, camera.PolicyType.PRIVACY); @@ -68,10 +71,12 @@ struct globalSwitch { let audioManager = audio.getAudioManager(); let audioVolumeManager = audioManager.getVolumeManager(); audioVolumeManager.getVolumeGroupManager(audio.DEFAULT_VOLUME_GROUP_ID).then(audioVolumeGroupManager => { - audioVolumeGroupManager.setMicMutePersistent(false, audio.PolicyType.PRIVACY).then(() => { - this.context.terminateSelf(); + audioVolumeGroupManager.setMicMutePersistent(false, audio.PolicyType.PRIVACY).then(() => { + this.context.terminateSelf(); + }) + }).catch((err: BusinessError) => { + Log.error(`getVolumeGroupManager failed: ${JSON.stringify(err)}`); }) - }) } } } diff --git a/permissionmanager/src/main/ets/pages/other-permissions.ets b/permissionmanager/src/main/ets/pages/other-permissions.ets index 0944385..a778e9d 100644 --- a/permissionmanager/src/main/ets/pages/other-permissions.ets +++ b/permissionmanager/src/main/ets/pages/other-permissions.ets @@ -17,9 +17,10 @@ import { backBar } from '../common/components/backBar'; import router from '@ohos.router'; import Constants from '../common/utils/constant'; import { permissionGroups } from '../common/model/permissionGroup'; -import { verifyAccessToken } from '../common/utils/utils'; +import { Log, verifyAccessToken } from '../common/utils/utils'; import { OtherPermission, RouterParams3 } from '../common/model/typedef'; import { Permissions } from '@ohos.abilityAccessCtrl'; +import { BusinessError } from '@kit.BasicServicesKit'; let status: number = (router.getParams() as RouterParams3).status; // Status: Allowed, Forbidden let permissions: Permissions[] = (router.getParams() as RouterParams3).permission; // permissions name @@ -70,8 +71,10 @@ struct appNamePage { onPageShow() { permissions.forEach(permission => { verifyAccessToken(this.tokenId, permission).then((data): void => { - status = data; - }); + status = data; + }).catch((err: BusinessError) => { + Log.error(`verifyAccessToken failed: ${JSON.stringify(err)}`) + }); }) } } -- Gitee