From 6252902535ae66e01e1267f9378fc44e06f759de Mon Sep 17 00:00:00 2001 From: zwx1094577 Date: Fri, 1 Nov 2024 11:06:00 +0800 Subject: [PATCH] =?UTF-8?q?IssueNo:=20#IB0OVC:=E4=BF=AE=E5=A4=8DStorageSta?= =?UTF-8?q?tistic=E5=8A=A0=E8=BD=BD=E9=97=AE=E9=A2=98=20Description:=20Fix?= =?UTF-8?q?=20Storage=20Statistics=20loading=20issue.=20Sig:=20SIG=5Fappli?= =?UTF-8?q?cations=5Fapp=5Fsamples=20Feature=20or=20Bugfix:=20Bugfix=20Bin?= =?UTF-8?q?ary=20Source:=20No?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zwx1094577 --- .../src/main/ets/common/QueryStorageData.ets | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/code/SystemFeature/DeviceManagement/StorageStatistic/entry/src/main/ets/common/QueryStorageData.ets b/code/SystemFeature/DeviceManagement/StorageStatistic/entry/src/main/ets/common/QueryStorageData.ets index 1d781a70c..434d77fc5 100644 --- a/code/SystemFeature/DeviceManagement/StorageStatistic/entry/src/main/ets/common/QueryStorageData.ets +++ b/code/SystemFeature/DeviceManagement/StorageStatistic/entry/src/main/ets/common/QueryStorageData.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -126,22 +126,28 @@ export class QueryStorageData { private async getAppNameSync(labelId: number, bundleName: string, appName: string): Promise { if (CheckEmptyUtils.isEmpty(labelId) || labelId <= 0 || CheckEmptyUtils.checkStrIsEmpty(bundleName)) { - Logger.info(TAG, `getAppNameSync param empty! appName: ${appName}`) - return appName + Logger.info(TAG, `getAppNameSync param empty! appName: ${appName}`); + return bundleName; } else { - let cacheKey = labelId + bundleName - Logger.info(TAG, `getAppNameSync getResourceManager cacheKey: ${cacheKey}`) + let cacheKey = labelId + bundleName; + Logger.info(TAG, `getAppNameSync getResourceManager cacheKey: ${cacheKey}`); if (this.isResourceManagerEmpty()) { - Logger.info(TAG, 'getAppNameSync resourceManager is empty') - return appName + Logger.info(TAG, 'getAppNameSync resourceManager is empty'); + return bundleName; } - let bundleContext: Context = this.context.createBundleContext(bundleName) - let resMgrName: string = await bundleContext.resourceManager.getString(labelId) - Logger.info(TAG, `getAppNameSync resMgrName: ${resMgrName}`) - if (resMgrName != null) { - return resMgrName + let resMgrName: string = ''; + try { + let bundleContext: Context = this.context.createBundleContext(bundleName); + resMgrName = bundleContext.resourceManager.getStringSync(labelId); + } catch (err) { + Logger.error(TAG, `getAppNameSync error: ${JSON.stringify(err)}`); + } + + Logger.info(TAG, `getAppNameSync resMgrName: ${resMgrName}`); + if (resMgrName != '') { + return resMgrName; } else { - return appName + return bundleName; } } }