blob: 4e386ee9fec7ab264aa2d9a6a8894074c927ca26 [file] [log] [blame]
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001/*
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
17package com.android.stk;
18
Alex Yakavenkad41f1d92010-07-12 14:13:13 -070019import com.android.internal.telephony.cat.CatLog;
Wink Savillee68857d2014-10-17 15:23:05 -070020import com.android.internal.telephony.PhoneConstants;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080021
22import android.content.ComponentName;
23import android.content.Context;
24import android.content.pm.PackageManager;
Wink Savillee68857d2014-10-17 15:23:05 -070025import android.telephony.TelephonyManager;
26import android.os.SystemProperties;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080027
28/**
29 * Application installer for SIM Toolkit.
Wink Saville79085fc2009-06-09 10:27:23 -070030 *
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080031 */
32abstract class StkAppInstaller {
Legler Wuc32560e2015-01-17 00:24:13 +080033 private static final String STK_MAIN_ACTIVITY = "com.android.stk.StkMain";
Yoshiaki Naka3a980db2019-10-30 17:11:33 +090034 private static final String LOG_TAG =
35 new Object(){}.getClass().getEnclosingClass().getSimpleName();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080036
Wink Savillee68857d2014-10-17 15:23:05 -070037 private StkAppInstaller() {
38 CatLog.d(LOG_TAG, "init");
39 }
40
41 public static void install(Context context) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080042 setAppState(context, true);
43 }
44
Wink Savillee68857d2014-10-17 15:23:05 -070045 public static void unInstall(Context context) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080046 setAppState(context, false);
47 }
48
49 private static void setAppState(Context context, boolean install) {
Wink Savillee68857d2014-10-17 15:23:05 -070050 CatLog.d(LOG_TAG, "[setAppState]+");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080051 if (context == null) {
Wink Savillee68857d2014-10-17 15:23:05 -070052 CatLog.d(LOG_TAG, "[setAppState]- no context, just return.");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080053 return;
54 }
55 PackageManager pm = context.getPackageManager();
56 if (pm == null) {
Wink Savillee68857d2014-10-17 15:23:05 -070057 CatLog.d(LOG_TAG, "[setAppState]- no package manager, just return.");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080058 return;
59 }
Legler Wuc32560e2015-01-17 00:24:13 +080060 ComponentName cName = new ComponentName("com.android.stk", STK_MAIN_ACTIVITY);
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080061 int state = install ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
62 : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
63
Wink Savillee68857d2014-10-17 15:23:05 -070064 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 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080078 }
Wink Savillee68857d2014-10-17 15:23:05 -070079 CatLog.d(LOG_TAG, "[setAppState]-");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080080 }
81}