blob: 02d943498a569f4f0f87683621a37a4722cc6744 [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);
Fan Zhangb9239182016-08-22 13:59:59 -0700481 mSearchView.setMaxWidth(Integer.MAX_VALUE);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700482 mSearchView.setOnQueryTextListener(this);
483 mSearchView.setOnCloseListener(this);
484
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700485 if (mSearchMenuItemExpanded) {
486 mSearchMenuItem.expandActionView();
487 }
488 mSearchView.setQuery(query, true /* submit */);
489
490 return true;
491 }
492
Jason Monk31c7c322016-01-20 14:41:52 -0500493 @Override
494 public SharedPreferences getSharedPreferences(String name, int mode) {
495 if (name.equals(getPackageName() + "_preferences")) {
Jason Monke4ebcd12016-02-21 09:37:41 -0500496 return new SharedPreferencesLogger(this, getMetricsTag());
Jason Monk31c7c322016-01-20 14:41:52 -0500497 }
498 return super.getSharedPreferences(name, mode);
499 }
500
Jason Monke4ebcd12016-02-21 09:37:41 -0500501 private String getMetricsTag() {
502 String tag = getClass().getName();
503 if (getIntent() != null && getIntent().hasExtra(EXTRA_SHOW_FRAGMENT)) {
504 tag = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
505 }
506 if (tag.startsWith("com.android.settings.")) {
507 tag = tag.replace("com.android.settings.", "");
508 }
509 return tag;
510 }
511
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700512 private static boolean isShortCutIntent(final Intent intent) {
513 Set<String> categories = intent.getCategories();
514 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
515 }
516
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700517 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700518 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700519 if (action == null) {
520 return false;
521 }
522 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
523 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
524 }
525 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700526 }
527
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700528 @Override
529 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700530 super.onCreate(savedState);
Jason Monkfd2c7222015-12-02 15:38:38 -0500531 long startTime = System.currentTimeMillis();
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700532
533 // Should happen before any call to getIntent()
534 getMetaData();
535
536 final Intent intent = getIntent();
537 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
538 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800539 }
Udam Saini92779ce2016-03-28 14:29:48 -0700540 if (intent.getBooleanExtra(EXTRA_HIDE_DRAWER, false)) {
541 setIsDrawerPresent(false);
542 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800543
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800544 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
545 Context.MODE_PRIVATE);
546
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700547 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700548 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700549
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700550 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700551 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
552
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700553 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700554 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700555
Jason Monk4da79e02015-09-10 10:54:36 -0400556 mIsShowingDashboard = className.equals(Settings.class.getName())
557 || className.equals(Settings.WirelessSettings.class.getName())
558 || className.equals(Settings.DeviceSettings.class.getName())
559 || className.equals(Settings.PersonalSettings.class.getName())
560 || className.equals(Settings.WirelessSettings.class.getName());
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700561
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700562 // This is a "Sub Settings" when:
563 // - this is a real SubSettings
564 // - or :settings:show_fragment_as_subsetting is passed to the Intent
Jorim Jaggi4dfcb822015-04-29 17:21:32 -0700565 final boolean isSubSettings = this instanceof SubSettings ||
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700566 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
567
568 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
569 if (isSubSettings) {
Fabrice Di Meglio712df6c2014-07-18 17:44:37 -0700570 // Check also that we are not a Theme Dialog as we don't want to override them
571 final int themeResId = getThemeResId();
572 if (themeResId != R.style.Theme_DialogWhenLarge &&
573 themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
574 setTheme(R.style.Theme_SubSettings);
575 }
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700576 }
577
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700578 setContentView(mIsShowingDashboard ?
579 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800580
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700581 mContent = (ViewGroup) findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700582
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800583 getFragmentManager().addOnBackStackChangedListener(this);
584
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700585 if (mIsShowingDashboard) {
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800586 // Run the Index update only if we have some space
587 if (!Utils.isLowStorage(this)) {
Jason Monkfd2c7222015-12-02 15:38:38 -0500588 long indexStartTime = System.currentTimeMillis();
Jason Monk6c9e8842016-04-14 14:34:16 -0400589 Index.getInstance(getApplicationContext()).update();
Jason Monkfd2c7222015-12-02 15:38:38 -0500590 if (DEBUG_TIMING) Log.d(LOG_TAG, "Index.update() took "
591 + (System.currentTimeMillis() - indexStartTime) + " ms");
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800592 } else {
593 Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
594 }
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700595 }
596
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700597 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700598 // We are restarting from a previous saved state; used that to initialize, instead
599 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700600 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
601 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700602 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800603
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700604 ArrayList<DashboardCategory> categories =
605 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
606 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700607 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700608 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700609 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800610 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700611
612 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700613 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Salvador Martinez2368e542016-07-25 18:16:47 -0700614
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800615 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700616 if (!mIsShowingDashboard) {
Jason Monkea8b1a72015-06-02 16:46:34 -0400617 mDisplaySearch = false;
618 // UP will be shown only if it is a sub settings
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700619 if (mIsShortcut) {
620 mDisplayHomeAsUpEnabled = isSubSettings;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700621 } else if (isSubSettings) {
622 mDisplayHomeAsUpEnabled = true;
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700623 } else {
624 mDisplayHomeAsUpEnabled = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700625 }
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700626 setTitleFromIntent(intent);
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700627
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700628 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700629 switchToFragment(initialFragmentName, initialArguments, true, false,
630 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000631 } else {
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700632 // No UP affordance if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700633 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700634 // Show Search affordance
635 mDisplaySearch = true;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700636 mInitialTitleResId = R.string.dashboard_title;
Salvador Martinez2368e542016-07-25 18:16:47 -0700637
638 // add argument to indicate which settings tab should be initially selected
639 final Bundle args = new Bundle();
640 final String extraName = DashboardContainerFragment.EXTRA_SELECT_SETTINGS_TAB;
641 args.putString(extraName, intent.getStringExtra(extraName));
642
643 switchToFragment(DashboardContainerFragment.class.getName(), args, false, false,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700644 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800645 }
646 }
647
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700648 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700649 if (mActionBar != null) {
650 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
651 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
652 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700653 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
Jason Monke4ebcd12016-02-21 09:37:41 -0500654 if (mSwitchBar != null) {
655 mSwitchBar.setMetricsTag(getMetricsTag());
656 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700657
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800658 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800659 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
660
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700661 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800662 if (buttonBar != null) {
663 buttonBar.setVisibility(View.VISIBLE);
664
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700665 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800666 backButton.setOnClickListener(new OnClickListener() {
667 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700668 setResult(RESULT_CANCELED, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800669 finish();
670 }
671 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700672 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800673 skipButton.setOnClickListener(new OnClickListener() {
674 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700675 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800676 finish();
677 }
678 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700679 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800680 mNextButton.setOnClickListener(new OnClickListener() {
681 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700682 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800683 finish();
684 }
685 });
686
687 // set our various button parameters
688 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
689 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
690 if (TextUtils.isEmpty(buttonText)) {
691 mNextButton.setVisibility(View.GONE);
692 }
693 else {
694 mNextButton.setText(buttonText);
695 }
696 }
697 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
698 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
699 if (TextUtils.isEmpty(buttonText)) {
700 backButton.setVisibility(View.GONE);
701 }
702 else {
703 backButton.setText(buttonText);
704 }
705 }
706 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
707 skipButton.setVisibility(View.VISIBLE);
708 }
709 }
710 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700711
Jason Monkfd2c7222015-12-02 15:38:38 -0500712 if (DEBUG_TIMING) Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
713 + " ms");
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700714 }
715
Fan Zhangece8ff62016-06-30 13:20:12 -0700716 public void setDisplaySearchMenu(boolean displaySearch) {
717 if (displaySearch != mDisplaySearch) {
718 mDisplaySearch = displaySearch;
719 invalidateOptionsMenu();
720 }
721 }
722
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700723 private void setTitleFromIntent(Intent intent) {
724 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
725 if (initialTitleResId > 0) {
726 mInitialTitle = null;
727 mInitialTitleResId = initialTitleResId;
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100728
729 final String initialTitleResPackageName = intent.getStringExtra(
730 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
731 if (initialTitleResPackageName != null) {
732 try {
733 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
734 0 /* flags */, new UserHandle(UserHandle.myUserId()));
735 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
736 setTitle(mInitialTitle);
737 mInitialTitleResId = -1;
738 return;
739 } catch (NameNotFoundException e) {
740 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
741 }
742 } else {
743 setTitle(mInitialTitleResId);
744 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700745 } else {
746 mInitialTitleResId = -1;
747 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
748 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
749 setTitle(mInitialTitle);
750 }
751 }
752
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800753 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800754 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700755 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800756 }
757
Fan Zhang28691572016-03-23 15:31:08 -0700758 private void setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800759 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700760
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800761 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700762 if (mInitialTitleResId > 0) {
763 setTitle(mInitialTitleResId);
764 } else {
765 setTitle(mInitialTitle);
766 }
Fan Zhang28691572016-03-23 15:31:08 -0700767 return;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800768 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700769
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800770 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
771 setTitleFromBackStackEntry(bse);
772 }
773
774 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
775 final CharSequence title;
776 final int titleRes = bse.getBreadCrumbTitleRes();
777 if (titleRes > 0) {
778 title = getText(titleRes);
779 } else {
780 title = bse.getBreadCrumbTitle();
781 }
782 if (title != null) {
783 setTitle(title);
784 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800785 }
786
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800787 @Override
788 protected void onSaveInstanceState(Bundle outState) {
789 super.onSaveInstanceState(outState);
790
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700791 if (mCategories.size() > 0) {
792 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800793 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700794
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700795 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700796 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700797
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700798 if (mDisplaySearch) {
799 // The option menus are created if the ActionBar is visible and they are also created
800 // asynchronously. If you launch Settings with an Intent action like
801 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
802 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
803 // menu item and search view are null.
804 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
805 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700806
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700807 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
808 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
809 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800810 }
811
812 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400813 protected void onResume() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800814 super.onResume();
815
816 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
817 @Override
818 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Jason Monk4da79e02015-09-10 10:54:36 -0400819 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800820 }
821 };
822 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
823 mDevelopmentPreferencesListener);
824
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800825 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Clara Bayarri6934a042015-10-14 11:07:35 +0100826 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_ADDED));
827 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_REMOVED));
Svetoslav853e4712014-04-14 10:10:25 -0700828
Philip P. Moltmannd9779db2016-02-24 12:11:05 -0800829 mDynamicIndexableContentMonitor.register(this, LOADER_ID_INDEXABLE_CONTENT_MONITOR);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700830
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700831 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700832 onQueryTextSubmit(mSearchQuery);
833 }
Jason Monk4da79e02015-09-10 10:54:36 -0400834 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800835 }
836
837 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400838 protected void onPause() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800839 super.onPause();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800840 unregisterReceiver(mBatteryInfoReceiver);
Clara Bayarri8c9521f2016-01-12 14:10:45 +0000841 unregisterReceiver(mUserAddRemoveReceiver);
Svetoslav990159a2014-04-14 17:14:59 -0700842 mDynamicIndexableContentMonitor.unregister();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800843 }
844
845 @Override
846 public void onDestroy() {
847 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700848
849 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
850 mDevelopmentPreferencesListener);
851 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800852 }
853
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800854 protected boolean isValidFragment(String fragmentName) {
855 // Almost all fragments are wrapped in this,
856 // except for a few that have their own activities.
857 for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
858 if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
859 }
860 return false;
861 }
862
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800863 @Override
864 public Intent getIntent() {
865 Intent superIntent = super.getIntent();
866 String startingFragment = getStartingFragmentClass(superIntent);
867 // This is called from super.onCreate, isMultiPane() is not yet reliable
868 // Do not use onIsHidingHeaders either, which relies itself on this method
869 if (startingFragment != null) {
870 Intent modIntent = new Intent(superIntent);
871 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
872 Bundle args = superIntent.getExtras();
873 if (args != null) {
874 args = new Bundle(args);
875 } else {
876 args = new Bundle();
877 }
878 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100879 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800880 return modIntent;
881 }
882 return superIntent;
883 }
884
885 /**
886 * Checks if the component name in the intent is different from the Settings class and
887 * returns the class name to load as a fragment.
888 */
889 private String getStartingFragmentClass(Intent intent) {
890 if (mFragmentClass != null) return mFragmentClass;
891
892 String intentClass = intent.getComponent().getClassName();
893 if (intentClass.equals(getClass().getName())) return null;
894
895 if ("com.android.settings.ManageApplications".equals(intentClass)
896 || "com.android.settings.RunningServices".equals(intentClass)
897 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
898 // Old names of manage apps.
899 intentClass = com.android.settings.applications.ManageApplications.class.getName();
900 }
901
902 return intentClass;
903 }
904
905 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000906 * Start a new fragment containing a preference panel. If the preferences
907 * are being displayed in multi-pane mode, the given fragment class will
908 * be instantiated and placed in the appropriate pane. If running in
909 * single-pane mode, a new activity will be launched in which to show the
910 * fragment.
911 *
912 * @param fragmentClass Full name of the class implementing the fragment.
913 * @param args Any desired arguments to supply to the fragment.
914 * @param titleRes Optional resource identifier of the title of this
915 * fragment.
916 * @param titleText Optional text of the title of this fragment.
917 * @param resultTo Optional fragment that result data should be sent to.
918 * If non-null, resultTo.onActivityResult() will be called when this
919 * preference panel is done. The launched panel must use
920 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
921 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700922 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000923 */
924 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700925 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700926 String title = null;
927 if (titleRes < 0) {
928 if (titleText != null) {
929 title = titleText.toString();
930 } else {
931 // There not much we can do in that case
932 title = "";
933 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700934 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700935 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700936 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000937 }
938
939 /**
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100940 * Start a new fragment in a new activity containing a preference panel for a given user. If the
941 * preferences are being displayed in multi-pane mode, the given fragment class will be
942 * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
943 * activity will be launched in which to show the fragment.
944 *
945 * @param fragmentClass Full name of the class implementing the fragment.
946 * @param args Any desired arguments to supply to the fragment.
947 * @param titleRes Optional resource identifier of the title of this fragment.
948 * @param titleText Optional text of the title of this fragment.
949 * @param userHandle The user for which the panel has to be started.
950 */
951 public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
952 CharSequence titleText, UserHandle userHandle) {
Lifu Tangd0332852015-04-02 12:05:46 -0700953 // This is a workaround.
954 //
955 // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
956 // starting the fragment could cause a native stack corruption. See b/17523189. However,
957 // adding that flag and start the preference panel with the same UserHandler will make it
958 // impossible to use back button to return to the previous screen. See b/20042570.
959 //
960 // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
961 // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
962 // when we're calling it as the same user.
963 if (userHandle.getIdentifier() == UserHandle.myUserId()) {
964 startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0);
965 } else {
966 String title = null;
967 if (titleRes < 0) {
968 if (titleText != null) {
969 title = titleText.toString();
970 } else {
971 // There not much we can do in that case
972 title = "";
973 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100974 }
Lifu Tangd0332852015-04-02 12:05:46 -0700975 Utils.startWithFragmentAsUser(this, fragmentClass, args,
976 titleRes, title, mIsShortcut, userHandle);
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100977 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100978 }
979
980 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800981 * Called by a preference panel fragment to finish itself.
982 *
983 * @param caller The fragment that is asking to be finished.
984 * @param resultCode Optional result code to send back to the original
985 * launching fragment.
986 * @param resultData Optional result data to send back to the original
987 * launching fragment.
988 */
989 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
990 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700991 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800992 }
993
994 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000995 * Start a new fragment.
996 *
997 * @param fragment The fragment to start
998 * @param push If true, the current fragment will be pushed onto the back stack. If false,
999 * the current fragment will be replaced.
1000 */
1001 public void startPreferenceFragment(Fragment fragment, boolean push) {
1002 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Anna Galusza6b1e9db2016-03-30 17:25:36 -07001003 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +00001004 if (push) {
1005 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
1006 transaction.addToBackStack(BACK_STACK_PREFS);
1007 } else {
1008 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
1009 }
1010 transaction.commitAllowingStateLoss();
1011 }
1012
1013 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001014 * Switch to a specific Fragment with taking care of validation, Title and BackStack
1015 */
1016 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001017 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001018 if (validate && !isValidFragment(fragmentName)) {
1019 throw new IllegalArgumentException("Invalid fragment for this activity: "
1020 + fragmentName);
1021 }
1022 Fragment f = Fragment.instantiate(this, fragmentName, args);
1023 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Anna Galusza6b1e9db2016-03-30 17:25:36 -07001024 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001025 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -07001026 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001027 }
1028 if (addToBackStack) {
1029 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
1030 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001031 if (titleResId > 0) {
1032 transaction.setBreadCrumbTitle(titleResId);
1033 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001034 transaction.setBreadCrumbTitle(title);
1035 }
1036 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -07001037 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001038 return f;
1039 }
1040
Jason Monk4da79e02015-09-10 10:54:36 -04001041 private void updateTilesList() {
Jason Monkfd2c7222015-12-02 15:38:38 -05001042 // Generally the items that are will be changing from these updates will
1043 // not be in the top list of tiles, so run it in the background and the
1044 // SettingsDrawerActivity will pick up on the updates automatically.
1045 AsyncTask.execute(new Runnable() {
1046 @Override
1047 public void run() {
1048 doUpdateTilesList();
1049 }
1050 });
1051 }
1052
1053 private void doUpdateTilesList() {
Jason Monk4da79e02015-09-10 10:54:36 -04001054 PackageManager pm = getPackageManager();
Xiaohui Chen44879a32015-07-22 13:53:22 -07001055 final UserManager um = UserManager.get(this);
1056 final boolean isAdmin = um.isAdminUser();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001057
Jason Monk4da79e02015-09-10 10:54:36 -04001058 String packageName = getPackageName();
1059 setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()),
1060 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001061
Jason Monk4da79e02015-09-10 10:54:36 -04001062 setTileEnabled(new ComponentName(packageName,
1063 Settings.BluetoothSettingsActivity.class.getName()),
1064 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001065
Jason Monk4da79e02015-09-10 10:54:36 -04001066 setTileEnabled(new ComponentName(packageName,
1067 Settings.DataUsageSummaryActivity.class.getName()),
1068 Utils.isBandwidthControlEnabled(), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001069
Jason Monk4da79e02015-09-10 10:54:36 -04001070 setTileEnabled(new ComponentName(packageName,
1071 Settings.SimSettingsActivity.class.getName()),
1072 Utils.showSimCardTile(this), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001073
Jason Monk4da79e02015-09-10 10:54:36 -04001074 setTileEnabled(new ComponentName(packageName,
1075 Settings.PowerUsageSummaryActivity.class.getName()),
1076 mBatteryPresent, isAdmin, pm);
1077
1078 setTileEnabled(new ComponentName(packageName,
Jason Monk4da79e02015-09-10 10:54:36 -04001079 Settings.UserSettingsActivity.class.getName()),
1080 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
1081 && !Utils.isMonkeyRunning(), isAdmin, pm);
1082
Fyodor Kupolovca060e32016-06-24 13:01:11 -07001083 setTileEnabled(new ComponentName(packageName,
1084 Settings.WirelessSettingsActivity.class.getName()),
1085 !UserManager.isDeviceInDemoMode(this), isAdmin, pm);
1086
1087 setTileEnabled(new ComponentName(packageName,
1088 Settings.DateTimeSettingsActivity.class.getName()),
1089 !UserManager.isDeviceInDemoMode(this), isAdmin, pm);
Jason Monk4da79e02015-09-10 10:54:36 -04001090 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
1091 setTileEnabled(new ComponentName(packageName,
1092 Settings.PaymentSettingsActivity.class.getName()),
1093 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
1094 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
1095 && adapter != null && adapter.isEnabled(), isAdmin, pm);
1096
1097 setTileEnabled(new ComponentName(packageName,
1098 Settings.PrintSettingsActivity.class.getName()),
1099 pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin, pm);
1100
1101 final boolean showDev = mDevelopmentPreferences.getBoolean(
Dan Sandler12c4ba42016-03-28 11:13:40 -04001102 DevelopmentSettings.PREF_SHOW, android.os.Build.TYPE.equals("eng"))
1103 && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES);
Jason Monk4da79e02015-09-10 10:54:36 -04001104 setTileEnabled(new ComponentName(packageName,
1105 Settings.DevelopmentSettingsActivity.class.getName()),
Dan Sandler12c4ba42016-03-28 11:13:40 -04001106 showDev, isAdmin, pm);
1107
1108 // Reveal development-only quick settings tiles
1109 DevelopmentTiles.setTilesEnabled(this, showDev);
Jason Monk4da79e02015-09-10 10:54:36 -04001110
1111 if (UserHandle.MU_ENABLED && !isAdmin) {
1112 // When on restricted users, disable all extra categories (but only the settings ones).
Jason Monkfd2c7222015-12-02 15:38:38 -05001113 List<DashboardCategory> categories = getDashboardCategories();
Jason Monk4da79e02015-09-10 10:54:36 -04001114 for (DashboardCategory category : categories) {
Jason Monkd4f03ec2016-01-07 16:25:34 -05001115 for (Tile tile : category.tiles) {
Jason Monk4da79e02015-09-10 10:54:36 -04001116 ComponentName component = tile.intent.getComponent();
Jason Monk5862c1e2016-06-07 14:02:33 -04001117 if (packageName.equals(component.getPackageName()) && !ArrayUtils.contains(
Jason Monk4da79e02015-09-10 10:54:36 -04001118 SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1119 setTileEnabled(component, false, isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001120 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001121 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001122 }
1123 }
Doris Ling26bf0032016-06-15 18:16:09 -07001124
1125 String backupIntent = getResources().getString(R.string.config_backup_settings_intent);
1126 boolean useDefaultBackup = TextUtils.isEmpty(backupIntent);
1127 setTileEnabled(new ComponentName(packageName,
1128 Settings.PrivacySettingsActivity.class.getName()), useDefaultBackup, isAdmin, pm);
1129 boolean hasBackupActivity = false;
1130 if (!useDefaultBackup) {
1131 try {
1132 Intent intent = Intent.parseUri(backupIntent, 0);
1133 hasBackupActivity = !getPackageManager().queryIntentActivities(intent, 0).isEmpty();
1134 } catch (URISyntaxException e) {
1135 Log.e(LOG_TAG, "Invalid backup intent URI!", e);
1136 }
1137 }
1138 setTileEnabled(new ComponentName(packageName,
1139 BackupSettingsActivity.class.getName()), hasBackupActivity, isAdmin, pm);
1140
Jason Monk2ebc8a02015-02-13 15:23:19 -05001141 }
1142
Jason Monk4da79e02015-09-10 10:54:36 -04001143 private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin,
1144 PackageManager pm) {
Jason Monk5862c1e2016-06-07 14:02:33 -04001145 if (UserHandle.MU_ENABLED && !isAdmin && getPackageName().equals(component.getPackageName())
Jason Monk4da79e02015-09-10 10:54:36 -04001146 && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1147 enabled = false;
1148 }
Jason Monk5862c1e2016-06-07 14:02:33 -04001149 setTileEnabled(component, enabled);
Jason Monk2ebc8a02015-02-13 15:23:19 -05001150 }
1151
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001152 private void getMetaData() {
1153 try {
1154 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1155 PackageManager.GET_META_DATA);
1156 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001157 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1158 } catch (NameNotFoundException nnfe) {
1159 // No recovery
1160 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1161 }
1162 }
1163
1164 // give subclasses access to the Next button
1165 public boolean hasNextButton() {
1166 return mNextButton != null;
1167 }
1168
1169 public Button getNextButton() {
1170 return mNextButton;
1171 }
1172
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001173 @Override
1174 public boolean shouldUpRecreateTask(Intent targetIntent) {
1175 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1176 }
1177
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001178 @Override
1179 public boolean onQueryTextSubmit(String query) {
1180 switchToSearchResultsFragmentIfNeeded();
1181 mSearchQuery = query;
1182 return mSearchResultsFragment.onQueryTextSubmit(query);
1183 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001184
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001185 @Override
1186 public boolean onQueryTextChange(String newText) {
1187 mSearchQuery = newText;
Fabrice Di Meglio7e4855e2014-05-23 16:03:43 -07001188 if (mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001189 return false;
1190 }
1191 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001192 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001193
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001194 @Override
1195 public boolean onClose() {
1196 return false;
1197 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001198
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001199 @Override
1200 public boolean onMenuItemActionExpand(MenuItem item) {
1201 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001202 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001203 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001204 return true;
1205 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001206
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001207 @Override
1208 public boolean onMenuItemActionCollapse(MenuItem item) {
1209 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001210 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001211 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001212 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001213 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001214 return true;
1215 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001216
Jason Monk4da79e02015-09-10 10:54:36 -04001217 @Override
Jason Monkd4f03ec2016-01-07 16:25:34 -05001218 protected void onTileClicked(Tile tile) {
Jason Monk4da79e02015-09-10 10:54:36 -04001219 if (mIsShowingDashboard) {
1220 // If on dashboard, don't finish so the back comes back to here.
1221 openTile(tile);
1222 } else {
1223 super.onTileClicked(tile);
1224 }
1225 }
1226
Jason Monkaf001092015-11-04 13:16:18 -05001227 @Override
1228 public void onProfileTileOpen() {
1229 if (!mIsShowingDashboard) {
1230 finish();
1231 }
1232 }
1233
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001234 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001235 if (mSearchResultsFragment != null) {
1236 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001237 }
Anna Galusza6b1e9db2016-03-30 17:25:36 -07001238 Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001239 if (current != null && current instanceof SearchResultsSummary) {
1240 mSearchResultsFragment = (SearchResultsSummary) current;
1241 } else {
Fan Zhang28691572016-03-23 15:31:08 -07001242 setContentHeaderView(null);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001243 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001244 SearchResultsSummary.class.getName(), null, false, true,
1245 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001246 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001247 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001248 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001249 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001250
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001251 public void needToRevertToInitialFragment() {
1252 mNeedToRevertToInitialFragment = true;
1253 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001254
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001255 private void revertToInitialFragment() {
1256 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001257 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001258 mSearchMenuItemExpanded = false;
1259 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1260 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001261 if (mSearchMenuItem != null) {
1262 mSearchMenuItem.collapseActionView();
1263 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001264 }
Jim Miller0698a212014-10-16 19:49:07 -07001265
1266 public Intent getResultIntentData() {
1267 return mResultIntentData;
1268 }
1269
1270 public void setResultIntentData(Intent resultIntentData) {
1271 mResultIntentData = resultIntentData;
1272 }
Jason Monkd4f03ec2016-01-07 16:25:34 -05001273
1274 public void startSuggestion(Intent intent) {
1275 mCurrentSuggestion = intent.getComponent();
1276 startActivityForResult(intent, REQUEST_SUGGESTION);
1277 }
1278
1279 @Override
1280 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
1281 if (requestCode == REQUEST_SUGGESTION && mCurrentSuggestion != null
1282 && resultCode != RESULT_CANCELED) {
1283 getPackageManager().setComponentEnabledSetting(mCurrentSuggestion,
1284 PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
1285 }
1286 super.onActivityResult(requestCode, resultCode, data);
1287 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001288}