From d9efaa3d5362c1907db028a9ec167a27c2755dff Mon Sep 17 00:00:00 2001 From: Clayton Grassick Date: Wed, 20 Jul 2022 19:28:18 -0500 Subject: [PATCH 1/4] Fix #525 --- src/android/ContentFilesystem.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/android/ContentFilesystem.java b/src/android/ContentFilesystem.java index f4df440d..b37eb355 100644 --- a/src/android/ContentFilesystem.java +++ b/src/android/ContentFilesystem.java @@ -45,7 +45,8 @@ public ContentFilesystem(Context context, CordovaResourceApi resourceApi, Cordov @Override public Uri toNativeUri(LocalFilesystemURL inputURL) { - String authorityAndPath = inputURL.uri.getEncodedPath().substring(this.name.length() + 2); + String encodedPath = inputURL.uri.getEncodedPath(); + String authorityAndPath = encodedPath.substring(encodedPath.indexOf(this.name) + 1 + this.name.length() + 2); if (authorityAndPath.length() < 2) { return null; } From 4eb406e40235fc62acf2bacdc041c64dd857aab7 Mon Sep 17 00:00:00 2001 From: Clayton Grassick Date: Wed, 20 Jul 2022 19:35:11 -0500 Subject: [PATCH 2/4] Correct indent --- src/android/ContentFilesystem.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/android/ContentFilesystem.java b/src/android/ContentFilesystem.java index b37eb355..34fd2deb 100644 --- a/src/android/ContentFilesystem.java +++ b/src/android/ContentFilesystem.java @@ -45,8 +45,8 @@ public ContentFilesystem(Context context, CordovaResourceApi resourceApi, Cordov @Override public Uri toNativeUri(LocalFilesystemURL inputURL) { - String encodedPath = inputURL.uri.getEncodedPath(); - String authorityAndPath = encodedPath.substring(encodedPath.indexOf(this.name) + 1 + this.name.length() + 2); + String encodedPath = inputURL.uri.getEncodedPath(); + String authorityAndPath = encodedPath.substring(encodedPath.indexOf(this.name) + 1 + this.name.length() + 2); if (authorityAndPath.length() < 2) { return null; } From e6712d1aafe762fc0880ee7dd8362e879b0aed57 Mon Sep 17 00:00:00 2001 From: Clayton Grassick Date: Thu, 4 Aug 2022 10:35:27 -0400 Subject: [PATCH 3/4] Indent using spaces --- src/android/ContentFilesystem.java | 116 ++++++++++++++--------------- 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/src/android/ContentFilesystem.java b/src/android/ContentFilesystem.java index 34fd2deb..12ad6391 100644 --- a/src/android/ContentFilesystem.java +++ b/src/android/ContentFilesystem.java @@ -38,15 +38,15 @@ public class ContentFilesystem extends Filesystem { private final Context context; - public ContentFilesystem(Context context, CordovaResourceApi resourceApi, CordovaPreferences preferences) { - super(Uri.parse("content://"), "content", resourceApi, preferences); + public ContentFilesystem(Context context, CordovaResourceApi resourceApi, CordovaPreferences preferences) { + super(Uri.parse("content://"), "content", resourceApi, preferences); this.context = context; - } + } @Override public Uri toNativeUri(LocalFilesystemURL inputURL) { - String encodedPath = inputURL.uri.getEncodedPath(); - String authorityAndPath = encodedPath.substring(encodedPath.indexOf(this.name) + 1 + this.name.length() + 2); + String encodedPath = inputURL.uri.getEncodedPath(); + String authorityAndPath = encodedPath.substring(encodedPath.indexOf(this.name) + 1 + this.name.length() + 2); if (authorityAndPath.length() < 2) { return null; } @@ -84,41 +84,41 @@ public LocalFilesystemURL toLocalUri(Uri inputURL) { } @Override - public JSONObject getFileForLocalURL(LocalFilesystemURL inputURL, - String fileName, JSONObject options, boolean directory) throws IOException, TypeMismatchException, JSONException { + public JSONObject getFileForLocalURL(LocalFilesystemURL inputURL, + String fileName, JSONObject options, boolean directory) throws IOException, TypeMismatchException, JSONException { throw new UnsupportedOperationException("getFile() not supported for content:. Use resolveLocalFileSystemURL instead."); - } + } - @Override - public boolean removeFileAtLocalURL(LocalFilesystemURL inputURL) - throws NoModificationAllowedException { + @Override + public boolean removeFileAtLocalURL(LocalFilesystemURL inputURL) + throws NoModificationAllowedException { Uri contentUri = toNativeUri(inputURL); - try { + try { context.getContentResolver().delete(contentUri, null, null); - } catch (UnsupportedOperationException t) { - // Was seeing this on the File mobile-spec tests on 4.0.3 x86 emulator. - // The ContentResolver applies only when the file was registered in the - // first case, which is generally only the case with images. + } catch (UnsupportedOperationException t) { + // Was seeing this on the File mobile-spec tests on 4.0.3 x86 emulator. + // The ContentResolver applies only when the file was registered in the + // first case, which is generally only the case with images. NoModificationAllowedException nmae = new NoModificationAllowedException("Deleting not supported for content uri: " + contentUri); nmae.initCause(t); throw nmae; - } + } return true; - } + } - @Override - public boolean recursiveRemoveFileAtLocalURL(LocalFilesystemURL inputURL) - throws NoModificationAllowedException { - throw new NoModificationAllowedException("Cannot remove content url"); - } + @Override + public boolean recursiveRemoveFileAtLocalURL(LocalFilesystemURL inputURL) + throws NoModificationAllowedException { + throw new NoModificationAllowedException("Cannot remove content url"); + } @Override public LocalFilesystemURL[] listChildren(LocalFilesystemURL inputURL) throws FileNotFoundException { throw new UnsupportedOperationException("readEntriesAtLocalURL() not supported for content:. Use resolveLocalFileSystemURL instead."); } - @Override - public JSONObject getFileMetadataForLocalURL(LocalFilesystemURL inputURL) throws FileNotFoundException { + @Override + public JSONObject getFileMetadataForLocalURL(LocalFilesystemURL inputURL) throws FileNotFoundException { long size = -1; long lastModified = 0; Uri nativeUri = toNativeUri(inputURL); @@ -143,55 +143,55 @@ public JSONObject getFileMetadataForLocalURL(LocalFilesystemURL inputURL) throws fnfe.initCause(e); throw fnfe; } finally { - if (cursor != null) - cursor.close(); + if (cursor != null) + cursor.close(); } JSONObject metadata = new JSONObject(); try { - metadata.put("size", size); - metadata.put("type", mimeType); - metadata.put("name", name); - metadata.put("fullPath", inputURL.path); - metadata.put("lastModifiedDate", lastModified); + metadata.put("size", size); + metadata.put("type", mimeType); + metadata.put("name", name); + metadata.put("fullPath", inputURL.path); + metadata.put("lastModifiedDate", lastModified); } catch (JSONException e) { - return null; + return null; } return metadata; - } + } - @Override - public long writeToFileAtURL(LocalFilesystemURL inputURL, String data, - int offset, boolean isBinary) throws NoModificationAllowedException { + @Override + public long writeToFileAtURL(LocalFilesystemURL inputURL, String data, + int offset, boolean isBinary) throws NoModificationAllowedException { throw new NoModificationAllowedException("Couldn't write to file given its content URI"); } - @Override - public long truncateFileAtURL(LocalFilesystemURL inputURL, long size) - throws NoModificationAllowedException { + @Override + public long truncateFileAtURL(LocalFilesystemURL inputURL, long size) + throws NoModificationAllowedException { throw new NoModificationAllowedException("Couldn't truncate file given its content URI"); - } + } - protected Cursor openCursorForURL(Uri nativeUri) { + protected Cursor openCursorForURL(Uri nativeUri) { ContentResolver contentResolver = context.getContentResolver(); try { return contentResolver.query(nativeUri, null, null, null, null); } catch (UnsupportedOperationException e) { return null; } - } + } - private Long resourceSizeForCursor(Cursor cursor) { + private Long resourceSizeForCursor(Cursor cursor) { int columnIndex = cursor.getColumnIndex(OpenableColumns.SIZE); if (columnIndex != -1) { String sizeStr = cursor.getString(columnIndex); if (sizeStr != null) { - return Long.parseLong(sizeStr); + return Long.parseLong(sizeStr); } } return null; - } - - protected Long lastModifiedDateForCursor(Cursor cursor) { + } + + protected Long lastModifiedDateForCursor(Cursor cursor) { int columnIndex = cursor.getColumnIndex(MediaStore.MediaColumns.DATE_MODIFIED); if (columnIndex == -1) { columnIndex = cursor.getColumnIndex(DocumentsContract.Document.COLUMN_LAST_MODIFIED); @@ -203,7 +203,7 @@ protected Long lastModifiedDateForCursor(Cursor cursor) { } } return null; - } + } @Override public String filesystemPathForURL(LocalFilesystemURL url) { @@ -211,14 +211,14 @@ public String filesystemPathForURL(LocalFilesystemURL url) { return f == null ? null : f.getAbsolutePath(); } - @Override - public LocalFilesystemURL URLforFilesystemPath(String path) { - // Returns null as we don't support reverse mapping back to content:// URLs - return null; - } + @Override + public LocalFilesystemURL URLforFilesystemPath(String path) { + // Returns null as we don't support reverse mapping back to content:// URLs + return null; + } - @Override - public boolean canRemoveFileAtLocalURL(LocalFilesystemURL inputURL) { - return true; - } + @Override + public boolean canRemoveFileAtLocalURL(LocalFilesystemURL inputURL) { + return true; + } } From 533583fccab275bbffe4d09860a668dac0d3bd73 Mon Sep 17 00:00:00 2001 From: Clayton Grassick Date: Thu, 4 Aug 2022 10:39:21 -0400 Subject: [PATCH 4/4] Revert indent --- src/android/ContentFilesystem.java | 112 ++++++++++++++--------------- 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/src/android/ContentFilesystem.java b/src/android/ContentFilesystem.java index 12ad6391..d528bd3a 100644 --- a/src/android/ContentFilesystem.java +++ b/src/android/ContentFilesystem.java @@ -38,10 +38,10 @@ public class ContentFilesystem extends Filesystem { private final Context context; - public ContentFilesystem(Context context, CordovaResourceApi resourceApi, CordovaPreferences preferences) { - super(Uri.parse("content://"), "content", resourceApi, preferences); + public ContentFilesystem(Context context, CordovaResourceApi resourceApi, CordovaPreferences preferences) { + super(Uri.parse("content://"), "content", resourceApi, preferences); this.context = context; - } + } @Override public Uri toNativeUri(LocalFilesystemURL inputURL) { @@ -84,41 +84,41 @@ public LocalFilesystemURL toLocalUri(Uri inputURL) { } @Override - public JSONObject getFileForLocalURL(LocalFilesystemURL inputURL, - String fileName, JSONObject options, boolean directory) throws IOException, TypeMismatchException, JSONException { + public JSONObject getFileForLocalURL(LocalFilesystemURL inputURL, + String fileName, JSONObject options, boolean directory) throws IOException, TypeMismatchException, JSONException { throw new UnsupportedOperationException("getFile() not supported for content:. Use resolveLocalFileSystemURL instead."); - } + } - @Override - public boolean removeFileAtLocalURL(LocalFilesystemURL inputURL) - throws NoModificationAllowedException { + @Override + public boolean removeFileAtLocalURL(LocalFilesystemURL inputURL) + throws NoModificationAllowedException { Uri contentUri = toNativeUri(inputURL); - try { + try { context.getContentResolver().delete(contentUri, null, null); - } catch (UnsupportedOperationException t) { - // Was seeing this on the File mobile-spec tests on 4.0.3 x86 emulator. - // The ContentResolver applies only when the file was registered in the - // first case, which is generally only the case with images. + } catch (UnsupportedOperationException t) { + // Was seeing this on the File mobile-spec tests on 4.0.3 x86 emulator. + // The ContentResolver applies only when the file was registered in the + // first case, which is generally only the case with images. NoModificationAllowedException nmae = new NoModificationAllowedException("Deleting not supported for content uri: " + contentUri); nmae.initCause(t); throw nmae; - } + } return true; - } + } - @Override - public boolean recursiveRemoveFileAtLocalURL(LocalFilesystemURL inputURL) - throws NoModificationAllowedException { - throw new NoModificationAllowedException("Cannot remove content url"); - } + @Override + public boolean recursiveRemoveFileAtLocalURL(LocalFilesystemURL inputURL) + throws NoModificationAllowedException { + throw new NoModificationAllowedException("Cannot remove content url"); + } @Override public LocalFilesystemURL[] listChildren(LocalFilesystemURL inputURL) throws FileNotFoundException { throw new UnsupportedOperationException("readEntriesAtLocalURL() not supported for content:. Use resolveLocalFileSystemURL instead."); } - @Override - public JSONObject getFileMetadataForLocalURL(LocalFilesystemURL inputURL) throws FileNotFoundException { + @Override + public JSONObject getFileMetadataForLocalURL(LocalFilesystemURL inputURL) throws FileNotFoundException { long size = -1; long lastModified = 0; Uri nativeUri = toNativeUri(inputURL); @@ -143,55 +143,55 @@ public JSONObject getFileMetadataForLocalURL(LocalFilesystemURL inputURL) throws fnfe.initCause(e); throw fnfe; } finally { - if (cursor != null) - cursor.close(); + if (cursor != null) + cursor.close(); } JSONObject metadata = new JSONObject(); try { - metadata.put("size", size); - metadata.put("type", mimeType); - metadata.put("name", name); - metadata.put("fullPath", inputURL.path); - metadata.put("lastModifiedDate", lastModified); + metadata.put("size", size); + metadata.put("type", mimeType); + metadata.put("name", name); + metadata.put("fullPath", inputURL.path); + metadata.put("lastModifiedDate", lastModified); } catch (JSONException e) { - return null; + return null; } return metadata; - } + } - @Override - public long writeToFileAtURL(LocalFilesystemURL inputURL, String data, - int offset, boolean isBinary) throws NoModificationAllowedException { + @Override + public long writeToFileAtURL(LocalFilesystemURL inputURL, String data, + int offset, boolean isBinary) throws NoModificationAllowedException { throw new NoModificationAllowedException("Couldn't write to file given its content URI"); } - @Override - public long truncateFileAtURL(LocalFilesystemURL inputURL, long size) - throws NoModificationAllowedException { + @Override + public long truncateFileAtURL(LocalFilesystemURL inputURL, long size) + throws NoModificationAllowedException { throw new NoModificationAllowedException("Couldn't truncate file given its content URI"); - } + } - protected Cursor openCursorForURL(Uri nativeUri) { + protected Cursor openCursorForURL(Uri nativeUri) { ContentResolver contentResolver = context.getContentResolver(); try { return contentResolver.query(nativeUri, null, null, null, null); } catch (UnsupportedOperationException e) { return null; } - } + } - private Long resourceSizeForCursor(Cursor cursor) { + private Long resourceSizeForCursor(Cursor cursor) { int columnIndex = cursor.getColumnIndex(OpenableColumns.SIZE); if (columnIndex != -1) { String sizeStr = cursor.getString(columnIndex); if (sizeStr != null) { - return Long.parseLong(sizeStr); + return Long.parseLong(sizeStr); } } return null; - } - - protected Long lastModifiedDateForCursor(Cursor cursor) { + } + + protected Long lastModifiedDateForCursor(Cursor cursor) { int columnIndex = cursor.getColumnIndex(MediaStore.MediaColumns.DATE_MODIFIED); if (columnIndex == -1) { columnIndex = cursor.getColumnIndex(DocumentsContract.Document.COLUMN_LAST_MODIFIED); @@ -203,7 +203,7 @@ protected Long lastModifiedDateForCursor(Cursor cursor) { } } return null; - } + } @Override public String filesystemPathForURL(LocalFilesystemURL url) { @@ -211,14 +211,14 @@ public String filesystemPathForURL(LocalFilesystemURL url) { return f == null ? null : f.getAbsolutePath(); } - @Override - public LocalFilesystemURL URLforFilesystemPath(String path) { - // Returns null as we don't support reverse mapping back to content:// URLs - return null; - } + @Override + public LocalFilesystemURL URLforFilesystemPath(String path) { + // Returns null as we don't support reverse mapping back to content:// URLs + return null; + } - @Override - public boolean canRemoveFileAtLocalURL(LocalFilesystemURL inputURL) { - return true; - } + @Override + public boolean canRemoveFileAtLocalURL(LocalFilesystemURL inputURL) { + return true; + } }