Merge commit '616b281b' into merge-conflict-TelephonySignal-Strength-cleanup
[android/platform/frameworks/opt/telephony.git] / src / java / com / android / internal / telephony / cdma / CdmaLteServiceStateTracker.java
old mode 100755 (executable)
new mode 100644 (file)
index c19cc5e..e82f07d
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 The Android Open Source Project
+ * Copyright (C) 2012 The Android Open Source Project
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,12 +23,17 @@ import com.android.internal.telephony.EventLogTags;
 import com.android.internal.telephony.RILConstants;
 import com.android.internal.telephony.IccCard;
 
-import android.content.Intent;
+import android.telephony.CellInfo;
+import android.telephony.CellInfoLte;
+import android.telephony.CellSignalStrengthLte;
+import android.telephony.CellIdentityLte;
 import android.telephony.SignalStrength;
 import android.telephony.ServiceState;
 import android.telephony.cdma.CdmaCellLocation;
+import android.text.TextUtils;
 import android.os.AsyncResult;
 import android.os.Message;
+import android.os.SystemClock;
 import android.os.SystemProperties;
 
 import android.text.TextUtils;
@@ -40,17 +45,27 @@ import com.android.internal.telephony.IccCardConstants;
 
 import java.io.FileDescriptor;
 import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.List;
 
 public class CdmaLteServiceStateTracker extends CdmaServiceStateTracker {
-    CDMALTEPhone mCdmaLtePhone;
+    private CDMALTEPhone mCdmaLtePhone;
+    private final CellInfoLte mCellInfoLte;
 
     private ServiceState  mLteSS;  // The last LTE state from Voice Registration
 
+    private CellIdentityLte mNewCellIdentityLte = new CellIdentityLte();
+    private CellIdentityLte mLasteCellIdentityLte = new CellIdentityLte();
+
     public CdmaLteServiceStateTracker(CDMALTEPhone phone) {
-        super(phone);
+        super(phone, new CellInfoLte());
         mCdmaLtePhone = phone;
+        mCellInfoLte = (CellInfoLte) mCellInfo;
 
         mLteSS = new ServiceState();
+        ((CellInfoLte)mCellInfo).setCellSignalStrength(new CellSignalStrengthLte());
+        ((CellInfoLte)mCellInfo).setCellIdentity(new CellIdentityLte());
+
         if (DBG) log("CdmaLteServiceStateTracker Constructors");
     }
 
@@ -101,8 +116,11 @@ public class CdmaLteServiceStateTracker extends CdmaServiceStateTracker {
     @Override
     protected void handlePollStateResultMessage(int what, AsyncResult ar) {
         if (what == EVENT_POLL_STATE_GPRS) {
-            if (DBG) log("handlePollStateResultMessage: EVENT_POLL_STATE_GPRS");
             String states[] = (String[])ar.result;
+            if (DBG) {
+                log("handlePollStateResultMessage: EVENT_POLL_STATE_GPRS states.length=" +
+                        states.length + " states=" + states);
+            }
 
             int type = 0;
             int regState = -1;
@@ -118,6 +136,71 @@ public class CdmaLteServiceStateTracker extends CdmaServiceStateTracker {
                     loge("handlePollStateResultMessage: error parsing GprsRegistrationState: "
                                     + ex);
                 }
+                if (states.length >= 10) {
+                    int mcc;
+                    int mnc;
+                    int tac;
+                    int pci;
+                    int eci;
+                    int csgid;
+                    String operatorNumeric = null;
+
+                    try {
+                        operatorNumeric = mLteSS.getOperatorNumeric();
+                        mcc = Integer.parseInt(operatorNumeric.substring(0,3));
+                    } catch (Exception e) {
+                        try {
+                            operatorNumeric = ss.getOperatorNumeric();
+                            mcc = Integer.parseInt(operatorNumeric.substring(0,3));
+                        } catch (Exception ex) {
+                            loge("handlePollStateResultMessage: bad mcc operatorNumeric=" +
+                                    operatorNumeric + " ex=" + ex);
+                            operatorNumeric = "";
+                            mcc = Integer.MAX_VALUE;
+                        }
+                    }
+                    try {
+                        mnc = Integer.parseInt(operatorNumeric.substring(3));
+                    } catch (Exception e) {
+                        loge("handlePollStateResultMessage: bad mnc operatorNumeric=" +
+                                operatorNumeric + " e=" + e);
+                        mnc = Integer.MAX_VALUE;
+                    }
+                    try {
+                        tac = Integer.parseInt(states[6], 16);
+                    } catch (Exception e) {
+                        loge("handlePollStateResultMessage: bad tac states[6]=" +
+                                states[6] + " e=" + e);
+                        tac = Integer.MAX_VALUE;
+                    }
+                    try {
+                        pci = Integer.parseInt(states[7], 16);
+                    } catch (Exception e) {
+                        loge("handlePollStateResultMessage: bad pci states[7]=" +
+                                states[7] + " e=" + e);
+                        pci = Integer.MAX_VALUE;
+                    }
+                    try {
+                        eci = Integer.parseInt(states[8], 16);
+                    } catch (Exception e) {
+                        loge("handlePollStateResultMessage: bad eci states[8]=" +
+                                states[8] + " e=" + e);
+                        eci = Integer.MAX_VALUE;
+                    }
+                    try {
+                        csgid = Integer.parseInt(states[9], 16);
+                    } catch (Exception e) {
+                        // FIX: Always bad so don't pollute the logs
+                        // loge("handlePollStateResultMessage: bad csgid states[9]=" +
+                        //        states[9] + " e=" + e);
+                        csgid = Integer.MAX_VALUE;
+                    }
+                    mNewCellIdentityLte = new CellIdentityLte(mcc, mnc, eci, pci, tac);
+                    if (DBG) {
+                        log("handlePollStateResultMessage: mNewLteCellIdentity=" +
+                                mNewCellIdentityLte);
+                    }
+                }
             }
 
             mLteSS.setRadioTechnology(type);
@@ -165,18 +248,10 @@ public class CdmaLteServiceStateTracker extends CdmaServiceStateTracker {
                 cm.getVoiceRegistrationState(obtainMessage(EVENT_POLL_STATE_REGISTRATION_CDMA,
                         pollingContext));
 
-                int networkMode = android.provider.Settings.Secure.getInt(phone.getContext()
-                        .getContentResolver(),
-                        android.provider.Settings.Secure.PREFERRED_NETWORK_MODE,
-                        RILConstants.PREFERRED_NETWORK_MODE);
-                if (DBG) log("pollState: network mode here is = " + networkMode);
-                if ((networkMode == RILConstants.NETWORK_MODE_GLOBAL)
-                        || (networkMode == RILConstants.NETWORK_MODE_LTE_ONLY)) {
-                    pollingContext[0]++;
-                    // RIL_REQUEST_DATA_REGISTRATION_STATE
-                    cm.getDataRegistrationState(obtainMessage(EVENT_POLL_STATE_GPRS,
-                                                pollingContext));
-                }
+                pollingContext[0]++;
+                // RIL_REQUEST_DATA_REGISTRATION_STATE
+                cm.getDataRegistrationState(obtainMessage(EVENT_POLL_STATE_GPRS,
+                                            pollingContext));
                 break;
         }
     }
@@ -434,14 +509,53 @@ public class CdmaLteServiceStateTracker extends CdmaServiceStateTracker {
         if (hasLocationChanged) {
             phone.notifyLocationChanged();
         }
+
+        ArrayList<CellInfo> arrayCi = new ArrayList<CellInfo>();
+        synchronized(mCellInfo) {
+            CellInfoLte cil = (CellInfoLte)mCellInfo;
+
+            boolean cidChanged = ! mNewCellIdentityLte.equals(mLasteCellIdentityLte);
+            if (hasRegistered || hasDeregistered || cidChanged) {
+                // TODO: Handle the absence of LteCellIdentity
+                long timeStamp = SystemClock.elapsedRealtime() * 1000;
+                boolean registered = ss.getState() == ServiceState.STATE_IN_SERVICE;
+                mLasteCellIdentityLte = mNewCellIdentityLte;
+
+                cil.setRegisterd(registered);
+                cil.setCellIdentity(mLasteCellIdentityLte);
+                if (DBG) {
+                    log("pollStateDone: hasRegistered=" + hasRegistered +
+                            " hasDeregistered=" + hasDeregistered +
+                            " cidChanged=" + cidChanged +
+                            " mCellInfo=" + mCellInfo);
+                }
+                arrayCi.add(mCellInfo);
+            }
+            mPhoneBase.notifyCellInfo(arrayCi);
+        }
     }
 
     @Override
-    protected void onSignalStrengthResult(AsyncResult ar, PhoneBase phone, boolean isGsm) {
+    protected boolean onSignalStrengthResult(AsyncResult ar, boolean isGsm) {
         if (mRilRadioTechnology == ServiceState.RIL_RADIO_TECHNOLOGY_LTE) {
             isGsm = true;
         }
-        super.onSignalStrengthResult(ar, phone, isGsm);
+        boolean ssChanged = super.onSignalStrengthResult(ar, isGsm);
+
+        synchronized (mCellInfo) {
+            if (mRilRadioTechnology == ServiceState.RIL_RADIO_TECHNOLOGY_LTE) {
+                mCellInfoLte.setTimeStamp(SystemClock.elapsedRealtime() * 1000);
+                mCellInfoLte.setTimeStampType(CellInfo.TIMESTAMP_TYPE_JAVA_RIL);
+                mCellInfoLte.getCellSignalStrength()
+                                .initialize(mSignalStrength,SignalStrength.INVALID);
+            }
+            if (mCellInfoLte.getCellIdentity() != null) {
+                ArrayList<CellInfo> arrayCi = new ArrayList<CellInfo>();
+                arrayCi.add(mCellInfoLte);
+                mPhoneBase.notifyCellInfo(arrayCi);
+            }
+        }
+        return ssChanged;
     }
 
     @Override
@@ -480,6 +594,20 @@ public class CdmaLteServiceStateTracker extends CdmaServiceStateTracker {
         return false;
     }
 
+    /**
+     * @return all available cell information, the returned List maybe empty but never null.
+     */
+    @Override
+    public List<CellInfo> getAllCellInfo() {
+        ArrayList<CellInfo> arrayList = new ArrayList<CellInfo>();
+        CellInfo ci;
+        synchronized(mCellInfo) {
+            arrayList.add(mCellInfoLte);
+        }
+        if (DBG) log ("getAllCellInfo: arrayList=" + arrayList);
+        return arrayList;
+    }
+
     @Override
     protected void log(String s) {
         Log.d(LOG_TAG, "[CdmaLteSST] " + s);