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