am 93300ce2: Merge "Enable recovery in RIL wakelock release check." into gingerbread

* commit '93300ce2d398195d5616a2e924eb4a785274538e':
  Enable recovery in RIL wakelock release check.
This commit is contained in:
John Wang
2011-01-24 09:26:56 -08:00
committed by Android Git Automerger

View File

@@ -226,7 +226,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;
@@ -309,16 +317,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;
@@ -367,7 +378,7 @@ public final class RIL extends BaseCommands implements CommandsInterface {
releaseWakeLockIfDone();
}
if (!alreadySubtracted) {
if (!alreadySubtracted && mRequestMessagesPending > 0) {
mRequestMessagesPending--;
}
@@ -382,25 +393,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;
}
}
@@ -613,6 +647,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;
@@ -2010,7 +2045,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.
@@ -2033,7 +2068,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();
}
@@ -2097,6 +2132,7 @@ public final class RIL extends BaseCommands implements CommandsInterface {
rr.release();
}
mRequestsList.clear();
mRequestMessagesWaiting = 0;
}
}
@@ -2107,6 +2143,8 @@ public final class RIL extends BaseCommands implements CommandsInterface {
if (rr.mSerial == serial) {
mRequestsList.remove(i);
if (mRequestMessagesWaiting > 0)
mRequestMessagesWaiting--;
return rr;
}
}