Improved locale tracker logging

The excessive cell info update can flood locale tracker
local log and caused important messages lost. Now we only
log the cell info when its cell identity changes.

Test: Manual
Bug: 119896432
Change-Id: If67f28e0df0899829822fc1b606dfdbf7462517d
diff --git a/src/java/com/android/internal/telephony/LocaleTracker.java b/src/java/com/android/internal/telephony/LocaleTracker.java
index d582762..b6d2871 100755
--- a/src/java/com/android/internal/telephony/LocaleTracker.java
+++ b/src/java/com/android/internal/telephony/LocaleTracker.java
@@ -100,7 +100,7 @@
 
     /** Current cell tower information */
     @Nullable
-    private List<CellInfo> mCellInfo;
+    private List<CellInfo> mCellInfoList;
 
     /** Count of invalid cell info we've got so far. Will reset once we get a successful one */
     private int mFailCellInfoCount;
@@ -146,14 +146,14 @@
             case EVENT_UNSOL_CELL_INFO:
                 processCellInfo((AsyncResult) msg.obj);
                 // If the unsol happened to be useful, use it; otherwise, pretend it didn't happen.
-                if (mCellInfo != null && mCellInfo.size() > 0) requestNextCellInfo(true);
+                if (mCellInfoList != null && mCellInfoList.size() > 0) requestNextCellInfo(true);
                 break;
 
             case EVENT_RESPONSE_CELL_INFO:
                 processCellInfo((AsyncResult) msg.obj);
                 // If the cellInfo was non-empty then it's business as usual. Either way, this
                 // cell info was requested by us, so it's our trigger to schedule another one.
-                requestNextCellInfo(mCellInfo != null && mCellInfo.size() > 0);
+                requestNextCellInfo(mCellInfoList != null && mCellInfoList.size() > 0);
                 break;
 
             case EVENT_SERVICE_STATE_CHANGED:
@@ -209,10 +209,10 @@
     @Nullable
     private String getMccFromCellInfo() {
         String selectedMcc = null;
-        if (mCellInfo != null) {
+        if (mCellInfoList != null) {
             Map<String, Integer> countryCodeMap = new HashMap<>();
             int maxCount = 0;
-            for (CellInfo cellInfo : mCellInfo) {
+            for (CellInfo cellInfo : mCellInfoList) {
                 String mcc = null;
                 if (cellInfo instanceof CellInfoGsm) {
                     mcc = ((CellInfoGsm) cellInfo).getCellIdentity().getMccString();
@@ -281,13 +281,28 @@
 
     private void processCellInfo(AsyncResult ar) {
         if (ar == null || ar.exception != null) {
-            mCellInfo = null;
+            mCellInfoList = null;
             return;
         }
-        mCellInfo = (List<CellInfo>) ar.result;
-        String msg = "getCellInfo: cell info=" + mCellInfo;
+        List<CellInfo> cellInfoList = (List<CellInfo>) ar.result;
+        String msg = "getCellInfo: cell info=" + cellInfoList;
         if (DBG) log(msg);
-        mLocalLog.log(msg);
+        if (cellInfoList != null) {
+            // We only log when cell identity changes, otherwise the local log is flooded with cell
+            // info.
+            if (mCellInfoList == null || cellInfoList.size() != mCellInfoList.size()) {
+                mLocalLog.log(msg);
+            } else {
+                for (int i = 0; i < cellInfoList.size(); i++) {
+                    if (!Objects.equals(mCellInfoList.get(i).getCellIdentity(),
+                            cellInfoList.get(i).getCellIdentity())) {
+                        mLocalLog.log(msg);
+                        break;
+                    }
+                }
+            }
+        }
+        mCellInfoList = cellInfoList;
         updateLocale();
     }
 
@@ -355,7 +370,7 @@
         String msg = "Stopping LocaleTracker";
         if (DBG) log(msg);
         mLocalLog.log(msg);
-        mCellInfo = null;
+        mCellInfoList = null;
         resetCellInfoRetry();
     }
 
@@ -392,12 +407,11 @@
             countryIso = MccTable.countryCodeForMcc(mcc);
         }
 
-        String msg = "updateLocale: mcc = " + mcc + ", country = " + countryIso;
-        log(msg);
-        mLocalLog.log(msg);
+        log("updateLocale: mcc = " + mcc + ", country = " + countryIso);
         boolean countryChanged = false;
         if (!Objects.equals(countryIso, mCurrentCountryIso)) {
-            msg = "updateLocale: Change the current country to " + countryIso;
+            String msg = "updateLocale: Change the current country to \"" + countryIso
+                    + "\", mcc = " + mcc;
             log(msg);
             mLocalLog.log(msg);
             mCurrentCountryIso = countryIso;
@@ -447,7 +461,7 @@
         ipw.println("mIsTracking = " + mIsTracking);
         ipw.println("mOperatorNumeric = " + mOperatorNumeric);
         ipw.println("mSimState = " + mSimState);
-        ipw.println("mCellInfo = " + mCellInfo);
+        ipw.println("mCellInfoList = " + mCellInfoList);
         ipw.println("mCurrentCountryIso = " + mCurrentCountryIso);
         ipw.println("mFailCellInfoCount = " + mFailCellInfoCount);
         ipw.println("Local logs:");