Move Tuner resource updating from Tuner java into Tuner client
Note that the main goal of this CL is to
move the resource updating with TunerResourceManager
from Tuner java into Tuner native client library.
This requires TunerResourceManager aidl interface to generate
both ndk and java library.
Also this CL removes the previously manually defined
TunerResourceManager java interface and use the automatically
generated java lib instead.
Some Android Services, such as MediaCase/TIF, that previously used the
manually defined TRM java APIs are changed to use the auto gen APIs
in this CL.
Test: atest android.media.tv.tuner.cts on Cuttlefish
Bug: 174095851
Change-Id: I46acdd2f118d5b082aa162c680661a304b4f628b
diff --git a/media/java/android/media/MediaCas.java b/media/java/android/media/MediaCas.java
index 9957975..582a28e 100644
--- a/media/java/android/media/MediaCas.java
+++ b/media/java/android/media/MediaCas.java
@@ -716,8 +716,9 @@
context.getSystemService(Context.TV_TUNER_RESOURCE_MGR_SERVICE);
if (mTunerResourceManager != null) {
int[] clientId = new int[1];
- ResourceClientProfile profile =
- new ResourceClientProfile(tvInputServiceSessionId, priorityHint);
+ ResourceClientProfile profile = new ResourceClientProfile();
+ profile.tvInputSessionId = tvInputServiceSessionId;
+ profile.useCase = priorityHint;
mTunerResourceManager.registerClientProfile(
profile, context.getMainExecutor(), mResourceListener, clientId);
mClientId = clientId[0];
@@ -921,7 +922,9 @@
int[] sessionResourceHandle = new int[1];
sessionResourceHandle[0] = -1;
if (mTunerResourceManager != null) {
- CasSessionRequest casSessionRequest = new CasSessionRequest(mClientId, mCasSystemId);
+ CasSessionRequest casSessionRequest = new CasSessionRequest();
+ casSessionRequest.clientId = mClientId;
+ casSessionRequest.casSystemId = mCasSystemId;
if (!mTunerResourceManager
.requestCasSession(casSessionRequest, sessionResourceHandle)) {
throw new MediaCasException.InsufficientResourceException(
diff --git a/media/java/android/media/tv/tuner/Tuner.java b/media/java/android/media/tv/tuner/Tuner.java
index 9abd8fc..1bd0e2c 100644
--- a/media/java/android/media/tv/tuner/Tuner.java
+++ b/media/java/android/media/tv/tuner/Tuner.java
@@ -46,7 +46,6 @@
import android.media.tv.tunerresourcemanager.ResourceClientProfile;
import android.media.tv.tunerresourcemanager.TunerDemuxRequest;
import android.media.tv.tunerresourcemanager.TunerDescramblerRequest;
-import android.media.tv.tunerresourcemanager.TunerFrontendInfo;
import android.media.tv.tunerresourcemanager.TunerFrontendRequest;
import android.media.tv.tunerresourcemanager.TunerLnbRequest;
import android.media.tv.tunerresourcemanager.TunerResourceManager;
@@ -343,33 +342,14 @@
mHandler = createEventHandler();
int[] clientId = new int[1];
- ResourceClientProfile profile = new ResourceClientProfile(tvInputSessionId, useCase);
+ ResourceClientProfile profile = new ResourceClientProfile();
+ profile.tvInputSessionId = tvInputSessionId;
+ profile.useCase = useCase;
mTunerResourceManager.registerClientProfile(
profile, new HandlerExecutor(mHandler), mResourceListener, clientId);
mClientId = clientId[0];
mUserId = ActivityManager.getCurrentUser();
-
- setFrontendInfoList();
- }
-
- private void setFrontendInfoList() {
- List<Integer> ids = getFrontendIds();
- if (ids == null) {
- return;
- }
- TunerFrontendInfo[] infos = new TunerFrontendInfo[ids.size()];
- for (int i = 0; i < ids.size(); i++) {
- int id = ids.get(i);
- FrontendInfo frontendInfo = getFrontendInfoById(id);
- if (frontendInfo == null) {
- continue;
- }
- TunerFrontendInfo tunerFrontendInfo = new TunerFrontendInfo(
- id, frontendInfo.getType(), frontendInfo.getExclusiveGroupId());
- infos[i] = tunerFrontendInfo;
- }
- mTunerResourceManager.setFrontendInfoList(infos);
}
/**
@@ -804,7 +784,9 @@
private boolean requestFrontend() {
int[] feHandle = new int[1];
- TunerFrontendRequest request = new TunerFrontendRequest(mClientId, mFrontendType);
+ TunerFrontendRequest request = new TunerFrontendRequest();
+ request.clientId = mClientId;
+ request.frontendType = mFrontendType;
boolean granted = mTunerResourceManager.requestFrontend(request, feHandle);
if (granted) {
mFrontendHandle = feHandle[0];
@@ -1258,7 +1240,8 @@
private boolean requestLnb() {
int[] lnbHandle = new int[1];
- TunerLnbRequest request = new TunerLnbRequest(mClientId);
+ TunerLnbRequest request = new TunerLnbRequest();
+ request.clientId = mClientId;
boolean granted = mTunerResourceManager.requestLnb(request, lnbHandle);
if (granted) {
mLnbHandle = lnbHandle[0];
@@ -1346,7 +1329,8 @@
private boolean requestDemux() {
int[] demuxHandle = new int[1];
- TunerDemuxRequest request = new TunerDemuxRequest(mClientId);
+ TunerDemuxRequest request = new TunerDemuxRequest();
+ request.clientId = mClientId;
boolean granted = mTunerResourceManager.requestDemux(request, demuxHandle);
if (granted) {
mDemuxHandle = demuxHandle[0];
@@ -1357,7 +1341,8 @@
private Descrambler requestDescrambler() {
int[] descramblerHandle = new int[1];
- TunerDescramblerRequest request = new TunerDescramblerRequest(mClientId);
+ TunerDescramblerRequest request = new TunerDescramblerRequest();
+ request.clientId = mClientId;
boolean granted = mTunerResourceManager.requestDescrambler(request, descramblerHandle);
if (!granted) {
return null;
diff --git a/media/java/android/media/tv/tunerresourcemanager/Android.bp b/media/java/android/media/tv/tunerresourcemanager/Android.bp
index c65d25a..cb2e190 100644
--- a/media/java/android/media/tv/tunerresourcemanager/Android.bp
+++ b/media/java/android/media/tv/tunerresourcemanager/Android.bp
@@ -1,17 +1,35 @@
filegroup {
- name: "framework-media-tv-tunerresourcemanager-sources",
+ name: "framework-media-tv-tunerresourcemanager-sources-aidl",
srcs: [
- "*.java",
- "*.aidl",
+ "aidl/android/media/tv/tunerresourcemanager/CasSessionRequest.aidl",
+ "aidl/android/media/tv/tunerresourcemanager/IResourcesReclaimListener.aidl",
+ "aidl/android/media/tv/tunerresourcemanager/ResourceClientProfile.aidl",
+ "aidl/android/media/tv/tunerresourcemanager/TunerDemuxRequest.aidl",
+ "aidl/android/media/tv/tunerresourcemanager/TunerDescramblerRequest.aidl",
+ "aidl/android/media/tv/tunerresourcemanager/TunerFrontendInfo.aidl",
+ "aidl/android/media/tv/tunerresourcemanager/TunerFrontendRequest.aidl",
+ "aidl/android/media/tv/tunerresourcemanager/TunerLnbRequest.aidl",
+ "aidl/android/media/tv/tunerresourcemanager/ITunerResourceManager.aidl",
],
- path: ".",
+ path: "aidl",
}
-java_library {
- name: "framework-media-tv-trm-sources",
- srcs: [":framework-media-tv-tunerresourcemanager-sources"],
- installable: true,
- visibility: [
- "//frameworks/base",
+aidl_interface {
+ name: "tv_tuner_resource_manager_aidl_interface",
+ unstable: true,
+ local_include_dir: "aidl",
+ backend: {
+ java: {
+ sdk_version: "current",
+ },
+ cpp: {
+ enabled: true,
+ },
+ ndk: {
+ enabled: true,
+ },
+ },
+ srcs: [
+ ":framework-media-tv-tunerresourcemanager-sources-aidl",
],
-}
\ No newline at end of file
+}
diff --git a/media/java/android/media/tv/tunerresourcemanager/CasSessionRequest.java b/media/java/android/media/tv/tunerresourcemanager/CasSessionRequest.java
deleted file mode 100644
index 59802ff..0000000
--- a/media/java/android/media/tv/tunerresourcemanager/CasSessionRequest.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * 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.tunerresourcemanager;
-
-import android.annotation.NonNull;
-import android.os.Parcel;
-import android.os.Parcelable;
-import android.util.Log;
-
-/**
- * Information required to request a Cas Session.
- *
- * @hide
- */
-public final class CasSessionRequest implements Parcelable {
- static final String TAG = "CasSessionRequest";
-
- public static final
- @NonNull
- Parcelable.Creator<CasSessionRequest> CREATOR =
- new Parcelable.Creator<CasSessionRequest>() {
- @Override
- public CasSessionRequest createFromParcel(Parcel source) {
- try {
- return new CasSessionRequest(source);
- } catch (Exception e) {
- Log.e(TAG, "Exception creating CasSessionRequest from parcel", e);
- return null;
- }
- }
-
- @Override
- public CasSessionRequest[] newArray(int size) {
- return new CasSessionRequest[size];
- }
- };
-
- /**
- * Client id of the client that sends the request.
- */
- private final int mClientId;
-
- /**
- * System id of the requested cas.
- */
- private final int mCasSystemId;
-
- private CasSessionRequest(@NonNull Parcel source) {
- mClientId = source.readInt();
- mCasSystemId = source.readInt();
- }
-
- /**
- * Constructs a new {@link CasSessionRequest} with the given parameters.
- *
- * @param clientId id of the client.
- * @param casSystemId the cas system id that the client is requesting.
- */
- public CasSessionRequest(int clientId,
- int casSystemId) {
- mClientId = clientId;
- mCasSystemId = casSystemId;
- }
-
- /**
- * Returns the id of the client.
- */
- public int getClientId() {
- return mClientId;
- }
-
- /**
- * Returns the cas system id requested.
- */
- public int getCasSystemId() {
- return mCasSystemId;
- }
-
- // Parcelable
- @Override
- public int describeContents() {
- return 0;
- }
-
- @NonNull
- @Override
- public String toString() {
- StringBuilder b = new StringBuilder(128);
- b.append("CasSessionRequest {clientId=").append(mClientId);
- b.append(", casSystemId=").append(mCasSystemId);
- b.append("}");
- return b.toString();
- }
-
- @Override
- public void writeToParcel(@NonNull Parcel dest, int flags) {
- dest.writeInt(mClientId);
- dest.writeInt(mCasSystemId);
- }
-}
diff --git a/media/java/android/media/tv/tunerresourcemanager/ResourceClientProfile.java b/media/java/android/media/tv/tunerresourcemanager/ResourceClientProfile.java
deleted file mode 100644
index 28f1ac9..0000000
--- a/media/java/android/media/tv/tunerresourcemanager/ResourceClientProfile.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * 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.tunerresourcemanager;
-
-import android.annotation.NonNull;
-import android.annotation.Nullable;
-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<ResourceClientProfile> CREATOR =
- new Parcelable.Creator<ResourceClientProfile>() {
- @Override
- public ResourceClientProfile createFromParcel(Parcel source) {
- try {
- return new ResourceClientProfile(source);
- } catch (Exception e) {
- Log.e(TAG, "Exception creating ResourceClientProfile from parcel", e);
- return null;
- }
- }
-
- @Override
- public ResourceClientProfile[] newArray(int size) {
- return new ResourceClientProfile[size];
- }
- };
-
- /**
- * This is used by TRM to get TV App’s processId from TIF.
- * The processId will be used to identify foreground applications.
- *
- * <p>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. The id of the useCaseVendor should be passed through this parameter. Any
- * undefined use case would cause IllegalArgumentException.
- */
- public ResourceClientProfile(@Nullable 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.
- */
- @Nullable
- 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/tunerresourcemanager/TunerDemuxRequest.java b/media/java/android/media/tv/tunerresourcemanager/TunerDemuxRequest.java
deleted file mode 100644
index 34a7761..0000000
--- a/media/java/android/media/tv/tunerresourcemanager/TunerDemuxRequest.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * 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.tunerresourcemanager;
-
-import android.annotation.NonNull;
-import android.os.Parcel;
-import android.os.Parcelable;
-import android.util.Log;
-
-/**
- * Information required to request a Tuner Demux.
- *
- * @hide
- */
-public final class TunerDemuxRequest implements Parcelable {
- static final String TAG = "TunerDemuxRequest";
-
- public static final
- @NonNull
- Parcelable.Creator<TunerDemuxRequest> CREATOR =
- new Parcelable.Creator<TunerDemuxRequest>() {
- @Override
- public TunerDemuxRequest createFromParcel(Parcel source) {
- try {
- return new TunerDemuxRequest(source);
- } catch (Exception e) {
- Log.e(TAG, "Exception creating TunerDemuxRequest from parcel", e);
- return null;
- }
- }
-
- @Override
- public TunerDemuxRequest[] newArray(int size) {
- return new TunerDemuxRequest[size];
- }
- };
-
- /**
- * Client id of the client that sends the request.
- */
- private final int mClientId;
-
- private TunerDemuxRequest(@NonNull Parcel source) {
- mClientId = source.readInt();
- }
-
- /**
- * Constructs a new {@link TunerDemuxRequest} with the given parameters.
- *
- * @param clientId id of the client.
- */
- public TunerDemuxRequest(int clientId) {
- mClientId = clientId;
- }
-
- /**
- * Returns the id of the client.
- */
- public int getClientId() {
- return mClientId;
- }
-
- // Parcelable
- @Override
- public int describeContents() {
- return 0;
- }
-
- @NonNull
- @Override
- public String toString() {
- StringBuilder b = new StringBuilder(128);
- b.append("TunerDemuxRequest {clientId=").append(mClientId);
- b.append("}");
- return b.toString();
- }
-
- @Override
- public void writeToParcel(@NonNull Parcel dest, int flags) {
- dest.writeInt(mClientId);
- }
-}
diff --git a/media/java/android/media/tv/tunerresourcemanager/TunerDescramblerRequest.java b/media/java/android/media/tv/tunerresourcemanager/TunerDescramblerRequest.java
deleted file mode 100644
index 5816287..0000000
--- a/media/java/android/media/tv/tunerresourcemanager/TunerDescramblerRequest.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * 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.tunerresourcemanager;
-
-import android.annotation.NonNull;
-import android.os.Parcel;
-import android.os.Parcelable;
-import android.util.Log;
-
-/**
- * Information required to request a Tuner Descrambler.
- *
- * @hide
- */
-public final class TunerDescramblerRequest implements Parcelable {
- static final String TAG = "TunerDescramblerRequest";
-
- public static final
- @NonNull
- Parcelable.Creator<TunerDescramblerRequest> CREATOR =
- new Parcelable.Creator<TunerDescramblerRequest>() {
- @Override
- public TunerDescramblerRequest createFromParcel(Parcel source) {
- try {
- return new TunerDescramblerRequest(source);
- } catch (Exception e) {
- Log.e(TAG, "Exception creating TunerDescramblerRequest from parcel", e);
- return null;
- }
- }
-
- @Override
- public TunerDescramblerRequest[] newArray(int size) {
- return new TunerDescramblerRequest[size];
- }
- };
-
- /**
- * Client id of the client that sends the request.
- */
- private final int mClientId;
-
- private TunerDescramblerRequest(@NonNull Parcel source) {
- mClientId = source.readInt();
- }
-
- /**
- * Constructs a new {@link TunerDescramblerRequest} with the given parameters.
- *
- * @param clientId id of the client.
- */
- public TunerDescramblerRequest(int clientId) {
- mClientId = clientId;
- }
-
- /**
- * Returns the id of the client.
- */
- public int getClientId() {
- return mClientId;
- }
-
- // Parcelable
- @Override
- public int describeContents() {
- return 0;
- }
-
- @NonNull
- @Override
- public String toString() {
- StringBuilder b = new StringBuilder(128);
- b.append("TunerDescramblerRequest {clientId=").append(mClientId);
- b.append("}");
- return b.toString();
- }
-
- @Override
- public void writeToParcel(@NonNull Parcel dest, int flags) {
- dest.writeInt(mClientId);
- }
-}
diff --git a/media/java/android/media/tv/tunerresourcemanager/TunerFrontendInfo.java b/media/java/android/media/tv/tunerresourcemanager/TunerFrontendInfo.java
deleted file mode 100644
index ef50aac..0000000
--- a/media/java/android/media/tv/tunerresourcemanager/TunerFrontendInfo.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * 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.tunerresourcemanager;
-
-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.
- *
- * <p>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<TunerFrontendInfo> CREATOR =
- new Parcelable.Creator<TunerFrontendInfo>() {
- @Override
- public TunerFrontendInfo createFromParcel(Parcel source) {
- try {
- return new TunerFrontendInfo(source);
- } catch (Exception e) {
- Log.e(TAG, "Exception creating TunerFrontendInfo from parcel", e);
- return null;
- }
- }
-
- @Override
- public TunerFrontendInfo[] newArray(int size) {
- return new TunerFrontendInfo[size];
- }
- };
-
- private final int mHandle;
-
- @Type
- private final int mFrontendType;
-
- /**
- * Frontends are assigned with the same exclusiveGroupId if they can't
- * function at same time. For instance, they share same hardware module.
- */
- private final int mExclusiveGroupId;
-
- private TunerFrontendInfo(@NonNull Parcel source) {
- mHandle = source.readInt();
- mFrontendType = source.readInt();
- mExclusiveGroupId = source.readInt();
- }
-
- /**
- * Constructs a new {@link TunerFrontendInfo} with the given parameters.
- *
- * @param handle frontend handle
- * @param frontendType the type of the frontend.
- * @param exclusiveGroupId the group id of the frontend. FE with the same
- group id can't function at the same time.
- */
- public TunerFrontendInfo(int handle,
- @Type int frontendType,
- int exclusiveGroupId) {
- mHandle = handle;
- mFrontendType = frontendType;
- mExclusiveGroupId = exclusiveGroupId;
- }
-
- /**
- * Returns the frontend handle.
- *
- * @return the value of the frontend handle.
- */
- public int getHandle() {
- return mHandle;
- }
-
- /**
- * Returns the application id that requests the tuner frontend resource.
- *
- * @return the value of the frontend type.
- */
- @Type
- public int getFrontendType() {
- return mFrontendType;
- }
-
- /**
- * Returns the exclusiveGroupId. Frontends with the same exclusiveGroupId
- * can't function at same time.
- *
- * @return the value of the exclusive group id.
- */
- public int getExclusiveGroupId() {
- return mExclusiveGroupId;
- }
-
- // Parcelable
- @Override
- public int describeContents() {
- return 0;
- }
-
- @NonNull
- @Override
- public String toString() {
- StringBuilder b = new StringBuilder(128);
- b.append("TunerFrontendInfo {handle=").append(mHandle);
- b.append(", frontendType=").append(mFrontendType);
- b.append(", exclusiveGroupId=").append(mExclusiveGroupId);
- b.append("}");
- return b.toString();
- }
-
- @Override
- public void writeToParcel(@NonNull Parcel dest, int flags) {
- dest.writeInt(mHandle);
- dest.writeInt(mFrontendType);
- dest.writeInt(mExclusiveGroupId);
- }
-}
diff --git a/media/java/android/media/tv/tunerresourcemanager/TunerFrontendRequest.java b/media/java/android/media/tv/tunerresourcemanager/TunerFrontendRequest.java
deleted file mode 100644
index 12f8032..0000000
--- a/media/java/android/media/tv/tunerresourcemanager/TunerFrontendRequest.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * 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.tunerresourcemanager;
-
-import android.annotation.NonNull;
-import android.media.tv.tuner.frontend.FrontendSettings.Type;
-import android.os.Parcel;
-import android.os.Parcelable;
-import android.util.Log;
-
-/**
- * Information required to request a Tuner Frontend.
- *
- * @hide
- */
-public final class TunerFrontendRequest implements Parcelable {
- static final String TAG = "TunerFrontendRequest";
-
- public static final
- @NonNull
- Parcelable.Creator<TunerFrontendRequest> CREATOR =
- new Parcelable.Creator<TunerFrontendRequest>() {
- @Override
- public TunerFrontendRequest createFromParcel(Parcel source) {
- try {
- return new TunerFrontendRequest(source);
- } catch (Exception e) {
- Log.e(TAG, "Exception creating TunerFrontendRequest from parcel", e);
- return null;
- }
- }
-
- @Override
- public TunerFrontendRequest[] newArray(int size) {
- return new TunerFrontendRequest[size];
- }
- };
-
- private final int mClientId;
- @Type
- private final int mFrontendType;
-
- private TunerFrontendRequest(@NonNull Parcel source) {
- mClientId = source.readInt();
- mFrontendType = source.readInt();
- }
-
- /**
- * Constructs a new {@link TunerFrontendRequest} with the given parameters.
- *
- * @param clientId the unique id of the client returned when registering profile.
- * @param frontendType the type of the requested frontend.
- */
- public TunerFrontendRequest(int clientId,
- @Type int frontendType) {
- mClientId = clientId;
- mFrontendType = frontendType;
- }
-
- /**
- * Returns the client id that requests the tuner frontend resource.
- *
- * @return the value of the client id.
- */
- public int getClientId() {
- return mClientId;
- }
-
- /**
- * Returns the frontend type that the client requests for.
- *
- * @return the value of the requested frontend type.
- */
- @Type
- public int getFrontendType() {
- return mFrontendType;
- }
-
- // Parcelable
- @Override
- public int describeContents() {
- return 0;
- }
-
- @NonNull
- @Override
- public String toString() {
- StringBuilder b = new StringBuilder(128);
- b.append("TunerFrontendRequest {clientId=").append(mClientId);
- b.append(", frontendType=").append(mFrontendType);
- b.append("}");
- return b.toString();
- }
-
- @Override
- public void writeToParcel(@NonNull Parcel dest, int flags) {
- dest.writeInt(mClientId);
- dest.writeInt(mFrontendType);
- }
-}
diff --git a/media/java/android/media/tv/tunerresourcemanager/TunerLnbRequest.java b/media/java/android/media/tv/tunerresourcemanager/TunerLnbRequest.java
deleted file mode 100644
index 5ed7f3f..0000000
--- a/media/java/android/media/tv/tunerresourcemanager/TunerLnbRequest.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * 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.tunerresourcemanager;
-
-import android.annotation.NonNull;
-import android.os.Parcel;
-import android.os.Parcelable;
-import android.util.Log;
-
-/**
- * Information required to request a Tuner Lnb.
- *
- * @hide
- */
-public final class TunerLnbRequest implements Parcelable {
- static final String TAG = "TunerLnbRequest";
-
- public static final
- @NonNull
- Parcelable.Creator<TunerLnbRequest> CREATOR =
- new Parcelable.Creator<TunerLnbRequest>() {
- @Override
- public TunerLnbRequest createFromParcel(Parcel source) {
- try {
- return new TunerLnbRequest(source);
- } catch (Exception e) {
- Log.e(TAG, "Exception creating TunerLnbRequest from parcel", e);
- return null;
- }
- }
-
- @Override
- public TunerLnbRequest[] newArray(int size) {
- return new TunerLnbRequest[size];
- }
- };
-
- /**
- * Client id of the client that sends the request.
- */
- private final int mClientId;
-
- private TunerLnbRequest(@NonNull Parcel source) {
- mClientId = source.readInt();
- }
-
- /**
- * Constructs a new {@link TunerLnbRequest} with the given parameters.
- *
- * @param clientId the id of the client.
- */
- public TunerLnbRequest(int clientId) {
- mClientId = clientId;
- }
-
- /**
- * Returns the id of the client
- */
- public int getClientId() {
- return mClientId;
- }
-
- // Parcelable
- @Override
- public int describeContents() {
- return 0;
- }
-
- @NonNull
- @Override
- public String toString() {
- StringBuilder b = new StringBuilder(128);
- b.append("TunerLnbRequest {clientId=").append(mClientId);
- b.append("}");
- return b.toString();
- }
-
- @Override
- public void writeToParcel(@NonNull Parcel dest, int flags) {
- dest.writeInt(mClientId);
- }
-}
diff --git a/media/java/android/media/tv/tunerresourcemanager/CasSessionRequest.aidl b/media/java/android/media/tv/tunerresourcemanager/aidl/android/media/tv/tunerresourcemanager/CasSessionRequest.aidl
similarity index 91%
rename from media/java/android/media/tv/tunerresourcemanager/CasSessionRequest.aidl
rename to media/java/android/media/tv/tunerresourcemanager/aidl/android/media/tv/tunerresourcemanager/CasSessionRequest.aidl
index c918d88..88f5915 100644
--- a/media/java/android/media/tv/tunerresourcemanager/CasSessionRequest.aidl
+++ b/media/java/android/media/tv/tunerresourcemanager/aidl/android/media/tv/tunerresourcemanager/CasSessionRequest.aidl
@@ -21,4 +21,8 @@
*
* @hide
*/
-parcelable CasSessionRequest;
\ No newline at end of file
+parcelable CasSessionRequest {
+ int clientId;
+
+ int casSystemId;
+}
\ No newline at end of file
diff --git a/media/java/android/media/tv/tunerresourcemanager/IResourcesReclaimListener.aidl b/media/java/android/media/tv/tunerresourcemanager/aidl/android/media/tv/tunerresourcemanager/IResourcesReclaimListener.aidl
similarity index 100%
rename from media/java/android/media/tv/tunerresourcemanager/IResourcesReclaimListener.aidl
rename to media/java/android/media/tv/tunerresourcemanager/aidl/android/media/tv/tunerresourcemanager/IResourcesReclaimListener.aidl
diff --git a/media/java/android/media/tv/tunerresourcemanager/ITunerResourceManager.aidl b/media/java/android/media/tv/tunerresourcemanager/aidl/android/media/tv/tunerresourcemanager/ITunerResourceManager.aidl
similarity index 100%
rename from media/java/android/media/tv/tunerresourcemanager/ITunerResourceManager.aidl
rename to media/java/android/media/tv/tunerresourcemanager/aidl/android/media/tv/tunerresourcemanager/ITunerResourceManager.aidl
diff --git a/media/java/android/media/tv/tunerresourcemanager/ResourceClientProfile.aidl b/media/java/android/media/tv/tunerresourcemanager/aidl/android/media/tv/tunerresourcemanager/ResourceClientProfile.aidl
similarity index 90%
rename from media/java/android/media/tv/tunerresourcemanager/ResourceClientProfile.aidl
rename to media/java/android/media/tv/tunerresourcemanager/aidl/android/media/tv/tunerresourcemanager/ResourceClientProfile.aidl
index ed90c1d..08c2bb8 100644
--- a/media/java/android/media/tv/tunerresourcemanager/ResourceClientProfile.aidl
+++ b/media/java/android/media/tv/tunerresourcemanager/aidl/android/media/tv/tunerresourcemanager/ResourceClientProfile.aidl
@@ -22,4 +22,8 @@
*
* @hide
*/
-parcelable ResourceClientProfile;
\ No newline at end of file
+parcelable ResourceClientProfile {
+ String tvInputSessionId;
+
+ int useCase;
+}
\ No newline at end of file
diff --git a/media/java/android/media/tv/tunerresourcemanager/TunerDemuxRequest.aidl b/media/java/android/media/tv/tunerresourcemanager/aidl/android/media/tv/tunerresourcemanager/TunerDemuxRequest.aidl
similarity index 93%
rename from media/java/android/media/tv/tunerresourcemanager/TunerDemuxRequest.aidl
rename to media/java/android/media/tv/tunerresourcemanager/aidl/android/media/tv/tunerresourcemanager/TunerDemuxRequest.aidl
index 919a215..457f90c 100644
--- a/media/java/android/media/tv/tunerresourcemanager/TunerDemuxRequest.aidl
+++ b/media/java/android/media/tv/tunerresourcemanager/aidl/android/media/tv/tunerresourcemanager/TunerDemuxRequest.aidl
@@ -21,4 +21,6 @@
*
* @hide
*/
-parcelable TunerDemuxRequest;
\ No newline at end of file
+parcelable TunerDemuxRequest {
+ int clientId;
+}
\ No newline at end of file
diff --git a/media/java/android/media/tv/tunerresourcemanager/TunerDescramblerRequest.aidl b/media/java/android/media/tv/tunerresourcemanager/aidl/android/media/tv/tunerresourcemanager/TunerDescramblerRequest.aidl
similarity index 92%
rename from media/java/android/media/tv/tunerresourcemanager/TunerDescramblerRequest.aidl
rename to media/java/android/media/tv/tunerresourcemanager/aidl/android/media/tv/tunerresourcemanager/TunerDescramblerRequest.aidl
index fbafb3b..98ab730 100644
--- a/media/java/android/media/tv/tunerresourcemanager/TunerDescramblerRequest.aidl
+++ b/media/java/android/media/tv/tunerresourcemanager/aidl/android/media/tv/tunerresourcemanager/TunerDescramblerRequest.aidl
@@ -21,4 +21,6 @@
*
* @hide
*/
-parcelable TunerDescramblerRequest;
\ No newline at end of file
+parcelable TunerDescramblerRequest {
+ int clientId;
+}
\ No newline at end of file
diff --git a/media/java/android/media/tv/tunerresourcemanager/TunerFrontendInfo.aidl b/media/java/android/media/tv/tunerresourcemanager/aidl/android/media/tv/tunerresourcemanager/TunerFrontendInfo.aidl
similarity index 88%
rename from media/java/android/media/tv/tunerresourcemanager/TunerFrontendInfo.aidl
rename to media/java/android/media/tv/tunerresourcemanager/aidl/android/media/tv/tunerresourcemanager/TunerFrontendInfo.aidl
index e649c2a..edf96dd 100644
--- a/media/java/android/media/tv/tunerresourcemanager/TunerFrontendInfo.aidl
+++ b/media/java/android/media/tv/tunerresourcemanager/aidl/android/media/tv/tunerresourcemanager/TunerFrontendInfo.aidl
@@ -21,4 +21,10 @@
*
* @hide
*/
-parcelable TunerFrontendInfo;
\ No newline at end of file
+parcelable TunerFrontendInfo {
+ int handle;
+
+ int frontendType;
+
+ int exclusiveGroupId;
+}
diff --git a/media/java/android/media/tv/tunerresourcemanager/TunerFrontendRequest.aidl b/media/java/android/media/tv/tunerresourcemanager/aidl/android/media/tv/tunerresourcemanager/TunerFrontendRequest.aidl
similarity index 90%
rename from media/java/android/media/tv/tunerresourcemanager/TunerFrontendRequest.aidl
rename to media/java/android/media/tv/tunerresourcemanager/aidl/android/media/tv/tunerresourcemanager/TunerFrontendRequest.aidl
index 5e48adc..4d98222 100644
--- a/media/java/android/media/tv/tunerresourcemanager/TunerFrontendRequest.aidl
+++ b/media/java/android/media/tv/tunerresourcemanager/aidl/android/media/tv/tunerresourcemanager/TunerFrontendRequest.aidl
@@ -21,4 +21,8 @@
*
* @hide
*/
-parcelable TunerFrontendRequest;
\ No newline at end of file
+parcelable TunerFrontendRequest {
+ int clientId;
+
+ int frontendType;
+}
\ No newline at end of file
diff --git a/media/java/android/media/tv/tunerresourcemanager/TunerLnbRequest.aidl b/media/java/android/media/tv/tunerresourcemanager/aidl/android/media/tv/tunerresourcemanager/TunerLnbRequest.aidl
similarity index 93%
rename from media/java/android/media/tv/tunerresourcemanager/TunerLnbRequest.aidl
rename to media/java/android/media/tv/tunerresourcemanager/aidl/android/media/tv/tunerresourcemanager/TunerLnbRequest.aidl
index 0e6fcde..1a059ea 100644
--- a/media/java/android/media/tv/tunerresourcemanager/TunerLnbRequest.aidl
+++ b/media/java/android/media/tv/tunerresourcemanager/aidl/android/media/tv/tunerresourcemanager/TunerLnbRequest.aidl
@@ -21,4 +21,6 @@
*
* @hide
*/
-parcelable TunerLnbRequest;
\ No newline at end of file
+parcelable TunerLnbRequest {
+ int clientId;
+}
\ No newline at end of file
diff --git a/media/jni/Android.bp b/media/jni/Android.bp
index f80f412..decf68f 100644
--- a/media/jni/Android.bp
+++ b/media/jni/Android.bp
@@ -137,6 +137,7 @@
cc_library_shared {
name: "libmedia_tv_tuner",
+
srcs: [
"android_media_tv_Tuner.cpp",
"tuner/DemuxClient.cpp",
@@ -163,6 +164,7 @@
"libnativehelper",
"libutils",
"tv_tuner_aidl_interface-ndk_platform",
+ "tv_tuner_resource_manager_aidl_interface-ndk_platform"
],
defaults: [
"libcodec2-impl-defaults",
diff --git a/media/jni/tuner/TunerClient.cpp b/media/jni/tuner/TunerClient.cpp
index b14e902..39e6ba2 100644
--- a/media/jni/tuner/TunerClient.cpp
+++ b/media/jni/tuner/TunerClient.cpp
@@ -25,6 +25,8 @@
using ::android::hardware::tv::tuner::V1_0::FrontendId;
using ::android::hardware::tv::tuner::V1_0::FrontendType;
+using ::aidl::android::media::tv::tunerresourcemanager::TunerFrontendInfo;
+
namespace android {
sp<ITuner> TunerClient::mTuner;
@@ -37,6 +39,7 @@
TunerClient::TunerClient() {
// Get HIDL Tuner in migration stage.
getHidlTuner();
+ updateTunerResources();
// Connect with Tuner Service.
::ndk::SpAIBinder binder(AServiceManager_getService("media.tuner"));
mTunerService = ITunerService::fromBinder(binder);
@@ -259,6 +262,49 @@
/////////////// TunerClient Helper Methods ///////////////////////
+void TunerClient::updateTunerResources() {
+ if (mTuner == NULL) {
+ return;
+ }
+
+ // Connect with Tuner Resource Manager.
+ ::ndk::SpAIBinder binder(AServiceManager_getService("tv_tuner_resource_mgr"));
+ mTunerResourceManager = ITunerResourceManager::fromBinder(binder);
+
+ updateFrontendResources();
+ updateLnbResources();
+ // TODO: update Demux, Descrambler.
+}
+
+void TunerClient::updateFrontendResources() {
+ vector<FrontendId> ids = getFrontendIds();
+ if (ids.size() == 0) {
+ return;
+ }
+ vector<TunerFrontendInfo> infos;
+ for (int i = 0; i < ids.size(); i++) {
+ shared_ptr<FrontendInfo> frontendInfo = getFrontendInfo((int)ids[i]);
+ if (frontendInfo == NULL) {
+ continue;
+ }
+ TunerFrontendInfo tunerFrontendInfo{
+ .handle = getResourceHandleFromId((int)ids[i], FRONTEND),
+ .frontendType = static_cast<int>(frontendInfo->type),
+ .exclusiveGroupId = static_cast<int>(frontendInfo->exclusiveGroupId),
+ };
+ infos.push_back(tunerFrontendInfo);
+ }
+ mTunerResourceManager->setFrontendInfoList(infos);
+}
+
+void TunerClient::updateLnbResources() {
+ vector<int> handles = getLnbHandles();
+ if (handles.size() == 0) {
+ return;
+ }
+ mTunerResourceManager->setLnbInfoList(handles);
+}
+
sp<ITuner> TunerClient::getHidlTuner() {
if (mTuner == NULL) {
mTunerVersion = 0;
@@ -366,6 +412,32 @@
return descrambler;
}
+vector<int> TunerClient::getLnbHandles() {
+ vector<int> lnbHandles;
+
+ if (mTunerService != NULL) {
+ // TODO: pending hidl interface
+ }
+
+ if (mTuner != NULL) {
+ Result res;
+ vector<LnbId> lnbIds;
+ mTuner->getLnbIds([&](Result r, const hardware::hidl_vec<LnbId>& ids) {
+ lnbIds = ids;
+ res = r;
+ });
+ if (res != Result::SUCCESS || lnbIds.size() == 0) {
+ ALOGW("Lnb isn't available");
+ } else {
+ for (int i = 0; i < lnbIds.size(); i++) {
+ lnbHandles.push_back(getResourceHandleFromId((int)lnbIds[i], LNB));
+ }
+ }
+ }
+
+ return lnbHandles;
+}
+
FrontendInfo TunerClient::FrontendInfoAidlToHidl(TunerServiceFrontendInfo aidlFrontendInfo) {
FrontendInfo hidlFrontendInfo {
.type = static_cast<FrontendType>(aidlFrontendInfo.type),
diff --git a/media/jni/tuner/TunerClient.h b/media/jni/tuner/TunerClient.h
index 94fdf27..a3d2d02c 100644
--- a/media/jni/tuner/TunerClient.h
+++ b/media/jni/tuner/TunerClient.h
@@ -17,6 +17,8 @@
#ifndef _ANDROID_MEDIA_TV_TUNER_CLIENT_H_
#define _ANDROID_MEDIA_TV_TUNER_CLIENT_H_
+#include <aidl/android/media/tv/tunerresourcemanager/ITunerResourceManager.h>
+#include <aidl/android/media/tv/tunerresourcemanager/TunerFrontendInfo.h>
#include <aidl/android/media/tv/tuner/ITunerService.h>
#include <android/hardware/tv/tuner/1.1/ITuner.h>
#include <android/hardware/tv/tuner/1.1/types.h>
@@ -28,10 +30,12 @@
using ::aidl::android::media::tv::tuner::ITunerService;
using ::aidl::android::media::tv::tuner::TunerServiceFrontendInfo;
+using ::aidl::android::media::tv::tunerresourcemanager::ITunerResourceManager;
using ::android::hardware::tv::tuner::V1_0::DemuxCapabilities;
using ::android::hardware::tv::tuner::V1_0::FrontendId;
using ::android::hardware::tv::tuner::V1_0::ITuner;
+using ::android::hardware::tv::tuner::V1_0::LnbId;
using ::android::hardware::tv::tuner::V1_0::Result;
using ::android::hardware::tv::tuner::V1_1::FrontendDtmbCapabilities;
@@ -136,13 +140,16 @@
sp<ILnb> openHidlLnbById(int id);
sp<ILnb> openHidlLnbByName(string name, LnbId& lnbId);
sp<IDescrambler> openHidlDescrambler();
+ vector<int> getLnbHandles();
FrontendInfo FrontendInfoAidlToHidl(TunerServiceFrontendInfo aidlFrontendInfo);
+ void updateTunerResources();
+ void updateFrontendResources();
+ void updateLnbResources();
int getResourceIdFromHandle(int handle, int resourceType);
int getResourceHandleFromId(int id, int resourceType);
-private:
/**
* An AIDL Tuner Service Singleton assigned at the first time the Tuner Client
* connects with the Tuner Service. Default null when the service does not exist.
@@ -167,6 +174,8 @@
// while the low 16 bits are the minor version. Default value is unknown version 0.
static int mTunerVersion;
+ shared_ptr<ITunerResourceManager> mTunerResourceManager;
+
int mResourceRequestCount = 0;
};
} // namespace android