void saveSettings() {
   if (!PreferenceManager.getDefaultSharedPreferences(Receiver.mContext)
       .getBoolean(
           org.sipdroid.sipua.ui.Settings.PREF_OLDVALID,
           org.sipdroid.sipua.ui.Settings.DEFAULT_OLDVALID)) {
     int oldvibrate = am.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER);
     int oldvibrate2 = am.getVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION);
     if (!PreferenceManager.getDefaultSharedPreferences(Receiver.mContext)
         .contains(org.sipdroid.sipua.ui.Settings.PREF_OLDVIBRATE2))
       oldvibrate2 = AudioManager.VIBRATE_SETTING_ON;
     int oldpolicy =
         android.provider.Settings.System.getInt(
             cr,
             android.provider.Settings.System.WIFI_SLEEP_POLICY,
             Settings.System.WIFI_SLEEP_POLICY_DEFAULT);
     Editor edit = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext).edit();
     edit.putInt(org.sipdroid.sipua.ui.Settings.PREF_OLDVIBRATE, oldvibrate);
     edit.putInt(org.sipdroid.sipua.ui.Settings.PREF_OLDVIBRATE2, oldvibrate2);
     edit.putInt(org.sipdroid.sipua.ui.Settings.PREF_OLDPOLICY, oldpolicy);
     edit.putInt(
         org.sipdroid.sipua.ui.Settings.PREF_OLDRING,
         am.getStreamVolume(AudioManager.STREAM_RING));
     edit.putBoolean(org.sipdroid.sipua.ui.Settings.PREF_OLDVALID, true);
     edit.commit();
   }
 }
  private String getPhoneVibrateSettingValue() {
    boolean vibeInSilent =
        (Settings.System.getInt(getContentResolver(), Settings.System.VIBRATE_IN_SILENT, 1) == 1);

    // Control phone vibe independent of silent mode
    int callsVibrateSetting = mAudioManager.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER);

    if (vibeInSilent) {
      if (callsVibrateSetting == AudioManager.VIBRATE_SETTING_OFF) {
        // this state does not make sense; fix it up for the user
        mAudioManager.setVibrateSetting(
            AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ONLY_SILENT);
      }
      if (callsVibrateSetting == AudioManager.VIBRATE_SETTING_ON) {
        return VALUE_VIBRATE_ALWAYS;
      } else {
        return VALUE_VIBRATE_ONLY_SILENT;
      }
    } else {
      if (callsVibrateSetting == AudioManager.VIBRATE_SETTING_ONLY_SILENT) {
        // this state does not make sense; fix it up
        mAudioManager.setVibrateSetting(
            AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);
      }
      if (callsVibrateSetting == AudioManager.VIBRATE_SETTING_ON) {
        return VALUE_VIBRATE_UNLESS_SILENT;
      } else {
        return VALUE_VIBRATE_NEVER;
      }
    }
  }
  private final synchronized void update(String newName, int newState) {
    if (newName != mRingerswitchName || newState != mRingerswitchState) {
      boolean isRingerOn = (newState == 0 && mRingerswitchState == 1);

      mRingerswitchName = newName;
      mRingerswitchState = newState;

      try {

        if (isRingerOn) {
          // Log.w(TAG,"Got ringer on");
          mAudioService.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        } else {
          // Log.w(TAG,"Got ringer off");
          AudioManager mAudioManager =
              (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
          boolean vibrateSetting =
              mAudioManager.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER)
                  == AudioManager.VIBRATE_SETTING_ON;

          // We probably lowered the volume on the way "down", so
          // raise it a notch before muting
          mAudioService.adjustStreamVolume(AudioManager.STREAM_RING, AudioManager.ADJUST_RAISE, 0);
          mAudioService.setRingerMode(
              vibrateSetting ? AudioManager.RINGER_MODE_VIBRATE : AudioManager.RINGER_MODE_SILENT);
        }

        // Raise UI
        mHandler.post(mVolumeChangeUiRunnable);

      } catch (RemoteException e) {
      }
    }
  }
  protected void setVibrateTo(boolean on) {

    if (Log.DEBUG) Log.d("on = " + on);

    if (on && _vibrateIsMuted) {

      _vibrateIsMuted = false;

      if (_defaultVibrateSettings == AudioManager.VIBRATE_SETTING_OFF) {
        return;
      }

      _audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, _defaultVibrateSettings);
      _audioManager.setVibrateSetting(
          AudioManager.VIBRATE_TYPE_NOTIFICATION, _defaultVibrateSettings);
    }

    if (!on && !_vibrateIsMuted) {

      _vibrateIsMuted = true;

      _defaultVibrateSettings = _audioManager.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER);
      if (_defaultVibrateSettings == AudioManager.VIBRATE_SETTING_OFF) {
        return;
      }

      _vibrator.cancel();
      _audioManager.setVibrateSetting(
          AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);
      _audioManager.setVibrateSetting(
          AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_OFF);
      _vibrator.cancel();
    }
  }
