aboutsummaryrefslogtreecommitdiff
path: root/sandbox
diff options
context:
space:
mode:
authoralixwar <alix.warnke@assaabloy.com>2023-05-30 16:24:36 +0200
committerutzcoz <43091780+utzcoz@users.noreply.github.com>2023-06-02 11:17:36 +0800
commit1ef305844cee51479bc27d56f129589cec0831fb (patch)
tree7bab3628554ce65809a943933004d1fa40e3167c /sandbox
parent4129c0b8e0d333e1e3b1ccd29b59e118dfc1bc63 (diff)
downloadrobolectric-1ef305844cee51479bc27d56f129589cec0831fb.tar.gz
Intercept Cipher#getCurrentSpi to avoid running error
Diffstat (limited to 'sandbox')
-rw-r--r--sandbox/src/main/java/org/robolectric/interceptors/AndroidInterceptors.java32
1 files changed, 32 insertions, 0 deletions
diff --git a/sandbox/src/main/java/org/robolectric/interceptors/AndroidInterceptors.java b/sandbox/src/main/java/org/robolectric/interceptors/AndroidInterceptors.java
index 219b8fcf6..842107f17 100644
--- a/sandbox/src/main/java/org/robolectric/interceptors/AndroidInterceptors.java
+++ b/sandbox/src/main/java/org/robolectric/interceptors/AndroidInterceptors.java
@@ -24,6 +24,8 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import javax.annotation.Nullable;
+import javax.crypto.Cipher;
+import javax.crypto.CipherSpi;
import org.robolectric.fakes.CleanerCompat;
import org.robolectric.internal.bytecode.Interceptor;
import org.robolectric.internal.bytecode.MethodRef;
@@ -46,6 +48,7 @@ public class AndroidInterceptors {
new FileDescriptorInterceptor(),
new NoOpInterceptor(),
new SocketInterceptor(),
+ new CipherInterceptor(),
new ReferenceRefersToInterceptor()));
if (Util.getJavaVersion() >= 9) {
@@ -465,6 +468,35 @@ public class AndroidInterceptors {
}
}
+ /** Intercepts calls to methods in {@link javax.crypto.Cipher} not present in the OpenJDK. */
+ public static class CipherInterceptor extends Interceptor {
+ public CipherInterceptor() {
+ super(new MethodRef(Cipher.class, "getCurrentSpi"));
+ }
+
+ @Nullable
+ static CipherSpi getCurrentSpi() {
+ return null;
+ }
+
+ @Override
+ public Function<Object, Object> handle(MethodSignature methodSignature) {
+ return new Function<Object, Object>() {
+ @Override
+ public Object call(Class<?> theClass, Object value, Object[] params) {
+ return getCurrentSpi();
+ }
+ };
+ }
+
+ @Override
+ public MethodHandle getMethodHandle(String methodName, MethodType type)
+ throws NoSuchMethodException, IllegalAccessException {
+ return lookup.findStatic(
+ getClass(), "getCurrentSpi", methodType(CipherSpi.class, void.class));
+ }
+ }
+
/** AndroidInterceptor for Reference.refersTo which is not available until JDK 16. */
public static class ReferenceRefersToInterceptor extends Interceptor {
private static final String METHOD = "refersTo";