blob: 36350f54f2d2ab992d39ef7b3eac81c13b58b6d3 [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;
Jason Monka2d47fc2016-03-03 10:49:44 -050067import com.android.settings.applications.NotificationApps;
Jason Monk2cdafc62015-06-12 12:32:50 -040068import com.android.settings.applications.ProcessStatsSummary;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080069import com.android.settings.applications.ProcessStatsUi;
Jason Monkd8da51c2015-04-17 14:34:12 -040070import com.android.settings.applications.UsageAccessDetails;
Ruben Brunkc461d5c2016-04-07 21:45:41 -070071import com.android.settings.applications.VrListenerSettings;
Fan Zhangece8ff62016-06-30 13:20:12 -070072import com.android.settings.applications.WriteSettingsDetails;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080073import com.android.settings.bluetooth.BluetoothSettings;
Fan Zhang5f79ae92016-08-18 16:04:19 -070074import com.android.settings.core.instrumentation.SharedPreferencesLogger;
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(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800357 };
358
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700359
360 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
361 "android.settings.APPLICATION_DETAILS_SETTINGS"
362 };
363
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800364 private SharedPreferences mDevelopmentPreferences;
365 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
366
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800367 private boolean mBatteryPresent = true;
368 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800369 @Override
370 public void onReceive(Context context, Intent intent) {
371 String action = intent.getAction();
372 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
373 boolean batteryPresent = Utils.isBatteryPresent(intent);
374
375 if (mBatteryPresent != batteryPresent) {
376 mBatteryPresent = batteryPresent;
Jason Monk4da79e02015-09-10 10:54:36 -0400377 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800378 }
379 }
380 }
381 };
382
Clara Bayarri6934a042015-10-14 11:07:35 +0100383 private final BroadcastReceiver mUserAddRemoveReceiver = new BroadcastReceiver() {
384 @Override
385 public void onReceive(Context context, Intent intent) {
386 String action = intent.getAction();
387 if (action.equals(Intent.ACTION_USER_ADDED)
388 || action.equals(Intent.ACTION_USER_REMOVED)) {
389 Index.getInstance(getApplicationContext()).update();
390 }
391 }
392 };
393
Svetoslav990159a2014-04-14 17:14:59 -0700394 private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor =
395 new DynamicIndexableContentMonitor();
Svetoslav853e4712014-04-14 10:10:25 -0700396
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700397 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700398 private SwitchBar mSwitchBar;
399
400 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700401
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700402 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700403 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700404
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700405 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700406 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700407
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700408 private ViewGroup mContent;
409
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700410 private SearchView mSearchView;
411 private MenuItem mSearchMenuItem;
412 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700413 private SearchResultsSummary mSearchResultsFragment;
414 private String mSearchQuery;
415
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700416 // Categories
417 private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800418
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700419 private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800420
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700421 private boolean mNeedToRevertToInitialFragment = false;
422
Jim Miller0698a212014-10-16 19:49:07 -0700423 private Intent mResultIntentData;
Jason Monkd4f03ec2016-01-07 16:25:34 -0500424 private ComponentName mCurrentSuggestion;
Jim Miller0698a212014-10-16 19:49:07 -0700425
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700426 public SwitchBar getSwitchBar() {
427 return mSwitchBar;
428 }
429
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800430 @Override
431 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
Sunny Goyal21ef89f2016-05-25 12:41:16 -0700432 startPreferencePanel(pref.getFragment(), pref.getExtras(), -1, pref.getTitle(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800433 null, 0);
434 return true;
435 }
436
437 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400438 public boolean onPreferenceTreeClick(Preference preference) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800439 return false;
440 }
441
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800442 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800443 public void onConfigurationChanged(Configuration newConfig) {
444 super.onConfigurationChanged(newConfig);
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800445 Index.getInstance(this).update();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800446 }
447
448 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700449 protected void onStart() {
450 super.onStart();
451
452 if (mNeedToRevertToInitialFragment) {
453 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800454 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800455 }
456
457 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700458 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700459 if (!mDisplaySearch) {
460 return false;
461 }
462
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700463 MenuInflater inflater = getMenuInflater();
464 inflater.inflate(R.menu.options_menu, menu);
465
466 // Cache the search query (can be overriden by the OnQueryTextListener)
467 final String query = mSearchQuery;
468
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700469 mSearchMenuItem = menu.findItem(R.id.search);
470 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700471
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700472 if (mSearchMenuItem == null || mSearchView == null) {
473 return false;
474 }
475
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700476 if (mSearchResultsFragment != null) {
477 mSearchResultsFragment.setSearchView(mSearchView);
478 }
479
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700480 mSearchMenuItem.setOnActionExpandListener(this);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700481 mSearchView.setOnQueryTextListener(this);
482 mSearchView.setOnCloseListener(this);
483
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700484 if (mSearchMenuItemExpanded) {
485 mSearchMenuItem.expandActionView();
486 }
487 mSearchView.setQuery(query, true /* submit */);
488
489 return true;
490 }
491
Jason Monk31c7c322016-01-20 14:41:52 -0500492 @Override
493 public SharedPreferences getSharedPreferences(String name, int mode) {
494 if (name.equals(getPackageName() + "_preferences")) {
Jason Monke4ebcd12016-02-21 09:37:41 -0500495 return new SharedPreferencesLogger(this, getMetricsTag());
Jason Monk31c7c322016-01-20 14:41:52 -0500496 }
497 return super.getSharedPreferences(name, mode);
498 }
499
Jason Monke4ebcd12016-02-21 09:37:41 -0500500 private String getMetricsTag() {
501 String tag = getClass().getName();
502 if (getIntent() != null && getIntent().hasExtra(EXTRA_SHOW_FRAGMENT)) {
503 tag = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
504 }
505 if (tag.startsWith("com.android.settings.")) {
506 tag = tag.replace("com.android.settings.", "");
507 }
508 return tag;
509 }
510
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700511 private static boolean isShortCutIntent(final Intent intent) {
512 Set<String> categories = intent.getCategories();
513 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
514 }
515
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700516 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700517 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700518 if (action == null) {
519 return false;
520 }
521 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
522 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
523 }
524 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700525 }
526
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700527 @Override
528 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700529 super.onCreate(savedState);
Jason Monkfd2c7222015-12-02 15:38:38 -0500530 long startTime = System.currentTimeMillis();
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700531
532 // Should happen before any call to getIntent()
533 getMetaData();
534
535 final Intent intent = getIntent();
536 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
537 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800538 }
Udam Saini92779ce2016-03-28 14:29:48 -0700539 if (intent.getBooleanExtra(EXTRA_HIDE_DRAWER, false)) {
540 setIsDrawerPresent(false);
541 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800542
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800543 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
544 Context.MODE_PRIVATE);
545
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700546 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700547 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700548
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700549 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700550 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
551
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700552 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700553 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700554
Jason Monk4da79e02015-09-10 10:54:36 -0400555 mIsShowingDashboard = className.equals(Settings.class.getName())
556 || className.equals(Settings.WirelessSettings.class.getName())
557 || className.equals(Settings.DeviceSettings.class.getName())
558 || className.equals(Settings.PersonalSettings.class.getName())
559 || className.equals(Settings.WirelessSettings.class.getName());
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700560
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700561 // This is a "Sub Settings" when:
562 // - this is a real SubSettings
563 // - or :settings:show_fragment_as_subsetting is passed to the Intent
Jorim Jaggi4dfcb822015-04-29 17:21:32 -0700564 final boolean isSubSettings = this instanceof SubSettings ||
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700565 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
566
567 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
568 if (isSubSettings) {
Fabrice Di Meglio712df6c2014-07-18 17:44:37 -0700569 // Check also that we are not a Theme Dialog as we don't want to override them
570 final int themeResId = getThemeResId();
571 if (themeResId != R.style.Theme_DialogWhenLarge &&
572 themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
573 setTheme(R.style.Theme_SubSettings);
574 }
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700575 }
576
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700577 setContentView(mIsShowingDashboard ?
578 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800579
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700580 mContent = (ViewGroup) findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700581
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800582 getFragmentManager().addOnBackStackChangedListener(this);
583
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700584 if (mIsShowingDashboard) {
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800585 // Run the Index update only if we have some space
586 if (!Utils.isLowStorage(this)) {
Jason Monkfd2c7222015-12-02 15:38:38 -0500587 long indexStartTime = System.currentTimeMillis();
Jason Monk6c9e8842016-04-14 14:34:16 -0400588 Index.getInstance(getApplicationContext()).update();
Jason Monkfd2c7222015-12-02 15:38:38 -0500589 if (DEBUG_TIMING) Log.d(LOG_TAG, "Index.update() took "
590 + (System.currentTimeMillis() - indexStartTime) + " ms");
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800591 } else {
592 Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
593 }
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700594 }
595
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700596 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700597 // We are restarting from a previous saved state; used that to initialize, instead
598 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700599 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
600 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700601 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800602
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700603 ArrayList<DashboardCategory> categories =
604 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
605 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700606 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700607 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700608 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800609 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700610
611 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700612 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Salvador Martinez2368e542016-07-25 18:16:47 -0700613
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800614 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700615 if (!mIsShowingDashboard) {
Jason Monkea8b1a72015-06-02 16:46:34 -0400616 mDisplaySearch = false;
617 // UP will be shown only if it is a sub settings
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700618 if (mIsShortcut) {
619 mDisplayHomeAsUpEnabled = isSubSettings;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700620 } else if (isSubSettings) {
621 mDisplayHomeAsUpEnabled = true;
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700622 } else {
623 mDisplayHomeAsUpEnabled = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700624 }
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700625 setTitleFromIntent(intent);
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700626
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700627 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700628 switchToFragment(initialFragmentName, initialArguments, true, false,
629 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000630 } else {
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700631 // No UP affordance if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700632 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700633 // Show Search affordance
634 mDisplaySearch = true;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700635 mInitialTitleResId = R.string.dashboard_title;
Salvador Martinez2368e542016-07-25 18:16:47 -0700636
637 // add argument to indicate which settings tab should be initially selected
638 final Bundle args = new Bundle();
639 final String extraName = DashboardContainerFragment.EXTRA_SELECT_SETTINGS_TAB;
640 args.putString(extraName, intent.getStringExtra(extraName));
641
642 switchToFragment(DashboardContainerFragment.class.getName(), args, false, false,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700643 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800644 }
645 }
646
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700647 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700648 if (mActionBar != null) {
649 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
650 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
651 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700652 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
Jason Monke4ebcd12016-02-21 09:37:41 -0500653 if (mSwitchBar != null) {
654 mSwitchBar.setMetricsTag(getMetricsTag());
655 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700656
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800657 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800658 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
659
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700660 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800661 if (buttonBar != null) {
662 buttonBar.setVisibility(View.VISIBLE);
663
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700664 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800665 backButton.setOnClickListener(new OnClickListener() {
666 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700667 setResult(RESULT_CANCELED, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800668 finish();
669 }
670 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700671 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800672 skipButton.setOnClickListener(new OnClickListener() {
673 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700674 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800675 finish();
676 }
677 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700678 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800679 mNextButton.setOnClickListener(new OnClickListener() {
680 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700681 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800682 finish();
683 }
684 });
685
686 // set our various button parameters
687 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
688 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
689 if (TextUtils.isEmpty(buttonText)) {
690 mNextButton.setVisibility(View.GONE);
691 }
692 else {
693 mNextButton.setText(buttonText);
694 }
695 }
696 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
697 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
698 if (TextUtils.isEmpty(buttonText)) {
699 backButton.setVisibility(View.GONE);
700 }
701 else {
702 backButton.setText(buttonText);
703 }
704 }
705 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
706 skipButton.setVisibility(View.VISIBLE);
707 }
708 }
709 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700710
Jason Monkfd2c7222015-12-02 15:38:38 -0500711 if (DEBUG_TIMING) Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
712 + " ms");
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700713 }
714
Fan Zhangece8ff62016-06-30 13:20:12 -0700715 public void setDisplaySearchMenu(boolean displaySearch) {
716 if (displaySearch != mDisplaySearch) {
717 mDisplaySearch = displaySearch;
718 invalidateOptionsMenu();
719 }
720 }
721
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700722 private void setTitleFromIntent(Intent intent) {
723 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
724 if (initialTitleResId > 0) {
725 mInitialTitle = null;
726 mInitialTitleResId = initialTitleResId;
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100727
728 final String initialTitleResPackageName = intent.getStringExtra(
729 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
730 if (initialTitleResPackageName != null) {
731 try {
732 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
733 0 /* flags */, new UserHandle(UserHandle.myUserId()));
734 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
735 setTitle(mInitialTitle);
736 mInitialTitleResId = -1;
737 return;
738 } catch (NameNotFoundException e) {
739 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
740 }
741 } else {
742 setTitle(mInitialTitleResId);
743 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700744 } else {
745 mInitialTitleResId = -1;
746 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
747 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
748 setTitle(mInitialTitle);
749 }
750 }
751
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800752 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800753 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700754 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800755 }
756
Fan Zhang28691572016-03-23 15:31:08 -0700757 private void setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800758 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700759
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800760 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700761 if (mInitialTitleResId > 0) {
762 setTitle(mInitialTitleResId);
763 } else {
764 setTitle(mInitialTitle);
765 }
Fan Zhang28691572016-03-23 15:31:08 -0700766 return;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800767 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700768
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800769 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
770 setTitleFromBackStackEntry(bse);
771 }
772
773 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
774 final CharSequence title;
775 final int titleRes = bse.getBreadCrumbTitleRes();
776 if (titleRes > 0) {
777 title = getText(titleRes);
778 } else {
779 title = bse.getBreadCrumbTitle();
780 }
781 if (title != null) {
782 setTitle(title);
783 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800784 }
785
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800786 @Override
787 protected void onSaveInstanceState(Bundle outState) {
788 super.onSaveInstanceState(outState);
789
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700790 if (mCategories.size() > 0) {
791 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800792 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700793
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700794 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700795 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700796
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700797 if (mDisplaySearch) {
798 // The option menus are created if the ActionBar is visible and they are also created
799 // asynchronously. If you launch Settings with an Intent action like
800 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
801 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
802 // menu item and search view are null.
803 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
804 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700805
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700806 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
807 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
808 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800809 }
810
811 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400812 protected void onResume() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800813 super.onResume();
814
815 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
816 @Override
817 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Jason Monk4da79e02015-09-10 10:54:36 -0400818 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800819 }
820 };
821 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
822 mDevelopmentPreferencesListener);
823
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800824 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Clara Bayarri6934a042015-10-14 11:07:35 +0100825 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_ADDED));
826 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_REMOVED));
Svetoslav853e4712014-04-14 10:10:25 -0700827
Philip P. Moltmannd9779db2016-02-24 12:11:05 -0800828 mDynamicIndexableContentMonitor.register(this, LOADER_ID_INDEXABLE_CONTENT_MONITOR);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700829
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700830 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700831 onQueryTextSubmit(mSearchQuery);
832 }
Jason Monk4da79e02015-09-10 10:54:36 -0400833 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800834 }
835
836 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400837 protected void onPause() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800838 super.onPause();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800839 unregisterReceiver(mBatteryInfoReceiver);
Clara Bayarri8c9521f2016-01-12 14:10:45 +0000840 unregisterReceiver(mUserAddRemoveReceiver);
Svetoslav990159a2014-04-14 17:14:59 -0700841 mDynamicIndexableContentMonitor.unregister();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800842 }
843
844 @Override
845 public void onDestroy() {
846 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700847
848 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
849 mDevelopmentPreferencesListener);
850 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800851 }
852
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800853 protected boolean isValidFragment(String fragmentName) {
854 // Almost all fragments are wrapped in this,
855 // except for a few that have their own activities.
856 for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
857 if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
858 }
859 return false;
860 }
861
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800862 @Override
863 public Intent getIntent() {
864 Intent superIntent = super.getIntent();
865 String startingFragment = getStartingFragmentClass(superIntent);
866 // This is called from super.onCreate, isMultiPane() is not yet reliable
867 // Do not use onIsHidingHeaders either, which relies itself on this method
868 if (startingFragment != null) {
869 Intent modIntent = new Intent(superIntent);
870 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
871 Bundle args = superIntent.getExtras();
872 if (args != null) {
873 args = new Bundle(args);
874 } else {
875 args = new Bundle();
876 }
877 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100878 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800879 return modIntent;
880 }
881 return superIntent;
882 }
883
884 /**
885 * Checks if the component name in the intent is different from the Settings class and
886 * returns the class name to load as a fragment.
887 */
888 private String getStartingFragmentClass(Intent intent) {
889 if (mFragmentClass != null) return mFragmentClass;
890
891 String intentClass = intent.getComponent().getClassName();
892 if (intentClass.equals(getClass().getName())) return null;
893
894 if ("com.android.settings.ManageApplications".equals(intentClass)
895 || "com.android.settings.RunningServices".equals(intentClass)
896 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
897 // Old names of manage apps.
898 intentClass = com.android.settings.applications.ManageApplications.class.getName();
899 }
900
901 return intentClass;
902 }
903
904 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000905 * Start a new fragment containing a preference panel. If the preferences
906 * are being displayed in multi-pane mode, the given fragment class will
907 * be instantiated and placed in the appropriate pane. If running in
908 * single-pane mode, a new activity will be launched in which to show the
909 * fragment.
910 *
911 * @param fragmentClass Full name of the class implementing the fragment.
912 * @param args Any desired arguments to supply to the fragment.
913 * @param titleRes Optional resource identifier of the title of this
914 * fragment.
915 * @param titleText Optional text of the title of this fragment.
916 * @param resultTo Optional fragment that result data should be sent to.
917 * If non-null, resultTo.onActivityResult() will be called when this
918 * preference panel is done. The launched panel must use
919 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
920 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700921 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000922 */
923 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700924 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700925 String title = null;
926 if (titleRes < 0) {
927 if (titleText != null) {
928 title = titleText.toString();
929 } else {
930 // There not much we can do in that case
931 title = "";
932 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700933 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700934 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700935 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000936 }
937
938 /**
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100939 * Start a new fragment in a new activity containing a preference panel for a given user. If the
940 * preferences are being displayed in multi-pane mode, the given fragment class will be
941 * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
942 * activity will be launched in which to show the fragment.
943 *
944 * @param fragmentClass Full name of the class implementing the fragment.
945 * @param args Any desired arguments to supply to the fragment.
946 * @param titleRes Optional resource identifier of the title of this fragment.
947 * @param titleText Optional text of the title of this fragment.
948 * @param userHandle The user for which the panel has to be started.
949 */
950 public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
951 CharSequence titleText, UserHandle userHandle) {
Lifu Tangd0332852015-04-02 12:05:46 -0700952 // This is a workaround.
953 //
954 // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
955 // starting the fragment could cause a native stack corruption. See b/17523189. However,
956 // adding that flag and start the preference panel with the same UserHandler will make it
957 // impossible to use back button to return to the previous screen. See b/20042570.
958 //
959 // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
960 // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
961 // when we're calling it as the same user.
962 if (userHandle.getIdentifier() == UserHandle.myUserId()) {
963 startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0);
964 } else {
965 String title = null;
966 if (titleRes < 0) {
967 if (titleText != null) {
968 title = titleText.toString();
969 } else {
970 // There not much we can do in that case
971 title = "";
972 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100973 }
Lifu Tangd0332852015-04-02 12:05:46 -0700974 Utils.startWithFragmentAsUser(this, fragmentClass, args,
975 titleRes, title, mIsShortcut, userHandle);
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100976 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100977 }
978
979 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800980 * Called by a preference panel fragment to finish itself.
981 *
982 * @param caller The fragment that is asking to be finished.
983 * @param resultCode Optional result code to send back to the original
984 * launching fragment.
985 * @param resultData Optional result data to send back to the original
986 * launching fragment.
987 */
988 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
989 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700990 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800991 }
992
993 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000994 * Start a new fragment.
995 *
996 * @param fragment The fragment to start
997 * @param push If true, the current fragment will be pushed onto the back stack. If false,
998 * the current fragment will be replaced.
999 */
1000 public void startPreferenceFragment(Fragment fragment, boolean push) {
1001 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Anna Galusza6b1e9db2016-03-30 17:25:36 -07001002 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +00001003 if (push) {
1004 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
1005 transaction.addToBackStack(BACK_STACK_PREFS);
1006 } else {
1007 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
1008 }
1009 transaction.commitAllowingStateLoss();
1010 }
1011
1012 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001013 * Switch to a specific Fragment with taking care of validation, Title and BackStack
1014 */
1015 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001016 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001017 if (validate && !isValidFragment(fragmentName)) {
1018 throw new IllegalArgumentException("Invalid fragment for this activity: "
1019 + fragmentName);
1020 }
1021 Fragment f = Fragment.instantiate(this, fragmentName, args);
1022 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Anna Galusza6b1e9db2016-03-30 17:25:36 -07001023 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001024 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -07001025 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001026 }
1027 if (addToBackStack) {
1028 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
1029 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001030 if (titleResId > 0) {
1031 transaction.setBreadCrumbTitle(titleResId);
1032 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001033 transaction.setBreadCrumbTitle(title);
1034 }
1035 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -07001036 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001037 return f;
1038 }
1039
Jason Monk4da79e02015-09-10 10:54:36 -04001040 private void updateTilesList() {
Jason Monkfd2c7222015-12-02 15:38:38 -05001041 // Generally the items that are will be changing from these updates will
1042 // not be in the top list of tiles, so run it in the background and the
1043 // SettingsDrawerActivity will pick up on the updates automatically.
1044 AsyncTask.execute(new Runnable() {
1045 @Override
1046 public void run() {
1047 doUpdateTilesList();
1048 }
1049 });
1050 }
1051
1052 private void doUpdateTilesList() {
Jason Monk4da79e02015-09-10 10:54:36 -04001053 PackageManager pm = getPackageManager();
Xiaohui Chen44879a32015-07-22 13:53:22 -07001054 final UserManager um = UserManager.get(this);
1055 final boolean isAdmin = um.isAdminUser();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001056
Jason Monk4da79e02015-09-10 10:54:36 -04001057 String packageName = getPackageName();
1058 setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()),
1059 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), 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.BluetoothSettingsActivity.class.getName()),
1063 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), 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.DataUsageSummaryActivity.class.getName()),
1067 Utils.isBandwidthControlEnabled(), 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.SimSettingsActivity.class.getName()),
1071 Utils.showSimCardTile(this), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001072
Jason Monk4da79e02015-09-10 10:54:36 -04001073 setTileEnabled(new ComponentName(packageName,
1074 Settings.PowerUsageSummaryActivity.class.getName()),
1075 mBatteryPresent, isAdmin, pm);
1076
1077 setTileEnabled(new ComponentName(packageName,
Jason Monk4da79e02015-09-10 10:54:36 -04001078 Settings.UserSettingsActivity.class.getName()),
1079 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
1080 && !Utils.isMonkeyRunning(), isAdmin, pm);
1081
Fyodor Kupolovca060e32016-06-24 13:01:11 -07001082 setTileEnabled(new ComponentName(packageName,
1083 Settings.WirelessSettingsActivity.class.getName()),
1084 !UserManager.isDeviceInDemoMode(this), isAdmin, pm);
1085
1086 setTileEnabled(new ComponentName(packageName,
1087 Settings.DateTimeSettingsActivity.class.getName()),
1088 !UserManager.isDeviceInDemoMode(this), isAdmin, pm);
Jason Monk4da79e02015-09-10 10:54:36 -04001089 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
1090 setTileEnabled(new ComponentName(packageName,
1091 Settings.PaymentSettingsActivity.class.getName()),
1092 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
1093 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
1094 && adapter != null && adapter.isEnabled(), isAdmin, pm);
1095
1096 setTileEnabled(new ComponentName(packageName,
1097 Settings.PrintSettingsActivity.class.getName()),
1098 pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin, pm);
1099
1100 final boolean showDev = mDevelopmentPreferences.getBoolean(
Dan Sandler12c4ba42016-03-28 11:13:40 -04001101 DevelopmentSettings.PREF_SHOW, android.os.Build.TYPE.equals("eng"))
1102 && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES);
Jason Monk4da79e02015-09-10 10:54:36 -04001103 setTileEnabled(new ComponentName(packageName,
1104 Settings.DevelopmentSettingsActivity.class.getName()),
Dan Sandler12c4ba42016-03-28 11:13:40 -04001105 showDev, isAdmin, pm);
1106
1107 // Reveal development-only quick settings tiles
1108 DevelopmentTiles.setTilesEnabled(this, showDev);
Jason Monk4da79e02015-09-10 10:54:36 -04001109
1110 if (UserHandle.MU_ENABLED && !isAdmin) {
1111 // When on restricted users, disable all extra categories (but only the settings ones).
Jason Monkfd2c7222015-12-02 15:38:38 -05001112 List<DashboardCategory> categories = getDashboardCategories();
Jason Monk4da79e02015-09-10 10:54:36 -04001113 for (DashboardCategory category : categories) {
Jason Monkd4f03ec2016-01-07 16:25:34 -05001114 for (Tile tile : category.tiles) {
Jason Monk4da79e02015-09-10 10:54:36 -04001115 ComponentName component = tile.intent.getComponent();
Jason Monk5862c1e2016-06-07 14:02:33 -04001116 if (packageName.equals(component.getPackageName()) && !ArrayUtils.contains(
Jason Monk4da79e02015-09-10 10:54:36 -04001117 SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1118 setTileEnabled(component, false, isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001119 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001120 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001121 }
1122 }
Doris Ling26bf0032016-06-15 18:16:09 -07001123
1124 String backupIntent = getResources().getString(R.string.config_backup_settings_intent);
1125 boolean useDefaultBackup = TextUtils.isEmpty(backupIntent);
1126 setTileEnabled(new ComponentName(packageName,
1127 Settings.PrivacySettingsActivity.class.getName()), useDefaultBackup, isAdmin, pm);
1128 boolean hasBackupActivity = false;
1129 if (!useDefaultBackup) {
1130 try {
1131 Intent intent = Intent.parseUri(backupIntent, 0);
1132 hasBackupActivity = !getPackageManager().queryIntentActivities(intent, 0).isEmpty();
1133 } catch (URISyntaxException e) {
1134 Log.e(LOG_TAG, "Invalid backup intent URI!", e);
1135 }
1136 }
1137 setTileEnabled(new ComponentName(packageName,
1138 BackupSettingsActivity.class.getName()), hasBackupActivity, isAdmin, pm);
1139
Jason Monk2ebc8a02015-02-13 15:23:19 -05001140 }
1141
Jason Monk4da79e02015-09-10 10:54:36 -04001142 private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin,
1143 PackageManager pm) {
Jason Monk5862c1e2016-06-07 14:02:33 -04001144 if (UserHandle.MU_ENABLED && !isAdmin && getPackageName().equals(component.getPackageName())
Jason Monk4da79e02015-09-10 10:54:36 -04001145 && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1146 enabled = false;
1147 }
Jason Monk5862c1e2016-06-07 14:02:33 -04001148 setTileEnabled(component, enabled);
Jason Monk2ebc8a02015-02-13 15:23:19 -05001149 }
1150
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001151 private void getMetaData() {
1152 try {
1153 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1154 PackageManager.GET_META_DATA);
1155 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001156 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1157 } catch (NameNotFoundException nnfe) {
1158 // No recovery
1159 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1160 }
1161 }
1162
1163 // give subclasses access to the Next button
1164 public boolean hasNextButton() {
1165 return mNextButton != null;
1166 }
1167
1168 public Button getNextButton() {
1169 return mNextButton;
1170 }
1171
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001172 @Override
1173 public boolean shouldUpRecreateTask(Intent targetIntent) {
1174 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1175 }
1176
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001177 @Override
1178 public boolean onQueryTextSubmit(String query) {
1179 switchToSearchResultsFragmentIfNeeded();
1180 mSearchQuery = query;
1181 return mSearchResultsFragment.onQueryTextSubmit(query);
1182 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001183
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001184 @Override
1185 public boolean onQueryTextChange(String newText) {
1186 mSearchQuery = newText;
Fabrice Di Meglio7e4855e2014-05-23 16:03:43 -07001187 if (mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001188 return false;
1189 }
1190 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001191 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001192
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001193 @Override
1194 public boolean onClose() {
1195 return false;
1196 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001197
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001198 @Override
1199 public boolean onMenuItemActionExpand(MenuItem item) {
1200 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001201 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001202 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001203 return true;
1204 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001205
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001206 @Override
1207 public boolean onMenuItemActionCollapse(MenuItem item) {
1208 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001209 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001210 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001211 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001212 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001213 return true;
1214 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001215
Jason Monk4da79e02015-09-10 10:54:36 -04001216 @Override
Jason Monkd4f03ec2016-01-07 16:25:34 -05001217 protected void onTileClicked(Tile tile) {
Jason Monk4da79e02015-09-10 10:54:36 -04001218 if (mIsShowingDashboard) {
1219 // If on dashboard, don't finish so the back comes back to here.
1220 openTile(tile);
1221 } else {
1222 super.onTileClicked(tile);
1223 }
1224 }
1225
Jason Monkaf001092015-11-04 13:16:18 -05001226 @Override
1227 public void onProfileTileOpen() {
1228 if (!mIsShowingDashboard) {
1229 finish();
1230 }
1231 }
1232
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001233 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001234 if (mSearchResultsFragment != null) {
1235 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001236 }
Anna Galusza6b1e9db2016-03-30 17:25:36 -07001237 Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001238 if (current != null && current instanceof SearchResultsSummary) {
1239 mSearchResultsFragment = (SearchResultsSummary) current;
1240 } else {
Fan Zhang28691572016-03-23 15:31:08 -07001241 setContentHeaderView(null);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001242 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001243 SearchResultsSummary.class.getName(), null, false, true,
1244 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001245 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001246 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001247 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001248 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001249
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001250 public void needToRevertToInitialFragment() {
1251 mNeedToRevertToInitialFragment = true;
1252 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001253
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001254 private void revertToInitialFragment() {
1255 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001256 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001257 mSearchMenuItemExpanded = false;
1258 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1259 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001260 if (mSearchMenuItem != null) {
1261 mSearchMenuItem.collapseActionView();
1262 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001263 }
Jim Miller0698a212014-10-16 19:49:07 -07001264
1265 public Intent getResultIntentData() {
1266 return mResultIntentData;
1267 }
1268
1269 public void setResultIntentData(Intent resultIntentData) {
1270 mResultIntentData = resultIntentData;
1271 }
Jason Monkd4f03ec2016-01-07 16:25:34 -05001272
1273 public void startSuggestion(Intent intent) {
1274 mCurrentSuggestion = intent.getComponent();
1275 startActivityForResult(intent, REQUEST_SUGGESTION);
1276 }
1277
1278 @Override
1279 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
1280 if (requestCode == REQUEST_SUGGESTION && mCurrentSuggestion != null
1281 && resultCode != RESULT_CANCELED) {
1282 getPackageManager().setComponentEnabledSetting(mCurrentSuggestion,
1283 PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
1284 }
1285 super.onActivityResult(requestCode, resultCode, data);
1286 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001287}