Fix WindowLeaked issue happening in StkInputActivity
WindowManager says that StkInputActivity can have a leaked window while
user is changing the multi-window mode. That is because finish() is
called in onResume() during the mode change. The basic design of this
activity is that it should not be finished but stay in the background if
the dialog activity is launched on it. It should be finished when the
current session ends or it is completely covered by another activity
except for the dialog activity.
Bug: 68366748
Test: Confirmed that no window leak happens in the manual test.
Change-Id: I1374583ef8ae3521d77bc05090505f8a64d1c0ee
diff --git a/src/com/android/stk/StkAppService.java b/src/com/android/stk/StkAppService.java
index 85a6a72..b7fce8c 100644
--- a/src/com/android/stk/StkAppService.java
+++ b/src/com/android/stk/StkAppService.java
@@ -827,7 +827,7 @@
}
// returns true if any Stk related activity already has focus on the screen
- private boolean isTopOfStack() {
+ boolean isTopOfStack() {
ActivityManager mActivityManager = (ActivityManager) mContext
.getSystemService(ACTIVITY_SERVICE);
String currentPackageName = null;
diff --git a/src/com/android/stk/StkInputActivity.java b/src/com/android/stk/StkInputActivity.java
index 522fd35..a4e6daf 100644
--- a/src/com/android/stk/StkInputActivity.java
+++ b/src/com/android/stk/StkInputActivity.java
@@ -223,10 +223,6 @@
CatLog.d(LOG_TAG, "onResume - mIsResponseSent[" + mIsResponseSent +
"], slot id: " + mSlotId);
startTimeOut();
- if (mIsResponseSent) {
- cancelTimeOut();
- finish();
- }
}
@Override
@@ -242,7 +238,9 @@
public void onStop() {
super.onStop();
CatLog.d(LOG_TAG, "onStop - mIsResponseSent[" + mIsResponseSent + "]");
- if (mIsResponseSent) {
+ // It is unnecessary to keep this activity if the response was already sent and
+ // this got invisible because of the other full-screen activity in this application.
+ if (mIsResponseSent && appService.isTopOfStack()) {
cancelTimeOut();
finish();
} else {