Loading src/java/com/android/internal/telephony/IccSmsInterfaceManager.java +51 −13 Original line number Diff line number Diff line Loading @@ -429,13 +429,26 @@ public class IccSmsInterfaceManager { } /** * A permissions check before passing to {@link IccSmsInterfaceManager#sendDataInternal}. * This method checks only if the calling package has the permission to send the data sms. * @deprecated Use {@link #sendData(String, String, String, String, int, byte[], PendingIntent, * PendingIntent)} instead. */ @Deprecated @UnsupportedAppUsage public void sendData(String callingPackage, String destAddr, String scAddr, int destPort, byte[] data, PendingIntent sentIntent, PendingIntent deliveryIntent) { if (!mSmsPermissions.checkCallingCanSendSms(callingPackage, "Sending SMS message")) { sendData(callingPackage, null, destAddr, scAddr, destPort, data, sentIntent, deliveryIntent); } /** * A permissions check before passing to {@link IccSmsInterfaceManager#sendDataInternal}. * This method checks only if the calling package has the permission to send the data sms. */ public void sendData(String callingPackage, String callingAttributionTag, String destAddr, String scAddr, int destPort, byte[] data, PendingIntent sentIntent, PendingIntent deliveryIntent) { if (!mSmsPermissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, "Sending SMS message")) { returnUnspecifiedFailure(sentIntent); return; } Loading Loading @@ -703,12 +716,12 @@ public class IccSmsInterfaceManager { * Used for logging and diagnostics purposes. The id may be 0. */ public void sendMultipartText(String callingPackage, String destAddr, String scAddr, List<String> parts, List<PendingIntent> sentIntents, public void sendMultipartText(String callingPackage, String callingAttributionTag, String destAddr, String scAddr, List<String> parts, List<PendingIntent> sentIntents, List<PendingIntent> deliveryIntents, boolean persistMessageForNonDefaultSmsApp, long messageId) { sendMultipartTextWithOptions(callingPackage, destAddr, scAddr, parts, sentIntents, deliveryIntents, persistMessageForNonDefaultSmsApp, sendMultipartTextWithOptions(callingPackage, callingAttributionTag, destAddr, scAddr, parts, sentIntents, deliveryIntents, persistMessageForNonDefaultSmsApp, SMS_MESSAGE_PRIORITY_NOT_SPECIFIED, false /* expectMore */, SMS_MESSAGE_PERIOD_NOT_SPECIFIED, messageId); Loading Loading @@ -763,12 +776,12 @@ public class IccSmsInterfaceManager { * Used for logging and diagnostics purposes. The id may be 0. */ public void sendMultipartTextWithOptions(String callingPackage, String destAddr, String scAddr, List<String> parts, List<PendingIntent> sentIntents, public void sendMultipartTextWithOptions(String callingPackage, String callingAttributionTag, String destAddr, String scAddr, List<String> parts, List<PendingIntent> sentIntents, List<PendingIntent> deliveryIntents, boolean persistMessageForNonDefaultSmsApp, int priority, boolean expectMore, int validityPeriod, long messageId) { if (!mSmsPermissions.checkCallingCanSendText( persistMessageForNonDefaultSmsApp, callingPackage, "Sending SMS message")) { if (!mSmsPermissions.checkCallingCanSendText(persistMessageForNonDefaultSmsApp, callingPackage, callingAttributionTag, "Sending SMS message")) { returnUnspecifiedFailure(sentIntents); return; } Loading Loading @@ -1283,10 +1296,22 @@ public class IccSmsInterfaceManager { return mDispatchersController.getImsSmsFormat(); } /** * @deprecated Use {@link #sendStoredText(String, String, Uri, String, PendingIntent, * PendingIntent)} instead */ @Deprecated @UnsupportedAppUsage public void sendStoredText(String callingPkg, Uri messageUri, String scAddress, PendingIntent sentIntent, PendingIntent deliveryIntent) { if (!mSmsPermissions.checkCallingCanSendSms(callingPkg, "Sending SMS message")) { sendStoredText(callingPkg, null, messageUri, scAddress, sentIntent, deliveryIntent); } public void sendStoredText(String callingPkg, String callingAttributionTag, Uri messageUri, String scAddress, PendingIntent sentIntent, PendingIntent deliveryIntent) { if (!mSmsPermissions.checkCallingCanSendSms(callingPkg, callingAttributionTag, "Sending SMS message")) { returnUnspecifiedFailure(sentIntent); return; } Loading Loading @@ -1315,10 +1340,23 @@ public class IccSmsInterfaceManager { 0L /* messageId */); } /** * @deprecated Use {@link #sendStoredMultipartText(String, String, Uri, String, List, List)} * instead */ @Deprecated @UnsupportedAppUsage public void sendStoredMultipartText(String callingPkg, Uri messageUri, String scAddress, List<PendingIntent> sentIntents, List<PendingIntent> deliveryIntents) { if (!mSmsPermissions.checkCallingCanSendSms(callingPkg, "Sending SMS message")) { sendStoredMultipartText(callingPkg, null, messageUri, scAddress, sentIntents, deliveryIntents); } public void sendStoredMultipartText(String callingPkg, String callingAttributionTag, Uri messageUri, String scAddress, List<PendingIntent> sentIntents, List<PendingIntent> deliveryIntents) { if (!mSmsPermissions.checkCallingCanSendSms(callingPkg, callingAttributionTag, "Sending SMS message")) { returnUnspecifiedFailure(sentIntents); return; } Loading src/java/com/android/internal/telephony/SmsController.java +41 −26 Original line number Diff line number Diff line Loading @@ -130,18 +130,30 @@ public class SmsController extends ISmsImplBase { } } /** * @deprecated Use {@link #sendDataForSubscriber(int, String, String, String, String, int, * byte[], PendingIntent, PendingIntent)} instead */ @Deprecated @UnsupportedAppUsage @Override public void sendDataForSubscriber(int subId, String callingPackage, String destAddr, String scAddr, int destPort, byte[] data, PendingIntent sentIntent, PendingIntent deliveryIntent) { sendDataForSubscriber(subId, callingPackage, null, destAddr, scAddr, destPort, data, sentIntent, deliveryIntent); } @Override public void sendDataForSubscriber(int subId, String callingPackage, String callingAttributionTag, String destAddr, String scAddr, int destPort, byte[] data, PendingIntent sentIntent, PendingIntent deliveryIntent) { if (callingPackage == null) { callingPackage = getCallingPackage(); } IccSmsInterfaceManager iccSmsIntMgr = getIccSmsInterfaceManager(subId); if (iccSmsIntMgr != null) { iccSmsIntMgr.sendData(callingPackage, destAddr, scAddr, destPort, data, sentIntent, deliveryIntent); iccSmsIntMgr.sendData(callingPackage, callingAttributionTag, destAddr, scAddr, destPort, data, sentIntent, deliveryIntent); } else { Rlog.e(LOG_TAG, "sendDataForSubscriber iccSmsIntMgr is null for" + " Subscription: " + subId); Loading Loading @@ -169,14 +181,15 @@ public class SmsController extends ISmsImplBase { } @Override public void sendTextForSubscriber(int subId, String callingPackage, String destAddr, String scAddr, String text, PendingIntent sentIntent, PendingIntent deliveryIntent, public void sendTextForSubscriber(int subId, String callingPackage, String callingAttributionTag, String destAddr, String scAddr, String text, PendingIntent sentIntent, PendingIntent deliveryIntent, boolean persistMessageForNonDefaultSmsApp, long messageId) { if (callingPackage == null) { callingPackage = getCallingPackage(); } if (!getSmsPermissions(subId).checkCallingCanSendText(persistMessageForNonDefaultSmsApp, callingPackage, "Sending SMS message")) { callingPackage, callingAttributionTag, "Sending SMS message")) { sendErrorInPendingIntent(sentIntent, SmsManager.RESULT_ERROR_GENERIC_FAILURE); return; } Loading Loading @@ -258,10 +271,10 @@ public class SmsController extends ISmsImplBase { } @Override public void sendMultipartTextForSubscriber(int subId, String callingPackage, String destAddr, String scAddr, List<String> parts, List<PendingIntent> sentIntents, List<PendingIntent> deliveryIntents, boolean persistMessageForNonDefaultSmsApp, long messageId) { public void sendMultipartTextForSubscriber(int subId, String callingPackage, String callingAttributionTag, String destAddr, String scAddr, List<String> parts, List<PendingIntent> sentIntents, List<PendingIntent> deliveryIntents, boolean persistMessageForNonDefaultSmsApp, long messageId) { // This is different from the checking of other method. It prefers the package name // returned by getCallPackage() for backward-compatibility. if (getCallingPackage() != null) { Loading @@ -269,8 +282,9 @@ public class SmsController extends ISmsImplBase { } IccSmsInterfaceManager iccSmsIntMgr = getIccSmsInterfaceManager(subId); if (iccSmsIntMgr != null) { iccSmsIntMgr.sendMultipartText(callingPackage, destAddr, scAddr, parts, sentIntents, deliveryIntents, persistMessageForNonDefaultSmsApp, messageId); iccSmsIntMgr.sendMultipartText(callingPackage, callingAttributionTag, destAddr, scAddr, parts, sentIntents, deliveryIntents, persistMessageForNonDefaultSmsApp, messageId); } else { Rlog.e(LOG_TAG, "sendMultipartTextForSubscriber iccSmsIntMgr is null for" + " Subscription: " + subId + " id: " + messageId); Loading @@ -280,17 +294,17 @@ public class SmsController extends ISmsImplBase { @Override public void sendMultipartTextForSubscriberWithOptions(int subId, String callingPackage, String destAddr, String scAddr, List<String> parts, List<PendingIntent> sentIntents, List<PendingIntent> deliveryIntents, boolean persistMessage, int priority, boolean expectMore, int validityPeriod) { String callingAttributionTag, String destAddr, String scAddr, List<String> parts, List<PendingIntent> sentIntents, List<PendingIntent> deliveryIntents, boolean persistMessage, int priority, boolean expectMore, int validityPeriod) { if (callingPackage == null) { callingPackage = getCallingPackage(); } IccSmsInterfaceManager iccSmsIntMgr = getIccSmsInterfaceManager(subId); if (iccSmsIntMgr != null) { iccSmsIntMgr.sendMultipartTextWithOptions(callingPackage, destAddr, scAddr, parts, sentIntents, deliveryIntents, persistMessage, priority, expectMore, validityPeriod, 0L /* messageId */); iccSmsIntMgr.sendMultipartTextWithOptions(callingPackage, callingAttributionTag, destAddr, scAddr, parts, sentIntents, deliveryIntents, persistMessage, priority, expectMore, validityPeriod, 0L /* messageId */); } else { Rlog.e(LOG_TAG, "sendMultipartTextWithOptions iccSmsIntMgr is null for" + " Subscription: " + subId); Loading Loading @@ -496,12 +510,13 @@ public class SmsController extends ISmsImplBase { } @Override public void sendStoredText(int subId, String callingPkg, Uri messageUri, String scAddress, PendingIntent sentIntent, PendingIntent deliveryIntent) { public void sendStoredText(int subId, String callingPkg, String callingAttributionTag, Uri messageUri, String scAddress, PendingIntent sentIntent, PendingIntent deliveryIntent) { IccSmsInterfaceManager iccSmsIntMgr = getIccSmsInterfaceManager(subId); if (iccSmsIntMgr != null) { iccSmsIntMgr.sendStoredText(callingPkg, messageUri, scAddress, sentIntent, deliveryIntent); iccSmsIntMgr.sendStoredText(callingPkg, callingAttributionTag, messageUri, scAddress, sentIntent, deliveryIntent); } else { Rlog.e(LOG_TAG, "sendStoredText iccSmsIntMgr is null for subscription: " + subId); sendErrorInPendingIntent(sentIntent, SmsManager.RESULT_ERROR_GENERIC_FAILURE); Loading @@ -509,13 +524,13 @@ public class SmsController extends ISmsImplBase { } @Override public void sendStoredMultipartText(int subId, String callingPkg, Uri messageUri, String scAddress, List<PendingIntent> sentIntents, public void sendStoredMultipartText(int subId, String callingPkg, String callingAttributionTag, Uri messageUri, String scAddress, List<PendingIntent> sentIntents, List<PendingIntent> deliveryIntents) { IccSmsInterfaceManager iccSmsIntMgr = getIccSmsInterfaceManager(subId); if (iccSmsIntMgr != null) { iccSmsIntMgr.sendStoredMultipartText(callingPkg, messageUri, scAddress, sentIntents, deliveryIntents); iccSmsIntMgr.sendStoredMultipartText(callingPkg, callingAttributionTag, messageUri, scAddress, sentIntents, deliveryIntents); } else { Rlog.e(LOG_TAG, "sendStoredMultipartText iccSmsIntMgr is null for subscription: " + subId); Loading src/java/com/android/internal/telephony/SmsPermissions.java +7 −5 Original line number Diff line number Diff line Loading @@ -60,7 +60,8 @@ public class SmsPermissions { * @return true unless the caller has all necessary permissions but has a revoked AppOps bit. */ public boolean checkCallingCanSendText( boolean persistMessageForNonDefaultSmsApp, String callingPackage, String message) { boolean persistMessageForNonDefaultSmsApp, String callingPackage, String callingAttributionTag, String message) { // TODO(b/75978989): Should we allow IMS/carrier apps for persisted messages as well? if (!persistMessageForNonDefaultSmsApp) { try { Loading @@ -72,7 +73,7 @@ public class SmsPermissions { android.Manifest.permission.MODIFY_PHONE_STATE, message); } } return checkCallingCanSendSms(callingPackage, message); return checkCallingCanSendSms(callingPackage, callingAttributionTag, message); } /** Loading Loading @@ -109,10 +110,11 @@ public class SmsPermissions { * permission revoked at runtime. * @return whether the caller has the OP_SEND_SMS AppOps bit. */ public boolean checkCallingCanSendSms(String callingPackage, String message) { public boolean checkCallingCanSendSms(String callingPackage, String callingAttributionTag, String message) { mContext.enforceCallingPermission(Manifest.permission.SEND_SMS, message); return mAppOps.noteOp(AppOpsManager.OPSTR_SEND_SMS, Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED; return mAppOps.noteOp(AppOpsManager.OPSTR_SEND_SMS, Binder.getCallingUid(), callingPackage, callingAttributionTag, null) == AppOpsManager.MODE_ALLOWED; } /** Loading tests/telephonytests/src/com/android/internal/telephony/PhoneSubInfoControllerTest.java +5 −0 Original line number Diff line number Diff line Loading @@ -105,6 +105,7 @@ public class PhoneSubInfoControllerTest extends TelephonyTest { // The READ_PRIVILEGED_PHONE_STATE permission or passing a device / profile owner access // check is required to access device identifiers. Since neither of those are true for this // test each case will result in a SecurityException being thrown. setIdentifierAccess(false); doReturn("353626073736741").when(mPhone).getDeviceId(); doReturn("353626073736742").when(mSecondPhone).getDeviceId(); Loading Loading @@ -188,6 +189,7 @@ public class PhoneSubInfoControllerTest extends TelephonyTest { // The READ_PRIVILEGED_PHONE_STATE permission, carrier privileges, or passing a device / // profile owner access check is required to access subscriber identifiers. Since none of // those are true for this test each case will result in a SecurityException being thrown. setIdentifierAccess(false); doReturn("aaa@example.com").when(mPhone).getNai(); doReturn("bbb@example.com").when(mSecondPhone).getNai(); Loading Loading @@ -270,6 +272,7 @@ public class PhoneSubInfoControllerTest extends TelephonyTest { // The READ_PRIVILEGED_PHONE_STATE permission, carrier privileges, or passing a device / // profile owner access check is required to access device identifiers. Since none of // those are true for this test each case will result in a SecurityException being thrown. setIdentifierAccess(false); doReturn("990000862471854").when(mPhone).getImei(); doReturn("990000862471855").when(mSecondPhone).getImei(); Loading Loading @@ -412,6 +415,7 @@ public class PhoneSubInfoControllerTest extends TelephonyTest { // The READ_PRIVILEGED_PHONE_STATE permission, carrier privileges, or passing a device / // profile owner access check is required to access subscriber identifiers. Since none of // those are true for this test each case will result in a SecurityException being thrown. setIdentifierAccess(false); doReturn("310260426283121").when(mPhone).getSubscriberId(); doReturn("310260426283122").when(mSecondPhone).getSubscriberId(); Loading Loading @@ -496,6 +500,7 @@ public class PhoneSubInfoControllerTest extends TelephonyTest { // The READ_PRIVILEGED_PHONE_STATE permission, carrier privileges, or passing a device / // profile owner access check is required to access subscriber identifiers. Since none of // those are true for this test each case will result in a SecurityException being thrown. setIdentifierAccess(false); doReturn("8991101200003204510").when(mPhone).getIccSerialNumber(); doReturn("8991101200003204511").when(mSecondPhone).getIccSerialNumber(); Loading tests/telephonytests/src/com/android/internal/telephony/SmsPermissionsTest.java +21 −14 Original line number Diff line number Diff line Loading @@ -47,6 +47,7 @@ import java.util.concurrent.TimeUnit; public class SmsPermissionsTest extends TelephonyTest { private static final String PACKAGE = "com.example.package"; private static final String ATTRIBUTION_TAG = null; private static final String MESSAGE = "msg"; private HandlerThread mHandlerThread; Loading Loading @@ -104,7 +105,7 @@ public class SmsPermissionsTest extends TelephonyTest { @Test public void testCheckCallingSendTextPermissions_persist_grant() { assertTrue(mSmsPermissionsTest.checkCallingCanSendText( true /* persistMessageForNonDefaultSmsApp */, PACKAGE, MESSAGE)); true /* persistMessageForNonDefaultSmsApp */, PACKAGE, ATTRIBUTION_TAG, MESSAGE)); } @Test Loading @@ -113,7 +114,8 @@ public class SmsPermissionsTest extends TelephonyTest { .enforceCallingPermission(Manifest.permission.SEND_SMS, MESSAGE); try { mSmsPermissionsTest.checkCallingCanSendText( true /* persistMessageForNonDefaultSmsApp */, PACKAGE, MESSAGE); true /* persistMessageForNonDefaultSmsApp */, PACKAGE, ATTRIBUTION_TAG, MESSAGE); fail(); } catch (SecurityException e) { // expected Loading @@ -122,11 +124,12 @@ public class SmsPermissionsTest extends TelephonyTest { @Test public void testCheckCallingSendTextPermissions_persist_noAppOps() { Mockito.when(mMockAppOps.noteOp( AppOpsManager.OPSTR_SEND_SMS, Binder.getCallingUid(), PACKAGE)) Mockito.when( mMockAppOps.noteOp(AppOpsManager.OPSTR_SEND_SMS, Binder.getCallingUid(), PACKAGE, ATTRIBUTION_TAG, null)) .thenReturn(AppOpsManager.MODE_ERRORED); assertFalse(mSmsPermissionsTest.checkCallingCanSendText( true /* persistMessageForNonDefaultSmsApp */, PACKAGE, MESSAGE)); true /* persistMessageForNonDefaultSmsApp */, PACKAGE, ATTRIBUTION_TAG, MESSAGE)); } @Test Loading @@ -137,18 +140,19 @@ public class SmsPermissionsTest extends TelephonyTest { .enforceCallingPermission(Manifest.permission.MODIFY_PHONE_STATE, MESSAGE); Mockito.doThrow(new SecurityException(MESSAGE)).when(mMockContext) .enforceCallingPermission(Manifest.permission.SEND_SMS, MESSAGE); Mockito.when(mMockAppOps.noteOp( AppOpsManager.OPSTR_SEND_SMS, Binder.getCallingUid(), PACKAGE)) Mockito.when( mMockAppOps.noteOp(AppOpsManager.OPSTR_SEND_SMS, Binder.getCallingUid(), PACKAGE, ATTRIBUTION_TAG, null)) .thenReturn(AppOpsManager.MODE_ERRORED); assertTrue(mSmsPermissionsTest.checkCallingCanSendText( false /* persistMessageForNonDefaultSmsApp */, PACKAGE, MESSAGE)); false /* persistMessageForNonDefaultSmsApp */, PACKAGE, ATTRIBUTION_TAG, MESSAGE)); } @Test public void testCheckCallingSendTextPermissions_noPersist_grantViaModifyAndSend() { assertTrue(mSmsPermissionsTest.checkCallingCanSendText( false /* persistMessageForNonDefaultSmsApp */, PACKAGE, MESSAGE)); false /* persistMessageForNonDefaultSmsApp */, PACKAGE, ATTRIBUTION_TAG, MESSAGE)); } @Test Loading @@ -157,7 +161,8 @@ public class SmsPermissionsTest extends TelephonyTest { .enforceCallingPermission(Manifest.permission.MODIFY_PHONE_STATE, MESSAGE); try { mSmsPermissionsTest.checkCallingCanSendText( false /* persistMessageForNonDefaultSmsApp */, PACKAGE, MESSAGE); false /* persistMessageForNonDefaultSmsApp */, PACKAGE, ATTRIBUTION_TAG, MESSAGE); fail(); } catch (SecurityException e) { // expected Loading @@ -170,7 +175,8 @@ public class SmsPermissionsTest extends TelephonyTest { .enforceCallingPermission(Manifest.permission.SEND_SMS, MESSAGE); try { mSmsPermissionsTest.checkCallingCanSendText( false /* persistMessageForNonDefaultSmsApp */, PACKAGE, MESSAGE); false /* persistMessageForNonDefaultSmsApp */, PACKAGE, ATTRIBUTION_TAG, MESSAGE); fail(); } catch (SecurityException e) { // expected Loading @@ -179,11 +185,12 @@ public class SmsPermissionsTest extends TelephonyTest { @Test public void testCheckCallingSendTextPermissions_noPersist_noAppOps() { Mockito.when(mMockAppOps.noteOp( AppOpsManager.OPSTR_SEND_SMS, Binder.getCallingUid(), PACKAGE)) Mockito.when( mMockAppOps.noteOp(AppOpsManager.OPSTR_SEND_SMS, Binder.getCallingUid(), PACKAGE, ATTRIBUTION_TAG, null)) .thenReturn(AppOpsManager.MODE_ERRORED); assertFalse(mSmsPermissionsTest.checkCallingCanSendText( false /* persistMessageForNonDefaultSmsApp */, PACKAGE, MESSAGE)); false /* persistMessageForNonDefaultSmsApp */, PACKAGE, ATTRIBUTION_TAG, MESSAGE)); } @Test Loading Loading
src/java/com/android/internal/telephony/IccSmsInterfaceManager.java +51 −13 Original line number Diff line number Diff line Loading @@ -429,13 +429,26 @@ public class IccSmsInterfaceManager { } /** * A permissions check before passing to {@link IccSmsInterfaceManager#sendDataInternal}. * This method checks only if the calling package has the permission to send the data sms. * @deprecated Use {@link #sendData(String, String, String, String, int, byte[], PendingIntent, * PendingIntent)} instead. */ @Deprecated @UnsupportedAppUsage public void sendData(String callingPackage, String destAddr, String scAddr, int destPort, byte[] data, PendingIntent sentIntent, PendingIntent deliveryIntent) { if (!mSmsPermissions.checkCallingCanSendSms(callingPackage, "Sending SMS message")) { sendData(callingPackage, null, destAddr, scAddr, destPort, data, sentIntent, deliveryIntent); } /** * A permissions check before passing to {@link IccSmsInterfaceManager#sendDataInternal}. * This method checks only if the calling package has the permission to send the data sms. */ public void sendData(String callingPackage, String callingAttributionTag, String destAddr, String scAddr, int destPort, byte[] data, PendingIntent sentIntent, PendingIntent deliveryIntent) { if (!mSmsPermissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, "Sending SMS message")) { returnUnspecifiedFailure(sentIntent); return; } Loading Loading @@ -703,12 +716,12 @@ public class IccSmsInterfaceManager { * Used for logging and diagnostics purposes. The id may be 0. */ public void sendMultipartText(String callingPackage, String destAddr, String scAddr, List<String> parts, List<PendingIntent> sentIntents, public void sendMultipartText(String callingPackage, String callingAttributionTag, String destAddr, String scAddr, List<String> parts, List<PendingIntent> sentIntents, List<PendingIntent> deliveryIntents, boolean persistMessageForNonDefaultSmsApp, long messageId) { sendMultipartTextWithOptions(callingPackage, destAddr, scAddr, parts, sentIntents, deliveryIntents, persistMessageForNonDefaultSmsApp, sendMultipartTextWithOptions(callingPackage, callingAttributionTag, destAddr, scAddr, parts, sentIntents, deliveryIntents, persistMessageForNonDefaultSmsApp, SMS_MESSAGE_PRIORITY_NOT_SPECIFIED, false /* expectMore */, SMS_MESSAGE_PERIOD_NOT_SPECIFIED, messageId); Loading Loading @@ -763,12 +776,12 @@ public class IccSmsInterfaceManager { * Used for logging and diagnostics purposes. The id may be 0. */ public void sendMultipartTextWithOptions(String callingPackage, String destAddr, String scAddr, List<String> parts, List<PendingIntent> sentIntents, public void sendMultipartTextWithOptions(String callingPackage, String callingAttributionTag, String destAddr, String scAddr, List<String> parts, List<PendingIntent> sentIntents, List<PendingIntent> deliveryIntents, boolean persistMessageForNonDefaultSmsApp, int priority, boolean expectMore, int validityPeriod, long messageId) { if (!mSmsPermissions.checkCallingCanSendText( persistMessageForNonDefaultSmsApp, callingPackage, "Sending SMS message")) { if (!mSmsPermissions.checkCallingCanSendText(persistMessageForNonDefaultSmsApp, callingPackage, callingAttributionTag, "Sending SMS message")) { returnUnspecifiedFailure(sentIntents); return; } Loading Loading @@ -1283,10 +1296,22 @@ public class IccSmsInterfaceManager { return mDispatchersController.getImsSmsFormat(); } /** * @deprecated Use {@link #sendStoredText(String, String, Uri, String, PendingIntent, * PendingIntent)} instead */ @Deprecated @UnsupportedAppUsage public void sendStoredText(String callingPkg, Uri messageUri, String scAddress, PendingIntent sentIntent, PendingIntent deliveryIntent) { if (!mSmsPermissions.checkCallingCanSendSms(callingPkg, "Sending SMS message")) { sendStoredText(callingPkg, null, messageUri, scAddress, sentIntent, deliveryIntent); } public void sendStoredText(String callingPkg, String callingAttributionTag, Uri messageUri, String scAddress, PendingIntent sentIntent, PendingIntent deliveryIntent) { if (!mSmsPermissions.checkCallingCanSendSms(callingPkg, callingAttributionTag, "Sending SMS message")) { returnUnspecifiedFailure(sentIntent); return; } Loading Loading @@ -1315,10 +1340,23 @@ public class IccSmsInterfaceManager { 0L /* messageId */); } /** * @deprecated Use {@link #sendStoredMultipartText(String, String, Uri, String, List, List)} * instead */ @Deprecated @UnsupportedAppUsage public void sendStoredMultipartText(String callingPkg, Uri messageUri, String scAddress, List<PendingIntent> sentIntents, List<PendingIntent> deliveryIntents) { if (!mSmsPermissions.checkCallingCanSendSms(callingPkg, "Sending SMS message")) { sendStoredMultipartText(callingPkg, null, messageUri, scAddress, sentIntents, deliveryIntents); } public void sendStoredMultipartText(String callingPkg, String callingAttributionTag, Uri messageUri, String scAddress, List<PendingIntent> sentIntents, List<PendingIntent> deliveryIntents) { if (!mSmsPermissions.checkCallingCanSendSms(callingPkg, callingAttributionTag, "Sending SMS message")) { returnUnspecifiedFailure(sentIntents); return; } Loading
src/java/com/android/internal/telephony/SmsController.java +41 −26 Original line number Diff line number Diff line Loading @@ -130,18 +130,30 @@ public class SmsController extends ISmsImplBase { } } /** * @deprecated Use {@link #sendDataForSubscriber(int, String, String, String, String, int, * byte[], PendingIntent, PendingIntent)} instead */ @Deprecated @UnsupportedAppUsage @Override public void sendDataForSubscriber(int subId, String callingPackage, String destAddr, String scAddr, int destPort, byte[] data, PendingIntent sentIntent, PendingIntent deliveryIntent) { sendDataForSubscriber(subId, callingPackage, null, destAddr, scAddr, destPort, data, sentIntent, deliveryIntent); } @Override public void sendDataForSubscriber(int subId, String callingPackage, String callingAttributionTag, String destAddr, String scAddr, int destPort, byte[] data, PendingIntent sentIntent, PendingIntent deliveryIntent) { if (callingPackage == null) { callingPackage = getCallingPackage(); } IccSmsInterfaceManager iccSmsIntMgr = getIccSmsInterfaceManager(subId); if (iccSmsIntMgr != null) { iccSmsIntMgr.sendData(callingPackage, destAddr, scAddr, destPort, data, sentIntent, deliveryIntent); iccSmsIntMgr.sendData(callingPackage, callingAttributionTag, destAddr, scAddr, destPort, data, sentIntent, deliveryIntent); } else { Rlog.e(LOG_TAG, "sendDataForSubscriber iccSmsIntMgr is null for" + " Subscription: " + subId); Loading Loading @@ -169,14 +181,15 @@ public class SmsController extends ISmsImplBase { } @Override public void sendTextForSubscriber(int subId, String callingPackage, String destAddr, String scAddr, String text, PendingIntent sentIntent, PendingIntent deliveryIntent, public void sendTextForSubscriber(int subId, String callingPackage, String callingAttributionTag, String destAddr, String scAddr, String text, PendingIntent sentIntent, PendingIntent deliveryIntent, boolean persistMessageForNonDefaultSmsApp, long messageId) { if (callingPackage == null) { callingPackage = getCallingPackage(); } if (!getSmsPermissions(subId).checkCallingCanSendText(persistMessageForNonDefaultSmsApp, callingPackage, "Sending SMS message")) { callingPackage, callingAttributionTag, "Sending SMS message")) { sendErrorInPendingIntent(sentIntent, SmsManager.RESULT_ERROR_GENERIC_FAILURE); return; } Loading Loading @@ -258,10 +271,10 @@ public class SmsController extends ISmsImplBase { } @Override public void sendMultipartTextForSubscriber(int subId, String callingPackage, String destAddr, String scAddr, List<String> parts, List<PendingIntent> sentIntents, List<PendingIntent> deliveryIntents, boolean persistMessageForNonDefaultSmsApp, long messageId) { public void sendMultipartTextForSubscriber(int subId, String callingPackage, String callingAttributionTag, String destAddr, String scAddr, List<String> parts, List<PendingIntent> sentIntents, List<PendingIntent> deliveryIntents, boolean persistMessageForNonDefaultSmsApp, long messageId) { // This is different from the checking of other method. It prefers the package name // returned by getCallPackage() for backward-compatibility. if (getCallingPackage() != null) { Loading @@ -269,8 +282,9 @@ public class SmsController extends ISmsImplBase { } IccSmsInterfaceManager iccSmsIntMgr = getIccSmsInterfaceManager(subId); if (iccSmsIntMgr != null) { iccSmsIntMgr.sendMultipartText(callingPackage, destAddr, scAddr, parts, sentIntents, deliveryIntents, persistMessageForNonDefaultSmsApp, messageId); iccSmsIntMgr.sendMultipartText(callingPackage, callingAttributionTag, destAddr, scAddr, parts, sentIntents, deliveryIntents, persistMessageForNonDefaultSmsApp, messageId); } else { Rlog.e(LOG_TAG, "sendMultipartTextForSubscriber iccSmsIntMgr is null for" + " Subscription: " + subId + " id: " + messageId); Loading @@ -280,17 +294,17 @@ public class SmsController extends ISmsImplBase { @Override public void sendMultipartTextForSubscriberWithOptions(int subId, String callingPackage, String destAddr, String scAddr, List<String> parts, List<PendingIntent> sentIntents, List<PendingIntent> deliveryIntents, boolean persistMessage, int priority, boolean expectMore, int validityPeriod) { String callingAttributionTag, String destAddr, String scAddr, List<String> parts, List<PendingIntent> sentIntents, List<PendingIntent> deliveryIntents, boolean persistMessage, int priority, boolean expectMore, int validityPeriod) { if (callingPackage == null) { callingPackage = getCallingPackage(); } IccSmsInterfaceManager iccSmsIntMgr = getIccSmsInterfaceManager(subId); if (iccSmsIntMgr != null) { iccSmsIntMgr.sendMultipartTextWithOptions(callingPackage, destAddr, scAddr, parts, sentIntents, deliveryIntents, persistMessage, priority, expectMore, validityPeriod, 0L /* messageId */); iccSmsIntMgr.sendMultipartTextWithOptions(callingPackage, callingAttributionTag, destAddr, scAddr, parts, sentIntents, deliveryIntents, persistMessage, priority, expectMore, validityPeriod, 0L /* messageId */); } else { Rlog.e(LOG_TAG, "sendMultipartTextWithOptions iccSmsIntMgr is null for" + " Subscription: " + subId); Loading Loading @@ -496,12 +510,13 @@ public class SmsController extends ISmsImplBase { } @Override public void sendStoredText(int subId, String callingPkg, Uri messageUri, String scAddress, PendingIntent sentIntent, PendingIntent deliveryIntent) { public void sendStoredText(int subId, String callingPkg, String callingAttributionTag, Uri messageUri, String scAddress, PendingIntent sentIntent, PendingIntent deliveryIntent) { IccSmsInterfaceManager iccSmsIntMgr = getIccSmsInterfaceManager(subId); if (iccSmsIntMgr != null) { iccSmsIntMgr.sendStoredText(callingPkg, messageUri, scAddress, sentIntent, deliveryIntent); iccSmsIntMgr.sendStoredText(callingPkg, callingAttributionTag, messageUri, scAddress, sentIntent, deliveryIntent); } else { Rlog.e(LOG_TAG, "sendStoredText iccSmsIntMgr is null for subscription: " + subId); sendErrorInPendingIntent(sentIntent, SmsManager.RESULT_ERROR_GENERIC_FAILURE); Loading @@ -509,13 +524,13 @@ public class SmsController extends ISmsImplBase { } @Override public void sendStoredMultipartText(int subId, String callingPkg, Uri messageUri, String scAddress, List<PendingIntent> sentIntents, public void sendStoredMultipartText(int subId, String callingPkg, String callingAttributionTag, Uri messageUri, String scAddress, List<PendingIntent> sentIntents, List<PendingIntent> deliveryIntents) { IccSmsInterfaceManager iccSmsIntMgr = getIccSmsInterfaceManager(subId); if (iccSmsIntMgr != null) { iccSmsIntMgr.sendStoredMultipartText(callingPkg, messageUri, scAddress, sentIntents, deliveryIntents); iccSmsIntMgr.sendStoredMultipartText(callingPkg, callingAttributionTag, messageUri, scAddress, sentIntents, deliveryIntents); } else { Rlog.e(LOG_TAG, "sendStoredMultipartText iccSmsIntMgr is null for subscription: " + subId); Loading
src/java/com/android/internal/telephony/SmsPermissions.java +7 −5 Original line number Diff line number Diff line Loading @@ -60,7 +60,8 @@ public class SmsPermissions { * @return true unless the caller has all necessary permissions but has a revoked AppOps bit. */ public boolean checkCallingCanSendText( boolean persistMessageForNonDefaultSmsApp, String callingPackage, String message) { boolean persistMessageForNonDefaultSmsApp, String callingPackage, String callingAttributionTag, String message) { // TODO(b/75978989): Should we allow IMS/carrier apps for persisted messages as well? if (!persistMessageForNonDefaultSmsApp) { try { Loading @@ -72,7 +73,7 @@ public class SmsPermissions { android.Manifest.permission.MODIFY_PHONE_STATE, message); } } return checkCallingCanSendSms(callingPackage, message); return checkCallingCanSendSms(callingPackage, callingAttributionTag, message); } /** Loading Loading @@ -109,10 +110,11 @@ public class SmsPermissions { * permission revoked at runtime. * @return whether the caller has the OP_SEND_SMS AppOps bit. */ public boolean checkCallingCanSendSms(String callingPackage, String message) { public boolean checkCallingCanSendSms(String callingPackage, String callingAttributionTag, String message) { mContext.enforceCallingPermission(Manifest.permission.SEND_SMS, message); return mAppOps.noteOp(AppOpsManager.OPSTR_SEND_SMS, Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED; return mAppOps.noteOp(AppOpsManager.OPSTR_SEND_SMS, Binder.getCallingUid(), callingPackage, callingAttributionTag, null) == AppOpsManager.MODE_ALLOWED; } /** Loading
tests/telephonytests/src/com/android/internal/telephony/PhoneSubInfoControllerTest.java +5 −0 Original line number Diff line number Diff line Loading @@ -105,6 +105,7 @@ public class PhoneSubInfoControllerTest extends TelephonyTest { // The READ_PRIVILEGED_PHONE_STATE permission or passing a device / profile owner access // check is required to access device identifiers. Since neither of those are true for this // test each case will result in a SecurityException being thrown. setIdentifierAccess(false); doReturn("353626073736741").when(mPhone).getDeviceId(); doReturn("353626073736742").when(mSecondPhone).getDeviceId(); Loading Loading @@ -188,6 +189,7 @@ public class PhoneSubInfoControllerTest extends TelephonyTest { // The READ_PRIVILEGED_PHONE_STATE permission, carrier privileges, or passing a device / // profile owner access check is required to access subscriber identifiers. Since none of // those are true for this test each case will result in a SecurityException being thrown. setIdentifierAccess(false); doReturn("aaa@example.com").when(mPhone).getNai(); doReturn("bbb@example.com").when(mSecondPhone).getNai(); Loading Loading @@ -270,6 +272,7 @@ public class PhoneSubInfoControllerTest extends TelephonyTest { // The READ_PRIVILEGED_PHONE_STATE permission, carrier privileges, or passing a device / // profile owner access check is required to access device identifiers. Since none of // those are true for this test each case will result in a SecurityException being thrown. setIdentifierAccess(false); doReturn("990000862471854").when(mPhone).getImei(); doReturn("990000862471855").when(mSecondPhone).getImei(); Loading Loading @@ -412,6 +415,7 @@ public class PhoneSubInfoControllerTest extends TelephonyTest { // The READ_PRIVILEGED_PHONE_STATE permission, carrier privileges, or passing a device / // profile owner access check is required to access subscriber identifiers. Since none of // those are true for this test each case will result in a SecurityException being thrown. setIdentifierAccess(false); doReturn("310260426283121").when(mPhone).getSubscriberId(); doReturn("310260426283122").when(mSecondPhone).getSubscriberId(); Loading Loading @@ -496,6 +500,7 @@ public class PhoneSubInfoControllerTest extends TelephonyTest { // The READ_PRIVILEGED_PHONE_STATE permission, carrier privileges, or passing a device / // profile owner access check is required to access subscriber identifiers. Since none of // those are true for this test each case will result in a SecurityException being thrown. setIdentifierAccess(false); doReturn("8991101200003204510").when(mPhone).getIccSerialNumber(); doReturn("8991101200003204511").when(mSecondPhone).getIccSerialNumber(); Loading
tests/telephonytests/src/com/android/internal/telephony/SmsPermissionsTest.java +21 −14 Original line number Diff line number Diff line Loading @@ -47,6 +47,7 @@ import java.util.concurrent.TimeUnit; public class SmsPermissionsTest extends TelephonyTest { private static final String PACKAGE = "com.example.package"; private static final String ATTRIBUTION_TAG = null; private static final String MESSAGE = "msg"; private HandlerThread mHandlerThread; Loading Loading @@ -104,7 +105,7 @@ public class SmsPermissionsTest extends TelephonyTest { @Test public void testCheckCallingSendTextPermissions_persist_grant() { assertTrue(mSmsPermissionsTest.checkCallingCanSendText( true /* persistMessageForNonDefaultSmsApp */, PACKAGE, MESSAGE)); true /* persistMessageForNonDefaultSmsApp */, PACKAGE, ATTRIBUTION_TAG, MESSAGE)); } @Test Loading @@ -113,7 +114,8 @@ public class SmsPermissionsTest extends TelephonyTest { .enforceCallingPermission(Manifest.permission.SEND_SMS, MESSAGE); try { mSmsPermissionsTest.checkCallingCanSendText( true /* persistMessageForNonDefaultSmsApp */, PACKAGE, MESSAGE); true /* persistMessageForNonDefaultSmsApp */, PACKAGE, ATTRIBUTION_TAG, MESSAGE); fail(); } catch (SecurityException e) { // expected Loading @@ -122,11 +124,12 @@ public class SmsPermissionsTest extends TelephonyTest { @Test public void testCheckCallingSendTextPermissions_persist_noAppOps() { Mockito.when(mMockAppOps.noteOp( AppOpsManager.OPSTR_SEND_SMS, Binder.getCallingUid(), PACKAGE)) Mockito.when( mMockAppOps.noteOp(AppOpsManager.OPSTR_SEND_SMS, Binder.getCallingUid(), PACKAGE, ATTRIBUTION_TAG, null)) .thenReturn(AppOpsManager.MODE_ERRORED); assertFalse(mSmsPermissionsTest.checkCallingCanSendText( true /* persistMessageForNonDefaultSmsApp */, PACKAGE, MESSAGE)); true /* persistMessageForNonDefaultSmsApp */, PACKAGE, ATTRIBUTION_TAG, MESSAGE)); } @Test Loading @@ -137,18 +140,19 @@ public class SmsPermissionsTest extends TelephonyTest { .enforceCallingPermission(Manifest.permission.MODIFY_PHONE_STATE, MESSAGE); Mockito.doThrow(new SecurityException(MESSAGE)).when(mMockContext) .enforceCallingPermission(Manifest.permission.SEND_SMS, MESSAGE); Mockito.when(mMockAppOps.noteOp( AppOpsManager.OPSTR_SEND_SMS, Binder.getCallingUid(), PACKAGE)) Mockito.when( mMockAppOps.noteOp(AppOpsManager.OPSTR_SEND_SMS, Binder.getCallingUid(), PACKAGE, ATTRIBUTION_TAG, null)) .thenReturn(AppOpsManager.MODE_ERRORED); assertTrue(mSmsPermissionsTest.checkCallingCanSendText( false /* persistMessageForNonDefaultSmsApp */, PACKAGE, MESSAGE)); false /* persistMessageForNonDefaultSmsApp */, PACKAGE, ATTRIBUTION_TAG, MESSAGE)); } @Test public void testCheckCallingSendTextPermissions_noPersist_grantViaModifyAndSend() { assertTrue(mSmsPermissionsTest.checkCallingCanSendText( false /* persistMessageForNonDefaultSmsApp */, PACKAGE, MESSAGE)); false /* persistMessageForNonDefaultSmsApp */, PACKAGE, ATTRIBUTION_TAG, MESSAGE)); } @Test Loading @@ -157,7 +161,8 @@ public class SmsPermissionsTest extends TelephonyTest { .enforceCallingPermission(Manifest.permission.MODIFY_PHONE_STATE, MESSAGE); try { mSmsPermissionsTest.checkCallingCanSendText( false /* persistMessageForNonDefaultSmsApp */, PACKAGE, MESSAGE); false /* persistMessageForNonDefaultSmsApp */, PACKAGE, ATTRIBUTION_TAG, MESSAGE); fail(); } catch (SecurityException e) { // expected Loading @@ -170,7 +175,8 @@ public class SmsPermissionsTest extends TelephonyTest { .enforceCallingPermission(Manifest.permission.SEND_SMS, MESSAGE); try { mSmsPermissionsTest.checkCallingCanSendText( false /* persistMessageForNonDefaultSmsApp */, PACKAGE, MESSAGE); false /* persistMessageForNonDefaultSmsApp */, PACKAGE, ATTRIBUTION_TAG, MESSAGE); fail(); } catch (SecurityException e) { // expected Loading @@ -179,11 +185,12 @@ public class SmsPermissionsTest extends TelephonyTest { @Test public void testCheckCallingSendTextPermissions_noPersist_noAppOps() { Mockito.when(mMockAppOps.noteOp( AppOpsManager.OPSTR_SEND_SMS, Binder.getCallingUid(), PACKAGE)) Mockito.when( mMockAppOps.noteOp(AppOpsManager.OPSTR_SEND_SMS, Binder.getCallingUid(), PACKAGE, ATTRIBUTION_TAG, null)) .thenReturn(AppOpsManager.MODE_ERRORED); assertFalse(mSmsPermissionsTest.checkCallingCanSendText( false /* persistMessageForNonDefaultSmsApp */, PACKAGE, MESSAGE)); false /* persistMessageForNonDefaultSmsApp */, PACKAGE, ATTRIBUTION_TAG, MESSAGE)); } @Test Loading