Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android]Enable OTA Provider in Android controller #28316

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/java-matter-controller/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ chip_project_config_include_dirs =
[ "${chip_root}/examples/java-matter-controller/include" ]
chip_project_config_include_dirs += [ "${chip_root}/config/standalone" ]
chip_stack_lock_tracking = "fatal"
chip_build_controller_dynamic_server = true
18 changes: 16 additions & 2 deletions src/app/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@

import("//build_overrides/chip.gni")
import("//build_overrides/nlio.gni")
import("${chip_root}/src/platform/device.gni")

import("${chip_root}/build/chip/buildconfig_header.gni")
import("${chip_root}/src/platform/device.gni")
import("common_flags.gni")
import("icd/icd.gni")

Expand Down Expand Up @@ -209,6 +208,21 @@ static_library("app") {
]
}

if (chip_build_controller_dynamic_server) {
defines = [
"CHIP_CONFIG_SKIP_APP_SPECIFIC_GENERATED_HEADER_INCLUDES=1",
"CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT=1",
]
sources += [
"clusters/ota-provider/ota-provider.cpp",
"dynamic_server/AccessControl.cpp",
"dynamic_server/AccessControl.h",
"dynamic_server/DynamicDispatcher.cpp",
"util/privilege-storage.cpp",
"util/privilege-storage.h",
]
}

if (chip_enable_read_client) {
sources += [
"BufferedReadCallback.cpp",
Expand Down
1 change: 1 addition & 0 deletions src/app/common_flags.gni
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ declare_args() {
# Temporary flag for interaction model and echo protocols, set it to true to enable
chip_app_use_echo = false
chip_enable_read_client = true
chip_build_controller_dynamic_server = false
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2022 Project CHIP Authors
* Copyright (c) 2022-2023 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,7 @@
* limitations under the License.
*/

#import "MTRControllerAccessControl.h"
#include "AccessControl.h"

#include <access/AccessControl.h>
#include <access/Privilege.h>
Expand All @@ -30,10 +30,11 @@

namespace {
// TODO: Maybe consider making this configurable? See also
// CHIPIMDispatch.mm.
// DynamicDispatch.cpp.
constexpr EndpointId kSupportedEndpoint = 0;

class DeviceTypeResolver : public Access::AccessControl::DeviceTypeResolver {
class DeviceTypeResolver : public Access::AccessControl::DeviceTypeResolver
{
public:
bool IsDeviceTypeOnEndpoint(DeviceTypeId deviceType, EndpointId endpoint) override
{
Expand All @@ -42,22 +43,26 @@ bool IsDeviceTypeOnEndpoint(DeviceTypeId deviceType, EndpointId endpoint) overri
} gDeviceTypeResolver;

// TODO: Make the policy more configurable by consumers.
class AccessControlDelegate : public Access::AccessControl::Delegate {
CHIP_ERROR Check(
const SubjectDescriptor & subjectDescriptor, const RequestPath & requestPath, Privilege requestPrivilege) override
class AccessControlDelegate : public Access::AccessControl::Delegate
{
CHIP_ERROR Check(const SubjectDescriptor & subjectDescriptor, const RequestPath & requestPath,
Privilege requestPrivilege) override
{
if (requestPath.endpoint != kSupportedEndpoint || requestPath.cluster != OtaSoftwareUpdateProvider::Id) {
if (requestPath.endpoint != kSupportedEndpoint || requestPath.cluster != OtaSoftwareUpdateProvider::Id)
{
// We only allow access to OTA software update provider.
return CHIP_ERROR_ACCESS_DENIED;
}

if (requestPrivilege != Privilege::kOperate) {
if (requestPrivilege != Privilege::kOperate)
{
// The commands on OtaSoftwareUpdateProvider all require
// Operate; we should not be asked for anything else.
return CHIP_ERROR_ACCESS_DENIED;
}

if (subjectDescriptor.authMode != AuthMode::kCase && subjectDescriptor.authMode != AuthMode::kPase) {
if (subjectDescriptor.authMode != AuthMode::kCase && subjectDescriptor.authMode != AuthMode::kPase)
{
// No idea who is asking; deny for now.
return CHIP_ERROR_ACCESS_DENIED;
}
Expand All @@ -71,14 +76,13 @@ CHIP_ERROR Check(
AccessControlDelegate gDelegate;
} // anonymous namespace

@implementation MTRControllerAccessControl

+ (void)init
namespace chip {
namespace app {
namespace dynamic_server {
void InitAccessControl()
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
GetAccessControl().Init(&gDelegate, gDeviceTypeResolver);
});
GetAccessControl().Init(&gDelegate, gDeviceTypeResolver);
}

@end
} // namespace dynamic_server
} // namespace app
} // namespace chip
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2022 Project CHIP Authors
* Copyright (c) 2022-2023 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,24 +15,16 @@
*/
#pragma once

#import <Foundation/Foundation.h>
#import <Matter/MTRDefines.h>

NS_ASSUME_NONNULL_BEGIN

MTR_HIDDEN
@interface MTRControllerAccessControl : NSObject

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
+ (instancetype)alloc NS_UNAVAILABLE;
// Experimental API for Access Control

namespace chip {
namespace app {
namespace dynamic_server {
/**
* Initialize the access control module. Must be called on the Matter task
* queue.
*/
+ (void)init;

@end

NS_ASSUME_NONNULL_END
void InitAccessControl();
} // namespace dynamic_server
} // namespace app
} // namespace chip
Loading
Loading