Merge change 24773 into eclair

* changes:
  Fix NPE in TelephonyManager.
This commit is contained in:
Android (Google) Code Review
2009-09-11 18:26:02 -04:00

View File

@@ -159,7 +159,8 @@ public class TelephonyManager {
/** /**
* Returns the software version number for the device, for example, * Returns the software version number for the device, for example,
* the IMEI/SV for GSM phones. * the IMEI/SV for GSM phones. Return null if the software version is
* not available.
* *
* <p>Requires Permission: * <p>Requires Permission:
* {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
@@ -168,13 +169,15 @@ public class TelephonyManager {
try { try {
return getSubscriberInfo().getDeviceSvn(); return getSubscriberInfo().getDeviceSvn();
} catch (RemoteException ex) { } catch (RemoteException ex) {
return null;
} catch (NullPointerException ex) {
return null;
} }
return null;
} }
/** /**
* Returns the unique device ID, for example, the IMEI for GSM and the MEID for CDMA * Returns the unique device ID, for example, the IMEI for GSM and the MEID
* phones. * for CDMA phones. Return null if device ID is not available.
* *
* <p>Requires Permission: * <p>Requires Permission:
* {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
@@ -183,12 +186,15 @@ public class TelephonyManager {
try { try {
return getSubscriberInfo().getDeviceId(); return getSubscriberInfo().getDeviceId();
} catch (RemoteException ex) { } catch (RemoteException ex) {
return null;
} catch (NullPointerException ex) {
return null;
} }
return null;
} }
/** /**
* Returns the current location of the device. * Returns the current location of the device.
* Return null if current location is not available.
* *
* <p>Requires Permission: * <p>Requires Permission:
* {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_COARSE_LOCATION} or * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_COARSE_LOCATION} or
@@ -199,8 +205,10 @@ public class TelephonyManager {
Bundle bundle = getITelephony().getCellLocation(); Bundle bundle = getITelephony().getCellLocation();
return CellLocation.newFromBundle(bundle); return CellLocation.newFromBundle(bundle);
} catch (RemoteException ex) { } catch (RemoteException ex) {
return null;
} catch (NullPointerException ex) {
return null;
} }
return null;
} }
/** /**
@@ -216,6 +224,7 @@ public class TelephonyManager {
try { try {
getITelephony().enableLocationUpdates(); getITelephony().enableLocationUpdates();
} catch (RemoteException ex) { } catch (RemoteException ex) {
} catch (NullPointerException ex) {
} }
} }
@@ -232,6 +241,7 @@ public class TelephonyManager {
try { try {
getITelephony().disableLocationUpdates(); getITelephony().disableLocationUpdates();
} catch (RemoteException ex) { } catch (RemoteException ex) {
} catch (NullPointerException ex) {
} }
} }
@@ -247,9 +257,10 @@ public class TelephonyManager {
try { try {
return getITelephony().getNeighboringCellInfo(); return getITelephony().getNeighboringCellInfo();
} catch (RemoteException ex) { } catch (RemoteException ex) {
return null;
} catch (NullPointerException ex) {
return null;
} }
return null;
} }
/** /**
@@ -289,7 +300,11 @@ public class TelephonyManager {
// This can happen when the ITelephony interface is not up yet. // This can happen when the ITelephony interface is not up yet.
return getPhoneTypeFromProperty(); return getPhoneTypeFromProperty();
} }
} catch(RemoteException ex){ } catch (RemoteException ex) {
// This shouldn't happen in the normal case, as a backup we
// read from the system property.
return getPhoneTypeFromProperty();
} catch (NullPointerException ex) {
// This shouldn't happen in the normal case, as a backup we // This shouldn't happen in the normal case, as a backup we
// read from the system property. // read from the system property.
return getPhoneTypeFromProperty(); return getPhoneTypeFromProperty();
@@ -418,9 +433,12 @@ public class TelephonyManager {
// This can happen when the ITelephony interface is not up yet. // This can happen when the ITelephony interface is not up yet.
return NETWORK_TYPE_UNKNOWN; return NETWORK_TYPE_UNKNOWN;
} }
} catch(RemoteException ex){ } catch(RemoteException ex) {
// This shouldn't happen in the normal case // This shouldn't happen in the normal case
return NETWORK_TYPE_UNKNOWN; return NETWORK_TYPE_UNKNOWN;
} catch (NullPointerException ex) {
// This could happen before phone restarts due to crashing
return NETWORK_TYPE_UNKNOWN;
} }
} }
@@ -489,6 +507,9 @@ public class TelephonyManager {
} catch (RemoteException ex) { } catch (RemoteException ex) {
// Assume no ICC card if remote exception which shouldn't happen // Assume no ICC card if remote exception which shouldn't happen
return false; return false;
} catch (NullPointerException ex) {
// This could happen before phone restarts due to crashing
return false;
} }
} }
@@ -556,7 +577,8 @@ public class TelephonyManager {
} }
/** /**
* Returns the serial number of the SIM, if applicable. * Returns the serial number of the SIM, if applicable. Return null if it is
* unavailable.
* <p> * <p>
* Requires Permission: * Requires Permission:
* {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
@@ -565,8 +587,11 @@ public class TelephonyManager {
try { try {
return getSubscriberInfo().getIccSerialNumber(); return getSubscriberInfo().getIccSerialNumber();
} catch (RemoteException ex) { } catch (RemoteException ex) {
return null;
} catch (NullPointerException ex) {
// This could happen before phone restarts due to crashing
return null;
} }
return null;
} }
// //
@@ -577,6 +602,7 @@ public class TelephonyManager {
/** /**
* Returns the unique subscriber ID, for example, the IMSI for a GSM phone. * Returns the unique subscriber ID, for example, the IMSI for a GSM phone.
* Return null if it is unavailable.
* <p> * <p>
* Requires Permission: * Requires Permission:
* {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
@@ -585,13 +611,16 @@ public class TelephonyManager {
try { try {
return getSubscriberInfo().getSubscriberId(); return getSubscriberInfo().getSubscriberId();
} catch (RemoteException ex) { } catch (RemoteException ex) {
return null;
} catch (NullPointerException ex) {
// This could happen before phone restarts due to crashing
return null;
} }
return null;
} }
/** /**
* Returns the phone number string for line 1, for example, the MSISDN * Returns the phone number string for line 1, for example, the MSISDN
* for a GSM phone. * for a GSM phone. Return null if it is unavailable.
* <p> * <p>
* Requires Permission: * Requires Permission:
* {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
@@ -600,12 +629,16 @@ public class TelephonyManager {
try { try {
return getSubscriberInfo().getLine1Number(); return getSubscriberInfo().getLine1Number();
} catch (RemoteException ex) { } catch (RemoteException ex) {
return null;
} catch (NullPointerException ex) {
// This could happen before phone restarts due to crashing
return null;
} }
return null;
} }
/** /**
* Returns the alphabetic identifier associated with the line 1 number. * Returns the alphabetic identifier associated with the line 1 number.
* Return null if it is unavailable.
* <p> * <p>
* Requires Permission: * Requires Permission:
* {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
@@ -616,12 +649,15 @@ public class TelephonyManager {
try { try {
return getSubscriberInfo().getLine1AlphaTag(); return getSubscriberInfo().getLine1AlphaTag();
} catch (RemoteException ex) { } catch (RemoteException ex) {
return null;
} catch (NullPointerException ex) {
// This could happen before phone restarts due to crashing
return null;
} }
return null;
} }
/** /**
* Returns the voice mail number. * Returns the voice mail number. Return null if it is unavailable.
* <p> * <p>
* Requires Permission: * Requires Permission:
* {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
@@ -630,12 +666,15 @@ public class TelephonyManager {
try { try {
return getSubscriberInfo().getVoiceMailNumber(); return getSubscriberInfo().getVoiceMailNumber();
} catch (RemoteException ex) { } catch (RemoteException ex) {
return null;
} catch (NullPointerException ex) {
// This could happen before phone restarts due to crashing
return null;
} }
return null;
} }
/** /**
* Returns the voice mail count. * Returns the voice mail count. Return 0 if unavailable.
* <p> * <p>
* Requires Permission: * Requires Permission:
* {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
@@ -645,8 +684,11 @@ public class TelephonyManager {
try { try {
return getITelephony().getVoiceMessageCount(); return getITelephony().getVoiceMessageCount();
} catch (RemoteException ex) { } catch (RemoteException ex) {
return 0;
} catch (NullPointerException ex) {
// This could happen before phone restarts due to crashing
return 0;
} }
return 0;
} }
/** /**
@@ -660,8 +702,11 @@ public class TelephonyManager {
try { try {
return getSubscriberInfo().getVoiceMailAlphaTag(); return getSubscriberInfo().getVoiceMailAlphaTag();
} catch (RemoteException ex) { } catch (RemoteException ex) {
return null;
} catch (NullPointerException ex) {
// This could happen before phone restarts due to crashing
return null;
} }
return null;
} }
private IPhoneSubInfo getSubscriberInfo() { private IPhoneSubInfo getSubscriberInfo() {
@@ -759,6 +804,8 @@ public class TelephonyManager {
} catch (RemoteException ex) { } catch (RemoteException ex) {
// the phone process is restarting. // the phone process is restarting.
return DATA_DISCONNECTED; return DATA_DISCONNECTED;
} catch (NullPointerException ex) {
return DATA_DISCONNECTED;
} }
} }
@@ -802,6 +849,8 @@ public class TelephonyManager {
mRegistry.listen(pkgForDebug, listener.callback, events, notifyNow); mRegistry.listen(pkgForDebug, listener.callback, events, notifyNow);
} catch (RemoteException ex) { } catch (RemoteException ex) {
// system process dead // system process dead
} catch (NullPointerException ex) {
// system process dead
} }
} }
@@ -816,6 +865,8 @@ public class TelephonyManager {
} catch (RemoteException ex) { } catch (RemoteException ex) {
// the phone process is restarting. // the phone process is restarting.
return -1; return -1;
} catch (NullPointerException ex) {
return -1;
} }
} }
@@ -832,6 +883,8 @@ public class TelephonyManager {
} catch (RemoteException ex) { } catch (RemoteException ex) {
// the phone process is restarting. // the phone process is restarting.
return -1; return -1;
} catch (NullPointerException ex) {
return -1;
} }
} }
@@ -846,6 +899,8 @@ public class TelephonyManager {
} catch (RemoteException ex) { } catch (RemoteException ex) {
// the phone process is restarting. // the phone process is restarting.
return null; return null;
} catch (NullPointerException ex) {
return null;
} }
} }
} }