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

Commit 4f699aab authored by Ludovic Barman's avatar Ludovic Barman
Browse files

Add PopulationDensityProvider

This change adds the concept of population density providers in AOSP. It allows the framework to query the population density at a given location. Internally, this is backed by a new type of Provider, following the current conventions in the location package. There is no app-facing change, only the LocationManagerService will access this provider (see other CLs in the topic).

Because the provider will be implemented by Play Services (or OEM implementations), we add a proxy mechanism identical to the current ProxyLocationProvider, which reads the config.xml and instantiates the correct provider.

The core of the change is IPopulationDensityProvider.aidl.

In details:
- We add a new IPopulationDensityProvider IDL with its associated implementation PopulationDensityProviderBase.
- We add the IDL for two callback type for the S2CellId and the default coarsening level.
- We change the LocationManagerService to instantiate a ProxyPopulationDensityProvider.
- This ProxyPopulationDensityProvider creates the correct provider given the XML config.

Tests:
- atest CtsLocationNoneTestCases:PopulationDensityProviderBaseTest
- atest FrameworksMockingServicesTests:LocationManagerServiceTest

NB: I also did a manual test by implementing a fake provider and querying it, this works on Pixel 7 pro, see linked commits with topic "population-density-provider-test-dns"

Test: manual atest on Pixel 7 pro (see above)
Bug: 376198890
Flag: android.location.flags.population_density_provider
Change-Id: I90663d478200c734abbf5f442dfb1bb8bb79a875
parent cd0151ce
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -2174,6 +2174,16 @@
        <item>com.android.location.fused</item>
    </string-array>

    <!-- Package name providing population density location support. -->
    <string name="config_populationDensityProviderPackageName" translatable="false">com.android.location.populationdensity</string>

    <!-- Whether to enable population density provider overlay, which allows the population density provider to
         be replaced by an app at run-time. When disabled, only the
         config_populationDensityProviderPackageName package will be searched for a population density
         provider, otherwise any system package is eligible. Anyone who wants to disable the overlay
         mechanism can set it to false. -->
    <bool name="config_enablePopulationDensityProviderOverlay" translatable="false">true</bool>

   <!-- Package name of the extension software fallback. -->
    <string name="config_extensionFallbackPackageName" translatable="false"></string>

+2 −0
Original line number Diff line number Diff line
@@ -2012,6 +2012,8 @@
  <java-symbol type="array" name="config_locationProviderPackageNames" />
  <java-symbol type="array" name="config_locationDriverAssistancePackageNames" />
  <java-symbol type="array" name="config_locationExtraPackageNames" />
  <java-symbol type="string" name="config_populationDensityProviderPackageName" />
  <java-symbol type="bool" name="config_enablePopulationDensityProviderOverlay" />
  <java-symbol type="array" name="config_testLocationProviders" />
  <java-symbol type="array" name="config_defaultNotificationVibePattern" />
  <java-symbol type="array" name="config_defaultNotificationVibeWaveform" />
+8 −0
Original line number Diff line number Diff line
@@ -642,6 +642,14 @@ package android.location.provider {
    method public void onFlushComplete();
  }

  @FlaggedApi("android.location.flags.population_density_provider") public abstract class PopulationDensityProviderBase {
    ctor public PopulationDensityProviderBase(@NonNull android.content.Context, @NonNull String);
    method @Nullable public final android.os.IBinder getBinder();
    method public abstract void onGetCoarsenedS2Cell(double, double, @NonNull android.os.OutcomeReceiver<long[],java.lang.Throwable>);
    method public abstract void onGetDefaultCoarseningLevel(@NonNull android.os.OutcomeReceiver<java.lang.Integer,java.lang.Throwable>);
    field public static final String ACTION_POPULATION_DENSITY_PROVIDER = "com.android.location.service.PopulationDensityProvider";
  }

  public final class ProviderRequest implements android.os.Parcelable {
    method public int describeContents();
    method @IntRange(from=0) public long getIntervalMillis();
+45 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.location.provider;

import android.os.Bundle;

import android.location.Location;
import android.location.provider.IS2CellIdsCallback;
import android.location.provider.IS2LevelCallback;

/**
 * Binder interface for services that implement a population density provider. Do not implement this
 * directly, extend {@link PopulationDensityProviderBase} instead.
 * @hide
 */
oneway interface IPopulationDensityProvider {
    /**
     * Gets the default S2 level to be used to coarsen any location, in case a more precise answer
     * from the method below can't be obtained.
     */
    void getDefaultCoarseningLevel(in IS2LevelCallback callback);

    /**
     * Returns a list of IDs of the S2 cells to be used to coarsen a location. The answer should
     * contain at least one S2 cell, which should contain the requested location. Its level
     * represents the population density. Optionally, additional nearby cells can be also returned,
     * to assist in coarsening nearby locations.
     */
    void getCoarsenedS2Cell(double latitudeDegrees, double longitudeDegrees, in IS2CellIdsCallback
        callback);
}
+36 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.location.provider;

import android.location.Location;

/**
 * Binder interface for S2 cell IDs callbacks.
 * @hide
 */
oneway interface IS2CellIdsCallback {

    /**
     * Called with the resulting list of S2 cell IDs. The first cell is expected to contain
     * the requested latitude/longitude. Its level represent the population density. Optionally,
     * the list can also contain additional nearby cells.
     */
    void onResult(in long[] s2CellIds);

    /** Called if any error occurs while processing the query. */
    void onError();
}
Loading