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 0af42686c445c7b9b7f4b49e4dd53f5acfeaedad..6f44736cfba2e51e0193247600d3169a20906dba 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 38f725b778ca1a17aeba9826224c03974d9af65f..492066dc7694517278c49dcfc72f8e2ed1f08055 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 2f932adf794bc359e0048cfc47d9ff2de4aa9d1d..6f10cbadc02a2ca9578a8faf9f07961c9069d058 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 9aa5e94c344a045499bdcf43af482b5607b6123f..cf7f7ea144e10c50ffe79e5d220afb326e16ba65 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 3ccd64737d9f8aa38f6754ab9ede7b762360eaf4..076d2f0bb8c04a56e416a2a95ee2c9d6e49b3e12 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)