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 int TOA; 83 @UnsupportedAppUsage 84 public boolean isVoice; 85 public boolean isVoicePrivacy; 86 public int als; 87 @UnsupportedAppUsage 88 public int numberPresentation; 89 @UnsupportedAppUsage 90 public String name; 91 public int namePresentation; 92 public UUSInfo uusInfo; 93 public int audioQuality = AUDIO_QUALITY_UNSPECIFIED; 94 95 /** returns null on error */ 96 static DriverCall fromCLCCLine(String line)97 fromCLCCLine(String line) { 98 DriverCall ret = new DriverCall(); 99 100 //+CLCC: 1,0,2,0,0,\"+18005551212\",145 101 // index,isMT,state,mode,isMpty(,number,TOA)? 102 ATResponseParser p = new ATResponseParser(line); 103 104 try { 105 ret.index = p.nextInt(); 106 ret.isMT = p.nextBoolean(); 107 ret.state = stateFromCLCC(p.nextInt()); 108 109 ret.isVoice = (0 == p.nextInt()); 110 ret.isMpty = p.nextBoolean(); 111 112 // use ALLOWED as default presentation while parsing CLCC 113 ret.numberPresentation = PhoneConstants.PRESENTATION_ALLOWED; 114 115 if (p.hasMore()) { 116 // Some lame implementations return strings 117 // like "NOT AVAILABLE" in the CLCC line 118 ret.number = PhoneNumberUtils.extractNetworkPortionAlt(p.nextString()); 119 120 if (ret.number.length() == 0) { 121 ret.number = null; 122 } 123 124 ret.TOA = p.nextInt(); 125 126 // Make sure there's a leading + on addresses with a TOA 127 // of 145 128 129 ret.number = PhoneNumberUtils.stringFromStringAndTOA( 130 ret.number, ret.TOA); 131 132 } 133 } catch (ATParseEx ex) { 134 Rlog.e(LOG_TAG,"Invalid CLCC line: '" + line + "'"); 135 return null; 136 } 137 138 return ret; 139 } 140 141 @UnsupportedAppUsage 142 public DriverCall()143 DriverCall() { 144 } 145 146 @Override 147 public String toString()148 toString() { 149 return "id=" + index + "," 150 + state + "," 151 + "toa=" + TOA + "," 152 + (isMpty ? "conf" : "norm") + "," 153 + (isMT ? "mt" : "mo") + "," 154 + als + "," 155 + (isVoice ? "voc" : "nonvoc") + "," 156 + (isVoicePrivacy ? "evp" : "noevp") + "," 157 /*+ "number=" + number */ + ",cli=" + numberPresentation + "," 158 /*+ "name="+ name */ + "," + namePresentation + "," 159 + "audioQuality=" + audioQuality; 160 } 161 162 public static State stateFromCLCC(int state)163 stateFromCLCC(int state) throws ATParseEx { 164 switch(state) { 165 case 0: return State.ACTIVE; 166 case 1: return State.HOLDING; 167 case 2: return State.DIALING; 168 case 3: return State.ALERTING; 169 case 4: return State.INCOMING; 170 case 5: return State.WAITING; 171 default: 172 throw new ATParseEx("illegal call state " + state); 173 } 174 } 175 176 public static int presentationFromCLIP(int cli)177 presentationFromCLIP(int cli) throws ATParseEx 178 { 179 switch(cli) { 180 case 0: return PhoneConstants.PRESENTATION_ALLOWED; 181 case 1: return PhoneConstants.PRESENTATION_RESTRICTED; 182 case 2: return PhoneConstants.PRESENTATION_UNKNOWN; 183 case 3: return PhoneConstants.PRESENTATION_PAYPHONE; 184 default: 185 throw new ATParseEx("illegal presentation " + cli); 186 } 187 } 188 189 //***** Comparable Implementation 190 191 /** For sorting by index */ 192 @Override 193 public int compareTo(DriverCall dc)194 compareTo(DriverCall dc) { 195 196 if (index < dc.index) { 197 return -1; 198 } else if (index == dc.index) { 199 return 0; 200 } else { /*index > dc.index*/ 201 return 1; 202 } 203 } 204 } 205