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