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
This commit is contained in:
Amy Zhang
2020-12-21 16:56:03 -08:00
parent cb3903f699
commit 39a3fa4653
26 changed files with 385 additions and 1019 deletions

View File

@@ -223,6 +223,9 @@ filegroup {
"media/java/**/*.java",
"media/java/**/*.aidl",
],
exclude_srcs: [
":framework-media-tv-tunerresourcemanager-sources-aidl",
],
path: "media/java",
}
@@ -630,6 +633,7 @@ java_defaults {
// in favor of an API stubs dependency in java_library "framework" below.
"mimemap",
"av-types-aidl-java",
"tv_tuner_resource_manager_aidl_interface-java",
"soundtrigger_middleware-aidl-java",
"modules-utils-os",
],

View File

@@ -716,8 +716,9 @@ public final class MediaCas implements AutoCloseable {
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 @@ public final class MediaCas implements AutoCloseable {
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(

View File

@@ -46,7 +46,6 @@ import android.media.tv.tuner.frontend.ScanCallback;
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 @@ public class Tuner implements AutoCloseable {
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 @@ public class Tuner implements AutoCloseable {
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 @@ public class Tuner implements AutoCloseable {
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 @@ public class Tuner implements AutoCloseable {
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 @@ public class Tuner implements AutoCloseable {
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;

View File

@@ -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",
],
}
}

View File

@@ -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);
}
}

View File

@@ -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 Apps 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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -21,4 +21,8 @@ package android.media.tv.tunerresourcemanager;
*
* @hide
*/
parcelable CasSessionRequest;
parcelable CasSessionRequest {
int clientId;
int casSystemId;
}

View File

@@ -22,4 +22,8 @@ package android.media.tv.tunerresourcemanager;
*
* @hide
*/
parcelable ResourceClientProfile;
parcelable ResourceClientProfile {
String tvInputSessionId;
int useCase;
}

View File

@@ -21,4 +21,6 @@ package android.media.tv.tunerresourcemanager;
*
* @hide
*/
parcelable TunerDemuxRequest;
parcelable TunerDemuxRequest {
int clientId;
}

View File

@@ -21,4 +21,6 @@ package android.media.tv.tunerresourcemanager;
*
* @hide
*/
parcelable TunerDescramblerRequest;
parcelable TunerDescramblerRequest {
int clientId;
}

View File

@@ -21,4 +21,10 @@ package android.media.tv.tunerresourcemanager;
*
* @hide
*/
parcelable TunerFrontendInfo;
parcelable TunerFrontendInfo {
int handle;
int frontendType;
int exclusiveGroupId;
}

View File

@@ -21,4 +21,8 @@ package android.media.tv.tunerresourcemanager;
*
* @hide
*/
parcelable TunerFrontendRequest;
parcelable TunerFrontendRequest {
int clientId;
int frontendType;
}

View File

@@ -21,4 +21,6 @@ package android.media.tv.tunerresourcemanager;
*
* @hide
*/
parcelable TunerLnbRequest;
parcelable TunerLnbRequest {
int clientId;
}

View File

@@ -137,6 +137,7 @@ cc_library_shared {
cc_library_shared {
name: "libmedia_tv_tuner",
srcs: [
"android_media_tv_Tuner.cpp",
"tuner/DemuxClient.cpp",
@@ -163,6 +164,7 @@ cc_library_shared {
"libnativehelper",
"libutils",
"tv_tuner_aidl_interface-ndk_platform",
"tv_tuner_resource_manager_aidl_interface-ndk_platform"
],
defaults: [
"libcodec2-impl-defaults",

View File

@@ -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 @@ int TunerClient::mTunerVersion;
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 @@ sp<LnbClient> TunerClient::openLnbByName(string lnbName) {
/////////////// 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 @@ sp<IDescrambler> TunerClient::openHidlDescrambler() {
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),

View File

@@ -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 @@ private:
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 @@ private:
// 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

View File

@@ -380,8 +380,9 @@ class TvInputHardwareManager implements TvInputHal.Callback {
return null;
}
ResourceClientProfile profile =
new ResourceClientProfile(tvInputSessionId, priorityHint);
ResourceClientProfile profile = new ResourceClientProfile();
profile.tvInputSessionId = tvInputSessionId;
profile.useCase = priorityHint;
ResourceClientProfile holderProfile = connection.getResourceClientProfileLocked();
if (holderProfile != null && trm != null
&& !trm.isHigherPriority(profile, holderProfile)) {

View File

@@ -141,8 +141,8 @@ public class TunerResourceManagerService extends SystemService implements IBinde
throw new RemoteException("IResourcesReclaimListener can't be null!");
}
if (!mPriorityCongfig.isDefinedUseCase(profile.getUseCase())) {
throw new RemoteException("Use undefined client use case:" + profile.getUseCase());
if (!mPriorityCongfig.isDefinedUseCase(profile.useCase)) {
throw new RemoteException("Use undefined client use case:" + profile.useCase);
}
synchronized (mLock) {
@@ -209,14 +209,14 @@ public class TunerResourceManagerService extends SystemService implements IBinde
throw new RemoteException("frontendHandle can't be null");
}
synchronized (mLock) {
if (!checkClientExists(request.getClientId())) {
if (!checkClientExists(request.clientId)) {
throw new RemoteException("Request frontend from unregistered client: "
+ request.getClientId());
+ request.clientId);
}
// If the request client is holding or sharing a frontend, throw an exception.
if (!getClientProfile(request.getClientId()).getInUseFrontendHandles().isEmpty()) {
if (!getClientProfile(request.clientId).getInUseFrontendHandles().isEmpty()) {
throw new RemoteException("Release frontend before requesting another one. "
+ "Client id: " + request.getClientId());
+ "Client id: " + request.clientId);
}
return requestFrontendInternal(request, frontendHandle);
}
@@ -252,9 +252,9 @@ public class TunerResourceManagerService extends SystemService implements IBinde
throw new RemoteException("demuxHandle can't be null");
}
synchronized (mLock) {
if (!checkClientExists(request.getClientId())) {
if (!checkClientExists(request.clientId)) {
throw new RemoteException("Request demux from unregistered client:"
+ request.getClientId());
+ request.clientId);
}
return requestDemuxInternal(request, demuxHandle);
}
@@ -269,9 +269,9 @@ public class TunerResourceManagerService extends SystemService implements IBinde
throw new RemoteException("descramblerHandle can't be null");
}
synchronized (mLock) {
if (!checkClientExists(request.getClientId())) {
if (!checkClientExists(request.clientId)) {
throw new RemoteException("Request descrambler from unregistered client:"
+ request.getClientId());
+ request.clientId);
}
return requestDescramblerInternal(request, descramblerHandle);
}
@@ -285,9 +285,9 @@ public class TunerResourceManagerService extends SystemService implements IBinde
throw new RemoteException("casSessionHandle can't be null");
}
synchronized (mLock) {
if (!checkClientExists(request.getClientId())) {
if (!checkClientExists(request.clientId)) {
throw new RemoteException("Request cas from unregistered client:"
+ request.getClientId());
+ request.clientId);
}
return requestCasSessionInternal(request, casSessionHandle);
}
@@ -302,9 +302,9 @@ public class TunerResourceManagerService extends SystemService implements IBinde
throw new RemoteException("lnbHandle can't be null");
}
synchronized (mLock) {
if (!checkClientExists(request.getClientId())) {
if (!checkClientExists(request.clientId)) {
throw new RemoteException("Request lnb from unregistered client:"
+ request.getClientId());
+ request.clientId);
}
return requestLnbInternal(request, lnbHandle);
}
@@ -441,12 +441,12 @@ public class TunerResourceManagerService extends SystemService implements IBinde
// TODO tell if the client already exists
clientId[0] = mNextUnusedClientId++;
int pid = profile.getTvInputSessionId() == null
int pid = profile.tvInputSessionId == null
? Binder.getCallingPid() /*callingPid*/
: mTvInputManager.getClientPid(profile.getTvInputSessionId()); /*tvAppId*/
: mTvInputManager.getClientPid(profile.tvInputSessionId); /*tvAppId*/
// Update Media Resource Manager with the tvAppId
if (profile.getTvInputSessionId() != null && mMediaResourceManager != null) {
if (profile.tvInputSessionId != null && mMediaResourceManager != null) {
try {
mMediaResourceManager.overridePid(Binder.getCallingPid(), pid);
} catch (RemoteException e) {
@@ -456,11 +456,11 @@ public class TunerResourceManagerService extends SystemService implements IBinde
}
ClientProfile clientProfile = new ClientProfile.Builder(clientId[0])
.tvInputSessionId(profile.getTvInputSessionId())
.useCase(profile.getUseCase())
.tvInputSessionId(profile.tvInputSessionId)
.useCase(profile.useCase)
.processId(pid)
.build();
clientProfile.setPriority(getClientPriority(profile.getUseCase(), pid));
clientProfile.setPriority(getClientPriority(profile.useCase, pid));
addClientProfile(clientId[0], clientProfile, listener);
}
@@ -520,16 +520,16 @@ public class TunerResourceManagerService extends SystemService implements IBinde
// Update frontendResources map and other mappings accordingly
for (int i = 0; i < infos.length; i++) {
if (getFrontendResource(infos[i].getHandle()) != null) {
if (getFrontendResource(infos[i].handle) != null) {
if (DEBUG) {
Slog.d(TAG, "Frontend handle=" + infos[i].getHandle() + "exists.");
Slog.d(TAG, "Frontend handle=" + infos[i].handle + "exists.");
}
updatingFrontendHandles.remove(infos[i].getHandle());
updatingFrontendHandles.remove(infos[i].handle);
} else {
// Add a new fe resource
FrontendResource newFe = new FrontendResource.Builder(infos[i].getHandle())
.type(infos[i].getFrontendType())
.exclusiveGroupId(infos[i].getExclusiveGroupId())
FrontendResource newFe = new FrontendResource.Builder(infos[i].handle)
.type(infos[i].frontendType)
.exclusiveGroupId(infos[i].exclusiveGroupId)
.build();
addFrontendResource(newFe);
}
@@ -610,13 +610,13 @@ public class TunerResourceManagerService extends SystemService implements IBinde
}
frontendHandle[0] = TunerResourceManager.INVALID_RESOURCE_HANDLE;
ClientProfile requestClient = getClientProfile(request.getClientId());
ClientProfile requestClient = getClientProfile(request.clientId);
int grantingFrontendHandle = TunerResourceManager.INVALID_RESOURCE_HANDLE;
int inUseLowestPriorityFrHandle = TunerResourceManager.INVALID_RESOURCE_HANDLE;
// Priority max value is 1000
int currentLowestPriority = MAX_CLIENT_PRIORITY + 1;
for (FrontendResource fr : getFrontendResources().values()) {
if (fr.getType() == request.getFrontendType()) {
if (fr.getType() == request.frontendType) {
if (!fr.isInUse()) {
// Grant unused frontend with no exclusive group members first.
if (fr.getExclusiveGroupMemberFeHandles().isEmpty()) {
@@ -643,7 +643,7 @@ public class TunerResourceManagerService extends SystemService implements IBinde
// Grant frontend when there is unused resource.
if (grantingFrontendHandle != TunerResourceManager.INVALID_RESOURCE_HANDLE) {
frontendHandle[0] = grantingFrontendHandle;
updateFrontendClientMappingOnNewGrant(grantingFrontendHandle, request.getClientId());
updateFrontendClientMappingOnNewGrant(grantingFrontendHandle, request.clientId);
return true;
}
@@ -658,7 +658,7 @@ public class TunerResourceManagerService extends SystemService implements IBinde
}
frontendHandle[0] = inUseLowestPriorityFrHandle;
updateFrontendClientMappingOnNewGrant(
inUseLowestPriorityFrHandle, request.getClientId());
inUseLowestPriorityFrHandle, request.clientId);
return true;
}
@@ -683,7 +683,7 @@ public class TunerResourceManagerService extends SystemService implements IBinde
}
lnbHandle[0] = TunerResourceManager.INVALID_RESOURCE_HANDLE;
ClientProfile requestClient = getClientProfile(request.getClientId());
ClientProfile requestClient = getClientProfile(request.clientId);
int grantingLnbHandle = TunerResourceManager.INVALID_RESOURCE_HANDLE;
int inUseLowestPriorityLnbHandle = TunerResourceManager.INVALID_RESOURCE_HANDLE;
// Priority max value is 1000
@@ -707,7 +707,7 @@ public class TunerResourceManagerService extends SystemService implements IBinde
// Grant Lnb when there is unused resource.
if (grantingLnbHandle > -1) {
lnbHandle[0] = grantingLnbHandle;
updateLnbClientMappingOnNewGrant(grantingLnbHandle, request.getClientId());
updateLnbClientMappingOnNewGrant(grantingLnbHandle, request.clientId);
return true;
}
@@ -720,7 +720,7 @@ public class TunerResourceManagerService extends SystemService implements IBinde
return false;
}
lnbHandle[0] = inUseLowestPriorityLnbHandle;
updateLnbClientMappingOnNewGrant(inUseLowestPriorityLnbHandle, request.getClientId());
updateLnbClientMappingOnNewGrant(inUseLowestPriorityLnbHandle, request.clientId);
return true;
}
@@ -732,23 +732,23 @@ public class TunerResourceManagerService extends SystemService implements IBinde
if (DEBUG) {
Slog.d(TAG, "requestCasSession(request=" + request + ")");
}
CasResource cas = getCasResource(request.getCasSystemId());
CasResource cas = getCasResource(request.casSystemId);
// Unregistered Cas System is treated as having unlimited sessions.
if (cas == null) {
cas = new CasResource.Builder(request.getCasSystemId())
cas = new CasResource.Builder(request.casSystemId)
.maxSessionNum(Integer.MAX_VALUE)
.build();
addCasResource(cas);
}
casSessionHandle[0] = TunerResourceManager.INVALID_RESOURCE_HANDLE;
ClientProfile requestClient = getClientProfile(request.getClientId());
ClientProfile requestClient = getClientProfile(request.clientId);
int lowestPriorityOwnerId = -1;
// Priority max value is 1000
int currentLowestPriority = MAX_CLIENT_PRIORITY + 1;
if (!cas.isFullyUsed()) {
casSessionHandle[0] = generateResourceHandle(
TunerResourceManager.TUNER_RESOURCE_TYPE_CAS_SESSION, cas.getSystemId());
updateCasClientMappingOnNewGrant(request.getCasSystemId(), request.getClientId());
updateCasClientMappingOnNewGrant(request.casSystemId, request.clientId);
return true;
}
for (int ownerId : cas.getOwnerClientIds()) {
@@ -769,7 +769,7 @@ public class TunerResourceManagerService extends SystemService implements IBinde
}
casSessionHandle[0] = generateResourceHandle(
TunerResourceManager.TUNER_RESOURCE_TYPE_CAS_SESSION, cas.getSystemId());
updateCasClientMappingOnNewGrant(request.getCasSystemId(), request.getClientId());
updateCasClientMappingOnNewGrant(request.casSystemId, request.clientId);
return true;
}
return false;
@@ -790,15 +790,15 @@ public class TunerResourceManagerService extends SystemService implements IBinde
return true;
}
int challengerPid = challengerProfile.getTvInputSessionId() == null
int challengerPid = challengerProfile.tvInputSessionId == null
? Binder.getCallingPid() /*callingPid*/
: mTvInputManager.getClientPid(challengerProfile.getTvInputSessionId()); /*tvAppId*/
int holderPid = holderProfile.getTvInputSessionId() == null
: mTvInputManager.getClientPid(challengerProfile.tvInputSessionId); /*tvAppId*/
int holderPid = holderProfile.tvInputSessionId == null
? Binder.getCallingPid() /*callingPid*/
: mTvInputManager.getClientPid(holderProfile.getTvInputSessionId()); /*tvAppId*/
: mTvInputManager.getClientPid(holderProfile.tvInputSessionId); /*tvAppId*/
int challengerPriority = getClientPriority(challengerProfile.getUseCase(), challengerPid);
int holderPriority = getClientPriority(holderProfile.getUseCase(), holderPid);
int challengerPriority = getClientPriority(challengerProfile.useCase, challengerPid);
int holderPriority = getClientPriority(holderProfile.useCase, holderPid);
return challengerPriority > holderPriority;
}

View File

@@ -86,9 +86,9 @@ public class TunerResourceManagerServiceTest {
return (actual == null) && (expected == null);
}
return actual.getHandle() == expected.getHandle()
&& actual.getType() == expected.getFrontendType()
&& actual.getExclusiveGroupId() == expected.getExclusiveGroupId();
return actual.getHandle() == expected.handle
&& actual.getType() == expected.frontendType
&& actual.getExclusiveGroupId() == expected.exclusiveGroupId;
}, "is correctly configured from ");
@Before
@@ -111,19 +111,19 @@ public class TunerResourceManagerServiceTest {
// Init frontend resources.
TunerFrontendInfo[] infos = new TunerFrontendInfo[2];
infos[0] =
new TunerFrontendInfo(0 /*id*/, FrontendSettings.TYPE_DVBT, 0 /*exclusiveGroupId*/);
tunerFrontendInfo(0 /*handle*/, FrontendSettings.TYPE_DVBT, 0 /*exclusiveGroupId*/);
infos[1] =
new TunerFrontendInfo(1 /*id*/, FrontendSettings.TYPE_DVBT, 1 /*exclusiveGroupId*/);
tunerFrontendInfo(1 /*handle*/, FrontendSettings.TYPE_DVBT, 1 /*exclusiveGroupId*/);
mTunerResourceManagerService.setFrontendInfoListInternal(infos);
Map<Integer, FrontendResource> resources =
mTunerResourceManagerService.getFrontendResources();
for (int id = 0; id < infos.length; id++) {
assertThat(resources.get(infos[id].getHandle())
assertThat(resources.get(infos[id].handle)
.getExclusiveGroupMemberFeHandles().size()).isEqualTo(0);
}
for (int id = 0; id < infos.length; id++) {
assertThat(resources.get(infos[id].getHandle())
assertThat(resources.get(infos[id].handle)
.getExclusiveGroupMemberFeHandles().size()).isEqualTo(0);
}
assertThat(resources.values()).comparingElementsUsing(FR_TFI_COMPARE)
@@ -135,13 +135,13 @@ public class TunerResourceManagerServiceTest {
// Init frontend resources.
TunerFrontendInfo[] infos = new TunerFrontendInfo[4];
infos[0] =
new TunerFrontendInfo(0 /*id*/, FrontendSettings.TYPE_DVBT, 0 /*exclusiveGroupId*/);
tunerFrontendInfo(0 /*handle*/, FrontendSettings.TYPE_DVBT, 0 /*exclusiveGroupId*/);
infos[1] =
new TunerFrontendInfo(1 /*id*/, FrontendSettings.TYPE_DVBT, 1 /*exclusiveGroupId*/);
tunerFrontendInfo(1 /*handle*/, FrontendSettings.TYPE_DVBT, 1 /*exclusiveGroupId*/);
infos[2] =
new TunerFrontendInfo(2 /*id*/, FrontendSettings.TYPE_DVBS, 1 /*exclusiveGroupId*/);
tunerFrontendInfo(2 /*handle*/, FrontendSettings.TYPE_DVBS, 1 /*exclusiveGroupId*/);
infos[3] =
new TunerFrontendInfo(3 /*id*/, FrontendSettings.TYPE_ATSC, 1 /*exclusiveGroupId*/);
tunerFrontendInfo(3 /*handle*/, FrontendSettings.TYPE_ATSC, 1 /*exclusiveGroupId*/);
mTunerResourceManagerService.setFrontendInfoListInternal(infos);
Map<Integer, FrontendResource> resources =
@@ -160,9 +160,9 @@ public class TunerResourceManagerServiceTest {
// Init frontend resources.
TunerFrontendInfo[] infos = new TunerFrontendInfo[2];
infos[0] =
new TunerFrontendInfo(0 /*id*/, FrontendSettings.TYPE_DVBT, 1 /*exclusiveGroupId*/);
tunerFrontendInfo(0 /*handle*/, FrontendSettings.TYPE_DVBT, 1 /*exclusiveGroupId*/);
infos[1] =
new TunerFrontendInfo(1 /*id*/, FrontendSettings.TYPE_DVBS, 1 /*exclusiveGroupId*/);
tunerFrontendInfo(1 /*handle*/, FrontendSettings.TYPE_DVBS, 1 /*exclusiveGroupId*/);
mTunerResourceManagerService.setFrontendInfoListInternal(infos);
Map<Integer, FrontendResource> resources0 =
@@ -180,22 +180,22 @@ public class TunerResourceManagerServiceTest {
// Init frontend resources.
TunerFrontendInfo[] infos0 = new TunerFrontendInfo[3];
infos0[0] =
new TunerFrontendInfo(0 /*id*/, FrontendSettings.TYPE_DVBT, 0 /*exclusiveGroupId*/);
tunerFrontendInfo(0 /*handle*/, FrontendSettings.TYPE_DVBT, 0 /*exclusiveGroupId*/);
infos0[1] =
new TunerFrontendInfo(1 /*id*/, FrontendSettings.TYPE_DVBT, 1 /*exclusiveGroupId*/);
tunerFrontendInfo(1 /*handle*/, FrontendSettings.TYPE_DVBT, 1 /*exclusiveGroupId*/);
infos0[2] =
new TunerFrontendInfo(2 /*id*/, FrontendSettings.TYPE_DVBS, 2 /*exclusiveGroupId*/);
tunerFrontendInfo(2 /*handle*/, FrontendSettings.TYPE_DVBS, 2 /*exclusiveGroupId*/);
mTunerResourceManagerService.setFrontendInfoListInternal(infos0);
TunerFrontendInfo[] infos1 = new TunerFrontendInfo[1];
infos1[0] =
new TunerFrontendInfo(1 /*id*/, FrontendSettings.TYPE_DVBT, 1 /*exclusiveGroupId*/);
tunerFrontendInfo(1 /*handle*/, FrontendSettings.TYPE_DVBT, 1 /*exclusiveGroupId*/);
mTunerResourceManagerService.setFrontendInfoListInternal(infos1);
Map<Integer, FrontendResource> resources =
mTunerResourceManagerService.getFrontendResources();
for (int id = 0; id < infos1.length; id++) {
assertThat(resources.get(infos1[id].getHandle())
assertThat(resources.get(infos1[id].handle)
.getExclusiveGroupMemberFeHandles().size()).isEqualTo(0);
}
assertThat(resources.values()).comparingElementsUsing(FR_TFI_COMPARE)
@@ -207,22 +207,22 @@ public class TunerResourceManagerServiceTest {
// Init frontend resources.
TunerFrontendInfo[] infos0 = new TunerFrontendInfo[3];
infos0[0] =
new TunerFrontendInfo(0 /*id*/, FrontendSettings.TYPE_DVBT, 0 /*exclusiveGroupId*/);
tunerFrontendInfo(0 /*handle*/, FrontendSettings.TYPE_DVBT, 0 /*exclusiveGroupId*/);
infos0[1] =
new TunerFrontendInfo(1 /*id*/, FrontendSettings.TYPE_DVBT, 1 /*exclusiveGroupId*/);
tunerFrontendInfo(1 /*handle*/, FrontendSettings.TYPE_DVBT, 1 /*exclusiveGroupId*/);
infos0[2] =
new TunerFrontendInfo(2 /*id*/, FrontendSettings.TYPE_DVBS, 1 /*exclusiveGroupId*/);
tunerFrontendInfo(2 /*handle*/, FrontendSettings.TYPE_DVBS, 1 /*exclusiveGroupId*/);
mTunerResourceManagerService.setFrontendInfoListInternal(infos0);
TunerFrontendInfo[] infos1 = new TunerFrontendInfo[1];
infos1[0] =
new TunerFrontendInfo(1 /*id*/, FrontendSettings.TYPE_DVBT, 1 /*exclusiveGroupId*/);
tunerFrontendInfo(1 /*handle*/, FrontendSettings.TYPE_DVBT, 1 /*exclusiveGroupId*/);
mTunerResourceManagerService.setFrontendInfoListInternal(infos1);
Map<Integer, FrontendResource> resources =
mTunerResourceManagerService.getFrontendResources();
for (int id = 0; id < infos1.length; id++) {
assertThat(resources.get(infos1[id].getHandle())
assertThat(resources.get(infos1[id].handle)
.getExclusiveGroupMemberFeHandles().size()).isEqualTo(0);
}
assertThat(resources.values()).comparingElementsUsing(FR_TFI_COMPARE)
@@ -232,7 +232,7 @@ public class TunerResourceManagerServiceTest {
@Test
public void requestFrontendTest_ClientNotRegistered() {
TunerFrontendRequest request =
new TunerFrontendRequest(0 /*clientId*/, FrontendSettings.TYPE_DVBT);
tunerFrontendRequest(0 /*clientId*/, FrontendSettings.TYPE_DVBT);
int[] frontendHandle = new int[1];
assertThat(mTunerResourceManagerService
.requestFrontendInternal(request, frontendHandle)).isFalse();
@@ -241,7 +241,7 @@ public class TunerResourceManagerServiceTest {
@Test
public void requestFrontendTest_NoFrontendWithGiveTypeAvailable() {
ResourceClientProfile profile = new ResourceClientProfile("0" /*sessionId*/,
ResourceClientProfile profile = resourceClientProfile("0" /*sessionId*/,
TvInputService.PRIORITY_HINT_USE_CASE_TYPE_PLAYBACK);
int[] clientId = new int[1];
mTunerResourceManagerService.registerClientProfileInternal(
@@ -251,11 +251,11 @@ public class TunerResourceManagerServiceTest {
// Init frontend resources.
TunerFrontendInfo[] infos = new TunerFrontendInfo[1];
infos[0] =
new TunerFrontendInfo(0 /*id*/, FrontendSettings.TYPE_DVBS, 0 /*exclusiveGroupId*/);
tunerFrontendInfo(0 /*handle*/, FrontendSettings.TYPE_DVBS, 0 /*exclusiveGroupId*/);
mTunerResourceManagerService.setFrontendInfoListInternal(infos);
TunerFrontendRequest request =
new TunerFrontendRequest(clientId[0] /*clientId*/, FrontendSettings.TYPE_DVBT);
tunerFrontendRequest(clientId[0] /*clientId*/, FrontendSettings.TYPE_DVBT);
int[] frontendHandle = new int[1];
assertThat(mTunerResourceManagerService
.requestFrontendInternal(request, frontendHandle)).isFalse();
@@ -264,7 +264,7 @@ public class TunerResourceManagerServiceTest {
@Test
public void requestFrontendTest_FrontendWithNoExclusiveGroupAvailable() {
ResourceClientProfile profile = new ResourceClientProfile("0" /*sessionId*/,
ResourceClientProfile profile = resourceClientProfile("0" /*sessionId*/,
TvInputService.PRIORITY_HINT_USE_CASE_TYPE_PLAYBACK);
int[] clientId = new int[1];
mTunerResourceManagerService.registerClientProfileInternal(
@@ -273,22 +273,22 @@ public class TunerResourceManagerServiceTest {
// Init frontend resources.
TunerFrontendInfo[] infos = new TunerFrontendInfo[3];
infos[0] = new TunerFrontendInfo(
infos[0] = tunerFrontendInfo(
0 /*handle*/,
FrontendSettings.TYPE_DVBT,
0 /*exclusiveGroupId*/);
infos[1] = new TunerFrontendInfo(
infos[1] = tunerFrontendInfo(
1 /*handle*/,
FrontendSettings.TYPE_DVBT,
1 /*exclusiveGroupId*/);
infos[2] = new TunerFrontendInfo(
infos[2] = tunerFrontendInfo(
2 /*handle*/,
FrontendSettings.TYPE_DVBS,
1 /*exclusiveGroupId*/);
mTunerResourceManagerService.setFrontendInfoListInternal(infos);
TunerFrontendRequest request =
new TunerFrontendRequest(clientId[0] /*clientId*/, FrontendSettings.TYPE_DVBT);
tunerFrontendRequest(clientId[0] /*clientId*/, FrontendSettings.TYPE_DVBT);
int[] frontendHandle = new int[1];
assertThat(mTunerResourceManagerService
.requestFrontendInternal(request, frontendHandle)).isTrue();
@@ -297,9 +297,9 @@ public class TunerResourceManagerServiceTest {
@Test
public void requestFrontendTest_FrontendWithExclusiveGroupAvailable() {
ResourceClientProfile profile0 = new ResourceClientProfile("0" /*sessionId*/,
ResourceClientProfile profile0 = resourceClientProfile("0" /*sessionId*/,
TvInputService.PRIORITY_HINT_USE_CASE_TYPE_PLAYBACK);
ResourceClientProfile profile1 = new ResourceClientProfile("1" /*sessionId*/,
ResourceClientProfile profile1 = resourceClientProfile("1" /*sessionId*/,
TvInputService.PRIORITY_HINT_USE_CASE_TYPE_PLAYBACK);
int[] clientId0 = new int[1];
int[] clientId1 = new int[1];
@@ -312,15 +312,15 @@ public class TunerResourceManagerServiceTest {
// Init frontend resources.
TunerFrontendInfo[] infos = new TunerFrontendInfo[3];
infos[0] = new TunerFrontendInfo(
infos[0] = tunerFrontendInfo(
0 /*handle*/,
FrontendSettings.TYPE_DVBT,
0 /*exclusiveGroupId*/);
infos[1] = new TunerFrontendInfo(
infos[1] = tunerFrontendInfo(
1 /*handle*/,
FrontendSettings.TYPE_DVBT,
1 /*exclusiveGroupId*/);
infos[2] = new TunerFrontendInfo(
infos[2] = tunerFrontendInfo(
2 /*handle*/,
FrontendSettings.TYPE_DVBS,
1 /*exclusiveGroupId*/);
@@ -328,19 +328,19 @@ public class TunerResourceManagerServiceTest {
int[] frontendHandle = new int[1];
TunerFrontendRequest request =
new TunerFrontendRequest(clientId1[0] /*clientId*/, FrontendSettings.TYPE_DVBT);
tunerFrontendRequest(clientId1[0] /*clientId*/, FrontendSettings.TYPE_DVBT);
assertThat(mTunerResourceManagerService
.requestFrontendInternal(request, frontendHandle)).isTrue();
assertThat(frontendHandle[0]).isEqualTo(infos[0].getHandle());
assertThat(frontendHandle[0]).isEqualTo(infos[0].handle);
request =
new TunerFrontendRequest(clientId0[0] /*clientId*/, FrontendSettings.TYPE_DVBT);
tunerFrontendRequest(clientId0[0] /*clientId*/, FrontendSettings.TYPE_DVBT);
assertThat(mTunerResourceManagerService
.requestFrontendInternal(request, frontendHandle)).isTrue();
assertThat(frontendHandle[0]).isEqualTo(infos[1].getHandle());
assertThat(mTunerResourceManagerService.getFrontendResource(infos[1].getHandle()).isInUse())
assertThat(frontendHandle[0]).isEqualTo(infos[1].handle);
assertThat(mTunerResourceManagerService.getFrontendResource(infos[1].handle).isInUse())
.isTrue();
assertThat(mTunerResourceManagerService.getFrontendResource(infos[2].getHandle()).isInUse())
assertThat(mTunerResourceManagerService.getFrontendResource(infos[2].handle).isInUse())
.isTrue();
}
@@ -348,9 +348,9 @@ public class TunerResourceManagerServiceTest {
public void requestFrontendTest_NoFrontendAvailable_RequestWithLowerPriority() {
// Register clients
ResourceClientProfile[] profiles = new ResourceClientProfile[2];
profiles[0] = new ResourceClientProfile("0" /*sessionId*/,
profiles[0] = resourceClientProfile("0" /*sessionId*/,
TvInputService.PRIORITY_HINT_USE_CASE_TYPE_PLAYBACK);
profiles[1] = new ResourceClientProfile("1" /*sessionId*/,
profiles[1] = resourceClientProfile("1" /*sessionId*/,
TvInputService.PRIORITY_HINT_USE_CASE_TYPE_PLAYBACK);
int[] clientPriorities = {100, 50};
int[] clientId0 = new int[1];
@@ -371,25 +371,25 @@ public class TunerResourceManagerServiceTest {
// Init frontend resources.
TunerFrontendInfo[] infos = new TunerFrontendInfo[2];
infos[0] =
new TunerFrontendInfo(0 /*id*/, FrontendSettings.TYPE_DVBT, 1 /*exclusiveGroupId*/);
tunerFrontendInfo(0 /*handle*/, FrontendSettings.TYPE_DVBT, 1 /*exclusiveGroupId*/);
infos[1] =
new TunerFrontendInfo(1 /*id*/, FrontendSettings.TYPE_DVBS, 1 /*exclusiveGroupId*/);
tunerFrontendInfo(1 /*handle*/, FrontendSettings.TYPE_DVBS, 1 /*exclusiveGroupId*/);
mTunerResourceManagerService.setFrontendInfoListInternal(infos);
TunerFrontendRequest request =
new TunerFrontendRequest(clientId0[0] /*clientId*/, FrontendSettings.TYPE_DVBT);
tunerFrontendRequest(clientId0[0] /*clientId*/, FrontendSettings.TYPE_DVBT);
int[] frontendHandle = new int[1];
assertThat(mTunerResourceManagerService
.requestFrontendInternal(request, frontendHandle)).isTrue();
request =
new TunerFrontendRequest(clientId1[0] /*clientId*/, FrontendSettings.TYPE_DVBT);
tunerFrontendRequest(clientId1[0] /*clientId*/, FrontendSettings.TYPE_DVBT);
assertThat(mTunerResourceManagerService
.requestFrontendInternal(request, frontendHandle)).isFalse();
assertThat(listener.isReclaimed()).isFalse();
request =
new TunerFrontendRequest(clientId1[0] /*clientId*/, FrontendSettings.TYPE_DVBS);
tunerFrontendRequest(clientId1[0] /*clientId*/, FrontendSettings.TYPE_DVBS);
assertThat(mTunerResourceManagerService
.requestFrontendInternal(request, frontendHandle)).isFalse();
assertThat(listener.isReclaimed()).isFalse();
@@ -399,9 +399,9 @@ public class TunerResourceManagerServiceTest {
public void requestFrontendTest_NoFrontendAvailable_RequestWithHigherPriority() {
// Register clients
ResourceClientProfile[] profiles = new ResourceClientProfile[2];
profiles[0] = new ResourceClientProfile("0" /*sessionId*/,
profiles[0] = resourceClientProfile("0" /*sessionId*/,
TvInputService.PRIORITY_HINT_USE_CASE_TYPE_PLAYBACK);
profiles[1] = new ResourceClientProfile("1" /*sessionId*/,
profiles[1] = resourceClientProfile("1" /*sessionId*/,
TvInputService.PRIORITY_HINT_USE_CASE_TYPE_PLAYBACK);
int[] clientPriorities = {100, 500};
int[] clientId0 = new int[1];
@@ -421,33 +421,33 @@ public class TunerResourceManagerServiceTest {
// Init frontend resources.
TunerFrontendInfo[] infos = new TunerFrontendInfo[2];
infos[0] =
new TunerFrontendInfo(0 /*id*/, FrontendSettings.TYPE_DVBT, 1 /*exclusiveGroupId*/);
tunerFrontendInfo(0 /*handle*/, FrontendSettings.TYPE_DVBT, 1 /*exclusiveGroupId*/);
infos[1] =
new TunerFrontendInfo(1 /*id*/, FrontendSettings.TYPE_DVBS, 1 /*exclusiveGroupId*/);
tunerFrontendInfo(1 /*handle*/, FrontendSettings.TYPE_DVBS, 1 /*exclusiveGroupId*/);
mTunerResourceManagerService.setFrontendInfoListInternal(infos);
TunerFrontendRequest request =
new TunerFrontendRequest(clientId0[0] /*clientId*/, FrontendSettings.TYPE_DVBT);
tunerFrontendRequest(clientId0[0] /*clientId*/, FrontendSettings.TYPE_DVBT);
int[] frontendHandle = new int[1];
assertThat(mTunerResourceManagerService
.requestFrontendInternal(request, frontendHandle)).isTrue();
assertThat(frontendHandle[0]).isEqualTo(infos[0].getHandle());
assertThat(frontendHandle[0]).isEqualTo(infos[0].handle);
assertThat(mTunerResourceManagerService.getClientProfile(clientId0[0])
.getInUseFrontendHandles()).isEqualTo(new HashSet<Integer>(Arrays.asList(
infos[0].getHandle(), infos[1].getHandle())));
infos[0].handle, infos[1].handle)));
request =
new TunerFrontendRequest(clientId1[0] /*clientId*/, FrontendSettings.TYPE_DVBS);
tunerFrontendRequest(clientId1[0] /*clientId*/, FrontendSettings.TYPE_DVBS);
assertThat(mTunerResourceManagerService
.requestFrontendInternal(request, frontendHandle)).isTrue();
assertThat(frontendHandle[0]).isEqualTo(infos[1].getHandle());
assertThat(mTunerResourceManagerService.getFrontendResource(infos[0].getHandle())
assertThat(frontendHandle[0]).isEqualTo(infos[1].handle);
assertThat(mTunerResourceManagerService.getFrontendResource(infos[0].handle)
.isInUse()).isTrue();
assertThat(mTunerResourceManagerService.getFrontendResource(infos[1].getHandle())
assertThat(mTunerResourceManagerService.getFrontendResource(infos[1].handle)
.isInUse()).isTrue();
assertThat(mTunerResourceManagerService.getFrontendResource(infos[0].getHandle())
assertThat(mTunerResourceManagerService.getFrontendResource(infos[0].handle)
.getOwnerClientId()).isEqualTo(clientId1[0]);
assertThat(mTunerResourceManagerService.getFrontendResource(infos[1].getHandle())
assertThat(mTunerResourceManagerService.getFrontendResource(infos[1].handle)
.getOwnerClientId()).isEqualTo(clientId1[0]);
assertThat(listener.isReclaimed()).isTrue();
}
@@ -456,7 +456,7 @@ public class TunerResourceManagerServiceTest {
public void releaseFrontendTest_UnderTheSameExclusiveGroup() {
// Register clients
ResourceClientProfile[] profiles = new ResourceClientProfile[1];
profiles[0] = new ResourceClientProfile("0" /*sessionId*/,
profiles[0] = resourceClientProfile("0" /*sessionId*/,
TvInputService.PRIORITY_HINT_USE_CASE_TYPE_PLAYBACK);
int[] clientId = new int[1];
TestResourcesReclaimListener listener = new TestResourcesReclaimListener();
@@ -466,19 +466,19 @@ public class TunerResourceManagerServiceTest {
// Init frontend resources.
TunerFrontendInfo[] infos = new TunerFrontendInfo[2];
infos[0] =
new TunerFrontendInfo(0 /*id*/, FrontendSettings.TYPE_DVBT, 1 /*exclusiveGroupId*/);
tunerFrontendInfo(0 /*handle*/, FrontendSettings.TYPE_DVBT, 1 /*exclusiveGroupId*/);
infos[1] =
new TunerFrontendInfo(1 /*id*/, FrontendSettings.TYPE_DVBS, 1 /*exclusiveGroupId*/);
tunerFrontendInfo(1 /*handle*/, FrontendSettings.TYPE_DVBS, 1 /*exclusiveGroupId*/);
mTunerResourceManagerService.setFrontendInfoListInternal(infos);
TunerFrontendRequest request =
new TunerFrontendRequest(clientId[0] /*clientId*/, FrontendSettings.TYPE_DVBT);
tunerFrontendRequest(clientId[0] /*clientId*/, FrontendSettings.TYPE_DVBT);
int[] frontendHandle = new int[1];
assertThat(mTunerResourceManagerService
.requestFrontendInternal(request, frontendHandle)).isTrue();
assertThat(frontendHandle[0]).isEqualTo(infos[0].getHandle());
assertThat(frontendHandle[0]).isEqualTo(infos[0].handle);
assertThat(mTunerResourceManagerService
.getFrontendResource(infos[1].getHandle()).isInUse()).isTrue();
.getFrontendResource(infos[1].handle).isInUse()).isTrue();
// Release frontend
mTunerResourceManagerService.releaseFrontendInternal(mTunerResourceManagerService
@@ -486,7 +486,7 @@ public class TunerResourceManagerServiceTest {
assertThat(mTunerResourceManagerService
.getFrontendResource(frontendHandle[0]).isInUse()).isFalse();
assertThat(mTunerResourceManagerService
.getFrontendResource(infos[1].getHandle()).isInUse()).isFalse();
.getFrontendResource(infos[1].handle).isInUse()).isFalse();
assertThat(mTunerResourceManagerService
.getClientProfile(clientId[0]).getInUseFrontendHandles().size()).isEqualTo(0);
}
@@ -495,9 +495,9 @@ public class TunerResourceManagerServiceTest {
public void requestCasTest_NoCasAvailable_RequestWithHigherPriority() {
// Register clients
ResourceClientProfile[] profiles = new ResourceClientProfile[2];
profiles[0] = new ResourceClientProfile("0" /*sessionId*/,
profiles[0] = resourceClientProfile("0" /*sessionId*/,
TvInputService.PRIORITY_HINT_USE_CASE_TYPE_PLAYBACK);
profiles[1] = new ResourceClientProfile("1" /*sessionId*/,
profiles[1] = resourceClientProfile("1" /*sessionId*/,
TvInputService.PRIORITY_HINT_USE_CASE_TYPE_PLAYBACK);
int[] clientPriorities = {100, 500};
int[] clientId0 = new int[1];
@@ -517,7 +517,7 @@ public class TunerResourceManagerServiceTest {
// Init cas resources.
mTunerResourceManagerService.updateCasInfoInternal(1 /*casSystemId*/, 2 /*maxSessionNum*/);
CasSessionRequest request = new CasSessionRequest(clientId0[0], 1 /*casSystemId*/);
CasSessionRequest request = casSessionRequest(clientId0[0], 1 /*casSystemId*/);
int[] casSessionHandle = new int[1];
// Request for 2 cas sessions.
assertThat(mTunerResourceManagerService
@@ -532,7 +532,7 @@ public class TunerResourceManagerServiceTest {
.getOwnerClientIds()).isEqualTo(new HashSet<Integer>(Arrays.asList(clientId0[0])));
assertThat(mTunerResourceManagerService.getCasResource(1).isFullyUsed()).isTrue();
request = new CasSessionRequest(clientId1[0], 1);
request = casSessionRequest(clientId1[0], 1);
assertThat(mTunerResourceManagerService
.requestCasSessionInternal(request, casSessionHandle)).isTrue();
assertThat(mTunerResourceManagerService.getResourceIdFromHandle(casSessionHandle[0]))
@@ -551,7 +551,7 @@ public class TunerResourceManagerServiceTest {
public void releaseCasTest() {
// Register clients
ResourceClientProfile[] profiles = new ResourceClientProfile[1];
profiles[0] = new ResourceClientProfile("0" /*sessionId*/,
profiles[0] = resourceClientProfile("0" /*sessionId*/,
TvInputService.PRIORITY_HINT_USE_CASE_TYPE_PLAYBACK);
int[] clientId = new int[1];
TestResourcesReclaimListener listener = new TestResourcesReclaimListener();
@@ -561,7 +561,7 @@ public class TunerResourceManagerServiceTest {
// Init cas resources.
mTunerResourceManagerService.updateCasInfoInternal(1 /*casSystemId*/, 2 /*maxSessionNum*/);
CasSessionRequest request = new CasSessionRequest(clientId[0], 1 /*casSystemId*/);
CasSessionRequest request = casSessionRequest(clientId[0], 1 /*casSystemId*/);
int[] casSessionHandle = new int[1];
// Request for 1 cas sessions.
assertThat(mTunerResourceManagerService
@@ -588,9 +588,9 @@ public class TunerResourceManagerServiceTest {
public void requestLnbTest_NoLnbAvailable_RequestWithHigherPriority() {
// Register clients
ResourceClientProfile[] profiles = new ResourceClientProfile[2];
profiles[0] = new ResourceClientProfile("0" /*sessionId*/,
profiles[0] = resourceClientProfile("0" /*sessionId*/,
TvInputService.PRIORITY_HINT_USE_CASE_TYPE_PLAYBACK);
profiles[1] = new ResourceClientProfile("1" /*sessionId*/,
profiles[1] = resourceClientProfile("1" /*sessionId*/,
TvInputService.PRIORITY_HINT_USE_CASE_TYPE_PLAYBACK);
int[] clientPriorities = {100, 500};
int[] clientId0 = new int[1];
@@ -611,7 +611,8 @@ public class TunerResourceManagerServiceTest {
int[] lnbHandles = {1};
mTunerResourceManagerService.setLnbInfoListInternal(lnbHandles);
TunerLnbRequest request = new TunerLnbRequest(clientId0[0]);
TunerLnbRequest request = new TunerLnbRequest();
request.clientId = clientId0[0];
int[] lnbHandle = new int[1];
assertThat(mTunerResourceManagerService
.requestLnbInternal(request, lnbHandle)).isTrue();
@@ -619,7 +620,9 @@ public class TunerResourceManagerServiceTest {
assertThat(mTunerResourceManagerService.getClientProfile(clientId0[0]).getInUseLnbHandles())
.isEqualTo(new HashSet<Integer>(Arrays.asList(lnbHandles[0])));
request = new TunerLnbRequest(clientId1[0]);
request = new TunerLnbRequest();
request.clientId = clientId1[0];
assertThat(mTunerResourceManagerService
.requestLnbInternal(request, lnbHandle)).isTrue();
assertThat(lnbHandle[0]).isEqualTo(lnbHandles[0]);
@@ -636,7 +639,7 @@ public class TunerResourceManagerServiceTest {
public void releaseLnbTest() {
// Register clients
ResourceClientProfile[] profiles = new ResourceClientProfile[1];
profiles[0] = new ResourceClientProfile("0" /*sessionId*/,
profiles[0] = resourceClientProfile("0" /*sessionId*/,
TvInputService.PRIORITY_HINT_USE_CASE_TYPE_PLAYBACK);
int[] clientId = new int[1];
TestResourcesReclaimListener listener = new TestResourcesReclaimListener();
@@ -647,7 +650,8 @@ public class TunerResourceManagerServiceTest {
int[] lnbHandles = {0};
mTunerResourceManagerService.setLnbInfoListInternal(lnbHandles);
TunerLnbRequest request = new TunerLnbRequest(clientId[0]);
TunerLnbRequest request = new TunerLnbRequest();
request.clientId = clientId[0];
int[] lnbHandle = new int[1];
assertThat(mTunerResourceManagerService
.requestLnbInternal(request, lnbHandle)).isTrue();
@@ -665,7 +669,7 @@ public class TunerResourceManagerServiceTest {
@Test
public void unregisterClientTest_usingFrontend() {
// Register client
ResourceClientProfile profile = new ResourceClientProfile("0" /*sessionId*/,
ResourceClientProfile profile = resourceClientProfile("0" /*sessionId*/,
TvInputService.PRIORITY_HINT_USE_CASE_TYPE_PLAYBACK);
int[] clientId = new int[1];
mTunerResourceManagerService.registerClientProfileInternal(
@@ -675,27 +679,27 @@ public class TunerResourceManagerServiceTest {
// Init frontend resources.
TunerFrontendInfo[] infos = new TunerFrontendInfo[2];
infos[0] =
new TunerFrontendInfo(0 /*id*/, FrontendSettings.TYPE_DVBT, 1 /*exclusiveGroupId*/);
tunerFrontendInfo(0 /*handle*/, FrontendSettings.TYPE_DVBT, 1 /*exclusiveGroupId*/);
infos[1] =
new TunerFrontendInfo(1 /*id*/, FrontendSettings.TYPE_DVBS, 1 /*exclusiveGroupId*/);
tunerFrontendInfo(1 /*handle*/, FrontendSettings.TYPE_DVBS, 1 /*exclusiveGroupId*/);
mTunerResourceManagerService.setFrontendInfoListInternal(infos);
TunerFrontendRequest request =
new TunerFrontendRequest(clientId[0] /*clientId*/, FrontendSettings.TYPE_DVBT);
tunerFrontendRequest(clientId[0] /*clientId*/, FrontendSettings.TYPE_DVBT);
int[] frontendHandle = new int[1];
assertThat(mTunerResourceManagerService
.requestFrontendInternal(request, frontendHandle)).isTrue();
assertThat(frontendHandle[0]).isEqualTo(infos[0].getHandle());
assertThat(mTunerResourceManagerService.getFrontendResource(infos[0].getHandle())
assertThat(frontendHandle[0]).isEqualTo(infos[0].handle);
assertThat(mTunerResourceManagerService.getFrontendResource(infos[0].handle)
.isInUse()).isTrue();
assertThat(mTunerResourceManagerService.getFrontendResource(infos[1].getHandle())
assertThat(mTunerResourceManagerService.getFrontendResource(infos[1].handle)
.isInUse()).isTrue();
// Unregister client when using frontend
mTunerResourceManagerService.unregisterClientProfileInternal(clientId[0]);
assertThat(mTunerResourceManagerService.getFrontendResource(infos[0].getHandle())
assertThat(mTunerResourceManagerService.getFrontendResource(infos[0].handle)
.isInUse()).isFalse();
assertThat(mTunerResourceManagerService.getFrontendResource(infos[1].getHandle())
assertThat(mTunerResourceManagerService.getFrontendResource(infos[1].handle)
.isInUse()).isFalse();
assertThat(mTunerResourceManagerService.checkClientExists(clientId[0])).isFalse();
@@ -704,7 +708,7 @@ public class TunerResourceManagerServiceTest {
@Test
public void requestDemuxTest() {
// Register client
ResourceClientProfile profile = new ResourceClientProfile("0" /*sessionId*/,
ResourceClientProfile profile = resourceClientProfile("0" /*sessionId*/,
TvInputService.PRIORITY_HINT_USE_CASE_TYPE_PLAYBACK);
int[] clientId = new int[1];
mTunerResourceManagerService.registerClientProfileInternal(
@@ -712,7 +716,8 @@ public class TunerResourceManagerServiceTest {
assertThat(clientId[0]).isNotEqualTo(TunerResourceManagerService.INVALID_CLIENT_ID);
int[] demuxHandle = new int[1];
TunerDemuxRequest request = new TunerDemuxRequest(clientId[0]);
TunerDemuxRequest request = new TunerDemuxRequest();
request.clientId = clientId[0];
assertThat(mTunerResourceManagerService.requestDemuxInternal(request, demuxHandle))
.isTrue();
assertThat(mTunerResourceManagerService.getResourceIdFromHandle(demuxHandle[0]))
@@ -722,7 +727,7 @@ public class TunerResourceManagerServiceTest {
@Test
public void requestDescramblerTest() {
// Register client
ResourceClientProfile profile = new ResourceClientProfile("0" /*sessionId*/,
ResourceClientProfile profile = resourceClientProfile("0" /*sessionId*/,
TvInputService.PRIORITY_HINT_USE_CASE_TYPE_PLAYBACK);
int[] clientId = new int[1];
mTunerResourceManagerService.registerClientProfileInternal(
@@ -730,7 +735,8 @@ public class TunerResourceManagerServiceTest {
assertThat(clientId[0]).isNotEqualTo(TunerResourceManagerService.INVALID_CLIENT_ID);
int[] desHandle = new int[1];
TunerDescramblerRequest request = new TunerDescramblerRequest(clientId[0]);
TunerDescramblerRequest request = new TunerDescramblerRequest();
request.clientId = clientId[0];
assertThat(mTunerResourceManagerService.requestDescramblerInternal(request, desHandle))
.isTrue();
assertThat(mTunerResourceManagerService.getResourceIdFromHandle(desHandle[0])).isEqualTo(0);
@@ -740,10 +746,10 @@ public class TunerResourceManagerServiceTest {
public void isHigherPriorityTest() {
mIsForeground = false;
ResourceClientProfile backgroundPlaybackProfile =
new ResourceClientProfile(null /*sessionId*/,
resourceClientProfile(null /*sessionId*/,
TvInputService.PRIORITY_HINT_USE_CASE_TYPE_PLAYBACK);
ResourceClientProfile backgroundRecordProfile =
new ResourceClientProfile(null /*sessionId*/,
resourceClientProfile(null /*sessionId*/,
TvInputService.PRIORITY_HINT_USE_CASE_TYPE_RECORD);
int backgroundPlaybackPriority = mTunerResourceManagerService.getClientPriority(
TvInputService.PRIORITY_HINT_USE_CASE_TYPE_PLAYBACK, 0);
@@ -767,16 +773,16 @@ public class TunerResourceManagerServiceTest {
// Predefined client profiles
ResourceClientProfile[] ownerProfiles = new ResourceClientProfile[2];
ResourceClientProfile[] shareProfiles = new ResourceClientProfile[2];
ownerProfiles[0] = new ResourceClientProfile(
ownerProfiles[0] = resourceClientProfile(
"0" /*sessionId*/,
TvInputService.PRIORITY_HINT_USE_CASE_TYPE_LIVE);
ownerProfiles[1] = new ResourceClientProfile(
ownerProfiles[1] = resourceClientProfile(
"1" /*sessionId*/,
TvInputService.PRIORITY_HINT_USE_CASE_TYPE_LIVE);
shareProfiles[0] = new ResourceClientProfile(
shareProfiles[0] = resourceClientProfile(
"2" /*sessionId*/,
TvInputService.PRIORITY_HINT_USE_CASE_TYPE_RECORD);
shareProfiles[1] = new ResourceClientProfile(
shareProfiles[1] = resourceClientProfile(
"3" /*sessionId*/,
TvInputService.PRIORITY_HINT_USE_CASE_TYPE_RECORD);
@@ -828,12 +834,12 @@ public class TunerResourceManagerServiceTest {
// Predefined frontend info
TunerFrontendInfo[] infos = new TunerFrontendInfo[2];
infos[0] = new TunerFrontendInfo(
0 /*id*/,
infos[0] = tunerFrontendInfo(
0 /*handle*/,
FrontendSettings.TYPE_DVBT,
1 /*exclusiveGroupId*/);
infos[1] = new TunerFrontendInfo(
1 /*id*/,
infos[1] = tunerFrontendInfo(
1 /*handle*/,
FrontendSettings.TYPE_DVBS,
1 /*exclusiveGroupId*/);
@@ -848,7 +854,7 @@ public class TunerResourceManagerServiceTest {
// Predefined frontend request and array to save returned frontend handle
int[] frontendHandle = new int[1];
TunerFrontendRequest request = new TunerFrontendRequest(
TunerFrontendRequest request = tunerFrontendRequest(
ownerClientId0[0] /*clientId*/,
FrontendSettings.TYPE_DVBT);
@@ -856,13 +862,13 @@ public class TunerResourceManagerServiceTest {
assertThat(mTunerResourceManagerService
.requestFrontendInternal(request, frontendHandle))
.isTrue();
assertThat(frontendHandle[0]).isEqualTo(infos[0].getHandle());
assertThat(frontendHandle[0]).isEqualTo(infos[0].handle);
assertThat(mTunerResourceManagerService
.getClientProfile(ownerClientId0[0])
.getInUseFrontendHandles())
.isEqualTo(new HashSet<Integer>(Arrays.asList(
infos[0].getHandle(),
infos[1].getHandle())));
infos[0].handle,
infos[1].handle)));
/**** Share Frontend ****/
@@ -874,14 +880,14 @@ public class TunerResourceManagerServiceTest {
shareClientId1[0]/*selfClientId*/,
ownerClientId0[0]/*targetClientId*/);
// Verify fe in use status
assertThat(mTunerResourceManagerService.getFrontendResource(infos[0].getHandle())
assertThat(mTunerResourceManagerService.getFrontendResource(infos[0].handle)
.isInUse()).isTrue();
assertThat(mTunerResourceManagerService.getFrontendResource(infos[1].getHandle())
assertThat(mTunerResourceManagerService.getFrontendResource(infos[1].handle)
.isInUse()).isTrue();
// Verify fe owner status
assertThat(mTunerResourceManagerService.getFrontendResource(infos[0].getHandle())
assertThat(mTunerResourceManagerService.getFrontendResource(infos[0].handle)
.getOwnerClientId()).isEqualTo(ownerClientId0[0]);
assertThat(mTunerResourceManagerService.getFrontendResource(infos[1].getHandle())
assertThat(mTunerResourceManagerService.getFrontendResource(infos[1].handle)
.getOwnerClientId()).isEqualTo(ownerClientId0[0]);
// Verify share fe client status in the primary owner client
assertThat(mTunerResourceManagerService.getClientProfile(ownerClientId0[0])
@@ -894,20 +900,20 @@ public class TunerResourceManagerServiceTest {
.getClientProfile(ownerClientId0[0])
.getInUseFrontendHandles())
.isEqualTo(new HashSet<Integer>(Arrays.asList(
infos[0].getHandle(),
infos[1].getHandle())));
infos[0].handle,
infos[1].handle)));
assertThat(mTunerResourceManagerService
.getClientProfile(shareClientId0[0])
.getInUseFrontendHandles())
.isEqualTo(new HashSet<Integer>(Arrays.asList(
infos[0].getHandle(),
infos[1].getHandle())));
infos[0].handle,
infos[1].handle)));
assertThat(mTunerResourceManagerService
.getClientProfile(shareClientId1[0])
.getInUseFrontendHandles())
.isEqualTo(new HashSet<Integer>(Arrays.asList(
infos[0].getHandle(),
infos[1].getHandle())));
infos[0].handle,
infos[1].handle)));
/**** Remove Frontend Share Owner ****/
@@ -923,19 +929,19 @@ public class TunerResourceManagerServiceTest {
.getClientProfile(ownerClientId0[0])
.getInUseFrontendHandles())
.isEqualTo(new HashSet<Integer>(Arrays.asList(
infos[0].getHandle(),
infos[1].getHandle())));
infos[0].handle,
infos[1].handle)));
assertThat(mTunerResourceManagerService
.getClientProfile(shareClientId0[0])
.getInUseFrontendHandles())
.isEqualTo(new HashSet<Integer>(Arrays.asList(
infos[0].getHandle(),
infos[1].getHandle())));
infos[0].handle,
infos[1].handle)));
/**** Request Shared Frontend with Higher Priority Client ****/
// Predefined second frontend request
request = new TunerFrontendRequest(
request = tunerFrontendRequest(
ownerClientId1[0] /*clientId*/,
FrontendSettings.TYPE_DVBT);
@@ -945,17 +951,17 @@ public class TunerResourceManagerServiceTest {
.isTrue();
// Validate granted resource and internal mapping
assertThat(frontendHandle[0]).isEqualTo(infos[0].getHandle());
assertThat(mTunerResourceManagerService.getFrontendResource(infos[0].getHandle())
assertThat(frontendHandle[0]).isEqualTo(infos[0].handle);
assertThat(mTunerResourceManagerService.getFrontendResource(infos[0].handle)
.getOwnerClientId()).isEqualTo(ownerClientId1[0]);
assertThat(mTunerResourceManagerService.getFrontendResource(infos[1].getHandle())
assertThat(mTunerResourceManagerService.getFrontendResource(infos[1].handle)
.getOwnerClientId()).isEqualTo(ownerClientId1[0]);
assertThat(mTunerResourceManagerService
.getClientProfile(ownerClientId1[0])
.getInUseFrontendHandles())
.isEqualTo(new HashSet<Integer>(Arrays.asList(
infos[0].getHandle(),
infos[1].getHandle())));
infos[0].handle,
infos[1].handle)));
assertThat(mTunerResourceManagerService
.getClientProfile(ownerClientId0[0])
.getInUseFrontendHandles()
@@ -983,12 +989,12 @@ public class TunerResourceManagerServiceTest {
// Release the frontend resource from the primary owner
mTunerResourceManagerService.releaseFrontendInternal(mTunerResourceManagerService
.getFrontendResource(infos[0].getHandle()), ownerClientId1[0]);
.getFrontendResource(infos[0].handle), ownerClientId1[0]);
// Validate the internal mapping
assertThat(mTunerResourceManagerService.getFrontendResource(infos[0].getHandle())
assertThat(mTunerResourceManagerService.getFrontendResource(infos[0].handle)
.isInUse()).isFalse();
assertThat(mTunerResourceManagerService.getFrontendResource(infos[1].getHandle())
assertThat(mTunerResourceManagerService.getFrontendResource(infos[1].handle)
.isInUse()).isFalse();
// Verify client status
assertThat(mTunerResourceManagerService
@@ -1010,7 +1016,8 @@ public class TunerResourceManagerServiceTest {
/**** Unregister Primary Owner when the Share owner owns an Lnb ****/
// Predefined Lnb request and handle array
TunerLnbRequest requestLnb = new TunerLnbRequest(shareClientId0[0]);
TunerLnbRequest requestLnb = new TunerLnbRequest();
requestLnb.clientId = shareClientId0[0];
int[] lnbHandle = new int[1];
// Request for an Lnb
@@ -1030,9 +1037,9 @@ public class TunerResourceManagerServiceTest {
mTunerResourceManagerService.unregisterClientProfileInternal(ownerClientId1[0]);
// Validate the internal mapping
assertThat(mTunerResourceManagerService.getFrontendResource(infos[0].getHandle())
assertThat(mTunerResourceManagerService.getFrontendResource(infos[0].handle)
.isInUse()).isFalse();
assertThat(mTunerResourceManagerService.getFrontendResource(infos[1].getHandle())
assertThat(mTunerResourceManagerService.getFrontendResource(infos[1].handle)
.isInUse()).isFalse();
// Verify client status
assertThat(mTunerResourceManagerService
@@ -1046,4 +1053,34 @@ public class TunerResourceManagerServiceTest {
.isEqualTo(new HashSet<Integer>(Arrays.asList(
lnbHandles[0])));
}
private TunerFrontendInfo tunerFrontendInfo(
int handle, int frontendType, int exclusiveGroupId) {
TunerFrontendInfo info = new TunerFrontendInfo();
info.handle = handle;
info.frontendType = frontendType;
info.exclusiveGroupId = exclusiveGroupId;
return info;
}
private TunerFrontendRequest tunerFrontendRequest(int clientId, int frontendType) {
TunerFrontendRequest request = new TunerFrontendRequest();
request.clientId = clientId;
request.frontendType = frontendType;
return request;
}
private ResourceClientProfile resourceClientProfile(String sessionId, int useCase) {
ResourceClientProfile profile = new ResourceClientProfile();
profile.tvInputSessionId = sessionId;
profile.useCase = useCase;
return profile;
}
private CasSessionRequest casSessionRequest(int clientId, int casSystemId) {
CasSessionRequest request = new CasSessionRequest();
request.clientId = clientId;
request.casSystemId = casSystemId;
return request;
}
}