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; } } }
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(); } }
/** Put the audio system into the correct vibrate setting */ private void setPhoneVibrateSettingValue(boolean vibeOnRing) { // If vibrate-on-ring is checked, use VIBRATE_SETTING_ON // Otherwise vibrate is off when ringer is silent int vibrateMode = vibeOnRing ? AudioManager.VIBRATE_SETTING_ON : AudioManager.VIBRATE_SETTING_ONLY_SILENT; mAudioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, vibrateMode); mAudioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, vibrateMode); }
private void setPhoneVibrateSettingValue(String value) { boolean vibeInSilent; int callsVibrateSetting; if (value.equals(VALUE_VIBRATE_UNLESS_SILENT)) { callsVibrateSetting = AudioManager.VIBRATE_SETTING_ON; vibeInSilent = false; } else if (value.equals(VALUE_VIBRATE_NEVER)) { callsVibrateSetting = AudioManager.VIBRATE_SETTING_OFF; vibeInSilent = false; } else if (value.equals(VALUE_VIBRATE_ONLY_SILENT)) { callsVibrateSetting = AudioManager.VIBRATE_SETTING_ONLY_SILENT; vibeInSilent = true; } else { // VALUE_VIBRATE_ALWAYS callsVibrateSetting = AudioManager.VIBRATE_SETTING_ON; vibeInSilent = true; } Settings.System.putInt( getContentResolver(), Settings.System.VIBRATE_IN_SILENT, vibeInSilent ? 1 : 0); // might need to switch the ringer mode from one kind of "silent" to // another if (mSilent.isChecked()) { mAudioManager.setRingerMode( vibeInSilent ? AudioManager.RINGER_MODE_VIBRATE : AudioManager.RINGER_MODE_SILENT); } mAudioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, callsVibrateSetting); }
public static void restoreSettings() { if (PreferenceManager.getDefaultSharedPreferences(Receiver.mContext) .getBoolean( org.sipdroid.sipua.ui.Settings.PREF_OLDVALID, org.sipdroid.sipua.ui.Settings.DEFAULT_OLDVALID)) { AudioManager am = (AudioManager) Receiver.mContext.getSystemService(Context.AUDIO_SERVICE); ContentResolver cr = Receiver.mContext.getContentResolver(); int oldvibrate = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext) .getInt( org.sipdroid.sipua.ui.Settings.PREF_OLDVIBRATE, org.sipdroid.sipua.ui.Settings.DEFAULT_OLDVIBRATE); int oldvibrate2 = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext) .getInt( org.sipdroid.sipua.ui.Settings.PREF_OLDVIBRATE2, org.sipdroid.sipua.ui.Settings.DEFAULT_OLDVIBRATE2); int oldpolicy = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext) .getInt( org.sipdroid.sipua.ui.Settings.PREF_OLDPOLICY, org.sipdroid.sipua.ui.Settings.DEFAULT_OLDPOLICY); am.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, oldvibrate); am.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, oldvibrate2); Settings.System.putInt(cr, Settings.System.WIFI_SLEEP_POLICY, oldpolicy); int oldring = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext).getInt("oldring", 0); if (oldring > 0) am.setStreamVolume(AudioManager.STREAM_RING, oldring, 0); Editor edit = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext).edit(); edit.putBoolean(org.sipdroid.sipua.ui.Settings.PREF_OLDVALID, false); edit.commit(); PowerManager pm = (PowerManager) Receiver.mContext.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock( PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "Sipdroid.RtpStreamReceiver"); wl.acquire(1000); } restoreMode(); }
/** Runs it in a new Thread. */ public void run() { boolean nodata = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext) .getBoolean( org.sipdroid.sipua.ui.Settings.PREF_NODATA, org.sipdroid.sipua.ui.Settings.DEFAULT_NODATA); keepon = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext) .getBoolean( org.sipdroid.sipua.ui.Settings.PREF_KEEPON, org.sipdroid.sipua.ui.Settings.DEFAULT_KEEPON); if (rtp_socket == null) { if (DEBUG) println("ERROR: RTP socket is null"); return; } byte[] buffer = new byte[BUFFER_SIZE + 12]; rtp_packet = new RtpPacket(buffer, 0); if (DEBUG) println("Reading blocks of max " + buffer.length + " bytes"); running = true; enableBluetooth( PreferenceManager.getDefaultSharedPreferences(Receiver.mContext) .getBoolean( org.sipdroid.sipua.ui.Settings.PREF_BLUETOOTH, org.sipdroid.sipua.ui.Settings.DEFAULT_BLUETOOTH)); restored = false; android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_AUDIO); am = (AudioManager) Receiver.mContext.getSystemService(Context.AUDIO_SERVICE); cr = Receiver.mContext.getContentResolver(); saveSettings(); Settings.System.putInt( cr, Settings.System.WIFI_SLEEP_POLICY, Settings.System.WIFI_SLEEP_POLICY_NEVER); am.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF); am.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_OFF); if (oldvol == -1) oldvol = am.getStreamVolume(AudioManager.STREAM_MUSIC); initMode(); setCodec(); short lin[] = new short[BUFFER_SIZE]; short lin2[] = new short[BUFFER_SIZE]; int server, headroom, todo, len = 0, m = 1, expseq, getseq, vm = 1, gap, gseq; ToneGenerator tg = new ToneGenerator( AudioManager.STREAM_VOICE_CALL, (int) (ToneGenerator.MAX_VOLUME * 2 * org.sipdroid.sipua.ui.Settings.getEarGain())); track.play(); System.gc(); empty(); lockFirst = true; while (running) { lock(true); if (Receiver.call_state == UserAgent.UA_STATE_HOLD) { lock(false); tg.stopTone(); track.pause(); while (running && Receiver.call_state == UserAgent.UA_STATE_HOLD) { try { sleep(1000); } catch (InterruptedException e1) { } } track.play(); System.gc(); timeout = 1; luser = luser2 = -8000 * mu; } try { rtp_socket.receive(rtp_packet); if (timeout != 0) { tg.stopTone(); track.pause(); for (int i = maxjitter * 2; i > 0; i -= BUFFER_SIZE) write(lin2, 0, i > BUFFER_SIZE ? BUFFER_SIZE : i); cnt += maxjitter * 2; track.play(); empty(); } timeout = 0; } catch (IOException e) { if (timeout == 0 && nodata) { tg.startTone(ToneGenerator.TONE_SUP_RINGTONE); } rtp_socket.getDatagramSocket().disconnect(); if (++timeout > 60) { Receiver.engine(Receiver.mContext).rejectcall(); break; } } if (running && timeout == 0) { gseq = rtp_packet.getSequenceNumber(); if (seq == gseq) { m++; continue; } gap = (gseq - seq) & 0xff; if (gap > 240) continue; server = track.getPlaybackHeadPosition(); headroom = user - server; if (headroom > 2 * jitter) cnt += len; else cnt = 0; if (lserver == server) cnt2++; else cnt2 = 0; if (cnt <= 500 * mu || cnt2 >= 2 || headroom - jitter < len || p_type.codec.number() != 8 || p_type.codec.number() != 0) { if (rtp_packet.getPayloadType() != p_type.number && p_type.change(rtp_packet.getPayloadType())) { saveVolume(); setCodec(); restoreVolume(); codec = p_type.codec.getTitle(); } len = p_type.codec.decode(buffer, lin, rtp_packet.getPayloadLength()); // Call recording: Save incoming. // Data is in buffer lin, from 0 to len. if (call_recorder != null) call_recorder.writeIncoming(lin, 0, len); if (speakermode == AudioManager.MODE_NORMAL) calc(lin, 0, len); else if (gain > 1) calc2(lin, 0, len); } avgheadroom = avgheadroom * 0.99 + (double) headroom * 0.01; if (avgcnt++ > 300) devheadroom = devheadroom * 0.999 + Math.pow(Math.abs(headroom - avgheadroom), 2) * 0.001; if (headroom < 250 * mu) { late++; newjitter(true); System.out.println("RTP:underflow " + (int) Math.sqrt(devheadroom)); todo = jitter - headroom; write(lin2, 0, todo > BUFFER_SIZE ? BUFFER_SIZE : todo); } if (cnt > 500 * mu && cnt2 < 2) { todo = headroom - jitter; if (todo < len) write(lin, todo, len - todo); } else write(lin, 0, len); if (seq != 0) { getseq = gseq & 0xff; expseq = ++seq & 0xff; if (m == RtpStreamSender.m) vm = m; gap = (getseq - expseq) & 0xff; if (gap > 0) { System.out.println("RTP:lost"); if (gap > 100) gap = 1; loss += gap; lost += gap; good += gap - 1; loss2++; } else { if (m < vm) { loss++; loss2++; } } good++; if (good > 110) { good *= 0.99; lost *= 0.99; loss *= 0.99; loss2 *= 0.99; late *= 0.99; } } m = 1; seq = gseq; if (user >= luser + 8000 * mu && (Receiver.call_state == UserAgent.UA_STATE_INCALL || Receiver.call_state == UserAgent.UA_STATE_OUTGOING_CALL)) { if (luser == -8000 * mu || getMode() != speakermode) { saveVolume(); setMode(speakermode); restoreVolume(); } luser = user; if (user >= luser2 + 160000 * mu) newjitter(false); } lserver = server; } } lock(false); track.stop(); track.release(); tg.stopTone(); tg.release(); saveVolume(); am.setStreamVolume(AudioManager.STREAM_MUSIC, oldvol, 0); restoreSettings(); enableBluetooth(false); am.setStreamVolume(AudioManager.STREAM_MUSIC, oldvol, 0); oldvol = -1; p_type.codec.close(); rtp_socket.close(); rtp_socket = null; codec = ""; // Call recording: stop incoming receive. if (call_recorder != null) { call_recorder.stopIncoming(); call_recorder = null; } if (DEBUG) println("rtp receiver terminated"); cleanupBluetooth(); }
@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)); }