Cancel PLAY TONE command if SIM is removed or disabled
CatService is disposed and StkAppService can also be stoped if SIM is
removed or disabled. The bad thing is that no one stops the tone being
played because of PLAY TONE command and user also has no way to stop it.
The tone must be stoped right after SIM is removed or disabled.
Bug: 132849761
Test: Confirmed the sound can be stopped with this change.
Change-Id: Iad68010a9d7ad9c72749cb88a1063de95f287588
diff --git a/src/com/android/stk/StkAppService.java b/src/com/android/stk/StkAppService.java
index 5fb9313..2618eca 100644
--- a/src/com/android/stk/StkAppService.java
+++ b/src/com/android/stk/StkAppService.java
@@ -719,6 +719,12 @@
mStkContext[slotId].mCurrentMenu = null;
mStkContext[slotId].mMainCmd = null;
mStkService[slotId] = null;
+ // Stop the tone currently being played if the relevant SIM is removed or disabled.
+ if (mStkContext[slotId].mCurrentCmd != null
+ && mStkContext[slotId].mCurrentCmd.getCmdType().value()
+ == AppInterface.CommandType.PLAY_TONE.value()) {
+ terminateTone(slotId);
+ }
if (isAllOtherCardsAbsent(slotId)) {
CatLog.d(LOG_TAG, "All CARDs are ABSENT");
StkAppInstaller.unInstall(mContext);
@@ -858,6 +864,14 @@
sendResponse(args, slotId);
}
+ private void terminateTone(int slotId) {
+ Message msg = new Message();
+ msg.what = OP_STOP_TONE;
+ msg.obj = mServiceHandler.hasMessages(OP_STOP_TONE, PLAY_TONE_WITH_DIALOG)
+ ? PLAY_TONE_WITH_DIALOG : PLAY_TONE_ONLY;
+ handleStopTone(msg, slotId);
+ }
+
private boolean isCmdInteractive(CatCmdMessage cmd) {
switch (cmd.getCmdType()) {
case SEND_DTMF:
@@ -2286,7 +2300,7 @@
mServiceHandler.removeMessages(OP_STOP_TONE);
mServiceHandler.removeMessages(OP_STOP_TONE_USER);
- if (mTonePlayer != null) {
+ if (mTonePlayer != null) {
mTonePlayer.stop();
mTonePlayer.release();
mTonePlayer = null;