diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2021-04-14 01:07:57 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2021-04-14 01:07:57 +0000 |
commit | c327af7803367a8392278f964d2f010ce1ef3dcf (patch) | |
tree | ef1a6259792b804f604b1fa7a5fd45b93abc88b6 | |
parent | ac55f1f644d470299e658b8d0e5642d4f3af48e5 (diff) | |
parent | 48b5c0222a5778aeac3f3f8340f8c11ac8ce571d (diff) | |
download | Stk-c327af7803367a8392278f964d2f010ce1ef3dcf.tar.gz |
Snap for 7280565 from 48b5c0222a5778aeac3f3f8340f8c11ac8ce571d to sc-d1-release
Change-Id: Id4e55feb56c1033975acd4e673f7c8843eab8120
-rw-r--r-- | src/com/android/stk/StkAppInstaller.java | 87 | ||||
-rw-r--r-- | src/com/android/stk/StkAppService.java | 43 |
2 files changed, 84 insertions, 46 deletions
diff --git a/src/com/android/stk/StkAppInstaller.java b/src/com/android/stk/StkAppInstaller.java index 4e386ee..fe25af6 100644 --- a/src/com/android/stk/StkAppInstaller.java +++ b/src/com/android/stk/StkAppInstaller.java @@ -16,66 +16,75 @@ package com.android.stk; -import com.android.internal.telephony.cat.CatLog; import com.android.internal.telephony.PhoneConstants; +import com.android.internal.telephony.cat.CatLog; +import com.android.internal.telephony.util.TelephonyUtils; import android.content.ComponentName; import android.content.Context; +import android.content.pm.IPackageManager; import android.content.pm.PackageManager; -import android.telephony.TelephonyManager; -import android.os.SystemProperties; +import android.os.Build; +import android.os.RemoteException; +import android.os.ServiceManager; /** * Application installer for SIM Toolkit. * */ -abstract class StkAppInstaller { - private static final String STK_MAIN_ACTIVITY = "com.android.stk.StkMain"; +final class StkAppInstaller { + private static final boolean DBG = TelephonyUtils.IS_DEBUGGABLE; private static final String LOG_TAG = new Object(){}.getClass().getEnclosingClass().getSimpleName(); private StkAppInstaller() { - CatLog.d(LOG_TAG, "init"); } - public static void install(Context context) { - setAppState(context, true); + static void installOrUpdate(Context context, String label) { + IPackageManager pm = IPackageManager.Stub.asInterface(ServiceManager.getService("package")); + if (pm != null) { + ComponentName component = new ComponentName(context, StkMain.class); + int userId = context.getUserId(); + int icon = R.drawable.ic_launcher_sim_toolkit; + try { + try { + if (label != null) { + pm.overrideLabelAndIcon(component, label, icon, userId); + } else { + pm.restoreLabelAndIcon(component, userId); + } + if (DBG) CatLog.d(LOG_TAG, "Set the label to " + label); + } catch (SecurityException e) { + CatLog.e(LOG_TAG, "Failed to set the label to " + label); + } + setAppState(pm, component, userId, true); + } catch (RemoteException e) { + CatLog.e(LOG_TAG, "Failed to enable SIM Toolkit"); + } + } } - public static void unInstall(Context context) { - setAppState(context, false); + static void uninstall(Context context) { + IPackageManager pm = IPackageManager.Stub.asInterface(ServiceManager.getService("package")); + if (pm != null) { + ComponentName component = new ComponentName(context, StkMain.class); + try { + setAppState(pm, component, context.getUserId(), false); + } catch (RemoteException e) { + CatLog.e(LOG_TAG, "Failed to disable SIM Toolkit"); + } + } } - private static void setAppState(Context context, boolean install) { - CatLog.d(LOG_TAG, "[setAppState]+"); - if (context == null) { - CatLog.d(LOG_TAG, "[setAppState]- no context, just return."); - return; - } - PackageManager pm = context.getPackageManager(); - if (pm == null) { - CatLog.d(LOG_TAG, "[setAppState]- no package manager, just return."); - return; - } - ComponentName cName = new ComponentName("com.android.stk", STK_MAIN_ACTIVITY); - int state = install ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED + static void setAppState(IPackageManager pm, ComponentName component, int userId, boolean enable) + throws RemoteException { + int current = pm.getComponentEnabledSetting(component, userId); + int expected = enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED; - - if (((PackageManager.COMPONENT_ENABLED_STATE_ENABLED == state) && - (PackageManager.COMPONENT_ENABLED_STATE_ENABLED == - pm.getComponentEnabledSetting(cName))) || - ((PackageManager.COMPONENT_ENABLED_STATE_DISABLED == state) && - (PackageManager.COMPONENT_ENABLED_STATE_DISABLED == - pm.getComponentEnabledSetting(cName)))) { - CatLog.d(LOG_TAG, "Need not change app state!!"); - } else { - CatLog.d(LOG_TAG, "Change app state[" + install + "]"); - try { - pm.setComponentEnabledSetting(cName, state, PackageManager.DONT_KILL_APP); - } catch (Exception e) { - CatLog.d(LOG_TAG, "Could not change STK app state"); - } + if (current != expected) { + pm.setComponentEnabledSetting(component, expected, PackageManager.DONT_KILL_APP, + userId); + if (DBG) CatLog.d(LOG_TAG, "SIM Toolkit is " + (enable ? "enabled" : "disabled")); } - CatLog.d(LOG_TAG, "[setAppState]-"); } } diff --git a/src/com/android/stk/StkAppService.java b/src/com/android/stk/StkAppService.java index 7b9f5b1..d3e6d83 100644 --- a/src/com/android/stk/StkAppService.java +++ b/src/com/android/stk/StkAppService.java @@ -369,7 +369,7 @@ public class StkAppService extends Service implements Runnable { } if (i == mSimCount) { stopSelf(); - StkAppInstaller.unInstall(mContext); + StkAppInstaller.uninstall(this); return; } } @@ -498,7 +498,7 @@ public class StkAppService extends Service implements Runnable { CatLog.d(LOG_TAG, "StkAppService, getMainMenu, sim id: " + slotId); if (slotId >=0 && slotId < mSimCount && (mStkContext[slotId].mMainCmd != null)) { Menu menu = mStkContext[slotId].mMainCmd.getMenu(); - if (menu != null && mSimCount > PhoneConstants.MAX_PHONE_COUNT_SINGLE_SIM) { + if (menu != null) { // If alpha identifier or icon identifier with the self-explanatory qualifier is // specified in SET-UP MENU command, it should be more prioritized than preset ones. if (menu.title == null @@ -634,7 +634,7 @@ public class StkAppService extends Service implements Runnable { } } if (i == mSimCount) { - StkAppInstaller.unInstall(mContext); + StkAppInstaller.uninstall(StkAppService.this); } break; case OP_DELAYED_MSG: @@ -738,8 +738,10 @@ public class StkAppService extends Service implements Runnable { } if (isAllOtherCardsAbsent(slotId)) { CatLog.d(LOG_TAG, "All CARDs are ABSENT"); - StkAppInstaller.unInstall(mContext); + StkAppInstaller.uninstall(StkAppService.this); stopSelf(); + } else { + addToMenuSystemOrUpdateLabel(); } } else { IccRefreshResponse state = new IccRefreshResponse(); @@ -1133,11 +1135,12 @@ public class StkAppService extends Service implements Runnable { } } if (i == mSimCount) { - StkAppInstaller.unInstall(mContext); + StkAppInstaller.uninstall(this); + } else { + addToMenuSystemOrUpdateLabel(); } } else { - CatLog.d(LOG_TAG, "install App"); - StkAppInstaller.install(mContext); + addToMenuSystemOrUpdateLabel(); } if (mStkContext[slotId].mMenuIsVisible) { launchMenuActivity(null, slotId); @@ -1265,6 +1268,32 @@ public class StkAppService extends Service implements Runnable { } } + private void addToMenuSystemOrUpdateLabel() { + String candidateLabel = null; + + for (int slotId = 0; slotId < mSimCount; slotId++) { + Menu menu = getMainMenu(slotId); + if (menu != null) { + if (!TextUtils.isEmpty(candidateLabel)) { + if (!TextUtils.equals(menu.title, candidateLabel)) { + // We should not display the alpha identifier of SET-UP MENU command + // as the application label on the application launcher + // if different alpha identifiers are provided by multiple SIMs. + candidateLabel = null; + break; + } + } else { + if (TextUtils.isEmpty(menu.title)) { + break; + } + candidateLabel = menu.title; + } + } + } + + StkAppInstaller.installOrUpdate(this, candidateLabel); + } + @SuppressWarnings("FallThrough") private void handleCmdResponse(Bundle args, int slotId) { CatLog.d(LOG_TAG, "handleCmdResponse, sim id: " + slotId); |