Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -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 | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 19 | import android.telecomm.CallInfo; |
| 20 | import android.telecomm.CallState; |
| 21 | |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 22 | import java.util.Date; |
| 23 | |
Ben Gilad | 2495d57 | 2014-01-09 17:26:19 -0800 | [diff] [blame] | 24 | /** |
| 25 | * Encapsulates all aspects of a given phone call throughout its lifecycle, starting |
| 26 | * from the time the call intent was received by Telecomm (vs. the time the call was |
| 27 | * connected etc). |
| 28 | */ |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 29 | final class Call { |
| 30 | |
Ben Gilad | 0bf5b91 | 2014-01-28 17:55:57 -0800 | [diff] [blame] | 31 | /** |
| 32 | * Unique identifier for the call as a UUID string. |
| 33 | */ |
| 34 | private final String mId; |
| 35 | |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 36 | /** |
| 37 | * The state of the call. |
| 38 | */ |
| 39 | private CallState mState; |
| 40 | |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 41 | /** The handle with which to establish this call. */ |
Ben Gilad | 0bf5b91 | 2014-01-28 17:55:57 -0800 | [diff] [blame] | 42 | private final String mHandle; |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 43 | |
| 44 | /** Additional contact information beyond handle above, optional. */ |
Ben Gilad | 0bf5b91 | 2014-01-28 17:55:57 -0800 | [diff] [blame] | 45 | private final ContactInfo mContactInfo; |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 46 | |
| 47 | /** |
| 48 | * The time this call was created, typically also the time this call was added to the set |
| 49 | * of pending outgoing calls (mPendingOutgoingCalls) that's maintained by the switchboard. |
| 50 | * Beyond logging and such, may also be used for bookkeeping and specifically for marking |
| 51 | * certain call attempts as failed attempts. |
| 52 | */ |
| 53 | private final Date mCreationTime; |
| 54 | |
| 55 | /** |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 56 | * Read-only and parcelable version of this call. |
| 57 | */ |
| 58 | private CallInfo mCallInfo; |
| 59 | |
| 60 | /** |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 61 | * Persists the specified parameters and initializes the new instance. |
| 62 | * |
| 63 | * @param handle The handle to dial. |
| 64 | * @param contactInfo Information about the entity being called. |
| 65 | */ |
Ben Gilad | 0bf5b91 | 2014-01-28 17:55:57 -0800 | [diff] [blame] | 66 | Call(String handle, ContactInfo contactInfo) { |
| 67 | // TODO(gilad): Pass this in etc. |
| 68 | mId = "dummy"; |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 69 | mState = CallState.NEW; |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 70 | mHandle = handle; |
| 71 | mContactInfo = contactInfo; |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 72 | mCreationTime = new Date(); |
| 73 | } |
| 74 | |
Ben Gilad | 0bf5b91 | 2014-01-28 17:55:57 -0800 | [diff] [blame] | 75 | String getId() { |
| 76 | return mId; |
| 77 | } |
| 78 | |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 79 | CallState getState() { |
| 80 | return mState; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Sets the call state. Although there exists the notion of appropriate state transitions |
| 85 | * (see {@link CallState}), in practice those expectations break down when cellular systems |
| 86 | * misbehave and they do this very often. The result is that we do not enforce state transitions |
| 87 | * and instead keep the code resilient to unexpected state changes. |
| 88 | */ |
| 89 | void setState(CallState state) { |
| 90 | mState = state; |
| 91 | clearCallInfo(); |
| 92 | } |
| 93 | |
Ben Gilad | 0bf5b91 | 2014-01-28 17:55:57 -0800 | [diff] [blame] | 94 | String getHandle() { |
| 95 | return mHandle; |
| 96 | } |
| 97 | |
| 98 | ContactInfo getContactInfo() { |
| 99 | return mContactInfo; |
| 100 | } |
| 101 | |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 102 | /** |
| 103 | * @return The "age" of this call object in milliseconds, which typically also represents the |
| 104 | * period since this call was added to the set pending outgoing calls, see mCreationTime. |
| 105 | */ |
Ben Gilad | 0bf5b91 | 2014-01-28 17:55:57 -0800 | [diff] [blame] | 106 | long getAgeInMilliseconds() { |
Ben Gilad | 0407fb2 | 2014-01-09 16:18:41 -0800 | [diff] [blame] | 107 | return new Date().getTime() - mCreationTime.getTime(); |
| 108 | } |
Santos Cordon | 0b03b4b | 2014-01-29 18:01:59 -0800 | [diff] [blame] | 109 | |
| 110 | /** |
| 111 | * @return An object containing read-only information about this call. |
| 112 | */ |
| 113 | CallInfo toCallInfo() { |
| 114 | if (mCallInfo == null) { |
| 115 | mCallInfo = new CallInfo(mId, mState, mHandle); |
| 116 | } |
| 117 | return mCallInfo; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Resets the cached read-only version of this call. |
| 122 | */ |
| 123 | private void clearCallInfo() { |
| 124 | mCallInfo = null; |
| 125 | } |
Ben Gilad | 9f2bed3 | 2013-12-12 17:43:26 -0800 | [diff] [blame] | 126 | } |