From 10601000d6e721f13980ff26de0c2621f08699b7 Mon Sep 17 00:00:00 2001 From: "Hui.Li-TCL" Date: Sat, 8 Jan 2022 03:20:30 +0800 Subject: [PATCH] added restart server on android tv server (#13177) * added restart server on android tv server * fix restyled-io and ci errors * ChipThreadWork can only work on android & linux * remove chip thread work on darwin because there is no "non-main" CHIP thread on darwin * move ChipThreadWork to server/java folder as bzbarsky-apple's suggestion because is it not suit for all platforms * change ChipAndroidAppShutdown to void and remove no mean [&] --- .../tcl/chip/chiptvserver/MainActivity.java | 10 ++++ .../chiptvserver/service/MatterServant.java | 9 ++- .../app/src/main/res/layout/activity_main.xml | 10 ++++ .../server/java/AndroidAppServerWrapper.cpp | 6 ++ src/app/server/java/AndroidAppServerWrapper.h | 2 + src/app/server/java/BUILD.gn | 2 + src/app/server/java/CHIPAppServer-JNI.cpp | 7 +++ src/app/server/java/ChipThreadWork.cpp | 58 +++++++++++++++++++ src/app/server/java/ChipThreadWork.h | 37 ++++++++++++ .../src/chip/appserver/ChipAppServer.java | 2 + 10 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 src/app/server/java/ChipThreadWork.cpp create mode 100644 src/app/server/java/ChipThreadWork.h diff --git a/examples/tv-app/android/App/app/src/main/java/com/tcl/chip/chiptvserver/MainActivity.java b/examples/tv-app/android/App/app/src/main/java/com/tcl/chip/chiptvserver/MainActivity.java index 7475aa4e7e8e85..e71a4663ea412d 100644 --- a/examples/tv-app/android/App/app/src/main/java/com/tcl/chip/chiptvserver/MainActivity.java +++ b/examples/tv-app/android/App/app/src/main/java/com/tcl/chip/chiptvserver/MainActivity.java @@ -2,12 +2,14 @@ import android.graphics.Bitmap; import android.os.Bundle; +import android.view.View; import android.widget.ImageView; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; import chip.setuppayload.DiscoveryCapability; import chip.setuppayload.SetupPayload; import chip.setuppayload.SetupPayloadParser; +import com.tcl.chip.chiptvserver.service.MatterServant; import java.util.HashSet; public class MainActivity extends AppCompatActivity { @@ -23,6 +25,14 @@ protected void onCreate(Bundle savedInstanceState) { mQrCodeImg = findViewById(R.id.qrCodeImg); mQrCodeTxt = findViewById(R.id.qrCodeTxt); mManualPairingCodeTxt = findViewById(R.id.manualPairingCodeTxt); + findViewById(R.id.resetBtn) + .setOnClickListener( + new View.OnClickListener() { + @Override + public void onClick(View view) { + MatterServant.get().restart(); + } + }); // TODO: Get these parameters from PreferencesConfigurationManager HashSet discoveryCapabilities = new HashSet<>(); 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 e6637744ab9dd3..fffb60be46040b 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 @@ -20,6 +20,8 @@ public class MatterServant { + private ChipAppServer chipAppServer; + private MatterServant() {} private static class SingletonHolder { @@ -49,7 +51,12 @@ public void init(@NonNull Context context) { new NsdManagerServiceResolver(applicationContext), new ChipMdnsCallbackImpl()); - ChipAppServer chipAppServer = new ChipAppServer(); + chipAppServer = new ChipAppServer(); + chipAppServer.startApp(); + } + + public void restart() { + chipAppServer.stopApp(); chipAppServer.startApp(); } } diff --git a/examples/tv-app/android/App/app/src/main/res/layout/activity_main.xml b/examples/tv-app/android/App/app/src/main/res/layout/activity_main.xml index 65b4ee55984ea5..f26237c235c4eb 100644 --- a/examples/tv-app/android/App/app/src/main/res/layout/activity_main.xml +++ b/examples/tv-app/android/App/app/src/main/res/layout/activity_main.xml @@ -32,4 +32,14 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" /> +