blob: 6a0ef2f32d21b06978965e5acb64fb4ed88bb5af [file] [log] [blame]
Chiao Chenge41661c2013-07-23 13:28:26 -07001/*
Santos Cordoncba1b442013-07-18 12:43:58 -07002 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
Chiao Chenge41661c2013-07-23 13:28:26 -070014 * limitations under the License
Santos Cordoncba1b442013-07-18 12:43:58 -070015 */
16
17package com.android.phone;
18
Chiao Chenge41661c2013-07-23 13:28:26 -070019import android.content.Context;
20import android.util.Log;
21
Santos Cordoncba1b442013-07-18 12:43:58 -070022import com.android.internal.telephony.CallManager;
23import com.android.services.telephony.common.ICallCommandService;
24
25/**
Chiao Chenge41661c2013-07-23 13:28:26 -070026 * Service interface used by in-call ui to control phone calls using commands exposed as methods.
27 * Instances of this class are handed to in-call UI via CallMonitorService.
Santos Cordoncba1b442013-07-18 12:43:58 -070028 */
29class CallCommandService extends ICallCommandService.Stub {
30
Chiao Chenge41661c2013-07-23 13:28:26 -070031 private static final String TAG = CallCommandService.class.getSimpleName();
32
33 private Context mContext;
Santos Cordoncba1b442013-07-18 12:43:58 -070034 private CallManager mCallManager;
35
Chiao Chenge41661c2013-07-23 13:28:26 -070036 public CallCommandService(Context context, CallManager callManager) {
37 mContext = context;
Santos Cordoncba1b442013-07-18 12:43:58 -070038 mCallManager = callManager;
39 }
40
41 /**
42 * TODO(klp): Add a confirmation callback parameter.
43 */
44 @Override
45 public void answerCall(int callId) {
Chiao Chenge41661c2013-07-23 13:28:26 -070046 try {
47 // TODO(klp): Change to using the callId and logic from InCallScreen::internalAnswerCall
48 PhoneUtils.answerCall(mCallManager.getFirstActiveRingingCall());
49 } catch (Exception e) {
50 Log.e(TAG, "Error during answerCall().", e);
51 }
Santos Cordoncba1b442013-07-18 12:43:58 -070052 }
53
54 /**
55 * TODO(klp): Add a confirmation callback parameter.
56 */
57 @Override
58 public void rejectCall(int callId) {
Chiao Chenge41661c2013-07-23 13:28:26 -070059 try {
60 // TODO(klp): Change to using the callId
61 PhoneUtils.hangupRingingCall(mCallManager.getFirstActiveRingingCall());
62 } catch (Exception e) {
63 Log.e(TAG, "Error during rejectCall().", e);
64 }
Santos Cordoncba1b442013-07-18 12:43:58 -070065 }
66
67 @Override
68 public void disconnectCall(int callId) {
Chiao Chenge41661c2013-07-23 13:28:26 -070069 try {
70 // TODO(klp): Change to using the callId
71 PhoneUtils.hangup(mCallManager);
72 } catch (Exception e) {
73 Log.e(TAG, "Error during disconnectCall().", e);
74 }
75 }
76
77 @Override
78 public void mute(boolean onOff) {
79 try {
80 PhoneUtils.setMute(onOff);
81 } catch (Exception e) {
82 Log.e(TAG, "Error during mute().", e);
83 }
84 }
85
86 @Override
87 public void speaker(boolean onOff) {
88 try {
89 // TODO(klp): add bluetooth logic from InCallScreen.toggleSpeaker()
90 PhoneUtils.turnOnSpeaker(mContext, onOff, true);
91 } catch (Exception e) {
92 Log.e(TAG, "Error during speaker().", e);
93 }
Santos Cordoncba1b442013-07-18 12:43:58 -070094 }
95}