summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Pasanen <dan.pasanen@gmail.com>2017-04-05 07:27:24 -0500
committerDan Pasanen <dan.pasanen@gmail.com>2017-04-05 07:27:24 -0500
commit80580cd695fd80d3cf0e37ef2d5c323457dafca2 (patch)
treeed6c29f5864f431db92dfb481bdb83d1cbc87c24
parentde8277e1932963ee54b799d098e775c4beab2f6c (diff)
parentf37c91b2ad585acf86f843efc275a063615b0f3b (diff)
downloadandroid_packages_services_Mms-cm-14.1.tar.gz
android_packages_services_Mms-cm-14.1.tar.bz2
android_packages_services_Mms-cm-14.1.zip
Merge tag 'android-7.1.2_r2' into cm-14.1staging/cm-14.1_android-7.1.2_r2cm-14.1
Android 7.1.2 Release 2 (N2G47E) # gpg: Signature made Mon 03 Apr 2017 01:41:50 AM CDT # gpg: using DSA key E8AD3F819AB10E78 # gpg: Can't check signature: No public key
-rw-r--r--src/com/android/mms/service/MmsNetworkManager.java40
-rw-r--r--src/com/android/mms/service/MmsRequest.java2
2 files changed, 39 insertions, 3 deletions
diff --git a/src/com/android/mms/service/MmsNetworkManager.java b/src/com/android/mms/service/MmsNetworkManager.java
index c2e2f6a..a37d31c 100644
--- a/src/com/android/mms/service/MmsNetworkManager.java
+++ b/src/com/android/mms/service/MmsNetworkManager.java
@@ -22,6 +22,8 @@ import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.net.NetworkRequest;
+import android.os.Handler;
+import android.os.Looper;
import android.os.SystemClock;
import com.android.mms.service.exception.MmsNetworkException;
@@ -37,6 +39,9 @@ public class MmsNetworkManager {
// to make sure we don't bail prematurely
private static final int NETWORK_ACQUIRE_TIMEOUT_MILLIS =
NETWORK_REQUEST_TIMEOUT_MILLIS + (5 * 1000);
+ // Waiting time used before releasing a network prematurely. This allows the MMS download
+ // acknowledgement messages to be sent using the same network that was used to download the data
+ private static final int NETWORK_RELEASE_TIMEOUT_MILLIS = 5 * 1000;
private final Context mContext;
@@ -57,6 +62,12 @@ public class MmsNetworkManager {
// The MMS HTTP client for this network
private MmsHttpClient mMmsHttpClient;
+ // The handler used for delayed release of the network
+ private final Handler mReleaseHandler;
+
+ // The task that does the delayed releasing of the network.
+ private final Runnable mNetworkReleaseTask;
+
// The SIM ID which we use to connect
private final int mSubId;
@@ -103,11 +114,23 @@ public class MmsNetworkManager {
mConnectivityManager = null;
mMmsHttpClient = null;
mSubId = subId;
+ mReleaseHandler = new Handler(Looper.getMainLooper());
mNetworkRequest = new NetworkRequest.Builder()
.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR)
.addCapability(NetworkCapabilities.NET_CAPABILITY_MMS)
.setNetworkSpecifier(Integer.toString(mSubId))
.build();
+
+ mNetworkReleaseTask = new Runnable() {
+ @Override
+ public void run() {
+ synchronized (this) {
+ if (mMmsRequestCount < 1) {
+ releaseRequestLocked(mNetworkCallback);
+ }
+ }
+ }
+ };
}
/**
@@ -118,6 +141,8 @@ public class MmsNetworkManager {
*/
public void acquireNetwork(final String requestId) throws MmsNetworkException {
synchronized (this) {
+ // Since we are acquiring the network, remove the network release task if exists.
+ mReleaseHandler.removeCallbacks(mNetworkReleaseTask);
mMmsRequestCount += 1;
if (mNetwork != null) {
// Already available
@@ -155,14 +180,25 @@ public class MmsNetworkManager {
* Release the MMS network when nobody is holding on to it.
*
* @param requestId request ID for logging
+ * @param shouldDelayRelease whether the release should be delayed for 5 seconds, the regular
+ * use case is to delay this for DownloadRequests to use the network
+ * for sending an acknowledgement on the same network
*/
- public void releaseNetwork(final String requestId) {
+ public void releaseNetwork(final String requestId, final boolean shouldDelayRelease) {
synchronized (this) {
if (mMmsRequestCount > 0) {
mMmsRequestCount -= 1;
LogUtil.d(requestId, "MmsNetworkManager: release, count=" + mMmsRequestCount);
if (mMmsRequestCount < 1) {
- releaseRequestLocked(mNetworkCallback);
+ if (shouldDelayRelease) {
+ // remove previously posted task and post a delayed task on the release
+ // handler to release the network
+ mReleaseHandler.removeCallbacks(mNetworkReleaseTask);
+ mReleaseHandler.postDelayed(mNetworkReleaseTask,
+ NETWORK_RELEASE_TIMEOUT_MILLIS);
+ } else {
+ releaseRequestLocked(mNetworkCallback);
+ }
}
}
}
diff --git a/src/com/android/mms/service/MmsRequest.java b/src/com/android/mms/service/MmsRequest.java
index 4eeac08..ec8b334 100644
--- a/src/com/android/mms/service/MmsRequest.java
+++ b/src/com/android/mms/service/MmsRequest.java
@@ -173,7 +173,7 @@ public abstract class MmsRequest {
// Success
break;
} finally {
- networkManager.releaseNetwork(requestId);
+ networkManager.releaseNetwork(requestId, this instanceof DownloadRequest);
}
} catch (ApnException e) {
LogUtil.e(requestId, "APN failure", e);