From b24efd91106d2f46958a30b1befb8df1522d8b69 Mon Sep 17 00:00:00 2001 From: "Hui.Li-TCL" Date: Thu, 24 Mar 2022 01:00:42 +0800 Subject: [PATCH] Extended Discovery has no timeout on android (#16285) * 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 --- .../chip/chiptvserver/service/MatterServant.java | 7 +++++++ examples/tv-app/android/java/TVApp-JNI.cpp | 14 ++++++++++++++ .../android/java/src/com/tcl/chip/tvapp/TvApp.java | 3 +++ 3 files changed, 24 insertions(+) diff --git a/examples/tv-app/android/App/app/src/main/java/com/tcl/chip/chiptvserver/service/MatterServant.java b/examples/tv-app/android/App/app/src/main/java/com/tcl/chip/chiptvserver/service/MatterServant.java index 6f88c05a895a33..1a1c6f914b0d57 100644 --- a/examples/tv-app/android/App/app/src/main/java/com/tcl/chip/chiptvserver/service/MatterServant.java +++ b/examples/tv-app/android/App/app/src/main/java/com/tcl/chip/chiptvserver/service/MatterServant.java @@ -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) -> { @@ -92,6 +97,8 @@ public void init(@NonNull Context context) { new ChipMdnsCallbackImpl(), new DiagnosticDataProviderImpl(applicationContext)); + tvApp.postInit(); + chipAppServer = new ChipAppServer(); chipAppServer.startApp(); } diff --git a/examples/tv-app/android/java/TVApp-JNI.cpp b/examples/tv-app/android/java/TVApp-JNI.cpp index caea0a1fbdebe9..71a659abcf789c 100644 --- a/examples/tv-app/android/java/TVApp-JNI.cpp +++ b/examples/tv-app/android/java/TVApp-JNI.cpp @@ -26,13 +26,20 @@ #include "MediaPlaybackManager.h" #include "WakeOnLanManager.h" #include "credentials/DeviceAttestationCredsProvider.h" +#include #include +#include +#include #include #include #include #include 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 @@ -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 +} diff --git a/examples/tv-app/android/java/src/com/tcl/chip/tvapp/TvApp.java b/examples/tv-app/android/java/src/com/tcl/chip/tvapp/TvApp.java index 289cbacea8d2d7..1479dc73a3b0e0 100644 --- a/examples/tv-app/android/java/src/com/tcl/chip/tvapp/TvApp.java +++ b/examples/tv-app/android/java/src/com/tcl/chip/tvapp/TvApp.java @@ -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);