summaryrefslogtreecommitdiff
path: root/InCallUI
diff options
context:
space:
mode:
authorYorke Lee <yorkelee@google.com>2014-11-06 21:07:51 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-11-06 21:07:51 +0000
commitc2274ab6e3760b05a028b841ab3cf4adb17dcb69 (patch)
tree0bff156b7389128e8976c0a39863a702a6016d46 /InCallUI
parent087d1c6462b3f474cf9f7011fb30fb6c7ac400cd (diff)
parentda3eb2e6151add52e9ca12297a443831fd22e1d9 (diff)
am eeb53d4c: am 60016104: am 30fd6cd5: Merge "Make setting and unsetting InCallPresenter.mInCallActivity more robust" into lmp-mr1-dev
* commit 'eeb53d4c597acd056a76679bf894ad82eb79b833': Make setting and unsetting InCallPresenter.mInCallActivity more robust
Diffstat (limited to 'InCallUI')
-rw-r--r--InCallUI/src/com/android/incallui/InCallActivity.java9
-rw-r--r--InCallUI/src/com/android/incallui/InCallPresenter.java49
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;
}