Fix problem with mediastreamer log
This commit is contained in:
parent
f018fd46b8
commit
946cb24eb3
1 changed files with 29 additions and 31 deletions
|
@ -20,8 +20,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.linphone.mediastream.Log;
|
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.bluetooth.BluetoothAssignedNumbers;
|
import android.bluetooth.BluetoothAssignedNumbers;
|
||||||
|
@ -65,14 +63,14 @@ public class BluetoothManager extends BroadcastReceiver {
|
||||||
public BluetoothManager() {
|
public BluetoothManager() {
|
||||||
isBluetoothConnected = false;
|
isBluetoothConnected = false;
|
||||||
if (!ensureInit()) {
|
if (!ensureInit()) {
|
||||||
Log.w("[Bluetooth] Manager tried to init but LinphoneService not ready yet...");
|
android.util.Log.w("BluetoothManager", "[Bluetooth] Manager tried to init but LinphoneService not ready yet...");
|
||||||
}
|
}
|
||||||
instance = this;
|
instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initBluetooth() {
|
public void initBluetooth() {
|
||||||
if (!ensureInit()) {
|
if (!ensureInit()) {
|
||||||
Log.w("[Bluetooth] Manager tried to init bluetooth but LinphoneService not ready yet...");
|
android.util.Log.w("BluetoothManager", "[Bluetooth] Manager tried to init bluetooth but LinphoneService not ready yet...");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,14 +80,14 @@ public class BluetoothManager extends BroadcastReceiver {
|
||||||
filter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED);
|
filter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED);
|
||||||
filter.addAction(BluetoothHeadset.ACTION_VENDOR_SPECIFIC_HEADSET_EVENT);
|
filter.addAction(BluetoothHeadset.ACTION_VENDOR_SPECIFIC_HEADSET_EVENT);
|
||||||
mContext.registerReceiver(this, filter);
|
mContext.registerReceiver(this, filter);
|
||||||
Log.d("[Bluetooth] Receiver started");
|
android.util.Log.d("BluetoothManager", "[Bluetooth] Receiver started");
|
||||||
|
|
||||||
startBluetooth();
|
startBluetooth();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startBluetooth() {
|
private void startBluetooth() {
|
||||||
if (isBluetoothConnected) {
|
if (isBluetoothConnected) {
|
||||||
Log.e("[Bluetooth] Already started, skipping...");
|
android.util.Log.e("BluetoothManager", "[Bluetooth] Already started, skipping...");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,14 +95,14 @@ public class BluetoothManager extends BroadcastReceiver {
|
||||||
|
|
||||||
if (mBluetoothAdapter != null && mBluetoothAdapter.isEnabled()) {
|
if (mBluetoothAdapter != null && mBluetoothAdapter.isEnabled()) {
|
||||||
if (mProfileListener != null) {
|
if (mProfileListener != null) {
|
||||||
Log.w("[Bluetooth] Headset profile was already opened, let's close it");
|
android.util.Log.w("BluetoothManager", "[Bluetooth] Headset profile was already opened, let's close it");
|
||||||
mBluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, mBluetoothHeadset);
|
mBluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, mBluetoothHeadset);
|
||||||
}
|
}
|
||||||
|
|
||||||
mProfileListener = new BluetoothProfile.ServiceListener() {
|
mProfileListener = new BluetoothProfile.ServiceListener() {
|
||||||
public void onServiceConnected(int profile, BluetoothProfile proxy) {
|
public void onServiceConnected(int profile, BluetoothProfile proxy) {
|
||||||
if (profile == BluetoothProfile.HEADSET) {
|
if (profile == BluetoothProfile.HEADSET) {
|
||||||
Log.d("[Bluetooth] Headset connected");
|
android.util.Log.d("BluetoothManager", "[Bluetooth] Headset connected");
|
||||||
mBluetoothHeadset = (BluetoothHeadset) proxy;
|
mBluetoothHeadset = (BluetoothHeadset) proxy;
|
||||||
isBluetoothConnected = true;
|
isBluetoothConnected = true;
|
||||||
}
|
}
|
||||||
|
@ -113,17 +111,17 @@ public class BluetoothManager extends BroadcastReceiver {
|
||||||
if (profile == BluetoothProfile.HEADSET) {
|
if (profile == BluetoothProfile.HEADSET) {
|
||||||
mBluetoothHeadset = null;
|
mBluetoothHeadset = null;
|
||||||
isBluetoothConnected = false;
|
isBluetoothConnected = false;
|
||||||
Log.d("[Bluetooth] Headset disconnected");
|
android.util.Log.d("BluetoothManager", "[Bluetooth] Headset disconnected");
|
||||||
LinphoneManager.getInstance().routeAudioToReceiver();
|
LinphoneManager.getInstance().routeAudioToReceiver();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
boolean success = mBluetoothAdapter.getProfileProxy(mContext, mProfileListener, BluetoothProfile.HEADSET);
|
boolean success = mBluetoothAdapter.getProfileProxy(mContext, mProfileListener, BluetoothProfile.HEADSET);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
Log.e("[Bluetooth] getProfileProxy failed !");
|
android.util.Log.e("BluetoothManager", "[Bluetooth] getProfileProxy failed !");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.w("[Bluetooth] Interface disabled on device");
|
android.util.Log.w("BluetoothManager", "[Bluetooth] Interface disabled on device");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,7 +154,7 @@ public class BluetoothManager extends BroadcastReceiver {
|
||||||
if (mBluetoothAdapter != null && mBluetoothAdapter.isEnabled() && mAudioManager != null && mAudioManager.isBluetoothScoAvailableOffCall()) {
|
if (mBluetoothAdapter != null && mBluetoothAdapter.isEnabled() && mAudioManager != null && mAudioManager.isBluetoothScoAvailableOffCall()) {
|
||||||
if (isBluetoothHeadsetAvailable()) {
|
if (isBluetoothHeadsetAvailable()) {
|
||||||
if (mAudioManager != null && !mAudioManager.isBluetoothScoOn()) {
|
if (mAudioManager != null && !mAudioManager.isBluetoothScoOn()) {
|
||||||
Log.d("[Bluetooth] SCO off, let's start it");
|
android.util.Log.d("BluetoothManager", "[Bluetooth] SCO off, let's start it");
|
||||||
mAudioManager.setBluetoothScoOn(true);
|
mAudioManager.setBluetoothScoOn(true);
|
||||||
mAudioManager.startBluetoothSco();
|
mAudioManager.startBluetoothSco();
|
||||||
}
|
}
|
||||||
|
@ -183,12 +181,12 @@ public class BluetoothManager extends BroadcastReceiver {
|
||||||
}
|
}
|
||||||
if (ok) {
|
if (ok) {
|
||||||
if (retries > 0) {
|
if (retries > 0) {
|
||||||
Log.d("[Bluetooth] Audio route ok after " + retries + " retries");
|
android.util.Log.d("BluetoothManager", "[Bluetooth] Audio route ok after " + retries + " retries");
|
||||||
} else {
|
} else {
|
||||||
Log.d("[Bluetooth] Audio route ok");
|
android.util.Log.d("BluetoothManager", "[Bluetooth] Audio route ok");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.d("[Bluetooth] Audio route still not ok...");
|
android.util.Log.d("BluetoothManager", "[Bluetooth] Audio route still not ok...");
|
||||||
}
|
}
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
|
@ -215,7 +213,7 @@ public class BluetoothManager extends BroadcastReceiver {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.d(isHeadsetConnected ? "[Bluetooth] Headset found, bluetooth audio route available" : "[Bluetooth] No headset found, bluetooth audio route unavailable");
|
android.util.Log.d("BluetoothManager", isHeadsetConnected ? "[Bluetooth] Headset found, bluetooth audio route available" : "[Bluetooth] No headset found, bluetooth audio route unavailable");
|
||||||
}
|
}
|
||||||
return isHeadsetConnected;
|
return isHeadsetConnected;
|
||||||
}
|
}
|
||||||
|
@ -240,12 +238,12 @@ public class BluetoothManager extends BroadcastReceiver {
|
||||||
mAudioManager.stopBluetoothSco();
|
mAudioManager.stopBluetoothSco();
|
||||||
mAudioManager.setBluetoothScoOn(false);
|
mAudioManager.setBluetoothScoOn(false);
|
||||||
}
|
}
|
||||||
Log.w("[Bluetooth] SCO disconnected!");
|
android.util.Log.w("BluetoothManager", "[Bluetooth] SCO disconnected!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopBluetooth() {
|
public void stopBluetooth() {
|
||||||
Log.w("[Bluetooth] Stopping...");
|
android.util.Log.w("BluetoothManager", "[Bluetooth] Stopping...");
|
||||||
isBluetoothConnected = false;
|
isBluetoothConnected = false;
|
||||||
|
|
||||||
disableBluetoothSCO();
|
disableBluetoothSCO();
|
||||||
|
@ -256,7 +254,7 @@ public class BluetoothManager extends BroadcastReceiver {
|
||||||
}
|
}
|
||||||
mBluetoothDevice = null;
|
mBluetoothDevice = null;
|
||||||
|
|
||||||
Log.w("[Bluetooth] Stopped!");
|
android.util.Log.w("BluetoothManager", "[Bluetooth] Stopped!");
|
||||||
|
|
||||||
if (LinphoneManager.isInstanciated()) {
|
if (LinphoneManager.isInstanciated()) {
|
||||||
LinphoneManager.getInstance().routeAudioToReceiver();
|
LinphoneManager.getInstance().routeAudioToReceiver();
|
||||||
|
@ -271,10 +269,10 @@ public class BluetoothManager extends BroadcastReceiver {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mContext.unregisterReceiver(this);
|
mContext.unregisterReceiver(this);
|
||||||
Log.d("[Bluetooth] Receiver stopped");
|
android.util.Log.d("BluetoothManager", "[Bluetooth] Receiver stopped");
|
||||||
} catch (Exception e) {}
|
} catch (Exception e) {}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(e);
|
android.util.Log.e("BluetoothManager", e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,32 +284,32 @@ public class BluetoothManager extends BroadcastReceiver {
|
||||||
if (AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED.equals(action)) {
|
if (AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED.equals(action)) {
|
||||||
int state = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, 0);
|
int state = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, 0);
|
||||||
if (state == AudioManager.SCO_AUDIO_STATE_CONNECTED) {
|
if (state == AudioManager.SCO_AUDIO_STATE_CONNECTED) {
|
||||||
Log.d("[Bluetooth] SCO state: connected");
|
android.util.Log.d("BluetoothManager", "[Bluetooth] SCO state: connected");
|
||||||
// LinphoneManager.getInstance().audioStateChanged(AudioState.BLUETOOTH);
|
// LinphoneManager.getInstance().audioStateChanged(AudioState.BLUETOOTH);
|
||||||
isScoConnected = true;
|
isScoConnected = true;
|
||||||
} else if (state == AudioManager.SCO_AUDIO_STATE_DISCONNECTED) {
|
} else if (state == AudioManager.SCO_AUDIO_STATE_DISCONNECTED) {
|
||||||
Log.d("[Bluetooth] SCO state: disconnected");
|
android.util.Log.d("BluetoothManager", "[Bluetooth] SCO state: disconnected");
|
||||||
// LinphoneManager.getInstance().audioStateChanged(AudioState.SPEAKER);
|
// LinphoneManager.getInstance().audioStateChanged(AudioState.SPEAKER);
|
||||||
isScoConnected = false;
|
isScoConnected = false;
|
||||||
} else if (state == AudioManager.SCO_AUDIO_STATE_CONNECTING) {
|
} else if (state == AudioManager.SCO_AUDIO_STATE_CONNECTING) {
|
||||||
Log.d("[Bluetooth] SCO state: connecting");
|
android.util.Log.d("BluetoothManager", "[Bluetooth] SCO state: connecting");
|
||||||
// LinphoneManager.getInstance().audioStateChanged(AudioState.BLUETOOTH);
|
// LinphoneManager.getInstance().audioStateChanged(AudioState.BLUETOOTH);
|
||||||
isScoConnected = true;
|
isScoConnected = true;
|
||||||
} else {
|
} else {
|
||||||
Log.d("[Bluetooth] SCO state: " + state);
|
android.util.Log.d("BluetoothManager", "[Bluetooth] SCO state: " + state);
|
||||||
}
|
}
|
||||||
refreshCallView();
|
refreshCallView();
|
||||||
}
|
}
|
||||||
else if (BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED.equals(action)) {
|
else if (BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED.equals(action)) {
|
||||||
int state = intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE, BluetoothAdapter.STATE_DISCONNECTED);
|
int state = intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE, BluetoothAdapter.STATE_DISCONNECTED);
|
||||||
if (state == 0) {
|
if (state == 0) {
|
||||||
Log.d("[Bluetooth] State: disconnected");
|
android.util.Log.d("BluetoothManager", "[Bluetooth] State: disconnected");
|
||||||
stopBluetooth();
|
stopBluetooth();
|
||||||
} else if (state == 2) {
|
} else if (state == 2) {
|
||||||
Log.d("[Bluetooth] State: connected");
|
android.util.Log.d("BluetoothManager", "[Bluetooth] State: connected");
|
||||||
startBluetooth();
|
startBluetooth();
|
||||||
} else {
|
} else {
|
||||||
Log.d("[Bluetooth] State: " + state);
|
android.util.Log.d("BluetoothManager", "[Bluetooth] State: " + state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (intent.getAction().equals(BluetoothHeadset.ACTION_VENDOR_SPECIFIC_HEADSET_EVENT)) {
|
else if (intent.getAction().equals(BluetoothHeadset.ACTION_VENDOR_SPECIFIC_HEADSET_EVENT)) {
|
||||||
|
@ -320,16 +318,16 @@ public class BluetoothManager extends BroadcastReceiver {
|
||||||
|
|
||||||
Object[] args = (Object[]) intent.getExtras().get(BluetoothHeadset.EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_ARGS);
|
Object[] args = (Object[]) intent.getExtras().get(BluetoothHeadset.EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_ARGS);
|
||||||
if (args.length <= 0) {
|
if (args.length <= 0) {
|
||||||
Log.d("[Bluetooth] Event: " + command + ", no args");
|
android.util.Log.d("BluetoothManager", "[Bluetooth] Event: " + command + ", no args");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String eventName = (args[0]).toString();
|
String eventName = (args[0]).toString();
|
||||||
if (eventName.equals("BUTTON") && args.length >= 3) {
|
if (eventName.equals("BUTTON") && args.length >= 3) {
|
||||||
String buttonID = args[1].toString();
|
String buttonID = args[1].toString();
|
||||||
String mode = args[2].toString();
|
String mode = args[2].toString();
|
||||||
Log.d("[Bluetooth] Event: " + command + " : " + eventName + ", id = " + buttonID + " (" + mode + ")");
|
android.util.Log.d("BluetoothManager", "[Bluetooth] Event: " + command + " : " + eventName + ", id = " + buttonID + " (" + mode + ")");
|
||||||
} else {
|
} else {
|
||||||
Log.d("[Bluetooth] Event: " + command + " : " + eventName);
|
android.util.Log.d("BluetoothManager", "[Bluetooth] Event: " + command + " : " + eventName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue