Attempt to swallow erroneous cancel alarm security exceptions.

This commit is contained in:
Cody Henthorne
2023-07-26 14:07:10 -04:00
parent 82e7050864
commit 1e9a0cdc16

View File

@@ -126,8 +126,23 @@ public abstract class TimedEventManager<E> {
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;
}
}
}
}