diff --git a/src/app/clusters/scenes/ExtensionFieldSetsImpl.cpp b/src/app/clusters/scenes/ExtensionFieldSetsImpl.cpp index 6e2817ba6b6709..f50bf4f58f257d 100644 --- a/src/app/clusters/scenes/ExtensionFieldSetsImpl.cpp +++ b/src/app/clusters/scenes/ExtensionFieldSetsImpl.cpp @@ -57,6 +57,10 @@ CHIP_ERROR ExtensionFieldSetsImpl::Deserialize(TLV::TLVReader & reader, TLV::Tag } mFieldSetsCount = i; + // In the event of an OTA where the maximum number of cluster per scene has been reduced, the extension field set will be + // considered "corrupted" if we don't manage to load it all (if err == CHIP_NO_ERROR after the loop). We therefore return an + // error and this scene will have to be deleted. This is done because truncating an EFS doesn't garrantee the order of the + // clusters loaded, which might allow to load clusters that are no longer supported and loosing supported ones. if (err != CHIP_END_OF_TLV) { if (err == CHIP_NO_ERROR) diff --git a/src/app/clusters/scenes/SceneTableImpl.cpp b/src/app/clusters/scenes/SceneTableImpl.cpp index a919283ff9a08b..19b9a2994151f3 100644 --- a/src/app/clusters/scenes/SceneTableImpl.cpp +++ b/src/app/clusters/scenes/SceneTableImpl.cpp @@ -226,6 +226,9 @@ struct FabricSceneData : public PersistentData i++; } + // In the event of an OTA, is kMaxScenesPerFabric was reduced, err will be equal to CHIP_NO_ERROR. We close the TLV with + // only the acceptable number of scenes and the next save will take care of reducing the memory usage of the map. This + // allows the user to preserve their scenes in between OTA updates. VerifyOrReturnError(err == CHIP_END_OF_TLV || err == CHIP_NO_ERROR, err); ReturnErrorOnFailure(reader.ExitContainer(sceneMapContainer)); diff --git a/src/app/tests/TestSceneTable.cpp b/src/app/tests/TestSceneTable.cpp index cb054418295457..45d0ca7c840171 100644 --- a/src/app/tests/TestSceneTable.cpp +++ b/src/app/tests/TestSceneTable.cpp @@ -435,7 +435,6 @@ void TestHandlerRegistration(nlTestSuite * aSuite, void * aContext) void TestHandlerFunctions(nlTestSuite * aSuite, void * aContext) { SceneTable * sceneTable = &sSceneTable; - ClusterId tempCluster = 0; app::Clusters::Scenes::Structs::ExtensionFieldSet::Type extensionFieldSetOut; app::Clusters::Scenes::Structs::ExtensionFieldSet::DecodableType extensionFieldSetIn;