AquaMail Forum

English - Android => How do I... => Topic started by: StR on October 15, 2014, 01:24:39 am

Title: Is it possible to tell Aquamail where to save the majority of its data?
Post by: StR on October 15, 2014, 01:24:39 am

I see that currently, about 36 MB of Aquamail's data resides on the internal memory, while about 5.5 MB is on the external card. I looked and couldn't find any configuration option that would allow me to tell Aquamail to use the external card for storage.

From some postings I can guess that what is presently saved on the external card is the attachments (right?). Also from what I know, Android 4.4* imposes some strict limitations on what apps can store/access on the external card. So, I am not sure if with that it would be even possible under Android 4.4+. But it would be nice to be able to use the external storage for data storage, especially on the phones that (1) have relatively small internal storage (8 GB) and do not allow installing apps on the external card (e.g. Droid Razr M).
Title: Re: Is it possible to tell Aquamail where to save the majority of its data?
Post by: Kostya Vasilyev on October 16, 2014, 01:52:23 am
Um, there is some terminology confusion here.

To an Android developer, Internal Memory is where apps are installed. Most likely not 8 GB, even on very shiny and expensive phones.

In that memory, Aqua only stores metadata and message text.

External Memory aka "memory card" -- as called by Android -- is the "logical" external memory. Used to be a microSD a few years ago, now typically built-in. Logically, it's different, even though it may be a partition on the same memory chip. This is your 8 GB partition. This is where Aqua stores attachments and inline images.

The "real external microSD memory card" -- the third thing -- is not used by Aqua. In theory, I could store attachments and inlines there, even with 4.4 (apps are allowed access to their own directories, even on the "real external microSD"), but there has not been any work for that.
Title: Re: Is it possible to tell Aquamail where to save the majority of its data?
Post by: grumpy on October 16, 2014, 10:48:39 am
Not wishing in any way to contradict our favourite developer (!) but it is of course possible to store attachments on the 'real external microSD memory card' via the 'look and feel/folder for attachments' setting if you're not plagued by the restrictions 4.4 places on you.

Works fine on my 4.3 tablet but won't work on my 4.4 phone which uses the download directory on the 'logical external memory'. Plenty of space there for a few attachments if you do a bit of housekeeping now and again

There are a variety of ways to remove the SD card restrictions under 4.4 involving rooting and patching which seem to work well - just not needed for me on my phone.

EDIT - I lied!. Since I rarely download attachments on my phone I had never tried to set it up to use the real external drive. Just did so and it worked fine, although I had assumed that 4.4 would prevent this. (Moto E, stock Android 4.4.4, unrooted). Any explanation Kostya?
Title: Re: Is it possible to tell Aquamail where to save the majority of its data?
Post by: Kostya Vasilyev on October 18, 2014, 02:21:57 am
@grumpy -- the 4.4 restriction is 1) hard, that is, no permission will get around it 2) only applies to directories outside the predefined app-specific storage folder.

Those app specific storage folders are under "Android/data", and in Aqua's case (or most any app's) not very useful as storage for user-exposed data.

Same with the "non-external external storage". Aqua stores attachments there as a cache, but they're not intended to be used right there as a user.

Now, when you "save" an attachment in Aqua -- it's detached from said cache, and is moved or copied into the user designated download folder, with a proper name. From that point on, it's under the user's control. And this is what fails on 4.4.
Title: Re: Is it possible to tell Aquamail where to save the majority of its data?
Post by: beaky on October 18, 2014, 09:49:52 pm
@grumpy -- the 4.4 restriction is 1) hard, that is, no permission will get around it 2) only applies to directories outside the predefined app-specific storage folder.

Those app specific storage folders are under "Android/data", and in Aqua's case (or most any app's) not very useful as storage for user-exposed data.

Same with the "non-external external storage". Aqua stores attachments there as a cache, but they're not intended to be used right there as a user.

Now, when you "save" an attachment in Aqua -- it's detached from said cache, and is moved or copied into the user designated download folder, with a proper name. From that point on, it's under the user's control. And this is what fails on 4.4.
To be clear - are you saying that under 4.4 an app like aqua can be used to save a file to a user designated folder, BUT that folder remains exclusive to aqua mail? So I cannot (say) open the attachment in a suitable application, that also has its own space? I hope I have misunderstood this! It seems fundamental to any email app.
Title: Re: Is it possible to tell Aquamail where to save the majority of its data?
Post by: Kostya Vasilyev on October 18, 2014, 10:39:55 pm
Sorry I probably got tangled up in those complicated English words :)

