2057 int InputDispatcher::handleReceiveCallback(int fd, int events, void* data) {
2058 InputDispatcher* d = static_cast<InputDispatcher*>(data);
2059
2060 {
2061 AutoMutex _l(d->mLock);
2062
2063 ssize_t connectionIndex = d->mConnectionsByFd.indexOfKey(fd);
2064 if (connectionIndex < 0) {
2065 ALOGE("Received spurious receive callback for unknown input channel. "
2066 "fd=%d, events=0x%x", fd, events);
2067 return 0;
2068 }
2069
2070 bool notify;
2071 sp<Connection> connection = d->mConnectionsByFd.valueAt(connectionIndex);
2072 if (!(events & (ALOOPER_EVENT_ERROR | ALOOPER_EVENT_HANGUP))) {
2073 if (!(events & ALOOPER_EVENT_INPUT)) {
2074 ALOGW("channel '%s' ~ Received spurious callback for unhandled poll event. "
2075 "events=0x%x", connection->getInputChannelName(), events);
2076 return 1;
2077 }
2078
2079 nsecs_t currentTime = now();
2080 bool gotOne = false;
2081 status_t status;
2082 for (;;) {
2083 uint32_t seq;
2084 bool handled;
2085 status = connection->inputPublisher.receiveFinishedSignal(&seq, &handled);
2086 if (status) {
2087 break;
2088 }
2089 d->finishDispatchCycleLocked(currentTime, connection, seq, handled);
2090 gotOne = true;
2091 }
2092 if (gotOne) {
2093 d->runCommandsLockedInterruptible();
2094 if (status == WOULD_BLOCK) {
2095 return 1;
2096 }
2097 }
2098
2099 notify = status != DEAD_OBJECT || !connection->monitor;
2100 if (notify) {
2101 ALOGE("channel '%s' ~ Failed to receive finished signal. status=%d",
2102 connection->getInputChannelName(), status);
2103 }
2104 } else {
2105
2106
2107
2108 notify = !connection->monitor;
2109 if (notify) {
2110 ALOGW("channel '%s' ~ Consumer closed input channel or an error occurred. "
2111 "events=0x%x", connection->getInputChannelName(), events);
2112 }
2113 }
2114
2115
2116 d->unregisterInputChannelLocked(connection->inputChannel, notify);
2117 return 0;
2118 }
2119 }
3281 void InputDispatcher::onDispatchCycleBrokenLocked(
3282 nsecs_t currentTime, const sp<Connection>& connection) {
3283 ALOGE("channel '%s' ~ Channel is unrecoverably broken and will be disposed!",
3284 connection->getInputChannelName());
3285
3286 CommandEntry* commandEntry = postCommandLocked(
3287 & InputDispatcher::doNotifyInputChannelBrokenLockedInterruptible);
3288 commandEntry->connection = connection;
3289 }
||<
></blockquote><
*1350996276*[android]java.lang.RuntimeException: Could not open input channel pair.
><blockquote cite="http://tools.oesf.biz/android-4.1.1_r1.0/xref/frameworks/base/core/jni/android_view_InputChannel.cpp#133" title="Cross Reference: /frameworks/base/core/jni/android_view_InputChannel.cpp"><
>|cpp|
121 static jobjectArray android_view_InputChannel_nativeOpenInputChannelPair(JNIEnv* env,
122 jclass clazz, jstring nameObj) {
123 const char* nameChars = env->GetStringUTFChars(nameObj, NULL);
124 String8 name(nameChars);
125 env->ReleaseStringUTFChars(nameObj, nameChars);
126
127 sp<InputChannel> serverChannel;
128 sp<InputChannel> clientChannel;
129 status_t result = InputChannel::openInputChannelPair(name, serverChannel, clientChannel);
130
131 if (result) {
132 String8 message;
133 message.appendFormat("Could not open input channel pair. status=%d", result);
134 jniThrowRuntimeException(env, message.string());
135 return NULL;
136 }
137
138 jobjectArray channelPair = env->NewObjectArray(2, gInputChannelClassInfo.clazz, NULL);
139 if (env->ExceptionCheck()) {
140 return NULL;
141 }
142
143 jobject serverChannelObj = android_view_InputChannel_createInputChannel(env,
144 new NativeInputChannel(serverChannel));
145 if (env->ExceptionCheck()) {
146 return NULL;
147 }
148
149 jobject clientChannelObj = android_view_InputChannel_createInputChannel(env,
150 new NativeInputChannel(clientChannel));
151 if (env->ExceptionCheck()) {
152 return NULL;
153 }
154
155 env->SetObjectArrayElement(channelPair, 0, serverChannelObj);
156 env->SetObjectArrayElement(channelPair, 1, clientChannelObj);
157 return channelPair;
158 }
118 status_t InputChannel::openInputChannelPair(const String8& name,
119 sp<InputChannel>& outServerChannel, sp<InputChannel>& outClientChannel) {
120 int sockets[2];
121 if (socketpair(AF_UNIX, SOCK_SEQPACKET, 0, sockets)) {
122 status_t result = -errno;
123 ALOGE("channel '%s' ~ Could not create socket pair. errno=%d",
124 name.string(), errno);
125 outServerChannel.clear();
126 outClientChannel.clear();
127 return result;
128 }
129
130 int bufferSize = SOCKET_BUFFER_SIZE;
131 setsockopt(sockets[0], SOL_SOCKET, SO_SNDBUF, &bufferSize, sizeof(bufferSize));
132 setsockopt(sockets[0], SOL_SOCKET, SO_RCVBUF, &bufferSize, sizeof(bufferSize));
133 setsockopt(sockets[1], SOL_SOCKET, SO_SNDBUF, &bufferSize, sizeof(bufferSize));
134 setsockopt(sockets[1], SOL_SOCKET, SO_RCVBUF, &bufferSize, sizeof(bufferSize));
135
136 String8 serverChannelName = name;
137 serverChannelName.append(" (server)");
138 outServerChannel = new InputChannel(serverChannelName, sockets[0]);
139
140 String8 clientChannelName = name;
141 clientChannelName.append(" (client)");
142 outClientChannel = new InputChannel(clientChannelName, sockets[1]);
143 return OK;
144 }
1 #ifndef _ASM_GENERIC_ERRNO_BASE_H
2 #define _ASM_GENERIC_ERRNO_BASE_H
3
4 #define EPERM 1
5 #define ENOENT 2
6 #define ESRCH 3
7 #define EINTR 4
8 #define EIO 5
9 #define ENXIO 6
10 #define E2BIG 7
11 #define ENOEXEC 8
12 #define EBADF 9
13 #define ECHILD 10
14 #define EAGAIN 11
15 #define ENOMEM 12
16 #define EACCES 13
17 #define EFAULT 14
18 #define ENOTBLK 15
19 #define EBUSY 16
20 #define EEXIST 17
21 #define EXDEV 18
22 #define ENODEV 19
23 #define ENOTDIR 20
24 #define EISDIR 21
25 #define EINVAL 22
26 #define ENFILE 23
27 #define EMFILE 24
28 #define ENOTTY 25
29 #define ETXTBSY 26
30 #define EFBIG 27
31 #define ENOSPC 28
32 #define ESPIPE 29
33 #define EROFS 30
34 #define EMLINK 31
35 #define EPIPE 32
36 #define EDOM 33
37 #define ERANGE 34
38
39 #endif
40