• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 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 */
15import dataRdb from '@ohos.data.rdb'
16import database from './DatabaseUtils'
17import BundleManager from '../utils/BundleMangerUtils';
18import { dateFormat } from '../utils/TimeUtils'
19import { ReportItem } from '../entity/LocalConfigEntity'
20import { sql_t_general_info, dbVersion, dbName } from '../constant/ConstantSQL';
21import { AppFileRealDir } from '../constant/ConstantsPath'
22import SPLogger from '../utils/SPLogger'
23
24
25const TAG = "LocalRepository"
26
27
28export function initDb(): void {
29  const STORE_CONFIG = {
30    name: dbName
31  };
32  dataRdb.getRdbStore(globalThis.abilityContext, STORE_CONFIG, dbVersion)
33    .then(rdbStore => {
34      rdbStore.executeSql(sql_t_general_info, null).catch(err => {
35        SPLogger.DEBUG(TAG, "--> createTable t_genneral_info err:" + err)
36      })
37      SPLogger.DEBUG(TAG, "--> createTable start execute sql_t_genneral_info:" + sql_t_general_info)
38      return rdbStore
39    })
40
41  getReportListDb().then(res => {
42    globalThis.reportList = res
43    let bundleNameArr = []
44    for (let reportItemKey in globalThis.reportList) {
45      bundleNameArr.push(globalThis.reportList[reportItemKey].packageName)
46    }
47
48    BundleManager.getIconByBundleName(bundleNameArr).then(map => {
49      globalThis.iconMap = map
50    })
51
52    let resReport: Array<ReportItem> = res
53
54    globalThis.sumTest = resReport.length
55    globalThis.sumTestTime = 0
56
57    let sumTestAppMap = new Map
58    for (let resReportKey in resReport) {
59      sumTestAppMap.set(resReport[resReportKey].appName, "")
60      globalThis.sumTestTime += Number(resReport[resReportKey].testDuration).valueOf()
61    }
62    globalThis.sumTestApp = sumTestAppMap.size
63  }).catch(err => {
64    SPLogger.DEBUG(TAG, "getReportListDb ERR:" + err);
65  })
66}
67
68
69export async function getReportListDb(): Promise<Array<ReportItem>> {
70  var result = Array<ReportItem>()
71  await database.queryGeneralData().then(generals => {
72    for (var i = 0; i < generals.length; i++) {
73      var curGeneralInfo = generals[i]
74      result.push(
75        new ReportItem(
76          curGeneralInfo.taskId.toString(),
77          AppFileRealDir + curGeneralInfo.sessionId.toString(),
78          curGeneralInfo.packageName,
79          "",
80          curGeneralInfo.taskName,
81          curGeneralInfo.appName,
82          dateFormat(curGeneralInfo.startTime),
83          curGeneralInfo.testDuration.toString(),
84          false
85        ))
86    }
87  })
88  return result
89}