Search in sources :

Example 96 with Uri

use of android.net.Uri in project android_frameworks_base by ParanoidAndroid.

the class MediaInserter method flushAllPriority.

private void flushAllPriority() throws RemoteException {
    for (Uri tableUri : mPriorityRowMap.keySet()) {
        List<ContentValues> list = mPriorityRowMap.get(tableUri);
        flush(tableUri, list);
    }
    mPriorityRowMap.clear();
}
Also used : ContentValues(android.content.ContentValues) Uri(android.net.Uri)

Example 97 with Uri

use of android.net.Uri in project android_frameworks_base by ParanoidAndroid.

the class MediaPlayer method setDataSource.

private void setDataSource(String path, String[] keys, String[] values) throws IOException, IllegalArgumentException, SecurityException, IllegalStateException {
    disableProxyListener();
    final Uri uri = Uri.parse(path);
    if ("file".equals(uri.getScheme())) {
        path = uri.getPath();
    }
    final File file = new File(path);
    if (file.exists()) {
        FileInputStream is = new FileInputStream(file);
        FileDescriptor fd = is.getFD();
        setDataSource(fd);
        is.close();
    } else {
        _setDataSource(path, keys, values);
    }
}
Also used : Uri(android.net.Uri) File(java.io.File) FileInputStream(java.io.FileInputStream) AssetFileDescriptor(android.content.res.AssetFileDescriptor) ParcelFileDescriptor(android.os.ParcelFileDescriptor) FileDescriptor(java.io.FileDescriptor)

Example 98 with Uri

use of android.net.Uri in project android_frameworks_base by ParanoidAndroid.

the class MtpDatabase method beginSendObject.

private int beginSendObject(String path, int format, int parent, int storageId, long size, long modified) {
    // if mSubDirectories is not null, do not allow copying files to any other locations
    if (!inStorageSubDirectory(path))
        return -1;
    // make sure the object does not exist
    if (path != null) {
        Cursor c = null;
        try {
            c = mMediaProvider.query(mPackageName, mObjectsUri, ID_PROJECTION, PATH_WHERE, new String[] { path }, null, null);
            if (c != null && c.getCount() > 0) {
                Log.w(TAG, "file already exists in beginSendObject: " + path);
                return -1;
            }
        } catch (RemoteException e) {
            Log.e(TAG, "RemoteException in beginSendObject", e);
        } finally {
            if (c != null) {
                c.close();
            }
        }
    }
    mDatabaseModified = true;
    ContentValues values = new ContentValues();
    values.put(Files.FileColumns.DATA, path);
    values.put(Files.FileColumns.FORMAT, format);
    values.put(Files.FileColumns.PARENT, parent);
    values.put(Files.FileColumns.STORAGE_ID, storageId);
    values.put(Files.FileColumns.SIZE, size);
    values.put(Files.FileColumns.DATE_MODIFIED, modified);
    try {
        Uri uri = mMediaProvider.insert(mPackageName, mObjectsUri, values);
        if (uri != null) {
            return Integer.parseInt(uri.getPathSegments().get(2));
        } else {
            return -1;
        }
    } catch (RemoteException e) {
        Log.e(TAG, "RemoteException in beginSendObject", e);
        return -1;
    }
}
Also used : ContentValues(android.content.ContentValues) Cursor(android.database.Cursor) RemoteException(android.os.RemoteException) Uri(android.net.Uri)

Example 99 with Uri

use of android.net.Uri in project android_frameworks_base by ParanoidAndroid.

the class MtpDatabase method setObjectReferences.

