am cfb046de: am 2c09a9c0: am 5520610c: Merge "Make adb shell am display-size persistent." into honeycomb-mr2

* commit 'cfb046dead49568de6f6808a697e0508ef39a3a6':
  Make adb shell am display-size persistent.
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 570b801..8ee18f7 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -2563,6 +2563,13 @@
             "lock_screen_owner_info_enabled";
 
         /**
+         * The saved value for WindowManagerService.setForcedDisplaySize().
+         * Two integers separated by a comma.  If unset, then use the real display size.
+         * @hide
+         */
+        public static final String DISPLAY_SIZE_FORCED = "display_size_forced";
+
+        /**
          * Whether assisted GPS should be enabled or not.
          * @hide
          */
diff --git a/services/java/com/android/server/wm/WindowManagerService.java b/services/java/com/android/server/wm/WindowManagerService.java
index 92c490e..79dbfd6 100644
--- a/services/java/com/android/server/wm/WindowManagerService.java
+++ b/services/java/com/android/server/wm/WindowManagerService.java
@@ -6000,8 +6000,12 @@
             mActivityManager.updateConfiguration(null);
         } catch (RemoteException e) {
         }
-        
+
         mPolicy.systemReady();
+
+        synchronized (mWindowMap) {
+            readForcedDisplaySizeLocked();
+        }
     }
 
     // This is an animation that does nothing: it just immediately finishes
@@ -6517,6 +6521,8 @@
                         ? shortDimen : mInitialDisplayHeight;
             }
             setForcedDisplaySizeLocked(width, height);
+            Settings.Secure.putString(mContext.getContentResolver(),
+                    Settings.Secure.DISPLAY_SIZE_FORCED, width + "," + height);
         }
     }
 
@@ -6563,7 +6569,29 @@
         }
     }
 
+    private void readForcedDisplaySizeLocked() {
+        final String str = Settings.Secure.getString(mContext.getContentResolver(),
+                Settings.Secure.DISPLAY_SIZE_FORCED);
+        if (str == null || str.length() == 0) {
+            return;
+        }
+        final int pos = str.indexOf(',');
+        if (pos <= 0 || str.lastIndexOf(',') != pos) {
+            return;
+        }
+        int width, height;
+        try {
+            width = Integer.parseInt(str.substring(0, pos));
+            height = Integer.parseInt(str.substring(pos+1));
+        } catch (NumberFormatException ex) {
+            return;
+        }
+        setForcedDisplaySizeLocked(width, height);
+    }
+
     private void setForcedDisplaySizeLocked(int width, int height) {
+        Slog.i(TAG, "Using new display size: " + width + "x" + height);
+
         mBaseDisplayWidth = width;
         mBaseDisplayHeight = height;
         mPolicy.setInitialDisplaySize(mBaseDisplayWidth, mBaseDisplayHeight);
@@ -6593,6 +6621,8 @@
     public void clearForcedDisplaySize() {
         synchronized(mWindowMap) {
             setForcedDisplaySizeLocked(mInitialDisplayWidth, mInitialDisplayHeight);
+            Settings.Secure.putString(mContext.getContentResolver(),
+                    Settings.Secure.DISPLAY_SIZE_FORCED, "");
         }
     }