1 /* 2 * Copyright 2025 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package androidx.privacysandbox.ui.core 18 19 import android.annotation.SuppressLint 20 import java.util.concurrent.Executor 21 22 /** 23 * An adapter that provides a communication channel between a UI provider and a client app, while 24 * the client is displaying shared UI, i.e. UI that can contain both client-owned and provider-owned 25 * elements. 26 */ 27 @SuppressLint("NullAnnotationGroup") 28 @ExperimentalFeatures.SharedUiPresentationApi 29 interface SharedUiAdapter { 30 31 /** 32 * Opens a new session to maintain connection with a UI provider. [client] will receive all 33 * incoming communication from the provider. All incoming calls to [client] will be made through 34 * the provided [clientExecutor]. 35 */ openSessionnull36 fun openSession(clientExecutor: Executor, client: SessionClient) 37 38 /** A single session with the UI provider. */ 39 interface Session : AutoCloseable { 40 /** 41 * Closes this session, indicating that the remote provider should dispose of associated 42 * resources and that the [SessionClient] should not receive further callback events. 43 */ 44 override fun close() 45 } 46 47 /** The client of a single session that will receive callback events from an active session. */ 48 interface SessionClient { 49 /** 50 * Called to report that the session was opened successfully, delivering the [Session] 51 * handle that should be used to communicate with the provider. 52 */ onSessionOpenednull53 fun onSessionOpened(session: Session) 54 55 /** 56 * Called to report a terminal error in the session. No further events will be reported to 57 * this [SessionClient] and any further or currently pending calls to the [Session] that may 58 * have been in flight may be ignored. 59 */ 60 fun onSessionError(throwable: Throwable) 61 } 62 } 63