Merge "Avoid NullPointerException when activity is automatically recreated"
am: ea5113094b
Change-Id: I3313ad358ce128b29c19840730577dce2c962727
diff --git a/src/com/android/stk/StkDialogActivity.java b/src/com/android/stk/StkDialogActivity.java
index 0d63043..78e1a2e 100755
--- a/src/com/android/stk/StkDialogActivity.java
+++ b/src/com/android/stk/StkDialogActivity.java
@@ -70,6 +70,15 @@
super.onCreate(icicle);
CatLog.d(LOG_TAG, "onCreate, sim id: " + mSlotId);
+
+ // 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;
+ }
+
// New Dialog is created - set to no response sent
mIsResponseSent = false;
@@ -229,6 +238,9 @@
super.onDestroy();
CatLog.d(LOG_TAG, "onDestroy - mIsResponseSent[" + mIsResponseSent +
"], sim id: " + mSlotId);
+ if (appService == null) {
+ return;
+ }
// if dialog activity is finished by stkappservice
// when receiving OP_LAUNCH_APP from the other SIM, we can not send TR here
// , since the dialog cmd is waiting user to process.
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.
diff --git a/src/com/android/stk/StkMenuActivity.java b/src/com/android/stk/StkMenuActivity.java
old mode 100644
new mode 100755
index f82b36b..5c68e86
--- a/src/com/android/stk/StkMenuActivity.java
+++ b/src/com/android/stk/StkMenuActivity.java
@@ -110,6 +110,15 @@
mContext = getBaseContext();
mAcceptUsersInput = true;
getListView().setOnCreateContextMenuListener(this);
+
+ // 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;
+ }
+
initFromIntent(getIntent());
}
@@ -272,6 +281,9 @@
getListView().setOnCreateContextMenuListener(null);
super.onDestroy();
CatLog.d(LOG_TAG, "onDestroy" + "," + mState);
+ if (appService == null) {
+ return;
+ }
//isMenuPending: if input act is finish by stkappservice when OP_LAUNCH_APP again,
//we can not send TR here, since the input cmd is waiting user to process.
if (mState == STATE_SECONDARY && !mIsResponseSent && !appService.isMenuPending(mSlotId)) {