private void b(KeyEvent paramKeyEvent) {
   int i = paramKeyEvent.getKeyCode();
   switch (i) {
     default:
     case 24:
     case 25:
     case 164:
   }
   while (true) {
     return;
     AudioManager localAudioManager = this.a;
     if (i == 24) ;
     for (int j = 1; ; j = -1) {
       localAudioManager.adjustSuggestedStreamVolume(j, this.b, 17);
       break;
     }
     if (paramKeyEvent.getRepeatCount() != 0) continue;
   }
 }
Ejemplo n.º 2
0
  @TestTargets({
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "setStreamVolume",
        args = {int.class, int.class, int.class}),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "getStreamMaxVolume",
        args = {int.class}),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "getStreamVolume",
        args = {int.class}),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "adjustStreamVolume",
        args = {int.class, int.class, int.class}),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "adjustSuggestedStreamVolume",
        args = {int.class, int.class, int.class}),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "adjustVolume",
        args = {int.class, int.class})
  })
  public void testVolume() throws Exception {
    int[] streams = {
      AudioManager.STREAM_ALARM,
      AudioManager.STREAM_MUSIC,
      AudioManager.STREAM_SYSTEM,
      AudioManager.STREAM_VOICE_CALL,
      AudioManager.STREAM_RING
    };

    mAudioManager.adjustVolume(ADJUST_RAISE, 100);
    mAudioManager.adjustSuggestedStreamVolume(ADJUST_LOWER, USE_DEFAULT_STREAM_TYPE, FLAG_SHOW_UI);

    for (int i = 0; i < streams.length; i++) {
      int maxVolume = mAudioManager.getStreamMaxVolume(streams[i]);

      mAudioManager.setStreamVolume(streams[i], 1, FLAG_SHOW_UI);
      assertEquals(1, mAudioManager.getStreamVolume(streams[i]));

      mAudioManager.setStreamVolume(streams[i], maxVolume, FLAG_SHOW_UI);
      mAudioManager.adjustStreamVolume(streams[i], ADJUST_RAISE, FLAG_SHOW_UI);
      assertEquals(maxVolume, mAudioManager.getStreamVolume(streams[i]));

      mAudioManager.adjustSuggestedStreamVolume(ADJUST_LOWER, streams[i], FLAG_SHOW_UI);
      assertEquals(maxVolume - 1, mAudioManager.getStreamVolume(streams[i]));

      // volume lower
      mAudioManager.setStreamVolume(streams[i], maxVolume, FLAG_SHOW_UI);
      for (int k = maxVolume; k > 0; k--) {
        mAudioManager.adjustStreamVolume(streams[i], ADJUST_LOWER, FLAG_SHOW_UI);
        assertEquals(k - 1, mAudioManager.getStreamVolume(streams[i]));
      }

      mAudioManager.setRingerMode(RINGER_MODE_NORMAL);
      assertEquals(RINGER_MODE_NORMAL, mAudioManager.getRingerMode());
      mAudioManager.setStreamVolume(streams[i], 1, FLAG_SHOW_UI);
      assertEquals(1, mAudioManager.getStreamVolume(streams[i]));
      if (streams[i] == AudioManager.STREAM_RING) {
        mAudioManager.adjustStreamVolume(streams[i], ADJUST_LOWER, FLAG_SHOW_UI);
        assertEquals(0, mAudioManager.getStreamVolume(streams[i]));
        // adjusting the volume to zero should result in either silent or vibrate mode
        assertTrue(
            mAudioManager.getRingerMode() == RINGER_MODE_VIBRATE
                || mAudioManager.getRingerMode() == RINGER_MODE_SILENT);
        mAudioManager.setRingerMode(RINGER_MODE_NORMAL);
        assertEquals(RINGER_MODE_NORMAL, mAudioManager.getRingerMode());
        assertEquals(1, mAudioManager.getStreamVolume(streams[i]));
      } else {
        mAudioManager.adjustStreamVolume(streams[i], ADJUST_LOWER, FLAG_SHOW_UI);
        assertEquals(0, mAudioManager.getStreamVolume(streams[i]));
        // lowering the volume should NOT have changed the ringer mode
        assertEquals(RINGER_MODE_NORMAL, mAudioManager.getRingerMode());
        // API quirk: volume must be decremented from 1 to get ringer mode change
        mAudioManager.setStreamVolume(streams[i], 1, FLAG_SHOW_UI);
        mAudioManager.adjustStreamVolume(streams[i], ADJUST_LOWER, FLAG_ALLOW_RINGER_MODES);
        // lowering the volume should have changed the ringer mode
        assertTrue(
            mAudioManager.getRingerMode() == RINGER_MODE_VIBRATE
                || mAudioManager.getRingerMode() == RINGER_MODE_SILENT);
        mAudioManager.adjustStreamVolume(streams[i], ADJUST_LOWER, FLAG_ALLOW_RINGER_MODES);
        // adjusting the volume to zero should result in either silent or vibrate mode
        assertTrue(
            mAudioManager.getRingerMode() == RINGER_MODE_VIBRATE
                || mAudioManager.getRingerMode() == RINGER_MODE_SILENT);
        mAudioManager.adjustStreamVolume(streams[i], ADJUST_RAISE, FLAG_ALLOW_RINGER_MODES);
        // There are two possible ways the device may work. It may have a silent/vibrate
        // mode or it may have distinct silent and vibrate modes.
        assertTrue(
            mAudioManager.getRingerMode() == RINGER_MODE_NORMAL
                || mAudioManager.getRingerMode() == RINGER_MODE_VIBRATE);
        // Increase the volume one more time to get out of the vibrate mode which may
        // be separate from silent mode.
        mAudioManager.adjustStreamVolume(streams[i], ADJUST_RAISE, FLAG_ALLOW_RINGER_MODES);
        assertEquals(RINGER_MODE_NORMAL, mAudioManager.getRingerMode());
      }

      // volume raise
      mAudioManager.setStreamVolume(streams[i], 0, FLAG_SHOW_UI);
      for (int k = 0; k < maxVolume; k++) {
        mAudioManager.adjustStreamVolume(streams[i], ADJUST_RAISE, FLAG_SHOW_UI);
        assertEquals(1 + k, mAudioManager.getStreamVolume(streams[i]));
      }

      // volume same
      mAudioManager.setStreamVolume(streams[i], maxVolume, FLAG_SHOW_UI);
      for (int k = 0; k < maxVolume; k++) {
        mAudioManager.adjustStreamVolume(streams[i], ADJUST_SAME, FLAG_SHOW_UI);
        assertEquals(maxVolume, mAudioManager.getStreamVolume(streams[i]));
      }

      mAudioManager.setStreamVolume(streams[i], maxVolume, FLAG_SHOW_UI);
    }

    // adjust volume
    int maxVolume = mAudioManager.getStreamMaxVolume(STREAM_MUSIC);
    mAudioManager.adjustVolume(ADJUST_RAISE, 100);

    MediaPlayer mp = MediaPlayer.create(mContext, MP3_TO_PLAY);
    mp.setAudioStreamType(STREAM_MUSIC);
    mp.setLooping(true);
    mp.start();
    Thread.sleep(TIME_TO_PLAY);
    assertTrue(mAudioManager.isMusicActive());

    // adjust volume as ADJUST_SAME
    for (int k = 0; k < maxVolume; k++) {
      mAudioManager.adjustVolume(ADJUST_SAME, FLAG_SHOW_UI);
      assertEquals(maxVolume, mAudioManager.getStreamVolume(STREAM_MUSIC));
    }

    // adjust volume as ADJUST_RAISE
    mAudioManager.setStreamVolume(STREAM_MUSIC, 1, FLAG_SHOW_UI);
    for (int k = 0; k < maxVolume - 1; k++) {
      mAudioManager.adjustVolume(ADJUST_RAISE, FLAG_SHOW_UI);
      assertEquals(2 + k, mAudioManager.getStreamVolume(STREAM_MUSIC));
    }

    // adjust volume as ADJUST_LOWER
    mAudioManager.setStreamVolume(STREAM_MUSIC, maxVolume, FLAG_SHOW_UI);
    maxVolume = mAudioManager.getStreamVolume(STREAM_MUSIC);

    mAudioManager.adjustVolume(ADJUST_LOWER, FLAG_SHOW_UI);
    assertEquals(maxVolume - 1, mAudioManager.getStreamVolume(STREAM_MUSIC));
    mp.stop();
    mp.release();
    Thread.sleep(TIME_TO_PLAY);
    assertFalse(mAudioManager.isMusicActive());
  }