1 /*
2  * Copyright (C) 2022 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.wm;
18 
19 import android.annotation.Nullable;
20 import android.annotation.SystemApi;
21 import android.graphics.Rect;
22 
23 
24 /**
25  * Wrapper of {@link com.android.server.wm.LaunchParamsController.LaunchParams}.
26  * @hide
27  */
28 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
29 public final class LaunchParamsWrapper {
30     /** Returned when the modifier does not want to influence the bounds calculation */
31     public static int RESULT_SKIP = LaunchParamsController.LaunchParamsModifier.RESULT_SKIP;
32     /**
33      * Returned when the modifier has changed the bounds and would like its results to be the
34      * final bounds applied.
35      */
36     public static int RESULT_DONE = LaunchParamsController.LaunchParamsModifier.RESULT_DONE;
37     /**
38      * Returned when the modifier has changed the bounds but is okay with other modifiers
39      * influencing the bounds.
40      */
41     public static int RESULT_CONTINUE = LaunchParamsController.LaunchParamsModifier.RESULT_CONTINUE;
42 
43     private final LaunchParamsController.LaunchParams mLaunchParams;
44 
LaunchParamsWrapper(LaunchParamsController.LaunchParams launchParams)45     private LaunchParamsWrapper(LaunchParamsController.LaunchParams launchParams) {
46         mLaunchParams = launchParams;
47     }
48 
49     /** @hide */
create( @ullable LaunchParamsController.LaunchParams launchParams)50     public static LaunchParamsWrapper create(
51             @Nullable LaunchParamsController.LaunchParams launchParams) {
52         if (launchParams == null) return null;
53         return new LaunchParamsWrapper(launchParams);
54     }
55 
56     /**
57      * Gets the {@link TaskDisplayAreaWrapper} the {@link Task} would prefer to be on.
58      */
getPreferredTaskDisplayArea()59     public TaskDisplayAreaWrapper getPreferredTaskDisplayArea() {
60         return TaskDisplayAreaWrapper.create(mLaunchParams.mPreferredTaskDisplayArea);
61     }
62 
63     /**
64      * Sets the {@link TaskDisplayAreaWrapper} the {@link Task} would prefer to be on.
65      */
setPreferredTaskDisplayArea(TaskDisplayAreaWrapper tda)66     public void setPreferredTaskDisplayArea(TaskDisplayAreaWrapper tda) {
67         mLaunchParams.mPreferredTaskDisplayArea = tda.getTaskDisplayArea();
68     }
69 
70     /**
71      * Gets the windowing mode to be in.
72      */
getWindowingMode()73     public int getWindowingMode() {
74         return mLaunchParams.mWindowingMode;
75     }
76 
77     /**
78      * Sets the windowing mode to be in.
79      */
setWindowingMode(int windowingMode)80     public void setWindowingMode(int windowingMode) {
81         mLaunchParams.mWindowingMode = windowingMode;
82     }
83 
84     /**
85      *  Gets the bounds within the parent container.
86      */
getBounds()87     public Rect getBounds() {
88         return mLaunchParams.mBounds;
89     }
90 
91     /**
92      *  Sets the bounds within the parent container.
93      */
setBounds(Rect bounds)94     public void setBounds(Rect bounds) {
95         mLaunchParams.mBounds.set(bounds);
96     }
97 
98     @Override
toString()99     public String toString() {
100         return "LaunchParams{" +
101                 "mPreferredTaskDisplayArea=" + mLaunchParams.mPreferredTaskDisplayArea +
102                 ", mWindowingMode=" + mLaunchParams.mWindowingMode +
103                 ", mBounds=" + mLaunchParams.mBounds.toString() + '}';
104     }
105 }
106