1 /* 2 * Copyright (C) 2008 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 android.media; 18 19 import android.annotation.NonNull; 20 import android.app.ActivityThread; 21 import android.compat.annotation.UnsupportedAppUsage; 22 import android.os.Build; 23 import android.text.TextUtils; 24 25 26 /** 27 * This class provides methods to play DTMF tones (ITU-T Recommendation Q.23), 28 * call supervisory tones (3GPP TS 22.001, CEPT) and proprietary tones (3GPP TS 31.111). 29 * Depending on call state and routing options, tones are mixed to the downlink audio 30 * or output to the speaker phone or headset. 31 * This API is not for generating tones over the uplink audio path. 32 */ 33 public class ToneGenerator 34 { 35 36 /* Values for toneType parameter of ToneGenerator() constructor */ 37 /* 38 * List of all available tones: These constants must be kept consistant with 39 * the enum in ToneGenerator C++ class. */ 40 41 /** 42 * Default value for an unknown or unspecified tone. 43 * @hide 44 */ 45 public static final int TONE_UNKNOWN = -1; 46 47 /** 48 * DTMF tone for key 0: 1336Hz, 941Hz, continuous</p> 49 * 50 * @see #ToneGenerator(int, int) 51 */ 52 public static final int TONE_DTMF_0 = 0; 53 /** 54 * DTMF tone for key 1: 1209Hz, 697Hz, continuous 55 * 56 * @see #ToneGenerator(int, int) 57 */ 58 public static final int TONE_DTMF_1 = 1; 59 /** 60 * DTMF tone for key 2: 1336Hz, 697Hz, continuous 61 * 62 * @see #ToneGenerator(int, int) 63 */ 64 public static final int TONE_DTMF_2 = 2; 65 /** 66 * DTMF tone for key 3: 1477Hz, 697Hz, continuous 67 * 68 * @see #ToneGenerator(int, int) 69 */ 70 public static final int TONE_DTMF_3 = 3; 71 /** 72 * DTMF tone for key 4: 1209Hz, 770Hz, continuous 73 * 74 * @see #ToneGenerator(int, int) 75 */ 76 public static final int TONE_DTMF_4 = 4; 77 /** 78 * DTMF tone for key 5: 1336Hz, 770Hz, continuous 79 * 80 * @see #ToneGenerator(int, int) 81 */ 82 public static final int TONE_DTMF_5 = 5; 83 /** 84 * DTMF tone for key 6: 1477Hz, 770Hz, continuous 85 * 86 * @see #ToneGenerator(int, int) 87 */ 88 public static final int TONE_DTMF_6 = 6; 89 /** 90 * DTMF tone for key 7: 1209Hz, 852Hz, continuous 91 * 92 * @see #ToneGenerator(int, int) 93 */ 94 public static final int TONE_DTMF_7 = 7; 95 /** 96 * DTMF tone for key 8: 1336Hz, 852Hz, continuous 97 * 98 * @see #ToneGenerator(int, int) 99 */ 100 public static final int TONE_DTMF_8 = 8; 101 /** 102 * DTMF tone for key 9: 1477Hz, 852Hz, continuous 103 * 104 * @see #ToneGenerator(int, int) 105 */ 106 public static final int TONE_DTMF_9 = 9; 107 /** 108 * DTMF tone for key *: 1209Hz, 941Hz, continuous 109 * 110 * @see #ToneGenerator(int, int) 111 */ 112 public static final int TONE_DTMF_S = 10; 113 /** 114 * DTMF tone for key #: 1477Hz, 941Hz, continuous 115 * 116 * @see #ToneGenerator(int, int) 117 */ 118 public static final int TONE_DTMF_P = 11; 119 /** 120 * DTMF tone for key A: 1633Hz, 697Hz, continuous 121 * 122 * @see #ToneGenerator(int, int) 123 */ 124 public static final int TONE_DTMF_A = 12; 125 /** 126 * DTMF tone for key B: 1633Hz, 770Hz, continuous 127 * 128 * @see #ToneGenerator(int, int) 129 */ 130 public static final int TONE_DTMF_B = 13; 131 /** 132 * DTMF tone for key C: 1633Hz, 852Hz, continuous 133 * 134 * @see #ToneGenerator(int, int) 135 */ 136 public static final int TONE_DTMF_C = 14; 137 /** 138 * DTMF tone for key D: 1633Hz, 941Hz, continuous 139 * 140 * @see #ToneGenerator(int, int) 141 */ 142 public static final int TONE_DTMF_D = 15; 143 /** 144 * Call supervisory tone, Dial tone: 145 * CEPT: 425Hz, continuous 146 * ANSI (IS-95): 350Hz+440Hz, continuous 147 * JAPAN: 400Hz, continuous 148 * 149 * @see #ToneGenerator(int, int) 150 */ 151 public static final int TONE_SUP_DIAL = 16; 152 /** 153 * Call supervisory tone, Busy: 154 * CEPT: 425Hz, 500ms ON, 500ms OFF... 155 * ANSI (IS-95): 480Hz+620Hz, 500ms ON, 500ms OFF... 156 * JAPAN: 400Hz, 500ms ON, 500ms OFF... 157 * 158 * @see #ToneGenerator(int, int) 159 */ 160 public static final int TONE_SUP_BUSY = 17; 161 /** 162 * Call supervisory tone, Congestion: 163 * CEPT, JAPAN: 425Hz, 200ms ON, 200ms OFF... 164 * ANSI (IS-95): 480Hz+620Hz, 250ms ON, 250ms OFF... 165 * 166 * @see #ToneGenerator(int, int) 167 */ 168 public static final int TONE_SUP_CONGESTION = 18; 169 /** 170 * Call supervisory tone, Radio path acknowlegment : 171 * CEPT, ANSI: 425Hz, 200ms ON 172 * JAPAN: 400Hz, 1s ON, 2s OFF... 173 * 174 * @see #ToneGenerator(int, int) 175 */ 176 public static final int TONE_SUP_RADIO_ACK = 19; 177 /** 178 * Call supervisory tone, Radio path not available: 425Hz, 200ms ON, 200 OFF 3 bursts 179 * 180 * @see #ToneGenerator(int, int) 181 */ 182 public static final int TONE_SUP_RADIO_NOTAVAIL = 20; 183 /** 184 * Call supervisory tone, Error/Special info: 950Hz+1400Hz+1800Hz, 330ms ON, 1s OFF... 185 * 186 * @see #ToneGenerator(int, int) 187 */ 188 public static final int TONE_SUP_ERROR = 21; 189 /** 190 * Call supervisory tone, Call Waiting: 191 * CEPT, JAPAN: 425Hz, 200ms ON, 600ms OFF, 200ms ON, 3s OFF... 192 * ANSI (IS-95): 440 Hz, 300 ms ON, 9.7 s OFF, 193 * (100 ms ON, 100 ms OFF, 100 ms ON, 9.7s OFF ...) 194 * 195 * @see #ToneGenerator(int, int) 196 */ 197 public static final int TONE_SUP_CALL_WAITING = 22; 198 /** 199 * Call supervisory tone, Ring Tone: 200 * CEPT, JAPAN: 425Hz, 1s ON, 4s OFF... 201 * ANSI (IS-95): 440Hz + 480Hz, 2s ON, 4s OFF... 202 * 203 * @see #ToneGenerator(int, int) 204 */ 205 public static final int TONE_SUP_RINGTONE = 23; 206 /** 207 * Proprietary tone, general beep: 400Hz+1200Hz, 35ms ON 208 * 209 * @see #ToneGenerator(int, int) 210 */ 211 public static final int TONE_PROP_BEEP = 24; 212 /** 213 * Proprietary tone, positive acknowlegement: 1200Hz, 100ms ON, 100ms OFF 2 bursts 214 * 215 * @see #ToneGenerator(int, int) 216 */ 217 public static final int TONE_PROP_ACK = 25; 218 /** 219 * Proprietary tone, negative acknowlegement: 300Hz+400Hz+500Hz, 400ms ON 220 * 221 * @see #ToneGenerator(int, int) 222 */ 223 public static final int TONE_PROP_NACK = 26; 224 /** 225 * Proprietary tone, prompt tone: 400Hz+1200Hz, 200ms ON 226 * 227 * @see #ToneGenerator(int, int) 228 */ 229 public static final int TONE_PROP_PROMPT = 27; 230 /** 231 * Proprietary tone, general double beep: twice 400Hz+1200Hz, 35ms ON, 200ms OFF, 35ms ON 232 * 233 * @see #ToneGenerator(int, int) 234 */ 235 public static final int TONE_PROP_BEEP2 = 28; 236 /** 237 * Call supervisory tone (IS-95), intercept tone: alternating 440 Hz and 620 Hz tones, 238 * each on for 250 ms 239 * 240 * @see #ToneGenerator(int, int) 241 */ 242 public static final int TONE_SUP_INTERCEPT = 29; 243 /** 244 * Call supervisory tone (IS-95), abbreviated intercept: intercept tone limited to 4 seconds 245 * 246 * @see #ToneGenerator(int, int) 247 */ 248 public static final int TONE_SUP_INTERCEPT_ABBREV = 30; 249 /** 250 * Call supervisory tone (IS-95), abbreviated congestion: congestion tone limited to 4 seconds 251 * 252 * @see #ToneGenerator(int, int) 253 */ 254 public static final int TONE_SUP_CONGESTION_ABBREV = 31; 255 /** 256 * Call supervisory tone (IS-95), confirm tone: a 350 Hz tone added to a 440 Hz tone 257 * repeated 3 times in a 100 ms on, 100 ms off cycle 258 * 259 * @see #ToneGenerator(int, int) 260 */ 261 public static final int TONE_SUP_CONFIRM = 32; 262 /** 263 * Call supervisory tone (IS-95), pip tone: four bursts of 480 Hz tone (0.1 s on, 0.1 s off). 264 * 265 * @see #ToneGenerator(int, int) 266 */ 267 public static final int TONE_SUP_PIP = 33; 268 /** 269 * CDMA Dial tone : 425Hz continuous 270 * 271 * @see #ToneGenerator(int, int) 272 */ 273 public static final int TONE_CDMA_DIAL_TONE_LITE = 34; 274 /** 275 * CDMA USA Ringback: 440Hz+480Hz 2s ON, 4000 OFF ... 276 * 277 * @see #ToneGenerator(int, int) 278 */ 279 public static final int TONE_CDMA_NETWORK_USA_RINGBACK = 35; 280 /** 281 * CDMA Intercept tone: 440Hz 250ms ON, 620Hz 250ms ON ... 282 * 283 * @see #ToneGenerator(int, int) 284 */ 285 public static final int TONE_CDMA_INTERCEPT = 36; 286 /** 287 * CDMA Abbr Intercept tone: 440Hz 250ms ON, 620Hz 250ms ON 288 * 289 * @see #ToneGenerator(int, int) 290 */ 291 public static final int TONE_CDMA_ABBR_INTERCEPT = 37; 292 /** 293 * CDMA Reorder tone: 480Hz+620Hz 250ms ON, 250ms OFF... 294 * 295 * @see #ToneGenerator(int, int) 296 */ 297 public static final int TONE_CDMA_REORDER = 38; 298 /** 299 * 300 * CDMA Abbr Reorder tone: 480Hz+620Hz 250ms ON, 250ms OFF repeated for 8 times 301 * @see #ToneGenerator(int, int) 302 */ 303 public static final int TONE_CDMA_ABBR_REORDER = 39; 304 /** 305 * CDMA Network Busy tone: 480Hz+620Hz 500ms ON, 500ms OFF continuous 306 * 307 * @see #ToneGenerator(int, int) 308 */ 309 public static final int TONE_CDMA_NETWORK_BUSY = 40; 310 /** 311 * CDMA Confirm tone: 350Hz+440Hz 100ms ON, 100ms OFF repeated for 3 times 312 * 313 * @see #ToneGenerator(int, int) 314 */ 315 public static final int TONE_CDMA_CONFIRM = 41; 316 /** 317 * 318 * CDMA answer tone: silent tone - defintion Frequency 0, 0ms ON, 0ms OFF 319 * @see #ToneGenerator(int, int) 320 */ 321 public static final int TONE_CDMA_ANSWER = 42; 322 /** 323 * 324 * CDMA Network Callwaiting tone: 440Hz 300ms ON 325 * @see #ToneGenerator(int, int) 326 */ 327 public static final int TONE_CDMA_NETWORK_CALLWAITING = 43; 328 /** 329 * CDMA PIP tone: 480Hz 100ms ON, 100ms OFF repeated for 4 times 330 * 331 * @see #ToneGenerator(int, int) 332 */ 333 public static final int TONE_CDMA_PIP = 44; 334 /** 335 * ISDN Call Signal Normal tone: {2091Hz 32ms ON, 2556 64ms ON} 20 times, 336 * 2091 32ms ON, 2556 48ms ON, 4s OFF 337 * 338 * @see #ToneGenerator(int, int) 339 */ 340 public static final int TONE_CDMA_CALL_SIGNAL_ISDN_NORMAL = 45; 341 /** 342 * ISDN Call Signal Intergroup tone: {2091Hz 32ms ON, 2556 64ms ON} 8 times, 343 * 2091Hz 32ms ON, 400ms OFF, {2091Hz 32ms ON, 2556Hz 64ms ON} times, 344 * 2091Hz 32ms ON, 4s OFF. 345 * 346 * @see #ToneGenerator(int, int) 347 */ 348 public static final int TONE_CDMA_CALL_SIGNAL_ISDN_INTERGROUP = 46; 349 /** 350 * ISDN Call Signal SP PRI tone:{2091Hz 32ms ON, 2556 64ms ON} 4 times 351 * 2091Hz 16ms ON, 200ms OFF, {2091Hz 32ms ON, 2556Hz 64ms ON} 4 times, 352 * 2091Hz 16ms ON, 200ms OFF 353 * 354 * @see #ToneGenerator(int, int) 355 */ 356 public static final int TONE_CDMA_CALL_SIGNAL_ISDN_SP_PRI = 47; 357 /** 358 * ISDN Call sign PAT3 tone: silent tone 359 * 360 * @see #ToneGenerator(int, int) 361 */ 362 public static final int TONE_CDMA_CALL_SIGNAL_ISDN_PAT3 = 48; 363 /** 364 * ISDN Ping Ring tone: {2091Hz 32ms ON, 2556Hz 64ms ON} 5 times 365 * 2091Hz 20ms ON 366 * 367 * @see #ToneGenerator(int, int) 368 */ 369 public static final int TONE_CDMA_CALL_SIGNAL_ISDN_PING_RING = 49; 370 /** 371 * 372 * ISDN Pat5 tone: silent tone 373 * @see #ToneGenerator(int, int) 374 */ 375 public static final int TONE_CDMA_CALL_SIGNAL_ISDN_PAT5 = 50; 376 /** 377 * 378 * ISDN Pat6 tone: silent tone 379 * @see #ToneGenerator(int, int) 380 */ 381 public static final int TONE_CDMA_CALL_SIGNAL_ISDN_PAT6 = 51; 382 /** 383 * ISDN Pat7 tone: silent tone 384 * 385 * @see #ToneGenerator(int, int) 386 */ 387 public static final int TONE_CDMA_CALL_SIGNAL_ISDN_PAT7 = 52; 388 /** 389 * TONE_CDMA_HIGH_L tone: {3700Hz 25ms, 4000Hz 25ms} 40 times 390 * 4000ms OFF, Repeat .... 391 * 392 * @see #ToneGenerator(int, int) 393 */ 394 public static final int TONE_CDMA_HIGH_L = 53; 395 /** 396 * TONE_CDMA_MED_L tone: {2600Hz 25ms, 2900Hz 25ms} 40 times 397 * 4000ms OFF, Repeat .... 398 * 399 * @see #ToneGenerator(int, int) 400 */ 401 public static final int TONE_CDMA_MED_L = 54; 402 /** 403 * TONE_CDMA_LOW_L tone: {1300Hz 25ms, 1450Hz 25ms} 40 times, 404 * 4000ms OFF, Repeat .... 405 * 406 * @see #ToneGenerator(int, int) 407 */ 408 public static final int TONE_CDMA_LOW_L = 55; 409 /** 410 * CDMA HIGH SS tone: {3700Hz 25ms, 4000Hz 25ms} repeat 16 times, 411 * 400ms OFF, repeat .... 412 * 413 * @see #ToneGenerator(int, int) 414 */ 415 public static final int TONE_CDMA_HIGH_SS = 56; 416 /** 417 * CDMA MED SS tone: {2600Hz 25ms, 2900Hz 25ms} repeat 16 times, 418 * 400ms OFF, repeat .... 419 * 420 * @see #ToneGenerator(int, int) 421 */ 422 public static final int TONE_CDMA_MED_SS = 57; 423 /** 424 * CDMA LOW SS tone: {1300z 25ms, 1450Hz 25ms} repeat 16 times, 425 * 400ms OFF, repeat .... 426 * 427 * @see #ToneGenerator(int, int) 428 */ 429 public static final int TONE_CDMA_LOW_SS = 58; 430 /** 431 * CDMA HIGH SSL tone: {3700Hz 25ms, 4000Hz 25ms} 8 times, 432 * 200ms OFF, {3700Hz 25ms, 4000Hz 25ms} repeat 8 times, 433 * 200ms OFF, {3700Hz 25ms, 4000Hz 25ms} repeat 16 times, 434 * 4000ms OFF, repeat ... 435 * 436 * @see #ToneGenerator(int, int) 437 */ 438 public static final int TONE_CDMA_HIGH_SSL = 59; 439 /** 440 * CDMA MED SSL tone: {2600Hz 25ms, 2900Hz 25ms} 8 times, 441 * 200ms OFF, {2600Hz 25ms, 2900Hz 25ms} repeat 8 times, 442 * 200ms OFF, {2600Hz 25ms, 2900Hz 25ms} repeat 16 times, 443 * 4000ms OFF, repeat ... 444 * 445 * @see #ToneGenerator(int, int) 446 */ 447 public static final int TONE_CDMA_MED_SSL = 60; 448 /** 449 * CDMA LOW SSL tone: {1300Hz 25ms, 1450Hz 25ms} 8 times, 450 * 200ms OFF, {1300Hz 25ms, 1450Hz 25ms} repeat 8 times, 451 * 200ms OFF, {1300Hz 25ms, 1450Hz 25ms} repeat 16 times, 452 * 4000ms OFF, repeat ... 453 * 454 * @see #ToneGenerator(int, int) 455 */ 456 public static final int TONE_CDMA_LOW_SSL = 61; 457 /** 458 * CDMA HIGH SS2 tone: {3700Hz 25ms, 4000Hz 25ms} 20 times, 459 * 1000ms OFF, {3700Hz 25ms, 4000Hz 25ms} 20 times, 460 * 3000ms OFF, repeat .... 461 * 462 * @see #ToneGenerator(int, int) 463 */ 464 public static final int TONE_CDMA_HIGH_SS_2 = 62; 465 /** 466 * CDMA MED SS2 tone: {2600Hz 25ms, 2900Hz 25ms} 20 times, 467 * 1000ms OFF, {2600Hz 25ms, 2900Hz 25ms} 20 times, 468 * 3000ms OFF, repeat .... 469 * 470 * @see #ToneGenerator(int, int) 471 */ 472 public static final int TONE_CDMA_MED_SS_2 = 63; 473 /** 474 * CDMA LOW SS2 tone: {1300Hz 25ms, 1450Hz 25ms} 20 times, 475 * 1000ms OFF, {1300Hz 25ms, 1450Hz 25ms} 20 times, 476 * 3000ms OFF, repeat .... 477 * 478 * @see #ToneGenerator(int, int) 479 */ 480 public static final int TONE_CDMA_LOW_SS_2 = 64; 481 /** 482 * CDMA HIGH SLS tone: {3700Hz 25ms, 4000Hz 25ms} 10 times, 483 * 500ms OFF, {3700Hz 25ms, 4000Hz 25ms} 20 times, 500ms OFF, 484 * {3700Hz 25ms, 4000Hz 25ms} 10 times, 3000ms OFF, REPEAT 485 * 486 * @see #ToneGenerator(int, int) 487 */ 488 public static final int TONE_CDMA_HIGH_SLS = 65; 489 /** 490 * CDMA MED SLS tone: {2600Hz 25ms, 2900Hz 25ms} 10 times, 491 * 500ms OFF, {2600Hz 25ms, 2900Hz 25ms} 20 times, 500ms OFF, 492 * {2600Hz 25ms, 2900Hz 25ms} 10 times, 3000ms OFF, REPEAT 493 * 494 * 495 * @see #ToneGenerator(int, int) 496 */ 497 public static final int TONE_CDMA_MED_SLS = 66; 498 /** 499 * CDMA LOW SLS tone: {1300Hz 25ms, 1450Hz 25ms} 10 times, 500 * 500ms OFF, {1300Hz 25ms, 1450Hz 25ms} 20 times, 500ms OFF, 501 * {1300Hz 25ms, 1450Hz 25ms} 10 times, 3000ms OFF, REPEAT 502 * 503 * @see #ToneGenerator(int, int) 504 */ 505 public static final int TONE_CDMA_LOW_SLS = 67; 506 /** 507 * CDMA HIGH S X4 tone: {3700Hz 25ms, 4000Hz 25ms} 10 times, 508 * 500ms OFF, {3700Hz 25ms, 4000Hz 25ms} 10 times, 500ms OFF, 509 * {3700Hz 25ms, 4000Hz 25ms} 10 times, 500ms OFF, 510 * {3700Hz 25ms, 4000Hz 25ms} 10 times, 2500ms OFF, REPEAT.... 511 * 512 * @see #ToneGenerator(int, int) 513 */ 514 public static final int TONE_CDMA_HIGH_S_X4 = 68; 515 /** 516 * CDMA MED S X4 tone: {2600Hz 25ms, 2900Hz 25ms} 10 times, 517 * 500ms OFF, {2600Hz 25ms, 2900Hz 25ms} 10 times, 500ms OFF, 518 * {2600Hz 25ms, 2900Hz 25ms} 10 times, 500ms OFF, 519 * {2600Hz 25ms, 2900Hz 25ms} 10 times, 2500ms OFF, REPEAT.... 520 * 521 * @see #ToneGenerator(int, int) 522 */ 523 public static final int TONE_CDMA_MED_S_X4 = 69; 524 /** 525 * CDMA LOW S X4 tone: {2600Hz 25ms, 2900Hz 25ms} 10 times, 526 * 500ms OFF, {2600Hz 25ms, 2900Hz 25ms} 10 times, 500ms OFF, 527 * {2600Hz 25ms, 2900Hz 25ms} 10 times, 500ms OFF, 528 * {2600Hz 25ms, 2900Hz 25ms} 10 times, 2500ms OFF, REPEAT.... 529 * 530 * 531 * @see #ToneGenerator(int, int) 532 */ 533 public static final int TONE_CDMA_LOW_S_X4 = 70; 534 /** 535 * CDMA HIGH PBX L: {3700Hz 25ms, 4000Hz 25ms}20 times, 536 * 2000ms OFF, REPEAT.... 537 * 538 * @see #ToneGenerator(int, int) 539 */ 540 public static final int TONE_CDMA_HIGH_PBX_L = 71; 541 /** 542 * CDMA MED PBX L: {2600Hz 25ms, 2900Hz 25ms}20 times, 543 * 2000ms OFF, REPEAT.... 544 * 545 * @see #ToneGenerator(int, int) 546 */ 547 public static final int TONE_CDMA_MED_PBX_L = 72; 548 /** 549 * CDMA LOW PBX L: {1300Hz 25ms,1450Hz 25ms}20 times, 550 * 2000ms OFF, REPEAT.... 551 * 552 * @see #ToneGenerator(int, int) 553 */ 554 public static final int TONE_CDMA_LOW_PBX_L = 73; 555 /** 556 * CDMA HIGH PBX SS tone: {3700Hz 25ms, 4000Hz 25ms} 8 times 557 * 200 ms OFF, {3700Hz 25ms 4000Hz 25ms}8 times, 558 * 2000ms OFF, REPEAT.... 559 * 560 * @see #ToneGenerator(int, int) 561 */ 562 public static final int TONE_CDMA_HIGH_PBX_SS = 74; 563 /** 564 * CDMA MED PBX SS tone: {2600Hz 25ms, 2900Hz 25ms} 8 times 565 * 200 ms OFF, {2600Hz 25ms 2900Hz 25ms}8 times, 566 * 2000ms OFF, REPEAT.... 567 * 568 * @see #ToneGenerator(int, int) 569 */ 570 public static final int TONE_CDMA_MED_PBX_SS = 75; 571 /** 572 * CDMA LOW PBX SS tone: {1300Hz 25ms, 1450Hz 25ms} 8 times 573 * 200 ms OFF, {1300Hz 25ms 1450Hz 25ms}8 times, 574 * 2000ms OFF, REPEAT.... 575 * 576 * @see #ToneGenerator(int, int) 577 */ 578 public static final int TONE_CDMA_LOW_PBX_SS = 76; 579 /** 580 * CDMA HIGH PBX SSL tone:{3700Hz 25ms, 4000Hz 25ms} 8 times 581 * 200ms OFF, {3700Hz 25ms, 4000Hz 25ms} 8 times, 200ms OFF, 582 * {3700Hz 25ms, 4000Hz 25ms} 16 times, 1000ms OFF, REPEAT.... 583 * 584 * @see #ToneGenerator(int, int) 585 */ 586 public static final int TONE_CDMA_HIGH_PBX_SSL = 77; 587 /** 588 * CDMA MED PBX SSL tone:{2600Hz 25ms, 2900Hz 25ms} 8 times 589 * 200ms OFF, {2600Hz 25ms, 2900Hz 25ms} 8 times, 200ms OFF, 590 * {2600Hz 25ms, 2900Hz 25ms} 16 times, 1000ms OFF, REPEAT.... 591 * 592 * @see #ToneGenerator(int, int) 593 */ 594 public static final int TONE_CDMA_MED_PBX_SSL = 78; 595 /** 596 * CDMA LOW PBX SSL tone:{1300Hz 25ms, 1450Hz 25ms} 8 times 597 * 200ms OFF, {1300Hz 25ms, 1450Hz 25ms} 8 times, 200ms OFF, 598 * {1300Hz 25ms, 1450Hz 25ms} 16 times, 1000ms OFF, REPEAT.... 599 * 600 * 601 * @see #ToneGenerator(int, int) 602 */ 603 public static final int TONE_CDMA_LOW_PBX_SSL = 79; 604 /** 605 * CDMA HIGH PBX SSL tone:{3700Hz 25ms, 4000Hz 25ms} 8 times 606 * 200ms OFF, {3700Hz 25ms, 4000Hz 25ms} 16 times, 200ms OFF, 607 * {3700Hz 25ms, 4000Hz 25ms} 8 times, 1000ms OFF, REPEAT.... 608 * 609 * @see #ToneGenerator(int, int) 610 */ 611 public static final int TONE_CDMA_HIGH_PBX_SLS = 80; 612 /** 613 * CDMA HIGH PBX SLS tone:{2600Hz 25ms, 2900Hz 25ms} 8 times 614 * 200ms OFF, {2600Hz 25ms, 2900Hz 25ms} 16 times, 200ms OFF, 615 * {2600Hz 25ms, 2900Hz 25ms} 8 times, 1000ms OFF, REPEAT.... 616 * 617 * @see #ToneGenerator(int, int) 618 */ 619 public static final int TONE_CDMA_MED_PBX_SLS = 81; 620 /** 621 * CDMA HIGH PBX SLS tone:{1300Hz 25ms, 1450Hz 25ms} 8 times 622 * 200ms OFF, {1300Hz 25ms, 1450Hz 25ms} 16 times, 200ms OFF, 623 * {1300Hz 25ms, 1450Hz 25ms} 8 times, 1000ms OFF, REPEAT.... 624 * 625 * @see #ToneGenerator(int, int) 626 */ 627 public static final int TONE_CDMA_LOW_PBX_SLS = 82; 628 /** 629 * CDMA HIGH PBX X S4 tone: {3700Hz 25ms 4000Hz 25ms} 8 times, 630 * 200ms OFF, {3700Hz 25ms 4000Hz 25ms} 8 times, 200ms OFF, 631 * {3700Hz 25ms 4000Hz 25ms} 8 times, 200ms OFF, 632 * {3700Hz 25ms 4000Hz 25ms} 8 times, 800ms OFF, REPEAT... 633 * 634 * @see #ToneGenerator(int, int) 635 */ 636 public static final int TONE_CDMA_HIGH_PBX_S_X4 = 83; 637 /** 638 * CDMA MED PBX X S4 tone: {2600Hz 25ms 2900Hz 25ms} 8 times, 639 * 200ms OFF, {2600Hz 25ms 2900Hz 25ms} 8 times, 200ms OFF, 640 * {2600Hz 25ms 2900Hz 25ms} 8 times, 200ms OFF, 641 * {2600Hz 25ms 2900Hz 25ms} 8 times, 800ms OFF, REPEAT... 642 * 643 * @see #ToneGenerator(int, int) 644 */ 645 public static final int TONE_CDMA_MED_PBX_S_X4 = 84; 646 /** 647 * CDMA LOW PBX X S4 tone: {1300Hz 25ms 1450Hz 25ms} 8 times, 648 * 200ms OFF, {1300Hz 25ms 1450Hz 25ms} 8 times, 200ms OFF, 649 * {1300Hz 25ms 1450Hz 25ms} 8 times, 200ms OFF, 650 * {1300Hz 25ms 1450Hz 25ms} 8 times, 800ms OFF, REPEAT... 651 * 652 * @see #ToneGenerator(int, int) 653 */ 654 public static final int TONE_CDMA_LOW_PBX_S_X4 = 85; 655 /** 656 * CDMA Alert Network Lite tone: 1109Hz 62ms ON, 784Hz 62ms ON, 740Hz 62ms ON 657 * 622Hz 62ms ON, 1109Hz 62ms ON 658 * 659 * @see #ToneGenerator(int, int) 660 */ 661 public static final int TONE_CDMA_ALERT_NETWORK_LITE = 86; 662 /** 663 * CDMA Alert Auto Redial tone: {1245Hz 62ms ON, 659Hz 62ms ON} 3 times, 664 * 1245 62ms ON 665 * 666 * @see #ToneGenerator(int, int) 667 */ 668 public static final int TONE_CDMA_ALERT_AUTOREDIAL_LITE = 87; 669 /** 670 * CDMA One Min Beep tone: 1150Hz+770Hz 400ms ON 671 * 672 * @see #ToneGenerator(int, int) 673 */ 674 public static final int TONE_CDMA_ONE_MIN_BEEP = 88; 675 /** 676 * 677 * CDMA KEYPAD Volume key lite tone: 941Hz+1477Hz 120ms ON 678 * @see #ToneGenerator(int, int) 679 */ 680 public static final int TONE_CDMA_KEYPAD_VOLUME_KEY_LITE = 89; 681 /** 682 * CDMA PRESSHOLDKEY LITE tone: 587Hz 375ms ON, 1175Hz 125ms ON 683 * 684 * @see #ToneGenerator(int, int) 685 */ 686 public static final int TONE_CDMA_PRESSHOLDKEY_LITE = 90; 687 /** 688 * CDMA ALERT INCALL LITE tone: 587Hz 62ms, 784 62ms, 831Hz 62ms, 689 * 784Hz 62ms, 1109 62ms, 784Hz 62ms, 831Hz 62ms, 784Hz 62ms 690 * 691 * @see #ToneGenerator(int, int) 692 */ 693 public static final int TONE_CDMA_ALERT_INCALL_LITE = 91; 694 /** 695 * CDMA EMERGENCY RINGBACK tone: {941Hz 125ms ON, 10ms OFF} 3times 696 * 4990ms OFF, REPEAT... 697 * 698 * @see #ToneGenerator(int, int) 699 */ 700 public static final int TONE_CDMA_EMERGENCY_RINGBACK = 92; 701 /** 702 * CDMA ALERT CALL GUARD tone: {1319Hz 125ms ON, 125ms OFF} 3 times 703 * 704 * @see #ToneGenerator(int, int) 705 */ 706 public static final int TONE_CDMA_ALERT_CALL_GUARD = 93; 707 /** 708 * CDMA SOFT ERROR LITE tone: 1047Hz 125ms ON, 370Hz 125ms 709 * 710 * @see #ToneGenerator(int, int) 711 */ 712 public static final int TONE_CDMA_SOFT_ERROR_LITE = 94; 713 /** 714 * CDMA CALLDROP LITE tone: 1480Hz 125ms, 1397Hz 125ms, 784Hz 125ms 715 * 716 * @see #ToneGenerator(int, int) 717 */ 718 public static final int TONE_CDMA_CALLDROP_LITE = 95; 719 /** 720 * CDMA_NETWORK_BUSY_ONE_SHOT tone: 425Hz 500ms ON, 500ms OFF. 721 * 722 * @see #ToneGenerator(int, int) 723 */ 724 public static final int TONE_CDMA_NETWORK_BUSY_ONE_SHOT = 96; 725 /** 726 * CDMA_ABBR_ALERT tone: 1150Hz+770Hz 400ms ON 727 * @see #ToneGenerator(int, int) 728 */ 729 public static final int TONE_CDMA_ABBR_ALERT = 97; 730 /** 731 * CDMA_SIGNAL_OFF - silent tone 732 * 733 * @see #ToneGenerator(int, int) 734 */ 735 public static final int TONE_CDMA_SIGNAL_OFF = 98; 736 737 /** Maximum volume, for use with {@link #ToneGenerator(int,int)} */ 738 public static final int MAX_VOLUME = 100; 739 /** Minimum volume setting, for use with {@link #ToneGenerator(int,int)} */ 740 public static final int MIN_VOLUME = 0; 741 742 743 /** 744 * ToneGenerator class contructor specifying output stream type and volume. 745 * 746 * @param streamType The streame type used for tone playback (e.g. STREAM_MUSIC). 747 * @param volume The volume of the tone, given in percentage of maximum volume (from 0-100). 748 * 749 */ ToneGenerator(int streamType, int volume)750 public ToneGenerator(int streamType, int volume) { 751 native_setup(streamType, volume, getCurrentOpPackageName()); 752 } 753 754 /** 755 * This method starts the playback of a tone of the specified type. 756 * only one tone can play at a time: if a tone is playing while this method is called, 757 * this tone is stopped and replaced by the one requested. 758 * @param toneType The type of tone generated chosen from the following list: 759 * <ul> 760 * <li>{@link #TONE_DTMF_0} 761 * <li>{@link #TONE_DTMF_1} 762 * <li>{@link #TONE_DTMF_2} 763 * <li>{@link #TONE_DTMF_3} 764 * <li>{@link #TONE_DTMF_4} 765 * <li>{@link #TONE_DTMF_5} 766 * <li>{@link #TONE_DTMF_6} 767 * <li>{@link #TONE_DTMF_7} 768 * <li>{@link #TONE_DTMF_8} 769 * <li>{@link #TONE_DTMF_9} 770 * <li>{@link #TONE_DTMF_A} 771 * <li>{@link #TONE_DTMF_B} 772 * <li>{@link #TONE_DTMF_C} 773 * <li>{@link #TONE_DTMF_D} 774 * <li>{@link #TONE_SUP_DIAL} 775 * <li>{@link #TONE_SUP_BUSY} 776 * <li>{@link #TONE_SUP_CONGESTION} 777 * <li>{@link #TONE_SUP_RADIO_ACK} 778 * <li>{@link #TONE_SUP_RADIO_NOTAVAIL} 779 * <li>{@link #TONE_SUP_ERROR} 780 * <li>{@link #TONE_SUP_CALL_WAITING} 781 * <li>{@link #TONE_SUP_RINGTONE} 782 * <li>{@link #TONE_PROP_BEEP} 783 * <li>{@link #TONE_PROP_ACK} 784 * <li>{@link #TONE_PROP_NACK} 785 * <li>{@link #TONE_PROP_PROMPT} 786 * <li>{@link #TONE_PROP_BEEP2} 787 * <li>{@link #TONE_SUP_INTERCEPT} 788 * <li>{@link #TONE_SUP_INTERCEPT_ABBREV} 789 * <li>{@link #TONE_SUP_CONGESTION_ABBREV} 790 * <li>{@link #TONE_SUP_CONFIRM} 791 * <li>{@link #TONE_SUP_PIP} 792 * <li>{@link #TONE_CDMA_DIAL_TONE_LITE} 793 * <li>{@link #TONE_CDMA_NETWORK_USA_RINGBACK} 794 * <li>{@link #TONE_CDMA_INTERCEPT} 795 * <li>{@link #TONE_CDMA_ABBR_INTERCEPT} 796 * <li>{@link #TONE_CDMA_REORDER} 797 * <li>{@link #TONE_CDMA_ABBR_REORDER} 798 * <li>{@link #TONE_CDMA_NETWORK_BUSY} 799 * <li>{@link #TONE_CDMA_CONFIRM} 800 * <li>{@link #TONE_CDMA_ANSWER} 801 * <li>{@link #TONE_CDMA_NETWORK_CALLWAITING} 802 * <li>{@link #TONE_CDMA_PIP} 803 * <li>{@link #TONE_CDMA_CALL_SIGNAL_ISDN_NORMAL} 804 * <li>{@link #TONE_CDMA_CALL_SIGNAL_ISDN_INTERGROUP} 805 * <li>{@link #TONE_CDMA_CALL_SIGNAL_ISDN_SP_PRI} 806 * <li>{@link #TONE_CDMA_CALL_SIGNAL_ISDN_PAT3} 807 * <li>{@link #TONE_CDMA_CALL_SIGNAL_ISDN_PING_RING} 808 * <li>{@link #TONE_CDMA_CALL_SIGNAL_ISDN_PAT5} 809 * <li>{@link #TONE_CDMA_CALL_SIGNAL_ISDN_PAT6} 810 * <li>{@link #TONE_CDMA_CALL_SIGNAL_ISDN_PAT7} 811 * <li>{@link #TONE_CDMA_HIGH_L} 812 * <li>{@link #TONE_CDMA_MED_L} 813 * <li>{@link #TONE_CDMA_LOW_L} 814 * <li>{@link #TONE_CDMA_HIGH_SS} 815 * <li>{@link #TONE_CDMA_MED_SS} 816 * <li>{@link #TONE_CDMA_LOW_SS} 817 * <li>{@link #TONE_CDMA_HIGH_SSL} 818 * <li>{@link #TONE_CDMA_MED_SSL} 819 * <li>{@link #TONE_CDMA_LOW_SSL} 820 * <li>{@link #TONE_CDMA_HIGH_SS_2} 821 * <li>{@link #TONE_CDMA_MED_SS_2} 822 * <li>{@link #TONE_CDMA_LOW_SS_2} 823 * <li>{@link #TONE_CDMA_HIGH_SLS} 824 * <li>{@link #TONE_CDMA_MED_SLS} 825 * <li>{@link #TONE_CDMA_LOW_SLS} 826 * <li>{@link #TONE_CDMA_HIGH_S_X4} 827 * <li>{@link #TONE_CDMA_MED_S_X4} 828 * <li>{@link #TONE_CDMA_LOW_S_X4} 829 * <li>{@link #TONE_CDMA_HIGH_PBX_L} 830 * <li>{@link #TONE_CDMA_MED_PBX_L} 831 * <li>{@link #TONE_CDMA_LOW_PBX_L} 832 * <li>{@link #TONE_CDMA_HIGH_PBX_SS} 833 * <li>{@link #TONE_CDMA_MED_PBX_SS} 834 * <li>{@link #TONE_CDMA_LOW_PBX_SS} 835 * <li>{@link #TONE_CDMA_HIGH_PBX_SSL} 836 * <li>{@link #TONE_CDMA_MED_PBX_SSL} 837 * <li>{@link #TONE_CDMA_LOW_PBX_SSL} 838 * <li>{@link #TONE_CDMA_HIGH_PBX_SLS} 839 * <li>{@link #TONE_CDMA_MED_PBX_SLS} 840 * <li>{@link #TONE_CDMA_LOW_PBX_SLS} 841 * <li>{@link #TONE_CDMA_HIGH_PBX_S_X4} 842 * <li>{@link #TONE_CDMA_MED_PBX_S_X4} 843 * <li>{@link #TONE_CDMA_LOW_PBX_S_X4} 844 * <li>{@link #TONE_CDMA_ALERT_NETWORK_LITE} 845 * <li>{@link #TONE_CDMA_ALERT_AUTOREDIAL_LITE} 846 * <li>{@link #TONE_CDMA_ONE_MIN_BEEP} 847 * <li>{@link #TONE_CDMA_KEYPAD_VOLUME_KEY_LITE} 848 * <li>{@link #TONE_CDMA_PRESSHOLDKEY_LITE} 849 * <li>{@link #TONE_CDMA_ALERT_INCALL_LITE} 850 * <li>{@link #TONE_CDMA_EMERGENCY_RINGBACK} 851 * <li>{@link #TONE_CDMA_ALERT_CALL_GUARD} 852 * <li>{@link #TONE_CDMA_SOFT_ERROR_LITE} 853 * <li>{@link #TONE_CDMA_CALLDROP_LITE} 854 * <li>{@link #TONE_CDMA_NETWORK_BUSY_ONE_SHOT} 855 * <li>{@link #TONE_CDMA_ABBR_ALERT} 856 * <li>{@link #TONE_CDMA_SIGNAL_OFF} 857 * </ul> 858 * @see #ToneGenerator(int, int) 859 */ startTone(int toneType)860 public boolean startTone(int toneType) { 861 return startTone(toneType, -1); 862 } 863 864 /** 865 * This method starts the playback of a tone of the specified type for the specified duration. 866 * @param toneType The type of tone generated @see {@link #startTone(int)}. 867 * @param durationMs The tone duration in milliseconds. If the tone is limited in time by definition, 868 * the actual duration will be the minimum of durationMs and the defined tone duration. Setting durationMs to -1, 869 * is equivalent to calling {@link #startTone(int)}. 870 */ startTone(int toneType, int durationMs)871 public native boolean startTone(int toneType, int durationMs); 872 873 /** 874 * This method stops the tone currently playing playback. 875 * @see #ToneGenerator(int, int) 876 */ stopTone()877 public native void stopTone(); 878 879 /** 880 * Releases resources associated with this ToneGenerator object. It is good 881 * practice to call this method when you're done using the ToneGenerator. 882 */ release()883 public native void release(); 884 native_setup( int streamType, int volume, @NonNull String opPackageName)885 private native void native_setup( 886 int streamType, int volume, @NonNull String opPackageName); 887 native_finalize()888 private native final void native_finalize(); 889 890 /** 891 * Returns the audio session ID. 892 * 893 * @return the ID of the audio session this ToneGenerator belongs to or 0 if an error 894 * occured. 895 */ getAudioSessionId()896 public native final int getAudioSessionId(); 897 898 @Override finalize()899 protected void finalize() { native_finalize(); } 900 getCurrentOpPackageName()901 private String getCurrentOpPackageName() { 902 return TextUtils.emptyIfNull(ActivityThread.currentOpPackageName()); 903 } 904 905 @SuppressWarnings("unused") 906 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 907 private long mNativeContext; // accessed by native methods 908 } 909