1 /* 2 * Copyright (C) 2009 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.cdma; 18 19 import java.util.HashMap; 20 import android.media.ToneGenerator; 21 22 public class SignalToneUtil { 23 /** A marker that isn't a valid TONE */ 24 public static final int CDMA_INVALID_TONE = -1; 25 26 // public final int int IS95_CONST_IR_SIGNAL_TYPE_TYPE; 27 static public final int IS95_CONST_IR_SIGNAL_TONE = 0; 28 static public final int IS95_CONST_IR_SIGNAL_ISDN = 1; 29 static public final int IS95_CONST_IR_SIGNAL_IS54B = 2; 30 static public final int IS95_CONST_IR_SIGNAL_USR_DEFD_ALERT = 4; 31 32 // public final int int IS95_CONST_IR_ALERT_PITCH_TYPE; 33 static public final int IS95_CONST_IR_ALERT_MED = 0; 34 static public final int IS95_CONST_IR_ALERT_HIGH = 1; 35 static public final int IS95_CONST_IR_ALERT_LOW = 2; 36 37 // Based on 3GPP2 C.S0005-E, section 3.7.5.5 Signal, 38 // set TAPIAMSSCDMA_SIGNAL_PITCH_UNKNOWN to 0 to avoid 39 // the alert pitch to be involved in hash calculation for 40 // signal type other than IS54B. 41 static public final int TAPIAMSSCDMA_SIGNAL_PITCH_UNKNOWN = 0; 42 43 // public final int int IS95_CONST_IR_SIGNAL_TYPE; 44 static public final int IS95_CONST_IR_SIG_ISDN_NORMAL = 0; 45 static public final int IS95_CONST_IR_SIG_ISDN_INTGRP = 1; 46 static public final int IS95_CONST_IR_SIG_ISDN_SP_PRI = 2; 47 static public final int IS95_CONST_IR_SIG_ISDN_PAT_3 = 3; 48 static public final int IS95_CONST_IR_SIG_ISDN_PING = 4; 49 static public final int IS95_CONST_IR_SIG_ISDN_PAT_5 = 5; 50 static public final int IS95_CONST_IR_SIG_ISDN_PAT_6 = 6; 51 static public final int IS95_CONST_IR_SIG_ISDN_PAT_7 = 7; 52 static public final int IS95_CONST_IR_SIG_ISDN_OFF = 15; 53 static public final int IS95_CONST_IR_SIG_TONE_DIAL = 0; 54 static public final int IS95_CONST_IR_SIG_TONE_RING = 1; 55 static public final int IS95_CONST_IR_SIG_TONE_INT = 2; 56 static public final int IS95_CONST_IR_SIG_TONE_ABB_INT = 3; 57 static public final int IS95_CONST_IR_SIG_TONE_REORDER = 4; 58 static public final int IS95_CONST_IR_SIG_TONE_ABB_RE = 5; 59 static public final int IS95_CONST_IR_SIG_TONE_BUSY = 6; 60 static public final int IS95_CONST_IR_SIG_TONE_CONFIRM = 7; 61 static public final int IS95_CONST_IR_SIG_TONE_ANSWER = 8; 62 static public final int IS95_CONST_IR_SIG_TONE_CALL_W = 9; 63 static public final int IS95_CONST_IR_SIG_TONE_PIP = 10; 64 static public final int IS95_CONST_IR_SIG_TONE_NO_TONE = 63; 65 static public final int IS95_CONST_IR_SIG_IS54B_NO_TONE = 0; 66 static public final int IS95_CONST_IR_SIG_IS54B_L = 1; 67 static public final int IS95_CONST_IR_SIG_IS54B_SS = 2; 68 static public final int IS95_CONST_IR_SIG_IS54B_SSL = 3; 69 static public final int IS95_CONST_IR_SIG_IS54B_SS_2 = 4; 70 static public final int IS95_CONST_IR_SIG_IS54B_SLS = 5; 71 static public final int IS95_CONST_IR_SIG_IS54B_S_X4 = 6; 72 static public final int IS95_CONST_IR_SIG_IS54B_PBX_L = 7; 73 static public final int IS95_CONST_IR_SIG_IS54B_PBX_SS = 8; 74 static public final int IS95_CONST_IR_SIG_IS54B_PBX_SSL = 9; 75 static public final int IS95_CONST_IR_SIG_IS54B_PBX_SLS = 10; 76 static public final int IS95_CONST_IR_SIG_IS54B_PBX_S_X4 = 11; 77 static public final int IS95_CONST_IR_SIG_TONE_ABBR_ALRT = 0; 78 79 // Hashmap to map signalInfo To AudioTone 80 static private HashMap<Integer, Integer> mHm = new HashMap<Integer, Integer>(); 81 82 private static Integer signalParamHash(int signalType, int alertPitch, int signal) { 83 if ((signalType < 0) || (signalType > 256) || (alertPitch > 256) || 84 (alertPitch < 0) || (signal > 256) || (signal < 0)) { 85 return new Integer(CDMA_INVALID_TONE); 86 } 87 // Based on 3GPP2 C.S0005-E, seciton 3.7.5.5 Signal, 88 // the alert pitch field is ignored by the mobile station unless 89 // SIGNAL_TYPE is '10',IS-54B Alerting. 90 // Set alert pitch to TAPIAMSSCDMA_SIGNAL_PITCH_UNKNOWN 91 // so the alert pitch is not involved in hash calculation 92 // when signal type is not IS-54B. 93 if (signalType != IS95_CONST_IR_SIGNAL_IS54B) { 94 alertPitch = TAPIAMSSCDMA_SIGNAL_PITCH_UNKNOWN; 95 } 96 return new Integer(signalType * 256 * 256 + alertPitch * 256 + signal); 97 } 98 99 public static int getAudioToneFromSignalInfo(int signalType, int alertPitch, int signal) { 100 Integer result = mHm.get(signalParamHash(signalType, alertPitch, signal)); 101 if (result == null) { 102 return CDMA_INVALID_TONE; 103 } 104 return result; 105 } 106 107 static { 108 109 /* SIGNAL_TYPE_ISDN */ 110 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_ISDN, TAPIAMSSCDMA_SIGNAL_PITCH_UNKNOWN, 111 IS95_CONST_IR_SIG_ISDN_NORMAL), ToneGenerator.TONE_CDMA_CALL_SIGNAL_ISDN_NORMAL); 112 113 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_ISDN, TAPIAMSSCDMA_SIGNAL_PITCH_UNKNOWN, 114 IS95_CONST_IR_SIG_ISDN_INTGRP), 115 ToneGenerator.TONE_CDMA_CALL_SIGNAL_ISDN_INTERGROUP); 116 117 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_ISDN, TAPIAMSSCDMA_SIGNAL_PITCH_UNKNOWN, 118 IS95_CONST_IR_SIG_ISDN_SP_PRI), ToneGenerator.TONE_CDMA_CALL_SIGNAL_ISDN_SP_PRI); 119 120 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_ISDN, TAPIAMSSCDMA_SIGNAL_PITCH_UNKNOWN, 121 IS95_CONST_IR_SIG_ISDN_PAT_3), ToneGenerator.TONE_CDMA_CALL_SIGNAL_ISDN_PAT3); 122 123 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_ISDN, TAPIAMSSCDMA_SIGNAL_PITCH_UNKNOWN, 124 IS95_CONST_IR_SIG_ISDN_PING), ToneGenerator.TONE_CDMA_CALL_SIGNAL_ISDN_PING_RING); 125 126 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_ISDN, TAPIAMSSCDMA_SIGNAL_PITCH_UNKNOWN, 127 IS95_CONST_IR_SIG_ISDN_PAT_5), ToneGenerator.TONE_CDMA_CALL_SIGNAL_ISDN_PAT5); 128 129 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_ISDN, TAPIAMSSCDMA_SIGNAL_PITCH_UNKNOWN, 130 IS95_CONST_IR_SIG_ISDN_PAT_6), ToneGenerator.TONE_CDMA_CALL_SIGNAL_ISDN_PAT6); 131 132 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_ISDN, TAPIAMSSCDMA_SIGNAL_PITCH_UNKNOWN, 133 IS95_CONST_IR_SIG_ISDN_PAT_7), ToneGenerator.TONE_CDMA_CALL_SIGNAL_ISDN_PAT7); 134 135 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_ISDN, TAPIAMSSCDMA_SIGNAL_PITCH_UNKNOWN, 136 IS95_CONST_IR_SIG_ISDN_OFF), ToneGenerator.TONE_CDMA_SIGNAL_OFF); 137 138 /* SIGNAL_TYPE_TONE */ 139 140 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_TONE, TAPIAMSSCDMA_SIGNAL_PITCH_UNKNOWN, 141 IS95_CONST_IR_SIG_TONE_DIAL), ToneGenerator.TONE_CDMA_DIAL_TONE_LITE); 142 143 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_TONE, TAPIAMSSCDMA_SIGNAL_PITCH_UNKNOWN, 144 IS95_CONST_IR_SIG_TONE_RING), ToneGenerator.TONE_CDMA_NETWORK_USA_RINGBACK); 145 146 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_TONE, TAPIAMSSCDMA_SIGNAL_PITCH_UNKNOWN, 147 IS95_CONST_IR_SIG_TONE_INT), ToneGenerator.TONE_SUP_INTERCEPT); 148 149 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_TONE, TAPIAMSSCDMA_SIGNAL_PITCH_UNKNOWN, 150 IS95_CONST_IR_SIG_TONE_ABB_INT), ToneGenerator.TONE_SUP_INTERCEPT_ABBREV); 151 152 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_TONE, TAPIAMSSCDMA_SIGNAL_PITCH_UNKNOWN, 153 IS95_CONST_IR_SIG_TONE_REORDER), ToneGenerator.TONE_CDMA_REORDER); 154 155 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_TONE, TAPIAMSSCDMA_SIGNAL_PITCH_UNKNOWN, 156 IS95_CONST_IR_SIG_TONE_ABB_RE), ToneGenerator.TONE_CDMA_ABBR_REORDER); 157 158 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_TONE, TAPIAMSSCDMA_SIGNAL_PITCH_UNKNOWN, 159 IS95_CONST_IR_SIG_TONE_BUSY), ToneGenerator.TONE_CDMA_NETWORK_BUSY); 160 161 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_TONE, TAPIAMSSCDMA_SIGNAL_PITCH_UNKNOWN, 162 IS95_CONST_IR_SIG_TONE_CONFIRM), ToneGenerator.TONE_SUP_CONFIRM); 163 164 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_TONE, TAPIAMSSCDMA_SIGNAL_PITCH_UNKNOWN, 165 IS95_CONST_IR_SIG_TONE_ANSWER), ToneGenerator.TONE_CDMA_ANSWER); 166 167 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_TONE, TAPIAMSSCDMA_SIGNAL_PITCH_UNKNOWN, 168 IS95_CONST_IR_SIG_TONE_CALL_W), ToneGenerator.TONE_CDMA_NETWORK_CALLWAITING); 169 170 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_TONE, TAPIAMSSCDMA_SIGNAL_PITCH_UNKNOWN, 171 IS95_CONST_IR_SIG_TONE_PIP), ToneGenerator.TONE_CDMA_PIP); 172 173 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_TONE, TAPIAMSSCDMA_SIGNAL_PITCH_UNKNOWN, 174 IS95_CONST_IR_SIG_TONE_NO_TONE), ToneGenerator.TONE_CDMA_SIGNAL_OFF); 175 176 /* SIGNAL_TYPE_IS54B */ 177 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_IS54B, IS95_CONST_IR_ALERT_HIGH, 178 IS95_CONST_IR_SIG_IS54B_L), ToneGenerator.TONE_CDMA_HIGH_L); 179 180 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_IS54B, IS95_CONST_IR_ALERT_MED, 181 IS95_CONST_IR_SIG_IS54B_L), ToneGenerator.TONE_CDMA_MED_L); 182 183 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_IS54B, IS95_CONST_IR_ALERT_LOW, 184 IS95_CONST_IR_SIG_IS54B_L), ToneGenerator.TONE_CDMA_LOW_L); 185 186 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_IS54B, IS95_CONST_IR_ALERT_HIGH, 187 IS95_CONST_IR_SIG_IS54B_SS), ToneGenerator.TONE_CDMA_HIGH_SS); 188 189 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_IS54B, IS95_CONST_IR_ALERT_MED, 190 IS95_CONST_IR_SIG_IS54B_SS), ToneGenerator.TONE_CDMA_MED_SS); 191 192 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_IS54B, IS95_CONST_IR_ALERT_LOW, 193 IS95_CONST_IR_SIG_IS54B_SS), ToneGenerator.TONE_CDMA_LOW_SS); 194 195 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_IS54B, IS95_CONST_IR_ALERT_HIGH, 196 IS95_CONST_IR_SIG_IS54B_SSL), ToneGenerator.TONE_CDMA_HIGH_SSL); 197 198 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_IS54B, IS95_CONST_IR_ALERT_MED, 199 IS95_CONST_IR_SIG_IS54B_SSL), ToneGenerator.TONE_CDMA_MED_SSL); 200 201 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_IS54B, IS95_CONST_IR_ALERT_LOW, 202 IS95_CONST_IR_SIG_IS54B_SSL), ToneGenerator.TONE_CDMA_LOW_SSL); 203 204 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_IS54B, IS95_CONST_IR_ALERT_HIGH, 205 IS95_CONST_IR_SIG_IS54B_SS_2), ToneGenerator.TONE_CDMA_HIGH_SS_2); 206 207 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_IS54B, IS95_CONST_IR_ALERT_MED, 208 IS95_CONST_IR_SIG_IS54B_SS_2), ToneGenerator.TONE_CDMA_MED_SS_2); 209 210 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_IS54B, IS95_CONST_IR_ALERT_LOW, 211 IS95_CONST_IR_SIG_IS54B_SS_2), ToneGenerator.TONE_CDMA_LOW_SS_2); 212 213 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_IS54B, IS95_CONST_IR_ALERT_HIGH, 214 IS95_CONST_IR_SIG_IS54B_SLS), ToneGenerator.TONE_CDMA_HIGH_SLS); 215 216 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_IS54B, IS95_CONST_IR_ALERT_MED, 217 IS95_CONST_IR_SIG_IS54B_SLS), ToneGenerator.TONE_CDMA_MED_SLS); 218 219 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_IS54B, IS95_CONST_IR_ALERT_LOW, 220 IS95_CONST_IR_SIG_IS54B_SLS), ToneGenerator.TONE_CDMA_LOW_SLS); 221 222 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_IS54B, IS95_CONST_IR_ALERT_HIGH, 223 IS95_CONST_IR_SIG_IS54B_S_X4), ToneGenerator.TONE_CDMA_HIGH_S_X4); 224 225 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_IS54B, IS95_CONST_IR_ALERT_MED, 226 IS95_CONST_IR_SIG_IS54B_S_X4), ToneGenerator.TONE_CDMA_MED_S_X4); 227 228 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_IS54B, IS95_CONST_IR_ALERT_LOW, 229 IS95_CONST_IR_SIG_IS54B_S_X4), ToneGenerator.TONE_CDMA_LOW_S_X4); 230 231 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_IS54B, IS95_CONST_IR_ALERT_HIGH, 232 IS95_CONST_IR_SIG_IS54B_PBX_L), ToneGenerator.TONE_CDMA_HIGH_PBX_L); 233 234 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_IS54B, IS95_CONST_IR_ALERT_MED, 235 IS95_CONST_IR_SIG_IS54B_PBX_L), ToneGenerator.TONE_CDMA_MED_PBX_L); 236 237 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_IS54B, IS95_CONST_IR_ALERT_LOW, 238 IS95_CONST_IR_SIG_IS54B_PBX_L), ToneGenerator.TONE_CDMA_LOW_PBX_L); 239 240 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_IS54B, IS95_CONST_IR_ALERT_HIGH, 241 IS95_CONST_IR_SIG_IS54B_PBX_SS), ToneGenerator.TONE_CDMA_HIGH_PBX_SS); 242 243 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_IS54B, IS95_CONST_IR_ALERT_MED, 244 IS95_CONST_IR_SIG_IS54B_PBX_SS), ToneGenerator.TONE_CDMA_MED_PBX_SS); 245 246 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_IS54B, IS95_CONST_IR_ALERT_LOW, 247 IS95_CONST_IR_SIG_IS54B_PBX_SS), ToneGenerator.TONE_CDMA_LOW_PBX_SS); 248 249 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_IS54B, IS95_CONST_IR_ALERT_HIGH, 250 IS95_CONST_IR_SIG_IS54B_PBX_SSL), ToneGenerator.TONE_CDMA_HIGH_PBX_SSL); 251 252 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_IS54B, IS95_CONST_IR_ALERT_MED, 253 IS95_CONST_IR_SIG_IS54B_PBX_SSL), ToneGenerator.TONE_CDMA_MED_PBX_SSL); 254 255 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_IS54B, IS95_CONST_IR_ALERT_LOW, 256 IS95_CONST_IR_SIG_IS54B_PBX_SSL), ToneGenerator.TONE_CDMA_LOW_PBX_SSL); 257 258 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_IS54B, IS95_CONST_IR_ALERT_HIGH, 259 IS95_CONST_IR_SIG_IS54B_PBX_SLS), ToneGenerator.TONE_CDMA_HIGH_PBX_SLS); 260 261 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_IS54B, IS95_CONST_IR_ALERT_MED, 262 IS95_CONST_IR_SIG_IS54B_PBX_SLS), ToneGenerator.TONE_CDMA_MED_PBX_SLS); 263 264 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_IS54B, IS95_CONST_IR_ALERT_LOW, 265 IS95_CONST_IR_SIG_IS54B_PBX_SLS), ToneGenerator.TONE_CDMA_LOW_PBX_SLS); 266 267 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_IS54B, IS95_CONST_IR_ALERT_HIGH, 268 IS95_CONST_IR_SIG_IS54B_PBX_S_X4), ToneGenerator.TONE_CDMA_HIGH_PBX_S_X4); 269 270 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_IS54B, IS95_CONST_IR_ALERT_MED, 271 IS95_CONST_IR_SIG_IS54B_PBX_S_X4), ToneGenerator.TONE_CDMA_MED_PBX_S_X4); 272 273 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_IS54B, IS95_CONST_IR_ALERT_LOW, 274 IS95_CONST_IR_SIG_IS54B_PBX_S_X4), ToneGenerator.TONE_CDMA_LOW_PBX_S_X4); 275 276 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_IS54B, TAPIAMSSCDMA_SIGNAL_PITCH_UNKNOWN, 277 IS95_CONST_IR_SIG_IS54B_NO_TONE), ToneGenerator.TONE_CDMA_SIGNAL_OFF); 278 279 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_USR_DEFD_ALERT, 280 TAPIAMSSCDMA_SIGNAL_PITCH_UNKNOWN, IS95_CONST_IR_SIG_TONE_ABBR_ALRT), 281 ToneGenerator.TONE_CDMA_ABBR_ALERT); 282 283 mHm.put(signalParamHash(IS95_CONST_IR_SIGNAL_USR_DEFD_ALERT, 284 TAPIAMSSCDMA_SIGNAL_PITCH_UNKNOWN, IS95_CONST_IR_SIG_TONE_NO_TONE), 285 ToneGenerator.TONE_CDMA_ABBR_ALERT); 286 287 } 288 289 // suppress default constructor for noninstantiability 290 private SignalToneUtil() { 291 } 292 } 293