summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-05-11 18:15:51 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-05-11 18:15:51 +0000
commite0a644973b7ef0fd0c70cb979ea919c68a0ac3aa (patch)
treec8af848f10661264ec2eaf4b5495796af5ea1440
parent039d94beda9443b448128481bd3d7359d541020f (diff)
parente58d32f79d60a913db172b7ec0cc4a0659328c5c (diff)
downloadTelephony-e0a644973b7ef0fd0c70cb979ea919c68a0ac3aa.tar.gz
Snap for 10078606 from e58d32f79d60a913db172b7ec0cc4a0659328c5c to aml-frc-releasefrc_340821000frc_340819280frc_340819220frc_340819190frc_340819030frc_340819020frc_340819010frc_340818170frc_340818110
Change-Id: I0855f81c397fce6ef58d07ea8e5608b45cc206c7
-rw-r--r--services/QualifiedNetworksService/src/com/android/telephony/qns/AccessNetworkEvaluator.java2
-rw-r--r--services/QualifiedNetworksService/src/com/android/telephony/qns/QnsCallStatusTracker.java35
-rw-r--r--services/QualifiedNetworksService/src/com/android/telephony/qns/QnsTimer.java69
-rw-r--r--services/QualifiedNetworksService/tests/src/com/android/telephony/qns/AccessNetworkEvaluatorTest.java10
-rw-r--r--services/QualifiedNetworksService/tests/src/com/android/telephony/qns/QnsCallStatusTrackerTest.java53
-rw-r--r--services/QualifiedNetworksService/tests/src/com/android/telephony/qns/QnsTimerTest.java34
6 files changed, 167 insertions, 36 deletions
diff --git a/services/QualifiedNetworksService/src/com/android/telephony/qns/AccessNetworkEvaluator.java b/services/QualifiedNetworksService/src/com/android/telephony/qns/AccessNetworkEvaluator.java
index 098820a..f77da91 100644
--- a/services/QualifiedNetworksService/src/com/android/telephony/qns/AccessNetworkEvaluator.java
+++ b/services/QualifiedNetworksService/src/com/android/telephony/qns/AccessNetworkEvaluator.java
@@ -1426,7 +1426,7 @@ class AccessNetworkEvaluator {
return true;
} else {
if (mNetCapability == NetworkCapabilities.NET_CAPABILITY_IMS
- && mCallType == QnsConstants.CALL_TYPE_IDLE) {
+ && mCallStatusTracker.isCallIdle(NetworkCapabilities.NET_CAPABILITY_IMS)) {
// Telephony will make new connection with preferred AccessNetwork
log("handover is not allowed. but need to move to target Transport.");
return true;
diff --git a/services/QualifiedNetworksService/src/com/android/telephony/qns/QnsCallStatusTracker.java b/services/QualifiedNetworksService/src/com/android/telephony/qns/QnsCallStatusTracker.java
index f8b335a..cc1f194 100644
--- a/services/QualifiedNetworksService/src/com/android/telephony/qns/QnsCallStatusTracker.java
+++ b/services/QualifiedNetworksService/src/com/android/telephony/qns/QnsCallStatusTracker.java
@@ -817,14 +817,18 @@ public class QnsCallStatusTracker {
}
}
//2. Notify a new ongoing call type
- if (hasEmergencyCall() && mLastEmergencyCallType != QnsConstants.CALL_TYPE_EMERGENCY) {
- mLastEmergencyCallType = QnsConstants.CALL_TYPE_EMERGENCY;
- if (!isDataNetworkConnected(NetworkCapabilities.NET_CAPABILITY_EIMS)
- && isDataNetworkConnected(NetworkCapabilities.NET_CAPABILITY_IMS)) {
- notifyCallType(NetworkCapabilities.NET_CAPABILITY_IMS, mLastEmergencyCallType);
- mEmergencyOverIms = true;
- } else {
- notifyCallType(NetworkCapabilities.NET_CAPABILITY_EIMS, mLastEmergencyCallType);
+ if (hasEmergencyCall()) {
+ if (mLastEmergencyCallType != QnsConstants.CALL_TYPE_EMERGENCY) {
+ mLastEmergencyCallType = QnsConstants.CALL_TYPE_EMERGENCY;
+ if (!isDataNetworkConnected(NetworkCapabilities.NET_CAPABILITY_EIMS)
+ && isDataNetworkConnected(NetworkCapabilities.NET_CAPABILITY_IMS)) {
+ notifyCallType(NetworkCapabilities.NET_CAPABILITY_IMS,
+ mLastEmergencyCallType);
+ mEmergencyOverIms = true;
+ } else {
+ notifyCallType(NetworkCapabilities.NET_CAPABILITY_EIMS,
+ mLastEmergencyCallType);
+ }
}
} else if (hasVideoCall()) {
if (mLastNormalCallType != QnsConstants.CALL_TYPE_VIDEO) {
@@ -865,6 +869,21 @@ public class QnsCallStatusTracker {
return mCallStates.size() == 0;
}
+ boolean isCallIdle(int netCapability) {
+ int callNum = mCallStates.size();
+ if (callNum == 0) {
+ return true;
+ }
+ if (netCapability == NetworkCapabilities.NET_CAPABILITY_IMS) {
+ return (mLastNormalCallType == QnsConstants.CALL_TYPE_IDLE)
+ && (mLastEmergencyCallType != QnsConstants.CALL_TYPE_IDLE
+ && !mEmergencyOverIms);
+ } else if (netCapability == NetworkCapabilities.NET_CAPABILITY_EIMS) {
+ return mLastEmergencyCallType == QnsConstants.CALL_TYPE_IDLE || mEmergencyOverIms;
+ }
+ return false;
+ }
+
boolean hasEmergencyCall() {
for (CallState cs : mCallStates) {
if (cs.getImsCallServiceType() == ImsCallProfile.SERVICE_TYPE_EMERGENCY
diff --git a/services/QualifiedNetworksService/src/com/android/telephony/qns/QnsTimer.java b/services/QualifiedNetworksService/src/com/android/telephony/qns/QnsTimer.java
index f2439bd..7630054 100644
--- a/services/QualifiedNetworksService/src/com/android/telephony/qns/QnsTimer.java
+++ b/services/QualifiedNetworksService/src/com/android/telephony/qns/QnsTimer.java
@@ -45,6 +45,11 @@ class QnsTimer {
private static final String TAG = QnsTimer.class.getSimpleName();
private static final int EVENT_QNS_TIMER_EXPIRED = 1;
+
+ private static final int MIN_ALARM_CALL_ACTIVE_DELAY_MS = 0;
+ private static final int MIN_ALARM_SCREEN_OFF_DELAY_MS = 10000;
+ private static final int MIN_ALARM_DEVICE_LIGHT_IDLE_DELAY_MS = 30000;
+ private static final int MIN_ALARM_DEVICE_IDLE_DELAY_MS = 60000;
static final String ACTION_ALARM_TIMER_EXPIRED =
"com.android.telephony.qns.action.ALARM_TIMER_EXPIRED";
@@ -56,11 +61,11 @@ class QnsTimer {
private final BroadcastReceiver mBroadcastReceiver;
private final PriorityQueue<TimerInfo> mTimerInfos;
private PendingIntent mPendingIntent;
- private long mMinAlarmTimeMs = 10000;
+ private long mMinAlarmTimeMs = MIN_ALARM_SCREEN_OFF_DELAY_MS;
private int mCurrentAlarmTimerId = INVALID_ID;
private int mCurrentHandlerTimerId = INVALID_ID;
private boolean mIsAlarmRequired;
- @VisibleForTesting final Handler mHandler;
+ @VisibleForTesting Handler mHandler;
private long mLastAlarmTriggerAtMs = Long.MAX_VALUE;
private int mCallType = CALL_TYPE_IDLE;
@@ -100,7 +105,7 @@ class QnsTimer {
mHandler.post(
() -> {
mTimerInfos.add(timerInfo);
- updateToShortestDelay(mIsAlarmRequired, true);
+ updateToShortestDelay(mIsAlarmRequired, false /* forceUpdate */);
});
return timerId;
}
@@ -120,7 +125,7 @@ class QnsTimer {
logd("Cancel timerId=" + timerId);
TimerInfo timerInfo = new TimerInfo(timerId);
if (mTimerInfos.remove(timerInfo) && timerId == mCurrentAlarmTimerId) {
- updateToShortestDelay(mIsAlarmRequired, true);
+ updateToShortestDelay(mIsAlarmRequired, false /* forceUpdate */);
}
});
}
@@ -136,20 +141,20 @@ class QnsTimer {
if (mCallType == CALL_TYPE_IDLE && type != CALL_TYPE_IDLE) {
mHandler.post(
() -> {
- mMinAlarmTimeMs = 0;
+ mMinAlarmTimeMs = MIN_ALARM_CALL_ACTIVE_DELAY_MS;
if (mIsAlarmRequired) {
- updateToShortestDelay(true, false);
+ updateToShortestDelay(true, true /* forceUpdate */);
}
});
}
mCallType = type;
if (mCallType == CALL_TYPE_IDLE && mIsAlarmRequired) {
if (mPowerManager.isDeviceIdleMode()) {
- mMinAlarmTimeMs = 60000;
+ mMinAlarmTimeMs = MIN_ALARM_DEVICE_IDLE_DELAY_MS;
} else if (mPowerManager.isDeviceLightIdleMode()) {
- mMinAlarmTimeMs = 30000;
+ mMinAlarmTimeMs = MIN_ALARM_DEVICE_LIGHT_IDLE_DELAY_MS;
} else {
- mMinAlarmTimeMs = 10000; // SCREEN_OFF case
+ mMinAlarmTimeMs = MIN_ALARM_SCREEN_OFF_DELAY_MS; // SCREEN_OFF case
}
}
}
@@ -161,11 +166,10 @@ class QnsTimer {
* respective handlers.
*
* @param isAlarmRequired flag indicates if timer is need to setup with Alarm.
- * @param skipTimerUpdate flag indicates if current scheduled alarm timers needs any change.
- * This flag will be false when call type changes or device moves or come out of idle state
- * because such cases mandates timer update.
+ * @param forceUpdate flag indicates to update the delay time for handler and/or alarm
+ * forcefully.
*/
- private void updateToShortestDelay(boolean isAlarmRequired, boolean skipTimerUpdate) {
+ private void updateToShortestDelay(boolean isAlarmRequired, boolean forceUpdate) {
TimerInfo timerInfo = mTimerInfos.peek();
long elapsedTime = getSystemElapsedRealTime();
while (timerInfo != null && timerInfo.getExpireAtElapsedMillis() <= elapsedTime) {
@@ -181,14 +185,14 @@ class QnsTimer {
}
long delay = timerInfo.getExpireAtElapsedMillis() - elapsedTime;
// Delayed Handler will always set for shortest delay.
- if (timerInfo.getTimerId() != mCurrentHandlerTimerId) {
+ if (timerInfo.getTimerId() != mCurrentHandlerTimerId || forceUpdate) {
mHandler.removeMessages(EVENT_QNS_TIMER_EXPIRED);
mHandler.sendEmptyMessageDelayed(EVENT_QNS_TIMER_EXPIRED, delay);
mCurrentHandlerTimerId = timerInfo.getTimerId();
}
// Alarm will always set for shortest from Math.max(delay, mMinAlarmTimeMs)
- if (timerInfo.getTimerId() != mCurrentAlarmTimerId || !skipTimerUpdate) {
+ if (timerInfo.getTimerId() != mCurrentAlarmTimerId || forceUpdate) {
if (isAlarmRequired) {
delay = Math.max(delay, mMinAlarmTimeMs);
// check if smaller timer alarm is already running for active timer info.
@@ -245,10 +249,13 @@ class QnsTimer {
case Intent.ACTION_SCREEN_OFF:
mHandler.post(
() -> {
- mMinAlarmTimeMs = (mCallType == CALL_TYPE_IDLE) ? 10000 : 0;
+ mMinAlarmTimeMs =
+ (mCallType == CALL_TYPE_IDLE)
+ ? MIN_ALARM_SCREEN_OFF_DELAY_MS
+ : MIN_ALARM_CALL_ACTIVE_DELAY_MS;
if (!mIsAlarmRequired) {
mIsAlarmRequired = true;
- updateToShortestDelay(true, false);
+ updateToShortestDelay(true, true /* forceUpdate */);
}
});
break;
@@ -257,7 +264,7 @@ class QnsTimer {
() -> {
if (mIsAlarmRequired) {
mIsAlarmRequired = false;
- updateToShortestDelay(false, false);
+ updateToShortestDelay(false, true /* forceUpdate */);
}
});
break;
@@ -265,13 +272,19 @@ class QnsTimer {
mHandler.post(
() -> {
if (mPowerManager.isDeviceLightIdleMode()) {
- mMinAlarmTimeMs = (mCallType == CALL_TYPE_IDLE) ? 30000 : 0;
+ mMinAlarmTimeMs =
+ (mCallType == CALL_TYPE_IDLE)
+ ? MIN_ALARM_DEVICE_LIGHT_IDLE_DELAY_MS
+ : MIN_ALARM_CALL_ACTIVE_DELAY_MS;
if (!mIsAlarmRequired) {
mIsAlarmRequired = true;
- updateToShortestDelay(true, false);
+ updateToShortestDelay(true, true /* forceUpdate */);
}
} else {
- mMinAlarmTimeMs = (mCallType == CALL_TYPE_IDLE) ? 10000 : 0;
+ mMinAlarmTimeMs =
+ (mCallType == CALL_TYPE_IDLE)
+ ? MIN_ALARM_SCREEN_OFF_DELAY_MS
+ : MIN_ALARM_CALL_ACTIVE_DELAY_MS;
}
});
break;
@@ -279,13 +292,19 @@ class QnsTimer {
mHandler.post(
() -> {
if (mPowerManager.isDeviceIdleMode()) {
- mMinAlarmTimeMs = (mCallType == CALL_TYPE_IDLE) ? 60000 : 0;
+ mMinAlarmTimeMs =
+ (mCallType == CALL_TYPE_IDLE)
+ ? MIN_ALARM_DEVICE_IDLE_DELAY_MS
+ : MIN_ALARM_CALL_ACTIVE_DELAY_MS;
if (!mIsAlarmRequired) {
mIsAlarmRequired = true;
- updateToShortestDelay(true, false);
+ updateToShortestDelay(true, true /* forceUpdate */);
}
} else {
- mMinAlarmTimeMs = (mCallType == CALL_TYPE_IDLE) ? 10000 : 0;
+ mMinAlarmTimeMs =
+ (mCallType == CALL_TYPE_IDLE)
+ ? MIN_ALARM_SCREEN_OFF_DELAY_MS
+ : MIN_ALARM_CALL_ACTIVE_DELAY_MS;
}
});
break;
@@ -307,7 +326,7 @@ class QnsTimer {
switch (msg.what) {
case EVENT_QNS_TIMER_EXPIRED:
logd("Timer expired");
- updateToShortestDelay(mIsAlarmRequired, true);
+ updateToShortestDelay(mIsAlarmRequired, false /* forceUpdate */);
break;
default:
break;
diff --git a/services/QualifiedNetworksService/tests/src/com/android/telephony/qns/AccessNetworkEvaluatorTest.java b/services/QualifiedNetworksService/tests/src/com/android/telephony/qns/AccessNetworkEvaluatorTest.java
index 7530767..9c59fd7 100644
--- a/services/QualifiedNetworksService/tests/src/com/android/telephony/qns/AccessNetworkEvaluatorTest.java
+++ b/services/QualifiedNetworksService/tests/src/com/android/telephony/qns/AccessNetworkEvaluatorTest.java
@@ -289,6 +289,8 @@ public class AccessNetworkEvaluatorTest extends QnsTest {
when(mDataConnectionStatusTracker.isActiveState()).thenReturn(true);
when(mDataConnectionStatusTracker.getLastTransportType())
.thenReturn(AccessNetworkConstants.TRANSPORT_TYPE_WLAN);
+ when(mMockQnsCallStatusTracker.isCallIdle(NetworkCapabilities.NET_CAPABILITY_IMS))
+ .thenReturn(true);
List<Integer> accessNetworks = new ArrayList<>();
accessNetworks.add(AccessNetworkConstants.AccessNetworkType.IWLAN);
QnsTelephonyListener.QnsTelephonyInfo info =
@@ -349,6 +351,8 @@ public class AccessNetworkEvaluatorTest extends QnsTest {
when(mDataConnectionStatusTracker.isActiveState()).thenReturn(true);
when(mDataConnectionStatusTracker.getLastTransportType())
.thenReturn(AccessNetworkConstants.TRANSPORT_TYPE_WLAN);
+ when(mMockQnsCallStatusTracker.isCallIdle(NetworkCapabilities.NET_CAPABILITY_IMS))
+ .thenReturn(true);
List<Integer> accessNetworks = new ArrayList<>();
accessNetworks.add(AccessNetworkConstants.AccessNetworkType.IWLAN);
QnsTelephonyListener.QnsTelephonyInfo info =
@@ -382,14 +386,20 @@ public class AccessNetworkEvaluatorTest extends QnsTest {
mAne.onQnsTelephonyInfoChanged(infoIms);
mAne.updateLastNotifiedQualifiedNetwork(accessNetworks);
mAne.onSetCallType(QnsConstants.CALL_TYPE_VOICE);
+ when(mMockQnsCallStatusTracker.isCallIdle(NetworkCapabilities.NET_CAPABILITY_IMS))
+ .thenReturn(false);
assertTrue(mAne.needHandoverPolicyCheck());
assertFalse(mAne.moveTransportTypeAllowed());
mAne.updateLastNotifiedQualifiedNetwork(accessNetworks);
mAne.onSetCallType(QnsConstants.CALL_TYPE_IDLE);
+ when(mMockQnsCallStatusTracker.isCallIdle(NetworkCapabilities.NET_CAPABILITY_IMS))
+ .thenReturn(true);
assertTrue(mAne.needHandoverPolicyCheck());
assertTrue(mAne.moveTransportTypeAllowed());
mAne.updateLastNotifiedQualifiedNetwork(accessNetworks);
mAne.onSetCallType(QnsConstants.CALL_TYPE_EMERGENCY);
+ when(mMockQnsCallStatusTracker.isCallIdle(NetworkCapabilities.NET_CAPABILITY_IMS))
+ .thenReturn(false);
assertTrue(mAne.needHandoverPolicyCheck());
assertFalse(mAne.moveTransportTypeAllowed());
}
diff --git a/services/QualifiedNetworksService/tests/src/com/android/telephony/qns/QnsCallStatusTrackerTest.java b/services/QualifiedNetworksService/tests/src/com/android/telephony/qns/QnsCallStatusTrackerTest.java
index 5d7f405..a9247f0 100644
--- a/services/QualifiedNetworksService/tests/src/com/android/telephony/qns/QnsCallStatusTrackerTest.java
+++ b/services/QualifiedNetworksService/tests/src/com/android/telephony/qns/QnsCallStatusTrackerTest.java
@@ -157,6 +157,8 @@ public class QnsCallStatusTrackerTest extends QnsTest {
assertNotNull(result.mResult);
assertEquals(QnsConstants.CALL_TYPE_VOICE, (int) result.mResult);
assertFalse(mCallTracker.isCallIdle());
+ assertTrue(mCallTracker.isCallIdle(NetworkCapabilities.NET_CAPABILITY_EIMS));
+ assertFalse(mCallTracker.isCallIdle(NetworkCapabilities.NET_CAPABILITY_IMS));
// Test2:
mTestCallStateList.clear();
@@ -176,7 +178,9 @@ public class QnsCallStatusTrackerTest extends QnsTest {
result = (QnsAsyncResult) msg.obj;
assertNotNull(result.mResult);
assertEquals(QnsConstants.CALL_TYPE_IDLE, (int) result.mResult);
- assertTrue(mCallTracker.isCallIdle()); // for IMS calls only
+ assertTrue(mCallTracker.isCallIdle());
+ assertTrue(mCallTracker.isCallIdle(NetworkCapabilities.NET_CAPABILITY_EIMS));
+ assertTrue(mCallTracker.isCallIdle(NetworkCapabilities.NET_CAPABILITY_IMS));
}
@Test
@@ -193,6 +197,9 @@ public class QnsCallStatusTrackerTest extends QnsTest {
assertNotNull(result.mResult);
assertEquals(QnsConstants.CALL_TYPE_VOICE, (int) result.mResult);
assertFalse(mCallTracker.isCallIdle());
+ assertTrue(mCallTracker.isCallIdle(NetworkCapabilities.NET_CAPABILITY_EIMS));
+ assertFalse(mCallTracker.isCallIdle(NetworkCapabilities.NET_CAPABILITY_IMS));
+ assertFalse(mCallTracker.isCallIdle(NetworkCapabilities.NET_CAPABILITY_MMS));
mTestCallStateList.clear();
mTestCallStateList.add(new CallState.Builder(PreciseCallState.PRECISE_CALL_STATE_ACTIVE)
@@ -208,7 +215,8 @@ public class QnsCallStatusTrackerTest extends QnsTest {
new CallState.Builder(PreciseCallState.PRECISE_CALL_STATE_DISCONNECTING)
.setImsCallType(ImsCallProfile.CALL_TYPE_VOICE)
.setImsCallServiceType(ImsCallProfile.SERVICE_TYPE_NORMAL).build());
- mTestCallStateList.add(new CallState.Builder(PreciseCallState.PRECISE_CALL_STATE_ACTIVE)
+ mTestCallStateList.add(
+ new CallState.Builder(PreciseCallState.PRECISE_CALL_STATE_ACTIVE)
.setImsCallType(ImsCallProfile.CALL_TYPE_VOICE)
.setImsCallServiceType(ImsCallProfile.SERVICE_TYPE_EMERGENCY).build());
mCallTracker.updateCallState(mTestCallStateList);
@@ -219,6 +227,8 @@ public class QnsCallStatusTrackerTest extends QnsTest {
assertNotNull(result.mResult);
assertEquals(QnsConstants.CALL_TYPE_EMERGENCY, (int) result.mResult);
assertFalse(mCallTracker.isCallIdle());
+ assertFalse(mCallTracker.isCallIdle(NetworkCapabilities.NET_CAPABILITY_EIMS));
+ assertFalse(mCallTracker.isCallIdle(NetworkCapabilities.NET_CAPABILITY_IMS));
mTestCallStateList.clear();
mTestCallStateList.add(new CallState.Builder(PreciseCallState.PRECISE_CALL_STATE_ACTIVE)
@@ -232,6 +242,8 @@ public class QnsCallStatusTrackerTest extends QnsTest {
assertNotNull(result.mResult);
assertEquals(QnsConstants.CALL_TYPE_IDLE, (int) result.mResult);
assertFalse(mCallTracker.isCallIdle());
+ assertFalse(mCallTracker.isCallIdle(NetworkCapabilities.NET_CAPABILITY_EIMS));
+ assertTrue(mCallTracker.isCallIdle(NetworkCapabilities.NET_CAPABILITY_IMS));
mTestCallStateList.clear();
mTestCallStateList.add(new CallState.Builder(PreciseCallState.PRECISE_CALL_STATE_ALERTING)
@@ -251,6 +263,8 @@ public class QnsCallStatusTrackerTest extends QnsTest {
assertNotNull(result.mResult);
assertEquals(QnsConstants.CALL_TYPE_VOICE, (int) result.mResult);
assertFalse(mCallTracker.isCallIdle());
+ assertTrue(mCallTracker.isCallIdle(NetworkCapabilities.NET_CAPABILITY_EIMS));
+ assertFalse(mCallTracker.isCallIdle(NetworkCapabilities.NET_CAPABILITY_IMS));
}
@Test
@@ -268,6 +282,8 @@ public class QnsCallStatusTrackerTest extends QnsTest {
assertNotNull(result.mResult);
assertEquals(QnsConstants.CALL_TYPE_VOICE, (int) result.mResult);
assertFalse(mCallTracker.isCallIdle()); // for IMS calls only
+ assertTrue(mCallTracker.isCallIdle(NetworkCapabilities.NET_CAPABILITY_EIMS));
+ assertFalse(mCallTracker.isCallIdle(NetworkCapabilities.NET_CAPABILITY_IMS));
mTestCallStateList.clear();
mTestCallStateList.add(new CallState.Builder(PreciseCallState.PRECISE_CALL_STATE_ACTIVE)
@@ -283,6 +299,8 @@ public class QnsCallStatusTrackerTest extends QnsTest {
assertNotNull(result.mResult);
assertEquals(QnsConstants.CALL_TYPE_VIDEO, (int) result.mResult);
assertFalse(mCallTracker.isCallIdle()); // for IMS calls only
+ assertTrue(mCallTracker.isCallIdle(NetworkCapabilities.NET_CAPABILITY_EIMS));
+ assertFalse(mCallTracker.isCallIdle(NetworkCapabilities.NET_CAPABILITY_IMS));
mTestCallStateList.clear();
mTestCallStateList.add(new CallState.Builder(PreciseCallState.PRECISE_CALL_STATE_ACTIVE)
@@ -295,6 +313,8 @@ public class QnsCallStatusTrackerTest extends QnsTest {
msg = mTestLooperListener.nextMessage();
assertNull(msg);
assertFalse(mCallTracker.isCallIdle()); // for IMS calls only
+ assertTrue(mCallTracker.isCallIdle(NetworkCapabilities.NET_CAPABILITY_EIMS));
+ assertFalse(mCallTracker.isCallIdle(NetworkCapabilities.NET_CAPABILITY_IMS));
mTestCallStateList.clear();
mTestCallStateList.add(new CallState.Builder(PreciseCallState.PRECISE_CALL_STATE_HOLDING)
@@ -308,6 +328,8 @@ public class QnsCallStatusTrackerTest extends QnsTest {
assertNotNull(result.mResult);
assertEquals(QnsConstants.CALL_TYPE_VOICE, (int) result.mResult);
assertFalse(mCallTracker.isCallIdle());
+ assertTrue(mCallTracker.isCallIdle(NetworkCapabilities.NET_CAPABILITY_EIMS));
+ assertFalse(mCallTracker.isCallIdle(NetworkCapabilities.NET_CAPABILITY_IMS));
mTestCallStateList.clear();
mTestCallStateList.add(new CallState.Builder(PreciseCallState.PRECISE_CALL_STATE_ACTIVE)
@@ -346,12 +368,16 @@ public class QnsCallStatusTrackerTest extends QnsTest {
assertNotNull(result.mResult);
assertEquals(QnsConstants.CALL_TYPE_IDLE, (int) result.mResult);
assertFalse(mCallTracker.isCallIdle());
+ assertTrue(mCallTracker.isCallIdle(NetworkCapabilities.NET_CAPABILITY_EIMS));
+ assertFalse(mCallTracker.isCallIdle(NetworkCapabilities.NET_CAPABILITY_IMS));
mTestCallStateList.clear();
mCallTracker.updateCallState(mTestCallStateList);
msg = mTestLooperListener.nextMessage();
assertNull(msg);
assertTrue(mCallTracker.isCallIdle());
+ assertTrue(mCallTracker.isCallIdle(NetworkCapabilities.NET_CAPABILITY_EIMS));
+ assertTrue(mCallTracker.isCallIdle(NetworkCapabilities.NET_CAPABILITY_IMS));
}
@Test
@@ -433,6 +459,8 @@ public class QnsCallStatusTrackerTest extends QnsTest {
QnsAsyncResult result = (QnsAsyncResult) msg.obj;
assertNotNull(result.mResult);
assertEquals(QnsConstants.CALL_TYPE_EMERGENCY, (int) result.mResult);
+ assertFalse(mCallTracker.isCallIdle(NetworkCapabilities.NET_CAPABILITY_IMS));
+ assertTrue(mCallTracker.isCallIdle(NetworkCapabilities.NET_CAPABILITY_EIMS));
// Test2:
mTestCallStateList.clear();
@@ -444,6 +472,27 @@ public class QnsCallStatusTrackerTest extends QnsTest {
// Should not notify if call type is not changed
assertNull(msg);
+ mTestCallStateList.clear();
+ mTestCallStateList.add(new CallState.Builder(PreciseCallState.PRECISE_CALL_STATE_ACTIVE)
+ .setImsCallType(ImsCallProfile.CALL_TYPE_VOICE)
+ .setImsCallServiceType(ImsCallProfile.SERVICE_TYPE_EMERGENCY).build());
+ mTestCallStateList.add(new CallState.Builder(PreciseCallState.PRECISE_CALL_STATE_WAITING)
+ .setImsCallType(ImsCallProfile.CALL_TYPE_VOICE)
+ .setImsCallServiceType(ImsCallProfile.SERVICE_TYPE_NORMAL).build());
+ mCallTracker.updateCallState(mTestCallStateList);
+ msg = mTestLooperListener.nextMessage();
+ // Should not notify if call type is not changed
+ assertNull(msg);
+
+ mTestCallStateList.clear();
+ mTestCallStateList.add(new CallState.Builder(PreciseCallState.PRECISE_CALL_STATE_ACTIVE)
+ .setImsCallType(ImsCallProfile.CALL_TYPE_VOICE)
+ .setImsCallServiceType(ImsCallProfile.SERVICE_TYPE_EMERGENCY).build());
+ mCallTracker.updateCallState(mTestCallStateList);
+ msg = mTestLooperListener.nextMessage();
+ // Should not notify if call type is not changed
+ assertNull(msg);
+
// Test3:
imsDataStatus =
new PreciseDataConnectionState.Builder()
diff --git a/services/QualifiedNetworksService/tests/src/com/android/telephony/qns/QnsTimerTest.java b/services/QualifiedNetworksService/tests/src/com/android/telephony/qns/QnsTimerTest.java
index c4acd5a..50a36b5 100644
--- a/services/QualifiedNetworksService/tests/src/com/android/telephony/qns/QnsTimerTest.java
+++ b/services/QualifiedNetworksService/tests/src/com/android/telephony/qns/QnsTimerTest.java
@@ -35,6 +35,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Handler;
+import android.os.HandlerThread;
import android.os.Message;
import android.os.PowerManager;
import android.os.SystemClock;
@@ -51,6 +52,8 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import java.util.concurrent.CountDownLatch;
+
@RunWith(AndroidJUnit4.class)
public class QnsTimerTest extends QnsTest {
@@ -306,4 +309,35 @@ public class QnsTimerTest extends QnsTest {
// assume 100ms as max delay in execution
assertTrue(delay < setDelay && delay > setDelay - 100);
}
+
+ @Test
+ public void testDeviceMovesToActiveState() {
+ int setDelay = 30000;
+ CountDownLatch latch = new CountDownLatch(2);
+ HandlerThread ht = new HandlerThread("");
+ ht.start();
+ Handler tempHandler = spy(new Handler(ht.getLooper()));
+ when(mPowerManager.isDeviceLightIdleMode()).thenReturn(true, false);
+ mBroadcastReceiver.onReceive(sMockContext, new Intent(Intent.ACTION_SCREEN_OFF));
+ mBroadcastReceiver.onReceive(
+ sMockContext, new Intent(PowerManager.ACTION_DEVICE_LIGHT_IDLE_MODE_CHANGED));
+ mQnsTimer.registerTimer(mMessage, setDelay);
+ waitForDelayedHandlerAction(mQnsTimer.mHandler, 10, 200);
+ verify(mAlarmManager)
+ .setExactAndAllowWhileIdle(anyInt(), anyLong(), isA(PendingIntent.class));
+ waitForDelayedHandlerAction(mQnsTimer.mHandler, 10, 5000);
+
+ mQnsTimer.mHandler = tempHandler;
+ mBroadcastReceiver.onReceive(
+ sMockContext, new Intent(PowerManager.ACTION_DEVICE_LIGHT_IDLE_MODE_CHANGED));
+ mBroadcastReceiver.onReceive(sMockContext, new Intent(Intent.ACTION_SCREEN_ON));
+ waitForDelayedHandlerAction(mQnsTimer.mHandler, 10, 200);
+ verify(mAlarmManager).cancel(isA(PendingIntent.class));
+
+ // Handler should reset for the updated delay
+ verify(tempHandler).removeMessages(EVENT_QNS_TIMER_EXPIRED);
+ verify(tempHandler).sendEmptyMessageDelayed(anyInt(), anyLong());
+ assertTrue(mQnsTimer.mHandler.hasMessages(EVENT_QNS_TIMER_EXPIRED));
+ ht.quit();
+ }
}