diff --git a/app/build.gradle b/app/build.gradle index 5b9ed63..1069af8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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 { diff --git a/app/src/main/aidl/net/typeblog/shelter/services/IFileShuttleService.aidl b/app/src/main/aidl/net/typeblog/shelter/services/IFileShuttleService.aidl index dd3b0de..007b3a4 100644 --- a/app/src/main/aidl/net/typeblog/shelter/services/IFileShuttleService.aidl +++ b/app/src/main/aidl/net/typeblog/shelter/services/IFileShuttleService.aidl @@ -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); } diff --git a/app/src/main/java/net/typeblog/shelter/services/FileShuttleService.java b/app/src/main/java/net/typeblog/shelter/services/FileShuttleService.java index b99fad8..67864e2 100644 --- a/app/src/main/java/net/typeblog/shelter/services/FileShuttleService.java +++ b/app/src/main/java/net/typeblog/shelter/services/FileShuttleService.java @@ -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 diff --git a/app/src/main/java/net/typeblog/shelter/util/CrossProfileDocumentsProvider.java b/app/src/main/java/net/typeblog/shelter/util/CrossProfileDocumentsProvider.java index b44e3b9..b54bc53 100644 --- a/app/src/main/java/net/typeblog/shelter/util/CrossProfileDocumentsProvider.java +++ b/app/src/main/java/net/typeblog/shelter/util/CrossProfileDocumentsProvider.java @@ -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 fileInfo) { final MatrixCursor.RowBuilder row = cursor.newRow(); for (String col : DEFAULT_DOCUMENT_PROJECTION) {