use of java.io.FileDescriptor in project platform_frameworks_base by android.
the class BluetoothSocket method acceptSocket.
private BluetoothSocket acceptSocket(String RemoteAddr) throws IOException {
BluetoothSocket as = new BluetoothSocket(this);
as.mSocketState = SocketState.CONNECTED;
FileDescriptor[] fds = mSocket.getAncillaryFileDescriptors();
if (DBG)
Log.d(TAG, "socket fd passed by stack fds: " + Arrays.toString(fds));
if (fds == null || fds.length != 1) {
Log.e(TAG, "socket fd passed from stack failed, fds: " + Arrays.toString(fds));
as.close();
throw new IOException("bt socket acept failed");
}
as.mPfd = new ParcelFileDescriptor(fds[0]);
as.mSocket = LocalSocket.createConnectedLocalSocket(fds[0]);
as.mSocketIS = as.mSocket.getInputStream();
as.mSocketOS = as.mSocket.getOutputStream();
as.mAddress = RemoteAddr;
as.mDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(RemoteAddr);
return as;
}
use of java.io.FileDescriptor in project androidquery by androidquery.
the class BitmapAjaxCallback method decodeFile.
private static Bitmap decodeFile(String path, BitmapFactory.Options options, boolean rotate) {
Bitmap result = null;
if (options == null) {
options = new Options();
}
options.inInputShareable = isInputSharable();
options.inPurgeable = true;
FileInputStream fis = null;
try {
fis = new FileInputStream(path);
FileDescriptor fd = fis.getFD();
result = BitmapFactory.decodeFileDescriptor(fd, null, options);
if (result != null && rotate) {
result = rotate(path, result);
}
} catch (IOException e) {
AQUtility.report(e);
} finally {
AQUtility.close(fis);
}
return result;
}
use of java.io.FileDescriptor in project platform_frameworks_base by android.
the class NativeCrashListener method run.
@Override
public void run() {
final byte[] ackSignal = new byte[1];
if (DEBUG)
Slog.i(TAG, "Starting up");
// The file system entity for this socket is created with 0777 perms, owned
// by system:system. selinux restricts things so that only crash_dump can
// access it.
{
File socketFile = new File(DEBUGGERD_SOCKET_PATH);
if (socketFile.exists()) {
socketFile.delete();
}
}
try {
FileDescriptor serverFd = Os.socket(AF_UNIX, SOCK_STREAM, 0);
final UnixSocketAddress sockAddr = UnixSocketAddress.createFileSystem(DEBUGGERD_SOCKET_PATH);
Os.bind(serverFd, sockAddr);
Os.listen(serverFd, 1);
Os.chmod(DEBUGGERD_SOCKET_PATH, 0777);
while (true) {
FileDescriptor peerFd = null;
try {
if (MORE_DEBUG)
Slog.v(TAG, "Waiting for debuggerd connection");
peerFd = Os.accept(serverFd, null);
if (MORE_DEBUG)
Slog.v(TAG, "Got debuggerd socket " + peerFd);
if (peerFd != null) {
// the reporting thread may take responsibility for
// acking the debugger; make sure we play along.
consumeNativeCrashData(peerFd);
}
} catch (Exception e) {
Slog.w(TAG, "Error handling connection", e);
} finally {
// byte written is irrelevant.
if (peerFd != null) {
try {
Os.write(peerFd, ackSignal, 0, 1);
} catch (Exception e) {
/* we don't care about failures here */
if (MORE_DEBUG) {
Slog.d(TAG, "Exception writing ack: " + e.getMessage());
}
}
try {
Os.close(peerFd);
} catch (ErrnoException e) {
if (MORE_DEBUG) {
Slog.d(TAG, "Exception closing socket: " + e.getMessage());
}
}
}
}
}
} catch (Exception e) {
Slog.e(TAG, "Unable to init native debug socket!", e);
}
}
use of java.io.FileDescriptor in project platform_frameworks_base by android.
the class MediaPlayer method addTimedTextSource.
/* TODO: Limit the total number of external timed text source to a reasonable number.
*/
/**
* Adds an external timed text source file.
*
* Currently supported format is SubRip with the file extension .srt, case insensitive.
* Note that a single external timed text source may contain multiple tracks in it.
* One can find the total number of available tracks using {@link #getTrackInfo()} to see what
* additional tracks become available after this method call.
*
* @param path The file path of external timed text source file.
* @param mimeType The mime type of the file. Must be one of the mime types listed above.
* @throws IOException if the file cannot be accessed or is corrupted.
* @throws IllegalArgumentException if the mimeType is not supported.
* @throws IllegalStateException if called in an invalid state.
*/
public void addTimedTextSource(String path, String mimeType) throws IOException, IllegalArgumentException, IllegalStateException {
if (!availableMimeTypeForExternalSource(mimeType)) {
final String msg = "Illegal mimeType for timed text source: " + mimeType;
throw new IllegalArgumentException(msg);
}
File file = new File(path);
if (file.exists()) {
FileInputStream is = new FileInputStream(file);
FileDescriptor fd = is.getFD();
addTimedTextSource(fd, mimeType);
is.close();
} else {
// We do not support the case where the path is not a file.
throw new IOException(path);
}
}
use of java.io.FileDescriptor in project platform_frameworks_base by android.
the class DrmManagerClient method getOriginalMimeType.
/**
* Retrieves the MIME type embedded in the original content.
*
* @param path Path to the rights-protected content.
*
* @return The MIME type of the original content, such as <code>video/mpeg</code>.
*/
public String getOriginalMimeType(String path) {
if (null == path || path.equals("")) {
throw new IllegalArgumentException("Given path should be non null");
}
String mime = null;
FileInputStream is = null;
try {
FileDescriptor fd = null;
File file = new File(path);
if (file.exists()) {
is = new FileInputStream(file);
fd = is.getFD();
}
mime = _getOriginalMimeType(mUniqueId, path, fd);
} catch (IOException ioe) {
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
}
}
}
return mime;
}
Aggregations