change name of func

Signed-off-by: 张文迪 <zhangwendi3@huawei.com>
This commit is contained in:
张文迪 2022-04-13 12:07:41 +08:00
parent 86d96a4906
commit fc579b8f87
17 changed files with 78 additions and 108 deletions

View File

@ -35,9 +35,9 @@ public:
virtual int64_t GetSystemSize() = 0;
virtual int64_t GetTotalSize() = 0;
virtual int64_t GetFreeSize() = 0;
virtual std::vector<int64_t> GetStorageTotalStats() = 0;
virtual std::vector<int64_t> GetUserStorageStats() = 0;
virtual std::vector<int64_t> GetUserStorageStats(int32_t userId) = 0;
virtual std::vector<int64_t> GetAppStorageStats() = 0;
virtual std::vector<int64_t> GetCurrentBundleStats() = 0;
virtual void NotifyVolumeCreated(VolumeCore vc) = 0;
virtual void NotifyVolumeMounted(std::string volumeId, int fsType, std::string fsUuid,
std::string path, std::string description) = 0;
@ -69,9 +69,9 @@ public:
GET_SYSTEM_SIZE,
GET_TOTAL_SIZE,
GET_FREE_SIZE,
GET_TOTAL_STATS,
GET_CURR_USER_STATS,
GET_USER_STATS,
GET_APP_STATS,
GET_CURR_BUNDLE_STATS,
NOTIFY_VOLUME_CREATED,
NOTIFY_VOLUME_MOUNTED,
NOTIFY_VOLUME_DESTROYED,

View File

