am 668e566e: Merge "Aggressively trim memory for system_process" into lmp-dev
* commit '668e566ec250a9548d6201c6190f80306e91dcce': Aggressively trim memory for system_process
This commit is contained in:
@@ -5132,6 +5132,8 @@ public final class ActivityThread {
|
||||
// process.
|
||||
if (!ActivityManager.isHighEndGfx()) {
|
||||
HardwareRenderer.disable(true);
|
||||
} else {
|
||||
HardwareRenderer.enableForegroundTrimming();
|
||||
}
|
||||
ActivityThread thread = new ActivityThread();
|
||||
thread.attach(true);
|
||||
|
||||
@@ -186,6 +186,18 @@ public abstract class HardwareRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean sTrimForeground = false;
|
||||
|
||||
/**
|
||||
* Controls whether or not the hardware renderer should aggressively
|
||||
* trim memory. Note that this must not be set for any process that
|
||||
* uses WebView! This should be only used by system_process or similar
|
||||
* that do not go into the background.
|
||||
*/
|
||||
public static void enableForegroundTrimming() {
|
||||
sTrimForeground = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether hardware acceleration is available under any form for
|
||||
* the view hierarchy.
|
||||
|
||||
@@ -804,6 +804,9 @@ public final class ViewRootImpl implements ViewParent,
|
||||
if (mAppVisible != visible) {
|
||||
mAppVisible = visible;
|
||||
scheduleTraversals();
|
||||
if (!mAppVisible) {
|
||||
WindowManagerGlobal.trimForeground();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -375,6 +375,9 @@ public final class WindowManagerGlobal {
|
||||
mDyingViews.remove(view);
|
||||
}
|
||||
}
|
||||
if (HardwareRenderer.sTrimForeground && HardwareRenderer.isAvailable()) {
|
||||
doTrimForeground();
|
||||
}
|
||||
}
|
||||
|
||||
private int findViewLocked(View view, boolean required) {
|
||||
@@ -413,6 +416,35 @@ public final class WindowManagerGlobal {
|
||||
}
|
||||
|
||||
HardwareRenderer.trimMemory(level);
|
||||
|
||||
if (HardwareRenderer.sTrimForeground) {
|
||||
doTrimForeground();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void trimForeground() {
|
||||
if (HardwareRenderer.sTrimForeground && HardwareRenderer.isAvailable()) {
|
||||
WindowManagerGlobal wm = WindowManagerGlobal.getInstance();
|
||||
wm.doTrimForeground();
|
||||
}
|
||||
}
|
||||
|
||||
private void doTrimForeground() {
|
||||
boolean hasVisibleWindows = false;
|
||||
synchronized (mLock) {
|
||||
for (int i = mRoots.size() - 1; i >= 0; --i) {
|
||||
if (mRoots.get(i).getHostVisibility() == View.VISIBLE
|
||||
&& mRoots.get(i).mAttachInfo.mHardwareRenderer != null) {
|
||||
hasVisibleWindows = true;
|
||||
} else {
|
||||
mRoots.get(i).destroyHardwareResources();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!hasVisibleWindows) {
|
||||
HardwareRenderer.trimMemory(
|
||||
ComponentCallbacks2.TRIM_MEMORY_COMPLETE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -428,7 +460,7 @@ public final class WindowManagerGlobal {
|
||||
for (int i = 0; i < count; i++) {
|
||||
ViewRootImpl root = mRoots.get(i);
|
||||
String name = getWindowName(root);
|
||||
pw.printf("\n\t%s", name);
|
||||
pw.printf("\n\t%s (visibility=%d)", name, root.getHostVisibility());
|
||||
|
||||
HardwareRenderer renderer =
|
||||
root.getView().mAttachInfo.mHardwareRenderer;
|
||||
|
||||
@@ -295,6 +295,7 @@ public class KeyguardServiceDelegate {
|
||||
stretch, stretch, type, flags, PixelFormat.TRANSLUCENT);
|
||||
lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
|
||||
lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
|
||||
lp.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
|
||||
lp.setTitle("KeyguardScrim");
|
||||
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
|
||||
wm.addView(view, lp);
|
||||
|
||||
Reference in New Issue
Block a user