1 /* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.stk; 18 19 import com.android.internal.telephony.PhoneConstants; 20 import com.android.internal.telephony.cat.CatLog; 21 import com.android.internal.telephony.util.TelephonyUtils; 22 23 import android.content.ComponentName; 24 import android.content.Context; 25 import android.content.pm.IPackageManager; 26 import android.content.pm.PackageManager; 27 import android.os.Build; 28 import android.os.RemoteException; 29 import android.os.ServiceManager; 30 31 /** 32 * Application installer for SIM Toolkit. 33 * 34 */ 35 final class StkAppInstaller { 36 private static final boolean DBG = TelephonyUtils.IS_DEBUGGABLE; 37 private static final String LOG_TAG = 38 new Object(){}.getClass().getEnclosingClass().getSimpleName(); 39 StkAppInstaller()40 private StkAppInstaller() { 41 } 42 installOrUpdate(Context context, String label)43 static void installOrUpdate(Context context, String label) { 44 IPackageManager pm = IPackageManager.Stub.asInterface(ServiceManager.getService("package")); 45 if (pm != null) { 46 ComponentName component = new ComponentName(context, StkMain.class); 47 int userId = context.getUserId(); 48 int icon = R.drawable.ic_launcher_sim_toolkit; 49 try { 50 try { 51 if (label != null) { 52 pm.overrideLabelAndIcon(component, label, icon, userId); 53 } else { 54 pm.restoreLabelAndIcon(component, userId); 55 } 56 if (DBG) CatLog.d(LOG_TAG, "Set the label to " + label); 57 } catch (SecurityException e) { 58 CatLog.e(LOG_TAG, "Failed to set the label to " + label); 59 } 60 setAppState(pm, component, userId, true); 61 } catch (RemoteException e) { 62 CatLog.e(LOG_TAG, "Failed to enable SIM Toolkit"); 63 } 64 } 65 } 66 uninstall(Context context)67 static void uninstall(Context context) { 68 IPackageManager pm = IPackageManager.Stub.asInterface(ServiceManager.getService("package")); 69 if (pm != null) { 70 ComponentName component = new ComponentName(context, StkMain.class); 71 try { 72 setAppState(pm, component, context.getUserId(), false); 73 } catch (RemoteException e) { 74 CatLog.e(LOG_TAG, "Failed to disable SIM Toolkit"); 75 } 76 } 77 } 78 setAppState(IPackageManager pm, ComponentName component, int userId, boolean enable)79 static void setAppState(IPackageManager pm, ComponentName component, int userId, boolean enable) 80 throws RemoteException { 81 int current = pm.getComponentEnabledSetting(component, userId); 82 int expected = enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED 83 : PackageManager.COMPONENT_ENABLED_STATE_DISABLED; 84 if (current != expected) { 85 pm.setComponentEnabledSetting(component, expected, PackageManager.DONT_KILL_APP, 86 userId); 87 if (DBG) CatLog.d(LOG_TAG, "SIM Toolkit is " + (enable ? "enabled" : "disabled")); 88 } 89 } 90 } 91