diff options
author | Taesu Lee <taesu82.lee@samsung.com> | 2021-06-25 23:15:15 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-06-25 23:15:15 +0000 |
commit | 617ad60ef7d85f402b109ad18ea52cd5cb349c2b (patch) | |
tree | 2798c7fede2758624507b703759f38df1d73d7d7 | |
parent | 8b49ddeb5c6093e410953ec0493d899211b20663 (diff) | |
parent | 2a18d12b0b5ab6f158441155c5db593cea02f787 (diff) | |
download | Mms-617ad60ef7d85f402b109ad18ea52cd5cb349c2b.tar.gz |
Fast-fail when enabledMMS config is not true am: 9aec9a1669 am: 2a18d12b0b
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/services/Mms/+/15113839
Change-Id: I7f4155a0316b0dd1c32d1c41f7d70112df1ac4ff
-rw-r--r-- | src/com/android/mms/service/MmsRequest.java | 41 | ||||
-rw-r--r-- | src/com/android/mms/service/MmsService.java | 88 |
2 files changed, 78 insertions, 51 deletions
diff --git a/src/com/android/mms/service/MmsRequest.java b/src/com/android/mms/service/MmsRequest.java index 64e10af..4c7b4c7 100644 --- a/src/com/android/mms/service/MmsRequest.java +++ b/src/com/android/mms/service/MmsRequest.java @@ -36,7 +36,6 @@ import android.telephony.ims.ImsMmTelManager; import android.telephony.ims.stub.ImsRegistrationImplBase; import android.telephony.SmsManager; import android.telephony.TelephonyManager; -import android.text.TextUtils; import com.android.mms.service.exception.ApnException; import com.android.mms.service.exception.MmsHttpException; @@ -99,8 +98,6 @@ public abstract class MmsRequest { protected String mCreator; // MMS config protected Bundle mMmsConfig; - // MMS config overrides that will be applied to mMmsConfig when we eventually load it. - protected Bundle mMmsConfigOverrides; // Context used to get TelephonyManager. protected Context mContext; protected long mMessageId; @@ -125,12 +122,11 @@ public abstract class MmsRequest { } public MmsRequest(RequestManager requestManager, int subId, String creator, - Bundle configOverrides, Context context, long messageId) { + Bundle mmsConfig, Context context, long messageId) { mRequestManager = requestManager; mSubId = subId; mCreator = creator; - mMmsConfigOverrides = configOverrides; - mMmsConfig = null; + mMmsConfig = mmsConfig; mContext = context; mMessageId = messageId; } @@ -139,34 +135,6 @@ public abstract class MmsRequest { return mSubId; } - private boolean ensureMmsConfigLoaded() { - if (mMmsConfig == null) { - // Not yet retrieved from mms config manager. Try getting it. - final Bundle config = MmsConfigManager.getInstance().getMmsConfigBySubId(mSubId); - if (config != null) { - mMmsConfig = config; - // TODO: Make MmsConfigManager authoritative for user agent and don't consult - // TelephonyManager. - final TelephonyManager telephonyManager = ((TelephonyManager) mContext - .getSystemService(Context.TELEPHONY_SERVICE)) - .createForSubscriptionId(mSubId); - final String userAgent = telephonyManager.getMmsUserAgent(); - if (!TextUtils.isEmpty(userAgent)) { - config.putString(SmsManager.MMS_CONFIG_USER_AGENT, userAgent); - } - final String userAgentProfileUrl = telephonyManager.getMmsUAProfUrl(); - if (!TextUtils.isEmpty(userAgentProfileUrl)) { - config.putString(SmsManager.MMS_CONFIG_UA_PROF_URL, userAgentProfileUrl); - } - // Apply overrides - if (mMmsConfigOverrides != null) { - mMmsConfig.putAll(mMmsConfigOverrides); - } - } - } - return mMmsConfig != null; - } - /** * Execute the request * @@ -181,10 +149,7 @@ public abstract class MmsRequest { byte[] response = null; // TODO: add mms data channel check back to fast fail if no way to send mms, // when telephony provides such API. - if (!ensureMmsConfigLoaded()) { // Check mms config - LogUtil.e(requestId, "mms config is not loaded yet"); - result = SmsManager.MMS_ERROR_CONFIGURATION_ERROR; - } else if (!prepareForHttpRequest()) { // Prepare request, like reading pdu data from user + if (!prepareForHttpRequest()) { // Prepare request, like reading pdu data from user LogUtil.e(requestId, "Failed to prepare for request"); result = SmsManager.MMS_ERROR_IO_ERROR; } else { // Execute diff --git a/src/com/android/mms/service/MmsService.java b/src/com/android/mms/service/MmsService.java index 2403e12..0394379 100644 --- a/src/com/android/mms/service/MmsService.java +++ b/src/com/android/mms/service/MmsService.java @@ -185,6 +185,24 @@ public class MmsService extends Service implements MmsRequest.RequestManager { } } + private Bundle loadMmsConfig(int subId) { + final Bundle config = MmsConfigManager.getInstance().getMmsConfigBySubId(subId); + if (config != null) { + // TODO: Make MmsConfigManager authoritative for user agent and don't consult + // TelephonyManager. + final TelephonyManager telephonyManager = getTelephonyManager(subId); + final String userAgent = telephonyManager.getMmsUserAgent(); + if (!TextUtils.isEmpty(userAgent)) { + config.putString(SmsManager.MMS_CONFIG_USER_AGENT, userAgent); + } + final String userAgentProfileUrl = telephonyManager.getMmsUAProfUrl(); + if (!TextUtils.isEmpty(userAgentProfileUrl)) { + config.putString(SmsManager.MMS_CONFIG_UA_PROF_URL, userAgentProfileUrl); + } + } + return config; + } + private IMms.Stub mStub = new IMms.Stub() { @Override public void sendMessage(int subId, String callingPkg, Uri contentUri, @@ -196,7 +214,7 @@ public class MmsService extends Service implements MmsRequest.RequestManager { // Make sure the subId is correct if (!SubscriptionManager.isValidSubscriptionId(subId)) { LogUtil.e("Invalid subId " + subId); - sendErrorInPendingIntent(sentIntent); + sendErrorInPendingIntent(sentIntent, SmsManager.MMS_ERROR_NO_DATA_NETWORK); return; } if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { @@ -205,13 +223,32 @@ public class MmsService extends Service implements MmsRequest.RequestManager { // Make sure the subId is active if (!isActiveSubId(subId)) { - sendErrorInPendingIntent(sentIntent); + sendErrorInPendingIntent(sentIntent, SmsManager.MMS_ERROR_NO_DATA_NETWORK); + return; + } + + // Load MMS config + Bundle mmsConfig = loadMmsConfig(subId); + if (mmsConfig == null) { + LogUtil.e("MMS config is not loaded yet for subId " + subId); + sendErrorInPendingIntent(sentIntent, SmsManager.MMS_ERROR_CONFIGURATION_ERROR); + return; + } + + // Apply overrides + if (configOverrides != null) { + mmsConfig.putAll(configOverrides); + } + + // Make sure MMS is enabled + if (!mmsConfig.getBoolean(SmsManager.MMS_CONFIG_MMS_ENABLED)) { + LogUtil.e("MMS is not enabled for subId " + subId); + sendErrorInPendingIntent(sentIntent, SmsManager.MMS_ERROR_CONFIGURATION_ERROR); return; } final SendRequest request = new SendRequest(MmsService.this, subId, contentUri, - locationUrl, sentIntent, callingPkg, configOverrides, MmsService.this, - messageId); + locationUrl, sentIntent, callingPkg, mmsConfig, MmsService.this, messageId); final String carrierMessagingServicePackage = getCarrierMessagingServicePackageIfExists(subId); @@ -232,7 +269,7 @@ public class MmsService extends Service implements MmsRequest.RequestManager { // AcknowledgeInd and NotifyRespInd are parts of downloading sequence. // TODO: Should consider ReadRecInd(Read Report)? sendSettingsIntentForFailedMms(!isRawPduSendReq(contentUri), subId); - sendErrorInPendingIntent(sentIntent); + sendErrorInPendingIntent(sentIntent, SmsManager.MMS_ERROR_NO_DATA_NETWORK); return; } @@ -254,7 +291,7 @@ public class MmsService extends Service implements MmsRequest.RequestManager { // Make sure the subId is correct if (!SubscriptionManager.isValidSubscriptionId(subId)) { LogUtil.e("Invalid subId " + subId); - sendErrorInPendingIntent(downloadedIntent); + sendErrorInPendingIntent(downloadedIntent, SmsManager.MMS_ERROR_NO_DATA_NETWORK); return; } if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { @@ -264,7 +301,8 @@ public class MmsService extends Service implements MmsRequest.RequestManager { if (!isActiveSubId(subId)) { List<SubscriptionInfo> activeSubList = getActiveSubscriptionsInGroup(subId); if (activeSubList.isEmpty()) { - sendErrorInPendingIntent(downloadedIntent); + sendErrorInPendingIntent( + downloadedIntent, SmsManager.MMS_ERROR_NO_DATA_NETWORK); return; } @@ -279,8 +317,30 @@ public class MmsService extends Service implements MmsRequest.RequestManager { } } + // Load MMS config + Bundle mmsConfig = loadMmsConfig(subId); + if (mmsConfig == null) { + LogUtil.e("MMS config is not loaded yet for subId " + subId); + sendErrorInPendingIntent( + downloadedIntent, SmsManager.MMS_ERROR_CONFIGURATION_ERROR); + return; + } + + // Apply overrides + if (configOverrides != null) { + mmsConfig.putAll(configOverrides); + } + + // Make sure MMS is enabled + if (!mmsConfig.getBoolean(SmsManager.MMS_CONFIG_MMS_ENABLED)) { + LogUtil.e("MMS is not enabled for subId " + subId); + sendErrorInPendingIntent( + downloadedIntent, SmsManager.MMS_ERROR_CONFIGURATION_ERROR); + return; + } + final DownloadRequest request = new DownloadRequest(MmsService.this, subId, locationUrl, - contentUri, downloadedIntent, callingPkg, configOverrides, MmsService.this, + contentUri, downloadedIntent, callingPkg, mmsConfig, MmsService.this, messageId); final String carrierMessagingServicePackage = @@ -296,7 +356,7 @@ public class MmsService extends Service implements MmsRequest.RequestManager { // Make sure subId has MMS data if (!getTelephonyManager(subId).isDataEnabledForApn(ApnSetting.TYPE_MMS)) { sendSettingsIntentForFailedMms(/*isIncoming=*/ true, subId); - sendErrorInPendingIntent(downloadedIntent); + sendErrorInPendingIntent(downloadedIntent, SmsManager.MMS_ERROR_NO_DATA_NETWORK); return; } @@ -486,14 +546,16 @@ public class MmsService extends Service implements MmsRequest.RequestManager { .isActiveSubscriptionId(subId); } - /* - * Calls the pending intent with <code>MMS_ERROR_NO_DATA_NETWORK</code>. + /** + * Calls the pending intent with one of these result codes: + * <code>MMS_ERROR_CONFIGURATION_ERROR</code> + * <code>MMS_ERROR_NO_DATA_NETWORK</code>. */ - private void sendErrorInPendingIntent(@Nullable PendingIntent intent) { + private void sendErrorInPendingIntent(@Nullable PendingIntent intent, int resultCode) { LogUtil.d("sendErrorInPendingIntent - no data network"); if (intent != null) { try { - intent.send(SmsManager.MMS_ERROR_NO_DATA_NETWORK); + intent.send(resultCode); } catch (PendingIntent.CanceledException ex) { } } |