1 /*
2  * Copyright (C) 2022 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 android.app.sdksandbox.sdkprovider;
18 
19 import android.annotation.NonNull;
20 import android.app.Activity;
21 import android.os.Build;
22 import android.os.Bundle;
23 import android.os.IBinder;
24 import android.view.View;
25 
26 import androidx.annotation.RequiresApi;
27 
28 /**
29  * This is used to notify the SDK when an {@link Activity} is created for it.
30  *
31  * <p>When an SDK wants to start an {@link Activity}, it should register an implementation of this
32  * class by calling {@link
33  * SdkSandboxController#registerSdkSandboxActivityHandler(SdkSandboxActivityHandler)} that will
34  * return an {@link android.os.IBinder} identifier for the registered {@link
35  * SdkSandboxActivityHandler} to The SDK.
36  *
37  * <p>The SDK should be notified about the {@link Activity} creation by calling {@link
38  * SdkSandboxActivityHandler#onActivityCreated(Activity)} which happens when the caller app calls
39  * {@link android.app.sdksandbox.SdkSandboxManager#startSdkSandboxActivity(Activity, IBinder)} using
40  * the same {@link IBinder} identifier for the registered {@link SdkSandboxActivityHandler}.
41  */
42 @RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
43 public interface SdkSandboxActivityHandler {
44     /**
45      * Notifies SDK when an {@link Activity} gets created.
46      *
47      * <p>This function is called synchronously from the main thread of the {@link Activity} that is
48      * getting created.
49      *
50      * <p>SDK is expected to call {@link Activity#setContentView(View)} to the passed {@link
51      * Activity} object to populate the view.
52      *
53      * <p>If SDK registers lifecycle callbacks over the passed {@link Activity} object using {@link
54      * Activity#registerActivityLifecycleCallbacks(
55      * android.app.Application.ActivityLifecycleCallbacks)}, it is important to note that {@link
56      * android.app.Application.ActivityLifecycleCallbacks#onActivityPreCreated(Activity, Bundle)}
57      * and {@link android.app.Application.ActivityLifecycleCallbacks#onActivityCreated(Activity,
58      * Bundle)} will not be triggered as {@link #onActivityCreated(Activity)} is called at the
59      * {@link Activity} creation stage. Then to know about the Activity state, SDKs should override
60      * {@link android.app.Application.ActivityLifecycleCallbacks#onActivityPostCreated(Activity,
61      * Bundle)}.
62      *
63      * @param activity the {@link Activity} gets created
64      */
onActivityCreated(@onNull Activity activity)65     void onActivityCreated(@NonNull Activity activity);
66 }
67