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

Commit b093ac46 authored by Madhava Srinivasan's avatar Madhava Srinivasan Committed by Aaron Kling
Browse files

Honor HDMI_CONTROL_ENABLED setting in AudioService

This change updates how AudioService is updated of changes to Hdmi Cec
status (enable/disable) and availablity.

Bug: 138956107
Bug: 138373017
Test: Android TV STB: make; flashall;Volume -/+; HDMI control enable/disable.
Change-Id: Iaf83a45206be076858e13d113ba772ed5c59ef60
Merged-In: Iaf83a45206be076858e13d113ba772ed5c59ef60
parent 610e9d4a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -179,6 +179,7 @@ java_defaults {
        "core/java/android/hardware/fingerprint/IFingerprintServiceReceiver.aidl",
        "core/java/android/hardware/hdmi/IHdmiControlCallback.aidl",
        "core/java/android/hardware/hdmi/IHdmiControlService.aidl",
        "core/java/android/hardware/hdmi/IHdmiControlStatusChangeListener.aidl",
        "core/java/android/hardware/hdmi/IHdmiDeviceEventListener.aidl",
        "core/java/android/hardware/hdmi/IHdmiHotplugEventListener.aidl",
        "core/java/android/hardware/hdmi/IHdmiInputChangeListener.aidl",
+91 −0
Original line number Diff line number Diff line
@@ -684,6 +684,28 @@ public final class HdmiControlManager {
    private final ArrayMap<HotplugEventListener, IHdmiHotplugEventListener>
            mHotplugEventListeners = new ArrayMap<>();

    /**
     * Listener used to get HDMI Control (CEC) status (enabled/disabled) and the connected display
     * status.
     * @hide
     */
    public interface HdmiControlStatusChangeListener {
        /**
         * Called when HDMI Control (CEC) is enabled/disabled.
         *
         * @param isCecEnabled status of HDMI Control
         * {@link android.provider.Settings.Global#HDMI_CONTROL_ENABLED}: {@code true} if enabled.
         * @param isCecAvailable status of CEC support of the connected display (the TV).
         * {@code true} if supported.
         *
         * Note: Value of isCecAvailable is only valid when isCecEnabled is true.
         **/
        void onStatusChange(boolean isCecEnabled, boolean isCecAvailable);
    }

    private final ArrayMap<HdmiControlStatusChangeListener, IHdmiControlStatusChangeListener>
            mHdmiControlStatusChangeListeners = new ArrayMap<>();

    /**
     * Listener used to get vendor-specific commands.
     */
@@ -777,4 +799,73 @@ public final class HdmiControlManager {
            }
        };
    }

    /**
     * Adds a listener to get informed of {@link HdmiControlStatusChange}.
     *
     * <p>To stop getting the notification,
     * use {@link #removeHdmiControlStatusChangeListener(HdmiControlStatusChangeListener)}.
     *
     * @param listener {@link HdmiControlStatusChangeListener} instance
     * @see HdmiControlManager#removeHdmiControlStatusChangeListener(
     * HdmiControlStatusChangeListener)
     *
     * @hide
     */
    @RequiresPermission(android.Manifest.permission.HDMI_CEC)
    public void addHdmiControlStatusChangeListener(HdmiControlStatusChangeListener listener) {
        if (mService == null) {
            Log.e(TAG, "HdmiControlService is not available");
            return;
        }
        if (mHdmiControlStatusChangeListeners.containsKey(listener)) {
            Log.e(TAG, "listener is already registered");
            return;
        }
        IHdmiControlStatusChangeListener wrappedListener =
                getHdmiControlStatusChangeListenerWrapper(listener);
        mHdmiControlStatusChangeListeners.put(listener, wrappedListener);
        try {
            mService.addHdmiControlStatusChangeListener(wrappedListener);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Removes a listener to stop getting informed of {@link HdmiControlStatusChange}.
     *
     * @param listener {@link HdmiControlStatusChangeListener} instance to be removed
     *
     * @hide
     */
    @RequiresPermission(android.Manifest.permission.HDMI_CEC)
    public void removeHdmiControlStatusChangeListener(HdmiControlStatusChangeListener listener) {
        if (mService == null) {
            Log.e(TAG, "HdmiControlService is not available");
            return;
        }
        IHdmiControlStatusChangeListener wrappedListener =
                mHdmiControlStatusChangeListeners.remove(listener);
        if (wrappedListener == null) {
            Log.e(TAG, "tried to remove not-registered listener");
            return;
        }
        try {
            mService.removeHdmiControlStatusChangeListener(wrappedListener);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    private IHdmiControlStatusChangeListener getHdmiControlStatusChangeListenerWrapper(
            final HdmiControlStatusChangeListener listener) {
        return new IHdmiControlStatusChangeListener.Stub() {
            @Override
            public void onStatusChange(boolean isCecEnabled, boolean isCecAvailable) {
                listener.onStatusChange(isCecEnabled, isCecAvailable);
            }
        };
    }

}
+3 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.hardware.hdmi;
import android.hardware.hdmi.HdmiDeviceInfo;
import android.hardware.hdmi.HdmiPortInfo;
import android.hardware.hdmi.IHdmiControlCallback;
import android.hardware.hdmi.IHdmiControlStatusChangeListener;
import android.hardware.hdmi.IHdmiDeviceEventListener;
import android.hardware.hdmi.IHdmiHotplugEventListener;
import android.hardware.hdmi.IHdmiInputChangeListener;
@@ -41,6 +42,8 @@ interface IHdmiControlService {
    HdmiDeviceInfo getActiveSource();
    void oneTouchPlay(IHdmiControlCallback callback);
    void queryDisplayStatus(IHdmiControlCallback callback);
    void addHdmiControlStatusChangeListener(IHdmiControlStatusChangeListener listener);
    void removeHdmiControlStatusChangeListener(IHdmiControlStatusChangeListener listener);
    void addHotplugEventListener(IHdmiHotplugEventListener listener);
    void removeHotplugEventListener(IHdmiHotplugEventListener listener);
    void addDeviceEventListener(IHdmiDeviceEventListener listener);
+40 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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.hardware.hdmi;

import android.hardware.hdmi.HdmiDeviceInfo;

/**
 * Callback interface definition for HDMI client to get informed of
 * the CEC availability change event.
 *
 * @hide
 */
oneway interface IHdmiControlStatusChangeListener {

    /**
     * Called when HDMI Control (CEC) is enabled/disabled.
     *
     * @param isCecEnabled status of HDMI Control
     * {@link android.provider.Settings.Global#HDMI_CONTROL_ENABLED}: {@code true} if enabled.
     * @param isCecAvailable status of CEC support of the connected display (the TV).
     * {@code true} if supported.
     *
     * Note: Value of isCecAvailable is only valid when isCecEnabled is true.
     **/
    void onStatusChange(boolean isCecEnabled, boolean isCecAvailable);
}
+10 −0
Original line number Diff line number Diff line
@@ -193,6 +193,16 @@ public class HdmiAudioSystemClientTest {
        public void queryDisplayStatus(final IHdmiControlCallback callback) {
        }

        @Override
        public void addHdmiControlStatusChangeListener(
                final IHdmiControlStatusChangeListener listener) {
        }

        @Override
        public void removeHdmiControlStatusChangeListener(
                final IHdmiControlStatusChangeListener listener) {
        }

        @Override
        public void addHotplugEventListener(final IHdmiHotplugEventListener listener) {
        }
Loading