blob: 587214a68df951434b42a1b6742b1ef6a9165a5a [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;
21
Ben Gilad0407fb22014-01-09 16:18:41 -080022import java.util.Date;
23
Ben Gilad2495d572014-01-09 17:26:19 -080024/**
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 Gilad0407fb22014-01-09 16:18:41 -080029final class Call {
30
Ben Gilad0bf5b912014-01-28 17:55:57 -080031 /**
32 * Unique identifier for the call as a UUID string.
33 */
34 private final String mId;
35
Santos Cordon0b03b4b2014-01-29 18:01:59 -080036 /**
37 * The state of the call.
38 */
39 private CallState mState;
40
Ben Gilad0407fb22014-01-09 16:18:41 -080041 /** The handle with which to establish this call. */
Ben Gilad0bf5b912014-01-28 17:55:57 -080042 private final String mHandle;
Ben Gilad0407fb22014-01-09 16:18:41 -080043
44 /** Additional contact information beyond handle above, optional. */
Ben Gilad0bf5b912014-01-28 17:55:57 -080045 private final ContactInfo mContactInfo;
Ben Gilad0407fb22014-01-09 16:18:41 -080046
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 Cordon0b03b4b2014-01-29 18:01:59 -080056 * Read-only and parcelable version of this call.
57 */
58 private CallInfo mCallInfo;
59
60 /**
Ben Gilad0407fb22014-01-09 16:18:41 -080061 * 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 Gilad0bf5b912014-01-28 17:55:57 -080066 Call(String handle, ContactInfo contactInfo) {
67 // TODO(gilad): Pass this in etc.
68 mId = "dummy";
Santos Cordon0b03b4b2014-01-29 18:01:59 -080069 mState = CallState.NEW;
Ben Gilad0407fb22014-01-09 16:18:41 -080070 mHandle = handle;
71 mContactInfo = contactInfo;
Ben Gilad0407fb22014-01-09 16:18:41 -080072 mCreationTime = new Date();
73 }
74
Ben Gilad0bf5b912014-01-28 17:55:57 -080075 String getId() {
76 return mId;
77 }
78
Santos Cordon0b03b4b2014-01-29 18:01:59 -080079 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 Gilad0bf5b912014-01-28 17:55:57 -080094 String getHandle() {
95 return mHandle;
96 }
97
98 ContactInfo getContactInfo() {
99 return mContactInfo;
100 }
101
Ben Gilad0407fb22014-01-09 16:18:41 -0800102 /**
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 Gilad0bf5b912014-01-28 17:55:57 -0800106 long getAgeInMilliseconds() {
Ben Gilad0407fb22014-01-09 16:18:41 -0800107 return new Date().getTime() - mCreationTime.getTime();
108 }
Santos Cordon0b03b4b2014-01-29 18:01:59 -0800109
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 Gilad9f2bed32013-12-12 17:43:26 -0800126}