From 591826a6ce1560141047a20857dca7a7d23f5c09 Mon Sep 17 00:00:00 2001 From: xylophone21 Date: Tue, 21 Dec 2021 15:34:00 +0800 Subject: [PATCH 1/6] added restart server on android tv server --- .../tcl/chip/chiptvserver/MainActivity.java | 10 +++ .../chiptvserver/service/MatterServant.java | 11 ++- .../app/src/main/res/layout/activity_main.xml | 10 +++ .../server/java/AndroidAppServerWrapper.cpp | 8 ++ src/app/server/java/AndroidAppServerWrapper.h | 2 + src/app/server/java/CHIPAppServer-JNI.cpp | 9 +++ .../src/chip/appserver/ChipAppServer.java | 2 + src/lib/support/BUILD.gn | 2 + src/lib/support/ChipThreadWork.cpp | 73 +++++++++++++++++++ src/lib/support/ChipThreadWork.h | 37 ++++++++++ 10 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 src/lib/support/ChipThreadWork.cpp create mode 100644 src/lib/support/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..a32b7728260770 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,9 +2,13 @@ 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 com.tcl.chip.chiptvserver.service.MatterServant; + import chip.setuppayload.DiscoveryCapability; import chip.setuppayload.SetupPayload; import chip.setuppayload.SetupPayloadParser; @@ -23,6 +27,12 @@ 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..e5e4b97e0fa02f 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,14 @@ 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" /> +