Fix flaky TeleServices tests causing module errors
Some tests were using reflection to replace static instances but not
resetting the previous values, causing the device to remain in a bad
state. Add a replaceInstance and restoreInstances method to
TelephonyTestBase and have these classes extend it so cleanup can be
done in the @After method.
Fix flaky NotificationMgrTests causing module errors due to incomplete
mocks.
Also revert changes added to help debug b/256244889.
Test: atest TeleServiceTests
Bug: 256244889
Change-Id: Id758e207da862f450d5c90971cb3ea1bd2afe40d
diff --git a/src/com/android/phone/PhoneGlobals.java b/src/com/android/phone/PhoneGlobals.java
index f18535c..abbd816 100644
--- a/src/com/android/phone/PhoneGlobals.java
+++ b/src/com/android/phone/PhoneGlobals.java
@@ -81,7 +81,6 @@
import java.io.PrintWriter;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
-import java.util.ArrayList;
import java.util.List;
/**
@@ -889,10 +888,8 @@
boolean dataAllowed;
boolean notAllowedDueToRoamingOff;
- List<DataDisallowedReason> reasons = new ArrayList<>();
- if (phone.getDataNetworkController() != null) {
- reasons = phone.getDataNetworkController().getInternetDataDisallowedReasons();
- }
+ List<DataDisallowedReason> reasons = phone.getDataNetworkController()
+ .getInternetDataDisallowedReasons();
dataAllowed = reasons.isEmpty();
notAllowedDueToRoamingOff = (reasons.size() == 1
&& reasons.contains(DataDisallowedReason.ROAMING_DISABLED));
@@ -938,11 +935,7 @@
* @return whether we have transitioned to dataRoaming
*/
private boolean dataIsNowRoaming(int subId) {
- if (getPhone(subId).getServiceState() == null) {
- return false;
- } else {
- return getPhone(subId).getServiceState().getDataRoaming();
- }
+ return getPhone(subId).getServiceState().getDataRoaming();
}
private void updateLimitedSimFunctionForDualSim() {
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index 3f05f0a..7c176ef 100755
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -6804,12 +6804,7 @@
int phoneId = mSubscriptionController.getPhoneId(subId);
Phone phone = PhoneFactory.getPhone(phoneId);
if (phone != null) {
- boolean retVal;
- if (phone.getDataSettingsManager() == null) {
- retVal = false;
- } else {
- retVal = phone.getDataSettingsManager().isDataEnabled();
- }
+ boolean retVal = phone.getDataSettingsManager().isDataEnabled();
if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId);
return retVal;
} else {