Fix a NPE when shutting down instrumentation

bug:23657953

Change-Id: I7187c3d911de24abe20a2c462a10352dd741efed
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 1b0e6a2..191bf99 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -17152,8 +17152,10 @@
         }
 
         // Can't call out of the system process with a lock held, so post a message.
-        mHandler.obtainMessage(SHUTDOWN_UI_AUTOMATION_CONNECTION_MSG,
-                app.instrumentationUiAutomationConnection).sendToTarget();
+        if (app.instrumentationUiAutomationConnection != null) {
+            mHandler.obtainMessage(SHUTDOWN_UI_AUTOMATION_CONNECTION_MSG,
+                    app.instrumentationUiAutomationConnection).sendToTarget();
+        }
 
         app.instrumentationWatcher = null;
         app.instrumentationUiAutomationConnection = null;