private int setObjectReferences(int handle, int[] references) {
    mDatabaseModified = true;
    Uri uri = Files.getMtpReferencesUri(mVolumeName, handle);
    int count = references.length;
    ContentValues[] valuesList = new ContentValues[count];
    for (int i = 0; i < count; i++) {
        ContentValues values = new ContentValues();
        values.put(Files.FileColumns._ID, references[i]);
        valuesList[i] = values;
    }
    try {
        if (mMediaProvider.bulkInsert(mPackageName, uri, valuesList) > 0) {
            return MtpConstants.RESPONSE_OK;
        }
    } catch (RemoteException e) {
        Log.e(TAG, "RemoteException in setObjectReferences", e);
    }
    return MtpConstants.RESPONSE_GENERAL_ERROR;
}
Also used : ContentValues(android.content.ContentValues) RemoteException(android.os.RemoteException) Uri(android.net.Uri)

Example 100 with Uri

use of android.net.Uri in project android_frameworks_base by ParanoidAndroid.

the class MtpDatabase method deleteFile.

private int deleteFile(int handle) {
    mDatabaseModified = true;
    String path = null;
    int format = 0;
    Cursor c = null;
    try {
        c = mMediaProvider.query(mPackageName, mObjectsUri, PATH_FORMAT_PROJECTION, ID_WHERE, new String[] { Integer.toString(handle) }, null, null);
        if (c != null && c.moveToNext()) {
            // don't convert to media path here, since we will be matching
            // against paths in the database matching /data/media
            path = c.getString(1);
            format = c.getInt(2);
        } else {
            return MtpConstants.RESPONSE_INVALID_OBJECT_HANDLE;
        }
        if (path == null || format == 0) {
            return MtpConstants.RESPONSE_GENERAL_ERROR;
        }
        // do not allow deleting any of the special subdirectories
        if (isStorageSubDirectory(path)) {
            return MtpConstants.RESPONSE_OBJECT_WRITE_PROTECTED;
        }
        if (format == MtpConstants.FORMAT_ASSOCIATION) {
            // recursive case - delete all children first
            Uri uri = Files.getMtpObjectsUri(mVolumeName);
            int count = mMediaProvider.delete(mPackageName, uri, // when the path contains sqlite wildcard characters
            "_data LIKE ?1 AND lower(substr(_data,1,?2))=lower(?3)", new String[] { path + "/%", Integer.toString(path.length() + 1), path + "/" });
        }
        Uri uri = Files.getMtpObjectsUri(mVolumeName, handle);
        if (mMediaProvider.delete(mPackageName, uri, null, null) > 0) {
            if (format != MtpConstants.FORMAT_ASSOCIATION && path.toLowerCase(Locale.US).endsWith("/.nomedia")) {
                try {
                    String parentPath = path.substring(0, path.lastIndexOf("/"));
                    mMediaProvider.call(mPackageName, MediaStore.UNHIDE_CALL, parentPath, null);
                } catch (RemoteException e) {
                    Log.e(TAG, "failed to unhide/rescan for " + path);
                }
            }
            return MtpConstants.RESPONSE_OK;
        } else {
            return MtpConstants.RESPONSE_INVALID_OBJECT_HANDLE;
        }
    } catch (RemoteException e) {
        Log.e(TAG, "RemoteException in deleteFile", e);
        return MtpConstants.RESPONSE_GENERAL_ERROR;
    } finally {
        if (c != null) {
            c.close();
        }
    }
}
Also used : Cursor(android.database.Cursor) RemoteException(android.os.RemoteException) Uri(android.net.Uri)

Aggregations

Uri (android.net.Uri)3223 Intent (android.content.Intent)682 Cursor (android.database.Cursor)455 File (java.io.File)311 ContentValues (android.content.ContentValues)282 IOException (java.io.IOException)239 ContentResolver (android.content.ContentResolver)236 ArrayList (java.util.ArrayList)197 Test (org.junit.Test)192 RemoteException (android.os.RemoteException)190 Bundle (android.os.Bundle)147 Bitmap (android.graphics.Bitmap)121 Context (android.content.Context)115 InputStream (java.io.InputStream)102 PendingIntent (android.app.PendingIntent)101 LargeTest (android.test.suitebuilder.annotation.LargeTest)97 FileNotFoundException (java.io.FileNotFoundException)91 View (android.view.View)89 Request (android.app.DownloadManager.Request)83 HashMap (java.util.HashMap)69