OSDN Git Service

Merge branch 'boringdroid-x86-9.0.0' of https://github.com/boringdroid/platform_frame...
[android-x86/frameworks-base.git] / services / core / java / com / android / server / wm / WindowManagerService.java
index 7a2c28b..7f8797a 100644 (file)
@@ -126,6 +126,7 @@ import android.content.ContentResolver;
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
+import android.content.SharedPreferences;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageManager;
 import android.content.pm.PackageManagerInternal;
@@ -148,6 +149,7 @@ import android.os.Binder;
 import android.os.Build;
 import android.os.Bundle;
 import android.os.Debug;
+import android.os.Environment;
 import android.os.Handler;
 import android.os.IBinder;
 import android.os.IRemoteCallback;
@@ -169,6 +171,7 @@ import android.os.SystemProperties;
 import android.os.SystemService;
 import android.os.Trace;
 import android.os.UserHandle;
+import android.os.UserManager;
 import android.os.WorkSource;
 import android.provider.Settings;
 import android.text.format.DateUtils;
@@ -7601,4 +7604,66 @@ public class WindowManagerService extends IWindowManager.Stub
             }
         }
     }
+    // region @boringdroid
+    private static final String PACKAGE_WINDOW_BOUNDS_NAME = "package-window-bounds";
+
+    private static boolean isDataSystemDirNotReady(Context context) {
+        UserManager userManager = context.getSystemService(UserManager.class);
+        return !(userManager != null && userManager.isUserUnlockingOrUnlocked(UserHandle.myUserId()));
+    }
+
+    private static File getPackageWindowBoundsName() {
+        return new File(
+                Environment.getDataSystemCeDirectory(UserHandle.myUserId())
+                        + File.separator + PACKAGE_WINDOW_BOUNDS_NAME
+        );
+    }
+
+    /**
+     * @hide
+     */
+    public static WindowManagerService getWMSInstance() {
+        return getInstance();
+    }
+
+    /**
+     * @hide
+     */
+    public void savePackageWindowBounds(String packageName, Rect bounds) {
+        if (isDataSystemDirNotReady(mContext)) {
+            Slog.e(TAG, "Calling savePackageWindowBounds with package " + packageName
+                    + ", and bounds " + bounds + ", before file is ready");
+            return;
+        }
+        SharedPreferences sharedPreferences =
+                mContext.getSharedPreferences(getPackageWindowBoundsName(), Context.MODE_PRIVATE);
+        Rect tempBounds = new Rect(bounds);
+        sharedPreferences
+                .edit()
+                .putInt(packageName + "-left", tempBounds.left)
+                .putInt(packageName + "-top", tempBounds.top)
+                .putInt(packageName + "-right", tempBounds.right)
+                .putInt(packageName + "-bottom", tempBounds.bottom)
+                .apply();
+    }
+
+    /**
+     * @hide
+     */
+    public Rect getPackageWindowBounds(String packageName) {
+        if (isDataSystemDirNotReady(mContext)) {
+            Slog.e(TAG, "Calling getPackageWindowBounds with package " + packageName
+                    + ", before file is ready");
+            return new Rect();
+        }
+        SharedPreferences sharedPreferences =
+                mContext.getSharedPreferences(getPackageWindowBoundsName(), Context.MODE_PRIVATE);
+        return new Rect(
+                sharedPreferences.getInt(packageName + "-left", 0),
+                sharedPreferences.getInt(packageName + "-top", 0),
+                sharedPreferences.getInt(packageName + "-right", 0),
+                sharedPreferences.getInt(packageName + "-bottom", 0)
+        );
+    }
+    // endregion
 }