Skip to content

Commit

Permalink
tv-casting-app: Adding new app params (#23624)
Browse files Browse the repository at this point in the history
* Adding new app params

* Using only nodeId to check two VideoPlayers for equality

* Checking for null data on the targetNavigation_navigateTarget command in JNI
  • Loading branch information
sharadb-amazon authored and pull[bot] committed Jul 31, 2023
1 parent 1d76f34 commit 3947576
Show file tree
Hide file tree
Showing 9 changed files with 322 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class AppParameters {

private byte[] rotatingDeviceIdUniqueId;
private DACProvider dacProvider = TEST_DAC_PROVIDER;
private String spake2pVerifierBase64;
private String Spake2pSaltBase64;
private int spake2pIterationCount;
private int setupPasscode = TEST_SETUP_PASSCODE;
private int discriminator = TEST_DISCRIMINATOR;

Expand All @@ -44,6 +47,30 @@ public void setDacProvider(DACProvider dacProvider) {
this.dacProvider = dacProvider;
}

public String getSpake2pVerifierBase64() {
return spake2pVerifierBase64;
}

public void setSpake2pVerifierBase64(String spake2pVerifierBase64) {
this.spake2pVerifierBase64 = spake2pVerifierBase64;
}

public String getSpake2pSaltBase64() {
return Spake2pSaltBase64;
}

public void setSpake2pSaltBase64(String spake2pSaltBase64) {
Spake2pSaltBase64 = spake2pSaltBase64;
}

public int getSpake2pIterationCount() {
return spake2pIterationCount;
}

public void setSpake2pIterationCount(int spake2pIterationCount) {
this.spake2pIterationCount = spake2pIterationCount;
}

public int getSetupPasscode() {
return setupPasscode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public class TvCastingApp {
private NsdManagerServiceResolver.NsdManagerResolverAvailState nsdManagerResolverAvailState;

public boolean initApp(Context applicationContext, AppParameters appParameters) {
if (applicationContext == null || appParameters == null) {
return false;
}

this.applicationContext = applicationContext;
nsdManagerResolverAvailState = new NsdManagerServiceResolver.NsdManagerResolverAvailState();
NsdManagerServiceResolver nsdManagerServiceResolver =
Expand All @@ -62,7 +66,11 @@ public boolean initApp(Context applicationContext, AppParameters appParameters)
new DiagnosticDataProviderImpl(applicationContext));

chipPlatform.updateCommissionableDataProviderData(
null, null, 0, appParameters.getSetupPasscode(), appParameters.getDiscriminator());
appParameters.getSpake2pVerifierBase64(),
appParameters.getSpake2pSaltBase64(),
appParameters.getSpake2pIterationCount(),
appParameters.getSetupPasscode(),
appParameters.getDiscriminator());

chipAppServer = new ChipAppServer();
chipAppServer.startApp();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,7 @@ JNI_METHOD(jboolean, targetNavigator_1navigateTarget)

ChipLogProgress(AppServer, "JNI_METHOD targetNavigator_navigateTarget called");

const char * nativeData = env->GetStringUTFChars(data, 0);
const char * nativeData = (data != nullptr ? env->GetStringUTFChars(data, 0) : nullptr);

TargetEndpointInfo endpoint;
CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
Expand All @@ -1371,12 +1371,16 @@ JNI_METHOD(jboolean, targetNavigator_1navigateTarget)
ChipLogError(AppServer, "MatterCallbackHandlerJNI.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));

err = CastingServer::GetInstance()->TargetNavigator_NavigateTarget(
&endpoint, static_cast<uint8_t>(target), chip::MakeOptional(CharSpan::fromCharString(nativeData)),
&endpoint, static_cast<uint8_t>(target),
(nativeData != nullptr ? chip::MakeOptional(CharSpan::fromCharString(nativeData)) : chip::NullOptional),
[](CHIP_ERROR err) { TvCastingAppJNIMgr().getMediaCommandResponseHandler(TargetNavigator_NavigateTarget).Handle(err); });
VerifyOrExit(CHIP_NO_ERROR == err,
ChipLogError(AppServer, "CastingServer.TargetNavigator_NavigateTarget failed %" CHIP_ERROR_FORMAT, err.Format()));

env->ReleaseStringUTFChars(data, nativeData);
if (nativeData != nullptr)
{
env->ReleaseStringUTFChars(data, nativeData);
}
exit:
if (err != CHIP_NO_ERROR)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
3C4E53B028E4F28100F293E8 /* MediaPlaybackTypes.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3C4E53AF28E4F28100F293E8 /* MediaPlaybackTypes.mm */; };
3C4E53B228E5184C00F293E8 /* TargetNavigatorTypes.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3C4E53B128E5184C00F293E8 /* TargetNavigatorTypes.mm */; };
3C4E53B628E5595A00F293E8 /* ContentLauncherTypes.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3C4E53B528E5595A00F293E8 /* ContentLauncherTypes.mm */; };
3C66FBFC290327BB00B63FE7 /* AppParameters.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C66FBFB290327BB00B63FE7 /* AppParameters.m */; };
3C66FBFC290327BB00B63FE7 /* AppParameters.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3C66FBFB290327BB00B63FE7 /* AppParameters.mm */; };
3C81C74C28F7A777001CB9D1 /* ContentApp.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3C81C74B28F7A777001CB9D1 /* ContentApp.mm */; };
3C81C75028F7A7D3001CB9D1 /* VideoPlayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C81C74F28F7A7D3001CB9D1 /* VideoPlayer.m */; };
3CCB87212869085400771BAD /* MatterTvCastingBridge.h in Headers */ = {isa = PBXBuildFile; fileRef = 3CCB87202869085400771BAD /* MatterTvCastingBridge.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand All @@ -27,6 +27,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
3C0D9CDF2920A30C00D3332B /* CommissionableDataProviderImpl.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = CommissionableDataProviderImpl.hpp; sourceTree = "<group>"; };
3C4AE64E286A7D40005B52A4 /* OnboardingPayload.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OnboardingPayload.h; sourceTree = "<group>"; };
3C4AE64F286A7D4D005B52A4 /* OnboardingPayload.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OnboardingPayload.m; sourceTree = "<group>"; };
3C4E53AF28E4F28100F293E8 /* MediaPlaybackTypes.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MediaPlaybackTypes.mm; sourceTree = "<group>"; };
Expand All @@ -35,7 +36,7 @@
3C4E53B428E5593700F293E8 /* ContentLauncherTypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ContentLauncherTypes.h; sourceTree = "<group>"; };
3C4E53B528E5595A00F293E8 /* ContentLauncherTypes.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ContentLauncherTypes.mm; sourceTree = "<group>"; };
3C66FBFA2903279A00B63FE7 /* AppParameters.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppParameters.h; sourceTree = "<group>"; };
3C66FBFB290327BB00B63FE7 /* AppParameters.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppParameters.m; sourceTree = "<group>"; };
3C66FBFB290327BB00B63FE7 /* AppParameters.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = AppParameters.mm; sourceTree = "<group>"; };
3C81C74B28F7A777001CB9D1 /* ContentApp.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ContentApp.mm; sourceTree = "<group>"; };
3C81C74E28F7A7AE001CB9D1 /* ContentApp.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ContentApp.h; sourceTree = "<group>"; };
3C81C74F28F7A7D3001CB9D1 /* VideoPlayer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VideoPlayer.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -93,7 +94,7 @@
3CCB873A286A593700771BAD /* CastingServerBridge.h */,
3CCB873D286A593700771BAD /* CastingServerBridge.mm */,
3C66FBFA2903279A00B63FE7 /* AppParameters.h */,
3C66FBFB290327BB00B63FE7 /* AppParameters.m */,
3C66FBFB290327BB00B63FE7 /* AppParameters.mm */,
3CCB873B286A593700771BAD /* DiscoveredNodeData.h */,
3CCB8739286A593700771BAD /* DiscoveredNodeData.mm */,
3CCB873C286A593700771BAD /* ConversionUtils.hpp */,
Expand All @@ -112,6 +113,7 @@
3C4E53AF28E4F28100F293E8 /* MediaPlaybackTypes.mm */,
3C4E53B328E5185F00F293E8 /* TargetNavigatorTypes.h */,
3C4E53B128E5184C00F293E8 /* TargetNavigatorTypes.mm */,
3C0D9CDF2920A30C00D3332B /* CommissionableDataProviderImpl.hpp */,
);
path = MatterTvCastingBridge;
sourceTree = "<group>";
Expand Down Expand Up @@ -226,7 +228,7 @@
3C81C75028F7A7D3001CB9D1 /* VideoPlayer.m in Sources */,
3CCB8744286A593700771BAD /* ConversionUtils.mm in Sources */,
3C4E53B028E4F28100F293E8 /* MediaPlaybackTypes.mm in Sources */,
3C66FBFC290327BB00B63FE7 /* AppParameters.m in Sources */,
3C66FBFC290327BB00B63FE7 /* AppParameters.mm in Sources */,
3CCB873F286A593700771BAD /* DiscoveredNodeData.mm in Sources */,
3C81C74C28F7A777001CB9D1 /* ContentApp.mm in Sources */,
3C4AE650286A7D4D005B52A4 /* OnboardingPayload.m in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,22 @@

#import <Foundation/Foundation.h>

#import "OnboardingPayload.h"

#ifndef AppParameters_h
#define AppParameters_h

@interface AppParameters : NSObject

@property NSData * rotatingDeviceIdUniqueId;

- (AppParameters *)initWithRotatingDeviceIdUniqueId:(NSData *)rotatingDeviceIdUniqueId;
@property OnboardingPayload * onboardingPayload;

@property uint32_t spake2pIterationCount;

@property NSData * spake2pSalt;

@property NSData * spake2pVerifier;

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@

@implementation AppParameters

- (AppParameters *)initWithRotatingDeviceIdUniqueId:(NSData *)rotatingDeviceIdUniqueId
/**
* Initialize with default values
*/
- (AppParameters *)init
{
self = [super init];
if (self) {
_rotatingDeviceIdUniqueId = rotatingDeviceIdUniqueId;
}
return self;
return [super init];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#import "CastingServerBridge.h"
#import "CastingServer.h"

#import "CommissionableDataProviderImpl.hpp"
#import "ConversionUtils.hpp"
#import "MatterCallbacks.h"
#import "OnboardingPayload.h"
Expand All @@ -29,15 +30,18 @@
#include <lib/support/CHIPListUtils.h>
#include <lib/support/CHIPMem.h>
#include <platform/PlatformManager.h>
#include <platform/TestOnlyCommissionableDataProvider.h>

@interface CastingServerBridge ()

// queue used to serialize all work performed by the CastingServerBridge
@property (atomic, readonly) dispatch_queue_t chipWorkQueue;
@property AppParameters * appParameters;

@property OnboardingPayload * _Nonnull onboardingPayload;

@property chip::DeviceLayer::CommissionableDataProviderImpl * commissionableDataProvider;

// queue used to serialize all work performed by the CastingServerBridge
@property (atomic) dispatch_queue_t chipWorkQueue;

@property void (^_Nonnull commissioningCompleteCallback)(bool);

@property void (^_Nonnull onConnectionSuccessCallback)(VideoPlayer *);
Expand Down Expand Up @@ -87,47 +91,12 @@ - (instancetype)init
return nil;
}

