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

Commit d38bf476 authored by Jinsuk Kim's avatar Jinsuk Kim
Browse files

Move input change event handling out of TVInputManager

HDMI input change event should be handled best in TIS implementation
of HDMI input since the input change request from TV/other device
needs to be properly coordinated. This requires the listener be
moved the input service.

Provided an interface in HdmiTvClient for the input service to access
the API through getSystemService(Context.HDMI_CONTROL_SERVICE).

Conflicts:
	services/core/java/com/android/server/tv/TvInputHardwareManager.java

Bug: 15570939
Change-Id: Ie2ad10d77907de3d4501f9c892ca553b75365467
parent 3afd00e9
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