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