diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2021-10-16 01:02:15 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2021-10-16 01:02:15 +0000 |
commit | 6e913eaab4b5f88dc5b4174c683d6c8eba875cf2 (patch) | |
tree | 7dada9629976efaca4537893d3c6841bdee6f692 | |
parent | ebf8af7daa4b9b486152817dcbebd9e06198c270 (diff) | |
parent | 7a49de334fab02528ca9ca7d236b17048e8b5566 (diff) | |
download | connectedappssdk-android12L-d2-s8-release.tar.gz |
Snap for 7829119 from 7a49de334fab02528ca9ca7d236b17048e8b5566 to sc-d2-releaseandroid-12.1.0_r26android-12.1.0_r25android-12.1.0_r24android-12.1.0_r23android-12.1.0_r18android-12.1.0_r17android-12.1.0_r16android-12.1.0_r15android-12.1.0_r14android-12.1.0_r13android-12.1.0_r12android12L-d2-s8-releaseandroid12L-d2-s7-releaseandroid12L-d2-s6-releaseandroid12L-d2-s5-releaseandroid12L-d2-s4-releaseandroid12L-d2-s3-releaseandroid12L-d2-s2-releaseandroid12L-d2-s1-releaseandroid12L-d2-release
Change-Id: I9e70bfec2c3f24b75f65a3c9b3da75a2be9e59f8
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); + } } |