Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 17 | package com.android.telecomm; |
| 18 | |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 19 | import android.os.Handler; |
| 20 | import android.os.Looper; |
| 21 | import android.telecomm.CallInfo; |
| 22 | import android.telecomm.ICallServiceAdapter; |
| 23 | |
| 24 | import com.google.common.base.Strings; |
| 25 | |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 26 | /** |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 27 | * Used by call services in order to update state and control calls while the call service is bound |
| 28 | * to Telecomm. Each call service is given its own instance for the lifetime of the binding between |
| 29 | * Telecomm and the call service. |
| 30 | * TODO(santoscordon): Whenever we get any method invocations from the call service, we need to |
| 31 | * check that the invocation is expected from that call service. |
| 32 | * TODO(santoscordon): Move away from Runnable objects and into messages so that we create fewer |
| 33 | * objects per IPC method call. |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 34 | */ |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 35 | public final class CallServiceAdapter extends ICallServiceAdapter.Stub { |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 36 | |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 37 | private final CallsManager mCallsManager; |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 38 | |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 39 | private final OutgoingCallsManager mOutgoingCallsManager; |
| 40 | |
| 41 | /** Used to run code (e.g. messages, Runnables) on the main (UI) thread. */ |
| 42 | private final Handler mHandler = new Handler(Looper.getMainLooper()); |
| 43 | |
| 44 | /** |
| 45 | * Persists the specified parameters. |
| 46 | */ |
| 47 | CallServiceAdapter(OutgoingCallsManager outgoingCallsManager) { |
| 48 | mCallsManager = CallsManager.getInstance(); |
| 49 | mOutgoingCallsManager = outgoingCallsManager; |
| 50 | } |
| 51 | |
| 52 | /** {@inheritDoc} */ |
| 53 | @Override public void getNextCallId() { |
| 54 | // TODO(santoscordon): needs response object. |
| 55 | } |
| 56 | |
| 57 | /** {@inheritDoc} */ |
| 58 | @Override public void setCompatibleWith(String callId, boolean isCompatible) { |
| 59 | // TODO(santoscordon): fill in. |
| 60 | } |
| 61 | |
| 62 | /** |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 63 | * {@inheritDoc} |
| 64 | */ |
Ben Gilad | 13329fd | 2014-02-11 17:20:29 -0800 | [diff] [blame^] | 65 | @Override public void handleIncomingCall(CallInfo callInfo) { |
Santos Cordon | 681663d | 2014-01-30 04:32:15 -0800 | [diff] [blame] | 66 | // TODO(santoscordon): fill in. |
| 67 | } |
| 68 | |
| 69 | /** {@inheritDoc} */ |
| 70 | @Override public void handleSuccessfulOutgoingCall(final String callId) { |
| 71 | checkValidCallId(callId); |
| 72 | mHandler.post(new Runnable() { |
| 73 | @Override public void run() { |
| 74 | mOutgoingCallsManager.handleSuccessfulCallAttempt(callId); |
| 75 | } |
| 76 | }); |
| 77 | } |
| 78 | |
| 79 | /** {@inheritDoc} */ |
| 80 | @Override public void handleFailedOutgoingCall(final String callId, final String reason) { |
| 81 | checkValidCallId(callId); |
| 82 | mHandler.post(new Runnable() { |
| 83 | @Override public void run() { |
| 84 | mOutgoingCallsManager.handleFailedCallAttempt(callId, reason); |
| 85 | } |
| 86 | }); |
| 87 | } |
| 88 | |
| 89 | /** {@inheritDoc} */ |
| 90 | @Override public void setActive(final String callId) { |
| 91 | checkValidCallId(callId); |
| 92 | mHandler.post(new Runnable() { |
| 93 | @Override public void run() { |
| 94 | mCallsManager.markCallAsActive(callId); |
| 95 | } |
| 96 | }); |
| 97 | } |
| 98 | |
| 99 | /** {@inheritDoc} */ |
| 100 | @Override public void setRinging(final String callId) { |
| 101 | checkValidCallId(callId); |
| 102 | mHandler.post(new Runnable() { |
| 103 | @Override public void run() { |
| 104 | mCallsManager.markCallAsRinging(callId); |
| 105 | } |
| 106 | }); |
| 107 | } |
| 108 | |
| 109 | /** {@inheritDoc} */ |
| 110 | @Override public void setDialing(final String callId) { |
| 111 | checkValidCallId(callId); |
| 112 | mHandler.post(new Runnable() { |
| 113 | @Override public void run() { |
| 114 | mCallsManager.markCallAsDialing(callId); |
| 115 | } |
| 116 | }); |
| 117 | } |
| 118 | |
| 119 | /** {@inheritDoc} */ |
| 120 | @Override public void setDisconnected(final String callId) { |
| 121 | checkValidCallId(callId); |
| 122 | mHandler.post(new Runnable() { |
| 123 | @Override public void run() { |
| 124 | mCallsManager.markCallAsDisconnected(callId); |
| 125 | } |
| 126 | }); |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Throws an IllegalArgumentException if the specified call ID is invalid. |
| 131 | * |
| 132 | * @param callId The call ID to check. |
| 133 | */ |
| 134 | private void checkValidCallId(String callId) { |
| 135 | if (Strings.isNullOrEmpty(callId)) { |
| 136 | throw new IllegalArgumentException(); |
| 137 | } |
| 138 | } |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 139 | } |