aboutsummaryrefslogtreecommitdiff
path: root/src/java/com/android/internal/telephony/DriverCall.java
blob: a67de7a69d9f93afc4d8e837129ae2353ec60406 (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
/*
 * Copyright (C) 2006 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.internal.telephony;

import android.compat.annotation.UnsupportedAppUsage;
import android.telephony.PhoneNumberUtils;

import com.android.telephony.Rlog;

/**
 * {@hide}
 */
public class DriverCall implements Comparable<DriverCall> {
    static final String LOG_TAG = "DriverCall";

    @UnsupportedAppUsage(implicitMember =
            "values()[Lcom/android/internal/telephony/DriverCall$State;")
    public enum State {
        @UnsupportedAppUsage
        ACTIVE,
        @UnsupportedAppUsage
        HOLDING,
        @UnsupportedAppUsage
        DIALING,    // MO call only
        @UnsupportedAppUsage
        ALERTING,   // MO call only
        @UnsupportedAppUsage
        INCOMING,   // MT call only
        @UnsupportedAppUsage
        WAITING;    // MT call only
        // If you add a state, make sure to look for the switch()
        // statements that use this enum
    }

    /**
     * Audio information
     */
    /** Unspecified audio codec */
    public static final int AUDIO_QUALITY_UNSPECIFIED = 0;
    /** AMR (Narrowband) audio codec */
    public static final int AUDIO_QUALITY_AMR = 1;
    /** AMR (Wideband) audio codec */
    public static final int AUDIO_QUALITY_AMR_WB = 2;
    /** GSM Enhanced Full-Rate audio codec */
    public static final int AUDIO_QUALITY_GSM_EFR = 3;
    /** GSM Full-Rate audio codec */
    public static final int AUDIO_QUALITY_GSM_FR = 4;
    /** GSM Half-Rate audio codec */
    public static final int AUDIO_QUALITY_GSM_HR = 5;
    /** Enhanced Variable rate codec */
    public static final int AUDIO_QUALITY_EVRC = 6;
    /** Enhanced Variable rate codec revision B */
    public static final int AUDIO_QUALITY_EVRC_B = 7;
    /** Enhanced Variable rate codec (Wideband) */
    public static final int AUDIO_QUALITY_EVRC_WB = 8;
    /** Enhanced Variable rate codec (Narrowband) */
    public static final int AUDIO_QUALITY_EVRC_NW = 9;

    @UnsupportedAppUsage
    public int index;
    @UnsupportedAppUsage
    public boolean isMT;
    @UnsupportedAppUsage
    public State state;     // May be null if unavail
    public boolean isMpty;
    @UnsupportedAppUsage
    public String number;
    public int TOA;
    @UnsupportedAppUsage
    public boolean isVoice;
    public boolean isVoicePrivacy;
    public int als;
    @UnsupportedAppUsage
    public int numberPresentation;
    @UnsupportedAppUsage
    public String name;
    public int namePresentation;
    public UUSInfo uusInfo;
    public int audioQuality = AUDIO_QUALITY_UNSPECIFIED;

    /** returns null on error */
    static DriverCall
    fromCLCCLine(String line) {
        DriverCall ret = new DriverCall();

        //+CLCC: 1,0,2,0,0,\"+18005551212\",145
        //     index,isMT,state,mode,isMpty(,number,TOA)?
        ATResponseParser p = new ATResponseParser(line);

        try {
            ret.index = p.nextInt();
            ret.isMT = p.nextBoolean();
            ret.state = stateFromCLCC(p.nextInt());

            ret.isVoice = (0 == p.nextInt());
            ret.isMpty = p.nextBoolean();

            // use ALLOWED as default presentation while parsing CLCC
            ret.numberPresentation = PhoneConstants.PRESENTATION_ALLOWED;

            if (p.hasMore()) {
                // Some lame implementations return strings
                // like "NOT AVAILABLE" in the CLCC line
                ret.number = PhoneNumberUtils.extractNetworkPortionAlt(p.nextString());

                if (ret.number.length() == 0) {
                    ret.number = null;
                }

                ret.TOA = p.nextInt();

                // Make sure there's a leading + on addresses with a TOA
                // of 145

                ret.number = PhoneNumberUtils.stringFromStringAndTOA(
                                ret.number, ret.TOA);

            }
        } catch (ATParseEx ex) {
            Rlog.e(LOG_TAG,"Invalid CLCC line: '" + line + "'");
            return null;
        }

        return ret;
    }

    @UnsupportedAppUsage
    public
    DriverCall() {
    }

    @Override
    public String
    toString() {
        return "id=" + index + ","
                + state + ","
                + "toa=" + TOA + ","
                + (isMpty ? "conf" : "norm") + ","
                + (isMT ? "mt" : "mo") + ","
                + als + ","
                + (isVoice ? "voc" : "nonvoc") + ","
                + (isVoicePrivacy ? "evp" : "noevp") + ","
                /*+ "number=" + number */ + ",cli=" + numberPresentation + ","
                /*+ "name="+ name */ + "," + namePresentation + ","
                + "audioQuality=" + audioQuality;
    }

    public static State
    stateFromCLCC(int state) throws ATParseEx {
        switch(state) {
            case 0: return State.ACTIVE;
            case 1: return State.HOLDING;
            case 2: return State.DIALING;
            case 3: return State.ALERTING;
            case 4: return State.INCOMING;
            case 5: return State.WAITING;
            default:
                throw new ATParseEx("illegal call state " + state);
        }
    }

    public static int
    presentationFromCLIP(int cli) throws ATParseEx
    {
        switch(cli) {
            case 0: return PhoneConstants.PRESENTATION_ALLOWED;
            case 1: return PhoneConstants.PRESENTATION_RESTRICTED;
            case 2: return PhoneConstants.PRESENTATION_UNKNOWN;
            case 3: return PhoneConstants.PRESENTATION_PAYPHONE;
            default:
                throw new ATParseEx("illegal presentation " + cli);
        }
    }

    //***** Comparable Implementation

    /** For sorting by index */
    @Override
    public int
    compareTo(DriverCall dc) {

        if (index < dc.index) {
            return -1;
        } else if (index == dc.index) {
            return 0;
        } else { /*index > dc.index*/
            return 1;
        }
    }
}