[ota] Restructure user consent files (#16549)
* [ota] Restructure user consent files
- Moved user consent related files to respective clusters
- Also, fixed an TODO to get requestor Node ID
* Rename the class names
diff --git a/examples/ota-provider-app/linux/main.cpp b/examples/ota-provider-app/linux/main.cpp
index 4764348..714fad6 100644
--- a/examples/ota-provider-app/linux/main.cpp
+++ b/examples/ota-provider-app/linux/main.cpp
@@ -16,13 +16,13 @@
* limitations under the License.
*/
+#include <app/clusters/ota-provider/DefaultOTAProviderUserConsent.h>
#include <app/clusters/ota-provider/ota-provider-delegate.h>
#include <app/clusters/ota-provider/ota-provider.h>
#include <app/server/Server.h>
#include <app/util/util.h>
#include <json/json.h>
#include <ota-provider-common/BdxOtaSender.h>
-#include <ota-provider-common/DefaultUserConsentProvider.h>
#include <ota-provider-common/OTAProviderExample.h>
#include "AppMain.h"
@@ -55,7 +55,7 @@
constexpr uint16_t kOptionUserConsentNeeded = 'c';
OTAProviderExample gOtaProvider;
-chip::ota::DefaultUserConsentProvider gUserConsentProvider;
+chip::ota::DefaultOTAProviderUserConsent gUserConsentProvider;
// Global variables used for passing the CLI arguments to the OTAProviderExample object
static OTAQueryStatus gQueryImageStatus = OTAQueryStatus::kUpdateAvailable;
diff --git a/examples/ota-provider-app/ota-provider-common/BUILD.gn b/examples/ota-provider-app/ota-provider-common/BUILD.gn
index 0ee36f4..63c5f2d 100644
--- a/examples/ota-provider-app/ota-provider-common/BUILD.gn
+++ b/examples/ota-provider-app/ota-provider-common/BUILD.gn
@@ -29,8 +29,6 @@
sources = [
"BdxOtaSender.cpp",
"BdxOtaSender.h",
- "DefaultUserConsentProvider.cpp",
- "DefaultUserConsentProvider.h",
"OTAProviderExample.cpp",
"OTAProviderExample.h",
]
diff --git a/examples/ota-provider-app/ota-provider-common/DefaultUserConsentProvider.cpp b/examples/ota-provider-app/ota-provider-common/DefaultUserConsentProvider.cpp
deleted file mode 100644
index 2c9d676..0000000
--- a/examples/ota-provider-app/ota-provider-common/DefaultUserConsentProvider.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- *
- * Copyright (c) 2022 Project CHIP Authors
- * All rights reserved.
- *
- * 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 <ota-provider-common/DefaultUserConsentProvider.h>
-
-namespace chip {
-namespace ota {
-
-UserConsentState DefaultUserConsentProvider::GetUserConsentState(const UserConsentSubject & subject)
-{
- subject.Log();
-
- if (mUseGlobalConsent)
- {
- // Reset mGlobalConsentState to success case after returning other possible values once.
- UserConsentState curGlobalConsentState = mGlobalConsentState;
- mGlobalConsentState = UserConsentState::kGranted;
- return curGlobalConsentState;
- }
-
- return UserConsentState::kGranted;
-}
-
-} // namespace ota
-} // namespace chip
diff --git a/examples/ota-provider-app/ota-provider-common/OTAProviderExample.h b/examples/ota-provider-app/ota-provider-common/OTAProviderExample.h
index 40c414b..60be91f 100644
--- a/examples/ota-provider-app/ota-provider-common/OTAProviderExample.h
+++ b/examples/ota-provider-app/ota-provider-common/OTAProviderExample.h
@@ -20,10 +20,10 @@
#include <app-common/zap-generated/cluster-objects.h>
#include <app/CommandHandler.h>
+#include <app/clusters/ota-provider/OTAProviderUserConsentDelegate.h>
#include <app/clusters/ota-provider/ota-provider-delegate.h>
#include <lib/core/OTAImageHeader.h>
#include <ota-provider-common/BdxOtaSender.h>
-#include <platform/UserConsentDelegate.h>
#include <vector>
/**
@@ -78,7 +78,7 @@
}
void SetDelayedQueryActionTimeSec(uint32_t time) { mDelayedQueryActionTimeSec = time; }
void SetDelayedApplyActionTimeSec(uint32_t time) { mDelayedApplyActionTimeSec = time; }
- void SetUserConsentDelegate(chip::ota::UserConsentDelegate * delegate) { mUserConsentDelegate = delegate; }
+ void SetUserConsentDelegate(chip::ota::OTAProviderUserConsentDelegate * delegate) { mUserConsentDelegate = delegate; }
void SetUserConsentNeeded(bool needed) { mUserConsentNeeded = needed; }
private:
@@ -106,7 +106,7 @@
uint32_t mIgnoreApplyUpdateCount;
uint32_t mDelayedQueryActionTimeSec;
uint32_t mDelayedApplyActionTimeSec;
- chip::ota::UserConsentDelegate * mUserConsentDelegate;
+ chip::ota::OTAProviderUserConsentDelegate * mUserConsentDelegate;
bool mUserConsentNeeded;
uint32_t mSoftwareVersion;
char mSoftwareVersionString[SW_VER_STR_MAX_LEN];
diff --git a/examples/ota-requestor-app/linux/main.cpp b/examples/ota-requestor-app/linux/main.cpp
index 4a3365d..e89525a 100644
--- a/examples/ota-requestor-app/linux/main.cpp
+++ b/examples/ota-requestor-app/linux/main.cpp
@@ -19,7 +19,7 @@
#include "AppMain.h"
#include <app/clusters/ota-requestor/BDXDownloader.h>
#include <app/clusters/ota-requestor/DefaultOTARequestorStorage.h>
-#include <app/clusters/ota-requestor/DefaultOTARequestorUserConsentProvider.h>
+#include <app/clusters/ota-requestor/DefaultOTARequestorUserConsent.h>
#include <app/clusters/ota-requestor/ExtendedOTARequestorDriver.h>
#include <app/clusters/ota-requestor/OTARequestor.h>
#include <platform/Linux/OTAImageProcessorImpl.h>
@@ -59,7 +59,7 @@
CustomOTARequestorDriver gRequestorUser;
BDXDownloader gDownloader;
OTAImageProcessorImpl gImageProcessor;
-chip::ota::DefaultOTARequestorUserConsentProvider gUserConsentProvider;
+chip::ota::DefaultOTARequestorUserConsent gUserConsentProvider;
static chip::ota::UserConsentState gUserConsentState = chip::ota::UserConsentState::kUnknown;
bool HandleOptions(const char * aProgram, OptionSet * aOptions, int aIdentifier, const char * aName, const char * aValue);
diff --git a/src/app/BUILD.gn b/src/app/BUILD.gn
index a04cd60..8f7f060 100644
--- a/src/app/BUILD.gn
+++ b/src/app/BUILD.gn
@@ -134,6 +134,7 @@
"MessageDef/TimedRequestMessage.cpp",
"MessageDef/WriteRequestMessage.cpp",
"MessageDef/WriteResponseMessage.cpp",
+ "OTAUserConsentCommon.h",
"OperationalDeviceProxy.cpp",
"OperationalDeviceProxy.h",
"OperationalDeviceProxyPool.h",
diff --git a/src/include/platform/UserConsentDelegate.h b/src/app/OTAUserConsentCommon.h
similarity index 84%
rename from src/include/platform/UserConsentDelegate.h
rename to src/app/OTAUserConsentCommon.h
index eb862b9..6bc66a4 100644
--- a/src/include/platform/UserConsentDelegate.h
+++ b/src/app/OTAUserConsentCommon.h
@@ -81,28 +81,5 @@
}
};
-class UserConsentDelegate
-{
-public:
- virtual ~UserConsentDelegate() = default;
-
- virtual UserConsentState GetUserConsentState(const UserConsentSubject & subject) = 0;
-
- const char * UserConsentStateToString(UserConsentState state)
- {
- switch (state)
- {
- case kGranted:
- return "Granted";
- case kObtaining:
- return "Obtaining";
- case kDenied:
- return "Denied";
- default:
- return "Unknown";
- }
- }
-};
-
} // namespace ota
} // namespace chip
diff --git a/src/app/chip_data_model.gni b/src/app/chip_data_model.gni
index bff61fa..185095d 100644
--- a/src/app/chip_data_model.gni
+++ b/src/app/chip_data_model.gni
@@ -134,7 +134,7 @@
"${_app_root}/clusters/${cluster}/BDXDownloader.h",
"${_app_root}/clusters/${cluster}/DefaultOTARequestorStorage.cpp",
"${_app_root}/clusters/${cluster}/DefaultOTARequestorStorage.h",
- "${_app_root}/clusters/${cluster}/DefaultOTARequestorUserConsentProvider.h",
+ "${_app_root}/clusters/${cluster}/DefaultOTARequestorUserConsent.h",
"${_app_root}/clusters/${cluster}/ExtendedOTARequestorDriver.cpp",
"${_app_root}/clusters/${cluster}/GenericOTARequestorDriver.cpp",
"${_app_root}/clusters/${cluster}/OTARequestor.cpp",
diff --git a/examples/ota-provider-app/ota-provider-common/DefaultUserConsentProvider.h b/src/app/clusters/ota-provider/DefaultOTAProviderUserConsent.h
similarity index 63%
rename from examples/ota-provider-app/ota-provider-common/DefaultUserConsentProvider.h
rename to src/app/clusters/ota-provider/DefaultOTAProviderUserConsent.h
index 09b4a28..ccc5ac9 100644
--- a/examples/ota-provider-app/ota-provider-common/DefaultUserConsentProvider.h
+++ b/src/app/clusters/ota-provider/DefaultOTAProviderUserConsent.h
@@ -17,21 +17,41 @@
*/
#pragma once
+#include <app/clusters/ota-provider/OTAProviderUserConsentDelegate.h>
#include <lib/core/CHIPError.h>
-#include <platform/UserConsentDelegate.h>
namespace chip {
namespace ota {
-class DefaultUserConsentProvider : public UserConsentDelegate
+/**
+ * @brief Default implementation of OTAProviderUserConsentDelegate interface.
+ *
+ * This class provides API to set the user consent state, and this state is then used by
+ * OTA Provider to send an apporpriate response to QueryImage request.
+ */
+
+class DefaultOTAProviderUserConsent : public OTAProviderUserConsentDelegate
{
public:
- DefaultUserConsentProvider() = default;
+ DefaultOTAProviderUserConsent() = default;
- ~DefaultUserConsentProvider() = default;
+ ~DefaultOTAProviderUserConsent() = default;
// This method returns kGranted unless explicitly set by the user by calling SetGlobalUserConsentState()
- UserConsentState GetUserConsentState(const UserConsentSubject & subject) override;
+ UserConsentState GetUserConsentState(const UserConsentSubject & subject) override
+ {
+ subject.Log();
+
+ if (mUseGlobalConsent)
+ {
+ // Reset mGlobalConsentState to success case after returning other possible values once.
+ UserConsentState curGlobalConsentState = mGlobalConsentState;
+ mGlobalConsentState = UserConsentState::kGranted;
+ return curGlobalConsentState;
+ }
+
+ return UserConsentState::kGranted;
+ }
// If this is set to true, all the user consent requests will be replied with global consent.
void SetGlobalUserConsentState(UserConsentState state)
diff --git a/src/include/platform/OTARequestorUserConsentDelegate.h b/src/app/clusters/ota-provider/OTAProviderUserConsentDelegate.h
similarity index 64%
copy from src/include/platform/OTARequestorUserConsentDelegate.h
copy to src/app/clusters/ota-provider/OTAProviderUserConsentDelegate.h
index 2418405..fb8869f 100644
--- a/src/include/platform/OTARequestorUserConsentDelegate.h
+++ b/src/app/clusters/ota-provider/OTAProviderUserConsentDelegate.h
@@ -16,21 +16,32 @@
* limitations under the License.
*/
#pragma once
-#include <platform/UserConsentDelegate.h>
+#include <app/OTAUserConsentCommon.h>
namespace chip {
namespace ota {
-class OTARequestorUserConsentDelegate : public UserConsentDelegate
+class OTAProviderUserConsentDelegate
{
public:
- virtual ~OTARequestorUserConsentDelegate() = default;
+ virtual ~OTAProviderUserConsentDelegate() = default;
virtual UserConsentState GetUserConsentState(const UserConsentSubject & subject) = 0;
- // When GetUserConsentState() returns kObtaining this will be called to
- // check if the user consent is granted or denied.
- virtual UserConsentState CheckDeferredUserConsentState() = 0;
+ const char * UserConsentStateToString(UserConsentState state)
+ {
+ switch (state)
+ {
+ case kGranted:
+ return "Granted";
+ case kObtaining:
+ return "Obtaining";
+ case kDenied:
+ return "Denied";
+ default:
+ return "Unknown";
+ }
+ }
};
} // namespace ota
diff --git a/src/app/clusters/ota-requestor/DefaultOTARequestorUserConsentProvider.h b/src/app/clusters/ota-requestor/DefaultOTARequestorUserConsent.h
similarity index 74%
rename from src/app/clusters/ota-requestor/DefaultOTARequestorUserConsentProvider.h
rename to src/app/clusters/ota-requestor/DefaultOTARequestorUserConsent.h
index d75d6a5..c56fde4 100644
--- a/src/app/clusters/ota-requestor/DefaultOTARequestorUserConsentProvider.h
+++ b/src/app/clusters/ota-requestor/DefaultOTARequestorUserConsent.h
@@ -17,18 +17,25 @@
*/
#pragma once
+#include <app/clusters/ota-requestor/OTARequestorUserConsentDelegate.h>
#include <lib/core/CHIPError.h>
-#include <platform/OTARequestorUserConsentDelegate.h>
namespace chip {
namespace ota {
-class DefaultOTARequestorUserConsentProvider : public OTARequestorUserConsentDelegate
+/**
+ * @brief Default implementation of OTARequestorUserConsentDelegate interface.
+ *
+ * This class provides API to set the user consent state, and this state is then used by
+ * OTA Requestor Driver to decide whether to continue with the OTA process.
+ */
+
+class DefaultOTARequestorUserConsent : public OTARequestorUserConsentDelegate
{
public:
- DefaultOTARequestorUserConsentProvider() = default;
+ DefaultOTARequestorUserConsent() = default;
- ~DefaultOTARequestorUserConsentProvider() = default;
+ ~DefaultOTARequestorUserConsent() = default;
// This method returns kGranted unless explicitly set by the user by calling SetUserConsentState()
UserConsentState GetUserConsentState(const UserConsentSubject & subject) override
diff --git a/src/app/clusters/ota-requestor/ExtendedOTARequestorDriver.cpp b/src/app/clusters/ota-requestor/ExtendedOTARequestorDriver.cpp
index ca5acb3..752dd23 100644
--- a/src/app/clusters/ota-requestor/ExtendedOTARequestorDriver.cpp
+++ b/src/app/clusters/ota-requestor/ExtendedOTARequestorDriver.cpp
@@ -17,6 +17,7 @@
#include "ExtendedOTARequestorDriver.h"
#include "OTARequestorInterface.h"
+#include <app/server/Server.h>
namespace chip {
namespace DeviceLayer {
@@ -81,7 +82,13 @@
return CHIP_ERROR_INTERNAL;
}
- // TODO: As we cannot use the src/app/Server.h in here so, figure out a way to get the node id.
+ FabricInfo * fabricInfo = Server::GetInstance().GetFabricTable().FindFabricWithIndex(subject.fabricIndex);
+ if (fabricInfo == nullptr)
+ {
+ ChipLogError(SoftwareUpdate, "Cannot find fabric");
+ return CHIP_ERROR_INTERNAL;
+ }
+ subject.requestorNodeId = fabricInfo->GetPeerId().GetNodeId();
ReturnErrorOnFailure(DeviceLayer::ConfigurationMgr().GetVendorId(subject.requestorVendorId));
ReturnErrorOnFailure(DeviceLayer::ConfigurationMgr().GetProductId(subject.requestorProductId));
diff --git a/src/app/clusters/ota-requestor/ExtendedOTARequestorDriver.h b/src/app/clusters/ota-requestor/ExtendedOTARequestorDriver.h
index f4ef1d9..82bbc96 100644
--- a/src/app/clusters/ota-requestor/ExtendedOTARequestorDriver.h
+++ b/src/app/clusters/ota-requestor/ExtendedOTARequestorDriver.h
@@ -15,8 +15,8 @@
* limitations under the License.
*/
#pragma once
+#include <app/clusters/ota-requestor/OTARequestorUserConsentDelegate.h>
#include <platform/CHIPDeviceLayer.h>
-#include <platform/OTARequestorUserConsentDelegate.h>
#include "GenericOTARequestorDriver.h"
diff --git a/src/include/platform/OTARequestorUserConsentDelegate.h b/src/app/clusters/ota-requestor/OTARequestorUserConsentDelegate.h
similarity index 73%
rename from src/include/platform/OTARequestorUserConsentDelegate.h
rename to src/app/clusters/ota-requestor/OTARequestorUserConsentDelegate.h
index 2418405..155f72d 100644
--- a/src/include/platform/OTARequestorUserConsentDelegate.h
+++ b/src/app/clusters/ota-requestor/OTARequestorUserConsentDelegate.h
@@ -16,12 +16,12 @@
* limitations under the License.
*/
#pragma once
-#include <platform/UserConsentDelegate.h>
+#include <app/OTAUserConsentCommon.h>
namespace chip {
namespace ota {
-class OTARequestorUserConsentDelegate : public UserConsentDelegate
+class OTARequestorUserConsentDelegate
{
public:
virtual ~OTARequestorUserConsentDelegate() = default;
@@ -31,6 +31,21 @@
// When GetUserConsentState() returns kObtaining this will be called to
// check if the user consent is granted or denied.
virtual UserConsentState CheckDeferredUserConsentState() = 0;
+
+ const char * UserConsentStateToString(UserConsentState state)
+ {
+ switch (state)
+ {
+ case kGranted:
+ return "Granted";
+ case kObtaining:
+ return "Obtaining";
+ case kDenied:
+ return "Denied";
+ default:
+ return "Unknown";
+ }
+ }
};
} // namespace ota