Let me try again:

- In 4.4, when talking about the "real external microSD that you can remove"

- Apps can read and write to their own per-application data directory under <externalSd>/Android/data/<package name>

- And cannot write anywhere else (IIRC, there are reading restrictions too)

In theory, I could use this per-app directory as the attachment *cache* (currently in the "built-in large storage"), but it's not something intended to be seen by the user...

Title: Re: Is it possible to tell Aquamail where to save the majority of its data?
Post by: pyler on October 18, 2014, 10:45:35 pm
Maybe option to save  attachments on removable SD Card could be nice addition.
Title: Re: Is it possible to tell Aquamail where to save the majority of its data?
Post by: Kostya Vasilyev on October 18, 2014, 11:15:09 pm
In 4.4 (and I presume 5.0), it would only be able to access:

<externalSd>/Android/data/<package name>
Title: Re: Is it possible to tell Aquamail where to save the majority of its data?
Post by: grumpy on October 18, 2014, 11:27:20 pm
I'm still confused and I'm supposed to be a native English speaker :D

I don't cache attachments during an aquamail refresh/sync but I just did the following
- created a new folder on the external SD card called 'dummy' and set it as the attachments folder in aquamail
- found an email with an attachment, swiped to attachments and hit 'just save'
- navigated to dummy folder and opened the file in Quick Office

No problem at all but isn't this what you are saying should not be possible under 4.4?
Or have I got it completely wrong?
Title: Re: Is it possible to tell Aquamail where to save the majority of its data?
Post by: Kostya Vasilyev on October 18, 2014, 11:40:57 pm
But I'm not! :)

>> should not be possible under 4.4

Correct.
Title: Re: Is it possible to tell Aquamail where to save the majority of its data?
Post by: pyler on October 19, 2014, 11:24:20 am
But it can work on ics and jb. On lollipop check this http://developer.android.com/reference/android/provider/DocumentsContract.html#createDocument(android.content.ContentResolver, android.net.Uri, java.lang.String, java.lang.String)
Title: Re: Is it possible to tell Aquamail where to save the majority of its data?
Post by: StR on October 20, 2014, 04:13:13 pm
Um, there is some terminology confusion here.

To an Android developer, Internal Memory is where apps are installed. Most likely not 8 GB, even on very shiny and expensive phones.

In that memory, Aqua only stores metadata and message text.

External Memory aka "memory card" -- as called by Android -- is the "logical" external memory. Used to be a microSD a few years ago, now typically built-in. Logically, it's different, even though it may be a partition on the same memory chip. This is your 8 GB partition. This is where Aqua stores attachments and inline images.

The "real external microSD memory card" -- the third thing -- is not used by Aqua. In theory, I could store attachments and inlines there, even with 4.4 (apps are allowed access to their own directories, even on the "real external microSD"), but there has not been any work for that.

Thank you, Kostya for the clarification.
It is, indeed, rather confusing.
Please, excuse my ignorance, I am still confused:  if the app (under ics or jb) were to have something stored on microSD, where would that show up in the app info, on the screen like the one in the attachment? Or, will it not show at all?
See the attached screenshot.

Thank you!

Title: Re: Is it possible to tell Aquamail where to save the majority of its data?
Post by: Kostya Vasilyev on October 24, 2014, 01:55:49 am
I'm confused too.

Believe that "Data" is the smaller portion of built-in memory, which you can't access unless rooted... And "SD card" is the larger portion of built-in memory, where your Download folder is (and others), and which you can access with any file manager.

