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

Commit 91e25eda authored by Jinsuk Kim's avatar Jinsuk Kim Committed by Android (Google) Code Review
Browse files

Merge "Move input change event handling out of TVInputManager" into lmp-dev

parents 78d1d0f9 d38bf476
Loading
Loading
Loading
Loading
+37 −0
Original line number Diff line number Diff line
@@ -98,6 +98,34 @@ public final class HdmiTvClient extends HdmiClient {
        }
    }

    /**
     * Callback interface used to get the input change event.
     */
    public interface InputChangeListener {
        /**
         * Called when the input was changed.
         *
         * @param info newly selected HDMI input
         */
        void onChanged(HdmiDeviceInfo info);
    }

    /**
     * Set the listener used to get informed of the input change event.
     *
     * @param listener listener object
     */
    public void setInputChangeListener(InputChangeListener listener) {
        if (listener == null) {
            throw new IllegalArgumentException("listener must not be null.");
        }
        try {
            mService.setInputChangeListener(getListenerWrapper(listener));
        } catch (RemoteException e) {
            Log.e("TAG", "Failed to set InputChangeListener:", e);
        }
    }

    /**
     * Set system audio volume
     *
@@ -257,6 +285,15 @@ public final class HdmiTvClient extends HdmiClient {
        };
    }

    private static IHdmiInputChangeListener getListenerWrapper(final InputChangeListener listener) {
        return new IHdmiInputChangeListener.Stub() {
            @Override
            public void onChanged(HdmiDeviceInfo info) {
                listener.onChanged(info);
            }
        };
    }

    private static IHdmiRecordListener getListenerWrapper(final HdmiRecordListener callback) {
        return new IHdmiRecordListener.Stub() {
            @Override
+1 −27
Original line number Diff line number Diff line
@@ -93,9 +93,9 @@ class TvInputHardwareManager implements TvInputHal.Callback {
    private final IHdmiHotplugEventListener mHdmiHotplugEventListener =
            new HdmiHotplugEventListener();
    private final IHdmiDeviceEventListener mHdmiDeviceEventListener = new HdmiDeviceEventListener();
    private final IHdmiInputChangeListener mHdmiInputChangeListener = new HdmiInputChangeListener();
    private final IHdmiSystemAudioModeChangeListener mHdmiSystemAudioModeChangeListener =
            new HdmiSystemAudioModeChangeListener();

    // TODO: Should handle STANDBY case.
    private final SparseBooleanArray mHdmiStateMap = new SparseBooleanArray();
    private final List<Message> mPendingHdmiDeviceEvents = new LinkedList<>();
@@ -123,7 +123,6 @@ class TvInputHardwareManager implements TvInputHal.Callback {
                    mHdmiControlService.addSystemAudioModeChangeListener(
                            mHdmiSystemAudioModeChangeListener);
                    mHdmiDeviceList.addAll(mHdmiControlService.getInputDevices());
                    mHdmiControlService.setInputChangeListener(mHdmiInputChangeListener);
                } catch (RemoteException e) {
                    Slog.w(TAG, "Error registering listeners to HdmiControlService:", e);
                }
@@ -994,31 +993,6 @@ class TvInputHardwareManager implements TvInputHal.Callback {
        }
    }

    private final class HdmiInputChangeListener extends IHdmiInputChangeListener.Stub {
        @Override
        public void onChanged(HdmiDeviceInfo device) throws RemoteException {
            String inputId;
            synchronized (mLock) {
                if (device.isCecDevice()) {
                    inputId = mHdmiInputIdMap.get(device.getLogicalAddress());
                } else {
                    TvInputHardwareInfo hardwareInfo =
                            findHardwareInfoForHdmiPortLocked(device.getPortId());
                    inputId = (hardwareInfo == null) ? null
                            : mHardwareInputIdMap.get(hardwareInfo.getDeviceId());
                }
            }
            if (inputId != null) {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(TvContract.buildChannelUriForPassthroughTvInput(inputId));
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                mContext.startActivity(intent);
            } else {
                Slog.w(TAG, "onChanged: InputId cannot be found for :" + device);
            }
        }
    }

    private final class HdmiSystemAudioModeChangeListener extends
        IHdmiSystemAudioModeChangeListener.Stub {
        @Override