Reputation: 199
i have a Simple Question :
Does
TelephonyManager.getDeviceId();
will work without Sim Card(SIM_STATE_ABSENT) in the Device ?
Upvotes: 5
Views: 2929
Reputation: 14271
Code talks:
The telephony.getDeviceId()
finally calls to Phone.getDeviceId(), the implementations of this method are different on different phone like CDMA Phone and GSM Phone. For example, CDMA Phone.
public String getMeid() {
return mMeid;
}
//returns MEID or ESN in CDMA
public String getDeviceId() {
String id = getMeid();
if ((id == null) || id.matches("^0*$")) {
Rlog.d(LOG_TAG, "getDeviceId(): MEID is not initialized use ESN");
id = getEsn();
}
return id;
}
It has no checks on that SIM ABSENT state. So of course you can get the result without a sim card.
However, take a look at when this mMeid is reset.
case EVENT_GET_IMEI_DONE:
ar = (AsyncResult)msg.obj;
if (ar.exception != null) {
break;
}
mImei = (String)ar.result;
case EVENT_RADIO_AVAILABLE: {
mCM.getBasebandVersion(
obtainMessage(EVENT_GET_BASEBAND_VERSION_DONE));
mCM.getIMEI(obtainMessage(EVENT_GET_IMEI_DONE));
mCM.getIMEISV(obtainMessage(EVENT_GET_IMEISV_DONE));
}
So it will get reset when it receives an EVENT_RADIO_AVAILABLE message. And that event is send from RIL. Only when it get an EVENT_RADIO_AVAILABLE message, it will send out a message to request device identity. Although the getting device identity has nothing to do with sim card, but EVENT_RADIO_AVAILABLE might do(need further confirmation).
I further check when will the system send out an EVENT_RADIO_AVAILABLE message. And finally found out that the RadioState contains:
enum RadioState {
RADIO_OFF, /* Radio explictly powered off (eg CFUN=0) */
RADIO_UNAVAILABLE, /* Radio unavailable (eg, resetting or not booted) */
SIM_NOT_READY, /* Radio is on, but the SIM interface is not ready */
SIM_LOCKED_OR_ABSENT, /* SIM PIN locked, PUK required, network
personalization, or SIM absent */
SIM_READY, /* Radio is on and SIM interface is available */
RUIM_NOT_READY, /* Radio is on, but the RUIM interface is not ready */
RUIM_READY, /* Radio is on and the RUIM interface is available */
RUIM_LOCKED_OR_ABSENT, /* RUIM PIN locked, PUK required, network
personalization locked, or RUIM absent */
NV_NOT_READY, /* Radio is on, but the NV interface is not available */
NV_READY; /* Radio is on and the NV interface is available */
...
}
and when isAvailable() returns true, it will send out the event. And the imei will get updated.
public boolean isAvailable() {
return this != RADIO_UNAVAILABLE;
}
So, SIM_ABSENT has nothing to do with device id.
Upvotes: 1
Reputation: 5859
It should work. I just tested this on my CDMA Galaxy nexus and it returned a value, even though it doesn't have a SIM card at all. When I ran it on an emulator, it returned a long string of zeroes.
Update: According to documentation, getDeviceId() returns IMEI for a GSM device. And IMEI is not a SIM-card feature, it comes with the device.
Upvotes: 2