aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Bright <dbright@google.com>2020-06-19 10:44:43 -0700
committerDaniel Bright <dbright@google.com>2020-06-19 11:54:52 -0700
commit7668b76c5c8400209f39c5207578593e2fb7414e (patch)
treee0442ff7700b6a257c889c5a8f9da0bc361817cc
parentf5b6d4bd7621d30b94fad2ca29090b784a4d174f (diff)
downloadtelephony-7668b76c5c8400209f39c5207578593e2fb7414e.tar.gz
Revert back wake locks in GsmCdmaConnection
Bug: 159462297 Test: atest FrameworksTelephonyTests Test: Made phone call using Gsm/Cmda Change-Id: Ia6906ea946ef6e0f5f5ab44428da0ac31d642c8b
-rw-r--r--src/java/com/android/internal/telephony/GsmCdmaConnection.java91
1 files changed, 89 insertions, 2 deletions
diff --git a/src/java/com/android/internal/telephony/GsmCdmaConnection.java b/src/java/com/android/internal/telephony/GsmCdmaConnection.java
index b627578b9e..282d974127 100644
--- a/src/java/com/android/internal/telephony/GsmCdmaConnection.java
+++ b/src/java/com/android/internal/telephony/GsmCdmaConnection.java
@@ -22,6 +22,7 @@ import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.PersistableBundle;
+import android.os.PowerManager;
import android.os.Registrant;
import android.os.SystemClock;
import android.telephony.CarrierConfigManager;
@@ -74,6 +75,8 @@ public class GsmCdmaConnection extends Connection {
Handler mHandler;
+ private PowerManager.WakeLock mPartialWakeLock;
+
// The cached delay to be used between DTMF tones fetched from carrier config.
private int mDtmfToneDelay = 0;
@@ -83,11 +86,13 @@ public class GsmCdmaConnection extends Connection {
static final int EVENT_DTMF_DONE = 1;
static final int EVENT_PAUSE_DONE = 2;
static final int EVENT_NEXT_POST_DIAL = 3;
+ static final int EVENT_WAKE_LOCK_TIMEOUT = 4;
static final int EVENT_DTMF_DELAY_DONE = 5;
//***** Constants
static final int PAUSE_DELAY_MILLIS_GSM = 3 * 1000;
static final int PAUSE_DELAY_MILLIS_CDMA = 2 * 1000;
+ static final int WAKE_LOCK_TIMEOUT_MILLIS = 60 * 1000;
//***** Inner Classes
@@ -104,6 +109,9 @@ public class GsmCdmaConnection extends Connection {
case EVENT_PAUSE_DONE:
processNextPostDialChar();
break;
+ case EVENT_WAKE_LOCK_TIMEOUT:
+ releaseWakeLock();
+ break;
case EVENT_DTMF_DONE:
// We may need to add a delay specified by carrier between DTMF tones that are
// 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. */
public GsmCdmaConnection (GsmCdmaPhone phone, DriverCall dc, GsmCdmaCallTracker ct, int index) {
super(phone.getPhoneType());
+ createWakeLock(phone.getContext());
+ acquireWakeLock();
mOwner = ct;
mHandler = new MyHandler(mOwner.getLooper());
@@ -149,6 +159,8 @@ public class GsmCdmaConnection extends Connection {
public GsmCdmaConnection (GsmCdmaPhone phone, String dialString, GsmCdmaCallTracker ct,
GsmCdmaCall parent, boolean isEmergencyCall) {
super(phone.getPhoneType());
+ createWakeLock(phone.getContext());
+ acquireWakeLock();
mOwner = ct;
mHandler = new MyHandler(mOwner.getLooper());
@@ -203,6 +215,8 @@ public class GsmCdmaConnection extends Connection {
public GsmCdmaConnection(Context context, CdmaCallWaitingNotification cw, GsmCdmaCallTracker ct,
GsmCdmaCall parent) {
super(parent.getPhone().getPhoneType());
+ createWakeLock(context);
+ acquireWakeLock();
mOwner = ct;
mHandler = new MyHandler(mOwner.getLooper());
@@ -226,6 +240,7 @@ public class GsmCdmaConnection extends Connection {
if (mParent != null) {
mParent.detach(this);
}
+ releaseAllWakeLocks();
}
static boolean equalsHandlesNulls(Object a, Object b) {
@@ -618,6 +633,7 @@ public class GsmCdmaConnection extends Connection {
mOrigConnection = null;
}
clearPostDialListeners();
+ releaseWakeLock();
return changed;
}
@@ -633,6 +649,7 @@ public class GsmCdmaConnection extends Connection {
mParent.detach(this);
}
}
+ releaseWakeLock();
}
// Returns true if state has changed, false if nothing changed
@@ -774,9 +791,23 @@ public class GsmCdmaConnection extends Connection {
if (!mIsIncoming) {
// outgoing calls only
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
doDisconnect() {
mIndex = -1;
@@ -861,7 +892,17 @@ public class GsmCdmaConnection extends Connection {
@Override
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();
+ releaseWakeLock();
}
private void
@@ -870,6 +911,7 @@ public class GsmCdmaConnection extends Connection {
Registrant postDialHandler;
if (mPostDialState == PostDialState.CANCELLED) {
+ releaseWakeLock();
return;
}
@@ -877,6 +919,9 @@ public class GsmCdmaConnection extends Connection {
mPostDialString.length() <= mNextPostDialChar) {
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
c = 0;
} else {
@@ -970,18 +1015,60 @@ public class GsmCdmaConnection extends Connection {
* @param s new PostDialState
*/
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;
notifyPostDialListeners();
}
@UnsupportedAppUsage
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
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