1 /* 2 * Copyright (C) 2019 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.test.taskembed; 18 19 import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; 20 21 import android.app.ActivityManager; 22 import android.app.Service; 23 import android.content.Intent; 24 import android.graphics.Rect; 25 import android.os.IBinder; 26 import android.view.SurfaceControl; 27 import android.view.ViewGroup; 28 import android.view.WindowManager; 29 import android.widget.FrameLayout; 30 import android.window.TaskOrganizer; 31 import android.window.WindowContainerTransaction; 32 33 public class TaskOrganizerPipTest extends Service { 34 private static final int PIP_WIDTH = 640; 35 private static final int PIP_HEIGHT = 360; 36 37 private TaskView mTaskView; 38 39 class Organizer extends TaskOrganizer { onTaskAppeared(ActivityManager.RunningTaskInfo ti, SurfaceControl leash)40 public void onTaskAppeared(ActivityManager.RunningTaskInfo ti, SurfaceControl leash) { 41 mTaskView.reparentTask(ti.token, leash); 42 43 final WindowContainerTransaction wct = new WindowContainerTransaction(); 44 wct.scheduleFinishEnterPip(ti.token, new Rect(0, 0, PIP_WIDTH, PIP_HEIGHT)); 45 applyTransaction(wct); 46 } 47 } 48 49 private Organizer mOrganizer = new Organizer(); 50 51 @Override onBind(Intent intent)52 public IBinder onBind(Intent intent) { 53 return null; 54 } 55 56 @Override onCreate()57 public void onCreate() { 58 super.onCreate(); 59 60 mOrganizer.registerOrganizer(WINDOWING_MODE_PINNED); 61 62 final WindowManager.LayoutParams wlp = new WindowManager.LayoutParams(); 63 wlp.setTitle("TaskOrganizerPipTest"); 64 wlp.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; 65 wlp.width = wlp.height = ViewGroup.LayoutParams.WRAP_CONTENT; 66 67 FrameLayout layout = new FrameLayout(this); 68 ViewGroup.LayoutParams lp = 69 new ViewGroup.LayoutParams(PIP_WIDTH, PIP_HEIGHT); 70 mTaskView = new TaskView(this); 71 layout.addView(mTaskView, lp); 72 73 WindowManager wm = getSystemService(WindowManager.class); 74 wm.addView(layout, wlp); 75 } 76 77 @Override onDestroy()78 public void onDestroy() { 79 super.onDestroy(); 80 mOrganizer.unregisterOrganizer(); 81 } 82 } 83