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

Commit 5e7ecaa8 authored by Nathan Harold's avatar Nathan Harold
Browse files

Make getAllCellInfo Asynchronous

Update the getAllCellInfo() call to be asynchronous
and support multiple modes. This enables us to add
asynchronous API support in TelephonyManager for
CellInfo and prepares us to deprecate CellLocation.

This also centralizes and homgenizes the behavior of
CellInfo, fixing some of the threading problems with
these APIs. The new behavior is as follows:

-Now whenever the getAllCellInfo() cache is updated
 in the SST, it will invoke the PhoneStateListener
 for all listeners of LISTEN_CELL_INFO.

-getAllCellInfo() now supports a Message parameter
 much like many other invocations on the Phone object.
   -This version is void, so it's unambiguous that
    this version is asynchronous.
   -If a Message object is provided, then the updated
    cell info will be posted as an AsyncResult in the
    message once the response is received from the
    radio.
   -If the message object is null, then the call will
    still query the modem and update the writethrough
    cache in SST and trigger the PhoneStateListener.

-There is now an overload for getAllCellInfo() to
 support synchronous calls on the same thread, which
 will ONLY return the cached value in SST and never
 calls down to the radio. This avoids calls to the
 same method having inconsistent behavior based on
 the calling context.

-getCellLocation() has been updated to use the new
 asynchronous version of getAllCellInfo() to support
 the legacy behavior that queries CellInfo when the
 device isn't registered and location is requested.
 Thus, this method is now also asynchronous, so that
 it is unambigous when calls *may* be made down to
 the modem.

-There is now a synchronous version of getCellLocation
 which will return the cached value in SST
 or attempt to get a cached value from CellInfo stored
 in SST if there is no valid CellIdentity.

Bug: 37100068
Test: atest FrameworksTelephonyTests

