blob: a601ee1c0c89c8c2833e41d158956908a008dcf0 [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
Winson Chung55893332017-02-17 17:13:10 -080023import com.android.server.wm.PinnedStackWindowController;
Winson Chung3a682872017-04-10 14:38:05 -070024import com.android.server.wm.PinnedStackWindowListener;
Winson Chung55893332017-02-17 17:13:10 -080025
Winson Chung5af42fc2017-03-24 17:11:33 -070026import java.util.ArrayList;
Winson Chung55893332017-02-17 17:13:10 -080027import java.util.List;
28
29/**
30 * State and management of the pinned stack of activities.
31 */
Winson Chung3a682872017-04-10 14:38:05 -070032class PinnedActivityStack extends ActivityStack<PinnedStackWindowController>
33 implements PinnedStackWindowListener {
Winson Chung55893332017-02-17 17:13:10 -080034
Andrii Kulian94e82d9b02017-07-13 15:33:06 -070035 PinnedActivityStack(ActivityStackSupervisor.ActivityDisplay display, int stackId,
36 ActivityStackSupervisor supervisor, RecentTasks recentTasks, boolean onTop) {
37 super(display, stackId, supervisor, recentTasks, onTop);
Winson Chung55893332017-02-17 17:13:10 -080038 }
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 Chunga71febe2017-05-22 11:14:22 -070046 Rect getDefaultPictureInPictureBounds(float aspectRatio) {
Winson Chung9c844412017-04-27 17:36:41 -070047 return getWindowContainerController().getPictureInPictureBounds(aspectRatio,
Winson Chunga71febe2017-05-22 11:14:22 -070048 null /* currentStackBounds */);
Winson Chung9c844412017-04-27 17:36:41 -070049 }
50
Winson Chung8bca9e42017-04-16 15:59:43 -070051 void animateResizePinnedStack(Rect sourceHintBounds, Rect toBounds, int animationDuration,
Winson Chunge7ba6862017-05-24 12:13:33 -070052 boolean fromFullscreen) {
Wale Ogunwale42f07d92017-05-01 21:32:58 -070053 if (skipResizeAnimation(toBounds == null /* toFullscreen */)) {
54 mService.moveTasksToFullscreenStack(mStackId, true /* onTop */);
55 } else {
56 getWindowContainerController().animateResizePinnedStack(toBounds, sourceHintBounds,
Winson Chunge7ba6862017-05-24 12:13:33 -070057 animationDuration, fromFullscreen);
Wale Ogunwale42f07d92017-05-01 21:32:58 -070058 }
59 }
60
61 private boolean skipResizeAnimation(boolean toFullscreen) {
62 if (!toFullscreen) {
63 return false;
64 }
65 final Configuration parentConfig = getParent().getConfiguration();
66 final ActivityRecord top = topRunningNonOverlayTaskActivity();
67 return top != null && !top.isConfigurationCompatible(parentConfig);
Winson Chung55893332017-02-17 17:13:10 -080068 }
69
70 void setPictureInPictureAspectRatio(float aspectRatio) {
71 getWindowContainerController().setPictureInPictureAspectRatio(aspectRatio);
72 }
73
74 void setPictureInPictureActions(List<RemoteAction> actions) {
75 getWindowContainerController().setPictureInPictureActions(actions);
76 }
Winson Chung02e71932017-03-10 10:08:17 -080077
Winson Chung40a5f932017-04-13 16:39:36 -070078 boolean isAnimatingBoundsToFullscreen() {
79 return getWindowContainerController().isAnimatingBoundsToFullscreen();
Winson Chung02e71932017-03-10 10:08:17 -080080 }
Winson Chung5af42fc2017-03-24 17:11:33 -070081
Winson Chung8bca9e42017-04-16 15:59:43 -070082 /**
83 * Returns whether to defer the scheduling of the multi-window mode.
84 */
85 boolean deferScheduleMultiWindowModeChanged() {
86 // For the pinned stack, the deferring of the multi-window mode changed is tied to the
87 // transition animation into picture-in-picture, and is called once the animation completes,
88 // or is interrupted in a way that would leave the stack in a non-fullscreen state.
89 // @see BoundsAnimationController
90 // @see BoundsAnimationControllerTests
91 return mWindowContainerController.deferScheduleMultiWindowModeChanged();
92 }
93
Winson Chungab76bbc2017-08-14 13:33:51 -070094 public void updatePictureInPictureModeForPinnedStackAnimation(Rect targetStackBounds,
95 boolean forceUpdate) {
Winson Chung5af42fc2017-03-24 17:11:33 -070096 // 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++ ) {
Winson Chungab76bbc2017-08-14 13:33:51 -0700102 mStackSupervisor.updatePictureInPictureMode(tasks.get(i), targetStackBounds,
103 forceUpdate);
Winson Chung5af42fc2017-03-24 17:11:33 -0700104 }
105 }
106 }
Winson Chung55893332017-02-17 17:13:10 -0800107}