blob: 9f9a692f674d3405b9414e02c183591aadffde09 [file] [log] [blame]
Ben Gilad0407fb22014-01-09 16:18:41 -08001/*
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 Gilad9f2bed32013-12-12 17:43:26 -080017package com.android.telecomm;
18
Santos Cordon0b03b4b2014-01-29 18:01:59 -080019import android.telecomm.CallInfo;
20import android.telecomm.CallState;
Santos Cordon681663d2014-01-30 04:32:15 -080021import android.telecomm.ICallService;
Santos Cordon0b03b4b2014-01-29 18:01:59 -080022
Ben Gilad0407fb22014-01-09 16:18:41 -080023import java.util.Date;
24
Ben Gilad2495d572014-01-09 17:26:19 -080025/**
26 * Encapsulates all aspects of a given phone call throughout its lifecycle, starting
27 * from the time the call intent was received by Telecomm (vs. the time the call was
28 * connected etc).
29 */
Ben Gilad0407fb22014-01-09 16:18:41 -080030final class Call {
31
Ben Gilad0bf5b912014-01-28 17:55:57 -080032 /**
33 * Unique identifier for the call as a UUID string.
34 */
35 private final String mId;
36
Santos Cordon0b03b4b2014-01-29 18:01:59 -080037 /**
38 * The state of the call.
39 */
40 private CallState mState;
41
Ben Gilad0407fb22014-01-09 16:18:41 -080042 /** The handle with which to establish this call. */
Ben Gilad0bf5b912014-01-28 17:55:57 -080043 private final String mHandle;
Ben Gilad0407fb22014-01-09 16:18:41 -080044
45 /** Additional contact information beyond handle above, optional. */
Ben Gilad0bf5b912014-01-28 17:55:57 -080046 private final ContactInfo mContactInfo;
Ben Gilad0407fb22014-01-09 16:18:41 -080047
48 /**
49 * The time this call was created, typically also the time this call was added to the set
50 * of pending outgoing calls (mPendingOutgoingCalls) that's maintained by the switchboard.
51 * Beyond logging and such, may also be used for bookkeeping and specifically for marking
52 * certain call attempts as failed attempts.
53 */
54 private final Date mCreationTime;
55
56 /**
Santos Cordon681663d2014-01-30 04:32:15 -080057 * The call service which is currently connecting this call, null as long as the call is not
58 * connected.
59 */
60 private ICallService mCallService;
61
62 /**
Santos Cordon0b03b4b2014-01-29 18:01:59 -080063 * Read-only and parcelable version of this call.
64 */
65 private CallInfo mCallInfo;
66
67 /**
Ben Gilad0407fb22014-01-09 16:18:41 -080068 * Persists the specified parameters and initializes the new instance.
69 *
70 * @param handle The handle to dial.
71 * @param contactInfo Information about the entity being called.
72 */
Ben Gilad0bf5b912014-01-28 17:55:57 -080073 Call(String handle, ContactInfo contactInfo) {
74 // TODO(gilad): Pass this in etc.
75 mId = "dummy";
Santos Cordon0b03b4b2014-01-29 18:01:59 -080076 mState = CallState.NEW;
Ben Gilad0407fb22014-01-09 16:18:41 -080077 mHandle = handle;
78 mContactInfo = contactInfo;
Ben Gilad0407fb22014-01-09 16:18:41 -080079 mCreationTime = new Date();
80 }
81
Ben Gilad0bf5b912014-01-28 17:55:57 -080082 String getId() {
83 return mId;
84 }
85
Santos Cordon0b03b4b2014-01-29 18:01:59 -080086 CallState getState() {
87 return mState;
88 }
89
90 /**
91 * Sets the call state. Although there exists the notion of appropriate state transitions
92 * (see {@link CallState}), in practice those expectations break down when cellular systems
93 * misbehave and they do this very often. The result is that we do not enforce state transitions
94 * and instead keep the code resilient to unexpected state changes.
95 */
96 void setState(CallState state) {
97 mState = state;
98 clearCallInfo();
99 }
100
Ben Gilad0bf5b912014-01-28 17:55:57 -0800101 String getHandle() {
102 return mHandle;
103 }
104
105 ContactInfo getContactInfo() {
106 return mContactInfo;
107 }
108
Ben Gilad0407fb22014-01-09 16:18:41 -0800109 /**
110 * @return The "age" of this call object in milliseconds, which typically also represents the
111 * period since this call was added to the set pending outgoing calls, see mCreationTime.
112 */
Ben Gilad0bf5b912014-01-28 17:55:57 -0800113 long getAgeInMilliseconds() {
Ben Gilad0407fb22014-01-09 16:18:41 -0800114 return new Date().getTime() - mCreationTime.getTime();
115 }
Santos Cordon0b03b4b2014-01-29 18:01:59 -0800116
Santos Cordon681663d2014-01-30 04:32:15 -0800117 ICallService getCallService() {
118 return mCallService;
119 }
120
121 void setCallService(ICallService callService) {
122 mCallService = callService;
123 }
124
125 /**
126 * Clears the associated call service.
127 */
128 void clearCallService() {
129 setCallService(null);
130 }
131
Santos Cordon0b03b4b2014-01-29 18:01:59 -0800132 /**
133 * @return An object containing read-only information about this call.
134 */
135 CallInfo toCallInfo() {
136 if (mCallInfo == null) {
137 mCallInfo = new CallInfo(mId, mState, mHandle);
138 }
139 return mCallInfo;
140 }
141
142 /**
143 * Resets the cached read-only version of this call.
144 */
145 private void clearCallInfo() {
146 mCallInfo = null;
147 }
Ben Gilad9f2bed32013-12-12 17:43:26 -0800148}