Adding a command interface to control phone calls.
Adds a command interface implementation to use with incall ui.
Change-Id: I337754ccc991b423481cda3bde17232e93a8014f
diff --git a/src/com/android/phone/CallCommandService.java b/src/com/android/phone/CallCommandService.java
new file mode 100644
index 0000000..c0f8c67
--- /dev/null
+++ b/src/com/android/phone/CallCommandService.java
@@ -0,0 +1,58 @@
+/**
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.phone;
+
+import com.android.internal.telephony.CallManager;
+import com.android.services.telephony.common.ICallCommandService;
+
+/**
+ * Service interface used by in-call ui to control phone calls using commands
+ * exposed as methods. Instances of this class are handed to in-call UI via
+ * CallMonitorService.
+ */
+class CallCommandService extends ICallCommandService.Stub {
+
+ private CallManager mCallManager;
+
+ public CallCommandService(CallManager callManager) {
+ mCallManager = callManager;
+ }
+
+ /**
+ * TODO(klp): Add a confirmation callback parameter.
+ */
+ @Override
+ public void answerCall(int callId) {
+ // TODO(klp): Change to using the callId and logic from InCallScreen::internalAnswerCall
+ PhoneUtils.answerCall(mCallManager.getFirstActiveRingingCall());
+ }
+
+ /**
+ * TODO(klp): Add a confirmation callback parameter.
+ */
+ @Override
+ public void rejectCall(int callId) {
+ // TODO(klp): Change to using the callId
+ PhoneUtils.hangupRingingCall(mCallManager.getFirstActiveRingingCall());
+ }
+
+ @Override
+ public void disconnectCall(int callId) {
+ // TODO(klp): Change to using the callId
+ PhoneUtils.hangup(mCallManager);
+ }
+}
diff --git a/src/com/android/phone/CallMonitorServiceProxy.java b/src/com/android/phone/CallMonitorServiceProxy.java
index 8865038..8339bba 100644
--- a/src/com/android/phone/CallMonitorServiceProxy.java
+++ b/src/com/android/phone/CallMonitorServiceProxy.java
@@ -29,6 +29,7 @@
import android.util.Log;
import com.android.services.telephony.common.ICallMonitorService;
+import com.android.services.telephony.common.ICallCommandService;
/**
* This class is responsible for passing through call state changes to the CallMonitorService.
@@ -44,10 +45,13 @@
private CallStateMonitor mCallStateMonitor;
private ServiceConnection mConnection;
private ICallMonitorService mCallMonitorService;
+ private CallCommandService mCallCommandService;
- public CallMonitorServiceProxy(Context context, CallStateMonitor callStateMonitor) {
+ public CallMonitorServiceProxy(Context context, CallStateMonitor callStateMonitor,
+ CallCommandService callCommandService) {
mContext = context;
mCallStateMonitor = callStateMonitor;
+ mCallCommandService = callCommandService;
mCallStateMonitor.addListener(this);
setupServiceConnection();
@@ -76,7 +80,7 @@
if (DBG) {
Log.d(TAG, "Service Connected");
}
- mCallMonitorService = ICallMonitorService.Stub.asInterface(service);
+ onCallMonitorServiceConnected(ICallMonitorService.Stub.asInterface(service));
}
@Override
@@ -92,12 +96,25 @@
}
/**
+ * Called when the in-call UI service is connected. Send command interface to in-call.
+ */
+ private void onCallMonitorServiceConnected(ICallMonitorService callMonitorService) {
+ mCallMonitorService = callMonitorService;
+
+ try {
+ mCallMonitorService.setCallCommandService(mCallCommandService);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Remote exception calling CallMonitorService::onConnected. " + e);
+ }
+ }
+
+ /**
* Send notification of a new incoming call.
*/
private void onNewRingingConnection(AsyncResult result) {
if (mCallMonitorService != null) {
try {
- mCallMonitorService.onIncomingCall(42);
+ mCallMonitorService.onIncomingCall(0);
} catch (RemoteException e) {
Log.e(TAG, "Remote exception handling onIncomingCall:" + e);
}
diff --git a/src/com/android/phone/PhoneGlobals.java b/src/com/android/phone/PhoneGlobals.java
index 865ad75..e4989dc 100644
--- a/src/com/android/phone/PhoneGlobals.java
+++ b/src/com/android/phone/PhoneGlobals.java
@@ -173,6 +173,7 @@
CallManager mCM;
CallStateMonitor callStateMonitor;
CallMonitorServiceProxy callMonitorServiceProxy;
+ CallCommandService callCommandService;
int mBluetoothHeadsetState = BluetoothProfile.STATE_DISCONNECTED;
int mBluetoothHeadsetAudioState = BluetoothHeadset.STATE_AUDIO_DISCONNECTED;
boolean mShowBluetoothIndication = false;
@@ -537,8 +538,12 @@
// Monitors call activity from the telephony layer
callStateMonitor = new CallStateMonitor(mCM);
+ // Service used by in-call UI to control calls
+ callCommandService = new CallCommandService(mCM);
+
// Sends call state to the UI
- callMonitorServiceProxy = new CallMonitorServiceProxy(this, callStateMonitor);
+ callMonitorServiceProxy = new CallMonitorServiceProxy(this, callStateMonitor,
+ callCommandService);
// Create the CallNotifer singleton, which handles
// asynchronous events from the telephony layer (like