From 5e107d8bd937adc44c2bfaa10eab4ea4b9cb866c Mon Sep 17 00:00:00 2001 From: Anton Kulakov Date: Mon, 18 Mar 2024 17:07:05 +0000 Subject: [PATCH] Replace NoOp implementation with NoOp proxy in SdkLoaderTest To reduce amount of changes required for new API support. This test doesn't call any methods of NoOp implementation. Test: SdkLoaderTest Bug: 327315108 Change-Id: Ic7875cc9750688115a556504eecbb66da39ca8df --- .../sdkruntime/client/loader/SdkLoaderTest.kt | 55 ++++--------------- 1 file changed, 11 insertions(+), 44 deletions(-) diff --git a/privacysandbox/sdkruntime/sdkruntime-client/src/androidTest/java/androidx/privacysandbox/sdkruntime/client/loader/SdkLoaderTest.kt b/privacysandbox/sdkruntime/sdkruntime-client/src/androidTest/java/androidx/privacysandbox/sdkruntime/client/loader/SdkLoaderTest.kt index 83c3fbe727968..112d751b21bc6 100644 --- a/privacysandbox/sdkruntime/sdkruntime-client/src/androidTest/java/androidx/privacysandbox/sdkruntime/client/loader/SdkLoaderTest.kt +++ b/privacysandbox/sdkruntime/sdkruntime-client/src/androidTest/java/androidx/privacysandbox/sdkruntime/client/loader/SdkLoaderTest.kt @@ -17,16 +17,10 @@ package androidx.privacysandbox.sdkruntime.client.loader import android.content.Context import android.os.Build -import android.os.Bundle -import android.os.IBinder import androidx.privacysandbox.sdkruntime.client.TestSdkConfigs import androidx.privacysandbox.sdkruntime.client.config.LocalSdkConfig -import androidx.privacysandbox.sdkruntime.core.AppOwnedSdkSandboxInterfaceCompat import androidx.privacysandbox.sdkruntime.core.LoadSdkCompatException -import androidx.privacysandbox.sdkruntime.core.SandboxedSdkCompat import androidx.privacysandbox.sdkruntime.core.Versions -import androidx.privacysandbox.sdkruntime.core.activity.SdkSandboxActivityHandlerCompat -import androidx.privacysandbox.sdkruntime.core.controller.LoadSdkCallback import androidx.privacysandbox.sdkruntime.core.controller.SdkSandboxControllerCompat import androidx.test.core.app.ApplicationProvider import androidx.test.ext.junit.runners.AndroidJUnit4 @@ -35,7 +29,7 @@ import androidx.test.filters.SmallTest import androidx.testutils.assertThrows import com.google.common.truth.Truth.assertThat import java.io.File -import java.util.concurrent.Executor +import java.lang.reflect.Proxy import org.junit.Before import org.junit.Test import org.junit.runner.RunWith @@ -157,45 +151,18 @@ class SdkLoaderTest { } private object NoOpFactory : SdkLoader.ControllerFactory { - override fun createControllerFor(sdkConfig: LocalSdkConfig) = NoOpImpl() - } - - private class NoOpImpl : SdkSandboxControllerCompat.SandboxControllerImpl { - - override fun loadSdk( - sdkName: String, - params: Bundle, - executor: Executor, - callback: LoadSdkCallback - ) { - executor.execute { - callback.onError( - LoadSdkCompatException( - LoadSdkCompatException.LOAD_SDK_INTERNAL_ERROR, - "NoOp" - ) - ) - } - } - - override fun getSandboxedSdks(): List { - throw UnsupportedOperationException("NoOp") - } - override fun getAppOwnedSdkSandboxInterfaces(): List { - throw UnsupportedOperationException("NoOp") - } + val controllerImplClass = SdkSandboxControllerCompat.SandboxControllerImpl::class.java - override fun registerSdkSandboxActivityHandler( - handlerCompat: SdkSandboxActivityHandlerCompat - ): IBinder { - throw UnsupportedOperationException("NoOp") - } + val noOpProxy = Proxy.newProxyInstance( + controllerImplClass.classLoader, + arrayOf(controllerImplClass) + ) { proxy, method, args -> + throw UnsupportedOperationException( + "Unexpected method call (NoOp) object:$proxy, method: $method, args: $args" + ) + } as SdkSandboxControllerCompat.SandboxControllerImpl - override fun unregisterSdkSandboxActivityHandler( - handlerCompat: SdkSandboxActivityHandlerCompat - ) { - throw UnsupportedOperationException("NoOp") - } + override fun createControllerFor(sdkConfig: LocalSdkConfig) = noOpProxy } }