blob: e1f8afef6ecb85e8aa7a87578f5898c2c32ed40b [file] [log] [blame]
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.settings;
18
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080019import android.app.ActionBar;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080020import android.app.Fragment;
21import android.app.FragmentManager;
22import android.app.FragmentTransaction;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080023import android.content.BroadcastReceiver;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070024import android.content.ComponentName;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080025import android.content.Context;
26import android.content.Intent;
27import android.content.IntentFilter;
28import android.content.SharedPreferences;
29import android.content.pm.ActivityInfo;
30import android.content.pm.PackageManager;
31import android.content.pm.PackageManager.NameNotFoundException;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080032import android.content.res.Configuration;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080033import android.nfc.NfcAdapter;
Jason Monkfd2c7222015-12-02 15:38:38 -050034import android.os.AsyncTask;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080035import android.os.Bundle;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080036import android.os.UserHandle;
37import android.os.UserManager;
Jason Monk39b46742015-09-10 15:52:51 -040038import android.support.v14.preference.PreferenceFragment;
39import android.support.v7.preference.Preference;
40import android.support.v7.preference.PreferenceManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080041import android.text.TextUtils;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070042import android.transition.TransitionManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080043import android.util.Log;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070044import android.view.Menu;
45import android.view.MenuInflater;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080046import android.view.MenuItem;
47import android.view.View;
48import android.view.View.OnClickListener;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070049import android.view.ViewGroup;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080050import android.widget.Button;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070051import android.widget.SearchView;
Fan Zhang28691572016-03-23 15:31:08 -070052
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080053import com.android.internal.util.ArrayUtils;
Jason Monk4da79e02015-09-10 10:54:36 -040054import com.android.settings.Settings.WifiSettingsActivity;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080055import com.android.settings.accessibility.AccessibilitySettings;
Anna Galuszab1795f52016-01-08 14:37:16 -080056import com.android.settings.accessibility.AccessibilitySettingsForSetupWizard;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080057import com.android.settings.accessibility.CaptionPropertiesFragment;
Alexandra Gherghina6d839872014-07-22 12:04:58 +000058import com.android.settings.accounts.AccountSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080059import com.android.settings.accounts.AccountSyncSettings;
Jason Monkb7e43802016-06-06 16:01:58 -040060import com.android.settings.accounts.ChooseAccountActivity;
Tony Mak64f6d982016-05-03 18:55:41 +010061import com.android.settings.accounts.ManagedProfileSettings;
Jason Monk91e2f892016-02-23 15:31:09 -050062import com.android.settings.applications.AdvancedAppSettings;
Billy Laufee78562015-07-27 12:57:07 +010063import com.android.settings.applications.DrawOverlayDetails;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070064import com.android.settings.applications.InstalledAppDetails;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080065import com.android.settings.applications.ManageApplications;
Xiyuan Xia86a55402015-06-02 14:55:32 -070066import com.android.settings.applications.ManageAssist;
Todd Kennedy2ef1aa52016-09-06 14:02:38 -070067import com.android.settings.applications.ManageDomainUrls;
Jason Monka2d47fc2016-03-03 10:49:44 -050068import com.android.settings.applications.NotificationApps;
Jason Monk2cdafc62015-06-12 12:32:50 -040069import com.android.settings.applications.ProcessStatsSummary;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080070import com.android.settings.applications.ProcessStatsUi;
Jason Monkd8da51c2015-04-17 14:34:12 -040071import com.android.settings.applications.UsageAccessDetails;
Ruben Brunkc461d5c2016-04-07 21:45:41 -070072import com.android.settings.applications.VrListenerSettings;
Fan Zhangece8ff62016-06-30 13:20:12 -070073import com.android.settings.applications.WriteSettingsDetails;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080074import com.android.settings.bluetooth.BluetoothSettings;
Fan Zhang28691572016-03-23 15:31:08 -070075import com.android.settings.dashboard.DashboardContainerFragment;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070076import com.android.settings.dashboard.SearchResultsSummary;
Jason Monkb37e2882016-01-11 14:27:20 -050077import com.android.settings.datausage.DataUsageSummary;
Daniel Nishi39818892016-09-20 16:40:49 -070078import com.android.settings.deletionhelper.AutomaticStorageManagerSettings;
Jason Monkb7e43802016-06-06 16:01:58 -040079import com.android.settings.deviceinfo.ImeiInformation;
Jeff Sharkeya16257d2015-04-28 13:41:01 -070080import com.android.settings.deviceinfo.PrivateVolumeForget;
Jeff Sharkeye77f0682015-04-29 11:24:57 -070081import com.android.settings.deviceinfo.PrivateVolumeSettings;
Jeff Sharkey42833b22015-04-11 21:27:33 -070082import com.android.settings.deviceinfo.PublicVolumeSettings;
Jason Monkb7e43802016-06-06 16:01:58 -040083import com.android.settings.deviceinfo.SimStatus;
84import com.android.settings.deviceinfo.Status;
Jeff Sharkey42833b22015-04-11 21:27:33 -070085import com.android.settings.deviceinfo.StorageSettings;
Justin Klaasseneae3d9f2016-07-21 19:25:17 -070086import com.android.settings.display.NightDisplaySettings;
John Spurlockc7f8e8c2014-06-04 19:11:22 -040087import com.android.settings.fuelgauge.BatterySaverSettings;
Jason Monk1eb54eb2015-04-29 12:46:42 -040088import com.android.settings.fuelgauge.PowerUsageDetail;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080089import com.android.settings.fuelgauge.PowerUsageSummary;
Doris Ling91365232016-05-23 17:06:26 -070090import com.android.settings.gestures.GestureSettings;
Abodunrinwa Toki976bb3f2016-01-20 18:43:20 +000091import com.android.settings.inputmethod.AvailableVirtualKeyboardFragment;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080092import com.android.settings.inputmethod.InputMethodAndLanguageSettings;
93import com.android.settings.inputmethod.KeyboardLayoutPickerFragment;
Abodunrinwa Toki5f0b59b2016-01-25 23:02:23 +000094import com.android.settings.inputmethod.KeyboardLayoutPickerFragment2;
Abodunrinwa Tokib28b2cc2016-03-22 16:29:38 +000095import com.android.settings.inputmethod.PhysicalKeyboardFragment;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080096import com.android.settings.inputmethod.SpellCheckersSettings;
97import com.android.settings.inputmethod.UserDictionaryList;
Mihai Nitad7d48fd2016-01-12 08:55:05 -080098import com.android.settings.localepicker.LocaleListEditor;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080099import com.android.settings.location.LocationSettings;
100import com.android.settings.nfc.AndroidBeam;
101import com.android.settings.nfc.PaymentSettings;
John Spurlock802ddf92014-07-18 11:51:13 -0400102import com.android.settings.notification.AppNotificationSettings;
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500103import com.android.settings.notification.ConfigureNotificationSettings;
John Spurlock4a350512014-04-08 14:08:21 -0400104import com.android.settings.notification.NotificationAccessSettings;
John Spurlock4a350512014-04-08 14:08:21 -0400105import com.android.settings.notification.NotificationStation;
Jason Monk2ebc8a02015-02-13 15:23:19 -0500106import com.android.settings.notification.OtherSoundSettings;
Jason Monkb37e2882016-01-11 14:27:20 -0500107import com.android.settings.notification.SoundSettings;
John Spurlock08531a82015-05-07 17:45:43 -0400108import com.android.settings.notification.ZenAccessSettings;
John Spurlock533a5662015-06-19 10:47:36 -0400109import com.android.settings.notification.ZenModeAutomationSettings;
John Spurlockf57bad72015-04-30 09:26:15 -0400110import com.android.settings.notification.ZenModeEventRuleSettings;
John Spurlockc1df2aa2015-04-13 20:57:06 -0400111import com.android.settings.notification.ZenModePrioritySettings;
John Spurlock45fa1402015-04-09 12:50:04 -0400112import com.android.settings.notification.ZenModeScheduleRuleSettings;
Jason Monk39b46742015-09-10 15:52:51 -0400113import com.android.settings.notification.ZenModeSettings;
Julia Reynolds5555d262015-11-09 10:52:17 -0500114import com.android.settings.notification.ZenModeVisualInterruptionSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800115import com.android.settings.print.PrintJobSettingsFragment;
116import com.android.settings.print.PrintSettingsFragment;
Dan Sandler12c4ba42016-03-28 11:13:40 -0400117import com.android.settings.qstile.DevelopmentTiles;
Jason Monk2ebc8a02015-02-13 15:23:19 -0500118import com.android.settings.search.DynamicIndexableContentMonitor;
119import com.android.settings.search.Index;
PauloftheWest38155612014-06-30 10:02:36 -0700120import com.android.settings.sim.SimSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800121import com.android.settings.tts.TextToSpeechSettings;
122import com.android.settings.users.UserSettings;
123import com.android.settings.vpn2.VpnSettings;
124import com.android.settings.wfd.WifiDisplaySettings;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700125import com.android.settings.widget.SwitchBar;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800126import com.android.settings.wifi.AdvancedWifiSettings;
PauloftheWest7837b992014-06-24 07:42:27 -0700127import com.android.settings.wifi.SavedAccessPointsWifiSettings;
Jason Monkb7e43802016-06-06 16:01:58 -0400128import com.android.settings.wifi.WifiAPITest;
129import com.android.settings.wifi.WifiInfo;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800130import com.android.settings.wifi.WifiSettings;
131import com.android.settings.wifi.p2p.WifiP2pSettings;
Jason Monk4da79e02015-09-10 10:54:36 -0400132import com.android.settingslib.drawer.DashboardCategory;
Jason Monk4da79e02015-09-10 10:54:36 -0400133import com.android.settingslib.drawer.SettingsDrawerActivity;
Jason Monk7ea14c52016-01-22 14:28:02 -0500134import com.android.settingslib.drawer.Tile;
Jason Monk2ebc8a02015-02-13 15:23:19 -0500135
Doris Ling26bf0032016-06-15 18:16:09 -0700136import java.net.URISyntaxException;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800137import java.util.ArrayList;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800138import java.util.List;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700139import java.util.Set;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800140
Jason Monk4da79e02015-09-10 10:54:36 -0400141public class SettingsActivity extends SettingsDrawerActivity
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800142 implements PreferenceManager.OnPreferenceTreeClickListener,
143 PreferenceFragment.OnPreferenceStartFragmentCallback,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100144 ButtonBarHandler, FragmentManager.OnBackStackChangedListener,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700145 SearchView.OnQueryTextListener, SearchView.OnCloseListener,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100146 MenuItem.OnActionExpandListener {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800147
148 private static final String LOG_TAG = "Settings";
149
Philip P. Moltmannd9779db2016-02-24 12:11:05 -0800150 private static final int LOADER_ID_INDEXABLE_CONTENT_MONITOR = 1;
151
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800152 // Constants for state save/restore
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700153 private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700154 private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
155 private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700156 private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700157 private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700158 private static final String SAVE_KEY_HOME_ACTIVITIES_COUNT = ":settings:home_activities_count";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800159
160 /**
161 * When starting this activity, the invoking Intent can contain this extra
162 * string to specify which fragment should be initially displayed.
163 * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
164 * will call isValidFragment() to confirm that the fragment class name is valid for this
165 * activity.
166 */
167 public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
168
169 /**
170 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
171 * this extra can also be specified to supply a Bundle of arguments to pass
172 * to that fragment when it is instantiated during the initial creation
173 * of the activity.
174 */
175 public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
176
177 /**
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700178 * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
179 */
180 public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
181
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800182 public static final String BACK_STACK_PREFS = ":settings:prefs";
183
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800184 // extras that allow any preference activity to be launched as part of a wizard
185
186 // show Back and Next buttons? takes boolean parameter
187 // Back will then return RESULT_CANCELED and Next RESULT_OK
188 protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
189
190 // add a Skip button?
191 private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
192
193 // specify custom text for the Back or Next buttons, or cause a button to not appear
194 // at all by setting it to null
195 protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
196 protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
197
198 /**
199 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700200 * 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 -0800201 * that fragment.
202 */
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700203 public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100204 /**
205 * The package name used to resolve the title resource id.
206 */
207 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
208 ":settings:show_fragment_title_res_package_name";
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700209 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
210 ":settings:show_fragment_title_resid";
211 public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
212 ":settings:show_fragment_as_shortcut";
213
214 public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
215 ":settings:show_fragment_as_subsetting";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800216
Udam Saini92779ce2016-03-28 14:29:48 -0700217 public static final String EXTRA_HIDE_DRAWER = ":settings:hide_drawer";
218
Jason Monk30695812015-11-17 09:01:08 -0500219 public static final String META_DATA_KEY_FRAGMENT_CLASS =
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800220 "com.android.settings.FRAGMENT_CLASS";
221
222 private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
223
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700224 private static final String EMPTY_QUERY = "";
225
Jason Monkd4f03ec2016-01-07 16:25:34 -0500226 private static final int REQUEST_SUGGESTION = 42;
227
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800228 private String mFragmentClass;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800229
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800230 private CharSequence mInitialTitle;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700231 private int mInitialTitleResId;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800232
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800233 // Show only these settings for restricted users
Jason Monk4da79e02015-09-10 10:54:36 -0400234 private String[] SETTINGS_FOR_RESTRICTED = {
235 //wireless_section
236 WifiSettingsActivity.class.getName(),
237 Settings.BluetoothSettingsActivity.class.getName(),
238 Settings.DataUsageSummaryActivity.class.getName(),
239 Settings.SimSettingsActivity.class.getName(),
240 Settings.WirelessSettingsActivity.class.getName(),
241 //device_section
242 Settings.HomeSettingsActivity.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500243 Settings.SoundSettingsActivity.class.getName(),
Jason Monk4da79e02015-09-10 10:54:36 -0400244 Settings.DisplaySettingsActivity.class.getName(),
245 Settings.StorageSettingsActivity.class.getName(),
246 Settings.ManageApplicationsActivity.class.getName(),
247 Settings.PowerUsageSummaryActivity.class.getName(),
Doris Ling91365232016-05-23 17:06:26 -0700248 Settings.GestureSettingsActivity.class.getName(),
Jason Monk4da79e02015-09-10 10:54:36 -0400249 //personal_section
250 Settings.LocationSettingsActivity.class.getName(),
251 Settings.SecuritySettingsActivity.class.getName(),
252 Settings.InputMethodAndLanguageSettingsActivity.class.getName(),
253 Settings.UserSettingsActivity.class.getName(),
254 Settings.AccountSettingsActivity.class.getName(),
255 //system_section
256 Settings.DateTimeSettingsActivity.class.getName(),
257 Settings.DeviceInfoSettingsActivity.class.getName(),
258 Settings.AccessibilitySettingsActivity.class.getName(),
259 Settings.PrintSettingsActivity.class.getName(),
260 Settings.PaymentSettingsActivity.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800261 };
262
263 private static final String[] ENTRY_FRAGMENTS = {
264 WirelessSettings.class.getName(),
265 WifiSettings.class.getName(),
266 AdvancedWifiSettings.class.getName(),
PauloftheWest7837b992014-06-24 07:42:27 -0700267 SavedAccessPointsWifiSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800268 BluetoothSettings.class.getName(),
PauloftheWest38155612014-06-30 10:02:36 -0700269 SimSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800270 TetherSettings.class.getName(),
271 WifiP2pSettings.class.getName(),
272 VpnSettings.class.getName(),
273 DateTimeSettings.class.getName(),
Mihai Nitad7d48fd2016-01-12 08:55:05 -0800274 LocaleListEditor.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800275 InputMethodAndLanguageSettings.class.getName(),
Abodunrinwa Toki976bb3f2016-01-20 18:43:20 +0000276 AvailableVirtualKeyboardFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800277 SpellCheckersSettings.class.getName(),
278 UserDictionaryList.class.getName(),
279 UserDictionarySettings.class.getName(),
Amith Yamasani3033ce02014-07-14 18:03:15 -0700280 HomeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800281 DisplaySettings.class.getName(),
282 DeviceInfoSettings.class.getName(),
283 ManageApplications.class.getName(),
Jason Monka2d47fc2016-03-03 10:49:44 -0500284 NotificationApps.class.getName(),
Xiyuan Xia86a55402015-06-02 14:55:32 -0700285 ManageAssist.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800286 ProcessStatsUi.class.getName(),
287 NotificationStation.class.getName(),
288 LocationSettings.class.getName(),
289 SecuritySettings.class.getName(),
Jason Monkd8da51c2015-04-17 14:34:12 -0400290 UsageAccessDetails.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800291 PrivacySettings.class.getName(),
292 DeviceAdminSettings.class.getName(),
293 AccessibilitySettings.class.getName(),
Anna Galuszab1795f52016-01-08 14:37:16 -0800294 AccessibilitySettingsForSetupWizard.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800295 CaptionPropertiesFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800296 com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(),
297 TextToSpeechSettings.class.getName(),
Jeff Sharkey42833b22015-04-11 21:27:33 -0700298 StorageSettings.class.getName(),
Jeff Sharkeya16257d2015-04-28 13:41:01 -0700299 PrivateVolumeForget.class.getName(),
Jeff Sharkeye77f0682015-04-29 11:24:57 -0700300 PrivateVolumeSettings.class.getName(),
301 PublicVolumeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800302 DevelopmentSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800303 AndroidBeam.class.getName(),
304 WifiDisplaySettings.class.getName(),
305 PowerUsageSummary.class.getName(),
306 AccountSyncSettings.class.getName(),
Alexandra Gherghina6d839872014-07-22 12:04:58 +0000307 AccountSettings.class.getName(),
Doris Ling91365232016-05-23 17:06:26 -0700308 GestureSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800309 CryptKeeperSettings.class.getName(),
310 DataUsageSummary.class.getName(),
311 DreamSettings.class.getName(),
312 UserSettings.class.getName(),
313 NotificationAccessSettings.class.getName(),
John Spurlock08531a82015-05-07 17:45:43 -0400314 ZenAccessSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800315 PrintSettingsFragment.class.getName(),
316 PrintJobSettingsFragment.class.getName(),
317 TrustedCredentialsSettings.class.getName(),
318 PaymentSettings.class.getName(),
319 KeyboardLayoutPickerFragment.class.getName(),
Abodunrinwa Toki5f0b59b2016-01-25 23:02:23 +0000320 KeyboardLayoutPickerFragment2.class.getName(),
Abodunrinwa Tokib28b2cc2016-03-22 16:29:38 +0000321 PhysicalKeyboardFragment.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700322 ZenModeSettings.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500323 SoundSettings.class.getName(),
324 ConfigureNotificationSettings.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700325 ChooseLockPassword.ChooseLockPasswordFragment.class.getName(),
326 ChooseLockPattern.ChooseLockPatternFragment.class.getName(),
John Spurlockc7f8e8c2014-06-04 19:11:22 -0400327 InstalledAppDetails.class.getName(),
328 BatterySaverSettings.class.getName(),
Fabrice Di Megliodcf59dd2014-07-21 11:22:20 -0700329 AppNotificationSettings.class.getName(),
Fabrice Di Meglioe3ff4d82014-07-23 20:03:20 -0700330 OtherSoundSettings.class.getName(),
Narayan Kamath33acb152015-03-16 12:48:05 +0000331 ApnSettings.class.getName(),
Jason Monkb7e43802016-06-06 16:01:58 -0400332 ApnEditor.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400333 WifiCallingSettings.class.getName(),
John Spurlockc1df2aa2015-04-13 20:57:06 -0400334 ZenModePrioritySettings.class.getName(),
John Spurlock533a5662015-06-19 10:47:36 -0400335 ZenModeAutomationSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400336 ZenModeScheduleRuleSettings.class.getName(),
John Spurlockf57bad72015-04-30 09:26:15 -0400337 ZenModeEventRuleSettings.class.getName(),
Julia Reynolds5555d262015-11-09 10:52:17 -0500338 ZenModeVisualInterruptionSettings.class.getName(),
Jason Monk2583fc12015-03-25 09:46:30 -0400339 ProcessStatsUi.class.getName(),
Jason Monk1eb54eb2015-04-29 12:46:42 -0400340 PowerUsageDetail.class.getName(),
Jason Monk2cdafc62015-06-12 12:32:50 -0400341 ProcessStatsSummary.class.getName(),
Billy Laufee78562015-07-27 12:57:07 +0100342 DrawOverlayDetails.class.getName(),
343 WriteSettingsDetails.class.getName(),
Jason Monk91e2f892016-02-23 15:31:09 -0500344 AdvancedAppSettings.class.getName(),
Jason Monkb9e5d232016-01-26 17:43:57 -0500345 WallpaperTypeSettings.class.getName(),
Ruben Brunkc461d5c2016-04-07 21:45:41 -0700346 VrListenerSettings.class.getName(),
Tony Mak64f6d982016-05-03 18:55:41 +0100347 ManagedProfileSettings.class.getName(),
Jason Monkb7e43802016-06-06 16:01:58 -0400348 ChooseAccountActivity.class.getName(),
349 IccLockSettings.class.getName(),
350 ImeiInformation.class.getName(),
351 SimStatus.class.getName(),
352 Status.class.getName(),
353 TestingSettings.class.getName(),
354 WifiAPITest.class.getName(),
355 WifiInfo.class.getName(),
Doris Ling7d73a292016-06-21 18:08:22 -0700356 MasterClear.class.getName(),
Justin Klaasseneae3d9f2016-07-21 19:25:17 -0700357 NightDisplaySettings.class.getName(),
Todd Kennedy2ef1aa52016-09-06 14:02:38 -0700358 ManageDomainUrls.class.getName(),
Daniel Nishi39818892016-09-20 16:40:49 -0700359 AutomaticStorageManagerSettings.class.getName()
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800360 };
361
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700362
363 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
364 "android.settings.APPLICATION_DETAILS_SETTINGS"
365 };
366
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800367 private SharedPreferences mDevelopmentPreferences;
368 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
369
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800370 private boolean mBatteryPresent = true;
371 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800372 @Override
373 public void onReceive(Context context, Intent intent) {
374 String action = intent.getAction();
375 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
376 boolean batteryPresent = Utils.isBatteryPresent(intent);
377
378 if (mBatteryPresent != batteryPresent) {
379 mBatteryPresent = batteryPresent;
Jason Monk4da79e02015-09-10 10:54:36 -0400380 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800381 }
382 }
383 }
384 };
385
Clara Bayarri6934a042015-10-14 11:07:35 +0100386 private final BroadcastReceiver mUserAddRemoveReceiver = new BroadcastReceiver() {
387 @Override
388 public void onReceive(Context context, Intent intent) {
389 String action = intent.getAction();
390 if (action.equals(Intent.ACTION_USER_ADDED)
391 || action.equals(Intent.ACTION_USER_REMOVED)) {
392 Index.getInstance(getApplicationContext()).update();
393 }
394 }
395 };
396
Svetoslav990159a2014-04-14 17:14:59 -0700397 private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor =
398 new DynamicIndexableContentMonitor();
Svetoslav853e4712014-04-14 10:10:25 -0700399
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700400 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700401 private SwitchBar mSwitchBar;
402
403 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700404
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700405 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700406 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700407
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700408 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700409 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700410
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700411 private ViewGroup mContent;
412
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700413 private SearchView mSearchView;
414 private MenuItem mSearchMenuItem;
415 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700416 private SearchResultsSummary mSearchResultsFragment;
417 private String mSearchQuery;
418
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700419 // Categories
420 private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800421
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700422 private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800423
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700424 private boolean mNeedToRevertToInitialFragment = false;
425
Jim Miller0698a212014-10-16 19:49:07 -0700426 private Intent mResultIntentData;
Jason Monkd4f03ec2016-01-07 16:25:34 -0500427 private ComponentName mCurrentSuggestion;
Jim Miller0698a212014-10-16 19:49:07 -0700428
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700429 public SwitchBar getSwitchBar() {
430 return mSwitchBar;
431 }
432
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800433 @Override
434 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
Sunny Goyal21ef89f2016-05-25 12:41:16 -0700435 startPreferencePanel(pref.getFragment(), pref.getExtras(), -1, pref.getTitle(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800436 null, 0);
437 return true;
438 }
439
440 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400441 public boolean onPreferenceTreeClick(Preference preference) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800442 return false;
443 }
444
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800445 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800446 public void onConfigurationChanged(Configuration newConfig) {
447 super.onConfigurationChanged(newConfig);
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800448 Index.getInstance(this).update();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800449 }
450
451 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700452 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700453 if (!mDisplaySearch) {
454 return false;
455 }
456
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700457 MenuInflater inflater = getMenuInflater();
458 inflater.inflate(R.menu.options_menu, menu);
459
460 // Cache the search query (can be overriden by the OnQueryTextListener)
461 final String query = mSearchQuery;
462
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700463 mSearchMenuItem = menu.findItem(R.id.search);
464 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700465
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700466 if (mSearchMenuItem == null || mSearchView == null) {
467 return false;
468 }
469
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700470 if (mSearchResultsFragment != null) {
471 mSearchResultsFragment.setSearchView(mSearchView);
472 }
473
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700474 mSearchMenuItem.setOnActionExpandListener(this);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700475 mSearchView.setOnQueryTextListener(this);
476 mSearchView.setOnCloseListener(this);
477
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700478 if (mSearchMenuItemExpanded) {
479 mSearchMenuItem.expandActionView();
480 }
481 mSearchView.setQuery(query, true /* submit */);
482
483 return true;
484 }
485
Jason Monk31c7c322016-01-20 14:41:52 -0500486 @Override
487 public SharedPreferences getSharedPreferences(String name, int mode) {
488 if (name.equals(getPackageName() + "_preferences")) {
Jason Monke4ebcd12016-02-21 09:37:41 -0500489 return new SharedPreferencesLogger(this, getMetricsTag());
Jason Monk31c7c322016-01-20 14:41:52 -0500490 }
491 return super.getSharedPreferences(name, mode);
492 }
493
Jason Monke4ebcd12016-02-21 09:37:41 -0500494 private String getMetricsTag() {
495 String tag = getClass().getName();
496 if (getIntent() != null && getIntent().hasExtra(EXTRA_SHOW_FRAGMENT)) {
497 tag = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
498 }
499 if (tag.startsWith("com.android.settings.")) {
500 tag = tag.replace("com.android.settings.", "");
501 }
502 return tag;
503 }
504
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700505 private static boolean isShortCutIntent(final Intent intent) {
506 Set<String> categories = intent.getCategories();
507 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
508 }
509
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700510 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700511 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700512 if (action == null) {
513 return false;
514 }
515 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
516 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
517 }
518 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700519 }
520
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700521 @Override
522 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700523 super.onCreate(savedState);
Jason Monkfd2c7222015-12-02 15:38:38 -0500524 long startTime = System.currentTimeMillis();
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700525
526 // Should happen before any call to getIntent()
527 getMetaData();
528
529 final Intent intent = getIntent();
530 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
531 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800532 }
Udam Saini92779ce2016-03-28 14:29:48 -0700533 if (intent.getBooleanExtra(EXTRA_HIDE_DRAWER, false)) {
534 setIsDrawerPresent(false);
535 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800536
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800537 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
538 Context.MODE_PRIVATE);
539
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700540 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700541 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700542
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700543 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700544 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
545
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700546 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700547 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700548
Jason Monk4da79e02015-09-10 10:54:36 -0400549 mIsShowingDashboard = className.equals(Settings.class.getName())
550 || className.equals(Settings.WirelessSettings.class.getName())
551 || className.equals(Settings.DeviceSettings.class.getName())
552 || className.equals(Settings.PersonalSettings.class.getName())
553 || className.equals(Settings.WirelessSettings.class.getName());
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700554
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700555 // This is a "Sub Settings" when:
556 // - this is a real SubSettings
557 // - or :settings:show_fragment_as_subsetting is passed to the Intent
Jorim Jaggi4dfcb822015-04-29 17:21:32 -0700558 final boolean isSubSettings = this instanceof SubSettings ||
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700559 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
560
561 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
562 if (isSubSettings) {
Fabrice Di Meglio712df6c2014-07-18 17:44:37 -0700563 // Check also that we are not a Theme Dialog as we don't want to override them
564 final int themeResId = getThemeResId();
565 if (themeResId != R.style.Theme_DialogWhenLarge &&
566 themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
567 setTheme(R.style.Theme_SubSettings);
568 }
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700569 }
570
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700571 setContentView(mIsShowingDashboard ?
572 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800573
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700574 mContent = (ViewGroup) findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700575
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800576 getFragmentManager().addOnBackStackChangedListener(this);
577
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700578 if (mIsShowingDashboard) {
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800579 // Run the Index update only if we have some space
580 if (!Utils.isLowStorage(this)) {
Jason Monkfd2c7222015-12-02 15:38:38 -0500581 long indexStartTime = System.currentTimeMillis();
Jason Monk6c9e8842016-04-14 14:34:16 -0400582 Index.getInstance(getApplicationContext()).update();
Jason Monkfd2c7222015-12-02 15:38:38 -0500583 if (DEBUG_TIMING) Log.d(LOG_TAG, "Index.update() took "
584 + (System.currentTimeMillis() - indexStartTime) + " ms");
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800585 } else {
586 Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
587 }
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700588 }
589
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700590 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700591 // We are restarting from a previous saved state; used that to initialize, instead
592 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700593 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
594 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700595 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800596
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700597 ArrayList<DashboardCategory> categories =
598 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
599 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700600 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700601 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700602 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800603 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700604
605 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700606 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Salvador Martinez12c52082016-07-25 18:16:47 -0700607
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800608 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700609 if (!mIsShowingDashboard) {
Jason Monkea8b1a72015-06-02 16:46:34 -0400610 mDisplaySearch = false;
611 // UP will be shown only if it is a sub settings
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700612 if (mIsShortcut) {
613 mDisplayHomeAsUpEnabled = isSubSettings;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700614 } else if (isSubSettings) {
615 mDisplayHomeAsUpEnabled = true;
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700616 } else {
617 mDisplayHomeAsUpEnabled = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700618 }
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700619 setTitleFromIntent(intent);
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700620
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700621 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700622 switchToFragment(initialFragmentName, initialArguments, true, false,
623 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000624 } else {
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700625 // No UP affordance if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700626 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700627 // Show Search affordance
628 mDisplaySearch = true;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700629 mInitialTitleResId = R.string.dashboard_title;
Salvador Martinez12c52082016-07-25 18:16:47 -0700630
631 // add argument to indicate which settings tab should be initially selected
632 final Bundle args = new Bundle();
633 final String extraName = DashboardContainerFragment.EXTRA_SELECT_SETTINGS_TAB;
634 args.putString(extraName, intent.getStringExtra(extraName));
635
636 switchToFragment(DashboardContainerFragment.class.getName(), args, false, false,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700637 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800638 }
639 }
640
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700641 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700642 if (mActionBar != null) {
643 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
644 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
645 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700646 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
Jason Monke4ebcd12016-02-21 09:37:41 -0500647 if (mSwitchBar != null) {
648 mSwitchBar.setMetricsTag(getMetricsTag());
649 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700650
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800651 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800652 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
653
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700654 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800655 if (buttonBar != null) {
656 buttonBar.setVisibility(View.VISIBLE);
657
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700658 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800659 backButton.setOnClickListener(new OnClickListener() {
660 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700661 setResult(RESULT_CANCELED, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800662 finish();
663 }
664 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700665 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800666 skipButton.setOnClickListener(new OnClickListener() {
667 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700668 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800669 finish();
670 }
671 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700672 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800673 mNextButton.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 });
679
680 // set our various button parameters
681 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
682 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
683 if (TextUtils.isEmpty(buttonText)) {
684 mNextButton.setVisibility(View.GONE);
685 }
686 else {
687 mNextButton.setText(buttonText);
688 }
689 }
690 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
691 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
692 if (TextUtils.isEmpty(buttonText)) {
693 backButton.setVisibility(View.GONE);
694 }
695 else {
696 backButton.setText(buttonText);
697 }
698 }
699 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
700 skipButton.setVisibility(View.VISIBLE);
701 }
702 }
703 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700704
Jason Monkfd2c7222015-12-02 15:38:38 -0500705 if (DEBUG_TIMING) Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
706 + " ms");
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700707 }
708
Fan Zhangece8ff62016-06-30 13:20:12 -0700709 public void setDisplaySearchMenu(boolean displaySearch) {
710 if (displaySearch != mDisplaySearch) {
711 mDisplaySearch = displaySearch;
712 invalidateOptionsMenu();
713 }
714 }
715
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700716 private void setTitleFromIntent(Intent intent) {
717 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
718 if (initialTitleResId > 0) {
719 mInitialTitle = null;
720 mInitialTitleResId = initialTitleResId;
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100721
722 final String initialTitleResPackageName = intent.getStringExtra(
723 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
724 if (initialTitleResPackageName != null) {
725 try {
726 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
727 0 /* flags */, new UserHandle(UserHandle.myUserId()));
728 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
729 setTitle(mInitialTitle);
730 mInitialTitleResId = -1;
731 return;
732 } catch (NameNotFoundException e) {
733 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
734 }
735 } else {
736 setTitle(mInitialTitleResId);
737 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700738 } else {
739 mInitialTitleResId = -1;
740 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
741 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
742 setTitle(mInitialTitle);
743 }
744 }
745
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800746 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800747 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700748 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800749 }
750
Fan Zhang28691572016-03-23 15:31:08 -0700751 private void setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800752 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700753
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800754 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700755 if (mInitialTitleResId > 0) {
756 setTitle(mInitialTitleResId);
757 } else {
758 setTitle(mInitialTitle);
759 }
Fan Zhang28691572016-03-23 15:31:08 -0700760 return;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800761 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700762
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800763 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
764 setTitleFromBackStackEntry(bse);
765 }
766
767 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
768 final CharSequence title;
769 final int titleRes = bse.getBreadCrumbTitleRes();
770 if (titleRes > 0) {
771 title = getText(titleRes);
772 } else {
773 title = bse.getBreadCrumbTitle();
774 }
775 if (title != null) {
776 setTitle(title);
777 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800778 }
779
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800780 @Override
781 protected void onSaveInstanceState(Bundle outState) {
782 super.onSaveInstanceState(outState);
783
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700784 if (mCategories.size() > 0) {
785 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800786 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700787
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700788 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700789 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700790
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700791 if (mDisplaySearch) {
792 // The option menus are created if the ActionBar is visible and they are also created
793 // asynchronously. If you launch Settings with an Intent action like
794 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
795 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
796 // menu item and search view are null.
797 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
798 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700799
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700800 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
801 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
802 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800803 }
804
805 @Override
Jason Monk350a9302016-06-01 13:45:25 -0400806 protected void onStart() {
807 super.onStart();
808
809 if (mNeedToRevertToInitialFragment) {
810 revertToInitialFragment();
811 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800812
813 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
814 @Override
815 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Jason Monk4da79e02015-09-10 10:54:36 -0400816 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800817 }
818 };
819 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
820 mDevelopmentPreferencesListener);
821
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800822 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Clara Bayarri6934a042015-10-14 11:07:35 +0100823 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_ADDED));
824 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_REMOVED));
Svetoslav853e4712014-04-14 10:10:25 -0700825
Philip P. Moltmannd9779db2016-02-24 12:11:05 -0800826 mDynamicIndexableContentMonitor.register(this, LOADER_ID_INDEXABLE_CONTENT_MONITOR);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700827
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700828 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700829 onQueryTextSubmit(mSearchQuery);
830 }
Jason Monk4da79e02015-09-10 10:54:36 -0400831 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800832 }
833
834 @Override
Jason Monk350a9302016-06-01 13:45:25 -0400835 protected void onStop() {
836 super.onStop();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800837 unregisterReceiver(mBatteryInfoReceiver);
Clara Bayarri8c9521f2016-01-12 14:10:45 +0000838 unregisterReceiver(mUserAddRemoveReceiver);
Svetoslav990159a2014-04-14 17:14:59 -0700839 mDynamicIndexableContentMonitor.unregister();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800840 }
841
842 @Override
843 public void onDestroy() {
844 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700845
846 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
847 mDevelopmentPreferencesListener);
848 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800849 }
850
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800851 protected boolean isValidFragment(String fragmentName) {
852 // Almost all fragments are wrapped in this,
853 // except for a few that have their own activities.
854 for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
855 if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
856 }
857 return false;
858 }
859
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800860 @Override
861 public Intent getIntent() {
862 Intent superIntent = super.getIntent();
863 String startingFragment = getStartingFragmentClass(superIntent);
864 // This is called from super.onCreate, isMultiPane() is not yet reliable
865 // Do not use onIsHidingHeaders either, which relies itself on this method
866 if (startingFragment != null) {
867 Intent modIntent = new Intent(superIntent);
868 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
869 Bundle args = superIntent.getExtras();
870 if (args != null) {
871 args = new Bundle(args);
872 } else {
873 args = new Bundle();
874 }
875 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100876 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800877 return modIntent;
878 }
879 return superIntent;
880 }
881
882 /**
883 * Checks if the component name in the intent is different from the Settings class and
884 * returns the class name to load as a fragment.
885 */
886 private String getStartingFragmentClass(Intent intent) {
887 if (mFragmentClass != null) return mFragmentClass;
888
889 String intentClass = intent.getComponent().getClassName();
890 if (intentClass.equals(getClass().getName())) return null;
891
892 if ("com.android.settings.ManageApplications".equals(intentClass)
893 || "com.android.settings.RunningServices".equals(intentClass)
894 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
895 // Old names of manage apps.
896 intentClass = com.android.settings.applications.ManageApplications.class.getName();
897 }
898
899 return intentClass;
900 }
901
902 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000903 * Start a new fragment containing a preference panel. If the preferences
904 * are being displayed in multi-pane mode, the given fragment class will
905 * be instantiated and placed in the appropriate pane. If running in
906 * single-pane mode, a new activity will be launched in which to show the
907 * fragment.
908 *
909 * @param fragmentClass Full name of the class implementing the fragment.
910 * @param args Any desired arguments to supply to the fragment.
911 * @param titleRes Optional resource identifier of the title of this
912 * fragment.
913 * @param titleText Optional text of the title of this fragment.
914 * @param resultTo Optional fragment that result data should be sent to.
915 * If non-null, resultTo.onActivityResult() will be called when this
916 * preference panel is done. The launched panel must use
917 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
918 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700919 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000920 */
921 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700922 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700923 String title = null;
924 if (titleRes < 0) {
925 if (titleText != null) {
926 title = titleText.toString();
927 } else {
928 // There not much we can do in that case
929 title = "";
930 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700931 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700932 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700933 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000934 }
935
936 /**
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100937 * Start a new fragment in a new activity containing a preference panel for a given user. If the
938 * preferences are being displayed in multi-pane mode, the given fragment class will be
939 * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
940 * activity will be launched in which to show the fragment.
941 *
942 * @param fragmentClass Full name of the class implementing the fragment.
943 * @param args Any desired arguments to supply to the fragment.
944 * @param titleRes Optional resource identifier of the title of this fragment.
945 * @param titleText Optional text of the title of this fragment.
946 * @param userHandle The user for which the panel has to be started.
947 */
948 public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
949 CharSequence titleText, UserHandle userHandle) {
Lifu Tangd0332852015-04-02 12:05:46 -0700950 // This is a workaround.
951 //
952 // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
953 // starting the fragment could cause a native stack corruption. See b/17523189. However,
954 // adding that flag and start the preference panel with the same UserHandler will make it
955 // impossible to use back button to return to the previous screen. See b/20042570.
956 //
957 // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
958 // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
959 // when we're calling it as the same user.
960 if (userHandle.getIdentifier() == UserHandle.myUserId()) {
961 startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0);
962 } else {
963 String title = null;
964 if (titleRes < 0) {
965 if (titleText != null) {
966 title = titleText.toString();
967 } else {
968 // There not much we can do in that case
969 title = "";
970 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100971 }
Lifu Tangd0332852015-04-02 12:05:46 -0700972 Utils.startWithFragmentAsUser(this, fragmentClass, args,
973 titleRes, title, mIsShortcut, userHandle);
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100974 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100975 }
976
977 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800978 * Called by a preference panel fragment to finish itself.
979 *
980 * @param caller The fragment that is asking to be finished.
981 * @param resultCode Optional result code to send back to the original
982 * launching fragment.
983 * @param resultData Optional result data to send back to the original
984 * launching fragment.
985 */
986 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
987 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700988 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800989 }
990
991 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000992 * Start a new fragment.
993 *
994 * @param fragment The fragment to start
995 * @param push If true, the current fragment will be pushed onto the back stack. If false,
996 * the current fragment will be replaced.
997 */
998 public void startPreferenceFragment(Fragment fragment, boolean push) {
999 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Anna Galusza6b1e9db2016-03-30 17:25:36 -07001000 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +00001001 if (push) {
1002 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
1003 transaction.addToBackStack(BACK_STACK_PREFS);
1004 } else {
1005 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
1006 }
1007 transaction.commitAllowingStateLoss();
1008 }
1009
1010 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001011 * Switch to a specific Fragment with taking care of validation, Title and BackStack
1012 */
1013 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001014 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001015 if (validate && !isValidFragment(fragmentName)) {
1016 throw new IllegalArgumentException("Invalid fragment for this activity: "
1017 + fragmentName);
1018 }
1019 Fragment f = Fragment.instantiate(this, fragmentName, args);
1020 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Anna Galusza6b1e9db2016-03-30 17:25:36 -07001021 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001022 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -07001023 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001024 }
1025 if (addToBackStack) {
1026 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
1027 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001028 if (titleResId > 0) {
1029 transaction.setBreadCrumbTitle(titleResId);
1030 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001031 transaction.setBreadCrumbTitle(title);
1032 }
1033 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -07001034 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001035 return f;
1036 }
1037
Jason Monk4da79e02015-09-10 10:54:36 -04001038 private void updateTilesList() {
Jason Monkfd2c7222015-12-02 15:38:38 -05001039 // Generally the items that are will be changing from these updates will
1040 // not be in the top list of tiles, so run it in the background and the
1041 // SettingsDrawerActivity will pick up on the updates automatically.
1042 AsyncTask.execute(new Runnable() {
1043 @Override
1044 public void run() {
1045 doUpdateTilesList();
1046 }
1047 });
1048 }
1049
1050 private void doUpdateTilesList() {
Jason Monk4da79e02015-09-10 10:54:36 -04001051 PackageManager pm = getPackageManager();
Xiaohui Chen44879a32015-07-22 13:53:22 -07001052 final UserManager um = UserManager.get(this);
1053 final boolean isAdmin = um.isAdminUser();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001054
Jason Monk4da79e02015-09-10 10:54:36 -04001055 String packageName = getPackageName();
1056 setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()),
1057 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001058
Jason Monk4da79e02015-09-10 10:54:36 -04001059 setTileEnabled(new ComponentName(packageName,
1060 Settings.BluetoothSettingsActivity.class.getName()),
1061 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001062
Jason Monk4da79e02015-09-10 10:54:36 -04001063 setTileEnabled(new ComponentName(packageName,
1064 Settings.DataUsageSummaryActivity.class.getName()),
1065 Utils.isBandwidthControlEnabled(), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001066
Jason Monk4da79e02015-09-10 10:54:36 -04001067 setTileEnabled(new ComponentName(packageName,
1068 Settings.SimSettingsActivity.class.getName()),
1069 Utils.showSimCardTile(this), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001070
Jason Monk4da79e02015-09-10 10:54:36 -04001071 setTileEnabled(new ComponentName(packageName,
1072 Settings.PowerUsageSummaryActivity.class.getName()),
1073 mBatteryPresent, isAdmin, pm);
1074
1075 setTileEnabled(new ComponentName(packageName,
Jason Monk4da79e02015-09-10 10:54:36 -04001076 Settings.UserSettingsActivity.class.getName()),
1077 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
1078 && !Utils.isMonkeyRunning(), isAdmin, pm);
1079
Fyodor Kupolovca060e32016-06-24 13:01:11 -07001080 setTileEnabled(new ComponentName(packageName,
1081 Settings.WirelessSettingsActivity.class.getName()),
1082 !UserManager.isDeviceInDemoMode(this), isAdmin, pm);
1083
1084 setTileEnabled(new ComponentName(packageName,
1085 Settings.DateTimeSettingsActivity.class.getName()),
1086 !UserManager.isDeviceInDemoMode(this), isAdmin, pm);
Jason Monk4da79e02015-09-10 10:54:36 -04001087 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
1088 setTileEnabled(new ComponentName(packageName,
1089 Settings.PaymentSettingsActivity.class.getName()),
1090 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
1091 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
1092 && adapter != null && adapter.isEnabled(), isAdmin, pm);
1093
1094 setTileEnabled(new ComponentName(packageName,
1095 Settings.PrintSettingsActivity.class.getName()),
1096 pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin, pm);
1097
1098 final boolean showDev = mDevelopmentPreferences.getBoolean(
Dan Sandler12c4ba42016-03-28 11:13:40 -04001099 DevelopmentSettings.PREF_SHOW, android.os.Build.TYPE.equals("eng"))
1100 && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES);
Jason Monk4da79e02015-09-10 10:54:36 -04001101 setTileEnabled(new ComponentName(packageName,
1102 Settings.DevelopmentSettingsActivity.class.getName()),
Dan Sandler12c4ba42016-03-28 11:13:40 -04001103 showDev, isAdmin, pm);
1104
1105 // Reveal development-only quick settings tiles
1106 DevelopmentTiles.setTilesEnabled(this, showDev);
Jason Monk4da79e02015-09-10 10:54:36 -04001107
1108 if (UserHandle.MU_ENABLED && !isAdmin) {
1109 // When on restricted users, disable all extra categories (but only the settings ones).
Jason Monkfd2c7222015-12-02 15:38:38 -05001110 List<DashboardCategory> categories = getDashboardCategories();
Jason Monk4da79e02015-09-10 10:54:36 -04001111 for (DashboardCategory category : categories) {
Jason Monkd4f03ec2016-01-07 16:25:34 -05001112 for (Tile tile : category.tiles) {
Jason Monk4da79e02015-09-10 10:54:36 -04001113 ComponentName component = tile.intent.getComponent();
Jason Monk5862c1e2016-06-07 14:02:33 -04001114 if (packageName.equals(component.getPackageName()) && !ArrayUtils.contains(
Jason Monk4da79e02015-09-10 10:54:36 -04001115 SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1116 setTileEnabled(component, false, isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001117 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001118 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001119 }
1120 }
Doris Ling26bf0032016-06-15 18:16:09 -07001121
1122 String backupIntent = getResources().getString(R.string.config_backup_settings_intent);
1123 boolean useDefaultBackup = TextUtils.isEmpty(backupIntent);
1124 setTileEnabled(new ComponentName(packageName,
1125 Settings.PrivacySettingsActivity.class.getName()), useDefaultBackup, isAdmin, pm);
1126 boolean hasBackupActivity = false;
1127 if (!useDefaultBackup) {
1128 try {
1129 Intent intent = Intent.parseUri(backupIntent, 0);
1130 hasBackupActivity = !getPackageManager().queryIntentActivities(intent, 0).isEmpty();
1131 } catch (URISyntaxException e) {
1132 Log.e(LOG_TAG, "Invalid backup intent URI!", e);
1133 }
1134 }
1135 setTileEnabled(new ComponentName(packageName,
1136 BackupSettingsActivity.class.getName()), hasBackupActivity, isAdmin, pm);
1137
Jason Monk2ebc8a02015-02-13 15:23:19 -05001138 }
1139
Jason Monk4da79e02015-09-10 10:54:36 -04001140 private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin,
1141 PackageManager pm) {
Jason Monk5862c1e2016-06-07 14:02:33 -04001142 if (UserHandle.MU_ENABLED && !isAdmin && getPackageName().equals(component.getPackageName())
Jason Monk4da79e02015-09-10 10:54:36 -04001143 && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1144 enabled = false;
1145 }
Jason Monk5862c1e2016-06-07 14:02:33 -04001146 setTileEnabled(component, enabled);
Jason Monk2ebc8a02015-02-13 15:23:19 -05001147 }
1148
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001149 private void getMetaData() {
1150 try {
1151 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1152 PackageManager.GET_META_DATA);
1153 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001154 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1155 } catch (NameNotFoundException nnfe) {
1156 // No recovery
1157 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1158 }
1159 }
1160
1161 // give subclasses access to the Next button
1162 public boolean hasNextButton() {
1163 return mNextButton != null;
1164 }
1165
1166 public Button getNextButton() {
1167 return mNextButton;
1168 }
1169
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001170 @Override
1171 public boolean shouldUpRecreateTask(Intent targetIntent) {
1172 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1173 }
1174
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001175 @Override
1176 public boolean onQueryTextSubmit(String query) {
1177 switchToSearchResultsFragmentIfNeeded();
1178 mSearchQuery = query;
1179 return mSearchResultsFragment.onQueryTextSubmit(query);
1180 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001181
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001182 @Override
1183 public boolean onQueryTextChange(String newText) {
1184 mSearchQuery = newText;
Fabrice Di Meglio7e4855e2014-05-23 16:03:43 -07001185 if (mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001186 return false;
1187 }
1188 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001189 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001190
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001191 @Override
1192 public boolean onClose() {
1193 return false;
1194 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001195
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001196 @Override
1197 public boolean onMenuItemActionExpand(MenuItem item) {
1198 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001199 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001200 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001201 return true;
1202 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001203
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001204 @Override
1205 public boolean onMenuItemActionCollapse(MenuItem item) {
1206 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001207 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001208 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001209 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001210 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001211 return true;
1212 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001213
Jason Monk4da79e02015-09-10 10:54:36 -04001214 @Override
Jason Monkd4f03ec2016-01-07 16:25:34 -05001215 protected void onTileClicked(Tile tile) {
Jason Monk4da79e02015-09-10 10:54:36 -04001216 if (mIsShowingDashboard) {
1217 // If on dashboard, don't finish so the back comes back to here.
1218 openTile(tile);
1219 } else {
1220 super.onTileClicked(tile);
1221 }
1222 }
1223
Jason Monkaf001092015-11-04 13:16:18 -05001224 @Override
1225 public void onProfileTileOpen() {
1226 if (!mIsShowingDashboard) {
1227 finish();
1228 }
1229 }
1230
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001231 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001232 if (mSearchResultsFragment != null) {
1233 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001234 }
Anna Galusza6b1e9db2016-03-30 17:25:36 -07001235 Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001236 if (current != null && current instanceof SearchResultsSummary) {
1237 mSearchResultsFragment = (SearchResultsSummary) current;
1238 } else {
Fan Zhang28691572016-03-23 15:31:08 -07001239 setContentHeaderView(null);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001240 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001241 SearchResultsSummary.class.getName(), null, false, true,
1242 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001243 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001244 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001245 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001246 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001247
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001248 public void needToRevertToInitialFragment() {
1249 mNeedToRevertToInitialFragment = true;
1250 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001251
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001252 private void revertToInitialFragment() {
1253 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001254 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001255 mSearchMenuItemExpanded = false;
1256 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1257 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001258 if (mSearchMenuItem != null) {
1259 mSearchMenuItem.collapseActionView();
1260 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001261 }
Jim Miller0698a212014-10-16 19:49:07 -07001262
1263 public Intent getResultIntentData() {
1264 return mResultIntentData;
1265 }
1266
1267 public void setResultIntentData(Intent resultIntentData) {
1268 mResultIntentData = resultIntentData;
1269 }
Jason Monkd4f03ec2016-01-07 16:25:34 -05001270
1271 public void startSuggestion(Intent intent) {
Matthew Fritze703dc602016-09-30 12:36:27 -07001272 if (intent == null) {
1273 return;
1274 }
1275 final ComponentName componentName = intent.getComponent();
1276 if (componentName.equals(mCurrentSuggestion)) {
1277 return;
1278 }
1279 mCurrentSuggestion = componentName;
Jason Monkd4f03ec2016-01-07 16:25:34 -05001280 startActivityForResult(intent, REQUEST_SUGGESTION);
1281 }
1282
1283 @Override
1284 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
1285 if (requestCode == REQUEST_SUGGESTION && mCurrentSuggestion != null
1286 && resultCode != RESULT_CANCELED) {
1287 getPackageManager().setComponentEnabledSetting(mCurrentSuggestion,
1288 PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
1289 }
1290 super.onActivityResult(requestCode, resultCode, data);
1291 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001292}