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 = StkAppInstaller.class.getSimpleName(); 38 StkAppInstaller()39 private StkAppInstaller() { 40 } 41 installOrUpdate(Context context, String label)42 static void installOrUpdate(Context context, String label) { 43 IPackageManager pm = IPackageManager.Stub.asInterface(ServiceManager.getService("package")); 44 if (pm != null) { 45 ComponentName component = new ComponentName(context, StkMain.class); 46 int userId = context.getUserId(); 47 int icon = R.drawable.ic_launcher_sim_toolkit; 48 try { 49 try { 50 if (label != null) { 51 pm.overrideLabelAndIcon(component, label, icon, userId); 52 } else { 53 pm.restoreLabelAndIcon(component, userId); 54 } 55 if (DBG) CatLog.d(LOG_TAG, "Set the label to " + label); 56 } catch (SecurityException e) { 57 CatLog.e(LOG_TAG, "Failed to set the label to " + label); 58 } 59 setAppState(pm, component, userId, true); 60 } catch (RemoteException e) { 61 CatLog.e(LOG_TAG, "Failed to enable SIM Toolkit"); 62 } 63 } 64 } 65 uninstall(Context context)66 static void uninstall(Context context) { 67 IPackageManager pm = IPackageManager.Stub.asInterface(ServiceManager.getService("package")); 68 if (pm != null) { 69 ComponentName component = new ComponentName(context, StkMain.class); 70 try { 71 setAppState(pm, component, context.getUserId(), false); 72 } catch (RemoteException e) { 73 CatLog.e(LOG_TAG, "Failed to disable SIM Toolkit"); 74 } 75 } 76 } 77 setAppState(IPackageManager pm, ComponentName component, int userId, boolean enable)78 static void setAppState(IPackageManager pm, ComponentName component, int userId, boolean enable) 79 throws RemoteException { 80 int current = pm.getComponentEnabledSetting(component, userId); 81 int expected = enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED 82 : PackageManager.COMPONENT_ENABLED_STATE_DISABLED; 83 if (current != expected) { 84 pm.setComponentEnabledSetting(component, expected, PackageManager.DONT_KILL_APP, 85 userId, "StkAppInstaller"); 86 if (DBG) CatLog.d(LOG_TAG, "SIM Toolkit is " + (enable ? "enabled" : "disabled")); 87 } 88 } 89 } 90