[tbb-bugs] #30239 [Applications/Tor Browser]: TBA: Gracefully handle auto-restart after crash

Tor Bug Tracker & Wiki blackhole at torproject.org
Thu May 2 00:30:23 UTC 2019


#30239: TBA: Gracefully handle auto-restart after crash
-------------------------------------------------+-------------------------
 Reporter:  sysrqb                               |          Owner:  tbb-
                                                 |  team
     Type:  defect                               |         Status:
                                                 |  needs_review
 Priority:  Medium                               |      Milestone:
Component:  Applications/Tor Browser             |        Version:
 Severity:  Normal                               |     Resolution:
 Keywords:  tbb-mobile tbb-8.5-must              |  Actual Points:
  TorBrowserTeam201904                           |
Parent ID:                                       |         Points:
 Reviewer:                                       |        Sponsor:
-------------------------------------------------+-------------------------
Changes (by sysrqb):

 * status:  new => needs_review


Comment:

 This required more debugging. TorService setting `START_STICKY` was a red
 herring and has no connection with this bug, as far as I can see. After
 stepping through the code with the debugger, I found this bug is caused
 because the UI is not created exactly the same when the app is first
 started compared with after the app is killed and it is restarted.

 In the first instance, when the app is started the first time, the UI
 components are created in the logical order (started at the root View,
 each layer is created on top of the previous layer).

 However, when the app is restarting after a crash or being killed, some UI
 components are created earlier than we expect. Specifically, the
 `TorBootstrap{,Log}Panel` Fragments are recreated by Android's
 FragmentManager early in the app startup process because the
 FragmentManager caches this information about the fragments previously
 existing. However, these fragments are created before the app creates the
 ViewPager (`TorBootstrapPager`) which is the underlying container of the
 Fragments. As a result, the Fragments are created without a parent, and
 the ViewPager isn't told about these fragments when it is created.
 Therefore, after all the Views and UI components are created, the
 ViewPager has zero children and the Fragments have a `null` parent
 reference.

 This seems like a bug other app developers would experience too, so there
 may be a more Androidy-way of correctly handling this situation, but I
 didn't see it.

 The first commit is only simplifying existing code, the second commit is
 similar and moves Fragment instantiation from `getItem()` to the
 Constructor. The third commit is the bugfix. When
 `TorBootstrapPager.load()` is called, we instantiate a new
 `ViewPagerAdapter` and call `setAdapter()` as we did before, but now we
 iterate over the Adapter's items and call `addView()` if that item's
 `getView().getParent()` is `null`.

 Branch `bug30239_02`. This is tested on Android 19, 23, and 28.

 The easiest steps for reproducing are:
 1. Launch app normally
 1. Press "Home" button so Tor Browser goes into the background and you see
 the your device's home screen
 1. run `adb shell am kill org.torproject.torbrowser_alpha` (substitute
 `adb` with whatever you need so it works)
 1. Open the "Recent Apps" menu and select Tor Browser

 Without this proposed patch, you should see a blank purple screen, and
 with this patch you should see the expected bootstrapping screen.

 In logcat, you should see something like this when you successfully kill
 the app:

 (Android 19)
 {{{
 D/AndroidRuntime( 3996): Calling main entry com.android.commands.am.Am
 D/AndroidRuntime( 3996): Shutting down VM
 I/ActivityManager( 1603): Killing
 3845:org.torproject.torbrowser_alpha/u0a62 (adj 7): kill background
 D/jdwp    ( 3996): Got wake-up signal, bailing out of select
 D/dalvikvm( 3996): Debugger has detached; object registry had 1 entries
 W/InputDispatcher( 1603): channel '9d2c4198
 org.torproject.torbrowser_alpha/org.mozilla.gecko.BrowserApp (server)' ~
 Consumer closed input channel or an error occurred.  events=0x9
 E/InputDispatcher( 1603): channel '9d2c4198
 org.torproject.torbrowser_alpha/org.mozilla.gecko.BrowserApp (server)' ~
 Channel is unrecoverably broken and will be disposed!
 W/InputDispatcher( 1603): Attempted to unregister already unregistered
 input channel '9d2c4198
 org.torproject.torbrowser_alpha/org.mozilla.gecko.BrowserApp (server)'
 I/WindowState( 1603): WIN DEATH: Window{9d2d2278 u0 SurfaceView}
 I/WindowState( 1603): WIN DEATH: Window{9d2c4198 u0
 org.torproject.torbrowser_alpha/org.mozilla.gecko.BrowserApp}
 }}}

 (Android 23)
 {{{
 05-01 23:05:19.533  8002  8002 D AndroidRuntime: Calling main entry
 com.android.commands.am.Am
 05-01 23:05:19.534  1597  2804 I ActivityManager: Killing
 7895:org.torproject.torbrowser_alpha/u0a143 (adj 7): kill background
 05-01 23:05:19.546  1597  1637 W InputDispatcher: channel 'cf88dca
 org.torproject.torbrowser_alpha/org.mozilla.gecko.BrowserApp (server)' ~
 Consumer closed input channel or an error occurred.  events=0x9
 05-01 23:05:19.546  1597  1637 E InputDispatcher: channel 'cf88dca
 org.torproject.torbrowser_alpha/org.mozilla.gecko.BrowserApp (server)' ~
 Channel is unrecoverably broken and will be disposed!
 05-01 23:05:19.548  1597  1609 D GraphicsStats: Buffer count: 4
 05-01 23:05:19.548  1597  2649 I WindowState: WIN DEATH: Window{cf88dca u0
 org.torproject.torbrowser_alpha/org.mozilla.gecko.BrowserApp}
 05-01 23:05:19.548  1597  2649 W InputDispatcher: Attempted to unregister
 already unregistered input channel 'cf88dca
 org.torproject.torbrowser_alpha/org.mozilla.gecko.BrowserApp (server)'
 05-01 23:05:19.548  1597  2649 W WindowManager: Force-removing child win
 Window{8b0b2a3 u0 SurfaceView} from container Window{cf88dca u0
 org.torproject.torbrowser_alpha/org.mozilla.gecko.BrowserApp}
 05-01 23:05:19.552  1597  2185 W WindowManager: Failed looking up window
 05-01 23:05:19.552  1597  2185 W WindowManager:
 java.lang.IllegalArgumentException: Requested window
 android.os.BinderProxy at ff9bc96 does not exist
 05-01 23:05:19.552  1597  2185 W WindowManager:         at
 com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:8733)
 05-01 23:05:19.552  1597  2185 W WindowManager:         at
 com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:8724)
 05-01 23:05:19.552  1597  2185 W WindowManager:         at
 com.android.server.wm.WindowState$DeathRecipient.binderDied(WindowState.java:1209)
 05-01 23:05:19.552  1597  2185 W WindowManager:         at
 android.os.BinderProxy.sendDeathNotice(Binder.java:558)
 05-01 23:05:19.552  1597  2185 I WindowState: WIN DEATH: null
 05-01 23:05:19.617  1597  2804 W ActivityManager: Scheduling restart of
 crashed service
 org.torproject.torbrowser_alpha/org.mozilla.gecko.media.MediaControlService
 in 1000ms
 05-01 23:05:19.617  1597  2804 W ActivityManager: Scheduling restart of
 crashed service
 org.torproject.torbrowser_alpha/org.torproject.android.service.TorService
 in 1000ms
 05-01 23:05:19.618  8002  8002 D AndroidRuntime: Shutting down VM
 05-01 23:05:19.618  1597  1721 W ActivityManager: Spurious death for
 ProcessRecord{6bbe9a0 0:org.torproject.torbrowser_alpha/u0a143}, curProc
 for 7895: null
 }}}

--
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/30239#comment:7>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online


More information about the tbb-bugs mailing list