From 58e076505425bfce5455dd36824b598ee8f36329 Mon Sep 17 00:00:00 2001 From: Yoshiaki Naka Date: Fri, 26 Apr 2019 17:58:52 +0900 Subject: Add new function to show or hide SIM Toolkit on the launcher screen There are several places we can find similar logics to show or hide SIM Toolkit application on the launcher screen. Some are a kind of code clone and another one is a bit different logic. That is not good for future code maintenance. Bug: 159662728 Test: Manually confirmed all the possible SIM removal scenarios. Change-Id: Iaea976aa772b2d07a162619ba089839bb465e83a --- src/com/android/stk/StkAppService.java | 38 ++++++++++++---------------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/src/com/android/stk/StkAppService.java b/src/com/android/stk/StkAppService.java index e3ceabd..e86c138 100644 --- a/src/com/android/stk/StkAppService.java +++ b/src/com/android/stk/StkAppService.java @@ -119,7 +119,6 @@ public class StkAppService extends Service implements Runnable { protected LinkedList mCmdsQ = null; protected boolean mCmdInProgress = false; protected int mStkServiceState = STATE_UNKNOWN; - protected int mSetupMenuState = STATE_NOT_EXIST; protected int mMenuState = StkMenuActivity.STATE_INIT; protected int mOpCode = -1; private Activity mActivityInstance = null; @@ -627,15 +626,7 @@ public class StkAppService extends Service implements Runnable { break; case OP_BOOT_COMPLETED: CatLog.d(LOG_TAG, " OP_BOOT_COMPLETED"); - int i = 0; - for (i = 0; i < mSimCount; i++) { - if (mStkContext[i].mMainCmd != null) { - break; - } - } - if (i == mSimCount) { - StkAppInstaller.uninstall(StkAppService.this); - } + uninstallIfUnnecessary(); break; case OP_DELAYED_MSG: handleDelayedCmd(slotId); @@ -1122,21 +1113,10 @@ public class StkAppService extends Service implements Runnable { CatLog.d(LOG_TAG, "SET_UP_MENU [" + removeMenu(slotId) + "]"); if (removeMenu(slotId)) { - int i = 0; - CatLog.d(LOG_TAG, "removeMenu() - Uninstall App"); mStkContext[slotId].mCurrentMenu = null; mStkContext[slotId].mMainCmd = null; //Check other setup menu state. If all setup menu are removed, uninstall apk. - for (i = 0; i < mSimCount; i++) { - if (i != slotId && mStkContext[i].mSetupMenuState != STATE_NOT_EXIST) { - CatLog.d(LOG_TAG, "Not Uninstall App:" + i + "," - + mStkContext[i].mSetupMenuState); - break; - } - } - if (i == mSimCount) { - StkAppInstaller.uninstall(this); - } else { + if (!uninstallIfUnnecessary()) { addToMenuSystemOrUpdateLabel(); } } else { @@ -2456,18 +2436,26 @@ public class StkAppService extends Service implements Runnable { try { if (mStkContext[slotId].mCurrentMenu.items.size() == 1 && mStkContext[slotId].mCurrentMenu.items.get(0) == null) { - mStkContext[slotId].mSetupMenuState = STATE_NOT_EXIST; return true; } } catch (NullPointerException e) { CatLog.d(LOG_TAG, "Unable to get Menu's items size"); - mStkContext[slotId].mSetupMenuState = STATE_NOT_EXIST; return true; } - mStkContext[slotId].mSetupMenuState = STATE_EXIST; return false; } + private boolean uninstallIfUnnecessary() { + for (int slot = 0; slot < mSimCount; slot++) { + if (mStkContext[slot].mMainCmd != null) { + return false; + } + } + CatLog.d(LOG_TAG, "Uninstall App"); + StkAppInstaller.uninstall(this); + return true; + } + synchronized StkContext getStkContext(int slotId) { if (slotId >= 0 && slotId < mSimCount) { return mStkContext[slotId]; -- cgit v1.2.3 From 2d10bbb2f0a4e6c8e51e1ef2f3405e0f7b0e42bf Mon Sep 17 00:00:00 2001 From: Yoshiaki Naka Date: Thu, 9 May 2019 15:35:21 +0900 Subject: Remove SIM Tookit from the launcher screen if no main menu is available SIM Toolkit has a logic to remove itself from the launcher screen once it becomes unnecessary, but the condition is wrong. It is removed when all the SIM cards go into ABSENT state in the current implementation, but it must be executed when the number of active main menu becomes 0. Bug: 159662728 Test: Manually confirmed all the possible SIM removal scenarios. Change-Id: I8091bf6ea82df873335cce3477a6c759735ed79b --- src/com/android/stk/StkAppService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/com/android/stk/StkAppService.java b/src/com/android/stk/StkAppService.java index e86c138..c507171 100644 --- a/src/com/android/stk/StkAppService.java +++ b/src/com/android/stk/StkAppService.java @@ -727,12 +727,12 @@ public class StkAppService extends Service implements Runnable { == AppInterface.CommandType.PLAY_TONE.value()) { terminateTone(slotId); } + if (!uninstallIfUnnecessary()) { + addToMenuSystemOrUpdateLabel(); + } if (isAllOtherCardsAbsent(slotId)) { CatLog.d(LOG_TAG, "All CARDs are ABSENT"); - StkAppInstaller.uninstall(StkAppService.this); stopSelf(); - } else { - addToMenuSystemOrUpdateLabel(); } } else { IccRefreshResponse state = new IccRefreshResponse(); -- cgit v1.2.3