Skip to content

Commit

Permalink
[Android]Enable OTA Provider in Android controller (#28316)
Browse files Browse the repository at this point in the history
* move MTRIMDispatch.mm and MTRControllerAccessControl

* Add dynamic dispatcher and access control for Android controller

* Fix spelling of "controller".

* Make Matter.framework work with the new setup.

* address comment

* Restyled by gn

---------

Co-authored-by: Boris Zbarsky <[email protected]>
Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
3 people authored and pull[bot] committed Sep 22, 2023
1 parent db164d8 commit 70915e4
Show file tree
Hide file tree
Showing 14 changed files with 457 additions and 420 deletions.
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

0 comments on commit 70915e4

Please sign in to comment.