Search in sources :

Example 1 with OnFileDescriptorEventListener

use of android.os.MessageQueue.OnFileDescriptorEventListener in project platform_frameworks_base by android.

the class ParcelFileDescriptor method fromFd.

/** {@hide} */
public static ParcelFileDescriptor fromFd(FileDescriptor fd, Handler handler, final OnCloseListener listener) throws IOException {
    if (handler == null) {
        throw new IllegalArgumentException("Handler must not be null");
    }
    if (listener == null) {
        throw new IllegalArgumentException("Listener must not be null");
    }
    final FileDescriptor[] comm = createCommSocketPair();
    final ParcelFileDescriptor pfd = new ParcelFileDescriptor(fd, comm[0]);
    final MessageQueue queue = handler.getLooper().getQueue();
    queue.addOnFileDescriptorEventListener(comm[1], OnFileDescriptorEventListener.EVENT_INPUT, new OnFileDescriptorEventListener() {

        @Override
        public int onFileDescriptorEvents(FileDescriptor fd, int events) {
            Status status = null;
            if ((events & OnFileDescriptorEventListener.EVENT_INPUT) != 0) {
                final byte[] buf = new byte[MAX_STATUS];
                status = readCommStatus(fd, buf);
            } else if ((events & OnFileDescriptorEventListener.EVENT_ERROR) != 0) {
                status = new Status(Status.DEAD);
            }
            if (status != null) {
                queue.removeOnFileDescriptorEventListener(fd);
                IoUtils.closeQuietly(fd);
                listener.onClose(status.asIOException());
                return 0;
            }
            return EVENT_INPUT;
        }
    });
    return pfd;
}
Also used : FileDescriptor(java.io.FileDescriptor) OnFileDescriptorEventListener(android.os.MessageQueue.OnFileDescriptorEventListener)

Example 2 with OnFileDescriptorEventListener

use of android.os.MessageQueue.OnFileDescriptorEventListener in project android_frameworks_base by ResurrectionRemix.

the class ParcelFileDescriptor method fromFd.

/** {@hide} */
public static ParcelFileDescriptor fromFd(FileDescriptor fd, Handler handler, final OnCloseListener listener) throws IOException {
    if (handler == null) {
        throw new IllegalArgumentException("Handler must not be null");
    }
    if (listener == null) {
        throw new IllegalArgumentException("Listener must not be null");
    }
    final FileDescriptor[] comm = createCommSocketPair();
    final ParcelFileDescriptor pfd = new ParcelFileDescriptor(fd, comm[0]);
    final MessageQueue queue = handler.getLooper().getQueue();
    queue.addOnFileDescriptorEventListener(comm[1], OnFileDescriptorEventListener.EVENT_INPUT, new OnFileDescriptorEventListener() {

        @Override
        public int onFileDescriptorEvents(FileDescriptor fd, int events) {
            Status status = null;
            if ((events & OnFileDescriptorEventListener.EVENT_INPUT) != 0) {
                final byte[] buf = new byte[MAX_STATUS];
                status = readCommStatus(fd, buf);
            } else if ((events & OnFileDescriptorEventListener.EVENT_ERROR) != 0) {
                status = new Status(Status.DEAD);
            }
            if (status != null) {
                queue.removeOnFileDescriptorEventListener(fd);
                IoUtils.closeQuietly(fd);
                listener.onClose(status.asIOException());
                return 0;
            }
            return EVENT_INPUT;
        }
    });
    return pfd;
}
Also used : FileDescriptor(java.io.FileDescriptor) OnFileDescriptorEventListener(android.os.MessageQueue.OnFileDescriptorEventListener)

Example 3 with OnFileDescriptorEventListener

use of android.os.MessageQueue.OnFileDescriptorEventListener in project android_frameworks_base by crdroidandroid.

the class ParcelFileDescriptor method fromFd.

