Add RestartEvent in Filter
Restart event would be sent when a filter is reconfigured and
restarted.
After stopping to reconfigure the filter, all the filter events
should be discarded until restart and receive the start event
from the newly configured filter.
Test: atest android.media.tv.tuner.cts
Bug: 172593389
Change-Id: I1c7c4391d8477ae191e318b1830dd8afed86ed87
diff --git a/core/api/system-current.txt b/core/api/system-current.txt
index 37a5389..ac6684c 100644
--- a/core/api/system-current.txt
+++ b/core/api/system-current.txt
@@ -5438,6 +5438,10 @@
method @NonNull public android.media.tv.tuner.filter.RecordSettings.Builder setTsIndexMask(int);
}
+ public final class RestartEvent extends android.media.tv.tuner.filter.FilterEvent {
+ method public int getStartId();
+ }
+
public final class ScramblingStatusEvent extends android.media.tv.tuner.filter.FilterEvent {
method public int getScramblingStatus();
}
diff --git a/media/java/android/media/tv/tuner/filter/RestartEvent.java b/media/java/android/media/tv/tuner/filter/RestartEvent.java
new file mode 100644
index 0000000..45ab7d9
--- /dev/null
+++ b/media/java/android/media/tv/tuner/filter/RestartEvent.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.media.tv.tuner.filter;
+
+import android.annotation.SystemApi;
+
+/**
+ * An Event that the client would reveice after stopping, reconfiguring and restarting a filter.
+ *
+ * <p>After stopping and restarting the filter, the client has to discard all coming events until
+ * it receive {@link RestartedEvent} to avoid using the events from the previous configuration.
+ *
+ * <p>Recofiguring must happen after stopping the filter.
+ *
+ * @hide
+ */
+@SystemApi
+public final class RestartEvent extends FilterEvent {
+ private final int mStartId;
+
+ // This constructor is used by JNI code only
+ private RestartEvent(int startId) {
+ mStartId = startId;
+ }
+
+ /**
+ * Gets the start id.
+ *
+ * <p>An unique ID to mark the start point of receiving the valid filter events after
+ * reconfiguring. It must be sent at least once in the first event after the filter is
+ * restarted.
+ *
+ * <p>0 is reserved for the newly opened filter's first start. It's optional to be received.
+ */
+ public int getStartId() {
+ return mStartId;
+ }
+}
diff --git a/media/jni/android_media_tv_Tuner.cpp b/media/jni/android_media_tv_Tuner.cpp
index b9e7848..b255a48 100644
--- a/media/jni/android_media_tv_Tuner.cpp
+++ b/media/jni/android_media_tv_Tuner.cpp
@@ -714,6 +714,34 @@
return arr;
}
+jobjectArray FilterCallback::getScramblingStatusEvent(
+ jobjectArray& arr, const std::vector<DemuxFilterEventExt::Event>& eventsExt) {
+ JNIEnv *env = AndroidRuntime::getJNIEnv();
+ jclass eventClazz = env->FindClass("android/media/tv/tuner/filter/ScramblingStatusEvent");
+ jmethodID eventInit = env->GetMethodID(eventClazz, "<init>", "(I)V");
+
+ for (int i = 0; i < eventsExt.size(); i++) {
+ auto scramblingStatus = eventsExt[i].scramblingStatus();
+ jobject obj = env->NewObject(eventClazz, eventInit, static_cast<jint>(scramblingStatus));
+ env->SetObjectArrayElement(arr, i, obj);
+ }
+ return arr;
+}
+
+jobjectArray FilterCallback::getRestartEvent(
+ jobjectArray& arr, const std::vector<DemuxFilterEventExt::Event>& eventsExt) {
+ JNIEnv *env = AndroidRuntime::getJNIEnv();
+ jclass eventClazz = env->FindClass("android/media/tv/tuner/filter/RestartEvent");
+ jmethodID eventInit = env->GetMethodID(eventClazz, "<init>", "(I)V");
+
+ for (int i = 0; i < eventsExt.size(); i++) {
+ auto startId = eventsExt[i].startId();
+ jobject obj = env->NewObject(eventClazz, eventInit, static_cast<jint>(startId));
+ env->SetObjectArrayElement(arr, i, obj);
+ }
+ return arr;
+}
+
Return<void> FilterCallback::onFilterEvent_1_1(const DemuxFilterEvent& filterEvent,
const DemuxFilterEventExt& filterEventExt) {
ALOGD("FilterCallback::onFilterEvent_1_1");
@@ -725,6 +753,23 @@
jclass eventClazz = env->FindClass("android/media/tv/tuner/filter/FilterEvent");
jobjectArray array = env->NewObjectArray(events.size(), eventClazz, NULL);
+ if (events.empty() && !eventsExt.empty()) {
+ auto eventExt = eventsExt[0];
+ switch (eventExt.getDiscriminator()) {
+ case DemuxFilterEventExt::Event::hidl_discriminator::scramblingStatus: {
+ array = getScramblingStatusEvent(array, eventsExt);
+ break;
+ }
+ case DemuxFilterEventExt::Event::hidl_discriminator::startId: {
+ array = getRestartEvent(array, eventsExt);
+ break;
+ }
+ default: {
+ break;
+ }
+ }
+ }
+
if (!events.empty()) {
auto event = events[0];
switch (event.getDiscriminator()) {
diff --git a/media/jni/android_media_tv_Tuner.h b/media/jni/android_media_tv_Tuner.h
index 71d2983..ebb95f4 100644
--- a/media/jni/android_media_tv_Tuner.h
+++ b/media/jni/android_media_tv_Tuner.h
@@ -186,6 +186,10 @@
jobjectArray& arr, const std::vector<DemuxFilterEvent::Event>& events);
jobjectArray getTemiEvent(
jobjectArray& arr, const std::vector<DemuxFilterEvent::Event>& events);
+ jobjectArray getScramblingStatusEvent(
+ jobjectArray& arr, const std::vector<DemuxFilterEventExt::Event>& eventsExt);
+ jobjectArray getRestartEvent(
+ jobjectArray& arr, const std::vector<DemuxFilterEventExt::Event>& eventsExt);
};
struct FrontendCallback : public IFrontendCallback {