Neither of the above is the "real MicroSD memory card" (/mnt/ext_sd). Don't know what "USB storage app" is -- on my Galaxy Note 3 with 4.4, I have "SD Card app" and it's zero.
Title: Re: Is it possible to tell Aquamail where to save the majority of its data?
Post by: Dmitry_N on December 03, 2014, 01:59:21 pm
What a nice thread, Kostya!
Long time no see ;)
I have a related issue: this folder on the "internal" SD card got cluttered and was taking about 130 MB until I cleared it manually.
Judging by creation dates of the files within this folder (\sdcard\Android\data\org.kman.AquaMail\files\parts\), they were leftovers from emails no longer present either on the server (POP3) or on my device.
Is this supposed to be an issue?
Title: Re: Is it possible to tell Aquamail where to save the majority of its data?
Post by: pyler on December 03, 2014, 06:29:56 pm
You can save attachment in any folder on ext sd card using SAF, no? This works on kitkat too
Title: Re: Is it possible to tell Aquamail where to save the majority of its data?
Post by: Kostya Vasilyev on December 03, 2014, 08:40:04 pm
Not sure what the SAF has to do with it... Can you elaborate?
Title: Re: Is it possible to tell Aquamail where to save the majority of its data?
Post by: pyler on December 03, 2014, 09:12:16 pm
To write outside app dir on external sd card. (ACTION_CREATE_DOCUMENT)
Title: Re: Is it possible to tell Aquamail where to save the majority of its data?
Post by: Dmitry_N on December 03, 2014, 10:21:01 pm
You can save attachment in any folder on ext sd card using SAF, no? This works on kitkat too
I can.
But this question is not about saving them manually. This is about the automatic "caching" stuff.
Title: Re: Is it possible to tell Aquamail where to save the majority of its data?
Post by: Kostya Vasilyev on December 03, 2014, 10:36:04 pm
>> ACTION_CREATE_DOCUMENT
>>
>> Activity Action: Allow the user to create a new document. When invoked, the system will display the various DocumentsProvider instances installed on the device, letting the user navigate through them.

I'm lost. It's just an abstraction (for making Google Drive, Gallery, Dropbox, etc look the same).

How does it help with saving attachments specifically on the "real" external memory card?

To be more specific. Existing code:

FileOutputStream ostream = new FileOutputStream(new File("/mnt/ext_sd/AquaMail Downloads", "foo.png"));

^^^ throws IOException (or SecurityException, I forget)

Let's say I replace it with SAF calls, prompting the user to create a new document and then saving there...

How would this document, picked through SAF, end up on the "real" external memory card?

Title: Re: Is it possible to tell Aquamail where to save the majority of its data?
Post by: Kostya Vasilyev on December 03, 2014, 10:40:19 pm
>> But this question is not about saving them manually. This is about the automatic "caching" stuff.

Димон, здаров! Сразу и не признал.

В общем так: программа хранит на устройстве некоторое "бОльшее" количество сообщений (по ум. 250), а "смотрит" на меньшее (по ум. 25). Так что если на сервере удаляется что-то в "хвосте" (за пределами этих 25), то программа не увидит этих удалений.

А вот по мере прихода новых сообщений, страые будут выходить за пределы "хранить сообщений" (по ум. 250) -- и при этом удаляться с устройства. На следующие сутки после этого, их вложения будут удалены.

Немного как сказка про Кащея, просто получается некоторая задержка.

Что можно еще сделать. Длинное нажатие на учетной записи -- доп. настройки и папки -- доп. настройки -- уменьшить "хранить сообщений" скажем до 100, и после этого в главном окне вызвать Меню / Сжать хранилище сообщений (этот процесс как раз происходит автоматом раз в сутки).
Title: Re: Is it possible to tell Aquamail where to save the majority of its data?
Post by: pyler on December 03, 2014, 10:42:00 pm
User decides where to save it.

After user "creates" file, you get uri to this file I think and you can write to it.
Title: Re: Is it possible to tell Aquamail where to save the majority of its data?
Post by: Kostya Vasilyev on December 03, 2014, 10:47:23 pm
>> User decides where to save it.

The user can already decide where Aqua "saves" attachments.

>> After user "creates" file, you get uri to this file I think and you can write to it.

Is there any reason you think that the user will be able to choose / create a file on the "external" SD card and it'll work?

I just tried creating a file on "ext_sd" in Solid Explorer, it failed with "error, limitation of Android 4.4, install an app to fix your system permissions, you need to be rooted...". But we already knew that.

On a rooted device with a custom ROM, creating files on "external" SD works in Solid Explorer, and it also works in AquaMail.

