summaryrefslogtreecommitdiff
path: root/InCallUI/src/com/android/incallui/Call.java
blob: 71698d6a8e8dc0c9dfa2880b8e8147ff0fe769a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/*
 * Copyright (C) 2013 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.incallui;

import android.net.Uri;
import android.telecomm.CallCapabilities;
import android.telecomm.CallNumberPresentation;
import android.telecomm.CallServiceDescriptor;
import android.telecomm.GatewayInfo;
import android.telecomm.Subscription;
import android.telephony.DisconnectCause;

import com.google.common.collect.ImmutableSortedSet;
import com.google.common.primitives.Ints;

import java.util.Collections;
import java.util.List;
import java.util.Locale;

/**
 * Class object used across CallHandlerService APIs.
 * Describes a single call and its state.
 */
public final class Call {
    /* Defines different states of this call */
    public static class State {
        public static final int INVALID = 0;
        public static final int IDLE = 1;           /* The call is idle.  Nothing active */
        public static final int ACTIVE = 2;         /* There is an active call */
        public static final int INCOMING = 3;       /* A normal incoming phone call */
        public static final int CALL_WAITING = 4;   /* Incoming call while another is active */
        public static final int DIALING = 5;        /* An outgoing call during dial phase */
        public static final int REDIALING = 6;      /* Subsequent dialing attempt after a failure */
        public static final int ONHOLD = 7;         /* An active phone call placed on hold */
        public static final int DISCONNECTING = 8;  /* A call is being ended. */
        public static final int DISCONNECTED = 9;   /* State after a call disconnects */
        public static final int CONFERENCED = 10;   /* Call part of a conference call */

        public static boolean isConnected(int state) {
            switch(state) {
                case ACTIVE:
                case INCOMING:
                case CALL_WAITING:
                case DIALING:
                case REDIALING:
                case ONHOLD:
                case CONFERENCED:
                    return true;
                default:
            }
            return false;
        }

        public static boolean isDialing(int state) {
            return state == DIALING || state == REDIALING;
        }

        public static String toString(int state) {
            switch (state) {
                case INVALID:
                    return "INVALID";
                case IDLE:
                    return "IDLE";
                case ACTIVE:
                    return "ACTIVE";
                case INCOMING:
                    return "INCOMING";
                case CALL_WAITING:
                    return "CALL_WAITING";
                case DIALING:
                    return "DIALING";
                case REDIALING:
                    return "REDIALING";
                case ONHOLD:
                    return "ONHOLD";
                case DISCONNECTING:
                    return "DISCONNECTING";
                case DISCONNECTED:
                    return "DISCONNECTED";
                case CONFERENCED:
                    return "CONFERENCED";
                default:
                    return "UNKOWN";
            }
        }
    }

    private String mCallId;
    private int mState = State.INVALID;
    private int mDisconnectCause = DisconnectCause.NOT_VALID;
    private List<String> mCannedSmsResponses = Collections.EMPTY_LIST;
    private int mCapabilities;
    private long mConnectTimeMillis = 0;
    private Uri mHandle;
    private GatewayInfo mGatewayInfo;
    private Subscription mSubscription;
    private CallServiceDescriptor mCurrentCallServiceDescriptor;
    private CallServiceDescriptor mHandoffCallServiceDescriptor;
    private String mParentCallId;
    private List<String> mChildCallIds;

    public Call(String callId) {
        mCallId = callId;
    }

    public String getCallId() {
        return mCallId;
    }

    public String getNumber() {
        if (mGatewayInfo != null) {
            return mGatewayInfo.getOriginalHandle().getSchemeSpecificPart();
        }
        return mHandle == null ? null : mHandle.getSchemeSpecificPart();
    }

    public Uri getHandle() {
        return mHandle;
    }

    public void setHandle(Uri handle) {
        mHandle = handle;
    }

    public int getState() {
        if (mParentCallId != null) {
            return State.CONFERENCED;
        } else {
            return mState;
        }
    }

    public void setState(int state) {
        mState = state;
    }

    public CallNumberPresentation getNumberPresentation() {
        return CallNumberPresentation.ALLOWED;
    }

    public CallNumberPresentation getCnapNamePresentation() {
        return CallNumberPresentation.ALLOWED;
    }

    public String getCnapName() {
        return "";
    }

    /** Returns call disconnect cause; values are defined in {@link DisconnectCause}. */
    public int getDisconnectCause() {
        if (mState == State.DISCONNECTED || mState == State.IDLE) {
            return mDisconnectCause;
        }

        return DisconnectCause.NOT_DISCONNECTED;
    }

    /** Sets the call disconnect cause; values are defined in {@link DisconnectCause}. */
    public void setDisconnectCause(int cause) {
        mDisconnectCause = cause;
    }

    /** Sets the possible text message responses. */
    public void setCannedSmsResponses(List<String> cannedSmsResponses) {
        mCannedSmsResponses = cannedSmsResponses;
    }

    /** Returns the possible text message responses. */
    public List<String> getCannedSmsResponses() {
        return mCannedSmsResponses;
    }

    /** Sets a bit mask of capabilities unique to this call. */
    public void setCapabilities(int capabilities) {
        mCapabilities = (CallCapabilities.ALL & capabilities);
    }

    /** Checks if the call supports the given set of capabilities supplied as a bit mask. */
    public boolean can(int capabilities) {
        return (capabilities == (capabilities & mCapabilities));
    }

    /** Sets the time when the call first became active. */
    public void setConnectTimeMillis(long connectTimeMillis) {
        mConnectTimeMillis = connectTimeMillis;
    }

    /** Gets the time when the call first became active. */
    public long getConnectTimeMillis() {
        return mConnectTimeMillis;
    }

    public boolean isConferenceCall() {
        return mChildCallIds != null && !mChildCallIds.isEmpty();
    }

    public GatewayInfo getGatewayInfo() {
        return mGatewayInfo;
    }

    public void setGatewayInfo(GatewayInfo gatewayInfo) {
        mGatewayInfo = gatewayInfo;
    }

    public Subscription getSubscription() {
        return mSubscription;
    }

    public void setSubscription(Subscription subscription) {
        mSubscription = subscription;
    }

    /** The descriptor for the call service currently routing this call. */
    public CallServiceDescriptor getCurrentCallServiceDescriptor() {
        return mCurrentCallServiceDescriptor;
    }

    public void setCurrentCallServiceDescriptor(CallServiceDescriptor descriptor) {
        mCurrentCallServiceDescriptor = descriptor;
    }

    /**
     * The descriptor for the call service that this call is being switched to, null if handoff is
     * not in progress.
     */
    public CallServiceDescriptor getHandoffCallServiceDescriptor() {
        return mHandoffCallServiceDescriptor;
    }

    public void setHandoffCallServiceDescriptor(CallServiceDescriptor descriptor) {
        mHandoffCallServiceDescriptor = descriptor;
    }

    public void setChildCallIds(List<String> callIds) {
        mChildCallIds = callIds;
    }

    public List<String> getChildCallIds() {
        return mChildCallIds;
    }

    public void setParentId(String callId) {
        mParentCallId = callId;
    }

    public String getParentId() {
        return mParentCallId;
    }

    @Override
    public String toString() {
        return String.format(Locale.US, "[%s, %s, %s, children:%s, parent:%s]",
                mCallId,
                State.toString(mState),
                CallCapabilities.toString(mCapabilities),
                mChildCallIds,
                mParentCallId);
    }
}