-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OTA-Provider: Implementation for obtaining user consent (#13816)
* ota-provider: Implementation for obtaining user consent * ota-provider: Support for user consent in linux app * Added an API SourceNodeId() in CommandHandler Using PRIu16 for logging endpoint and ChipLogFormatX64/ChipLogValueX64 for logging Node Id. Use Clock::Seconds32 insetead of Clock::Milliseconds32 * Modified the UserConsent delegate and added default implementation UserConsent is not a SHALL so, using it when its available. Default implementation returns true by default, also added APIs to grant and revoke the UserConsent. * Do not crash if it's a group session * Keep supporting query behaviour option and set DelayedActionTime in Busy and NotAvailable Case * restyled * Fixing error after resolving merge conflict * Remove unnecessary chip:: resolution usage * Use GetSubjectDescriptor() to get SourceNodeId * Addressed review comments * minor changes * Addressed review comments and removed per subject handling, for now supporting only global user consent poliy.
- Loading branch information
Showing
8 changed files
with
380 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
examples/ota-provider-app/ota-provider-common/DefaultUserConsentProvider.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* | ||
* 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 <lib/support/logging/CHIPLogging.h> | ||
#include <ota-provider-common/DefaultUserConsentProvider.h> | ||
|
||
namespace chip { | ||
namespace ota { | ||
|
||
void DefaultUserConsentProvider::LogUserConsentSubject(const UserConsentSubject & subject) | ||
{ | ||
ChipLogDetail(SoftwareUpdate, "User consent request for:"); | ||
ChipLogDetail(SoftwareUpdate, ": FabricIndex: %" PRIu8, subject.fabricIndex); | ||
ChipLogDetail(SoftwareUpdate, ": RequestorNodeId: " ChipLogFormatX64, ChipLogValueX64(subject.requestorNodeId)); | ||
ChipLogDetail(SoftwareUpdate, ": ProviderEndpointId: %" PRIu16, subject.providerEndpointId); | ||
ChipLogDetail(SoftwareUpdate, ": RequestorVendorId: %" PRIu16, subject.requestorVendorId); | ||
ChipLogDetail(SoftwareUpdate, ": RequestorProductId: %" PRIu16, subject.requestorProductId); | ||
ChipLogDetail(SoftwareUpdate, ": RequestorCurrentVersion: %" PRIu32, subject.requestorCurrentVersion); | ||
ChipLogDetail(SoftwareUpdate, ": RequestorTargetVersion: %" PRIu32, subject.requestorTargetVersion); | ||
ChipLogDetail(SoftwareUpdate, ": Metadata:"); | ||
ChipLogByteSpan(SoftwareUpdate, subject.metadata); | ||
} | ||
|
||
UserConsentState DefaultUserConsentProvider::GetUserConsentState(const UserConsentSubject & subject) | ||
{ | ||
LogUserConsentSubject(subject); | ||
|
||
if (mUseGlobalConsent) | ||
{ | ||
return mGlobalConsentState; | ||
} | ||
|
||
return UserConsentState::kGranted; | ||
} | ||
|
||
} // namespace ota | ||
} // namespace chip |
62 changes: 62 additions & 0 deletions
62
examples/ota-provider-app/ota-provider-common/DefaultUserConsentProvider.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* | ||
* 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. | ||
*/ | ||
#pragma once | ||
|
||
#include <lib/core/CHIPError.h> | ||
#include <ota-provider-common/UserConsentDelegate.h> | ||
|
||
namespace chip { | ||
namespace ota { | ||
|
||
class DefaultUserConsentProvider : public UserConsentDelegate | ||
{ | ||
public: | ||
DefaultUserConsentProvider() = default; | ||
|
||
~DefaultUserConsentProvider() = default; | ||
|
||
// This method returns kGranted unless explicitly denied by the user by calling RevokeUserConsent() | ||
UserConsentState GetUserConsentState(const UserConsentSubject & subject) override; | ||
|
||
// If this is set to true, all the user consent requests will be replied with global consent. | ||
void SetGlobalUserConsentState(UserConsentState state) | ||
{ | ||
mUseGlobalConsent = true; | ||
mGlobalConsentState = state; | ||
} | ||
|
||
// state is only valid if isGlobalConsentSet is true | ||
void GetGlobalUserConsentState(bool & isGlobalConsentSet, UserConsentState & state) | ||
{ | ||
isGlobalConsentSet = mUseGlobalConsent; | ||
state = mGlobalConsentState; | ||
} | ||
|
||
// Clear the global user consent state | ||
void ClearGlobalUserConsentState() { mUseGlobalConsent = false; } | ||
|
||
private: | ||
bool mUseGlobalConsent = false; | ||
|
||
UserConsentState mGlobalConsentState = UserConsentState::kGranted; | ||
|
||
void LogUserConsentSubject(const UserConsentSubject & subject); | ||
}; | ||
|
||
} // namespace ota | ||
} // namespace chip |
Oops, something went wrong.