Skip to content

Commit

Permalink
Merge pull request #11 from dji-sdk/BRDG-14-investigate-fix-recent-cr…
Browse files Browse the repository at this point in the history
…ashes

Trace crash due to runners
  • Loading branch information
siddutgikar authored Dec 8, 2018
2 parents 114ce9e + f7ef828 commit 3787178
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion android-wsbridge/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ android {
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.2.4"
versionName "1.2.5"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
buildConfigField "String", "BASE_URL", getBaseUrl()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
Expand All @@ -28,6 +29,7 @@
import android.widget.TextView;
import android.widget.Toast;

import com.crashlytics.android.Crashlytics;
import com.dji.wsbridge.lib.BridgeApplication;
import com.dji.wsbridge.lib.BridgeUpdateService;
import com.dji.wsbridge.lib.DJILogger;
Expand Down Expand Up @@ -314,8 +316,22 @@ private void refreshRunners() {
isStreamRunnerActive.set(true);
deviceToWSRunner = new StreamRunner(wsInputStream, usbOutputStream, "Bridge to USB");
wsToDeviceRunner = new StreamRunner(usbInputStream, wsOutputStream, "USB to Bridge");
deviceToWSRunner.start();
wsToDeviceRunner.start();
try {
Crashlytics.log("Device to WS Runner alive "+ deviceToWSRunner.isAlive());
Crashlytics.log("WS to Device Runner alive "+ wsToDeviceRunner.isAlive());
deviceToWSRunner.start();
wsToDeviceRunner.start();
} catch (IllegalThreadStateException exception){
Crashlytics.logException(exception);
stopStreamTransfer();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
refresh();
}
},1500);
}

} else {
Log.d(TAG, "Stream Transfers NOT started");
DJILogger.e(TAG, "Stream Transfers NOT started");
Expand Down Expand Up @@ -372,18 +388,18 @@ private boolean setupStreams() {
}

private void stopStreamTransfer() {
if (wsToDeviceRunner != null && deviceToWSRunner != null) {
isStreamRunnerActive.set(false);

if (wsToDeviceRunner != null) {
wsToDeviceRunner.cleanup();
wsToDeviceRunner = null;

}
if (deviceToWSRunner != null) {
deviceToWSRunner.cleanup();
deviceToWSRunner = null;

USBConnectionManager.getInstance().closeStreams();
WSConnectionManager.getInstance().closeStreams();
}
isStreamRunnerActive.set(false);

USBConnectionManager.getInstance().closeStreams();
WSConnectionManager.getInstance().closeStreams();
}
//endregion -----------------------------------------------------------------------------------------------------

Expand Down

0 comments on commit 3787178

Please sign in to comment.