diff --git a/media/java/android/media/tv/tuner/ITunerResourceManager.aidl b/media/java/android/media/tv/tuner/ITunerResourceManager.aidl new file mode 100644 index 0000000000000..c1fc7d82cea3b --- /dev/null +++ b/media/java/android/media/tv/tuner/ITunerResourceManager.aidl @@ -0,0 +1,138 @@ +/* + * 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; + +import android.media.tv.tuner.ITunerResourceManagerListener; +import android.media.tv.tuner.ResourceClientProfile; +import android.media.tv.tuner.TunerFrontendInfo; +import android.media.tv.tuner.TunerFrontendRequest; + +/** + * Interface of the Tuner Resource Manager. It manages resources used by TV Tuners. + *
Resources include: + *
Expected workflow is: + *
The profile contains information that can show the base priority score of the client. + * + * @param profile {@link ResourceClientProfile} profile of the current client + * @param listener {@link ITunerResourceManagerListener} a callback to + * reclaim clients' resources when needed. + * @param clientId returns a clientId from the resource manager when the + * the client registers its profile. + */ + void registerClientProfile(in ResourceClientProfile profile, + ITunerResourceManagerListener listener, out int[] clientId); + + /* + * This API is used by the client to unregister their profile with the Tuner Resource manager. + * + * @param clientId the client id that needs to be unregistered. + */ + void unregisterClientProfile(in int clientId); + + /* + * Updates a registered client's priority and niceValue. + * + * @param clientId the id of the client that is updating its profile. + * @param priority the priority that the client would like to update to. + * @param niceValue the nice value that the client would like to update to. + * + * @return true if the update is successful. + */ + boolean updateClientPriority(in int clientId, in int priority, in int niceValue); + + /* + * Updates the available Frontend resources information on the current device. + * + *
Note: This update must happen before the first + * {@link #requestFrontend(TunerFrontendRequest,int[])} and {@link #releaseFrontend(int)} call. + * + * @param infos an array of the available {@link TunerFrontendInfo} information. + */ + void setFrontendInfoList(in TunerFrontendInfo[] infos); + + /* + * This API is used by the Tuner framework to request an available frontend from the TunerHAL. + * + *
There are three possible scenarios: + *
Note: {@link #setFrontendInfoList(TunerFrontendInfo[])} must be called + * before this request. + * + * @param request {@link TunerFrontendRequest} information of the current request. + * @param frontendId a one-element array to return the granted frontendId. + * + * @return true if there is frontend granted. + */ + boolean requestFrontend(in TunerFrontendRequest request, out int[] frontendId); + + /* + * Requests to share frontend with an existing client. + * + *
Note: {@link #setFrontendInfoList(TunerFrontendInfo[])} must be called + * before this request. + * + * @param selfClientId the id of the client that sends the request. + * @param targetClientId the id of the client to share the frontend with. + */ + void shareFrontend(in int selfClientId, in int targetClientId); + + /* + * Notifies the TRM that the given frontend has been released. + * + *
Client must call this whenever it releases a Tuner frontend. + * + *
Note: {@link #setFrontendInfoList(TunerFrontendInfo[])} must be called + * before this release. + * + * @param frontendId the id of the released frontend. + */ + void releaseFrontend(in int frontendId); +} diff --git a/media/java/android/media/tv/tuner/ITunerResourceManagerListener.aidl b/media/java/android/media/tv/tuner/ITunerResourceManagerListener.aidl new file mode 100644 index 0000000000000..557032ca8d6d7 --- /dev/null +++ b/media/java/android/media/tv/tuner/ITunerResourceManagerListener.aidl @@ -0,0 +1,33 @@ +/* + * 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; + +/** + * Interface to receive callbacks from ITunerResourceManager. + * + * @hide + */ +oneway interface ITunerResourceManagerListener { + /* + * TRM invokes this method when the client's resources need to be reclaimed. + * + *
This method is implemented in Tuner Framework to take the reclaiming
+ * actions. It's a synchonized call. TRM would wait on the call to finish
+ * then grant the resource.
+ */
+ void onResourcesReclaim();
+}
\ No newline at end of file
diff --git a/media/java/android/media/tv/tuner/ResourceClientProfile.aidl b/media/java/android/media/tv/tuner/ResourceClientProfile.aidl
new file mode 100644
index 0000000000000..da3c5c4f15f92
--- /dev/null
+++ b/media/java/android/media/tv/tuner/ResourceClientProfile.aidl
@@ -0,0 +1,25 @@
+/*
+ * 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;
+
+/**
+ * A profile of a resource client. This profile is used to register the client info
+ * with the Tuner Resource Manager.
+ *
+ * @hide
+ */
+parcelable ResourceClientProfile;
\ No newline at end of file
diff --git a/media/java/android/media/tv/tuner/ResourceClientProfile.java b/media/java/android/media/tv/tuner/ResourceClientProfile.java
new file mode 100644
index 0000000000000..e2031353b27a4
--- /dev/null
+++ b/media/java/android/media/tv/tuner/ResourceClientProfile.java
@@ -0,0 +1,129 @@
+/*
+ * 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;
+
+import android.annotation.NonNull;
+import android.os.Parcel;
+import android.os.Parcelable;
+import android.util.Log;
+
+/**
+ * A profile of a resource client. This profile is used to register the client info
+ * with the Tuner Resource Manager(TRM).
+ *
+ * @hide
+ */
+public final class ResourceClientProfile implements Parcelable {
+ static final String TAG = "ResourceClientProfile";
+
+ public static final
+ @NonNull
+ Parcelable.Creator MediaCas, Tuner and TvInputHardwareManager get tvInputSessionId from TIS.
+ * If mTvInputSessionId is UNKNOWN, the client is always background.
+ */
+ private final String mTvInputSessionId;
+
+ /**
+ * Usage of the client.
+ */
+ private final int mUseCase;
+
+ private ResourceClientProfile(@NonNull Parcel source) {
+ mTvInputSessionId = source.readString();
+ mUseCase = source.readInt();
+ }
+
+ /**
+ * Constructs a new {@link ResourceClientProfile} with the given parameters.
+ *
+ * @param tvInputSessionId the unique id of the session owned by the client.
+ * @param useCase the usage of the client. Suggested priority hints are
+ * {@link android.media.tv.TvInputService.PRIORITY_HINT_USE_CASE_TYPE_PLAYBACK}
+ * {@link android.media.tv.TvInputService.PRIORITY_HINT_USE_CASE_TYPE_LIVE}
+ * {@link android.media.tv.TvInputService.PRIORITY_HINT_USE_CASE_TYPE_RECORD}.
+ * New [use case : priority value] pair can be defined in the manifest by the
+ * OEM. Any undefined use case would cause IllegalArgumentException.
+ */
+ public ResourceClientProfile(@NonNull String tvInputSessionId,
+ int useCase) {
+ mTvInputSessionId = tvInputSessionId;
+ mUseCase = useCase;
+ }
+
+ /**
+ * Returns the tv input session id of the client.
+ *
+ * @return the value of the tv input session id.
+ */
+ @NonNull
+ public String getTvInputSessionId() {
+ return mTvInputSessionId;
+ }
+
+ /**
+ * Returns the user usage of the client.
+ *
+ * @return the value of use case.
+ */
+ public int getUseCase() {
+ return mUseCase;
+ }
+
+ // Parcelable
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @NonNull
+ @Override
+ public String toString() {
+ StringBuilder b = new StringBuilder(128);
+ b.append("ResourceClientProfile {tvInputSessionId=").append(mTvInputSessionId);
+ b.append(", useCase=").append(mUseCase);
+ b.append("}");
+ return b.toString();
+ }
+
+ @Override
+ public void writeToParcel(@NonNull Parcel dest, int flags) {
+ dest.writeString(mTvInputSessionId);
+ dest.writeInt(mUseCase);
+ }
+}
diff --git a/media/java/android/media/tv/tuner/TunerFrontendInfo.aidl b/media/java/android/media/tv/tuner/TunerFrontendInfo.aidl
new file mode 100644
index 0000000000000..012e051d85980
--- /dev/null
+++ b/media/java/android/media/tv/tuner/TunerFrontendInfo.aidl
@@ -0,0 +1,24 @@
+/*
+ * 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;
+
+/**
+ * Simple container of the FrontendInfo struct defined in the TunerHAL 1.0 interface.
+ *
+ * @hide
+ */
+parcelable TunerFrontendInfo;
\ No newline at end of file
diff --git a/media/java/android/media/tv/tuner/TunerFrontendInfo.java b/media/java/android/media/tv/tuner/TunerFrontendInfo.java
new file mode 100644
index 0000000000000..a62ecb3893ea7
--- /dev/null
+++ b/media/java/android/media/tv/tuner/TunerFrontendInfo.java
@@ -0,0 +1,141 @@
+/*
+ * 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;
+
+import android.annotation.NonNull;
+import android.media.tv.tuner.frontend.FrontendSettings.Type;
+import android.os.Parcel;
+import android.os.Parcelable;
+import android.util.Log;
+
+/**
+ * Simple container of the FrontendInfo struct defined in the TunerHAL 1.0 interface.
+ *
+ * Note that this object is defined to pass necessary frontend info between the
+ * Tuner Resource Manager and the client. It includes partial information in
+ * {@link FrontendInfo}.
+ *
+ * @hide
+ */
+public final class TunerFrontendInfo implements Parcelable {
+ static final String TAG = "TunerFrontendInfo";
+
+ public static final
+ @NonNull
+ Parcelable.Creator