summaryrefslogtreecommitdiff
path: root/packages/FakeOemFeatures
diff options
context:
space:
mode:
authorAndrii Kulian <akulian@google.com>2020-01-26 20:59:07 -0800
committerAndrii Kulian <akulian@google.com>2020-01-31 01:15:21 +0000
commite57f2dc246532d54229046d319d7b907b23288b3 (patch)
treedbb2b0b84814f0fffaf7b80f4c94c4820dfbf2bf /packages/FakeOemFeatures
parentea325634d3c465817c48f31ad2d5b047661128a6 (diff)
Exempt-From-Owner-Approval: Fix usages of WindowManager.getDefaultDisplay() in f/b
Replace the existing usages of now-deprecated API WindowManager.getDefaultDisplay() with WindowMetrics or Context.getDisplay() in frameworks/base. Bug: 128338354 Test: Build, auto test Change-Id: I02d38a022c5e0e6e9d699f03d35b65d6c8126da9
Diffstat (limited to 'packages/FakeOemFeatures')
-rw-r--r--packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeApp.java21
-rw-r--r--packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeBackgroundService.java23
2 files changed, 33 insertions, 11 deletions
diff --git a/packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeApp.java b/packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeApp.java
index c9e0d0ab351d..d4eb2a9c75d0 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,9 +28,11 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
+import android.hardware.display.DisplayManager;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
+import android.util.Size;
import android.util.Slog;
import android.view.Display;
import android.view.ViewGroup;
@@ -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();
+ Size maxWindowSize = wm.getMaximumWindowMetrics().getSize();
+ int maxSize = Math.max(maxWindowSize.getWidth(), maxWindowSize.getHeight());
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..df00eee63b50 100644
--- a/packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeBackgroundService.java
+++ b/packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeBackgroundService.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 java.util.ArrayList;
import java.util.Random;
@@ -23,9 +26,11 @@ import android.app.Dialog;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
+import android.hardware.display.DisplayManager;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
+import android.util.Size;
import android.view.Display;
import android.view.ViewGroup;
import android.view.WindowManager;
@@ -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);
+ Size maxWindowSize = wm.getMaximumWindowMetrics().getSize();
+ int maxSize = Math.max(maxWindowSize.getWidth(), maxWindowSize.getHeight());
maxSize *= 2;
lp.x = maxSize;
lp.y = maxSize;