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; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 20 | |
| 21 | import android.content.ComponentName; |
| 22 | import android.content.Context; |
| 23 | import android.content.pm.PackageManager; |
| 24 | |
| 25 | /** |
| 26 | * Application installer for SIM Toolkit. |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 27 | * |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 28 | */ |
| 29 | abstract class StkAppInstaller { |
| 30 | private StkAppInstaller() {} |
| 31 | |
| 32 | static void install(Context context) { |
| 33 | setAppState(context, true); |
| 34 | } |
| 35 | |
| 36 | static void unInstall(Context context) { |
| 37 | setAppState(context, false); |
| 38 | } |
| 39 | |
| 40 | private static void setAppState(Context context, boolean install) { |
| 41 | if (context == null) { |
| 42 | return; |
| 43 | } |
| 44 | PackageManager pm = context.getPackageManager(); |
| 45 | if (pm == null) { |
| 46 | return; |
| 47 | } |
| 48 | // check that STK app package is known to the PackageManager |
| 49 | ComponentName cName = new ComponentName("com.android.stk", |
| 50 | "com.android.stk.StkLauncherActivity"); |
| 51 | int state = install ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED |
| 52 | : PackageManager.COMPONENT_ENABLED_STATE_DISABLED; |
| 53 | |
| 54 | try { |
| 55 | pm.setComponentEnabledSetting(cName, state, |
| 56 | PackageManager.DONT_KILL_APP); |
| 57 | } catch (Exception e) { |
Alex Yakavenka | d41f1d9 | 2010-07-12 14:13:13 -0700 | [diff] [blame] | 58 | CatLog.d("StkAppInstaller", "Could not change STK app state"); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 59 | } |
| 60 | } |
| 61 | } |