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

Commit 696794fc authored by John Wang's avatar John Wang
Browse files

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
parent 398a589c
Loading
Loading
Loading
Loading
+56 −18
Original line number Original line Diff line number Diff line
@@ -225,7 +225,15 @@ public final class RIL extends BaseCommands implements CommandsInterface {
    private Context mContext;
    private Context mContext;
    WakeLock mWakeLock;
    WakeLock mWakeLock;
    int mWakeLockTimeout;
    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;
    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?
    // Is this the first radio state change?
    private boolean mInitialRadioStateChange = true;
    private boolean mInitialRadioStateChange = true;
@@ -308,6 +316,7 @@ public final class RIL extends BaseCommands implements CommandsInterface {
                        if (s == null) {
                        if (s == null) {
                            rr.onError(RADIO_NOT_AVAILABLE, null);
                            rr.onError(RADIO_NOT_AVAILABLE, null);
                            rr.release();
                            rr.release();
                            if (mRequestMessagesPending > 0)
                                mRequestMessagesPending--;
                                mRequestMessagesPending--;
                            alreadySubtracted = true;
                            alreadySubtracted = true;
                            return;
                            return;
@@ -315,8 +324,10 @@ public final class RIL extends BaseCommands implements CommandsInterface {


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


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


@@ -361,7 +372,7 @@ public final class RIL extends BaseCommands implements CommandsInterface {
                        }
                        }
                    }
                    }


                    if (!alreadySubtracted) {
                    if (!alreadySubtracted && mRequestMessagesPending > 0) {
                        mRequestMessagesPending--;
                        mRequestMessagesPending--;
                    }
                    }


@@ -376,25 +387,48 @@ public final class RIL extends BaseCommands implements CommandsInterface {
                            // new send request. So when WAKE_LOCK_TIMEOUT occurs
                            // new send request. So when WAKE_LOCK_TIMEOUT occurs
                            // all requests in mRequestList already waited at
                            // all requests in mRequestList already waited at
                            // least DEFAULT_WAKE_LOCK_TIMEOUT but no response.
                            // least DEFAULT_WAKE_LOCK_TIMEOUT but no response.
                            // Therefore all should be treated as lost requests.
                            // Reset mRequestMessagesWaiting to enable
                            // Those lost requests return GENERIC_FAILURE and
                            // releaseWakeLockIfDone().
                            // request list is cleared.
                            //
                            //
                            // 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
                            // requests are waiting to be sent (and before
                            // to be added in request list) since star the
                            // to be added in request list) since star the
                            //       timer. It should be
                            // WAKE_LOCK_TIMEOUT timer. Since WAKE_LOCK_TIMEOUT
                            //       zero here since all request should already
                            // is the expected time to get response, all requests
                            //       be put in request list while TIMEOUT occurs.
                            // should already sent out (i.e.
                            clearRequestsList(GENERIC_FAILURE, true);
                            // mRequestMessagesPending is 0 )while TIMEOUT occurs.
                            if (mRequestMessagesPending != 0) {
                            if (mRequestMessagesPending != 0) {
                                Log.e(LOG_TAG, "ERROR: mReqPending is NOT 0 at TIMEOUT, "
                                Log.e(LOG_TAG, "ERROR: mReqPending is NOT 0 but"
                                    + "mReqPending = " + mRequestMessagesPending);
                                        + mRequestMessagesPending + " at TIMEOUT, reset!");
                                mRequestMessagesPending = 0;

                            }
                            }
                            mWakeLock.release();
                            mWakeLock.release();
                        }
                        }
                    }
                    }

                    break;
                    break;
            }
            }
        }
        }
@@ -607,6 +641,7 @@ public final class RIL extends BaseCommands implements CommandsInterface {
        mWakeLockTimeout = SystemProperties.getInt(TelephonyProperties.PROPERTY_WAKE_LOCK_TIMEOUT,
        mWakeLockTimeout = SystemProperties.getInt(TelephonyProperties.PROPERTY_WAKE_LOCK_TIMEOUT,
                DEFAULT_WAKE_LOCK_TIMEOUT);
                DEFAULT_WAKE_LOCK_TIMEOUT);
        mRequestMessagesPending = 0;
        mRequestMessagesPending = 0;
        mRequestMessagesWaiting = 0;


        mContext = context;
        mContext = context;


@@ -2000,7 +2035,7 @@ public final class RIL extends BaseCommands implements CommandsInterface {
    /**
    /**
     * Holds a PARTIAL_WAKE_LOCK whenever
     * Holds a PARTIAL_WAKE_LOCK whenever
     * a) There is outstanding RIL request sent to RIL deamon and no replied
     * 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
     * There is a WAKE_LOCK_TIMEOUT to release the lock, though it shouldn't
     * happen often.
     * happen often.
@@ -2023,7 +2058,7 @@ public final class RIL extends BaseCommands implements CommandsInterface {
        synchronized (mWakeLock) {
        synchronized (mWakeLock) {
            if (mWakeLock.isHeld() &&
            if (mWakeLock.isHeld() &&
                (mRequestMessagesPending == 0) &&
                (mRequestMessagesPending == 0) &&
                (mRequestsList.size() == 0)) {
                (mRequestMessagesWaiting == 0)) {
                mSender.removeMessages(EVENT_WAKE_LOCK_TIMEOUT);
                mSender.removeMessages(EVENT_WAKE_LOCK_TIMEOUT);
                mWakeLock.release();
                mWakeLock.release();
            }
            }
@@ -2081,6 +2116,7 @@ public final class RIL extends BaseCommands implements CommandsInterface {
                rr.release();
                rr.release();
            }
            }
            mRequestsList.clear();
            mRequestsList.clear();
            mRequestMessagesWaiting = 0;
        }
        }
    }
    }


@@ -2091,6 +2127,8 @@ public final class RIL extends BaseCommands implements CommandsInterface {


                if (rr.mSerial == serial) {
                if (rr.mSerial == serial) {
                    mRequestsList.remove(i);
                    mRequestsList.remove(i);
                    if (mRequestMessagesWaiting > 0)
                        mRequestMessagesWaiting--;
                    return rr;
                    return rr;
                }
                }
            }
            }