use of com.android.documentsui.model.DocumentInfo in project android_frameworks_base by ResurrectionRemix.
the class CreateDirectoryFragment method createDirectory.
private void createDirectory(String name) {
final BaseActivity activity = (BaseActivity) getActivity();
final DocumentInfo cwd = activity.getCurrentDirectory();
new CreateDirectoryTask(activity, cwd, name).executeOnExecutor(ProviderExecutor.forAuthority(cwd.authority));
}
use of com.android.documentsui.model.DocumentInfo in project android_frameworks_base by ResurrectionRemix.
the class CopyJob method byteCopyDocument.
void byteCopyDocument(DocumentInfo src, DocumentInfo dest) throws ResourceException {
final String dstMimeType;
final String dstDisplayName;
if (DEBUG)
Log.d(TAG, "Doing byte copy of document: " + src);
// as such format. Also, append an extension for the target mime type (if known).
if (src.isVirtualDocument()) {
String[] streamTypes = null;
try {
streamTypes = getContentResolver().getStreamTypes(src.derivedUri, "*/*");
} catch (RuntimeException e) {
throw new ResourceException("Failed to obtain streamable types for %s due to an exception.", src.derivedUri, e);
}
if (streamTypes != null && streamTypes.length > 0) {
dstMimeType = streamTypes[0];
final String extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(dstMimeType);
dstDisplayName = src.displayName + (extension != null ? "." + extension : src.displayName);
} else {
throw new ResourceException("Cannot copy virtual file %s. No streamable formats " + "available.", src.derivedUri);
}
} else {
dstMimeType = src.mimeType;
dstDisplayName = src.displayName;
}
// Create the target document (either a file or a directory), then copy recursively the
// contents (bytes or children).
Uri dstUri = null;
try {
dstUri = DocumentsContract.createDocument(getClient(dest), dest.derivedUri, dstMimeType, dstDisplayName);
} catch (RemoteException | RuntimeException e) {
throw new ResourceException("Couldn't create destination document " + dstDisplayName + " in directory %s " + "due to an exception.", dest.derivedUri, e);
}
if (dstUri == null) {
// If this is a directory, the entire subdir will not be copied over.
throw new ResourceException("Couldn't create destination document " + dstDisplayName + " in directory %s.", dest.derivedUri);
}
DocumentInfo dstInfo = null;
try {
dstInfo = DocumentInfo.fromUri(getContentResolver(), dstUri);
} catch (FileNotFoundException | RuntimeException e) {
throw new ResourceException("Could not load DocumentInfo for newly created file %s.", dstUri);
}
if (Document.MIME_TYPE_DIR.equals(src.mimeType)) {
copyDirectoryHelper(src, dstInfo);
} else {
copyFileHelper(src, dstInfo, dest, dstMimeType);
}
}
use of com.android.documentsui.model.DocumentInfo in project android_frameworks_base by ResurrectionRemix.
the class FileOperationService method handleOperation.
private void handleOperation(Intent intent, int serviceId, String jobId, int operationType) {
if (DEBUG)
Log.d(TAG, "onStartCommand: " + jobId + " with serviceId " + serviceId);
// Track the service supplied id so we can stop the service once we're out of work to do.
mLastServiceId = serviceId;
Job job = null;
synchronized (mRunning) {
if (mWakeLock == null) {
mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
}
List<DocumentInfo> srcs = intent.getParcelableArrayListExtra(EXTRA_SRC_LIST);
DocumentInfo srcParent = intent.getParcelableExtra(EXTRA_SRC_PARENT);
DocumentStack stack = intent.getParcelableExtra(Shared.EXTRA_STACK);
job = createJob(operationType, jobId, srcs, srcParent, stack);
if (job == null) {
return;
}
mWakeLock.acquire();
}
assert (job != null);
int delay = intent.getIntExtra(EXTRA_DELAY, DEFAULT_DELAY);
assert (delay <= MAX_DELAY);
if (DEBUG)
Log.d(TAG, "Scheduling job " + job.id + " to run in " + delay + " milliseconds.");
ScheduledFuture<?> future = executor.schedule(job, delay, TimeUnit.MILLISECONDS);
mRunning.put(jobId, new JobRecord(job, future));
}
use of com.android.documentsui.model.DocumentInfo in project android_frameworks_base by ResurrectionRemix.
the class DocumentsProviderHelper method assertHasDirectory.
public void assertHasDirectory(Uri parentUri, String name) throws Exception {
List<DocumentInfo> children = listChildren(parentUri);
for (DocumentInfo child : children) {
if (name.equals(child.displayName) && child.isDirectory()) {
return;
}
}
fail("Could not find name=" + name + " in children " + children);
}
use of com.android.documentsui.model.DocumentInfo in project android_frameworks_base by ResurrectionRemix.
the class DocumentsProviderHelper method listChildren.
public List<DocumentInfo> listChildren(String documentId) throws Exception {
Uri uri = buildChildDocumentsUri(mAuthority, documentId);
List<DocumentInfo> children = new ArrayList<>();
try (Cursor cursor = mClient.query(uri, null, null, null, null, null)) {
Cursor wrapper = new RootCursorWrapper(mAuthority, "totally-fake", cursor, 100);
while (wrapper.moveToNext()) {
children.add(DocumentInfo.fromDirectoryCursor(wrapper));
}
}
return children;
}
Aggregations