Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Player Model] Corrected DeadSystemException handling #2063

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.content.Context
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.os.DeadSystemException
import android.util.AndroidException

class ApplicationInfoHelper {
companion object {
Expand All @@ -26,15 +25,20 @@ class ApplicationInfoHelper {
PackageManager.GET_META_DATA,
)
cachedInfo
} catch (e: AndroidException) {
} catch (e: RuntimeException) {
// Android internally throws this via RemoteException.rethrowFromSystemServer()
// so we must catch RuntimeException and check the cause.

// Suppressing DeadSystemException as the app is already dying for
// another reason and allowing this exception to bubble up would
// create a red herring for app developers. We still re-throw
// others, as we don't want to silently hide other issues.
if (e !is DeadSystemException) {
if (e.cause is DeadSystemException) {
null
}
else {
throw e
}
null
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,15 @@ private static List<NotificationChannel> getChannelList(NotificationManager noti
// "Attempt to invoke virtual method 'boolean android.app.NotificationChannel.isDeleted()' on a null object reference"
// https://github.com/OneSignal/OneSignal-Android-SDK/issues/1291
OneSignal.onesignalLog(OneSignal.LOG_LEVEL.ERROR, "Error when trying to delete notification channel: " + e.getMessage());
}
catch (Exception e) {
} catch (RuntimeException e) {
// Android internally throws this via RemoteException.rethrowFromSystemServer()
// so we must catch RuntimeException and check the cause.

// Suppressing DeadSystemException as the app is already dying for
// another reason and allowing this exception to bubble up would
// create a red herring for app developers. We still re-throw
// others, as we don't want to silently hide other issues.
if (!(e instanceof DeadSystemException)) {
if (!(e.getCause() instanceof DeadSystemException)) {
throw e;
}
}
Expand Down
11 changes: 7 additions & 4 deletions OneSignalSDK/onesignal/src/main/java/com/onesignal/OSUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,15 +306,18 @@ private static boolean isHMSCoreInstalledAndEnabled() {
HuaweiApiAvailability availability = HuaweiApiAvailability.getInstance();
try {
return availability.isHuaweiMobileServicesAvailable(OneSignal.appContext) == HMS_AVAILABLE_SUCCESSFUL;
} catch (Exception e) {
} catch (RuntimeException e) {
// Android internally throws this via RemoteException.rethrowFromSystemServer()
// so we must catch RuntimeException and check the cause.

// Suppressing DeadSystemException as the app is already dying for
// another reason and allowing this exception to bubble up would
// create a red herring for app developers. We still re-throw
// others, as we don't want to silently hide other issues.
if (!(e instanceof DeadSystemException)) {
throw e;
if (e.getCause() instanceof DeadSystemException) {
return false;
}
return false;
throw e;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.content.Context
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.os.DeadSystemException
import android.util.AndroidException

data class GetPackageInfoResult(
// Check this value first, if false ignore other properties
Expand Down Expand Up @@ -35,15 +34,20 @@ class PackageInfoHelper {
} catch (e: PackageManager.NameNotFoundException) {
// Expected if package is not installed on the device.
GetPackageInfoResult(true, null)
} catch (e: AndroidException) {
} catch (e: RuntimeException) {
// Android internally throws this via RemoteException.rethrowFromSystemServer()
// so we must catch RuntimeException and check the cause.

// Suppressing DeadSystemException as the app is already dying for
// another reason and allowing this exception to bubble up would
// create a red herring for app developers. We still re-throw
// others, as we don't want to silently hide other issues.
if (e !is DeadSystemException) {
if (e.cause is DeadSystemException) {
GetPackageInfoResult(false, null)
}
else {
throw e
}
GetPackageInfoResult(false, null)
}
}
}
Expand Down
Loading