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

Commit 6d97f5b9 authored by Jinsuk Kim's avatar Jinsuk Kim
Browse files

A few more APIs for HdmiControlService

Added following APIs in HdmiControlService:

- portSelect
- sendKeyEvent
- getPortInfo
- addDeviceEventListener

Some are not fleshed out yet. Will work on it in a follow up CL.

Change-Id: Ia8c635176c0378f6e8db589bf714d82bf21ce85d
parent 7237cd81
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -152,6 +152,7 @@ LOCAL_SRC_FILES += \
	core/java/android/hardware/display/IDisplayManagerCallback.aidl \
	core/java/android/hardware/hdmi/IHdmiControlCallback.aidl \
	core/java/android/hardware/hdmi/IHdmiControlService.aidl \
	core/java/android/hardware/hdmi/IHdmiDeviceEventListener.aidl \
	core/java/android/hardware/hdmi/IHdmiHotplugEventListener.aidl \
	core/java/android/hardware/input/IInputManager.aidl \
	core/java/android/hardware/input/IInputDevicesChangedListener.aidl \
+19 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 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;

parcelable HdmiCecDeviceInfo;
+9 −1
Original line number Diff line number Diff line
@@ -16,10 +16,14 @@

package android.hardware.hdmi;

import android.hardware.hdmi.HdmiCecMessage;
import android.hardware.hdmi.HdmiCecDeviceInfo;
import android.hardware.hdmi.HdmiPortInfo;
import android.hardware.hdmi.IHdmiControlCallback;
import android.hardware.hdmi.IHdmiDeviceEventListener;
import android.hardware.hdmi.IHdmiHotplugEventListener;

import java.util.List;

/**
 * Binder interface that clients running in the application process
 * will use to perform HDMI-CEC features by communicating with other devices
@@ -33,5 +37,9 @@ interface IHdmiControlService {
    void queryDisplayStatus(IHdmiControlCallback callback);
    void addHotplugEventListener(IHdmiHotplugEventListener listener);
    void removeHotplugEventListener(IHdmiHotplugEventListener listener);
    void addDeviceEventListener(IHdmiDeviceEventListener listener);
    void deviceSelect(int logicalAddress, IHdmiControlCallback callback);
    void portSelect(int portId, IHdmiControlCallback callback);
    void sendKeyEvent(int keyCode);
    List<HdmiPortInfo> getPortInfo();
}
+35 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 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.HdmiCecDeviceInfo;

/**
 * Callback interface definition for HDMI client to get informed of
 * the CEC logical device status change event.
 *
 * @hide
 */
oneway interface IHdmiDeviceEventListener {

    /**
     * @param deviceInfo {@link HdmiCecDeviceInfo} of the logical device whose
     *                   status has changed
     * @param activated true if the device gets activated
     */
    void onStatusChanged(in HdmiCecDeviceInfo deviceInfo, in boolean activated);
}
+65 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.hardware.hdmi.HdmiHotplugEvent;
import android.hardware.hdmi.HdmiPortInfo;
import android.hardware.hdmi.IHdmiControlCallback;
import android.hardware.hdmi.IHdmiControlService;
import android.hardware.hdmi.IHdmiDeviceEventListener;
import android.hardware.hdmi.IHdmiHotplugEventListener;
import android.os.Build;
import android.os.Handler;
@@ -118,6 +119,14 @@ public final class HdmiControlService extends SystemService {
    private final ArrayList<HotplugEventListenerRecord> mHotplugEventListenerRecords =
            new ArrayList<>();

    // List of listeners registered by callers that want to get notified of
    // device status events.
    private final ArrayList<IHdmiDeviceEventListener> mDeviceEventListeners = new ArrayList<>();

    // List of records for device event listener to handle the the caller killed in action.
    private final ArrayList<DeviceEventListenerRecord> mDeviceEventListenerRecords =
            new ArrayList<>();

    // Handler running on service thread. It's used to run a task in service thread.
    private final Handler mHandler = new Handler();

@@ -777,6 +786,22 @@ public final class HdmiControlService extends SystemService {
        }
    }

    private final class DeviceEventListenerRecord implements IBinder.DeathRecipient {
        private final IHdmiDeviceEventListener mListener;

        public DeviceEventListenerRecord(IHdmiDeviceEventListener listener) {
            mListener = listener;
        }

        @Override
            public void binderDied() {
            synchronized (mLock) {
                mDeviceEventListenerRecords.remove(this);
                mDeviceEventListeners.remove(mListener);
            }
        }
    }

    private void enforceAccessPermission() {
        getContext().enforceCallingOrSelfPermission(PERMISSION, TAG);
    }
@@ -854,6 +879,33 @@ public final class HdmiControlService extends SystemService {
                }
            });
        }

        @Override
        public void addDeviceEventListener(final IHdmiDeviceEventListener listener) {
            enforceAccessPermission();
            runOnServiceThread(new Runnable() {
                @Override
                    public void run() {
                    HdmiControlService.this.addDeviceEventListener(listener);
                }
            });
        }

        @Override
        public void portSelect(int portId, IHdmiControlCallback callback) {
            // TODO: Implement this
        }

        @Override
        public void sendKeyEvent(int keyCode) {
            // TODO: Implement this
        }

        @Override
        public List<HdmiPortInfo> getPortInfo() {
            enforceAccessPermission();
            return mPortInfo;
        }
    }

    private void oneTouchPlay(IHdmiControlCallback callback) {
@@ -930,6 +982,19 @@ public final class HdmiControlService extends SystemService {
        }
    }

    private void addDeviceEventListener(IHdmiDeviceEventListener listener) {
        synchronized (mLock) {
            for (DeviceEventListenerRecord record : mDeviceEventListenerRecords) {
                if (record.mListener.asBinder() == listener.asBinder()) {
                    listener.asBinder().unlinkToDeath(record, 0);
                    mDeviceEventListenerRecords.remove(record);
                    break;
                }
            }
            mHotplugEventListeners.remove(listener);
        }
    }

    private void invokeCallback(IHdmiControlCallback callback, int result) {
        try {
            callback.onComplete(result);