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

Commit c2e49334 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Revert back wake locks in GsmCdmaConnection" into rvc-dev am: 015d1f7b am: 2fc4f57a

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/opt/telephony/+/11932121

Change-Id: I11d120d1a1d1c32059e96bbeeb928f43378d13bb
parents 591152ec 2fc4f57a
Loading
Loading
Loading
Loading
+89 −2
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@ import android.os.Handler;
import android.os.Looper;
import android.os.Looper;
import android.os.Message;
import android.os.Message;
import android.os.PersistableBundle;
import android.os.PersistableBundle;
import android.os.PowerManager;
import android.os.Registrant;
import android.os.Registrant;
import android.os.SystemClock;
import android.os.SystemClock;
import android.telephony.CarrierConfigManager;
import android.telephony.CarrierConfigManager;
@@ -74,6 +75,8 @@ public class GsmCdmaConnection extends Connection {


    Handler mHandler;
    Handler mHandler;


    private PowerManager.WakeLock mPartialWakeLock;

    // The cached delay to be used between DTMF tones fetched from carrier config.
    // The cached delay to be used between DTMF tones fetched from carrier config.
    private int mDtmfToneDelay = 0;
    private int mDtmfToneDelay = 0;


@@ -83,11 +86,13 @@ public class GsmCdmaConnection extends Connection {
    static final int EVENT_DTMF_DONE = 1;
    static final int EVENT_DTMF_DONE = 1;
    static final int EVENT_PAUSE_DONE = 2;
    static final int EVENT_PAUSE_DONE = 2;
    static final int EVENT_NEXT_POST_DIAL = 3;
    static final int EVENT_NEXT_POST_DIAL = 3;
    static final int EVENT_WAKE_LOCK_TIMEOUT = 4;
    static final int EVENT_DTMF_DELAY_DONE = 5;
    static final int EVENT_DTMF_DELAY_DONE = 5;


    //***** Constants
    //***** Constants
    static final int PAUSE_DELAY_MILLIS_GSM = 3 * 1000;
    static final int PAUSE_DELAY_MILLIS_GSM = 3 * 1000;
    static final int PAUSE_DELAY_MILLIS_CDMA = 2 * 1000;
    static final int PAUSE_DELAY_MILLIS_CDMA = 2 * 1000;
    static final int WAKE_LOCK_TIMEOUT_MILLIS = 60 * 1000;


    //***** Inner Classes
    //***** Inner Classes


@@ -104,6 +109,9 @@ public class GsmCdmaConnection extends Connection {
                case EVENT_PAUSE_DONE:
                case EVENT_PAUSE_DONE:
                    processNextPostDialChar();
                    processNextPostDialChar();
                    break;
                    break;
                case EVENT_WAKE_LOCK_TIMEOUT:
                    releaseWakeLock();
                    break;
                case EVENT_DTMF_DONE:
                case EVENT_DTMF_DONE:
                    // We may need to add a delay specified by carrier between DTMF tones that are
                    // We may need to add a delay specified by carrier between DTMF tones that are
                    // sent out.
                    // sent out.
@@ -119,6 +127,8 @@ public class GsmCdmaConnection extends Connection {
    /** This is probably an MT call that we first saw in a CLCC response or a hand over. */
    /** This is probably an MT call that we first saw in a CLCC response or a hand over. */
    public GsmCdmaConnection (GsmCdmaPhone phone, DriverCall dc, GsmCdmaCallTracker ct, int index) {
    public GsmCdmaConnection (GsmCdmaPhone phone, DriverCall dc, GsmCdmaCallTracker ct, int index) {
        super(phone.getPhoneType());
        super(phone.getPhoneType());
        createWakeLock(phone.getContext());
        acquireWakeLock();


        mOwner = ct;
        mOwner = ct;
        mHandler = new MyHandler(mOwner.getLooper());
        mHandler = new MyHandler(mOwner.getLooper());
@@ -149,6 +159,8 @@ public class GsmCdmaConnection extends Connection {
    public GsmCdmaConnection (GsmCdmaPhone phone, String dialString, GsmCdmaCallTracker ct,
    public GsmCdmaConnection (GsmCdmaPhone phone, String dialString, GsmCdmaCallTracker ct,
                              GsmCdmaCall parent, boolean isEmergencyCall) {
                              GsmCdmaCall parent, boolean isEmergencyCall) {
        super(phone.getPhoneType());
        super(phone.getPhoneType());
        createWakeLock(phone.getContext());
        acquireWakeLock();


        mOwner = ct;
        mOwner = ct;
        mHandler = new MyHandler(mOwner.getLooper());
        mHandler = new MyHandler(mOwner.getLooper());
@@ -203,6 +215,8 @@ public class GsmCdmaConnection extends Connection {
    public GsmCdmaConnection(Context context, CdmaCallWaitingNotification cw, GsmCdmaCallTracker ct,
    public GsmCdmaConnection(Context context, CdmaCallWaitingNotification cw, GsmCdmaCallTracker ct,
                             GsmCdmaCall parent) {
                             GsmCdmaCall parent) {
        super(parent.getPhone().getPhoneType());
        super(parent.getPhone().getPhoneType());
        createWakeLock(context);
        acquireWakeLock();


        mOwner = ct;
        mOwner = ct;
        mHandler = new MyHandler(mOwner.getLooper());
        mHandler = new MyHandler(mOwner.getLooper());
@@ -226,6 +240,7 @@ public class GsmCdmaConnection extends Connection {
        if (mParent != null) {
        if (mParent != null) {
            mParent.detach(this);
            mParent.detach(this);
        }
        }
        releaseAllWakeLocks();
    }
    }


    static boolean equalsHandlesNulls(Object a, Object b) {
    static boolean equalsHandlesNulls(Object a, Object b) {
@@ -618,6 +633,7 @@ public class GsmCdmaConnection extends Connection {
            mOrigConnection = null;
            mOrigConnection = null;
        }
        }
        clearPostDialListeners();
        clearPostDialListeners();
        releaseWakeLock();
        return changed;
        return changed;
    }
    }


@@ -633,6 +649,7 @@ public class GsmCdmaConnection extends Connection {
                mParent.detach(this);
                mParent.detach(this);
            }
            }
        }
        }
        releaseWakeLock();
    }
    }


    // Returns true if state has changed, false if nothing changed
    // Returns true if state has changed, false if nothing changed
@@ -774,7 +791,21 @@ public class GsmCdmaConnection extends Connection {
        if (!mIsIncoming) {
        if (!mIsIncoming) {
            // outgoing calls only
            // outgoing calls only
            processNextPostDialChar();
            processNextPostDialChar();
        } else {
            // Only release wake lock for incoming calls, for outgoing calls the wake lock
            // will be released after any pause-dial is completed
            releaseWakeLock();
        }
    }
    }

    /**
     * We have completed the migration of another connection to this GsmCdmaConnection (for example,
     * in the case of SRVCC) and not still DIALING/ALERTING/INCOMING/WAITING.
     */
    void onConnectedConnectionMigrated() {
        // We can release the wakelock in this case, the migrated call is not still
        // DIALING/ALERTING/INCOMING/WAITING.
        releaseWakeLock();
    }
    }


    private void
    private void
@@ -861,7 +892,17 @@ public class GsmCdmaConnection extends Connection {
    @Override
    @Override
    protected void finalize()
    protected void finalize()
    {
    {
        /**
         * It is understood that This finalizer is not guaranteed
         * to be called and the release lock call is here just in
         * case there is some path that doesn't call onDisconnect
         * and or onConnectedInOrOut.
         */
        if (mPartialWakeLock != null && mPartialWakeLock.isHeld()) {
            Rlog.e(LOG_TAG, "UNEXPECTED; mPartialWakeLock is held when finalizing.");
        }
        clearPostDialListeners();
        clearPostDialListeners();
        releaseWakeLock();
    }
    }


    private void
    private void
@@ -870,6 +911,7 @@ public class GsmCdmaConnection extends Connection {
        Registrant postDialHandler;
        Registrant postDialHandler;


        if (mPostDialState == PostDialState.CANCELLED) {
        if (mPostDialState == PostDialState.CANCELLED) {
            releaseWakeLock();
            return;
            return;
        }
        }


@@ -877,6 +919,9 @@ public class GsmCdmaConnection extends Connection {
                mPostDialString.length() <= mNextPostDialChar) {
                mPostDialString.length() <= mNextPostDialChar) {
            setPostDialState(PostDialState.COMPLETE);
            setPostDialState(PostDialState.COMPLETE);


            // We were holding a wake lock until pause-dial was complete, so give it up now
            releaseWakeLock();

            // notifyMessage.arg1 is 0 on complete
            // notifyMessage.arg1 is 0 on complete
            c = 0;
            c = 0;
        } else {
        } else {
@@ -970,18 +1015,60 @@ public class GsmCdmaConnection extends Connection {
     * @param s new PostDialState
     * @param s new PostDialState
     */
     */
    private void setPostDialState(PostDialState s) {
    private void setPostDialState(PostDialState s) {
        if (s == PostDialState.STARTED
                || s == PostDialState.PAUSE) {
            synchronized (mPartialWakeLock) {
                if (mPartialWakeLock.isHeld()) {
                    mHandler.removeMessages(EVENT_WAKE_LOCK_TIMEOUT);
                } else {
                    acquireWakeLock();
                }
                Message msg = mHandler.obtainMessage(EVENT_WAKE_LOCK_TIMEOUT);
                mHandler.sendMessageDelayed(msg, WAKE_LOCK_TIMEOUT_MILLIS);
            }
        } else {
            mHandler.removeMessages(EVENT_WAKE_LOCK_TIMEOUT);
            releaseWakeLock();
        }
        mPostDialState = s;
        mPostDialState = s;
        notifyPostDialListeners();
        notifyPostDialListeners();
    }
    }


    @UnsupportedAppUsage
    @UnsupportedAppUsage
    private void createWakeLock(Context context) {
    private void createWakeLock(Context context) {
        // no-op
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        mPartialWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, LOG_TAG);
    }
    }


    @UnsupportedAppUsage
    @UnsupportedAppUsage
    private void acquireWakeLock() {
    private void acquireWakeLock() {
        // no-op
        if (mPartialWakeLock != null) {
            synchronized (mPartialWakeLock) {
                log("acquireWakeLock");
                mPartialWakeLock.acquire();
            }
        }
    }

    private void releaseWakeLock() {
        if (mPartialWakeLock != null) {
            synchronized (mPartialWakeLock) {
                if (mPartialWakeLock.isHeld()) {
                    log("releaseWakeLock");
                    mPartialWakeLock.release();
                }
            }
        }
    }

    private void releaseAllWakeLocks() {
        if (mPartialWakeLock != null) {
            synchronized (mPartialWakeLock) {
                while (mPartialWakeLock.isHeld()) {
                    mPartialWakeLock.release();
                }
            }
        }
    }
    }


    @UnsupportedAppUsage
    @UnsupportedAppUsage