From a0962f016fbdbbfa690d53c99651146d2ed9a1dd Mon Sep 17 00:00:00 2001 From: hunili Date: Thu, 25 Apr 2024 15:40:06 +0800 Subject: [PATCH] Modify use deviceType issue: https://gitee.com/openharmony/filemanagement_user_file_service/issues/I9JLSH Signed-off-by: hunili --- .../src/js_file_access_ext_ability.cpp | 7 ++----- .../kits/native/recent/recent_n_exporter.cpp | 4 ++-- .../native/trash/src/file_trash_n_exporter.cpp | 4 ++-- .../useraccesscommonutils_fuzzer.cpp | 7 +++---- utils/user_access_common_utils.h | 17 +++++++++-------- 5 files changed, 18 insertions(+), 21 deletions(-) diff --git a/interfaces/inner_api/file_access/src/js_file_access_ext_ability.cpp b/interfaces/inner_api/file_access/src/js_file_access_ext_ability.cpp index 0af42686..6f44736c 100644 --- a/interfaces/inner_api/file_access/src/js_file_access_ext_ability.cpp +++ b/interfaces/inner_api/file_access/src/js_file_access_ext_ability.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 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 @@ -1227,9 +1227,6 @@ bool JsFileAccessExtAbility::ParserGetRootsJsResult(napi_env &env, napi_value na return false; } - std::string deviceType; - bool deviceResult = GetDeviceType(deviceType); - HILOG_INFO("deviceType: %{public}s", deviceType.c_str()); for (uint32_t i = 0; i < length; i++) { napi_value nativeRootInfo = nullptr; napi_get_element(env, nativeArray, i, &nativeRootInfo); @@ -1244,7 +1241,7 @@ bool JsFileAccessExtAbility::ParserGetRootsJsResult(napi_env &env, napi_value na return false; } - if (deviceResult && deviceType == "2in1") { + if (IsFullMountEnable()) { ChangeCurrentDir(rootInfo); } result.data.emplace_back(std::move(rootInfo)); diff --git a/interfaces/kits/native/recent/recent_n_exporter.cpp b/interfaces/kits/native/recent/recent_n_exporter.cpp index 38f725b7..492066dc 100644 --- a/interfaces/kits/native/recent/recent_n_exporter.cpp +++ b/interfaces/kits/native/recent/recent_n_exporter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-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 @@ -324,7 +324,7 @@ void RecentNExporter::InitRecentPath() } RecentNExporter::recentPath_ = "/storage/Users/currentUser/.Recent/"; std::string deviceType; - if (GetDeviceType(deviceType) && deviceType == "2in1") { + if (IsFullMountEnable()) { std::string userName; if (GetUserName(userName) && userName != "") { RecentNExporter::recentPath_ = "/storage/Users/" + userName + "/.Recent/"; diff --git a/interfaces/kits/native/trash/src/file_trash_n_exporter.cpp b/interfaces/kits/native/trash/src/file_trash_n_exporter.cpp index 2f932adf..6f10cbad 100644 --- a/interfaces/kits/native/trash/src/file_trash_n_exporter.cpp +++ b/interfaces/kits/native/trash/src/file_trash_n_exporter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-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 @@ -697,7 +697,7 @@ void FileTrashNExporter::InitTrashPath() } FileTrashNExporter::trashPath_ = "/storage/Users/currentUser/.Trash"; std::string deviceType; - if (GetDeviceType(deviceType) && deviceType == "2in1") { + if (IsFullMountEnable()) { std::string userName; if (GetUserName(userName) && userName != "") { FileTrashNExporter::trashPath_ = "/storage/Users/" + userName + "/.Trash"; diff --git a/test/fuzztest/useraccesscommonutils_fuzzer/useraccesscommonutils_fuzzer.cpp b/test/fuzztest/useraccesscommonutils_fuzzer/useraccesscommonutils_fuzzer.cpp index 9aa5e94c..cf7f7ea1 100644 --- a/test/fuzztest/useraccesscommonutils_fuzzer/useraccesscommonutils_fuzzer.cpp +++ b/test/fuzztest/useraccesscommonutils_fuzzer/useraccesscommonutils_fuzzer.cpp @@ -23,10 +23,9 @@ namespace OHOS { using namespace std; using namespace FileAccessFwk; -bool GetDeviceTypeFuzzTest(const uint8_t *data, size_t size) +bool IsFullMountFuzzTest(const uint8_t *data, size_t size) { - string deviceType; - GetDeviceType(deviceType); + IsFullMountEnable(); return true; } @@ -42,7 +41,7 @@ bool GetUserNameFuzzTest(const uint8_t *data, size_t size) /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - OHOS::GetDeviceTypeFuzzTest(data, size); + OHOS::IsFullMountFuzzTest(data, size); OHOS::GetUserNameFuzzTest(data, size); return 0; diff --git a/utils/user_access_common_utils.h b/utils/user_access_common_utils.h index 3ccd6473..076d2f0b 100644 --- a/utils/user_access_common_utils.h +++ b/utils/user_access_common_utils.h @@ -21,17 +21,18 @@ namespace OHOS { namespace FileAccessFwk { +const std::string FULL_MOUNT_ENABLE_PARAMETER = "const.filemanager.full_mount.enable"; -static bool GetDeviceType(std::string &deviceType) +static bool IsFullMountEnable() { - char deviceTypeChar[PARAM_CONST_VALUE_LEN_MAX]; - int32_t ret = GetParameter("const.product.devicetype", "0", deviceTypeChar, PARAM_CONST_VALUE_LEN_MAX); - if (ret < 0) { - HILOG_ERROR("Get deviceType fail. %{public}d", ret); - return false; + char value[] = "false"; + int ret = GetParameter(FULL_MOUNT_ENABLE_PARAMETER.c_str(), "false", value, sizeof(value)); + if ((ret > 0) && (std::string(value) == "true")) { + HILOG_INFO("Supporting all mounts"); + return true; } - deviceType = deviceTypeChar; - return true; + HILOG_INFO("Not supporting all mounts"); + return false; } static bool GetUserName(std::string &userName) -- Gitee