Don't use HW accel drawing in lock screen on lower-end devices.

This saves about 8MB in the system process because we don't need
to do HW accelerated drawing there anymore.

Change-Id: Ieaf72fe772536e12d10cf129d9338ca9fce6a6d4
diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java
index f7e5cf1..93e30af 100644
--- a/core/java/android/app/ActivityManager.java
+++ b/core/java/android/app/ActivityManager.java
@@ -18,6 +18,7 @@
 
 import com.android.internal.app.IUsageStats;
 import com.android.internal.os.PkgUsageStats;
+import com.android.internal.util.MemInfoReader;
 
 import android.content.ComponentName;
 import android.content.Context;
@@ -28,6 +29,7 @@
 import android.content.res.Configuration;
 import android.content.res.Resources;
 import android.graphics.Bitmap;
+import android.graphics.Point;
 import android.os.Debug;
 import android.os.Handler;
 import android.os.Parcel;
@@ -38,6 +40,8 @@
 import android.text.TextUtils;
 import android.util.DisplayMetrics;
 import android.util.Log;
+import android.util.Slog;
+import android.view.Display;
 
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -206,6 +210,31 @@
     }
     
     /**
+     * Used by persistent processes to determine if they are running on a
+     * higher-end device so should be okay using hardware drawing acceleration
+     * (which tends to consume a lot more RAM).
+     * @hide
+     */
+    static public boolean isHighEndGfx(Display display) {
+        MemInfoReader reader = new MemInfoReader();
+        reader.readMemInfo();
+        if (reader.getTotalSize() >= (512*1024*1024)) {
+            // If the device has at least 512MB RAM available to the kernel,
+            // we can afford the overhead of graphics acceleration.
+            return true;
+        }
+        Point p = new Point();
+        display.getRealSize(p);
+        int pixels = p.x * p.y;
+        if (pixels >= (1024*600)) {
+            // If this is a sufficiently large screen, then there are enough
+            // pixels on it that we'd really like to use hw drawing.
+            return true;
+        }
+        return false;
+    }
+
+    /**
      * Information you can retrieve about tasks that the user has most recently
      * started or visited.
      */
diff --git a/policy/src/com/android/internal/policy/impl/KeyguardViewManager.java b/policy/src/com/android/internal/policy/impl/KeyguardViewManager.java
index 6ee5861..f52bb26 100644
--- a/policy/src/com/android/internal/policy/impl/KeyguardViewManager.java
+++ b/policy/src/com/android/internal/policy/impl/KeyguardViewManager.java
@@ -18,6 +18,7 @@
 
 import com.android.internal.R;
 
+import android.app.ActivityManager;
 import android.content.Context;
 import android.content.pm.ActivityInfo;
 import android.content.res.Resources;
@@ -107,13 +108,16 @@
             int flags = WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN
                     | WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER
                     | WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING
-                    | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED
-                    | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED_SYSTEM
                     /*| WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                     | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR*/ ;
             if (!mNeedsInput) {
                 flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
             }
+            if (ActivityManager.isHighEndGfx(((WindowManager)mContext.getSystemService(
+                    Context.WINDOW_SERVICE)).getDefaultDisplay())) {
+                flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED
+                        | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED_SYSTEM;
+            }
             WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
                     stretch, stretch, WindowManager.LayoutParams.TYPE_KEYGUARD,
                     flags, PixelFormat.TRANSLUCENT);