chip::DeviceLayer::TestOnlyCommissionableDataProvider TestOnlyCommissionableDataProvider;
uint32_t defaultTestPasscode = 0;
VerifyOrDie(TestOnlyCommissionableDataProvider.GetSetupPasscode(defaultTestPasscode) == CHIP_NO_ERROR);
uint16_t defaultTestSetupDiscriminator = 0;
VerifyOrDie(TestOnlyCommissionableDataProvider.GetSetupDiscriminator(defaultTestSetupDiscriminator) == CHIP_NO_ERROR);
_onboardingPayload = [[OnboardingPayload alloc] initWithSetupPasscode:defaultTestPasscode
setupDiscriminator:defaultTestSetupDiscriminator];

// Initialize device attestation config
SetDeviceAttestationCredentialsProvider(chip::Credentials::Examples::GetExampleDACProvider());

// Initialize device attestation verifier from a constant version
{
// TODO: Replace testingRootStore with a AttestationTrustStore that has the necessary official PAA roots available
const chip::Credentials::AttestationTrustStore * testingRootStore = chip::Credentials::GetTestAttestationTrustStore();
SetDeviceAttestationVerifier(GetDefaultDACVerifier(testingRootStore));
}

// init app Server
static chip::CommonCaseDeviceServerInitParams initParams;
err = initParams.InitializeStaticResourcesBeforeServerInit();
if (err != CHIP_NO_ERROR) {
ChipLogError(AppServer, "InitializeStaticResourcesBeforeServerInit failed: %s", ErrorStr(err));
return nil;
}
err = chip::Server::GetInstance().Init(initParams);
if (err != CHIP_NO_ERROR) {
ChipLogError(AppServer, "chip::Server init failed: %s", ErrorStr(err));
return nil;
}

