blob: 27269791f568302ec82573d820b5dc1adbc2d169 [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
Wale Ogunwale04a05ac2017-09-17 21:35:02 -070019import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
20import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
21
Winson Chung55893332017-02-17 17:13:10 -080022import android.app.RemoteAction;
Wale Ogunwale42f07d92017-05-01 21:32:58 -070023import android.content.res.Configuration;
Winson Chung55893332017-02-17 17:13:10 -080024import android.graphics.Rect;
25
Winson Chung55893332017-02-17 17:13:10 -080026import com.android.server.wm.PinnedStackWindowController;
Winson Chung3a682872017-04-10 14:38:05 -070027import com.android.server.wm.PinnedStackWindowListener;
Winson Chung55893332017-02-17 17:13:10 -080028
Winson Chung5af42fc2017-03-24 17:11:33 -070029import java.util.ArrayList;
Winson Chung55893332017-02-17 17:13:10 -080030import java.util.List;
31
32/**
33 * State and management of the pinned stack of activities.
34 */
Winson Chung3a682872017-04-10 14:38:05 -070035class PinnedActivityStack extends ActivityStack<PinnedStackWindowController>
36 implements PinnedStackWindowListener {
Winson Chung55893332017-02-17 17:13:10 -080037
Wale Ogunwale9dcf9462017-09-19 15:13:01 -070038 PinnedActivityStack(ActivityDisplay display, int stackId, ActivityStackSupervisor supervisor,
39 boolean onTop) {
Wale Ogunwale04a05ac2017-09-17 21:35:02 -070040 super(display, stackId, supervisor, WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD, onTop);
Winson Chung55893332017-02-17 17:13:10 -080041 }
42
43 @Override
44 PinnedStackWindowController createStackWindowController(int displayId, boolean onTop,
Wale Ogunwale034a8ec2017-09-02 17:14:40 -070045 Rect outBounds) {
Bryce Lee4e4a3ec2017-09-27 08:25:03 -070046 return new PinnedStackWindowController(mStackId, this, displayId, onTop, outBounds,
47 mStackSupervisor.mWindowManager);
Winson Chung55893332017-02-17 17:13:10 -080048 }
49
Winson Chunga71febe2017-05-22 11:14:22 -070050 Rect getDefaultPictureInPictureBounds(float aspectRatio) {
Winson Chung9c844412017-04-27 17:36:41 -070051 return getWindowContainerController().getPictureInPictureBounds(aspectRatio,
Winson Chunga71febe2017-05-22 11:14:22 -070052 null /* currentStackBounds */);
Winson Chung9c844412017-04-27 17:36:41 -070053 }
54
Winson Chung8bca9e42017-04-16 15:59:43 -070055 void animateResizePinnedStack(Rect sourceHintBounds, Rect toBounds, int animationDuration,
Winson Chunge7ba6862017-05-24 12:13:33 -070056 boolean fromFullscreen) {
Wale Ogunwale42f07d92017-05-01 21:32:58 -070057 if (skipResizeAnimation(toBounds == null /* toFullscreen */)) {
58 mService.moveTasksToFullscreenStack(mStackId, true /* onTop */);
59 } else {
60 getWindowContainerController().animateResizePinnedStack(toBounds, sourceHintBounds,
Winson Chunge7ba6862017-05-24 12:13:33 -070061 animationDuration, fromFullscreen);
Wale Ogunwale42f07d92017-05-01 21:32:58 -070062 }
63 }
64
65 private boolean skipResizeAnimation(boolean toFullscreen) {
66 if (!toFullscreen) {
67 return false;
68 }
69 final Configuration parentConfig = getParent().getConfiguration();
70 final ActivityRecord top = topRunningNonOverlayTaskActivity();
71 return top != null && !top.isConfigurationCompatible(parentConfig);
Winson Chung55893332017-02-17 17:13:10 -080072 }
73
74 void setPictureInPictureAspectRatio(float aspectRatio) {
75 getWindowContainerController().setPictureInPictureAspectRatio(aspectRatio);
76 }
77
78 void setPictureInPictureActions(List<RemoteAction> actions) {
79 getWindowContainerController().setPictureInPictureActions(actions);
80 }
Winson Chung02e71932017-03-10 10:08:17 -080081
Winson Chung40a5f932017-04-13 16:39:36 -070082 boolean isAnimatingBoundsToFullscreen() {
83 return getWindowContainerController().isAnimatingBoundsToFullscreen();
Winson Chung02e71932017-03-10 10:08:17 -080084 }
Winson Chung5af42fc2017-03-24 17:11:33 -070085
Winson Chung8bca9e42017-04-16 15:59:43 -070086 /**
87 * Returns whether to defer the scheduling of the multi-window mode.
88 */
89 boolean deferScheduleMultiWindowModeChanged() {
90 // For the pinned stack, the deferring of the multi-window mode changed is tied to the
91 // transition animation into picture-in-picture, and is called once the animation completes,
92 // or is interrupted in a way that would leave the stack in a non-fullscreen state.
93 // @see BoundsAnimationController
94 // @see BoundsAnimationControllerTests
95 return mWindowContainerController.deferScheduleMultiWindowModeChanged();
96 }
97
Winson Chungab76bbc2017-08-14 13:33:51 -070098 public void updatePictureInPictureModeForPinnedStackAnimation(Rect targetStackBounds,
99 boolean forceUpdate) {
Winson Chung5af42fc2017-03-24 17:11:33 -0700100 // It is guaranteed that the activities requiring the update will be in the pinned stack at
101 // this point (either reparented before the animation into PiP, or before reparenting after
102 // the animation out of PiP)
103 synchronized(this) {
104 ArrayList<TaskRecord> tasks = getAllTasks();
105 for (int i = 0; i < tasks.size(); i++ ) {
Winson Chungab76bbc2017-08-14 13:33:51 -0700106 mStackSupervisor.updatePictureInPictureMode(tasks.get(i), targetStackBounds,
107 forceUpdate);
Winson Chung5af42fc2017-03-24 17:11:33 -0700108 }
109 }
110 }
Winson Chung55893332017-02-17 17:13:10 -0800111}