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 | /** |
| 63 | * TODO(santoscordon): Rename to handleIncomingCall. |
| 64 | * {@inheritDoc} |
| 65 | */ |
| 66 | @Override public void newIncomingCall(CallInfo callInfo) { |
| 67 | // TODO(santoscordon): fill in. |
| 68 | } |
| 69 | |
| 70 | /** {@inheritDoc} */ |
| 71 | @Override public void handleSuccessfulOutgoingCall(final String callId) { |
| 72 | checkValidCallId(callId); |
| 73 | mHandler.post(new Runnable() { |
| 74 | @Override public void run() { |
| 75 | mOutgoingCallsManager.handleSuccessfulCallAttempt(callId); |
| 76 | } |
| 77 | }); |
| 78 | } |
| 79 | |
| 80 | /** {@inheritDoc} */ |
| 81 | @Override public void handleFailedOutgoingCall(final String callId, final String reason) { |
| 82 | checkValidCallId(callId); |
| 83 | mHandler.post(new Runnable() { |
| 84 | @Override public void run() { |
| 85 | mOutgoingCallsManager.handleFailedCallAttempt(callId, reason); |
| 86 | } |
| 87 | }); |
| 88 | } |
| 89 | |
| 90 | /** {@inheritDoc} */ |
| 91 | @Override public void setActive(final String callId) { |
| 92 | checkValidCallId(callId); |
| 93 | mHandler.post(new Runnable() { |
| 94 | @Override public void run() { |
| 95 | mCallsManager.markCallAsActive(callId); |
| 96 | } |
| 97 | }); |
| 98 | } |
| 99 | |
| 100 | /** {@inheritDoc} */ |
| 101 | @Override public void setRinging(final String callId) { |
| 102 | checkValidCallId(callId); |
| 103 | mHandler.post(new Runnable() { |
| 104 | @Override public void run() { |
| 105 | mCallsManager.markCallAsRinging(callId); |
| 106 | } |
| 107 | }); |
| 108 | } |
| 109 | |
| 110 | /** {@inheritDoc} */ |
| 111 | @Override public void setDialing(final String callId) { |
| 112 | checkValidCallId(callId); |
| 113 | mHandler.post(new Runnable() { |
| 114 | @Override public void run() { |
| 115 | mCallsManager.markCallAsDialing(callId); |
| 116 | } |
| 117 | }); |
| 118 | } |
| 119 | |
| 120 | /** {@inheritDoc} */ |
| 121 | @Override public void setDisconnected(final String callId) { |
| 122 | checkValidCallId(callId); |
| 123 | mHandler.post(new Runnable() { |
| 124 | @Override public void run() { |
| 125 | mCallsManager.markCallAsDisconnected(callId); |
| 126 | } |
| 127 | }); |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Throws an IllegalArgumentException if the specified call ID is invalid. |
| 132 | * |
| 133 | * @param callId The call ID to check. |
| 134 | */ |
| 135 | private void checkValidCallId(String callId) { |
| 136 | if (Strings.isNullOrEmpty(callId)) { |
| 137 | throw new IllegalArgumentException(); |
| 138 | } |
| 139 | } |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 140 | } |