Home | History | Annotate | Download | only in am
      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 static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
     20 import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
     21 
     22 import android.app.RemoteAction;
     23 import android.content.res.Configuration;
     24 import android.graphics.Rect;
     25 
     26 import com.android.server.wm.PinnedStackWindowController;
     27 import com.android.server.wm.PinnedStackWindowListener;
     28 
     29 import java.util.ArrayList;
     30 import java.util.List;
     31 
     32 /**
     33  * State and management of the pinned stack of activities.
     34  */
     35 class PinnedActivityStack extends ActivityStack<PinnedStackWindowController>
     36         implements PinnedStackWindowListener {
     37 
     38     PinnedActivityStack(ActivityDisplay display, int stackId, ActivityStackSupervisor supervisor,
     39             boolean onTop) {
     40         super(display, stackId, supervisor, WINDOWING_MODE_PINNED, ACTIVITY_TYPE_STANDARD, onTop);
     41     }
     42 
     43     @Override
     44     PinnedStackWindowController createStackWindowController(int displayId, boolean onTop,
     45             Rect outBounds) {
     46         return new PinnedStackWindowController(mStackId, this, displayId, onTop, outBounds,
     47                 mStackSupervisor.mWindowManager);
     48     }
     49 
     50     Rect getDefaultPictureInPictureBounds(float aspectRatio) {
     51         return getWindowContainerController().getPictureInPictureBounds(aspectRatio,
     52                 null /* currentStackBounds */);
     53     }
     54 
     55     void animateResizePinnedStack(Rect sourceHintBounds, Rect toBounds, int animationDuration,
     56             boolean fromFullscreen) {
     57         if (skipResizeAnimation(toBounds == null /* toFullscreen */)) {
     58             mService.moveTasksToFullscreenStack(mStackId, true /* onTop */);
     59         } else {
     60             getWindowContainerController().animateResizePinnedStack(toBounds, sourceHintBounds,
     61                     animationDuration, fromFullscreen);
     62         }
     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);
     72     }
     73 
     74     void setPictureInPictureAspectRatio(float aspectRatio) {
     75         getWindowContainerController().setPictureInPictureAspectRatio(aspectRatio);
     76     }
     77 
     78     void setPictureInPictureActions(List<RemoteAction> actions) {
     79         getWindowContainerController().setPictureInPictureActions(actions);
     80     }
     81 
     82     boolean isAnimatingBoundsToFullscreen() {
     83         return getWindowContainerController().isAnimatingBoundsToFullscreen();
     84     }
     85 
     86     /**
     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 
     98     public void updatePictureInPictureModeForPinnedStackAnimation(Rect targetStackBounds,
     99             boolean forceUpdate) {
    100         // 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++ ) {
    106                 mStackSupervisor.updatePictureInPictureMode(tasks.get(i), targetStackBounds,
    107                         forceUpdate);
    108             }
    109         }
    110     }
    111 }
    112