Merge "Create a OnTunerEventListener"
This commit is contained in:
@@ -4679,7 +4679,10 @@ package android.media.tv.tuner {
|
||||
|
||||
public final class Tuner implements java.lang.AutoCloseable {
|
||||
ctor public Tuner(@NonNull android.content.Context);
|
||||
method @RequiresPermission(android.Manifest.permission.ACCESS_TV_TUNER) public void clearOnTuneEventListener();
|
||||
method @Nullable @RequiresPermission(android.Manifest.permission.ACCESS_TV_TUNER) public android.media.tv.tuner.Tuner.Descrambler openDescrambler();
|
||||
method @RequiresPermission(android.Manifest.permission.ACCESS_TV_TUNER) public void setOnTuneEventListener(@NonNull java.util.concurrent.Executor, @NonNull android.media.tv.tuner.frontend.OnTuneEventListener);
|
||||
method @RequiresPermission(android.Manifest.permission.ACCESS_TV_TUNER) public int stopTune();
|
||||
method @RequiresPermission(android.Manifest.permission.ACCESS_TV_TUNER) public int tune(@NonNull android.media.tv.tuner.FrontendSettings);
|
||||
}
|
||||
|
||||
@@ -4761,6 +4764,17 @@ package android.media.tv.tuner.filter {
|
||||
|
||||
}
|
||||
|
||||
package android.media.tv.tuner.frontend {
|
||||
|
||||
public interface OnTuneEventListener {
|
||||
method public void onTuneEvent(int);
|
||||
field public static final int SIGNAL_LOCKED = 0; // 0x0
|
||||
field public static final int SIGNAL_LOST_LOCK = 2; // 0x2
|
||||
field public static final int SIGNAL_NO_SIGNAL = 1; // 0x1
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
package android.metrics {
|
||||
|
||||
public class LogMaker {
|
||||
|
||||
@@ -32,9 +32,9 @@ import android.media.tv.tuner.filter.Filter.Subtype;
|
||||
import android.media.tv.tuner.filter.Filter.Type;
|
||||
import android.media.tv.tuner.filter.FilterEvent;
|
||||
import android.media.tv.tuner.filter.TimeFilter;
|
||||
import android.media.tv.tuner.frontend.FrontendCallback;
|
||||
import android.media.tv.tuner.frontend.FrontendInfo;
|
||||
import android.media.tv.tuner.frontend.FrontendStatus;
|
||||
import android.media.tv.tuner.frontend.OnTuneEventListener;
|
||||
import android.media.tv.tuner.frontend.ScanCallback;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
@@ -57,7 +57,6 @@ public final class Tuner implements AutoCloseable {
|
||||
private static final String TAG = "MediaTvTuner";
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
private static final int MSG_ON_FRONTEND_EVENT = 1;
|
||||
private static final int MSG_ON_FILTER_EVENT = 2;
|
||||
private static final int MSG_ON_FILTER_STATUS = 3;
|
||||
private static final int MSG_ON_LNB_EVENT = 4;
|
||||
@@ -76,6 +75,10 @@ public final class Tuner implements AutoCloseable {
|
||||
private List<Integer> mLnbIds;
|
||||
private Lnb mLnb;
|
||||
@Nullable
|
||||
private OnTuneEventListener mOnTuneEventListener;
|
||||
@Nullable
|
||||
private Executor mOnTunerEventExecutor;
|
||||
@Nullable
|
||||
private ScanCallback mScanCallback;
|
||||
@Nullable
|
||||
private Executor mScanCallbackExecutor;
|
||||
@@ -222,11 +225,6 @@ public final class Tuner implements AutoCloseable {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
switch (msg.what) {
|
||||
case MSG_ON_FRONTEND_EVENT:
|
||||
if (mFrontend != null && mFrontend.mCallback != null) {
|
||||
mFrontend.mCallback.onEvent(msg.arg1);
|
||||
}
|
||||
break;
|
||||
case MSG_ON_FILTER_STATUS: {
|
||||
Filter filter = (Filter) msg.obj;
|
||||
if (filter.mCallback != null) {
|
||||
@@ -242,7 +240,6 @@ public final class Tuner implements AutoCloseable {
|
||||
|
||||
private class Frontend {
|
||||
private int mId;
|
||||
private FrontendCallback mCallback;
|
||||
|
||||
private Frontend(int id) {
|
||||
mId = id;
|
||||
@@ -250,13 +247,59 @@ public final class Tuner implements AutoCloseable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tunes the frontend to the settings given.
|
||||
* Listens for tune events.
|
||||
*
|
||||
* @return result status of tune operation.
|
||||
* <p>
|
||||
* Tuner events are started when {@link #tune(FrontendSettings)} is called and end when {@link
|
||||
* #stopTune()} is called.
|
||||
*
|
||||
* @param eventListener receives tune events.
|
||||
* @throws SecurityException if the caller does not have appropriate permissions.
|
||||
* TODO: add result constants or throw exceptions.
|
||||
* @see #tune(FrontendSettings)
|
||||
*/
|
||||
@RequiresPermission(android.Manifest.permission.ACCESS_TV_TUNER)
|
||||
public void setOnTuneEventListener(@NonNull @CallbackExecutor Executor executor,
|
||||
@NonNull OnTuneEventListener eventListener) {
|
||||
TunerUtils.checkTunerPermission(mContext);
|
||||
mOnTuneEventListener = eventListener;
|
||||
mOnTunerEventExecutor = executor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the {@link OnTuneEventListener} and its associated {@link Executor}.
|
||||
*
|
||||
* @throws SecurityException if the caller does not have appropriate permissions.
|
||||
* @see #setOnTuneEventListener(Executor, OnTuneEventListener)
|
||||
*/
|
||||
@RequiresPermission(android.Manifest.permission.ACCESS_TV_TUNER)
|
||||
public void clearOnTuneEventListener() {
|
||||
TunerUtils.checkTunerPermission(mContext);
|
||||
mOnTuneEventListener = null;
|
||||
mOnTunerEventExecutor = null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tunes the frontend to using the settings given.
|
||||
*
|
||||
* <p>
|
||||
* This locks the frontend to a frequency by providing signal
|
||||
* delivery information. If previous tuning isn't completed, this stop the previous tuning, and
|
||||
* start a new tuning.
|
||||
*
|
||||
* <p>
|
||||
* Tune is an async call, with {@link OnTuneEventListener#LOCKED LOCKED} and {@link
|
||||
* OnTuneEventListener#NO_SIGNAL NO_SIGNAL} events sent to the {@link OnTuneEventListener}
|
||||
* specified in {@link #setOnTuneEventListener(Executor, OnTuneEventListener)}.
|
||||
*
|
||||
* @param settings Signal delivery information the frontend uses to
|
||||
* search and lock the signal.
|
||||
* @return result status of tune operation.
|
||||
* @throws SecurityException if the caller does not have appropriate permissions.
|
||||
* @see #setOnTuneEventListener(Executor, OnTuneEventListener)
|
||||
*/
|
||||
@RequiresPermission(android.Manifest.permission.ACCESS_TV_TUNER)
|
||||
@Result
|
||||
public int tune(@NonNull FrontendSettings settings) {
|
||||
TunerUtils.checkTunerPermission(mContext);
|
||||
return nativeTune(settings.getType(), settings);
|
||||
@@ -269,8 +312,6 @@ public final class Tuner implements AutoCloseable {
|
||||
* will be sent to attached filters.
|
||||
*
|
||||
* @return result status of the operation.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@RequiresPermission(android.Manifest.permission.ACCESS_TV_TUNER)
|
||||
@Result
|
||||
@@ -501,8 +542,8 @@ public final class Tuner implements AutoCloseable {
|
||||
}
|
||||
|
||||
private void onFrontendEvent(int eventType) {
|
||||
if (mHandler != null) {
|
||||
mHandler.sendMessage(mHandler.obtainMessage(MSG_ON_FRONTEND_EVENT, eventType, 0));
|
||||
if (mOnTunerEventExecutor != null && mOnTuneEventListener != null) {
|
||||
mOnTunerEventExecutor.execute(() -> mOnTuneEventListener.onTuneEvent(eventType));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,30 +47,6 @@ public final class TunerConstants {
|
||||
*/
|
||||
public static final int INVALID_STREAM_ID = Constants.Constant.INVALID_STREAM_ID;
|
||||
|
||||
|
||||
/** @hide */
|
||||
@IntDef(prefix = "FRONTEND_EVENT_TYPE_",
|
||||
value = {FRONTEND_EVENT_TYPE_LOCKED, FRONTEND_EVENT_TYPE_NO_SIGNAL,
|
||||
FRONTEND_EVENT_TYPE_LOST_LOCK})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface FrontendEventType {}
|
||||
/**
|
||||
* Frontend locked.
|
||||
* @hide
|
||||
*/
|
||||
public static final int FRONTEND_EVENT_TYPE_LOCKED = Constants.FrontendEventType.LOCKED;
|
||||
/**
|
||||
* No signal detected.
|
||||
* @hide
|
||||
*/
|
||||
public static final int FRONTEND_EVENT_TYPE_NO_SIGNAL = Constants.FrontendEventType.NO_SIGNAL;
|
||||
/**
|
||||
* Frontend lock lost.
|
||||
* @hide
|
||||
*/
|
||||
public static final int FRONTEND_EVENT_TYPE_LOST_LOCK = Constants.FrontendEventType.LOST_LOCK;
|
||||
|
||||
|
||||
/** @hide */
|
||||
@IntDef(flag = true, prefix = "FILTER_STATUS_", value = {FILTER_STATUS_DATA_READY,
|
||||
FILTER_STATUS_LOW_WATER, FILTER_STATUS_HIGH_WATER, FILTER_STATUS_OVERFLOW})
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 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.frontend;
|
||||
|
||||
/**
|
||||
* Frontend Callback.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public interface FrontendCallback {
|
||||
|
||||
/**
|
||||
* Invoked when there is a frontend event.
|
||||
*/
|
||||
void onEvent(int frontendEventType);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (C) 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.frontend;
|
||||
|
||||
import android.annotation.IntDef;
|
||||
import android.annotation.SystemApi;
|
||||
import android.hardware.tv.tuner.V1_0.Constants;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/**
|
||||
* Listens for tune events.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
public interface OnTuneEventListener {
|
||||
|
||||
/** @hide */
|
||||
@IntDef(prefix = "SIGNAL_", value = {SIGNAL_LOCKED, SIGNAL_NO_SIGNAL, SIGNAL_LOST_LOCK})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@interface TuneEvent {}
|
||||
|
||||
/** The frontend has locked to the signal specified by the tune method. */
|
||||
int SIGNAL_LOCKED = Constants.FrontendEventType.LOCKED;
|
||||
/** The frontend is unable to lock to the signal specified by the tune method. */
|
||||
int SIGNAL_NO_SIGNAL = Constants.FrontendEventType.NO_SIGNAL;
|
||||
/** The frontend has lost the lock to the signal specified by the tune method. */
|
||||
int SIGNAL_LOST_LOCK = Constants.FrontendEventType.LOST_LOCK;
|
||||
|
||||
/** Tune Event from the frontend */
|
||||
void onTuneEvent(@TuneEvent int tuneEvent);
|
||||
}
|
||||
Reference in New Issue
Block a user