Skip to content

Commit

Permalink
Merge "Replace NoOp implementation with NoOp proxy in SdkLoaderTest" …
Browse files Browse the repository at this point in the history
…into androidx-main
  • Loading branch information
Anton Kulakov authored and Gerrit Code Review committed Mar 19, 2024
2 parents a004886 + 5e107d8 commit cd6f0b8
Showing 1 changed file with 11 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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<SandboxedSdkCompat> {
throw UnsupportedOperationException("NoOp")
}

override fun getAppOwnedSdkSandboxInterfaces(): List<AppOwnedSdkSandboxInterfaceCompat> {
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
}
}

0 comments on commit cd6f0b8

Please sign in to comment.