FileShuttle: allow OPEN_DOCUMENT_TREE [WIP]
implement isChildDocument() for this.
This commit is contained in:
parent
bb8cfb1171
commit
c716a22df8
|
@ -7,8 +7,8 @@ android {
|
|||
applicationId "net.typeblog.shelter"
|
||||
minSdkVersion 24
|
||||
targetSdkVersion 28
|
||||
versionCode 7
|
||||
versionName "1.2"
|
||||
versionCode 8
|
||||
versionName "1.3-alpha"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
buildTypes {
|
||||
|
|
|
@ -12,4 +12,5 @@ interface IFileShuttleService {
|
|||
ParcelFileDescriptor openThumbnail(String path, in Point sizeHint);
|
||||
String createFile(String path, String mimeType, String displayName);
|
||||
String deleteFile(String path);
|
||||
boolean isChildOf(String parentPath, String childPath);
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import android.os.Handler;
|
|||
import android.os.IBinder;
|
||||
import android.os.Looper;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.RemoteException;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.annotation.Nullable;
|
||||
|
@ -164,6 +165,19 @@ public class FileShuttleService extends Service {
|
|||
f.delete();
|
||||
return f.getParentFile().getAbsolutePath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChildOf(String parent, String child) {
|
||||
File parentFile = new File(resolvePath(parent));
|
||||
File childFile = new File(resolvePath(child));
|
||||
String parentPath = parentFile.getAbsolutePath();
|
||||
if (parentPath.charAt(parentPath.length() - 1) != '/') {
|
||||
parentPath += "/"; // Make sure it ends with '/'
|
||||
}
|
||||
return parentFile.exists() && parentFile.isDirectory()
|
||||
&& childFile.exists()
|
||||
&& childFile.getAbsolutePath().startsWith(parentPath);
|
||||
}
|
||||
};
|
||||
|
||||
@Nullable
|
||||
|
|
|
@ -127,7 +127,9 @@ public class CrossProfileDocumentsProvider extends DocumentsProvider {
|
|||
Utility.isProfileOwner(getContext()) ?
|
||||
getContext().getString(R.string.fragment_profile_main) :
|
||||
getContext().getString(R.string.fragment_profile_work));
|
||||
row.add(DocumentsContract.Root.COLUMN_FLAGS, DocumentsContract.Root.FLAG_SUPPORTS_CREATE);
|
||||
row.add(DocumentsContract.Root.COLUMN_FLAGS,
|
||||
DocumentsContract.Root.FLAG_SUPPORTS_CREATE | DocumentsContract.Root.FLAG_LOCAL_ONLY |
|
||||
DocumentsContract.Root.FLAG_SUPPORTS_IS_CHILD); // SUPPORTS_IS_CHILD is required for OPEN_DOCUMENT_TREE
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -211,6 +213,16 @@ public class CrossProfileDocumentsProvider extends DocumentsProvider {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChildDocument(String parentDocumentId, String documentId) {
|
||||
ensureServiceBound();
|
||||
try {
|
||||
return mService.isChildOf(parentDocumentId, documentId);
|
||||
} catch (RemoteException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void includeFile(MatrixCursor cursor, Map<String, Object> fileInfo) {
|
||||
final MatrixCursor.RowBuilder row = cursor.newRow();
|
||||
for (String col : DEFAULT_DOCUMENT_PROJECTION) {
|
||||
|
|
Loading…
Reference in a new issue