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

Commit 4ea3b6d4 authored by Amy's avatar Amy
Browse files

Adding ITunerResourceManagerService interface into android.media.tv

This CL handles the frontend related APIs.
Please see MediaCas and Lnb related APIs in the CL chain.

Test: manual
Bug: 147380513
Change-Id: I0c463dc29b39fdca0cba07a4a4a445d7a6054c14
parent 004e36da
Loading
Loading
Loading
Loading
+138 −0
Original line number Diff line number Diff line
/*
 * Copyright 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.media.tv.tuner;

import android.media.tv.tuner.ITunerResourceManagerListener;
import android.media.tv.tuner.ResourceClientProfile;
import android.media.tv.tuner.TunerFrontendInfo;
import android.media.tv.tuner.TunerFrontendRequest;

/**
 * Interface of the Tuner Resource Manager. It manages resources used by TV Tuners.
 * <p>Resources include:
 * <ul>
 * <li>TunerFrontend {@link android.media.tv.tuner.frontend}.
 * <li>TunerLnb {@link android.media.tv.tuner.Lnb}.
 * <li>MediaCas {@link android.media.MediaCas}.
 * <li>TvInputHardware {@link android.media.tv.TvInputHardwareInfo}.
 * <ul>
 *
 * <p>Expected workflow is:
 * <ul>
 * <li>Tuner Java/MediaCas/TIF update resources of the current device with TRM.
 * <li>Client registers its profile through {@link #registerClientProfile(ResourceClientProfile,
 * ITunerResourceManagerListener, int[])}.
 * <li>Client requests resources through request APIs.
 * <li>If the resource needs to be handed to a higher priority client from a lower priority
 * one, TRM calls ITunerResourceManagerListener registered by the lower priority client to release
 * the resource.
 * <ul>
 *
 * @hide
 */
interface ITunerResourceManager {
    /*
     * This API is used by the client to register their profile with the Tuner Resource manager.
     *
     * <p>The profile contains information that can show the base priority score of the client.
     *
     * @param profile {@link ResourceClientProfile} profile of the current client
     * @param listener {@link ITunerResourceManagerListener} a callback to
     *                 reclaim clients' resources when needed.
     * @param clientId returns a clientId from the resource manager when the
     *                 the client registers its profile.
     */
    void registerClientProfile(in ResourceClientProfile profile,
        ITunerResourceManagerListener listener, out int[] clientId);

    /*
     * This API is used by the client to unregister their profile with the Tuner Resource manager.
     *
     * @param clientId the client id that needs to be unregistered.
     */
    void unregisterClientProfile(in int clientId);

    /*
     * Updates a registered client's priority and niceValue.
     *
     * @param clientId the id of the client that is updating its profile.
     * @param priority the priority that the client would like to update to.
     * @param niceValue the nice value that the client would like to update to.
     *
     * @return true if the update is successful.
     */
    boolean updateClientPriority(in int clientId, in int priority, in int niceValue);

    /*
     * Updates the available Frontend resources information on the current device.
     *
     * <p><strong>Note:</strong> This update must happen before the first
     * {@link #requestFrontend(TunerFrontendRequest,int[])} and {@link #releaseFrontend(int)} call.
     *
     * @param infos an array of the available {@link TunerFrontendInfo} information.
     */
    void setFrontendInfoList(in TunerFrontendInfo[] infos);

    /*
     * This API is used by the Tuner framework to request an available frontend from the TunerHAL.
     *
     * <p>There are three possible scenarios:
     * <ul>
     * <li>If there is frontend available, the API would send the id back.
     *
     * <li>If no Frontend is available but the current request info can show higher priority than
     * other uses of Frontend, the API will send
     * {@link ITunerResourceManagerListener#onResourcesReclaim()} to the {@link Tuner}. Tuner would
     * handle the resource reclaim on the holder of lower priority and notify the holder of its
     * resource loss.
     *
     * <li>If no frontend can be granted, the API would return false.
     * <ul>
     *
     * <p><strong>Note:</strong> {@link #setFrontendInfoList(TunerFrontendInfo[])} must be called
     * before this request.
     *
     * @param request {@link TunerFrontendRequest} information of the current request.
     * @param frontendId a one-element array to return the granted frontendId.
     *
     * @return true if there is frontend granted.
     */
    boolean requestFrontend(in TunerFrontendRequest request, out int[] frontendId);

    /*
     * Requests to share frontend with an existing client.
     *
     * <p><strong>Note:</strong> {@link #setFrontendInfoList(TunerFrontendInfo[])} must be called
     * before this request.
     *
     * @param selfClientId the id of the client that sends the request.
     * @param targetClientId the id of the client to share the frontend with.
     */
    void shareFrontend(in int selfClientId, in int targetClientId);

