Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 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 | |
Robert Carr | 00c0dbe | 2020-01-24 15:30:24 -0800 | [diff] [blame] | 19 | import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; |
| 20 | |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 21 | import android.app.ActivityManager; |
| 22 | import android.app.ActivityTaskManager; |
| 23 | import android.app.Service; |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 24 | import android.content.Intent; |
| 25 | import android.graphics.Rect; |
| 26 | import android.os.IBinder; |
| 27 | import android.view.ITaskOrganizer; |
| 28 | import android.view.IWindowContainer; |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 29 | import android.view.SurfaceControl; |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 30 | import android.view.ViewGroup; |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 31 | import android.view.WindowContainerTransaction; |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 32 | import android.view.WindowManager; |
| 33 | import android.widget.FrameLayout; |
| 34 | |
| 35 | public class TaskOrganizerPipTest extends Service { |
| 36 | static final int PIP_WIDTH = 640; |
| 37 | static final int PIP_HEIGHT = 360; |
| 38 | |
Robert Carr | 00c0dbe | 2020-01-24 15:30:24 -0800 | [diff] [blame] | 39 | TaskView mTaskView; |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 40 | |
| 41 | class Organizer extends ITaskOrganizer.Stub { |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 42 | public void taskAppeared(ActivityManager.RunningTaskInfo ti) { |
| 43 | mTaskView.reparentTask(ti.token); |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 44 | |
| 45 | final WindowContainerTransaction wct = new WindowContainerTransaction(); |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 46 | wct.scheduleFinishEnterPip(ti.token, new Rect(0, 0, PIP_WIDTH, PIP_HEIGHT)); |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 47 | try { |
Robert Carr | e10ee3d | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 48 | ActivityTaskManager.getTaskOrganizerController().applyContainerTransaction(wct, null); |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 49 | } catch (Exception e) { |
| 50 | } |
| 51 | } |
| 52 | public void taskVanished(IWindowContainer wc) { |
| 53 | } |
| 54 | public void transactionReady(int id, SurfaceControl.Transaction t) { |
| 55 | } |
Evan Rosky | 0037e5f | 2019-11-05 10:26:24 -0800 | [diff] [blame] | 56 | public void onTaskInfoChanged(ActivityManager.RunningTaskInfo info) { |
| 57 | } |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 58 | } |
| 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 Carr | 02524d0 | 2020-02-06 13:57:18 -0800 | [diff] [blame] | 71 | try { |
| 72 | ActivityTaskManager.getTaskOrganizerController().registerTaskOrganizer(mOrganizer, |
| 73 | WINDOWING_MODE_PINNED); |
| 74 | |
| 75 | } catch (Exception e) { |
| 76 | } |
| 77 | |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 78 | 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 Carr | 00c0dbe | 2020-01-24 15:30:24 -0800 | [diff] [blame] | 86 | mTaskView = new TaskView(this, mOrganizer, WINDOWING_MODE_PINNED); |
| 87 | layout.addView(mTaskView, lp); |
Robert Carr | 8a2f913 | 2019-11-11 15:03:15 -0800 | [diff] [blame] | 88 | |
| 89 | WindowManager wm = getSystemService(WindowManager.class); |
| 90 | wm.addView(layout, wlp); |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public void onDestroy() { |
| 95 | super.onDestroy(); |
| 96 | } |
| 97 | } |