Skip to content

Commit c18e988

Browse files
committed
handle DeadSystemException from huawei APIs
Under the hood isHuaweiMobileServicesAvailable uses getApplicationInfo which can throw this Android level expection.
1 parent 1ad0eba commit c18e988

File tree

1 file changed

+15
-1
lines changed
  • OneSignalSDK/onesignal/src/main/java/com/onesignal

1 file changed

+15
-1
lines changed

OneSignalSDK/onesignal/src/main/java/com/onesignal/OSUtils.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
package com.onesignal;
2929

30+
import android.annotation.TargetApi;
3031
import android.app.Activity;
3132
import android.content.ContentResolver;
3233
import android.content.Context;
@@ -40,6 +41,7 @@
4041
import android.net.Uri;
4142
import android.os.Build;
4243
import android.os.Bundle;
44+
import android.os.DeadSystemException;
4345
import android.os.Handler;
4446
import android.os.Looper;
4547

@@ -298,9 +300,21 @@ static boolean isGMSInstalledAndEnabled() {
298300
}
299301

300302
private static final int HMS_AVAILABLE_SUCCESSFUL = 0;
303+
@TargetApi(24)
301304
private static boolean isHMSCoreInstalledAndEnabled() {
302305
HuaweiApiAvailability availability = HuaweiApiAvailability.getInstance();
303-
return availability.isHuaweiMobileServicesAvailable(OneSignal.appContext) == HMS_AVAILABLE_SUCCESSFUL;
306+
try {
307+
return availability.isHuaweiMobileServicesAvailable(OneSignal.appContext) == HMS_AVAILABLE_SUCCESSFUL;
308+
} catch (Exception e) {
309+
// Suppressing DeadSystemException as the app is already dying for
310+
// another reason and allowing this exception to bubble up would
311+
// create a red herring for app developers. We still re-throw
312+
// others, as we don't want to silently hide other issues.
313+
if (!(e instanceof DeadSystemException)) {
314+
throw e;
315+
}
316+
return false;
317+
}
304318
}
305319

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

0 commit comments

Comments
 (0)