Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 93300ce2 authored by John Wang's avatar John Wang Committed by Android (Google) Code Review
Browse files

Merge "Enable recovery in RIL wakelock release check." into gingerbread

parents c896d85c 696794fc
Loading
Loading
Loading
Loading
+56 −18
Original line number Diff line number Diff line
@@ -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,6 +316,7 @@ public final class RIL extends BaseCommands implements CommandsInterface {
                        if (s == null) {
                            rr.onError(RADIO_NOT_AVAILABLE, null);
                            rr.release();
                            if (mRequestMessagesPending > 0)
                                mRequestMessagesPending--;
                            alreadySubtracted = true;
                            return;
@@ -315,8 +324,10 @@ public final class RIL extends BaseCommands implements CommandsInterface {

                        synchronized (mRequestsList) {
                            mRequestsList.add(rr);
                            mRequestMessagesWaiting++;
                        }

                        if (mRequestMessagesPending > 0)
                            mRequestMessagesPending--;
                        alreadySubtracted = true;

@@ -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
                            // 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
                            //       timer. It should be
                            //       zero here since all request should already
                            //       be put in request list while TIMEOUT occurs.
                            clearRequestsList(GENERIC_FAILURE, true);
                            // 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;
                }
            }