blob: 26a4afdc7c61f4ad5db7c2fe08c89a130aed621e [file] [log] [blame]
Gilles Debunnea6a8a142011-06-09 11:56:17 -07001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Lifu Tang83ab7c92013-07-29 12:07:48 -070017package com.android.settings.location;
Gilles Debunnea6a8a142011-06-09 11:56:17 -070018
Fan Zhang31b21002019-01-16 13:49:47 -080019import android.app.settings.SettingsEnums;
Lifu Tang32e016b2013-08-22 17:43:19 -070020import android.content.Context;
Lifu Tang32e016b2013-08-22 17:43:19 -070021import android.location.SettingInjectorService;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080022import android.os.Bundle;
Fan Zhangc8f021a2018-06-11 15:35:03 -070023
Fan Zhang9ce4a1f2018-08-15 12:55:56 -070024import androidx.preference.Preference;
25import androidx.preference.PreferenceGroup;
26
Lifu Tang83ab7c92013-07-29 12:07:48 -070027import com.android.settings.R;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080028import com.android.settings.SettingsActivity;
Doris Ling9ed29a22017-11-02 16:42:45 -070029import com.android.settings.dashboard.DashboardFragment;
Fan Zhang89b8e5c2017-10-23 15:21:09 -070030import com.android.settings.search.BaseSearchIndexProvider;
Fan Zhang87d120a2018-01-11 13:31:43 -080031import com.android.settings.widget.SwitchBar;
Lifu Tang166b54c2019-05-06 15:24:04 -070032import com.android.settingslib.location.RecentLocationApps;
Tony Mantler0fcd6cb2018-03-26 15:17:25 -070033import com.android.settingslib.search.SearchIndexable;
34
Lifu Tang25518c32013-08-20 19:40:44 -070035import java.util.Collections;
36import java.util.Comparator;
37import java.util.List;
38
Gilles Debunnea6a8a142011-06-09 11:56:17 -070039/**
Tom O'Neill67dc5542015-05-18 14:13:29 -070040 * System location settings (Settings > Location). The screen has three parts:
41 * <ul>
42 * <li>Platform location controls</li>
43 * <ul>
Maggie85e2f612018-01-04 15:35:49 -080044 * <li>In switch bar: location master switch. Used to toggle location on and off.
Tom O'Neill67dc5542015-05-18 14:13:29 -070045 * </li>
Tom O'Neill67dc5542015-05-18 14:13:29 -070046 * </ul>
Lifu Tang166b54c2019-05-06 15:24:04 -070047 * <li>Recent location requests: automatically populated by {@link RecentLocationApps}</li>
Tom O'Neill67dc5542015-05-18 14:13:29 -070048 * <li>Location services: multi-app settings provided from outside the Android framework. Each
49 * is injected by a system-partition app via the {@link SettingInjectorService} API.</li>
50 * </ul>
51 * <p>
52 * Note that as of KitKat, the {@link SettingInjectorService} is the preferred method for OEMs to
53 * add their own settings to this page, rather than directly modifying the framework code. Among
54 * other things, this simplifies integration with future changes to the default (AOSP)
55 * implementation.
Gilles Debunnea6a8a142011-06-09 11:56:17 -070056 */
Tony Mantler0fcd6cb2018-03-26 15:17:25 -070057@SearchIndexable
Doris Ling9ed29a22017-11-02 16:42:45 -070058public class LocationSettings extends DashboardFragment {
Tom O'Neille17ce5f2013-08-23 15:23:12 -070059
60 private static final String TAG = "LocationSettings";
61
Doris Ling9ed29a22017-11-02 16:42:45 -070062 private LocationSwitchBarController mSwitchBarController;
Lifu Tangc3e9ac92013-08-12 16:34:45 -070063
Gilles Debunnea6a8a142011-06-09 11:56:17 -070064 @Override
Fan Zhang65076132016-08-08 10:25:13 -070065 public int getMetricsCategory() {
Fan Zhang31b21002019-01-16 13:49:47 -080066 return SettingsEnums.LOCATION;
Chris Wren8a963ba2015-03-20 10:29:14 -040067 }
68
69 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080070 public void onActivityCreated(Bundle savedInstanceState) {
71 super.onActivityCreated(savedInstanceState);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080072 final SettingsActivity activity = (SettingsActivity) getActivity();
Fan Zhang87d120a2018-01-11 13:31:43 -080073 final SwitchBar switchBar = activity.getSwitchBar();
74 switchBar.setSwitchBarText(R.string.location_settings_master_switch_title,
75 R.string.location_settings_master_switch_title);
tmfang27c84de2018-06-28 11:39:05 +080076 mSwitchBarController = new LocationSwitchBarController(activity, switchBar,
77 getSettingsLifecycle());
Maggie601054c2018-03-02 09:56:19 -080078 switchBar.show();
Fabrice Di Meglio138ff8c2014-06-11 20:14:15 -070079 }
80
81 @Override
Raff Tsai22295852019-11-22 11:35:40 +080082 public void onAttach(Context context) {
83 super.onAttach(context);
84
85 use(AppLocationPermissionPreferenceController.class).init(this);
86 use(RecentLocationRequestPreferenceController.class).init(this);
87 use(LocationServicePreferenceController.class).init(this);
88 use(LocationFooterPreferenceController.class).init(this);
89 use(LocationForWorkPreferenceController.class).init(this);
Raff Tsai50896292019-11-22 16:36:21 +080090 use(LocationServiceForWorkPreferenceController.class).init(this);
Raff Tsai22295852019-11-22 11:35:40 +080091 }
92
93 @Override
Doris Ling9ed29a22017-11-02 16:42:45 -070094 protected int getPreferenceScreenResId() {
Raff Tsai966fa012019-09-25 11:19:06 +080095 return R.xml.location_settings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080096 }
97
98 @Override
Doris Ling9ed29a22017-11-02 16:42:45 -070099 protected String getLogTag() {
100 return TAG;
Gilles Debunnea6a8a142011-06-09 11:56:17 -0700101 }
102
Doris Ling9ed29a22017-11-02 16:42:45 -0700103 static void addPreferencesSorted(List<Preference> prefs, PreferenceGroup container) {
Lifu Tang25518c32013-08-20 19:40:44 -0700104 // If there's some items to display, sort the items and add them to the container.
Fan Zhanga4da9d72018-12-20 16:21:46 -0800105 Collections.sort(prefs,
106 Comparator.comparing(lhs -> lhs.getTitle().toString()));
Lifu Tang25518c32013-08-20 19:40:44 -0700107 for (Preference entry : prefs) {
108 container.addPreference(entry);
109 }
110 }
111
Amith Yamasani38223dc2012-09-18 09:51:07 -0700112 @Override
113 public int getHelpResource() {
114 return R.string.help_url_location_access;
115 }
Amith Yamasani8442db22012-07-25 18:28:51 -0700116
Fan Zhang89b8e5c2017-10-23 15:21:09 -0700117 /**
118 * For Search.
119 */
Raff Tsaiac3e0d02019-09-19 17:06:45 +0800120 public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
Raff Tsai22295852019-11-22 11:35:40 +0800121 new BaseSearchIndexProvider(R.xml.location_settings);
Amith Yamasani8442db22012-07-25 18:28:51 -0700122}