FileShuttle: allow OPEN_DOCUMENT_TREE [WIP]

implement isChildDocument() for this.
This commit is contained in:
Peter Cai 2018-09-21 16:08:47 +08:00
parent bb8cfb1171
commit c716a22df8
No known key found for this signature in database
GPG key ID: 71F5FB4E4F3FD54F
4 changed files with 30 additions and 3 deletions

View file

@ -7,8 +7,8 @@ android {
applicationId "net.typeblog.shelter" applicationId "net.typeblog.shelter"
minSdkVersion 24 minSdkVersion 24
targetSdkVersion 28 targetSdkVersion 28
versionCode 7 versionCode 8
versionName "1.2" versionName "1.3-alpha"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
} }
buildTypes { buildTypes {

View file

@ -12,4 +12,5 @@ interface IFileShuttleService {
ParcelFileDescriptor openThumbnail(String path, in Point sizeHint); ParcelFileDescriptor openThumbnail(String path, in Point sizeHint);
String createFile(String path, String mimeType, String displayName); String createFile(String path, String mimeType, String displayName);
String deleteFile(String path); String deleteFile(String path);
boolean isChildOf(String parentPath, String childPath);
} }

View file

@ -12,6 +12,7 @@ import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
import android.os.Looper; import android.os.Looper;
import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.provider.DocumentsContract; import android.provider.DocumentsContract;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
@ -164,6 +165,19 @@ public class FileShuttleService extends Service {
f.delete(); f.delete();
return f.getParentFile().getAbsolutePath(); 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 @Nullable

View file

@ -127,7 +127,9 @@ public class CrossProfileDocumentsProvider extends DocumentsProvider {
Utility.isProfileOwner(getContext()) ? Utility.isProfileOwner(getContext()) ?
getContext().getString(R.string.fragment_profile_main) : getContext().getString(R.string.fragment_profile_main) :
getContext().getString(R.string.fragment_profile_work)); 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; 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) { private void includeFile(MatrixCursor cursor, Map<String, Object> fileInfo) {
final MatrixCursor.RowBuilder row = cursor.newRow(); final MatrixCursor.RowBuilder row = cursor.newRow();
for (String col : DEFAULT_DOCUMENT_PROJECTION) { for (String col : DEFAULT_DOCUMENT_PROJECTION) {