Chiao Cheng | e41661c | 2013-07-23 13:28:26 -0700 | [diff] [blame^] | 1 | /* |
Santos Cordon | cba1b44 | 2013-07-18 12:43:58 -0700 | [diff] [blame] | 2 | * 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 Cheng | e41661c | 2013-07-23 13:28:26 -0700 | [diff] [blame^] | 14 | * limitations under the License |
Santos Cordon | cba1b44 | 2013-07-18 12:43:58 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | package com.android.phone; |
| 18 | |
Chiao Cheng | e41661c | 2013-07-23 13:28:26 -0700 | [diff] [blame^] | 19 | import android.content.Context; |
| 20 | import android.util.Log; |
| 21 | |
Santos Cordon | cba1b44 | 2013-07-18 12:43:58 -0700 | [diff] [blame] | 22 | import com.android.internal.telephony.CallManager; |
| 23 | import com.android.services.telephony.common.ICallCommandService; |
| 24 | |
| 25 | /** |
Chiao Cheng | e41661c | 2013-07-23 13:28:26 -0700 | [diff] [blame^] | 26 | * 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 Cordon | cba1b44 | 2013-07-18 12:43:58 -0700 | [diff] [blame] | 28 | */ |
| 29 | class CallCommandService extends ICallCommandService.Stub { |
| 30 | |
Chiao Cheng | e41661c | 2013-07-23 13:28:26 -0700 | [diff] [blame^] | 31 | private static final String TAG = CallCommandService.class.getSimpleName(); |
| 32 | |
| 33 | private Context mContext; |
Santos Cordon | cba1b44 | 2013-07-18 12:43:58 -0700 | [diff] [blame] | 34 | private CallManager mCallManager; |
| 35 | |
Chiao Cheng | e41661c | 2013-07-23 13:28:26 -0700 | [diff] [blame^] | 36 | public CallCommandService(Context context, CallManager callManager) { |
| 37 | mContext = context; |
Santos Cordon | cba1b44 | 2013-07-18 12:43:58 -0700 | [diff] [blame] | 38 | mCallManager = callManager; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * TODO(klp): Add a confirmation callback parameter. |
| 43 | */ |
| 44 | @Override |
| 45 | public void answerCall(int callId) { |
Chiao Cheng | e41661c | 2013-07-23 13:28:26 -0700 | [diff] [blame^] | 46 | 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 Cordon | cba1b44 | 2013-07-18 12:43:58 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | /** |
| 55 | * TODO(klp): Add a confirmation callback parameter. |
| 56 | */ |
| 57 | @Override |
| 58 | public void rejectCall(int callId) { |
Chiao Cheng | e41661c | 2013-07-23 13:28:26 -0700 | [diff] [blame^] | 59 | 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 Cordon | cba1b44 | 2013-07-18 12:43:58 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public void disconnectCall(int callId) { |
Chiao Cheng | e41661c | 2013-07-23 13:28:26 -0700 | [diff] [blame^] | 69 | 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 Cordon | cba1b44 | 2013-07-18 12:43:58 -0700 | [diff] [blame] | 94 | } |
| 95 | } |