The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 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 | |
Alex Yakavenka | d41f1d9 | 2010-07-12 14:13:13 -0700 | [diff] [blame] | 19 | import com.android.internal.telephony.cat.CatLog; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 20 | import com.android.internal.telephony.PhoneConstants; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 21 | |
| 22 | import android.content.ComponentName; |
| 23 | import android.content.Context; |
| 24 | import android.content.pm.PackageManager; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 25 | import android.telephony.TelephonyManager; |
| 26 | import android.os.SystemProperties; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * Application installer for SIM Toolkit. |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 30 | * |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 31 | */ |
| 32 | abstract class StkAppInstaller { |
Legler Wu | c32560e | 2015-01-17 00:24:13 +0800 | [diff] [blame] | 33 | private static final String STK_MAIN_ACTIVITY = "com.android.stk.StkMain"; |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 34 | private static final String LOG_TAG = |
| 35 | new Object(){}.getClass().getEnclosingClass().getSimpleName(); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 36 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 37 | private StkAppInstaller() { |
| 38 | CatLog.d(LOG_TAG, "init"); |
| 39 | } |
| 40 | |
| 41 | public static void install(Context context) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 42 | setAppState(context, true); |
| 43 | } |
| 44 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 45 | public static void unInstall(Context context) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 46 | setAppState(context, false); |
| 47 | } |
| 48 | |
| 49 | private static void setAppState(Context context, boolean install) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 50 | CatLog.d(LOG_TAG, "[setAppState]+"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 51 | if (context == null) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 52 | CatLog.d(LOG_TAG, "[setAppState]- no context, just return."); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 53 | return; |
| 54 | } |
| 55 | PackageManager pm = context.getPackageManager(); |
| 56 | if (pm == null) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 57 | CatLog.d(LOG_TAG, "[setAppState]- no package manager, just return."); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 58 | return; |
| 59 | } |
Legler Wu | c32560e | 2015-01-17 00:24:13 +0800 | [diff] [blame] | 60 | ComponentName cName = new ComponentName("com.android.stk", STK_MAIN_ACTIVITY); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 61 | int state = install ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED |
| 62 | : PackageManager.COMPONENT_ENABLED_STATE_DISABLED; |
| 63 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 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 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 78 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 79 | CatLog.d(LOG_TAG, "[setAppState]-"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 80 | } |
| 81 | } |