blob: 34cdb54d0b76b2832947f8c74b5822ce943fa701 [file] [log] [blame]
Winson Chung55893332017-02-17 17:13:10 -08001/*
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
17package com.android.server.am;
18
19import android.app.RemoteAction;
Wale Ogunwale42f07d92017-05-01 21:32:58 -070020import android.content.res.Configuration;
Winson Chung55893332017-02-17 17:13:10 -080021import android.graphics.Rect;
22
23import com.android.server.am.ActivityStackSupervisor.ActivityContainer;
24import com.android.server.wm.PinnedStackWindowController;
Winson Chung3a682872017-04-10 14:38:05 -070025import com.android.server.wm.PinnedStackWindowListener;
Winson Chung55893332017-02-17 17:13:10 -080026
Winson Chung5af42fc2017-03-24 17:11:33 -070027import java.util.ArrayList;
Winson Chung55893332017-02-17 17:13:10 -080028import java.util.List;
29
30/**
31 * State and management of the pinned stack of activities.
32 */
Winson Chung3a682872017-04-10 14:38:05 -070033class PinnedActivityStack extends ActivityStack<PinnedStackWindowController>
34 implements PinnedStackWindowListener {
Winson Chung55893332017-02-17 17:13:10 -080035
36 PinnedActivityStack(ActivityContainer activityContainer,
37 RecentTasks recentTasks, boolean onTop) {
38 super(activityContainer, recentTasks, onTop);
39 }
40
41 @Override
42 PinnedStackWindowController createStackWindowController(int displayId, boolean onTop,
43 Rect outBounds) {
44 return new PinnedStackWindowController(mStackId, this, displayId, onTop, outBounds);
45 }
46
Winson Chung9c844412017-04-27 17:36:41 -070047 Rect getPictureInPictureBounds(float aspectRatio, boolean useExistingStackBounds) {
48 return getWindowContainerController().getPictureInPictureBounds(aspectRatio,
49 useExistingStackBounds);
50 }
51
Winson Chung8bca9e42017-04-16 15:59:43 -070052 void animateResizePinnedStack(Rect sourceHintBounds, Rect toBounds, int animationDuration,
53 boolean schedulePipModeChangedOnAnimationEnd) {
Wale Ogunwale42f07d92017-05-01 21:32:58 -070054 if (skipResizeAnimation(toBounds == null /* toFullscreen */)) {
55 mService.moveTasksToFullscreenStack(mStackId, true /* onTop */);
56 } else {
57 getWindowContainerController().animateResizePinnedStack(toBounds, sourceHintBounds,
58 animationDuration, schedulePipModeChangedOnAnimationEnd);
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 Chung55893332017-02-17 17:13:10 -080069 }
70
71 void setPictureInPictureAspectRatio(float aspectRatio) {
72 getWindowContainerController().setPictureInPictureAspectRatio(aspectRatio);
73 }
74
75 void setPictureInPictureActions(List<RemoteAction> actions) {
76 getWindowContainerController().setPictureInPictureActions(actions);
77 }
Winson Chung02e71932017-03-10 10:08:17 -080078
Winson Chung40a5f932017-04-13 16:39:36 -070079 boolean isAnimatingBoundsToFullscreen() {
80 return getWindowContainerController().isAnimatingBoundsToFullscreen();
Winson Chung02e71932017-03-10 10:08:17 -080081 }
Winson Chung5af42fc2017-03-24 17:11:33 -070082
Winson Chung8bca9e42017-04-16 15:59:43 -070083 /**
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 Chung5af42fc2017-03-24 17:11:33 -070095 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 Chung55893332017-02-17 17:13:10 -0800107}