Renaming CallMonitorService to CallHandlerService
Change-Id: Idfbbf79f706ff359f218252f74d2e8133188d93a
diff --git a/src/com/android/phone/CallHandlerServiceProxy.java b/src/com/android/phone/CallHandlerServiceProxy.java
new file mode 100644
index 0000000..cb1e188
--- /dev/null
+++ b/src/com/android/phone/CallHandlerServiceProxy.java
@@ -0,0 +1,123 @@
+/*
+ * 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 android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.os.AsyncResult;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.Message;
+import android.os.RemoteException;
+import android.os.SystemProperties;
+import android.util.Log;
+
+import com.android.services.telephony.common.ICallHandlerService;
+import com.android.services.telephony.common.ICallCommandService;
+
+/**
+ * This class is responsible for passing through call state changes to the CallHandlerService.
+ */
+public class CallHandlerServiceProxy extends Handler {
+
+ private static final String TAG = CallHandlerServiceProxy.class.getSimpleName();
+ private static final boolean DBG =
+ (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
+ private static final boolean VDBG = (PhoneGlobals.DBG_LEVEL >= 2);
+
+ private Context mContext;
+ private CallStateMonitor mCallStateMonitor;
+ private ServiceConnection mConnection;
+ private ICallHandlerService mCallHandlerService;
+ private CallCommandService mCallCommandService;
+
+ public CallHandlerServiceProxy(Context context, CallStateMonitor callStateMonitor,
+ CallCommandService callCommandService) {
+ mContext = context;
+ mCallStateMonitor = callStateMonitor;
+ mCallCommandService = callCommandService;
+
+ mCallStateMonitor.addListener(this);
+ setupServiceConnection();
+ }
+
+ @Override
+ public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case CallStateMonitor.PHONE_NEW_RINGING_CONNECTION:
+ onNewRingingConnection((AsyncResult) msg.obj);
+ break;
+
+ default:
+ //super.handleMessage(msg);
+ break;
+ }
+ }
+
+ /**
+ * Sets up the connection with ICallHandlerService
+ */
+ private void setupServiceConnection() {
+ mConnection = new ServiceConnection() {
+ @Override
+ public void onServiceConnected(ComponentName className, IBinder service) {
+ if (DBG) {
+ Log.d(TAG, "Service Connected");
+ }
+ onCallHandlerServiceConnected(ICallHandlerService.Stub.asInterface(service));
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName className) {
+ mCallHandlerService = null;
+ }
+ };
+
+ Intent serviceIntent = new Intent(ICallHandlerService.class.getName());
+ if (!mContext.bindService(serviceIntent, mConnection, Context.BIND_AUTO_CREATE)) {
+ Log.e(TAG, "Cound not bind to ICallHandlerService");
+ }
+ }
+
+ /**
+ * Called when the in-call UI service is connected. Send command interface to in-call.
+ */
+ private void onCallHandlerServiceConnected(ICallHandlerService CallHandlerService) {
+ mCallHandlerService = CallHandlerService;
+
+ try {
+ mCallHandlerService.setCallCommandService(mCallCommandService);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Remote exception calling CallHandlerService::onConnected. " + e);
+ }
+ }
+
+ /**
+ * Send notification of a new incoming call.
+ */
+ private void onNewRingingConnection(AsyncResult result) {
+ if (mCallHandlerService != null) {
+ try {
+ mCallHandlerService.onIncomingCall(0);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Remote exception handling onIncomingCall:" + e);
+ }
+ }
+ }
+}