    /*
     * Notifies the TRM that the given frontend has been released.
     *
     * <p>Client must call this whenever it releases a Tuner frontend.
     *
     * <p><strong>Note:</strong> {@link #setFrontendInfoList(TunerFrontendInfo[])} must be called
     * before this release.
     *
     * @param frontendId the id of the released frontend.
     */
    void releaseFrontend(in int frontendId);
}
+33 −0
Original line number Diff line number Diff line
/*
 * Copyright 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.media.tv.tuner;

/**
 * Interface to receive callbacks from ITunerResourceManager.
 *
 * @hide
 */
oneway interface ITunerResourceManagerListener {
    /*
     * TRM invokes this method when the client's resources need to be reclaimed.
     *
     * <p>This method is implemented in Tuner Framework to take the reclaiming
     * actions. It's a synchonized call. TRM would wait on the call to finish
     * then grant the resource.
     */
    void onResourcesReclaim();
}
 No newline at end of file
+25 −0
Original line number Diff line number Diff line
/*
 * Copyright 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.media.tv.tuner;

/**
 * A profile of a resource client. This profile is used to register the client info
 * with the Tuner Resource Manager.
 *
 * @hide
 */
parcelable ResourceClientProfile;
 No newline at end of file
+129 −0
Original line number Diff line number Diff line
/*
 * Copyright 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.media.tv.tuner;

import android.annotation.NonNull;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;

/**
 * A profile of a resource client. This profile is used to register the client info
 * with the Tuner Resource Manager(TRM).
 *
 * @hide
 */
public final class ResourceClientProfile implements Parcelable {
    static final String TAG = "ResourceClientProfile";

    public static final
                @NonNull
                Parcelable.Creator<ResourceClientProfile> CREATOR =
                new Parcelable.Creator<ResourceClientProfile>() {
                @Override
                public ResourceClientProfile createFromParcel(Parcel source) {
                    try {
                        return new ResourceClientProfile(source);
                    } catch (Exception e) {
                        Log.e(TAG, "Exception creating ResourceClientProfile from parcel", e);
                        return null;
                    }
                }

                @Override
                public ResourceClientProfile[] newArray(int size) {
                    return new ResourceClientProfile[size];
                }
            };

    /**
     * This is used by TRM to get TV App’s processId from TIF.
     * The processId will be used to identify foreground applications.
     *
     * <p>MediaCas, Tuner and TvInputHardwareManager get tvInputSessionId from TIS.
     * If mTvInputSessionId is UNKNOWN, the client is always background.
     */
    private final String mTvInputSessionId;

    /**
     * Usage of the client.
     */
    private final int mUseCase;

    private ResourceClientProfile(@NonNull Parcel source) {
        mTvInputSessionId = source.readString();
        mUseCase = source.readInt();
    }

    /**
     * Constructs a new {@link ResourceClientProfile} with the given parameters.
     *
     * @param tvInputSessionId the unique id of the session owned by the client.
     * @param useCase the usage of the client. Suggested priority hints are
     *                {@link android.media.tv.TvInputService.PRIORITY_HINT_USE_CASE_TYPE_PLAYBACK}
     *                {@link android.media.tv.TvInputService.PRIORITY_HINT_USE_CASE_TYPE_LIVE}
     *                {@link android.media.tv.TvInputService.PRIORITY_HINT_USE_CASE_TYPE_RECORD}.
     *                New [use case : priority value] pair can be defined in the manifest by the
     *                OEM. Any undefined use case would cause IllegalArgumentException.
     */
    public ResourceClientProfile(@NonNull String tvInputSessionId,
                                 int useCase) {
        mTvInputSessionId = tvInputSessionId;
        mUseCase = useCase;
    }

    /**
     * Returns the tv input session id of the client.
     *
     * @return the value of the tv input session id.
     */
    @NonNull
    public String getTvInputSessionId() {
        return mTvInputSessionId;
    }

    /**
     * Returns the user usage of the client.
     *
     * @return the value of use case.
     */
    public int getUseCase() {
        return mUseCase;
    }

    // Parcelable
    @Override
    public int describeContents() {
        return 0;
    }

    @NonNull
    @Override
    public String toString() {
        StringBuilder b = new StringBuilder(128);
        b.append("ResourceClientProfile {tvInputSessionId=").append(mTvInputSessionId);
        b.append(", useCase=").append(mUseCase);
        b.append("}");
        return b.toString();
    }

    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        dest.writeString(mTvInputSessionId);
        dest.writeInt(mUseCase);
    }
}
+24 −0
Original line number Diff line number Diff line
/*
 * Copyright 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.media.tv.tuner;

/**
 * Simple container of the FrontendInfo struct defined in the TunerHAL 1.0 interface.
 *
 * @hide
 */
parcelable TunerFrontendInfo;
 No newline at end of file
Loading