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

Commit 44a77728 authored by Lee Chu's avatar Lee Chu Committed by Gerrit Code Review
Browse files

Debug RILJ wakelocks on Smdk4210Ril:

Original author's commit message:
------------------------------------
There is a battery drain due to a wakelock being held for an unspecified
length of time. BetterBatteryStats shows it to be RILJ holding the wakelock.
I've narrowed it down to a RIL request named RIL_REQUEST_SET_TTY_MODE. I
dumped out RILJ.mRequestsList during the held wakelock and I see this request
staying around and waiting for a response from the RIL. It's as if the RIL
is not responding to this request and I don't see RILReceiver processing a
response to this request.

One thing to note is that RIL_REQUEST_SET_TTY_MODE is generated when we see
EVENT_TTY_PREFERRED_MODE_CHANGED from PhoneApp. This happens when the phone
boots up and also when you plug in a pair of headphones. Thus this wakelock
can be reproduced by plugging in a pair of headphones.

To work around this, I've added logic to perform a lazy removal of RILRequests
that haven't received a response in the existing wake lock timeout
(60 seconds.)  The removal itself is done as part of
findAndRemoveRequestFromList().  Since new RIL requests are appended to this
list, we're guaranteed that the stale TTY requests will eventually be removed
either when the existing timeout fires, or through this new lazy removal
------------------------------------
Additional comments from Andrew Dodd:

There seem to be all sorts of things that can cause similar behavior.

Rather than purge requests known to have issues, we just print them
so we can fix root cause.

Change-Id: I0a80ba8fb5a1811ab1d8f78e3b8d1bcbfc627377
parent b5e4f0ac
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@ class RILRequest {
    //***** Instance Variables
    int mSerial;
    int mRequest;
    long creationTime;
    Message mResult;
    Parcel mp;
    RILRequest mNext;
@@ -115,6 +116,7 @@ class RILRequest {
        }
        rr.mRequest = request;
        rr.mResult = result;
        rr.creationTime = System.currentTimeMillis();
        rr.mp = Parcel.obtain();

        if (result != null && result.getTarget() == null) {
+54 −0
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ import java.io.InputStream;
import java.lang.Runtime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;

public class Smdk4210RIL extends RIL implements CommandsInterface {

@@ -310,6 +311,59 @@ public class Smdk4210RIL extends RIL implements CommandsInterface {
        }
    }

    @Override
    protected RILRequest findAndRemoveRequestFromList(int serial) {
        long removalTime = System.currentTimeMillis();
        long timeDiff = 0;

        synchronized (mRequestsList) {
          Iterator<RILRequest> itr = mRequestsList.iterator();

          while ( itr.hasNext() ) {
            RILRequest rr = itr.next();

            if (rr.mSerial == serial) {
                itr.remove();
                if (mRequestMessagesWaiting > 0)
                    mRequestMessagesWaiting--;
                return rr;
            }
            else
            {
              // We need some special code here for the Samsung RIL,
              // which isn't responding to some requests.
              // We will print a list of such stale requests which
              // haven't yet received a response.  If the timeout fires
              // first, then the wakelock is released without debugging.
              timeDiff = removalTime - rr.creationTime;
              if ( timeDiff > mWakeLockTimeout )
              {
                Log.d(LOG_TAG,  "No response for [" + rr.mSerial + "] " +
                        requestToString(rr.mRequest) + " after " + timeDiff + " milliseconds.");

                /* Don't actually remove anything for now.  Consider uncommenting this to
                   purge stale requests */

                /*
                itr.remove();
                if (mRequestMessagesWaiting > 0) {
                    mRequestMessagesWaiting--;
                }

                // We don't handle the callback (ie. rr.mResult) for
                // RIL_REQUEST_SET_TTY_MODE, which is
                // RIL_REQUEST_QUERY_TTY_MODE.  The reason for not doing
                // so is because it will also not get a response from the
                // Samsung RIL
                rr.release();
                */
              }
            }
          }
        }
        return null;
    }

    @Override
    protected void processSolicited (Parcel p) {
    int serial, error;