diff options
6 files changed, 179 insertions, 1 deletions
diff --git a/core/java/android/content/pm/PackageManagerInternal.java b/core/java/android/content/pm/PackageManagerInternal.java index ea08956..bf70d6c 100644 --- a/core/java/android/content/pm/PackageManagerInternal.java +++ b/core/java/android/content/pm/PackageManagerInternal.java @@ -83,6 +83,12 @@ public abstract class PackageManagerInternal { public abstract void setDialerAppPackagesProvider(PackagesProvider provider); /** + * Sets the sim call manager packages provider. + * @param provider The packages provider. + */ + public abstract void setSimCallManagerPackagesProvider(PackagesProvider provider); + + /** * Sets the sync adapter packages provider. * @param provider The provider. */ @@ -101,4 +107,12 @@ public abstract class PackageManagerInternal { * @param userId The user for which to grant the permissions. */ public abstract void grantDefaultPermissionsToDefaultDialerApp(String packageName, int userId); + + /** + * Requests granting of the default permissions to the current default sim call manager. + * @param packageName The default sim call manager package name. + * @param userId The user for which to grant the permissions. + */ + public abstract void grantDefaultPermissionsToDefaultSimCallManager(String packageName, + int userId); } diff --git a/services/core/java/com/android/server/pm/DefaultPermissionGrantPolicy.java b/services/core/java/com/android/server/pm/DefaultPermissionGrantPolicy.java index 0d1d1ea..94011fd 100644 --- a/services/core/java/com/android/server/pm/DefaultPermissionGrantPolicy.java +++ b/services/core/java/com/android/server/pm/DefaultPermissionGrantPolicy.java @@ -125,6 +125,7 @@ final class DefaultPermissionGrantPolicy { private PackagesProvider mVoiceInteractionPackagesProvider; private PackagesProvider mSmsAppPackagesProvider; private PackagesProvider mDialerAppPackagesProvider; + private PackagesProvider mSimCallManagerPackagesProvider; private SyncAdapterPackagesProvider mSyncAdapterPackagesProvider; public DefaultPermissionGrantPolicy(PackageManagerService service) { @@ -151,6 +152,10 @@ final class DefaultPermissionGrantPolicy { mDialerAppPackagesProvider = provider; } + public void setSimCallManagerPackagesProviderLPw(PackagesProvider provider) { + mSimCallManagerPackagesProvider = provider; + } + public void setSyncAdapterPackagesProviderLPw(SyncAdapterPackagesProvider provider) { mSyncAdapterPackagesProvider = provider; } @@ -201,6 +206,7 @@ final class DefaultPermissionGrantPolicy { final PackagesProvider voiceInteractionPackagesProvider; final PackagesProvider smsAppPackagesProvider; final PackagesProvider dialerAppPackagesProvider; + final PackagesProvider simCallManagerPackagesProvider; final SyncAdapterPackagesProvider syncAdapterPackagesProvider; synchronized (mService.mPackages) { @@ -209,6 +215,7 @@ final class DefaultPermissionGrantPolicy { voiceInteractionPackagesProvider = mVoiceInteractionPackagesProvider; smsAppPackagesProvider = mSmsAppPackagesProvider; dialerAppPackagesProvider = mDialerAppPackagesProvider; + simCallManagerPackagesProvider = mSimCallManagerPackagesProvider; syncAdapterPackagesProvider = mSyncAdapterPackagesProvider; } @@ -222,6 +229,8 @@ final class DefaultPermissionGrantPolicy { ? smsAppPackagesProvider.getPackages(userId) : null; String[] dialerAppPackageNames = (dialerAppPackagesProvider != null) ? dialerAppPackagesProvider.getPackages(userId) : null; + String[] simCallManagerPackageNames = (simCallManagerPackagesProvider != null) + ? simCallManagerPackagesProvider.getPackages(userId) : null; String[] contactsSyncAdapterPackages = (syncAdapterPackagesProvider != null) ? syncAdapterPackagesProvider.getPackages(ContactsContract.AUTHORITY, userId) : null; String[] calendarSyncAdapterPackages = (syncAdapterPackagesProvider != null) ? @@ -313,6 +322,18 @@ final class DefaultPermissionGrantPolicy { } } + // Sim call manager + if (simCallManagerPackageNames != null) { + for (String simCallManagerPackageName : simCallManagerPackageNames) { + PackageParser.Package simCallManagerPackage = + getSystemPackageLPr(simCallManagerPackageName); + if (simCallManagerPackage != null) { + grantDefaultPermissionsToDefaultSimCallManagerLPr(simCallManagerPackage, + userId); + } + } + } + // SMS if (smsAppPackageNames == null) { Intent smsIntent = new Intent(Intent.ACTION_MAIN); @@ -590,6 +611,25 @@ final class DefaultPermissionGrantPolicy { } } + private void grantDefaultPermissionsToDefaultSimCallManagerLPr( + PackageParser.Package simCallManagerPackage, int userId) { + Log.i(TAG, "Granting permissions to sim call manager for user:" + userId); + if (doesPackageSupportRuntimePermissions(simCallManagerPackage)) { + grantRuntimePermissionsLPw(simCallManagerPackage, PHONE_PERMISSIONS, userId); + grantRuntimePermissionsLPw(simCallManagerPackage, MICROPHONE_PERMISSIONS, userId); + } + } + + public void grantDefaultPermissionsToDefaultSimCallManagerLPr(String packageName, int userId) { + if (packageName == null) { + return; + } + PackageParser.Package simCallManagerPackage = getPackageLPr(packageName); + if (simCallManagerPackage != null) { + grantDefaultPermissionsToDefaultSimCallManagerLPr(simCallManagerPackage, userId); + } + } + public void grantDefaultPermissionsToEnabledCarrierAppsLPr(String[] packageNames, int userId) { Log.i(TAG, "Granting permissions to enabled carrier apps for user:" + userId); if (packageNames == null) { diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java index b7756ac..b0d66ed 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -16519,6 +16519,13 @@ public class PackageManagerService extends IPackageManager.Stub { } @Override + public void setSimCallManagerPackagesProvider(PackagesProvider provider) { + synchronized (mPackages) { + mDefaultPermissionPolicy.setSimCallManagerPackagesProviderLPw(provider); + } + } + + @Override public void setSyncAdapterPackagesprovider(SyncAdapterPackagesProvider provider) { synchronized (mPackages) { mDefaultPermissionPolicy.setSyncAdapterPackagesProviderLPw(provider); @@ -16540,6 +16547,13 @@ public class PackageManagerService extends IPackageManager.Stub { packageName, userId); } } + @Override + public void grantDefaultPermissionsToDefaultSimCallManager(String packageName, int userId) { + synchronized (mPackages) { + mDefaultPermissionPolicy.grantDefaultPermissionsToDefaultSimCallManagerLPr( + packageName, userId); + } + } } @Override diff --git a/services/core/java/com/android/server/telecom/TelecomLoaderService.java b/services/core/java/com/android/server/telecom/TelecomLoaderService.java index c2ce572..f4bd61f 100644 --- a/services/core/java/com/android/server/telecom/TelecomLoaderService.java +++ b/services/core/java/com/android/server/telecom/TelecomLoaderService.java @@ -16,9 +16,11 @@ package com.android.server.telecom; +import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; import android.content.Intent; +import android.content.IntentFilter; import android.content.ServiceConnection; import android.content.pm.PackageManagerInternal; import android.database.ContentObserver; @@ -31,6 +33,9 @@ import android.os.ServiceManager; import android.os.UserHandle; import android.provider.Settings; import android.telecom.DefaultDialerManager; +import android.telecom.PhoneAccountHandle; +import android.telecom.TelecomManager; +import android.telephony.CarrierConfigManager; import android.util.IntArray; import android.util.Slog; @@ -39,6 +44,7 @@ import com.android.internal.annotations.GuardedBy; import com.android.internal.telephony.SmsApplication; import com.android.server.LocalServices; import com.android.server.SystemService; +import com.android.server.pm.UserManagerService; /** * Starts the telecom component by binding to its ITelecomService implementation. Telecom is setup @@ -64,7 +70,8 @@ public class TelecomLoaderService extends SystemService { ServiceManager.addService(Context.TELECOM_SERVICE, service); synchronized (mLock) { - if (mDefaultSmsAppRequests != null || mDefaultDialerAppRequests != null) { + if (mDefaultSmsAppRequests != null || mDefaultDialerAppRequests != null + || mDefaultSimCallManagerRequests != null) { final PackageManagerInternal packageManagerInternal = LocalServices .getService(PackageManagerInternal.class); @@ -95,6 +102,23 @@ public class TelecomLoaderService extends SystemService { } } } + if (mDefaultSimCallManagerRequests != null) { + TelecomManager telecomManager = + (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); + PhoneAccountHandle phoneAccount = telecomManager.getSimCallManager(); + if (phoneAccount != null) { + final int requestCount = mDefaultSimCallManagerRequests.size(); + final String packageName = + phoneAccount.getComponentName().getPackageName(); + for (int i = requestCount - 1; i >= 0; i--) { + final int userId = mDefaultSimCallManagerRequests.get(i); + mDefaultSimCallManagerRequests.remove(i); + packageManagerInternal + .grantDefaultPermissionsToDefaultSimCallManager( + packageName, userId); + } + } + } } } } catch (RemoteException e) { @@ -122,6 +146,9 @@ public class TelecomLoaderService extends SystemService { @GuardedBy("mLock") private IntArray mDefaultDialerAppRequests; + @GuardedBy("mLock") + private IntArray mDefaultSimCallManagerRequests; + private final Context mContext; @GuardedBy("mLock") @@ -141,6 +168,7 @@ public class TelecomLoaderService extends SystemService { public void onBootPhase(int phase) { if (phase == PHASE_ACTIVITY_MANAGER_READY) { registerDefaultAppNotifier(); + registerCarrierConfigChangedReceiver(); connectToTelecom(); } } @@ -215,6 +243,30 @@ public class TelecomLoaderService extends SystemService { return null; } }); + + // Set a callback for the package manager to query the default sim call manager. + packageManagerInternal.setSimCallManagerPackagesProvider( + new PackageManagerInternal.PackagesProvider() { + @Override + public String[] getPackages(int userId) { + synchronized (mLock) { + if (mServiceConnection == null) { + if (mDefaultSimCallManagerRequests == null) { + mDefaultSimCallManagerRequests = new IntArray(); + } + mDefaultSimCallManagerRequests.add(userId); + return null; + } + } + TelecomManager telecomManager = + (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); + PhoneAccountHandle phoneAccount = telecomManager.getSimCallManager(userId); + if (phoneAccount != null) { + return new String[]{phoneAccount.getComponentName().getPackageName()}; + } + return null; + } + }); } private void registerDefaultAppNotifier() { @@ -245,6 +297,7 @@ public class TelecomLoaderService extends SystemService { packageManagerInternal.grantDefaultPermissionsToDefaultDialerApp( packageName, userId); } + updateSimCallManagerPermissions(packageManagerInternal, userId); } } }; @@ -254,4 +307,36 @@ public class TelecomLoaderService extends SystemService { mContext.getContentResolver().registerContentObserver(defaultDialerAppUri, false, contentObserver, UserHandle.USER_ALL); } + + + private void registerCarrierConfigChangedReceiver() { + final PackageManagerInternal packageManagerInternal = LocalServices.getService( + PackageManagerInternal.class); + BroadcastReceiver receiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + if (intent.getAction().equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) { + for (int userId : UserManagerService.getInstance().getUserIds()) { + updateSimCallManagerPermissions(packageManagerInternal, userId); + } + } + } + }; + + mContext.registerReceiverAsUser(receiver, UserHandle.ALL, + new IntentFilter(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED), null, null); + } + + private void updateSimCallManagerPermissions(PackageManagerInternal packageManagerInternal, + int userId) { + TelecomManager telecomManager = + (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); + PhoneAccountHandle phoneAccount = telecomManager.getSimCallManager(userId); + if (phoneAccount != null) { + Slog.i(TAG, "updating sim call manager permissions for userId:" + userId); + String packageName = phoneAccount.getComponentName().getPackageName(); + packageManagerInternal.grantDefaultPermissionsToDefaultSimCallManager( + packageName, userId); + } + } } diff --git a/telecomm/java/android/telecom/TelecomManager.java b/telecomm/java/android/telecom/TelecomManager.java index a30e1c0..3b59f27 100644 --- a/telecomm/java/android/telecom/TelecomManager.java +++ b/telecomm/java/android/telecom/TelecomManager.java @@ -493,6 +493,26 @@ public class TelecomManager { } /** + * Returns the current SIM call manager for the specified user. Apps must be prepared for this + * method to return {@code null}, indicating that there currently exists no user-chosen default + * {@code PhoneAccount}. + * + * @return The phone account handle of the current sim call manager. + * + * @hide + */ + public PhoneAccountHandle getSimCallManager(int userId) { + try { + if (isServiceConnected()) { + return getTelecomService().getSimCallManagerForUser(userId); + } + } catch (RemoteException e) { + Log.e(TAG, "Error calling ITelecomService#getSimCallManagerForUser"); + } + return null; + } + + /** * Returns the current connection manager. Apps must be prepared for this method to return * {@code null}, indicating that there currently exists no user-chosen default * {@code PhoneAccount}. diff --git a/telecomm/java/com/android/internal/telecom/ITelecomService.aidl b/telecomm/java/com/android/internal/telecom/ITelecomService.aidl index fb0f6da..2e07759 100644 --- a/telecomm/java/com/android/internal/telecom/ITelecomService.aidl +++ b/telecomm/java/com/android/internal/telecom/ITelecomService.aidl @@ -93,6 +93,11 @@ interface ITelecomService { PhoneAccountHandle getSimCallManager(); /** + * @see TelecomServiceImpl#getSimCallManagerForUser + */ + PhoneAccountHandle getSimCallManagerForUser(int userId); + + /** * @see TelecomServiceImpl#registerPhoneAccount */ void registerPhoneAccount(in PhoneAccount metadata); |