Construct NeighborCell from CellInfo

This change will map calls to getNeighboringCellInfo() to
calls to getAllCellInfo() so that the underlying support
for this API can be removed, and it will only return the
information from getAllCellInfo() which is available to
callers of getNeighboringCellInfo().

Bug: 62490173
Test: tested manually using SL4A with both O-MR1 and current
    target SDKs
Change-Id: Ie39d578929c20e5df8b899bd72e34f26e1cbca11
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index dbfb317..ed9804a 100755
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -54,6 +54,8 @@
 import android.telecom.TelecomManager;
 import android.telephony.CarrierConfigManager;
 import android.telephony.CellInfo;
+import android.telephony.CellInfoGsm;
+import android.telephony.CellInfoWcdma;
 import android.telephony.ClientRequestStats;
 import android.telephony.IccOpenLogicalChannelResponse;
 import android.telephony.LocationAccessPolicy;
@@ -142,8 +144,6 @@
 
     // Message codes used with mMainThreadHandler
     private static final int CMD_HANDLE_PIN_MMI = 1;
-    private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
-    private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
     private static final int CMD_ANSWER_RINGING_CALL = 4;
     private static final int CMD_END_CALL = 5;  // not used yet
     private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
@@ -363,28 +363,6 @@
                     break;
                 }
 
-                case CMD_HANDLE_NEIGHBORING_CELL:
-                    request = (MainThreadRequest) msg.obj;
-                    onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
-                            request);
-                    mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
-                    break;
-
-                case EVENT_NEIGHBORING_CELL_DONE:
-                    ar = (AsyncResult) msg.obj;
-                    request = (MainThreadRequest) ar.userObj;
-                    if (ar.exception == null && ar.result != null) {
-                        request.result = ar.result;
-                    } else {
-                        // create an empty list to notify the waiting thread
-                        request.result = new ArrayList<NeighboringCellInfo>(0);
-                    }
-                    // Wake up the requesting thread
-                    synchronized (request) {
-                        request.notifyAll();
-                    }
-                    break;
-
                 case CMD_ANSWER_RINGING_CALL:
                     request = (MainThreadRequest) msg.obj;
                     int answer_subId = request.subId;
@@ -1933,11 +1911,6 @@
         // FIXME: use the P constant when available
         if (targetSdk > android.os.Build.VERSION_CODES.O_MR1 + 1) return null;
 
-        if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
-                callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
-            return null;
-        }
-
         if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
                 callingPackage) != AppOpsManager.MODE_ALLOWED) {
             return null;
@@ -1945,21 +1918,18 @@
 
         if (DBG_LOC) log("getNeighboringCellInfo: is active user");
 
-        ArrayList<NeighboringCellInfo> cells = null;
+        List<CellInfo> info = getAllCellInfo(callingPackage);
+        if (info == null) return null;
 
-        WorkSource workSource = getWorkSource(Binder.getCallingUid());
-
-        final long identity = Binder.clearCallingIdentity();
-        try {
-            cells = (ArrayList<NeighboringCellInfo>) sendRequest(
-                    CMD_HANDLE_NEIGHBORING_CELL, workSource,
-                    SubscriptionManager.INVALID_SUBSCRIPTION_ID);
-        } catch (RuntimeException e) {
-            Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
-        } finally {
-            Binder.restoreCallingIdentity(identity);
+        List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
+        for (CellInfo ci : info) {
+            if (ci instanceof CellInfoGsm) {
+                neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
+            } else if (ci instanceof CellInfoWcdma) {
+                neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
+            }
         }
-        return cells;
+        return (neighbors.size()) > 0 ? neighbors : null;
     }