Refactor LocationSettings
- Extends BasePreferenceController in LocationBasePreferenceController which binds preference key based on xml file instead of writing the key in java code. Then the controller can be used in many xmls. - Modify LocationServicePreferenceController to support only personal or profile user. Bug: 141601408 Test: manual, robolectric Change-Id: I51ee950dfb87474df84a8dc3db55fb911edcf599
This commit is contained in:
@@ -2,6 +2,9 @@ package com.android.settings.location;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.location.LocationManager;
|
||||
import android.provider.Settings;
|
||||
@@ -30,6 +33,7 @@ public class AppLocationPermissionPreferenceControllerTest {
|
||||
private LifecycleOwner mLifecycleOwner;
|
||||
private Lifecycle mLifecycle;
|
||||
private LocationManager mLocationManager;
|
||||
private LocationSettings mLocationSettings;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -37,7 +41,10 @@ public class AppLocationPermissionPreferenceControllerTest {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mLifecycleOwner = () -> mLifecycle;
|
||||
mLifecycle = new Lifecycle(mLifecycleOwner);
|
||||
mController = new AppLocationPermissionPreferenceController(mContext, mLifecycle);
|
||||
mLocationSettings = spy(new LocationSettings());
|
||||
when(mLocationSettings.getSettingsLifecycle()).thenReturn(mLifecycle);
|
||||
mController = new AppLocationPermissionPreferenceController(mContext, "key");
|
||||
mController.init(mLocationSettings);
|
||||
mLocationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ public class LocationFooterPreferenceControllerTest {
|
||||
Context context = spy(RuntimeEnvironment.application);
|
||||
when(context.getPackageManager()).thenReturn(mPackageManager);
|
||||
when(mPreferenceCategory.getContext()).thenReturn(context);
|
||||
mController = spy(new LocationFooterPreferenceController(context));
|
||||
mController = spy(new LocationFooterPreferenceController(context, "key"));
|
||||
when(mPackageManager.getResourcesForApplication(any(ApplicationInfo.class)))
|
||||
.thenReturn(mResources);
|
||||
when(mResources.getString(TEST_RES_ID)).thenReturn(TEST_TEXT);
|
||||
|
||||
@@ -69,6 +69,7 @@ public class LocationForWorkPreferenceControllerTest {
|
||||
private LocationForWorkPreferenceController mController;
|
||||
private LifecycleOwner mLifecycleOwner;
|
||||
private Lifecycle mLifecycle;
|
||||
private LocationSettings mLocationSettings;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -77,10 +78,13 @@ public class LocationForWorkPreferenceControllerTest {
|
||||
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||
mLifecycleOwner = () -> mLifecycle;
|
||||
mLifecycle = new Lifecycle(mLifecycleOwner);
|
||||
mController = spy(new LocationForWorkPreferenceController(mContext, mLifecycle));
|
||||
mLocationSettings = spy(new LocationSettings());
|
||||
when(mLocationSettings.getSettingsLifecycle()).thenReturn(mLifecycle);
|
||||
mController = spy(new LocationForWorkPreferenceController(mContext, "key"));
|
||||
mController.init(mLocationSettings);
|
||||
mockManagedProfile();
|
||||
ReflectionHelpers.setField(mController, "mLocationEnabler", mEnabler);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
when(mScreen.findPreference(any())).thenReturn(mPreference);
|
||||
final String key = mController.getPreferenceKey();
|
||||
when(mPreference.getKey()).thenReturn(key);
|
||||
when(mPreference.isVisible()).thenReturn(true);
|
||||
|
||||
@@ -38,7 +38,7 @@ public class LocationScanningPreferenceControllerTest {
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = new LocationScanningPreferenceController(mContext);
|
||||
mController = new LocationScanningPreferenceController(mContext, "key");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
*/
|
||||
package com.android.settings.location;
|
||||
|
||||
import static com.android.settings.location.LocationServicePreferenceController.KEY_LOCATION_SERVICES;
|
||||
import static com.android.settings.location.LocationServicePreferenceController.KEY_LOCATION_SERVICES_MANAGED;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
@@ -59,8 +62,6 @@ import java.util.Map;
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = ShadowUserManager.class)
|
||||
public class LocationServicePreferenceControllerTest {
|
||||
private static final String LOCATION_SERVICES_MANAGED_PROFILE_KEY =
|
||||
"location_services_managed_profile";
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private LocationSettings mFragment;
|
||||
@@ -86,14 +87,16 @@ public class LocationServicePreferenceControllerTest {
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mLifecycleOwner = () -> mLifecycle;
|
||||
mLifecycle = new Lifecycle(mLifecycleOwner);
|
||||
mController = spy(new LocationServicePreferenceController(
|
||||
mContext, mFragment, mLifecycle, mSettingsInjector));
|
||||
mController = spy(new LocationServicePreferenceController(mContext, KEY_LOCATION_SERVICES));
|
||||
when(mFragment.getSettingsLifecycle()).thenReturn(mLifecycle);
|
||||
mController.init(mFragment);
|
||||
mController.mInjector = mSettingsInjector;
|
||||
final String key = mController.getPreferenceKey();
|
||||
when(mScreen.findPreference(key)).thenReturn(mCategoryPrimary);
|
||||
when(mScreen.findPreference(LOCATION_SERVICES_MANAGED_PROFILE_KEY)).thenReturn(
|
||||
when(mScreen.findPreference(KEY_LOCATION_SERVICES_MANAGED)).thenReturn(
|
||||
mCategoryManaged);
|
||||
when(mCategoryPrimary.getKey()).thenReturn(key);
|
||||
when(mCategoryManaged.getKey()).thenReturn(LOCATION_SERVICES_MANAGED_PROFILE_KEY);
|
||||
when(mCategoryManaged.getKey()).thenReturn(KEY_LOCATION_SERVICES_MANAGED);
|
||||
when(mContext.getSystemService(Context.DEVICE_POLICY_SERVICE))
|
||||
.thenReturn(mDevicePolicyManager);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user