Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 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 android.app; |
| 18 | |
Wale Ogunwale | 6cbbc9a | 2017-09-06 19:01:03 -0700 | [diff] [blame] | 19 | import static android.app.ActivityThread.isSystem; |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 20 | import static android.app.WindowConfigurationProto.ACTIVITY_TYPE; |
| 21 | import static android.app.WindowConfigurationProto.APP_BOUNDS; |
Adrian Roos | 5f8b52c | 2018-11-28 16:31:55 +0100 | [diff] [blame] | 22 | import static android.app.WindowConfigurationProto.BOUNDS; |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 23 | import static android.app.WindowConfigurationProto.WINDOWING_MODE; |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 24 | import static android.view.Surface.rotationToString; |
Wale Ogunwale | 6cbbc9a | 2017-09-06 19:01:03 -0700 | [diff] [blame] | 25 | |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 26 | import android.annotation.IntDef; |
| 27 | import android.annotation.NonNull; |
Steven Timotius | e597ca1 | 2017-09-05 15:46:29 -0700 | [diff] [blame] | 28 | import android.annotation.TestApi; |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 29 | import android.content.res.Configuration; |
| 30 | import android.graphics.Rect; |
| 31 | import android.os.Parcel; |
| 32 | import android.os.Parcelable; |
Michael Wachenschwanz | c8c2636 | 2018-09-07 14:59:25 -0700 | [diff] [blame] | 33 | import android.util.proto.ProtoInputStream; |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 34 | import android.util.proto.ProtoOutputStream; |
Michael Wachenschwanz | c8c2636 | 2018-09-07 14:59:25 -0700 | [diff] [blame] | 35 | import android.util.proto.WireTypeMismatchException; |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 36 | import android.view.DisplayInfo; |
| 37 | |
Artur Satayev | f0b7d0b | 2019-11-04 11:16:45 +0000 | [diff] [blame^] | 38 | import dalvik.annotation.compat.UnsupportedAppUsage; |
| 39 | |
Michael Wachenschwanz | c8c2636 | 2018-09-07 14:59:25 -0700 | [diff] [blame] | 40 | import java.io.IOException; |
| 41 | |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 42 | /** |
| 43 | * Class that contains windowing configuration/state for other objects that contain windows directly |
| 44 | * or indirectly. E.g. Activities, Task, Displays, ... |
| 45 | * The test class is {@link com.android.server.wm.WindowConfigurationTests} which must be kept |
| 46 | * up-to-date and ran anytime changes are made to this class. |
| 47 | * @hide |
| 48 | */ |
Steven Timotius | e597ca1 | 2017-09-05 15:46:29 -0700 | [diff] [blame] | 49 | @TestApi |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 50 | public class WindowConfiguration implements Parcelable, Comparable<WindowConfiguration> { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 51 | /** |
| 52 | * bounds that can differ from app bounds, which may include things such as insets. |
| 53 | * |
| 54 | * TODO: Investigate combining with {@link mAppBounds}. Can the latter be a product of the |
| 55 | * former? |
| 56 | */ |
| 57 | private Rect mBounds = new Rect(); |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 58 | |
| 59 | /** |
| 60 | * {@link android.graphics.Rect} defining app bounds. The dimensions override usages of |
| 61 | * {@link DisplayInfo#appHeight} and {@link DisplayInfo#appWidth} and mirrors these values at |
| 62 | * the display level. Lower levels can override these values to provide custom bounds to enforce |
| 63 | * features such as a max aspect ratio. |
| 64 | */ |
| 65 | private Rect mAppBounds; |
| 66 | |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 67 | /** |
| 68 | * The current rotation of this window container relative to the default |
| 69 | * orientation of the display it is on (regardless of how deep in the hierarchy |
| 70 | * it is). It is used by the configuration hierarchy to apply rotation-dependent |
| 71 | * policy during bounds calculation. |
| 72 | */ |
| 73 | private int mRotation = ROTATION_UNDEFINED; |
| 74 | |
| 75 | /** Rotation is not defined, use the parent containers rotation. */ |
| 76 | public static final int ROTATION_UNDEFINED = -1; |
| 77 | |
Wale Ogunwale | 687b427 | 2017-07-27 02:56:23 -0700 | [diff] [blame] | 78 | /** The current windowing mode of the configuration. */ |
| 79 | private @WindowingMode int mWindowingMode; |
| 80 | |
Yunfan Chen | 7daa6ac | 2018-11-29 18:16:44 -0800 | [diff] [blame] | 81 | /** The display windowing mode of the configuration */ |
| 82 | private @WindowingMode int mDisplayWindowingMode; |
| 83 | |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 84 | /** Windowing mode is currently not defined. */ |
Wale Ogunwale | 687b427 | 2017-07-27 02:56:23 -0700 | [diff] [blame] | 85 | public static final int WINDOWING_MODE_UNDEFINED = 0; |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 86 | /** Occupies the full area of the screen or the parent container. */ |
Wale Ogunwale | 687b427 | 2017-07-27 02:56:23 -0700 | [diff] [blame] | 87 | public static final int WINDOWING_MODE_FULLSCREEN = 1; |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 88 | /** Always on-top (always visible). of other siblings in its parent container. */ |
Wale Ogunwale | 687b427 | 2017-07-27 02:56:23 -0700 | [diff] [blame] | 89 | public static final int WINDOWING_MODE_PINNED = 2; |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 90 | /** The primary container driving the screen to be in split-screen mode. */ |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 91 | public static final int WINDOWING_MODE_SPLIT_SCREEN_PRIMARY = 3; |
| 92 | /** |
| 93 | * The containers adjacent to the {@link #WINDOWING_MODE_SPLIT_SCREEN_PRIMARY} container in |
| 94 | * split-screen mode. |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 95 | * NOTE: Containers launched with the windowing mode with APIs like |
| 96 | * {@link ActivityOptions#setLaunchWindowingMode(int)} will be launched in |
| 97 | * {@link #WINDOWING_MODE_FULLSCREEN} if the display isn't currently in split-screen windowing |
| 98 | * mode |
| 99 | * @see #WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 100 | */ |
| 101 | public static final int WINDOWING_MODE_SPLIT_SCREEN_SECONDARY = 4; |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 102 | /** |
| 103 | * Alias for {@link #WINDOWING_MODE_SPLIT_SCREEN_SECONDARY} that makes it clear that the usage |
| 104 | * points for APIs like {@link ActivityOptions#setLaunchWindowingMode(int)} that the container |
| 105 | * will launch into fullscreen or split-screen secondary depending on if the device is currently |
| 106 | * in fullscreen mode or split-screen mode. |
| 107 | */ |
| 108 | public static final int WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY = |
| 109 | WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 110 | /** Can be freely resized within its parent container. */ |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 111 | public static final int WINDOWING_MODE_FREEFORM = 5; |
Wale Ogunwale | 687b427 | 2017-07-27 02:56:23 -0700 | [diff] [blame] | 112 | |
Steven Timotius | e597ca1 | 2017-09-05 15:46:29 -0700 | [diff] [blame] | 113 | /** @hide */ |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 114 | @IntDef(prefix = { "WINDOWING_MODE_" }, value = { |
Wale Ogunwale | 687b427 | 2017-07-27 02:56:23 -0700 | [diff] [blame] | 115 | WINDOWING_MODE_UNDEFINED, |
| 116 | WINDOWING_MODE_FULLSCREEN, |
| 117 | WINDOWING_MODE_PINNED, |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 118 | WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, |
| 119 | WINDOWING_MODE_SPLIT_SCREEN_SECONDARY, |
Wale Ogunwale | 0568aed | 2017-09-08 13:29:37 -0700 | [diff] [blame] | 120 | WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY, |
Wale Ogunwale | 687b427 | 2017-07-27 02:56:23 -0700 | [diff] [blame] | 121 | WINDOWING_MODE_FREEFORM, |
| 122 | }) |
Wale Ogunwale | 687b427 | 2017-07-27 02:56:23 -0700 | [diff] [blame] | 123 | public @interface WindowingMode {} |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 124 | |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 125 | /** The current activity type of the configuration. */ |
| 126 | private @ActivityType int mActivityType; |
| 127 | |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 128 | /** Activity type is currently not defined. */ |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 129 | public static final int ACTIVITY_TYPE_UNDEFINED = 0; |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 130 | /** Standard activity type. Nothing special about the activity... */ |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 131 | public static final int ACTIVITY_TYPE_STANDARD = 1; |
| 132 | /** Home/Launcher activity type. */ |
| 133 | public static final int ACTIVITY_TYPE_HOME = 2; |
Winson Chung | 3f0e59a | 2017-10-25 10:19:05 -0700 | [diff] [blame] | 134 | /** Recents/Overview activity type. There is only one activity with this type in the system. */ |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 135 | public static final int ACTIVITY_TYPE_RECENTS = 3; |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 136 | /** Assistant activity type. */ |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 137 | public static final int ACTIVITY_TYPE_ASSISTANT = 4; |
| 138 | |
Steven Timotius | e597ca1 | 2017-09-05 15:46:29 -0700 | [diff] [blame] | 139 | /** @hide */ |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 140 | @IntDef(prefix = { "ACTIVITY_TYPE_" }, value = { |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 141 | ACTIVITY_TYPE_UNDEFINED, |
| 142 | ACTIVITY_TYPE_STANDARD, |
| 143 | ACTIVITY_TYPE_HOME, |
| 144 | ACTIVITY_TYPE_RECENTS, |
| 145 | ACTIVITY_TYPE_ASSISTANT, |
| 146 | }) |
| 147 | public @interface ActivityType {} |
| 148 | |
Kazuki Takise | 4e7e789 | 2018-06-19 13:55:23 +0900 | [diff] [blame] | 149 | /** The current always on top status of the configuration. */ |
| 150 | private @AlwaysOnTop int mAlwaysOnTop; |
| 151 | |
| 152 | /** Always on top is currently not defined. */ |
| 153 | private static final int ALWAYS_ON_TOP_UNDEFINED = 0; |
| 154 | /** Always on top is currently on for this configuration. */ |
| 155 | private static final int ALWAYS_ON_TOP_ON = 1; |
| 156 | /** Always on top is currently off for this configuration. */ |
| 157 | private static final int ALWAYS_ON_TOP_OFF = 2; |
| 158 | |
| 159 | /** @hide */ |
| 160 | @IntDef(prefix = { "ALWAYS_ON_TOP_" }, value = { |
| 161 | ALWAYS_ON_TOP_UNDEFINED, |
| 162 | ALWAYS_ON_TOP_ON, |
| 163 | ALWAYS_ON_TOP_OFF, |
| 164 | }) |
| 165 | private @interface AlwaysOnTop {} |
| 166 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 167 | /** Bit that indicates that the {@link #mBounds} changed. |
| 168 | * @hide */ |
| 169 | public static final int WINDOW_CONFIG_BOUNDS = 1 << 0; |
Steven Timotius | e597ca1 | 2017-09-05 15:46:29 -0700 | [diff] [blame] | 170 | /** Bit that indicates that the {@link #mAppBounds} changed. |
| 171 | * @hide */ |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 172 | public static final int WINDOW_CONFIG_APP_BOUNDS = 1 << 1; |
Steven Timotius | e597ca1 | 2017-09-05 15:46:29 -0700 | [diff] [blame] | 173 | /** Bit that indicates that the {@link #mWindowingMode} changed. |
| 174 | * @hide */ |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 175 | public static final int WINDOW_CONFIG_WINDOWING_MODE = 1 << 2; |
Steven Timotius | e597ca1 | 2017-09-05 15:46:29 -0700 | [diff] [blame] | 176 | /** Bit that indicates that the {@link #mActivityType} changed. |
| 177 | * @hide */ |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 178 | public static final int WINDOW_CONFIG_ACTIVITY_TYPE = 1 << 3; |
Kazuki Takise | 4e7e789 | 2018-06-19 13:55:23 +0900 | [diff] [blame] | 179 | /** Bit that indicates that the {@link #mAlwaysOnTop} changed. |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 180 | * @hide */ |
Kazuki Takise | 4e7e789 | 2018-06-19 13:55:23 +0900 | [diff] [blame] | 181 | public static final int WINDOW_CONFIG_ALWAYS_ON_TOP = 1 << 4; |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 182 | /** Bit that indicates that the {@link #mRotation} changed. |
| 183 | * @hide */ |
| 184 | public static final int WINDOW_CONFIG_ROTATION = 1 << 5; |
Yunfan Chen | 7daa6ac | 2018-11-29 18:16:44 -0800 | [diff] [blame] | 185 | /** Bit that indicates that the {@link #mDisplayWindowingMode} changed. |
| 186 | * @hide */ |
| 187 | public static final int WINDOW_CONFIG_DISPLAY_WINDOWING_MODE = 1 << 6; |
| 188 | |
Steven Timotius | e597ca1 | 2017-09-05 15:46:29 -0700 | [diff] [blame] | 189 | /** @hide */ |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 190 | @IntDef(flag = true, prefix = { "WINDOW_CONFIG_" }, value = { |
| 191 | WINDOW_CONFIG_BOUNDS, |
| 192 | WINDOW_CONFIG_APP_BOUNDS, |
| 193 | WINDOW_CONFIG_WINDOWING_MODE, |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 194 | WINDOW_CONFIG_ACTIVITY_TYPE, |
Kazuki Takise | 4e7e789 | 2018-06-19 13:55:23 +0900 | [diff] [blame] | 195 | WINDOW_CONFIG_ALWAYS_ON_TOP, |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 196 | WINDOW_CONFIG_ROTATION, |
Yunfan Chen | 7daa6ac | 2018-11-29 18:16:44 -0800 | [diff] [blame] | 197 | WINDOW_CONFIG_DISPLAY_WINDOWING_MODE, |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 198 | }) |
Wale Ogunwale | 687b427 | 2017-07-27 02:56:23 -0700 | [diff] [blame] | 199 | public @interface WindowConfig {} |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 200 | |
Robert Carr | 32bcb10 | 2018-01-29 15:03:23 -0800 | [diff] [blame] | 201 | /** @hide */ |
| 202 | public static final int PINNED_WINDOWING_MODE_ELEVATION_IN_DIP = 5; |
| 203 | |
Artur Satayev | f0b7d0b | 2019-11-04 11:16:45 +0000 | [diff] [blame^] | 204 | @UnsupportedAppUsage |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 205 | public WindowConfiguration() { |
| 206 | unset(); |
| 207 | } |
| 208 | |
Steven Timotius | e597ca1 | 2017-09-05 15:46:29 -0700 | [diff] [blame] | 209 | /** @hide */ |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 210 | public WindowConfiguration(WindowConfiguration configuration) { |
| 211 | setTo(configuration); |
| 212 | } |
| 213 | |
| 214 | private WindowConfiguration(Parcel in) { |
| 215 | readFromParcel(in); |
| 216 | } |
| 217 | |
| 218 | @Override |
| 219 | public void writeToParcel(Parcel dest, int flags) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 220 | dest.writeParcelable(mBounds, flags); |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 221 | dest.writeParcelable(mAppBounds, flags); |
Wale Ogunwale | 687b427 | 2017-07-27 02:56:23 -0700 | [diff] [blame] | 222 | dest.writeInt(mWindowingMode); |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 223 | dest.writeInt(mActivityType); |
Kazuki Takise | 4e7e789 | 2018-06-19 13:55:23 +0900 | [diff] [blame] | 224 | dest.writeInt(mAlwaysOnTop); |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 225 | dest.writeInt(mRotation); |
Yunfan Chen | 7daa6ac | 2018-11-29 18:16:44 -0800 | [diff] [blame] | 226 | dest.writeInt(mDisplayWindowingMode); |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | private void readFromParcel(Parcel source) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 230 | mBounds = source.readParcelable(Rect.class.getClassLoader()); |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 231 | mAppBounds = source.readParcelable(Rect.class.getClassLoader()); |
Wale Ogunwale | 687b427 | 2017-07-27 02:56:23 -0700 | [diff] [blame] | 232 | mWindowingMode = source.readInt(); |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 233 | mActivityType = source.readInt(); |
Kazuki Takise | 4e7e789 | 2018-06-19 13:55:23 +0900 | [diff] [blame] | 234 | mAlwaysOnTop = source.readInt(); |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 235 | mRotation = source.readInt(); |
Yunfan Chen | 7daa6ac | 2018-11-29 18:16:44 -0800 | [diff] [blame] | 236 | mDisplayWindowingMode = source.readInt(); |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | @Override |
| 240 | public int describeContents() { |
| 241 | return 0; |
| 242 | } |
| 243 | |
Steven Timotius | e597ca1 | 2017-09-05 15:46:29 -0700 | [diff] [blame] | 244 | /** @hide */ |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 245 | public static final @android.annotation.NonNull Creator<WindowConfiguration> CREATOR = new Creator<WindowConfiguration>() { |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 246 | @Override |
| 247 | public WindowConfiguration createFromParcel(Parcel in) { |
| 248 | return new WindowConfiguration(in); |
| 249 | } |
| 250 | |
| 251 | @Override |
| 252 | public WindowConfiguration[] newArray(int size) { |
| 253 | return new WindowConfiguration[size]; |
| 254 | } |
| 255 | }; |
| 256 | |
| 257 | /** |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 258 | * Sets the bounds to the provided {@link Rect}. |
| 259 | * @param rect the new bounds value. |
| 260 | */ |
| 261 | public void setBounds(Rect rect) { |
| 262 | if (rect == null) { |
| 263 | mBounds.setEmpty(); |
| 264 | return; |
| 265 | } |
| 266 | |
| 267 | mBounds.set(rect); |
| 268 | } |
| 269 | |
| 270 | /** |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 271 | * Set {@link #mAppBounds} to the input Rect. |
| 272 | * @param rect The rect value to set {@link #mAppBounds} to. |
| 273 | * @see #getAppBounds() |
| 274 | */ |
| 275 | public void setAppBounds(Rect rect) { |
| 276 | if (rect == null) { |
| 277 | mAppBounds = null; |
| 278 | return; |
| 279 | } |
| 280 | |
| 281 | setAppBounds(rect.left, rect.top, rect.right, rect.bottom); |
| 282 | } |
| 283 | |
Kazuki Takise | 4e7e789 | 2018-06-19 13:55:23 +0900 | [diff] [blame] | 284 | |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 285 | |
| 286 | /** |
| 287 | * Sets whether this window should be always on top. |
| 288 | * @param alwaysOnTop {@code true} to set window always on top, otherwise {@code false} |
| 289 | * @hide |
| 290 | */ |
| 291 | public void setAlwaysOnTop(boolean alwaysOnTop) { |
Kazuki Takise | 4e7e789 | 2018-06-19 13:55:23 +0900 | [diff] [blame] | 292 | mAlwaysOnTop = alwaysOnTop ? ALWAYS_ON_TOP_ON : ALWAYS_ON_TOP_OFF; |
| 293 | } |
| 294 | |
| 295 | private void setAlwaysOnTop(@AlwaysOnTop int alwaysOnTop) { |
| 296 | mAlwaysOnTop = alwaysOnTop; |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 297 | } |
| 298 | |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 299 | /** |
| 300 | * @see #setAppBounds(Rect) |
| 301 | * @see #getAppBounds() |
Steven Timotius | e597ca1 | 2017-09-05 15:46:29 -0700 | [diff] [blame] | 302 | * @hide |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 303 | */ |
| 304 | public void setAppBounds(int left, int top, int right, int bottom) { |
| 305 | if (mAppBounds == null) { |
| 306 | mAppBounds = new Rect(); |
| 307 | } |
| 308 | |
| 309 | mAppBounds.set(left, top, right, bottom); |
| 310 | } |
| 311 | |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 312 | /** @see #setAppBounds(Rect) */ |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 313 | public Rect getAppBounds() { |
| 314 | return mAppBounds; |
| 315 | } |
| 316 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 317 | /** @see #setBounds(Rect) */ |
| 318 | public Rect getBounds() { |
| 319 | return mBounds; |
| 320 | } |
| 321 | |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 322 | public int getRotation() { |
| 323 | return mRotation; |
| 324 | } |
| 325 | |
| 326 | public void setRotation(int rotation) { |
| 327 | mRotation = rotation; |
| 328 | } |
| 329 | |
Wale Ogunwale | 687b427 | 2017-07-27 02:56:23 -0700 | [diff] [blame] | 330 | public void setWindowingMode(@WindowingMode int windowingMode) { |
| 331 | mWindowingMode = windowingMode; |
| 332 | } |
| 333 | |
| 334 | @WindowingMode |
| 335 | public int getWindowingMode() { |
| 336 | return mWindowingMode; |
| 337 | } |
| 338 | |
Yunfan Chen | 7daa6ac | 2018-11-29 18:16:44 -0800 | [diff] [blame] | 339 | /** @hide */ |
| 340 | public void setDisplayWindowingMode(@WindowingMode int windowingMode) { |
| 341 | mDisplayWindowingMode = windowingMode; |
| 342 | } |
| 343 | |
Garfield Tan | 3129b85 | 2019-06-24 16:51:20 -0700 | [diff] [blame] | 344 | /** @hide */ |
| 345 | @WindowingMode |
| 346 | public int getDisplayWindowingMode() { |
| 347 | return mDisplayWindowingMode; |
| 348 | } |
Yunfan Chen | 7daa6ac | 2018-11-29 18:16:44 -0800 | [diff] [blame] | 349 | |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 350 | public void setActivityType(@ActivityType int activityType) { |
| 351 | if (mActivityType == activityType) { |
| 352 | return; |
| 353 | } |
Wale Ogunwale | 6cbbc9a | 2017-09-06 19:01:03 -0700 | [diff] [blame] | 354 | |
| 355 | // Error check within system server that we are not changing activity type which can be |
| 356 | // dangerous. It is okay for things to change in the application process as it doesn't |
| 357 | // affect how other things is the system is managed. |
| 358 | if (isSystem() |
| 359 | && mActivityType != ACTIVITY_TYPE_UNDEFINED |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 360 | && activityType != ACTIVITY_TYPE_UNDEFINED) { |
| 361 | throw new IllegalStateException("Can't change activity type once set: " + this |
| 362 | + " activityType=" + activityTypeToString(activityType)); |
| 363 | } |
| 364 | mActivityType = activityType; |
| 365 | } |
| 366 | |
| 367 | @ActivityType |
| 368 | public int getActivityType() { |
| 369 | return mActivityType; |
| 370 | } |
| 371 | |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 372 | public void setTo(WindowConfiguration other) { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 373 | setBounds(other.mBounds); |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 374 | setAppBounds(other.mAppBounds); |
Wale Ogunwale | 687b427 | 2017-07-27 02:56:23 -0700 | [diff] [blame] | 375 | setWindowingMode(other.mWindowingMode); |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 376 | setActivityType(other.mActivityType); |
Kazuki Takise | 4e7e789 | 2018-06-19 13:55:23 +0900 | [diff] [blame] | 377 | setAlwaysOnTop(other.mAlwaysOnTop); |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 378 | setRotation(other.mRotation); |
Yunfan Chen | 7daa6ac | 2018-11-29 18:16:44 -0800 | [diff] [blame] | 379 | setDisplayWindowingMode(other.mDisplayWindowingMode); |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 380 | } |
| 381 | |
Steven Timotius | e597ca1 | 2017-09-05 15:46:29 -0700 | [diff] [blame] | 382 | /** Set this object to completely undefined. |
| 383 | * @hide */ |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 384 | public void unset() { |
| 385 | setToDefaults(); |
| 386 | } |
| 387 | |
Steven Timotius | e597ca1 | 2017-09-05 15:46:29 -0700 | [diff] [blame] | 388 | /** @hide */ |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 389 | public void setToDefaults() { |
| 390 | setAppBounds(null); |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 391 | setBounds(null); |
Wale Ogunwale | 687b427 | 2017-07-27 02:56:23 -0700 | [diff] [blame] | 392 | setWindowingMode(WINDOWING_MODE_UNDEFINED); |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 393 | setActivityType(ACTIVITY_TYPE_UNDEFINED); |
Kazuki Takise | 4e7e789 | 2018-06-19 13:55:23 +0900 | [diff] [blame] | 394 | setAlwaysOnTop(ALWAYS_ON_TOP_UNDEFINED); |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 395 | setRotation(ROTATION_UNDEFINED); |
Yunfan Chen | 7daa6ac | 2018-11-29 18:16:44 -0800 | [diff] [blame] | 396 | setDisplayWindowingMode(WINDOWING_MODE_UNDEFINED); |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | /** |
| 400 | * Copies the fields from delta into this Configuration object, keeping |
| 401 | * track of which ones have changed. Any undefined fields in {@code delta} |
| 402 | * are ignored and not copied in to the current Configuration. |
| 403 | * |
| 404 | * @return a bit mask of the changed fields, as per {@link #diff} |
Steven Timotius | e597ca1 | 2017-09-05 15:46:29 -0700 | [diff] [blame] | 405 | * @hide |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 406 | */ |
| 407 | public @WindowConfig int updateFrom(@NonNull WindowConfiguration delta) { |
| 408 | int changed = 0; |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 409 | // Only allow override if bounds is not empty |
| 410 | if (!delta.mBounds.isEmpty() && !delta.mBounds.equals(mBounds)) { |
| 411 | changed |= WINDOW_CONFIG_BOUNDS; |
| 412 | setBounds(delta.mBounds); |
| 413 | } |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 414 | if (delta.mAppBounds != null && !delta.mAppBounds.equals(mAppBounds)) { |
| 415 | changed |= WINDOW_CONFIG_APP_BOUNDS; |
| 416 | setAppBounds(delta.mAppBounds); |
| 417 | } |
Wale Ogunwale | 687b427 | 2017-07-27 02:56:23 -0700 | [diff] [blame] | 418 | if (delta.mWindowingMode != WINDOWING_MODE_UNDEFINED |
| 419 | && mWindowingMode != delta.mWindowingMode) { |
| 420 | changed |= WINDOW_CONFIG_WINDOWING_MODE; |
| 421 | setWindowingMode(delta.mWindowingMode); |
| 422 | } |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 423 | if (delta.mActivityType != ACTIVITY_TYPE_UNDEFINED |
| 424 | && mActivityType != delta.mActivityType) { |
| 425 | changed |= WINDOW_CONFIG_ACTIVITY_TYPE; |
| 426 | setActivityType(delta.mActivityType); |
| 427 | } |
Kazuki Takise | 4e7e789 | 2018-06-19 13:55:23 +0900 | [diff] [blame] | 428 | if (delta.mAlwaysOnTop != ALWAYS_ON_TOP_UNDEFINED |
| 429 | && mAlwaysOnTop != delta.mAlwaysOnTop) { |
| 430 | changed |= WINDOW_CONFIG_ALWAYS_ON_TOP; |
| 431 | setAlwaysOnTop(delta.mAlwaysOnTop); |
| 432 | } |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 433 | if (delta.mRotation != ROTATION_UNDEFINED && delta.mRotation != mRotation) { |
| 434 | changed |= WINDOW_CONFIG_ROTATION; |
| 435 | setRotation(delta.mRotation); |
| 436 | } |
Yunfan Chen | 7daa6ac | 2018-11-29 18:16:44 -0800 | [diff] [blame] | 437 | if (delta.mDisplayWindowingMode != WINDOWING_MODE_UNDEFINED |
| 438 | && mDisplayWindowingMode != delta.mDisplayWindowingMode) { |
| 439 | changed |= WINDOW_CONFIG_DISPLAY_WINDOWING_MODE; |
| 440 | setDisplayWindowingMode(delta.mDisplayWindowingMode); |
| 441 | } |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 442 | return changed; |
| 443 | } |
| 444 | |
| 445 | /** |
Evan Rosky | ddedfd4 | 2019-10-04 13:38:38 -0700 | [diff] [blame] | 446 | * Copies the fields specified by mask from delta into this Configuration object. |
| 447 | * @hide |
| 448 | */ |
| 449 | public void setTo(@NonNull WindowConfiguration delta, @WindowConfig int mask) { |
| 450 | if ((mask & WINDOW_CONFIG_BOUNDS) != 0) { |
| 451 | setBounds(delta.mBounds); |
| 452 | } |
| 453 | if ((mask & WINDOW_CONFIG_APP_BOUNDS) != 0) { |
| 454 | setAppBounds(delta.mAppBounds); |
| 455 | } |
| 456 | if ((mask & WINDOW_CONFIG_WINDOWING_MODE) != 0) { |
| 457 | setWindowingMode(delta.mWindowingMode); |
| 458 | } |
| 459 | if ((mask & WINDOW_CONFIG_ACTIVITY_TYPE) != 0) { |
| 460 | setActivityType(delta.mActivityType); |
| 461 | } |
| 462 | if ((mask & WINDOW_CONFIG_ALWAYS_ON_TOP) != 0) { |
| 463 | setAlwaysOnTop(delta.mAlwaysOnTop); |
| 464 | } |
| 465 | if ((mask & WINDOW_CONFIG_ROTATION) != 0) { |
| 466 | setRotation(delta.mRotation); |
| 467 | } |
| 468 | if ((mask & WINDOW_CONFIG_DISPLAY_WINDOWING_MODE) != 0) { |
| 469 | setDisplayWindowingMode(delta.mDisplayWindowingMode); |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | /** |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 474 | * Return a bit mask of the differences between this Configuration object and the given one. |
| 475 | * Does not change the values of either. Any undefined fields in <var>other</var> are ignored. |
| 476 | * @param other The configuration to diff against. |
| 477 | * @param compareUndefined If undefined values should be compared. |
| 478 | * @return Returns a bit mask indicating which configuration |
| 479 | * values has changed, containing any combination of {@link WindowConfig} flags. |
| 480 | * |
| 481 | * @see Configuration#diff(Configuration) |
Steven Timotius | e597ca1 | 2017-09-05 15:46:29 -0700 | [diff] [blame] | 482 | * @hide |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 483 | */ |
| 484 | public @WindowConfig long diff(WindowConfiguration other, boolean compareUndefined) { |
| 485 | long changes = 0; |
| 486 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 487 | if (!mBounds.equals(other.mBounds)) { |
| 488 | changes |= WINDOW_CONFIG_BOUNDS; |
| 489 | } |
| 490 | |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 491 | // Make sure that one of the values is not null and that they are not equal. |
| 492 | if ((compareUndefined || other.mAppBounds != null) |
| 493 | && mAppBounds != other.mAppBounds |
| 494 | && (mAppBounds == null || !mAppBounds.equals(other.mAppBounds))) { |
| 495 | changes |= WINDOW_CONFIG_APP_BOUNDS; |
| 496 | } |
| 497 | |
Wale Ogunwale | 687b427 | 2017-07-27 02:56:23 -0700 | [diff] [blame] | 498 | if ((compareUndefined || other.mWindowingMode != WINDOWING_MODE_UNDEFINED) |
| 499 | && mWindowingMode != other.mWindowingMode) { |
| 500 | changes |= WINDOW_CONFIG_WINDOWING_MODE; |
| 501 | } |
| 502 | |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 503 | if ((compareUndefined || other.mActivityType != ACTIVITY_TYPE_UNDEFINED) |
| 504 | && mActivityType != other.mActivityType) { |
| 505 | changes |= WINDOW_CONFIG_ACTIVITY_TYPE; |
| 506 | } |
| 507 | |
Kazuki Takise | 4e7e789 | 2018-06-19 13:55:23 +0900 | [diff] [blame] | 508 | if ((compareUndefined || other.mAlwaysOnTop != ALWAYS_ON_TOP_UNDEFINED) |
| 509 | && mAlwaysOnTop != other.mAlwaysOnTop) { |
| 510 | changes |= WINDOW_CONFIG_ALWAYS_ON_TOP; |
| 511 | } |
| 512 | |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 513 | if ((compareUndefined || other.mRotation != ROTATION_UNDEFINED) |
| 514 | && mRotation != other.mRotation) { |
| 515 | changes |= WINDOW_CONFIG_ROTATION; |
| 516 | } |
| 517 | |
Yunfan Chen | 7daa6ac | 2018-11-29 18:16:44 -0800 | [diff] [blame] | 518 | if ((compareUndefined || other.mDisplayWindowingMode != WINDOWING_MODE_UNDEFINED) |
| 519 | && mDisplayWindowingMode != other.mDisplayWindowingMode) { |
| 520 | changes |= WINDOW_CONFIG_DISPLAY_WINDOWING_MODE; |
| 521 | } |
| 522 | |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 523 | return changes; |
| 524 | } |
| 525 | |
| 526 | @Override |
| 527 | public int compareTo(WindowConfiguration that) { |
| 528 | int n = 0; |
| 529 | if (mAppBounds == null && that.mAppBounds != null) { |
| 530 | return 1; |
| 531 | } else if (mAppBounds != null && that.mAppBounds == null) { |
| 532 | return -1; |
| 533 | } else if (mAppBounds != null && that.mAppBounds != null) { |
| 534 | n = mAppBounds.left - that.mAppBounds.left; |
| 535 | if (n != 0) return n; |
| 536 | n = mAppBounds.top - that.mAppBounds.top; |
| 537 | if (n != 0) return n; |
| 538 | n = mAppBounds.right - that.mAppBounds.right; |
| 539 | if (n != 0) return n; |
| 540 | n = mAppBounds.bottom - that.mAppBounds.bottom; |
| 541 | if (n != 0) return n; |
| 542 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 543 | |
| 544 | n = mBounds.left - that.mBounds.left; |
| 545 | if (n != 0) return n; |
| 546 | n = mBounds.top - that.mBounds.top; |
| 547 | if (n != 0) return n; |
| 548 | n = mBounds.right - that.mBounds.right; |
| 549 | if (n != 0) return n; |
| 550 | n = mBounds.bottom - that.mBounds.bottom; |
| 551 | if (n != 0) return n; |
| 552 | |
Wale Ogunwale | 687b427 | 2017-07-27 02:56:23 -0700 | [diff] [blame] | 553 | n = mWindowingMode - that.mWindowingMode; |
| 554 | if (n != 0) return n; |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 555 | n = mActivityType - that.mActivityType; |
| 556 | if (n != 0) return n; |
Kazuki Takise | 4e7e789 | 2018-06-19 13:55:23 +0900 | [diff] [blame] | 557 | n = mAlwaysOnTop - that.mAlwaysOnTop; |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 558 | if (n != 0) return n; |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 559 | n = mRotation - that.mRotation; |
| 560 | if (n != 0) return n; |
Yunfan Chen | 7daa6ac | 2018-11-29 18:16:44 -0800 | [diff] [blame] | 561 | n = mDisplayWindowingMode - that.mDisplayWindowingMode; |
| 562 | if (n != 0) return n; |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 563 | |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 564 | // if (n != 0) return n; |
| 565 | return n; |
| 566 | } |
| 567 | |
Steven Timotius | e597ca1 | 2017-09-05 15:46:29 -0700 | [diff] [blame] | 568 | /** @hide */ |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 569 | @Override |
| 570 | public boolean equals(Object that) { |
| 571 | if (that == null) return false; |
| 572 | if (that == this) return true; |
| 573 | if (!(that instanceof WindowConfiguration)) { |
| 574 | return false; |
| 575 | } |
| 576 | return this.compareTo((WindowConfiguration) that) == 0; |
| 577 | } |
| 578 | |
Steven Timotius | e597ca1 | 2017-09-05 15:46:29 -0700 | [diff] [blame] | 579 | /** @hide */ |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 580 | @Override |
| 581 | public int hashCode() { |
| 582 | int result = 0; |
| 583 | if (mAppBounds != null) { |
| 584 | result = 31 * result + mAppBounds.hashCode(); |
| 585 | } |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 586 | result = 31 * result + mBounds.hashCode(); |
| 587 | |
Wale Ogunwale | 687b427 | 2017-07-27 02:56:23 -0700 | [diff] [blame] | 588 | result = 31 * result + mWindowingMode; |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 589 | result = 31 * result + mActivityType; |
Kazuki Takise | 4e7e789 | 2018-06-19 13:55:23 +0900 | [diff] [blame] | 590 | result = 31 * result + mAlwaysOnTop; |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 591 | result = 31 * result + mRotation; |
Yunfan Chen | 7daa6ac | 2018-11-29 18:16:44 -0800 | [diff] [blame] | 592 | result = 31 * result + mDisplayWindowingMode; |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 593 | return result; |
| 594 | } |
| 595 | |
Steven Timotius | e597ca1 | 2017-09-05 15:46:29 -0700 | [diff] [blame] | 596 | /** @hide */ |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 597 | @Override |
| 598 | public String toString() { |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 599 | return "{ mBounds=" + mBounds |
| 600 | + " mAppBounds=" + mAppBounds |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 601 | + " mWindowingMode=" + windowingModeToString(mWindowingMode) |
Yunfan Chen | 7daa6ac | 2018-11-29 18:16:44 -0800 | [diff] [blame] | 602 | + " mDisplayWindowingMode=" + windowingModeToString(mDisplayWindowingMode) |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 603 | + " mActivityType=" + activityTypeToString(mActivityType) |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 604 | + " mAlwaysOnTop=" + alwaysOnTopToString(mAlwaysOnTop) |
Evan Rosky | e747c3e | 2018-10-30 20:06:41 -0700 | [diff] [blame] | 605 | + " mRotation=" + (mRotation == ROTATION_UNDEFINED |
| 606 | ? "undefined" : rotationToString(mRotation)) |
Kazuki Takise | 148d00a | 2018-05-31 15:32:19 +0900 | [diff] [blame] | 607 | + "}"; |
Wale Ogunwale | 687b427 | 2017-07-27 02:56:23 -0700 | [diff] [blame] | 608 | } |
| 609 | |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 610 | /** |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 611 | * Write to a protocol buffer output stream. |
| 612 | * Protocol buffer message definition at {@link android.app.WindowConfigurationProto} |
| 613 | * |
| 614 | * @param protoOutputStream Stream to write the WindowConfiguration object to. |
| 615 | * @param fieldId Field Id of the WindowConfiguration as defined in the parent message |
| 616 | * @hide |
| 617 | */ |
| 618 | public void writeToProto(ProtoOutputStream protoOutputStream, long fieldId) { |
| 619 | final long token = protoOutputStream.start(fieldId); |
| 620 | if (mAppBounds != null) { |
| 621 | mAppBounds.writeToProto(protoOutputStream, APP_BOUNDS); |
| 622 | } |
| 623 | protoOutputStream.write(WINDOWING_MODE, mWindowingMode); |
| 624 | protoOutputStream.write(ACTIVITY_TYPE, mActivityType); |
Adrian Roos | 5f8b52c | 2018-11-28 16:31:55 +0100 | [diff] [blame] | 625 | if (mBounds != null) { |
| 626 | mBounds.writeToProto(protoOutputStream, BOUNDS); |
| 627 | } |
Wale Ogunwale | 0d5609b | 2017-09-13 05:55:07 -0700 | [diff] [blame] | 628 | protoOutputStream.end(token); |
| 629 | } |
| 630 | |
| 631 | /** |
Michael Wachenschwanz | c8c2636 | 2018-09-07 14:59:25 -0700 | [diff] [blame] | 632 | * Read from a protocol buffer input stream. |
| 633 | * Protocol buffer message definition at {@link android.app.WindowConfigurationProto} |
| 634 | * |
| 635 | * @param proto Stream to read the WindowConfiguration object from. |
| 636 | * @param fieldId Field Id of the WindowConfiguration as defined in the parent message |
| 637 | * @hide |
| 638 | */ |
| 639 | public void readFromProto(ProtoInputStream proto, long fieldId) |
| 640 | throws IOException, WireTypeMismatchException { |
| 641 | final long token = proto.start(fieldId); |
| 642 | try { |
| 643 | while (proto.nextField() != ProtoInputStream.NO_MORE_FIELDS) { |
| 644 | switch (proto.getFieldNumber()) { |
| 645 | case (int) APP_BOUNDS: |
| 646 | mAppBounds = new Rect(); |
| 647 | mAppBounds.readFromProto(proto, APP_BOUNDS); |
| 648 | break; |
Adrian Roos | 5f8b52c | 2018-11-28 16:31:55 +0100 | [diff] [blame] | 649 | case (int) BOUNDS: |
| 650 | mBounds = new Rect(); |
| 651 | mBounds.readFromProto(proto, BOUNDS); |
| 652 | break; |
Michael Wachenschwanz | c8c2636 | 2018-09-07 14:59:25 -0700 | [diff] [blame] | 653 | case (int) WINDOWING_MODE: |
| 654 | mWindowingMode = proto.readInt(WINDOWING_MODE); |
| 655 | break; |
| 656 | case (int) ACTIVITY_TYPE: |
| 657 | mActivityType = proto.readInt(ACTIVITY_TYPE); |
| 658 | break; |
| 659 | } |
| 660 | } |
| 661 | } finally { |
| 662 | // Let caller handle any exceptions |
| 663 | proto.end(token); |
| 664 | } |
| 665 | } |
| 666 | |
| 667 | /** |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 668 | * Returns true if the activities associated with this window configuration display a shadow |
| 669 | * around their border. |
Steven Timotius | e597ca1 | 2017-09-05 15:46:29 -0700 | [diff] [blame] | 670 | * @hide |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 671 | */ |
| 672 | public boolean hasWindowShadow() { |
| 673 | return tasksAreFloating(); |
| 674 | } |
| 675 | |
| 676 | /** |
| 677 | * Returns true if the activities associated with this window configuration display a decor |
| 678 | * view. |
Steven Timotius | e597ca1 | 2017-09-05 15:46:29 -0700 | [diff] [blame] | 679 | * @hide |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 680 | */ |
| 681 | public boolean hasWindowDecorCaption() { |
Yunfan Chen | 7daa6ac | 2018-11-29 18:16:44 -0800 | [diff] [blame] | 682 | return mActivityType == ACTIVITY_TYPE_STANDARD && (mWindowingMode == WINDOWING_MODE_FREEFORM |
| 683 | || mDisplayWindowingMode == WINDOWING_MODE_FREEFORM); |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | /** |
| 687 | * Returns true if the tasks associated with this window configuration can be resized |
| 688 | * independently of their parent container. |
Steven Timotius | e597ca1 | 2017-09-05 15:46:29 -0700 | [diff] [blame] | 689 | * @hide |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 690 | */ |
| 691 | public boolean canResizeTask() { |
| 692 | return mWindowingMode == WINDOWING_MODE_FREEFORM; |
| 693 | } |
| 694 | |
Steven Timotius | e597ca1 | 2017-09-05 15:46:29 -0700 | [diff] [blame] | 695 | /** Returns true if the task bounds should persist across power cycles. |
| 696 | * @hide */ |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 697 | public boolean persistTaskBounds() { |
| 698 | return mWindowingMode == WINDOWING_MODE_FREEFORM; |
| 699 | } |
| 700 | |
| 701 | /** |
| 702 | * Returns true if the tasks associated with this window configuration are floating. |
| 703 | * Floating tasks are laid out differently as they are allowed to extend past the display bounds |
| 704 | * without overscan insets. |
Steven Timotius | e597ca1 | 2017-09-05 15:46:29 -0700 | [diff] [blame] | 705 | * @hide |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 706 | */ |
| 707 | public boolean tasksAreFloating() { |
Evan Rosky | b0e3888 | 2018-04-25 12:48:54 -0700 | [diff] [blame] | 708 | return isFloating(mWindowingMode); |
| 709 | } |
| 710 | |
| 711 | /** |
| 712 | * Returns true if the windowingMode represents a floating window. |
| 713 | * @hide |
| 714 | */ |
| 715 | public static boolean isFloating(int windowingMode) { |
| 716 | return windowingMode == WINDOWING_MODE_FREEFORM || windowingMode == WINDOWING_MODE_PINNED; |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | /** |
Evan Rosky | 1ac8446 | 2018-11-13 11:25:30 -0800 | [diff] [blame] | 720 | * Returns true if the windowingMode represents a split window. |
| 721 | * @hide |
| 722 | */ |
| 723 | public static boolean isSplitScreenWindowingMode(int windowingMode) { |
| 724 | return windowingMode == WINDOWING_MODE_SPLIT_SCREEN_PRIMARY |
| 725 | || windowingMode == WINDOWING_MODE_SPLIT_SCREEN_SECONDARY; |
| 726 | } |
| 727 | |
| 728 | /** |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 729 | * Returns true if the windows associated with this window configuration can receive input keys. |
Steven Timotius | e597ca1 | 2017-09-05 15:46:29 -0700 | [diff] [blame] | 730 | * @hide |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 731 | */ |
| 732 | public boolean canReceiveKeys() { |
| 733 | return mWindowingMode != WINDOWING_MODE_PINNED; |
| 734 | } |
| 735 | |
| 736 | /** |
| 737 | * Returns true if the container associated with this window configuration is always-on-top of |
| 738 | * its siblings. |
Steven Timotius | e597ca1 | 2017-09-05 15:46:29 -0700 | [diff] [blame] | 739 | * @hide |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 740 | */ |
| 741 | public boolean isAlwaysOnTop() { |
Kazuki Takise | 048e266 | 2018-06-27 17:05:11 +0900 | [diff] [blame] | 742 | return mWindowingMode == WINDOWING_MODE_PINNED |
| 743 | || (mWindowingMode == WINDOWING_MODE_FREEFORM && mAlwaysOnTop == ALWAYS_ON_TOP_ON); |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | /** |
| 747 | * Returns true if any visible windows belonging to apps with this window configuration should |
| 748 | * be kept on screen when the app is killed due to something like the low memory killer. |
Steven Timotius | e597ca1 | 2017-09-05 15:46:29 -0700 | [diff] [blame] | 749 | * @hide |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 750 | */ |
| 751 | public boolean keepVisibleDeadAppWindowOnScreen() { |
| 752 | return mWindowingMode != WINDOWING_MODE_PINNED; |
| 753 | } |
| 754 | |
| 755 | /** |
| 756 | * Returns true if the backdrop on the client side should match the frame of the window. |
| 757 | * Returns false, if the backdrop should be fullscreen. |
Steven Timotius | e597ca1 | 2017-09-05 15:46:29 -0700 | [diff] [blame] | 758 | * @hide |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 759 | */ |
| 760 | public boolean useWindowFrameForBackdrop() { |
| 761 | return mWindowingMode == WINDOWING_MODE_FREEFORM || mWindowingMode == WINDOWING_MODE_PINNED; |
| 762 | } |
| 763 | |
| 764 | /** |
| 765 | * Returns true if this container may be scaled without resizing, and windows within may need |
| 766 | * to be configured as such. |
Steven Timotius | e597ca1 | 2017-09-05 15:46:29 -0700 | [diff] [blame] | 767 | * @hide |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 768 | */ |
| 769 | public boolean windowsAreScaleable() { |
| 770 | return mWindowingMode == WINDOWING_MODE_PINNED; |
| 771 | } |
| 772 | |
| 773 | /** |
| 774 | * Returns true if windows in this container should be given move animations by default. |
Steven Timotius | e597ca1 | 2017-09-05 15:46:29 -0700 | [diff] [blame] | 775 | * @hide |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 776 | */ |
| 777 | public boolean hasMovementAnimations() { |
Jorim Jaggi | bb6ee9b | 2017-09-06 23:59:34 +0200 | [diff] [blame] | 778 | return mWindowingMode != WINDOWING_MODE_PINNED; |
Wale Ogunwale | 3382ab1 | 2017-07-27 08:55:03 -0700 | [diff] [blame] | 779 | } |
| 780 | |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 781 | /** |
| 782 | * Returns true if this container can be put in either |
| 783 | * {@link #WINDOWING_MODE_SPLIT_SCREEN_PRIMARY} or |
| 784 | * {@link #WINDOWING_MODE_SPLIT_SCREEN_SECONDARY} windowing modes based on its current state. |
| 785 | * @hide |
| 786 | */ |
| 787 | public boolean supportSplitScreenWindowingMode() { |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 788 | return supportSplitScreenWindowingMode(mActivityType); |
Wale Ogunwale | 04a05ac | 2017-09-17 21:35:02 -0700 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | /** @hide */ |
Wale Ogunwale | 2b07da8 | 2017-11-08 14:52:40 -0800 | [diff] [blame] | 792 | public static boolean supportSplitScreenWindowingMode(int activityType) { |
| 793 | return activityType != ACTIVITY_TYPE_ASSISTANT; |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 794 | } |
| 795 | |
Wale Ogunwale | 44f036f | 2017-09-29 05:09:09 -0700 | [diff] [blame] | 796 | /** @hide */ |
| 797 | public static String windowingModeToString(@WindowingMode int windowingMode) { |
Wale Ogunwale | 687b427 | 2017-07-27 02:56:23 -0700 | [diff] [blame] | 798 | switch (windowingMode) { |
| 799 | case WINDOWING_MODE_UNDEFINED: return "undefined"; |
| 800 | case WINDOWING_MODE_FULLSCREEN: return "fullscreen"; |
| 801 | case WINDOWING_MODE_PINNED: return "pinned"; |
Wale Ogunwale | 926aade | 2017-08-29 11:24:37 -0700 | [diff] [blame] | 802 | case WINDOWING_MODE_SPLIT_SCREEN_PRIMARY: return "split-screen-primary"; |
| 803 | case WINDOWING_MODE_SPLIT_SCREEN_SECONDARY: return "split-screen-secondary"; |
Wale Ogunwale | 687b427 | 2017-07-27 02:56:23 -0700 | [diff] [blame] | 804 | case WINDOWING_MODE_FREEFORM: return "freeform"; |
| 805 | } |
| 806 | return String.valueOf(windowingMode); |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 807 | } |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 808 | |
Steven Timotius | e597ca1 | 2017-09-05 15:46:29 -0700 | [diff] [blame] | 809 | /** @hide */ |
Wale Ogunwale | 6fbde9f | 2017-08-24 07:24:12 -0700 | [diff] [blame] | 810 | public static String activityTypeToString(@ActivityType int applicationType) { |
| 811 | switch (applicationType) { |
| 812 | case ACTIVITY_TYPE_UNDEFINED: return "undefined"; |
| 813 | case ACTIVITY_TYPE_STANDARD: return "standard"; |
| 814 | case ACTIVITY_TYPE_HOME: return "home"; |
| 815 | case ACTIVITY_TYPE_RECENTS: return "recents"; |
| 816 | case ACTIVITY_TYPE_ASSISTANT: return "assistant"; |
| 817 | } |
| 818 | return String.valueOf(applicationType); |
| 819 | } |
Kazuki Takise | f85197b | 2018-06-18 18:18:36 +0900 | [diff] [blame] | 820 | |
| 821 | /** @hide */ |
| 822 | public static String alwaysOnTopToString(@AlwaysOnTop int alwaysOnTop) { |
| 823 | switch (alwaysOnTop) { |
| 824 | case ALWAYS_ON_TOP_UNDEFINED: return "undefined"; |
| 825 | case ALWAYS_ON_TOP_ON: return "on"; |
| 826 | case ALWAYS_ON_TOP_OFF: return "off"; |
| 827 | } |
| 828 | return String.valueOf(alwaysOnTop); |
| 829 | } |
Wale Ogunwale | 822e512 | 2017-07-26 06:02:24 -0700 | [diff] [blame] | 830 | } |