@ -27,6 +27,8 @@ declare namespace storageStatistics {
* Get the totalSize of volume.
*
* @since 8
* @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
* @permission ohos.permission.STORAGE_MANAGER
* @systemapi
*/
function getTotalSizeOfVolume(volumeUuid: string, callback: AsyncCallback<number>): void;
@ -35,6 +37,8 @@ declare namespace storageStatistics {
* Get the free size Of volume.
*
* @since 8
* @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
* @permission ohos.permission.STORAGE_MANAGER
* @systemapi
*/
function getFreeSizeOfVolume(volumeUuid: string, callback: AsyncCallback<number>): void;
@ -44,6 +48,8 @@ declare namespace storageStatistics {
* Get the bundlestat
*
* @since 9
* @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
* @permission ohos.permission.STORAGE_MANAGER
* @systemapi
*/
@ -56,23 +62,28 @@ declare namespace storageStatistics {
* Get the bundlestat
*
* @since 9
* @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
* @permission ohos.permission.STORAGE_MANAGER
* @systemapi
*/
function getBundleStats(packageName: string, callback: AsyncCallback<BundleStats>): void;
function getBundleStats(packageName: string): Promise<BundleStats>;
/**
* Get the AppStorageStats
* Get the CurrentBundleStats
*
* @since 9
* @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
*/
function getAppStorageStats(callback: AsyncCallback<BundleStats>): void;
function getAppStorageStats(): Promise<BundleStats>;
function getCurrentBundleStats(callback: AsyncCallback<BundleStats>): void;
function getCurrentBundleStats(): Promise<BundleStats>;
/**
* Get the systemsize
*
* @since 9
* @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
* @permission ohos.permission.STORAGE_MANAGER
* @systemapi
*/
function getSystemSize(callback: AsyncCallback<number>): void;
@ -82,13 +93,15 @@ declare namespace storageStatistics {
* Get the UserStorageStats
*
* @since 9
* @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
* @systemapi
*/
export interface TotalStats {
export interface StorageStats {
total: number;
audio: number;
video: number;
image: number;
file: number;
app: number;
}
@ -96,15 +109,20 @@ declare namespace storageStatistics {
* Get the UserStorageStats
*
* @since 9
* @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
* @permission ohos.permission.STORAGE_MANAGER
* @systemapi
*/
function getUserStorageStats(userId: string, callback: AsyncCallback<TotalStats>): void;
function getUserStorageStats(userId: string): Promise<TotalStats>;
function getUserStorageStats(userId: string, callback: AsyncCallback<StorageStats>): void;
function getUserStorageStats(callback: AsyncCallback<StorageStats>): void;
function getUserStorageStats(userId?: string): Promise<StorageStats>;
/**
* Get the totalsize
*
* @since 9
* @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
* @permission ohos.permission.STORAGE_MANAGER
* @systemapi
*/
function getTotalSize(callback: AsyncCallback<number>): void;
@ -114,20 +132,13 @@ declare namespace storageStatistics {
* Get the freesize
*
* @since 9
* @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
* @permission ohos.permission.STORAGE_MANAGER
* @systemapi
*/
function getFreeSize(callback: AsyncCallback<number>): void;
function getFreeSize(): Promise<number>;
/**
* Get the StorageTotalStats
*
* @since 9
* @systemapi
*/
function getStorageTotalStats(callback: AsyncCallback<TotalStats>): void;
function getStorageTotalStats(): Promise<TotalStats>;
}
export default storageStatistics;

View File

@ -38,9 +38,9 @@ public:
int64_t GetSystemSize();
int64_t GetTotalSize();
int64_t GetFreeSize();
std::vector<int64_t> GetStorageTotalStats();
std::vector<int64_t> GetUserStorageStats();
std::vector<int64_t> GetUserStorageStats(int32_t userId);
std::vector<int64_t> GetAppStorageStats();
std::vector<int64_t> GetCurrentBundleStats();
private:
sptr<StorageManager::IStorageManager> storageManager_ = nullptr;
};

View File

@ -24,12 +24,11 @@ namespace StorageManager {
napi_value GetTotalSizeOfVolume(napi_env env, napi_callback_info info);
napi_value GetFreeSizeOfVolume(napi_env env, napi_callback_info info);
napi_value GetBundleStats(napi_env env, napi_callback_info info);
napi_value GetAppStorageStats(napi_env env, napi_callback_info info);
napi_value GetCurrentBundleStats(napi_env env, napi_callback_info info);
napi_value GetSystemSize(napi_env env, napi_callback_info info);
napi_value GetUserStorageStats(napi_env env, napi_callback_info info);
napi_value GetTotalSize(napi_env env, napi_callback_info info);
napi_value GetFreeSize(napi_env env, napi_callback_info info);
napi_value GetStorageTotalStats(napi_env env, napi_callback_info info);
} // namespace StorageManager
} // namespace OHOS
#endif // STORAGESTATUS_N_EXPORTER_H

View File

@ -46,9 +46,9 @@ public:
int64_t GetSystemSize() override;
int64_t GetTotalSize() override;
int64_t GetFreeSize() override;
std::vector<int64_t> GetStorageTotalStats() override;
std::vector<int64_t> GetUserStorageStats() override;
std::vector<int64_t> GetUserStorageStats(int32_t userId) override;
std::vector<int64_t> GetAppStorageStats() override;
std::vector<int64_t> GetCurrentBundleStats() override;
void NotifyVolumeCreated(VolumeCore vc) override;
void NotifyVolumeMounted(std::string volumeId, int32_t fsType, std::string fsUuid,

View File

@ -37,9 +37,9 @@ public:
int64_t GetSystemSize() override;
int64_t GetTotalSize() override;
int64_t GetFreeSize() override;
std::vector<int64_t> GetStorageTotalStats() override;
std::vector<int64_t> GetUserStorageStats() override;
std::vector<int64_t> GetUserStorageStats(int32_t userId) override;
std::vector<int64_t> GetAppStorageStats() override;
std::vector<int64_t> GetCurrentBundleStats() override;
void NotifyVolumeCreated(VolumeCore vc) override;
void NotifyVolumeMounted(std::string volumeId, int32_t fsType, std::string fsUuid,
std::string path, std::string description) override;

View File

@ -40,9 +40,9 @@ private:
int32_t HandleGetSystemSize(MessageParcel &data, MessageParcel &reply);
int32_t HandleGetTotalSize(MessageParcel &data, MessageParcel &reply);
int32_t HandleGetFreeSize(MessageParcel &data, MessageParcel &reply);
int32_t HandleGetStorageTotalStats(MessageParcel &data, MessageParcel &reply);
int32_t HandleGetCurrUserStorageStats(MessageParcel &data, MessageParcel &reply);
int32_t HandleGetUserStorageStats(MessageParcel &data, MessageParcel &reply);
int32_t HandleGetAppStorageStats(MessageParcel &data, MessageParcel &reply);
int32_t HandleGetCurrentBundleStats(MessageParcel &data, MessageParcel &reply);
int32_t HandleNotifyVolumeCreated(MessageParcel &data, MessageParcel &reply);
int32_t HandleNotifyVolumeMounted(MessageParcel &data, MessageParcel &reply);
int32_t HandleNotifyVolumeDestroyed(MessageParcel &data, MessageParcel &reply);

View File

@ -28,9 +28,9 @@ class StorageStatusService : public NoCopyable {
public:
std::vector<int64_t> GetBundleStats(std::string pkgName);
std::vector<int64_t> GetStorageTotalStats();
std::vector<int64_t> GetUserStorageStats();
std::vector<int64_t> GetUserStorageStats(int32_t userId);
std::vector<int64_t> GetAppStorageStats();
std::vector<int64_t> GetCurrentBundleStats();
private:
int GetCurrentUserId();
std::string GetCallingPkgName();

View File

@ -118,10 +118,10 @@ int64_t StorageManager::GetFreeSize()
return result;
}
std::vector<int64_t> StorageManager::GetStorageTotalStats()
std::vector<int64_t> StorageManager::GetUserStorageStats()
{
LOGI("StorageManger::GetStorageTotalStats start");
std::vector<int64_t> result = DelayedSingleton<StorageStatusService>::GetInstance()->GetStorageTotalStats();
LOGI("StorageManger::GetUserStorageStats start");
std::vector<int64_t> result = DelayedSingleton<StorageStatusService>::GetInstance()->GetUserStorageStats();
return result;
}
@ -132,10 +132,10 @@ std::vector<int64_t> StorageManager::GetUserStorageStats(int32_t userId)
return result;
}
std::vector<int64_t> StorageManager::GetAppStorageStats()
std::vector<int64_t> StorageManager::GetCurrentBundleStats()
{
LOGI("StorageManger::GetAppStorageStats start");
std::vector<int64_t> result = DelayedSingleton<StorageStatusService>::GetInstance()->GetAppStorageStats();
LOGI("StorageManger::GetCurrentBundleStats start");
std::vector<int64_t> result = DelayedSingleton<StorageStatusService>::GetInstance()->GetCurrentBundleStats();
return result;
}

View File

@ -624,7 +624,7 @@ int64_t StorageManagerProxy::GetFreeSize()
return reply.ReadInt64();
}
std::vector<int64_t> StorageManagerProxy::GetStorageTotalStats()
std::vector<int64_t> StorageManagerProxy::GetUserStorageStats()
{
std::vector<int64_t> result = {};
MessageParcel data, reply;
@ -633,7 +633,7 @@ std::vector<int64_t> StorageManagerProxy::GetStorageTotalStats()
return result;
}
int err = Remote()->SendRequest(GET_TOTAL_STATS, data, reply, option);
int err = Remote()->SendRequest(GET_CURR_USER_STATS, data, reply, option);
if (err != E_OK) {
return result;
}
@ -667,7 +667,7 @@ std::vector<int64_t> StorageManagerProxy::GetUserStorageStats(int32_t userId)
return val;
}
std::vector<int64_t> StorageManagerProxy::GetAppStorageStats()
std::vector<int64_t> StorageManagerProxy::GetCurrentBundleStats()
{
std::vector<int64_t> result = {};
MessageParcel data, reply;
@ -676,7 +676,7 @@ std::vector<int64_t> StorageManagerProxy::GetAppStorageStats()
return result;
}
int err = Remote()->SendRequest(GET_APP_STATS, data, reply, option);
int err = Remote()->SendRequest(GET_CURR_BUNDLE_STATS, data, reply, option);
if (err != E_OK) {
return result;
}

View File

@ -89,14 +89,14 @@ int32_t StorageManagerStub::OnRemoteRequest(uint32_t code,
case GET_FREE_SIZE:
HandleGetFreeSize(data, reply);
break;
case GET_TOTAL_STATS:
HandleGetStorageTotalStats(data, reply);
case GET_CURR_USER_STATS:
HandleGetCurrUserStorageStats(data, reply);
break;
case GET_USER_STATS:
HandleGetUserStorageStats(data, reply);
break;
case GET_APP_STATS:
HandleGetAppStorageStats(data, reply);
case GET_CURR_BUNDLE_STATS:
HandleGetCurrentBundleStats(data, reply);
break;
case GET_BUNDLE_STATUS:
HandleGetBundleStatus(data, reply);
@ -271,9 +271,9 @@ int32_t StorageManagerStub::HandleGetFreeSize(MessageParcel &data, MessageParcel
return E_OK;
}
int32_t StorageManagerStub::HandleGetStorageTotalStats(MessageParcel &data, MessageParcel &reply)
int32_t StorageManagerStub::HandleGetCurrUserStorageStats(MessageParcel &data, MessageParcel &reply)
{
std::vector<int64_t> storageStats = GetStorageTotalStats();
std::vector<int64_t> storageStats = GetUserStorageStats();
if (!reply.WriteInt64Vector(storageStats)) {
return E_IPC_ERROR;
}
@ -290,9 +290,9 @@ int32_t StorageManagerStub::HandleGetUserStorageStats(MessageParcel &data, Messa
return E_OK;
}
int32_t StorageManagerStub::HandleGetAppStorageStats(MessageParcel &data, MessageParcel &reply)
int32_t StorageManagerStub::HandleGetCurrentBundleStats(MessageParcel &data, MessageParcel &reply)
{
std::vector<int64_t> bundleStats = GetAppStorageStats();
std::vector<int64_t> bundleStats = GetCurrentBundleStats();
if (!reply.WriteInt64Vector(bundleStats)) {
return E_IPC_ERROR;
}

View File

@ -86,7 +86,7 @@ public:
return E_OK;
}
virtual std::vector<int64_t> GetStorageTotalStats() override
virtual std::vector<int64_t> GetUserStorageStats() override
{
std::vector<int64_t> result;
return result;
@ -98,7 +98,7 @@ public:
return result;
}
virtual std::vector<int64_t> GetAppStorageStats() override
virtual std::vector<int64_t> GetCurrentBundleStats() override
{
std::vector<int64_t> result;
return result;

View File

@ -147,14 +147,14 @@ int64_t StorageManagerConnect::GetFreeSize()
return result;
}
std::vector<int64_t> StorageManagerConnect::GetStorageTotalStats()
std::vector<int64_t> StorageManagerConnect::GetUserStorageStats()
{
std::vector<int64_t> result = {};
if (Connect() != E_OK) {
LOGE("StorageManagerConnect::GetStorageTotalStats:Connect error");
LOGE("StorageManagerConnect::GetUserStorageStats:Connect error");
return result;
}
result = storageManager_->GetStorageTotalStats();
result = storageManager_->GetUserStorageStats();
return result;
}
@ -169,14 +169,14 @@ std::vector<int64_t> StorageManagerConnect::GetUserStorageStats(int32_t userId)
return result;
}
std::vector<int64_t> StorageManagerConnect::GetAppStorageStats()
std::vector<int64_t> StorageManagerConnect::GetCurrentBundleStats()
{
std::vector<int64_t> result = {};
if (Connect() != E_OK) {
LOGE("StorageManagerConnect::GetAppStorageStats:Connect error");
LOGE("StorageManagerConnect::GetCurrentBundleStats:Connect error");
return result;
}
result = storageManager_->GetAppStorageStats();
result = storageManager_->GetCurrentBundleStats();
return result;
}
} // StorageManager

View File

@ -162,7 +162,7 @@ napi_value GetBundleStats(napi_env env, napi_callback_info info)
return NVal::CreateUndefined(env).val_;
}
napi_value GetAppStorageStats(napi_env env, napi_callback_info info)
napi_value GetCurrentBundleStats(napi_env env, napi_callback_info info)
{
NFuncArg funcArg(env, info);
if (!funcArg.InitArgs((int)NARG_CNT::ZERO, (int)NARG_CNT::ONE)) {
@ -172,7 +172,7 @@ napi_value GetAppStorageStats(napi_env env, napi_callback_info info)
auto bundleStats = std::make_shared<std::vector<int64_t>>();
auto cbExec = [bundleStats](napi_env env) -> UniError {
*bundleStats = DelayedSingleton<StorageManagerConnect>::GetInstance()->GetAppStorageStats();
*bundleStats = DelayedSingleton<StorageManagerConnect>::GetInstance()->GetCurrentBundleStats();
return UniError(ERRNO_NOERR);
};
auto cbComplete = [bundleStats](napi_env env, UniError err) -> NVal {
@ -190,7 +190,7 @@ napi_value GetAppStorageStats(napi_env env, napi_callback_info info)
bundleObject.AddProp("dataSize", NVal::CreateInt64(env, (*bundleStats)[2]).val_);
return bundleObject;
};
std::string procedureName = "GetAppStorageStats";
std::string procedureName = "GetCurrentBundleStats";
NVal thisVar(env, funcArg.GetThisVar());
if (funcArg.GetArgc() == (int)NARG_CNT::ZERO) {
return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbComplete).val_;
@ -258,7 +258,7 @@ napi_value GetUserStorageStats(napi_env env, napi_callback_info info)
return { env, err.GetNapiErr(env) };
}
NVal totalObject = NVal::CreateObject(env);
if ((*totalStats).size() != 5) {
if ((*totalStats).size() != 6) {
UniError(EINVAL).ThrowErr(env, "vector size error");
return totalObject;
}
@ -266,7 +266,8 @@ napi_value GetUserStorageStats(napi_env env, napi_callback_info info)
totalObject.AddProp("audio", NVal::CreateInt64(env, (*totalStats)[1]).val_);
totalObject.AddProp("video", NVal::CreateInt64(env, (*totalStats)[2]).val_);
totalObject.AddProp("image", NVal::CreateInt64(env, (*totalStats)[3]).val_);
totalObject.AddProp("app", NVal::CreateInt64(env, (*totalStats)[4]).val_);
totalObject.AddProp("file", NVal::CreateInt64(env, (*totalStats)[4]).val_);
totalObject.AddProp("app", NVal::CreateInt64(env, (*totalStats)[5]).val_);
return totalObject;
};
std::string procedureName = "GetUserStorageStats";
@ -341,45 +342,5 @@ napi_value GetFreeSize(napi_env env, napi_callback_info info)
}
return NVal::CreateUndefined(env).val_;
}
napi_value GetStorageTotalStats(napi_env env, napi_callback_info info)
{
NFuncArg funcArg(env, info);
if (!funcArg.InitArgs((int)NARG_CNT::ZERO, (int)NARG_CNT::ONE)) {
UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched 1-2");
return nullptr;
}
auto totalStats = std::make_shared<std::vector<int64_t>>();
auto cbExec = [totalStats](napi_env env) -> UniError {
*totalStats = DelayedSingleton<StorageManagerConnect>::GetInstance()->GetStorageTotalStats();
return UniError(ERRNO_NOERR);
};
auto cbComplete = [totalStats](napi_env env, UniError err) -> NVal {
if (err) {
return { env, err.GetNapiErr(env) };
}
NVal totalObject = NVal::CreateObject(env);
if ((*totalStats).size() != 5) {
UniError(EINVAL).ThrowErr(env, "vector size error");
return totalObject;
}
totalObject.AddProp("total", NVal::CreateInt64(env, (*totalStats)[0]).val_);
totalObject.AddProp("audio", NVal::CreateInt64(env, (*totalStats)[1]).val_);
totalObject.AddProp("video", NVal::CreateInt64(env, (*totalStats)[2]).val_);
totalObject.AddProp("image", NVal::CreateInt64(env, (*totalStats)[3]).val_);
totalObject.AddProp("app", NVal::CreateInt64(env, (*totalStats)[4]).val_);
return totalObject;
};
std::string procedureName = "GetStorageTotalStats";
NVal thisVar(env, funcArg.GetThisVar());
if (funcArg.GetArgc() == (int)NARG_CNT::ZERO) {
return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbComplete).val_;
} else {
NVal cb(env, funcArg[(int)NARG_POS::FIRST]);
return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_;
}
return NVal::CreateUndefined(env).val_;
}
} // namespace StorageManager
} // namespace OHOS

