diff options
author | Santos Cordon <santoscordon@google.com> | 2013-09-05 13:22:07 -0700 |
---|---|---|
committer | Santos Cordon <santoscordon@google.com> | 2013-09-09 12:18:12 -0700 |
commit | 1f63d2d8e8db3616c16886952813b3d0473216e7 (patch) | |
tree | 9ffb5c9a744cc5679c59091e617c00acc4209193 /InCallUI/src/com/android/incallui/InCallActivity.java | |
parent | 24deb0f78f1854bfc273bb888e7fd4ac123bcc22 (diff) |
Improve lifecycle ordering for InCallUI
This CL rearranges startup and teardown of InCallUI to reduce the number
of race conditions resulting in runtime exceptions and app crashes.
At a high level this CL fixes the following:
- TeleService should be able to unbind and rebind at any time without
causing problems in the UI. (Fixes to InCallPresenter)
- On weird occasions we were seeing secondary UIs pop up if we
rebound while the older UI was still up and one of the UIs would be
orphaned on the foreground.
- call notifications can be sent during (1) activity startup, (2)
activity lifetime, (3) activity destruction, (4) no activity...and
nothing should crash.
- Lots of crashes when notifications came during destruction and
startup. (Fixed setup in InCallActivity + presenters, and
startup/teardown ordering in InCallPresenter)
Details:
(1) InCallPresenter handed out instances of member classes to the UI
classes, but upon unbinding and rebinding, the classes were
recreated. This meant that the activity which was potentially still up
had stale versions of AudioModeProvider and ProximitySensor.
- Classes created/used by CallHandlerService are now singletons so that
they do not change from one bind to the other. If the service tries
to initialize InCallPresenter while the activity is still up (and so
we haven't yet torn down) we reuse the reuse the previous
initialization since there is no need to recreate them, and classes
in the Activity dont ever become stale.
(2) We were recreating new copies of InCallActivity on updates that
occur while tearing down the previous activity. This caused weird
errors where second emptier activities were up after all calls ended.
- Solution to this was to ignore all updates while we are finishing the
activity. When the activity is finally finished, we check if we
should bring up a new activity in case some update came while we were
finishing.
(3) We set listeners on presenters from a parent class that wasn't aware
of UI transitions.
- All Presenters are not responsible for setting and unsetting their
listeners. This allows them to unset them before their UI goes away.
+ renamed HIDDEN to NO_CALLS as hidden was confusing to developers
which associated the term with foreground/backgroundness of the app.
+ Improved some logging
bug:10573125
Change-Id: I2d1af6a6e972b3b3bd93af839054e879f0b74b4f
Diffstat (limited to 'InCallUI/src/com/android/incallui/InCallActivity.java')
-rw-r--r-- | InCallUI/src/com/android/incallui/InCallActivity.java | 37 |
1 files changed, 5 insertions, 32 deletions
diff --git a/InCallUI/src/com/android/incallui/InCallActivity.java b/InCallUI/src/com/android/incallui/InCallActivity.java index 6cae6b05e..fb9f99c10 100644 --- a/InCallUI/src/com/android/incallui/InCallActivity.java +++ b/InCallUI/src/com/android/incallui/InCallActivity.java @@ -58,14 +58,17 @@ public class InCallActivity extends Activity { // Inflate everything in incall_screen.xml and add it to the screen. setContentView(R.layout.incall_screen); + initializeInCall(); Log.d(this, "onCreate(): exit"); } @Override protected void onStart() { + Log.d(this, "onStart()..."); super.onStart(); - initializeInCall(); + // setting activity should be last thing in setup process + InCallPresenter.getInstance().setActivity(this); } @Override @@ -98,7 +101,7 @@ public class InCallActivity extends Activity { protected void onDestroy() { Log.d(this, "onDestroy()... this = " + this); - tearDownPresenters(); + InCallPresenter.getInstance().setActivity(null); super.onDestroy(); } @@ -293,36 +296,6 @@ public class InCallActivity extends Activity { .findFragmentById(R.id.conferenceManagerFragment); mConferenceManagerFragment.getView().setVisibility(View.INVISIBLE); } - setUpPresenterCallbacks(); - } - - private void setUpPresenterCallbacks() { - InCallPresenter mainPresenter = InCallPresenter.getInstance(); - - mCallButtonFragment.getPresenter().setAudioModeProvider( - mainPresenter.getAudioModeProvider()); - mCallButtonFragment.getPresenter().setProximitySensor( - mainPresenter.getProximitySensor()); - final CallCardPresenter presenter = mCallCardFragment.getPresenter(); - presenter.setAudioModeProvider(mainPresenter.getAudioModeProvider()); - - mainPresenter.addListener(mCallButtonFragment.getPresenter()); - mainPresenter.addListener(mCallCardFragment.getPresenter()); - mainPresenter.addListener(mConferenceManagerFragment.getPresenter()); - - // setting activity should be last thing in setup process - mainPresenter.setActivity(this); - } - - private void tearDownPresenters() { - Log.d(this, "Tearing down presenters."); - InCallPresenter mainPresenter = InCallPresenter.getInstance(); - - mainPresenter.removeListener(mCallButtonFragment.getPresenter()); - mainPresenter.removeListener(mCallCardFragment.getPresenter()); - mainPresenter.removeListener(mConferenceManagerFragment.getPresenter()); - - mainPresenter.setActivity(null); } private void toast(String text) { |