Merge "Move injected services for work into a new page" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
3b477b13e1
@@ -33,6 +33,6 @@
|
|||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="location_services"
|
android:key="location_services"
|
||||||
android:layout="@layout/preference_category_no_label"
|
android:layout="@layout/preference_category_no_label"
|
||||||
settings:controller="com.android.settings.location.LocationServicePreferenceController"/>
|
settings:controller="com.android.settings.location.LocationInjectedServicesPreferenceController"/>
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
27
res/xml/location_services_workprofile.xml
Normal file
27
res/xml/location_services_workprofile.xml
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2021 The Android Open Source Project
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:title="@string/location_services_screen_title">
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:title="@string/managed_profile_location_services"
|
||||||
|
android:layout="@layout/preference_category_no_label"
|
||||||
|
android:key="location_services_managed_profile"
|
||||||
|
settings:controller="com.android.settings.location.LocationInjectedServicesForWorkPreferenceController"/>
|
||||||
|
|
||||||
|
</PreferenceScreen>
|
@@ -54,7 +54,7 @@
|
|||||||
android:fragment="com.android.settings.location.LocationServices"
|
android:fragment="com.android.settings.location.LocationServices"
|
||||||
android:key="location_services"
|
android:key="location_services"
|
||||||
android:title="@string/location_services_screen_title"
|
android:title="@string/location_services_screen_title"
|
||||||
settings:controller="com.android.settings.location.LocationScanningPreferenceController"/>
|
settings:controller="com.android.settings.location.LocationServicesPreferenceController"/>
|
||||||
|
|
||||||
<!-- This preference gets removed if there is no managed profile -->
|
<!-- This preference gets removed if there is no managed profile -->
|
||||||
<com.android.settingslib.RestrictedSwitchPreference
|
<com.android.settingslib.RestrictedSwitchPreference
|
||||||
@@ -71,7 +71,7 @@
|
|||||||
android:key="location_services_managed_profile"
|
android:key="location_services_managed_profile"
|
||||||
android:title="@string/managed_profile_location_services"
|
android:title="@string/managed_profile_location_services"
|
||||||
settings:forWork="true"
|
settings:forWork="true"
|
||||||
settings:controller="com.android.settings.location.LocationServiceForWorkPreferenceController"/>
|
settings:controller="com.android.settings.location.LocationInjectedServicesForWorkPreferenceController"/>
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
@@ -50,7 +50,7 @@
|
|||||||
android:key="location_services"
|
android:key="location_services"
|
||||||
android:title="@string/location_services_screen_title"
|
android:title="@string/location_services_screen_title"
|
||||||
android:fragment="com.android.settings.location.LocationServices"
|
android:fragment="com.android.settings.location.LocationServices"
|
||||||
settings:controller="com.android.settings.location.LocationScanningPreferenceController"/>
|
settings:controller="com.android.settings.location.LocationServicesPreferenceController"/>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="location_footer"
|
android:key="location_footer"
|
||||||
|
@@ -55,11 +55,11 @@
|
|||||||
</intent>
|
</intent>
|
||||||
</Preference>
|
</Preference>
|
||||||
|
|
||||||
<PreferenceCategory
|
<Preference
|
||||||
android:title="@string/managed_profile_location_services"
|
android:key="location_services_for_work"
|
||||||
android:layout="@layout/preference_category_no_label"
|
android:title="@string/location_services_screen_title"
|
||||||
android:key="location_services_managed_profile"
|
android:fragment="com.android.settings.location.LocationServicesForWork"
|
||||||
settings:controller="com.android.settings.location.LocationServiceForWorkPreferenceController"/>
|
settings:controller="com.android.settings.location.LocationServicesForWorkPreferenceController"/>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="location_footer"
|
android:key="location_footer"
|
||||||
|
@@ -27,6 +27,9 @@ import com.android.settings.Utils;
|
|||||||
import com.android.settingslib.RestrictedLockUtils;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
import com.android.settingslib.RestrictedSwitchPreference;
|
import com.android.settingslib.RestrictedSwitchPreference;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Preference Controller for Location for Work Profile.
|
||||||
|
*/
|
||||||
public class LocationForWorkPreferenceController extends LocationBasePreferenceController {
|
public class LocationForWorkPreferenceController extends LocationBasePreferenceController {
|
||||||
|
|
||||||
private RestrictedSwitchPreference mPreference;
|
private RestrictedSwitchPreference mPreference;
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2019 The Android Open Source Project
|
* Copyright (C) 2021 The Android Open Source Project
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -27,13 +27,13 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the Location Services used in profile user.
|
* Retrieve the Location Services used in work profile user.
|
||||||
*/
|
*/
|
||||||
public class LocationServiceForWorkPreferenceController extends
|
public class LocationInjectedServicesForWorkPreferenceController extends
|
||||||
LocationServicePreferenceController {
|
LocationInjectedServicesPreferenceController {
|
||||||
private static final String TAG = "LocationWorkPrefCtrl";
|
private static final String TAG = "LocationWorkPrefCtrl";
|
||||||
|
|
||||||
public LocationServiceForWorkPreferenceController(Context context, String key) {
|
public LocationInjectedServicesForWorkPreferenceController(Context context, String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
}
|
}
|
||||||
|
|
@@ -1,15 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2017 The Android Open Source Project
|
* Copyright (C) 2021 The Android Open Source Project
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* except in compliance with the License. You may obtain a copy of the License at
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software distributed under the
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* KIND, either express or implied. See the License for the specific language governing
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* permissions and limitations under the License.
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package com.android.settings.location;
|
package com.android.settings.location;
|
||||||
|
|
||||||
@@ -36,7 +38,10 @@ import com.android.settingslib.core.lifecycle.events.OnResume;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class LocationServicePreferenceController extends LocationBasePreferenceController
|
/**
|
||||||
|
* Preference controller for the injected Location Services.
|
||||||
|
*/
|
||||||
|
public class LocationInjectedServicesPreferenceController extends LocationBasePreferenceController
|
||||||
implements LifecycleObserver, OnResume, OnPause {
|
implements LifecycleObserver, OnResume, OnPause {
|
||||||
|
|
||||||
private static final String TAG = "LocationPrefCtrl";
|
private static final String TAG = "LocationPrefCtrl";
|
||||||
@@ -51,7 +56,7 @@ public class LocationServicePreferenceController extends LocationBasePreferenceC
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
BroadcastReceiver mInjectedSettingsReceiver;
|
BroadcastReceiver mInjectedSettingsReceiver;
|
||||||
|
|
||||||
public LocationServicePreferenceController(Context context, String key) {
|
public LocationInjectedServicesPreferenceController(Context context, String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
}
|
}
|
||||||
|
|
@@ -60,7 +60,7 @@ public class LocationServices extends DashboardFragment {
|
|||||||
public void onAttach(Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
|
|
||||||
use(LocationServicePreferenceController.class).init(this);
|
use(LocationInjectedServicesPreferenceController.class).init(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context) {
|
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context) {
|
||||||
|
@@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.location;
|
||||||
|
|
||||||
|
import android.app.settings.SettingsEnums;
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
|
import com.android.settingslib.search.SearchIndexable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A page that configures the Location Services settings for work profile.
|
||||||
|
*/
|
||||||
|
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
||||||
|
public class LocationServicesForWork extends DashboardFragment {
|
||||||
|
private static final String TAG = "LocationServicesForWork";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMetricsCategory() {
|
||||||
|
return SettingsEnums.LOCATION_SERVICES;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getPreferenceScreenResId() {
|
||||||
|
return R.xml.location_services_workprofile;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getLogTag() {
|
||||||
|
return TAG;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||||
|
return buildPreferenceControllers(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttach(Context context) {
|
||||||
|
super.onAttach(context);
|
||||||
|
use(LocationInjectedServicesForWorkPreferenceController.class).init(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context) {
|
||||||
|
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||||
|
return controllers;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For Search.
|
||||||
|
*/
|
||||||
|
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||||
|
new BaseSearchIndexProvider(R.xml.location_services_workprofile) {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AbstractPreferenceController> createPreferenceControllers(Context
|
||||||
|
context) {
|
||||||
|
return buildPreferenceControllers(context);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.location;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Preference controller for Location Services for Work Profile.
|
||||||
|
*/
|
||||||
|
public class LocationServicesForWorkPreferenceController extends BasePreferenceController {
|
||||||
|
|
||||||
|
public LocationServicesForWorkPreferenceController(Context context, String key) {
|
||||||
|
super(context, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CharSequence getSummary() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@AvailabilityStatus
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
return AVAILABLE;
|
||||||
|
}
|
||||||
|
}
|
@@ -23,12 +23,14 @@ import android.provider.Settings;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
|
||||||
|
/**
|
||||||
public class LocationScanningPreferenceController extends BasePreferenceController {
|
* Preference controller for Location Services.
|
||||||
|
*/
|
||||||
|
public class LocationServicesPreferenceController extends BasePreferenceController {
|
||||||
|
|
||||||
private final WifiManager mWifiManager;
|
private final WifiManager mWifiManager;
|
||||||
|
|
||||||
public LocationScanningPreferenceController(Context context, String key) {
|
public LocationServicesPreferenceController(Context context, String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
mWifiManager = context.getSystemService(WifiManager.class);
|
mWifiManager = context.getSystemService(WifiManager.class);
|
||||||
}
|
}
|
||||||
@@ -57,4 +59,4 @@ public class LocationScanningPreferenceController extends BasePreferenceControll
|
|||||||
? AVAILABLE
|
? AVAILABLE
|
||||||
: UNSUPPORTED_ON_DEVICE;
|
: UNSUPPORTED_ON_DEVICE;
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -85,7 +85,7 @@ public class LocationSettings extends DashboardFragment {
|
|||||||
use(RecentLocationAccessPreferenceController.class).init(this);
|
use(RecentLocationAccessPreferenceController.class).init(this);
|
||||||
use(LocationFooterPreferenceController.class).init(this);
|
use(LocationFooterPreferenceController.class).init(this);
|
||||||
use(LocationForWorkPreferenceController.class).init(this);
|
use(LocationForWorkPreferenceController.class).init(this);
|
||||||
use(LocationServiceForWorkPreferenceController.class).init(this);
|
use(LocationInjectedServicesForWorkPreferenceController.class).init(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -50,7 +50,6 @@ public class LocationWorkProfileSettings extends DashboardFragment {
|
|||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
|
|
||||||
use(AppLocationPermissionPreferenceController.class).init(this);
|
use(AppLocationPermissionPreferenceController.class).init(this);
|
||||||
use(LocationServiceForWorkPreferenceController.class).init(this);
|
|
||||||
use(LocationFooterPreferenceController.class).init(this);
|
use(LocationFooterPreferenceController.class).init(this);
|
||||||
use(LocationForWorkPreferenceController.class).init(this);
|
use(LocationForWorkPreferenceController.class).init(this);
|
||||||
|
|
||||||
|
@@ -58,7 +58,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@Config(shadows = ShadowUserManager.class)
|
@Config(shadows = ShadowUserManager.class)
|
||||||
public class LocationServicePreferenceControllerTest {
|
public class LocationInjectedServicesPreferenceControllerTest {
|
||||||
|
|
||||||
private static final String KEY_LOCATION_SERVICES = "location_service";
|
private static final String KEY_LOCATION_SERVICES = "location_service";
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ public class LocationServicePreferenceControllerTest {
|
|||||||
private DevicePolicyManager mDevicePolicyManager;
|
private DevicePolicyManager mDevicePolicyManager;
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private LocationServicePreferenceController mController;
|
private LocationInjectedServicesPreferenceController mController;
|
||||||
private LifecycleOwner mLifecycleOwner;
|
private LifecycleOwner mLifecycleOwner;
|
||||||
private Lifecycle mLifecycle;
|
private Lifecycle mLifecycle;
|
||||||
|
|
||||||
@@ -86,7 +86,8 @@ public class LocationServicePreferenceControllerTest {
|
|||||||
mContext = spy(RuntimeEnvironment.application);
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
mLifecycleOwner = () -> mLifecycle;
|
mLifecycleOwner = () -> mLifecycle;
|
||||||
mLifecycle = new Lifecycle(mLifecycleOwner);
|
mLifecycle = new Lifecycle(mLifecycleOwner);
|
||||||
mController = spy(new LocationServicePreferenceController(mContext, KEY_LOCATION_SERVICES));
|
mController = spy(
|
||||||
|
new LocationInjectedServicesPreferenceController(mContext, KEY_LOCATION_SERVICES));
|
||||||
when(mFragment.getSettingsLifecycle()).thenReturn(mLifecycle);
|
when(mFragment.getSettingsLifecycle()).thenReturn(mLifecycle);
|
||||||
mController.init(mFragment);
|
mController.init(mFragment);
|
||||||
mController.mInjector = mSettingsInjector;
|
mController.mInjector = mSettingsInjector;
|
@@ -37,18 +37,18 @@ import org.robolectric.RuntimeEnvironment;
|
|||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class LocationScanningPreferenceControllerTest {
|
public class LocationServicesPreferenceControllerTest {
|
||||||
@Mock
|
@Mock
|
||||||
private WifiManager mWifiManager;
|
private WifiManager mWifiManager;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private LocationScanningPreferenceController mController;
|
private LocationServicesPreferenceController mController;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mContext = spy(RuntimeEnvironment.application);
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
when(mContext.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
|
when(mContext.getSystemService(WifiManager.class)).thenReturn(mWifiManager);
|
||||||
mController = new LocationScanningPreferenceController(mContext, "key");
|
mController = new LocationServicesPreferenceController(mContext, "key");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -97,4 +97,4 @@ public class LocationScanningPreferenceControllerTest {
|
|||||||
public void testLocationScanning_ifDisabled_shouldNotBeShown() {
|
public void testLocationScanning_ifDisabled_shouldNotBeShown() {
|
||||||
assertThat(mController.isAvailable()).isFalse();
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user