Skip to content

Commit

Permalink
[Android] Add to get DeviceTypeId, DeviceName on Android app server (#…
Browse files Browse the repository at this point in the history
…28742)

* add custom configuration for android (DeviceTypeId, DeviceName)

Signed-off-by: Jaehoon You <[email protected]>
Signed-off-by: Charles Kim <[email protected]>

* Restyled by clang-format

Signed-off-by: Charles Kim <[email protected]>

---------

Signed-off-by: Jaehoon You <[email protected]>
Signed-off-by: Charles Kim <[email protected]>
Co-authored-by: Jaehoon You <[email protected]>
Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
3 people authored and pull[bot] committed Jan 27, 2024
1 parent 5859969 commit 1443858
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/platform/android/AndroidConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ const AndroidConfig::Key AndroidConfig::kConfigKey_UniqueId = { kCo
const AndroidConfig::Key AndroidConfig::kConfigKey_Spake2pIterationCount = { kConfigNamespace_ChipFactory, "iteration-count" };
const AndroidConfig::Key AndroidConfig::kConfigKey_Spake2pSalt = { kConfigNamespace_ChipFactory, "salt" };
const AndroidConfig::Key AndroidConfig::kConfigKey_Spake2pVerifier = { kConfigNamespace_ChipFactory, "verifier" };
const AndroidConfig::Key AndroidConfig::kConfigKey_DeviceTypeId = { kConfigNamespace_ChipFactory, "device-type-id" };
const AndroidConfig::Key AndroidConfig::kConfigKey_DeviceName = { kConfigNamespace_ChipFactory, "device-name" };

// Keys stored in the Chip-config namespace
const AndroidConfig::Key AndroidConfig::kConfigKey_ServiceConfig = { kConfigNamespace_ChipConfig, "service-config" };
Expand Down
2 changes: 2 additions & 0 deletions src/platform/android/AndroidConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class AndroidConfig
static const Key kConfigKey_Spake2pIterationCount;
static const Key kConfigKey_Spake2pSalt;
static const Key kConfigKey_Spake2pVerifier;
static const Key kConfigKey_DeviceTypeId;
static const Key kConfigKey_DeviceName;

static CHIP_ERROR Init();

Expand Down
33 changes: 33 additions & 0 deletions src/platform/android/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,39 @@ CHIP_ERROR ConfigurationManagerImpl::GetUniqueId(char * buf, size_t bufSize)
return ReadConfigValueStr(AndroidConfig::kConfigKey_UniqueId, buf, bufSize, dateLen);
}

CHIP_ERROR ConfigurationManagerImpl::GetDeviceTypeId(uint32_t & deviceType)
{
CHIP_ERROR err;
uint32_t u32DeviceTypeId = 0;
err = ReadConfigValue(AndroidConfig::kConfigKey_DeviceTypeId, u32DeviceTypeId);

if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND)
{
deviceType = CHIP_DEVICE_CONFIG_DEVICE_TYPE;
}
else
{
deviceType = u32DeviceTypeId;
}

return CHIP_NO_ERROR;
}

CHIP_ERROR ConfigurationManagerImpl::GetCommissionableDeviceName(char * buf, size_t bufSize)
{
CHIP_ERROR err;
size_t u32DeviceNameSize = 0;
err = ReadConfigValueStr(AndroidConfig::kConfigKey_DeviceName, buf, bufSize, u32DeviceNameSize);

if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND)
{
ReturnErrorCodeIf(bufSize < sizeof(CHIP_DEVICE_CONFIG_DEVICE_NAME), CHIP_ERROR_BUFFER_TOO_SMALL);
strcpy(buf, CHIP_DEVICE_CONFIG_DEVICE_NAME);
}

return CHIP_NO_ERROR;
}

ConfigurationManager & ConfigurationMgrImpl()
{
return ConfigurationManagerImpl::GetDefaultInstance();
Expand Down
2 changes: 2 additions & 0 deletions src/platform/android/ConfigurationManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp
CHIP_ERROR GetSoftwareVersionString(char * buf, size_t bufSize) override;
CHIP_ERROR GetSoftwareVersion(uint32_t & softwareVer) override;
CHIP_ERROR GetUniqueId(char * buf, size_t bufSize) override;
CHIP_ERROR GetDeviceTypeId(uint32_t & deviceType) override;
CHIP_ERROR GetCommissionableDeviceName(char * buf, size_t bufSize) override;

private:
// ===== Members that implement the ConfigurationManager public interface.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public interface ConfigurationManager {
String kConfigKey_Spake2pIterationCount = "iteration-count";
String kConfigKey_Spake2pSalt = "salt";
String kConfigKey_Spake2pVerifier = "verifier";
String kConfigKey_DeviceTypeId = "device-type-id";
String kConfigKey_DeviceName = "device-name";

// Keys stored in the Chip-config namespace
String kConfigKey_ServiceConfig = "service-config";
Expand Down

0 comments on commit 1443858

Please sign in to comment.