summaryrefslogtreecommitdiff
path: root/src/com
diff options
context:
space:
mode:
authorAnna Suzuki <anna.x.suzuki@sony.com>2019-11-05 21:35:11 -0800
committerandroid-build-merger <android-build-merger@google.com>2019-11-05 21:35:11 -0800
commit1aa4fd0be3c216f339fef4fd52b8b8be97caef0e (patch)
tree459717300f020ef93f214fa01ff81f0f0441883f /src/com
parenta8b16a434eb549c194e47b736616e13b1243c2ec (diff)
parent8646fb22f98ced926c2c9e3211a03daf1e2e84eb (diff)
downloadStk-1aa4fd0be3c216f339fef4fd52b8b8be97caef0e.tar.gz
Simplify the mechanism of the pending activity and dialog am: 35309b0e5e am: 2c2c64a75c
am: 8646fb22f9 Change-Id: Ib4d676a367a7a8275b19d95281ee66a57ad67e33
Diffstat (limited to 'src/com')
-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 0212a46..dea5820 100644
--- a/src/com/android/stk/StkAppService.java
+++ b/src/com/android/stk/StkAppService.java
@@ -651,18 +651,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:
@@ -670,14 +664,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:
@@ -1255,6 +1241,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;
}
@@ -1562,6 +1549,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);
@@ -1588,6 +1578,7 @@ public class StkAppService extends Service implements Runnable {
notifyUserIfNecessary(slotId, input.text);
}
startActivity(newIntent);
+ startToObserveIdleScreen(slotId);
}
private void launchTextDialog(int slotId) {
@@ -1616,6 +1607,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);
}
}
@@ -1726,25 +1719,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 9e05e27..43f44de 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 5ef79f9..80bdf75 100644
--- a/src/com/android/stk/StkInputActivity.java
+++ b/src/com/android/stk/StkInputActivity.java
@@ -87,7 +87,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;
@@ -96,8 +95,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..
@@ -193,6 +190,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
@@ -207,12 +205,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();
}
@@ -231,23 +223,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
@@ -327,11 +302,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
@@ -389,7 +359,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
@@ -409,22 +378,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() {