From 8968f9f6d47585daf0f81db3ba7f54b1d7ae3498 Mon Sep 17 00:00:00 2001 From: Kazuhiro Ondo Date: Fri, 1 Apr 2011 20:19:22 -0500 Subject: [PATCH] Check different CellLocation type in GsmDataConnectionTracker Addressing phone app crash in GsmDataConnectionTracker when CDMALTEPhone is used. CDMALTEPhone uses CDMA SST so getCellLocation() was returning an instance of CdmaCellLocation. This was causing a crash when GsmDCT type casts the instance as GsmCellLocation. This patch tries to check the instance type before retrieving corresponding cell id. Change-Id: I6ac9cd4dc078552dc58d4d9350494a7b608c2b98 --- .../gsm/GsmDataConnectionTracker.java | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java b/telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java index cfb78d0d6f353..53cbad59eb5a6 100644 --- a/telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java +++ b/telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java @@ -38,8 +38,10 @@ import android.os.SystemClock; import android.os.SystemProperties; import android.provider.Settings; import android.provider.Telephony; +import android.telephony.CellLocation; import android.telephony.ServiceState; import android.telephony.TelephonyManager; +import android.telephony.cdma.CdmaCellLocation; import android.telephony.gsm.GsmCellLocation; import android.text.TextUtils; import android.util.EventLog; @@ -995,9 +997,7 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker { Log.i(LOG_TAG, "PDP connection has dropped. Reconnecting"); // Add an event log when the network drops PDP - int cid = -1; - GsmCellLocation loc = ((GsmCellLocation)mPhone.getCellLocation()); - if (loc != null) cid = loc.getCid(); + int cid = getCellLocationId(); EventLog.writeEvent(EventLogTags.PDP_NETWORK_DROP, cid, TelephonyManager.getDefault().getNetworkType()); @@ -1018,9 +1018,7 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker { + " Reconnecting"); // Log the network drop on the event log. - int cid = -1; - GsmCellLocation loc = ((GsmCellLocation)mPhone.getCellLocation()); - if (loc != null) cid = loc.getCid(); + int cid = getCellLocationId(); EventLog.writeEvent(EventLogTags.PDP_NETWORK_DROP, cid, TelephonyManager.getDefault().getNetworkType()); @@ -1522,10 +1520,9 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker { } if (cause.isEventLoggable()) { // Log this failure to the Event Logs. - GsmCellLocation loc = ((GsmCellLocation)mPhone.getCellLocation()); + int cid = getCellLocationId(); EventLog.writeEvent(EventLogTags.PDP_SETUP_FAIL, - cause.ordinal(), loc != null ? loc.getCid() : -1, - TelephonyManager.getDefault().getNetworkType()); + cause.ordinal(), cid, TelephonyManager.getDefault().getNetworkType()); } // Count permanent failures and remove the APN we just tried @@ -1984,6 +1981,20 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker { } } + private int getCellLocationId() { + int cid = -1; + CellLocation loc = mPhone.getCellLocation(); + + if (loc != null) { + if (loc instanceof GsmCellLocation) { + cid = ((GsmCellLocation)loc).getCid(); + } else if (loc instanceof CdmaCellLocation) { + cid = ((CdmaCellLocation)loc).getBaseStationId(); + } + } + return cid; + } + @Override public boolean isAnyActiveDataConnections() { return isConnected();