diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 71dbca0ac8285..9ea703726d664 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -5438,6 +5438,10 @@ package android.media.tv.tuner.filter { 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 0000000000000..45ab7d9da4cce --- /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. + * + *

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. + * + *

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. + * + *

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. + * + *

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 b9e78483a1885..b255a48d34d0e 100644 --- a/media/jni/android_media_tv_Tuner.cpp +++ b/media/jni/android_media_tv_Tuner.cpp @@ -714,6 +714,34 @@ jobjectArray FilterCallback::getTemiEvent( return arr; } +jobjectArray FilterCallback::getScramblingStatusEvent( + jobjectArray& arr, const std::vector& eventsExt) { + JNIEnv *env = AndroidRuntime::getJNIEnv(); + jclass eventClazz = env->FindClass("android/media/tv/tuner/filter/ScramblingStatusEvent"); + jmethodID eventInit = env->GetMethodID(eventClazz, "", "(I)V"); + + for (int i = 0; i < eventsExt.size(); i++) { + auto scramblingStatus = eventsExt[i].scramblingStatus(); + jobject obj = env->NewObject(eventClazz, eventInit, static_cast(scramblingStatus)); + env->SetObjectArrayElement(arr, i, obj); + } + return arr; +} + +jobjectArray FilterCallback::getRestartEvent( + jobjectArray& arr, const std::vector& eventsExt) { + JNIEnv *env = AndroidRuntime::getJNIEnv(); + jclass eventClazz = env->FindClass("android/media/tv/tuner/filter/RestartEvent"); + jmethodID eventInit = env->GetMethodID(eventClazz, "", "(I)V"); + + for (int i = 0; i < eventsExt.size(); i++) { + auto startId = eventsExt[i].startId(); + jobject obj = env->NewObject(eventClazz, eventInit, static_cast(startId)); + env->SetObjectArrayElement(arr, i, obj); + } + return arr; +} + Return FilterCallback::onFilterEvent_1_1(const DemuxFilterEvent& filterEvent, const DemuxFilterEventExt& filterEventExt) { ALOGD("FilterCallback::onFilterEvent_1_1"); @@ -725,6 +753,23 @@ Return FilterCallback::onFilterEvent_1_1(const DemuxFilterEvent& filterEve 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 71d2983b7c51b..ebb95f43c52d2 100644 --- a/media/jni/android_media_tv_Tuner.h +++ b/media/jni/android_media_tv_Tuner.h @@ -186,6 +186,10 @@ private: jobjectArray& arr, const std::vector& events); jobjectArray getTemiEvent( jobjectArray& arr, const std::vector& events); + jobjectArray getScramblingStatusEvent( + jobjectArray& arr, const std::vector& eventsExt); + jobjectArray getRestartEvent( + jobjectArray& arr, const std::vector& eventsExt); }; struct FrontendCallback : public IFrontendCallback {