Skip to content

Commit

Permalink
handle DeadSystemException from huawei APIs
Browse files Browse the repository at this point in the history
Under the hood isHuaweiMobileServicesAvailable uses getApplicationInfo
which can throw this Android level expection.
  • Loading branch information
jkasten2 committed Dec 8, 2023
1 parent 1ad0eba commit c18e988
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion OneSignalSDK/onesignal/src/main/java/com/onesignal/OSUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

package com.onesignal;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
Expand All @@ -40,6 +41,7 @@
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.DeadSystemException;
import android.os.Handler;
import android.os.Looper;

Expand Down Expand Up @@ -298,9 +300,21 @@ static boolean isGMSInstalledAndEnabled() {
}

private static final int HMS_AVAILABLE_SUCCESSFUL = 0;
@TargetApi(24)
private static boolean isHMSCoreInstalledAndEnabled() {
HuaweiApiAvailability availability = HuaweiApiAvailability.getInstance();
return availability.isHuaweiMobileServicesAvailable(OneSignal.appContext) == HMS_AVAILABLE_SUCCESSFUL;
try {
return availability.isHuaweiMobileServicesAvailable(OneSignal.appContext) == HMS_AVAILABLE_SUCCESSFUL;
} catch (Exception e) {
// 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;
}
return false;
}
}

private static final String HMS_CORE_SERVICES_PACKAGE = "com.huawei.hwid"; // = HuaweiApiAvailability.SERVICES_PACKAGE
Expand Down

0 comments on commit c18e988

Please sign in to comment.