Search in sources :

Example 76 with Uri

use of android.net.Uri in project platform_frameworks_base by android.

the class MtpDatabase method endSendObject.

private void endSendObject(String path, int handle, int format, boolean succeeded) {
    if (succeeded) {
        // they do not exist in the file system so don't use the media scanner here
        if (format == MtpConstants.FORMAT_ABSTRACT_AV_PLAYLIST) {
            // extract name from path
            String name = path;
            int lastSlash = name.lastIndexOf('/');
            if (lastSlash >= 0) {
                name = name.substring(lastSlash + 1);
            }
            // strip trailing ".pla" from the name
            if (name.endsWith(".pla")) {
                name = name.substring(0, name.length() - 4);
            }
            ContentValues values = new ContentValues(1);
            values.put(Audio.Playlists.DATA, path);
            values.put(Audio.Playlists.NAME, name);
            values.put(Files.FileColumns.FORMAT, format);
            values.put(Files.FileColumns.DATE_MODIFIED, System.currentTimeMillis() / 1000);
            values.put(MediaColumns.MEDIA_SCANNER_NEW_OBJECT_ID, handle);
            try {
                Uri uri = mMediaProvider.insert(Audio.Playlists.EXTERNAL_CONTENT_URI, values);
            } catch (RemoteException e) {
                Log.e(TAG, "RemoteException in endSendObject", e);
            }
        } else {
            mMediaScanner.scanMtpFile(path, handle, format);
        }
    } else {
        deleteFile(handle);
    }
}
Also used : ContentValues(android.content.ContentValues) RemoteException(android.os.RemoteException) Uri(android.net.Uri)

Example 77 with Uri

use of android.net.Uri in project platform_frameworks_base by android.

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(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 78 with Uri

use of android.net.Uri in project platform_frameworks_base by android.

the class MtpPropertyGroup method queryGenre.

private String queryGenre(int id) {
    Cursor c = null;
    try {
        Uri uri = Audio.Genres.getContentUriForAudioId(mVolumeName, id);
        c = mProvider.query(uri, new String[] { Files.FileColumns._ID, Audio.GenresColumns.NAME }, null, null, null, null);
        if (c != null && c.moveToNext()) {
            return c.getString(1);
        } else {
            return "";
        }
    } catch (Exception e) {
        Log.e(TAG, "queryGenre exception", e);
        return null;
    } finally {
        if (c != null) {
            c.close();
        }
    }
}
Also used : Cursor(android.database.Cursor) Uri(android.net.Uri) RemoteException(android.os.RemoteException)

Example 79 with Uri

use of android.net.Uri in project platform_frameworks_base by android.

the class MtpDatabase method getObjectReferences.

private int[] getObjectReferences(int handle) {
    Uri uri = Files.getMtpReferencesUri(mVolumeName, handle);
    Cursor c = null;
    try {
        c = mMediaProvider.query(uri, ID_PROJECTION, null, null, null, null);
        if (c == null) {
            return null;
        }
        int count = c.getCount();
        if (count > 0) {
            int[] result = new int[count];
            for (int i = 0; i < count; i++) {
                c.moveToNext();
                result[i] = c.getInt(0);
            }
            return result;
        }
    } catch (RemoteException e) {
        Log.e(TAG, "RemoteException in getObjectList", e);
    } finally {
        if (c != null) {
            c.close();
        }
    }
    return null;
}
Also used : Cursor(android.database.Cursor) RemoteException(android.os.RemoteException) Uri(android.net.Uri)

Example 80 with Uri

use of android.net.Uri in project platform_frameworks_base by android.

the class TestDocumentsProvider method queryChildDocuments.

@Override
public Cursor queryChildDocuments(String parentDocumentId, String[] projection, String sortOrder) throws FileNotFoundException {
    if (LAG)
        lagUntilCanceled(null);
    if (CHILD_WEDGE)
        SystemClock.sleep(Integer.MAX_VALUE);
    if (CHILD_CRASH)
        System.exit(12);
    final ContentResolver resolver = getContext().getContentResolver();
    final Uri notifyUri = DocumentsContract.buildDocumentUri("com.example.documents", parentDocumentId);
    CloudCursor result = new CloudCursor(resolveDocumentProjection(projection));
    result.setNotificationUri(resolver, notifyUri);
    // Always include local results
    includeFile(result, MY_DOC_NULL, 0);
    includeFile(result, "localfile1", 0);
    includeFile(result, "localfile2", Document.FLAG_SUPPORTS_THUMBNAIL);
    includeFile(result, "localfile3", 0);
    includeFile(result, "localfile4", 0);
    if (THUMB_HUNDREDS) {
        for (int i = 0; i < 256; i++) {
            includeFile(result, "i maded u an picshure" + i, Document.FLAG_SUPPORTS_THUMBNAIL);
        }
    }
    synchronized (this) {
        // Try picking up an existing network fetch
        CloudTask task = mTask != null ? mTask.get() : null;
        if (task == null) {
            Log.d(TAG, "No network task found; starting!");
            task = new CloudTask(resolver, notifyUri);
            mTask = new WeakReference<CloudTask>(task);
            new Thread(task).start();
            // Aggressively try freeing weak reference above
            new Thread() {

                @Override
                public void run() {
                    while (mTask.get() != null) {
                        SystemClock.sleep(200);
                        System.gc();
                        System.runFinalization();
                    }
                    Log.d(TAG, "AHA! THE CLOUD TASK WAS GC'ED!");
                }
            }.start();
        }
        // Blend in cloud results if ready
        if (task.includeIfFinished(result)) {
            result.extras.putString(DocumentsContract.EXTRA_INFO, "Everything Went Better Than Expected and this message is quite " + "long and verbose and maybe even too long");
            result.extras.putString(DocumentsContract.EXTRA_ERROR, "But then again, maybe our server ran into an error, which means " + "we're going to have a bad time");
        } else {
            result.extras.putBoolean(DocumentsContract.EXTRA_LOADING, true);
        }
        // Tie the network fetch to the cursor GC lifetime
        result.keepAlive = task;
        return result;
    }
}
Also used : Uri(android.net.Uri) Point(android.graphics.Point) Paint(android.graphics.Paint) ContentResolver(android.content.ContentResolver)

Aggregations

Uri (android.net.Uri)3406 Intent (android.content.Intent)732 Cursor (android.database.Cursor)466 ContentValues (android.content.ContentValues)349 File (java.io.File)339 IOException (java.io.IOException)254 ContentResolver (android.content.ContentResolver)242 ArrayList (java.util.ArrayList)209 Test (org.junit.Test)194 RemoteException (android.os.RemoteException)190 Bundle (android.os.Bundle)154 Bitmap (android.graphics.Bitmap)129 Context (android.content.Context)118 InputStream (java.io.InputStream)110 PendingIntent (android.app.PendingIntent)104 LargeTest (android.test.suitebuilder.annotation.LargeTest)97 View (android.view.View)95 FileNotFoundException (java.io.FileNotFoundException)94 Request (android.app.DownloadManager.Request)83 TextView (android.widget.TextView)73