Fix headset disconnect problem when other devices connected and we received ACL_CONNECTED, ACL_DISCONNECTED broadcasts
This commit is contained in:
parent
37b768e335
commit
6a01b0099d
5 changed files with 102 additions and 55 deletions
18
vxt-engine/proguard-rules.pro
vendored
18
vxt-engine/proguard-rules.pro
vendored
|
|
@ -1,19 +1,19 @@
|
|||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
|
||||
-assumenosideeffects class android.util.Log {
|
||||
public static boolean isLoggable(java.lang.String, int);
|
||||
public static int v(...);
|
||||
public static int i(...);
|
||||
public static int w(...);
|
||||
public static int d(...);
|
||||
public static int e(...);
|
||||
}
|
||||
#-assumenosideeffects class android.util.Log {
|
||||
# public static boolean isLoggable(java.lang.String, int);
|
||||
# public static int v(...);
|
||||
# public static int i(...);
|
||||
# public static int w(...);
|
||||
# public static int d(...);
|
||||
# public static int e(...);
|
||||
#}
|
||||
|
||||
-keep class com.nuance.android.vocalizer.** { *; }
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@
|
|||
<activity android:name="com.voixtreme.vocalengine.MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
<action android:name="com.nuance.vocalizer.VOCALIZER_DATA" />
|
||||
</intent-filter>
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import android.os.Handler;
|
|||
import android.os.Looper;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import com.dixitmobile.common.BluetoothHelper;
|
||||
import com.dixitmobile.common.BroadcastParams;
|
||||
import com.voixtreme.vocalengine.service.VoiXtremeService;
|
||||
import com.voixtreme.vxtenginejni.VxtEngineApi;
|
||||
|
|
@ -309,8 +310,6 @@ public class BluetoothSCOManager extends BroadcastReceiver {
|
|||
*/
|
||||
private void scoConnected() {
|
||||
|
||||
Log.v(TAG, "eml: scoConnected()");
|
||||
|
||||
if (mReconnectSCO != null) {
|
||||
mReconnectSCO.interrupt();
|
||||
mReconnectSCO = null;
|
||||
|
|
@ -322,6 +321,8 @@ public class BluetoothSCOManager extends BroadcastReceiver {
|
|||
}
|
||||
|
||||
mConnectedSCO = true;
|
||||
mConnectedMAC = getConnectedMAC();
|
||||
Log.v(TAG, "eml: scoConnected(): " + mConnectedMAC);
|
||||
|
||||
if (!mStarted || mPaused) {
|
||||
return;
|
||||
|
|
@ -346,6 +347,24 @@ public class BluetoothSCOManager extends BroadcastReceiver {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to get the MAC address of the Headset connected with BluetoothSCO
|
||||
*
|
||||
* @return MAC or empty string if not found
|
||||
*/
|
||||
private String getConnectedMAC() {
|
||||
|
||||
for (BluetoothDevice device : mBTAdapter.getBondedDevices()) {
|
||||
if (BluetoothHelper.isMajorHeadset(device)) {
|
||||
if (BluetoothHelper.isConnected(device)) {
|
||||
return device.getAddress();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper class for re-establishing a SCO connection with the headset
|
||||
*/
|
||||
|
|
@ -371,7 +390,7 @@ public class BluetoothSCOManager extends BroadcastReceiver {
|
|||
|
||||
while (!mConnectedSCO && mStarted && !mPaused) {
|
||||
if (disconnected) {
|
||||
Log.i(TAG, "eml: connectHeadset() loop");
|
||||
Log.i(TAG, "eml: connectHeadset() loop: " + counter);
|
||||
connectHeadset("");
|
||||
|
||||
try {
|
||||
|
|
@ -443,14 +462,17 @@ public class BluetoothSCOManager extends BroadcastReceiver {
|
|||
*/
|
||||
private void deviceConnected(BluetoothDevice btDevice) {
|
||||
|
||||
final boolean isHeadset = BluetoothHelper.isMajorHeadset(btDevice);
|
||||
|
||||
Log.v(TAG, "eml: BluetoothDevice.ACTION_ACL_CONNECTED: " + btDevice.getAddress() + " / "
|
||||
+ btDevice.getName());
|
||||
Log.i(TAG, "eml: mStarted: " + mStarted);
|
||||
Log.i(TAG, "eml: mPaused : " + mPaused);
|
||||
Log.i(TAG, "eml: MACs : " + mConnectedMAC + " <--> " + btDevice.getAddress());
|
||||
Log.i(TAG, "eml: mStarted : " + mStarted);
|
||||
Log.i(TAG, "eml: mPaused : " + mPaused);
|
||||
Log.i(TAG, "eml: isHeadset: " + isHeadset);
|
||||
Log.i(TAG, "eml: MACs : " + mConnectedMAC + " <--> " + btDevice.getAddress());
|
||||
|
||||
if (mResuming
|
||||
|| ((mStarted || mPaused) && mConnectedMAC != null && mConnectedMAC.equals(btDevice.getAddress()))) {
|
||||
if (isHeadset && (mResuming
|
||||
|| ((mStarted || mPaused) && mConnectedMAC != null && mConnectedMAC.equals(btDevice.getAddress())))) {
|
||||
|
||||
// Log.i(TAG, "eml: request connect to headset !!! ");
|
||||
// connectHeadset(mConnectedMAC);
|
||||
|
|
@ -475,52 +497,59 @@ public class BluetoothSCOManager extends BroadcastReceiver {
|
|||
}
|
||||
|
||||
/**
|
||||
* A Bluetooth devices was disconnected from the system. We do not know if this is a headset or not but we
|
||||
* save the information just in case.
|
||||
* A Bluetooth devices was disconnected from the system.
|
||||
*
|
||||
* @param btDevice The device that was disconnected
|
||||
*/
|
||||
private void deviceDisconnected(BluetoothDevice btDevice) {
|
||||
|
||||
final boolean isHeadset = BluetoothHelper.isMajorHeadset(btDevice);
|
||||
|
||||
Log.v(TAG, "eml: BluetoothDevice.ACTION_ACL_DISCONNECTED: " + btDevice.getAddress() + " / "
|
||||
+ btDevice.getName());
|
||||
if (mStarted) {
|
||||
Log.i(TAG, "eml: saving MAC: " + btDevice.getAddress());
|
||||
Log.i(TAG, "eml: isHeadset: " + isHeadset);
|
||||
|
||||
if (mConnectedSCO) {
|
||||
mDisconnectedMAC = btDevice.getAddress();
|
||||
} else {
|
||||
// Sometimes the BluetoothSCO gets disconnected before we know the devices was disconnected
|
||||
mConnectedMAC = btDevice.getAddress();
|
||||
mDisconnectedMAC = null;
|
||||
}
|
||||
if (isHeadset) {
|
||||
if (mStarted) {
|
||||
Log.i(TAG, "eml: saving MAC: " + btDevice.getAddress());
|
||||
Log.d(TAG, "eml: mConMAC: " + mConnectedMAC);
|
||||
Log.d(TAG, "eml: mDisMAC: " + mDisconnectedMAC);
|
||||
|
||||
stop();
|
||||
|
||||
if (mReconnectSCO != null) {
|
||||
mReconnectSCO.interrupt();
|
||||
|
||||
try {
|
||||
Thread.sleep(713);
|
||||
} catch (Exception e) {
|
||||
// empty by design
|
||||
if (mConnectedSCO) {
|
||||
mDisconnectedMAC = btDevice.getAddress();
|
||||
} else {
|
||||
// Sometimes the BluetoothSCO gets disconnected before we know the devices was disconnected
|
||||
mConnectedMAC = btDevice.getAddress();
|
||||
mDisconnectedMAC = null;
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
Thread.sleep(1713);
|
||||
} catch (Exception e) {
|
||||
// empty by design
|
||||
}
|
||||
}
|
||||
|
||||
start();
|
||||
stop();
|
||||
|
||||
if (mReconnectSCO != null) {
|
||||
mReconnectSCO.interrupt();
|
||||
|
||||
try {
|
||||
Thread.sleep(713);
|
||||
} catch (Exception e) {
|
||||
// empty by design
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
Thread.sleep(1713);
|
||||
} catch (Exception e) {
|
||||
// empty by design
|
||||
}
|
||||
}
|
||||
|
||||
start();
|
||||
|
||||
// mReconnectSCO = new Thread(new SCOReconnect(true));
|
||||
// mReconnectSCO.start();
|
||||
} else {
|
||||
Log.w(TAG, "eml: NOT started, ignoring device");
|
||||
mDisconnectedMAC = null;
|
||||
mConnectedMAC = null;
|
||||
} else {
|
||||
Log.w(TAG, "eml: NOT started, ignoring device");
|
||||
mDisconnectedMAC = null;
|
||||
mConnectedMAC = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import android.os.Message;
|
|||
import android.util.Log;
|
||||
|
||||
import com.dixitmobile.common.BroadcastParams;
|
||||
import com.dixitmobile.common.Common;
|
||||
import com.voixtreme.vocalengine.service.VoiXtremeService;
|
||||
import com.voixtreme.vocalengine.service.VxtCommandManager;
|
||||
import com.voixtreme.vocalengine.service.VxtAsrStateManager;
|
||||
|
|
@ -128,9 +129,18 @@ public class VoiXtremeReceiver extends BroadcastReceiver {
|
|||
break;
|
||||
|
||||
case BroadcastParams.COMMAND_FINALIZE:
|
||||
Log.i(TAG, "Intent COMMAND_FINALIZE");
|
||||
Log.i(TAG, "Intent COMMAND_FINALIZE: "
|
||||
+ intent.getExtras().getString( BroadcastParams.EXTRAS_RESPONSE_ACTION));
|
||||
//commandManager.setCommand(command, null);
|
||||
mHandler.sendMessage( Message.obtain( mHandler, command));
|
||||
|
||||
Log.d(TAG, "eml: engine service: " + Common.isServiceRunning(context, VoiXtremeService.class.getName()));
|
||||
Log.d(TAG, "eml: engine service: " + VoiXtremeService.class.getName());
|
||||
|
||||
if (!Common.isServiceRunning(context, VoiXtremeService.class.getName())) {
|
||||
Log.e(TAG, "VxtEngine: KILLING VoiXtreme");
|
||||
System.exit(0);
|
||||
}
|
||||
break;
|
||||
|
||||
case BroadcastParams.COMMAND_SPEECH:
|
||||
|
|
|
|||
|
|
@ -172,6 +172,8 @@ public class VoiXtremeService extends VoiXtremeServiceBase
|
|||
super.onCreate();
|
||||
mIsConfigured = false;
|
||||
|
||||
Log.i(TAG, "eml: onCreate()");
|
||||
|
||||
mInputType = BroadcastParams.INPUT_TYPE_OPEN;
|
||||
mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
|
||||
mAudioSystem = new AudioSystem(mAudioManager);
|
||||
|
|
@ -223,6 +225,8 @@ public class VoiXtremeService extends VoiXtremeServiceBase
|
|||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
|
||||
Log.i(TAG, "eml: onStartCommand()");
|
||||
|
||||
super.onStartCommand(intent, flags, startId);
|
||||
startForeground(313, buildForegroundNotification());
|
||||
|
||||
|
|
@ -1078,12 +1082,14 @@ public class VoiXtremeService extends VoiXtremeServiceBase
|
|||
break;
|
||||
|
||||
case BroadcastParams.COMMAND_FINALIZE:
|
||||
Log.i(TAG, "update COMMAND_FINALIZE" );
|
||||
|
||||
mVxtEngineApi.nativelog( 0, TAG, "updateFromHandler COMMAND_FINALIZE" );
|
||||
mVxtEngineApi.vxtFinalizeAll();
|
||||
|
||||
Log.i(TAG, "update COMMAND_FINALIZE #1" );
|
||||
stopSelf();
|
||||
|
||||
Log.i(TAG, "update COMMAND_FINALIZE #2" );
|
||||
mVxtEngineApi.nativelog( 0, TAG, "updateFromHandler COMMAND_FINALIZE #1" );
|
||||
mVxtEngineApi.vxtFinalizeAll();
|
||||
Log.i(TAG, "update COMMAND_FINALIZE #3" );
|
||||
mVxtEngineApi.nativelog( 0, TAG, "updateFromHandler COMMAND_FINALIZE #2" );
|
||||
break;
|
||||
|
||||
// From intent
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue