summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTaesu Lee <taesu82.lee@samsung.com>2021-06-26 00:57:12 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-06-26 00:57:12 +0000
commiteed845d8eea53cc14fc6b860edb72d8ada611dad (patch)
tree53aad910ce75f5939cdf8e14a93805556a9bcafa
parent4a388d04f8a25050b0bf092ab09a0e2d647f7c38 (diff)
parentc13b57a4c15263320db3af36b73d1469ce874885 (diff)
downloadMms-eed845d8eea53cc14fc6b860edb72d8ada611dad.tar.gz
Fast-fail when enabledMMS config is not true am: c13b57a4c1
Original change: https://android-review.googlesource.com/c/platform/packages/services/Mms/+/1197862 Change-Id: I079f0a97d70e7a4e4724caa7c74029817077859a
-rw-r--r--src/com/android/mms/service/MmsRequest.java41
-rw-r--r--src/com/android/mms/service/MmsService.java88
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 f8c882b..e24ae2d 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 40f13d9..a37ebe5 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);
@@ -231,7 +268,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;
}
@@ -253,7 +290,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) {
@@ -263,7 +300,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;
}
@@ -278,8 +316,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 =
@@ -294,7 +354,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;
}
@@ -484,13 +544,15 @@ 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) {
if (intent != null) {
try {
- intent.send(SmsManager.MMS_ERROR_NO_DATA_NETWORK);
+ intent.send(resultCode);
} catch (PendingIntent.CanceledException ex) {
}
}