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);
}
}
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;
}
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();
}
}
}
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;
}
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;
}
}
Aggregations