Gilles Debunne | a6a8a14 | 2011-06-09 11:56:17 -0700 | [diff] [blame] | 1 | /* |
| 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 Tang | 83ab7c9 | 2013-07-29 12:07:48 -0700 | [diff] [blame] | 17 | package com.android.settings.location; |
Gilles Debunne | a6a8a14 | 2011-06-09 11:56:17 -0700 | [diff] [blame] | 18 | |
Fan Zhang | 31b2100 | 2019-01-16 13:49:47 -0800 | [diff] [blame] | 19 | import android.app.settings.SettingsEnums; |
Lifu Tang | 32e016b | 2013-08-22 17:43:19 -0700 | [diff] [blame] | 20 | import android.content.Context; |
Lifu Tang | 32e016b | 2013-08-22 17:43:19 -0700 | [diff] [blame] | 21 | import android.location.SettingInjectorService; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 22 | import android.os.Bundle; |
Fan Zhang | c8f021a | 2018-06-11 15:35:03 -0700 | [diff] [blame] | 23 | |
Fan Zhang | 9ce4a1f | 2018-08-15 12:55:56 -0700 | [diff] [blame] | 24 | import androidx.preference.Preference; |
| 25 | import androidx.preference.PreferenceGroup; |
| 26 | |
Lifu Tang | 83ab7c9 | 2013-07-29 12:07:48 -0700 | [diff] [blame] | 27 | import com.android.settings.R; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 28 | import com.android.settings.SettingsActivity; |
Doris Ling | 9ed29a2 | 2017-11-02 16:42:45 -0700 | [diff] [blame] | 29 | import com.android.settings.dashboard.DashboardFragment; |
Fan Zhang | 89b8e5c | 2017-10-23 15:21:09 -0700 | [diff] [blame] | 30 | import com.android.settings.search.BaseSearchIndexProvider; |
Fan Zhang | 87d120a | 2018-01-11 13:31:43 -0800 | [diff] [blame] | 31 | import com.android.settings.widget.SwitchBar; |
Lifu Tang | 166b54c | 2019-05-06 15:24:04 -0700 | [diff] [blame] | 32 | import com.android.settingslib.location.RecentLocationApps; |
Tony Mantler | 0fcd6cb | 2018-03-26 15:17:25 -0700 | [diff] [blame] | 33 | import com.android.settingslib.search.SearchIndexable; |
| 34 | |
Lifu Tang | 25518c3 | 2013-08-20 19:40:44 -0700 | [diff] [blame] | 35 | import java.util.Collections; |
| 36 | import java.util.Comparator; |
| 37 | import java.util.List; |
| 38 | |
Gilles Debunne | a6a8a14 | 2011-06-09 11:56:17 -0700 | [diff] [blame] | 39 | /** |
Tom O'Neill | 67dc554 | 2015-05-18 14:13:29 -0700 | [diff] [blame] | 40 | * System location settings (Settings > Location). The screen has three parts: |
| 41 | * <ul> |
| 42 | * <li>Platform location controls</li> |
| 43 | * <ul> |
Maggie | 85e2f61 | 2018-01-04 15:35:49 -0800 | [diff] [blame] | 44 | * <li>In switch bar: location master switch. Used to toggle location on and off. |
Tom O'Neill | 67dc554 | 2015-05-18 14:13:29 -0700 | [diff] [blame] | 45 | * </li> |
Tom O'Neill | 67dc554 | 2015-05-18 14:13:29 -0700 | [diff] [blame] | 46 | * </ul> |
Lifu Tang | 166b54c | 2019-05-06 15:24:04 -0700 | [diff] [blame] | 47 | * <li>Recent location requests: automatically populated by {@link RecentLocationApps}</li> |
Tom O'Neill | 67dc554 | 2015-05-18 14:13:29 -0700 | [diff] [blame] | 48 | * <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 Debunne | a6a8a14 | 2011-06-09 11:56:17 -0700 | [diff] [blame] | 56 | */ |
Tony Mantler | 0fcd6cb | 2018-03-26 15:17:25 -0700 | [diff] [blame] | 57 | @SearchIndexable |
Doris Ling | 9ed29a2 | 2017-11-02 16:42:45 -0700 | [diff] [blame] | 58 | public class LocationSettings extends DashboardFragment { |
Tom O'Neill | e17ce5f | 2013-08-23 15:23:12 -0700 | [diff] [blame] | 59 | |
| 60 | private static final String TAG = "LocationSettings"; |
| 61 | |
Doris Ling | 9ed29a2 | 2017-11-02 16:42:45 -0700 | [diff] [blame] | 62 | private LocationSwitchBarController mSwitchBarController; |
Lifu Tang | c3e9ac9 | 2013-08-12 16:34:45 -0700 | [diff] [blame] | 63 | |
Gilles Debunne | a6a8a14 | 2011-06-09 11:56:17 -0700 | [diff] [blame] | 64 | @Override |
Fan Zhang | 6507613 | 2016-08-08 10:25:13 -0700 | [diff] [blame] | 65 | public int getMetricsCategory() { |
Fan Zhang | 31b2100 | 2019-01-16 13:49:47 -0800 | [diff] [blame] | 66 | return SettingsEnums.LOCATION; |
Chris Wren | 8a963ba | 2015-03-20 10:29:14 -0400 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | @Override |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 70 | public void onActivityCreated(Bundle savedInstanceState) { |
| 71 | super.onActivityCreated(savedInstanceState); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 72 | final SettingsActivity activity = (SettingsActivity) getActivity(); |
Fan Zhang | 87d120a | 2018-01-11 13:31:43 -0800 | [diff] [blame] | 73 | final SwitchBar switchBar = activity.getSwitchBar(); |
| 74 | switchBar.setSwitchBarText(R.string.location_settings_master_switch_title, |
| 75 | R.string.location_settings_master_switch_title); |
tmfang | 27c84de | 2018-06-28 11:39:05 +0800 | [diff] [blame] | 76 | mSwitchBarController = new LocationSwitchBarController(activity, switchBar, |
| 77 | getSettingsLifecycle()); |
Maggie | 601054c | 2018-03-02 09:56:19 -0800 | [diff] [blame] | 78 | switchBar.show(); |
Fabrice Di Meglio | 138ff8c | 2014-06-11 20:14:15 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | @Override |
Raff Tsai | 2229585 | 2019-11-22 11:35:40 +0800 | [diff] [blame] | 82 | 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 Tsai | 5089629 | 2019-11-22 16:36:21 +0800 | [diff] [blame] | 90 | use(LocationServiceForWorkPreferenceController.class).init(this); |
Raff Tsai | 2229585 | 2019-11-22 11:35:40 +0800 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | @Override |
Doris Ling | 9ed29a2 | 2017-11-02 16:42:45 -0700 | [diff] [blame] | 94 | protected int getPreferenceScreenResId() { |
Raff Tsai | 966fa01 | 2019-09-25 11:19:06 +0800 | [diff] [blame] | 95 | return R.xml.location_settings; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | @Override |
Doris Ling | 9ed29a2 | 2017-11-02 16:42:45 -0700 | [diff] [blame] | 99 | protected String getLogTag() { |
| 100 | return TAG; |
Gilles Debunne | a6a8a14 | 2011-06-09 11:56:17 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Doris Ling | 9ed29a2 | 2017-11-02 16:42:45 -0700 | [diff] [blame] | 103 | static void addPreferencesSorted(List<Preference> prefs, PreferenceGroup container) { |
Lifu Tang | 25518c3 | 2013-08-20 19:40:44 -0700 | [diff] [blame] | 104 | // If there's some items to display, sort the items and add them to the container. |
Fan Zhang | a4da9d7 | 2018-12-20 16:21:46 -0800 | [diff] [blame] | 105 | Collections.sort(prefs, |
| 106 | Comparator.comparing(lhs -> lhs.getTitle().toString())); |
Lifu Tang | 25518c3 | 2013-08-20 19:40:44 -0700 | [diff] [blame] | 107 | for (Preference entry : prefs) { |
| 108 | container.addPreference(entry); |
| 109 | } |
| 110 | } |
| 111 | |
Amith Yamasani | 38223dc | 2012-09-18 09:51:07 -0700 | [diff] [blame] | 112 | @Override |
| 113 | public int getHelpResource() { |
| 114 | return R.string.help_url_location_access; |
| 115 | } |
Amith Yamasani | 8442db2 | 2012-07-25 18:28:51 -0700 | [diff] [blame] | 116 | |
Fan Zhang | 89b8e5c | 2017-10-23 15:21:09 -0700 | [diff] [blame] | 117 | /** |
| 118 | * For Search. |
| 119 | */ |
Raff Tsai | ac3e0d0 | 2019-09-19 17:06:45 +0800 | [diff] [blame] | 120 | public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = |
Raff Tsai | 2229585 | 2019-11-22 11:35:40 +0800 | [diff] [blame] | 121 | new BaseSearchIndexProvider(R.xml.location_settings); |
Amith Yamasani | 8442db2 | 2012-07-25 18:28:51 -0700 | [diff] [blame] | 122 | } |