Open 4G+ file by using AppFuse.
am: 77a1c65 * commit '77a1c65610618891ba28d7a10e4f107ea27e392e': Open 4G+ file by using AppFuse.
This commit is contained in:
@@ -144,6 +144,8 @@ public class AppFuse {
|
||||
return mCallback.getFileSize(inode);
|
||||
} catch (FileNotFoundException e) {
|
||||
return -OsConstants.ENOENT;
|
||||
} catch (UnsupportedOperationException e) {
|
||||
return -OsConstants.ENOTSUP;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,8 +56,15 @@ class MtpDeviceRecord {
|
||||
}
|
||||
|
||||
static boolean isPartialReadSupported(@Nullable int[] supportedList, long fileSize) {
|
||||
return fileSize <= 0xffffffffl &&
|
||||
isSupported(supportedList, MtpConstants.OPERATION_GET_PARTIAL_OBJECT);
|
||||
if (isSupported(supportedList, MtpConstants.OPERATION_GET_PARTIAL_OBJECT_64)) {
|
||||
return true;
|
||||
}
|
||||
if (0 <= fileSize &&
|
||||
fileSize <= 0xffffffffL &&
|
||||
isSupported(supportedList, MtpConstants.OPERATION_GET_PARTIAL_OBJECT)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static boolean isWritingSupported(@Nullable int[] supportedList) {
|
||||
|
||||
@@ -234,11 +234,14 @@ public class MtpDocumentsProvider extends DocumentsProvider {
|
||||
final MtpDeviceRecord device = getDeviceToolkit(identifier.mDeviceId).mDeviceRecord;
|
||||
switch (mode) {
|
||||
case "r":
|
||||
final long fileSize = getFileSize(documentId);
|
||||
long fileSize;
|
||||
try {
|
||||
fileSize = getFileSize(documentId);
|
||||
} catch (UnsupportedOperationException exception) {
|
||||
fileSize = -1;
|
||||
}
|
||||
// MTP getPartialObject operation does not support files that are larger than
|
||||
// 4GB. Fallback to non-seekable file descriptor.
|
||||
// TODO: Use getPartialObject64 for MTP devices that support Android vendor
|
||||
// extension.
|
||||
if (MtpDeviceRecord.isPartialReadSupported(
|
||||
device.operationsSupported, fileSize)) {
|
||||
return mAppFuse.openFile(
|
||||
@@ -543,6 +546,9 @@ public class MtpDocumentsProvider extends DocumentsProvider {
|
||||
MtpDatabase.strings(Document.COLUMN_SIZE, Document.COLUMN_DISPLAY_NAME));
|
||||
try {
|
||||
if (cursor.moveToNext()) {
|
||||
if (cursor.isNull(0)) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
return cursor.getLong(0);
|
||||
} else {
|
||||
throw new FileNotFoundException();
|
||||
@@ -594,12 +600,20 @@ public class MtpDocumentsProvider extends DocumentsProvider {
|
||||
int inode, long offset, long size, byte[] buffer) throws IOException {
|
||||
final Identifier identifier = mDatabase.createIdentifier(Integer.toString(inode));
|
||||
final MtpDeviceRecord record = getDeviceToolkit(identifier.mDeviceId).mDeviceRecord;
|
||||
if (MtpDeviceRecord.isPartialReadSupported(record.operationsSupported, offset)) {
|
||||
|
||||
if (MtpDeviceRecord.isSupported(
|
||||
record.operationsSupported, MtpConstants.OPERATION_GET_PARTIAL_OBJECT_64)) {
|
||||
return mMtpManager.getPartialObject64(
|
||||
identifier.mDeviceId, identifier.mObjectHandle, offset, size, buffer);
|
||||
}
|
||||
|
||||
if (0 <= offset && offset <= 0xffffffffL && MtpDeviceRecord.isSupported(
|
||||
record.operationsSupported, MtpConstants.OPERATION_GET_PARTIAL_OBJECT)) {
|
||||
return mMtpManager.getPartialObject(
|
||||
identifier.mDeviceId, identifier.mObjectHandle, offset, size, buffer);
|
||||
} else {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -170,6 +170,14 @@ class MtpManager {
|
||||
}
|
||||
}
|
||||
|
||||
long getPartialObject64(int deviceId, int objectHandle, long offset, long size, byte[] buffer)
|
||||
throws IOException {
|
||||
final MtpDevice device = getDevice(deviceId);
|
||||
synchronized (device) {
|
||||
return device.getPartialObject64(objectHandle, offset, size, buffer);
|
||||
}
|
||||
}
|
||||
|
||||
byte[] getThumbnail(int deviceId, int objectHandle) throws IOException {
|
||||
final MtpDevice device = getDevice(deviceId);
|
||||
synchronized (device) {
|
||||
|
||||
Reference in New Issue
Block a user