MCPcopy Create free account
hub / github.com/golang/mobile / runInputQueue

Function runInputQueue

app/android.go:352–387  ·  view source on GitHub ↗
(vm, jniEnv, ctx uintptr)

Source from the content-addressed store, hash-verified

350}
351
352func runInputQueue(vm, jniEnv, ctx uintptr) error {
353 env := (*C.JNIEnv)(unsafe.Pointer(jniEnv)) // not a Go heap pointer
354
355 // Android loopers select on OS file descriptors, not Go channels, so we
356 // translate the inputQueue channel to an ALooper_wake call.
357 l := C.ALooper_prepare(C.ALOOPER_PREPARE_ALLOW_NON_CALLBACKS)
358 pending := make(chan *C.AInputQueue, 1)
359 go func() {
360 for q := range inputQueue {
361 pending <- q
362 C.ALooper_wake(l)
363 }
364 }()
365
366 var q *C.AInputQueue
367 for {
368 if C.ALooper_pollOnce(-1, nil, nil, nil) == C.ALOOPER_POLL_WAKE {
369 select {
370 default:
371 case p := <-pending:
372 if q != nil {
373 processEvents(env, q)
374 C.AInputQueue_detachLooper(q)
375 }
376 q = p
377 if q != nil {
378 C.AInputQueue_attachLooper(q, l, 0, nil, nil)
379 }
380 inputQueueDone <- struct{}{}
381 }
382 }
383 if q != nil {
384 processEvents(env, q)
385 }
386 }
387}
388
389func processEvents(env *C.JNIEnv, q *C.AInputQueue) {
390 var e *C.AInputEvent

Callers

nothing calls this directly

Calls 1

processEventsFunction · 0.85

Tested by

no test coverage detected