1 /*
2  * Copyright (C) 2006 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 
17 package com.android.internal.telephony;
18 
19 import android.annotation.UnsupportedAppUsage;
20 import android.telephony.Rlog;
21 import java.lang.Comparable;
22 import android.telephony.PhoneNumberUtils;
23 
24 /**
25  * {@hide}
26  */
27 public class DriverCall implements Comparable<DriverCall> {
28     static final String LOG_TAG = "DriverCall";
29 
30     public enum State {
31         @UnsupportedAppUsage
32         ACTIVE,
33         @UnsupportedAppUsage
34         HOLDING,
35         @UnsupportedAppUsage
36         DIALING,    // MO call only
37         @UnsupportedAppUsage
38         ALERTING,   // MO call only
39         @UnsupportedAppUsage
40         INCOMING,   // MT call only
41         @UnsupportedAppUsage
42         WAITING;    // MT call only
43         // If you add a state, make sure to look for the switch()
44         // statements that use this enum
45     }
46 
47     /**
48      * Audio information
49      */
50     /** Unspecified audio codec */
51     public static final int AUDIO_QUALITY_UNSPECIFIED = 0;
52     /** AMR (Narrowband) audio codec */
53     public static final int AUDIO_QUALITY_AMR = 1;
54     /** AMR (Wideband) audio codec */
55     public static final int AUDIO_QUALITY_AMR_WB = 2;
56     /** GSM Enhanced Full-Rate audio codec */
57     public static final int AUDIO_QUALITY_GSM_EFR = 3;
58     /** GSM Full-Rate audio codec */
59     public static final int AUDIO_QUALITY_GSM_FR = 4;
60     /** GSM Half-Rate audio codec */
61     public static final int AUDIO_QUALITY_GSM_HR = 5;
62     /** Enhanced Variable rate codec */
63     public static final int AUDIO_QUALITY_EVRC = 6;
64     /** Enhanced Variable rate codec revision B */
65     public static final int AUDIO_QUALITY_EVRC_B = 7;
66     /** Enhanced Variable rate codec (Wideband) */
67     public static final int AUDIO_QUALITY_EVRC_WB = 8;
68     /** Enhanced Variable rate codec (Narrowband) */
69     public static final int AUDIO_QUALITY_EVRC_NW = 9;
70 
71     @UnsupportedAppUsage
72     public int index;
73     @UnsupportedAppUsage
74     public boolean isMT;
75     @UnsupportedAppUsage
76     public State state;     // May be null if unavail
77     public boolean isMpty;
78     @UnsupportedAppUsage
79     public String number;
80     public int TOA;
81     @UnsupportedAppUsage
82     public boolean isVoice;
83     public boolean isVoicePrivacy;
84     public int als;
85     @UnsupportedAppUsage
86     public int numberPresentation;
87     @UnsupportedAppUsage
88     public String name;
89     public int namePresentation;
90     public UUSInfo uusInfo;
91     public int audioQuality = AUDIO_QUALITY_UNSPECIFIED;
92 
93     /** returns null on error */
94     static DriverCall
fromCLCCLine(String line)95     fromCLCCLine(String line) {
96         DriverCall ret = new DriverCall();
97 
98         //+CLCC: 1,0,2,0,0,\"+18005551212\",145
99         //     index,isMT,state,mode,isMpty(,number,TOA)?
100         ATResponseParser p = new ATResponseParser(line);
101 
102         try {
103             ret.index = p.nextInt();
104             ret.isMT = p.nextBoolean();
105             ret.state = stateFromCLCC(p.nextInt());
106 
107             ret.isVoice = (0 == p.nextInt());
108             ret.isMpty = p.nextBoolean();
109 
110             // use ALLOWED as default presentation while parsing CLCC
111             ret.numberPresentation = PhoneConstants.PRESENTATION_ALLOWED;
112 
113             if (p.hasMore()) {
114                 // Some lame implementations return strings
115                 // like "NOT AVAILABLE" in the CLCC line
116                 ret.number = PhoneNumberUtils.extractNetworkPortionAlt(p.nextString());
117 
118                 if (ret.number.length() == 0) {
119                     ret.number = null;
120                 }
121 
122                 ret.TOA = p.nextInt();
123 
124                 // Make sure there's a leading + on addresses with a TOA
125                 // of 145
126 
127                 ret.number = PhoneNumberUtils.stringFromStringAndTOA(
128                                 ret.number, ret.TOA);
129 
130             }
131         } catch (ATParseEx ex) {
132             Rlog.e(LOG_TAG,"Invalid CLCC line: '" + line + "'");
133             return null;
134         }
135 
136         return ret;
137     }
138 
139     @UnsupportedAppUsage
140     public
DriverCall()141     DriverCall() {
142     }
143 
144     @Override
145     public String
toString()146     toString() {
147         return "id=" + index + ","
148                 + state + ","
149                 + "toa=" + TOA + ","
150                 + (isMpty ? "conf" : "norm") + ","
151                 + (isMT ? "mt" : "mo") + ","
152                 + als + ","
153                 + (isVoice ? "voc" : "nonvoc") + ","
154                 + (isVoicePrivacy ? "evp" : "noevp") + ","
155                 /*+ "number=" + number */ + ",cli=" + numberPresentation + ","
156                 /*+ "name="+ name */ + "," + namePresentation + ","
157                 + "audioQuality=" + audioQuality;
158     }
159 
160     public static State
stateFromCLCC(int state)161     stateFromCLCC(int state) throws ATParseEx {
162         switch(state) {
163             case 0: return State.ACTIVE;
164             case 1: return State.HOLDING;
165             case 2: return State.DIALING;
166             case 3: return State.ALERTING;
167             case 4: return State.INCOMING;
168             case 5: return State.WAITING;
169             default:
170                 throw new ATParseEx("illegal call state " + state);
171         }
172     }
173 
174     public static int
presentationFromCLIP(int cli)175     presentationFromCLIP(int cli) throws ATParseEx
176     {
177         switch(cli) {
178             case 0: return PhoneConstants.PRESENTATION_ALLOWED;
179             case 1: return PhoneConstants.PRESENTATION_RESTRICTED;
180             case 2: return PhoneConstants.PRESENTATION_UNKNOWN;
181             case 3: return PhoneConstants.PRESENTATION_PAYPHONE;
182             default:
183                 throw new ATParseEx("illegal presentation " + cli);
184         }
185     }
186 
187     //***** Comparable Implementation
188 
189     /** For sorting by index */
190     @Override
191     public int
compareTo(DriverCall dc)192     compareTo(DriverCall dc) {
193 
194         if (index < dc.index) {
195             return -1;
196         } else if (index == dc.index) {
197             return 0;
198         } else { /*index > dc.index*/
199             return 1;
200         }
201     }
202 }
203