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

Commit 7b20d435 authored by Dante Russo's avatar Dante Russo Committed by Luca Stefani
Browse files

NLP Combo feature

If Combo Provider is listening for network
locations, it will want to screen these locations
before they are sent out to clients.

Get the package name for combo provider from resouce
instead of hardcoding the name. Also, geofence services
provider is renamed to differentiate from the hal
geofence provider

Only screen network locations if Combo provider is
the connected network location provider.

Resolved issue where MockProvider was being cast to
LocationProviderProxy and would cause a fatal exception

CRs-fixed: 483398, 608477, 619882

Change-Id: I3156e85307b40aee9fb06b433c83153c84b8ed42
parent 22c9c67a
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -1733,6 +1733,9 @@
        -->
    </string-array>

    <!-- Component name of the combo network location provider. -->
    <string name="config_comboNetworkLocationProvider" translatable="false">com.qualcomm.location</string>

    <!-- Boolean indicating if current platform supports bluetooth SCO for off call
    use cases -->
    <bool name="config_bluetooth_sco_off_call">true</bool>
+1 −0
Original line number Diff line number Diff line
@@ -2025,6 +2025,7 @@
  <java-symbol type="string" name="config_geocoderProviderPackageName" />
  <java-symbol type="string" name="config_geofenceProviderPackageName" />
  <java-symbol type="string" name="config_networkLocationProviderPackageName" />
  <java-symbol type="string" name="config_comboNetworkLocationProvider" />
  <java-symbol type="string" name="config_wimaxManagerClassname" />
  <java-symbol type="string" name="config_wimaxNativeLibLocation" />
  <java-symbol type="string" name="config_wimaxServiceClassname" />
+78 −0
Original line number Diff line number Diff line
@@ -171,6 +171,9 @@ public class LocationManagerService extends ILocationManager.Stub {
    private LocationFudger mLocationFudger;
    private GeofenceManager mGeofenceManager;
    private PackageManager mPackageManager;
    private String mComboNlpPackageName;
    private String mComboNlpReadyMarker;
    private String mComboNlpScreenMarker;
    private PowerManager mPowerManager;
    private ActivityManager mActivityManager;
    private UserManager mUserManager;
@@ -711,6 +714,13 @@ public class LocationManagerService extends ILocationManager.Stub {
            Slog.d(TAG, "Unable to bind ActivityRecognitionProxy.");
        }

        mComboNlpPackageName = resources.getString(
                com.android.internal.R.string.config_comboNetworkLocationProvider);
        if (mComboNlpPackageName != null) {
            mComboNlpReadyMarker = mComboNlpPackageName + ".nlp:ready";
            mComboNlpScreenMarker = mComboNlpPackageName + ".nlp:screen";
        }

        String[] testProviderStrings = resources.getStringArray(
                com.android.internal.R.array.config_testLocationProviders);
        for (String testProviderString : testProviderStrings) {
@@ -3030,6 +3040,70 @@ public class LocationManagerService extends ILocationManager.Stub {
        synchronized (mLock) {
            return mMockProviders.containsKey(provider);
        }

    }

    private Location screenLocationLocked(Location location, String provider) {
        if (isMockProvider(LocationManager.NETWORK_PROVIDER)) {
            return location;
        }
        LocationProviderProxy providerProxy =
                (LocationProviderProxy) mProvidersByName.get(LocationManager.NETWORK_PROVIDER);
        if (mComboNlpPackageName == null || providerProxy == null ||
                !provider.equals(LocationManager.NETWORK_PROVIDER) ||
                isMockProvider(LocationManager.NETWORK_PROVIDER)) {
            return location;
        }

        String connectedNlpPackage = providerProxy.getConnectedPackageName();
        if (connectedNlpPackage == null || !connectedNlpPackage.equals(mComboNlpPackageName)) {
            return location;
        }

        Bundle extras = location.getExtras();
        boolean isBeingScreened = false;
        if (extras == null) {
            extras = new Bundle();
        }

        if (!extras.containsKey(mComboNlpReadyMarker)) {
            // see if Combo Nlp is a passive listener
            ArrayList<UpdateRecord> records =
                    mRecordsByProvider.get(LocationManager.PASSIVE_PROVIDER);
            if (records != null) {
                for (UpdateRecord r : records) {
                    if (r.mReceiver.mIdentity.mPackageName.equals(mComboNlpPackageName)) {
                        if (!isBeingScreened) {
                            isBeingScreened = true;
                            extras.putBoolean(mComboNlpScreenMarker, true);
                        }
                        // send location to Combo Nlp for screening
                        if (!r.mReceiver.callLocationChangedLocked(location)) {
                            Slog.w(TAG, "RemoteException calling onLocationChanged on "
                                   + r.mReceiver);
                        } else {
                            if (D) {
                                Log.d(TAG, "Sending location for screening");
                            }
                        }
                    }
                }
            }
            if (isBeingScreened) {
                return null;
            }
            if (D) {
                Log.d(TAG, "Not screening locations");
            }
        } else {
            if (D) {
                Log.d(TAG, "This location is marked as ready for broadcast");
            }
            // clear the ready marker
            extras.remove(mComboNlpReadyMarker);
        }

        return location;
    }

    private void handleLocationChanged(Location location, boolean passive) {
@@ -3048,6 +3122,10 @@ public class LocationManagerService extends ILocationManager.Stub {
        synchronized (mLock) {
            if (isAllowedByCurrentUserSettingsLocked(provider)) {
                if (!passive) {
                    location = screenLocationLocked(location, provider);
                    if (location == null) {
                        return;
                    }
                    // notify passive provider of the new location
                    mPassiveProvider.updateLocation(myLocation);
                }