summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRicardo Cerqueira <ricardo@cyngn.com>2016-04-17 00:38:52 +0100
committerRicardo Cerqueira <ricardo@cyngn.com>2016-04-17 14:25:38 +0100
commitb7a3f51a512cd425059503c0cbb818f15f4291db (patch)
tree05379b7a2dc20e6954f49840273469fb7ac6b9ad
parentc642b5a174a5207956b4a86da415557a2b405c22 (diff)
downloadandroid_packages_services_Mms-b7a3f51a512cd425059503c0cbb818f15f4291db.tar.gz
android_packages_services_Mms-b7a3f51a512cd425059503c0cbb818f15f4291db.tar.bz2
android_packages_services_Mms-b7a3f51a512cd425059503c0cbb818f15f4291db.zip
MmsRequest: Switch data subscription on MSIM if needed
If the active data subscription isn't the one we're trying to send the message out of, request a switch so that we don't try using the device's data sub instead of the one that is needed. In these scenarios, extend the retry cycle, too. We don't want to flip back and forth when radio conditions are poor, so try to get more mileage out of the temporary switch periods. Ref CYNGNOS-2492 Change-Id: Ide3bcc65beb171c8db1f49f9c101a5db7fd505f4
-rw-r--r--src/com/android/mms/service/MmsRequest.java38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/com/android/mms/service/MmsRequest.java b/src/com/android/mms/service/MmsRequest.java
index 1b6845b..badcca1 100644
--- a/src/com/android/mms/service/MmsRequest.java
+++ b/src/com/android/mms/service/MmsRequest.java
@@ -25,6 +25,7 @@ import android.os.Bundle;
import android.service.carrier.CarrierMessagingService;
import android.service.carrier.ICarrierMessagingCallback;
import android.telephony.SmsManager;
+import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
@@ -37,6 +38,7 @@ import com.android.mms.service.exception.MmsNetworkException;
*/
public abstract class MmsRequest {
private static final int RETRY_TIMES = 3;
+ private static final int RETRY_TIMES_WITH_DATA_SWITCH = 5;
/**
* Interface for certain functionalities from MmsService
@@ -83,6 +85,8 @@ public abstract class MmsRequest {
protected Bundle mMmsConfigOverrides;
// Context used to get TelephonyManager.
protected Context mContext;
+ // The active DDS id
+ protected int mDataSubId;
public MmsRequest(RequestManager requestManager, int subId, String creator,
Bundle configOverrides, Context context) {
@@ -137,6 +141,8 @@ public abstract class MmsRequest {
int result = SmsManager.MMS_ERROR_UNSPECIFIED;
int httpStatusCode = 0;
byte[] response = null;
+
+ mDataSubId = getDefaultDataSubId();
// 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
@@ -146,9 +152,21 @@ public abstract class MmsRequest {
LogUtil.e(requestId, "Failed to prepare for request");
result = SmsManager.MMS_ERROR_IO_ERROR;
} else { // Execute
+ int retryTimes = RETRY_TIMES;
+ if (getDefaultDataSubId() != mSubId) {
+ setDefaultDataSubId(mSubId);
+ // Give the switch some time to happen
+ try {
+ Thread.sleep(10 * 1000, 0/*nano*/);
+ } catch (InterruptedException e) {}
+ // DDS switches are expensive. Instead of retrying for just 30 seconds,
+ // try up to approximately 2 minutes before giving up and switching back
+ retryTimes = RETRY_TIMES_WITH_DATA_SWITCH;
+ }
+
long retryDelaySecs = 2;
// Try multiple times of MMS HTTP request
- for (int i = 0; i < RETRY_TIMES; i++) {
+ for (int i = 0; i < retryTimes; i++) {
try {
networkManager.acquireNetwork(requestId);
final String apnName = networkManager.getApnName();
@@ -239,6 +257,9 @@ public abstract class MmsRequest {
}
revokeUriPermission(context);
+ if (getDefaultDataSubId() != mDataSubId) {
+ setDefaultDataSubId(mDataSubId);
+ }
}
/**
@@ -351,4 +372,19 @@ public abstract class MmsRequest {
LogUtil.e("Unexpected onFilterComplete call with result: " + keepMessage);
}
}
+
+ /*
+ * @return the subId of whichever subId is active for data.
+ */
+ private int getDefaultDataSubId() {
+ return SubscriptionManager.from(mContext).getDefaultDataSubId();
+ }
+ /*
+ * @return set the subId for data
+ */
+ private void setDefaultDataSubId(int subId) {
+ SubscriptionManager.from(mContext).setDefaultDataSubId(subId);
+ // Should we toast about the data switch like Settings?
+ }
+
}