summaryrefslogtreecommitdiff
path: root/packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeBackgroundService.java
diff options
context:
space:
mode:
Diffstat (limited to 'packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeBackgroundService.java')
-rw-r--r--packages/FakeOemFeatures/src/com/android/fakeoemfeatures/FakeBackgroundService.java23
1 files changed, 17 insertions, 6 deletions
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;