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