Santos Cordon | 5d2c1e6 | 2014-11-21 15:20:15 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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.server.telecom; |
| 18 | |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 19 | import android.content.BroadcastReceiver; |
Santos Cordon | 5d2c1e6 | 2014-11-21 15:20:15 -0800 | [diff] [blame] | 20 | import android.content.ComponentName; |
| 21 | import android.content.Context; |
| 22 | import android.content.Intent; |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 23 | import android.content.IntentFilter; |
Santos Cordon | 5d2c1e6 | 2014-11-21 15:20:15 -0800 | [diff] [blame] | 24 | import android.content.ServiceConnection; |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 25 | import android.database.ContentObserver; |
| 26 | import android.net.Uri; |
| 27 | import android.os.Handler; |
Santos Cordon | 5d2c1e6 | 2014-11-21 15:20:15 -0800 | [diff] [blame] | 28 | import android.os.IBinder; |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 29 | import android.os.Looper; |
Santos Cordon | 5d2c1e6 | 2014-11-21 15:20:15 -0800 | [diff] [blame] | 30 | import android.os.RemoteException; |
| 31 | import android.os.ServiceManager; |
| 32 | import android.os.UserHandle; |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 33 | import android.provider.Settings; |
| 34 | import android.telecom.DefaultDialerManager; |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 35 | import android.telecom.PhoneAccountHandle; |
| 36 | import android.telecom.TelecomManager; |
| 37 | import android.telephony.CarrierConfigManager; |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 38 | import android.util.IntArray; |
Santos Cordon | 5d2c1e6 | 2014-11-21 15:20:15 -0800 | [diff] [blame] | 39 | import android.util.Slog; |
| 40 | |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 41 | import com.android.internal.annotations.GuardedBy; |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 42 | import com.android.internal.telephony.SmsApplication; |
| 43 | import com.android.server.LocalServices; |
Santos Cordon | 5d2c1e6 | 2014-11-21 15:20:15 -0800 | [diff] [blame] | 44 | import com.android.server.SystemService; |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 45 | import com.android.server.pm.UserManagerService; |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 46 | import com.android.server.pm.permission.DefaultPermissionGrantPolicy; |
| 47 | import com.android.server.pm.permission.PermissionManagerInternal; |
Santos Cordon | 5d2c1e6 | 2014-11-21 15:20:15 -0800 | [diff] [blame] | 48 | |
| 49 | /** |
| 50 | * Starts the telecom component by binding to its ITelecomService implementation. Telecom is setup |
| 51 | * to run in the system-server process so once it is loaded into memory it will stay running. |
| 52 | * @hide |
| 53 | */ |
| 54 | public class TelecomLoaderService extends SystemService { |
| 55 | private static final String TAG = "TelecomLoaderService"; |
| 56 | |
| 57 | private class TelecomServiceConnection implements ServiceConnection { |
| 58 | @Override |
| 59 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 60 | // Normally, we would listen for death here, but since telecom runs in the same process |
| 61 | // as this loader (process="system") thats redundant here. |
| 62 | try { |
| 63 | service.linkToDeath(new IBinder.DeathRecipient() { |
| 64 | @Override |
| 65 | public void binderDied() { |
| 66 | connectToTelecom(); |
| 67 | } |
| 68 | }, 0); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 69 | SmsApplication.getDefaultMmsApplication(mContext, false); |
Santos Cordon | 5d2c1e6 | 2014-11-21 15:20:15 -0800 | [diff] [blame] | 70 | ServiceManager.addService(Context.TELECOM_SERVICE, service); |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 71 | |
| 72 | synchronized (mLock) { |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 73 | if (mDefaultSmsAppRequests != null || mDefaultDialerAppRequests != null |
| 74 | || mDefaultSimCallManagerRequests != null) { |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 75 | final DefaultPermissionGrantPolicy permissionPolicy = |
| 76 | getDefaultPermissionGrantPolicy(); |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 77 | |
| 78 | if (mDefaultSmsAppRequests != null) { |
| 79 | ComponentName smsComponent = SmsApplication.getDefaultSmsApplication( |
| 80 | mContext, true); |
| 81 | if (smsComponent != null) { |
| 82 | final int requestCount = mDefaultSmsAppRequests.size(); |
| 83 | for (int i = requestCount - 1; i >= 0; i--) { |
| 84 | final int userid = mDefaultSmsAppRequests.get(i); |
| 85 | mDefaultSmsAppRequests.remove(i); |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 86 | permissionPolicy.grantDefaultPermissionsToDefaultSmsApp( |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 87 | smsComponent.getPackageName(), userid); |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | if (mDefaultDialerAppRequests != null) { |
| 93 | String packageName = DefaultDialerManager.getDefaultDialerApplication( |
| 94 | mContext); |
| 95 | if (packageName != null) { |
| 96 | final int requestCount = mDefaultDialerAppRequests.size(); |
| 97 | for (int i = requestCount - 1; i >= 0; i--) { |
| 98 | final int userId = mDefaultDialerAppRequests.get(i); |
| 99 | mDefaultDialerAppRequests.remove(i); |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 100 | permissionPolicy.grantDefaultPermissionsToDefaultDialerApp( |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 101 | packageName, userId); |
| 102 | } |
| 103 | } |
| 104 | } |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 105 | if (mDefaultSimCallManagerRequests != null) { |
| 106 | TelecomManager telecomManager = |
| 107 | (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); |
| 108 | PhoneAccountHandle phoneAccount = telecomManager.getSimCallManager(); |
| 109 | if (phoneAccount != null) { |
| 110 | final int requestCount = mDefaultSimCallManagerRequests.size(); |
| 111 | final String packageName = |
| 112 | phoneAccount.getComponentName().getPackageName(); |
| 113 | for (int i = requestCount - 1; i >= 0; i--) { |
| 114 | final int userId = mDefaultSimCallManagerRequests.get(i); |
| 115 | mDefaultSimCallManagerRequests.remove(i); |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 116 | permissionPolicy |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 117 | .grantDefaultPermissionsToDefaultSimCallManager( |
| 118 | packageName, userId); |
| 119 | } |
| 120 | } |
| 121 | } |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 122 | } |
| 123 | } |
Santos Cordon | 5d2c1e6 | 2014-11-21 15:20:15 -0800 | [diff] [blame] | 124 | } catch (RemoteException e) { |
| 125 | Slog.w(TAG, "Failed linking to death."); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | @Override |
| 130 | public void onServiceDisconnected(ComponentName name) { |
| 131 | connectToTelecom(); |
| 132 | } |
| 133 | } |
| 134 | |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 135 | private DefaultPermissionGrantPolicy getDefaultPermissionGrantPolicy() { |
| 136 | return LocalServices.getService(PermissionManagerInternal.class) |
| 137 | .getDefaultPermissionGrantPolicy(); |
| 138 | } |
| 139 | |
Santos Cordon | 5d2c1e6 | 2014-11-21 15:20:15 -0800 | [diff] [blame] | 140 | private static final ComponentName SERVICE_COMPONENT = new ComponentName( |
| 141 | "com.android.server.telecom", |
Ihab Awad | c4959ab | 2015-02-06 17:01:49 -0800 | [diff] [blame] | 142 | "com.android.server.telecom.components.TelecomService"); |
Santos Cordon | 5d2c1e6 | 2014-11-21 15:20:15 -0800 | [diff] [blame] | 143 | |
| 144 | private static final String SERVICE_ACTION = "com.android.ITelecomService"; |
| 145 | |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 146 | private final Object mLock = new Object(); |
| 147 | |
| 148 | @GuardedBy("mLock") |
| 149 | private IntArray mDefaultSmsAppRequests; |
| 150 | |
| 151 | @GuardedBy("mLock") |
| 152 | private IntArray mDefaultDialerAppRequests; |
| 153 | |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 154 | @GuardedBy("mLock") |
| 155 | private IntArray mDefaultSimCallManagerRequests; |
| 156 | |
Santos Cordon | 5d2c1e6 | 2014-11-21 15:20:15 -0800 | [diff] [blame] | 157 | private final Context mContext; |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 158 | |
| 159 | @GuardedBy("mLock") |
Santos Cordon | 5d2c1e6 | 2014-11-21 15:20:15 -0800 | [diff] [blame] | 160 | private TelecomServiceConnection mServiceConnection; |
| 161 | |
| 162 | public TelecomLoaderService(Context context) { |
| 163 | super(context); |
| 164 | mContext = context; |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 165 | registerDefaultAppProviders(); |
Santos Cordon | 5d2c1e6 | 2014-11-21 15:20:15 -0800 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | @Override |
| 169 | public void onStart() { |
| 170 | } |
| 171 | |
| 172 | @Override |
| 173 | public void onBootPhase(int phase) { |
| 174 | if (phase == PHASE_ACTIVITY_MANAGER_READY) { |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 175 | registerDefaultAppNotifier(); |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 176 | registerCarrierConfigChangedReceiver(); |
Santos Cordon | 5d2c1e6 | 2014-11-21 15:20:15 -0800 | [diff] [blame] | 177 | connectToTelecom(); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | private void connectToTelecom() { |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 182 | synchronized (mLock) { |
| 183 | if (mServiceConnection != null) { |
| 184 | // TODO: Is unbinding worth doing or wait for system to rebind? |
| 185 | mContext.unbindService(mServiceConnection); |
| 186 | mServiceConnection = null; |
| 187 | } |
Santos Cordon | 5d2c1e6 | 2014-11-21 15:20:15 -0800 | [diff] [blame] | 188 | |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 189 | TelecomServiceConnection serviceConnection = new TelecomServiceConnection(); |
| 190 | Intent intent = new Intent(SERVICE_ACTION); |
| 191 | intent.setComponent(SERVICE_COMPONENT); |
| 192 | int flags = Context.BIND_IMPORTANT | Context.BIND_FOREGROUND_SERVICE |
| 193 | | Context.BIND_AUTO_CREATE; |
Santos Cordon | 5d2c1e6 | 2014-11-21 15:20:15 -0800 | [diff] [blame] | 194 | |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 195 | // Bind to Telecom and register the service |
Xiaohui Chen | e4de5a0 | 2015-09-22 15:33:31 -0700 | [diff] [blame] | 196 | if (mContext.bindServiceAsUser(intent, serviceConnection, flags, UserHandle.SYSTEM)) { |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 197 | mServiceConnection = serviceConnection; |
| 198 | } |
Santos Cordon | 5d2c1e6 | 2014-11-21 15:20:15 -0800 | [diff] [blame] | 199 | } |
| 200 | } |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 201 | |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 202 | |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 203 | private void registerDefaultAppProviders() { |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 204 | final DefaultPermissionGrantPolicy permissionPolicy = getDefaultPermissionGrantPolicy(); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 205 | |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 206 | // Set a callback for the permission grant policy to query the default sms app. |
| 207 | permissionPolicy.setSmsAppPackagesProvider(userId -> { |
| 208 | synchronized (mLock) { |
| 209 | if (mServiceConnection == null) { |
| 210 | if (mDefaultSmsAppRequests == null) { |
| 211 | mDefaultSmsAppRequests = new IntArray(); |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 212 | } |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 213 | mDefaultSmsAppRequests.add(userId); |
| 214 | return null; |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 215 | } |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 216 | } |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 217 | ComponentName smsComponent = SmsApplication.getDefaultSmsApplication( |
| 218 | mContext, true); |
| 219 | if (smsComponent != null) { |
| 220 | return new String[]{smsComponent.getPackageName()}; |
| 221 | } |
| 222 | return null; |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 223 | }); |
| 224 | |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 225 | // Set a callback for the permission grant policy to query the default dialer app. |
| 226 | permissionPolicy.setDialerAppPackagesProvider(userId -> { |
| 227 | synchronized (mLock) { |
| 228 | if (mServiceConnection == null) { |
| 229 | if (mDefaultDialerAppRequests == null) { |
| 230 | mDefaultDialerAppRequests = new IntArray(); |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 231 | } |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 232 | mDefaultDialerAppRequests.add(userId); |
| 233 | return null; |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 234 | } |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 235 | } |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 236 | String packageName = DefaultDialerManager.getDefaultDialerApplication(mContext); |
| 237 | if (packageName != null) { |
| 238 | return new String[]{packageName}; |
| 239 | } |
| 240 | return null; |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 241 | }); |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 242 | |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 243 | // Set a callback for the permission grant policy to query the default sim call manager. |
| 244 | permissionPolicy.setSimCallManagerPackagesProvider(userId -> { |
| 245 | synchronized (mLock) { |
| 246 | if (mServiceConnection == null) { |
| 247 | if (mDefaultSimCallManagerRequests == null) { |
| 248 | mDefaultSimCallManagerRequests = new IntArray(); |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 249 | } |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 250 | mDefaultSimCallManagerRequests.add(userId); |
| 251 | return null; |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 252 | } |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 253 | } |
| 254 | TelecomManager telecomManager = |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 255 | (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 256 | PhoneAccountHandle phoneAccount = telecomManager.getSimCallManager(userId); |
| 257 | if (phoneAccount != null) { |
| 258 | return new String[]{phoneAccount.getComponentName().getPackageName()}; |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 259 | } |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 260 | return null; |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 261 | }); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | private void registerDefaultAppNotifier() { |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 265 | final DefaultPermissionGrantPolicy permissionPolicy = getDefaultPermissionGrantPolicy(); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 266 | |
| 267 | // Notify the package manager on default app changes |
| 268 | final Uri defaultSmsAppUri = Settings.Secure.getUriFor( |
| 269 | Settings.Secure.SMS_DEFAULT_APPLICATION); |
| 270 | final Uri defaultDialerAppUri = Settings.Secure.getUriFor( |
| 271 | Settings.Secure.DIALER_DEFAULT_APPLICATION); |
| 272 | |
| 273 | ContentObserver contentObserver = new ContentObserver( |
| 274 | new Handler(Looper.getMainLooper())) { |
| 275 | @Override |
| 276 | public void onChange(boolean selfChange, Uri uri, int userId) { |
| 277 | if (defaultSmsAppUri.equals(uri)) { |
| 278 | ComponentName smsComponent = SmsApplication.getDefaultSmsApplication( |
| 279 | mContext, true); |
| 280 | if (smsComponent != null) { |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 281 | permissionPolicy.grantDefaultPermissionsToDefaultSmsApp( |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 282 | smsComponent.getPackageName(), userId); |
| 283 | } |
| 284 | } else if (defaultDialerAppUri.equals(uri)) { |
| 285 | String packageName = DefaultDialerManager.getDefaultDialerApplication( |
| 286 | mContext); |
| 287 | if (packageName != null) { |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 288 | permissionPolicy.grantDefaultPermissionsToDefaultDialerApp( |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 289 | packageName, userId); |
| 290 | } |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 291 | updateSimCallManagerPermissions(permissionPolicy, userId); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 292 | } |
| 293 | } |
| 294 | }; |
| 295 | |
| 296 | mContext.getContentResolver().registerContentObserver(defaultSmsAppUri, |
| 297 | false, contentObserver, UserHandle.USER_ALL); |
| 298 | mContext.getContentResolver().registerContentObserver(defaultDialerAppUri, |
| 299 | false, contentObserver, UserHandle.USER_ALL); |
| 300 | } |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 301 | |
| 302 | |
| 303 | private void registerCarrierConfigChangedReceiver() { |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 304 | BroadcastReceiver receiver = new BroadcastReceiver() { |
| 305 | @Override |
| 306 | public void onReceive(Context context, Intent intent) { |
| 307 | if (intent.getAction().equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) { |
| 308 | for (int userId : UserManagerService.getInstance().getUserIds()) { |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 309 | updateSimCallManagerPermissions(getDefaultPermissionGrantPolicy(), userId); |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 310 | } |
| 311 | } |
| 312 | } |
| 313 | }; |
| 314 | |
| 315 | mContext.registerReceiverAsUser(receiver, UserHandle.ALL, |
| 316 | new IntentFilter(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED), null, null); |
| 317 | } |
| 318 | |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 319 | private void updateSimCallManagerPermissions( |
| 320 | DefaultPermissionGrantPolicy permissionGrantPolicy, int userId) { |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 321 | TelecomManager telecomManager = |
| 322 | (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); |
| 323 | PhoneAccountHandle phoneAccount = telecomManager.getSimCallManager(userId); |
| 324 | if (phoneAccount != null) { |
| 325 | Slog.i(TAG, "updating sim call manager permissions for userId:" + userId); |
| 326 | String packageName = phoneAccount.getComponentName().getPackageName(); |
Philip P. Moltmann | b0be05c | 2018-09-19 02:46:56 +0000 | [diff] [blame] | 327 | permissionGrantPolicy.grantDefaultPermissionsToDefaultSimCallManager( |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 328 | packageName, userId); |
| 329 | } |
| 330 | } |
Santos Cordon | 5d2c1e6 | 2014-11-21 15:20:15 -0800 | [diff] [blame] | 331 | } |