/** {@hide} */
public static ParcelFileDescriptor fromFd(FileDescriptor fd, Handler handler, final OnCloseListener listener) throws IOException {
    if (handler == null) {
        throw new IllegalArgumentException("Handler must not be null");
    }
    if (listener == null) {
        throw new IllegalArgumentException("Listener must not be null");
    }
    final FileDescriptor[] comm = createCommSocketPair();
    final ParcelFileDescriptor pfd = new ParcelFileDescriptor(fd, comm[0]);
    final MessageQueue queue = handler.getLooper().getQueue();
    queue.addOnFileDescriptorEventListener(comm[1], OnFileDescriptorEventListener.EVENT_INPUT, new OnFileDescriptorEventListener() {

        @Override
        public int onFileDescriptorEvents(FileDescriptor fd, int events) {
            Status status = null;
            if ((events & OnFileDescriptorEventListener.EVENT_INPUT) != 0) {
                final byte[] buf = new byte[MAX_STATUS];
                status = readCommStatus(fd, buf);
            } else if ((events & OnFileDescriptorEventListener.EVENT_ERROR) != 0) {
                status = new Status(Status.DEAD);
            }
            if (status != null) {
                queue.removeOnFileDescriptorEventListener(fd);
                IoUtils.closeQuietly(fd);
                listener.onClose(status.asIOException());
                return 0;
            }
            return EVENT_INPUT;
        }
    });
    return pfd;
}
Also used : FileDescriptor(java.io.FileDescriptor) OnFileDescriptorEventListener(android.os.MessageQueue.OnFileDescriptorEventListener)

Example 4 with OnFileDescriptorEventListener

use of android.os.MessageQueue.OnFileDescriptorEventListener in project android_frameworks_base by AOSPA.

the class ParcelFileDescriptor method fromFd.

/** {@hide} */
public static ParcelFileDescriptor fromFd(FileDescriptor fd, Handler handler, final OnCloseListener listener) throws IOException {
    if (handler == null) {
        throw new IllegalArgumentException("Handler must not be null");
    }
    if (listener == null) {
        throw new IllegalArgumentException("Listener must not be null");
    }
    final FileDescriptor[] comm = createCommSocketPair();
    final ParcelFileDescriptor pfd = new ParcelFileDescriptor(fd, comm[0]);
    final MessageQueue queue = handler.getLooper().getQueue();
    queue.addOnFileDescriptorEventListener(comm[1], OnFileDescriptorEventListener.EVENT_INPUT, new OnFileDescriptorEventListener() {

        @Override
        public int onFileDescriptorEvents(FileDescriptor fd, int events) {
            Status status = null;
            if ((events & OnFileDescriptorEventListener.EVENT_INPUT) != 0) {
                final byte[] buf = new byte[MAX_STATUS];
                status = readCommStatus(fd, buf);
            } else if ((events & OnFileDescriptorEventListener.EVENT_ERROR) != 0) {
                status = new Status(Status.DEAD);
            }
            if (status != null) {
                queue.removeOnFileDescriptorEventListener(fd);
                IoUtils.closeQuietly(fd);
                listener.onClose(status.asIOException());
                return 0;
            }
            return EVENT_INPUT;
        }
    });
    return pfd;
}
Also used : FileDescriptor(java.io.FileDescriptor) OnFileDescriptorEventListener(android.os.MessageQueue.OnFileDescriptorEventListener)

Example 5 with OnFileDescriptorEventListener

use of android.os.MessageQueue.OnFileDescriptorEventListener in project android_frameworks_base by DirtyUnicorns.

the class ParcelFileDescriptor method fromFd.

/** {@hide} */
public static ParcelFileDescriptor fromFd(FileDescriptor fd, Handler handler, final OnCloseListener listener) throws IOException {
    if (handler == null) {
        throw new IllegalArgumentException("Handler must not be null");
    }
    if (listener == null) {
        throw new IllegalArgumentException("Listener must not be null");
    }
    final FileDescriptor[] comm = createCommSocketPair();
    final ParcelFileDescriptor pfd = new ParcelFileDescriptor(fd, comm[0]);
    final MessageQueue queue = handler.getLooper().getQueue();
    queue.addOnFileDescriptorEventListener(comm[1], OnFileDescriptorEventListener.EVENT_INPUT, new OnFileDescriptorEventListener() {

        @Override
        public int onFileDescriptorEvents(FileDescriptor fd, int events) {
            Status status = null;
            if ((events & OnFileDescriptorEventListener.EVENT_INPUT) != 0) {
                final byte[] buf = new byte[MAX_STATUS];
                status = readCommStatus(fd, buf);
            } else if ((events & OnFileDescriptorEventListener.EVENT_ERROR) != 0) {
                status = new Status(Status.DEAD);
            }
            if (status != null) {
                queue.removeOnFileDescriptorEventListener(fd);
                IoUtils.closeQuietly(fd);
                listener.onClose(status.asIOException());
                return 0;
            }
            return EVENT_INPUT;
        }
    });
    return pfd;
}
Also used : FileDescriptor(java.io.FileDescriptor) OnFileDescriptorEventListener(android.os.MessageQueue.OnFileDescriptorEventListener)

Aggregations

OnFileDescriptorEventListener (android.os.MessageQueue.OnFileDescriptorEventListener)5 FileDescriptor (java.io.FileDescriptor)5