View File

@ -31,12 +31,11 @@ napi_value StorageStatisticsExport(napi_env env, napi_value exports)
DECLARE_NAPI_FUNCTION("getTotalSizeOfVolume", GetTotalSizeOfVolume),
DECLARE_NAPI_FUNCTION("getFreeSizeOfVolume", GetFreeSizeOfVolume),
DECLARE_NAPI_FUNCTION("getBundleStats", GetBundleStats),
DECLARE_NAPI_FUNCTION("getAppStorageStats", GetAppStorageStats),
DECLARE_NAPI_FUNCTION("getCurrentBundleStats", GetCurrentBundleStats),
DECLARE_NAPI_FUNCTION("getSystemSize", GetSystemSize),
DECLARE_NAPI_FUNCTION("getUserStorageStats", GetUserStorageStats),
DECLARE_NAPI_FUNCTION("getTotalSize", GetTotalSize),
DECLARE_NAPI_FUNCTION("getFreeSize", GetFreeSize),
DECLARE_NAPI_FUNCTION("getStorageTotalStats", GetStorageTotalStats),
};
NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
return exports;

View File

@ -72,7 +72,7 @@ vector<int64_t> StorageStatusService::GetBundleStats(std::string pkgName)
return result;
}
std::vector<int64_t> StorageStatusService::GetStorageTotalStats()
std::vector<int64_t> StorageStatusService::GetUserStorageStats()
{
vector<int64_t> result = {0, 0, 0, 0, 0};
return result;
@ -84,7 +84,7 @@ std::vector<int64_t> StorageStatusService::GetUserStorageStats(int32_t userId)
return result;
}
std::vector<int64_t> StorageStatusService::GetAppStorageStats()
std::vector<int64_t> StorageStatusService::GetCurrentBundleStats()
{
vector<int64_t> result = {0, 0, 0};
int userId = GetCurrentUserId();

View File

@ -75,7 +75,7 @@ int64_t StorageTotalStatusService::GetSystemSize()
int64_t StorageTotalStatusService::GetTotalSize()
{
string path = "/data"; // todo
string path = "/data";
struct statvfs diskInfo;
int ret = statvfs(path.c_str(), &diskInfo);
if (ret != E_OK) {
@ -87,7 +87,7 @@ int64_t StorageTotalStatusService::GetTotalSize()
int64_t StorageTotalStatusService::GetFreeSize()
{
string path = "/data"; // todo
string path = "/data";
struct statvfs diskInfo;
int ret = statvfs(path.c_str(), &diskInfo);
if (ret != E_OK) {