diff --git a/permissionmanager/src/main/ets/GlobalExtAbility/GlobalDialogModel.ets b/permissionmanager/src/main/ets/GlobalExtAbility/GlobalDialogModel.ets index b0999c72cc40b7d99d16d1ad2df01c870a39ef00..e8b8f1c5691194b0451aa2b1a216c717619b08a7 100644 --- a/permissionmanager/src/main/ets/GlobalExtAbility/GlobalDialogModel.ets +++ b/permissionmanager/src/main/ets/GlobalExtAbility/GlobalDialogModel.ets @@ -21,7 +21,6 @@ import { Log } from '../common/utils/utils'; import { PermissionGroup } from '../common/model/definition'; import { PermissionApplications } from '../common/model/typedef'; import { GlobalDialogViewState } from './GlobalDialogViewState'; -import router from '@ohos.router'; import window from '@ohos.window'; import display from '@ohos.display'; import common from '@ohos.app.ability.common'; @@ -189,7 +188,7 @@ export class GlobalDialogModel extends BaseModel { * return */ public getMuteStateAndGoto( - context: common.UIAbilityContext, + context: UIContext, type: PermissionGroup, backTitle: ResourceStr, list: PermissionApplications[] @@ -201,16 +200,16 @@ export class GlobalDialogModel extends BaseModel { let audioVolumeGroupManager = audioVolumeManager.getVolumeGroupManagerSync(audio.DEFAULT_VOLUME_GROUP_ID); let muteState = audioVolumeGroupManager.isPersistentMicMute(); Log.info(`get muteState success: ${muteState}.`); - router.pushUrl({ + context.getRouter().pushUrl({ url: 'pages/authority-tertiary-groups', params: { list, backTitle, globalIsOn: !muteState, isMuteSupported: true } }) } else { - let cameraManager = camera.getCameraManager(context); + let cameraManager = camera.getCameraManager(context.getHostContext()); let mute = cameraManager.isCameraMuted(); let isCameraMuteSupported = cameraManager.isCameraMuteSupported(); Log.info(`get muteState success: ${mute}.`); - router.pushUrl({ + context.getRouter().pushUrl({ url: 'pages/authority-tertiary-groups', params: { list, backTitle, globalIsOn: !mute, isMuteSupported: isCameraMuteSupported } }) diff --git a/permissionmanager/src/main/ets/PermissionSheet/GlobalSwitchSheetDialog.ets b/permissionmanager/src/main/ets/PermissionSheet/GlobalSwitchSheetDialog.ets index 1b2f90b03d49407d3593f65a4fab964a696cd10f..e63cb2d7d2f9a9e6b4348ae4733f36abe198e83a 100644 --- a/permissionmanager/src/main/ets/PermissionSheet/GlobalSwitchSheetDialog.ets +++ b/permissionmanager/src/main/ets/PermissionSheet/GlobalSwitchSheetDialog.ets @@ -32,16 +32,14 @@ import { PermissionGroup } from '../common/model/definition'; let globalIsOn: boolean; let session: UIExtensionContentSession; -let storage = LocalStorage.getShared(); let bundleName = ''; -@Entry(storage) +@Entry({ useSharedStorage: true }) @Component struct GlobalSwitchSheetDialog { - @LocalStorageLink('want') want: Want | null = storage.get('want') || null; - @LocalStorageLink('session') session: UIExtensionContentSession = - storage.get('session') as UIExtensionContentSession; - private context = getContext(this) as common.UIExtensionContext; + @LocalStorageLink('want') want: Want | null = null; + @LocalStorageLink('session') session: UIExtensionContentSession = {} as UIExtensionContentSession; + private context = this.getUIContext().getHostContext() as common.UIExtensionContext; private muteSuppoted = false; private groupName: PermissionGroup = PermissionGroup.OTHER; dialogController: CustomDialogController | null = new CustomDialogController({ @@ -139,7 +137,7 @@ struct GlobalSwitchSheetDialog { @CustomDialog struct applicationItem { - private context = getContext(this) as common.UIExtensionContext; + private context = this.getUIContext().getHostContext() as common.UIExtensionContext; @State globalIsOn: boolean = false; @State backTitle: string = ''; @State groupInfo: GroupInfo = new GroupInfo(PermissionGroup.OTHER, '', '', '', [], '', [], [], false); @@ -183,7 +181,7 @@ struct applicationItem { }) } else { let cameraManager = camera.getCameraManager(this.context); - cameraManager.muteCamera(true); + cameraManager.muteCameraPersistent(true, camera.PolicyType.PRIVACY); if (this.dialogController !== null) { this.dialogController.close(); } @@ -333,7 +331,7 @@ struct applicationItem { if (isOn) { if (this.currentGroup == 'CAMERA') { let cameraManager = camera.getCameraManager(this.context); - cameraManager.muteCamera(false); + cameraManager.muteCameraPersistent(false, camera.PolicyType.PRIVACY); PermissionDialogReturn([Constants.PERMISSION_DIALOG_SUCCESS], session); this.context.terminateSelf(); } else { diff --git a/permissionmanager/src/main/ets/PermissionSheet/PermissionStateSheetDialog.ets b/permissionmanager/src/main/ets/PermissionSheet/PermissionStateSheetDialog.ets index cdd7d11458c7d29659e7791e1b79494d97f95cea..1d8cd4a92cf46562342b48b748cb9c2cb5393f69 100644 --- a/permissionmanager/src/main/ets/PermissionSheet/PermissionStateSheetDialog.ets +++ b/permissionmanager/src/main/ets/PermissionSheet/PermissionStateSheetDialog.ets @@ -33,7 +33,6 @@ import { groups, showSubPermissionsGroup } from '../common/model/permissionGroup import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; import { CustomContentDialog } from '@ohos.arkui.advanced.Dialog' -let storage = LocalStorage.getShared(); let accessTokenId: number = 0; let session: UIExtensionContentSession; let results: Map = new Map(); @@ -73,13 +72,12 @@ export function getCallerBundleInfo(want: WantInfo): CallerBundleInfo { return callerBundle; } -@Entry(storage) +@Entry({ useSharedStorage: true }) @Component struct PermissionStateSheetDialog { - private context = getContext(this) as common.ServiceExtensionContext; - @LocalStorageLink('want') want: Want | null = storage.get('want') || null; - @LocalStorageLink('session') session: UIExtensionContentSession = - storage.get('session') as UIExtensionContentSession; + private context = this.getUIContext().getHostContext() as common.ServiceExtensionContext; + @LocalStorageLink('want') want: Want | null = null; + @LocalStorageLink('session') session: UIExtensionContentSession = {} as UIExtensionContentSession; @State applicationInfo: AppInfo | undefined = undefined; @State folderStatus: boolean[] = [false, false, false]; @State reqUserPermissions: Permission[] = []; @@ -349,7 +347,7 @@ struct PermissionStateSheetDialog { @CustomDialog struct mediaDocumentItem { - private context = getContext(this) as common.UIAbilityContext; + private context = this.getUIContext().getHostContext() as common.UIAbilityContext; private backTitle: ResourceStr = ''; private bundleName: string = ''; private permissions: Permission[] = []; diff --git a/permissionmanager/src/main/ets/common/components/backBar.ets b/permissionmanager/src/main/ets/common/components/backBar.ets index 759f6fd26f3480c1b36a327572992a53c9780299..c8991e59f18b841ac84ef174ce02f3a1d171f51a 100644 --- a/permissionmanager/src/main/ets/common/components/backBar.ets +++ b/permissionmanager/src/main/ets/common/components/backBar.ets @@ -13,14 +13,13 @@ * limitations under the License. */ -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 { - private context = getContext(this) as common.UIAbilityContext; + private context = this.getUIContext().getHostContext() as common.UIAbilityContext; @Prop title: string = ''; // return title name @Prop recordable: boolean = false; @State record: string = ''; @@ -57,6 +56,7 @@ export struct backBar { } }) .onClick(() => { + let router = this.getUIContext().getRouter(); let length = router.getLength(); Number(length) == 1 ? this.context.terminateSelf() : router.back(); }) @@ -140,7 +140,7 @@ export struct backBar { } }) .onClick(() => { - router.pushUrl({ url: 'pages/permission-access-record' }) + this.getUIContext().getRouter().pushUrl({ url: 'pages/permission-access-record' }) }) } } diff --git a/permissionmanager/src/main/ets/pages/application-secondary.ets b/permissionmanager/src/main/ets/pages/application-secondary.ets index aaa3734f7c56f2693a1efbc2d7ddbaa548011e64..a3250b12a38be00f008fd27f758ab5678114f02e 100644 --- a/permissionmanager/src/main/ets/pages/application-secondary.ets +++ b/permissionmanager/src/main/ets/pages/application-secondary.ets @@ -14,7 +14,6 @@ */ import { backBar } from '../common/components/backBar'; -import router from '@ohos.router'; import common from '@ohos.app.ability.common'; import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl'; import bundleManager from '@ohos.bundle.bundleManager'; @@ -29,7 +28,7 @@ import { Permission } from '../common/model/definition'; @Entry @Component struct appNamePlusPage { - private context = getContext(this) as common.UIAbilityContext; + private context = this.getUIContext().getHostContext() as common.UIAbilityContext; @State allowedListItem: PermissionObj[] = []; // Array of allowed permissions @State bannedListItem: PermissionObj[] = []; // array of forbidden permissions @State applicationInfo: AppInfo = GlobalContext.load('applicationInfo'); // Routing jump data @@ -63,8 +62,8 @@ struct appNamePlusPage { } }.onClick(() => { GlobalContext.store('currentPermissionGroup', item.group); - router.pushUrl({ - url: item.group == 'OTHER' ? 'pages/other-permissions' : 'pages/application-tertiary', + this.getUIContext().getRouter().pushUrl({ + url: 'pages/application-tertiary', params: { bundleName: this.applicationInfo.bundleName, backTitle: item.groupName, @@ -259,7 +258,7 @@ struct appNamePlusPage { bundleManager.getApplicationInfo( this.applicationInfo.bundleName, bundleManager.ApplicationFlag.GET_APPLICATION_INFO_DEFAULT ).then(appInfo => { - let bundleContext = this.context.createBundleContext(this.applicationInfo.bundleName) + let bundleContext = this.context.createBundleContext(this.applicationInfo.bundleName); bundleContext.resourceManager.getStringValue(appInfo.labelId, (error, value) => { if (value) { this.applicationInfo.label = value; diff --git a/permissionmanager/src/main/ets/pages/application-tertiary.ets b/permissionmanager/src/main/ets/pages/application-tertiary.ets index 9c9eeae2047b1eff89e5594fe480821deaf21da9..59b13d976cbdb3133b1cbfb2e3c26097232dd737 100644 --- a/permissionmanager/src/main/ets/pages/application-tertiary.ets +++ b/permissionmanager/src/main/ets/pages/application-tertiary.ets @@ -14,7 +14,6 @@ */ import { backBar } from '../common/components/backBar'; -import router from '@ohos.router'; import common from '@ohos.app.ability.common'; import bundleManager from '@ohos.bundle.bundleManager'; import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl'; @@ -33,9 +32,9 @@ let reqPermissionInfo: bundleManager.ReqPermissionDetail; @Entry @Component struct mediaDocumentPage { - private backTitle: ResourceStr = (router.getParams() as RouterParams3).backTitle; - private permissions: Permissions[] = (router.getParams() as RouterParams3).permission; - private tokenId: number = (router.getParams() as RouterParams3).tokenId; + private backTitle: ResourceStr = (this.getUIContext().getRouter().getParams() as RouterParams3).backTitle; + private permissions: Permissions[] = (this.getUIContext().getRouter().getParams() as RouterParams3).permission; + private tokenId: number = (this.getUIContext().getRouter().getParams() as RouterParams3).tokenId; @State currentGroup: string = GlobalContext.load('currentPermissionGroup'); @State folderStatus: boolean[] = GlobalContext.load('folderStatus'); @State refresh: boolean = false; @@ -157,11 +156,11 @@ struct mediaDocumentPage { @Component struct mediaDocumentItem { - private context = getContext(this) as common.UIAbilityContext; - private backTitle: ResourceStr = (router.getParams() as RouterParams3).backTitle; - private bundleName: string = (router.getParams() as RouterParams3).bundleName; - private permissions: Permission[] = (router.getParams() as RouterParams3).permission; - private status: number = (router.getParams() as RouterParams3).status; + private context = this.getUIContext().getHostContext() as common.UIAbilityContext; + private backTitle: ResourceStr = (this.getUIContext().getRouter().getParams() as RouterParams3).backTitle; + private bundleName: string = (this.getUIContext().getRouter().getParams() as RouterParams3).bundleName; + private permissions: Permission[] = (this.getUIContext().getRouter().getParams() as RouterParams3).permission; + private status: number = (this.getUIContext().getRouter().getParams() as RouterParams3).status; @State currentGroup: PermissionGroup = GlobalContext.load('currentPermissionGroup'); @State applicationInfo: AppInfo = GlobalContext.load('applicationInfo'); @Link folderStatus: boolean[]; diff --git a/permissionmanager/src/main/ets/pages/authority-management.ets b/permissionmanager/src/main/ets/pages/authority-management.ets index 3181642f8b96b589df79d1b741f63694cbfa27c2..4210d1482a2c2c922aa94e341663aa2950b9f26f 100644 --- a/permissionmanager/src/main/ets/pages/authority-management.ets +++ b/permissionmanager/src/main/ets/pages/authority-management.ets @@ -16,7 +16,6 @@ import { backBar } from '../common/components/backBar'; import { alphabetIndexerComponent } from '../common/components/alphabeticalIndex'; import { textInput } from '../common/components/search'; -import router from '@ohos.router'; import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; import display from '@ohos.display'; import common from '@ohos.app.ability.common'; @@ -38,8 +37,6 @@ import { GlobalDialogModel } from '../GlobalExtAbility/GlobalDialogModel'; import Constants from '../common/utils/constant'; import bundleManager from '@ohos.bundle.bundleManager'; -let storage = LocalStorage.getShared(); - @Extend(Image)function customizeImage(width: number, height: number) { .objectFit(ImageFit.Contain) .width(width) @@ -47,7 +44,7 @@ let storage = LocalStorage.getShared(); .draggable(false) }; -@Entry(storage) +@Entry({ useSharedStorage: true }) @Component struct authorityManagementPage { @Builder ListItemLayout(item: GroupPermission) { @@ -77,7 +74,7 @@ struct authorityManagementPage { } }.onClick(() => { if (item.group === 'OTHER' || showSubPermissionsGroup.indexOf(item.group) !== -1) { - router.pushUrl({ + this.getUIContext().getRouter().pushUrl({ url: 'pages/authority-secondary', params: { list: this.allPermissionApplications, backTitle: item.groupName, group: item.group } }) @@ -88,12 +85,14 @@ struct authorityManagementPage { GlobalContext.store('currentPermissionGroup', item.group); if (globalGroup.indexOf(item.group) == -1) { - router.pushUrl({ + this.getUIContext().getRouter().pushUrl({ url: 'pages/authority-tertiary-groups', params: { list: dataList, backTitle: item.groupName } }) } else { - GlobalDialogModel.getInstance().getMuteStateAndGoto(this.context, item.group, item.groupName, dataList); + GlobalDialogModel.getInstance().getMuteStateAndGoto( + this.getUIContext(), item.group, item.groupName, dataList + ); } } }) @@ -122,7 +121,7 @@ struct authorityManagementPage { }) } - private context = getContext(this) as common.UIAbilityContext; + private context = this.getUIContext().getHostContext() as common.UIAbilityContext; @LocalStorageLink('initialGroups') initialGroups: bundleManager.BundleInfo[] = []; @State allPermissionApplications: PermissionApplications [] = []; // All app permissions @State allGroupPermission: GroupPermission[] = []; // All group permissions @@ -585,7 +584,7 @@ struct applicationItem { } }.onClick(() => { GlobalContext.store('applicationInfo', item); - router.pushUrl({ url: 'pages/application-secondary' }); + this.getUIContext().getRouter().pushUrl({ url: 'pages/application-secondary' }); }) } }.padding({ left: $r('sys.float.ohos_id_card_margin_start'), right: $r('sys.float.ohos_id_card_margin_end') }) diff --git a/permissionmanager/src/main/ets/pages/authority-secondary.ets b/permissionmanager/src/main/ets/pages/authority-secondary.ets index 1d7e1f1c45b4fac22fd2ec56b36c26f5f38b4979..280f0fca62d2f3783498cbf08dc3d4a1f02cbb23 100644 --- a/permissionmanager/src/main/ets/pages/authority-secondary.ets +++ b/permissionmanager/src/main/ets/pages/authority-secondary.ets @@ -15,14 +15,13 @@ import { backBar } from '../common/components/backBar'; import { permissionInfos, groups } from '../common/model/permissionGroup'; -import router from '@ohos.router'; import Constants from '../common/utils/constant'; import { CalendarObj, RouterParams1, PermissionApplications } from '../common/model/typedef'; @Entry @Component struct appNamePage { - private backTitle: ResourceStr = (router.getParams() as RouterParams1).backTitle; + private backTitle: ResourceStr = (this.getUIContext().getRouter().getParams() as RouterParams1).backTitle; build() { GridRow({ gutter: Constants.GUTTER, columns: { @@ -55,9 +54,9 @@ struct appNamePage { @Component struct appNameItem { - @State calendarListItem: CalendarObj[] = []; // Permission management secondary interface data array - private list: PermissionApplications[] = (router.getParams() as RouterParams1).list; // Routing jump data - private group: string = (router.getParams() as RouterParams1).group; + @State calendarListItem: CalendarObj[] = []; + private list: PermissionApplications[] = (this.getUIContext().getRouter().getParams() as RouterParams1).list; + private group: string = (this.getUIContext().getRouter().getParams() as RouterParams1).group; @State isTouch: string = ''; @Builder ListItemLayout(item: CalendarObj) { @@ -85,7 +84,7 @@ struct appNameItem { let dataList = this.list.filter((ele) => { return ele.permission === item.permissionName; }) - router.pushUrl({ + this.getUIContext().getRouter().pushUrl({ url: 'pages/authority-tertiary', params: { list: dataList, backTitle: item.label, permissionName: item.permissionName } }); diff --git a/permissionmanager/src/main/ets/pages/authority-tertiary-groups.ets b/permissionmanager/src/main/ets/pages/authority-tertiary-groups.ets index 208861b0704026665d91764b3623aad585ccb4a2..4e1a4651f049ec9c6089110e5f034843af56e780 100644 --- a/permissionmanager/src/main/ets/pages/authority-tertiary-groups.ets +++ b/permissionmanager/src/main/ets/pages/authority-tertiary-groups.ets @@ -16,7 +16,6 @@ import { backBar } from '../common/components/backBar'; import { alphabetIndexerComponent } from '../common/components/alphabeticalIndex'; import { textInput } from '../common/components/search'; -import router from '@ohos.router'; import bundleManager from '@ohos.bundle.bundleManager'; import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl'; import { BusinessError } from '@ohos.base'; @@ -40,13 +39,12 @@ const locationStatus: Resource[] = [ ]; let cameraManager: camera.CameraManager; let audioVolumeGroupManager: audio.AudioVolumeGroupManager; -let globalIsOn: boolean = (router.getParams() as RouterParams1).globalIsOn; // return title name @Entry @Component struct locationInfoPage { - private backTitle: ResourceStr = (router.getParams() as RouterParams1).backTitle; - private list: PermissionApplications[] = (router.getParams() as RouterParams1).list; + private backTitle: ResourceStr = (this.getUIContext().getRouter().getParams() as RouterParams1).backTitle; + private list: PermissionApplications[] = (this.getUIContext().getRouter().getParams() as RouterParams1).list; @State currentGroup: PermissionGroup = GlobalContext.load('currentPermissionGroup'); @State polymorphismIsOn: Array = []; @State folderStatusArray: Array> = [[]]; @@ -159,10 +157,12 @@ struct locationInfoPage { @Component struct applicationItem { - private context = getContext(this) as common.UIAbilityContext; - private backTitle: ResourceStr = (router.getParams() as RouterParams1).backTitle; - private list: PermissionApplications[] = (router.getParams() as RouterParams1).list; - private isMuteSupported: boolean | undefined = (router.getParams() as RouterParams1).isMuteSupported; + private context = this.getUIContext().getHostContext() as common.UIAbilityContext; + private backTitle: ResourceStr = (this.getUIContext().getRouter().getParams() as RouterParams1).backTitle; + private list: PermissionApplications[] = (this.getUIContext().getRouter().getParams() as RouterParams1).list; + private isMuteSupported: boolean | undefined = + (this.getUIContext().getRouter().getParams() as RouterParams1).isMuteSupported; + @State globalIsOn: boolean = (this.getUIContext().getRouter().getParams() as RouterParams1).globalIsOn ?? true; @State permissionNum: number = Constants.PERMISSION_NUM; // permission num @State toggleIsOn: boolean[] = []; // toggle switch state array @State isRisk: boolean[] = []; @@ -171,7 +171,6 @@ struct applicationItem { @State searchResult: boolean = true; // search results @Link polymorphismIsOn: Array; @Link folderStatusArray: Array>; - @State globalIsOn: boolean = true; @State selectedIndex: number = 0; @State isTouch: string = ''; @State groupInfo: GroupInfo = new GroupInfo(PermissionGroup.OTHER, '', '', '', [], '', [], [], false); @@ -345,7 +344,7 @@ struct applicationItem { }) GlobalContext.store('folderStatus', this.folderStatusArray[item.index]); GlobalContext.store('locationStatus', this.polymorphismIsOn[item.index]); - router.pushUrl({ + this.getUIContext().getRouter().pushUrl({ url: 'pages/application-tertiary', params: { bundleName: item.bundleName, @@ -526,7 +525,6 @@ struct applicationItem { globalListen() { try { - this.globalIsOn = globalIsOn; if (this.currentGroup === 'CAMERA') { cameraManager = camera.getCameraManager(this.context); cameraManager.on('cameraMute', (err, curMuted) => { diff --git a/permissionmanager/src/main/ets/pages/authority-tertiary.ets b/permissionmanager/src/main/ets/pages/authority-tertiary.ets index 79b6b6c3dd0960bcf4fd21de0697aed4752100d9..3f17017a02049f37a48208cc8c9acd3c073f696d 100644 --- a/permissionmanager/src/main/ets/pages/authority-tertiary.ets +++ b/permissionmanager/src/main/ets/pages/authority-tertiary.ets @@ -16,7 +16,6 @@ import { backBar } from '../common/components/backBar'; import { alphabetIndexerComponent } from '../common/components/alphabeticalIndex'; import { textInput } from '../common/components/search'; -import router from '@ohos.router'; import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl'; import { BusinessError } from '@ohos.base'; import { Log, verifyAccessToken, indexValue, sortByName } from '../common/utils/utils'; @@ -41,7 +40,7 @@ import { Permission } from '../common/model/definition'; @Entry @Component struct locationInfoPage { - private backTitle: ResourceStr = (router.getParams() as RouterParams2).backTitle; + private backTitle: ResourceStr = (this.getUIContext().getRouter().getParams() as RouterParams2).backTitle; build() { GridRow({ gutter: Constants.GUTTER, columns: { @@ -74,8 +73,8 @@ struct locationInfoPage { @Component struct applicationItem { - private list: PermissionApplications[] = (router.getParams() as RouterParams2).list; - private permissionName: Permission = (router.getParams() as RouterParams2).permissionName; + private list: PermissionApplications[] = (this.getUIContext().getRouter().getParams() as RouterParams2).list; + private permissionName: Permission = (this.getUIContext().getRouter().getParams() as RouterParams2).permissionName; @State permissionNum: number = Constants.PERMISSION_NUM; // permission num @State toggleIsOn: boolean[] = []; // toggle switch state array @State isRisk: boolean[] = []; diff --git a/permissionmanager/src/main/ets/pages/dialogPlus.ets b/permissionmanager/src/main/ets/pages/dialogPlus.ets index 8cdc2ebd43f403a56f9eff6220e4781de9a95433..16b06970bf832aad4d8bf373e1bd6c6e8a365ac2 100644 --- a/permissionmanager/src/main/ets/pages/dialogPlus.ets +++ b/permissionmanager/src/main/ets/pages/dialogPlus.ets @@ -16,7 +16,6 @@ import window from '@ohos.window'; import common from '@ohos.app.ability.common'; import Constants from '../common/utils/constant'; -import { MeasureText } from '@kit.ArkUI'; import { CustomContentDialog } from '@ohos.arkui.advanced.Dialog'; import { Log, getFontSizeScale, } from '../common/utils/utils'; import { EventObserver } from '../common/observer/EventObserver'; @@ -43,25 +42,24 @@ import { GrantDialogViewState } from '../ServiceExtAbility/GrantDialogViewState' } const EVENT_BUNDLE_RESOURCES_CHANGED = 'usual.event.BUNDLE_RESOURCES_CHANGED'; -let storage = LocalStorage.getShared(); -let callerAppInfo: CallerAppInfo = storage.get('callerAppInfo') as CallerAppInfo; -let win: window.Window = storage.get('win') as window.Window; -let viewModel: GrantDialogViewModel = new GrantDialogViewModel(callerAppInfo, win); -@Entry(storage) +@Entry({ useSharedStorage: true }) @Component struct dialogPlusPage { - private context = getContext(this) as common.ServiceExtensionContext; + private context = this.getUIContext().getHostContext() as common.ServiceExtensionContext; private resourceChangeObserver: EventObserver = new EventObserver([EVENT_BUNDLE_RESOURCES_CHANGED]); - @State viewState: GrantDialogViewState = viewModel.getViewState(); + @LocalStorageLink('callerAppInfo') callerAppInfo: CallerAppInfo = {} as CallerAppInfo; + @LocalStorageLink('win') win: window.Window = {} as window.Window; + @State viewModel: GrantDialogViewModel = new GrantDialogViewModel(this.callerAppInfo, this.win); + @State viewState: GrantDialogViewState = this.viewModel.getViewState(); private refreshData = (): void => { - if (callerAppInfo === undefined) { + if (this.callerAppInfo === undefined) { Log.error(`event error, callerAppInfo is undefined.`); return; } try { - viewModel.processIntent( - new GrantDialogIntent.RefreshIntent(this.context, callerAppInfo) + this.viewModel.processIntent( + new GrantDialogIntent.RefreshIntent(this.context, this.callerAppInfo) ); } catch (error) { Log.error(`try to refresh data faild, code: ${error.code}, message: ${error.message}.`); @@ -228,12 +226,12 @@ struct dialogPlusPage { let denyText = buttonResource.get(buttonStatus[0]); let allowText = buttonResource.get(buttonStatus[1]); let maxButtonTextLength = Math.max( - MeasureText.measureText({ textContent: denyText }), - MeasureText.measureText({ textContent: allowText }) + this.getUIContext().getMeasureUtils().measureText({ textContent: denyText }), + this.getUIContext().getMeasureUtils().measureText({ textContent: allowText }) ) - Log.info(`px2vp(maxButtonTextLength): ${px2vp(maxButtonTextLength)}`); - if (px2vp(maxButtonTextLength) > Constants.DIALOG_BUTTON_MAX_WIDTH) { + Log.info(`px2vp(maxButtonTextLength): ${this.getUIContext().px2vp(maxButtonTextLength)}`); + if (this.getUIContext().px2vp(maxButtonTextLength) > Constants.DIALOG_BUTTON_MAX_WIDTH) { return false; } @@ -241,7 +239,7 @@ struct dialogPlusPage { } aboutToAppear() { - viewModel.processIntent(new GrantDialogIntent.InitIntent(this.context)).then(result => { + this.viewModel.processIntent(new GrantDialogIntent.InitIntent(this.context)).then(result => { this.dialogController?.open(); }) this.context.eventHub.on('refresh', () => { @@ -258,13 +256,13 @@ struct dialogPlusPage { processClick(buttonStatus: ButtonStatus) { let groupConfig: PermissionGroupConfig = this.viewState.grantGroups[this.viewState.curIndex]; - if (callerAppInfo === undefined) { + if (this.callerAppInfo === undefined) { Log.error(`processClick faild, callerAppInfo is undefined.`); return; } let clickIntent: GrantDialogIntent.ClickIntent = - new GrantDialogIntent.ClickIntent(this.context, groupConfig, callerAppInfo, buttonStatus); - viewModel.processIntent(clickIntent); + new GrantDialogIntent.ClickIntent(this.context, groupConfig, this.callerAppInfo, buttonStatus); + this.viewModel.processIntent(clickIntent); } } \ No newline at end of file diff --git a/permissionmanager/src/main/ets/pages/globalSwitch.ets b/permissionmanager/src/main/ets/pages/globalSwitch.ets index 1d0f70acd6d1e03513a9921f2ad63c64c10662eb..923aab14393b3301268d0134c5d73218a4cbbb09 100644 --- a/permissionmanager/src/main/ets/pages/globalSwitch.ets +++ b/permissionmanager/src/main/ets/pages/globalSwitch.ets @@ -19,15 +19,14 @@ import { CustomContentDialog } from '@ohos.arkui.advanced.Dialog'; import { GlobalDialogModel } from '../GlobalExtAbility/GlobalDialogModel'; import { GlobalDialogViewState } from '../GlobalExtAbility/GlobalDialogViewState'; -let storage = LocalStorage.getShared(); -let globalState: string = storage.get('globalState') as string; let globalDialogModel: GlobalDialogModel = new GlobalDialogModel(); -@Entry +@Entry({ useSharedStorage: true }) @Component struct globalSwitch { - private context = getContext(this) as common.ServiceExtensionContext; - @State viewState: GlobalDialogViewState = globalDialogModel.initViewState(globalState); + private context = this.getUIContext().getHostContext() as common.ServiceExtensionContext; + @LocalStorageLink('globalState') globalState: string = ''; + @State viewState: GlobalDialogViewState = globalDialogModel.initViewState(this.globalState); dialogController: CustomDialogController | null = new CustomDialogController({ builder: CustomContentDialog({ @@ -47,7 +46,7 @@ struct globalSwitch { value: $r('app.string.open'), buttonStyle: ButtonStyleMode.TEXTUAL, action: () => { - globalDialogModel.setMuteState(this.context, globalState, false, true); + globalDialogModel.setMuteState(this.context, this.globalState, false, true); } } ], diff --git a/permissionmanager/src/main/ets/pages/other-permissions.ets b/permissionmanager/src/main/ets/pages/other-permissions.ets deleted file mode 100644 index 32355444ad84f1a5942ec69df4ecefbd9eb62aec..0000000000000000000000000000000000000000 --- a/permissionmanager/src/main/ets/pages/other-permissions.ets +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright (c) 2021-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 { backBar } from '../common/components/backBar'; -import router from '@ohos.router'; -import Constants from '../common/utils/constant'; -import { permissionInfos } from '../common/model/permissionGroup'; -import { Log, verifyAccessToken } from '../common/utils/utils'; -import { OtherPermission, RouterParams3 } from '../common/model/typedef'; -import { Permission } from '../common/model/definition'; -import { BusinessError } from '@kit.BasicServicesKit'; - -let status: number = (router.getParams() as RouterParams3).status; // Status: Allowed, Forbidden -let permissions: Permission[] = (router.getParams() as RouterParams3).permission; // permissions name -let otherPermissionList: OtherPermission[] = []; // otherPermission List -for (let i = 0; i < permissions.length; i++) { - let permissionInfo = permissionInfos.get(permissions[i]); - if (!permissionInfo) { - continue; - } - otherPermissionList.push( - new OtherPermission(permissionInfo.label, permissions[i]) - ); -} - -@Entry -@Component -struct appNamePage { - private backTitle: ResourceStr = (router.getParams() as RouterParams3).backTitle; - private tokenId: number = (router.getParams() as RouterParams3).tokenId; - - build() { - GridRow({ gutter: Constants.GUTTER, columns: { - xs: Constants.XS_COLUMNS, sm: Constants.SM_COLUMNS, md: Constants.MD_COLUMNS, lg: Constants.LG_COLUMNS } }) { - GridCol({ - span: { xs: Constants.XS_SPAN, sm: Constants.SM_SPAN, md: Constants.MD_SPAN, lg: Constants.LG_SPAN }, - offset: { xs: Constants.XS_OFFSET, sm: Constants.SM_OFFSET, md: Constants.MD_OFFSET, lg: Constants.LG_OFFSET } - }) { - Row() { - Column() { - Row() { - backBar({ title: JSON.stringify(this.backTitle), recordable: false }) - } - Row() { - Column() { - Scroll() { - appNameItem() - } - } - }.layoutWeight(Constants.LAYOUT_WEIGHT) - } - } - .height(Constants.FULL_HEIGHT) - .width(Constants.FULL_WIDTH) - .backgroundColor($r('sys.color.background_secondary')) - } - }.backgroundColor($r('sys.color.background_secondary')) - } - -/** - * Lifecycle function, triggered once when this page is displayed - */ - onPageShow() { - permissions.forEach(permission => { - verifyAccessToken(this.tokenId, permission).then((data): void => { - status = data; - }).catch((err: BusinessError) => { - Log.error(`verifyAccessToken failed: ${JSON.stringify(err)}`) - }); - }) - } -} - -@Component -struct appNameItem { - private bundleName: string = (router.getParams() as RouterParams3).bundleName; - private tokenId: number = (router.getParams() as RouterParams3).tokenId; - @State otherPermissionListItem: OtherPermission[] = otherPermissionList; // Other permission interface data array - @State isTouch: string = ''; - - @Builder ListItemLayout(item: OtherPermission) { - ListItem() { - Row() { - Column() { - Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { - Row() { - Text(item.permissionLabel) - .fontSize(Constants.TEXT_MIDDLE_FONT_SIZE) - .fontColor($r('sys.color.font_primary')) - .flexGrow(Constants.FLEX_GROW) - SymbolGlyph($r('sys.symbol.chevron_forward')) - .width(Constants.IMAGE_WIDTH) - .height(Constants.IMAGE_HEIGHT) - .fontSize(Constants.FONT_SIZE_18_vp) - .fontColor([$r('sys.color.icon_tertiary')]) - .fontWeight(FontWeight.Medium) - } - .width(Constants.FULL_WIDTH) - .height(Constants.LISTITEM_ROW_HEIGHT) - } - }.onClick(() => { - router.pushUrl({ - url: 'pages/application-tertiary', - params: { - bundleName: this.bundleName, - backTitle: item.permissionLabel, - permission: [item.permission], - status, - tokenId: this.tokenId - } - }); - }) - } - }.padding({ left: $r('sys.float.ohos_id_card_margin_start'), right: $r('sys.float.ohos_id_card_margin_end') }) - .borderRadius($r('sys.float.ohos_id_corner_radius_default_l')) - .linearGradient((this.isTouch === item.permission) ? { - angle: 90, - direction: GradientDirection.Right, - colors: [['#DCEAF9', 0.0], ['#FAFAFA', 1.0]] - } : { - angle: 90, - direction: GradientDirection.Right, - colors: [[$r('sys.color.comp_background_list_card'), 1], [$r('sys.color.comp_background_list_card'), 1]] - }) - .onTouch(event => { - if (event === undefined) { - return; - } - if (event.type === TouchType.Down) { - this.isTouch = item.permission; - } - if (event.type === TouchType.Up) { - this.isTouch = ''; - } - }) - } - - build() { - Row() { - Column() { - Row() { - List() { - ForEach(this.otherPermissionListItem, (item: OtherPermission) => { - this.ListItemLayout(item) - }, (item: OtherPermission) => JSON.stringify(item)) - }.backgroundColor($r('sys.color.comp_background_list_card')) - .borderRadius($r('sys.float.ohos_id_corner_radius_card')) - .padding(Constants.LIST_PADDING_TOP) - .divider({ - strokeWidth: Constants.DIVIDER, - color: $r('sys.color.comp_divider'), - startMargin: Constants.DEFAULT_MARGIN_START, - endMargin: Constants.DEFAULT_MARGIN_END - }) - }.margin({ top: Constants.ROW_MARGIN_TOP }) - .padding({ left: Constants.LIST_PADDING_LEFT, right: Constants.LISTITEM_PADDING_RIGHT }) - } - .width(Constants.FULL_WIDTH) - .height(Constants.FULL_HEIGHT) - } - } -} diff --git a/permissionmanager/src/main/ets/pages/permission-access-record.ets b/permissionmanager/src/main/ets/pages/permission-access-record.ets index 69ba3c2abea81e768ffcb84471159c1e7a6a63cb..6e7a04b2f7e47ac9eaafb8ff9939feb308949e3e 100644 --- a/permissionmanager/src/main/ets/pages/permission-access-record.ets +++ b/permissionmanager/src/main/ets/pages/permission-access-record.ets @@ -14,7 +14,6 @@ */ import bundleManager from '@ohos.bundle.bundleManager'; -import router from '@ohos.router'; import common from '@ohos.app.ability.common'; import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; import privacyManager from '@ohos.privacyManager'; @@ -42,7 +41,7 @@ import { Permission } from '../common/model/definition'; @Entry @Component struct permissionRecordPage { - private context = getContext(this) as common.UIAbilityContext; + private context = this.getUIContext().getHostContext() as common.UIAbilityContext; @State isVertical: boolean = GlobalContext.load('isVertical'); @State allBundleInfo: AppInfo[] = GlobalContext.load('allBundleInfo'); @State groups: GroupRecordInfo[] = []; @@ -179,7 +178,7 @@ struct permissionRecordPage { permissionApplication.groupIds ) GlobalContext.store('applicationInfo', info); - router.pushUrl({ url: 'pages/application-secondary' }); + this.getUIContext().getRouter().pushUrl({ url: 'pages/application-secondary' }); }) .padding({ left: $r('sys.float.ohos_id_card_margin_start'), @@ -308,7 +307,7 @@ struct permissionRecordPage { item.groupIds ); GlobalContext.store('applicationInfo', info); - router.pushUrl({ url: 'pages/application-secondary' }); + this.getUIContext().getRouter().pushUrl({ url: 'pages/application-secondary' }); }) .padding({ left: $r('sys.float.ohos_id_card_margin_start'), diff --git a/permissionmanager/src/main/ets/pages/securityDialog.ets b/permissionmanager/src/main/ets/pages/securityDialog.ets index 61abd38fa7c5b51e2745e1d63735344ac3099f90..c687806cb52dbabfbe8d7f51a8a4b1cad1d6e75a 100644 --- a/permissionmanager/src/main/ets/pages/securityDialog.ets +++ b/permissionmanager/src/main/ets/pages/securityDialog.ets @@ -25,7 +25,6 @@ import { GlobalContext } from '../common/utils/globalContext'; import bundleResourceManager from '@ohos.bundle.bundleResourceManager'; import deviceInfo from '@ohos.deviceInfo'; -let storage = LocalStorage.getShared(); const RESOURCE_TYPE: number = 10003; @Extend(Text) @@ -212,10 +211,10 @@ struct CustomDialogWearable { } } -@Entry(storage) +@Entry({ useSharedStorage: true }) @Component struct SecurityDialog { - private context = getContext(this) as common.ServiceExtensionContext; + private context = this.getUIContext().getHostContext() as common.ServiceExtensionContext; @LocalStorageLink('want') want: WantInfo = new WantInfo([]); @LocalStorageLink('win') win: window.Window = {} as window.Window; @State appName: ResourceStr = 'Application'; diff --git a/permissionmanager/src/main/resources/base/profile/main_pages.json b/permissionmanager/src/main/resources/base/profile/main_pages.json index bdcffc5e3ba92173dea23f74e474465dc0462093..2de3e8934d7c0ac42fd57c1424d14daa0cb43d13 100644 --- a/permissionmanager/src/main/resources/base/profile/main_pages.json +++ b/permissionmanager/src/main/resources/base/profile/main_pages.json @@ -5,7 +5,6 @@ "pages/authority-secondary", "pages/authority-tertiary", "pages/application-tertiary", - "pages/other-permissions", "pages/authority-tertiary-groups", "pages/permission-access-record", "pages/dialogPlus",