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.cat.CatLog; 20 import com.android.internal.telephony.PhoneConstants; 21 import com.android.internal.telephony.TelephonyProperties; 22 23 import android.content.ComponentName; 24 import android.content.Context; 25 import android.content.pm.PackageManager; 26 import android.telephony.TelephonyManager; 27 import android.os.SystemProperties; 28 29 /** 30 * Application installer for SIM Toolkit. 31 * 32 */ 33 abstract class StkAppInstaller { 34 private static final String STK_MAIN_ACTIVITY = "com.android.stk.StkMain"; 35 private static final String LOG_TAG = "StkAppInstaller"; 36 StkAppInstaller()37 private StkAppInstaller() { 38 CatLog.d(LOG_TAG, "init"); 39 } 40 install(Context context)41 public static void install(Context context) { 42 setAppState(context, true); 43 } 44 unInstall(Context context)45 public static void unInstall(Context context) { 46 setAppState(context, false); 47 } 48 setAppState(Context context, boolean install)49 private static void setAppState(Context context, boolean install) { 50 CatLog.d(LOG_TAG, "[setAppState]+"); 51 if (context == null) { 52 CatLog.d(LOG_TAG, "[setAppState]- no context, just return."); 53 return; 54 } 55 PackageManager pm = context.getPackageManager(); 56 if (pm == null) { 57 CatLog.d(LOG_TAG, "[setAppState]- no package manager, just return."); 58 return; 59 } 60 ComponentName cName = new ComponentName("com.android.stk", STK_MAIN_ACTIVITY); 61 int state = install ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED 62 : PackageManager.COMPONENT_ENABLED_STATE_DISABLED; 63 64 if (((PackageManager.COMPONENT_ENABLED_STATE_ENABLED == state) && 65 (PackageManager.COMPONENT_ENABLED_STATE_ENABLED == 66 pm.getComponentEnabledSetting(cName))) || 67 ((PackageManager.COMPONENT_ENABLED_STATE_DISABLED == state) && 68 (PackageManager.COMPONENT_ENABLED_STATE_DISABLED == 69 pm.getComponentEnabledSetting(cName)))) { 70 CatLog.d(LOG_TAG, "Need not change app state!!"); 71 } else { 72 CatLog.d(LOG_TAG, "Change app state[" + install + "]"); 73 try { 74 pm.setComponentEnabledSetting(cName, state, PackageManager.DONT_KILL_APP); 75 } catch (Exception e) { 76 CatLog.d(LOG_TAG, "Could not change STK app state"); 77 } 78 } 79 CatLog.d(LOG_TAG, "[setAppState]-"); 80 } 81 } 82