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 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 19 | import com.android.internal.telephony.PhoneConstants; |
Yoshiaki Naka | 835e300 | 2020-05-11 18:15:12 +0900 | [diff] [blame] | 20 | import com.android.internal.telephony.cat.CatLog; |
| 21 | import com.android.internal.telephony.util.TelephonyUtils; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 22 | |
| 23 | import android.content.ComponentName; |
| 24 | import android.content.Context; |
Yoshiaki Naka | 835e300 | 2020-05-11 18:15:12 +0900 | [diff] [blame] | 25 | import android.content.pm.IPackageManager; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 26 | import android.content.pm.PackageManager; |
Yoshiaki Naka | 835e300 | 2020-05-11 18:15:12 +0900 | [diff] [blame] | 27 | import android.os.Build; |
| 28 | import android.os.RemoteException; |
| 29 | import android.os.ServiceManager; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * Application installer for SIM Toolkit. |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 33 | * |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 34 | */ |
Yoshiaki Naka | 835e300 | 2020-05-11 18:15:12 +0900 | [diff] [blame] | 35 | final class StkAppInstaller { |
| 36 | private static final boolean DBG = TelephonyUtils.IS_DEBUGGABLE; |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 37 | private static final String LOG_TAG = |
| 38 | new Object(){}.getClass().getEnclosingClass().getSimpleName(); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 39 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 40 | private StkAppInstaller() { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 41 | } |
| 42 | |
Yoshiaki Naka | 835e300 | 2020-05-11 18:15:12 +0900 | [diff] [blame] | 43 | 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 Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 49 | try { |
Yoshiaki Naka | 835e300 | 2020-05-11 18:15:12 +0900 | [diff] [blame] | 50 | 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 Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 63 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 64 | } |
Yoshiaki Naka | 835e300 | 2020-05-11 18:15:12 +0900 | [diff] [blame] | 65 | } |
| 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 Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 89 | } |
| 90 | } |