_chipWorkQueue = chip::DeviceLayer::PlatformMgrImpl().GetWorkQueue();

_commandResponseCallbacks = [NSMutableDictionary dictionary];
_subscriptionEstablishedCallbacks = [NSMutableDictionary dictionary];
_subscriptionReadSuccessCallbacks = [NSMutableDictionary dictionary];
_subscriptionReadFailureCallbacks = [NSMutableDictionary dictionary];
_readSuccessCallbacks = [NSMutableDictionary dictionary];
_readFailureCallbacks = [NSMutableDictionary dictionary];

chip::DeviceLayer::PlatformMgrImpl().StartEventLoopTask();
}
return self;
}
Expand All @@ -138,17 +107,82 @@ - (void)initApp:(AppParameters * _Nullable)appParameters
{
ChipLogProgress(AppServer, "CastingServerBridge().initApp() called");

dispatch_async(_chipWorkQueue, ^{
bool initAppStatus = true;
CHIP_ERROR err = CHIP_NO_ERROR;
_commissionableDataProvider = new chip::DeviceLayer::CommissionableDataProviderImpl();
_appParameters = appParameters;
AppParams cppAppParams;
if (_appParameters != nil) {
err = [ConversionUtils convertToCppAppParamsInfoFrom:_appParameters outAppParams:cppAppParams];
if (err != CHIP_NO_ERROR) {
ChipLogError(AppServer, "AppParameters conversion failed: %s", ErrorStr(err));
return;
}

// set fields in commissionableDataProvider
_commissionableDataProvider->SetSpake2pIterationCount(_appParameters.spake2pIterationCount);
if (_appParameters.spake2pSalt != nil) {
chip::ByteSpan spake2pSaltSpan
= chip::ByteSpan(static_cast<const uint8_t *>(_appParameters.spake2pSalt.bytes), _appParameters.spake2pSalt.length);
_commissionableDataProvider->SetSpake2pSalt(spake2pSaltSpan);
}

if (_appParameters.spake2pVerifier != nil) {
chip::ByteSpan spake2pVerifierSpan = chip::ByteSpan(
static_cast<const uint8_t *>(_appParameters.spake2pVerifier.bytes), _appParameters.spake2pVerifier.length);
_commissionableDataProvider->SetSpake2pSalt(spake2pVerifierSpan);
}

if (_appParameters.onboardingPayload != nil) {
_commissionableDataProvider->SetSetupPasscode(_appParameters.onboardingPayload.setupPasscode);
_commissionableDataProvider->SetSetupDiscriminator(_appParameters.onboardingPayload.setupDiscriminator);
}

uint32_t setupPasscode = 0;
uint16_t setupDiscriminator = 0;
_commissionableDataProvider->GetSetupPasscode(setupPasscode);
_commissionableDataProvider->GetSetupDiscriminator(setupDiscriminator);
_onboardingPayload = [[OnboardingPayload alloc] initWithSetupPasscode:setupPasscode setupDiscriminator:setupDiscriminator];
}
chip::DeviceLayer::SetCommissionableDataProvider(_commissionableDataProvider);

// Initialize device attestation config
SetDeviceAttestationCredentialsProvider(chip::Credentials::Examples::GetExampleDACProvider());

// Initialize device attestation verifier from a constant version
{
// TODO: Replace testingRootStore with a AttestationTrustStore that has the necessary official PAA roots available
const chip::Credentials::AttestationTrustStore * testingRootStore = chip::Credentials::GetTestAttestationTrustStore();
SetDeviceAttestationVerifier(GetDefaultDACVerifier(testingRootStore));
}

// init app Server
static chip::CommonCaseDeviceServerInitParams initParams;
err = initParams.InitializeStaticResourcesBeforeServerInit();
if (err != CHIP_NO_ERROR) {
ChipLogError(AppServer, "InitializeStaticResourcesBeforeServerInit failed: %s", ErrorStr(err));
return;
}

err = chip::Server::GetInstance().Init(initParams);
if (err != CHIP_NO_ERROR) {
ChipLogError(AppServer, "chip::Server init failed: %s", ErrorStr(err));
return;
}

_chipWorkQueue = chip::DeviceLayer::PlatformMgrImpl().GetWorkQueue();

chip::DeviceLayer::PlatformMgrImpl().StartEventLoopTask();

dispatch_async(_chipWorkQueue, ^{
CHIP_ERROR err = CHIP_NO_ERROR;
AppParams appParams;
if (appParameters == nil) {
AppParams appParam;
if (appParameters != nil) {
err = CastingServer::GetInstance()->Init();
} else if ((err = [ConversionUtils convertToCppAppParamsInfoFrom:appParameters outAppParams:appParams]) == CHIP_NO_ERROR) {
err = CastingServer::GetInstance()->Init(&appParams);
} else if ((err = [ConversionUtils convertToCppAppParamsInfoFrom:appParameters outAppParams:appParam]) == CHIP_NO_ERROR) {
err = CastingServer::GetInstance()->Init(&appParam);
}

Boolean initAppStatus = true;
if (err != CHIP_NO_ERROR) {
ChipLogError(AppServer, "CastingServerBridge().initApp() failed: %" CHIP_ERROR_FORMAT, err.Format());
initAppStatus = false;
Expand Down
Loading

0 comments on commit 3947576

Please sign in to comment.