aboutsummaryrefslogtreecommitdiff
path: root/sdk/src/main/java/com/google/android/enterprise/connectedapps/internal/BackgroundExceptionThrower.java
diff options
context:
space:
mode:
Diffstat (limited to 'sdk/src/main/java/com/google/android/enterprise/connectedapps/internal/BackgroundExceptionThrower.java')
-rw-r--r--sdk/src/main/java/com/google/android/enterprise/connectedapps/internal/BackgroundExceptionThrower.java22
1 files changed, 18 insertions, 4 deletions
diff --git a/sdk/src/main/java/com/google/android/enterprise/connectedapps/internal/BackgroundExceptionThrower.java b/sdk/src/main/java/com/google/android/enterprise/connectedapps/internal/BackgroundExceptionThrower.java
index 0999a35..9511e19 100644
--- a/sdk/src/main/java/com/google/android/enterprise/connectedapps/internal/BackgroundExceptionThrower.java
+++ b/sdk/src/main/java/com/google/android/enterprise/connectedapps/internal/BackgroundExceptionThrower.java
@@ -24,15 +24,23 @@ public final class BackgroundExceptionThrower {
private BackgroundExceptionThrower() {}
private static class ThrowingRunnable implements Runnable {
- RuntimeException throwable;
+ RuntimeException runtimeException;
+ Error error;
- ThrowingRunnable(RuntimeException throwable) {
- this.throwable = throwable;
+ ThrowingRunnable(RuntimeException runtimeException) {
+ this.runtimeException = runtimeException;
+ }
+
+ ThrowingRunnable(Error error) {
+ this.error = error;
}
@Override
public void run() {
- throw throwable;
+ if (error != null) {
+ throw error;
+ }
+ throw runtimeException;
}
}
@@ -41,4 +49,10 @@ public final class BackgroundExceptionThrower {
// We add a small delay to ensure that the return can be completed before crashing
new Handler(Looper.getMainLooper()).postDelayed(new ThrowingRunnable(throwable), 1000);
}
+
+ /** Throw the given {@link Error} after a delay on the main looper. */
+ public static void throwInBackground(Error throwable) {
+ // We add a small delay to ensure that the return can be completed before crashing
+ new Handler(Looper.getMainLooper()).postDelayed(new ThrowingRunnable(throwable), 1000);
+ }
}