diff options
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/app/ContextImpl.java | 9 | ||||
| -rw-r--r-- | core/java/android/content/Context.java | 12 | ||||
| -rw-r--r-- | core/java/android/hardware/hdmi/HdmiCec.java | 63 | ||||
| -rw-r--r-- | core/java/android/hardware/hdmi/HdmiCecClient.java | 125 | ||||
| -rw-r--r-- | core/java/android/hardware/hdmi/HdmiCecManager.java | 73 |
5 files changed, 281 insertions, 1 deletions
diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java index d9cad3b8195a..bb46197fd02f 100644 --- a/core/java/android/app/ContextImpl.java +++ b/core/java/android/app/ContextImpl.java @@ -51,6 +51,8 @@ import android.hardware.ConsumerIrManager; import android.hardware.ISerialManager; import android.hardware.SerialManager; import android.hardware.SystemSensorManager; +import android.hardware.hdmi.HdmiCecManager; +import android.hardware.hdmi.IHdmiCecService; import android.hardware.camera2.CameraManager; import android.hardware.display.DisplayManager; import android.hardware.input.InputManager; @@ -357,6 +359,13 @@ class ContextImpl extends Context { return new BluetoothManager(ctx); }}); + registerService(HDMI_CEC_SERVICE, new StaticServiceFetcher() { + public Object createStaticService() { + IBinder b = ServiceManager.getService(HDMI_CEC_SERVICE); + return new HdmiCecManager(IHdmiCecService.Stub.asInterface(b)); + }}); + + registerService(CLIPBOARD_SERVICE, new ServiceFetcher() { public Object createService(ContextImpl ctx) { return new ClipboardManager(ctx.getOuterContext(), diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java index 2e4e209b5c15..f4b1afe89e91 100644 --- a/core/java/android/content/Context.java +++ b/core/java/android/content/Context.java @@ -1974,6 +1974,8 @@ public abstract class Context { * @see android.app.SearchManager * @see #SENSOR_SERVICE * @see android.hardware.SensorManager + * @see #HDMI_CEC_SERVICE + * @see android.hardware.hdmi.HdmiCecManager * @see #STORAGE_SERVICE * @see android.os.storage.StorageManager * @see #VIBRATOR_SERVICE @@ -2389,6 +2391,16 @@ public abstract class Context { /** * Use with {@link #getSystemService} to retrieve a + * {@link android.hardware.hdmi.HdmiCecManager for controlling and managing + * HDMI-CEC protocol. + * + * @see #getSystemService + * @see android.hardware.hdmi.HdmiCecManager + */ + public static final String HDMI_CEC_SERVICE = "hdmi_cec"; + + /** + * Use with {@link #getSystemService} to retrieve a * {@link android.hardware.input.InputManager} for interacting with input devices. * * @see #getSystemService diff --git a/core/java/android/hardware/hdmi/HdmiCec.java b/core/java/android/hardware/hdmi/HdmiCec.java index c95431a2f094..38d9de41697b 100644 --- a/core/java/android/hardware/hdmi/HdmiCec.java +++ b/core/java/android/hardware/hdmi/HdmiCec.java @@ -97,7 +97,68 @@ public final class HdmiCec { public static final int ADDR_INVALID = -1; // TODO: Complete the list of CEC messages definition. - public static final int MESSAGE_ACTIVE_SOURCE = 0x9D; + public static final int MESSAGE_FEATURE_ABORT = 0x00; + public static final int MESSAGE_IMAGE_VIEW_ON = 0x04; + public static final int MESSAGE_TUNER_STEP_INCREMENT = 0x05; + public static final int MESSAGE_TUNER_STEP_DECREMENT = 0x06; + public static final int MESSAGE_TUNER_DEVICE_STATUS = 0x07; + public static final int MESSAGE_GIVE_TUNER_DEVICE_STATUS = 0x08; + public static final int MESSAGE_RECORD_ON = 0x09; + public static final int MESSAGE_RECORD_STATUS = 0x0A; + public static final int MESSAGE_RECORD_OFF = 0x0B; + public static final int MESSAGE_TEXT_VIEW_ON = 0x0D; + public static final int MESSAGE_RECORD_TV_SCREEN = 0x0F; + public static final int MESSAGE_GIVE_DECK_STATUS = 0x1A; + public static final int MESSAGE_DECK_STATUS = 0x1B; + public static final int MESSAGE_SET_MENU_LANGUAGE = 0x32; + public static final int MESSAGE_CLEAR_ANALOG_TIMER = 0x33; + public static final int MESSAGE_SET_ANALOG_TIMER = 0x34; + public static final int MESSAGE_TIMER_STATUS = 0x35; + public static final int MESSAGE_STANDBY = 0x36; + public static final int MESSAGE_PLAY = 0x41; + public static final int MESSAGE_DECK_CONTROL = 0x42; + public static final int MESSAGE_TIMER_CLEARED_STATUS = 0x043; + public static final int MESSAGE_USER_CONTROL_PRESSED = 0x44; + public static final int MESSAGE_USER_CONTROL_RELEASED = 0x45; + public static final int MESSAGE_GET_OSD_NAME = 0x46; + public static final int MESSAGE_SET_OSD_NAME = 0x47; + public static final int MESSAGE_SET_OSD_STRING = 0x64; + public static final int MESSAGE_SET_TIMER_PROGRAM_TITLE = 0x67; + public static final int MESSAGE_SYSTEM_AUDIO_MODE_REQUEST = 0x70; + public static final int MESSAGE_GIVE_AUDIO_STATUS = 0x71; + public static final int MESSAGE_SET_SYSTEM_AUDIO_MODE = 0x72; + public static final int MESSAGE_REPORT_AUDIO_STATUS = 0x7A; + public static final int MESSAGE_GIVE_SYSTEM_AUDIO_MODE_STATUS = 0x7D; + public static final int MESSAGE_SYSTEM_AUDIO_MODE_STATUS = 0x7E; + public static final int MESSAGE_ROUTING_CHANGE = 0x80; + public static final int MESSAGE_ROUTING_INFORMATION = 0x81; + public static final int MESSAGE_ACTIVE_SOURCE = 0x82; + public static final int MESSAGE_GIVE_PHYSICAL_ADDRESS = 0x83; + public static final int MESSAGE_REPORT_PHYSICAL_ADDRESS = 0x84; + public static final int MESSAGE_REQUEST_ACTIVE_SOURCE = 0x85; + public static final int MESSAGE_SET_STREAM_PATH = 0x86; + public static final int MESSAGE_DEVICE_VENDOR_ID = 0x87; + public static final int MESSAGE_VENDOR_COMMAND = 0x89; + public static final int MESSAGE_VENDOR_REMOTE_BUTTON_DOWN = 0x8A; + public static final int MESSAGE_VENDOR_REMOTE_BUTTON_UP = 0x8B; + public static final int MESSAGE_GIVE_DEVICE_VENDOR_ID = 0x8C; + public static final int MESSAGE_MENU_REQUEST = 0x8D; + public static final int MESSAGE_MENU_STATUS = 0x8E; + public static final int MESSAGE_GIVE_DEVICE_POWER_STATUS = 0x8F; + public static final int MESSAGE_REPORT_POWER_STATUS = 0x90; + public static final int MESSAGE_GET_MENU_LANGUAGE = 0x91; + public static final int MESSAGE_SELECT_ANALOG_SERVICE = 0x92; + public static final int MESSAGE_SELECT_DIGITAL_SERVICE = 0x93; + public static final int MESSAGE_SET_DIGITAL_TIMER = 0x97; + public static final int MESSAGE_CLEAR_DIGITAL_TIMER = 0x99; + public static final int MESSAGE_SET_AUDIO_RATE = 0x9A; + public static final int MESSAGE_INACTIVE_SOURCE = 0x9D; + public static final int MESSAGE_CEC_VERSION = 0x9E; + public static final int MESSAGE_GET_CEC_VERSION = 0x9F; + public static final int MESSAGE_VENDOR_COMMAND_WITH_ID = 0xA0; + public static final int MESSAGE_CLEAR_EXTERNAL_TIMER = 0xA1; + public static final int MESSAGE_SET_EXTERNAL_TIMER = 0xA2; + public static final int MESSAGE_ABORT = 0xFF; private static final int[] ADDRESS_TO_TYPE = { DEVICE_TV, // ADDR_TV diff --git a/core/java/android/hardware/hdmi/HdmiCecClient.java b/core/java/android/hardware/hdmi/HdmiCecClient.java new file mode 100644 index 000000000000..d7f4a72c6eb8 --- /dev/null +++ b/core/java/android/hardware/hdmi/HdmiCecClient.java @@ -0,0 +1,125 @@ +/* + * 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.os.IBinder; +import android.os.RemoteException; + +import android.util.Log; + +/** + * HdmiCecClient is used to control HDMI-CEC logical device instance in the system. + * It is connected to actual hardware part via HdmiCecService. It provides with methods + * to send CEC messages to other device on the bus, and listener that allows to receive + * incoming messages to the device. + */ +public final class HdmiCecClient { + private static final String TAG = "HdmiCecClient"; + + private final IHdmiCecService mService; + private final IBinder mBinder; + + /** + * Listener used by the client to get the incoming messages. + */ + public static abstract class Listener { + /** + * Called when CEC message arrives. Override this method to receive the incoming + * CEC messages from other device on the bus. + * + * @param message {@link HdmiCecMessage} object + */ + public void onMessageReceived(HdmiCecMessage message) { } + + /** + * Called when hotplug event occurs. Override this method to receive the events. + * + * @param connected true if the cable is connected; otherwise false. + */ + public void onCableStatusChanged(boolean connected) { } + } + + // Private constructor. + private HdmiCecClient(IHdmiCecService service, IBinder b) { + mService = service; + mBinder = b; + } + + // Factory method for HdmiCecClient. + // Declared package-private. Accessed by HdmiCecManager only. + static HdmiCecClient create(IHdmiCecService service, IBinder b) { + return new HdmiCecClient(service, b); + } + + /** + * Send <Active Source> message. + */ + public void sendActiveSource() { + try { + mService.sendActiveSource(mBinder); + } catch (RemoteException e) { + Log.e(TAG, "sendActiveSource threw exception ", e); + } + } + + /** + * Send <Inactive Source> message. + */ + public void sendInactiveSource() { + try { + mService.sendInactiveSource(mBinder); + } catch (RemoteException e) { + Log.e(TAG, "sendInactiveSource threw exception ", e); + } + } + + /** + * Send <TextViewOn> message. + */ + public void sendTextViewOn() { + try { + mService.sendTextViewOn(mBinder); + } catch (RemoteException e) { + Log.e(TAG, "sendTextViewOn threw exception ", e); + } + } + + /** + * Send <ImageViewOn> message. + */ + public void sendImageViewOn() { + try { + mService.sendImageViewOn(mBinder); + } catch (RemoteException e) { + Log.e(TAG, "sendImageViewOn threw exception ", e); + } + } + + /** + * Send <GiveDevicePowerStatus> message. + * + * @param address logical address of the device to send the message to, such as + * {@link HdmiCec#ADDR_TV}. + */ + public void sendGiveDevicePowerStatus(int address) { + try { + mService.sendGiveDevicePowerStatus(mBinder, address); + } catch (RemoteException e) { + Log.e(TAG, "sendGiveDevicePowerStatus threw exception ", e); + } + } +} diff --git a/core/java/android/hardware/hdmi/HdmiCecManager.java b/core/java/android/hardware/hdmi/HdmiCecManager.java new file mode 100644 index 000000000000..575785d351f5 --- /dev/null +++ b/core/java/android/hardware/hdmi/HdmiCecManager.java @@ -0,0 +1,73 @@ +/* + * 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.os.IBinder; +import android.os.RemoteException; + +/** + * The HdmiCecManager class is used to provide an HdmiCecClient instance, + * get various information on HDMI ports configuration. It is connected to actual hardware + * via HdmiCecService. + */ +public final class HdmiCecManager { + private final IHdmiCecService mService; + + /** + * @hide - hide this constructor because it has a parameter of type IHdmiCecService, + * which is a system private class. The right way to create an instance of this class + * is using the factory Context.getSystemService. + */ + public HdmiCecManager(IHdmiCecService service) { + mService = service; + } + + /** + * Provide the HdmiCecClient instance of the given type. It also registers the listener + * for client to get the events coming to the device. + * + * @param type type of the HDMI-CEC logical device + * @param listener listener to be called + * @return {@link HdmiCecClient} instance. {@code null} on failure. + */ + public HdmiCecClient getClient(int type, HdmiCecClient.Listener listener) { + try { + IBinder b = mService.allocateLogicalDevice(type, getListenerWrapper(listener)); + return HdmiCecClient.create(mService, b); + } catch (RemoteException e) { + return null; + } + } + + private IHdmiCecListener getListenerWrapper(final HdmiCecClient.Listener listener) { + // TODO: The message/events are not yet forwarded to client since it is not clearly + // defined as to how/who to handle them. Revisit it once the decision is + // made on what messages will have to reach the clients, what will be + // handled by service/manager. + return new IHdmiCecListener.Stub() { + @Override + public void onMessageReceived(HdmiCecMessage message) { + // Do nothing. + } + + @Override + public void onCableStatusChanged(boolean connected) { + // Do nothing. + } + }; + } +} |
