Skip to content

Commit

Permalink
Attempt to swallow erroneous cancel alarm security exceptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
cody-signal committed Jul 26, 2023
1 parent 82e7050 commit 1e9a0cd
Showing 1 changed file with 17 additions and 2 deletions.
Expand Up @@ -126,8 +126,23 @@ protected static void cancelAlarm(@NonNull Context context, @NonNull Class<? ext
try {
pendingIntent.cancel();
ServiceUtil.getAlarmManager(context).cancel(pendingIntent);
} catch (SecurityException e) {
Log.i(TAG, "Unable to cancel alarm because we don't have permission");
} catch (Exception e) {
Throwable cause = e;
int depth = 0;
while (cause != null && depth < 5) {
if (cause instanceof SecurityException) {
break;
} else {
cause = e.getCause();
depth++;
}
}

if (e instanceof SecurityException) {
Log.i(TAG, "Unable to cancel alarm because we don't have permission");
} else {
throw e;
}
}
}
}

0 comments on commit 1e9a0cd

Please sign in to comment.