From 34270400b393be04e58eef7caa5727491829ccb8 Mon Sep 17 00:00:00 2001 From: Wootak Jung Date: Thu, 4 May 2023 13:42:30 +0900 Subject: [PATCH] [Tizen] Add system info module to check platform properties (#26325) * [Tizen] Add system info module to check platform properties * change to integer type from double --------- Signed-off-by: Wootak Jung --- config/tizen/chip-gn/platform/BUILD.gn | 5 ++ src/platform/Tizen/BLEManagerImpl.cpp | 17 ++++-- src/platform/Tizen/BUILD.gn | 2 + src/platform/Tizen/PlatformManagerImpl.cpp | 5 ++ src/platform/Tizen/SystemInfo.cpp | 62 ++++++++++++++++++++++ src/platform/Tizen/SystemInfo.h | 46 ++++++++++++++++ 6 files changed, 134 insertions(+), 3 deletions(-) create mode 100644 src/platform/Tizen/SystemInfo.cpp create mode 100644 src/platform/Tizen/SystemInfo.h diff --git a/config/tizen/chip-gn/platform/BUILD.gn b/config/tizen/chip-gn/platform/BUILD.gn index 781cf53d222929..7d2f25e9bcf4f8 100644 --- a/config/tizen/chip-gn/platform/BUILD.gn +++ b/config/tizen/chip-gn/platform/BUILD.gn @@ -35,6 +35,10 @@ pkg_config("glib") { ] } +pkg_config("capi-system-info") { + packages = [ "capi-system-info" ] +} + if (chip_mdns == "platform") { pkg_config("nsd-dns-sd") { packages = [ "nsd-dns-sd" ] @@ -64,6 +68,7 @@ source_set("tizen") { ":dlog", ":glib", ":capi-appfw-preference", + ":capi-system-info", ] if (chip_mdns == "platform") { diff --git a/src/platform/Tizen/BLEManagerImpl.cpp b/src/platform/Tizen/BLEManagerImpl.cpp index 8b55c11ea61cf2..2af519916520a6 100644 --- a/src/platform/Tizen/BLEManagerImpl.cpp +++ b/src/platform/Tizen/BLEManagerImpl.cpp @@ -65,6 +65,7 @@ #include "CHIPDevicePlatformEvent.h" #include "ChipDeviceScanner.h" +#include "SystemInfo.h" namespace chip { namespace DeviceLayer { @@ -619,6 +620,7 @@ int BLEManagerImpl::StartBLEAdvertising() Ble::ChipBLEDeviceIdentificationInfo deviceIdInfo = { 0x0, }; + PlatformVersion version; if (sInstance.mAdvReqInProgress) { @@ -667,9 +669,18 @@ int BLEManagerImpl::StartBLEAdvertising() VerifyOrExit(ret == BT_ERROR_NONE, ChipLogError(DeviceLayer, "bt_adapter_le_add_advertising_service_data() failed. ret: %d", ret)); - ret = bt_adapter_le_set_advertising_flags( - mAdvertiser, BT_ADAPTER_LE_ADVERTISING_FLAGS_GEN_DISC | BT_ADAPTER_LE_ADVERTISING_FLAGS_BREDR_UNSUP); - VerifyOrExit(ret == BT_ERROR_NONE, ChipLogError(DeviceLayer, "bt_adapter_le_set_advertising_flags() failed. ret: %d", ret)); + err = SystemInfo::GetPlatformVersion(version); + VerifyOrExit(err == CHIP_NO_ERROR, ChipLogError(DeviceLayer, "GetPlatformVersion() failed. %s", ErrorStr(err))); + if (version.mMajor >= 7 && version.mMinor >= 5) + { + ret = bt_adapter_le_set_advertising_flags( + mAdvertiser, BT_ADAPTER_LE_ADVERTISING_FLAGS_GEN_DISC | BT_ADAPTER_LE_ADVERTISING_FLAGS_BREDR_UNSUP); + VerifyOrExit(ret == BT_ERROR_NONE, ChipLogError(DeviceLayer, "bt_adapter_le_set_advertising_flags() failed. ret: %d", ret)); + } + else + { + ChipLogProgress(DeviceLayer, "setting function of advertising flags is available from tizen 7.5 or later"); + } ret = bt_adapter_le_set_advertising_device_name(mAdvertiser, BT_ADAPTER_LE_PACKET_ADVERTISING, true); VerifyOrExit(ret == BT_ERROR_NONE, diff --git a/src/platform/Tizen/BUILD.gn b/src/platform/Tizen/BUILD.gn index 9a6d42f050dc08..12b7ab03352575 100644 --- a/src/platform/Tizen/BUILD.gn +++ b/src/platform/Tizen/BUILD.gn @@ -57,6 +57,8 @@ static_library("Tizen") { "PlatformManagerImpl.h", "PosixConfig.cpp", "PosixConfig.h", + "SystemInfo.cpp", + "SystemInfo.h", "SystemPlatformConfig.h", "SystemTimeSupport.cpp", ] diff --git a/src/platform/Tizen/PlatformManagerImpl.cpp b/src/platform/Tizen/PlatformManagerImpl.cpp index 41e011052742c0..9f55f3b824f3de 100644 --- a/src/platform/Tizen/PlatformManagerImpl.cpp +++ b/src/platform/Tizen/PlatformManagerImpl.cpp @@ -40,6 +40,7 @@ #include #include "PosixConfig.h" +#include "SystemInfo.h" #include "platform/internal/GenericPlatformManagerImpl.h" #include "platform/internal/GenericPlatformManagerImpl.ipp" #include "platform/internal/GenericPlatformManagerImpl_POSIX.h" @@ -119,6 +120,10 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack() mStartTime = System::SystemClock().GetMonotonicTimestamp(); + Internal::PlatformVersion version; + ReturnErrorOnFailure(Internal::SystemInfo::GetPlatformVersion(version)); + ChipLogProgress(DeviceLayer, "Tizen Version: %d.%d", version.mMajor, version.mMinor); + return CHIP_NO_ERROR; } diff --git a/src/platform/Tizen/SystemInfo.cpp b/src/platform/Tizen/SystemInfo.cpp new file mode 100644 index 00000000000000..04f445a87202ba --- /dev/null +++ b/src/platform/Tizen/SystemInfo.cpp @@ -0,0 +1,62 @@ +/* + * + * Copyright (c) 2023 Project CHIP Authors + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "SystemInfo.h" + +#include + +#include +#include + +#include + +using namespace std; + +namespace chip { +namespace DeviceLayer { +namespace Internal { + +SystemInfo SystemInfo::sInstance; + +CHIP_ERROR SystemInfo::GetPlatformVersion(PlatformVersion & version) +{ + char * platformVersion; + int ret; + + if (sInstance.mMajor > 0) + { + version.mMajor = sInstance.mMajor; + version.mMinor = sInstance.mMinor; + return CHIP_NO_ERROR; + } + + ret = system_info_get_platform_string("http://tizen.org/feature/platform.version", &platformVersion); + if (ret != SYSTEM_INFO_ERROR_NONE) + { + ChipLogError(DeviceLayer, "system_info_get_platform_string() failed. %s", get_error_message(ret)); + return CHIP_ERROR_INTERNAL; + } + + sInstance.mMajor = version.mMajor = (uint8_t)(platformVersion[0] - '0'); + sInstance.mMinor = version.mMinor = (uint8_t)(platformVersion[2] - '0'); + free(platformVersion); + return CHIP_NO_ERROR; +} + +} // namespace Internal +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/Tizen/SystemInfo.h b/src/platform/Tizen/SystemInfo.h new file mode 100644 index 00000000000000..d1504895f16d80 --- /dev/null +++ b/src/platform/Tizen/SystemInfo.h @@ -0,0 +1,46 @@ +/* + * + * Copyright (c) 2023 Project CHIP Authors + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include + +namespace chip { +namespace DeviceLayer { +namespace Internal { + +struct PlatformVersion +{ + uint8_t mMajor; + uint8_t mMinor; +}; + +class SystemInfo +{ +public: + static CHIP_ERROR GetPlatformVersion(PlatformVersion & version); + +private: + static SystemInfo sInstance; + uint8_t mMajor = 0; + uint8_t mMinor = 0; +}; + +} // namespace Internal +} // namespace DeviceLayer +} // namespace chip