Title: Re: Is it possible to tell Aquamail where to save the majority of its data?
Post by: pyler on December 03, 2014, 11:28:29 pm
SAF is system component, there are no limitations unlike 3rd party file managers.
Title: Re: Is it possible to tell Aquamail where to save the majority of its data?
Post by: Kostya Vasilyev on December 04, 2014, 02:22:00 pm
SAF is a framework that provides a unified abstraction of actual storage back-ends.

It does not store data itself.

There is no built-in back-end that provides a view of the raw file system -- maybe because Android has been steadily moving away from "file system" view of the world to "document collections".

Other SAF back-ends are still third party apps, and would not be signed by system keys.

If I'm missing something and you can point me to something specific (e.g. "Kostya, you dumbass, just call this function and everything will magically work") -- it would be great.
Title: Re: Is it possible to tell Aquamail where to save the majority of its data?
Post by: pyler on December 04, 2014, 05:28:04 pm
On Lollipop user just pick "sd card" in SAF once and AquaMail can access all files on sd card (real one)
Title: Re: Is it possible to tell Aquamail where to save the majority of its data?
Post by: Kostya Vasilyev on December 04, 2014, 06:50:18 pm
Pick when and where exactly? Access how, read or write?

Also:

5.0 has so far been released for: Nexus 4, 5, 6, 7, 9.

None of those devices has a "real" sd card.

I must be missing something, or just too dumb to understand.
Title: Re: Is it possible to tell Aquamail where to save the majority of its data?
Post by: pyler on December 04, 2014, 07:13:34 pm
If user chooses X directory via SAF, app grants access to this dir. Read and write.

G3 and S5 are getting Lollipop, so you can test it maybe.
Title: Re: Is it possible to tell Aquamail where to save the majority of its data?
Post by: Kostya Vasilyev on December 04, 2014, 09:32:18 pm
>> user chooses X directory via SAF

I don't see a directory chooser in SAF if I go to add a new attachment (when composing a message) in Aqua.

And SAF's Unified Document Picker is what comes up then, since 4.4

>> G3 and S5 are getting Lollipop, so you can test it maybe

I have a G3, no 5.0 yet.
Title: Re: Is it possible to tell Aquamail where to save the majority of its data?
Post by: pyler on December 04, 2014, 09:48:46 pm
There is special intent to pick directory I think.
Title: Re: Is it possible to tell Aquamail where to save the majority of its data?
Post by: Kostya Vasilyev on December 04, 2014, 09:50:26 pm
>> There is special intent to pick directory I think

Ah!

Ok, thanks, now I know what to try -- once my G3 actually gets 5.0.
Title: Re: Is it possible to tell Aquamail where to save the majority of its data?
Post by: pyler on December 04, 2014, 11:16:59 pm
http://stackoverflow.com/questions/26744842/how-to-use-the-new-sd-card-access-api-presented-for-lollipop
Title: Re: Is it possible to tell Aquamail where to save the majority of its data?
Post by: Kostya Vasilyev on December 04, 2014, 11:35:43 pm
Thank you.

>> Apps can launch this intent to pick and return a directory from any supported DocumentProvider, including any of the shared storage supported by the device

Argh.

It's not just the file system -- it will list things like "Google Drive" and "Dropbox" etc.

>> We heard loud and clear that developers wanted richer access beyond these directories

And over-engineered it by a factor of 10 or so...

Just need to wait for my G3 to get the 5.0.


Title: Re: Is it possible to tell Aquamail where to save the majority of its data?
Post by: pyler on December 04, 2014, 11:55:04 pm
Not only cloud drives, you can pick any folder in the device too afaik.

Many file managers are document providers so in SAF you can select directory even by your favourite file manager.
Title: Re: Is it possible to tell Aquamail where to save the majority of its data?
Post by: Kostya Vasilyev on December 05, 2014, 01:34:36 am
Actually, seems to work -- I've only tried the "picking" part, not actually creating documents there yet...

As for file manager integration -- I've got Solid Explorer, and it does show when picking *files*, but does not show when doing this new "pick root directory" thing. I guess that part's not implemented yet (I mean in Solid Explorer).

The good part though, is that Google Drive didn't show. It would be weird to have the "save" folder be in the cloud.