Implement the new requestNetworkScan API with current modem API.

Test: Telephony sanity tests
Bug: 30954762

Merged-in: Id4ec30c5ca670393b1f83adfeb46fef938faf9e9
Change-Id: Id4ec30c5ca670393b1f83adfeb46fef938faf9e9
(cherry picked from commit b1bed745159e5db8fc40de06dc2c0762cbee0be6)
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index 3b2ffc6..0a1d073 100644
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -38,8 +38,8 @@
 import android.os.Looper;
 import android.os.Message;
 import android.os.Messenger;
-import android.os.Process;
 import android.os.PersistableBundle;
+import android.os.Process;
 import android.os.ResultReceiver;
 import android.os.ServiceManager;
 import android.os.UserHandle;
@@ -86,6 +86,7 @@
 import com.android.internal.telephony.ITelephony;
 import com.android.internal.telephony.IccCard;
 import com.android.internal.telephony.MccTable;
+import com.android.internal.telephony.NetworkScanRequestTracker;
 import com.android.internal.telephony.OperatorInfo;
 import com.android.internal.telephony.Phone;
 import com.android.internal.telephony.PhoneConstantConversions;
@@ -192,6 +193,8 @@
     private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
     private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
 
+    private NetworkScanRequestTracker mNetworkScanRequestTracker;
+
     /**
      * A request object to use for transmitting data to an ICC.
      */
@@ -1054,6 +1057,7 @@
         mTelephonySharedPreferences =
                 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
         mSubscriptionController = SubscriptionController.getInstance();
+        mNetworkScanRequestTracker = new NetworkScanRequestTracker();
 
         publish();
     }
@@ -2676,24 +2680,32 @@
     }
 
     /**
-     * Performs a new network scan and returns the id of this scan.
+     * Starts a new network scan and returns the id of this scan.
      *
+     * @param subId id of the subscription
+     * @param request contains the radio access networks with bands/channels to scan
+     * @param messenger callback messenger for scan results or errors
+     * @param binder for the purpose of auto clean when the user thread crashes
      * @return the id of the requested scan which can be used to stop the scan.
      */
     @Override
     public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
             IBinder binder) {
-        // TODO(yinxu): Implement this method.
-        throw new UnsupportedOperationException("To be implemented...");
+        enforceModifyPermissionOrCarrierPrivilege(subId);
+        return mNetworkScanRequestTracker.startNetworkScan(
+                request, messenger, binder, getPhone(subId));
     }
 
     /**
      * Stops an existing network scan with the given scanId.
+     *
+     * @param subId id of the subscription
+     * @param scanId id of the scan that needs to be stopped
      */
     @Override
     public void stopNetworkScan(int subId, int scanId) {
-        // TODO(yinxu): Implement this method.
-        throw new UnsupportedOperationException("To be implemented...");
+        enforceModifyPermissionOrCarrierPrivilege(subId);
+        mNetworkScanRequestTracker.stopNetworkScan(scanId);
     }
 
     /**