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; |
Wale Ogunwale | 42f07d9 | 2017-05-01 21:32:58 -0700 | [diff] [blame] | 20 | import android.content.res.Configuration; |
Winson Chung | 5589333 | 2017-02-17 17:13:10 -0800 | [diff] [blame] | 21 | import android.graphics.Rect; |
| 22 | |
Winson Chung | 5589333 | 2017-02-17 17:13:10 -0800 | [diff] [blame] | 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 | |
Andrii Kulian | b1cdb10 | 2017-07-13 15:33:06 -0700 | [diff] [blame] | 35 | PinnedActivityStack(ActivityStackSupervisor.ActivityDisplay display, int stackId, |
| 36 | ActivityStackSupervisor supervisor, RecentTasks recentTasks, boolean onTop) { |
| 37 | super(display, stackId, supervisor, recentTasks, onTop); |
Winson Chung | 5589333 | 2017-02-17 17:13:10 -0800 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | @Override |
| 41 | PinnedStackWindowController createStackWindowController(int displayId, boolean onTop, |
Wale Ogunwale | f75962a | 2017-08-23 14:58:04 -0700 | [diff] [blame^] | 42 | Rect outBounds, Configuration overrideConfig) { |
Wale Ogunwale | 687b427 | 2017-07-27 02:56:23 -0700 | [diff] [blame] | 43 | return new PinnedStackWindowController(mStackId, this, displayId, onTop, outBounds, |
Wale Ogunwale | f75962a | 2017-08-23 14:58:04 -0700 | [diff] [blame^] | 44 | overrideConfig); |
Winson Chung | 5589333 | 2017-02-17 17:13:10 -0800 | [diff] [blame] | 45 | } |
| 46 | |
Winson Chung | a71febe | 2017-05-22 11:14:22 -0700 | [diff] [blame] | 47 | Rect getDefaultPictureInPictureBounds(float aspectRatio) { |
Winson Chung | 9c84441 | 2017-04-27 17:36:41 -0700 | [diff] [blame] | 48 | return getWindowContainerController().getPictureInPictureBounds(aspectRatio, |
Winson Chung | a71febe | 2017-05-22 11:14:22 -0700 | [diff] [blame] | 49 | null /* currentStackBounds */); |
Winson Chung | 9c84441 | 2017-04-27 17:36:41 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 52 | void animateResizePinnedStack(Rect sourceHintBounds, Rect toBounds, int animationDuration, |
Winson Chung | e7ba686 | 2017-05-24 12:13:33 -0700 | [diff] [blame] | 53 | boolean fromFullscreen) { |
Wale Ogunwale | 42f07d9 | 2017-05-01 21:32:58 -0700 | [diff] [blame] | 54 | if (skipResizeAnimation(toBounds == null /* toFullscreen */)) { |
| 55 | mService.moveTasksToFullscreenStack(mStackId, true /* onTop */); |
| 56 | } else { |
| 57 | getWindowContainerController().animateResizePinnedStack(toBounds, sourceHintBounds, |
Winson Chung | e7ba686 | 2017-05-24 12:13:33 -0700 | [diff] [blame] | 58 | animationDuration, fromFullscreen); |
Wale Ogunwale | 42f07d9 | 2017-05-01 21:32:58 -0700 | [diff] [blame] | 59 | } |
| 60 | } |
| 61 | |
| 62 | private boolean skipResizeAnimation(boolean toFullscreen) { |
| 63 | if (!toFullscreen) { |
| 64 | return false; |
| 65 | } |
| 66 | final Configuration parentConfig = getParent().getConfiguration(); |
| 67 | final ActivityRecord top = topRunningNonOverlayTaskActivity(); |
| 68 | return top != null && !top.isConfigurationCompatible(parentConfig); |
Winson Chung | 5589333 | 2017-02-17 17:13:10 -0800 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | void setPictureInPictureAspectRatio(float aspectRatio) { |
| 72 | getWindowContainerController().setPictureInPictureAspectRatio(aspectRatio); |
| 73 | } |
| 74 | |
| 75 | void setPictureInPictureActions(List<RemoteAction> actions) { |
| 76 | getWindowContainerController().setPictureInPictureActions(actions); |
| 77 | } |
Winson Chung | 02e7193 | 2017-03-10 10:08:17 -0800 | [diff] [blame] | 78 | |
Winson Chung | 40a5f93 | 2017-04-13 16:39:36 -0700 | [diff] [blame] | 79 | boolean isAnimatingBoundsToFullscreen() { |
| 80 | return getWindowContainerController().isAnimatingBoundsToFullscreen(); |
Winson Chung | 02e7193 | 2017-03-10 10:08:17 -0800 | [diff] [blame] | 81 | } |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 82 | |
Winson Chung | 8bca9e4 | 2017-04-16 15:59:43 -0700 | [diff] [blame] | 83 | /** |
| 84 | * Returns whether to defer the scheduling of the multi-window mode. |
| 85 | */ |
| 86 | boolean deferScheduleMultiWindowModeChanged() { |
| 87 | // For the pinned stack, the deferring of the multi-window mode changed is tied to the |
| 88 | // transition animation into picture-in-picture, and is called once the animation completes, |
| 89 | // or is interrupted in a way that would leave the stack in a non-fullscreen state. |
| 90 | // @see BoundsAnimationController |
| 91 | // @see BoundsAnimationControllerTests |
| 92 | return mWindowContainerController.deferScheduleMultiWindowModeChanged(); |
| 93 | } |
| 94 | |
Winson Chung | 5af42fc | 2017-03-24 17:11:33 -0700 | [diff] [blame] | 95 | public void updatePictureInPictureModeForPinnedStackAnimation(Rect targetStackBounds) { |
| 96 | // It is guaranteed that the activities requiring the update will be in the pinned stack at |
| 97 | // this point (either reparented before the animation into PiP, or before reparenting after |
| 98 | // the animation out of PiP) |
| 99 | synchronized(this) { |
| 100 | ArrayList<TaskRecord> tasks = getAllTasks(); |
| 101 | for (int i = 0; i < tasks.size(); i++ ) { |
| 102 | mStackSupervisor.scheduleUpdatePictureInPictureModeIfNeeded(tasks.get(i), |
| 103 | targetStackBounds, true /* immediate */); |
| 104 | } |
| 105 | } |
| 106 | } |
Winson Chung | 5589333 | 2017-02-17 17:13:10 -0800 | [diff] [blame] | 107 | } |