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

Commit 79124a71 authored by Terry Heo's avatar Terry Heo
Browse files

TIF: Enable capturing TV input of TvInputPassthroughWrapperService

Also fixed usage of Log.e() in TvInputService to show stack trace.

Bug: 16441553
Change-Id: I5c160de4a628698907ffd00510d982d597c0ea01
parent 35efc633
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -27,4 +27,5 @@ oneway interface ITvInputServiceCallback {
    void addHardwareTvInput(in int deviceID, in TvInputInfo inputInfo);
    void addHdmiCecTvInput(in int logicalAddress, in TvInputInfo inputInfo);
    void removeTvInput(in String inputId);
    void setWrappedInputId(in String inputId, in String wrappedInputId);
}
+1 −0
Original line number Diff line number Diff line
@@ -75,6 +75,7 @@ public abstract class TvInputPassthroughWrapperService extends TvInputService {
        if (!session.connect(passthroughInputId)) {
            throw new IllegalStateException("WrapperSession cannot be reused.");
        }
        notifyWrappedInputId(inputId, passthroughInputId);
        return session;
    }

+38 −3
Original line number Diff line number Diff line
@@ -216,6 +216,21 @@ public abstract class TvInputService extends Service {
        return null;
    }

    /**
     * Notify wrapped TV input ID of current input to TV input framework manager
     *
     * @param inputId The TV input ID of {@link TvInputPassthroughWrapperService}
     * @param wrappedInputId The ID of the wrapped TV input such as external pass-though TV input
     * @hide
     */
    public final void notifyWrappedInputId(String inputId, String wrappedInputId) {
        SomeArgs args = SomeArgs.obtain();
        args.arg1 = inputId;
        args.arg2 = wrappedInputId;
        mHandler.obtainMessage(TvInputService.ServiceHandler.DO_SET_WRAPPED_TV_INPUT_ID,
                args).sendToTarget();
    }

    /**
     * Base class for derived classes to implement to provide a TV input session.
     */
@@ -943,6 +958,7 @@ public abstract class TvInputService extends Service {
        private static final int DO_REMOVE_HARDWARE_TV_INPUT = 3;
        private static final int DO_ADD_HDMI_CEC_TV_INPUT = 4;
        private static final int DO_REMOVE_HDMI_CEC_TV_INPUT = 5;
        private static final int DO_SET_WRAPPED_TV_INPUT_ID = 6;

        private void broadcastAddHardwareTvInput(int deviceId, TvInputInfo inputInfo) {
            int n = mCallbacks.beginBroadcast();
@@ -950,7 +966,7 @@ public abstract class TvInputService extends Service {
                try {
                    mCallbacks.getBroadcastItem(i).addHardwareTvInput(deviceId, inputInfo);
                } catch (RemoteException e) {
                    Log.e(TAG, "Error while broadcasting: " + e);
                    Log.e(TAG, "Error while broadcasting.", e);
                }
            }
            mCallbacks.finishBroadcast();
@@ -963,7 +979,7 @@ public abstract class TvInputService extends Service {
                try {
                    mCallbacks.getBroadcastItem(i).addHdmiCecTvInput(logicalAddress, inputInfo);
                } catch (RemoteException e) {
                    Log.e(TAG, "Error while broadcasting: " + e);
                    Log.e(TAG, "Error while broadcasting.", e);
                }
            }
            mCallbacks.finishBroadcast();
@@ -975,7 +991,19 @@ public abstract class TvInputService extends Service {
                try {
                    mCallbacks.getBroadcastItem(i).removeTvInput(inputId);
                } catch (RemoteException e) {
                    Log.e(TAG, "Error while broadcasting: " + e);
                    Log.e(TAG, "Error while broadcasting.", e);
                }
            }
            mCallbacks.finishBroadcast();
        }

        private void broadcastSetWrappedTvInputId(String inputId, String wrappedInputId) {
            int n = mCallbacks.beginBroadcast();
            for (int i = 0; i < n; ++i) {
                try {
                    mCallbacks.getBroadcastItem(i).setWrappedInputId(inputId, wrappedInputId);
                } catch (RemoteException e) {
                    Log.e(TAG, "Error while broadcasting.", e);
                }
            }
            mCallbacks.finishBroadcast();
@@ -1038,6 +1066,13 @@ public abstract class TvInputService extends Service {
                    }
                    return;
                }
                case DO_SET_WRAPPED_TV_INPUT_ID: {
                    SomeArgs args = (SomeArgs) msg.obj;
                    String inputId = (String) args.arg1;
                    String wrappedInputId = (String) args.arg2;
                    broadcastSetWrappedTvInputId(inputId, wrappedInputId);
                    return;
                }
                default: {
                    Log.w(TAG, "Unhandled message code: " + msg.what);
                    return;
+34 −2
Original line number Diff line number Diff line
@@ -1293,8 +1293,14 @@ public final class TvInputManagerService extends SystemService {
            final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid,
                    userId, "captureFrame");
            try {
                final String wrappedInputId;
                synchronized (mLock) {
                    UserState userState = getUserStateLocked(resolvedUserId);
                    wrappedInputId = userState.wrappedInputMap.get(inputId);
                }
                return mTvInputHardwareManager.captureFrame(
                        inputId, surface, config, callingUid, resolvedUserId);
                        (wrappedInputId != null) ? wrappedInputId : inputId,
                        surface, config, callingUid, resolvedUserId);
            } finally {
                Binder.restoreCallingIdentity(identity);
            }
@@ -1470,6 +1476,9 @@ public final class TvInputManagerService extends SystemService {
        // A set of callbacks.
        private final Set<ITvInputManagerCallback> callbackSet =
                new HashSet<ITvInputManagerCallback>();

        // A mapping from the TV input id to wrapped input id.
        private final Map<String, String> wrappedInputMap = new HashMap<String, String>();
    }

    private final class ClientState implements IBinder.DeathRecipient {
@@ -1662,8 +1671,10 @@ public final class TvInputManagerService extends SystemService {

                    for (TvInputState inputState : userState.inputMap.values()) {
                        if (inputState.mInfo.getComponent().equals(name)) {
                            notifyInputStateChangedLocked(userState, inputState.mInfo.getId(),
                            String inputId = inputState.mInfo.getId();
                            notifyInputStateChangedLocked(userState, inputId,
                                    INPUT_STATE_DISCONNECTED, null);
                            userState.wrappedInputMap.remove(inputId);
                        }
                    }
                    updateServiceConnectionLocked(mName, mUserId);
@@ -1742,6 +1753,27 @@ public final class TvInputManagerService extends SystemService {
                }
            }
        }

        @Override
        public void setWrappedInputId(String inputId, String wrappedInputId) {
            synchronized (mLock) {
                if (!hasInputIdLocked(inputId)) {
                    return;
                }
                UserState userState = getUserStateLocked(mUserId);
                userState.wrappedInputMap.put(inputId, wrappedInputId);
            }
        }

        private boolean hasInputIdLocked(String inputId) {
            ServiceState serviceState = getServiceStateLocked(mName, mUserId);
            for (TvInputInfo inputInfo : serviceState.mInputList) {
                if (inputInfo.getId().equals(inputId)) {
                    return true;
                }
            }
            return false;
        }
    }

    private final class LogHandler extends Handler {