Search in sources :

Example 66 with ParcelFileDescriptor

use of android.os.ParcelFileDescriptor in project XobotOS by xamarin.

the class BluetoothHealthProfileHandler method onHealthDeviceChannelChanged.

/*package*/
void onHealthDeviceChannelChanged(String devicePath, String channelPath, boolean exists) {
    debugLog("onHealthDeviceChannelChanged: devicePath: " + devicePath + "ChannelPath: " + channelPath + "Exists: " + exists);
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    String address = mBluetoothService.getAddressFromObjectPath(devicePath);
    if (address == null)
        return;
    BluetoothDevice device = adapter.getRemoteDevice(address);
    BluetoothHealthAppConfiguration config;
    int state, prevState = BluetoothHealth.STATE_CHANNEL_DISCONNECTED;
    ParcelFileDescriptor fd;
    HealthChannel channel;
    config = findHealthApplication(device, channelPath);
    if (exists) {
        channel = findConnectingChannel(device, config);
        if (channel == null) {
            channel = new HealthChannel(device, config, null, false, channelPath);
            channel.mState = BluetoothHealth.STATE_CHANNEL_DISCONNECTED;
            mHealthChannels.add(channel);
        }
        channel.mChannelPath = channelPath;
        fd = mBluetoothService.getChannelFdNative(channelPath);
        if (fd == null) {
            errorLog("Error obtaining fd for channel:" + channelPath);
            disconnectChannel(device, config, channel.mId);
            return;
        }
        boolean mainChannel = getMainChannel(device, config) == null ? false : true;
        if (!mainChannel) {
            String mainChannelPath = mBluetoothService.getMainChannelNative(devicePath);
            if (mainChannelPath == null) {
                errorLog("Main Channel Path is null for devicePath:" + devicePath);
                return;
            }
            if (mainChannelPath.equals(channelPath))
                mainChannel = true;
        }
        channel.mChannelFd = fd;
        channel.mMainChannel = mainChannel;
        prevState = channel.mState;
        state = BluetoothHealth.STATE_CHANNEL_CONNECTED;
    } else {
        channel = findChannelByPath(device, channelPath);
        if (channel == null) {
            errorLog("Channel not found:" + config + ":" + channelPath);
            return;
        }
        mHealthChannels.remove(channel);
        channel.mChannelFd = null;
        prevState = channel.mState;
        state = BluetoothHealth.STATE_CHANNEL_DISCONNECTED;
    }
    channel.mState = state;
    callHealthChannelCallback(config, device, prevState, state, channel.mChannelFd, channel.mId);
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) ParcelFileDescriptor(android.os.ParcelFileDescriptor) BluetoothAdapter(android.bluetooth.BluetoothAdapter) BluetoothHealthAppConfiguration(android.bluetooth.BluetoothHealthAppConfiguration)

Example 67 with ParcelFileDescriptor

use of android.os.ParcelFileDescriptor in project XobotOS by xamarin.

the class SoundPool method load.

/**
     * Load the sound from the specified path.
     *
     * @param path the path to the audio file
     * @param priority the priority of the sound. Currently has no effect. Use
     *                 a value of 1 for future compatibility.
     * @return a sound ID. This value can be used to play or unload the sound.
     */
public int load(String path, int priority) {
    // pass network streams to player
    if (path.startsWith("http:"))
        return _load(path, priority);
    // try local path
    int id = 0;
    try {
        File f = new File(path);
        if (f != null) {
            ParcelFileDescriptor fd = ParcelFileDescriptor.open(f, ParcelFileDescriptor.MODE_READ_ONLY);
            if (fd != null) {
                id = _load(fd.getFileDescriptor(), 0, f.length(), priority);
                fd.close();
            }
        }
    } catch (java.io.IOException e) {
        Log.e(TAG, "error loading " + path);
    }
    return id;
}
Also used : ParcelFileDescriptor(android.os.ParcelFileDescriptor) IOException(java.io.IOException) File(java.io.File)

Example 68 with ParcelFileDescriptor

use of android.os.ParcelFileDescriptor in project platform_frameworks_base by android.

the class SerialManager method openSerialPort.

