frameworks/base
Révision | f3b4e6b21d6372c2118cf7f200469c897b296929 (tree) |
---|---|
l'heure | 2020-06-12 00:24:15 |
Auteur | utzcoz <utzcoz@outl...> |
Commiter | utzcoz |
Support persist window bounds
1. Add methods in WMS to store/restore window bounds in
2. When resizing/moving window, save its value.
3. When launching window, use saved value as launch bounds.
This patch also disable the launch bounds in ActivityOptions, because
the starter doesn't know the new window bounds after resizing. The
Taskbar sets the launch bounds to the center position of screen
forcibly, and it will cause saved bounds can't work. Before finding a
solution to let Taskbar to manage freeform window bounds, we will
disable launch bounds of ActivityOptions.
Signed-off-by: utzcoz <utzcoz@outlook.com>
@@ -49,7 +49,13 @@ public class ActivityLaunchParamsModifier implements LaunchParamsModifier { | ||
49 | 49 | return RESULT_SKIP; |
50 | 50 | } |
51 | 51 | |
52 | - final Rect bounds = options.getLaunchBounds(); | |
52 | + // region @boringdroid | |
53 | + // Leave window bounds to wms/ams, and ignore launch bounds from starter. | |
54 | + // The starter doesn't know the current window bounds after resizing, so launch | |
55 | + // bounds will reset freeform window bounds to the default state. | |
56 | + // final Rect bounds = options.getLaunchBounds(); | |
57 | + final Rect bounds = null; | |
58 | + // endregion | |
53 | 59 | |
54 | 60 | // Bounds weren't valid. |
55 | 61 | if (bounds == null || bounds.isEmpty()) { |
@@ -92,6 +92,13 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier { | ||
92 | 92 | final Rect resultBounds = outParams.mBounds; |
93 | 93 | |
94 | 94 | if (layout == null) { |
95 | + // region @boringdroid | |
96 | + // For freeform window, we should use its launch bounds instead of recauclate its bounds. | |
97 | + if (task.inFreeformWindowingMode()) { | |
98 | + task.updateOverrideConfiguration(task.getLaunchBounds()); | |
99 | + return RESULT_CONTINUE; | |
100 | + } | |
101 | + // endregion | |
95 | 102 | positionCenter(tasks, mAvailableRect, getFreeformWidth(mAvailableRect), |
96 | 103 | getFreeformHeight(mAvailableRect), resultBounds); |
97 | 104 | return RESULT_CONTINUE; |
@@ -118,6 +125,13 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier { | ||
118 | 125 | // center. |
119 | 126 | Slog.w(TAG, "Received unsupported gravity: " + layout.gravity |
120 | 127 | + ", positioning in the center instead."); |
128 | + // region @boringdroid | |
129 | + // For freeform window, we should use its launch bounds instead of recauclate its bounds. | |
130 | + if (task.inFreeformWindowingMode()) { | |
131 | + task.updateOverrideConfiguration(task.getLaunchBounds()); | |
132 | + return RESULT_CONTINUE; | |
133 | + } | |
134 | + // endregion | |
121 | 135 | positionCenter(tasks, mAvailableRect, width, height, resultBounds); |
122 | 136 | } |
123 | 137 |
@@ -548,6 +548,10 @@ class TaskRecord extends ConfigurationContainer implements TaskWindowContainerLi | ||
548 | 548 | } |
549 | 549 | } |
550 | 550 | mWindowContainerController.resize(kept, forced); |
551 | + // region @boringdroid | |
552 | + // After window resizes its bounds(real resize and move), we should save the window bounds. | |
553 | + saveTaskBounds(); | |
554 | + // endregion | |
551 | 555 | |
552 | 556 | Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); |
553 | 557 | return kept; |
@@ -559,7 +563,31 @@ class TaskRecord extends ConfigurationContainer implements TaskWindowContainerLi | ||
559 | 563 | // TODO: Investigate combining with the resize() method above. |
560 | 564 | void resizeWindowContainer() { |
561 | 565 | mWindowContainerController.resize(false /* relayout */, false /* forced */); |
566 | + // region @boringdroid | |
567 | + // After window resizes its bounds(real resize and move), we should save the window bounds. | |
568 | + saveTaskBounds(); | |
569 | + // endregion | |
570 | + } | |
571 | + // region @boringdroid | |
572 | + private void saveTaskBounds() { | |
573 | + Rect savedBounds = new Rect(); | |
574 | + mWindowContainerController.getBounds(savedBounds); | |
575 | + String packageName = null; | |
576 | + if (realActivity != null) { | |
577 | + packageName = realActivity.getPackageName(); | |
578 | + } else if (getRootActivity() != null) { | |
579 | + packageName = getRootActivity().packageName; | |
580 | + } | |
581 | + if (mStack != null | |
582 | + && mStack.getWindowingMode() == WINDOWING_MODE_FREEFORM | |
583 | + && !savedBounds.isEmpty() | |
584 | + && packageName != null) { | |
585 | + WindowManagerService | |
586 | + .getWMSInstance() | |
587 | + .savePackageWindowBounds(packageName, savedBounds); | |
588 | + } | |
562 | 589 | } |
590 | + // endregion | |
563 | 591 | |
564 | 592 | void getWindowContainerBounds(Rect bounds) { |
565 | 593 | mWindowContainerController.getBounds(bounds); |
@@ -1895,6 +1923,32 @@ class TaskRecord extends ConfigurationContainer implements TaskWindowContainerLi | ||
1895 | 1923 | } else if (!getWindowConfiguration().persistTaskBounds()) { |
1896 | 1924 | return mStack.getOverrideBounds(); |
1897 | 1925 | } |
1926 | + // region @boringdroid | |
1927 | + if (mLastNonFullscreenBounds == null) { | |
1928 | + String packageName = null; | |
1929 | + if (realActivity != null) { | |
1930 | + packageName = realActivity.getPackageName(); | |
1931 | + } else if (getRootActivity() != null) { | |
1932 | + packageName = getRootActivity().packageName; | |
1933 | + } | |
1934 | + mLastNonFullscreenBounds = | |
1935 | + packageName != null ? | |
1936 | + WindowManagerService | |
1937 | + .getWMSInstance() | |
1938 | + .getPackageWindowBounds(packageName) | |
1939 | + : new Rect(); | |
1940 | + if (!mLastNonFullscreenBounds.isEmpty()) { | |
1941 | + return mLastNonFullscreenBounds; | |
1942 | + } | |
1943 | + getParent().getBounds(mLastNonFullscreenBounds); | |
1944 | + int width = mLastNonFullscreenBounds.width() / 2; | |
1945 | + int height = mLastNonFullscreenBounds.height() / 2; | |
1946 | + int left = mLastNonFullscreenBounds.left + width / 2; | |
1947 | + int top = mLastNonFullscreenBounds.top + height / 2; | |
1948 | + mLastNonFullscreenBounds.set(left, top , left + width, top + height); | |
1949 | + adjustForMinimalTaskDimensions(mLastNonFullscreenBounds); | |
1950 | + } | |
1951 | + // endregion | |
1898 | 1952 | return mLastNonFullscreenBounds; |
1899 | 1953 | } |
1900 | 1954 |
@@ -126,6 +126,7 @@ import android.content.ContentResolver; | ||
126 | 126 | import android.content.Context; |
127 | 127 | import android.content.Intent; |
128 | 128 | import android.content.IntentFilter; |
129 | +import android.content.SharedPreferences; | |
129 | 130 | import android.content.pm.ApplicationInfo; |
130 | 131 | import android.content.pm.PackageManager; |
131 | 132 | import android.content.pm.PackageManagerInternal; |
@@ -148,6 +149,7 @@ import android.os.Binder; | ||
148 | 149 | import android.os.Build; |
149 | 150 | import android.os.Bundle; |
150 | 151 | import android.os.Debug; |
152 | +import android.os.Environment; | |
151 | 153 | import android.os.Handler; |
152 | 154 | import android.os.IBinder; |
153 | 155 | import android.os.IRemoteCallback; |
@@ -169,6 +171,7 @@ import android.os.SystemProperties; | ||
169 | 171 | import android.os.SystemService; |
170 | 172 | import android.os.Trace; |
171 | 173 | import android.os.UserHandle; |
174 | +import android.os.UserManager; | |
172 | 175 | import android.os.WorkSource; |
173 | 176 | import android.provider.Settings; |
174 | 177 | import android.text.format.DateUtils; |
@@ -7601,4 +7604,66 @@ public class WindowManagerService extends IWindowManager.Stub | ||
7601 | 7604 | } |
7602 | 7605 | } |
7603 | 7606 | } |
7607 | + // region @boringdroid | |
7608 | + private static final String PACKAGE_WINDOW_BOUNDS_NAME = "package-window-bounds"; | |
7609 | + | |
7610 | + private static boolean isDataSystemDirNotReady(Context context) { | |
7611 | + UserManager userManager = context.getSystemService(UserManager.class); | |
7612 | + return !(userManager != null && userManager.isUserUnlockingOrUnlocked(UserHandle.myUserId())); | |
7613 | + } | |
7614 | + | |
7615 | + private static File getPackageWindowBoundsName() { | |
7616 | + return new File( | |
7617 | + Environment.getDataSystemCeDirectory(UserHandle.myUserId()) | |
7618 | + + File.separator + PACKAGE_WINDOW_BOUNDS_NAME | |
7619 | + ); | |
7620 | + } | |
7621 | + | |
7622 | + /** | |
7623 | + * @hide | |
7624 | + */ | |
7625 | + public static WindowManagerService getWMSInstance() { | |
7626 | + return getInstance(); | |
7627 | + } | |
7628 | + | |
7629 | + /** | |
7630 | + * @hide | |
7631 | + */ | |
7632 | + public void savePackageWindowBounds(String packageName, Rect bounds) { | |
7633 | + if (isDataSystemDirNotReady(mContext)) { | |
7634 | + Slog.e(TAG, "Calling savePackageWindowBounds with package " + packageName | |
7635 | + + ", and bounds " + bounds + ", before file is ready"); | |
7636 | + return; | |
7637 | + } | |
7638 | + SharedPreferences sharedPreferences = | |
7639 | + mContext.getSharedPreferences(getPackageWindowBoundsName(), Context.MODE_PRIVATE); | |
7640 | + Rect tempBounds = new Rect(bounds); | |
7641 | + sharedPreferences | |
7642 | + .edit() | |
7643 | + .putInt(packageName + "-left", tempBounds.left) | |
7644 | + .putInt(packageName + "-top", tempBounds.top) | |
7645 | + .putInt(packageName + "-right", tempBounds.right) | |
7646 | + .putInt(packageName + "-bottom", tempBounds.bottom) | |
7647 | + .apply(); | |
7648 | + } | |
7649 | + | |
7650 | + /** | |
7651 | + * @hide | |
7652 | + */ | |
7653 | + public Rect getPackageWindowBounds(String packageName) { | |
7654 | + if (isDataSystemDirNotReady(mContext)) { | |
7655 | + Slog.e(TAG, "Calling getPackageWindowBounds with package " + packageName | |
7656 | + + ", before file is ready"); | |
7657 | + return new Rect(); | |
7658 | + } | |
7659 | + SharedPreferences sharedPreferences = | |
7660 | + mContext.getSharedPreferences(getPackageWindowBoundsName(), Context.MODE_PRIVATE); | |
7661 | + return new Rect( | |
7662 | + sharedPreferences.getInt(packageName + "-left", 0), | |
7663 | + sharedPreferences.getInt(packageName + "-top", 0), | |
7664 | + sharedPreferences.getInt(packageName + "-right", 0), | |
7665 | + sharedPreferences.getInt(packageName + "-bottom", 0) | |
7666 | + ); | |
7667 | + } | |
7668 | + // endregion | |
7604 | 7669 | } |