Fix issue #2095422: Some fades from opaque to transparent don't work

ViewRoot was using Surface.clear(), which has different behavior
in different processes -- in the system process it would kill the
surface, causing all windows in that process to immediately disappear
instead of animating away.

This change makes Surface.release() public and uses that instead.  It
also renames Surface.clear() to Surface.destroy().

Also fixed some issues in the window manager that were causing the
wallpaper to not get immediately resized when the orientation changes
and its target window is removed and re-added.

Change-Id: I2a992e365cf5747511f0bf1193db32dc2525b218
diff --git a/core/java/android/service/wallpaper/WallpaperService.java b/core/java/android/service/wallpaper/WallpaperService.java
index 2cdfc66..2e4f1d2 100644
--- a/core/java/android/service/wallpaper/WallpaperService.java
+++ b/core/java/android/service/wallpaper/WallpaperService.java
@@ -377,6 +377,7 @@
                     if (!mCreated) {
                         mLayout.type = mIWallpaperEngine.mWindowType;
                         mLayout.gravity = Gravity.LEFT|Gravity.TOP;
+                        mLayout.setTitle(WallpaperService.this.getClass().getName());
                         mLayout.windowAnimations =
                                 com.android.internal.R.style.Animation_Wallpaper;
                         mSession.add(mWindow, mLayout, View.VISIBLE, mContentInsets);
@@ -558,7 +559,7 @@
                     mSession.remove(mWindow);
                 } catch (RemoteException e) {
                 }
-                mSurfaceHolder.mSurface.clear();
+                mSurfaceHolder.mSurface.release();
                 mCreated = false;
             }
         }
diff --git a/core/java/android/view/Surface.java b/core/java/android/view/Surface.java
index 5cecac3..b85667b 100644
--- a/core/java/android/view/Surface.java
+++ b/core/java/android/view/Surface.java
@@ -181,7 +181,7 @@
     public Surface(SurfaceSession s,
             int pid, int display, int w, int h, int format, int flags)
         throws OutOfResourcesException {
-        mCanvas = new Canvas();
+        mCanvas = new CompatibleCanvas();
         init(s,pid,display,w,h,format,flags);
     }
 
@@ -271,8 +271,12 @@
      */
     public native   boolean isValid();
     
-    /** Call this free the surface up. {@hide} */
-    public native   void clear();
+    /** Free all server-side state associated with this surface and
+     * release this object's reference. {@hide} */
+    public native void destroy();
+    
+    /** Release the local reference to the server-side surface. @hide */
+    public native void release();
     
     /** draw into a surface */
     public Canvas lockCanvas(Rect dirty) throws OutOfResourcesException, IllegalArgumentException
@@ -400,6 +404,4 @@
             throws OutOfResourcesException;
 
     private native void init(Parcel source);
-    
-    private native void release();
 }
diff --git a/core/java/android/view/ViewRoot.java b/core/java/android/view/ViewRoot.java
index fafe00f..b61465a 100644
--- a/core/java/android/view/ViewRoot.java
+++ b/core/java/android/view/ViewRoot.java
@@ -1575,7 +1575,7 @@
         if (mUseGL) {
             destroyGL();
         }
-        mSurface.clear();
+        mSurface.release();
 
         try {
             sWindowSession.remove(mWindow);
@@ -2532,7 +2532,7 @@
                     }
                 }
 
-                mSurface.clear();
+                mSurface.release();
             }
             if (mAdded) {
                 mAdded = false;
diff --git a/core/jni/android_view_Surface.cpp b/core/jni/android_view_Surface.cpp
index 02677f4..40c8aa0 100644
--- a/core/jni/android_view_Surface.cpp
+++ b/core/jni/android_view_Surface.cpp
@@ -214,7 +214,7 @@
     setSurface(env, clazz, rhs);
 }
 
-static void Surface_clear(JNIEnv* env, jobject clazz, uintptr_t *ostack)
+static void Surface_destroy(JNIEnv* env, jobject clazz, uintptr_t *ostack)
 {
     const sp<SurfaceControl>& surface(getSurfaceControl(env, clazz));
     if (SurfaceControl::isValid(surface)) {
@@ -622,7 +622,7 @@
     {"nativeClassInit",     "()V",  (void*)nativeClassInit },
     {"init",                "(Landroid/view/SurfaceSession;IIIIII)V",  (void*)Surface_init },
     {"init",                "(Landroid/os/Parcel;)V",  (void*)Surface_initParcel },
-    {"clear",               "()V",  (void*)Surface_clear },
+    {"destroy",             "()V",  (void*)Surface_destroy },
     {"release",             "()V",  (void*)Surface_release },
 	{"copyFrom",            "(Landroid/view/Surface;)V",  (void*)Surface_copyFrom },
 	{"isValid",             "()Z",  (void*)Surface_isValid },