New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Saving to content:// is still broken #426
Comments
|
@vishal0071 I am not talking about opening. I am talking about this line. You should not assume that
Some of them may look like
But you can not make any assumptions about their structure.
Not sure why, but during my test the apk failed with following exception:
|
We're not assuming uri.getpath is path to disk. If you check further, that's what checks are for, both while getting InputStream and OutputStream. If the uri indeed is from content provider, then the path returned by ````uri.getPath``` would fail to get stream using basic filesystem methods, and when it does that, then only we look for the FileDescriptors as rw, and finally as r as last resort. So basically, when reading, we check for if(failed above) try // opening rw ParcelFileDescriptor So, you see, basic file system will automatically fail when we have a Uri from ContentProviders, and we would fall back to FDs. Similarly for getting OutputStream. PS. the only pitfall that seems to me is, when you have rootmode and you get a Uri from ContentProvider. Then first check would obviously be triggered and we would try to copy the path from uri into cache. But since that is not a real path, an empty file would be created? Hence a stream pointing to empty file, maybe that's where you case lies? |
More or less, you got it.
No, this won't work. You seem to assume, that ContentProviders are some dumb mechanism to read regular files. This is not true. ContentProvider is Android answer to Unix shell command pipes. They can convert/transform input on fly. When Unix admin wants to view a pdf in console, they may run something like this is Bash:
Android allows ContentProviders to do the same: one ContentProvider may download content from web on fly (e.g. Google Drive content provider) while another one converts it to text on fly. And the resulting uri (referring to pipe) may be passed to your editor. If you get a uri, referring to pdf file on disk, you current code will try to circumvent the converting ContentProvider and directly load the pdf file file from local disk… This is a bug. This means that your |
@vishal0071 Regarding |
Alright, I didn't know Ps. I didn't get these statements by you quite much
I hope you're not referring here to the new code, and are actually referring to the old code which didn't handle uri from |
Sorry, it seems I have misled you: it is possible to use RandomAccessFile with
It seems, our previous discussion has somehow gotten over your head… Do you know, what a "socket" is? It is a special thing, used to get data stuff from network. The entire file does not get transferred instantly: the server is writing it at the same time as client is reading. Piece by piece. This is how video streaming works. Pipes are the same as sockets except between local processes. When you read from pipe, another side is writing to it. If the other side does not have enough data to fill the pipe/socket buffer, your reading thread may be blocked until the other side writes some more. Pipes and sockets are file descriptors. ContentProvider may be streaming it's data to you. This is the point of using |
You're right! I totally overlooked sockets and pipe and assumed everything to be file, my bad. |
BTW test whether the issue is been fixed with v3.1.2 beta 9 |
@vishal0071 What a coincidence — I am also writing one right now (actually there is both provider and a library for creating such providers). When finished, is might be able to resolve #405
It still crashes when null ParcelFileDescriptor is returned:
|
Have there been any progress on this? Is there a newer version I can test? By the way, the above-mentioned ContentProvider is finished. |
I'm sorry. Got caught up on content provider. Will work on this. |
@vishal0071 It allows opening files via |
That's great! Looking forward to using it with Amaze (: |
I have downloaded the latest apk and looked at the current code. It seems, that saving to
content://
was not fixed and the broken behavior was made even more broken in recent changes by @martinczThe text viewer still assumes that
uri.getPath
== path to local file. This is obviously not the case: if, say, opencloud ContentProvider exposes uri whereuri.getPath
==/mnt/storage/example.txt
, that does not mean that you should mess with/mnt/storage/example.txt
on local drive... What if the uri path accidentally happens to match something on local system? Say,/dev/block/vdc
? Trying to blindly open that file with root shell (before even asking ContentProvider for file descriptor!) is not a good idea...The same goes for filename. The documentation of OpenableColumns#FILE_NAME clearly states:
E.g. you should query the ContentProvider for
OpenableColumns#FILE_NAME
before assuming thatgetLastPathSegment()
can be used as file name.No check for null from
openFile
: if ContentProvider does not return a file, your app crashes.If something happen to process (see p. 3), the file manager starts to crash upon reopening:
The text was updated successfully, but these errors were encountered: