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

Commit 1510c41e authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Pipe requestSetProviderAllowed through"

parents 4d581143 17d8c838
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -649,7 +649,7 @@ public class LocationManagerService extends ILocationManager.Stub {
            mEnabled = new SparseArray<>(1);

            // initialize last since this lets our reference escape
            mProvider = new MockableLocationProvider(mContext, mLock, this);
            mProvider = new MockableLocationProvider(mLock, this);

            // we can assume all users start with disabled location state since the initial state
            // of all providers is disabled. no need to initialize mEnabled further.
@@ -2699,7 +2699,7 @@ public class LocationManagerService extends ILocationManager.Stub {
                mProviderManagers.add(manager);
            }

            manager.setMockProvider(new MockProvider(mContext, properties));
            manager.setMockProvider(new MockProvider(properties));
        }
    }

+8 −11
Original line number Diff line number Diff line
@@ -177,7 +177,6 @@ public abstract class AbstractLocationProvider {
        }
    }

    protected final Context mContext;
    protected final Executor mExecutor;

    // we use a lock-free implementation to update state to ensure atomicity between updating the
@@ -186,13 +185,11 @@ public abstract class AbstractLocationProvider {
    // before it was set, and should not miss any updates that occur after it was set).
    private final AtomicReference<InternalState> mInternalState;

    protected AbstractLocationProvider(Context context, Executor executor) {
        this(context, executor, Collections.singleton(context.getPackageName()));
    protected AbstractLocationProvider(Executor executor, Context context) {
        this(executor, Collections.singleton(context.getPackageName()));
    }

    protected AbstractLocationProvider(Context context, Executor executor,
            Set<String> packageNames) {
        mContext = context;
    protected AbstractLocationProvider(Executor executor, Set<String> packageNames) {
        mExecutor = executor;
        mInternalState = new AtomicReference<>(
                new InternalState(null, State.EMPTY_STATE.withProviderPackageNames(packageNames)));
@@ -202,7 +199,7 @@ public abstract class AbstractLocationProvider {
     * Sets the listener and returns the state at the moment the listener was set. The listener can
     * expect to receive all state updates from after this point.
     */
    State setListener(@Nullable Listener listener) {
    protected State setListener(@Nullable Listener listener) {
        return mInternalState.updateAndGet(
                internalState -> internalState.withListener(listener)).state;
    }
@@ -210,14 +207,14 @@ public abstract class AbstractLocationProvider {
    /**
     * Retrieves the state of the provider.
     */
    State getState() {
    public State getState() {
        return mInternalState.get().state;
    }

    /**
     * Sets the state of the provider to the new state.
     */
    void setState(State newState) {
    protected void setState(State newState) {
        InternalState oldInternalState = mInternalState.getAndUpdate(
                internalState -> internalState.withState(newState));
        if (newState.equals(oldInternalState.state)) {
@@ -357,7 +354,7 @@ public abstract class AbstractLocationProvider {
    /**
     * Always invoked on the provider executor.
     */
    protected void onExtraCommand(int uid, int pid, String command, Bundle extras) {}
    protected abstract void onExtraCommand(int uid, int pid, String command, Bundle extras);

    /**
     * Requests a provider to enable itself for the given user id.
@@ -370,7 +367,7 @@ public abstract class AbstractLocationProvider {
    /**
     * Always invoked on the provider executor.
     */
    protected void onRequestSetAllowed(boolean allowed) {}
    protected abstract void onRequestSetAllowed(boolean allowed);

    /**
     * Dumps debug or log information. May be invoked from any thread.
+8 −2
Original line number Diff line number Diff line
@@ -408,7 +408,7 @@ public class GnssLocationProvider extends AbstractLocationProvider implements
    // Available only on GNSS HAL 2.0 implementations and later.
    private GnssVisibilityControl mGnssVisibilityControl;

    // Handler for processing events
    private final Context mContext;
    private Handler mHandler;

    private final GnssNetworkConnectivityHandler mNetworkConnectivityHandler;
@@ -625,10 +625,11 @@ public class GnssLocationProvider extends AbstractLocationProvider implements
    }

    public GnssLocationProvider(Context context) {
        super(context, FgThread.getExecutor());
        super(FgThread.getExecutor(), context);

        ensureInitialized();

        mContext = context;
        mLooper = FgThread.getHandler().getLooper();

        // Create a wake lock
@@ -1212,6 +1213,11 @@ public class GnssLocationProvider extends AbstractLocationProvider implements
        }
    }

    @Override
    protected void onRequestSetAllowed(boolean allowed) {
        // do nothing - the gnss provider is always allowed
    }

    private void deleteAidingData(Bundle extras) {
        int flags;

+5 −3
Original line number Diff line number Diff line
@@ -134,6 +134,7 @@ public class LocationProviderProxy extends AbstractLocationProvider {
    // also used to synchronized any state changes (setEnabled, setProperties, setState, etc)
    private final Object mLock = new Object();

    private final Context mContext;
    private final ServiceWatcher mServiceWatcher;

    @GuardedBy("mLock")
@@ -143,10 +144,11 @@ public class LocationProviderProxy extends AbstractLocationProvider {

    private LocationProviderProxy(Context context, String action, int enableOverlayResId,
            int nonOverlayPackageResId) {
        // safe to use direct executor since none of our callbacks call back into any code above
        // this provider - they simply forward to the proxy service
        super(context, DIRECT_EXECUTOR);
        // safe to use direct executor even though this class has internal locks - all of our
        // callbacks go to oneway binder transactions which cannot possibly be re-entrant
        super(DIRECT_EXECUTOR, Collections.emptySet());

        mContext = context;
        mServiceWatcher = new ServiceWatcher(context, FgThread.getHandler(), action, this::onBind,
                this::onUnbind, enableOverlayResId, nonOverlayPackageResId);

+10 −5
Original line number Diff line number Diff line
@@ -16,15 +16,18 @@

package com.android.server.location;

import static com.android.internal.util.ConcurrentUtils.DIRECT_EXECUTOR;

import android.annotation.Nullable;
import android.content.Context;
import android.location.Location;
import android.os.Bundle;

import com.android.internal.location.ProviderProperties;
import com.android.internal.location.ProviderRequest;

import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.Collections;

/**
 * A mock location provider used by LocationManagerService to implement test providers.
@@ -35,10 +38,9 @@ public class MockProvider extends AbstractLocationProvider {

    @Nullable private Location mLocation;

    public MockProvider(Context context, ProviderProperties properties) {
        // using a direct executor is only acceptable because this class is so simple it is trivial
        // to verify that it does not acquire any locks or re-enter LMS from callbacks
        super(context, Runnable::run);
    public MockProvider(ProviderProperties properties) {
        // using a direct executor is ok because this class has no locks that could deadlock
        super(DIRECT_EXECUTOR, Collections.emptySet());
        setProperties(properties);
    }

@@ -58,6 +60,9 @@ public class MockProvider extends AbstractLocationProvider {
    @Override
    public void onSetRequest(ProviderRequest request) {}

    @Override
    protected void onExtraCommand(int uid, int pid, String command, Bundle extras) {}

    @Override
    protected void onRequestSetAllowed(boolean allowed) {
        setAllowed(allowed);
Loading