Snap for 10580647 from dd8676cb73ed7cf910f3c54fc16bd02e58f39103 to udc-d1-release

Change-Id: I90a226fa0d656c1372c2623dbc9d38a786efca38
diff --git a/src/com/android/wallpaper/util/WallpaperConnection.java b/src/com/android/wallpaper/util/WallpaperConnection.java
index e712c7a..b345085 100644
--- a/src/com/android/wallpaper/util/WallpaperConnection.java
+++ b/src/com/android/wallpaper/util/WallpaperConnection.java
@@ -191,6 +191,9 @@
      * @see ServiceConnection#onServiceConnected(ComponentName, IBinder)
      */
     public void onServiceConnected(ComponentName name, IBinder service) {
+        if (mContainerView == null) {
+            return;
+        }
         mService = IWallpaperService.Stub.asInterface(service);
         if (mContainerView.getDisplay() == null) {
             mContainerView.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
@@ -278,11 +281,13 @@
 
     @Override
     public void onWallpaperColorsChanged(WallpaperColors colors, int displayId) {
-        mContainerView.post(() -> {
-            if (mListener != null) {
-                mListener.onWallpaperColorsChanged(colors, displayId);
-            }
-        });
+        if (mContainerView != null) {
+            mContainerView.post(() -> {
+                if (mListener != null) {
+                    mListener.onWallpaperColorsChanged(colors, displayId);
+                }
+            });
+        }
     }
 
     @Override
@@ -294,12 +299,13 @@
         if (mSecondContainerView != null) {
             mSecondContainerView.post(() -> reparentWallpaperSurface(mSecondContainerView));
         }
-
-        mContainerView.post(() -> {
-            if (mListener != null) {
-                mListener.onEngineShown();
-            }
-        });
+        if (mContainerView != null) {
+            mContainerView.post(() -> {
+                if (mListener != null) {
+                    mListener.onEngineShown();
+                }
+            });
+        }
     }
 
     /**
@@ -354,6 +360,9 @@
     }
 
     private void reparentWallpaperSurface(SurfaceView parentSurface) {
+        if (parentSurface == null) {
+            return;
+        }
         synchronized (this) {
             if (mEngine == null) {
                 Log.i(TAG, "Engine is null, was the service disconnected?");