diff options
author | Xin Li <delphij@google.com> | 2020-08-31 21:21:38 -0700 |
---|---|---|
committer | Xin Li <delphij@google.com> | 2020-08-31 21:21:38 -0700 |
commit | 628590d7ec80e10a3fc24b1c18a1afb55cca10a8 (patch) | |
tree | 4b1c3f52d86d7fb53afbe9e9438468588fa489f8 /packages/FakeOemFeatures/src | |
parent | b11b8ec3aec8bb42f2c07e1c5ac7942da293baa8 (diff) | |
parent | d2d3a20624d968199353ccf6ddbae6f3ac39c9af (diff) |
Merge Android R (rvc-dev-plus-aosp-without-vendor@6692709)
Bug: 166295507
Merged-In: I3d92a6de21a938f6b352ec26dc23420c0fe02b27
Change-Id: Ifdb80563ef042738778ebb8a7581a97c4e3d96e2
Diffstat (limited to 'packages/FakeOemFeatures/src')
-rw-r--r-- | packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeApp.java | 21 | ||||
-rw-r--r-- | packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeBackgroundService.java | 27 |
2 files changed, 35 insertions, 13 deletions
diff --git a/packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeApp.java b/packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeApp.java index c9e0d0ab351d..a2da23e918d2 100644 --- a/packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeApp.java +++ b/packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeApp.java @@ -16,6 +16,9 @@ package com.android.fakeoemfeatures; +import static android.view.Display.DEFAULT_DISPLAY; +import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; + import android.app.ActivityManager; import android.app.ActivityThread; import android.app.AlertDialog; @@ -25,6 +28,8 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; +import android.graphics.Rect; +import android.hardware.display.DisplayManager; import android.os.Handler; import android.os.IBinder; import android.os.Message; @@ -94,8 +99,13 @@ public class FakeApp extends Application { return; } - final WindowManager wm = (WindowManager)getSystemService(Context.WINDOW_SERVICE); - final Display display = wm.getDefaultDisplay(); + // Construct an instance of WindowManager to add the window of TYPE_APPLICATION_OVERLAY to + // the default display. + final DisplayManager dm = getSystemService(DisplayManager.class); + final Display defaultDisplay = dm.getDisplay(DEFAULT_DISPLAY); + final Context windowContext = createDisplayContext(defaultDisplay) + .createWindowContext(TYPE_APPLICATION_OVERLAY, null /* options */); + final WindowManager wm = windowContext.getSystemService(WindowManager.class); // Check to make sure we are not running on a user build. If this // is a user build, WARN! Do not want! @@ -108,14 +118,14 @@ public class FakeApp extends Application { builder.setCancelable(false); builder.setPositiveButton("I understand", null); Dialog dialog = builder.create(); - dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY); + dialog.getWindow().setType(TYPE_APPLICATION_OVERLAY); dialog.show(); } // Make a fake window that is always around eating graphics resources. FakeView view = new FakeView(this); WindowManager.LayoutParams lp = new WindowManager.LayoutParams( - WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY, + TYPE_APPLICATION_OVERLAY, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); @@ -124,7 +134,8 @@ public class FakeApp extends Application { } lp.width = ViewGroup.LayoutParams.MATCH_PARENT; lp.height = ViewGroup.LayoutParams.MATCH_PARENT; - int maxSize = display.getMaximumSizeDimension(); + Rect maxWindowBounds = wm.getMaximumWindowMetrics().getBounds(); + int maxSize = Math.max(maxWindowBounds.width(), maxWindowBounds.height()); maxSize *= 2; lp.x = maxSize; lp.y = maxSize; diff --git a/packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeBackgroundService.java b/packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeBackgroundService.java index ff09000b7bbd..e2120f80f1c9 100644 --- a/packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeBackgroundService.java +++ b/packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeBackgroundService.java @@ -16,13 +16,15 @@ package com.android.fakeoemfeatures; -import java.util.ArrayList; -import java.util.Random; +import static android.view.Display.DEFAULT_DISPLAY; +import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; import android.app.Dialog; import android.app.Service; import android.content.Context; import android.content.Intent; +import android.graphics.Rect; +import android.hardware.display.DisplayManager; import android.os.Handler; import android.os.IBinder; import android.os.Message; @@ -30,6 +32,9 @@ import android.view.Display; import android.view.ViewGroup; import android.view.WindowManager; +import java.util.ArrayList; +import java.util.Random; + public class FakeBackgroundService extends Service { final ArrayList<int[]> mAllocs = new ArrayList<int[]>(); @@ -68,13 +73,15 @@ public class FakeBackgroundService extends Service { super.onCreate(); mHandler.sendEmptyMessageDelayed(MSG_TICK, TICK_DELAY); - final WindowManager wm = (WindowManager)getSystemService(Context.WINDOW_SERVICE); - final Display display = wm.getDefaultDisplay(); + final DisplayManager dm = getSystemService(DisplayManager.class); + final Display display = dm.getDisplay(DEFAULT_DISPLAY); + final Context windowContext = createDisplayContext(display) + .createWindowContext(TYPE_APPLICATION_OVERLAY, null /* options */); // Make a fake window that is always around eating graphics resources. - FakeView view = new FakeView(this); - Dialog dialog = new Dialog(this, android.R.style.Theme_Holo_Dialog); - dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY); + FakeView view = new FakeView(windowContext); + Dialog dialog = new Dialog(windowContext, android.R.style.Theme_Holo_Dialog); + dialog.getWindow().setType(TYPE_APPLICATION_OVERLAY); dialog.getWindow().setFlags( WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE @@ -89,7 +96,11 @@ public class FakeBackgroundService extends Service { dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); WindowManager.LayoutParams lp = dialog.getWindow().getAttributes(); - int maxSize = display.getMaximumSizeDimension(); + // Create an instance of WindowManager that is adjusted to the area of the display dedicated + // for windows with type TYPE_APPLICATION_OVERLAY. + final WindowManager wm = windowContext.getSystemService(WindowManager.class); + Rect maxWindowBounds = wm.getMaximumWindowMetrics().getBounds(); + int maxSize = Math.max(maxWindowBounds.width(), maxWindowBounds.height()); maxSize *= 2; lp.x = maxSize; lp.y = maxSize; |