summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnna Suzuki <anna.x.suzuki@sony.com>2019-02-15 16:24:59 +0900
committerMichael Bestas <mkbestas@lineageos.org>2020-05-23 21:05:06 +0300
commit7b5e4985d6ce607df9507df3ac5713162853d39d (patch)
tree27df0846ab23a3b02aeca60e43f2a5a45d179714
parente6c106689ab9813d51b823afa61cee75b0eab58c (diff)
downloadandroid_packages_apps_Stk-7b5e4985d6ce607df9507df3ac5713162853d39d.tar.gz
android_packages_apps_Stk-7b5e4985d6ce607df9507df3ac5713162853d39d.tar.bz2
android_packages_apps_Stk-7b5e4985d6ce607df9507df3ac5713162853d39d.zip
Simplify the mechanism of the pending activity and dialog
The mechanism of the pending activity and dialog can be more simplified because the coming change will introduce new method to detect the screen transition to the home screen and it is not so costly. Bug: 130142364 Test: Performed manual test cases which includes regression tests. Change-Id: Iaec0551dece215941d73871f74035792dfbce13b
-rw-r--r--src/com/android/stk/StkAppService.java52
-rw-r--r--src/com/android/stk/StkDialogActivity.java31
-rw-r--r--src/com/android/stk/StkInputActivity.java49
-rw-r--r--src/com/android/stk/StkMenuActivity.java52
4 files changed, 19 insertions, 165 deletions
diff --git a/src/com/android/stk/StkAppService.java b/src/com/android/stk/StkAppService.java
index 97bb021..9de0ce5 100644
--- a/src/com/android/stk/StkAppService.java
+++ b/src/com/android/stk/StkAppService.java
@@ -644,18 +644,12 @@ public class StkAppService extends Service implements Runnable {
CatLog.d(LOG_TAG, "Finish the previous pending activity - " + previous);
previous.finish();
}
- // Pending activity is registered in the following 2 scnarios;
- // A. TERMINAL RESPONSE was sent to the card.
- // B. Activity was moved to the background before TR is sent to the card.
- // No need to observe idle screen for the pending activity in the scenario A.
- if (act != null && mStkContext[slotId].mCmdInProgress) {
- startToObserveIdleScreen(slotId);
- } else {
- if (mStkContext[slotId].mCurrentCmd != null) {
- unregisterProcessObserver(
- mStkContext[slotId].mCurrentCmd.getCmdType(), slotId);
- }
- }
+ }
+ // Clear pending dialog instance if it has not been cleared yet.
+ Activity dialog = mStkContext[slotId].getPendingDialogInstance();
+ if (dialog != null && (dialog.isDestroyed() || dialog.isFinishing())) {
+ CatLog.d(LOG_TAG, "Clear pending dialog instance - " + dialog);
+ mStkContext[slotId].mDialogInstance = null;
}
break;
case OP_SET_DAL_INST:
@@ -663,14 +657,6 @@ public class StkAppService extends Service implements Runnable {
if (mStkContext[slotId].mDialogInstance != dal) {
CatLog.d(LOG_TAG, "Set pending dialog instance - " + dal);
mStkContext[slotId].mDialogInstance = dal;
- if (dal != null) {
- startToObserveIdleScreen(slotId);
- } else {
- if (mStkContext[slotId].mCurrentCmd != null) {
- unregisterProcessObserver(
- mStkContext[slotId].mCurrentCmd.getCmdType(), slotId);
- }
- }
}
break;
case OP_SET_IMMED_DAL_INST:
@@ -1217,6 +1203,7 @@ public class StkAppService extends Service implements Runnable {
@SuppressWarnings("FallThrough")
private void handleCmdResponse(Bundle args, int slotId) {
CatLog.d(LOG_TAG, "handleCmdResponse, sim id: " + slotId);
+ unregisterProcessObserver();
if (mStkContext[slotId].mCurrentCmd == null) {
return;
}
@@ -1524,6 +1511,9 @@ public class StkAppService extends Service implements Runnable {
newIntent.putExtra("STATE", StkMenuActivity.STATE_SECONDARY);
mStkContext[slotId].mMenuState = StkMenuActivity.STATE_SECONDARY;
}
+ if (mStkContext[slotId].mMenuState == StkMenuActivity.STATE_SECONDARY) {
+ startToObserveIdleScreen(slotId);
+ }
newIntent.putExtra(SLOT_ID, slotId);
newIntent.setData(uriData);
newIntent.setFlags(intentFlags);
@@ -1550,6 +1540,7 @@ public class StkAppService extends Service implements Runnable {
notifyUserIfNecessary(slotId, input.text);
}
startActivity(newIntent);
+ startToObserveIdleScreen(slotId);
}
private void launchTextDialog(int slotId) {
@@ -1578,6 +1569,8 @@ public class StkAppService extends Service implements Runnable {
// the immediate response tlv.
if (!mStkContext[slotId].mCurrentCmd.geTextMessage().responseNeeded) {
sendResponse(RES_ID_CONFIRM, slotId, true);
+ } else {
+ startToObserveIdleScreen(slotId);
}
}
@@ -1688,25 +1681,6 @@ public class StkAppService extends Service implements Runnable {
return getNotificationId(slotId) + (notificationType * mSimCount);
}
- /**
- * Checks whether the dialog exists as the top activity of this task.
- *
- * @return true if the top activity of this task is the dialog.
- */
- public boolean isStkDialogActivated() {
- ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
- ComponentName componentName = am.getAppTasks().get(0).getTaskInfo().topActivity;
- if (componentName != null) {
- String[] split = componentName.getClassName().split(Pattern.quote("."));
- String topActivity = split[split.length - 1];
- CatLog.d(LOG_TAG, "Top activity: " + topActivity);
- if (TextUtils.equals(topActivity, StkDialogActivity.class.getSimpleName())) {
- return true;
- }
- }
- return false;
- }
-
private void replaceEventList(int slotId) {
if (mStkContext[slotId].mSetupEventListSettings != null) {
for (int current : mStkContext[slotId].mSetupEventListSettings.eventList) {
diff --git a/src/com/android/stk/StkDialogActivity.java b/src/com/android/stk/StkDialogActivity.java
index 1462480..43eb928 100644
--- a/src/com/android/stk/StkDialogActivity.java
+++ b/src/com/android/stk/StkDialogActivity.java
@@ -48,8 +48,6 @@ public class StkDialogActivity extends Activity {
private StkAppService appService = StkAppService.getInstance();
// Determines whether Terminal Response (TR) has been sent
private boolean mIsResponseSent = false;
- // Determines whether this is in the pending state.
- private boolean mIsPending = false;
// Utilize AlarmManager for real-time countdown
private static final String DIALOG_ALARM_TAG = LOG_TAG;
private static final long NO_DIALOG_ALARM = -1;
@@ -60,7 +58,6 @@ public class StkDialogActivity extends Activity {
private static final String ALARM_TIME_KEY = "alarm_time";
private static final String RESPONSE_SENT_KEY = "response_sent";
private static final String SLOT_ID_KEY = "slotid";
- private static final String PENDING = "pending";
private AlertDialog mAlertDialog;
@@ -124,6 +121,8 @@ public class StkDialogActivity extends Activity {
// command with an immediate response object should disappear when the terminal receives
// a subsequent proactive command containing display data.
appService.getStkContext(mSlotId).setImmediateDialogInstance(this);
+ } else {
+ appService.getStkContext(mSlotId).setPendingDialogInstance(this);
}
alertDialogBuilder.setTitle(mTextMsg.title);
@@ -158,9 +157,6 @@ public class StkDialogActivity extends Activity {
super.onResume();
CatLog.d(LOG_TAG, "onResume - mIsResponseSent[" + mIsResponseSent +
"], sim id: " + mSlotId);
- // The pending dialog is unregistered if this instance was registered as it before.
- setPendingState(false);
-
/*
* If the userClear flag is set and dialogduration is set to 0, the display Text
* should be displayed to user forever until some high priority event occurs
@@ -215,14 +211,6 @@ public class StkDialogActivity extends Activity {
super.onStop();
CatLog.d(LOG_TAG, "onStop - before Send CONFIRM false mIsResponseSent[" +
mIsResponseSent + "], sim id: " + mSlotId);
-
- // Nothing should be done here if this activity is being finished or restarted now.
- if (isFinishing() || isChangingConfigurations()) {
- return;
- }
-
- // This is registered as the pending dialog as this was sent to the background.
- setPendingState(true);
}
@Override
@@ -260,7 +248,6 @@ public class StkDialogActivity extends Activity {
outState.putBoolean(RESPONSE_SENT_KEY, mIsResponseSent);
outState.putLong(ALARM_TIME_KEY, mAlarmTime);
outState.putInt(SLOT_ID_KEY, mSlotId);
- outState.putBoolean(PENDING, mIsPending);
}
@Override
@@ -274,11 +261,6 @@ public class StkDialogActivity extends Activity {
mAlarmTime = savedInstanceState.getLong(ALARM_TIME_KEY, NO_DIALOG_ALARM);
mSlotId = savedInstanceState.getInt(SLOT_ID_KEY);
- // The pending dialog must be replaced if the previous instance was in the pending state.
- if (savedInstanceState.getBoolean(PENDING)) {
- setPendingState(true);
- }
-
if (mAlarmTime != NO_DIALOG_ALARM) {
startTimeOut();
}
@@ -303,15 +285,6 @@ public class StkDialogActivity extends Activity {
}
}
- private void setPendingState(boolean on) {
- if (mTextMsg.responseNeeded) {
- if (mIsPending != on) {
- appService.getStkContext(mSlotId).setPendingDialogInstance(on ? this : null);
- mIsPending = on;
- }
- }
- }
-
private void sendResponse(int resId, boolean confirmed) {
cancelTimeOut();
diff --git a/src/com/android/stk/StkInputActivity.java b/src/com/android/stk/StkInputActivity.java
index da80f9a..34f7fe5 100644
--- a/src/com/android/stk/StkInputActivity.java
+++ b/src/com/android/stk/StkInputActivity.java
@@ -86,7 +86,6 @@ public class StkInputActivity extends AppCompatActivity implements View.OnClickL
private static final String RESPONSE_SENT_KEY = "response_sent";
private static final String INPUT_STRING_KEY = "input_string";
private static final String ALARM_TIME_KEY = "alarm_time";
- private static final String PENDING = "pending";
private static final String INPUT_ALARM_TAG = LOG_TAG;
private static final long NO_INPUT_ALARM = -1;
@@ -95,8 +94,6 @@ public class StkInputActivity extends AppCompatActivity implements View.OnClickL
private StkAppService appService = StkAppService.getInstance();
private boolean mIsResponseSent = false;
- // Determines whether this is in the pending state.
- private boolean mIsPending = false;
private int mSlotId = -1;
// Click listener to handle buttons press..
@@ -192,6 +189,7 @@ public class StkInputActivity extends AppCompatActivity implements View.OnClickL
mYesNoLayout = findViewById(R.id.yes_no_layout);
mNormalLayout = findViewById(R.id.normal_layout);
initFromIntent(getIntent());
+ appService.getStkContext(mSlotId).setPendingActivityInstance(this);
}
@Override
@@ -206,12 +204,6 @@ public class StkInputActivity extends AppCompatActivity implements View.OnClickL
super.onResume();
CatLog.d(LOG_TAG, "onResume - mIsResponseSent[" + mIsResponseSent +
"], slot id: " + mSlotId);
- // If the terminal has already sent response to the card when this activity is resumed,
- // keep this as a pending activity as this should be finished when the session ends.
- if (!mIsResponseSent) {
- setPendingState(false);
- }
-
if (mAlarmTime == NO_INPUT_ALARM) {
startTimeOut();
}
@@ -230,23 +222,6 @@ public class StkInputActivity extends AppCompatActivity implements View.OnClickL
public void onStop() {
super.onStop();
CatLog.d(LOG_TAG, "onStop - mIsResponseSent[" + mIsResponseSent + "]");
-
- // Nothing should be done here if this activity is being finished or restarted now.
- if (isFinishing() || isChangingConfigurations()) {
- return;
- }
-
- if (mIsResponseSent) {
- // It is unnecessary to keep this activity if the response was already sent and
- // the dialog activity is NOT on the top of this activity.
- if (!appService.isStkDialogActivated()) {
- finish();
- }
- } else {
- // This should be registered as the pending activity here
- // only when no response has been sent back to the card.
- setPendingState(true);
- }
}
@Override
@@ -326,11 +301,6 @@ public class StkInputActivity extends AppCompatActivity implements View.OnClickL
}
args.putBoolean(StkAppService.HELP, help);
appService.sendResponse(args, mSlotId);
-
- // This instance should be set as a pending activity and finished by the service
- if (resId != StkAppService.RES_ID_END_SESSION) {
- setPendingState(true);
- }
}
@Override
@@ -388,7 +358,6 @@ public class StkInputActivity extends AppCompatActivity implements View.OnClickL
outState.putBoolean(RESPONSE_SENT_KEY, mIsResponseSent);
outState.putString(INPUT_STRING_KEY, mTextIn.getText().toString());
outState.putLong(ALARM_TIME_KEY, mAlarmTime);
- outState.putBoolean(PENDING, mIsPending);
}
@Override
@@ -408,22 +377,6 @@ public class StkInputActivity extends AppCompatActivity implements View.OnClickL
if (mAlarmTime != NO_INPUT_ALARM) {
startTimeOut();
}
-
- if (!mIsResponseSent && !savedInstanceState.getBoolean(PENDING)) {
- // If this is in the foreground and no response has been sent to the card,
- // this must not be registered as pending activity by the previous instance.
- // No need to renew nor clear pending activity in this case.
- } else {
- // Renew the instance of the pending activity.
- setPendingState(true);
- }
- }
-
- private void setPendingState(boolean on) {
- if (mIsPending != on) {
- appService.getStkContext(mSlotId).setPendingActivityInstance(on ? this : null);
- mIsPending = on;
- }
}
public void beforeTextChanged(CharSequence s, int start, int count,
diff --git a/src/com/android/stk/StkMenuActivity.java b/src/com/android/stk/StkMenuActivity.java
index 3d5641c..fb4f84c 100644
--- a/src/com/android/stk/StkMenuActivity.java
+++ b/src/com/android/stk/StkMenuActivity.java
@@ -55,8 +55,6 @@ public class StkMenuActivity extends ListActivity implements View.OnCreateContex
private boolean mAcceptUsersInput = true;
private int mSlotId = -1;
private boolean mIsResponseSent = false;
- // Determines whether this is in the pending state.
- private boolean mIsPending = false;
private TextView mTitleTextView = null;
private ImageView mTitleIconView = null;
@@ -71,7 +69,6 @@ public class StkMenuActivity extends ListActivity implements View.OnCreateContex
private static final String ACCEPT_USERS_INPUT_KEY = "accept_users_input";
private static final String RESPONSE_SENT_KEY = "response_sent";
private static final String ALARM_TIME_KEY = "alarm_time";
- private static final String PENDING = "pending";
private static final String SELECT_ALARM_TAG = LOG_TAG;
private static final long NO_SELECT_ALARM = -1;
@@ -116,6 +113,9 @@ public class StkMenuActivity extends ListActivity implements View.OnCreateContex
finish();
return;
}
+ if (mState == STATE_SECONDARY) {
+ appService.getStkContext(mSlotId).setPendingActivityInstance(this);
+ }
}
@Override
@@ -182,11 +182,6 @@ public class StkMenuActivity extends ListActivity implements View.OnCreateContex
}
displayMenu();
- // If the terminal has already sent response to the card when this activity is resumed,
- // keep this as a pending activity as this should be finished when the session ends.
- if (!mIsResponseSent) {
- setPendingState(false);
- }
if (mAlarmTime == NO_SELECT_ALARM) {
startTimeOut();
}
@@ -221,23 +216,6 @@ public class StkMenuActivity extends ListActivity implements View.OnCreateContex
public void onStop() {
super.onStop();
CatLog.d(LOG_TAG, "onStop, slot id: " + mSlotId + "," + mIsResponseSent + "," + mState);
-
- // Nothing should be done here if this activity is being finished or restarted now.
- if (isFinishing() || isChangingConfigurations()) {
- return;
- }
-
- if (mIsResponseSent) {
- // It is unnecessary to keep this activity if the response was already sent and
- // the dialog activity is NOT on the top of this activity.
- if (mState == STATE_SECONDARY && !appService.isStkDialogActivated()) {
- finish();
- }
- } else {
- // This instance should be registered as the pending activity here
- // only when no response has been sent back to the card.
- setPendingState(true);
- }
}
@Override
@@ -345,7 +323,6 @@ public class StkMenuActivity extends ListActivity implements View.OnCreateContex
outState.putBoolean(ACCEPT_USERS_INPUT_KEY, mAcceptUsersInput);
outState.putBoolean(RESPONSE_SENT_KEY, mIsResponseSent);
outState.putLong(ALARM_TIME_KEY, mAlarmTime);
- outState.putBoolean(PENDING, mIsPending);
}
@Override
@@ -367,24 +344,6 @@ public class StkMenuActivity extends ListActivity implements View.OnCreateContex
if (mAlarmTime != NO_SELECT_ALARM) {
startTimeOut();
}
-
- if (!mIsResponseSent && !savedInstanceState.getBoolean(PENDING)) {
- // If this is in the foreground and no response has been sent to the card,
- // this must not be registered as pending activity by the previous instance.
- // No need to renew nor clear pending activity in this case.
- } else {
- // Renew the instance of the pending activity.
- setPendingState(true);
- }
- }
-
- private void setPendingState(boolean on) {
- if (mState == STATE_SECONDARY) {
- if (mIsPending != on) {
- appService.getStkContext(mSlotId).setPendingActivityInstance(on ? this : null);
- mIsPending = on;
- }
- }
}
private void cancelTimeOut() {
@@ -502,11 +461,6 @@ public class StkMenuActivity extends ListActivity implements View.OnCreateContex
args.putInt(StkAppService.MENU_SELECTION, itemId);
args.putBoolean(StkAppService.HELP, help);
appService.sendResponse(args, mSlotId);
-
- // This instance should be set as a pending activity and finished by the service.
- if (resId != StkAppService.RES_ID_END_SESSION) {
- setPendingState(true);
- }
}
private final BroadcastReceiver mLocalBroadcastReceiver = new BroadcastReceiver() {