HdmiControlService.java revision e9c77c88ea34a66f83a94f960547275c0ff6bd07
1/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.hdmi;
18
19import android.annotation.Nullable;
20import android.content.Context;
21import android.os.HandlerThread;
22import android.os.Looper;
23import android.util.Slog;
24
25import com.android.server.SystemService;
26
27/**
28 * Provides a service for sending and processing HDMI control messages,
29 * HDMI-CEC and MHL control command, and providing the information on both standard.
30 */
31public final class HdmiControlService extends SystemService {
32    private static final String TAG = "HdmiControlService";
33
34    // A thread to handle synchronous IO of CEC and MHL control service.
35    // Since all of CEC and MHL HAL interfaces processed in short time (< 200ms)
36    // and sparse call it shares a thread to handle IO operations.
37    private final HandlerThread mIoThread = new HandlerThread("Hdmi Control Io Thread");
38
39    @Nullable
40    private HdmiCecController mCecController;
41
42    @Nullable
43    private HdmiMhlController mMhlController;
44
45    public HdmiControlService(Context context) {
46        super(context);
47    }
48
49    @Override
50    public void onStart() {
51        mCecController = HdmiCecController.create(this);
52        if (mCecController == null) {
53            Slog.i(TAG, "Device does not support HDMI-CEC.");
54        }
55
56        mMhlController = HdmiMhlController.create(this);
57        if (mMhlController == null) {
58            Slog.i(TAG, "Device does not support MHL-control.");
59        }
60    }
61
62    /**
63     * Returns {@link Looper} for IO operation.
64     *
65     * <p>Declared as package-private.
66     */
67    Looper getIoLooper() {
68        return mIoThread.getLooper();
69    }
70
71    /**
72     * Returns {@link Looper} of main thread. Use this {@link Looper} instance
73     * for tasks that are running on main service thread.
74     *
75     * <p>Declared as package-private.
76     */
77    Looper getServiceLooper() {
78        return Looper.myLooper();
79    }
80}
81