blob: fe25af619cbd1121bbaee684c876dce93d70be44 [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
Wink Savillee68857d2014-10-17 15:23:05 -070019import com.android.internal.telephony.PhoneConstants;
Yoshiaki Naka835e3002020-05-11 18:15:12 +090020import com.android.internal.telephony.cat.CatLog;
21import com.android.internal.telephony.util.TelephonyUtils;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080022
23import android.content.ComponentName;
24import android.content.Context;
Yoshiaki Naka835e3002020-05-11 18:15:12 +090025import android.content.pm.IPackageManager;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080026import android.content.pm.PackageManager;
Yoshiaki Naka835e3002020-05-11 18:15:12 +090027import android.os.Build;
28import android.os.RemoteException;
29import android.os.ServiceManager;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080030
31/**
32 * Application installer for SIM Toolkit.
Wink Saville79085fc2009-06-09 10:27:23 -070033 *
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080034 */
Yoshiaki Naka835e3002020-05-11 18:15:12 +090035final class StkAppInstaller {
36 private static final boolean DBG = TelephonyUtils.IS_DEBUGGABLE;
Yoshiaki Naka3a980db2019-10-30 17:11:33 +090037 private static final String LOG_TAG =
38 new Object(){}.getClass().getEnclosingClass().getSimpleName();
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080039
Wink Savillee68857d2014-10-17 15:23:05 -070040 private StkAppInstaller() {
Wink Savillee68857d2014-10-17 15:23:05 -070041 }
42
Yoshiaki Naka835e3002020-05-11 18:15:12 +090043 static void installOrUpdate(Context context, String label) {
44 IPackageManager pm = IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
45 if (pm != null) {
46 ComponentName component = new ComponentName(context, StkMain.class);
47 int userId = context.getUserId();
48 int icon = R.drawable.ic_launcher_sim_toolkit;
Wink Savillee68857d2014-10-17 15:23:05 -070049 try {
Yoshiaki Naka835e3002020-05-11 18:15:12 +090050 try {
51 if (label != null) {
52 pm.overrideLabelAndIcon(component, label, icon, userId);
53 } else {
54 pm.restoreLabelAndIcon(component, userId);
55 }
56 if (DBG) CatLog.d(LOG_TAG, "Set the label to " + label);
57 } catch (SecurityException e) {
58 CatLog.e(LOG_TAG, "Failed to set the label to " + label);
59 }
60 setAppState(pm, component, userId, true);
61 } catch (RemoteException e) {
62 CatLog.e(LOG_TAG, "Failed to enable SIM Toolkit");
Wink Savillee68857d2014-10-17 15:23:05 -070063 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080064 }
Yoshiaki Naka835e3002020-05-11 18:15:12 +090065 }
66
67 static void uninstall(Context context) {
68 IPackageManager pm = IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
69 if (pm != null) {
70 ComponentName component = new ComponentName(context, StkMain.class);
71 try {
72 setAppState(pm, component, context.getUserId(), false);
73 } catch (RemoteException e) {
74 CatLog.e(LOG_TAG, "Failed to disable SIM Toolkit");
75 }
76 }
77 }
78
79 static void setAppState(IPackageManager pm, ComponentName component, int userId, boolean enable)
80 throws RemoteException {
81 int current = pm.getComponentEnabledSetting(component, userId);
82 int expected = enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
83 : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
84 if (current != expected) {
85 pm.setComponentEnabledSetting(component, expected, PackageManager.DONT_KILL_APP,
86 userId);
87 if (DBG) CatLog.d(LOG_TAG, "SIM Toolkit is " + (enable ? "enabled" : "disabled"));
88 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080089 }
90}