Skip to content

Commit 98365d7

Browse files
author
Jeff Brown
committed
Refactor for multi-display support.
Split WindowManagerImpl into two parts, the WindowManager interface implementation remains where it is but the global communications with the window manager are now handled by the WindowManagerGlobal class. This change greatly simplifies the challenge of having separate WindowManager instances for each Context. Removed WindowManagerImpl.getDefault(). This represents the bulk of this change. Most of the usages of this method were either to perform global functions (now handled by WindowManagerGlobal) or to obtain the default display (now handled by DisplayManager). Explicitly associate each new window with a display and make the Display object available to the View hierarchy. Add stubs for some new display manager API features. Start to split apart the concepts of display id and layer stack. since they operate at different layers of abstraction. While it's true that each logical display uniquely corresponds to a surface flinger layer stack, it is not necessarily the case that they must use the same ids. Added Display.getLayerStack() and started using it in places where it was relatively easy to do. Change-Id: I29ed909114dec86807c4d3a5059c3fa0358bea61
1 parent 848c2dc commit 98365d7

File tree

57 files changed

+1101
-888
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1101
-888
lines changed

api/current.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9981,6 +9981,15 @@ package android.hardware {
99819981
package android.hardware.display {
99829982

99839983
public final class DisplayManager {
9984+
method public android.view.Display getDisplay(int, android.content.Context);
9985+
method public void registerDisplayListener(android.hardware.display.DisplayManager.DisplayListener, android.os.Handler);
9986+
method public void unregisterDisplayListener(android.hardware.display.DisplayManager.DisplayListener);
9987+
}
9988+
9989+
public static abstract interface DisplayManager.DisplayListener {
9990+
method public abstract void onDisplayAdded(int);
9991+
method public abstract void onDisplayChanged(int);
9992+
method public abstract void onDisplayRemoved(int);
99849993
}
99859994

99869995
}
@@ -24579,6 +24588,7 @@ package android.view {
2457924588
method public final android.content.Context getContext();
2458024589
method protected android.view.ContextMenu.ContextMenuInfo getContextMenuInfo();
2458124590
method public static int getDefaultSize(int, int);
24591+
method public android.view.Display getDisplay();
2458224592
method public final int[] getDrawableState();
2458324593
method public android.graphics.Bitmap getDrawingCache();
2458424594
method public android.graphics.Bitmap getDrawingCache(boolean);

core/java/android/app/Activity.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
import android.view.ViewManager;
7575
import android.view.Window;
7676
import android.view.WindowManager;
77-
import android.view.WindowManagerImpl;
77+
import android.view.WindowManagerGlobal;
7878
import android.view.accessibility.AccessibilityEvent;
7979
import android.widget.AdapterView;
8080

@@ -5018,7 +5018,9 @@ final void attach(Context context, ActivityThread aThread,
50185018
mEmbeddedID = id;
50195019
mLastNonConfigurationInstances = lastNonConfigurationInstances;
50205020

5021-
mWindow.setWindowManager(null, mToken, mComponent.flattenToString(),
5021+
mWindow.setWindowManager(
5022+
(WindowManager)context.getSystemService(Context.WINDOW_SERVICE),
5023+
mToken, mComponent.flattenToString(),
50225024
(info.flags & ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0);
50235025
if (mParent != null) {
50245026
mWindow.setContainer(mParent.getWindow());
@@ -5065,7 +5067,7 @@ final void performRestart() {
50655067
if (mStopped) {
50665068
mStopped = false;
50675069
if (mToken != null && mParent == null) {
5068-
WindowManagerImpl.getDefault().setStoppedState(mToken, false);
5070+
WindowManagerGlobal.getInstance().setStoppedState(mToken, false);
50695071
}
50705072

50715073
synchronized (mManagedCursors) {
@@ -5165,7 +5167,7 @@ final void performStop() {
51655167
}
51665168

51675169
if (mToken != null && mParent == null) {
5168-
WindowManagerImpl.getDefault().setStoppedState(mToken, true);
5170+
WindowManagerGlobal.getInstance().setStoppedState(mToken, true);
51695171
}
51705172

51715173
mFragments.dispatchStop();

core/java/android/app/ActivityManager.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import android.content.res.Resources;
3131
import android.graphics.Bitmap;
3232
import android.graphics.Point;
33+
import android.hardware.display.DisplayManager;
3334
import android.os.Binder;
3435
import android.os.Bundle;
3536
import android.os.Debug;
@@ -366,14 +367,16 @@ static public int staticGetLargeMemoryClass() {
366367
* (which tends to consume a lot more RAM).
367368
* @hide
368369
*/
369-
static public boolean isHighEndGfx(Display display) {
370+
static public boolean isHighEndGfx() {
370371
MemInfoReader reader = new MemInfoReader();
371372
reader.readMemInfo();
372373
if (reader.getTotalSize() >= (512*1024*1024)) {
373374
// If the device has at least 512MB RAM available to the kernel,
374375
// we can afford the overhead of graphics acceleration.
375376
return true;
376377
}
378+
379+
Display display = DisplayManager.getInstance().getRealDisplay(Display.DEFAULT_DISPLAY);
377380
Point p = new Point();
378381
display.getRealSize(p);
379382
int pixels = p.x * p.y;

core/java/android/app/ActivityThread.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import android.database.sqlite.SQLiteDebug.DbStats;
4343
import android.graphics.Bitmap;
4444
import android.graphics.Canvas;
45+
import android.hardware.display.DisplayManager;
4546
import android.net.IConnectivityManager;
4647
import android.net.Proxy;
4748
import android.net.ProxyProperties;
@@ -79,7 +80,7 @@
7980
import android.view.ViewRootImpl;
8081
import android.view.Window;
8182
import android.view.WindowManager;
82-
import android.view.WindowManagerImpl;
83+
import android.view.WindowManagerGlobal;
8384
import android.renderscript.RenderScript;
8485

8586
import com.android.internal.os.BinderInternal;
@@ -1055,7 +1056,7 @@ private Debug.MemoryInfo dumpMemInfo(PrintWriter pw, boolean checkin, boolean al
10551056
@Override
10561057
public void dumpGfxInfo(FileDescriptor fd, String[] args) {
10571058
dumpGraphicsInfo(fd);
1058-
WindowManagerImpl.getDefault().dumpGfxInfo(fd);
1059+
WindowManagerGlobal.getInstance().dumpGfxInfo(fd);
10591060
}
10601061

10611062
@Override
@@ -1569,7 +1570,7 @@ DisplayMetrics getDisplayMetricsLocked(CompatibilityInfo ci, boolean forceUpdate
15691570

15701571
CompatibilityInfoHolder cih = new CompatibilityInfoHolder();
15711572
cih.set(ci);
1572-
Display d = WindowManagerImpl.getDefault().makeCompatible(cih).getDefaultDisplay();
1573+
Display d = displayManager.getCompatibleDisplay(Display.DEFAULT_DISPLAY, cih);
15731574
d.getMetrics(dm);
15741575
//Slog.i("foo", "New metrics: w=" + metrics.widthPixels + " h="
15751576
// + metrics.heightPixels + " den=" + metrics.density
@@ -2641,7 +2642,7 @@ static final void cleanUpPendingRemoveWindows(ActivityClientRecord r) {
26412642
r.mPendingRemoveWindowManager.removeViewImmediate(r.mPendingRemoveWindow);
26422643
IBinder wtoken = r.mPendingRemoveWindow.getWindowToken();
26432644
if (wtoken != null) {
2644-
WindowManagerImpl.getDefault().closeAll(wtoken,
2645+
WindowManagerGlobal.getInstance().closeAll(wtoken,
26452646
r.activity.getClass().getName(), "Activity");
26462647
}
26472648
}
@@ -3176,7 +3177,7 @@ private void handleUpdatePackageCompatibilityInfo(UpdateCompatibilityData data)
31763177
apk.mCompatibilityInfo.set(data.info);
31773178
}
31783179
handleConfigurationChanged(mConfiguration, data.info);
3179-
WindowManagerImpl.getDefault().reportNewConfiguration(mConfiguration);
3180+
WindowManagerGlobal.getInstance().reportNewConfiguration(mConfiguration);
31803181
}
31813182

31823183
private void deliverResults(ActivityClientRecord r, List<ResultInfo> results) {
@@ -3365,7 +3366,7 @@ private void handleDestroyActivity(IBinder token, boolean finishing,
33653366
}
33663367
}
33673368
if (wtoken != null && r.mPendingRemoveWindow == null) {
3368-
WindowManagerImpl.getDefault().closeAll(wtoken,
3369+
WindowManagerGlobal.getInstance().closeAll(wtoken,
33693370
r.activity.getClass().getName(), "Activity");
33703371
}
33713372
r.activity.mDecor = null;
@@ -3377,7 +3378,7 @@ private void handleDestroyActivity(IBinder token, boolean finishing,
33773378
// by the app will leak. Well we try to warning them a lot
33783379
// about leaking windows, because that is a bug, so if they are
33793380
// using this recreate facility then they get to live with leaks.
3380-
WindowManagerImpl.getDefault().closeAll(token,
3381+
WindowManagerGlobal.getInstance().closeAll(token,
33813382
r.activity.getClass().getName(), "Activity");
33823383
}
33833384

@@ -3805,7 +3806,7 @@ final void handleConfigurationChanged(Configuration config, CompatibilityInfo co
38053806
}
38063807

38073808
// Cleanup hardware accelerated stuff
3808-
WindowManagerImpl.getDefault().trimLocalMemory();
3809+
WindowManagerGlobal.getInstance().trimLocalMemory();
38093810

38103811
freeTextLayoutCachesIfNeeded(configDiff);
38113812

@@ -3945,7 +3946,7 @@ final void handleLowMemory() {
39453946
final void handleTrimMemory(int level) {
39463947
if (DEBUG_MEMORY_TRIM) Slog.v(TAG, "Trimming memory to level: " + level);
39473948

3948-
final WindowManagerImpl windowManager = WindowManagerImpl.getDefault();
3949+
final WindowManagerGlobal windowManager = WindowManagerGlobal.getInstance();
39493950
windowManager.startTrimMemory(level);
39503951

39513952
ArrayList<ComponentCallbacks2> callbacks;
@@ -3958,7 +3959,7 @@ final void handleTrimMemory(int level) {
39583959
callbacks.get(i).onTrimMemory(level);
39593960
}
39603961

3961-
windowManager.endTrimMemory();
3962+
windowManager.endTrimMemory();
39623963
}
39633964

39643965
private void setupGraphicsSupport(LoadedApk info, File cacheDir) {
@@ -4011,8 +4012,7 @@ private void handleBindApplication(AppBindData data) {
40114012
// Persistent processes on low-memory devices do not get to
40124013
// use hardware accelerated drawing, since this can add too much
40134014
// overhead to the process.
4014-
final Display display = WindowManagerImpl.getDefault().getDefaultDisplay();
4015-
if (!ActivityManager.isHighEndGfx(display)) {
4015+
if (!ActivityManager.isHighEndGfx()) {
40164016
HardwareRenderer.disable(false);
40174017
}
40184018
}

core/java/android/app/ContextImpl.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@
9595
import android.content.ClipboardManager;
9696
import android.util.AndroidRuntimeException;
9797
import android.util.Log;
98+
import android.view.CompatibilityInfoHolder;
9899
import android.view.ContextThemeWrapper;
100+
import android.view.Display;
99101
import android.view.WindowManagerImpl;
100102
import android.view.accessibility.AccessibilityManager;
101103
import android.view.inputmethod.InputMethodManager;
@@ -499,8 +501,8 @@ public Object createService(ContextImpl ctx) {
499501

500502
registerService(WINDOW_SERVICE, new ServiceFetcher() {
501503
public Object getService(ContextImpl ctx) {
502-
return WindowManagerImpl.getDefault().makeCompatible(
503-
ctx.mPackageInfo.mCompatibilityInfo);
504+
return new WindowManagerImpl(ctx.getOuterContext(),
505+
Display.DEFAULT_DISPLAY);
504506
}});
505507

506508
registerService(USER_SERVICE, new ServiceFetcher() {
@@ -1609,6 +1611,11 @@ public boolean isRestricted() {
16091611
return mRestricted;
16101612
}
16111613

1614+
@Override
1615+
public CompatibilityInfoHolder getCompatibilityInfo() {
1616+
return mPackageInfo.mCompatibilityInfo;
1617+
}
1618+
16121619
private File getDataDirFile() {
16131620
if (mPackageInfo != null) {
16141621
return mPackageInfo.getDataDirFile();

core/java/android/app/KeyguardManager.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616

1717
package android.app;
1818

19-
import android.content.Context;
2019
import android.os.Binder;
2120
import android.os.RemoteException;
2221
import android.os.IBinder;
23-
import android.os.ServiceManager;
2422
import android.view.IWindowManager;
2523
import android.view.IOnKeyguardExitResult;
24+
import android.view.WindowManagerGlobal;
2625

2726
/**
2827
* Class that can be used to lock and unlock the keyboard. Get an instance of this
@@ -111,7 +110,7 @@ public interface OnKeyguardExitResult {
111110

112111

113112
KeyguardManager() {
114-
mWM = IWindowManager.Stub.asInterface(ServiceManager.getService(Context.WINDOW_SERVICE));
113+
mWM = WindowManagerGlobal.getWindowManagerService();
115114
}
116115

117116
/**

core/java/android/app/WallpaperManager.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import android.util.Log;
4444
import android.view.ViewRootImpl;
4545
import android.view.WindowManager;
46+
import android.view.WindowManagerGlobal;
4647

4748
import java.io.FileOutputStream;
4849
import java.io.IOException;
@@ -689,7 +690,7 @@ public void suggestDesiredDimensions(int minimumWidth, int minimumHeight) {
689690
public void setWallpaperOffsets(IBinder windowToken, float xOffset, float yOffset) {
690691
try {
691692
//Log.v(TAG, "Sending new wallpaper offsets from app...");
692-
ViewRootImpl.getWindowSession(mContext.getMainLooper()).setWallpaperPosition(
693+
WindowManagerGlobal.getWindowSession(mContext.getMainLooper()).setWallpaperPosition(
693694
windowToken, xOffset, yOffset, mWallpaperXStep, mWallpaperYStep);
694695
//Log.v(TAG, "...app returning after sending offsets!");
695696
} catch (RemoteException e) {
@@ -727,7 +728,7 @@ public void sendWallpaperCommand(IBinder windowToken, String action,
727728
int x, int y, int z, Bundle extras) {
728729
try {
729730
//Log.v(TAG, "Sending new wallpaper offsets from app...");
730-
ViewRootImpl.getWindowSession(mContext.getMainLooper()).sendWallpaperCommand(
731+
WindowManagerGlobal.getWindowSession(mContext.getMainLooper()).sendWallpaperCommand(
731732
windowToken, action, x, y, z, extras, false);
732733
//Log.v(TAG, "...app returning after sending offsets!");
733734
} catch (RemoteException e) {
@@ -747,7 +748,7 @@ public void sendWallpaperCommand(IBinder windowToken, String action,
747748
*/
748749
public void clearWallpaperOffsets(IBinder windowToken) {
749750
try {
750-
ViewRootImpl.getWindowSession(mContext.getMainLooper()).setWallpaperPosition(
751+
WindowManagerGlobal.getWindowSession(mContext.getMainLooper()).setWallpaperPosition(
751752
windowToken, -1, -1, -1, -1);
752753
} catch (RemoteException e) {
753754
// Ignore.

core/java/android/content/Context.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import android.os.Looper;
3535
import android.os.UserHandle;
3636
import android.util.AttributeSet;
37+
import android.view.CompatibilityInfoHolder;
3738

3839
import java.io.File;
3940
import java.io.FileInputStream;
@@ -2463,6 +2464,16 @@ public abstract Context createPackageContext(String packageName,
24632464
*/
24642465
public abstract Context createConfigurationContext(Configuration overrideConfiguration);
24652466

2467+
/**
2468+
* Gets the compatibility info holder for this context. This information
2469+
* is provided on a per-application basis and is used to simulate lower density
2470+
* display metrics for legacy applications.
2471+
*
2472+
* @return The compatibility info holder, or null if not required by the application.
2473+
* @hide
2474+
*/
2475+
public abstract CompatibilityInfoHolder getCompatibilityInfo();
2476+
24662477
/**
24672478
* Indicates whether this Context is restricted.
24682479
*

core/java/android/content/ContextWrapper.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import android.os.Handler;
3232
import android.os.Looper;
3333
import android.os.UserHandle;
34+
import android.view.CompatibilityInfoHolder;
3435

3536
import java.io.File;
3637
import java.io.FileInputStream;
@@ -543,4 +544,10 @@ public Context createConfigurationContext(Configuration overrideConfiguration) {
543544
public boolean isRestricted() {
544545
return mBase.isRestricted();
545546
}
547+
548+
/** @hide */
549+
@Override
550+
public CompatibilityInfoHolder getCompatibilityInfo() {
551+
return mBase.getCompatibilityInfo();
552+
}
546553
}

0 commit comments

Comments
 (0)