• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

frameworks/base


Commit MetaInfo

Révisionf3b4e6b21d6372c2118cf7f200469c897b296929 (tree)
l'heure2020-06-12 00:24:15
Auteurutzcoz <utzcoz@outl...>
Commiterutzcoz

Message de Log

Support persist window bounds

1. Add methods in WMS to store/restore window bounds in

SharedPreferences.

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>

Change Summary

Modification

--- a/services/core/java/com/android/server/am/ActivityLaunchParamsModifier.java
+++ b/services/core/java/com/android/server/am/ActivityLaunchParamsModifier.java
@@ -49,7 +49,13 @@ public class ActivityLaunchParamsModifier implements LaunchParamsModifier {
4949 return RESULT_SKIP;
5050 }
5151
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
5359
5460 // Bounds weren't valid.
5561 if (bounds == null || bounds.isEmpty()) {
--- a/services/core/java/com/android/server/am/TaskLaunchParamsModifier.java
+++ b/services/core/java/com/android/server/am/TaskLaunchParamsModifier.java
@@ -92,6 +92,13 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {
9292 final Rect resultBounds = outParams.mBounds;
9393
9494 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
95102 positionCenter(tasks, mAvailableRect, getFreeformWidth(mAvailableRect),
96103 getFreeformHeight(mAvailableRect), resultBounds);
97104 return RESULT_CONTINUE;
@@ -118,6 +125,13 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {
118125 // center.
119126 Slog.w(TAG, "Received unsupported gravity: " + layout.gravity
120127 + ", 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
121135 positionCenter(tasks, mAvailableRect, width, height, resultBounds);
122136 }
123137
--- a/services/core/java/com/android/server/am/TaskRecord.java
+++ b/services/core/java/com/android/server/am/TaskRecord.java
@@ -548,6 +548,10 @@ class TaskRecord extends ConfigurationContainer implements TaskWindowContainerLi
548548 }
549549 }
550550 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
551555
552556 Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
553557 return kept;
@@ -559,7 +563,31 @@ class TaskRecord extends ConfigurationContainer implements TaskWindowContainerLi
559563 // TODO: Investigate combining with the resize() method above.
560564 void resizeWindowContainer() {
561565 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+ }
562589 }
590+ // endregion
563591
564592 void getWindowContainerBounds(Rect bounds) {
565593 mWindowContainerController.getBounds(bounds);
@@ -1895,6 +1923,32 @@ class TaskRecord extends ConfigurationContainer implements TaskWindowContainerLi
18951923 } else if (!getWindowConfiguration().persistTaskBounds()) {
18961924 return mStack.getOverrideBounds();
18971925 }
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
18981952 return mLastNonFullscreenBounds;
18991953 }
19001954
--- a/services/core/java/com/android/server/wm/WindowManagerService.java
+++ b/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -126,6 +126,7 @@ import android.content.ContentResolver;
126126 import android.content.Context;
127127 import android.content.Intent;
128128 import android.content.IntentFilter;
129+import android.content.SharedPreferences;
129130 import android.content.pm.ApplicationInfo;
130131 import android.content.pm.PackageManager;
131132 import android.content.pm.PackageManagerInternal;
@@ -148,6 +149,7 @@ import android.os.Binder;
148149 import android.os.Build;
149150 import android.os.Bundle;
150151 import android.os.Debug;
152+import android.os.Environment;
151153 import android.os.Handler;
152154 import android.os.IBinder;
153155 import android.os.IRemoteCallback;
@@ -169,6 +171,7 @@ import android.os.SystemProperties;
169171 import android.os.SystemService;
170172 import android.os.Trace;
171173 import android.os.UserHandle;
174+import android.os.UserManager;
172175 import android.os.WorkSource;
173176 import android.provider.Settings;
174177 import android.text.format.DateUtils;
@@ -7601,4 +7604,66 @@ public class WindowManagerService extends IWindowManager.Stub
76017604 }
76027605 }
76037606 }
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
76047669 }