Remove obsolete broadcast behavior
There is no need to broadcast when a footer is displayed/removed. The broadcasts were added specifically for gmscore to know when the footer was visible, so that GLS consent could be given. However, this was only very briefly actually used within GmsCore, and has been obsolete for several releases. Test: CTS Change-Id: I1df6c6214fe79c943cabd7b04357c8ab7d1c1c39
This commit is contained in:
@@ -158,10 +158,6 @@ public class LocationEnablerTest {
|
||||
Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_OFF);
|
||||
mEnabler.setLocationEnabled(true);
|
||||
|
||||
verify(mContext).sendBroadcastAsUser(
|
||||
argThat(actionMatches(LocationManager.MODE_CHANGING_ACTION)),
|
||||
eq(UserHandle.of(ActivityManager.getCurrentUser())),
|
||||
eq(WRITE_SECURE_SETTINGS));
|
||||
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.LOCATION_CHANGER, Settings.Secure.LOCATION_CHANGER_UNKNOWN))
|
||||
.isEqualTo(Settings.Secure.LOCATION_CHANGER_SYSTEM_SETTINGS);
|
||||
|
@@ -22,11 +22,9 @@ import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
@@ -38,12 +36,9 @@ import android.content.res.Resources;
|
||||
import android.location.LocationManager;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -65,22 +60,17 @@ public class LocationFooterPreferenceControllerTest {
|
||||
private PackageManager mPackageManager;
|
||||
@Mock
|
||||
private Resources mResources;
|
||||
private Context mContext;
|
||||
private LocationFooterPreferenceController mController;
|
||||
private LifecycleOwner mLifecycleOwner;
|
||||
private Lifecycle mLifecycle;
|
||||
private static final int TEST_RES_ID = 1234;
|
||||
private static final String TEST_TEXT = "text";
|
||||
|
||||
@Before
|
||||
public void setUp() throws NameNotFoundException {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
mLifecycleOwner = () -> mLifecycle;
|
||||
mLifecycle = new Lifecycle(mLifecycleOwner);
|
||||
when(mPreferenceCategory.getContext()).thenReturn(mContext);
|
||||
mController = spy(new LocationFooterPreferenceController(mContext, mLifecycle));
|
||||
Context context = spy(RuntimeEnvironment.application);
|
||||
when(context.getPackageManager()).thenReturn(mPackageManager);
|
||||
when(mPreferenceCategory.getContext()).thenReturn(context);
|
||||
mController = spy(new LocationFooterPreferenceController(context));
|
||||
when(mPackageManager.getResourcesForApplication(any(ApplicationInfo.class)))
|
||||
.thenReturn(mResources);
|
||||
when(mResources.getString(TEST_RES_ID)).thenReturn(TEST_TEXT);
|
||||
@@ -118,32 +108,6 @@ public class LocationFooterPreferenceControllerTest {
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendBroadcastFooterInject() {
|
||||
ArgumentCaptor<Intent> intent = ArgumentCaptor.forClass(Intent.class);
|
||||
final ActivityInfo activityInfo =
|
||||
getTestResolveInfo(/*isSystemApp*/ true, /*hasRequiredMetadata*/ true).activityInfo;
|
||||
mController.sendBroadcastFooterDisplayed(
|
||||
new ComponentName(activityInfo.packageName, activityInfo.name));
|
||||
verify(mContext).sendBroadcast(intent.capture());
|
||||
assertThat(intent.getValue().getAction())
|
||||
.isEqualTo(LocationManager.SETTINGS_FOOTER_DISPLAYED_ACTION);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_sendBroadcast() {
|
||||
final List<ResolveInfo> testResolveInfos = new ArrayList<>();
|
||||
testResolveInfos.add(
|
||||
getTestResolveInfo(/*isSystemApp*/ true, /*hasRequiredMetadata*/ true));
|
||||
when(mPackageManager.queryBroadcastReceivers(any(), anyInt()))
|
||||
.thenReturn(testResolveInfos);
|
||||
mController.updateState(mPreferenceCategory);
|
||||
ArgumentCaptor<Intent> intent = ArgumentCaptor.forClass(Intent.class);
|
||||
verify(mContext).sendBroadcast(intent.capture());
|
||||
assertThat(intent.getValue().getAction())
|
||||
.isEqualTo(LocationManager.SETTINGS_FOOTER_DISPLAYED_ACTION);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_addPreferences() {
|
||||
final List<ResolveInfo> testResolveInfos = new ArrayList<>();
|
||||
@@ -166,32 +130,6 @@ public class LocationFooterPreferenceControllerTest {
|
||||
.thenReturn(testResolveInfos);
|
||||
mController.updateState(mPreferenceCategory);
|
||||
verify(mPreferenceCategory, never()).addPreference(any(Preference.class));
|
||||
verify(mContext, never()).sendBroadcast(any(Intent.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_thenOnPause_sendBroadcasts() {
|
||||
final List<ResolveInfo> testResolveInfos = new ArrayList<>();
|
||||
testResolveInfos.add(
|
||||
getTestResolveInfo(/*isSystemApp*/ true, /*hasRequiredMetadata*/ true));
|
||||
when(mPackageManager.queryBroadcastReceivers(any(Intent.class), anyInt()))
|
||||
.thenReturn(testResolveInfos);
|
||||
mController.updateState(mPreferenceCategory);
|
||||
ArgumentCaptor<Intent> intent = ArgumentCaptor.forClass(Intent.class);
|
||||
verify(mContext).sendBroadcast(intent.capture());
|
||||
assertThat(intent.getValue().getAction())
|
||||
.isEqualTo(LocationManager.SETTINGS_FOOTER_DISPLAYED_ACTION);
|
||||
|
||||
mController.onPause();
|
||||
verify(mContext, times(2)).sendBroadcast(intent.capture());
|
||||
assertThat(intent.getValue().getAction())
|
||||
.isEqualTo(LocationManager.SETTINGS_FOOTER_REMOVED_ACTION);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPause_doNotSendBroadcast() {
|
||||
mController.onPause();
|
||||
verify(mContext, never()).sendBroadcast(any(Intent.class));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user