1/* 2 * Copyright (c) 2021-2023 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 { verifyAccessToken } from "../common/utils/utils"; 21import { otherPermission, routerParams_3 } from '../common/utils/typedef'; 22import { Permissions } from '@ohos.abilityAccessCtrl'; 23 24const TAG = 'PermissionManager_MainAbility:'; 25let status: number = (router.getParams() as routerParams_3).status; // Status: Allowed, Forbidden 26let permissions: Permissions[] = (router.getParams() as routerParams_3).permission; // permissions name 27let otherPermissionList: otherPermission[] = []; // otherPermission List 28for (let i = 0; i < permissions.length; i++) { 29 otherPermissionList.push(new otherPermission(permissionGroups.filter(item => item.permissionName == permissions[i])[0].label, permissions[i])); 30} 31 32@Entry 33@Component 34struct appNamePage { 35 private backTitle: ResourceStr = (router.getParams() as routerParams_3).backTitle; 36 private tokenId: number = (router.getParams() as routerParams_3).tokenId; 37 38 build() { 39 GridRow({ gutter: Constants.GUTTER, columns: { 40 xs: Constants.XS_COLUMNS, sm: Constants.SM_COLUMNS, md: Constants.MD_COLUMNS, lg: Constants.LG_COLUMNS } }) { 41 GridCol({ span: { xs: Constants.XS_SPAN, sm: Constants.SM_SPAN, md: Constants.MD_SPAN, lg: Constants.LG_SPAN }, 42 offset: { xs: Constants.XS_OFFSET, sm: Constants.SM_OFFSET, md: Constants.MD_OFFSET, lg: Constants.LG_OFFSET } }) { 43 Row() { 44 Column() { 45 Row() { 46 backBar({ title: JSON.stringify(this.backTitle), recordable: false }) 47 } 48 Row() { 49 Column() { 50 Scroll() { 51 appNameItem() 52 } 53 } 54 }.layoutWeight(Constants.LAYOUT_WEIGHT) 55 } 56 } 57 .height(Constants.FULL_HEIGHT) 58 .width(Constants.FULL_WIDTH) 59 .backgroundColor($r("sys.color.ohos_id_color_sub_background")) 60 } 61 }.backgroundColor($r("sys.color.ohos_id_color_sub_background")) 62 } 63 64/** 65 * Lifecycle function, triggered once when this page is displayed 66 */ 67 onPageShow() { 68 console.log(TAG + 'onPageShow other-permissions'); 69 permissions.forEach(permission => { 70 verifyAccessToken(this.tokenId, permission).then((data): void => { 71 status = data; 72 }); 73 }) 74 } 75} 76 77@Component 78struct appNameItem { 79 private bundleName: string = (router.getParams() as routerParams_3).bundleName; 80 private tokenId: number = (router.getParams() as routerParams_3).tokenId; 81 @State otherPermissionListItem: otherPermission[] = otherPermissionList; // Other permission interface data array 82 @State isTouch: string = ''; 83 84 @Builder ListItemLayout(item: otherPermission) { 85 ListItem() { 86 Row() { 87 Column() { 88 Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { 89 Row() { 90 Text(item.permissionLabel) 91 .fontSize(Constants.TEXT_MIDDLE_FONT_SIZE) 92 .fontColor($r('sys.color.ohos_id_color_text_primary')) 93 .flexGrow(Constants.FLEX_GROW) 94 Image($r('app.media.ic_public_arrow_right')) 95 .fillColor($r('sys.color.ohos_id_color_tertiary')) 96 .objectFit(ImageFit.Contain) 97 .height(Constants.IMAGE_HEIGHT) 98 .width(Constants.IMAGE_WIDTH) 99 } 100 .width(Constants.FULL_WIDTH) 101 .height(Constants.LISTITEM_ROW_HEIGHT) 102 } 103 }.onClick(() => { 104 router.pushUrl({ 105 url: 'pages/application-tertiary', 106 params: { 107 bundleName: this.bundleName, 108 backTitle: item.permissionLabel, 109 permission: [item.permission], 110 status, 111 tokenId: this.tokenId 112 } 113 }); 114 }) 115 } 116 }.padding({ left: $r('sys.float.ohos_id_card_margin_start'), right: $r('sys.float.ohos_id_card_margin_end') }) 117 .borderRadius($r("sys.float.ohos_id_corner_radius_default_l")) 118 .linearGradient((this.isTouch === item.permission) ? { 119 angle: 90, 120 direction: GradientDirection.Right, 121 colors: [['#DCEAF9', 0.0], ['#FAFAFA', 1.0]] 122 } : { 123 angle: 90, 124 direction: GradientDirection.Right, 125 colors: [[$r("sys.color.ohos_id_color_list_card_bg"), 1], [$r("sys.color.ohos_id_color_list_card_bg"), 1]] 126 }) 127 .onTouch(event => { 128 if (event === undefined) { 129 return; 130 } 131 if (event.type === TouchType.Down) { 132 this.isTouch = item.permission; 133 } 134 if (event.type === TouchType.Up) { 135 this.isTouch = ''; 136 } 137 }) 138 } 139 140 build() { 141 Row() { 142 Column() { 143 Row() { 144 List() { 145 ForEach(this.otherPermissionListItem, (item: otherPermission) => { 146 this.ListItemLayout(item) 147 }, (item: otherPermission) => JSON.stringify(item)) 148 }.backgroundColor($r('sys.color.ohos_id_color_list_card_bg')) 149 .borderRadius($r('sys.float.ohos_id_corner_radius_card')) 150 .padding(Constants.LIST_PADDING_TOP) 151 .divider({ 152 strokeWidth: Constants.DIVIDER, 153 color: $r('sys.color.ohos_id_color_list_separator'), 154 startMargin: Constants.DEFAULT_MARGIN_START, 155 endMargin: Constants.DEFAULT_MARGIN_END 156 }) 157 }.margin({ top: Constants.ROW_MARGIN_TOP }) 158 .padding({ left: Constants.LIST_PADDING_LEFT, right: Constants.LISTITEM_PADDING_RIGHT }) 159 } 160 .width(Constants.FULL_WIDTH) 161 .height(Constants.FULL_HEIGHT) 162 } 163 } 164} 165