diff options
author | John Wang <johnwang@google.com> | 2011-01-21 16:18:26 -0800 |
---|---|---|
committer | John Wang <johnwang@google.com> | 2011-01-21 17:46:08 -0800 |
commit | 696794fc139a752e2a10fa66d73a9ae6fd085acc (patch) | |
tree | 42bf30c10b15428b3bbc4cdd3603ac95c28f875a /telephony/java | |
parent | 398a589ccea744556732b25097412dbb22c51271 (diff) | |
download | frameworks_base-696794fc139a752e2a10fa66d73a9ae6fd085acc.zip frameworks_base-696794fc139a752e2a10fa66d73a9ae6fd085acc.tar.gz frameworks_base-696794fc139a752e2a10fa66d73a9ae6fd085acc.tar.bz2 |
Enable recovery in RIL wakelock release check.
Wakelock will get released while
1) no request pending to be sent out, in which mRequestMessagesPending increases
before calling EVENT_SEND and decreases while handling EVENT_SEND.
and
2) no waiting requests sent to RIL but no replied, in which mRequestMessagesWaiting
increases while sending request and decreases while handling response.
Both will be cleared while WAKE_LOCK_TIMEOUT occurs to recovery from out of sync situation.
bug: 3369427, 3370827
Change-Id: Ib2fc54db3b155bd3fb1296ad83720b7836708caf
Diffstat (limited to 'telephony/java')
-rw-r--r-- | telephony/java/com/android/internal/telephony/RIL.java | 74 |
1 files changed, 56 insertions, 18 deletions
diff --git a/telephony/java/com/android/internal/telephony/RIL.java b/telephony/java/com/android/internal/telephony/RIL.java index 7d31687..f2643bb 100644 --- a/telephony/java/com/android/internal/telephony/RIL.java +++ b/telephony/java/com/android/internal/telephony/RIL.java @@ -225,7 +225,15 @@ public final class RIL extends BaseCommands implements CommandsInterface { private Context mContext; WakeLock mWakeLock; int mWakeLockTimeout; + // The number of requests pending to be sent out, it increases before calling + // EVENT_SEND and decreases while handling EVENT_SEND. It gets cleared while + // WAKE_LOCK_TIMEOUT occurs. int mRequestMessagesPending; + // The number of requests sent out but waiting for response. It increases while + // sending request and decreases while handling response. It should match + // mRequestList.size() unless there are requests no replied while + // WAKE_LOCK_TIMEOUT occurs. + int mRequestMessagesWaiting; // Is this the first radio state change? private boolean mInitialRadioStateChange = true; @@ -308,16 +316,19 @@ public final class RIL extends BaseCommands implements CommandsInterface { if (s == null) { rr.onError(RADIO_NOT_AVAILABLE, null); rr.release(); - mRequestMessagesPending--; + if (mRequestMessagesPending > 0) + mRequestMessagesPending--; alreadySubtracted = true; return; } synchronized (mRequestsList) { mRequestsList.add(rr); + mRequestMessagesWaiting++; } - mRequestMessagesPending--; + if (mRequestMessagesPending > 0) + mRequestMessagesPending--; alreadySubtracted = true; byte[] data; @@ -361,7 +372,7 @@ public final class RIL extends BaseCommands implements CommandsInterface { } } - if (!alreadySubtracted) { + if (!alreadySubtracted && mRequestMessagesPending > 0) { mRequestMessagesPending--; } @@ -376,25 +387,48 @@ public final class RIL extends BaseCommands implements CommandsInterface { // new send request. So when WAKE_LOCK_TIMEOUT occurs // all requests in mRequestList already waited at // least DEFAULT_WAKE_LOCK_TIMEOUT but no response. - // Therefore all should be treated as lost requests. - // Those lost requests return GENERIC_FAILURE and - // request list is cleared. + // Reset mRequestMessagesWaiting to enable + // releaseWakeLockIfDone(). // - // Note: mRequestMessagesPending shows how many - // requests are waiting to be sent (and before - // to be added in request list) since star the - // timer. It should be - // zero here since all request should already - // be put in request list while TIMEOUT occurs. - clearRequestsList(GENERIC_FAILURE, true); + // Note: Keep mRequestList so that delayed response + // can still be handled when response finally comes. + if (mRequestMessagesWaiting != 0) { + Log.d(LOG_TAG, "NOTE: mReqWaiting is NOT 0 but" + + mRequestMessagesWaiting + " at TIMEOUT, reset!" + + " There still msg waitng for response"); + + mRequestMessagesWaiting = 0; + + if (RILJ_LOGD) { + synchronized (mRequestsList) { + int count = mRequestsList.size(); + Log.d(LOG_TAG, "WAKE_LOCK_TIMEOUT " + + " mRequestList=" + count); + + for (int i = 0; i < count; i++) { + rr = mRequestsList.get(i); + Log.d(LOG_TAG, i + ": [" + rr.mSerial + "] " + + requestToString(rr.mRequest)); + } + } + } + } + // mRequestMessagesPending shows how many + // requests are waiting to be sent (and before + // to be added in request list) since star the + // WAKE_LOCK_TIMEOUT timer. Since WAKE_LOCK_TIMEOUT + // is the expected time to get response, all requests + // should already sent out (i.e. + // mRequestMessagesPending is 0 )while TIMEOUT occurs. if (mRequestMessagesPending != 0) { - Log.e(LOG_TAG, "ERROR: mReqPending is NOT 0 at TIMEOUT, " - + "mReqPending = " + mRequestMessagesPending); + Log.e(LOG_TAG, "ERROR: mReqPending is NOT 0 but" + + mRequestMessagesPending + " at TIMEOUT, reset!"); + mRequestMessagesPending = 0; + } mWakeLock.release(); } } - break; } } @@ -607,6 +641,7 @@ public final class RIL extends BaseCommands implements CommandsInterface { mWakeLockTimeout = SystemProperties.getInt(TelephonyProperties.PROPERTY_WAKE_LOCK_TIMEOUT, DEFAULT_WAKE_LOCK_TIMEOUT); mRequestMessagesPending = 0; + mRequestMessagesWaiting = 0; mContext = context; @@ -2000,7 +2035,7 @@ public final class RIL extends BaseCommands implements CommandsInterface { /** * Holds a PARTIAL_WAKE_LOCK whenever * a) There is outstanding RIL request sent to RIL deamon and no replied - * b) There is a request waiting to be sent out. + * b) There is a request pending to be sent out. * * There is a WAKE_LOCK_TIMEOUT to release the lock, though it shouldn't * happen often. @@ -2023,7 +2058,7 @@ public final class RIL extends BaseCommands implements CommandsInterface { synchronized (mWakeLock) { if (mWakeLock.isHeld() && (mRequestMessagesPending == 0) && - (mRequestsList.size() == 0)) { + (mRequestMessagesWaiting == 0)) { mSender.removeMessages(EVENT_WAKE_LOCK_TIMEOUT); mWakeLock.release(); } @@ -2081,6 +2116,7 @@ public final class RIL extends BaseCommands implements CommandsInterface { rr.release(); } mRequestsList.clear(); + mRequestMessagesWaiting = 0; } } @@ -2091,6 +2127,8 @@ public final class RIL extends BaseCommands implements CommandsInterface { if (rr.mSerial == serial) { mRequestsList.remove(i); + if (mRequestMessagesWaiting > 0) + mRequestMessagesWaiting--; return rr; } } |