Winson Chung | 5589333 | 2017-02-17 17:13:10 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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.server.am; |
| 18 | |
| 19 | import android.app.RemoteAction; |
| 20 | import android.graphics.Rect; |
| 21 | |
| 22 | import com.android.server.am.ActivityStackSupervisor.ActivityContainer; |
| 23 | import com.android.server.wm.PinnedStackWindowController; |
Winson Chung | 3a68287 | 2017-04-10 14:38:05 -0700 | [diff] [blame] | 24 | import com.android.server.wm.PinnedStackWindowListener; |
Winson Chung | 5589333 | 2017-02-17 17:13:10 -0800 | [diff] [blame] | 25 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 26 | import java.util.ArrayList; |
Winson Chung | 5589333 | 2017-02-17 17:13:10 -0800 | [diff] [blame] | 27 | import java.util.List; |
| 28 | |
| 29 | /** |
| 30 | * State and management of the pinned stack of activities. |
| 31 | */ |
Winson Chung | 3a68287 | 2017-04-10 14:38:05 -0700 | [diff] [blame] | 32 | class PinnedActivityStack extends ActivityStack<PinnedStackWindowController> |
| 33 | implements PinnedStackWindowListener { |
Winson Chung | 5589333 | 2017-02-17 17:13:10 -0800 | [diff] [blame] | 34 | |
| 35 | PinnedActivityStack(ActivityContainer activityContainer, |
| 36 | RecentTasks recentTasks, boolean onTop) { |
| 37 | super(activityContainer, recentTasks, onTop); |
| 38 | } |
| 39 | |
| 40 | @Override |
| 41 | PinnedStackWindowController createStackWindowController(int displayId, boolean onTop, |
| 42 | Rect outBounds) { |
| 43 | return new PinnedStackWindowController(mStackId, this, displayId, onTop, outBounds); |
| 44 | } |
| 45 | |
Winson Chung | 9c84441 | 2017-04-27 17:36:41 -0700 | [diff] [blame^] | 46 | Rect getPictureInPictureBounds(float aspectRatio, boolean useExistingStackBounds) { |
| 47 | return getWindowContainerController().getPictureInPictureBounds(aspectRatio, |
| 48 | useExistingStackBounds); |
| 49 | } |
| 50 | |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 51 | void animateResizePinnedStack(Rect sourceHintBounds, Rect toBounds, int animationDuration, |
| 52 | boolean schedulePipModeChangedOnAnimationEnd) { |
| 53 | getWindowContainerController().animateResizePinnedStack(toBounds, sourceHintBounds, |
| 54 | animationDuration, schedulePipModeChangedOnAnimationEnd); |
Winson Chung | 5589333 | 2017-02-17 17:13:10 -0800 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | void setPictureInPictureAspectRatio(float aspectRatio) { |
| 58 | getWindowContainerController().setPictureInPictureAspectRatio(aspectRatio); |
| 59 | } |
| 60 | |
| 61 | void setPictureInPictureActions(List<RemoteAction> actions) { |
| 62 | getWindowContainerController().setPictureInPictureActions(actions); |
| 63 | } |
Winson Chung | 02e7193 | 2017-03-10 10:08:17 -0800 | [diff] [blame] | 64 | |
Winson Chung | 40a5f93 | 2017-04-13 16:39:36 -0700 | [diff] [blame] | 65 | boolean isAnimatingBoundsToFullscreen() { |
| 66 | return getWindowContainerController().isAnimatingBoundsToFullscreen(); |
Winson Chung | 02e7193 | 2017-03-10 10:08:17 -0800 | [diff] [blame] | 67 | } |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 68 | |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 69 | /** |
| 70 | * Returns whether to defer the scheduling of the multi-window mode. |
| 71 | */ |
| 72 | boolean deferScheduleMultiWindowModeChanged() { |
| 73 | // For the pinned stack, the deferring of the multi-window mode changed is tied to the |
| 74 | // transition animation into picture-in-picture, and is called once the animation completes, |
| 75 | // or is interrupted in a way that would leave the stack in a non-fullscreen state. |
| 76 | // @see BoundsAnimationController |
| 77 | // @see BoundsAnimationControllerTests |
| 78 | return mWindowContainerController.deferScheduleMultiWindowModeChanged(); |
| 79 | } |
| 80 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 81 | public void updatePictureInPictureModeForPinnedStackAnimation(Rect targetStackBounds) { |
| 82 | // It is guaranteed that the activities requiring the update will be in the pinned stack at |
| 83 | // this point (either reparented before the animation into PiP, or before reparenting after |
| 84 | // the animation out of PiP) |
| 85 | synchronized(this) { |
| 86 | ArrayList<TaskRecord> tasks = getAllTasks(); |
| 87 | for (int i = 0; i < tasks.size(); i++ ) { |
| 88 | mStackSupervisor.scheduleUpdatePictureInPictureModeIfNeeded(tasks.get(i), |
| 89 | targetStackBounds, true /* immediate */); |
| 90 | } |
| 91 | } |
| 92 | } |
Winson Chung | 5589333 | 2017-02-17 17:13:10 -0800 | [diff] [blame] | 93 | } |