Skip to content

Commit

Permalink
Merge pull request #96 from zelloptt/issues/ANDROID-845-foreground-se…
Browse files Browse the repository at this point in the history
…rvice

Try/catch service start to prevent crashes
  • Loading branch information
padgrayson91 authored Feb 13, 2024
2 parents cb7c9e6 + 4fe7b10 commit 4825f43
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 2 deletions.
Binary file modified zello-sdk-sample-contacts/libs/zello-sdk.aar
Binary file not shown.
Binary file modified zello-sdk-sample-misc/libs/zello-sdk.aar
Binary file not shown.
Binary file modified zello-sdk-sample-ptt/libs/zello-sdk.aar
Binary file not shown.
Binary file modified zello-sdk-sample-signin/libs/zello-sdk.aar
Binary file not shown.
Binary file modified zello-sdk-sample/libs/zello-sdk.aar
Binary file not shown.
Binary file modified zello-sdk.aar
Binary file not shown.
15 changes: 13 additions & 2 deletions zello-sdk/src/main/java/com/zello/sdk/Sdk.java
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,12 @@ boolean signIn(@Nullable String network, @Nullable String username, @Nullable St
context.sendBroadcast(intent);
// Service intent in guaranteed to be non-null at this point
if (_serviceIntent != null) {
ContextCompat.startForegroundService(context, _serviceIntent);
try {
ContextCompat.startForegroundService(context, _serviceIntent);
} catch (Throwable t) {
// Caller may not be in the right state to start a service
Log.INSTANCE.e("Failed to start " + connectedPackage + " service", t);
}
}
return true;
}
Expand Down Expand Up @@ -675,7 +680,13 @@ public void onServiceConnected(@Nullable ComponentName name, @Nullable IBinder s
_serviceConnecting = false;
// Service intent in guaranteed to be non-null at this point
if (_serviceIntent != null) {
ContextCompat.startForegroundService(context, _serviceIntent);
try {
ContextCompat.startForegroundService(context, _serviceIntent);
} catch (Throwable t) {
// Caller may not be in the right state to start a service
String componentPackageName = name != null ? name.getPackageName() : null;
Log.INSTANCE.e("Failed to start " + componentPackageName + " service", t);
}
}
if (_delayedShowBtAccessoriesNotifications != null) {
setShowBluetoothAccessoriesNotifications(_delayedShowBtAccessoriesNotifications);
Expand Down

0 comments on commit 4825f43

Please sign in to comment.