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"> +