Skip to content

Commit 0966a01

Browse files
authored
Merge branch 'master' into add_presets_to_Sdk
2 parents 627e3f6 + bbef51a commit 0966a01

File tree

15 files changed

+782
-625
lines changed

15 files changed

+782
-625
lines changed

.github/workflows/tests.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ jobs:
551551
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_FAN_3_5.py'
552552
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_ICDM_2_1.py'
553553
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_ICDM_3_1.py'
554+
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_ICDM_3_3.py'
554555
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_ICDManagementCluster.py'
555556
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_IDM_1_2.py'
556557
scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --load-from-env /tmp/test_env.yaml --script src/python_testing/TC_IDM_1_4.py'

examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/utils/ResourceUtils.java

+36-31
Original file line numberDiff line numberDiff line change
@@ -58,38 +58,43 @@ public Set<SupportedCluster> getSupportedClusters(final Resources resources, fin
5858
SupportedCluster cluster = new SupportedCluster();
5959
while (reader.hasNext()) {
6060
String name = reader.nextName();
61-
if (name.equals(KEY_CLUSTER_ID)) {
62-
cluster.clusterIdentifier = reader.nextInt();
63-
} else if (name.equals(KEY_FEATURE_FLAGS)) {
64-
cluster.features = reader.nextInt();
65-
} else if (name.equals(KEY_OPTIONAL_COMMANDS)) {
66-
List<Integer> commands = new ArrayList<>();
67-
reader.beginArray();
68-
while (reader.hasNext()) {
69-
commands.add(reader.nextInt());
61+
try {
62+
if (name.equals(KEY_CLUSTER_ID)) {
63+
cluster.clusterIdentifier = reader.nextInt();
64+
} else if (name.equals(KEY_FEATURE_FLAGS)) {
65+
cluster.features = reader.nextInt();
66+
} else if (name.equals(KEY_OPTIONAL_COMMANDS)) {
67+
List<Integer> commands = new ArrayList<>();
68+
reader.beginArray();
69+
while (reader.hasNext()) {
70+
commands.add(reader.nextInt());
71+
}
72+
reader.endArray();
73+
int[] commandIds = new int[commands.size()];
74+
int i = 0;
75+
for (Integer command : commands) {
76+
commandIds[i++] = command;
77+
}
78+
cluster.optionalCommandIdentifiers = commandIds;
79+
} else if (name.equals(KEY_OPTIONAL_ATTRIBUTES)) {
80+
List<Integer> attributes = new ArrayList<>();
81+
reader.beginArray();
82+
while (reader.hasNext()) {
83+
attributes.add(reader.nextInt());
84+
}
85+
reader.endArray();
86+
int[] attributeIds = new int[attributes.size()];
87+
int i = 0;
88+
for (Integer command : attributes) {
89+
attributeIds[i++] = command;
90+
}
91+
cluster.optionalAttributesIdentifiers = attributeIds;
92+
} else {
93+
reader.skipValue();
7094
}
71-
reader.endArray();
72-
int[] commandIds = new int[commands.size()];
73-
int i = 0;
74-
for (Integer command : commands) {
75-
commandIds[i++] = command;
76-
}
77-
cluster.optionalCommandIdentifiers = commandIds;
78-
} else if (name.equals(KEY_OPTIONAL_ATTRIBUTES)) {
79-
List<Integer> attributes = new ArrayList<>();
80-
reader.beginArray();
81-
while (reader.hasNext()) {
82-
attributes.add(reader.nextInt());
83-
}
84-
reader.endArray();
85-
int[] attributeIds = new int[attributes.size()];
86-
int i = 0;
87-
for (Integer command : attributes) {
88-
attributeIds[i++] = command;
89-
}
90-
cluster.optionalAttributesIdentifiers = attributeIds;
91-
} else {
92-
reader.skipValue();
95+
} catch (NumberFormatException | IllegalStateException e) {
96+
Log.e(TAG, "Invalid number format in JSON for key: " + name, e);
97+
reader.skipValue(); // Skip the invalid entry
9398
}
9499
}
95100
supportedClusters.add(cluster);

examples/tv-app/android/java/ContentAppCommandDelegate.cpp

+39
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,26 @@ Status ContentAppCommandDelegate::InvokeCommand(EndpointId epId, ClusterId clust
133133
JniUtfString respStr(env, resp);
134134
ChipLogProgress(Zcl, "ContentAppCommandDelegate::InvokeCommand got response %s", respStr.c_str());
135135

136+
Json::CharReaderBuilder readerBuilder;
137+
std::string errors;
138+
139+
std::unique_ptr<Json::CharReader> testReader(readerBuilder.newCharReader());
140+
141+
if (!testReader->parse(respStr.c_str(), respStr.c_str() + std::strlen(respStr.c_str()), &value, &errors))
142+
{
143+
ChipLogError(Zcl, "Failed to parse JSON: %s\n", errors.c_str());
144+
env->DeleteLocalRef(resp);
145+
return chip::Protocols::InteractionModel::Status::Failure;
146+
}
147+
148+
// Validate and access JSON data safely
149+
if (!value.isObject())
150+
{
151+
ChipLogError(Zcl, "Invalid JSON structure: not an object");
152+
env->DeleteLocalRef(resp);
153+
return chip::Protocols::InteractionModel::Status::Failure;
154+
}
155+
136156
Json::Reader reader;
137157
if (!reader.parse(respStr.c_str(), value))
138158
{
@@ -166,7 +186,26 @@ void ContentAppCommandDelegate::FormatResponseData(CommandHandlerInterface::Hand
166186
{
167187
handlerContext.SetCommandHandled();
168188
Json::Reader reader;
189+
190+
Json::CharReaderBuilder readerBuilder;
191+
std::string errors;
192+
169193
Json::Value value;
194+
std::unique_ptr<Json::CharReader> testReader(readerBuilder.newCharReader());
195+
196+
if (!testReader->parse(response, response + std::strlen(response), &value, &errors))
197+
{
198+
ChipLogError(Zcl, "Failed to parse JSON: %s\n", errors.c_str());
199+
return;
200+
}
201+
202+
// Validate and access JSON data safely
203+
if (!value.isObject())
204+
{
205+
ChipLogError(Zcl, "Invalid JSON structure: not an object");
206+
return;
207+
}
208+
170209
if (!reader.parse(response, value))
171210
{
172211
return;

src/app/clusters/ecosystem-information-server/ecosystem-information-server.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ CHIP_ERROR AttrAccess::Read(const ConcreteReadAttributePath & aPath, AttributeVa
6666
// TODO(#33223) To improve safety we could make GetEncodableLocationDescriptorStruct a private
6767
// memeber method where we explicitly delete member method for the parameter that matches
6868
// (LocationDescriptorStruct && aLocationDescriptor).
69-
Structs::LocationDescriptorStruct::Type GetEncodableLocationDescriptorStruct(const LocationDescriptorStruct & aLocationDescriptor)
69+
Globals::Structs::LocationDescriptorStruct::Type
70+
GetEncodableLocationDescriptorStruct(const LocationDescriptorStruct & aLocationDescriptor)
7071
{
71-
Structs::LocationDescriptorStruct::Type locationDescriptor;
72+
Globals::Structs::LocationDescriptorStruct::Type locationDescriptor;
7273
// This would imply data is either not properly validated before being
7374
// stored here or corruption has occurred.
7475
VerifyOrDie(!aLocationDescriptor.mLocationName.empty());
@@ -199,7 +200,8 @@ EcosystemLocationStruct::Builder & EcosystemLocationStruct::Builder::SetFloorNum
199200
return *this;
200201
}
201202

202-
EcosystemLocationStruct::Builder & EcosystemLocationStruct::Builder::SetAreaTypeTag(std::optional<AreaTypeTag> aAreaTypeTag)
203+
EcosystemLocationStruct::Builder &
204+
EcosystemLocationStruct::Builder::SetAreaTypeTag(std::optional<Globals::AreaTypeTag> aAreaTypeTag)
203205
{
204206
VerifyOrDie(!mIsAlreadyBuilt);
205207
mLocationDescriptor.mAreaType = aAreaTypeTag;

src/app/clusters/ecosystem-information-server/ecosystem-information-server.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ struct LocationDescriptorStruct
9696
{
9797
std::string mLocationName;
9898
std::optional<int16_t> mFloorNumber;
99-
std::optional<AreaTypeTag> mAreaType;
99+
std::optional<Globals::AreaTypeTag> mAreaType;
100100
};
101101

102102
// This intentionally mirrors Structs::EcosystemLocationStruct::Type but has ownership
@@ -111,7 +111,7 @@ class EcosystemLocationStruct
111111

112112
Builder & SetLocationName(std::string aLocationName);
113113
Builder & SetFloorNumber(std::optional<int16_t> aFloorNumber);
114-
Builder & SetAreaTypeTag(std::optional<AreaTypeTag> aAreaTypeTag);
114+
Builder & SetAreaTypeTag(std::optional<Globals::AreaTypeTag> aAreaTypeTag);
115115
Builder & SetLocationDescriptorLastEdit(uint64_t aLocationDescriptorLastEditEpochUs);
116116

117117
// Upon success this object will have moved all ownership of underlying

src/app/clusters/on-off-server/on-off-server.cpp

+47-27
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,16 @@
4545
#endif // MATTER_DM_PLUGIN_MODE_BASE
4646

4747
#include <platform/CHIPDeviceLayer.h>
48+
#include <platform/DiagnosticDataProvider.h>
4849
#include <platform/PlatformManager.h>
4950

5051
using namespace chip;
5152
using namespace chip::app::Clusters;
5253
using namespace chip::app::Clusters::OnOff;
5354
using chip::Protocols::InteractionModel::Status;
5455

56+
using BootReasonType = GeneralDiagnostics::BootReasonEnum;
57+
5558
namespace {
5659

5760
#ifdef MATTER_DM_PLUGIN_MODE_BASE
@@ -95,6 +98,22 @@ bool IsKnownEnumValue(EnumType value)
9598
return (EnsureKnownEnumValue(value) != EnumType::kUnknownEnumValue);
9699
}
97100

101+
BootReasonType GetBootReason()
102+
{
103+
BootReasonType bootReason = BootReasonType::kUnspecified;
104+
105+
CHIP_ERROR error = DeviceLayer::GetDiagnosticDataProvider().GetBootReason(bootReason);
106+
if (error != CHIP_NO_ERROR)
107+
{
108+
ChipLogError(Zcl, "Unable to retrieve boot reason: %" CHIP_ERROR_FORMAT, error.Format());
109+
bootReason = BootReasonType::kUnspecified;
110+
}
111+
112+
ChipLogProgress(Zcl, "Boot reason: %u", to_underlying(bootReason));
113+
114+
return bootReason;
115+
}
116+
98117
} // namespace
99118

100119
#ifdef MATTER_DM_PLUGIN_LEVEL_CONTROL
@@ -537,35 +556,36 @@ Status OnOffServer::getOnOffValueForStartUp(chip::EndpointId endpoint, bool & on
537556
{
538557
app::DataModel::Nullable<OnOff::StartUpOnOffEnum> startUpOnOff;
539558
Status status = Attributes::StartUpOnOff::Get(endpoint, startUpOnOff);
540-
if (status == Status::Success)
559+
VerifyOrReturnError(status == Status::Success, status);
560+
561+
bool currentOnOff = false;
562+
status = Attributes::OnOff::Get(endpoint, &currentOnOff);
563+
VerifyOrReturnError(status == Status::Success, status);
564+
565+
if (startUpOnOff.IsNull() || GetBootReason() == BootReasonType::kSoftwareUpdateCompleted)
541566
{
542-
// Initialise updated value to 0
543-
bool updatedOnOff = false;
544-
status = Attributes::OnOff::Get(endpoint, &updatedOnOff);
545-
if (status == Status::Success)
546-
{
547-
if (!startUpOnOff.IsNull())
548-
{
549-
switch (startUpOnOff.Value())
550-
{
551-
case OnOff::StartUpOnOffEnum::kOff:
552-
updatedOnOff = false; // Off
553-
break;
554-
case OnOff::StartUpOnOffEnum::kOn:
555-
updatedOnOff = true; // On
556-
break;
557-
case OnOff::StartUpOnOffEnum::kToggle:
558-
updatedOnOff = !updatedOnOff;
559-
break;
560-
default:
561-
// All other values 0x03- 0xFE are reserved - no action.
562-
break;
563-
}
564-
}
565-
onOffValueForStartUp = updatedOnOff;
566-
}
567+
onOffValueForStartUp = currentOnOff;
568+
return Status::Success;
567569
}
568-
return status;
570+
571+
switch (startUpOnOff.Value())
572+
{
573+
case OnOff::StartUpOnOffEnum::kOff:
574+
onOffValueForStartUp = false; // Off
575+
break;
576+
case OnOff::StartUpOnOffEnum::kOn:
577+
onOffValueForStartUp = true; // On
578+
break;
579+
case OnOff::StartUpOnOffEnum::kToggle:
580+
onOffValueForStartUp = !currentOnOff;
581+
break;
582+
default:
583+
// All other values 0x03- 0xFE are reserved - no action.
584+
onOffValueForStartUp = currentOnOff;
585+
break;
586+
}
587+
588+
return Status::Success;
569589
}
570590

571591
bool OnOffServer::offCommand(app::CommandHandler * commandObj, const app::ConcreteCommandPath & commandPath)

0 commit comments

Comments
 (0)