Merge "Attempt to fix simulator build." into gingerbread
diff --git a/libs/utils/ZipFileRO.cpp b/libs/utils/ZipFileRO.cpp
index 5ff1f8f..4261196 100644
--- a/libs/utils/ZipFileRO.cpp
+++ b/libs/utils/ZipFileRO.cpp
@@ -412,10 +412,18 @@
 /*
  * Find a matching entry.
  *
- * Returns 0 if not found.
+ * Returns NULL if not found.
  */
 ZipEntryRO ZipFileRO::findEntryByName(const char* fileName) const
 {
+    /*
+     * If the ZipFileRO instance is not initialized, the entry number will
+     * end up being garbage since mHashTableSize is -1.
+     */
+    if (mHashTableSize <= 0) {
+        return NULL;
+    }
+
     int nameLen = strlen(fileName);
     unsigned int hash = computeHash(fileName, nameLen);
     int ent = hash & (mHashTableSize-1);
diff --git a/services/java/com/android/server/location/GpsLocationProvider.java b/services/java/com/android/server/location/GpsLocationProvider.java
index 4a6b5f4..755a228 100755
--- a/services/java/com/android/server/location/GpsLocationProvider.java
+++ b/services/java/com/android/server/location/GpsLocationProvider.java
@@ -1451,23 +1451,30 @@
                 mContext.getSystemService(Context.TELEPHONY_SERVICE);
         if (phone.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) {
             GsmCellLocation gsm_cell = (GsmCellLocation) phone.getCellLocation();
-            if ((gsm_cell != null) && (phone.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM)
-                    && (phone.getNetworkOperator().length() > 3)) {
+            if ((gsm_cell != null) && (phone.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) &&
+                    (phone.getNetworkOperator() != null) &&
+                        (phone.getNetworkOperator().length() > 3)) {
                 int type;
                 int mcc = Integer.parseInt(phone.getNetworkOperator().substring(0,3));
                 int mnc = Integer.parseInt(phone.getNetworkOperator().substring(3));
-                if (phone.getNetworkType() == TelephonyManager.NETWORK_TYPE_UMTS)
+                int networkType = phone.getNetworkType();
+                if (networkType == TelephonyManager.NETWORK_TYPE_UMTS
+                    || networkType == TelephonyManager.NETWORK_TYPE_HSDPA
+                    || networkType == TelephonyManager.NETWORK_TYPE_HSUPA
+                    || networkType == TelephonyManager.NETWORK_TYPE_HSPA) {
                     type = AGPS_REF_LOCATION_TYPE_UMTS_CELLID;
-                else
+                } else {
                     type = AGPS_REF_LOCATION_TYPE_GSM_CELLID;
+                }
                 native_agps_set_ref_location_cellid(type, mcc, mnc,
                         gsm_cell.getLac(), gsm_cell.getCid());
-            }
-            else
+            } else {
                 Log.e(TAG,"Error getting cell location info.");
+            }
         }
-        else
+        else {
             Log.e(TAG,"CDMA not supported.");
+        }
     }
 
     private void sendMessage(int message, int arg, Object obj) {
diff --git a/voip/java/com/android/server/sip/SipService.java b/voip/java/com/android/server/sip/SipService.java
index 84e0803..f480fec 100644
--- a/voip/java/com/android/server/sip/SipService.java
+++ b/voip/java/com/android/server/sip/SipService.java
@@ -441,13 +441,26 @@
 
     private synchronized void addPendingSession(ISipSession session) {
         try {
+            cleanUpPendingSessions();
             mPendingSessions.put(session.getCallId(), session);
+            if (DEBUG) Log.d(TAG, "#pending sess=" + mPendingSessions.size());
         } catch (RemoteException e) {
             // should not happen with a local call
             Log.e(TAG, "addPendingSession()", e);
         }
     }
 
+    private void cleanUpPendingSessions() throws RemoteException {
+        Map.Entry<String, ISipSession>[] entries =
+                mPendingSessions.entrySet().toArray(
+                new Map.Entry[mPendingSessions.size()]);
+        for (Map.Entry<String, ISipSession> entry : entries) {
+            if (entry.getValue().getState() != SipSession.State.INCOMING_CALL) {
+                mPendingSessions.remove(entry.getKey());
+            }
+        }
+    }
+
     private synchronized boolean callingSelf(SipSessionGroupExt ringingGroup,
             SipSessionGroup.SipSessionImpl ringingSession) {
         String callId = ringingSession.getCallId();
@@ -1095,8 +1108,6 @@
         }
     }
 
-    // TODO: clean up pending SipSession(s) periodically
-
     /**
      * Timer that can schedule events to occur even when the device is in sleep.
      * Only used internally in this package.