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

Commit 68bc7d7a authored by Soonil Nagarkar's avatar Soonil Nagarkar Committed by Automerger Merge Worker
Browse files

Merge "Include provider tag in complete attribution tag list" into sc-dev am: 9f8a57eb

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14331392

Change-Id: I94545591e5cf65ef5e884983a5de00c884d6aefc
parents 631a0202 9f8a57eb
Loading
Loading
Loading
Loading
+10 −4
Original line number Original line Diff line number Diff line
@@ -2271,7 +2271,8 @@ public class LocationProviderManager extends
        }
        }


        if (mOnLocationTagsChangeListener != null) {
        if (mOnLocationTagsChangeListener != null) {
            if (!oldState.extraAttributionTags.equals(newState.extraAttributionTags)) {
            if (!oldState.extraAttributionTags.equals(newState.extraAttributionTags)
                    || !Objects.equals(oldState.identity, newState.identity)) {
                if (oldState.identity != null) {
                if (oldState.identity != null) {
                    FgThread.getHandler().sendMessage(PooledLambda.obtainMessage(
                    FgThread.getHandler().sendMessage(PooledLambda.obtainMessage(
                            OnProviderLocationTagsChangeListener::onLocationTagsChanged,
                            OnProviderLocationTagsChangeListener::onLocationTagsChanged,
@@ -2281,11 +2282,16 @@ public class LocationProviderManager extends
                    ));
                    ));
                }
                }
                if (newState.identity != null) {
                if (newState.identity != null) {
                    ArraySet<String> attributionTags = new ArraySet<>(
                            newState.extraAttributionTags.size() + 1);
                    attributionTags.addAll(newState.extraAttributionTags);
                    attributionTags.add(newState.identity.getAttributionTag());

                    FgThread.getHandler().sendMessage(PooledLambda.obtainMessage(
                    FgThread.getHandler().sendMessage(PooledLambda.obtainMessage(
                            OnProviderLocationTagsChangeListener::onLocationTagsChanged,
                            OnProviderLocationTagsChangeListener::onLocationTagsChanged,
                            mOnLocationTagsChangeListener, new LocationTagInfo(
                            mOnLocationTagsChangeListener, new LocationTagInfo(
                                    newState.identity.getUid(), newState.identity.getPackageName(),
                                    newState.identity.getUid(), newState.identity.getPackageName(),
                                    newState.extraAttributionTags)
                                    attributionTags)
                    ));
                    ));
                }
                }
            }
            }
+18 −0
Original line number Original line Diff line number Diff line
@@ -61,6 +61,8 @@ import android.location.ILocationListener;
import android.location.LastLocationRequest;
import android.location.LastLocationRequest;
import android.location.Location;
import android.location.Location;
import android.location.LocationManagerInternal;
import android.location.LocationManagerInternal;
import android.location.LocationManagerInternal.LocationTagInfo;
import android.location.LocationManagerInternal.OnProviderLocationTagsChangeListener;
import android.location.LocationManagerInternal.ProviderEnabledListener;
import android.location.LocationManagerInternal.ProviderEnabledListener;
import android.location.LocationRequest;
import android.location.LocationRequest;
import android.location.LocationResult;
import android.location.LocationResult;
@@ -90,6 +92,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Before;
import org.junit.Test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.Mock;


@@ -215,6 +218,21 @@ public class LocationProviderManagerTest {
        assertThat(mManager.hasProvider()).isFalse();
        assertThat(mManager.hasProvider()).isFalse();
    }
    }


    @Test
    public void testAttributionTags() {
        OnProviderLocationTagsChangeListener listener = mock(
                OnProviderLocationTagsChangeListener.class);
        mManager.setOnProviderLocationTagsChangeListener(listener);

        mProvider.setExtraAttributionTags(Collections.singleton("extra"));

        ArgumentCaptor<LocationTagInfo> captor = ArgumentCaptor.forClass(LocationTagInfo.class);
        verify(listener, times(2)).onLocationTagsChanged(captor.capture());

        assertThat(captor.getAllValues().get(0).getTags()).isEmpty();
        assertThat(captor.getAllValues().get(1).getTags()).containsExactly("extra", "attribution");
    }

    @Test
    @Test
    public void testRemoveProvider() {
    public void testRemoveProvider() {
        mManager.setRealProvider(null);
        mManager.setRealProvider(null);