Example #5
0
  // updateState in fact updates the UI to reflect the system state
  private void updateState(boolean force) {
    if (getActivity() == null) return;

    final int vibrateMode = mAudioManager.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER);

    mVibrateOnRing.setChecked(vibrateMode == AudioManager.VIBRATE_SETTING_ON);
    mSilentMode.setValue(getPhoneSilentModeSettingValue());

    mSilentMode.setSummary(mSilentMode.getEntry());
  }
  @TestTargets({
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "shouldVibrate",
        args = {int.class}),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "setVibrateSetting",
        args = {int.class, int.class}),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "getVibrateSetting",
        args = {int.class}),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "setRingerMode",
        args = {int.class})
  })
  public void testVibrateRinger() throws Exception {
    // VIBRATE_TYPE_RINGER
    mAudioManager.setVibrateSetting(VIBRATE_TYPE_RINGER, VIBRATE_SETTING_ON);
    assertEquals(VIBRATE_SETTING_ON, mAudioManager.getVibrateSetting(VIBRATE_TYPE_RINGER));
    mAudioManager.setRingerMode(RINGER_MODE_NORMAL);
    assertTrue(mAudioManager.shouldVibrate(VIBRATE_TYPE_RINGER));

    mAudioManager.setRingerMode(RINGER_MODE_SILENT);
    assertFalse(mAudioManager.shouldVibrate(VIBRATE_TYPE_RINGER));

    mAudioManager.setRingerMode(RINGER_MODE_VIBRATE);
    assertEquals(RINGER_MODE_VIBRATE, mAudioManager.getRingerMode());
    assertTrue(mAudioManager.shouldVibrate(VIBRATE_TYPE_RINGER));

    // VIBRATE_SETTING_OFF
    mAudioManager.setVibrateSetting(VIBRATE_TYPE_RINGER, VIBRATE_SETTING_OFF);
    assertEquals(VIBRATE_SETTING_OFF, mAudioManager.getVibrateSetting(VIBRATE_TYPE_RINGER));
    mAudioManager.setRingerMode(RINGER_MODE_NORMAL);
    assertFalse(mAudioManager.shouldVibrate(VIBRATE_TYPE_RINGER));

    mAudioManager.setRingerMode(RINGER_MODE_SILENT);
    assertFalse(mAudioManager.shouldVibrate(VIBRATE_TYPE_RINGER));

    mAudioManager.setRingerMode(RINGER_MODE_VIBRATE);
    assertEquals(RINGER_MODE_VIBRATE, mAudioManager.getRingerMode());
    // Note: as of Froyo, if VIBRATE_TYPE_RINGER is set to OFF, it will
    // not vibrate, even in RINGER_MODE_VIBRATE. This allows users to
    // disable the vibration for incoming calls only.
    assertFalse(mAudioManager.shouldVibrate(VIBRATE_TYPE_RINGER));

    // VIBRATE_SETTING_ONLY_SILENT
    mAudioManager.setVibrateSetting(VIBRATE_TYPE_RINGER, VIBRATE_SETTING_ONLY_SILENT);
    assertEquals(VIBRATE_SETTING_ONLY_SILENT, mAudioManager.getVibrateSetting(VIBRATE_TYPE_RINGER));
    mAudioManager.setRingerMode(RINGER_MODE_NORMAL);
    assertFalse(mAudioManager.shouldVibrate(VIBRATE_TYPE_RINGER));

    mAudioManager.setRingerMode(RINGER_MODE_SILENT);
    assertFalse(mAudioManager.shouldVibrate(VIBRATE_TYPE_RINGER));

    mAudioManager.setRingerMode(RINGER_MODE_VIBRATE);
    assertEquals(RINGER_MODE_VIBRATE, mAudioManager.getRingerMode());
    assertTrue(mAudioManager.shouldVibrate(VIBRATE_TYPE_RINGER));

    // VIBRATE_TYPE_NOTIFICATION
    mAudioManager.setVibrateSetting(VIBRATE_TYPE_RINGER, VIBRATE_SETTING_ON);
    assertEquals(VIBRATE_SETTING_ON, mAudioManager.getVibrateSetting(VIBRATE_TYPE_RINGER));
    mAudioManager.setVibrateSetting(VIBRATE_TYPE_RINGER, VIBRATE_SETTING_OFF);
    assertEquals(VIBRATE_SETTING_OFF, mAudioManager.getVibrateSetting(VIBRATE_TYPE_RINGER));
    mAudioManager.setVibrateSetting(VIBRATE_TYPE_RINGER, VIBRATE_SETTING_ONLY_SILENT);
    assertEquals(VIBRATE_SETTING_ONLY_SILENT, mAudioManager.getVibrateSetting(VIBRATE_TYPE_RINGER));
  }
  @TestTargets({
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "shouldVibrate",
        args = {int.class}),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "setVibrateSetting",
        args = {int.class, int.class}),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "getVibrateSetting",
        args = {int.class}),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        method = "setRingerMode",
        args = {int.class})
  })
  public void testVibrateNotification() throws Exception {
    // VIBRATE_SETTING_ON
    mAudioManager.setVibrateSetting(VIBRATE_TYPE_NOTIFICATION, VIBRATE_SETTING_ON);
    assertEquals(VIBRATE_SETTING_ON, mAudioManager.getVibrateSetting(VIBRATE_TYPE_NOTIFICATION));
    mAudioManager.setRingerMode(RINGER_MODE_NORMAL);
    assertTrue(mAudioManager.shouldVibrate(VIBRATE_TYPE_NOTIFICATION));

    mAudioManager.setRingerMode(RINGER_MODE_SILENT);
    assertFalse(mAudioManager.shouldVibrate(VIBRATE_TYPE_NOTIFICATION));

    mAudioManager.setRingerMode(RINGER_MODE_VIBRATE);
    assertEquals(RINGER_MODE_VIBRATE, mAudioManager.getRingerMode());
    assertTrue(mAudioManager.shouldVibrate(VIBRATE_TYPE_NOTIFICATION));

    // VIBRATE_SETTING_OFF
    mAudioManager.setVibrateSetting(VIBRATE_TYPE_NOTIFICATION, VIBRATE_SETTING_OFF);
    assertEquals(VIBRATE_SETTING_OFF, mAudioManager.getVibrateSetting(VIBRATE_TYPE_NOTIFICATION));
    mAudioManager.setRingerMode(RINGER_MODE_NORMAL);
    assertFalse(mAudioManager.shouldVibrate(VIBRATE_TYPE_NOTIFICATION));

    mAudioManager.setRingerMode(RINGER_MODE_SILENT);
    assertFalse(mAudioManager.shouldVibrate(VIBRATE_TYPE_NOTIFICATION));

    mAudioManager.setRingerMode(RINGER_MODE_VIBRATE);
    assertEquals(RINGER_MODE_VIBRATE, mAudioManager.getRingerMode());
    assertFalse(mAudioManager.shouldVibrate(VIBRATE_TYPE_NOTIFICATION));

    // VIBRATE_SETTING_ONLY_SILENT
    mAudioManager.setVibrateSetting(VIBRATE_TYPE_NOTIFICATION, VIBRATE_SETTING_ONLY_SILENT);
    assertEquals(
        VIBRATE_SETTING_ONLY_SILENT, mAudioManager.getVibrateSetting(VIBRATE_TYPE_NOTIFICATION));
    mAudioManager.setRingerMode(RINGER_MODE_NORMAL);
    assertFalse(mAudioManager.shouldVibrate(VIBRATE_TYPE_NOTIFICATION));

    mAudioManager.setRingerMode(RINGER_MODE_SILENT);
    assertFalse(mAudioManager.shouldVibrate(VIBRATE_TYPE_NOTIFICATION));

    mAudioManager.setRingerMode(RINGER_MODE_VIBRATE);
    assertEquals(RINGER_MODE_VIBRATE, mAudioManager.getRingerMode());
    assertTrue(mAudioManager.shouldVibrate(VIBRATE_TYPE_NOTIFICATION));

    // VIBRATE_TYPE_NOTIFICATION
    mAudioManager.setVibrateSetting(VIBRATE_TYPE_NOTIFICATION, VIBRATE_SETTING_ON);
    assertEquals(VIBRATE_SETTING_ON, mAudioManager.getVibrateSetting(VIBRATE_TYPE_NOTIFICATION));
    mAudioManager.setVibrateSetting(VIBRATE_TYPE_NOTIFICATION, VIBRATE_SETTING_OFF);
    assertEquals(VIBRATE_SETTING_OFF, mAudioManager.getVibrateSetting(VIBRATE_TYPE_NOTIFICATION));
    mAudioManager.setVibrateSetting(VIBRATE_TYPE_NOTIFICATION, VIBRATE_SETTING_ONLY_SILENT);
    assertEquals(
        VIBRATE_SETTING_ONLY_SILENT, mAudioManager.getVibrateSetting(VIBRATE_TYPE_NOTIFICATION));
  }