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

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

Assorted cleanup and refactoring

Will minimize future changes:
-Never return null GpsStatus to avoid breaking legacy clients
-Allow null location callback complete callbacks
-Return void from sendExtraCommand
-Combine appops and permissions checks into a single helper
-Allow passive provider to remember last locations even when there is
no active passive request.
-Add a couple new injectable helpers to support future changes along
with fakes for testing.

Test: presubmits + manual
Change-Id: If22bee787c5ab5c8c09d20e4742a8b5d1b7f0b59
parent 63199840
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ public interface ListenerExecutor {
        /**
         * Called before this operation is to be run. Some operations may be canceled before they
         * are run, in which case this method may not be called. {@link #onPostExecute(boolean)}
         * will only be run if this method was run.
         * will only be run if this method was run. This callback is invoked on the calling thread.
         */
        default void onPreExecute() {}

@@ -49,7 +49,7 @@ public interface ListenerExecutor {
         * RuntimeException, which will propagate normally. Implementations of
         * {@link ListenerExecutor} have the option to override
         * {@link ListenerExecutor#onOperationFailure(ListenerOperation, Exception)} instead to
         * intercept failures at the class level.
         * intercept failures at the class level. This callback is invoked on the executor thread.
         */
        default void onFailure(Exception e) {
            // implementations should handle any exceptions that may be thrown
@@ -59,21 +59,24 @@ public interface ListenerExecutor {
        /**
         * Called after the operation is run. This method will always be called if
         * {@link #onPreExecute()} is called. Success implies that the operation was run to
         * completion with no failures.
         * completion with no failures. This callback may be invoked on the calling thread or
         * executor thread.
         */
        default void onPostExecute(boolean success) {}

        /**
         * Called after this operation is complete (which does not imply that it was necessarily
         * run). Will always be called once per operation, no matter if the operation was run or
         * not. Success implies that the operation was run to completion with no failures.
         * not. Success implies that the operation was run to completion with no failures. This
         * callback may be invoked on the calling thread or executor thread.
         */
        default void onComplete(boolean success) {}
    }

    /**
     * May be override to handle operation failures at a class level. Will not be invoked in the
     * event of a RuntimeException, which will propagate normally.
     * event of a RuntimeException, which will propagate normally. This callback is invoked on the
     * executor thread.
     */
    default <TListener> void onOperationFailure(ListenerOperation<TListener> operation,
            Exception exception) {
@@ -83,7 +86,8 @@ public interface ListenerExecutor {
    /**
     * Executes the given listener operation on the given executor, using the provided listener
     * supplier. If the supplier returns a null value, or a value during the operation that does not
     * match the value prior to the operation, then the operation is considered canceled.
     * match the value prior to the operation, then the operation is considered canceled. If a null
     * operation is supplied, nothing happens.
     */
    default <TListener> void executeSafely(Executor executor, Supplier<TListener> listenerSupplier,
            @Nullable ListenerOperation<TListener> operation) {
+10 −0
Original line number Diff line number Diff line
@@ -151,6 +151,16 @@ public final class GpsStatus {
        return status;
    }

    /**
     * Builds an empty GpsStatus. Should only be used for legacy reasons.
     *
     * @hide
     */
    @NonNull
    static GpsStatus createEmpty() {
        return new GpsStatus();
    }

    private GpsStatus() {
    }

+1 −1
Original line number Diff line number Diff line
@@ -24,6 +24,6 @@ import android.os.IRemoteCallback;
 */
oneway interface ILocationListener
{
    void onLocationChanged(in Location location, in IRemoteCallback onCompleteCallback);
    void onLocationChanged(in Location location, in @nullable IRemoteCallback onCompleteCallback);
    void onProviderEnabledChanged(String provider, boolean enabled);
}
+1 −1
Original line number Diff line number Diff line
@@ -113,7 +113,7 @@ interface ILocationManager
    List<LocationRequest> getTestProviderCurrentRequests(String provider);
    LocationTime getGnssTimeMillis();

    boolean sendExtraCommand(String provider, String command, inout Bundle extras);
    void sendExtraCommand(String provider, String command, inout Bundle extras);

    // used by gts tests to verify whitelists
    String[] getBackgroundThrottlingWhitelist();
+8 −7
Original line number Diff line number Diff line
@@ -36,7 +36,9 @@ import android.os.Bundle;
public interface LocationListener {

    /**
     * Called when the location has changed.
     * Called when the location has changed. A wakelock is held on behalf on the listener for some
     * brief amount of time as this callback executes. If this callback performs long running
     * operations, it is the client's responsibility to obtain their own wakelock.
     *
     * @param location the updated location
     */
@@ -52,18 +54,17 @@ public interface LocationListener {
    default void onStatusChanged(String provider, int status, Bundle extras) {}

    /**
     * Called when the provider is enabled by the user.
     * Called when a provider this listener is registered with becomes enabled.
     *
     * @param provider the name of the location provider that has become enabled
     * @param provider the name of the location provider
     */
    default void onProviderEnabled(@NonNull String provider) {}

    /**
     * Called when the provider is disabled by the user. If requestLocationUpdates
     * is called on an already disabled provider, this method is called
     * immediately.
     * Called when the provider this listener is registered with becomes disabled. If a provider is
     * disabled when this listener is registered, this callback will be invoked immediately.
     *
     * @param provider the name of the location provider that has become disabled
     * @param provider the name of the location provider
     */
    default void onProviderDisabled(@NonNull String provider) {}
}
Loading