Loading services/people/java/com/android/server/people/data/DataManager.java +1 −1 Original line number Diff line number Diff line Loading @@ -788,7 +788,7 @@ public class DataManager { private void updateDefaultSmsApp(@NonNull UserData userData) { ComponentName component = SmsApplication.getDefaultSmsApplicationAsUser( mContext, /* updateIfNeeded= */ false, userData.getUserId()); mContext, /* updateIfNeeded= */ false, UserHandle.of(userData.getUserId())); String defaultSmsApp = component != null ? component.getPackageName() : null; userData.setDefaultSmsApp(defaultSmsApp); } Loading telephony/common/com/android/internal/telephony/SmsApplication.java +95 −34 Original line number Diff line number Diff line Loading @@ -209,6 +209,15 @@ public final class SmsApplication { } } /** * Returns the userHandle of the current process, if called from a system app, * otherwise it returns the caller's userHandle * @return userHandle of the caller. */ private static UserHandle getIncomingUserHandle() { return UserHandle.of(getIncomingUserId()); } /** * Returns the list of available SMS apps defined as apps that are registered for both the * SMS_RECEIVED_ACTION (SMS) and WAP_PUSH_RECEIVED_ACTION (MMS) broadcasts (and their broadcast Loading Loading @@ -951,24 +960,28 @@ public final class SmsApplication { */ @UnsupportedAppUsage public static ComponentName getDefaultSmsApplication(Context context, boolean updateIfNeeded) { return getDefaultSmsApplicationAsUser(context, updateIfNeeded, getIncomingUserId()); return getDefaultSmsApplicationAsUser(context, updateIfNeeded, getIncomingUserHandle()); } /** * Gets the default SMS application on a given user * @param context context from the calling app * @param updateIfNeeded update the default app if there is no valid default app configured. * @param userId target user ID. * @param userHandle target user handle * if {@code null} is passed in then calling package uid is used to find out target user handle. * @return component name of the app and class to deliver SMS messages to */ @VisibleForTesting public static ComponentName getDefaultSmsApplicationAsUser(Context context, boolean updateIfNeeded, int userId) { boolean updateIfNeeded, @Nullable UserHandle userHandle) { if (userHandle == null) { userHandle = getIncomingUserHandle(); } final long token = Binder.clearCallingIdentity(); try { ComponentName component = null; SmsApplicationData smsApplicationData = getApplication(context, updateIfNeeded, userId); userHandle.getIdentifier()); if (smsApplicationData != null) { component = new ComponentName(smsApplicationData.mPackageName, smsApplicationData.mSmsReceiverClass); Loading @@ -987,23 +1000,28 @@ public final class SmsApplication { */ @UnsupportedAppUsage public static ComponentName getDefaultMmsApplication(Context context, boolean updateIfNeeded) { return getDefaultMmsApplicationAsUser(context, updateIfNeeded, getIncomingUserId()); return getDefaultMmsApplicationAsUser(context, updateIfNeeded, getIncomingUserHandle()); } /** * Gets the default MMS application on a given user * @param context context from the calling app * @param updateIfNeeded update the default app if there is no valid default app configured. * @param userId target user ID. * @param userHandle target user handle * if {@code null} is passed in then calling package uid is used to find out target user handle. * @return component name of the app and class to deliver MMS messages to. */ public static ComponentName getDefaultMmsApplicationAsUser(Context context, boolean updateIfNeeded, int userId) { boolean updateIfNeeded, @Nullable UserHandle userHandle) { if (userHandle == null) { userHandle = getIncomingUserHandle(); } final long token = Binder.clearCallingIdentity(); try { ComponentName component = null; SmsApplicationData smsApplicationData = getApplication(context, updateIfNeeded, userId); userHandle.getIdentifier()); if (smsApplicationData != null) { component = new ComponentName(smsApplicationData.mPackageName, smsApplicationData.mMmsReceiverClass); Loading @@ -1024,23 +1042,28 @@ public final class SmsApplication { public static ComponentName getDefaultRespondViaMessageApplication(Context context, boolean updateIfNeeded) { return getDefaultRespondViaMessageApplicationAsUser(context, updateIfNeeded, getIncomingUserId()); getIncomingUserHandle()); } /** * Gets the default Respond Via Message application on a given user * @param context context from the calling app * @param updateIfNeeded update the default app if there is no valid default app configured * @param userId target user ID. * @param userHandle target user handle * if {@code null} is passed in then calling package uid is used to find out target user handle. * @return component name of the app and class to direct Respond Via Message intent to */ public static ComponentName getDefaultRespondViaMessageApplicationAsUser(Context context, boolean updateIfNeeded, int userId) { boolean updateIfNeeded, @Nullable UserHandle userHandle) { if (userHandle == null) { userHandle = getIncomingUserHandle(); } final long token = Binder.clearCallingIdentity(); try { ComponentName component = null; SmsApplicationData smsApplicationData = getApplication(context, updateIfNeeded, userId); userHandle.getIdentifier()); if (smsApplicationData != null) { component = new ComponentName(smsApplicationData.mPackageName, smsApplicationData.mRespondViaMessageClass); Loading @@ -1062,6 +1085,7 @@ public final class SmsApplication { public static ComponentName getDefaultSendToApplication(Context context, boolean updateIfNeeded) { int userId = getIncomingUserId(); final long token = Binder.clearCallingIdentity(); try { ComponentName component = null; Loading @@ -1087,7 +1111,7 @@ public final class SmsApplication { public static ComponentName getDefaultExternalTelephonyProviderChangedApplication( Context context, boolean updateIfNeeded) { return getDefaultExternalTelephonyProviderChangedApplicationAsUser(context, updateIfNeeded, getIncomingUserId()); getIncomingUserHandle()); } /** Loading @@ -1095,16 +1119,21 @@ public final class SmsApplication { * MmsProvider on a given user. * @param context context from the calling app * @param updateIfNeeded update the default app if there is no valid default app configured * @param userId target user ID. * @param userHandle target user handle * if {@code null} is passed in then calling package uid is used to find out target user handle. * @return component name of the app and class to deliver change intents to. */ public static ComponentName getDefaultExternalTelephonyProviderChangedApplicationAsUser( Context context, boolean updateIfNeeded, int userId) { Context context, boolean updateIfNeeded, @Nullable UserHandle userHandle) { if (userHandle == null) { userHandle = getIncomingUserHandle(); } final long token = Binder.clearCallingIdentity(); try { ComponentName component = null; SmsApplicationData smsApplicationData = getApplication(context, updateIfNeeded, userId); userHandle.getIdentifier()); if (smsApplicationData != null && smsApplicationData.mProviderChangedReceiverClass != null) { component = new ComponentName(smsApplicationData.mPackageName, Loading @@ -1124,23 +1153,28 @@ public final class SmsApplication { */ public static ComponentName getDefaultSimFullApplication( Context context, boolean updateIfNeeded) { return getDefaultSimFullApplicationAsUser(context, updateIfNeeded, getIncomingUserId()); return getDefaultSimFullApplicationAsUser(context, updateIfNeeded, getIncomingUserHandle()); } /** * Gets the default application that handles sim full event on a given user. * @param context context from the calling app * @param updateIfNeeded update the default app if there is no valid default app configured * @param userId target user ID. * @param userHandle target user handle * if {@code null} is passed in then calling package uid is used to find out target user handle. * @return component name of the app and class to deliver change intents to */ public static ComponentName getDefaultSimFullApplicationAsUser(Context context, boolean updateIfNeeded, int userId) { boolean updateIfNeeded, @Nullable UserHandle userHandle) { if (userHandle == null) { userHandle = getIncomingUserHandle(); } final long token = Binder.clearCallingIdentity(); try { ComponentName component = null; SmsApplicationData smsApplicationData = getApplication(context, updateIfNeeded, userId); userHandle.getIdentifier()); if (smsApplicationData != null && smsApplicationData.mSimFullReceiverClass != null) { component = new ComponentName(smsApplicationData.mPackageName, Loading @@ -1153,19 +1187,35 @@ public final class SmsApplication { } /** * Returns whether need to wrgetIncomingUserIdite the SMS message to SMS database for this * package. * Returns whether it is required to write the SMS message to SMS database for this package. * * @param packageName the name of the package to be checked * @param context context from the calling app * @return true if it is required to write SMS message to SMS database for this package. * * <p> * Caller must pass in the correct user context if calling from a singleton service. */ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) public static boolean shouldWriteMessageForPackage(String packageName, Context context) { return !shouldWriteMessageForPackageAsUser(packageName, context, getIncomingUserId()); return !shouldWriteMessageForPackageAsUser(packageName, context, getIncomingUserHandle()); } /** * Returns whether it is required to write the SMS message to SMS database for this package. * * @param packageName the name of the package to be checked * @param context context from the calling app * @param userHandle target user handle * if {@code null} is passed in then calling package uid is used to find out target user handle. * @return true if it is required to write SMS message to SMS database for this package. * * <p> * Caller must pass in the correct user context if calling from a singleton service. */ public static boolean shouldWriteMessageForPackageAsUser(String packageName, Context context, int userId) { return !isDefaultSmsApplicationAsUser(context, packageName, userId); @Nullable UserHandle userHandle) { return !isDefaultSmsApplicationAsUser(context, packageName, userHandle); } /** Loading @@ -1177,7 +1227,7 @@ public final class SmsApplication { */ @UnsupportedAppUsage public static boolean isDefaultSmsApplication(Context context, String packageName) { return isDefaultSmsApplicationAsUser(context, packageName, getIncomingUserId()); return isDefaultSmsApplicationAsUser(context, packageName, getIncomingUserHandle()); } /** Loading @@ -1185,16 +1235,22 @@ public final class SmsApplication { * * @param context context from the calling app * @param packageName the name of the package to be checked * @param userId target user ID. * @param userHandle target user handle * if {@code null} is passed in then calling package uid is used to find out target user handle. * @return true if the package is default sms app or bluetooth */ public static boolean isDefaultSmsApplicationAsUser(Context context, String packageName, int userId) { @Nullable UserHandle userHandle) { if (packageName == null) { return false; } if (userHandle == null) { userHandle = getIncomingUserHandle(); } ComponentName component = getDefaultSmsApplicationAsUser(context, false, userId); userHandle); if (component == null) { return false; } Loading Loading @@ -1222,7 +1278,7 @@ public final class SmsApplication { */ @UnsupportedAppUsage public static boolean isDefaultMmsApplication(Context context, String packageName) { return isDefaultMmsApplicationAsUser(context, packageName, getIncomingUserId()); return isDefaultMmsApplicationAsUser(context, packageName, getIncomingUserHandle()); } /** Loading @@ -1230,17 +1286,22 @@ public final class SmsApplication { * * @param context context from the calling app * @param packageName the name of the package to be checked * @param userId target user ID. * @param userHandle target user handle * if {@code null} is passed in then calling package uid is used to find out target user handle. * @return true if the package is default mms app or bluetooth */ public static boolean isDefaultMmsApplicationAsUser(Context context, String packageName, int userId) { @Nullable UserHandle userHandle) { if (packageName == null) { return false; } if (userHandle == null) { userHandle = getIncomingUserHandle(); } ComponentName component = getDefaultMmsApplicationAsUser(context, false, userId); userHandle); if (component == null) { return false; } Loading telephony/common/com/android/internal/telephony/util/TelephonyUtils.java +29 −1 Original line number Diff line number Diff line Loading @@ -27,6 +27,8 @@ import android.os.Binder; import android.os.Bundle; import android.os.PersistableBundle; import android.os.SystemProperties; import android.os.UserHandle; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import java.io.PrintWriter; Loading Loading @@ -212,4 +214,30 @@ public final class TelephonyUtils { return "UNKNOWN(" + mobileDataPolicy + ")"; } } /** * Utility method to get user handle associated with this subscription. * * This method should be used internally as it returns null instead of throwing * IllegalArgumentException or IllegalStateException. * * @param context Context object * @param subId the subId of the subscription. * @return userHandle associated with this subscription * or {@code null} if: * 1. subscription is not associated with any user * 2. subId is invalid. * 3. subscription service is not available. * * @throws SecurityException if the caller doesn't have permissions required. */ @Nullable public static UserHandle getSubscriptionUserHandle(Context context, int subId) { UserHandle userHandle = null; SubscriptionManager subManager = context.getSystemService(SubscriptionManager.class); if ((subManager != null) && (SubscriptionManager.isValidSubscriptionId(subId))) { userHandle = subManager.getSubscriptionUserHandle(subId); } return userHandle; } } No newline at end of file telephony/java/android/telephony/TelephonyManager.java +24 −5 Original line number Diff line number Diff line Loading @@ -71,6 +71,7 @@ import android.os.PersistableBundle; import android.os.RemoteException; import android.os.ResultReceiver; import android.os.SystemProperties; import android.os.UserHandle; import android.os.WorkSource; import android.provider.Settings.SettingNotFoundException; import android.service.carrier.CarrierIdentifier; Loading Loading @@ -11934,8 +11935,9 @@ public class TelephonyManager { } /** * Gets the default Respond Via Message application, updating the cache if there is no * respond-via-message application currently configured. * Get the component name of the default app to direct respond-via-message intent for the * user associated with this subscription, update the cache if there is no respond-via-message * application currently configured for this user. * @return component name of the app and class to direct Respond Via Message intent to, or * {@code null} if the functionality is not supported. * @hide Loading @@ -11944,11 +11946,20 @@ public class TelephonyManager { @RequiresPermission(Manifest.permission.INTERACT_ACROSS_USERS) @RequiresFeature(PackageManager.FEATURE_TELEPHONY_MESSAGING) public @Nullable ComponentName getAndUpdateDefaultRespondViaMessageApplication() { return SmsApplication.getDefaultRespondViaMessageApplication(mContext, true); try { ITelephony telephony = getITelephony(); if (telephony != null) { return telephony.getDefaultRespondViaMessageApplication(getSubId(), true); } } catch (RemoteException e) { Log.e(TAG, "Error in getAndUpdateDefaultRespondViaMessageApplication: " + e); } return null; } /** * Gets the default Respond Via Message application. * Get the component name of the default app to direct respond-via-message intent for the * user associated with this subscription. * @return component name of the app and class to direct Respond Via Message intent to, or * {@code null} if the functionality is not supported. * @hide Loading @@ -11957,7 +11968,15 @@ public class TelephonyManager { @RequiresPermission(Manifest.permission.INTERACT_ACROSS_USERS) @RequiresFeature(PackageManager.FEATURE_TELEPHONY_MESSAGING) public @Nullable ComponentName getDefaultRespondViaMessageApplication() { return SmsApplication.getDefaultRespondViaMessageApplication(mContext, false); try { ITelephony telephony = getITelephony(); if (telephony != null) { return telephony.getDefaultRespondViaMessageApplication(getSubId(), false); } } catch (RemoteException e) { Log.e(TAG, "Error in getDefaultRespondViaMessageApplication: " + e); } return null; } /** Loading telephony/java/com/android/internal/telephony/ITelephony.aidl +11 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.internal.telephony; import android.app.PendingIntent; import android.content.ComponentName; import android.content.Intent; import android.content.IntentSender; import android.os.Bundle; Loading Loading @@ -2618,4 +2619,14 @@ interface ITelephony { * @hide */ boolean isRemovableEsimDefaultEuicc(String callingPackage); /** * Get the component name of the default app to direct respond-via-message intent for the * user associated with this subscription, update the cache if there is no respond-via-message * application currently configured for this user. * @return component name of the app and class to direct Respond Via Message intent to, or * {@code null} if the functionality is not supported. * @hide */ ComponentName getDefaultRespondViaMessageApplication(int subId, boolean updateIfNeeded); } Loading
services/people/java/com/android/server/people/data/DataManager.java +1 −1 Original line number Diff line number Diff line Loading @@ -788,7 +788,7 @@ public class DataManager { private void updateDefaultSmsApp(@NonNull UserData userData) { ComponentName component = SmsApplication.getDefaultSmsApplicationAsUser( mContext, /* updateIfNeeded= */ false, userData.getUserId()); mContext, /* updateIfNeeded= */ false, UserHandle.of(userData.getUserId())); String defaultSmsApp = component != null ? component.getPackageName() : null; userData.setDefaultSmsApp(defaultSmsApp); } Loading
telephony/common/com/android/internal/telephony/SmsApplication.java +95 −34 Original line number Diff line number Diff line Loading @@ -209,6 +209,15 @@ public final class SmsApplication { } } /** * Returns the userHandle of the current process, if called from a system app, * otherwise it returns the caller's userHandle * @return userHandle of the caller. */ private static UserHandle getIncomingUserHandle() { return UserHandle.of(getIncomingUserId()); } /** * Returns the list of available SMS apps defined as apps that are registered for both the * SMS_RECEIVED_ACTION (SMS) and WAP_PUSH_RECEIVED_ACTION (MMS) broadcasts (and their broadcast Loading Loading @@ -951,24 +960,28 @@ public final class SmsApplication { */ @UnsupportedAppUsage public static ComponentName getDefaultSmsApplication(Context context, boolean updateIfNeeded) { return getDefaultSmsApplicationAsUser(context, updateIfNeeded, getIncomingUserId()); return getDefaultSmsApplicationAsUser(context, updateIfNeeded, getIncomingUserHandle()); } /** * Gets the default SMS application on a given user * @param context context from the calling app * @param updateIfNeeded update the default app if there is no valid default app configured. * @param userId target user ID. * @param userHandle target user handle * if {@code null} is passed in then calling package uid is used to find out target user handle. * @return component name of the app and class to deliver SMS messages to */ @VisibleForTesting public static ComponentName getDefaultSmsApplicationAsUser(Context context, boolean updateIfNeeded, int userId) { boolean updateIfNeeded, @Nullable UserHandle userHandle) { if (userHandle == null) { userHandle = getIncomingUserHandle(); } final long token = Binder.clearCallingIdentity(); try { ComponentName component = null; SmsApplicationData smsApplicationData = getApplication(context, updateIfNeeded, userId); userHandle.getIdentifier()); if (smsApplicationData != null) { component = new ComponentName(smsApplicationData.mPackageName, smsApplicationData.mSmsReceiverClass); Loading @@ -987,23 +1000,28 @@ public final class SmsApplication { */ @UnsupportedAppUsage public static ComponentName getDefaultMmsApplication(Context context, boolean updateIfNeeded) { return getDefaultMmsApplicationAsUser(context, updateIfNeeded, getIncomingUserId()); return getDefaultMmsApplicationAsUser(context, updateIfNeeded, getIncomingUserHandle()); } /** * Gets the default MMS application on a given user * @param context context from the calling app * @param updateIfNeeded update the default app if there is no valid default app configured. * @param userId target user ID. * @param userHandle target user handle * if {@code null} is passed in then calling package uid is used to find out target user handle. * @return component name of the app and class to deliver MMS messages to. */ public static ComponentName getDefaultMmsApplicationAsUser(Context context, boolean updateIfNeeded, int userId) { boolean updateIfNeeded, @Nullable UserHandle userHandle) { if (userHandle == null) { userHandle = getIncomingUserHandle(); } final long token = Binder.clearCallingIdentity(); try { ComponentName component = null; SmsApplicationData smsApplicationData = getApplication(context, updateIfNeeded, userId); userHandle.getIdentifier()); if (smsApplicationData != null) { component = new ComponentName(smsApplicationData.mPackageName, smsApplicationData.mMmsReceiverClass); Loading @@ -1024,23 +1042,28 @@ public final class SmsApplication { public static ComponentName getDefaultRespondViaMessageApplication(Context context, boolean updateIfNeeded) { return getDefaultRespondViaMessageApplicationAsUser(context, updateIfNeeded, getIncomingUserId()); getIncomingUserHandle()); } /** * Gets the default Respond Via Message application on a given user * @param context context from the calling app * @param updateIfNeeded update the default app if there is no valid default app configured * @param userId target user ID. * @param userHandle target user handle * if {@code null} is passed in then calling package uid is used to find out target user handle. * @return component name of the app and class to direct Respond Via Message intent to */ public static ComponentName getDefaultRespondViaMessageApplicationAsUser(Context context, boolean updateIfNeeded, int userId) { boolean updateIfNeeded, @Nullable UserHandle userHandle) { if (userHandle == null) { userHandle = getIncomingUserHandle(); } final long token = Binder.clearCallingIdentity(); try { ComponentName component = null; SmsApplicationData smsApplicationData = getApplication(context, updateIfNeeded, userId); userHandle.getIdentifier()); if (smsApplicationData != null) { component = new ComponentName(smsApplicationData.mPackageName, smsApplicationData.mRespondViaMessageClass); Loading @@ -1062,6 +1085,7 @@ public final class SmsApplication { public static ComponentName getDefaultSendToApplication(Context context, boolean updateIfNeeded) { int userId = getIncomingUserId(); final long token = Binder.clearCallingIdentity(); try { ComponentName component = null; Loading @@ -1087,7 +1111,7 @@ public final class SmsApplication { public static ComponentName getDefaultExternalTelephonyProviderChangedApplication( Context context, boolean updateIfNeeded) { return getDefaultExternalTelephonyProviderChangedApplicationAsUser(context, updateIfNeeded, getIncomingUserId()); getIncomingUserHandle()); } /** Loading @@ -1095,16 +1119,21 @@ public final class SmsApplication { * MmsProvider on a given user. * @param context context from the calling app * @param updateIfNeeded update the default app if there is no valid default app configured * @param userId target user ID. * @param userHandle target user handle * if {@code null} is passed in then calling package uid is used to find out target user handle. * @return component name of the app and class to deliver change intents to. */ public static ComponentName getDefaultExternalTelephonyProviderChangedApplicationAsUser( Context context, boolean updateIfNeeded, int userId) { Context context, boolean updateIfNeeded, @Nullable UserHandle userHandle) { if (userHandle == null) { userHandle = getIncomingUserHandle(); } final long token = Binder.clearCallingIdentity(); try { ComponentName component = null; SmsApplicationData smsApplicationData = getApplication(context, updateIfNeeded, userId); userHandle.getIdentifier()); if (smsApplicationData != null && smsApplicationData.mProviderChangedReceiverClass != null) { component = new ComponentName(smsApplicationData.mPackageName, Loading @@ -1124,23 +1153,28 @@ public final class SmsApplication { */ public static ComponentName getDefaultSimFullApplication( Context context, boolean updateIfNeeded) { return getDefaultSimFullApplicationAsUser(context, updateIfNeeded, getIncomingUserId()); return getDefaultSimFullApplicationAsUser(context, updateIfNeeded, getIncomingUserHandle()); } /** * Gets the default application that handles sim full event on a given user. * @param context context from the calling app * @param updateIfNeeded update the default app if there is no valid default app configured * @param userId target user ID. * @param userHandle target user handle * if {@code null} is passed in then calling package uid is used to find out target user handle. * @return component name of the app and class to deliver change intents to */ public static ComponentName getDefaultSimFullApplicationAsUser(Context context, boolean updateIfNeeded, int userId) { boolean updateIfNeeded, @Nullable UserHandle userHandle) { if (userHandle == null) { userHandle = getIncomingUserHandle(); } final long token = Binder.clearCallingIdentity(); try { ComponentName component = null; SmsApplicationData smsApplicationData = getApplication(context, updateIfNeeded, userId); userHandle.getIdentifier()); if (smsApplicationData != null && smsApplicationData.mSimFullReceiverClass != null) { component = new ComponentName(smsApplicationData.mPackageName, Loading @@ -1153,19 +1187,35 @@ public final class SmsApplication { } /** * Returns whether need to wrgetIncomingUserIdite the SMS message to SMS database for this * package. * Returns whether it is required to write the SMS message to SMS database for this package. * * @param packageName the name of the package to be checked * @param context context from the calling app * @return true if it is required to write SMS message to SMS database for this package. * * <p> * Caller must pass in the correct user context if calling from a singleton service. */ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) public static boolean shouldWriteMessageForPackage(String packageName, Context context) { return !shouldWriteMessageForPackageAsUser(packageName, context, getIncomingUserId()); return !shouldWriteMessageForPackageAsUser(packageName, context, getIncomingUserHandle()); } /** * Returns whether it is required to write the SMS message to SMS database for this package. * * @param packageName the name of the package to be checked * @param context context from the calling app * @param userHandle target user handle * if {@code null} is passed in then calling package uid is used to find out target user handle. * @return true if it is required to write SMS message to SMS database for this package. * * <p> * Caller must pass in the correct user context if calling from a singleton service. */ public static boolean shouldWriteMessageForPackageAsUser(String packageName, Context context, int userId) { return !isDefaultSmsApplicationAsUser(context, packageName, userId); @Nullable UserHandle userHandle) { return !isDefaultSmsApplicationAsUser(context, packageName, userHandle); } /** Loading @@ -1177,7 +1227,7 @@ public final class SmsApplication { */ @UnsupportedAppUsage public static boolean isDefaultSmsApplication(Context context, String packageName) { return isDefaultSmsApplicationAsUser(context, packageName, getIncomingUserId()); return isDefaultSmsApplicationAsUser(context, packageName, getIncomingUserHandle()); } /** Loading @@ -1185,16 +1235,22 @@ public final class SmsApplication { * * @param context context from the calling app * @param packageName the name of the package to be checked * @param userId target user ID. * @param userHandle target user handle * if {@code null} is passed in then calling package uid is used to find out target user handle. * @return true if the package is default sms app or bluetooth */ public static boolean isDefaultSmsApplicationAsUser(Context context, String packageName, int userId) { @Nullable UserHandle userHandle) { if (packageName == null) { return false; } if (userHandle == null) { userHandle = getIncomingUserHandle(); } ComponentName component = getDefaultSmsApplicationAsUser(context, false, userId); userHandle); if (component == null) { return false; } Loading Loading @@ -1222,7 +1278,7 @@ public final class SmsApplication { */ @UnsupportedAppUsage public static boolean isDefaultMmsApplication(Context context, String packageName) { return isDefaultMmsApplicationAsUser(context, packageName, getIncomingUserId()); return isDefaultMmsApplicationAsUser(context, packageName, getIncomingUserHandle()); } /** Loading @@ -1230,17 +1286,22 @@ public final class SmsApplication { * * @param context context from the calling app * @param packageName the name of the package to be checked * @param userId target user ID. * @param userHandle target user handle * if {@code null} is passed in then calling package uid is used to find out target user handle. * @return true if the package is default mms app or bluetooth */ public static boolean isDefaultMmsApplicationAsUser(Context context, String packageName, int userId) { @Nullable UserHandle userHandle) { if (packageName == null) { return false; } if (userHandle == null) { userHandle = getIncomingUserHandle(); } ComponentName component = getDefaultMmsApplicationAsUser(context, false, userId); userHandle); if (component == null) { return false; } Loading
telephony/common/com/android/internal/telephony/util/TelephonyUtils.java +29 −1 Original line number Diff line number Diff line Loading @@ -27,6 +27,8 @@ import android.os.Binder; import android.os.Bundle; import android.os.PersistableBundle; import android.os.SystemProperties; import android.os.UserHandle; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import java.io.PrintWriter; Loading Loading @@ -212,4 +214,30 @@ public final class TelephonyUtils { return "UNKNOWN(" + mobileDataPolicy + ")"; } } /** * Utility method to get user handle associated with this subscription. * * This method should be used internally as it returns null instead of throwing * IllegalArgumentException or IllegalStateException. * * @param context Context object * @param subId the subId of the subscription. * @return userHandle associated with this subscription * or {@code null} if: * 1. subscription is not associated with any user * 2. subId is invalid. * 3. subscription service is not available. * * @throws SecurityException if the caller doesn't have permissions required. */ @Nullable public static UserHandle getSubscriptionUserHandle(Context context, int subId) { UserHandle userHandle = null; SubscriptionManager subManager = context.getSystemService(SubscriptionManager.class); if ((subManager != null) && (SubscriptionManager.isValidSubscriptionId(subId))) { userHandle = subManager.getSubscriptionUserHandle(subId); } return userHandle; } } No newline at end of file
telephony/java/android/telephony/TelephonyManager.java +24 −5 Original line number Diff line number Diff line Loading @@ -71,6 +71,7 @@ import android.os.PersistableBundle; import android.os.RemoteException; import android.os.ResultReceiver; import android.os.SystemProperties; import android.os.UserHandle; import android.os.WorkSource; import android.provider.Settings.SettingNotFoundException; import android.service.carrier.CarrierIdentifier; Loading Loading @@ -11934,8 +11935,9 @@ public class TelephonyManager { } /** * Gets the default Respond Via Message application, updating the cache if there is no * respond-via-message application currently configured. * Get the component name of the default app to direct respond-via-message intent for the * user associated with this subscription, update the cache if there is no respond-via-message * application currently configured for this user. * @return component name of the app and class to direct Respond Via Message intent to, or * {@code null} if the functionality is not supported. * @hide Loading @@ -11944,11 +11946,20 @@ public class TelephonyManager { @RequiresPermission(Manifest.permission.INTERACT_ACROSS_USERS) @RequiresFeature(PackageManager.FEATURE_TELEPHONY_MESSAGING) public @Nullable ComponentName getAndUpdateDefaultRespondViaMessageApplication() { return SmsApplication.getDefaultRespondViaMessageApplication(mContext, true); try { ITelephony telephony = getITelephony(); if (telephony != null) { return telephony.getDefaultRespondViaMessageApplication(getSubId(), true); } } catch (RemoteException e) { Log.e(TAG, "Error in getAndUpdateDefaultRespondViaMessageApplication: " + e); } return null; } /** * Gets the default Respond Via Message application. * Get the component name of the default app to direct respond-via-message intent for the * user associated with this subscription. * @return component name of the app and class to direct Respond Via Message intent to, or * {@code null} if the functionality is not supported. * @hide Loading @@ -11957,7 +11968,15 @@ public class TelephonyManager { @RequiresPermission(Manifest.permission.INTERACT_ACROSS_USERS) @RequiresFeature(PackageManager.FEATURE_TELEPHONY_MESSAGING) public @Nullable ComponentName getDefaultRespondViaMessageApplication() { return SmsApplication.getDefaultRespondViaMessageApplication(mContext, false); try { ITelephony telephony = getITelephony(); if (telephony != null) { return telephony.getDefaultRespondViaMessageApplication(getSubId(), false); } } catch (RemoteException e) { Log.e(TAG, "Error in getDefaultRespondViaMessageApplication: " + e); } return null; } /** Loading
telephony/java/com/android/internal/telephony/ITelephony.aidl +11 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.internal.telephony; import android.app.PendingIntent; import android.content.ComponentName; import android.content.Intent; import android.content.IntentSender; import android.os.Bundle; Loading Loading @@ -2618,4 +2619,14 @@ interface ITelephony { * @hide */ boolean isRemovableEsimDefaultEuicc(String callingPackage); /** * Get the component name of the default app to direct respond-via-message intent for the * user associated with this subscription, update the cache if there is no respond-via-message * application currently configured for this user. * @return component name of the app and class to direct Respond Via Message intent to, or * {@code null} if the functionality is not supported. * @hide */ ComponentName getDefaultRespondViaMessageApplication(int subId, boolean updateIfNeeded); }