• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022-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 bundleManager from '@ohos.bundle.bundleManager';
17import router from '@ohos.router';
18import common from '@ohos.app.ability.common';
19import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl';
20import privacyManager from '@ohos.privacyManager';
21import { backBar } from "../common/components/backBar";
22import Constants from '../common/utils/constant';
23import { userGrantPermissions } from "../common/model/permissionGroup";
24import { getPermissionGroup, getGroupIdByPermission } from '../common/utils/utils';
25import { StringObj, appInfoSimple, appRecordInfo, appInfo, GroupRecordInfo, appGroupRecordInfo } from '../common/utils/typedef';
26import { GlobalContext } from "../common/utils/globalContext";
27
28const TAG = 'PermissionManager_MainAbility:';
29
30@Extend(Image) function customizeImage(width: number, height: number) {
31  .objectFit(ImageFit.Contain)
32  .width(width)
33  .height(height)
34};
35
36@Entry
37@Component
38struct permissionRecordPage {
39  private context = getContext(this) as common.UIAbilityContext;
40  @State isVertical: boolean = GlobalContext.load('isVertical');
41  @State allBundleInfo: appInfo[] = GlobalContext.load('allBundleInfo');
42  @State groups: GroupRecordInfo[] = [];
43  @State applicationInfos: appRecordInfo[] = [];
44  @State permissionApplications: appRecordInfo[] = [];
45  @State permissionIndex: number = -1;
46  @State applicationIndex: number = -1;
47  @State strings: StringObj = new StringObj('', '');
48  @State currentIndex: number = 0;
49  @State show: boolean = false;
50  @State isTouch: string = '';
51  @Builder TabBuilder(index: number) {
52    Flex({ alignItems: index ? ItemAlign.Start : ItemAlign.End, justifyContent: FlexAlign.Center, direction: FlexDirection.Column }) {
53      Text(index ? $r('app.string.application') : $r('app.string.permission'))
54        .fontSize(Constants.TEXT_MIDDLE_FONT_SIZE)
55        .fontColor(this.currentIndex == index ? $r('sys.color.ohos_id_color_subtab_text_on') : $r('sys.color.ohos_id_color_secondary'))
56        .fontWeight(this.currentIndex == index ? FontWeight.Bold : FontWeight.Regular)
57        .lineHeight(Constants.TEXT_LINE_HEIGHT)
58        .baselineOffset(Constants.TAB_DECORATION_POSITION_Y)
59      if (this.currentIndex == index) {
60        Text(index ? $r('app.string.application') : $r('app.string.permission'))
61          .fontSize(Constants.TEXT_MIDDLE_FONT_SIZE)
62          .fontWeight(FontWeight.Bold)
63          .lineHeight(Constants.TAB_LINE_HEIGHT)
64          .height(Constants.TAB_DECORATION_HEIGHT)
65          .backgroundColor($r('sys.color.ohos_id_color_subtab_line_on'))
66      }
67    }.height(Constants.TAB_HEIGHT)
68    .width(Constants.FULL_WIDTH)
69    .padding({ left: this.isVertical ? Constants.TAB_INNER_PADDING : Constants.DEFAULT_PADDING_START,
70      right: this.isVertical ? Constants.TAB_INNER_PADDING : Constants.DEFAULT_PADDING_END })
71  }
72
73  @Builder PermissionListItemLayout(item: GroupRecordInfo, index: number) {
74    ListItem() {
75      Column() {
76        Column() {
77          Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) {
78            Row() {
79              Image(item.icon)
80                .fillColor($r('sys.color.ohos_id_color_secondary'))
81                .customizeImage(Constants.MANAGEMENT_IMAGE_WIDTH, Constants.MANAGEMENT_IMAGE_HEIGHT)
82                .margin({ right: Constants.MANAGEMENT_IMAGE_MARGIN_RIGHT_RECORD, left: Constants.MANAGEMENT_IMAGE_MARGIN_LEFT })
83              Column() {
84                Text(item.groupName)
85                  .width(Constants.MAXIMUM_HEADER_WIDTH)
86                  .maxLines(Constants.MAXIMUM_HEADER_LINES)
87                  .textOverflow({ overflow: TextOverflow.Ellipsis })
88                  .fontSize(Constants.TEXT_MIDDLE_FONT_SIZE)
89                  .fontWeight(FontWeight.Medium)
90                  .fontColor($r('sys.color.ohos_id_color_text_primary'))
91                  .lineHeight(Constants.TEXT_LINE_HEIGHT)
92                  .margin({ bottom: Constants.TERTIARY_LABEL_MARGIN_BOTTOM })
93                Text() {
94                  Span($r("app.string.visits"))
95                  Span(String(item.sum))
96                }
97                  .fontSize(Constants.TEXT_SMALL_FONT_SIZE)
98                  .fontColor($r('sys.color.ohos_id_color_text_secondary'))
99                  .lineHeight(Constants.TEXT_SMALL_LINE_HEIGHT)
100              }.flexGrow(Constants.FLEX_GROW)
101              .alignItems(HorizontalAlign.Start)
102              Image(index == this.permissionIndex ? $r('app.media.xiangshangjiantou') : $r('app.media.xiangxiajiantou'))
103                .fillColor($r('sys.color.ohos_id_color_secondary'))
104                .customizeImage(Constants.IMAGE_WIDTH_RECORD, Constants.IMAGE_HEIGHT_RECORD)
105            }
106            .width(Constants.FULL_WIDTH)
107            .height(Constants.LISTITEM_HEIGHT_PERMISSION)
108          }
109        }.onClick(() => {
110          this.permissionIndex = this.permissionIndex == index ? -1 : index
111          this.permissionApplications = this.applicationInfos.filter((appInfo) => {
112            return appInfo.groupNames.includes(item.groupName);
113          })
114        })
115        .padding({ left: $r('sys.float.ohos_id_card_margin_start'), right: $r('sys.float.ohos_id_card_margin_end') })
116        if (index == this.permissionIndex) {
117          List() {
118            ForEach(this.permissionApplications, (permissionApplication: appRecordInfo) => {
119              ListItem() {
120                Row() {
121                  Image(permissionApplication.icon)
122                    .customizeImage(Constants.APPLICATION_IMAGE_WIDTH, Constants.APPLICATION_IMAGE_HEIGHT)
123                    .margin({ right: Constants.MANAGEMENT_IMAGE_MARGIN_RIGHT })
124                  Column() {
125                    Row().width(Constants.FULL_WIDTH).height(Constants.DIVIDER)
126                      .backgroundColor($r("sys.color.ohos_id_color_list_separator"))
127                      .position({ x: 0, y: 0 })
128                    Text(permissionApplication.groupName)
129                      .width(Constants.MAXIMUM_HEADER_WIDTH)
130                      .maxLines(Constants.MAXIMUM_HEADER_LINES)
131                      .textOverflow({ overflow: TextOverflow.Ellipsis })
132                      .fontSize(Constants.TEXT_MIDDLE_FONT_SIZE)
133                      .fontWeight(FontWeight.Medium)
134                      .fontColor($r('sys.color.ohos_id_color_text_primary'))
135                      .lineHeight(Constants.TEXT_LINE_HEIGHT)
136                      .margin({ bottom: Constants.TERTIARY_LABEL_MARGIN_BOTTOM })
137                    Text() {
138                      Span($r("app.string.visits"))
139                      Span(String(this.getAppRecords(permissionApplication, item.groupName, true)))
140                      Span($r("app.string.recent_visit"))
141                      Span(this.getTime(this.getAppRecords(permissionApplication, item.groupName, false)))
142                    }
143                      .padding({ right: Constants.LISTITEM_PADDING_RIGHT_RECORD })
144                      .fontSize(Constants.TEXT_SMALL_FONT_SIZE)
145                      .fontColor($r('sys.color.ohos_id_color_text_secondary'))
146                      .lineHeight(Constants.TEXT_SMALL_LINE_HEIGHT)
147                  }.alignItems(HorizontalAlign.Start)
148                  .height(Constants.FULL_HEIGHT)
149                  .width(Constants.FULL_WIDTH)
150                  .justifyContent(FlexAlign.Center)
151                }
152              }.height(Constants.LISTITEM_HEIGHT_APPLICATION)
153              .onClick(() => {
154                let info: appInfoSimple = new appInfoSimple(
155                  permissionApplication.name,
156                  permissionApplication.api,
157                  permissionApplication.accessTokenId,
158                  permissionApplication.icon,
159                  permissionApplication.groupName,
160                  permissionApplication.reqUserPermissions,
161                  permissionApplication.groupIds
162                )
163                GlobalContext.store('applicationInfo', info);
164                router.pushUrl({ url: 'pages/application-secondary' });
165              })
166              .padding({ left: $r('sys.float.ohos_id_card_margin_start'), right: $r('sys.float.ohos_id_card_margin_end') })
167              .borderRadius($r("sys.float.ohos_id_corner_radius_default_l"))
168              .linearGradient((this.isTouch === permissionApplication.name) ? {
169                  angle: 90,
170                  direction: GradientDirection.Right,
171                  colors: [['#DCEAF9', 0.0], ['#FAFAFA', 1.0]]
172                } : {
173                  angle: 90,
174                  direction: GradientDirection.Right,
175                  colors: [[$r("sys.color.ohos_id_color_list_card_bg"), 1], [$r("sys.color.ohos_id_color_list_card_bg"), 1]]
176                })
177              .onTouch(event => {
178                if (event === undefined) {
179                  return;
180                }
181                if (event.type === TouchType.Down) {
182                  this.isTouch = permissionApplication.name;
183                }
184                if (event.type === TouchType.Up) {
185                  this.isTouch = '';
186                }
187              })
188            }, (item: appRecordInfo) => JSON.stringify(item))
189          }
190        }
191      }
192    }.padding(Constants.LIST_PADDING_TOP)
193    .margin({ bottom: Constants.LISTITEM_MARGIN_BOTTOM })
194    .backgroundColor($r('sys.color.ohos_id_color_list_card_bg'))
195    .borderRadius($r('sys.float.ohos_id_corner_radius_card'))
196  }
197
198  @Builder ApplicationListItemLayout(item: appRecordInfo, index: number) {
199    ListItem() {
200      Column() {
201        Column() {
202          Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) {
203            Row() {
204              Image(item.icon)
205                .customizeImage(Constants.APPLICATION_IMAGE_WIDTH, Constants.APPLICATION_IMAGE_HEIGHT)
206                .margin({ right: Constants.MANAGEMENT_IMAGE_MARGIN_RIGHT })
207              Column() {
208                Text(item.groupName)
209                  .width(Constants.MAXIMUM_HEADER_WIDTH)
210                  .maxLines(Constants.MAXIMUM_HEADER_LINES)
211                  .textOverflow({ overflow: TextOverflow.Ellipsis })
212                  .fontSize(Constants.TEXT_MIDDLE_FONT_SIZE)
213                  .fontWeight(FontWeight.Medium)
214                  .fontColor($r('sys.color.ohos_id_color_text_primary'))
215                  .lineHeight(Constants.TEXT_LINE_HEIGHT)
216                  .margin({ bottom: Constants.TERTIARY_LABEL_MARGIN_BOTTOM })
217                Row() {
218                  ForEach(item.permissions, (permission: appGroupRecordInfo) => {
219                    Image(permission.icon)
220                      .fillColor($r('sys.color.ohos_id_color_secondary'))
221                      .customizeImage(Constants.IMAGE_WIDTH_RECORD_APPLICATION, Constants.IMAGE_HEIGHT_RECORD_APPLICATION)
222                      .margin({ right: Constants.APPLICATION_TEXT_MARGIN_RIGHT })
223                  }, (item: appGroupRecordInfo) => JSON.stringify(item))
224                }
225              }.flexGrow(Constants.FLEX_GROW)
226              .alignItems(HorizontalAlign.Start)
227              Image(index == this.applicationIndex ? $r('app.media.xiangshangjiantou') : $r('app.media.xiangxiajiantou'))
228                .fillColor($r('sys.color.ohos_id_color_secondary'))
229                .customizeImage(Constants.IMAGE_WIDTH_RECORD, Constants.IMAGE_HEIGHT_RECORD)
230            }
231            .width(Constants.FULL_WIDTH)
232            .height(Constants.LISTITEM_HEIGHT_APPLICATION)
233          }
234        }.onClick(() => {
235          this.applicationIndex = this.applicationIndex == index ? -1 : index
236        })
237        .padding({ left: $r('sys.float.ohos_id_card_margin_start'), right: $r('sys.float.ohos_id_card_margin_end') })
238        if (index == this.applicationIndex) {
239          List() {
240            ForEach(item.permissions, (permission: appGroupRecordInfo) => {
241              ListItem() {
242                Row() {
243                  Image(permission.icon)
244                    .fillColor($r('sys.color.ohos_id_color_secondary'))
245                    .customizeImage(Constants.MANAGEMENT_IMAGE_WIDTH, Constants.MANAGEMENT_IMAGE_HEIGHT)
246                    .margin({ right: Constants.MANAGEMENT_IMAGE_MARGIN_RIGHT_RECORD, left: Constants.MANAGEMENT_IMAGE_MARGIN_LEFT })
247                  Column() {
248                    Row().width(Constants.FULL_WIDTH).height(Constants.DIVIDER)
249                      .backgroundColor($r("sys.color.ohos_id_color_list_separator"))
250                      .position({ x: 0, y: 0 })
251                    Text(permission.groupName)
252                      .fontSize(Constants.TEXT_MIDDLE_FONT_SIZE)
253                      .fontWeight(FontWeight.Medium)
254                      .fontColor($r('sys.color.ohos_id_color_text_primary'))
255                      .lineHeight(Constants.TEXT_LINE_HEIGHT)
256                      .margin({ bottom: Constants.TERTIARY_LABEL_MARGIN_BOTTOM })
257                    Text() {
258                      Span($r("app.string.visits"))
259                      Span(String(permission.count))
260                      Span($r("app.string.recent_visit"))
261                      Span(this.getTime(permission.lastTime))
262                    }
263                    .padding({ right: Constants.LISTITEM_PADDING_RIGHT_RECORD })
264                    .fontSize(Constants.TEXT_SMALL_FONT_SIZE)
265                    .fontColor($r('sys.color.ohos_id_color_text_secondary'))
266                    .lineHeight(Constants.TEXT_SMALL_LINE_HEIGHT)
267                  }.alignItems(HorizontalAlign.Start)
268                  .height(Constants.FULL_HEIGHT)
269                  .width(Constants.FULL_WIDTH)
270                  .justifyContent(FlexAlign.Center)
271                }
272              }.height(Constants.LISTITEM_HEIGHT_PERMISSION)
273              .onClick(() => {
274                let info: appInfoSimple = new appInfoSimple(item.name, item.api, item.accessTokenId, item.icon, item.groupName, item.reqUserPermissions, item.groupIds);
275                GlobalContext.store('applicationInfo', info);
276                router.pushUrl({ url: 'pages/application-secondary' });
277              })
278              .padding({ left: $r('sys.float.ohos_id_card_margin_start'), right: $r('sys.float.ohos_id_card_margin_end') })
279              .borderRadius($r("sys.float.ohos_id_corner_radius_default_l"))
280              .linearGradient((this.isTouch === permission.name) ? {
281                   angle: 90,
282                   direction: GradientDirection.Right,
283                   colors: [['#DCEAF9', 0.0], ['#FAFAFA', 1.0]]
284                 } : {
285                   angle: 90,
286                   direction: GradientDirection.Right,
287                   colors: [[$r("sys.color.ohos_id_color_list_card_bg"), 1], [$r("sys.color.ohos_id_color_list_card_bg"), 1]]
288                 })
289              .onTouch(event => {
290                if (event === undefined) {
291                  return;
292                }
293                if (event.type === TouchType.Down) {
294                  this.isTouch = permission.name;
295                }
296                if (event.type === TouchType.Up) {
297                  this.isTouch = '';
298                }
299              })
300            }, (item: appGroupRecordInfo) => JSON.stringify(item))
301          }
302        }
303      }
304    }.padding(Constants.LIST_PADDING_TOP)
305    .margin({ bottom: Constants.LISTITEM_MARGIN_BOTTOM })
306    .backgroundColor($r('sys.color.ohos_id_color_list_card_bg'))
307    .borderRadius($r('sys.float.ohos_id_corner_radius_card'))
308  }
309
310  build() {
311    GridRow({ gutter: Constants.GUTTER, columns: {
312      xs: Constants.XS_COLUMNS, sm: Constants.SM_COLUMNS, md: Constants.MD_COLUMNS, lg: Constants.LG_COLUMNS } }) {
313      GridCol({ span: { xs: Constants.XS_SPAN, sm: Constants.SM_SPAN, md: Constants.MD_SPAN, lg: Constants.LG_SPAN },
314        offset: { xs: Constants.XS_OFFSET, sm: Constants.SM_OFFSET, md: Constants.MD_OFFSET, lg: Constants.LG_OFFSET } }) {
315        Row() {
316          Column() {
317            Row() {
318              backBar( { title: JSON.stringify($r('app.string.permission_access_record')), recordable: false })
319            }
320            Row() {
321              Column() {
322                Column() {
323                  Flex({ justifyContent: FlexAlign.Start }) {
324                    Text($r('app.string.record_time_limit'))
325                      .margin({ left: Constants.DEFAULT_MARGIN_START })
326                      .fontSize(Constants.TEXT_SMALL_FONT_SIZE)
327                      .fontColor($r('sys.color.ohos_id_color_text_secondary'))
328                      .lineHeight(Constants.SUBTITLE_LINE_HEIGHT)
329                  }.constraintSize({ minHeight: Constants.SUBTITLE_MIN_HEIGHT })
330                  .padding({ top: Constants.SUBTITLE_PADDING_TOP, bottom: Constants.SUBTITLE_PADDING_BOTTOM })
331                  if (this.groups.length) {
332                    Stack() {
333                      Tabs() {
334                        TabContent() {
335                          Row() {
336                            Column() {
337                              Scroll() {
338                                Row() {
339                                  List() {
340                                    ForEach(this.groups, (item: GroupRecordInfo, index) => {
341                                      this.PermissionListItemLayout(item, index as number)
342                                    }, (item: GroupRecordInfo) => JSON.stringify(item))
343                                  }.padding({ top: Constants.LIST_PADDING_TOP, bottom: Constants.LIST_PADDING_BOTTOM })
344                                  .height(Constants.FULL_HEIGHT)
345                                }.padding({
346                                  left: Constants.MANAGEMENT_ROW_PADDING_LEFT,
347                                  right: Constants.MANAGEMENT_ROW_PADDING_RIGHT,
348                                  top: Constants.MANAGEMENT_ROW_PADDING_TOP,
349                                  bottom: Constants.MANAGEMENT_ROW_PADDING_BOTTOM
350                                })
351                              }.scrollBar(BarState.Off)
352                            }.width(Constants.FULL_WIDTH)
353                          }
354                        }.tabBar(this.TabBuilder(0))
355                        TabContent() {
356                          Row() {
357                            Column() {
358                              Scroll() {
359                                Row() {
360                                  if (this.show) {
361                                    List() {
362                                      ForEach(this.applicationInfos, (item: appRecordInfo, index) => {
363                                        this.ApplicationListItemLayout(item, index as number)
364                                      }, (item: appRecordInfo) => JSON.stringify(item))
365                                    }.padding({ top: Constants.LIST_PADDING_TOP, bottom: Constants.LIST_PADDING_BOTTOM })
366                                    .height(Constants.FULL_HEIGHT)
367                                  }
368                                }.padding({
369                                  left: Constants.MANAGEMENT_ROW_PADDING_LEFT,
370                                  right: Constants.MANAGEMENT_ROW_PADDING_RIGHT,
371                                  top: Constants.MANAGEMENT_ROW_PADDING_TOP,
372                                  bottom: Constants.MANAGEMENT_ROW_PADDING_BOTTOM
373                                })
374                              }.scrollBar(BarState.Off)
375                            }.width(Constants.FULL_WIDTH)
376                          }
377                        }.tabBar(this.TabBuilder(1))
378                      }
379                      .barMode(BarMode.Fixed)
380                      .onChange((index) => {
381                        this.currentIndex = index;
382                        if (!this.show) this.show = true;
383                      })
384                    }.height(Constants.FULL_HEIGHT)
385                  } else {
386                    Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center, direction: FlexDirection.Column }) {
387                      Image($r('app.media.noRecord'))
388                        .customizeImage(Constants.NORECORD_IMAGE_WIDTH, Constants.NORECORD_IMAGE_HEIGHT)
389                        .margin({ left: Constants.NORECORD_IMAGE_MARGIN_LEFT })
390                      Text($r('app.string.no_record')).margin({ top: Constants.DIALOG_REQ_MARGIN_TOP })
391                        .fontSize(Constants.TEXT_SMALL_FONT_SIZE)
392                        .fontColor($r('sys.color.ohos_id_color_text_secondary'))
393                    }.width(Constants.FULL_WIDTH).height(Constants.FULL_HEIGHT)
394                    .padding({ bottom: Constants.RECORD_PADDING_BOTTOM })
395                  }
396                }
397              }
398            }
399            .layoutWeight(Constants.LAYOUT_WEIGHT)
400          }
401        }
402        .height(Constants.FULL_HEIGHT)
403        .width(Constants.FULL_WIDTH)
404        .backgroundColor($r("sys.color.ohos_id_color_sub_background"))
405      }
406    }.backgroundColor($r("sys.color.ohos_id_color_sub_background"))
407  }
408
409  /**
410   * Get time
411   * @param {Number} The time stamp
412   */
413  getTime(time: number, format='MM月DD日 NNHH:mm') {
414    if (this.strings.morning == 'am') { format = 'HH:mm NN MM/DD' }
415    let date = new Date(time);
416    let key = ['MM', 'DD', 'NN', 'HH', 'mm'];
417    let value = [
418      date.getMonth() + 1,
419      date.getDate(),
420      date.getHours() >= 12 ? this.strings.afternoon : this.strings.morning,
421      date.getHours() >= 12 ? date.getHours() - 12 : date.getHours(),
422      date.getMinutes() >= 10 ? date.getMinutes() : '0' + date.getMinutes(),
423    ];
424
425    for (let i = 0; i < key.length; ++i) {
426      format = format.replace(key[i], String(value[i]));
427    }
428    return format;
429  }
430
431  /**
432   * Get application record info
433   * @param {Object} application info
434   * @param {String} groupName
435   * @param {Boolean} true: count, false: lastTime
436   */
437  getAppRecords(appInfo: appRecordInfo, groupName: ResourceStr, option: boolean): number {
438    let record = appInfo.permissions.filter(permission => {
439      return permission.groupName == groupName;
440    })
441    if (record.length > 0) {
442      return option ? record[0].count : record[0].lastTime;
443    } else {
444      return 0;
445    }
446  }
447
448  getStrings() {
449    this.context.resourceManager.getStringValue($r("app.string.morning").id, (err, val) => {
450      this.strings.morning = val;
451    })
452    this.context.resourceManager.getStringValue($r("app.string.afternoon").id, (err, val) => {
453      this.strings.afternoon = val;
454    })
455  }
456
457  getInfo(record: privacyManager.BundleUsedRecord, sortFlag: boolean) {
458    bundleManager.getBundleInfo(record.bundleName, bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION).then(async (info): Promise<boolean> => {
459      let reqUserPermissions: string[] = [];
460      let reqUserRecords: privacyManager.PermissionUsedRecord[] = [];
461      let permissionGroups: appGroupRecordInfo[] = [];
462      let acManager = abilityAccessCtrl.createAtManager();
463      let appInfo: appRecordInfo = new appRecordInfo('', '', '', 0, 0, [], [], [], [], 0);
464      let reqPermissions: Array<Permissions> = [];
465      info.reqPermissionDetails.forEach(item => {
466        reqPermissions.push(item.name as Permissions);
467      });
468      for (let j = 0; j < record.permissionRecords.length; j++) {
469        let permission = record.permissionRecords[j].permissionName;
470        try {
471          let flag = await acManager.getPermissionFlags(info.appInfo.accessTokenId, permission);
472          if (flag == Constants.PERMISSION_SYSTEM_FIXED) {
473            continue;
474          }
475        }
476        catch(err) {
477          console.log(TAG + 'getPermissionFlags error: ' + JSON.stringify(err));
478        }
479        if (userGrantPermissions.indexOf(permission) != -1) {
480          reqUserRecords.push(record.permissionRecords[j]);
481        }
482      }
483      if (reqUserRecords.length == 0) {
484        return false;
485      }
486      for (let k = 0; k < reqPermissions.length; k++) {
487        let reqPermission = reqPermissions[k];
488        try {
489          let reqFlag = await acManager.getPermissionFlags(info.appInfo.accessTokenId, reqPermission);
490          if (reqFlag == Constants.PERMISSION_SYSTEM_FIXED) {
491            continue;
492          }
493        }
494        catch(err) {
495          console.log(TAG + 'getPermissionFlags error: ' + JSON.stringify(err));
496        }
497        if (userGrantPermissions.indexOf(reqPermission) != -1) {
498          reqUserPermissions.push(reqPermission);
499        }
500      }
501
502      let groupNames: ResourceStr[] = [];
503      let appLastTime = 0;
504      reqUserRecords.forEach(reqUserRecord => {
505        let group = getPermissionGroup(reqUserRecord.permissionName);
506        if (!group) {
507          console.info(TAG + "permission not find:" + reqUserRecord.permissionName);
508        } else {
509          let existing = permissionGroups.find(permissionGroup => permissionGroup.name == group.name);
510          let lastTime = reqUserRecord.lastAccessTime;
511          lastTime > appLastTime ? appLastTime = lastTime : '';
512          if (!existing) {
513            let appGroupRecord: appGroupRecordInfo = new appGroupRecordInfo(group.name, group.groupName, group.label, group.icon, reqUserRecord.accessCount, lastTime);
514            permissionGroups.push(appGroupRecord);
515            groupNames.push(group.groupName);
516          } else {
517            existing.count += reqUserRecord.accessCount;
518            lastTime > existing.lastTime ? existing.lastTime = lastTime : '';
519          }
520        }
521      })
522
523      let groupIds: number[] = [];
524      for (let i = 0; i < reqUserPermissions.length; i++) {
525        let groupId = getGroupIdByPermission(reqUserPermissions[i])
526        if (groupIds.indexOf(groupId) == -1){
527          groupIds.push(groupId);
528        }
529      }
530
531      this.allBundleInfo.forEach(bundleInfo => {
532        if (bundleInfo.bundleName === info.name) {
533          appInfo.groupName = bundleInfo.label;
534          appInfo.icon = bundleInfo.icon;
535        }
536      })
537
538      appInfo.name = info.name;
539      appInfo.api = info.targetVersion;
540      appInfo.accessTokenId = info.appInfo.accessTokenId;
541      appInfo.reqUserPermissions = reqUserPermissions;
542      appInfo.permissions = permissionGroups;
543      appInfo.groupNames = groupNames;
544      appInfo.groupIds = groupIds;
545      appInfo.appLastTime = appLastTime;
546      this.applicationInfos.push(appInfo);
547      if (sortFlag) {
548        let appInfos: appRecordInfo[] = [];
549        this.applicationInfos.forEach(item => { appInfos.push(item) });
550        appInfos.sort((a, b) => { return b.appLastTime - a.appLastTime });
551        this.applicationInfos = appInfos;
552      }
553      return true;
554    })
555  }
556
557  getAllRecords() {
558    let request: privacyManager.PermissionUsedRequest = {
559      tokenId: 0,
560      isRemote: false,
561      deviceId: '',
562      bundleName: '',
563      permissionNames: [],
564      beginTime: 0,
565      endTime: 0,
566      flag: 1
567    }
568    privacyManager.getPermissionUsedRecord(request).then(async records => {
569      console.info(TAG + "records: " + JSON.stringify(records.bundleRecords));
570      let groupArray: GroupRecordInfo[] = [];
571      let acManager = abilityAccessCtrl.createAtManager();
572      for (let i = 0; i < records.bundleRecords.length; i++) {
573        let record = records.bundleRecords[i];
574        try {
575          await bundleManager.queryAbilityInfo({
576            bundleName: record.bundleName,
577            action: "action.system.home",
578            entities: ["entity.system.home"]
579          }, bundleManager.AbilityFlag.GET_ABILITY_INFO_WITH_APPLICATION);
580        } catch(e) {
581          continue;
582        }
583        console.info(TAG + "record: " + JSON.stringify(record));
584        this.getInfo(record, (i + 1) == records.bundleRecords.length);
585
586        for (let j = 0; j < record.permissionRecords.length; j++) {
587          let permissionRecord = record.permissionRecords[j];
588          try {
589            let reqFlag = await acManager.getPermissionFlags(record.tokenId, permissionRecord.permissionName);
590            if (reqFlag == Constants.PERMISSION_SYSTEM_FIXED) {
591              continue;
592            }
593          }
594          catch(err) {
595            console.log(TAG + 'getPermissionFlags error: ' + JSON.stringify(err));
596          }
597          let group = getPermissionGroup(permissionRecord.permissionName);
598          if (group) {
599            let exist = groupArray.find(permissionGroup => permissionGroup.name == group.name);
600            let lastTime = permissionRecord.lastAccessTime;
601            if (!exist) {
602              let groupRecord: GroupRecordInfo = new GroupRecordInfo(group.name, group.groupName, group.label, group.icon, group.permissions, permissionRecord.accessCount, lastTime);
603              groupArray.push(groupRecord);
604            } else {
605              exist.sum += permissionRecord.accessCount;
606              lastTime > exist.recentVisit ? exist.recentVisit = lastTime : '';
607            }
608          }
609        }
610      }
611      groupArray.sort((a, b) => { return b.recentVisit - a.recentVisit });
612      this.groups = groupArray;
613    })
614  }
615
616  aboutToAppear() {
617    this.getStrings();
618    this.getAllRecords();
619  }
620}
621