StkAppInstaller.java revision c46d8a06f810a3b5b570e43e7e0ed8b36efd23e5
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
17package com.android.stk;
18
19import com.android.internal.telephony.gsm.stk.StkLog;
20
21import android.content.ComponentName;
22import android.content.Context;
23import android.content.pm.PackageManager;
24
25/**
26 * Application installer for SIM Toolkit.
27 *
28 */
29abstract 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) {
58            StkLog.d("StkAppInstaller", "Could not change STK app state");
59        }
60    }
61}
62