Avoid NullPointerException when activity is automatically recreated

Android system recreates activity with the saved Bundle object if it is
unexpectedly destroyed. If the death of the phone process caused such
unexpected destruction of activity, it is possible that StkAppService is
not started yet when the activity is recreated.

Bug: 31980334
Test: Confirmed NPE does not happen after the phone process is killed.

Change-Id: I7aeb570a6d866ec4ae6c33c7cea309bf83080d0a
diff --git a/src/com/android/stk/StkInputActivity.java b/src/com/android/stk/StkInputActivity.java
old mode 100644
new mode 100755
index 4dbad00..96b7dca
--- a/src/com/android/stk/StkInputActivity.java
+++ b/src/com/android/stk/StkInputActivity.java
@@ -134,6 +134,14 @@
 
         CatLog.d(LOG_TAG, "onCreate - mIsResponseSent[" + mIsResponseSent + "]");
 
+        // appService can be null if this activity is automatically recreated by the system
+        // with the saved instance state right after the phone process is killed.
+        if (appService == null) {
+            CatLog.d(LOG_TAG, "onCreate - appService is null");
+            finish();
+            return;
+        }
+
         // Set the layout for this activity.
         requestWindowFeature(Window.FEATURE_LEFT_ICON);
         setContentView(R.layout.stk_input);
@@ -201,6 +209,9 @@
         super.onDestroy();
         CatLog.d(LOG_TAG, "onDestroy - before Send End Session mIsResponseSent[" +
                 mIsResponseSent + " , " + mSlotId + "]");
+        if (appService == null) {
+            return;
+        }
         //If the input activity is finished by stkappservice
         //when receiving OP_LAUNCH_APP from the other SIM, we can not send TR here
         //, since the input cmd is waiting user to process.