Signal-Android icon indicating copy to clipboard operation
Signal-Android copied to clipboard

Shared media draft disappears after reboot, orphaned PersistentBlobProvider file

Open unrulygnu opened this issue 11 years ago • 11 comments

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)

  1. adb shell ls -la /data/data/org.thoughtcrime.securesms/app_captures/ to verify contents
  2. Select a photo or video in Gallery/Photos
  3. Share the media with Signal
  4. Select a contact and note the time
  5. Observe the draft media message in the Conversation
  6. Tap Back (this saves the draft media message)
  7. Tap on the Conversation to open it again
  8. OPTIONAL: Tap Home (calls onPause(), but not onDestroy())
  9. adb reboot, install a new build, or other Activity-killing action that does not call onDestroy()
  10. Open Signal
  11. Observe the draft media message in the Conversation List
  12. Tap the Conversation
  13. Behold the disappearance of the draft media message
  14. adb shell ls -la /data/data/org.thoughtcrime.securesms/app_captures/
  15. 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

unrulygnu avatar Nov 22 '15 10:11 unrulygnu

I'm having intermittent luck reproducing this tonight. I'll update when I have a better repro script.

EDIT: script updated above.

unrulygnu avatar Nov 23 '15 18:11 unrulygnu

I've noticed this pre-3.5.0. I think this should go to 3.6.0 to speed up the .1 release.

mcginty avatar Nov 23 '15 19:11 mcginty

this sounds like a DraftDatabase issue?

mcginty avatar Nov 24 '15 01:11 mcginty

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 DraftDatabase activity)

    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 drafts table

  • 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 Back from the conversation, draft remains

    D/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 Home from 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 drafts table

  • 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=[]
    

unrulygnu avatar Nov 24 '15 09:11 unrulygnu

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.

unrulygnu avatar Nov 24 '15 09:11 unrulygnu

Updated all three diagnostic posts above on this issue.

unrulygnu avatar Nov 24 '15 14:11 unrulygnu

If the conversation is open and you restart the phone, will onPause() be called?

agrajaghh avatar Nov 24 '15 14:11 agrajaghh

@agrajaghh :

If the conversation is open and you restart the phone, will onPause() be called?

  • adb reboot: No

    E/(): 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}
    

unrulygnu avatar Nov 24 '15 15:11 unrulygnu

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:

agrajaghh avatar Nov 24 '15 15:11 agrajaghh

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!

unrulygnu avatar Nov 24 '15 15:11 unrulygnu

GitHub Issue Cleanup: See #7598 for more information.

automated-signal avatar Apr 02 '18 23:04 automated-signal