Don't ever report a null ServiceState

Report out of service if we don't know any better.  Sometimes when switching radios
we were finding nulls reported - it crashed some code and highlighted this problem.
If we don't have a service state we're certainly out of service, so this isn't a lie.

bug:4553701
Change-Id: I094798a5f9f39f45c0ba30179aaa8f88f9b3e405
This commit is contained in:
Robert Greenwalt
2011-06-30 12:24:26 -07:00
parent f3f9967e22
commit a2267451dd
2 changed files with 14 additions and 19 deletions

View File

@@ -473,8 +473,8 @@ public class ServiceState implements Parcelable {
+ " EmergOnly=" + mIsEmergencyOnly);
}
public void setStateOutOfService() {
mState = STATE_OUT_OF_SERVICE;
private void setNullState(int state) {
mState = state;
mRoaming = false;
mOperatorAlphaLong = null;
mOperatorAlphaShort = null;
@@ -491,23 +491,12 @@ public class ServiceState implements Parcelable {
mIsEmergencyOnly = false;
}
// TODO - can't this be combined with the above method?
public void setStateOutOfService() {
setNullState(STATE_OUT_OF_SERVICE);
}
public void setStateOff() {
mState = STATE_POWER_OFF;
mRoaming = false;
mOperatorAlphaLong = null;
mOperatorAlphaShort = null;
mOperatorNumeric = null;
mIsManualNetworkSelection = false;
mRadioTechnology = 0;
mCssIndicator = false;
mNetworkId = -1;
mSystemId = -1;
mCdmaRoamingIndicator = -1;
mCdmaDefaultRoamingIndicator = -1;
mCdmaEriIconIndex = -1;
mCdmaEriIconMode = -1;
mIsEmergencyOnly = false;
setNullState(STATE_POWER_OFF);
}
public void setState(int state) {

View File

@@ -21,6 +21,7 @@ import android.net.LinkProperties;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.telephony.ServiceState;
import android.telephony.TelephonyManager;
import android.util.Log;
@@ -55,8 +56,13 @@ public class DefaultPhoneNotifier implements PhoneNotifier {
}
public void notifyServiceState(Phone sender) {
ServiceState ss = sender.getServiceState();
if (ss == null) {
ss = new ServiceState();
ss.setStateOutOfService();
}
try {
mRegistry.notifyServiceState(sender.getServiceState());
mRegistry.notifyServiceState(ss);
} catch (RemoteException ex) {
// system process is dead
}