From 00a6fcf478185594396c02e788dd7fabf7425a01 Mon Sep 17 00:00:00 2001 From: Sharad Binjola <31142146+sharadb-amazon@users.noreply.github.com> Date: Thu, 16 Mar 2023 16:45:25 -0700 Subject: [PATCH] tv-casting-app: Allow for a way for Matter TV casting cache to be purged (#25665) * tv-casting-app: Allow for a way for Matter TV casting cache to be purged (#112) * tv-casting-app: Adding a way to purge cached video players * Android tv-casting-app: Adding purge cache button * iOS tv-casting-app: Adding purge cache button * Addressing feedback from Cliff --- .../app/CommissionerDiscoveryFragment.java | 17 +++++++++++++++++ .../main/jni/com/chip/casting/TvCastingApp.java | 2 ++ .../app/src/main/jni/cpp/TvCastingApp-JNI.cpp | 14 ++++++++++++++ .../layout/fragment_commissioner_discovery.xml | 6 ++++++ .../MatterTvCastingBridge/CastingServerBridge.h | 11 ++++++++++- .../CastingServerBridge.mm | 11 +++++++++++ .../TvCasting/StartFromCacheView.swift | 9 +++++++++ .../TvCasting/StartFromCacheViewModel.swift | 12 ++++++++++++ .../tv-casting-common/include/CastingServer.h | 2 +- .../tv-casting-common/src/CastingServer.cpp | 2 +- .../src/PersistenceManager.cpp | 8 +++++++- 11 files changed, 90 insertions(+), 4 deletions(-) diff --git a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/CommissionerDiscoveryFragment.java b/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/CommissionerDiscoveryFragment.java index 0f0529a6c70cfa..dbb95e88806a92 100644 --- a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/CommissionerDiscoveryFragment.java +++ b/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/CommissionerDiscoveryFragment.java @@ -11,6 +11,7 @@ import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ListView; +import android.widget.Toast; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import com.chip.casting.DiscoveredNodeData; @@ -77,6 +78,22 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { v -> callback.handleCommissioningButtonClicked(null); manualCommissioningButton.setOnClickListener(manualCommissioningButtonOnClickListener); + Button purgeCacheButton = getView().findViewById(R.id.purgeCacheButton); + Context context = getContext().getApplicationContext(); + View.OnClickListener purgeCacheOnClickListener = + new View.OnClickListener() { + @Override + public void onClick(View v) { + boolean status = tvCastingApp.purgeCache(); + Toast.makeText( + context, + "Cache purge " + (status ? "successful!" : "failed!"), + Toast.LENGTH_SHORT) + .show(); + } + }; + purgeCacheButton.setOnClickListener(purgeCacheOnClickListener); + ArrayAdapter arrayAdapter = new VideoPlayerCommissionerAdapter(getActivity(), commissionerVideoPlayerList); final ListView list = getActivity().findViewById(R.id.commissionerList); diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/TvCastingApp.java b/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/TvCastingApp.java index 316edf3ba26357..b44d8e2b1c2119 100644 --- a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/TvCastingApp.java +++ b/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/TvCastingApp.java @@ -181,6 +181,8 @@ public native boolean verifyOrEstablishConnection( public native List getActiveTargetVideoPlayers(); + public native boolean purgeCache(); + /* * CONTENT LAUNCHER CLUSTER * diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/TvCastingApp-JNI.cpp b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/TvCastingApp-JNI.cpp index eb584e2589bd5b..77d6c5e0e40fc1 100644 --- a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/TvCastingApp-JNI.cpp +++ b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/TvCastingApp-JNI.cpp @@ -303,6 +303,20 @@ JNI_METHOD(jboolean, sendCommissioningRequest)(JNIEnv * env, jobject, jobject jD return true; } +JNI_METHOD(jboolean, purgeCache)(JNIEnv * env, jobject) +{ + chip::DeviceLayer::StackLock lock; + ChipLogProgress(AppServer, "JNI_METHOD purgeCache called"); + + CHIP_ERROR err = CastingServer::GetInstance()->PurgeCache(); + if (err != CHIP_NO_ERROR) + { + ChipLogError(AppServer, "TVCastingApp-JNI::purgeCache failed: %" CHIP_ERROR_FORMAT, err.Format()); + return false; + } + return true; +} + JNI_METHOD(jboolean, contentLauncherLaunchURL) (JNIEnv * env, jobject, jobject contentApp, jstring contentUrl, jstring contentDisplayStr, jobject jResponseHandler) { diff --git a/examples/tv-casting-app/android/App/app/src/main/res/layout/fragment_commissioner_discovery.xml b/examples/tv-casting-app/android/App/app/src/main/res/layout/fragment_commissioner_discovery.xml index 7cfdf23b0b335b..85855dbff4e5a9 100644 --- a/examples/tv-casting-app/android/App/app/src/main/res/layout/fragment_commissioner_discovery.xml +++ b/examples/tv-casting-app/android/App/app/src/main/res/layout/fragment_commissioner_discovery.xml @@ -14,6 +14,12 @@ tools:layout_editor_absoluteY="1dp" android:padding="10sp"> +