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

Commit f4c020d1 authored by Soonil Nagarkar's avatar Soonil Nagarkar
Browse files

Use listener for AntennaInfo

Replace broadcast with listeners in response to API feedback.

Bug: 178714745
Test: atest CtsLocationFineTestCases
Change-Id: Ibb52b167c916fa6b5a9238371ba26b86801389d2
parent 3f9a7c0f
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -19293,8 +19293,8 @@ package android.location {
    method @NonNull public android.location.GnssAntennaInfo.Builder setSignalGainCorrections(@Nullable android.location.GnssAntennaInfo.SphericalCorrections);
  }
  @Deprecated public static interface GnssAntennaInfo.Listener {
    method @Deprecated public void onGnssAntennaInfoReceived(@NonNull java.util.List<android.location.GnssAntennaInfo>);
  public static interface GnssAntennaInfo.Listener {
    method public void onGnssAntennaInfoReceived(@NonNull java.util.List<android.location.GnssAntennaInfo>);
  }
  public static final class GnssAntennaInfo.PhaseCenterOffset implements android.os.Parcelable {
@@ -19683,7 +19683,7 @@ package android.location {
    method public boolean hasProvider(@NonNull String);
    method public boolean isLocationEnabled();
    method public boolean isProviderEnabled(@NonNull String);
    method @Deprecated public boolean registerAntennaInfoListener(@NonNull java.util.concurrent.Executor, @NonNull android.location.GnssAntennaInfo.Listener);
    method public boolean registerAntennaInfoListener(@NonNull java.util.concurrent.Executor, @NonNull android.location.GnssAntennaInfo.Listener);
    method @Deprecated @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) public boolean registerGnssMeasurementsCallback(@NonNull android.location.GnssMeasurementsEvent.Callback);
    method @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) public boolean registerGnssMeasurementsCallback(@NonNull android.location.GnssMeasurementsEvent.Callback, @Nullable android.os.Handler);
    method @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) public boolean registerGnssMeasurementsCallback(@NonNull java.util.concurrent.Executor, @NonNull android.location.GnssMeasurementsEvent.Callback);
