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;
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;
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;
}
}
}
+ // 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
}