<string name="location_recent_location_requests_see_all">See all</string>
<!-- Location settings screen, sub category for location services [CHAR LIMIT=30] -->
<string name="location_category_location_services">Location services</string>
+ <!-- Location settings screen, sub category for recent work profile app location requests [CHAR LIMIT=NONE] -->
+ <string name="location_category_recent_location_work_requests">Recent work app location requests</string>
<!-- Security & location settings screen, section header for settings relating to location -->
<string name="location_title">My Location</string>
<!-- This preference gets removed if there is no managed profile -->
<PreferenceCategory
android:key="location_services_managed_profile"
- android:title="@string/managed_profile_location_services"/>
+ android:title="@string/managed_profile_location_services"
+ settings:controller="com.android.settings.location.LocationServiceForWorkPreferenceController"/>
</PreferenceCategory>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2019 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:key="location_settings"
+ android:title="@string/location_settings_title"
+ settings:keywords="@string/keywords_location">
+
+ <PreferenceCategory
+ android:key="recent_location_requests"
+ android:title="@string/location_category_recent_location_requests"
+ settings:controller="com.android.settings.location.RecentLocationRequestPreferenceController"/>
+
+ <Preference
+ android:key="recent_location_requests_see_all_button"
+ android:title="@string/location_recent_location_requests_see_all"
+ android:icon="@drawable/ic_chevron_right_24dp"
+ android:fragment="com.android.settings.location.RecentLocationRequestSeeAllFragment"
+ settings:searchable="false"/>
+
+ <PreferenceCategory
+ android:key="location_advanced_settings"
+ android:layout="@layout/preference_category_no_label"
+ settings:initialExpandedChildrenCount="2">
+
+ <!-- This preference category gets removed if new_recent_location_ui is disabled -->
+ <Preference
+ android:key="app_level_permissions"
+ android:title="@string/location_app_level_permissions"
+ settings:controller="com.android.settings.location.AppLocationPermissionPreferenceController">
+ <intent android:action="android.intent.action.MANAGE_PERMISSION_APPS">
+ <extra android:name="android.intent.extra.PERMISSION_NAME"
+ android:value="android.permission-group.LOCATION"/>
+ </intent>
+ </Preference>
+
+ <Preference
+ android:key="location_scanning"
+ android:title="@string/location_scanning_screen_title"
+ android:fragment="com.android.settings.location.ScanningSettings"
+ settings:controller="com.android.settings.location.LocationScanningPreferenceController"/>
+
+ <PreferenceCategory
+ android:key="location_services"
+ android:layout="@layout/preference_category_no_label"
+ settings:controller="com.android.settings.location.LocationServicePreferenceController"/>
+
+ </PreferenceCategory>
+
+ <PreferenceCategory
+ android:key="location_footer"
+ android:layout="@layout/preference_category_no_label"
+ settings:allowDividerAbove="false"
+ settings:controller="com.android.settings.location.LocationFooterPreferenceController"/>
+</PreferenceScreen>
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2019 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:key="location_settings"
+ android:title="@string/location_settings_title"
+ settings:keywords="@string/keywords_location">
+
+ <com.android.settingslib.RestrictedSwitchPreference
+ android:key="managed_profile_location_switch"
+ android:title="@string/managed_profile_location_switch_title"
+ settings:useAdminDisabledSummary="true"
+ settings:controller="com.android.settings.location.LocationForWorkPreferenceController"
+ android:enabled="false"
+ android:selectable="true"/>
+
+ <PreferenceCategory
+ android:key="recent_location_requests"
+ android:title="@string/location_category_recent_location_work_requests"
+ settings:controller="com.android.settings.location.RecentLocationRequestPreferenceController"/>
+
+ <Preference
+ android:key="recent_location_requests_see_all_button"
+ android:title="@string/location_recent_location_requests_see_all"
+ android:icon="@drawable/ic_chevron_right_24dp"
+ android:fragment="com.android.settings.location.RecentLocationRequestSeeAllFragment"
+ settings:searchable="false"/>
+
+ <PreferenceCategory
+ android:key="location_advanced_settings"
+ android:layout="@layout/preference_category_no_label"
+ settings:initialExpandedChildrenCount="2">
+
+ <!-- This preference category gets removed if new_recent_location_ui is disabled -->
+ <Preference
+ android:key="app_level_permissions"
+ android:title="@string/location_app_level_permissions"
+ settings:controller="com.android.settings.location.AppLocationPermissionPreferenceController">
+ <intent android:action="android.intent.action.MANAGE_PERMISSION_APPS">
+ <extra android:name="android.intent.extra.PERMISSION_NAME"
+ android:value="android.permission-group.LOCATION"/>
+ </intent>
+ </Preference>
+
+ <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.LocationServiceForWorkPreferenceController"/>
+
+ </PreferenceCategory>
+
+ <PreferenceCategory
+ android:key="location_footer"
+ android:layout="@layout/preference_category_no_label"
+ settings:allowDividerAbove="false"
+ settings:controller="com.android.settings.location.LocationFooterPreferenceController"/>
+</PreferenceScreen>
@Override
public int getMetricsCategory() {
- return SettingsEnums.ACCOUNT;
+ return SettingsEnums.ACCOUNT_WORK;
}
@Override
import com.android.settings.accounts.AccountDashboardFragment;
import com.android.settings.applications.manageapplications.ManageApplications;
import com.android.settings.deviceinfo.StorageDashboardFragment;
+import com.android.settings.location.LocationSettings;
import java.util.Map;
ProfileSelectManageApplications.class.getName());
FRAGMENT_MAP.put(StorageDashboardFragment.class.getName(),
ProfileSelectStorageFragment.class.getName());
+ FRAGMENT_MAP.put(LocationSettings.class.getName(),
+ ProfileSelectLocationFragment.class.getName());
}
}
--- /dev/null
+/*
+ * Copyright (C) 2019 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.dashboard.profileselector;
+
+import android.os.Bundle;
+
+import androidx.fragment.app.Fragment;
+
+import com.android.settings.R;
+import com.android.settings.SettingsActivity;
+import com.android.settings.location.LocationPersonalSettings;
+import com.android.settings.location.LocationSwitchBarController;
+import com.android.settings.location.LocationWorkProfileSettings;
+import com.android.settings.widget.SwitchBar;
+
+/**
+ * Location Setting page for personal/managed profile.
+ */
+public class ProfileSelectLocationFragment extends ProfileSelectFragment {
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+ final SettingsActivity activity = (SettingsActivity) getActivity();
+ final SwitchBar switchBar = activity.getSwitchBar();
+ switchBar.setSwitchBarText(R.string.location_settings_master_switch_title,
+ R.string.location_settings_master_switch_title);
+ final LocationSwitchBarController switchBarController = new LocationSwitchBarController(
+ activity, switchBar, getSettingsLifecycle());
+ switchBar.show();
+ }
+
+ @Override
+ public Fragment[] getFragments() {
+ return new Fragment[]{
+ new LocationPersonalSettings(),
+ new LocationWorkProfileSettings()
+ };
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2019 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;
+
+/**
+ * Location Setting page for personal profile.
+ */
+public class LocationPersonalSettings extends DashboardFragment {
+
+ private static final String TAG = "LocationPersonal";
+
+ @Override
+ public int getMetricsCategory() {
+ return SettingsEnums.LOCATION;
+ }
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.location_settings_personal;
+ }
+
+ @Override
+ protected String getLogTag() {
+ return TAG;
+ }
+
+ @Override
+ public void onAttach(Context context) {
+ super.onAttach(context);
+
+ use(AppLocationPermissionPreferenceController.class).init(this);
+ use(RecentLocationRequestPreferenceController.class).init(this);
+ use(LocationServicePreferenceController.class).init(this);
+ use(LocationFooterPreferenceController.class).init(this);
+ }
+
+ @Override
+ public int getHelpResource() {
+ return R.string.help_url_location_access;
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2019 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 android.os.UserHandle;
+
+import androidx.preference.Preference;
+
+import com.android.settings.widget.RestrictedAppPreference;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Retrieve the Location Services used in profile user.
+ */
+public class LocationServiceForWorkPreferenceController extends
+ LocationServicePreferenceController {
+ private static final String TAG = "LocationWorkPrefCtrl";
+
+ public LocationServiceForWorkPreferenceController(Context context, String key) {
+ super(context, key);
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ mCategoryLocationServices.removeAll();
+ final Map<Integer, List<Preference>> prefs = getLocationServices();
+ boolean show = false;
+ for (Map.Entry<Integer, List<Preference>> entry : prefs.entrySet()) {
+ for (Preference pref : entry.getValue()) {
+ if (pref instanceof RestrictedAppPreference) {
+ ((RestrictedAppPreference) pref).checkRestrictionAndSetDisabled();
+ }
+ }
+ if (entry.getKey() != UserHandle.myUserId()) {
+ LocationSettings.addPreferencesSorted(entry.getValue(),
+ mCategoryLocationServices);
+ show = true;
+ }
+ }
+ mCategoryLocationServices.setVisible(show);
+ }
+}
public class LocationServicePreferenceController extends LocationBasePreferenceController
implements LifecycleObserver, OnResume, OnPause {
- private static final String TAG = "LocationServicePrefCtrl";
- /** Key for preference category "Location services" */
- @VisibleForTesting
- static final String KEY_LOCATION_SERVICES = "location_services";
- /** Key for preference category "Location services for work" */
- @VisibleForTesting
- static final String KEY_LOCATION_SERVICES_MANAGED = "location_services_managed_profile";
+ private static final String TAG = "LocationPrefCtrl";
@VisibleForTesting
static final IntentFilter INTENT_FILTER_INJECTED_SETTING_CHANGED =
new IntentFilter(SettingInjectorService.ACTION_INJECTED_SETTING_CHANGED);
- private PreferenceCategory mCategoryLocationServices;
- private PreferenceCategory mCategoryLocationServicesManaged;
+ protected PreferenceCategory mCategoryLocationServices;
@VisibleForTesting
AppSettingsInjector mInjector;
/** Receives UPDATE_INTENT */
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
- mCategoryLocationServices = screen.findPreference(KEY_LOCATION_SERVICES);
- mCategoryLocationServicesManaged = screen.findPreference(KEY_LOCATION_SERVICES_MANAGED);
+ mCategoryLocationServices = screen.findPreference(getPreferenceKey());
}
@Override
public void updateState(Preference preference) {
- if (mCategoryLocationServices != null) {
- mCategoryLocationServices.removeAll();
- }
- if (mCategoryLocationServicesManaged != null) {
- mCategoryLocationServicesManaged.removeAll();
- }
+ mCategoryLocationServices.removeAll();
final Map<Integer, List<Preference>> prefs = getLocationServices();
- boolean showPrimary = false;
- boolean showManaged = false;
+ boolean show = false;
for (Map.Entry<Integer, List<Preference>> entry : prefs.entrySet()) {
for (Preference pref : entry.getValue()) {
if (pref instanceof RestrictedAppPreference) {
LocationSettings.addPreferencesSorted(entry.getValue(),
mCategoryLocationServices);
}
- showPrimary = true;
- } else {
- if (mCategoryLocationServicesManaged != null) {
- LocationSettings.addPreferencesSorted(entry.getValue(),
- mCategoryLocationServicesManaged);
- }
- showManaged = true;
+ show = true;
}
}
- if (mCategoryLocationServices != null) {
- mCategoryLocationServices.setVisible(showPrimary);
- }
- if (mCategoryLocationServicesManaged != null) {
- mCategoryLocationServicesManaged.setVisible(showManaged);
- }
+ mCategoryLocationServices.setVisible(show);
}
@Override
mContext.unregisterReceiver(mInjectedSettingsReceiver);
}
- private Map<Integer, List<Preference>> getLocationServices() {
+ protected Map<Integer, List<Preference>> getLocationServices() {
// If location access is locked down by device policy then we only show injected settings
// for the primary profile.
final int profileUserId = Utils.getManagedProfileId(mUserManager, UserHandle.myUserId());
use(LocationServicePreferenceController.class).init(this);
use(LocationFooterPreferenceController.class).init(this);
use(LocationForWorkPreferenceController.class).init(this);
+ use(LocationServiceForWorkPreferenceController.class).init(this);
}
@Override
--- /dev/null
+/*
+ * Copyright (C) 2019 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;
+
+/**
+ * Location Setting page for managed profile.
+ */
+public class LocationWorkProfileSettings extends DashboardFragment {
+
+ private static final String TAG = "LocationWorkProfile";
+
+ @Override
+ public int getMetricsCategory() {
+ return SettingsEnums.LOCATION_WORK;
+ }
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.location_settings_workprofile;
+ }
+
+ @Override
+ protected String getLogTag() {
+ return TAG;
+ }
+
+ @Override
+ public void onAttach(Context context) {
+ super.onAttach(context);
+
+ use(AppLocationPermissionPreferenceController.class).init(this);
+ use(RecentLocationRequestPreferenceController.class).init(this);
+ use(LocationServiceForWorkPreferenceController.class).init(this);
+ use(LocationFooterPreferenceController.class).init(this);
+ use(LocationForWorkPreferenceController.class).init(this);
+ }
+
+ @Override
+ public int getHelpResource() {
+ return R.string.help_url_location_access;
+ }
+}
com.android.settings.dashboard.profileselector.ProfileSelectAccountFragment
com.android.settings.dashboard.profileselector.ProfileSelectManageApplications
com.android.settings.dashboard.profileselector.ProfileSelectStorageFragment
+com.android.settings.dashboard.profileselector.ProfileSelectLocationFragment
com.android.settings.datausage.AppDataUsage
com.android.settings.datausage.DataUsageList
com.android.settings.datausage.DataUsageSummary
com.android.settings.inputmethod.KeyboardLayoutPickerFragment
com.android.settings.inputmethod.SpellCheckersSettings
com.android.settings.localepicker.LocaleListEditor
+com.android.settings.location.LocationPersonalSettings
+com.android.settings.location.LocationWorkProfileSettings
com.android.settings.network.ApnEditor
com.android.settings.network.ApnSettings
com.android.settings.network.telephony.NetworkSelectSettings
*/
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;
@Config(shadows = ShadowUserManager.class)
public class LocationServicePreferenceControllerTest {
+ private static final String KEY_LOCATION_SERVICES = "location_service";
+
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private LocationSettings mFragment;
@Mock
mController.mInjector = mSettingsInjector;
final String key = mController.getPreferenceKey();
when(mScreen.findPreference(key)).thenReturn(mCategoryPrimary);
- when(mScreen.findPreference(KEY_LOCATION_SERVICES_MANAGED)).thenReturn(
- mCategoryManaged);
when(mCategoryPrimary.getKey()).thenReturn(key);
- when(mCategoryManaged.getKey()).thenReturn(KEY_LOCATION_SERVICES_MANAGED);
when(mContext.getSystemService(Context.DEVICE_POLICY_SERVICE))
.thenReturn(mDevicePolicyManager);
}