use of java.io.FileDescriptor in project XobotOS by xamarin.
the class MemoryMappedFile method mmapRO.
/**
* Use this to mmap the whole file read-only.
*/
public static MemoryMappedFile mmapRO(String path) throws ErrnoException {
FileDescriptor fd = Libcore.os.open(path, O_RDONLY, 0);
long size = Libcore.os.fstat(fd).st_size;
long address = Libcore.os.mmap(0L, size, PROT_READ, MAP_SHARED, fd, 0);
Libcore.os.close(fd);
return new MemoryMappedFile(address, size);
}
use of java.io.FileDescriptor in project XobotOS by xamarin.
the class IInputMethodWrapper method executeMessage.
public void executeMessage(Message msg) {
InputMethod inputMethod = mInputMethod.get();
// Need a valid reference to the inputMethod for everything except a dump.
if (inputMethod == null && msg.what != DO_DUMP) {
Log.w(TAG, "Input method reference was null, ignoring message: " + msg.what);
return;
}
switch(msg.what) {
case DO_DUMP:
{
AbstractInputMethodService target = mTarget.get();
if (target == null) {
return;
}
HandlerCaller.SomeArgs args = (HandlerCaller.SomeArgs) msg.obj;
try {
target.dump((FileDescriptor) args.arg1, (PrintWriter) args.arg2, (String[]) args.arg3);
} catch (RuntimeException e) {
((PrintWriter) args.arg2).println("Exception: " + e);
}
synchronized (args.arg4) {
((CountDownLatch) args.arg4).countDown();
}
return;
}
case DO_ATTACH_TOKEN:
{
inputMethod.attachToken((IBinder) msg.obj);
return;
}
case DO_SET_INPUT_CONTEXT:
{
inputMethod.bindInput((InputBinding) msg.obj);
return;
}
case DO_UNSET_INPUT_CONTEXT:
inputMethod.unbindInput();
return;
case DO_START_INPUT:
{
HandlerCaller.SomeArgs args = (HandlerCaller.SomeArgs) msg.obj;
IInputContext inputContext = (IInputContext) args.arg1;
InputConnection ic = inputContext != null ? new InputConnectionWrapper(inputContext) : null;
EditorInfo info = (EditorInfo) args.arg2;
info.makeCompatible(mTargetSdkVersion);
inputMethod.startInput(ic, info);
return;
}
case DO_RESTART_INPUT:
{
HandlerCaller.SomeArgs args = (HandlerCaller.SomeArgs) msg.obj;
IInputContext inputContext = (IInputContext) args.arg1;
InputConnection ic = inputContext != null ? new InputConnectionWrapper(inputContext) : null;
EditorInfo info = (EditorInfo) args.arg2;
info.makeCompatible(mTargetSdkVersion);
inputMethod.restartInput(ic, info);
return;
}
case DO_CREATE_SESSION:
{
inputMethod.createSession(new InputMethodSessionCallbackWrapper(mCaller.mContext, (IInputMethodCallback) msg.obj));
return;
}
case DO_SET_SESSION_ENABLED:
inputMethod.setSessionEnabled((InputMethodSession) msg.obj, msg.arg1 != 0);
return;
case DO_REVOKE_SESSION:
inputMethod.revokeSession((InputMethodSession) msg.obj);
return;
case DO_SHOW_SOFT_INPUT:
inputMethod.showSoftInput(msg.arg1, (ResultReceiver) msg.obj);
return;
case DO_HIDE_SOFT_INPUT:
inputMethod.hideSoftInput(msg.arg1, (ResultReceiver) msg.obj);
return;
case DO_CHANGE_INPUTMETHOD_SUBTYPE:
inputMethod.changeInputMethodSubtype((InputMethodSubtype) msg.obj);
return;
}
Log.w(TAG, "Unhandled message code: " + msg.what);
}
use of java.io.FileDescriptor in project platform_frameworks_base by android.
the class IInputMethodWrapper method executeMessage.
@Override
public void executeMessage(Message msg) {
InputMethod inputMethod = mInputMethod.get();
// Need a valid reference to the inputMethod for everything except a dump.
if (inputMethod == null && msg.what != DO_DUMP) {
Log.w(TAG, "Input method reference was null, ignoring message: " + msg.what);
return;
}
switch(msg.what) {
case DO_DUMP:
{
AbstractInputMethodService target = mTarget.get();
if (target == null) {
return;
}
SomeArgs args = (SomeArgs) msg.obj;
try {
target.dump((FileDescriptor) args.arg1, (PrintWriter) args.arg2, (String[]) args.arg3);
} catch (RuntimeException e) {
((PrintWriter) args.arg2).println("Exception: " + e);
}
synchronized (args.arg4) {
((CountDownLatch) args.arg4).countDown();
}
args.recycle();
return;
}
case DO_ATTACH_TOKEN:
{
inputMethod.attachToken((IBinder) msg.obj);
return;
}
case DO_SET_INPUT_CONTEXT:
{
inputMethod.bindInput((InputBinding) msg.obj);
return;
}
case DO_UNSET_INPUT_CONTEXT:
inputMethod.unbindInput();
return;
case DO_START_INPUT:
{
SomeArgs args = (SomeArgs) msg.obj;
int missingMethods = msg.arg1;
IInputContext inputContext = (IInputContext) args.arg1;
InputConnection ic = inputContext != null ? new InputConnectionWrapper(mTarget, inputContext, missingMethods) : null;
EditorInfo info = (EditorInfo) args.arg2;
info.makeCompatible(mTargetSdkVersion);
inputMethod.startInput(ic, info);
args.recycle();
return;
}
case DO_RESTART_INPUT:
{
SomeArgs args = (SomeArgs) msg.obj;
int missingMethods = msg.arg1;
IInputContext inputContext = (IInputContext) args.arg1;
InputConnection ic = inputContext != null ? new InputConnectionWrapper(mTarget, inputContext, missingMethods) : null;
EditorInfo info = (EditorInfo) args.arg2;
info.makeCompatible(mTargetSdkVersion);
inputMethod.restartInput(ic, info);
args.recycle();
return;
}
case DO_CREATE_SESSION:
{
SomeArgs args = (SomeArgs) msg.obj;
inputMethod.createSession(new InputMethodSessionCallbackWrapper(mContext, (InputChannel) args.arg1, (IInputSessionCallback) args.arg2));
args.recycle();
return;
}
case DO_SET_SESSION_ENABLED:
inputMethod.setSessionEnabled((InputMethodSession) msg.obj, msg.arg1 != 0);
return;
case DO_REVOKE_SESSION:
inputMethod.revokeSession((InputMethodSession) msg.obj);
return;
case DO_SHOW_SOFT_INPUT:
inputMethod.showSoftInput(msg.arg1, (ResultReceiver) msg.obj);
return;
case DO_HIDE_SOFT_INPUT:
inputMethod.hideSoftInput(msg.arg1, (ResultReceiver) msg.obj);
return;
case DO_CHANGE_INPUTMETHOD_SUBTYPE:
inputMethod.changeInputMethodSubtype((InputMethodSubtype) msg.obj);
return;
}
Log.w(TAG, "Unhandled message code: " + msg.what);
}
use of java.io.FileDescriptor in project platform_frameworks_base by android.
the class ParcelFileDescriptor method fromData.
/**
* @hide Please use createPipe() or ContentProvider.openPipeHelper().
* Gets a file descriptor for a read-only copy of the given data.
*
* @param data Data to copy.
* @param name Name for the shared memory area that may back the file descriptor.
* This is purely informative and may be {@code null}.
* @return A ParcelFileDescriptor.
* @throws IOException if there is an error while creating the shared memory area.
*/
@Deprecated
public static ParcelFileDescriptor fromData(byte[] data, String name) throws IOException {
if (data == null)
return null;
MemoryFile file = new MemoryFile(name, data.length);
if (data.length > 0) {
file.writeBytes(data, 0, 0, data.length);
}
file.deactivate();
FileDescriptor fd = file.getFileDescriptor();
return fd != null ? new ParcelFileDescriptor(fd) : null;
}
use of java.io.FileDescriptor in project platform_frameworks_base by android.
the class ParcelFileDescriptor method adoptFd.
/**
* Take ownership of a raw native fd in to a new ParcelFileDescriptor.
* The returned ParcelFileDescriptor now owns the given fd, and will be
* responsible for closing it. You must not close the fd yourself.
*
* @param fd The native fd that the ParcelFileDescriptor should adopt.
*
* @return Returns a new ParcelFileDescriptor holding a FileDescriptor
* for the given fd.
*/
public static ParcelFileDescriptor adoptFd(int fd) {
final FileDescriptor fdesc = new FileDescriptor();
fdesc.setInt$(fd);
return new ParcelFileDescriptor(fdesc);
}
Aggregations