/**
     * Opens and returns the {@link android.hardware.SerialPort} with the given name.
     * The speed of the serial port must be one of:
     * 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600,
     * 19200, 38400, 57600, 115200, 230400, 460800, 500000, 576000, 921600, 1000000, 1152000,
     * 1500000, 2000000, 2500000, 3000000, 3500000 or 4000000
     *
     * @param name of the serial port
     * @param speed at which to open the serial port
     * @return the serial port
     */
public SerialPort openSerialPort(String name, int speed) throws IOException {
    try {
        ParcelFileDescriptor pfd = mService.openSerialPort(name);
        if (pfd != null) {
            SerialPort port = new SerialPort(name);
            port.open(pfd, speed);
            return port;
        } else {
            throw new IOException("Could not open serial port " + name);
        }
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}
Also used : ParcelFileDescriptor(android.os.ParcelFileDescriptor) IOException(java.io.IOException) RemoteException(android.os.RemoteException)

Example 69 with ParcelFileDescriptor

use of android.os.ParcelFileDescriptor in project platform_frameworks_base by android.

the class DocumentsProvider method openAssetFile.

/**
     * Implementation is provided by the parent class. Cannot be overriden.
     *
     * @see #openDocument(String, String, CancellationSignal)
     */
@Override
@SuppressWarnings("resource")
public final AssetFileDescriptor openAssetFile(Uri uri, String mode) throws FileNotFoundException {
    enforceTree(uri);
    final ParcelFileDescriptor fd = openDocument(getDocumentId(uri), mode, null);
    return fd != null ? new AssetFileDescriptor(fd, 0, -1) : null;
}
Also used : AssetFileDescriptor(android.content.res.AssetFileDescriptor) ParcelFileDescriptor(android.os.ParcelFileDescriptor)

Example 70 with ParcelFileDescriptor

use of android.os.ParcelFileDescriptor in project platform_frameworks_base by android.

the class DocumentsContract method openImageThumbnail.

/**
     * Open the given image for thumbnail purposes, using any embedded EXIF
     * thumbnail if available, and providing orientation hints from the parent
     * image.
     *
     * @hide
     */
public static AssetFileDescriptor openImageThumbnail(File file) throws FileNotFoundException {
    final ParcelFileDescriptor pfd = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
    Bundle extras = null;
    try {
        final ExifInterface exif = new ExifInterface(file.getAbsolutePath());
        switch(exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1)) {
            case ExifInterface.ORIENTATION_ROTATE_90:
                extras = new Bundle(1);
                extras.putInt(EXTRA_ORIENTATION, 90);
                break;
            case ExifInterface.ORIENTATION_ROTATE_180:
                extras = new Bundle(1);
                extras.putInt(EXTRA_ORIENTATION, 180);
                break;
            case ExifInterface.ORIENTATION_ROTATE_270:
                extras = new Bundle(1);
                extras.putInt(EXTRA_ORIENTATION, 270);
                break;
        }
        final long[] thumb = exif.getThumbnailRange();
        if (thumb != null) {
            return new AssetFileDescriptor(pfd, thumb[0], thumb[1], extras);
        }
    } catch (IOException e) {
    }
    return new AssetFileDescriptor(pfd, 0, AssetFileDescriptor.UNKNOWN_LENGTH, extras);
}
Also used : AssetFileDescriptor(android.content.res.AssetFileDescriptor) Bundle(android.os.Bundle) ExifInterface(android.media.ExifInterface) ParcelFileDescriptor(android.os.ParcelFileDescriptor) IOException(java.io.IOException)

Aggregations

ParcelFileDescriptor (android.os.ParcelFileDescriptor)526 IOException (java.io.IOException)199 FileNotFoundException (java.io.FileNotFoundException)136 RemoteException (android.os.RemoteException)127 File (java.io.File)127 FileDescriptor (java.io.FileDescriptor)58 FileOutputStream (java.io.FileOutputStream)58 AssetFileDescriptor (android.content.res.AssetFileDescriptor)44 FileInputStream (java.io.FileInputStream)36 Parcel (android.os.Parcel)35 Uri (android.net.Uri)33 Intent (android.content.Intent)30 Bundle (android.os.Bundle)29 Cursor (android.database.Cursor)27 StorageManager (android.os.storage.StorageManager)25 Request (android.app.DownloadManager.Request)24 Bitmap (android.graphics.Bitmap)22 InputStream (java.io.InputStream)18 ProfilerInfo (android.app.ProfilerInfo)17 Binder (android.os.Binder)17