Simon's fixes for LinphoneManager + fix for bluetooth
This commit is contained in:
parent
29acd2cafd
commit
05fbb9ef03
2 changed files with 69 additions and 49 deletions
|
@ -228,7 +228,7 @@ public class InCallActivity extends FragmentActivity implements
|
||||||
routeBluetooth = (TextView) findViewById(R.id.routeBluetooth);
|
routeBluetooth = (TextView) findViewById(R.id.routeBluetooth);
|
||||||
routeBluetooth.setOnClickListener(this);
|
routeBluetooth.setOnClickListener(this);
|
||||||
} catch (NullPointerException npe) {
|
} catch (NullPointerException npe) {
|
||||||
Log.e("Audio routes menu disabled on tablets for now");
|
Log.e("Bluetooth: Audio routes menu disabled on tablets for now (1)");
|
||||||
}
|
}
|
||||||
|
|
||||||
switchCamera = (ImageView) findViewById(R.id.switchCamera);
|
switchCamera = (ImageView) findViewById(R.id.switchCamera);
|
||||||
|
@ -251,16 +251,18 @@ public class InCallActivity extends FragmentActivity implements
|
||||||
|
|
||||||
if (LinphoneManager.getInstance().isBluetoothScoConnected) {
|
if (LinphoneManager.getInstance().isBluetoothScoConnected) {
|
||||||
try {
|
try {
|
||||||
routeLayout.setVisibility(View.VISIBLE);
|
if (routeLayout != null)
|
||||||
|
routeLayout.setVisibility(View.VISIBLE);
|
||||||
audioRoute.setVisibility(View.VISIBLE);
|
audioRoute.setVisibility(View.VISIBLE);
|
||||||
speaker.setVisibility(View.GONE);
|
speaker.setVisibility(View.GONE);
|
||||||
} catch (NullPointerException npe) {}
|
} catch (NullPointerException npe) { Log.e("Bluetooth: Audio routes menu disabled on tablets for now (2)"); }
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
routeLayout.setVisibility(View.GONE);
|
if (routeLayout != null)
|
||||||
|
routeLayout.setVisibility(View.GONE);
|
||||||
audioRoute.setVisibility(View.GONE);
|
audioRoute.setVisibility(View.GONE);
|
||||||
speaker.setVisibility(View.VISIBLE);
|
speaker.setVisibility(View.VISIBLE);
|
||||||
} catch (NullPointerException npe) {}
|
} catch (NullPointerException npe) { Log.e("Bluetooth: Audio routes menu disabled on tablets for now (3)"); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,7 +301,7 @@ public class InCallActivity extends FragmentActivity implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (NullPointerException npe) {
|
} catch (NullPointerException npe) {
|
||||||
Log.e("Audio routes menu disabled on tablets for now");
|
Log.e("Bluetooth: Audio routes menu disabled on tablets for now (4)");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isMicMuted) {
|
if (isMicMuted) {
|
||||||
|
|
|
@ -148,6 +148,7 @@ public class LinphoneManager implements LinphoneCoreListener {
|
||||||
private String basePath;
|
private String basePath;
|
||||||
private static boolean sExited;
|
private static boolean sExited;
|
||||||
private String contactParams;
|
private String contactParams;
|
||||||
|
private boolean mAudioFocused;
|
||||||
|
|
||||||
private WakeLock mIncallWakeLock;
|
private WakeLock mIncallWakeLock;
|
||||||
|
|
||||||
|
@ -157,6 +158,7 @@ public class LinphoneManager implements LinphoneCoreListener {
|
||||||
private BroadcastReceiver bluetoothReiceiver = new BluetoothManager();
|
private BroadcastReceiver bluetoothReiceiver = new BluetoothManager();
|
||||||
public boolean isBluetoothScoConnected;
|
public boolean isBluetoothScoConnected;
|
||||||
public boolean isUsingBluetoothAudioRoute;
|
public boolean isUsingBluetoothAudioRoute;
|
||||||
|
private boolean mBluetoothStarted;
|
||||||
|
|
||||||
public ChatStorage chatStorage;
|
public ChatStorage chatStorage;
|
||||||
|
|
||||||
|
@ -211,10 +213,11 @@ public class LinphoneManager implements LinphoneCoreListener {
|
||||||
|
|
||||||
private void routeAudioToSpeakerHelper(boolean speakerOn) {
|
private void routeAudioToSpeakerHelper(boolean speakerOn) {
|
||||||
isUsingBluetoothAudioRoute = false;
|
isUsingBluetoothAudioRoute = false;
|
||||||
if (mAudioManager != null) {
|
if (mAudioManager != null && mBluetoothStarted) {
|
||||||
Compatibility.setAudioManagerInCallMode(mAudioManager);
|
//Compatibility.setAudioManagerInCallMode(mAudioManager);
|
||||||
mAudioManager.stopBluetoothSco();
|
mAudioManager.stopBluetoothSco();
|
||||||
mAudioManager.setBluetoothScoOn(false);
|
mAudioManager.setBluetoothScoOn(false);
|
||||||
|
mBluetoothStarted=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!speakerOn) {
|
if (!speakerOn) {
|
||||||
|
@ -259,6 +262,7 @@ public class LinphoneManager implements LinphoneCoreListener {
|
||||||
public void onServiceConnected(int profile, BluetoothProfile proxy) {
|
public void onServiceConnected(int profile, BluetoothProfile proxy) {
|
||||||
if (profile == BluetoothProfile.HEADSET) {
|
if (profile == BluetoothProfile.HEADSET) {
|
||||||
mBluetoothHeadset = (BluetoothHeadset) proxy;
|
mBluetoothHeadset = (BluetoothHeadset) proxy;
|
||||||
|
isBluetoothScoConnected = true;
|
||||||
Log.d("Bluetooth headset connected");
|
Log.d("Bluetooth headset connected");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -266,8 +270,8 @@ public class LinphoneManager implements LinphoneCoreListener {
|
||||||
public void onServiceDisconnected(int profile) {
|
public void onServiceDisconnected(int profile) {
|
||||||
if (profile == BluetoothProfile.HEADSET) {
|
if (profile == BluetoothProfile.HEADSET) {
|
||||||
mBluetoothHeadset = null;
|
mBluetoothHeadset = null;
|
||||||
Log.d("Bluetooth headset disconnected");
|
|
||||||
isBluetoothScoConnected = false;
|
isBluetoothScoConnected = false;
|
||||||
|
Log.d("Bluetooth headset disconnected");
|
||||||
routeAudioToReceiver();
|
routeAudioToReceiver();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -293,10 +297,11 @@ public class LinphoneManager implements LinphoneCoreListener {
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||||
public boolean routeAudioToBluetooth() {
|
public boolean routeAudioToBluetooth() {
|
||||||
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||||
if (mBluetoothAdapter.isEnabled() && mAudioManager.isBluetoothScoAvailableOffCall()) {
|
if (bluetoothAdapter.isEnabled() && mAudioManager.isBluetoothScoAvailableOffCall()) {
|
||||||
mAudioManager.setBluetoothScoOn(true);
|
mAudioManager.setBluetoothScoOn(true);
|
||||||
mAudioManager.startBluetoothSco();
|
mAudioManager.startBluetoothSco();
|
||||||
|
mBluetoothStarted=true;
|
||||||
|
|
||||||
if (Version.sdkAboveOrEqual(Version.API11_HONEYCOMB_30)) {
|
if (Version.sdkAboveOrEqual(Version.API11_HONEYCOMB_30)) {
|
||||||
isUsingBluetoothAudioRoute = false;
|
isUsingBluetoothAudioRoute = false;
|
||||||
|
@ -311,7 +316,8 @@ public class LinphoneManager implements LinphoneCoreListener {
|
||||||
Log.d("No bluetooth device available");
|
Log.d("No bluetooth device available");
|
||||||
scoDisconnected();
|
scoDisconnected();
|
||||||
} else {
|
} else {
|
||||||
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
|
//Why is this for:
|
||||||
|
//mAudioManager.setMode(AudioManager.MODE_IN_CALL);
|
||||||
for (LinphoneOnAudioChangedListener listener : getSimpleListeners(LinphoneOnAudioChangedListener.class)) {
|
for (LinphoneOnAudioChangedListener listener : getSimpleListeners(LinphoneOnAudioChangedListener.class)) {
|
||||||
listener.onAudioStateChanged(AudioState.SPEAKER);
|
listener.onAudioStateChanged(AudioState.SPEAKER);
|
||||||
}
|
}
|
||||||
|
@ -324,16 +330,17 @@ public class LinphoneManager implements LinphoneCoreListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void scoConnected() {
|
public void scoConnected() {
|
||||||
Log.e("Bluetooth sco connected!");
|
Log.i("Bluetooth sco connected!");
|
||||||
isBluetoothScoConnected = true;
|
isBluetoothScoConnected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void scoDisconnected() {
|
public void scoDisconnected() {
|
||||||
Log.e("Bluetooth sco disconnected!");
|
Log.w("Bluetooth sco disconnected!");
|
||||||
isUsingBluetoothAudioRoute = false;
|
isUsingBluetoothAudioRoute = false;
|
||||||
isBluetoothScoConnected = false;
|
isBluetoothScoConnected = false;
|
||||||
if (mAudioManager != null) {
|
if (mAudioManager != null) {
|
||||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
//why is this for ?
|
||||||
|
//mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
||||||
mAudioManager.stopBluetoothSco();
|
mAudioManager.stopBluetoothSco();
|
||||||
mAudioManager.setBluetoothScoOn(false);
|
mAudioManager.setBluetoothScoOn(false);
|
||||||
}
|
}
|
||||||
|
@ -484,12 +491,6 @@ public class LinphoneManager implements LinphoneCoreListener {
|
||||||
getLc().playDtmf(dtmf, -1);
|
getLc().playDtmf(dtmf, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void changeResolution() {
|
|
||||||
BandwidthManager manager = BandwidthManager.getInstance();
|
|
||||||
manager.setUserRestriction(!manager.isUserRestriction());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void terminateCall() {
|
public void terminateCall() {
|
||||||
if (mLc.isIncall()) {
|
if (mLc.isIncall()) {
|
||||||
mLc.terminateCall(mLc.getCurrentCall());
|
mLc.terminateCall(mLc.getCurrentCall());
|
||||||
|
@ -586,7 +587,8 @@ public class LinphoneManager implements LinphoneCoreListener {
|
||||||
mLc.iterate();
|
mLc.iterate();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
mTimer.scheduleAtFixedRate(lTask, 0, 20);
|
/*use schedule instead of scheduleAtFixedRate to avoid iterate from being call in burst after cpu wake up*/
|
||||||
|
mTimer.schedule(lTask, 0, 20);
|
||||||
|
|
||||||
IntentFilter lFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
|
IntentFilter lFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
|
||||||
lFilter.addAction(Intent.ACTION_SCREEN_OFF);
|
lFilter.addAction(Intent.ACTION_SCREEN_OFF);
|
||||||
|
@ -863,6 +865,8 @@ public class LinphoneManager implements LinphoneCoreListener {
|
||||||
//stun server
|
//stun server
|
||||||
String lStun = getPrefString(R.string.pref_stun_server_key, getString(R.string.default_stun));
|
String lStun = getPrefString(R.string.pref_stun_server_key, getString(R.string.default_stun));
|
||||||
boolean useICE = getPrefBoolean(R.string.pref_ice_enable_key, mR.getBoolean(R.bool.pref_ice_enabled_default));
|
boolean useICE = getPrefBoolean(R.string.pref_ice_enable_key, mR.getBoolean(R.bool.pref_ice_enabled_default));
|
||||||
|
//boolean useUpnp = getPrefBoolean(R.string.pref_upnp_enable_key, mR.getBoolean(R.bool.pref_upnp_enabled_default));
|
||||||
|
|
||||||
mLc.setStunServer(lStun);
|
mLc.setStunServer(lStun);
|
||||||
if (lStun!=null && lStun.length()>0) {
|
if (lStun!=null && lStun.length()>0) {
|
||||||
mLc.setFirewallPolicy(useICE ? FirewallPolicy.UseIce : FirewallPolicy.UseStun);
|
mLc.setFirewallPolicy(useICE ? FirewallPolicy.UseIce : FirewallPolicy.UseStun);
|
||||||
|
@ -1215,13 +1219,6 @@ public class LinphoneManager implements LinphoneCoreListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state == LinphoneCall.State.Connected) {
|
|
||||||
if (mLc.getCallsNb() == 1) {
|
|
||||||
int res=mAudioManager.requestAudioFocus(null, AudioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN);
|
|
||||||
Log.d("Audio focus requested: " + (res == AudioManager.AUDIOFOCUS_REQUEST_GRANTED ? "Granted" : "Denied"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state == IncomingReceived || (state == State.CallIncomingEarlyMedia && mR.getBoolean(R.bool.allow_ringing_while_early_media))) {
|
if (state == IncomingReceived || (state == State.CallIncomingEarlyMedia && mR.getBoolean(R.bool.allow_ringing_while_early_media))) {
|
||||||
// Brighten screen for at least 10 seconds
|
// Brighten screen for at least 10 seconds
|
||||||
if (mLc.getCallsNb() == 1) {
|
if (mLc.getCallsNb() == 1) {
|
||||||
|
@ -1234,26 +1231,36 @@ public class LinphoneManager implements LinphoneCoreListener {
|
||||||
stopRinging();
|
stopRinging();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state == CallEnd || state == Error || state == CallReleased) {
|
if (state == LinphoneCall.State.Connected) {
|
||||||
if (mLc.getCallsNb() == 0) {
|
if (mLc.getCallsNb() == 1) {
|
||||||
int res=mAudioManager.abandonAudioFocus(null);
|
requestAudioFocus();
|
||||||
Log.d("Audio focus released: " + (res == AudioManager.AUDIOFOCUS_REQUEST_GRANTED ? "Granted" : "Denied"));
|
Compatibility.setAudioManagerInCallMode(mAudioManager);
|
||||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
|
||||||
}
|
}
|
||||||
Context activity = getContext();
|
|
||||||
if (activity != null) {
|
|
||||||
TelephonyManager tm = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);
|
|
||||||
if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) {
|
|
||||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (state == State.Connected) {
|
|
||||||
if (Hacks.needSoftvolume() || sLPref.useSoftvolume()) {
|
if (Hacks.needSoftvolume() || sLPref.useSoftvolume()) {
|
||||||
adjustVolume(0); // Synchronize
|
adjustVolume(0); // Synchronize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (state == CallEnd || state == Error) {
|
||||||
|
if (mLc.getCallsNb() == 0) {
|
||||||
|
if (mAudioFocused){
|
||||||
|
int res=mAudioManager.abandonAudioFocus(null);
|
||||||
|
Log.d("Audio focus released a bit later: " + (res == AudioManager.AUDIOFOCUS_REQUEST_GRANTED ? "Granted" : "Denied"));
|
||||||
|
mAudioFocused=false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Context activity = getContext();
|
||||||
|
if (activity != null) {
|
||||||
|
TelephonyManager tm = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);
|
||||||
|
if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) {
|
||||||
|
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
||||||
|
Log.d("---AudioManager: back to MODE_NORMAL");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (state == CallEnd) {
|
if (state == CallEnd) {
|
||||||
if (mLc.getCallsNb() == 0) {
|
if (mLc.getCallsNb() == 0) {
|
||||||
if (mIncallWakeLock != null && mIncallWakeLock.isHeld()) {
|
if (mIncallWakeLock != null && mIncallWakeLock.isHeld()) {
|
||||||
|
@ -1274,7 +1281,6 @@ public class LinphoneManager implements LinphoneCoreListener {
|
||||||
} else {
|
} else {
|
||||||
Log.i("New call active while incall (CPU only) wake lock already active");
|
Log.i("New call active while incall (CPU only) wake lock already active");
|
||||||
}
|
}
|
||||||
Compatibility.setAudioManagerInCallMode(mAudioManager);
|
|
||||||
}
|
}
|
||||||
mListenerDispatcher.onCallStateChanged(call, state, message);
|
mListenerDispatcher.onCallStateChanged(call, state, message);
|
||||||
}
|
}
|
||||||
|
@ -1319,6 +1325,14 @@ public class LinphoneManager implements LinphoneCoreListener {
|
||||||
disableRinging = true;
|
disableRinging = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void requestAudioFocus(){
|
||||||
|
if (!mAudioFocused){
|
||||||
|
int res=mAudioManager.requestAudioFocus(null, AudioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT );
|
||||||
|
Log.d("Audio focus requested: " + (res == AudioManager.AUDIOFOCUS_REQUEST_GRANTED ? "Granted" : "Denied"));
|
||||||
|
if (res==AudioManager.AUDIOFOCUS_REQUEST_GRANTED) mAudioFocused=true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private synchronized void startRinging() {
|
private synchronized void startRinging() {
|
||||||
if (disableRinging ) {
|
if (disableRinging ) {
|
||||||
return;
|
return;
|
||||||
|
@ -1334,6 +1348,7 @@ public class LinphoneManager implements LinphoneCoreListener {
|
||||||
mVibrator.vibrate(patern, 1);
|
mVibrator.vibrate(patern, 1);
|
||||||
}
|
}
|
||||||
if (mRingerPlayer == null) {
|
if (mRingerPlayer == null) {
|
||||||
|
requestAudioFocus();
|
||||||
mRingerPlayer = new MediaPlayer();
|
mRingerPlayer = new MediaPlayer();
|
||||||
mRingerPlayer.setAudioStreamType(STREAM_RING);
|
mRingerPlayer.setAudioStreamType(STREAM_RING);
|
||||||
mListenerDispatcher.onRingerPlayerCreated(mRingerPlayer);
|
mListenerDispatcher.onRingerPlayerCreated(mRingerPlayer);
|
||||||
|
@ -1359,6 +1374,9 @@ public class LinphoneManager implements LinphoneCoreListener {
|
||||||
mVibrator.cancel();
|
mVibrator.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Hacks.needGalaxySAudioHack())
|
||||||
|
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
||||||
|
|
||||||
isRinging = false;
|
isRinging = false;
|
||||||
// You may need to call galaxys audio hack after this method
|
// You may need to call galaxys audio hack after this method
|
||||||
routeAudioToReceiver();
|
routeAudioToReceiver();
|
||||||
|
@ -1620,7 +1638,7 @@ public class LinphoneManager implements LinphoneCoreListener {
|
||||||
|
|
||||||
Context activity = getContext();
|
Context activity = getContext();
|
||||||
if (activity != null) {
|
if (activity != null) {
|
||||||
TelephonyManager tm = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);
|
TelephonyManager tm = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);
|
||||||
if (state == State.CallEnd && mLc.getCallsNb() == 0 && tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) {
|
if (state == State.CallEnd && mLc.getCallsNb() == 0 && tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) {
|
||||||
routeAudioToReceiver();
|
routeAudioToReceiver();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue