blob: 07ba41494bf0fe3f6904fef976e124004cecc9c0 [file] [log] [blame]
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001/*
2 * Copyright (C) 2014 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
17package com.android.settings;
18
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080019import android.app.ActionBar;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080020import android.app.Fragment;
21import android.app.FragmentManager;
22import android.app.FragmentTransaction;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080023import android.content.BroadcastReceiver;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070024import android.content.ComponentName;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080025import android.content.Context;
26import android.content.Intent;
27import android.content.IntentFilter;
28import android.content.SharedPreferences;
29import android.content.pm.ActivityInfo;
30import android.content.pm.PackageManager;
31import android.content.pm.PackageManager.NameNotFoundException;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080032import android.content.res.Configuration;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080033import android.nfc.NfcAdapter;
Jason Monkfd2c7222015-12-02 15:38:38 -050034import android.os.AsyncTask;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080035import android.os.Bundle;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080036import android.os.UserHandle;
37import android.os.UserManager;
Jason Monk39b46742015-09-10 15:52:51 -040038import android.support.v14.preference.PreferenceFragment;
39import android.support.v7.preference.Preference;
40import android.support.v7.preference.PreferenceManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080041import android.text.TextUtils;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070042import android.transition.TransitionManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080043import android.util.Log;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070044import android.view.Menu;
45import android.view.MenuInflater;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080046import android.view.MenuItem;
47import android.view.View;
48import android.view.View.OnClickListener;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070049import android.view.ViewGroup;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080050import android.widget.Button;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070051import android.widget.SearchView;
Fan Zhang28691572016-03-23 15:31:08 -070052
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080053import com.android.internal.util.ArrayUtils;
Jason Monk4da79e02015-09-10 10:54:36 -040054import com.android.settings.Settings.WifiSettingsActivity;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080055import com.android.settings.accessibility.AccessibilitySettings;
Anna Galuszab1795f52016-01-08 14:37:16 -080056import com.android.settings.accessibility.AccessibilitySettingsForSetupWizard;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080057import com.android.settings.accessibility.CaptionPropertiesFragment;
Alexandra Gherghina6d839872014-07-22 12:04:58 +000058import com.android.settings.accounts.AccountSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080059import com.android.settings.accounts.AccountSyncSettings;
Jason Monkb7e43802016-06-06 16:01:58 -040060import com.android.settings.accounts.ChooseAccountActivity;
Tony Mak64f6d982016-05-03 18:55:41 +010061import com.android.settings.accounts.ManagedProfileSettings;
Jason Monk91e2f892016-02-23 15:31:09 -050062import com.android.settings.applications.AdvancedAppSettings;
Billy Laufee78562015-07-27 12:57:07 +010063import com.android.settings.applications.DrawOverlayDetails;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070064import com.android.settings.applications.InstalledAppDetails;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080065import com.android.settings.applications.ManageApplications;
Xiyuan Xia86a55402015-06-02 14:55:32 -070066import com.android.settings.applications.ManageAssist;
Todd Kennedy2ef1aa52016-09-06 14:02:38 -070067import com.android.settings.applications.ManageDomainUrls;
Jason Monka2d47fc2016-03-03 10:49:44 -050068import com.android.settings.applications.NotificationApps;
Jason Monk2cdafc62015-06-12 12:32:50 -040069import com.android.settings.applications.ProcessStatsSummary;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080070import com.android.settings.applications.ProcessStatsUi;
Jason Monkd8da51c2015-04-17 14:34:12 -040071import com.android.settings.applications.UsageAccessDetails;
Ruben Brunkc461d5c2016-04-07 21:45:41 -070072import com.android.settings.applications.VrListenerSettings;
Fan Zhangece8ff62016-06-30 13:20:12 -070073import com.android.settings.applications.WriteSettingsDetails;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080074import com.android.settings.bluetooth.BluetoothSettings;
Fan Zhang28691572016-03-23 15:31:08 -070075import com.android.settings.dashboard.DashboardContainerFragment;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070076import com.android.settings.dashboard.SearchResultsSummary;
Jason Monkb37e2882016-01-11 14:27:20 -050077import com.android.settings.datausage.DataUsageSummary;
Jason Monkb7e43802016-06-06 16:01:58 -040078import com.android.settings.deviceinfo.ImeiInformation;
Jeff Sharkeya16257d2015-04-28 13:41:01 -070079import com.android.settings.deviceinfo.PrivateVolumeForget;
Jeff Sharkeye77f0682015-04-29 11:24:57 -070080import com.android.settings.deviceinfo.PrivateVolumeSettings;
Jeff Sharkey42833b22015-04-11 21:27:33 -070081import com.android.settings.deviceinfo.PublicVolumeSettings;
Jason Monkb7e43802016-06-06 16:01:58 -040082import com.android.settings.deviceinfo.SimStatus;
83import com.android.settings.deviceinfo.Status;
Jeff Sharkey42833b22015-04-11 21:27:33 -070084import com.android.settings.deviceinfo.StorageSettings;
Justin Klaasseneae3d9f2016-07-21 19:25:17 -070085import com.android.settings.display.NightDisplaySettings;
John Spurlockc7f8e8c2014-06-04 19:11:22 -040086import com.android.settings.fuelgauge.BatterySaverSettings;
Jason Monk1eb54eb2015-04-29 12:46:42 -040087import com.android.settings.fuelgauge.PowerUsageDetail;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080088import com.android.settings.fuelgauge.PowerUsageSummary;
Doris Ling91365232016-05-23 17:06:26 -070089import com.android.settings.gestures.GestureSettings;
Abodunrinwa Toki976bb3f2016-01-20 18:43:20 +000090import com.android.settings.inputmethod.AvailableVirtualKeyboardFragment;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080091import com.android.settings.inputmethod.InputMethodAndLanguageSettings;
92import com.android.settings.inputmethod.KeyboardLayoutPickerFragment;
Abodunrinwa Toki5f0b59b2016-01-25 23:02:23 +000093import com.android.settings.inputmethod.KeyboardLayoutPickerFragment2;
Abodunrinwa Tokib28b2cc2016-03-22 16:29:38 +000094import com.android.settings.inputmethod.PhysicalKeyboardFragment;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080095import com.android.settings.inputmethod.SpellCheckersSettings;
96import com.android.settings.inputmethod.UserDictionaryList;
Mihai Nitad7d48fd2016-01-12 08:55:05 -080097import com.android.settings.localepicker.LocaleListEditor;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080098import com.android.settings.location.LocationSettings;
99import com.android.settings.nfc.AndroidBeam;
100import com.android.settings.nfc.PaymentSettings;
John Spurlock802ddf92014-07-18 11:51:13 -0400101import com.android.settings.notification.AppNotificationSettings;
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500102import com.android.settings.notification.ConfigureNotificationSettings;
John Spurlock4a350512014-04-08 14:08:21 -0400103import com.android.settings.notification.NotificationAccessSettings;
John Spurlock4a350512014-04-08 14:08:21 -0400104import com.android.settings.notification.NotificationStation;
Jason Monk2ebc8a02015-02-13 15:23:19 -0500105import com.android.settings.notification.OtherSoundSettings;
Jason Monkb37e2882016-01-11 14:27:20 -0500106import com.android.settings.notification.SoundSettings;
John Spurlock08531a82015-05-07 17:45:43 -0400107import com.android.settings.notification.ZenAccessSettings;
John Spurlock533a5662015-06-19 10:47:36 -0400108import com.android.settings.notification.ZenModeAutomationSettings;
John Spurlockf57bad72015-04-30 09:26:15 -0400109import com.android.settings.notification.ZenModeEventRuleSettings;
John Spurlockc1df2aa2015-04-13 20:57:06 -0400110import com.android.settings.notification.ZenModePrioritySettings;
John Spurlock45fa1402015-04-09 12:50:04 -0400111import com.android.settings.notification.ZenModeScheduleRuleSettings;
Jason Monk39b46742015-09-10 15:52:51 -0400112import com.android.settings.notification.ZenModeSettings;
Julia Reynolds5555d262015-11-09 10:52:17 -0500113import com.android.settings.notification.ZenModeVisualInterruptionSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800114import com.android.settings.print.PrintJobSettingsFragment;
115import com.android.settings.print.PrintSettingsFragment;
Dan Sandler12c4ba42016-03-28 11:13:40 -0400116import com.android.settings.qstile.DevelopmentTiles;
Jason Monk2ebc8a02015-02-13 15:23:19 -0500117import com.android.settings.search.DynamicIndexableContentMonitor;
118import com.android.settings.search.Index;
PauloftheWest38155612014-06-30 10:02:36 -0700119import com.android.settings.sim.SimSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800120import com.android.settings.tts.TextToSpeechSettings;
121import com.android.settings.users.UserSettings;
122import com.android.settings.vpn2.VpnSettings;
123import com.android.settings.wfd.WifiDisplaySettings;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700124import com.android.settings.widget.SwitchBar;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800125import com.android.settings.wifi.AdvancedWifiSettings;
PauloftheWest7837b992014-06-24 07:42:27 -0700126import com.android.settings.wifi.SavedAccessPointsWifiSettings;
Jason Monkb7e43802016-06-06 16:01:58 -0400127import com.android.settings.wifi.WifiAPITest;
128import com.android.settings.wifi.WifiInfo;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800129import com.android.settings.wifi.WifiSettings;
130import com.android.settings.wifi.p2p.WifiP2pSettings;
Jason Monk4da79e02015-09-10 10:54:36 -0400131import com.android.settingslib.drawer.DashboardCategory;
Jason Monk4da79e02015-09-10 10:54:36 -0400132import com.android.settingslib.drawer.SettingsDrawerActivity;
Jason Monk7ea14c52016-01-22 14:28:02 -0500133import com.android.settingslib.drawer.Tile;
Jason Monk2ebc8a02015-02-13 15:23:19 -0500134
Doris Ling26bf0032016-06-15 18:16:09 -0700135import java.net.URISyntaxException;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800136import java.util.ArrayList;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800137import java.util.List;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700138import java.util.Set;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800139
Jason Monk4da79e02015-09-10 10:54:36 -0400140public class SettingsActivity extends SettingsDrawerActivity
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800141 implements PreferenceManager.OnPreferenceTreeClickListener,
142 PreferenceFragment.OnPreferenceStartFragmentCallback,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100143 ButtonBarHandler, FragmentManager.OnBackStackChangedListener,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700144 SearchView.OnQueryTextListener, SearchView.OnCloseListener,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100145 MenuItem.OnActionExpandListener {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800146
147 private static final String LOG_TAG = "Settings";
148
Philip P. Moltmannd9779db2016-02-24 12:11:05 -0800149 private static final int LOADER_ID_INDEXABLE_CONTENT_MONITOR = 1;
150
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800151 // Constants for state save/restore
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700152 private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700153 private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
154 private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700155 private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700156 private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700157 private static final String SAVE_KEY_HOME_ACTIVITIES_COUNT = ":settings:home_activities_count";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800158
159 /**
160 * When starting this activity, the invoking Intent can contain this extra
161 * string to specify which fragment should be initially displayed.
162 * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
163 * will call isValidFragment() to confirm that the fragment class name is valid for this
164 * activity.
165 */
166 public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
167
168 /**
169 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
170 * this extra can also be specified to supply a Bundle of arguments to pass
171 * to that fragment when it is instantiated during the initial creation
172 * of the activity.
173 */
174 public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
175
176 /**
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700177 * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
178 */
179 public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
180
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800181 public static final String BACK_STACK_PREFS = ":settings:prefs";
182
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800183 // extras that allow any preference activity to be launched as part of a wizard
184
185 // show Back and Next buttons? takes boolean parameter
186 // Back will then return RESULT_CANCELED and Next RESULT_OK
187 protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
188
189 // add a Skip button?
190 private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
191
192 // specify custom text for the Back or Next buttons, or cause a button to not appear
193 // at all by setting it to null
194 protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
195 protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
196
197 /**
198 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700199 * those extra can also be specify to supply the title or title res id to be shown for
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800200 * that fragment.
201 */
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700202 public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100203 /**
204 * The package name used to resolve the title resource id.
205 */
206 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
207 ":settings:show_fragment_title_res_package_name";
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700208 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
209 ":settings:show_fragment_title_resid";
210 public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
211 ":settings:show_fragment_as_shortcut";
212
213 public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
214 ":settings:show_fragment_as_subsetting";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800215
Udam Saini92779ce2016-03-28 14:29:48 -0700216 public static final String EXTRA_HIDE_DRAWER = ":settings:hide_drawer";
217
Jason Monk30695812015-11-17 09:01:08 -0500218 public static final String META_DATA_KEY_FRAGMENT_CLASS =
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800219 "com.android.settings.FRAGMENT_CLASS";
220
221 private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
222
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700223 private static final String EMPTY_QUERY = "";
224
Jason Monkd4f03ec2016-01-07 16:25:34 -0500225 private static final int REQUEST_SUGGESTION = 42;
226
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800227 private String mFragmentClass;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800228
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800229 private CharSequence mInitialTitle;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700230 private int mInitialTitleResId;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800231
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800232 // Show only these settings for restricted users
Jason Monk4da79e02015-09-10 10:54:36 -0400233 private String[] SETTINGS_FOR_RESTRICTED = {
234 //wireless_section
235 WifiSettingsActivity.class.getName(),
236 Settings.BluetoothSettingsActivity.class.getName(),
237 Settings.DataUsageSummaryActivity.class.getName(),
238 Settings.SimSettingsActivity.class.getName(),
239 Settings.WirelessSettingsActivity.class.getName(),
240 //device_section
241 Settings.HomeSettingsActivity.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500242 Settings.SoundSettingsActivity.class.getName(),
Jason Monk4da79e02015-09-10 10:54:36 -0400243 Settings.DisplaySettingsActivity.class.getName(),
244 Settings.StorageSettingsActivity.class.getName(),
245 Settings.ManageApplicationsActivity.class.getName(),
246 Settings.PowerUsageSummaryActivity.class.getName(),
Doris Ling91365232016-05-23 17:06:26 -0700247 Settings.GestureSettingsActivity.class.getName(),
Jason Monk4da79e02015-09-10 10:54:36 -0400248 //personal_section
249 Settings.LocationSettingsActivity.class.getName(),
250 Settings.SecuritySettingsActivity.class.getName(),
251 Settings.InputMethodAndLanguageSettingsActivity.class.getName(),
252 Settings.UserSettingsActivity.class.getName(),
253 Settings.AccountSettingsActivity.class.getName(),
254 //system_section
255 Settings.DateTimeSettingsActivity.class.getName(),
256 Settings.DeviceInfoSettingsActivity.class.getName(),
257 Settings.AccessibilitySettingsActivity.class.getName(),
258 Settings.PrintSettingsActivity.class.getName(),
259 Settings.PaymentSettingsActivity.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800260 };
261
262 private static final String[] ENTRY_FRAGMENTS = {
263 WirelessSettings.class.getName(),
264 WifiSettings.class.getName(),
265 AdvancedWifiSettings.class.getName(),
PauloftheWest7837b992014-06-24 07:42:27 -0700266 SavedAccessPointsWifiSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800267 BluetoothSettings.class.getName(),
PauloftheWest38155612014-06-30 10:02:36 -0700268 SimSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800269 TetherSettings.class.getName(),
270 WifiP2pSettings.class.getName(),
271 VpnSettings.class.getName(),
272 DateTimeSettings.class.getName(),
Mihai Nitad7d48fd2016-01-12 08:55:05 -0800273 LocaleListEditor.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800274 InputMethodAndLanguageSettings.class.getName(),
Abodunrinwa Toki976bb3f2016-01-20 18:43:20 +0000275 AvailableVirtualKeyboardFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800276 SpellCheckersSettings.class.getName(),
277 UserDictionaryList.class.getName(),
278 UserDictionarySettings.class.getName(),
Amith Yamasani3033ce02014-07-14 18:03:15 -0700279 HomeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800280 DisplaySettings.class.getName(),
281 DeviceInfoSettings.class.getName(),
282 ManageApplications.class.getName(),
Jason Monka2d47fc2016-03-03 10:49:44 -0500283 NotificationApps.class.getName(),
Xiyuan Xia86a55402015-06-02 14:55:32 -0700284 ManageAssist.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800285 ProcessStatsUi.class.getName(),
286 NotificationStation.class.getName(),
287 LocationSettings.class.getName(),
288 SecuritySettings.class.getName(),
Jason Monkd8da51c2015-04-17 14:34:12 -0400289 UsageAccessDetails.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800290 PrivacySettings.class.getName(),
291 DeviceAdminSettings.class.getName(),
292 AccessibilitySettings.class.getName(),
Anna Galuszab1795f52016-01-08 14:37:16 -0800293 AccessibilitySettingsForSetupWizard.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800294 CaptionPropertiesFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800295 com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(),
296 TextToSpeechSettings.class.getName(),
Jeff Sharkey42833b22015-04-11 21:27:33 -0700297 StorageSettings.class.getName(),
Jeff Sharkeya16257d2015-04-28 13:41:01 -0700298 PrivateVolumeForget.class.getName(),
Jeff Sharkeye77f0682015-04-29 11:24:57 -0700299 PrivateVolumeSettings.class.getName(),
300 PublicVolumeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800301 DevelopmentSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800302 AndroidBeam.class.getName(),
303 WifiDisplaySettings.class.getName(),
304 PowerUsageSummary.class.getName(),
305 AccountSyncSettings.class.getName(),
Alexandra Gherghina6d839872014-07-22 12:04:58 +0000306 AccountSettings.class.getName(),
Doris Ling91365232016-05-23 17:06:26 -0700307 GestureSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800308 CryptKeeperSettings.class.getName(),
309 DataUsageSummary.class.getName(),
310 DreamSettings.class.getName(),
311 UserSettings.class.getName(),
312 NotificationAccessSettings.class.getName(),
John Spurlock08531a82015-05-07 17:45:43 -0400313 ZenAccessSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800314 PrintSettingsFragment.class.getName(),
315 PrintJobSettingsFragment.class.getName(),
316 TrustedCredentialsSettings.class.getName(),
317 PaymentSettings.class.getName(),
318 KeyboardLayoutPickerFragment.class.getName(),
Abodunrinwa Toki5f0b59b2016-01-25 23:02:23 +0000319 KeyboardLayoutPickerFragment2.class.getName(),
Abodunrinwa Tokib28b2cc2016-03-22 16:29:38 +0000320 PhysicalKeyboardFragment.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700321 ZenModeSettings.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500322 SoundSettings.class.getName(),
323 ConfigureNotificationSettings.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700324 ChooseLockPassword.ChooseLockPasswordFragment.class.getName(),
325 ChooseLockPattern.ChooseLockPatternFragment.class.getName(),
John Spurlockc7f8e8c2014-06-04 19:11:22 -0400326 InstalledAppDetails.class.getName(),
327 BatterySaverSettings.class.getName(),
Fabrice Di Megliodcf59dd2014-07-21 11:22:20 -0700328 AppNotificationSettings.class.getName(),
Fabrice Di Meglioe3ff4d82014-07-23 20:03:20 -0700329 OtherSoundSettings.class.getName(),
Narayan Kamath33acb152015-03-16 12:48:05 +0000330 ApnSettings.class.getName(),
Jason Monkb7e43802016-06-06 16:01:58 -0400331 ApnEditor.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400332 WifiCallingSettings.class.getName(),
John Spurlockc1df2aa2015-04-13 20:57:06 -0400333 ZenModePrioritySettings.class.getName(),
John Spurlock533a5662015-06-19 10:47:36 -0400334 ZenModeAutomationSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400335 ZenModeScheduleRuleSettings.class.getName(),
John Spurlockf57bad72015-04-30 09:26:15 -0400336 ZenModeEventRuleSettings.class.getName(),
Julia Reynolds5555d262015-11-09 10:52:17 -0500337 ZenModeVisualInterruptionSettings.class.getName(),
Jason Monk2583fc12015-03-25 09:46:30 -0400338 ProcessStatsUi.class.getName(),
Jason Monk1eb54eb2015-04-29 12:46:42 -0400339 PowerUsageDetail.class.getName(),
Jason Monk2cdafc62015-06-12 12:32:50 -0400340 ProcessStatsSummary.class.getName(),
Billy Laufee78562015-07-27 12:57:07 +0100341 DrawOverlayDetails.class.getName(),
342 WriteSettingsDetails.class.getName(),
Jason Monk91e2f892016-02-23 15:31:09 -0500343 AdvancedAppSettings.class.getName(),
Jason Monkb9e5d232016-01-26 17:43:57 -0500344 WallpaperTypeSettings.class.getName(),
Ruben Brunkc461d5c2016-04-07 21:45:41 -0700345 VrListenerSettings.class.getName(),
Tony Mak64f6d982016-05-03 18:55:41 +0100346 ManagedProfileSettings.class.getName(),
Jason Monkb7e43802016-06-06 16:01:58 -0400347 ChooseAccountActivity.class.getName(),
348 IccLockSettings.class.getName(),
349 ImeiInformation.class.getName(),
350 SimStatus.class.getName(),
351 Status.class.getName(),
352 TestingSettings.class.getName(),
353 WifiAPITest.class.getName(),
354 WifiInfo.class.getName(),
Doris Ling7d73a292016-06-21 18:08:22 -0700355 MasterClear.class.getName(),
Justin Klaasseneae3d9f2016-07-21 19:25:17 -0700356 NightDisplaySettings.class.getName(),
Todd Kennedy2ef1aa52016-09-06 14:02:38 -0700357 ManageDomainUrls.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800358 };
359
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700360
361 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
362 "android.settings.APPLICATION_DETAILS_SETTINGS"
363 };
364
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800365 private SharedPreferences mDevelopmentPreferences;
366 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
367
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800368 private boolean mBatteryPresent = true;
369 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800370 @Override
371 public void onReceive(Context context, Intent intent) {
372 String action = intent.getAction();
373 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
374 boolean batteryPresent = Utils.isBatteryPresent(intent);
375
376 if (mBatteryPresent != batteryPresent) {
377 mBatteryPresent = batteryPresent;
Jason Monk4da79e02015-09-10 10:54:36 -0400378 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800379 }
380 }
381 }
382 };
383
Clara Bayarri6934a042015-10-14 11:07:35 +0100384 private final BroadcastReceiver mUserAddRemoveReceiver = new BroadcastReceiver() {
385 @Override
386 public void onReceive(Context context, Intent intent) {
387 String action = intent.getAction();
388 if (action.equals(Intent.ACTION_USER_ADDED)
389 || action.equals(Intent.ACTION_USER_REMOVED)) {
390 Index.getInstance(getApplicationContext()).update();
391 }
392 }
393 };
394
Svetoslav990159a2014-04-14 17:14:59 -0700395 private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor =
396 new DynamicIndexableContentMonitor();
Svetoslav853e4712014-04-14 10:10:25 -0700397
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700398 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700399 private SwitchBar mSwitchBar;
400
401 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700402
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700403 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700404 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700405
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700406 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700407 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700408
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700409 private ViewGroup mContent;
410
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700411 private SearchView mSearchView;
412 private MenuItem mSearchMenuItem;
413 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700414 private SearchResultsSummary mSearchResultsFragment;
415 private String mSearchQuery;
416
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700417 // Categories
418 private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800419
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700420 private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800421
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700422 private boolean mNeedToRevertToInitialFragment = false;
423
Jim Miller0698a212014-10-16 19:49:07 -0700424 private Intent mResultIntentData;
Jason Monkd4f03ec2016-01-07 16:25:34 -0500425 private ComponentName mCurrentSuggestion;
Jim Miller0698a212014-10-16 19:49:07 -0700426
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700427 public SwitchBar getSwitchBar() {
428 return mSwitchBar;
429 }
430
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800431 @Override
432 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
Sunny Goyal21ef89f2016-05-25 12:41:16 -0700433 startPreferencePanel(pref.getFragment(), pref.getExtras(), -1, pref.getTitle(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800434 null, 0);
435 return true;
436 }
437
438 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400439 public boolean onPreferenceTreeClick(Preference preference) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800440 return false;
441 }
442
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800443 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800444 public void onConfigurationChanged(Configuration newConfig) {
445 super.onConfigurationChanged(newConfig);
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800446 Index.getInstance(this).update();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800447 }
448
449 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700450 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700451 if (!mDisplaySearch) {
452 return false;
453 }
454
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700455 MenuInflater inflater = getMenuInflater();
456 inflater.inflate(R.menu.options_menu, menu);
457
458 // Cache the search query (can be overriden by the OnQueryTextListener)
459 final String query = mSearchQuery;
460
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700461 mSearchMenuItem = menu.findItem(R.id.search);
462 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700463
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700464 if (mSearchMenuItem == null || mSearchView == null) {
465 return false;
466 }
467
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700468 if (mSearchResultsFragment != null) {
469 mSearchResultsFragment.setSearchView(mSearchView);
470 }
471
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700472 mSearchMenuItem.setOnActionExpandListener(this);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700473 mSearchView.setOnQueryTextListener(this);
474 mSearchView.setOnCloseListener(this);
475
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700476 if (mSearchMenuItemExpanded) {
477 mSearchMenuItem.expandActionView();
478 }
479 mSearchView.setQuery(query, true /* submit */);
480
481 return true;
482 }
483
Jason Monk31c7c322016-01-20 14:41:52 -0500484 @Override
485 public SharedPreferences getSharedPreferences(String name, int mode) {
486 if (name.equals(getPackageName() + "_preferences")) {
Jason Monke4ebcd12016-02-21 09:37:41 -0500487 return new SharedPreferencesLogger(this, getMetricsTag());
Jason Monk31c7c322016-01-20 14:41:52 -0500488 }
489 return super.getSharedPreferences(name, mode);
490 }
491
Jason Monke4ebcd12016-02-21 09:37:41 -0500492 private String getMetricsTag() {
493 String tag = getClass().getName();
494 if (getIntent() != null && getIntent().hasExtra(EXTRA_SHOW_FRAGMENT)) {
495 tag = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
496 }
497 if (tag.startsWith("com.android.settings.")) {
498 tag = tag.replace("com.android.settings.", "");
499 }
500 return tag;
501 }
502
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700503 private static boolean isShortCutIntent(final Intent intent) {
504 Set<String> categories = intent.getCategories();
505 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
506 }
507
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700508 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700509 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700510 if (action == null) {
511 return false;
512 }
513 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
514 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
515 }
516 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700517 }
518
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700519 @Override
520 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700521 super.onCreate(savedState);
Jason Monkfd2c7222015-12-02 15:38:38 -0500522 long startTime = System.currentTimeMillis();
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700523
524 // Should happen before any call to getIntent()
525 getMetaData();
526
527 final Intent intent = getIntent();
528 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
529 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800530 }
Udam Saini92779ce2016-03-28 14:29:48 -0700531 if (intent.getBooleanExtra(EXTRA_HIDE_DRAWER, false)) {
532 setIsDrawerPresent(false);
533 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800534
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800535 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
536 Context.MODE_PRIVATE);
537
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700538 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700539 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700540
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700541 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700542 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
543
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700544 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700545 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700546
Jason Monk4da79e02015-09-10 10:54:36 -0400547 mIsShowingDashboard = className.equals(Settings.class.getName())
548 || className.equals(Settings.WirelessSettings.class.getName())
549 || className.equals(Settings.DeviceSettings.class.getName())
550 || className.equals(Settings.PersonalSettings.class.getName())
551 || className.equals(Settings.WirelessSettings.class.getName());
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700552
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700553 // This is a "Sub Settings" when:
554 // - this is a real SubSettings
555 // - or :settings:show_fragment_as_subsetting is passed to the Intent
Jorim Jaggi4dfcb822015-04-29 17:21:32 -0700556 final boolean isSubSettings = this instanceof SubSettings ||
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700557 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
558
559 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
560 if (isSubSettings) {
Fabrice Di Meglio712df6c2014-07-18 17:44:37 -0700561 // Check also that we are not a Theme Dialog as we don't want to override them
562 final int themeResId = getThemeResId();
563 if (themeResId != R.style.Theme_DialogWhenLarge &&
564 themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
565 setTheme(R.style.Theme_SubSettings);
566 }
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700567 }
568
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700569 setContentView(mIsShowingDashboard ?
570 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800571
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700572 mContent = (ViewGroup) findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700573
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800574 getFragmentManager().addOnBackStackChangedListener(this);
575
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700576 if (mIsShowingDashboard) {
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800577 // Run the Index update only if we have some space
578 if (!Utils.isLowStorage(this)) {
Jason Monkfd2c7222015-12-02 15:38:38 -0500579 long indexStartTime = System.currentTimeMillis();
Jason Monk6c9e8842016-04-14 14:34:16 -0400580 Index.getInstance(getApplicationContext()).update();
Jason Monkfd2c7222015-12-02 15:38:38 -0500581 if (DEBUG_TIMING) Log.d(LOG_TAG, "Index.update() took "
582 + (System.currentTimeMillis() - indexStartTime) + " ms");
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800583 } else {
584 Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
585 }
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700586 }
587
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700588 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700589 // We are restarting from a previous saved state; used that to initialize, instead
590 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700591 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
592 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700593 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800594
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700595 ArrayList<DashboardCategory> categories =
596 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
597 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700598 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700599 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700600 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800601 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700602
603 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700604 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Salvador Martinez12c52082016-07-25 18:16:47 -0700605
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800606 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700607 if (!mIsShowingDashboard) {
Jason Monkea8b1a72015-06-02 16:46:34 -0400608 mDisplaySearch = false;
609 // UP will be shown only if it is a sub settings
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700610 if (mIsShortcut) {
611 mDisplayHomeAsUpEnabled = isSubSettings;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700612 } else if (isSubSettings) {
613 mDisplayHomeAsUpEnabled = true;
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700614 } else {
615 mDisplayHomeAsUpEnabled = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700616 }
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700617 setTitleFromIntent(intent);
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700618
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700619 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700620 switchToFragment(initialFragmentName, initialArguments, true, false,
621 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000622 } else {
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700623 // No UP affordance if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700624 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700625 // Show Search affordance
626 mDisplaySearch = true;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700627 mInitialTitleResId = R.string.dashboard_title;
Salvador Martinez12c52082016-07-25 18:16:47 -0700628
629 // add argument to indicate which settings tab should be initially selected
630 final Bundle args = new Bundle();
631 final String extraName = DashboardContainerFragment.EXTRA_SELECT_SETTINGS_TAB;
632 args.putString(extraName, intent.getStringExtra(extraName));
633
634 switchToFragment(DashboardContainerFragment.class.getName(), args, false, false,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700635 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800636 }
637 }
638
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700639 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700640 if (mActionBar != null) {
641 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
642 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
643 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700644 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
Jason Monke4ebcd12016-02-21 09:37:41 -0500645 if (mSwitchBar != null) {
646 mSwitchBar.setMetricsTag(getMetricsTag());
647 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700648
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800649 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800650 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
651
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700652 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800653 if (buttonBar != null) {
654 buttonBar.setVisibility(View.VISIBLE);
655
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700656 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800657 backButton.setOnClickListener(new OnClickListener() {
658 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700659 setResult(RESULT_CANCELED, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800660 finish();
661 }
662 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700663 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800664 skipButton.setOnClickListener(new OnClickListener() {
665 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700666 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800667 finish();
668 }
669 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700670 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800671 mNextButton.setOnClickListener(new OnClickListener() {
672 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700673 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800674 finish();
675 }
676 });
677
678 // set our various button parameters
679 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
680 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
681 if (TextUtils.isEmpty(buttonText)) {
682 mNextButton.setVisibility(View.GONE);
683 }
684 else {
685 mNextButton.setText(buttonText);
686 }
687 }
688 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
689 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
690 if (TextUtils.isEmpty(buttonText)) {
691 backButton.setVisibility(View.GONE);
692 }
693 else {
694 backButton.setText(buttonText);
695 }
696 }
697 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
698 skipButton.setVisibility(View.VISIBLE);
699 }
700 }
701 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700702
Jason Monkfd2c7222015-12-02 15:38:38 -0500703 if (DEBUG_TIMING) Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
704 + " ms");
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700705 }
706
Fan Zhangece8ff62016-06-30 13:20:12 -0700707 public void setDisplaySearchMenu(boolean displaySearch) {
708 if (displaySearch != mDisplaySearch) {
709 mDisplaySearch = displaySearch;
710 invalidateOptionsMenu();
711 }
712 }
713
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700714 private void setTitleFromIntent(Intent intent) {
715 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
716 if (initialTitleResId > 0) {
717 mInitialTitle = null;
718 mInitialTitleResId = initialTitleResId;
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100719
720 final String initialTitleResPackageName = intent.getStringExtra(
721 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
722 if (initialTitleResPackageName != null) {
723 try {
724 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
725 0 /* flags */, new UserHandle(UserHandle.myUserId()));
726 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
727 setTitle(mInitialTitle);
728 mInitialTitleResId = -1;
729 return;
730 } catch (NameNotFoundException e) {
731 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
732 }
733 } else {
734 setTitle(mInitialTitleResId);
735 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700736 } else {
737 mInitialTitleResId = -1;
738 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
739 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
740 setTitle(mInitialTitle);
741 }
742 }
743
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800744 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800745 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700746 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800747 }
748
Fan Zhang28691572016-03-23 15:31:08 -0700749 private void setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800750 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700751
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800752 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700753 if (mInitialTitleResId > 0) {
754 setTitle(mInitialTitleResId);
755 } else {
756 setTitle(mInitialTitle);
757 }
Fan Zhang28691572016-03-23 15:31:08 -0700758 return;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800759 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700760
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800761 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
762 setTitleFromBackStackEntry(bse);
763 }
764
765 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
766 final CharSequence title;
767 final int titleRes = bse.getBreadCrumbTitleRes();
768 if (titleRes > 0) {
769 title = getText(titleRes);
770 } else {
771 title = bse.getBreadCrumbTitle();
772 }
773 if (title != null) {
774 setTitle(title);
775 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800776 }
777
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800778 @Override
779 protected void onSaveInstanceState(Bundle outState) {
780 super.onSaveInstanceState(outState);
781
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700782 if (mCategories.size() > 0) {
783 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800784 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700785
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700786 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700787 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700788
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700789 if (mDisplaySearch) {
790 // The option menus are created if the ActionBar is visible and they are also created
791 // asynchronously. If you launch Settings with an Intent action like
792 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
793 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
794 // menu item and search view are null.
795 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
796 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700797
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700798 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
799 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
800 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800801 }
802
803 @Override
Jason Monk350a9302016-06-01 13:45:25 -0400804 protected void onStart() {
805 super.onStart();
806
807 if (mNeedToRevertToInitialFragment) {
808 revertToInitialFragment();
809 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800810
811 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
812 @Override
813 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Jason Monk4da79e02015-09-10 10:54:36 -0400814 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800815 }
816 };
817 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
818 mDevelopmentPreferencesListener);
819
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800820 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Clara Bayarri6934a042015-10-14 11:07:35 +0100821 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_ADDED));
822 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_REMOVED));
Svetoslav853e4712014-04-14 10:10:25 -0700823
Philip P. Moltmannd9779db2016-02-24 12:11:05 -0800824 mDynamicIndexableContentMonitor.register(this, LOADER_ID_INDEXABLE_CONTENT_MONITOR);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700825
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700826 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700827 onQueryTextSubmit(mSearchQuery);
828 }
Jason Monk4da79e02015-09-10 10:54:36 -0400829 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800830 }
831
832 @Override
Jason Monk350a9302016-06-01 13:45:25 -0400833 protected void onStop() {
834 super.onStop();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800835 unregisterReceiver(mBatteryInfoReceiver);
Clara Bayarri8c9521f2016-01-12 14:10:45 +0000836 unregisterReceiver(mUserAddRemoveReceiver);
Svetoslav990159a2014-04-14 17:14:59 -0700837 mDynamicIndexableContentMonitor.unregister();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800838 }
839
840 @Override
841 public void onDestroy() {
842 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700843
844 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
845 mDevelopmentPreferencesListener);
846 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800847 }
848
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800849 protected boolean isValidFragment(String fragmentName) {
850 // Almost all fragments are wrapped in this,
851 // except for a few that have their own activities.
852 for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
853 if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
854 }
855 return false;
856 }
857
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800858 @Override
859 public Intent getIntent() {
860 Intent superIntent = super.getIntent();
861 String startingFragment = getStartingFragmentClass(superIntent);
862 // This is called from super.onCreate, isMultiPane() is not yet reliable
863 // Do not use onIsHidingHeaders either, which relies itself on this method
864 if (startingFragment != null) {
865 Intent modIntent = new Intent(superIntent);
866 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
867 Bundle args = superIntent.getExtras();
868 if (args != null) {
869 args = new Bundle(args);
870 } else {
871 args = new Bundle();
872 }
873 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100874 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800875 return modIntent;
876 }
877 return superIntent;
878 }
879
880 /**
881 * Checks if the component name in the intent is different from the Settings class and
882 * returns the class name to load as a fragment.
883 */
884 private String getStartingFragmentClass(Intent intent) {
885 if (mFragmentClass != null) return mFragmentClass;
886
887 String intentClass = intent.getComponent().getClassName();
888 if (intentClass.equals(getClass().getName())) return null;
889
890 if ("com.android.settings.ManageApplications".equals(intentClass)
891 || "com.android.settings.RunningServices".equals(intentClass)
892 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
893 // Old names of manage apps.
894 intentClass = com.android.settings.applications.ManageApplications.class.getName();
895 }
896
897 return intentClass;
898 }
899
900 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000901 * Start a new fragment containing a preference panel. If the preferences
902 * are being displayed in multi-pane mode, the given fragment class will
903 * be instantiated and placed in the appropriate pane. If running in
904 * single-pane mode, a new activity will be launched in which to show the
905 * fragment.
906 *
907 * @param fragmentClass Full name of the class implementing the fragment.
908 * @param args Any desired arguments to supply to the fragment.
909 * @param titleRes Optional resource identifier of the title of this
910 * fragment.
911 * @param titleText Optional text of the title of this fragment.
912 * @param resultTo Optional fragment that result data should be sent to.
913 * If non-null, resultTo.onActivityResult() will be called when this
914 * preference panel is done. The launched panel must use
915 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
916 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700917 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000918 */
919 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700920 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700921 String title = null;
922 if (titleRes < 0) {
923 if (titleText != null) {
924 title = titleText.toString();
925 } else {
926 // There not much we can do in that case
927 title = "";
928 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700929 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700930 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700931 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000932 }
933
934 /**
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100935 * Start a new fragment in a new activity containing a preference panel for a given user. If the
936 * preferences are being displayed in multi-pane mode, the given fragment class will be
937 * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
938 * activity will be launched in which to show the fragment.
939 *
940 * @param fragmentClass Full name of the class implementing the fragment.
941 * @param args Any desired arguments to supply to the fragment.
942 * @param titleRes Optional resource identifier of the title of this fragment.
943 * @param titleText Optional text of the title of this fragment.
944 * @param userHandle The user for which the panel has to be started.
945 */
946 public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
947 CharSequence titleText, UserHandle userHandle) {
Lifu Tangd0332852015-04-02 12:05:46 -0700948 // This is a workaround.
949 //
950 // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
951 // starting the fragment could cause a native stack corruption. See b/17523189. However,
952 // adding that flag and start the preference panel with the same UserHandler will make it
953 // impossible to use back button to return to the previous screen. See b/20042570.
954 //
955 // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
956 // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
957 // when we're calling it as the same user.
958 if (userHandle.getIdentifier() == UserHandle.myUserId()) {
959 startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0);
960 } else {
961 String title = null;
962 if (titleRes < 0) {
963 if (titleText != null) {
964 title = titleText.toString();
965 } else {
966 // There not much we can do in that case
967 title = "";
968 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100969 }
Lifu Tangd0332852015-04-02 12:05:46 -0700970 Utils.startWithFragmentAsUser(this, fragmentClass, args,
971 titleRes, title, mIsShortcut, userHandle);
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100972 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100973 }
974
975 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800976 * Called by a preference panel fragment to finish itself.
977 *
978 * @param caller The fragment that is asking to be finished.
979 * @param resultCode Optional result code to send back to the original
980 * launching fragment.
981 * @param resultData Optional result data to send back to the original
982 * launching fragment.
983 */
984 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
985 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700986 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800987 }
988
989 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000990 * Start a new fragment.
991 *
992 * @param fragment The fragment to start
993 * @param push If true, the current fragment will be pushed onto the back stack. If false,
994 * the current fragment will be replaced.
995 */
996 public void startPreferenceFragment(Fragment fragment, boolean push) {
997 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700998 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000999 if (push) {
1000 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
1001 transaction.addToBackStack(BACK_STACK_PREFS);
1002 } else {
1003 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
1004 }
1005 transaction.commitAllowingStateLoss();
1006 }
1007
1008 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001009 * Switch to a specific Fragment with taking care of validation, Title and BackStack
1010 */
1011 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001012 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001013 if (validate && !isValidFragment(fragmentName)) {
1014 throw new IllegalArgumentException("Invalid fragment for this activity: "
1015 + fragmentName);
1016 }
1017 Fragment f = Fragment.instantiate(this, fragmentName, args);
1018 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Anna Galusza6b1e9db2016-03-30 17:25:36 -07001019 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001020 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -07001021 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001022 }
1023 if (addToBackStack) {
1024 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
1025 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001026 if (titleResId > 0) {
1027 transaction.setBreadCrumbTitle(titleResId);
1028 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001029 transaction.setBreadCrumbTitle(title);
1030 }
1031 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -07001032 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001033 return f;
1034 }
1035
Jason Monk4da79e02015-09-10 10:54:36 -04001036 private void updateTilesList() {
Jason Monkfd2c7222015-12-02 15:38:38 -05001037 // Generally the items that are will be changing from these updates will
1038 // not be in the top list of tiles, so run it in the background and the
1039 // SettingsDrawerActivity will pick up on the updates automatically.
1040 AsyncTask.execute(new Runnable() {
1041 @Override
1042 public void run() {
1043 doUpdateTilesList();
1044 }
1045 });
1046 }
1047
1048 private void doUpdateTilesList() {
Jason Monk4da79e02015-09-10 10:54:36 -04001049 PackageManager pm = getPackageManager();
Xiaohui Chen44879a32015-07-22 13:53:22 -07001050 final UserManager um = UserManager.get(this);
1051 final boolean isAdmin = um.isAdminUser();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001052
Jason Monk4da79e02015-09-10 10:54:36 -04001053 String packageName = getPackageName();
1054 setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()),
1055 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001056
Jason Monk4da79e02015-09-10 10:54:36 -04001057 setTileEnabled(new ComponentName(packageName,
1058 Settings.BluetoothSettingsActivity.class.getName()),
1059 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001060
Jason Monk4da79e02015-09-10 10:54:36 -04001061 setTileEnabled(new ComponentName(packageName,
1062 Settings.DataUsageSummaryActivity.class.getName()),
1063 Utils.isBandwidthControlEnabled(), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001064
Jason Monk4da79e02015-09-10 10:54:36 -04001065 setTileEnabled(new ComponentName(packageName,
1066 Settings.SimSettingsActivity.class.getName()),
1067 Utils.showSimCardTile(this), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001068
Jason Monk4da79e02015-09-10 10:54:36 -04001069 setTileEnabled(new ComponentName(packageName,
1070 Settings.PowerUsageSummaryActivity.class.getName()),
1071 mBatteryPresent, isAdmin, pm);
1072
1073 setTileEnabled(new ComponentName(packageName,
Jason Monk4da79e02015-09-10 10:54:36 -04001074 Settings.UserSettingsActivity.class.getName()),
1075 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
1076 && !Utils.isMonkeyRunning(), isAdmin, pm);
1077
Fyodor Kupolovca060e32016-06-24 13:01:11 -07001078 setTileEnabled(new ComponentName(packageName,
1079 Settings.WirelessSettingsActivity.class.getName()),
1080 !UserManager.isDeviceInDemoMode(this), isAdmin, pm);
1081
1082 setTileEnabled(new ComponentName(packageName,
1083 Settings.DateTimeSettingsActivity.class.getName()),
1084 !UserManager.isDeviceInDemoMode(this), isAdmin, pm);
Jason Monk4da79e02015-09-10 10:54:36 -04001085 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
1086 setTileEnabled(new ComponentName(packageName,
1087 Settings.PaymentSettingsActivity.class.getName()),
1088 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
1089 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
1090 && adapter != null && adapter.isEnabled(), isAdmin, pm);
1091
1092 setTileEnabled(new ComponentName(packageName,
1093 Settings.PrintSettingsActivity.class.getName()),
1094 pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin, pm);
1095
1096 final boolean showDev = mDevelopmentPreferences.getBoolean(
Dan Sandler12c4ba42016-03-28 11:13:40 -04001097 DevelopmentSettings.PREF_SHOW, android.os.Build.TYPE.equals("eng"))
1098 && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES);
Jason Monk4da79e02015-09-10 10:54:36 -04001099 setTileEnabled(new ComponentName(packageName,
1100 Settings.DevelopmentSettingsActivity.class.getName()),
Dan Sandler12c4ba42016-03-28 11:13:40 -04001101 showDev, isAdmin, pm);
1102
1103 // Reveal development-only quick settings tiles
1104 DevelopmentTiles.setTilesEnabled(this, showDev);
Jason Monk4da79e02015-09-10 10:54:36 -04001105
1106 if (UserHandle.MU_ENABLED && !isAdmin) {
1107 // When on restricted users, disable all extra categories (but only the settings ones).
Jason Monkfd2c7222015-12-02 15:38:38 -05001108 List<DashboardCategory> categories = getDashboardCategories();
Jason Monk4da79e02015-09-10 10:54:36 -04001109 for (DashboardCategory category : categories) {
Jason Monkd4f03ec2016-01-07 16:25:34 -05001110 for (Tile tile : category.tiles) {
Jason Monk4da79e02015-09-10 10:54:36 -04001111 ComponentName component = tile.intent.getComponent();
Jason Monk5862c1e2016-06-07 14:02:33 -04001112 if (packageName.equals(component.getPackageName()) && !ArrayUtils.contains(
Jason Monk4da79e02015-09-10 10:54:36 -04001113 SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1114 setTileEnabled(component, false, isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001115 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001116 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001117 }
1118 }
Doris Ling26bf0032016-06-15 18:16:09 -07001119
1120 String backupIntent = getResources().getString(R.string.config_backup_settings_intent);
1121 boolean useDefaultBackup = TextUtils.isEmpty(backupIntent);
1122 setTileEnabled(new ComponentName(packageName,
1123 Settings.PrivacySettingsActivity.class.getName()), useDefaultBackup, isAdmin, pm);
1124 boolean hasBackupActivity = false;
1125 if (!useDefaultBackup) {
1126 try {
1127 Intent intent = Intent.parseUri(backupIntent, 0);
1128 hasBackupActivity = !getPackageManager().queryIntentActivities(intent, 0).isEmpty();
1129 } catch (URISyntaxException e) {
1130 Log.e(LOG_TAG, "Invalid backup intent URI!", e);
1131 }
1132 }
1133 setTileEnabled(new ComponentName(packageName,
1134 BackupSettingsActivity.class.getName()), hasBackupActivity, isAdmin, pm);
1135
Jason Monk2ebc8a02015-02-13 15:23:19 -05001136 }
1137
Jason Monk4da79e02015-09-10 10:54:36 -04001138 private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin,
1139 PackageManager pm) {
Jason Monk5862c1e2016-06-07 14:02:33 -04001140 if (UserHandle.MU_ENABLED && !isAdmin && getPackageName().equals(component.getPackageName())
Jason Monk4da79e02015-09-10 10:54:36 -04001141 && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1142 enabled = false;
1143 }
Jason Monk5862c1e2016-06-07 14:02:33 -04001144 setTileEnabled(component, enabled);
Jason Monk2ebc8a02015-02-13 15:23:19 -05001145 }
1146
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001147 private void getMetaData() {
1148 try {
1149 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1150 PackageManager.GET_META_DATA);
1151 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001152 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1153 } catch (NameNotFoundException nnfe) {
1154 // No recovery
1155 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1156 }
1157 }
1158
1159 // give subclasses access to the Next button
1160 public boolean hasNextButton() {
1161 return mNextButton != null;
1162 }
1163
1164 public Button getNextButton() {
1165 return mNextButton;
1166 }
1167
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001168 @Override
1169 public boolean shouldUpRecreateTask(Intent targetIntent) {
1170 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1171 }
1172
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001173 @Override
1174 public boolean onQueryTextSubmit(String query) {
1175 switchToSearchResultsFragmentIfNeeded();
1176 mSearchQuery = query;
1177 return mSearchResultsFragment.onQueryTextSubmit(query);
1178 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001179
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001180 @Override
1181 public boolean onQueryTextChange(String newText) {
1182 mSearchQuery = newText;
Fabrice Di Meglio7e4855e2014-05-23 16:03:43 -07001183 if (mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001184 return false;
1185 }
1186 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001187 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001188
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001189 @Override
1190 public boolean onClose() {
1191 return false;
1192 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001193
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001194 @Override
1195 public boolean onMenuItemActionExpand(MenuItem item) {
1196 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001197 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001198 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001199 return true;
1200 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001201
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001202 @Override
1203 public boolean onMenuItemActionCollapse(MenuItem item) {
1204 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001205 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001206 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001207 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001208 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001209 return true;
1210 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001211
Jason Monk4da79e02015-09-10 10:54:36 -04001212 @Override
Jason Monkd4f03ec2016-01-07 16:25:34 -05001213 protected void onTileClicked(Tile tile) {
Jason Monk4da79e02015-09-10 10:54:36 -04001214 if (mIsShowingDashboard) {
1215 // If on dashboard, don't finish so the back comes back to here.
1216 openTile(tile);
1217 } else {
1218 super.onTileClicked(tile);
1219 }
1220 }
1221
Jason Monkaf001092015-11-04 13:16:18 -05001222 @Override
1223 public void onProfileTileOpen() {
1224 if (!mIsShowingDashboard) {
1225 finish();
1226 }
1227 }
1228
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001229 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001230 if (mSearchResultsFragment != null) {
1231 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001232 }
Anna Galusza6b1e9db2016-03-30 17:25:36 -07001233 Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001234 if (current != null && current instanceof SearchResultsSummary) {
1235 mSearchResultsFragment = (SearchResultsSummary) current;
1236 } else {
Fan Zhang28691572016-03-23 15:31:08 -07001237 setContentHeaderView(null);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001238 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001239 SearchResultsSummary.class.getName(), null, false, true,
1240 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001241 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001242 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001243 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001244 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001245
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001246 public void needToRevertToInitialFragment() {
1247 mNeedToRevertToInitialFragment = true;
1248 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001249
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001250 private void revertToInitialFragment() {
1251 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001252 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001253 mSearchMenuItemExpanded = false;
1254 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1255 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001256 if (mSearchMenuItem != null) {
1257 mSearchMenuItem.collapseActionView();
1258 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001259 }
Jim Miller0698a212014-10-16 19:49:07 -07001260
1261 public Intent getResultIntentData() {
1262 return mResultIntentData;
1263 }
1264
1265 public void setResultIntentData(Intent resultIntentData) {
1266 mResultIntentData = resultIntentData;
1267 }
Jason Monkd4f03ec2016-01-07 16:25:34 -05001268
1269 public void startSuggestion(Intent intent) {
1270 mCurrentSuggestion = intent.getComponent();
1271 startActivityForResult(intent, REQUEST_SUGGESTION);
1272 }
1273
1274 @Override
1275 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
1276 if (requestCode == REQUEST_SUGGESTION && mCurrentSuggestion != null
1277 && resultCode != RESULT_CANCELED) {
1278 getPackageManager().setComponentEnabledSetting(mCurrentSuggestion,
1279 PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
1280 }
1281 super.onActivityResult(requestCode, resultCode, data);
1282 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001283}