Skip to content

Commit

Permalink
Fix some very rare crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
mar-v-in committed Jul 6, 2023
1 parent 4772008 commit bca01d0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,32 @@ class ClearcutLoggerServiceImpl(private val lifecycle: Lifecycle) : IClearcutLog

override fun log(callbacks: IClearcutLoggerCallbacks, event: LogEventParcelable) {
lifecycleScope.launchWhenStarted {
callbacks.onLogResult(Status.SUCCESS)
runCatching { callbacks.onLogResult(Status.SUCCESS) }
}
}

override fun forceUpload(callbacks: IClearcutLoggerCallbacks) {
lifecycleScope.launchWhenStarted {
callbacks.onLogResult(Status.SUCCESS)
runCatching { callbacks.onLogResult(Status.SUCCESS) }
}
}

override fun startCollectForDebug(callbacks: IClearcutLoggerCallbacks) {
lifecycleScope.launchWhenStarted {
collectForDebugExpiryTime = System.currentTimeMillis() + COLLECT_FOR_DEBUG_DURATION
callbacks.onStartCollectForDebugResult(Status.SUCCESS, collectForDebugExpiryTime)
runCatching { callbacks.onStartCollectForDebugResult(Status.SUCCESS, collectForDebugExpiryTime) }
}
}

override fun stopCollectForDebug(callbacks: IClearcutLoggerCallbacks) {
lifecycleScope.launchWhenStarted {
callbacks.onStopCollectForDebugResult(Status.SUCCESS)
runCatching { callbacks.onStopCollectForDebugResult(Status.SUCCESS) }
}
}

override fun getCollectForDebugExpiryTime(callbacks: IClearcutLoggerCallbacks) {
lifecycleScope.launchWhenStarted {
callbacks.onCollectForDebugExpiryTime(Status.SUCCESS, collectForDebugExpiryTime)
runCatching { callbacks.onCollectForDebugExpiryTime(Status.SUCCESS, collectForDebugExpiryTime) }
}
}

Expand All @@ -69,7 +69,7 @@ class ClearcutLoggerServiceImpl(private val lifecycle: Lifecycle) : IClearcutLog

override fun getLogEventParcelables(callbacks: IClearcutLoggerCallbacks) {
lifecycleScope.launchWhenStarted {
callbacks.onLogEventParcelables(DataHolder.empty(CommonStatusCodes.SUCCESS))
runCatching { callbacks.onLogEventParcelables(DataHolder.empty(CommonStatusCodes.SUCCESS)) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CountDownLatch;

import okio.ByteString;

Expand All @@ -89,6 +90,7 @@ public class WearableImpl {
private ConnectionConfiguration[] configurations;
private boolean configurationsUpdated = false;
private ClockworkNodePreferences clockworkNodePreferences;
private CountDownLatch networkHandlerLock = new CountDownLatch(1);
public Handler networkHandler;

public WearableImpl(Context context, NodeDatabaseHelper nodeDatabase, ConfigurationDatabaseHelper configDatabase) {
Expand All @@ -100,6 +102,7 @@ public WearableImpl(Context context, NodeDatabaseHelper nodeDatabase, Configurat
new Thread(() -> {
Looper.prepare();
networkHandler = new Handler(Looper.myLooper());
networkHandlerLock.countDown();
Looper.loop();
}).start();
}
Expand Down Expand Up @@ -619,7 +622,12 @@ public int sendMessage(String packageName, String targetNodeId, String path, byt
}

public void stop() {
this.networkHandler.getLooper().quit();
try {
this.networkHandlerLock.await();
this.networkHandler.getLooper().quit();
} catch (InterruptedException e) {
Log.w(TAG, e);
}
}

private class ListenerInfo {
Expand Down

0 comments on commit bca01d0

Please sign in to comment.