blob: d19fe017d6d326efa25498c1bef203bca207f020 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
/*
* Copyright (C) 2012 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 com.android.server.display;
import android.content.Context;
import android.os.Handler;
import java.io.PrintWriter;
/**
* A display adapter makes zero or more display devices available to the system
* and provides facilities for discovering when displays are connected or disconnected.
* <p>
* For now, all display adapters are registered in the system server but
* in principle it could be done from other processes.
* </p><p>
* Display devices are not thread-safe and must only be accessed
* on the display manager service's handler thread.
* </p>
*/
public class DisplayAdapter {
private final Context mContext;
private final String mName;
private final Handler mHandler;
private Listener mListener;
public static final int DISPLAY_DEVICE_EVENT_ADDED = 1;
public static final int DISPLAY_DEVICE_EVENT_CHANGED = 2;
public static final int DISPLAY_DEVICE_EVENT_REMOVED = 3;
public DisplayAdapter(Context context, String name) {
mContext = context;
mName = name;
mHandler = new Handler();
}
public final Context getContext() {
return mContext;
}
public final Handler getHandler() {
return mHandler;
}
/**
* Gets the display adapter name for debugging purposes.
*
* @return The display adapter name.
*/
public final String getName() {
return mName;
}
/**
* Registers the display adapter with the display manager.
*
* @param listener The listener for callbacks. The listener will
* be invoked on the display manager service's handler thread.
*/
public final void register(Listener listener) {
mListener = listener;
onRegister();
}
/**
* Dumps the local state of the display adapter.
*/
public void dump(PrintWriter pw) {
}
/**
* Called when the display adapter is registered.
*
* The display adapter should register any built-in display devices as soon as possible.
* The boot process will wait for the default display to be registered.
*
* Other display devices can be registered dynamically later.
*/
protected void onRegister() {
}
/**
* Sends a display device event to the display adapter listener asynchronously.
*/
protected void sendDisplayDeviceEvent(final DisplayDevice device, final int event) {
mHandler.post(new Runnable() {
@Override
public void run() {
mListener.onDisplayDeviceEvent(device, event);
}
});
}
public interface Listener {
public void onDisplayDeviceEvent(DisplayDevice device, int event);
}
}
|