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 .draggable(false) 100 } 101 .width(Constants.FULL_WIDTH) 102 .height(Constants.LISTITEM_ROW_HEIGHT) 103 } 104 }.onClick(() => { 105 router.pushUrl({ 106 url: 'pages/application-tertiary', 107 params: { 108 bundleName: this.bundleName, 109 backTitle: item.permissionLabel, 110 permission: [item.permission], 111 status, 112 tokenId: this.tokenId 113 } 114 }); 115 }) 116 } 117 }.padding({ left: $r('sys.float.ohos_id_card_margin_start'), right: $r('sys.float.ohos_id_card_margin_end') }) 118 .borderRadius($r("sys.float.ohos_id_corner_radius_default_l")) 119 .linearGradient((this.isTouch === item.permission) ? { 120 angle: 90, 121 direction: GradientDirection.Right, 122 colors: [['#DCEAF9', 0.0], ['#FAFAFA', 1.0]] 123 } : { 124 angle: 90, 125 direction: GradientDirection.Right, 126 colors: [[$r("sys.color.ohos_id_color_list_card_bg"), 1], [$r("sys.color.ohos_id_color_list_card_bg"), 1]] 127 }) 128 .onTouch(event => { 129 if (event === undefined) { 130 return; 131 } 132 if (event.type === TouchType.Down) { 133 this.isTouch = item.permission; 134 } 135 if (event.type === TouchType.Up) { 136 this.isTouch = ''; 137 } 138 }) 139 } 140 141 build() { 142 Row() { 143 Column() { 144 Row() { 145 List() { 146 ForEach(this.otherPermissionListItem, (item: otherPermission) => { 147 this.ListItemLayout(item) 148 }, (item: otherPermission) => JSON.stringify(item)) 149 }.backgroundColor($r('sys.color.ohos_id_color_list_card_bg')) 150 .borderRadius($r('sys.float.ohos_id_corner_radius_card')) 151 .padding(Constants.LIST_PADDING_TOP) 152 .divider({ 153 strokeWidth: Constants.DIVIDER, 154 color: $r('sys.color.ohos_id_color_list_separator'), 155 startMargin: Constants.DEFAULT_MARGIN_START, 156 endMargin: Constants.DEFAULT_MARGIN_END 157 }) 158 }.margin({ top: Constants.ROW_MARGIN_TOP }) 159 .padding({ left: Constants.LIST_PADDING_LEFT, right: Constants.LISTITEM_PADDING_RIGHT }) 160 } 161 .width(Constants.FULL_WIDTH) 162 .height(Constants.FULL_HEIGHT) 163 } 164 } 165} 166