Shared media draft disappears after reboot, orphaned PersistentBlobProvider file
While working on another issue, I found a handful of orphaned files in app_captures, at a time when I had no draft media messages pending. I narrowed down these steps to reproduce consistently, yet there may be other ways to reproduce the issue.
Steps to reproduce (UPDATED)
adb shell ls -la /data/data/org.thoughtcrime.securesms/app_captures/to verify contents- Select a photo or video in Gallery/Photos
- Share the media with Signal
- Select a contact and note the time
- Observe the draft media message in the Conversation
- Tap
Back(this saves the draft media message) - Tap on the Conversation to open it again
- OPTIONAL: Tap
Home(callsonPause(), but notonDestroy()) adb reboot, install a new build, or otherActivity-killing action that does not callonDestroy()- Open Signal
- Observe the draft media message in the Conversation List
- Tap the Conversation
- Behold the disappearance of the draft media message
adb shell ls -la /data/data/org.thoughtcrime.securesms/app_captures/- Behold the orphaned, a-bit-too-persistent blob file
Device info: Nexus 5, stock Android 6.0 MRA58K, Signal 3.5.0 (d21fe51), 3.5.1 (6a18824)
App state: Signal registered, SMS enabled, default SMS app
I'm having intermittent luck reproducing this tonight. I'll update when I have a better repro script.
EDIT: script updated above.
I've noticed this pre-3.5.0. I think this should go to 3.6.0 to speed up the .1 release.
this sounds like a DraftDatabase issue?
I can work on this only intermittently right now, so I'm going to post findings as I go.
ADDING THE ATTACHMENT
-
After selecting the recipient (note, no
DraftDatabaseactivity)W/ConversationActivity: onCreate() W/PassphraseRequiredActionBarActivity: onResume() W/AttachmentManager: slide with size XXX took 78ms W/ThumbnailView: loading part with id content://org.thoughtcrime.securesms/capture/XXX/XXX, progress 1
DRAFT EXISTS
-
File in
/data/data/org.thoughtcrime.securesms/app_captures/ -
Record in
draftstable -
On opening the conversation:
D/ConversationActivity: initializeDraftFromDatabase(), doInBackground(), threadId= 4 D/DatabaseFactory: getDraftDatabase(context) D/DraftDatabase: getDrafts(4), results: [org.thoughtcrime.securesms.database.DraftDatabase$Draft@2ef9e02] D/DraftDatabase: clearDrafts(4) D/ConversationActivity: initializeDraftFromDatabase(), onPostExecute(), threadId= 4, drafts=[org.thoughtcrime.securesms.database.DraftDatabase$Draft@XXXXXXX] D/ConversationActivity: initializeDraftFromDatabase(), onPostExecute(), setMedia(Uri.parse(content://org.thoughtcrime.securesms/capture/XXXXXXXXXXXXX/XXXXXXXXXXXXX), MediaType.VIDEO) -
On pressing
Backfrom the conversation, draft remainsD/ConversationActivity: onDestroy() D/ConversationActivity: saveDraft() D/DatabaseFactory: getDraftDatabase(context) W/PassphraseRequiredActionBarActivity: onDestroy() D/DraftDatabase: insertDrafts(thread_id=4 type=XXX value=XXX) W/AttachmentManager: slide with size XXX took 102ms W/ThumbnailView: loading part with id content://org.thoughtcrime.securesms/capture/XXX/XXX, progress 1 -
On killing Signal from Overview/Recents with conversation open, draft remains
W/PassphraseRequiredActionBarActivity: onDestroy() D/ConversationActivity: onDestroy() D/ConversationActivity: saveDraft() W/PassphraseRequiredActionBarActivity: onDestroy() D/DatabaseFactory: getDraftDatabase(context) D/DraftDatabase: insertDrafts(thread_id=4 type=XXX value=XXX) -
On pressing
Homefrom the conversation (rebooting from here makes the draft disappear)D/ConversationActivity: onPause() D/ConversationActivity: onStop()
DRAFT GONE
-
File in
/data/data/org.thoughtcrime.securesms/app_captures/ -
NO RECORD in
draftstable -
On opening the conversation:
D/ConversationActivity: initializeDraftFromDatabase(), doInBackground(), threadId= 4 D/DatabaseFactory: getDraftDatabase(context) D/DraftDatabase: getDrafts(4), results: [] D/DraftDatabase: clearDrafts(4) D/ConversationActivity: initializeDraftFromDatabase(), onPostExecute(), threadId= 4, drafts=[]
From ConversationActivity.java
@Override
protected void onDestroy() {
saveDraft();
From Activity | Android Developers:
protected void onDestroy ()
Note: do not count on this method being called as a place for saving data! For example, if an activity is editing data in a content provider, those edits should be committed in either onPause() or onSaveInstanceState(Bundle), not here.
Moving saveDraft() to onPause() will help when the user performs an action on the Conversation that calls onPause() before killing the app; however, it will NOT help if the user performs an app-killing action that doesn't call onPause(). This will require reworking the draft editing and saving process, which may also partially or completely address #4680.
I'll submit a PR within the next day or two.
Updated all three diagnostic posts above on this issue.
If the conversation is open and you restart the phone, will onPause() be called?
@agrajaghh :
If the conversation is open and you restart the phone, will
onPause()be called?
-
adb reboot: NoE/(): Device disconnected -
Power button: Yes, but not
onDestroy()D/ShutdownThread: Notifying thread to start shutdown longPressBehavior=1 I/ShutdownThread: Sending shutdown broadcast... D/ShutDownListener: ACTION_SHUTDOWN Received, waiting for oemhook readiness callback I/ShutdownThread: Shutting down activity manager... W/PassphraseRequiredActionBarActivity: onPause() D/ConversationActivity: onPause() W/KeyCachingService: onStartCommand, org.thoughtcrime.securesms.service.action.ACTIVITY_STOP_EVENT W/KeyCachingService: Decrementing activity count... D/ConversationActivity: onStop() -
Lightning strikes, other acts of God: I assume not :stuck_out_tongue_winking_eye:
And for the sake of thoroughness:
-
Installing a new build: No
I/ActivityManager: Force stopping org.thoughtcrime.securesms appid=XXX user=-1: uninstall pkg I/ActivityManager: Killing XXX:org.thoughtcrime.securesms/XXX (adj 0): stop org.thoughtcrime.securesms I/WindowState: WIN DEATH: Window{XXX u0 org.thoughtcrime.securesms/org.thoughtcrime.securesms.ConversationActivity}
adb reboot: No
Lightning strikes, other acts of God: I assume not
thats okay I guess...
Installing a new build: No
Android is so weird sometimes... :grimacing:
thats okay I guess...
I'm testing moving saveDraft() to onPause(). Will try to create any other scenarios which normal users may encounter and see if it breaks. If it tests well, I'll submit a PR.
Thanks for the feedback!
GitHub Issue Cleanup: See #7598 for more information.