blob: bd17751f183e3276fbfb6a1692da4046bdb28e1c [file] [log] [blame]
Robert Carr8a2f9132019-11-11 15:03:15 -08001/*
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
17package com.android.test.taskembed;
18
Robert Carr00c0dbe2020-01-24 15:30:24 -080019import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
20
Robert Carr8a2f9132019-11-11 15:03:15 -080021import android.app.ActivityManager;
22import android.app.ActivityTaskManager;
23import android.app.Service;
Robert Carr8a2f9132019-11-11 15:03:15 -080024import android.content.Intent;
25import android.graphics.Rect;
26import android.os.IBinder;
27import android.view.ITaskOrganizer;
28import android.view.IWindowContainer;
Robert Carr8a2f9132019-11-11 15:03:15 -080029import android.view.SurfaceControl;
Robert Carr8a2f9132019-11-11 15:03:15 -080030import android.view.ViewGroup;
Evan Rosky0037e5f2019-11-05 10:26:24 -080031import android.view.WindowContainerTransaction;
Robert Carr8a2f9132019-11-11 15:03:15 -080032import android.view.WindowManager;
33import android.widget.FrameLayout;
34
35public class TaskOrganizerPipTest extends Service {
36 static final int PIP_WIDTH = 640;
37 static final int PIP_HEIGHT = 360;
38
Robert Carr00c0dbe2020-01-24 15:30:24 -080039 TaskView mTaskView;
Robert Carr8a2f9132019-11-11 15:03:15 -080040
41 class Organizer extends ITaskOrganizer.Stub {
Evan Rosky0037e5f2019-11-05 10:26:24 -080042 public void taskAppeared(ActivityManager.RunningTaskInfo ti) {
43 mTaskView.reparentTask(ti.token);
Robert Carr8a2f9132019-11-11 15:03:15 -080044
45 final WindowContainerTransaction wct = new WindowContainerTransaction();
Evan Rosky0037e5f2019-11-05 10:26:24 -080046 wct.scheduleFinishEnterPip(ti.token, new Rect(0, 0, PIP_WIDTH, PIP_HEIGHT));
Robert Carr8a2f9132019-11-11 15:03:15 -080047 try {
Robert Carre10ee3d2019-11-11 15:03:15 -080048 ActivityTaskManager.getTaskOrganizerController().applyContainerTransaction(wct, null);
Robert Carr8a2f9132019-11-11 15:03:15 -080049 } catch (Exception e) {
50 }
51 }
52 public void taskVanished(IWindowContainer wc) {
53 }
54 public void transactionReady(int id, SurfaceControl.Transaction t) {
55 }
Evan Rosky0037e5f2019-11-05 10:26:24 -080056 public void onTaskInfoChanged(ActivityManager.RunningTaskInfo info) {
57 }
Robert Carr8a2f9132019-11-11 15:03:15 -080058 }
59
60 Organizer mOrganizer = new Organizer();
61
62 @Override
63 public IBinder onBind(Intent intent) {
64 return null;
65 }
66
67 @Override
68 public void onCreate() {
69 super.onCreate();
70
Robert Carr02524d02020-02-06 13:57:18 -080071 try {
72 ActivityTaskManager.getTaskOrganizerController().registerTaskOrganizer(mOrganizer,
73 WINDOWING_MODE_PINNED);
74
75 } catch (Exception e) {
76 }
77
Robert Carr8a2f9132019-11-11 15:03:15 -080078 final WindowManager.LayoutParams wlp = new WindowManager.LayoutParams();
79 wlp.setTitle("TaskOrganizerPipTest");
80 wlp.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
81 wlp.width = wlp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
82
83 FrameLayout layout = new FrameLayout(this);
84 ViewGroup.LayoutParams lp =
85 new ViewGroup.LayoutParams(PIP_WIDTH, PIP_HEIGHT);
Robert Carr00c0dbe2020-01-24 15:30:24 -080086 mTaskView = new TaskView(this, mOrganizer, WINDOWING_MODE_PINNED);
87 layout.addView(mTaskView, lp);
Robert Carr8a2f9132019-11-11 15:03:15 -080088
89 WindowManager wm = getSystemService(WindowManager.class);
90 wm.addView(layout, wlp);
91 }
92
93 @Override
94 public void onDestroy() {
95 super.onDestroy();
96 }
97}