@@ -19720,13 +19720,11 @@ package android.location {
    method public void setTestProviderEnabled(@NonNull String, boolean);
    method public void setTestProviderLocation(@NonNull String, @NonNull android.location.Location);
    method @Deprecated public void setTestProviderStatus(@NonNull String, int, @Nullable android.os.Bundle, long);
    method @Deprecated public void unregisterAntennaInfoListener(@NonNull android.location.GnssAntennaInfo.Listener);
    method public void unregisterAntennaInfoListener(@NonNull android.location.GnssAntennaInfo.Listener);
    method public void unregisterGnssMeasurementsCallback(@NonNull android.location.GnssMeasurementsEvent.Callback);
    method public void unregisterGnssNavigationMessageCallback(@NonNull android.location.GnssNavigationMessage.Callback);
    method public void unregisterGnssStatusCallback(@NonNull android.location.GnssStatus.Callback);
    field public static final String ACTION_GNSS_ANTENNA_INFOS_CHANGED = "android.location.action.GNSS_ANTENNA_INFOS_CHANGED";
    field public static final String ACTION_GNSS_CAPABILITIES_CHANGED = "android.location.action.GNSS_CAPABILITIES_CHANGED";
    field public static final String EXTRA_GNSS_ANTENNA_INFOS = "android.location.extra.GNSS_ANTENNA_INFOS";
    field public static final String EXTRA_GNSS_CAPABILITIES = "android.location.extra.GNSS_CAPABILITIES";
    field public static final String EXTRA_LOCATION_ENABLED = "android.location.extra.LOCATION_ENABLED";
    field public static final String EXTRA_PROVIDER_ENABLED = "android.location.extra.PROVIDER_ENABLED";
+0 −4
Original line number Diff line number Diff line
@@ -39,11 +39,7 @@ public final class GnssAntennaInfo implements Parcelable {

    /**
     * Used for receiving GNSS antenna info from the GNSS engine.
     *
     * @deprecated Prefer to use a broadcast receiver for
     * {@link LocationManager#ACTION_GNSS_ANTENNA_INFOS_CHANGED}.
     */
    @Deprecated
    public interface Listener {
        /**
         * Invoked on a change to GNSS antenna info.
+26 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020, 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;

import android.location.GnssAntennaInfo;

/**
 * {@hide}
 */
oneway interface IGnssAntennaInfoListener {
    void onGnssAntennaInfoChanged(in List<GnssAntennaInfo> antennaInfos);
}
+4 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.location.GnssCapabilities;
import android.location.GnssMeasurementCorrections;
import android.location.GnssMeasurementRequest;
import android.location.IGeocodeListener;
import android.location.IGnssAntennaInfoListener;
import android.location.IGnssMeasurementsListener;
import android.location.IGnssStatusListener;
import android.location.IGnssNavigationMessageListener;
@@ -92,6 +93,9 @@ interface ILocationManager
    void addGnssNavigationMessageListener(in IGnssNavigationMessageListener listener, String packageName, @nullable String attributionTag, String listenerId);
    void removeGnssNavigationMessageListener(in IGnssNavigationMessageListener listener);

    void addGnssAntennaInfoListener(in IGnssAntennaInfoListener listener, String packageName, @nullable String attributionTag, String listenerId);
    void removeGnssAntennaInfoListener(in IGnssAntennaInfoListener listener);

    void addProviderRequestListener(in IProviderRequestListener listener);
    void removeProviderRequestListener(in IProviderRequestListener listener);

+26 −50
Original line number Diff line number Diff line
@@ -43,10 +43,8 @@ import android.app.PropertyInvalidatedCache;
import android.compat.Compatibility;
import android.compat.annotation.ChangeId;
import android.compat.annotation.EnabledAfter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.location.provider.IProviderRequestListener;
import android.location.provider.ProviderProperties;
@@ -348,28 +346,6 @@ public class LocationManager {
     */
    public static final String EXTRA_GNSS_CAPABILITIES = "android.location.extra.GNSS_CAPABILITIES";

    /**
     * Broadcast intent action when GNSS antenna infos change. Includes an intent extra,
     * {@link #EXTRA_GNSS_ANTENNA_INFOS}, with an ArrayList of the new {@link GnssAntennaInfo}. This
     * may be read via {@link android.content.Intent#getParcelableArrayListExtra(String)}.
     *
     * @see #EXTRA_GNSS_ANTENNA_INFOS
     * @see #getGnssAntennaInfos()
     */
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    public static final String ACTION_GNSS_ANTENNA_INFOS_CHANGED =
            "android.location.action.GNSS_ANTENNA_INFOS_CHANGED";

    /**
     * Intent extra included with {@link #ACTION_GNSS_ANTENNA_INFOS_CHANGED} broadcasts, containing
     * the new ArrayList of {@link GnssAntennaInfo}. This may be read via
     * {@link android.content.Intent#getParcelableArrayListExtra(String)}.
     *
     * @see #ACTION_GNSS_ANTENNA_INFOS_CHANGED
     */
    public static final String EXTRA_GNSS_ANTENNA_INFOS =
            "android.location.extra.GNSS_ANTENNA_INFOS";

    /**
     * Broadcast intent action for Settings app to inject a footer at the bottom of location
     * settings. This is for use only by apps that are included in the system image.
@@ -2659,10 +2635,11 @@ public class LocationManager {
    }

    /**
     * Registers a GNSS antenna info listener. GNSS antenna info updates will only be received while
     * the {@link #GPS_PROVIDER} is enabled, and while the client app is in the foreground.
     * Registers a GNSS antenna info listener that will receive all changes to antenna info. Use
     * {@link #getGnssAntennaInfos()} to get current antenna info.
     *
     * <p>Not all GNSS chipsets support antenna info updates, see {@link #getGnssCapabilities()}.
     * <p>Not all GNSS chipsets support antenna info updates, see {@link #getGnssCapabilities()}. If
     * unsupported, the listener will never be invoked.
     *
     * <p>Prior to Android S, this requires the {@link Manifest.permission#ACCESS_FINE_LOCATION}
     * permission.
@@ -2673,10 +2650,7 @@ public class LocationManager {
     *
     * @throws IllegalArgumentException if executor is null
     * @throws IllegalArgumentException if listener is null
     *
     * @deprecated Prefer to use a receiver for {@link #ACTION_GNSS_ANTENNA_INFOS_CHANGED}.
     */
    @Deprecated
    public boolean registerAntennaInfoListener(
            @NonNull @CallbackExecutor Executor executor,
            @NonNull GnssAntennaInfo.Listener listener) {
@@ -2686,13 +2660,10 @@ public class LocationManager {
    }

    /**
     * Unregisters a GNSS Antenna Info listener.
     * Unregisters a GNSS antenna info listener.
     *
     * @param listener a {@link GnssAntennaInfo.Listener} object to remove
     *
     * @deprecated Prefer to use a receiver for {@link #ACTION_GNSS_ANTENNA_INFOS_CHANGED}.
     */
    @Deprecated
    public void unregisterAntennaInfoListener(@NonNull GnssAntennaInfo.Listener listener) {
        GnssLazyLoader.sGnssAntennaInfoListeners.removeListener(listener);
    }
@@ -3009,14 +2980,17 @@ public class LocationManager {
        }

        @Override
        protected void registerTransport(GnssAntennaInfoTransport transport) {
            transport.getContext().registerReceiver(transport,
                    new IntentFilter(ACTION_GNSS_ANTENNA_INFOS_CHANGED));
        protected void registerTransport(GnssAntennaInfoTransport transport)
                throws RemoteException {
            getService().addGnssAntennaInfoListener(transport, transport.getPackage(),
                    transport.getAttributionTag(),
                    AppOpsManager.toReceiverId(transport.getListener()));
        }

        @Override
        protected void unregisterTransport(GnssAntennaInfoTransport transport) {
            transport.getContext().unregisterReceiver(transport);
        protected void unregisterTransport(GnssAntennaInfoTransport transport)
                throws RemoteException {
            getService().removeGnssAntennaInfoListener(transport);
        }
    }

@@ -3376,11 +3350,12 @@ public class LocationManager {
        }
    }

    private static class GnssAntennaInfoTransport extends BroadcastReceiver implements
    private static class GnssAntennaInfoTransport extends IGnssAntennaInfoListener.Stub implements
            ListenerTransport<GnssAntennaInfo.Listener> {

        private final Executor mExecutor;
        private final Context mContext;
        private final String mPackageName;
        private final String mAttributionTag;

        private volatile @Nullable GnssAntennaInfo.Listener mListener;

@@ -3389,12 +3364,17 @@ public class LocationManager {
            Preconditions.checkArgument(executor != null, "invalid null executor");
            Preconditions.checkArgument(listener != null, "invalid null listener");
            mExecutor = executor;
            mContext = context;
            mPackageName = context.getPackageName();
            mAttributionTag = context.getAttributionTag();
            mListener = listener;
        }

        public Context getContext() {
            return mContext;
        public String getPackage() {
            return mPackageName;
        }

        public String getAttributionTag() {
            return mAttributionTag;
        }

        @Override
@@ -3408,12 +3388,8 @@ public class LocationManager {
        }

        @Override
        public void onReceive(Context context, Intent intent) {
            ArrayList<GnssAntennaInfo> infos = intent.getParcelableArrayListExtra(
                    EXTRA_GNSS_ANTENNA_INFOS);
            if (infos != null) {
                execute(mExecutor, callback -> callback.onGnssAntennaInfoReceived(infos));
            }
        public void onGnssAntennaInfoChanged(List<GnssAntennaInfo> antennaInfos) {
            execute(mExecutor, callback -> callback.onGnssAntennaInfoReceived(antennaInfos));
        }
    }

Loading