summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSantos Cordon <santoscordon@google.com>2013-09-10 19:56:05 -0700
committerSantos Cordon <santoscordon@google.com>2013-09-11 11:42:30 -0700
commit3b0b9918292d394b3895f9d98cbbfc17a85b8f70 (patch)
tree82d3781466183f386e2484ee7027ed0fc09c0cbd
parent60fc683f685060c575ae070d8573e9d21462c57d (diff)
Make creations and destruction of InCallUI system queued.
We queue creating and destroying of the world into the message handler so that it happens in order with the other actions that are queued into the message handler. bug: 10682538 Change-Id: I28a21d97861468528186e823ba9021446e9b08c3
-rw-r--r--InCallUI/src/com/android/incallui/CallHandlerService.java106
-rw-r--r--InCallUI/src/com/android/incallui/Log.java2
2 files changed, 67 insertions, 41 deletions
diff --git a/InCallUI/src/com/android/incallui/CallHandlerService.java b/InCallUI/src/com/android/incallui/CallHandlerService.java
index dccdcdf32..65665494f 100644
--- a/InCallUI/src/com/android/incallui/CallHandlerService.java
+++ b/InCallUI/src/com/android/incallui/CallHandlerService.java
@@ -46,54 +46,51 @@ public class CallHandlerService extends Service {
private static final int ON_DISCONNECT_CALL = 6;
private static final int ON_BRING_TO_FOREGROUND = 7;
private static final int ON_POST_CHAR_WAIT = 8;
+ private static final int ON_CREATE = 9;
+ private static final int ON_DESTROY = 10;
- private static final int LARGEST_MSG_ID = ON_POST_CHAR_WAIT;
+ private static final int LARGEST_MSG_ID = ON_DESTROY;
private CallList mCallList;
private Handler mMainHandler;
+ private Object mHandlerInitLock = new Object();
private InCallPresenter mInCallPresenter;
private AudioModeProvider mAudioModeProvider;
@Override
public void onCreate() {
- Log.i(this, "creating");
+ Log.i(this, "onCreate");
super.onCreate();
- mMainHandler = new MainHandler();
- mCallList = CallList.getInstance();
- mAudioModeProvider = AudioModeProvider.getInstance();
- mInCallPresenter = InCallPresenter.getInstance();
+ synchronized(mHandlerInitLock) {
+ if (mMainHandler == null) {
+ mMainHandler = new MainHandler();
+ }
+ }
- mInCallPresenter.setUp(getApplicationContext(), mCallList, mAudioModeProvider);
- Log.d(this, "onCreate finished");
+ // Creation (and destruction) are sent to the message handler. The reason for this is that
+ // at any time the service could potentially unbind for both legitimate reasons as well as
+ // app crashes and it's better to queue up create/destroy because:
+ // (1) Previous actions like onUpdate/onDisconnect could be queued up and we dont want to
+ // destroy the system from a different thread in the middle of executing those actions.
+ // (2) If we queue up destruction we must also queue up creation or else we risk having a
+ // second "create" happen before the first "destroy".
+ // (e.g., create1, queue destroy1, create2, do destroy1)
+ mMainHandler.sendMessage(mMainHandler.obtainMessage(ON_CREATE));
+
+ // TODO: consider optimization of checking to see if any ON_DESTROY messages exist
+ // in the queue and in those cases simply remove the pending message.
}
@Override
public void onDestroy() {
- Log.i(this, "destroying");
-
- // Remove all pending messages before nulling out handler
- for (int i = 1; i <= LARGEST_MSG_ID; i++) {
- mMainHandler.removeMessages(i);
- }
- mMainHandler = null;
-
- // The service gets disconnected under two circumstances:
- // 1. When there are no more calls
- // 2. When the phone app crashes.
- // If (2) happens, we can't leave the UI thinking that there are still
- // live calls. So we will tell the callList to clear as a final request.
- mCallList.clearOnDisconnect();
- mCallList = null;
-
- mInCallPresenter.tearDown();
- mInCallPresenter = null;
- mAudioModeProvider = null;
+ Log.i(this, "onDestroy");
- Log.d(this, "onDestroy finished");
+ mMainHandler.sendMessage(mMainHandler.obtainMessage(ON_DESTROY));
}
+
@Override
public IBinder onBind(Intent intent) {
Log.i(this, "onBind");
@@ -124,7 +121,6 @@ public class CallHandlerService extends Service {
@Override
public void onDisconnect(Call call) {
try {
- Log.i(CallHandlerService.this, "onDisconnected: " + call);
mMainHandler.sendMessage(mMainHandler.obtainMessage(ON_DISCONNECT_CALL, call));
} catch (Exception e) {
Log.e(TAG, "Error processing onDisconnect() call.", e);
@@ -134,12 +130,8 @@ public class CallHandlerService extends Service {
@Override
public void onIncoming(Call call, List<String> textResponses) {
try {
- Log.i(CallHandlerService.this, "onIncomingCall: " + call);
-
- // TODO(klp): Add text responses to the call object.
Map.Entry<Call, List<String>> incomingCall
= new AbstractMap.SimpleEntry<Call, List<String>>(call, textResponses);
- Log.d("TEST", mMainHandler.toString());
mMainHandler.sendMessage(mMainHandler.obtainMessage(
ON_UPDATE_CALL_WITH_TEXT_RESPONSES, incomingCall));
} catch (Exception e) {
@@ -150,9 +142,6 @@ public class CallHandlerService extends Service {
@Override
public void onUpdate(List<Call> calls) {
try {
- Log.i(CallHandlerService.this, "onUpdate " + calls.toString());
-
- // TODO(klp): Add use of fullUpdate to message
mMainHandler.sendMessage(mMainHandler.obtainMessage(ON_UPDATE_MULTI_CALL, calls));
} catch (Exception e) {
Log.e(TAG, "Error processing onUpdate() call.", e);
@@ -162,7 +151,6 @@ public class CallHandlerService extends Service {
@Override
public void onAudioModeChange(int mode, boolean muted) {
try {
- Log.i(CallHandlerService.this, "onAudioModeChange : " + AudioMode.toString(mode));
mMainHandler.sendMessage(mMainHandler.obtainMessage(ON_AUDIO_MODE, mode,
muted ? 1 : 0, null));
} catch (Exception e) {
@@ -173,9 +161,6 @@ public class CallHandlerService extends Service {
@Override
public void onSupportedAudioModeChange(int modeMask) {
try {
- Log.i(CallHandlerService.this, "onSupportedAudioModeChange : " + AudioMode.toString(
- modeMask));
-
mMainHandler.sendMessage(mMainHandler.obtainMessage(ON_SUPPORTED_AUDIO_MODE,
modeMask, 0, null));
} catch (Exception e) {
@@ -195,6 +180,32 @@ public class CallHandlerService extends Service {
}
};
+ private void doCreate() {
+ Log.i(this, "doCreate");
+
+ mCallList = CallList.getInstance();
+ mAudioModeProvider = AudioModeProvider.getInstance();
+ mInCallPresenter = InCallPresenter.getInstance();
+
+ mInCallPresenter.setUp(getApplicationContext(), mCallList, mAudioModeProvider);
+ }
+
+ public void doDestroy() {
+ Log.i(this, "doDestroy");
+
+ // The service gets disconnected under two circumstances:
+ // 1. When there are no more calls
+ // 2. When the phone app crashes.
+ // If (2) happens, we can't leave the UI thinking that there are still
+ // live calls. So we will tell the callList to clear as a final request.
+ mCallList.clearOnDisconnect();
+ mCallList = null;
+
+ mInCallPresenter.tearDown();
+ mInCallPresenter = null;
+ mAudioModeProvider = null;
+ }
+
/**
* Handles messages from the service so that they get executed on the main thread, where they
* can interact with UI.
@@ -221,26 +232,35 @@ public class CallHandlerService extends Service {
switch (msg.what) {
case ON_UPDATE_CALL:
+ Log.i(CallHandlerService.this, "onUpdate: " + msg.obj);
mCallList.onUpdate((Call) msg.obj);
break;
case ON_UPDATE_MULTI_CALL:
+ Log.i(CallHandlerService.this, "onUpdateMulti: " + msg.obj);
mCallList.onUpdate((List<Call>) msg.obj);
break;
case ON_UPDATE_CALL_WITH_TEXT_RESPONSES:
AbstractMap.SimpleEntry<Call, List<String>> entry
= (AbstractMap.SimpleEntry<Call, List<String>>) msg.obj;
+ Log.i(CallHandlerService.this, "onIncomingCall: " + entry.getKey());
mCallList.onIncoming(entry.getKey(), entry.getValue());
break;
case ON_DISCONNECT_CALL:
+ Log.i(CallHandlerService.this, "onDisconnected: " + msg.obj);
mCallList.onDisconnect((Call) msg.obj);
break;
case ON_POST_CHAR_WAIT:
mInCallPresenter.onPostDialCharWait(msg.arg1, (String) msg.obj);
break;
case ON_AUDIO_MODE:
+ Log.i(CallHandlerService.this, "onAudioModeChange : " +
+ AudioMode.toString(msg.arg1) + ", muted (" + (msg.arg2 == 1) + ")");
mAudioModeProvider.onAudioModeChange(msg.arg1, msg.arg2 == 1);
break;
case ON_SUPPORTED_AUDIO_MODE:
+ Log.i(CallHandlerService.this, "onSupportedAudioModeChange : " + AudioMode.toString(
+ msg.arg1));
+
mAudioModeProvider.onSupportedAudioModeChange(msg.arg1);
break;
case ON_BRING_TO_FOREGROUND:
@@ -248,6 +268,12 @@ public class CallHandlerService extends Service {
mInCallPresenter.bringToForeground();
}
break;
+ case ON_CREATE:
+ doCreate();
+ break;
+ case ON_DESTROY:
+ doDestroy();
+ break;
default:
break;
}
diff --git a/InCallUI/src/com/android/incallui/Log.java b/InCallUI/src/com/android/incallui/Log.java
index bc57ed7d7..3099ea56b 100644
--- a/InCallUI/src/com/android/incallui/Log.java
+++ b/InCallUI/src/com/android/incallui/Log.java
@@ -30,7 +30,7 @@ public class Log {
public static void d(String tag, String msg) {
if (DEBUG) {
- android.util.Log.d(TAG, tag + msg);
+ android.util.Log.d(TAG, tag + " - " + msg);
}
}