Change-Id: I52cd652b350733991bae1457ec07ad1414c5d1dd
parent 62de98e1
Loading
Loading
Loading
Loading
+3 −2
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@ import android.os.Bundle;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.ServiceManager;
import android.telephony.CellInfo;
import android.telephony.CellInfo;
import android.telephony.CellLocation;
import android.telephony.PhoneCapability;
import android.telephony.PhoneCapability;
import android.telephony.PhysicalChannelConfig;
import android.telephony.PhysicalChannelConfig;
import android.telephony.PreciseCallState;
import android.telephony.PreciseCallState;
@@ -208,10 +209,10 @@ public class DefaultPhoneNotifier implements PhoneNotifier {
    }
    }


    @Override
    @Override
    public void notifyCellLocation(Phone sender) {
    public void notifyCellLocation(Phone sender, CellLocation cl) {
        int subId = sender.getSubId();
        int subId = sender.getSubId();
        Bundle data = new Bundle();
        Bundle data = new Bundle();
        sender.getCellLocation().fillInNotifierBundle(data);
        cl.fillInNotifierBundle(data);
        try {
        try {
            if (mRegistry != null) {
            if (mRegistry != null) {
                mRegistry.notifyCellLocationForSubscriber(subId, data);
                mRegistry.notifyCellLocationForSubscriber(subId, data);
+9 −9
Original line number Original line Diff line number Diff line
@@ -66,8 +66,6 @@ import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.TelephonyManager;
import android.telephony.UssdResponse;
import android.telephony.UssdResponse;
import android.telephony.cdma.CdmaCellLocation;
import android.telephony.gsm.GsmCellLocation;
import android.text.TextUtils;
import android.text.TextUtils;
import android.util.Log;
import android.util.Log;


@@ -434,11 +432,8 @@ public class GsmCdmaPhone extends Phone {
    }
    }


    @Override
    @Override
    public CellLocation getCellLocation(WorkSource workSource) {
    public void getCellLocation(WorkSource workSource, Message rspMsg) {
        CellLocation l = mSST.getCellLocation(workSource);
        mSST.requestCellLocation(workSource, rspMsg);
        if (l != null) return l;
        if (getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) return new CdmaCellLocation();
        return new GsmCellLocation();
    }
    }


    @Override
    @Override
@@ -653,8 +648,13 @@ public class GsmCdmaPhone extends Phone {
        super.notifyServiceStateChangedP(ss);
        super.notifyServiceStateChangedP(ss);
    }
    }


    public void notifyLocationChanged() {
    /**
        mNotifier.notifyCellLocation(this);
     * Notify that the CellLocation has changed.
     *
     * @param cl the new CellLocation
     */
    public void notifyLocationChanged(CellLocation cl) {
        mNotifier.notifyCellLocation(this, cl);
    }
    }


    @Override
    @Override
+2 −3
Original line number Original line Diff line number Diff line
@@ -338,9 +338,8 @@ public class LocaleTracker extends Handler {
            return;
            return;
        }
        }


        // Get all cell info. Passing null to use default worksource, which indicates the original
        // FIXME: This needs to use the async version of getAllCellInfo()
        // request is from telephony internally.
        mCellInfo = mPhone.getAllCellInfo();
        mCellInfo = mPhone.getAllCellInfo(null);
        msg = "getCellInfo: cell info=" + mCellInfo;
        msg = "getCellInfo: cell info=" + mCellInfo;
        if (DBG) log(msg);
        if (DBG) log(msg);
        mLocalLog.log(msg);
        mLocalLog.log(msg);
+23 −41
Original line number Original line Diff line number Diff line
@@ -41,9 +41,7 @@ import android.provider.Settings;
import android.service.carrier.CarrierIdentifier;
import android.service.carrier.CarrierIdentifier;
import android.telecom.VideoProfile;
import android.telecom.VideoProfile;
import android.telephony.CarrierConfigManager;
import android.telephony.CarrierConfigManager;
import android.telephony.CellIdentityCdma;
import android.telephony.CellInfo;
import android.telephony.CellInfo;
import android.telephony.CellInfoCdma;
import android.telephony.CellLocation;
import android.telephony.CellLocation;
import android.telephony.ClientRequestStats;
import android.telephony.ClientRequestStats;
import android.telephony.ImsiEncryptionInfo;
import android.telephony.ImsiEncryptionInfo;
@@ -1690,50 +1688,34 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
        return (r != null) ? r.getRecordsLoaded() : false;
        return (r != null) ? r.getRecordsLoaded() : false;
    }
    }


    /**
     * @return the last known CellInfo
     */
    public List<CellInfo> getAllCellInfo() {
        return getServiceStateTracker().getAllCellInfo();
    }

    /**
    /**
     * @param workSource calling WorkSource
     * @param workSource calling WorkSource
     * @return all available cell information or null if none.
     * @param rspMsg the response message containing the cell info
     */
     */
    public List<CellInfo> getAllCellInfo(WorkSource workSource) {
    public void getAllCellInfo(WorkSource workSource, Message rspMsg) {
        List<CellInfo> cellInfoList = getServiceStateTracker().getAllCellInfo(workSource);
        getServiceStateTracker().requestAllCellInfo(workSource, rspMsg);
        return privatizeCellInfoList(cellInfoList);
    }
    }


    /**
     * @return the current cell location if known
     */
    public CellLocation getCellLocation() {
    public CellLocation getCellLocation() {
        return getCellLocation(null);
        return getServiceStateTracker().getCellLocation();
    }

    /**
     * Clear CDMA base station lat/long values if location setting is disabled.
     * @param cellInfoList the original cell info list from the RIL
     * @return the original list with CDMA lat/long cleared if necessary
     */
    private List<CellInfo> privatizeCellInfoList(List<CellInfo> cellInfoList) {
        if (cellInfoList == null) return null;
        int mode = Settings.Secure.getInt(getContext().getContentResolver(),
                Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_OFF);
        if (mode == Settings.Secure.LOCATION_MODE_OFF) {
            ArrayList<CellInfo> privateCellInfoList = new ArrayList<CellInfo>(cellInfoList.size());
            // clear lat/lon values for location privacy
            for (CellInfo c : cellInfoList) {
                if (c instanceof CellInfoCdma) {
                    CellInfoCdma cellInfoCdma = (CellInfoCdma) c;
                    CellIdentityCdma cellIdentity = cellInfoCdma.getCellIdentity();
                    CellIdentityCdma maskedCellIdentity = new CellIdentityCdma(
                            cellIdentity.getNetworkId(),
                            cellIdentity.getSystemId(),
                            cellIdentity.getBasestationId(),
                            Integer.MAX_VALUE, Integer.MAX_VALUE);
                    CellInfoCdma privateCellInfoCdma = new CellInfoCdma(cellInfoCdma);
                    privateCellInfoCdma.setCellIdentity(maskedCellIdentity);
                    privateCellInfoList.add(privateCellInfoCdma);
                } else {
                    privateCellInfoList.add(c);
    }
    }
            }

            cellInfoList = privateCellInfoList;
    /**
        }
     * @param workSource calling WorkSource
        return cellInfoList;
     * @param rspMsg the response message containing the cell location
     */
    public void getCellLocation(WorkSource workSource, Message rspMsg) {
        getServiceStateTracker().requestCellLocation(workSource, rspMsg);
    }
    }


    /**
    /**
@@ -2195,7 +2177,7 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
    }
    }


    public void notifyCellInfo(List<CellInfo> cellInfo) {
    public void notifyCellInfo(List<CellInfo> cellInfo) {
        mNotifier.notifyCellInfo(this, privatizeCellInfoList(cellInfo));
        mNotifier.notifyCellInfo(this, cellInfo);
    }
    }


    /** Notify {@link PhysicalChannelConfig} changes. */
    /** Notify {@link PhysicalChannelConfig} changes. */
+0 −8
Original line number Original line Diff line number Diff line
@@ -21,9 +21,7 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.Handler;
import android.os.Message;
import android.os.Message;
import android.os.ResultReceiver;
import android.os.ResultReceiver;
import android.os.WorkSource;
import android.telecom.VideoProfile;
import android.telecom.VideoProfile;
import android.telephony.CellLocation;
import android.telephony.ImsiEncryptionInfo;
import android.telephony.ImsiEncryptionInfo;
import android.telephony.NetworkScanRequest;
import android.telephony.NetworkScanRequest;
import android.telephony.ServiceState;
import android.telephony.ServiceState;
@@ -255,12 +253,6 @@ public interface PhoneInternalInterface {
     */
     */
    ServiceState getServiceState();
    ServiceState getServiceState();


    /**
     * Get the current CellLocation.
     * @param workSource calling WorkSource
     */
    CellLocation getCellLocation(WorkSource workSource);

    /**
    /**
     * Get the current DataState. No change notification exists at this
     * Get the current DataState. No change notification exists at this
     * interface -- use
     * interface -- use
Loading