diff --git a/core/java/android/app/SystemServiceRegistry.java b/core/java/android/app/SystemServiceRegistry.java index 50b9d6b47e020..8b07418668bad 100644 --- a/core/java/android/app/SystemServiceRegistry.java +++ b/core/java/android/app/SystemServiceRegistry.java @@ -109,6 +109,8 @@ import android.media.session.MediaSessionManager; import android.media.soundtrigger.SoundTriggerManager; import android.media.tv.ITvInputManager; import android.media.tv.TvInputManager; +import android.media.tv.tuner.ITunerResourceManager; +import android.media.tv.tuner.TunerResourceManager; import android.net.ConnectivityDiagnosticsManager; import android.net.ConnectivityManager; import android.net.ConnectivityThread; @@ -937,6 +939,17 @@ public final class SystemServiceRegistry { return new TvInputManager(service, ctx.getUserId()); }}); + registerService(Context.TV_TUNER_RESOURCE_MGR_SERVICE, TunerResourceManager.class, + new CachedServiceFetcher() { + @Override + public TunerResourceManager createService(ContextImpl ctx) + throws ServiceNotFoundException { + IBinder iBinder = + ServiceManager.getServiceOrThrow(Context.TV_TUNER_RESOURCE_MGR_SERVICE); + ITunerResourceManager service = ITunerResourceManager.Stub.asInterface(iBinder); + return new TunerResourceManager(service, ctx.getUserId()); + }}); + registerService(Context.NETWORK_SCORE_SERVICE, NetworkScoreManager.class, new CachedServiceFetcher() { @Override diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java index 249e58244870d..49f62f4078068 100644 --- a/core/java/android/content/Context.java +++ b/core/java/android/content/Context.java @@ -3457,6 +3457,7 @@ public abstract class Context { CONSUMER_IR_SERVICE, //@hide: TRUST_SERVICE, TV_INPUT_SERVICE, + //@hide: TV_TUNER_RESOURCE_MGR_SERVICE, //@hide: NETWORK_SCORE_SERVICE, USAGE_STATS_SERVICE, MEDIA_SESSION_SERVICE, @@ -4756,6 +4757,17 @@ public abstract class Context { */ public static final String TV_INPUT_SERVICE = "tv_input"; + /** + * Use with {@link #getSystemService(String)} to retrieve a + * {@link android.media.tv.TunerResourceManager} for interacting with TV + * tuner resources on the device. + * + * @see #getSystemService(String) + * @see android.media.tv.TunerResourceManager + * @hide + */ + public static final String TV_TUNER_RESOURCE_MGR_SERVICE = "tv_tuner_resource_mgr"; + /** * {@link android.net.NetworkScoreManager} for managing network scoring. * @see #getSystemService(String) diff --git a/media/java/android/media/tv/tuner/ITunerResourceManager.aidl b/media/java/android/media/tv/tuner/ITunerResourceManager.aidl index 7c33e93f45f93..758c68949b657 100644 --- a/media/java/android/media/tv/tuner/ITunerResourceManager.aidl +++ b/media/java/android/media/tv/tuner/ITunerResourceManager.aidl @@ -230,4 +230,15 @@ interface ITunerResourceManager { * @param lnbId the id of the released Tuner Lnb. */ void releaseLnb(in int lnbId); + + /* + * Compare two clients' priority. + * + * @param challengerProfile the {@link ResourceClientProfile} of the challenger. + * @param holderProfile the {@link ResourceClientProfile} of the holder of the resource. + * + * @return true if the challenger has higher priority than the holder. + */ + boolean isHigherPriority(in ResourceClientProfile challengerProfile, + in ResourceClientProfile holderProfile); } diff --git a/media/java/android/media/tv/tuner/TunerResourceManager.java b/media/java/android/media/tv/tuner/TunerResourceManager.java new file mode 100644 index 0000000000000..68ca5722ecad6 --- /dev/null +++ b/media/java/android/media/tv/tuner/TunerResourceManager.java @@ -0,0 +1,407 @@ +/* + * Copyright 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.media.tv.tuner; + +import android.annotation.CallbackExecutor; +import android.annotation.NonNull; +import android.annotation.Nullable; +import android.annotation.RequiresFeature; +import android.annotation.SystemService; +import android.content.Context; +import android.content.pm.PackageManager; +import android.os.Binder; +import android.os.RemoteException; +import android.util.Log; + +import java.util.concurrent.Executor; + +/** + * Interface of the Tuner Resource Manager(TRM). It manages resources used by TV Tuners. + *

Resources include: + *