summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Liu <jminjie@google.com>2021-04-13 18:45:54 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-04-13 18:45:54 +0000
commit5e023c00b15cb12526008f0fa88ecdd09cf5d468 (patch)
treea4435012091be05cc701c747ec7c521a34eb07b8
parentd5e97b5a8eb3a3a62fdbfcdf4e9f883d0278d44c (diff)
parent22d92add67350a763ecf4658c36db5dae50ca1b7 (diff)
downloadStk-5e023c00b15cb12526008f0fa88ecdd09cf5d468.tar.gz
Merge "Override the label of the SIM Toolkit application dynamically" am: 22d92add67
Original change: https://android-review.googlesource.com/c/platform/packages/apps/Stk/+/743041 Change-Id: I5df8dcac536329b20ea55a78e85c06a1ffe84622
-rw-r--r--src/com/android/stk/StkAppInstaller.java87
-rw-r--r--src/com/android/stk/StkAppService.java43
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 0f9f0e8..e3ceabd 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);