Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7184bedd authored by Hall Liu's avatar Hall Liu Committed by Gerrit Code Review
Browse files

Merge "Add location checks to NetworkScanRequestTracker"

parents a4191860 6095ce4c
Loading
Loading
Loading
Loading
+30 −7
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import static android.telephony.AccessNetworkConstants.AccessNetworkType.UTRAN;
import android.hardware.radio.V1_0.RadioError;
import android.os.AsyncResult;
import android.os.Binder;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
@@ -31,6 +32,7 @@ import android.os.Messenger;
import android.os.Process;
import android.os.RemoteException;
import android.telephony.CellInfo;
import android.telephony.LocationAccessPolicy;
import android.telephony.NetworkScan;
import android.telephony.NetworkScanRequest;
import android.telephony.RadioAccessSpecifier;
@@ -194,9 +196,11 @@ public final class NetworkScanRequestTracker {
        private final int mScanId;
        private final int mUid;
        private final int mPid;
        private final String mCallingPackage;
        private boolean mIsBinderDead;

        NetworkScanRequestInfo(NetworkScanRequest r, Messenger m, IBinder b, int id, Phone phone) {
        NetworkScanRequestInfo(NetworkScanRequest r, Messenger m, IBinder b, int id, Phone phone,
                String callingPackage) {
            super();
            mRequest = r;
            mMessenger = m;
@@ -205,6 +209,7 @@ public final class NetworkScanRequestTracker {
            mPhone = phone;
            mUid = Binder.getCallingUid();
            mPid = Binder.getCallingPid();
            mCallingPackage = callingPackage;
            mIsBinderDead = false;

            try {
@@ -372,20 +377,36 @@ public final class NetworkScanRequestTracker {
                Log.e(TAG, "EVENT_RECEIVE_NETWORK_SCAN_RESULT: nsri is null");
                return;
            }
            LocationAccessPolicy.LocationPermissionQuery locationQuery =
                    new LocationAccessPolicy.LocationPermissionQuery.Builder()
                    .setCallingPackage(nsri.mCallingPackage)
                    .setCallingPid(nsri.mPid)
                    .setCallingUid(nsri.mUid)
                    .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
                    .setMethod("NetworkScanTracker#onResult")
                    .build();
            if (ar.exception == null && ar.result != null) {
                NetworkScanResult nsr = (NetworkScanResult) ar.result;
                if (nsr.scanError == NetworkScan.SUCCESS) {
                    if (LocationAccessPolicy.checkLocationPermission(
                            nsri.mPhone.getContext(), locationQuery)
                            == LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
                        notifyMessenger(nsri, TelephonyScanManager.CALLBACK_SCAN_RESULTS,
                                rilErrorToScanError(nsr.scanError), nsr.networkInfos);
                    }
                    if (nsr.scanStatus == NetworkScanResult.SCAN_STATUS_COMPLETE) {
                        deleteScanAndMayNotify(nsri, NetworkScan.SUCCESS, true);
                        nsri.mPhone.mCi.unregisterForNetworkScanResult(mHandler);
                    }
                } else {
                    if (nsr.networkInfos != null) {
                        if (LocationAccessPolicy.checkLocationPermission(
                                nsri.mPhone.getContext(), locationQuery)
                                == LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
                            notifyMessenger(nsri, TelephonyScanManager.CALLBACK_SCAN_RESULTS,
                                    NetworkScan.SUCCESS, nsr.networkInfos);
                        }
                    }
                    deleteScanAndMayNotify(nsri, rilErrorToScanError(nsr.scanError), true);
                    nsri.mPhone.mCi.unregisterForNetworkScanResult(mHandler);
                }
@@ -535,10 +556,12 @@ public final class NetworkScanRequestTracker {
     * returned to the user, no matter how this scan will be actually handled.
     */
    public int startNetworkScan(
            NetworkScanRequest request, Messenger messenger, IBinder binder, Phone phone) {
            NetworkScanRequest request, Messenger messenger, IBinder binder, Phone phone,
            String callingPackage) {
        int scanId = mNextNetworkScanRequestId.getAndIncrement();
        NetworkScanRequestInfo nsri =
                new NetworkScanRequestInfo(request, messenger, binder, scanId, phone);
                new NetworkScanRequestInfo(request, messenger, binder, scanId, phone,
                        callingPackage);
        // nsri will be stored as Message.obj
        mHandler.obtainMessage(CMD_START_NETWORK_SCAN, nsri).sendToTarget();
        return scanId;