Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c01fac78 authored by Sham Rathod's avatar Sham Rathod Committed by Yixiao Luo
Browse files

TunerResourceManager: Add API to determine Resource Ownership.

Added APIs to MediaCas and Tuner JAVA for determining resource ownership
between Resource Holder and Resource Challenger.
Implemented tests to validate scenarios where Resource Holder retains
ownership and Resource Challenger acquires it.

Bug: 264857199
Bug: 300565729
Bug: 372973197

Test: atest TunerResourceManagerServiceTest
Test: atest MediaCasTest
Test: atest TunerTest
(cherry picked from https://partner-android-review.googlesource.com/q/commit:5a71bdb2a97dcb2d85c8580c6e0f000783141263)
Flag: android.media.tv.flags.set_resource_holder_retain

Change-Id: I12e386fb610b5814f902e5ac9b7eb6aa11d1b201
parent dc12d6ea
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -22608,7 +22608,6 @@ package android.media {
    method public void sendEvent(int, int, @Nullable byte[]) throws android.media.MediaCasException;
    method public void setEventListener(@Nullable android.media.MediaCas.EventListener, @Nullable android.os.Handler);
    method public void setPrivateData(@NonNull byte[]) throws android.media.MediaCasException;
    method @FlaggedApi("com.android.media.flags.update_client_profile_priority") public boolean updateResourcePriority(int, int);
    field public static final int PLUGIN_STATUS_PHYSICAL_MODULE_CHANGED = 0; // 0x0
    field public static final int PLUGIN_STATUS_SESSION_NUMBER_CHANGED = 1; // 0x1
    field public static final int SCRAMBLING_MODE_AES128 = 9; // 0x9
+6 −0
Original line number Diff line number Diff line
@@ -7454,6 +7454,11 @@ package android.media {
    method @NonNull public android.media.HwAudioSource.Builder setAudioDeviceInfo(@NonNull android.media.AudioDeviceInfo);
  }
  public final class MediaCas implements java.lang.AutoCloseable {
    method @FlaggedApi("android.media.tv.flags.set_resource_holder_retain") @RequiresPermission("android.permission.TUNER_RESOURCE_ACCESS") public void setResourceHolderRetain(boolean);
    method @FlaggedApi("com.android.media.flags.update_client_profile_priority") @RequiresPermission("android.permission.TUNER_RESOURCE_ACCESS") public boolean updateResourcePriority(int, int);
  }
  public final class MediaCodec {
    method @NonNull @RequiresPermission(android.Manifest.permission.MEDIA_RESOURCE_OVERRIDE_PID) public static android.media.MediaCodec createByCodecNameForClient(@NonNull String, int, int) throws java.io.IOException;
  }
@@ -8226,6 +8231,7 @@ package android.media.tv.tuner {
    method public int setLnaEnabled(boolean);
    method public int setMaxNumberOfFrontends(int, @IntRange(from=0) int);
    method public void setOnTuneEventListener(@NonNull java.util.concurrent.Executor, @NonNull android.media.tv.tuner.frontend.OnTuneEventListener);
    method @FlaggedApi("android.media.tv.flags.set_resource_holder_retain") @RequiresPermission("android.permission.TUNER_RESOURCE_ACCESS") public void setResourceHolderRetain(boolean);
    method public void setResourceLostListener(@NonNull java.util.concurrent.Executor, @NonNull android.media.tv.tuner.Tuner.OnResourceLostListener);
    method public void shareFrontendFromTuner(@NonNull android.media.tv.tuner.Tuner);
    method public int transferOwner(@NonNull android.media.tv.tuner.Tuner);
+24 −0
Original line number Diff line number Diff line
@@ -16,12 +16,16 @@

package android.media;

import static android.media.tv.flags.Flags.FLAG_SET_RESOURCE_HOLDER_RETAIN;

import static com.android.media.flags.Flags.FLAG_UPDATE_CLIENT_PROFILE_PRIORITY;

import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.content.Context;
import android.hardware.cas.AidlCasPluginDescriptor;
@@ -988,12 +992,32 @@ public final class MediaCas implements AutoCloseable {
     * @param priority the new priority. Any negative value would cause no-op on priority setting
     *     and the API would only process nice value setting in that case.
     * @param niceValue the nice value.
     * @hide
     */
    @FlaggedApi(FLAG_UPDATE_CLIENT_PROFILE_PRIORITY)
    @SystemApi
    @RequiresPermission(android.Manifest.permission.TUNER_RESOURCE_ACCESS)
    public boolean updateResourcePriority(int priority, int niceValue) {
        return mTunerResourceManager.updateClientPriority(mClientId, priority, niceValue);
    }

    /**
     * Determines whether the resource holder retains ownership of the resource during a challenge
     * scenario, when both resource holder and resource challenger have same processId and same
     * priority.
     *
     * @param resourceHolderRetain Set to {@code true} to allow the resource holder to retain
     *     ownership, or false to allow the resource challenger to acquire the resource.
     *     If not explicitly set, resourceHolderRetain is set to {@code false}.
     * @hide
     */
    @FlaggedApi(FLAG_SET_RESOURCE_HOLDER_RETAIN)
    @SystemApi
    @RequiresPermission(android.Manifest.permission.TUNER_RESOURCE_ACCESS)
    public void setResourceHolderRetain(boolean resourceHolderRetain) {
        mTunerResourceManager.setResourceHolderRetain(mClientId, resourceHolderRetain);
    }

    IHwBinder getBinder() {
        if (mICas != null) {
            return null; // Return IHwBinder only for HIDL
+9 −1
Original line number Diff line number Diff line
@@ -72,3 +72,11 @@ flag {
    description: "Standardize AIDL Extension Interface of TIS"
    bug: "330366987"
}

flag {
    name: "set_resource_holder_retain"
    is_exported: true
    namespace: "media_tv"
    description : "Feature flag to add setResourceHolderRetain api to MediaCas and Tuner JAVA."
    bug: "372973197"
}
+17 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.media.tv.tuner;

import static android.media.tv.flags.Flags.FLAG_SET_RESOURCE_HOLDER_RETAIN;

import android.annotation.BytesLong;
import android.annotation.CallbackExecutor;
import android.annotation.FlaggedApi;
@@ -750,6 +752,21 @@ public class Tuner implements AutoCloseable {
        mTunerResourceManager.updateClientPriority(mClientId, priority, niceValue);
    }

    /**
     * Determines whether the resource holder retains ownership of the resource during a challenge
     * scenario, when both resource holder and resource challenger have same processId and same
     * priority.
     *
     * @param resourceHolderRetain Set to true to allow the resource holder to retain ownership, or
     *     false to allow the resource challenger to acquire the resource. If not explicitly set,
     *     resourceHolderRetain is set to false.
     */
    @FlaggedApi(FLAG_SET_RESOURCE_HOLDER_RETAIN)
    @RequiresPermission(android.Manifest.permission.TUNER_RESOURCE_ACCESS)
    public void setResourceHolderRetain(boolean resourceHolderRetain) {
        mTunerResourceManager.setResourceHolderRetain(mClientId, resourceHolderRetain);
    }

    /**
     * Checks if there is an unused frontend resource available.
     *
Loading