1 /* 2 * Copyright (C) 2023 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.view.surfacecontrol.cts; 18 19 import static org.junit.Assert.assertTrue; 20 21 import android.app.Activity; 22 import android.app.KeyguardManager; 23 import android.os.Bundle; 24 import android.util.Log; 25 import android.util.Pair; 26 import android.util.Size; 27 import android.view.Gravity; 28 import android.view.SurfaceControlViewHost; 29 import android.view.View; 30 import android.view.ViewGroup; 31 import android.view.cts.util.SurfaceControlViewHostHelper; 32 import android.view.cts.util.aidl.IAttachEmbeddedWindow; 33 import android.widget.FrameLayout; 34 35 import androidx.annotation.Nullable; 36 37 import java.util.concurrent.CountDownLatch; 38 import java.util.concurrent.TimeUnit; 39 40 public class SurfaceSyncGroupActivity extends Activity { 41 private static final String TAG = "SurfaceSyncGroupActivity"; 42 private SurfaceControlViewHostHelper mSurfaceControlViewHostHelper; 43 private final CountDownLatch mCountDownLatch = new CountDownLatch(1); 44 45 private ViewGroup mParentView; 46 private static final Size sSize = new Size(500, 500); 47 48 @Override onCreate(@ullable Bundle savedInstanceState)49 public void onCreate(@Nullable Bundle savedInstanceState) { 50 super.onCreate(savedInstanceState); 51 52 mSurfaceControlViewHostHelper = new SurfaceControlViewHostHelper(TAG, 53 mCountDownLatch, 54 this, 0, sSize); 55 56 mParentView = new FrameLayout(this); 57 setContentView(mParentView); 58 59 KeyguardManager km = getSystemService(KeyguardManager.class); 60 km.requestDismissKeyguard(this, null); 61 } 62 setupEmbeddedSCVH()63 public Pair<SurfaceControlViewHost.SurfacePackage, IAttachEmbeddedWindow> setupEmbeddedSCVH() { 64 FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(sSize.getWidth(), 65 sSize.getHeight()); 66 layoutParams.gravity = Gravity.CENTER; 67 runOnUiThread(() -> mSurfaceControlViewHostHelper.attachSurfaceView(mParentView, 68 layoutParams)); 69 mSurfaceControlViewHostHelper.bindEmbeddedService(false /* inProcess */); 70 71 boolean ready = false; 72 try { 73 ready = mCountDownLatch.await(5, TimeUnit.SECONDS); 74 } catch (InterruptedException e) { 75 Log.e(TAG, "Failed to wait for SCVH to attach"); 76 } 77 78 assertTrue("Failed to attach SCVH", ready); 79 80 return new Pair<>(mSurfaceControlViewHostHelper.getSurfacePackage(), 81 mSurfaceControlViewHostHelper.getAttachedEmbeddedWindow()); 82 } 83 getBackgroundView()84 public View getBackgroundView() { 85 return mParentView; 86 } 87 } 88