aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2021-10-16 01:02:11 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2021-10-16 01:02:11 +0000
commit101102838597ea8383623738ef82ff565e468970 (patch)
tree7dada9629976efaca4537893d3c6841bdee6f692
parentde4f038d35c280f37f03852dd9136ca2ce59908b (diff)
parent7a49de334fab02528ca9ca7d236b17048e8b5566 (diff)
downloadconnectedappssdk-android12L-s1-release.tar.gz
Change-Id: I75aec93d3a2e6a21609001565dcfcf18002e5cbc
-rw-r--r--processor/src/main/java/com/google/android/enterprise/connectedapps/processor/DispatcherGenerator.java15
-rw-r--r--processor/src/main/java/com/google/android/enterprise/connectedapps/processor/FakeOtherGenerator.java6
-rw-r--r--sdk/src/main/java/com/google/android/enterprise/connectedapps/exceptions/ProfileRuntimeException.java4
-rw-r--r--sdk/src/main/java/com/google/android/enterprise/connectedapps/internal/BackgroundExceptionThrower.java22
4 files changed, 41 insertions, 6 deletions
diff --git a/processor/src/main/java/com/google/android/enterprise/connectedapps/processor/DispatcherGenerator.java b/processor/src/main/java/com/google/android/enterprise/connectedapps/processor/DispatcherGenerator.java
index f5264b0..a4f8ef6 100644
--- a/processor/src/main/java/com/google/android/enterprise/connectedapps/processor/DispatcherGenerator.java
+++ b/processor/src/main/java/com/google/android/enterprise/connectedapps/processor/DispatcherGenerator.java
@@ -187,6 +187,21 @@ final class DispatcherGenerator {
methodCode.addStatement("$T.throwInBackground(e)", BACKGROUND_EXCEPTION_THROWER_CLASSNAME);
methodCode.addStatement("return throwableBytes");
+ methodCode.nextControlFlow("catch ($T e)", Error.class);
+
+ // parcel is recycled in this method
+ methodCode.addStatement("$1T throwableParcel = $1T.obtain()", PARCEL_CLASSNAME);
+ methodCode.add("throwableParcel.writeInt(1); //errors\n");
+ methodCode.addStatement(
+ "$T.writeThrowableToParcel(throwableParcel, e)", PARCEL_UTILITIES_CLASSNAME);
+ methodCode.addStatement(
+ "$1T throwableBytes = parcelCallReceiver.prepareResponse(callId, throwableParcel)",
+ ArrayTypeName.of(byte.class));
+ methodCode.addStatement("throwableParcel.recycle()");
+
+ methodCode.addStatement("$T.throwInBackground(e)", BACKGROUND_EXCEPTION_THROWER_CLASSNAME);
+
+ methodCode.addStatement("return throwableBytes");
methodCode.endControlFlow();
MethodSpec callMethod =
diff --git a/processor/src/main/java/com/google/android/enterprise/connectedapps/processor/FakeOtherGenerator.java b/processor/src/main/java/com/google/android/enterprise/connectedapps/processor/FakeOtherGenerator.java
index 20bf0fb..53e5c72 100644
--- a/processor/src/main/java/com/google/android/enterprise/connectedapps/processor/FakeOtherGenerator.java
+++ b/processor/src/main/java/com/google/android/enterprise/connectedapps/processor/FakeOtherGenerator.java
@@ -215,6 +215,8 @@ final class FakeOtherGenerator {
methodBuilder.addStatement(methodCall);
methodBuilder.nextControlFlow("catch ($T e)", RuntimeException.class);
methodBuilder.addStatement("throw new $T(e)", PROFILE_RUNTIME_EXCEPTION_CLASSNAME);
+ methodBuilder.nextControlFlow("catch ($T e)", Error.class);
+ methodBuilder.addStatement("throw new $T(e)", PROFILE_RUNTIME_EXCEPTION_CLASSNAME);
methodBuilder.endControlFlow();
classBuilder.addMethod(methodBuilder.build());
}
@@ -267,6 +269,8 @@ final class FakeOtherGenerator {
methodBuilder.addStatement(methodCall);
methodBuilder.nextControlFlow("catch ($T e)", RuntimeException.class);
methodBuilder.addStatement("throw new $T(e)", PROFILE_RUNTIME_EXCEPTION_CLASSNAME);
+ methodBuilder.nextControlFlow("catch ($T e)", Error.class);
+ methodBuilder.addStatement("throw new $T(e)", PROFILE_RUNTIME_EXCEPTION_CLASSNAME);
methodBuilder.endControlFlow();
classBuilder.addMethod(methodBuilder.build());
@@ -332,6 +336,8 @@ final class FakeOtherGenerator {
}
methodBuilder.nextControlFlow("catch ($T e)", RuntimeException.class);
methodBuilder.addStatement("throw new $T(e)", PROFILE_RUNTIME_EXCEPTION_CLASSNAME);
+ methodBuilder.nextControlFlow("catch ($T e)", Error.class);
+ methodBuilder.addStatement("throw new $T(e)", PROFILE_RUNTIME_EXCEPTION_CLASSNAME);
methodBuilder.endControlFlow();
classBuilder.addMethod(methodBuilder.build());
diff --git a/sdk/src/main/java/com/google/android/enterprise/connectedapps/exceptions/ProfileRuntimeException.java b/sdk/src/main/java/com/google/android/enterprise/connectedapps/exceptions/ProfileRuntimeException.java
index 6ea9005..511a77a 100644
--- a/sdk/src/main/java/com/google/android/enterprise/connectedapps/exceptions/ProfileRuntimeException.java
+++ b/sdk/src/main/java/com/google/android/enterprise/connectedapps/exceptions/ProfileRuntimeException.java
@@ -16,12 +16,12 @@
package com.google.android.enterprise.connectedapps.exceptions;
/**
- * Thrown when a {@link RuntimeException} is thrown during a cross-profile call.
+ * Thrown when a {@link Throwable} is thrown during a cross-profile call.
*
* <p>To get the original exception, call {@link #getCause()}.
*/
public class ProfileRuntimeException extends RuntimeException {
- public ProfileRuntimeException(RuntimeException cause) {
+ public ProfileRuntimeException(Throwable cause) {
super(cause);
}
}
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);
+ }
}