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