diff options
author | Yorke Lee <yorkelee@google.com> | 2014-11-06 19:20:54 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-11-06 19:20:54 +0000 |
commit | 21fbe6a137aae0c479558cce8456424a2e23a97a (patch) | |
tree | 6d06bb923c2077b528f4b55e0e34e411bc25985d /InCallUI | |
parent | 573e18569a4293a523e14e6185f22f2ec33c6abc (diff) | |
parent | ccc5064e1df33c0480f5edf67cd9c358b58a99f9 (diff) |
am 30fd6cd5: Merge "Make setting and unsetting InCallPresenter.mInCallActivity more robust" into lmp-mr1-dev
* commit '30fd6cd5b348e087568a0acd67fa0cf5549f8103':
Make setting and unsetting InCallPresenter.mInCallActivity more robust
Diffstat (limited to 'InCallUI')
-rw-r--r-- | InCallUI/src/com/android/incallui/InCallActivity.java | 9 | ||||
-rw-r--r-- | InCallUI/src/com/android/incallui/InCallPresenter.java | 49 |
2 files changed, 45 insertions, 13 deletions
diff --git a/InCallUI/src/com/android/incallui/InCallActivity.java b/InCallUI/src/com/android/incallui/InCallActivity.java index 1444b11ce..ead4170e4 100644 --- a/InCallUI/src/com/android/incallui/InCallActivity.java +++ b/InCallUI/src/com/android/incallui/InCallActivity.java @@ -32,7 +32,6 @@ import android.graphics.Point; import android.net.Uri; import android.os.Bundle; import android.telecom.DisconnectCause; -import android.telecom.PhoneAccount; import android.telecom.PhoneAccountHandle; import android.telecom.TelecomManager; import android.telephony.PhoneNumberUtils; @@ -236,6 +235,10 @@ public class InCallActivity extends Activity { } InCallPresenter.getInstance().onUiShowing(false); + + if (isFinishing()) { + InCallPresenter.getInstance().unsetActivity(this); + } } @Override @@ -247,9 +250,7 @@ public class InCallActivity extends Activity { @Override protected void onDestroy() { Log.d(this, "onDestroy()... this = " + this); - - InCallPresenter.getInstance().setActivity(null); - + InCallPresenter.getInstance().unsetActivity(this); super.onDestroy(); } diff --git a/InCallUI/src/com/android/incallui/InCallPresenter.java b/InCallUI/src/com/android/incallui/InCallPresenter.java index bd81f1036..ec30ee1fa 100644 --- a/InCallUI/src/com/android/incallui/InCallPresenter.java +++ b/InCallUI/src/com/android/incallui/InCallPresenter.java @@ -243,11 +243,44 @@ public class InCallPresenter implements CallList.Listener, InCallPhoneListener { } /** - * Called when the UI begins or ends. Starts the callstate callbacks if the UI just began. - * Attempts to tear down everything if the UI just ended. See #tearDown for more insight on - * the tear-down process. + * Called when the UI begins, and starts the callstate callbacks if necessary. */ public void setActivity(InCallActivity inCallActivity) { + if (inCallActivity == null) { + throw new IllegalArgumentException("registerActivity cannot be called with null"); + } + if (mInCallActivity != null && mInCallActivity != inCallActivity) { + Log.wtf(this, "Setting a second activity before destroying the first."); + } + updateActivity(inCallActivity); + } + + /** + * Called when the UI ends. Attempts to tear down everything if necessary. See + * {@link #tearDown()} for more insight on the tear-down process. + */ + public void unsetActivity(InCallActivity inCallActivity) { + if (inCallActivity == null) { + throw new IllegalArgumentException("unregisterActivity cannot be called with null"); + } + if (mInCallActivity == null) { + Log.i(this, "No InCallActivity currently set, no need to unset."); + return; + } + if (mInCallActivity != inCallActivity) { + Log.w(this, "Second instance of InCallActivity is trying to unregister when another" + + " instance is active. Ignoring."); + return; + } + updateActivity(null); + } + + /** + * Updates the current instance of {@link InCallActivity} with the provided one. If a + * {@code null} activity is provided, it means that the activity was finished and we should + * attempt to cleanup. + */ + private void updateActivity(InCallActivity inCallActivity) { boolean updateListeners = false; boolean doAttemptCleanup = false; @@ -255,8 +288,6 @@ public class InCallPresenter implements CallList.Listener, InCallPhoneListener { if (mInCallActivity == null) { updateListeners = true; Log.i(this, "UI Initialized"); - } else if (mInCallActivity != inCallActivity) { - Log.wtf(this, "Setting a second activity before destroying the first."); } else { // since setActivity is called onStart(), it can be called multiple times. // This is fine and ignorable, but we do not want to update the world every time @@ -278,18 +309,18 @@ public class InCallPresenter implements CallList.Listener, InCallPhoneListener { // NOTE: This code relies on {@link #mInCallActivity} being set so we run it after // it has been set. if (mInCallState == InCallState.NO_CALLS) { - Log.i(this, "UI Intialized, but no calls left. shut down."); + Log.i(this, "UI Initialized, but no calls left. shut down."); attemptFinishActivity(); return; } } else { - Log.i(this, "UI Destroyed)"); + Log.i(this, "UI Destroyed"); updateListeners = true; mInCallActivity = null; // We attempt cleanup for the destroy case but only after we recalculate the state - // to see if we need to come back up or stay shut down. This is why we do the cleanup - // after the call to onCallListChange() instead of directly here. + // to see if we need to come back up or stay shut down. This is why we do the + // cleanup after the call to onCallListChange() instead of directly here. doAttemptCleanup = true; } |