/** Reset the audio mode */ private synchronized void actualUnsetAudioInCall() { if (!prefs.getBoolean("isSavedAudioState", false) || !isSetAudioMode) { return; } Log.d(THIS_FILE, "Unset Audio In call"); int inCallStream = Compatibility.getInCallStream(userWantBluetooth); if (bluetoothWrapper != null) { // This fixes the BT activation but... but... seems to introduce a // lot of other issues // bluetoothWrapper.setBluetoothOn(true); Log.d(THIS_FILE, "Unset bt"); bluetoothWrapper.setBluetoothOn(false); } audioManager.setMicrophoneMute(false); if (doFocusAudio) { audioManager.setStreamSolo(inCallStream, false); audioFocusWrapper.unFocus(); } restoreAudioState(); if (wifiLock != null && wifiLock.isHeld()) { wifiLock.release(); } if (screenLock != null && screenLock.isHeld()) { Log.d(THIS_FILE, "Release screen lock"); screenLock.release(); } isSetAudioMode = false; }
/** Save current audio mode in order to be able to restore it once done */ @SuppressWarnings("deprecation") private synchronized void saveAudioState() { if (prefs.getBoolean("isSavedAudioState", false)) { // If we have already set, do not set it again !!! return; } ContentResolver ctntResolver = service.getContentResolver(); Editor ed = prefs.edit(); // ed.putInt("savedVibrateRing", // audioManager.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER)); // ed.putInt("savedVibradeNotif", // audioManager.getVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION)); // ed.putInt("savedRingerMode", audioManager.getRingerMode()); ed.putInt( "savedWifiPolicy", android.provider.Settings.System.getInt( ctntResolver, android.provider.Settings.System.WIFI_SLEEP_POLICY, Settings.System.WIFI_SLEEP_POLICY_DEFAULT)); int inCallStream = Compatibility.getInCallStream(userWantBluetooth); ed.putInt("savedVolume", audioManager.getStreamVolume(inCallStream)); int targetMode = getAudioTargetMode(); if (service.getPrefs().useRoutingApi()) { ed.putInt("savedRoute", audioManager.getRouting(targetMode)); } else { ed.putBoolean("savedSpeakerPhone", audioManager.isSpeakerphoneOn()); } ed.putInt("savedMode", audioManager.getMode()); ed.putBoolean("isSavedAudioState", true); ed.commit(); }
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == Compatibility.getHomeMenuId()) { finish(); return true; } return false; }
@TargetApi(5) public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0 && !Compatibility.isCompatible(5)) { onBackPressed(); } return super.onKeyDown(keyCode, event); }
public static ContactsWrapper getInstance() { if (instance == null) { String className = "com.csipsimple.utils.contacts.ContactsUtils"; if (Compatibility.isCompatible(14)) { className += "14"; } else if (Compatibility.isCompatible(5)) { className += "5"; } else { className += "3"; } try { Class<? extends ContactsWrapper> wrappedClass = Class.forName(className).asSubclass(ContactsWrapper.class); instance = wrappedClass.newInstance(); } catch (Exception e) { throw new IllegalStateException(e); } } return instance; }
public void adjustStreamVolume(int streamType, int direction, int flags) { broadcastVolumeWillBeUpdated(streamType, EXTRA_VALUE_UNKNOWN); audioManager.adjustStreamVolume(streamType, direction, flags); if (streamType == AudioManager.STREAM_RING) { // Update ringer ringer.updateRingerMode(); } int inCallStream = Compatibility.getInCallStream(userWantBluetooth); if (streamType == inCallStream) { int maxLevel = audioManager.getStreamMaxVolume(inCallStream); float modifiedLevel = (audioManager.getStreamVolume(inCallStream) / (float) maxLevel) * 10.0f; // Update default stream level service.getPrefs().setPreferenceFloatValue(SipConfigManager.SND_STREAM_LEVEL, modifiedLevel); } }
/** Restore the state of the audio */ @SuppressWarnings("deprecation") private final synchronized void restoreAudioState() { if (!prefs.getBoolean("isSavedAudioState", false)) { // If we have NEVER set, do not try to reset ! return; } ContentResolver ctntResolver = service.getContentResolver(); Settings.System.putInt( ctntResolver, Settings.System.WIFI_SLEEP_POLICY, prefs.getInt("savedWifiPolicy", Settings.System.WIFI_SLEEP_POLICY_DEFAULT)); // audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, // prefs.getInt("savedVibrateRing", // AudioManager.VIBRATE_SETTING_ONLY_SILENT)); // audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, // prefs.getInt("savedVibradeNotif", AudioManager.VIBRATE_SETTING_OFF)); // audioManager.setRingerMode(prefs.getInt("savedRingerMode", // AudioManager.RINGER_MODE_NORMAL)); int inCallStream = Compatibility.getInCallStream(userWantBluetooth); setStreamVolume( inCallStream, prefs.getInt("savedVolume", (int) (audioManager.getStreamMaxVolume(inCallStream) * 0.8)), 0); int targetMode = getAudioTargetMode(); if (service.getPrefs().useRoutingApi()) { audioManager.setRouting( targetMode, prefs.getInt("savedRoute", AudioManager.ROUTE_SPEAKER), AudioManager.ROUTE_ALL); } else { audioManager.setSpeakerphoneOn(prefs.getBoolean("savedSpeakerPhone", false)); } audioManager.setMode(prefs.getInt("savedMode", AudioManager.MODE_NORMAL)); Editor ed = prefs.edit(); ed.putBoolean("isSavedAudioState", false); ed.commit(); }
/** Set the audio mode as in call */ @SuppressWarnings("deprecation") private synchronized void actualSetAudioInCall() { // Ensure not already set if (isSetAudioMode) { return; } stopRing(); saveAudioState(); // Set the rest of the phone in a better state to not interferate with // current call // Do that only if we were not already in silent mode /* * Not needed anymore with on flight gsm call capture * if(audioManager.getRingerMode() != AudioManager.RINGER_MODE_SILENT) { * audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, * AudioManager.VIBRATE_SETTING_ON); * audioManager.setVibrateSetting(AudioManager * .VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_OFF); * audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE); } */ // LOCKS // Wifi management if necessary ContentResolver ctntResolver = service.getContentResolver(); Settings.System.putInt( ctntResolver, Settings.System.WIFI_SLEEP_POLICY, Settings.System.WIFI_SLEEP_POLICY_NEVER); // Acquire wifi lock WifiManager wman = (WifiManager) service.getSystemService(Context.WIFI_SERVICE); if (wifiLock == null) { wifiLock = wman.createWifiLock( (Compatibility.isCompatible(9)) ? WifiManager.WIFI_MODE_FULL_HIGH_PERF : WifiManager.WIFI_MODE_FULL, "com.csipsimple.InCallLock"); wifiLock.setReferenceCounted(false); } WifiInfo winfo = wman.getConnectionInfo(); if (winfo != null) { DetailedState dstate = WifiInfo.getDetailedStateOf(winfo.getSupplicantState()); // We assume that if obtaining ip addr, we are almost connected so // can keep wifi lock if (dstate == DetailedState.OBTAINING_IPADDR || dstate == DetailedState.CONNECTED) { if (!wifiLock.isHeld()) { wifiLock.acquire(); } } // This wake lock purpose is to prevent PSP wifi mode if (service.getPrefs().getPreferenceBooleanValue(SipConfigManager.KEEP_AWAKE_IN_CALL)) { if (screenLock == null) { PowerManager pm = (PowerManager) service.getSystemService(Context.POWER_SERVICE); screenLock = pm.newWakeLock( PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "com.csipsimple.onIncomingCall.SCREEN"); screenLock.setReferenceCounted(false); } // Ensure single lock if (!screenLock.isHeld()) { screenLock.acquire(); } } } if (!useWebRTCImpl) { // Audio routing int targetMode = getAudioTargetMode(); Log.d(THIS_FILE, "Set mode audio in call to " + targetMode); if (service.getPrefs().generateForSetCall()) { boolean needOutOfSilent = (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT); if (needOutOfSilent) { audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); } ToneGenerator toneGenerator = new ToneGenerator(AudioManager.STREAM_VOICE_CALL, 1); toneGenerator.startTone(41 /* ToneGenerator.TONE_CDMA_CONFIRM */); toneGenerator.stopTone(); toneGenerator.release(); // Restore silent mode if (needOutOfSilent) { audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT); } } // Set mode if (targetMode != AudioManager.MODE_IN_CALL && useSgsWrkAround) { // For galaxy S we need to set in call mode before to reset // stack audioManager.setMode(AudioManager.MODE_IN_CALL); } audioManager.setMode(targetMode); // Routing if (service.getPrefs().useRoutingApi()) { audioManager.setRouting( targetMode, userWantSpeaker ? AudioManager.ROUTE_SPEAKER : AudioManager.ROUTE_EARPIECE, AudioManager.ROUTE_ALL); } else { audioManager.setSpeakerphoneOn(userWantSpeaker ? true : false); } audioManager.setMicrophoneMute(false); if (bluetoothWrapper != null && userWantBluetooth && bluetoothWrapper.canBluetooth()) { Log.d(THIS_FILE, "Try to enable bluetooth"); bluetoothWrapper.setBluetoothOn(true); } } else { // WebRTC implementation for routing int apiLevel = Compatibility.getApiLevel(); // SetAudioMode // ***IMPORTANT*** When the API level for honeycomb (H) has been // decided, // the condition should be changed to include API level 8 to H-1. if (android.os.Build.BRAND.equalsIgnoreCase("Samsung") && (8 == apiLevel)) { // Set Samsung specific VoIP mode for 2.2 devices int mode = 4; audioManager.setMode(mode); if (audioManager.getMode() != mode) { Log.e(THIS_FILE, "Could not set audio mode for Samsung device"); } } // SetPlayoutSpeaker if ((3 == apiLevel) || (4 == apiLevel)) { // 1.5 and 1.6 devices if (userWantSpeaker) { // route audio to back speaker audioManager.setMode(AudioManager.MODE_NORMAL); } else { // route audio to earpiece audioManager.setMode(AudioManager.MODE_IN_CALL); } } else { // 2.x devices if ((android.os.Build.BRAND.equalsIgnoreCase("samsung")) && ((5 == apiLevel) || (6 == apiLevel) || (7 == apiLevel))) { // Samsung 2.0, 2.0.1 and 2.1 devices if (userWantSpeaker) { // route audio to back speaker audioManager.setMode(AudioManager.MODE_IN_CALL); audioManager.setSpeakerphoneOn(userWantSpeaker); } else { // route audio to earpiece audioManager.setSpeakerphoneOn(userWantSpeaker); audioManager.setMode(AudioManager.MODE_NORMAL); } } else { // Non-Samsung and Samsung 2.2 and up devices audioManager.setSpeakerphoneOn(userWantSpeaker); } } } // Set stream solo/volume/focus int inCallStream = Compatibility.getInCallStream(userWantBluetooth); if (doFocusAudio) { if (!accessibilityManager.isEnabled()) { audioManager.setStreamSolo(inCallStream, true); } audioFocusWrapper.focus(userWantBluetooth); } Log.d(THIS_FILE, "Initial volume level : " + service.getPrefs().getInitialVolumeLevel()); setStreamVolume( inCallStream, (int) (audioManager.getStreamMaxVolume(inCallStream) * service.getPrefs().getInitialVolumeLevel()), 0); isSetAudioMode = true; // System.gc(); }