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 =
36             new Object(){}.getClass().getEnclosingClass().getSimpleName();
37 
StkAppInstaller()38     private StkAppInstaller() {
39         CatLog.d(LOG_TAG, "init");
40     }
41 
install(Context context)42     public static void install(Context context) {
43         setAppState(context, true);
44     }
45 
unInstall(Context context)46     public static void unInstall(Context context) {
47         setAppState(context, false);
48     }
49 
setAppState(Context context, boolean install)50     private static void setAppState(Context context, boolean install) {
51         CatLog.d(LOG_TAG, "[setAppState]+");
52         if (context == null) {
53             CatLog.d(LOG_TAG, "[setAppState]- no context, just return.");
54             return;
55         }
56         PackageManager pm = context.getPackageManager();
57         if (pm == null) {
58             CatLog.d(LOG_TAG, "[setAppState]- no package manager, just return.");
59             return;
60         }
61         ComponentName cName = new ComponentName("com.android.stk", STK_MAIN_ACTIVITY);
62         int state = install ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
63                 : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
64 
65         if (((PackageManager.COMPONENT_ENABLED_STATE_ENABLED == state) &&
66                 (PackageManager.COMPONENT_ENABLED_STATE_ENABLED ==
67                 pm.getComponentEnabledSetting(cName))) ||
68                 ((PackageManager.COMPONENT_ENABLED_STATE_DISABLED == state) &&
69                 (PackageManager.COMPONENT_ENABLED_STATE_DISABLED ==
70                 pm.getComponentEnabledSetting(cName)))) {
71             CatLog.d(LOG_TAG, "Need not change app state!!");
72         } else {
73             CatLog.d(LOG_TAG, "Change app state[" + install + "]");
74             try {
75                 pm.setComponentEnabledSetting(cName, state, PackageManager.DONT_KILL_APP);
76             } catch (Exception e) {
77                 CatLog.d(LOG_TAG, "Could not change STK app state");
78             }
79         }
80         CatLog.d(LOG_TAG, "[setAppState]-");
81     }
82 }
83