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 com.android.ctssdkprovider;
18 
19 import android.app.sdksandbox.LoadSdkException;
20 import android.app.sdksandbox.SandboxedSdk;
21 import android.app.sdksandbox.SandboxedSdkProvider;
22 import android.content.Context;
23 import android.os.Bundle;
24 import android.text.TextUtils;
25 import android.view.View;
26 
27 public class SdkProvider extends SandboxedSdkProvider {
28 
29     private static final String TEST_OPTION = "test-option";
30     private static final String OPTION_THROW_INTERNAL_ERROR = "internal-error";
31     private static final String OPTION_THROW_REQUEST_SURFACE_PACKAGE_ERROR = "rsp-error";
32 
33     @Override
onLoadSdk(Bundle params)34     public SandboxedSdk onLoadSdk(Bundle params) throws LoadSdkException {
35 
36         String testOption = params.getString(TEST_OPTION);
37         if (TextUtils.equals(testOption, OPTION_THROW_INTERNAL_ERROR)) {
38             throw new RuntimeException("General Exception");
39         }
40         return new SandboxedSdk(new CtsSdkProviderApiImpl(getContext()));
41     }
42 
43     @Override
getView(Context windowContext, Bundle params, int width, int height)44     public View getView(Context windowContext, Bundle params, int width, int height) {
45         String testOption = params.getString(TEST_OPTION);
46         if (TextUtils.equals(testOption, OPTION_THROW_REQUEST_SURFACE_PACKAGE_ERROR)) {
47             throw new RuntimeException("General Exception");
48         }
49         return new View(windowContext);
50     }
51 }
52