1/* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { backBar } from "../common/components/backBar"; 17import router from '@ohos.router'; 18import Constants from '../common/utils/constant'; 19import { permissionGroups } from '../common/model/permissionGroup' 20import abilityAccessCtrl from '@ohos.abilityAccessCtrl' 21 22var TAG = 'PermissionManager_MainAbility:' 23 24let routerData = router.getParams()['routerData']; // Routing jump data 25let tokenId: any = router.getParams()['tokenId']; // tokenId for verify permission 26let backTitle = router.getParams()['backTitle']; // return title name 27let status = router.getParams()['status']; // Status: Allowed, Forbidden 28let permissions: any = router.getParams()['permission']; // permissions name 29let otherPermissionList = []; // otherPermission List 30for (let i = 0; i < permissions.length; i++) { 31 otherPermissionList.push({ 32 permissionLabel: permissionGroups.filter(item => item.permissionName == permissions[i])[0].label, 33 permission: permissions[i] 34 }) 35} 36 37@Entry 38@Component 39struct appNamePage { 40 build() { 41 GridContainer({ gutter: Constants.GUTTER, margin: Constants.GRID_MARGIN }) { 42 Row() { 43 Row() 44 .useSizeType({ 45 xs: { span: Constants.LEFT_XS_SPAN, offset: Constants.LEFT_XS_OFFSET }, 46 sm: { span: Constants.LEFT_SM_SPAN, offset: Constants.LEFT_SM_OFFSET }, 47 md: { span: Constants.LEFT_MD_SPAN, offset: Constants.LEFT_MD_OFFSET }, 48 lg: { span: Constants.LEFT_LG_SPAN, offset: Constants.LEFT_LG_OFFSET } 49 }) 50 .height(Constants.FULL_HEIGHT) 51 Row() { 52 Column() { 53 Row() { 54 backBar({ title: JSON.stringify(backTitle), recordable: false }) 55 } 56 Row() { 57 Column() { 58 Scroll() { 59 appNameItem() 60 } 61 } 62 }.layoutWeight(Constants.LAYOUT_WEIGHT) 63 } 64 } 65 .useSizeType({ 66 xs: { span: Constants.MIDDLE_XS_SPAN, offset: Constants.MIDDLE_XS_OFFSET }, 67 sm: { span: Constants.MIDDLE_SM_SPAN, offset: Constants.MIDDLE_SM_OFFSET }, 68 md: { span: Constants.MIDDLE_MD_SPAN, offset: Constants.MIDDLE_MD_OFFSET }, 69 lg: { span: Constants.MIDDLE_LG_SPAN, offset: Constants.MIDDLE_LG_OFFSET } 70 }) 71 .height(Constants.FULL_HEIGHT) 72 Row() 73 .useSizeType({ 74 xs: { span: Constants.RIGHT_XS_SPAN, offset: Constants.RIGHT_XS_OFFSET }, 75 sm: { span: Constants.RIGHT_SM_SPAN, offset: Constants.RIGHT_SM_OFFSET }, 76 md: { span: Constants.RIGHT_MD_SPAN, offset: Constants.RIGHT_MD_OFFSET }, 77 lg: { span: Constants.RIGHT_LG_SPAN, offset: Constants.RIGHT_LG_OFFSET } 78 }) 79 .height(Constants.FULL_HEIGHT) 80 } 81 .height(Constants.FULL_HEIGHT) 82 .width(Constants.FULL_WIDTH) 83 .backgroundColor($r("sys.color.ohos_id_color_sub_background")) 84 } 85 } 86 87/** 88 * Lifecycle function, triggered once when this page is displayed 89 */ 90 onPageShow() { 91 console.log(TAG + 'onPageShow other-permissions') 92 permissions.forEach(permission => { 93 abilityAccessCtrl.createAtManager().verifyAccessToken(tokenId, permission).then(res => { 94 status = res; 95 }) 96 .catch(err => { 97 console.error(TAG + 'verifyAccessToken occure error: ' + JSON.stringify(err)) 98 }) 99 }) 100 } 101} 102 103@Component 104struct appNameItem { 105 @State otherPermissionListItem: string[] = otherPermissionList; // Other permission interface data array 106 @Builder ListItemLayout(item, index) { 107 ListItem() { 108 Row() { 109 Column() { 110 Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { 111 Row() { 112 Text(item.permissionLabel) 113 .fontSize(Constants.TEXT_MIDDLE_FONT_SIZE) 114 .fontColor($r('app.color.text_color')) 115 .flexGrow(Constants.FLEX_GROW) 116 Image($r('app.media.ic_public_arrow_right')) 117 .objectFit(ImageFit.Contain) 118 .height(Constants.IMAGE_HEIGHT) 119 .width(Constants.IMAGE_WIDTH) 120 } 121 .width(Constants.FULL_WIDTH) 122 .height(Constants.LISTITEM_ROW_HEIGHT) 123 } 124 if (!index) { 125 Row() { 126 Column() 127 .backgroundColor($r('app.color.text_decoration_color')) 128 .width(Constants.FULL_WIDTH) 129 .height(Constants.TEXT_DECORATION_HEIGHT) 130 } 131 } 132 }.onClick(() => { 133 router.pushUrl({ 134 url: 'pages/application-tertiary', 135 params: { 136 routerData: routerData, 137 backTitle: item.permissionLabel, 138 permission: [item.permission], 139 status: status 140 } 141 }); 142 }) 143 } 144 }.padding({ left: Constants.DEFAULT_PADDING_START, right: Constants.DEFAULT_PADDING_END }) 145 } 146 147 build() { 148 Row() { 149 Column() { 150 Row() { 151 List() { 152 ForEach(this.otherPermissionListItem.slice(Constants.SLICE_START, this.otherPermissionListItem.length - 1), 153 (item) => { 154 this.ListItemLayout(item, Constants.SLICE_START_INDEX) 155 }, item => item.toString()) 156 ForEach(this.otherPermissionListItem.slice(Constants.SLICE_END), (item) => { 157 this.ListItemLayout(item, Constants.SLICE_END_INDEX) 158 }, item => item.toString()) 159 }.backgroundColor($r('app.color.default_background_color')).borderRadius(Constants.BORDER_RADIUS) 160 .padding({ top: Constants.LIST_PADDING_TOP, bottom: Constants.LIST_PADDING_BOTTOM }) 161 }.margin({ top: Constants.ROW_MARGIN_TOP }) 162 .padding({ left: Constants.LIST_PADDING_LEFT, right: Constants.LISTITEM_PADDING_RIGHT }) 163 } 164 .width(Constants.FULL_WIDTH) 165 .height(Constants.FULL_HEIGHT) 166 } 167 } 168} 169