Skip to content

Commit

Permalink
Extended Discovery has no timeout on android (#16285)
Browse files Browse the repository at this point in the history
* added app init before running Matter main loop and added SetExtendedDiscoveryTimeoutSecs

* fix restyled-io and ci errors

* remove weak ApplicationInit() in app server as PR request

* fix restyled-io and ci errors

* move ApplicationInit to TvApp-JNI, we do not need it call in main loop
  • Loading branch information
xylophone21 authored Mar 23, 2022
1 parent 545d9bf commit b24efd9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public static MatterServant get() {
}

public void init(@NonNull Context context) {
// The order is important, must
// first new TvApp to load dynamic library
// then chipPlatform to prepare platform
// then TvApp.postInit to init app which needs platform
// then start ChipAppServer
TvApp tvApp =
new TvApp(
(app, clusterId, endpoint) -> {
Expand Down Expand Up @@ -92,6 +97,8 @@ public void init(@NonNull Context context) {
new ChipMdnsCallbackImpl(),
new DiagnosticDataProviderImpl(applicationContext));

tvApp.postInit();

chipAppServer = new ChipAppServer();
chipAppServer.startApp();
}
Expand Down
14 changes: 14 additions & 0 deletions examples/tv-app/android/java/TVApp-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,20 @@
#include "MediaPlaybackManager.h"
#include "WakeOnLanManager.h"
#include "credentials/DeviceAttestationCredsProvider.h"
#include <app/server/Dnssd.h>
#include <app/server/java/AndroidAppServerWrapper.h>
#include <credentials/DeviceAttestationCredsProvider.h>
#include <credentials/examples/DeviceAttestationCredsExample.h>
#include <jni.h>
#include <lib/core/CHIPError.h>
#include <lib/support/CHIPJNIError.h>
#include <lib/support/JniReferences.h>

using namespace chip;
using namespace chip::app;
using namespace chip::Credentials;

#define EXTENDED_DISCOVERY_TIMEOUT_SEC 20

#define JNI_METHOD(RETURN, METHOD_NAME) extern "C" JNIEXPORT RETURN JNICALL Java_com_tcl_chip_tvapp_TvApp_##METHOD_NAME

Expand Down Expand Up @@ -130,3 +137,10 @@ JNI_METHOD(void, setDACProvider)(JNIEnv *, jobject, jobject provider)
chip::Credentials::SetDeviceAttestationCredentialsProvider(p);
}
}

JNI_METHOD(void, postInit)(JNIEnv *, jobject app)
{
#if CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY
DnssdServer::Instance().SetExtendedDiscoveryTimeoutSecs(EXTENDED_DISCOVERY_TIMEOUT_SEC);
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ private void postClusterInit(int clusterId, int endpoint) {

public native void nativeInit();

// post native init after platform is inited
public native void postInit();

public native void setKeypadInputManager(int endpoint, KeypadInputManager manager);

public native void setWakeOnLanManager(int endpoint, WakeOnLanManager manager);
Expand Down

0 comments on commit b24efd9

Please sign in to comment.