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

Commit 104149e9 authored by Yixiao Luo's avatar Yixiao Luo
Browse files

add function setTvView to link the input Session and IApp Session

Bug: 204926703
Change-Id: I235e9817ce47dd8d5bed1fbc322a7cb68d4bcdf5
parent 0ec644c1
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.content.Context;
import android.content.Intent;
import android.graphics.Rect;
import android.media.PlaybackParams;
import android.media.tv.interactive.TvIAppManager;
import android.net.Uri;
import android.os.Binder;
import android.os.Bundle;
@@ -2073,6 +2074,8 @@ public final class TvInputManager {
        // @GuardedBy("mMetadataLock")
        private int mVideoHeight;

        private TvIAppManager.Session mIAppSession;

        private Session(IBinder token, InputChannel channel, ITvInputManager service, int userId,
                int seq, SparseArray<SessionCallbackRecord> sessionCallbackRecordMap) {
            mToken = token;
@@ -2083,6 +2086,14 @@ public final class TvInputManager {
            mSessionCallbackRecordMap = sessionCallbackRecordMap;
        }

        public TvIAppManager.Session getIAppSession() {
            return mIAppSession;
        }

        public void setIAppSession(TvIAppManager.Session IAppSession) {
            this.mIAppSession = IAppSession;
        }

        /**
         * Releases this session.
         */
+7 −0
Original line number Diff line number Diff line
@@ -34,6 +34,8 @@ import android.media.PlaybackParams;
import android.media.tv.TvInputManager.Session;
import android.media.tv.TvInputManager.Session.FinishedInputEventCallback;
import android.media.tv.TvInputManager.SessionCallback;
import android.media.tv.interactive.TvIAppManager;
import android.media.tv.interactive.TvIAppView;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
@@ -197,6 +199,11 @@ public class TvView extends ViewGroup {
        mCallback = callback;
    }

    /** @hide */
    public Session getInputSession() {
        return mSession;
    }

    /**
     * Sets this as the main {@link TvView}.
     *
+11 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemService;
import android.content.Context;
import android.media.tv.TvInputManager;
import android.os.Handler;
import android.os.IBinder;
import android.os.RemoteException;
@@ -150,6 +151,8 @@ public final class TvIAppManager {

        private IBinder mToken;

        private TvInputManager.Session mInputSession;

        private Session(IBinder token, ITvIAppManager service, int userId, int seq,
                SparseArray<SessionCallbackRecord> sessionCallbackRecordMap) {
            mToken = token;
@@ -159,6 +162,14 @@ public final class TvIAppManager {
            mSessionCallbackRecordMap = sessionCallbackRecordMap;
        }

        public TvInputManager.Session getInputSession() {
            return mInputSession;
        }

        public void setInputSession(TvInputManager.Session inputSession) {
            mInputSession = inputSession;
        }

        void startIApp() {
            if (mToken == null) {
                Log.w(TAG, "The session has been already released");
+41 −0
Original line number Diff line number Diff line
@@ -16,9 +16,12 @@

package android.media.tv.interactive;

import android.annotation.Nullable;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.media.tv.TvInputManager;
import android.media.tv.TvView;
import android.media.tv.interactive.TvIAppManager.Session;
import android.media.tv.interactive.TvIAppManager.SessionCallback;
import android.os.Handler;
@@ -39,6 +42,11 @@ public class TvIAppView extends ViewGroup {
    private static final String TAG = "TvIAppView";
    private static final boolean DEBUG = false;

    private static final int SET_TVVIEW_SUCCESS = 1;
    private static final int SET_TVVIEW_FAIL = 2;
    private static final int UNSET_TVVIEW_SUCCESS = 3;
    private static final int UNSET_TVVIEW_FAIL = 4;

    private final TvIAppManager mTvIAppManager;
    private final Handler mHandler = new Handler();
    private Session mSession;
@@ -213,6 +221,39 @@ public class TvIAppView extends ViewGroup {
        }
    }

    public Session getIAppSession() {
        return mSession;
    }

    /**
     * Sets the TvIAppView to receive events from TIS. This method links the session of
     * TvIAppManager to TvInputManager session, so the TIAS can get the TIS events.
     *
     * @param tvView the TvView to be linked to this TvIAppView via linking of Sessions.
     * @return to be added
     */
    public int setTvView(@Nullable TvView tvView) {
        if (tvView == null) {
            return unsetTvView();
        }
        TvInputManager.Session inputSession = tvView.getInputSession();
        if (inputSession == null || mSession == null) {
            return SET_TVVIEW_FAIL;
        }
        mSession.setInputSession(inputSession);
        inputSession.setIAppSession(mSession);
        return SET_TVVIEW_SUCCESS;
    }

    private int unsetTvView() {
        if (mSession == null || mSession.getInputSession() == null) {
            return UNSET_TVVIEW_FAIL;
        }
        mSession.getInputSession().setIAppSession(null);
        mSession.setInputSession(null);
        return UNSET_TVVIEW_SUCCESS;
    }

    private class MySessionCallback extends SessionCallback {
        final String mIAppServiceId;
        int mType;