Merge "Fix phone crash for mobile device without sim." into mnc-dev
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index 3eb6be4..e8b6e05 100644
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -1007,7 +1007,12 @@
}
public boolean isOffhookForSubscriber(int subId) {
- return (getPhone(subId).getState() == PhoneConstants.State.OFFHOOK);
+ final Phone phone = getPhone(subId);
+ if (phone != null) {
+ return (phone.getState() == PhoneConstants.State.OFFHOOK);
+ } else {
+ return false;
+ }
}
public boolean isRinging() {
@@ -1015,7 +1020,12 @@
}
public boolean isRingingForSubscriber(int subId) {
- return (getPhone(subId).getState() == PhoneConstants.State.RINGING);
+ final Phone phone = getPhone(subId);
+ if (phone != null) {
+ return (phone.getState() == PhoneConstants.State.RINGING);
+ } else {
+ return false;
+ }
}
public boolean isIdle() {
@@ -1023,7 +1033,12 @@
}
public boolean isIdleForSubscriber(int subId) {
- return (getPhone(subId).getState() == PhoneConstants.State.IDLE);
+ final Phone phone = getPhone(subId);
+ if (phone != null) {
+ return (phone.getState() == PhoneConstants.State.IDLE);
+ } else {
+ return false;
+ }
}
public boolean isSimPinEnabled(String callingPackage) {
@@ -1184,7 +1199,10 @@
// No permission check needed here: this call is harmless, and it's
// needed for the ServiceState.requestStateUpdate() call (which is
// already intentionally exposed to 3rd parties.)
- getPhone(subId).updateServiceLocation();
+ final Phone phone = getPhone(subId);
+ if (phone != null) {
+ phone.updateServiceLocation();
+ }
}
public boolean isRadioOn() {
@@ -1192,7 +1210,12 @@
}
public boolean isRadioOnForSubscriber(int subId) {
- return getPhone(subId).getServiceState().getState() != ServiceState.STATE_POWER_OFF;
+ final Phone phone = getPhone(subId);
+ if (phone != null) {
+ return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
+ } else {
+ return false;
+ }
}
public void toggleRadioOnOff() {
@@ -1202,7 +1225,10 @@
public void toggleRadioOnOffForSubscriber(int subId) {
enforceModifyPermission();
- getPhone(subId).setRadioPower(!isRadioOnForSubscriber(subId));
+ final Phone phone = getPhone(subId);
+ if (phone != null) {
+ phone.setRadioPower(!isRadioOnForSubscriber(subId));
+ }
}
public boolean setRadio(boolean turnOn) {
@@ -1211,7 +1237,11 @@
public boolean setRadioForSubscriber(int subId, boolean turnOn) {
enforceModifyPermission();
- if ((getPhone(subId).getServiceState().getState() !=
+ final Phone phone = getPhone(subId);
+ if (phone == null) {
+ return false;
+ }
+ if ((phone.getServiceState().getState() !=
ServiceState.STATE_POWER_OFF) != turnOn) {
toggleRadioOnOffForSubscriber(subId);
}
@@ -1252,30 +1282,53 @@
public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
enforceModifyPermission();
- getPhone(subId).setRadioPower(turnOn);
- return true;
+ final Phone phone = getPhone(subId);
+ if (phone != null) {
+ phone.setRadioPower(turnOn);
+ return true;
+ } else {
+ return false;
+ }
}
// FIXME: subId version needed
+ @Override
public boolean enableDataConnectivity() {
enforceModifyPermission();
int subId = mSubscriptionController.getDefaultDataSubId();
- getPhone(subId).setDataEnabled(true);
- return true;
+ final Phone phone = getPhone(subId);
+ if (phone != null) {
+ phone.setDataEnabled(true);
+ return true;
+ } else {
+ return false;
+ }
}
// FIXME: subId version needed
+ @Override
public boolean disableDataConnectivity() {
enforceModifyPermission();
int subId = mSubscriptionController.getDefaultDataSubId();
- getPhone(subId).setDataEnabled(false);
- return true;
+ final Phone phone = getPhone(subId);
+ if (phone != null) {
+ phone.setDataEnabled(false);
+ return true;
+ } else {
+ return false;
+ }
}
// FIXME: subId version needed
+ @Override
public boolean isDataConnectivityPossible() {
int subId = mSubscriptionController.getDefaultDataSubId();
- return getPhone(subId).isDataConnectivityPossible();
+ final Phone phone = getPhone(subId);
+ if (phone != null) {
+ return phone.isDataConnectivityPossible();
+ } else {
+ return false;
+ }
}
public boolean handlePinMmi(String dialString) {
@@ -1284,6 +1337,9 @@
public boolean handlePinMmiForSubscriber(int subId, String dialString) {
enforceModifyPermission();
+ if (!SubscriptionManager.isValidSubscriptionId(subId)) {
+ return false;
+ }
return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
}
@@ -1295,14 +1351,24 @@
return DefaultPhoneNotifier.convertCallState(getPhone(subId).getState());
}
+ @Override
public int getDataState() {
Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
- return DefaultPhoneNotifier.convertDataState(phone.getDataConnectionState());
+ if (phone != null) {
+ return DefaultPhoneNotifier.convertDataState(phone.getDataConnectionState());
+ } else {
+ return DefaultPhoneNotifier.convertDataState(PhoneConstants.DataState.DISCONNECTED);
+ }
}
+ @Override
public int getDataActivity() {
Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
- return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
+ if (phone != null) {
+ return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
+ } else {
+ return TelephonyManager.DATA_ACTIVITY_NONE;
+ }
}
@Override
@@ -1320,6 +1386,9 @@
if (DBG_LOC) log("getCellLocation: is active user");
Bundle data = new Bundle();
Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
+ if (phone == null) {
+ return null;
+ }
phone.getCellLocation().fillInNotifierBundle(data);
return data;
} else {
@@ -1347,10 +1416,14 @@
enableLocationUpdatesForSubscriber(getDefaultSubscription());
}
+ @Override
public void enableLocationUpdatesForSubscriber(int subId) {
mApp.enforceCallingOrSelfPermission(
android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
- getPhone(subId).enableLocationUpdates();
+ final Phone phone = getPhone(subId);
+ if (phone != null) {
+ phone.enableLocationUpdates();
+ }
}
@Override
@@ -1358,10 +1431,14 @@
disableLocationUpdatesForSubscriber(getDefaultSubscription());
}
+ @Override
public void disableLocationUpdatesForSubscriber(int subId) {
mApp.enforceCallingOrSelfPermission(
android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
- getPhone(subId).disableLocationUpdates();
+ final Phone phone = getPhone(subId);
+ if (phone != null) {
+ phone.disableLocationUpdates();
+ }
}
@Override
@@ -1552,8 +1629,14 @@
return getActivePhoneTypeForSubscriber(getDefaultSubscription());
}
+ @Override
public int getActivePhoneTypeForSubscriber(int subId) {
- return getPhone(subId).getPhoneType();
+ final Phone phone = getPhone(subId);
+ if (phone == null) {
+ return PhoneConstants.PHONE_TYPE_NONE;
+ } else {
+ return getPhone(subId).getPhoneType();
+ }
}
/**
@@ -1561,11 +1644,16 @@
*/
public int getCdmaEriIconIndex() {
return getCdmaEriIconIndexForSubscriber(getDefaultSubscription());
-
}
+ @Override
public int getCdmaEriIconIndexForSubscriber(int subId) {
- return getPhone(subId).getCdmaEriIconIndex();
+ final Phone phone = getPhone(subId);
+ if (phone != null) {
+ return phone.getCdmaEriIconIndex();
+ } else {
+ return -1;
+ }
}
/**
@@ -1577,8 +1665,14 @@
return getCdmaEriIconModeForSubscriber(getDefaultSubscription());
}
+ @Override
public int getCdmaEriIconModeForSubscriber(int subId) {
- return getPhone(subId).getCdmaEriIconMode();
+ final Phone phone = getPhone(subId);
+ if (phone != null) {
+ return phone.getCdmaEriIconMode();
+ } else {
+ return -1;
+ }
}
/**
@@ -1588,17 +1682,25 @@
return getCdmaEriTextForSubscriber(getDefaultSubscription());
}
+ @Override
public String getCdmaEriTextForSubscriber(int subId) {
- return getPhone(subId).getCdmaEriText();
+ final Phone phone = getPhone(subId);
+ if (phone != null) {
+ return phone.getCdmaEriText();
+ } else {
+ return null;
+ }
}
/**
* Returns the CDMA MDN.
*/
+ @Override
public String getCdmaMdn(int subId) {
enforceModifyPermissionOrCarrierPrivilege();
- if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
- return getPhone(subId).getLine1Number();
+ final Phone phone = getPhone(subId);
+ if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
+ return phone.getLine1Number();
} else {
return null;
}
@@ -1607,10 +1709,12 @@
/**
* Returns the CDMA MIN.
*/
+ @Override
public String getCdmaMin(int subId) {
enforceModifyPermissionOrCarrierPrivilege();
- if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
- return getPhone(subId).getCdmaMin();
+ final Phone phone = getPhone(subId);
+ if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
+ return phone.getCdmaMin();
} else {
return null;
}
@@ -1644,8 +1748,14 @@
/**
* Returns the unread count of voicemails for a subId
*/
+ @Override
public int getVoiceMessageCountForSubscriber( int subId) {
- return getPhone(subId).getVoiceMessageCount();
+ final Phone phone = getPhone(subId);
+ if (phone != null) {
+ return phone.getVoiceMessageCount();
+ } else {
+ return 0;
+ }
}
/**
@@ -1663,7 +1773,12 @@
*/
@Override
public int getNetworkTypeForSubscriber(int subId) {
- return getPhone(subId).getServiceState().getDataNetworkType();
+ final Phone phone = getPhone(subId);
+ if (phone != null) {
+ return phone.getServiceState().getDataNetworkType();
+ } else {
+ return TelephonyManager.NETWORK_TYPE_UNKNOWN;
+ }
}
/**
@@ -1679,7 +1794,12 @@
*/
@Override
public int getDataNetworkTypeForSubscriber(int subId) {
- return getPhone(subId).getServiceState().getDataNetworkType();
+ final Phone phone = getPhone(subId);
+ if (phone != null) {
+ return phone.getServiceState().getDataNetworkType();
+ } else {
+ return TelephonyManager.NETWORK_TYPE_UNKNOWN;
+ }
}
/**
@@ -1695,7 +1815,12 @@
*/
@Override
public int getVoiceNetworkTypeForSubscriber(int subId) {
- return getPhone(subId).getServiceState().getVoiceNetworkType();
+ final Phone phone = getPhone(subId);
+ if (phone != null) {
+ return phone.getServiceState().getVoiceNetworkType();
+ } else {
+ return TelephonyManager.NETWORK_TYPE_UNKNOWN;
+ }
}
/**
@@ -1709,10 +1834,12 @@
/**
* @return true if a ICC card is present for a slotId
*/
+ @Override
public boolean hasIccCardUsingSlotId(int slotId) {
int subId[] = mSubscriptionController.getSubIdUsingSlotId(slotId);
- if (subId != null) {
- return getPhone(subId[0]).getIccCard().hasIccCard();
+ final Phone phone = getPhone(subId[0]);
+ if (subId != null && phone != null) {
+ return phone.getIccCard().hasIccCard();
} else {
return false;
}
@@ -1730,8 +1857,14 @@
return getLteOnCdmaModeForSubscriber(getDefaultSubscription());
}
+ @Override
public int getLteOnCdmaModeForSubscriber(int subId) {
- return getPhone(subId).getLteOnCdmaMode();
+ final Phone phone = getPhone(subId);
+ if (phone == null) {
+ return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
+ } else {
+ return phone.getLteOnCdmaMode();
+ }
}
public void setPhone(Phone phone) {
@@ -2198,7 +2331,8 @@
}
private String getIccId(int subId) {
- UiccCard card = getPhone(subId).getUiccCard();
+ final Phone phone = getPhone(subId);
+ UiccCard card = phone == null ? null : phone.getUiccCard();
if (card == null) {
loge("getIccId: No UICC");
return null;
@@ -2217,7 +2351,11 @@
enforceCarrierPrivilege();
final String iccId = getIccId(subId);
- final String subscriberId = getPhone(subId).getSubscriberId();
+ final Phone phone = getPhone(subId);
+ if (phone == null) {
+ return false;
+ }
+ final String subscriberId = phone.getSubscriberId();
if (DBG_MERGE) {
Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="