blob: 34dd09598fd4b3897750e6355b4d51a627f7fd81 [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
Fan Zhang60f01072016-10-13 16:53:41 -070019import android.app.ActionBar;
Matthew Fritze7ac78f22016-10-03 13:26:07 -070020import android.app.ActivityManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080021import android.app.Fragment;
22import android.app.FragmentManager;
23import android.app.FragmentTransaction;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080024import android.content.BroadcastReceiver;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070025import android.content.ComponentName;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080026import android.content.Context;
27import android.content.Intent;
28import android.content.IntentFilter;
29import android.content.SharedPreferences;
30import android.content.pm.ActivityInfo;
31import android.content.pm.PackageManager;
32import android.content.pm.PackageManager.NameNotFoundException;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080033import android.content.res.Configuration;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080034import android.nfc.NfcAdapter;
Jason Monkfd2c7222015-12-02 15:38:38 -050035import android.os.AsyncTask;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080036import android.os.Bundle;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080037import android.os.UserHandle;
38import android.os.UserManager;
Jason Monk39b46742015-09-10 15:52:51 -040039import android.support.v14.preference.PreferenceFragment;
40import android.support.v7.preference.Preference;
41import android.support.v7.preference.PreferenceManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080042import android.text.TextUtils;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070043import android.transition.TransitionManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080044import android.util.Log;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070045import android.view.Menu;
46import android.view.MenuInflater;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080047import android.view.MenuItem;
48import android.view.View;
49import android.view.View.OnClickListener;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070050import android.view.ViewGroup;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080051import android.widget.Button;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070052import android.widget.SearchView;
Fan Zhang28691572016-03-23 15:31:08 -070053
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080054import com.android.internal.util.ArrayUtils;
Jason Monk4da79e02015-09-10 10:54:36 -040055import com.android.settings.Settings.WifiSettingsActivity;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080056import com.android.settings.accessibility.AccessibilitySettings;
Anna Galuszab1795f52016-01-08 14:37:16 -080057import com.android.settings.accessibility.AccessibilitySettingsForSetupWizard;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080058import com.android.settings.accessibility.CaptionPropertiesFragment;
Fan Zhanga96a2d82016-09-27 17:51:11 -070059import com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment;
Alexandra Gherghina6d839872014-07-22 12:04:58 +000060import com.android.settings.accounts.AccountSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080061import com.android.settings.accounts.AccountSyncSettings;
Jason Monkb7e43802016-06-06 16:01:58 -040062import com.android.settings.accounts.ChooseAccountActivity;
Tony Mak64f6d982016-05-03 18:55:41 +010063import com.android.settings.accounts.ManagedProfileSettings;
Doris Lingd7aae182016-10-21 11:33:54 -070064import com.android.settings.accounts.UserAndAccountDashboardFragment;
Fan Zhangf37be6a2016-10-20 12:47:52 -070065import com.android.settings.applications.AppAndNotificationDashboardFragment;
Jason Monk91e2f892016-02-23 15:31:09 -050066import com.android.settings.applications.AdvancedAppSettings;
Billy Laufee78562015-07-27 12:57:07 +010067import com.android.settings.applications.DrawOverlayDetails;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070068import com.android.settings.applications.InstalledAppDetails;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080069import com.android.settings.applications.ManageApplications;
Xiyuan Xia86a55402015-06-02 14:55:32 -070070import com.android.settings.applications.ManageAssist;
Todd Kennedy2ef1aa52016-09-06 14:02:38 -070071import com.android.settings.applications.ManageDomainUrls;
Jason Monka2d47fc2016-03-03 10:49:44 -050072import com.android.settings.applications.NotificationApps;
Jason Monk2cdafc62015-06-12 12:32:50 -040073import com.android.settings.applications.ProcessStatsSummary;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080074import com.android.settings.applications.ProcessStatsUi;
Jason Monkd8da51c2015-04-17 14:34:12 -040075import com.android.settings.applications.UsageAccessDetails;
Ruben Brunkc461d5c2016-04-07 21:45:41 -070076import com.android.settings.applications.VrListenerSettings;
Fan Zhangece8ff62016-06-30 13:20:12 -070077import com.android.settings.applications.WriteSettingsDetails;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080078import com.android.settings.bluetooth.BluetoothSettings;
Doris Lingb2c8c9c2016-10-10 16:59:16 -070079import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
Fan Zhang5f79ae92016-08-18 16:04:19 -070080import com.android.settings.core.instrumentation.SharedPreferencesLogger;
Fan Zhang28691572016-03-23 15:31:08 -070081import com.android.settings.dashboard.DashboardContainerFragment;
Fan Zhanga96a2d82016-09-27 17:51:11 -070082import com.android.settings.dashboard.DashboardFeatureProvider;
83import com.android.settings.dashboard.DashboardSummary;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070084import com.android.settings.dashboard.SearchResultsSummary;
Fan Zhanga96a2d82016-09-27 17:51:11 -070085import com.android.settings.dashboard.SupportFragment;
Jason Monkb37e2882016-01-11 14:27:20 -050086import com.android.settings.datausage.DataUsageSummary;
Daniel Nishi39818892016-09-20 16:40:49 -070087import com.android.settings.deletionhelper.AutomaticStorageManagerSettings;
Jason Monkb7e43802016-06-06 16:01:58 -040088import com.android.settings.deviceinfo.ImeiInformation;
Jeff Sharkeya16257d2015-04-28 13:41:01 -070089import com.android.settings.deviceinfo.PrivateVolumeForget;
Jeff Sharkeye77f0682015-04-29 11:24:57 -070090import com.android.settings.deviceinfo.PrivateVolumeSettings;
Jeff Sharkey42833b22015-04-11 21:27:33 -070091import com.android.settings.deviceinfo.PublicVolumeSettings;
Jason Monkb7e43802016-06-06 16:01:58 -040092import com.android.settings.deviceinfo.SimStatus;
93import com.android.settings.deviceinfo.Status;
Fan Zhangbb6d2602016-10-04 13:21:06 -070094import com.android.settings.deviceinfo.StorageDashboardFragment;
Jeff Sharkey42833b22015-04-11 21:27:33 -070095import com.android.settings.deviceinfo.StorageSettings;
Justin Klaasseneae3d9f2016-07-21 19:25:17 -070096import com.android.settings.display.NightDisplaySettings;
John Spurlockc7f8e8c2014-06-04 19:11:22 -040097import com.android.settings.fuelgauge.BatterySaverSettings;
Jason Monk1eb54eb2015-04-29 12:46:42 -040098import com.android.settings.fuelgauge.PowerUsageDetail;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080099import com.android.settings.fuelgauge.PowerUsageSummary;
Doris Ling91365232016-05-23 17:06:26 -0700100import com.android.settings.gestures.GestureSettings;
Abodunrinwa Toki976bb3f2016-01-20 18:43:20 +0000101import com.android.settings.inputmethod.AvailableVirtualKeyboardFragment;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800102import com.android.settings.inputmethod.InputMethodAndLanguageSettings;
103import com.android.settings.inputmethod.KeyboardLayoutPickerFragment;
Abodunrinwa Toki5f0b59b2016-01-25 23:02:23 +0000104import com.android.settings.inputmethod.KeyboardLayoutPickerFragment2;
Abodunrinwa Tokib28b2cc2016-03-22 16:29:38 +0000105import com.android.settings.inputmethod.PhysicalKeyboardFragment;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800106import com.android.settings.inputmethod.SpellCheckersSettings;
107import com.android.settings.inputmethod.UserDictionaryList;
Mihai Nitad7d48fd2016-01-12 08:55:05 -0800108import com.android.settings.localepicker.LocaleListEditor;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800109import com.android.settings.location.LocationSettings;
Fan Zhangbb93dc02016-10-11 16:27:45 -0700110import com.android.settings.network.NetworkDashboardFragment;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800111import com.android.settings.nfc.AndroidBeam;
112import com.android.settings.nfc.PaymentSettings;
John Spurlock802ddf92014-07-18 11:51:13 -0400113import com.android.settings.notification.AppNotificationSettings;
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500114import com.android.settings.notification.ConfigureNotificationSettings;
John Spurlock4a350512014-04-08 14:08:21 -0400115import com.android.settings.notification.NotificationAccessSettings;
John Spurlock4a350512014-04-08 14:08:21 -0400116import com.android.settings.notification.NotificationStation;
Jason Monk2ebc8a02015-02-13 15:23:19 -0500117import com.android.settings.notification.OtherSoundSettings;
Jason Monkb37e2882016-01-11 14:27:20 -0500118import com.android.settings.notification.SoundSettings;
John Spurlock08531a82015-05-07 17:45:43 -0400119import com.android.settings.notification.ZenAccessSettings;
John Spurlock533a5662015-06-19 10:47:36 -0400120import com.android.settings.notification.ZenModeAutomationSettings;
John Spurlockf57bad72015-04-30 09:26:15 -0400121import com.android.settings.notification.ZenModeEventRuleSettings;
John Spurlockc1df2aa2015-04-13 20:57:06 -0400122import com.android.settings.notification.ZenModePrioritySettings;
John Spurlock45fa1402015-04-09 12:50:04 -0400123import com.android.settings.notification.ZenModeScheduleRuleSettings;
Jason Monk39b46742015-09-10 15:52:51 -0400124import com.android.settings.notification.ZenModeSettings;
Julia Reynolds5555d262015-11-09 10:52:17 -0500125import com.android.settings.notification.ZenModeVisualInterruptionSettings;
Fan Zhanga96a2d82016-09-27 17:51:11 -0700126import com.android.settings.overlay.FeatureFactory;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800127import com.android.settings.print.PrintJobSettingsFragment;
128import com.android.settings.print.PrintSettingsFragment;
Dan Sandler12c4ba42016-03-28 11:13:40 -0400129import com.android.settings.qstile.DevelopmentTiles;
Jason Monk2ebc8a02015-02-13 15:23:19 -0500130import com.android.settings.search.DynamicIndexableContentMonitor;
131import com.android.settings.search.Index;
PauloftheWest38155612014-06-30 10:02:36 -0700132import com.android.settings.sim.SimSettings;
Fan Zhangcc335d92016-09-29 14:37:14 -0700133import com.android.settings.system.SystemDashboardFragment;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800134import com.android.settings.tts.TextToSpeechSettings;
135import com.android.settings.users.UserSettings;
136import com.android.settings.vpn2.VpnSettings;
137import com.android.settings.wfd.WifiDisplaySettings;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700138import com.android.settings.widget.SwitchBar;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800139import com.android.settings.wifi.AdvancedWifiSettings;
PauloftheWest7837b992014-06-24 07:42:27 -0700140import com.android.settings.wifi.SavedAccessPointsWifiSettings;
Jason Monkb7e43802016-06-06 16:01:58 -0400141import com.android.settings.wifi.WifiAPITest;
142import com.android.settings.wifi.WifiInfo;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800143import com.android.settings.wifi.WifiSettings;
144import com.android.settings.wifi.p2p.WifiP2pSettings;
Jason Monk4da79e02015-09-10 10:54:36 -0400145import com.android.settingslib.drawer.DashboardCategory;
Jason Monk4da79e02015-09-10 10:54:36 -0400146import com.android.settingslib.drawer.SettingsDrawerActivity;
Jason Monk7ea14c52016-01-22 14:28:02 -0500147import com.android.settingslib.drawer.Tile;
Jason Monk2ebc8a02015-02-13 15:23:19 -0500148
Doris Ling26bf0032016-06-15 18:16:09 -0700149import java.net.URISyntaxException;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800150import java.util.ArrayList;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800151import java.util.List;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700152import java.util.Set;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800153
Jason Monk4da79e02015-09-10 10:54:36 -0400154public class SettingsActivity extends SettingsDrawerActivity
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800155 implements PreferenceManager.OnPreferenceTreeClickListener,
156 PreferenceFragment.OnPreferenceStartFragmentCallback,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100157 ButtonBarHandler, FragmentManager.OnBackStackChangedListener,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700158 SearchView.OnQueryTextListener, SearchView.OnCloseListener,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100159 MenuItem.OnActionExpandListener {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800160
161 private static final String LOG_TAG = "Settings";
162
Philip P. Moltmannd9779db2016-02-24 12:11:05 -0800163 private static final int LOADER_ID_INDEXABLE_CONTENT_MONITOR = 1;
164
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800165 // Constants for state save/restore
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700166 private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700167 private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
168 private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700169 private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700170 private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800171
172 /**
173 * When starting this activity, the invoking Intent can contain this extra
174 * string to specify which fragment should be initially displayed.
175 * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
176 * will call isValidFragment() to confirm that the fragment class name is valid for this
177 * activity.
178 */
179 public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
180
181 /**
182 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
183 * this extra can also be specified to supply a Bundle of arguments to pass
184 * to that fragment when it is instantiated during the initial creation
185 * of the activity.
186 */
187 public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
188
189 /**
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700190 * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
191 */
192 public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
193
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800194 public static final String BACK_STACK_PREFS = ":settings:prefs";
195
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800196 // extras that allow any preference activity to be launched as part of a wizard
197
198 // show Back and Next buttons? takes boolean parameter
199 // Back will then return RESULT_CANCELED and Next RESULT_OK
200 protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
201
202 // add a Skip button?
203 private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
204
205 // specify custom text for the Back or Next buttons, or cause a button to not appear
206 // at all by setting it to null
207 protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
208 protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
209
210 /**
211 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700212 * 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 -0800213 * that fragment.
214 */
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700215 public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100216 /**
217 * The package name used to resolve the title resource id.
218 */
219 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
220 ":settings:show_fragment_title_res_package_name";
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700221 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
222 ":settings:show_fragment_title_resid";
223 public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
224 ":settings:show_fragment_as_shortcut";
225
226 public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
227 ":settings:show_fragment_as_subsetting";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800228
Udam Saini92779ce2016-03-28 14:29:48 -0700229 public static final String EXTRA_HIDE_DRAWER = ":settings:hide_drawer";
230
Jason Monk30695812015-11-17 09:01:08 -0500231 public static final String META_DATA_KEY_FRAGMENT_CLASS =
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800232 "com.android.settings.FRAGMENT_CLASS";
233
234 private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
235
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700236 private static final String EMPTY_QUERY = "";
237
Jason Monkd4f03ec2016-01-07 16:25:34 -0500238 private static final int REQUEST_SUGGESTION = 42;
239
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800240 private String mFragmentClass;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800241
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800242 private CharSequence mInitialTitle;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700243 private int mInitialTitleResId;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800244
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800245 // Show only these settings for restricted users
Jason Monk4da79e02015-09-10 10:54:36 -0400246 private String[] SETTINGS_FOR_RESTRICTED = {
247 //wireless_section
248 WifiSettingsActivity.class.getName(),
249 Settings.BluetoothSettingsActivity.class.getName(),
250 Settings.DataUsageSummaryActivity.class.getName(),
251 Settings.SimSettingsActivity.class.getName(),
252 Settings.WirelessSettingsActivity.class.getName(),
253 //device_section
254 Settings.HomeSettingsActivity.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500255 Settings.SoundSettingsActivity.class.getName(),
Jason Monk4da79e02015-09-10 10:54:36 -0400256 Settings.DisplaySettingsActivity.class.getName(),
257 Settings.StorageSettingsActivity.class.getName(),
258 Settings.ManageApplicationsActivity.class.getName(),
259 Settings.PowerUsageSummaryActivity.class.getName(),
Doris Ling91365232016-05-23 17:06:26 -0700260 Settings.GestureSettingsActivity.class.getName(),
Jason Monk4da79e02015-09-10 10:54:36 -0400261 //personal_section
262 Settings.LocationSettingsActivity.class.getName(),
263 Settings.SecuritySettingsActivity.class.getName(),
264 Settings.InputMethodAndLanguageSettingsActivity.class.getName(),
265 Settings.UserSettingsActivity.class.getName(),
266 Settings.AccountSettingsActivity.class.getName(),
267 //system_section
268 Settings.DateTimeSettingsActivity.class.getName(),
269 Settings.DeviceInfoSettingsActivity.class.getName(),
270 Settings.AccessibilitySettingsActivity.class.getName(),
271 Settings.PrintSettingsActivity.class.getName(),
272 Settings.PaymentSettingsActivity.class.getName(),
Fan Zhangcc335d92016-09-29 14:37:14 -0700273
274 // New IA
275 // Home page
Fan Zhangbb93dc02016-10-11 16:27:45 -0700276 Settings.NetworkDashboardActivity.class.getName(),
Fan Zhangf37be6a2016-10-20 12:47:52 -0700277 Settings.ConnectedDeviceDashboardActivity.class.getName(),
278 Settings.AppAndNotificationDashboardActivity.class.getName(),
Fan Zhangcc335d92016-09-29 14:37:14 -0700279 "com.android.settings.Settings.BatteryDashboardAlias",
Fan Zhang66b573a2016-10-06 16:33:13 -0700280 "com.android.settings.Settings.DisplayDashboardAlias",
Doris Ling55578652016-10-18 13:08:29 -0700281 "com.android.settings.Settings.SoundDashboardAlias",
Fan Zhang8da6f882016-10-14 14:02:03 -0700282 "com.android.settings.Settings.SecurityDashboardAlias",
Doris Lingd7aae182016-10-21 11:33:54 -0700283 Settings.UserAndAccountDashboardActivity.class.getName(),
Fan Zhangcc335d92016-09-29 14:37:14 -0700284 Settings.SystemDashboardActivity.class.getName(),
285 Settings.SupportDashboardActivity.class.getName(),
Fan Zhangcdacd1d2016-10-20 17:15:50 -0700286 // Home page > Apps & Notifications
287 "com.android.settings.Settings.ManageApplicationsDashboardAlias",
Fan Zhangbb93dc02016-10-11 16:27:45 -0700288 // Home page > Network & Internet
289 "com.android.settings.Settings.WifiDashboardAlias",
290 "com.android.settings.Settings.DataUsageDashboardAlias",
Fan Zhangcc335d92016-09-29 14:37:14 -0700291 // Home page > System
292 "com.android.settings.Settings.LanguageAndInputDashboardAlias",
293 "com.android.settings.Settings.DateTimeDashboardAlias",
294 "com.android.settings.Settings.AccessibilityDashboardAlias",
295 "com.android.settings.Settings.AboutDeviceDashboardAlias",
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800296 };
297
298 private static final String[] ENTRY_FRAGMENTS = {
299 WirelessSettings.class.getName(),
300 WifiSettings.class.getName(),
301 AdvancedWifiSettings.class.getName(),
PauloftheWest7837b992014-06-24 07:42:27 -0700302 SavedAccessPointsWifiSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800303 BluetoothSettings.class.getName(),
PauloftheWest38155612014-06-30 10:02:36 -0700304 SimSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800305 TetherSettings.class.getName(),
306 WifiP2pSettings.class.getName(),
307 VpnSettings.class.getName(),
308 DateTimeSettings.class.getName(),
Mihai Nitad7d48fd2016-01-12 08:55:05 -0800309 LocaleListEditor.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800310 InputMethodAndLanguageSettings.class.getName(),
Abodunrinwa Toki976bb3f2016-01-20 18:43:20 +0000311 AvailableVirtualKeyboardFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800312 SpellCheckersSettings.class.getName(),
313 UserDictionaryList.class.getName(),
314 UserDictionarySettings.class.getName(),
Amith Yamasani3033ce02014-07-14 18:03:15 -0700315 HomeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800316 DisplaySettings.class.getName(),
317 DeviceInfoSettings.class.getName(),
318 ManageApplications.class.getName(),
Jason Monka2d47fc2016-03-03 10:49:44 -0500319 NotificationApps.class.getName(),
Xiyuan Xia86a55402015-06-02 14:55:32 -0700320 ManageAssist.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800321 ProcessStatsUi.class.getName(),
322 NotificationStation.class.getName(),
323 LocationSettings.class.getName(),
324 SecuritySettings.class.getName(),
Jason Monkd8da51c2015-04-17 14:34:12 -0400325 UsageAccessDetails.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800326 PrivacySettings.class.getName(),
327 DeviceAdminSettings.class.getName(),
328 AccessibilitySettings.class.getName(),
Anna Galuszab1795f52016-01-08 14:37:16 -0800329 AccessibilitySettingsForSetupWizard.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800330 CaptionPropertiesFragment.class.getName(),
Fan Zhanga96a2d82016-09-27 17:51:11 -0700331 ToggleDaltonizerPreferenceFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800332 TextToSpeechSettings.class.getName(),
Jeff Sharkey42833b22015-04-11 21:27:33 -0700333 StorageSettings.class.getName(),
Jeff Sharkeya16257d2015-04-28 13:41:01 -0700334 PrivateVolumeForget.class.getName(),
Jeff Sharkeye77f0682015-04-29 11:24:57 -0700335 PrivateVolumeSettings.class.getName(),
336 PublicVolumeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800337 DevelopmentSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800338 AndroidBeam.class.getName(),
339 WifiDisplaySettings.class.getName(),
340 PowerUsageSummary.class.getName(),
341 AccountSyncSettings.class.getName(),
Alexandra Gherghina6d839872014-07-22 12:04:58 +0000342 AccountSettings.class.getName(),
Doris Ling91365232016-05-23 17:06:26 -0700343 GestureSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800344 CryptKeeperSettings.class.getName(),
345 DataUsageSummary.class.getName(),
346 DreamSettings.class.getName(),
347 UserSettings.class.getName(),
348 NotificationAccessSettings.class.getName(),
John Spurlock08531a82015-05-07 17:45:43 -0400349 ZenAccessSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800350 PrintSettingsFragment.class.getName(),
351 PrintJobSettingsFragment.class.getName(),
352 TrustedCredentialsSettings.class.getName(),
353 PaymentSettings.class.getName(),
354 KeyboardLayoutPickerFragment.class.getName(),
Abodunrinwa Toki5f0b59b2016-01-25 23:02:23 +0000355 KeyboardLayoutPickerFragment2.class.getName(),
Abodunrinwa Tokib28b2cc2016-03-22 16:29:38 +0000356 PhysicalKeyboardFragment.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700357 ZenModeSettings.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500358 SoundSettings.class.getName(),
359 ConfigureNotificationSettings.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700360 ChooseLockPassword.ChooseLockPasswordFragment.class.getName(),
361 ChooseLockPattern.ChooseLockPatternFragment.class.getName(),
John Spurlockc7f8e8c2014-06-04 19:11:22 -0400362 InstalledAppDetails.class.getName(),
363 BatterySaverSettings.class.getName(),
Fabrice Di Megliodcf59dd2014-07-21 11:22:20 -0700364 AppNotificationSettings.class.getName(),
Fabrice Di Meglioe3ff4d82014-07-23 20:03:20 -0700365 OtherSoundSettings.class.getName(),
Narayan Kamath33acb152015-03-16 12:48:05 +0000366 ApnSettings.class.getName(),
Jason Monkb7e43802016-06-06 16:01:58 -0400367 ApnEditor.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400368 WifiCallingSettings.class.getName(),
John Spurlockc1df2aa2015-04-13 20:57:06 -0400369 ZenModePrioritySettings.class.getName(),
John Spurlock533a5662015-06-19 10:47:36 -0400370 ZenModeAutomationSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400371 ZenModeScheduleRuleSettings.class.getName(),
John Spurlockf57bad72015-04-30 09:26:15 -0400372 ZenModeEventRuleSettings.class.getName(),
Julia Reynolds5555d262015-11-09 10:52:17 -0500373 ZenModeVisualInterruptionSettings.class.getName(),
Jason Monk2583fc12015-03-25 09:46:30 -0400374 ProcessStatsUi.class.getName(),
Jason Monk1eb54eb2015-04-29 12:46:42 -0400375 PowerUsageDetail.class.getName(),
Jason Monk2cdafc62015-06-12 12:32:50 -0400376 ProcessStatsSummary.class.getName(),
Billy Laufee78562015-07-27 12:57:07 +0100377 DrawOverlayDetails.class.getName(),
378 WriteSettingsDetails.class.getName(),
Jason Monk91e2f892016-02-23 15:31:09 -0500379 AdvancedAppSettings.class.getName(),
Jason Monkb9e5d232016-01-26 17:43:57 -0500380 WallpaperTypeSettings.class.getName(),
Ruben Brunkc461d5c2016-04-07 21:45:41 -0700381 VrListenerSettings.class.getName(),
Tony Mak64f6d982016-05-03 18:55:41 +0100382 ManagedProfileSettings.class.getName(),
Jason Monkb7e43802016-06-06 16:01:58 -0400383 ChooseAccountActivity.class.getName(),
384 IccLockSettings.class.getName(),
385 ImeiInformation.class.getName(),
386 SimStatus.class.getName(),
387 Status.class.getName(),
388 TestingSettings.class.getName(),
389 WifiAPITest.class.getName(),
390 WifiInfo.class.getName(),
Doris Ling7d73a292016-06-21 18:08:22 -0700391 MasterClear.class.getName(),
Justin Klaasseneae3d9f2016-07-21 19:25:17 -0700392 NightDisplaySettings.class.getName(),
Todd Kennedy2ef1aa52016-09-06 14:02:38 -0700393 ManageDomainUrls.class.getName(),
Fan Zhanga96a2d82016-09-27 17:51:11 -0700394 AutomaticStorageManagerSettings.class.getName(),
Fan Zhangcc335d92016-09-29 14:37:14 -0700395 SupportFragment.class.getName(),
Fan Zhangbb6d2602016-10-04 13:21:06 -0700396 StorageDashboardFragment.class.getName(),
Fan Zhangcc335d92016-09-29 14:37:14 -0700397 SystemDashboardFragment.class.getName(),
Fan Zhangbb93dc02016-10-11 16:27:45 -0700398 NetworkDashboardFragment.class.getName(),
Doris Lingb2c8c9c2016-10-10 16:59:16 -0700399 ConnectedDeviceDashboardFragment.class.getName(),
Fan Zhangf37be6a2016-10-20 12:47:52 -0700400 AppAndNotificationDashboardFragment.class.getName(),
Doris Lingd7aae182016-10-21 11:33:54 -0700401 UserAndAccountDashboardFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800402 };
403
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700404
405 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
406 "android.settings.APPLICATION_DETAILS_SETTINGS"
407 };
408
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800409 private SharedPreferences mDevelopmentPreferences;
410 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
411
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800412 private boolean mBatteryPresent = true;
413 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800414 @Override
415 public void onReceive(Context context, Intent intent) {
416 String action = intent.getAction();
417 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
418 boolean batteryPresent = Utils.isBatteryPresent(intent);
419
420 if (mBatteryPresent != batteryPresent) {
421 mBatteryPresent = batteryPresent;
Jason Monk4da79e02015-09-10 10:54:36 -0400422 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800423 }
424 }
425 }
426 };
427
Clara Bayarri6934a042015-10-14 11:07:35 +0100428 private final BroadcastReceiver mUserAddRemoveReceiver = new BroadcastReceiver() {
429 @Override
430 public void onReceive(Context context, Intent intent) {
431 String action = intent.getAction();
432 if (action.equals(Intent.ACTION_USER_ADDED)
433 || action.equals(Intent.ACTION_USER_REMOVED)) {
434 Index.getInstance(getApplicationContext()).update();
435 }
436 }
437 };
438
Svetoslav990159a2014-04-14 17:14:59 -0700439 private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor =
440 new DynamicIndexableContentMonitor();
Svetoslav853e4712014-04-14 10:10:25 -0700441
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700442 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700443 private SwitchBar mSwitchBar;
444
445 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700446
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700447 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700448 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700449
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700450 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700451 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700452
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700453 private ViewGroup mContent;
454
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700455 private SearchView mSearchView;
456 private MenuItem mSearchMenuItem;
457 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700458 private SearchResultsSummary mSearchResultsFragment;
459 private String mSearchQuery;
460
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700461 // Categories
462 private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800463
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700464 private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800465
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700466 private boolean mNeedToRevertToInitialFragment = false;
467
Fan Zhanga96a2d82016-09-27 17:51:11 -0700468 private DashboardFeatureProvider mDashboardFeatureProvider;
Jim Miller0698a212014-10-16 19:49:07 -0700469 private Intent mResultIntentData;
Jason Monkd4f03ec2016-01-07 16:25:34 -0500470 private ComponentName mCurrentSuggestion;
Jim Miller0698a212014-10-16 19:49:07 -0700471
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700472 public SwitchBar getSwitchBar() {
473 return mSwitchBar;
474 }
475
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800476 @Override
477 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
Sunny Goyal21ef89f2016-05-25 12:41:16 -0700478 startPreferencePanel(pref.getFragment(), pref.getExtras(), -1, pref.getTitle(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800479 null, 0);
480 return true;
481 }
482
483 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400484 public boolean onPreferenceTreeClick(Preference preference) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800485 return false;
486 }
487
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800488 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800489 public void onConfigurationChanged(Configuration newConfig) {
490 super.onConfigurationChanged(newConfig);
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800491 Index.getInstance(this).update();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800492 }
493
494 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700495 protected void onStart() {
496 super.onStart();
497
498 if (mNeedToRevertToInitialFragment) {
499 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800500 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800501 }
502
503 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700504 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700505 if (!mDisplaySearch) {
506 return false;
507 }
508
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700509 MenuInflater inflater = getMenuInflater();
510 inflater.inflate(R.menu.options_menu, menu);
511
512 // Cache the search query (can be overriden by the OnQueryTextListener)
513 final String query = mSearchQuery;
514
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700515 mSearchMenuItem = menu.findItem(R.id.search);
516 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700517
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700518 if (mSearchMenuItem == null || mSearchView == null) {
519 return false;
520 }
521
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700522 if (mSearchResultsFragment != null) {
523 mSearchResultsFragment.setSearchView(mSearchView);
524 }
525
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700526 mSearchMenuItem.setOnActionExpandListener(this);
Fan Zhangb9239182016-08-22 13:59:59 -0700527 mSearchView.setMaxWidth(Integer.MAX_VALUE);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700528 mSearchView.setOnQueryTextListener(this);
529 mSearchView.setOnCloseListener(this);
530
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700531 if (mSearchMenuItemExpanded) {
532 mSearchMenuItem.expandActionView();
533 }
534 mSearchView.setQuery(query, true /* submit */);
535
536 return true;
537 }
538
Jason Monk31c7c322016-01-20 14:41:52 -0500539 @Override
540 public SharedPreferences getSharedPreferences(String name, int mode) {
541 if (name.equals(getPackageName() + "_preferences")) {
Jason Monke4ebcd12016-02-21 09:37:41 -0500542 return new SharedPreferencesLogger(this, getMetricsTag());
Jason Monk31c7c322016-01-20 14:41:52 -0500543 }
544 return super.getSharedPreferences(name, mode);
545 }
546
Jason Monke4ebcd12016-02-21 09:37:41 -0500547 private String getMetricsTag() {
548 String tag = getClass().getName();
549 if (getIntent() != null && getIntent().hasExtra(EXTRA_SHOW_FRAGMENT)) {
550 tag = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
551 }
552 if (tag.startsWith("com.android.settings.")) {
553 tag = tag.replace("com.android.settings.", "");
554 }
555 return tag;
556 }
557
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700558 private static boolean isShortCutIntent(final Intent intent) {
559 Set<String> categories = intent.getCategories();
560 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
561 }
562
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700563 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700564 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700565 if (action == null) {
566 return false;
567 }
568 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
569 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
570 }
571 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700572 }
573
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700574 @Override
575 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700576 super.onCreate(savedState);
Jason Monkfd2c7222015-12-02 15:38:38 -0500577 long startTime = System.currentTimeMillis();
Fan Zhanga96a2d82016-09-27 17:51:11 -0700578 mDashboardFeatureProvider =
579 FeatureFactory.getFactory(this).getDashboardFeatureProvider(this);
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700580 // Should happen before any call to getIntent()
581 getMetaData();
582
583 final Intent intent = getIntent();
584 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
585 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800586 }
Udam Saini92779ce2016-03-28 14:29:48 -0700587 if (intent.getBooleanExtra(EXTRA_HIDE_DRAWER, false)) {
588 setIsDrawerPresent(false);
589 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800590
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800591 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
592 Context.MODE_PRIVATE);
593
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700594 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700595 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700596
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700597 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700598 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
599
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700600 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700601 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700602
Jason Monk4da79e02015-09-10 10:54:36 -0400603 mIsShowingDashboard = className.equals(Settings.class.getName())
604 || className.equals(Settings.WirelessSettings.class.getName())
605 || className.equals(Settings.DeviceSettings.class.getName())
606 || className.equals(Settings.PersonalSettings.class.getName())
607 || className.equals(Settings.WirelessSettings.class.getName());
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700608
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700609 // This is a "Sub Settings" when:
610 // - this is a real SubSettings
611 // - or :settings:show_fragment_as_subsetting is passed to the Intent
Jorim Jaggi4dfcb822015-04-29 17:21:32 -0700612 final boolean isSubSettings = this instanceof SubSettings ||
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700613 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
614
615 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
616 if (isSubSettings) {
Fabrice Di Meglio712df6c2014-07-18 17:44:37 -0700617 // Check also that we are not a Theme Dialog as we don't want to override them
618 final int themeResId = getThemeResId();
619 if (themeResId != R.style.Theme_DialogWhenLarge &&
620 themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
621 setTheme(R.style.Theme_SubSettings);
622 }
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700623 }
624
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700625 setContentView(mIsShowingDashboard ?
626 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800627
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700628 mContent = (ViewGroup) findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700629
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800630 getFragmentManager().addOnBackStackChangedListener(this);
631
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700632 if (mIsShowingDashboard) {
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800633 // Run the Index update only if we have some space
634 if (!Utils.isLowStorage(this)) {
Jason Monkfd2c7222015-12-02 15:38:38 -0500635 long indexStartTime = System.currentTimeMillis();
Jason Monk6c9e8842016-04-14 14:34:16 -0400636 Index.getInstance(getApplicationContext()).update();
Jason Monkfd2c7222015-12-02 15:38:38 -0500637 if (DEBUG_TIMING) Log.d(LOG_TAG, "Index.update() took "
638 + (System.currentTimeMillis() - indexStartTime) + " ms");
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800639 } else {
640 Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
641 }
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700642 }
643
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700644 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700645 // We are restarting from a previous saved state; used that to initialize, instead
646 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700647 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
648 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700649 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800650
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700651 ArrayList<DashboardCategory> categories =
652 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
653 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700654 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700655 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700656 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800657 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700658
659 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700660 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Salvador Martinez2368e542016-07-25 18:16:47 -0700661
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800662 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700663 if (!mIsShowingDashboard) {
Jason Monkea8b1a72015-06-02 16:46:34 -0400664 mDisplaySearch = false;
665 // UP will be shown only if it is a sub settings
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700666 if (mIsShortcut) {
667 mDisplayHomeAsUpEnabled = isSubSettings;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700668 } else if (isSubSettings) {
669 mDisplayHomeAsUpEnabled = true;
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700670 } else {
671 mDisplayHomeAsUpEnabled = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700672 }
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700673 setTitleFromIntent(intent);
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700674
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700675 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700676 switchToFragment(initialFragmentName, initialArguments, true, false,
677 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000678 } else {
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700679 // No UP affordance if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700680 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700681 // Show Search affordance
682 mDisplaySearch = true;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700683 mInitialTitleResId = R.string.dashboard_title;
Salvador Martinez2368e542016-07-25 18:16:47 -0700684
685 // add argument to indicate which settings tab should be initially selected
686 final Bundle args = new Bundle();
687 final String extraName = DashboardContainerFragment.EXTRA_SELECT_SETTINGS_TAB;
688 args.putString(extraName, intent.getStringExtra(extraName));
Fan Zhanga96a2d82016-09-27 17:51:11 -0700689 if (isDashboardFeatureEnabled()) {
690 switchToFragment(DashboardSummary.class.getName(), args, false, false,
691 mInitialTitleResId, mInitialTitle, false);
692 } else {
693 switchToFragment(DashboardContainerFragment.class.getName(), args, false, false,
694 mInitialTitleResId, mInitialTitle, false);
695 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800696 }
697 }
698
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700699 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700700 if (mActionBar != null) {
701 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
702 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
703 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700704 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
Jason Monke4ebcd12016-02-21 09:37:41 -0500705 if (mSwitchBar != null) {
706 mSwitchBar.setMetricsTag(getMetricsTag());
707 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700708
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800709 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800710 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
711
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700712 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800713 if (buttonBar != null) {
714 buttonBar.setVisibility(View.VISIBLE);
715
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700716 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800717 backButton.setOnClickListener(new OnClickListener() {
718 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700719 setResult(RESULT_CANCELED, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800720 finish();
721 }
722 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700723 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800724 skipButton.setOnClickListener(new OnClickListener() {
725 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700726 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800727 finish();
728 }
729 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700730 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800731 mNextButton.setOnClickListener(new OnClickListener() {
732 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700733 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800734 finish();
735 }
736 });
737
738 // set our various button parameters
739 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
740 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
741 if (TextUtils.isEmpty(buttonText)) {
742 mNextButton.setVisibility(View.GONE);
743 }
744 else {
745 mNextButton.setText(buttonText);
746 }
747 }
748 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
749 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
750 if (TextUtils.isEmpty(buttonText)) {
751 backButton.setVisibility(View.GONE);
752 }
753 else {
754 backButton.setText(buttonText);
755 }
756 }
757 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
758 skipButton.setVisibility(View.VISIBLE);
759 }
760 }
761 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700762
Jason Monkfd2c7222015-12-02 15:38:38 -0500763 if (DEBUG_TIMING) Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
764 + " ms");
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700765 }
766
Fan Zhangece8ff62016-06-30 13:20:12 -0700767 public void setDisplaySearchMenu(boolean displaySearch) {
768 if (displaySearch != mDisplaySearch) {
769 mDisplaySearch = displaySearch;
770 invalidateOptionsMenu();
771 }
772 }
773
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700774 private void setTitleFromIntent(Intent intent) {
775 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
776 if (initialTitleResId > 0) {
777 mInitialTitle = null;
778 mInitialTitleResId = initialTitleResId;
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100779
780 final String initialTitleResPackageName = intent.getStringExtra(
781 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
782 if (initialTitleResPackageName != null) {
783 try {
784 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
785 0 /* flags */, new UserHandle(UserHandle.myUserId()));
786 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
787 setTitle(mInitialTitle);
788 mInitialTitleResId = -1;
789 return;
790 } catch (NameNotFoundException e) {
791 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
792 }
793 } else {
794 setTitle(mInitialTitleResId);
795 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700796 } else {
797 mInitialTitleResId = -1;
798 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
799 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
800 setTitle(mInitialTitle);
801 }
802 }
803
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800804 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800805 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700806 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800807 }
808
Fan Zhang28691572016-03-23 15:31:08 -0700809 private void setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800810 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700811
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800812 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700813 if (mInitialTitleResId > 0) {
814 setTitle(mInitialTitleResId);
815 } else {
816 setTitle(mInitialTitle);
817 }
Fan Zhang28691572016-03-23 15:31:08 -0700818 return;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800819 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700820
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800821 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
822 setTitleFromBackStackEntry(bse);
823 }
824
825 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
826 final CharSequence title;
827 final int titleRes = bse.getBreadCrumbTitleRes();
828 if (titleRes > 0) {
829 title = getText(titleRes);
830 } else {
831 title = bse.getBreadCrumbTitle();
832 }
833 if (title != null) {
834 setTitle(title);
835 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800836 }
837
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800838 @Override
839 protected void onSaveInstanceState(Bundle outState) {
840 super.onSaveInstanceState(outState);
841
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700842 if (mCategories.size() > 0) {
843 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800844 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700845
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700846 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700847 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700848
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700849 if (mDisplaySearch) {
850 // The option menus are created if the ActionBar is visible and they are also created
851 // asynchronously. If you launch Settings with an Intent action like
852 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
853 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
854 // menu item and search view are null.
855 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
856 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700857
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700858 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
859 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
860 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800861 }
862
863 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400864 protected void onResume() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800865 super.onResume();
866
867 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
868 @Override
869 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Jason Monk4da79e02015-09-10 10:54:36 -0400870 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800871 }
872 };
873 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
874 mDevelopmentPreferencesListener);
875
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800876 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Clara Bayarri6934a042015-10-14 11:07:35 +0100877 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_ADDED));
878 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_REMOVED));
Svetoslav853e4712014-04-14 10:10:25 -0700879
Philip P. Moltmannd9779db2016-02-24 12:11:05 -0800880 mDynamicIndexableContentMonitor.register(this, LOADER_ID_INDEXABLE_CONTENT_MONITOR);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700881
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700882 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700883 onQueryTextSubmit(mSearchQuery);
884 }
Jason Monk4da79e02015-09-10 10:54:36 -0400885 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800886 }
887
888 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400889 protected void onPause() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800890 super.onPause();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800891 unregisterReceiver(mBatteryInfoReceiver);
Clara Bayarri8c9521f2016-01-12 14:10:45 +0000892 unregisterReceiver(mUserAddRemoveReceiver);
Svetoslav990159a2014-04-14 17:14:59 -0700893 mDynamicIndexableContentMonitor.unregister();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800894 }
895
896 @Override
897 public void onDestroy() {
898 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700899
900 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
901 mDevelopmentPreferencesListener);
902 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800903 }
904
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800905 protected boolean isValidFragment(String fragmentName) {
906 // Almost all fragments are wrapped in this,
907 // except for a few that have their own activities.
908 for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
909 if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
910 }
911 return false;
912 }
913
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800914 @Override
915 public Intent getIntent() {
916 Intent superIntent = super.getIntent();
917 String startingFragment = getStartingFragmentClass(superIntent);
918 // This is called from super.onCreate, isMultiPane() is not yet reliable
919 // Do not use onIsHidingHeaders either, which relies itself on this method
920 if (startingFragment != null) {
921 Intent modIntent = new Intent(superIntent);
922 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
923 Bundle args = superIntent.getExtras();
924 if (args != null) {
925 args = new Bundle(args);
926 } else {
927 args = new Bundle();
928 }
929 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100930 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800931 return modIntent;
932 }
933 return superIntent;
934 }
935
936 /**
937 * Checks if the component name in the intent is different from the Settings class and
938 * returns the class name to load as a fragment.
939 */
940 private String getStartingFragmentClass(Intent intent) {
941 if (mFragmentClass != null) return mFragmentClass;
942
943 String intentClass = intent.getComponent().getClassName();
944 if (intentClass.equals(getClass().getName())) return null;
945
946 if ("com.android.settings.ManageApplications".equals(intentClass)
947 || "com.android.settings.RunningServices".equals(intentClass)
948 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
949 // Old names of manage apps.
950 intentClass = com.android.settings.applications.ManageApplications.class.getName();
951 }
952
953 return intentClass;
954 }
955
956 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000957 * Start a new fragment containing a preference panel. If the preferences
958 * are being displayed in multi-pane mode, the given fragment class will
959 * be instantiated and placed in the appropriate pane. If running in
960 * single-pane mode, a new activity will be launched in which to show the
961 * fragment.
962 *
963 * @param fragmentClass Full name of the class implementing the fragment.
964 * @param args Any desired arguments to supply to the fragment.
965 * @param titleRes Optional resource identifier of the title of this
966 * fragment.
967 * @param titleText Optional text of the title of this fragment.
968 * @param resultTo Optional fragment that result data should be sent to.
969 * If non-null, resultTo.onActivityResult() will be called when this
970 * preference panel is done. The launched panel must use
971 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
972 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700973 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000974 */
975 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700976 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700977 String title = null;
978 if (titleRes < 0) {
979 if (titleText != null) {
980 title = titleText.toString();
981 } else {
982 // There not much we can do in that case
983 title = "";
984 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700985 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700986 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700987 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000988 }
989
990 /**
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100991 * Start a new fragment in a new activity containing a preference panel for a given user. If the
992 * preferences are being displayed in multi-pane mode, the given fragment class will be
993 * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
994 * activity will be launched in which to show the fragment.
995 *
996 * @param fragmentClass Full name of the class implementing the fragment.
997 * @param args Any desired arguments to supply to the fragment.
998 * @param titleRes Optional resource identifier of the title of this fragment.
999 * @param titleText Optional text of the title of this fragment.
1000 * @param userHandle The user for which the panel has to be started.
1001 */
1002 public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
1003 CharSequence titleText, UserHandle userHandle) {
Lifu Tangd0332852015-04-02 12:05:46 -07001004 // This is a workaround.
1005 //
1006 // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
1007 // starting the fragment could cause a native stack corruption. See b/17523189. However,
1008 // adding that flag and start the preference panel with the same UserHandler will make it
1009 // impossible to use back button to return to the previous screen. See b/20042570.
1010 //
1011 // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
1012 // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
1013 // when we're calling it as the same user.
1014 if (userHandle.getIdentifier() == UserHandle.myUserId()) {
1015 startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0);
1016 } else {
1017 String title = null;
1018 if (titleRes < 0) {
1019 if (titleText != null) {
1020 title = titleText.toString();
1021 } else {
1022 // There not much we can do in that case
1023 title = "";
1024 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +01001025 }
Lifu Tangd0332852015-04-02 12:05:46 -07001026 Utils.startWithFragmentAsUser(this, fragmentClass, args,
1027 titleRes, title, mIsShortcut, userHandle);
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +01001028 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +01001029 }
1030
1031 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001032 * Called by a preference panel fragment to finish itself.
1033 *
1034 * @param caller The fragment that is asking to be finished.
1035 * @param resultCode Optional result code to send back to the original
1036 * launching fragment.
1037 * @param resultData Optional result data to send back to the original
1038 * launching fragment.
1039 */
1040 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
1041 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -07001042 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001043 }
1044
1045 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +00001046 * Start a new fragment.
1047 *
1048 * @param fragment The fragment to start
1049 * @param push If true, the current fragment will be pushed onto the back stack. If false,
1050 * the current fragment will be replaced.
1051 */
1052 public void startPreferenceFragment(Fragment fragment, boolean push) {
1053 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Anna Galusza6b1e9db2016-03-30 17:25:36 -07001054 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +00001055 if (push) {
1056 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
1057 transaction.addToBackStack(BACK_STACK_PREFS);
1058 } else {
1059 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
1060 }
1061 transaction.commitAllowingStateLoss();
1062 }
1063
1064 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001065 * Switch to a specific Fragment with taking care of validation, Title and BackStack
1066 */
1067 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001068 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001069 if (validate && !isValidFragment(fragmentName)) {
1070 throw new IllegalArgumentException("Invalid fragment for this activity: "
1071 + fragmentName);
1072 }
1073 Fragment f = Fragment.instantiate(this, fragmentName, args);
1074 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Anna Galusza6b1e9db2016-03-30 17:25:36 -07001075 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001076 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -07001077 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001078 }
1079 if (addToBackStack) {
1080 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
1081 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001082 if (titleResId > 0) {
1083 transaction.setBreadCrumbTitle(titleResId);
1084 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001085 transaction.setBreadCrumbTitle(title);
1086 }
1087 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -07001088 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001089 return f;
1090 }
1091
Jason Monk4da79e02015-09-10 10:54:36 -04001092 private void updateTilesList() {
Jason Monkfd2c7222015-12-02 15:38:38 -05001093 // Generally the items that are will be changing from these updates will
1094 // not be in the top list of tiles, so run it in the background and the
1095 // SettingsDrawerActivity will pick up on the updates automatically.
1096 AsyncTask.execute(new Runnable() {
1097 @Override
1098 public void run() {
1099 doUpdateTilesList();
1100 }
1101 });
1102 }
1103
1104 private void doUpdateTilesList() {
Jason Monk4da79e02015-09-10 10:54:36 -04001105 PackageManager pm = getPackageManager();
Xiaohui Chen44879a32015-07-22 13:53:22 -07001106 final UserManager um = UserManager.get(this);
1107 final boolean isAdmin = um.isAdminUser();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001108
Jason Monk4da79e02015-09-10 10:54:36 -04001109 String packageName = getPackageName();
1110 setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()),
1111 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001112
Jason Monk4da79e02015-09-10 10:54:36 -04001113 setTileEnabled(new ComponentName(packageName,
1114 Settings.BluetoothSettingsActivity.class.getName()),
1115 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001116
Jason Monk4da79e02015-09-10 10:54:36 -04001117 setTileEnabled(new ComponentName(packageName,
1118 Settings.DataUsageSummaryActivity.class.getName()),
1119 Utils.isBandwidthControlEnabled(), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001120
Jason Monk4da79e02015-09-10 10:54:36 -04001121 setTileEnabled(new ComponentName(packageName,
1122 Settings.SimSettingsActivity.class.getName()),
1123 Utils.showSimCardTile(this), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001124
Jason Monk4da79e02015-09-10 10:54:36 -04001125 setTileEnabled(new ComponentName(packageName,
1126 Settings.PowerUsageSummaryActivity.class.getName()),
1127 mBatteryPresent, isAdmin, pm);
1128
1129 setTileEnabled(new ComponentName(packageName,
Jason Monk4da79e02015-09-10 10:54:36 -04001130 Settings.UserSettingsActivity.class.getName()),
1131 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
1132 && !Utils.isMonkeyRunning(), isAdmin, pm);
1133
Fyodor Kupolovca060e32016-06-24 13:01:11 -07001134 setTileEnabled(new ComponentName(packageName,
1135 Settings.WirelessSettingsActivity.class.getName()),
1136 !UserManager.isDeviceInDemoMode(this), isAdmin, pm);
1137
1138 setTileEnabled(new ComponentName(packageName,
1139 Settings.DateTimeSettingsActivity.class.getName()),
1140 !UserManager.isDeviceInDemoMode(this), isAdmin, pm);
Jason Monk4da79e02015-09-10 10:54:36 -04001141 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
1142 setTileEnabled(new ComponentName(packageName,
1143 Settings.PaymentSettingsActivity.class.getName()),
1144 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
1145 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
1146 && adapter != null && adapter.isEnabled(), isAdmin, pm);
1147
1148 setTileEnabled(new ComponentName(packageName,
1149 Settings.PrintSettingsActivity.class.getName()),
1150 pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin, pm);
1151
1152 final boolean showDev = mDevelopmentPreferences.getBoolean(
Dan Sandler12c4ba42016-03-28 11:13:40 -04001153 DevelopmentSettings.PREF_SHOW, android.os.Build.TYPE.equals("eng"))
1154 && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES);
Jason Monk4da79e02015-09-10 10:54:36 -04001155 setTileEnabled(new ComponentName(packageName,
1156 Settings.DevelopmentSettingsActivity.class.getName()),
Dan Sandler12c4ba42016-03-28 11:13:40 -04001157 showDev, isAdmin, pm);
Fan Zhangcc335d92016-09-29 14:37:14 -07001158 setTileEnabled(new ComponentName(packageName,
1159 Settings.DevelopmentSettingsActivity.DASHBOARD_ALIAS),
1160 showDev, isAdmin, pm);
Dan Sandler12c4ba42016-03-28 11:13:40 -04001161
1162 // Reveal development-only quick settings tiles
1163 DevelopmentTiles.setTilesEnabled(this, showDev);
Jason Monk4da79e02015-09-10 10:54:36 -04001164
1165 if (UserHandle.MU_ENABLED && !isAdmin) {
1166 // When on restricted users, disable all extra categories (but only the settings ones).
Fan Zhanga96a2d82016-09-27 17:51:11 -07001167 List<DashboardCategory> categories;
1168 if (isDashboardFeatureEnabled()) {
1169 categories = mDashboardFeatureProvider.getAllCategories();
1170 } else {
1171 categories = getDashboardCategories();
1172 }
1173
Jason Monk4da79e02015-09-10 10:54:36 -04001174 for (DashboardCategory category : categories) {
Jason Monkd4f03ec2016-01-07 16:25:34 -05001175 for (Tile tile : category.tiles) {
Jason Monk4da79e02015-09-10 10:54:36 -04001176 ComponentName component = tile.intent.getComponent();
Jason Monk5862c1e2016-06-07 14:02:33 -04001177 if (packageName.equals(component.getPackageName()) && !ArrayUtils.contains(
Jason Monk4da79e02015-09-10 10:54:36 -04001178 SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1179 setTileEnabled(component, false, isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001180 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001181 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001182 }
1183 }
Doris Ling26bf0032016-06-15 18:16:09 -07001184
1185 String backupIntent = getResources().getString(R.string.config_backup_settings_intent);
1186 boolean useDefaultBackup = TextUtils.isEmpty(backupIntent);
1187 setTileEnabled(new ComponentName(packageName,
1188 Settings.PrivacySettingsActivity.class.getName()), useDefaultBackup, isAdmin, pm);
1189 boolean hasBackupActivity = false;
1190 if (!useDefaultBackup) {
1191 try {
1192 Intent intent = Intent.parseUri(backupIntent, 0);
1193 hasBackupActivity = !getPackageManager().queryIntentActivities(intent, 0).isEmpty();
1194 } catch (URISyntaxException e) {
1195 Log.e(LOG_TAG, "Invalid backup intent URI!", e);
1196 }
1197 }
1198 setTileEnabled(new ComponentName(packageName,
1199 BackupSettingsActivity.class.getName()), hasBackupActivity, isAdmin, pm);
1200
Jason Monk2ebc8a02015-02-13 15:23:19 -05001201 }
1202
Jason Monk4da79e02015-09-10 10:54:36 -04001203 private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin,
1204 PackageManager pm) {
Jason Monk5862c1e2016-06-07 14:02:33 -04001205 if (UserHandle.MU_ENABLED && !isAdmin && getPackageName().equals(component.getPackageName())
Jason Monk4da79e02015-09-10 10:54:36 -04001206 && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1207 enabled = false;
1208 }
Jason Monk5862c1e2016-06-07 14:02:33 -04001209 setTileEnabled(component, enabled);
Jason Monk2ebc8a02015-02-13 15:23:19 -05001210 }
1211
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001212 private void getMetaData() {
1213 try {
1214 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1215 PackageManager.GET_META_DATA);
1216 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001217 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1218 } catch (NameNotFoundException nnfe) {
1219 // No recovery
1220 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1221 }
1222 }
1223
Fan Zhanga96a2d82016-09-27 17:51:11 -07001224 @Override
1225 protected boolean isDashboardFeatureEnabled() {
1226 if (mDashboardFeatureProvider == null) {
1227 mDashboardFeatureProvider =
1228 FeatureFactory.getFactory(this).getDashboardFeatureProvider(this);
1229 }
1230 return mDashboardFeatureProvider.isEnabled();
1231 }
1232
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001233 // give subclasses access to the Next button
1234 public boolean hasNextButton() {
1235 return mNextButton != null;
1236 }
1237
1238 public Button getNextButton() {
1239 return mNextButton;
1240 }
1241
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001242 @Override
1243 public boolean shouldUpRecreateTask(Intent targetIntent) {
1244 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1245 }
1246
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001247 @Override
1248 public boolean onQueryTextSubmit(String query) {
1249 switchToSearchResultsFragmentIfNeeded();
1250 mSearchQuery = query;
1251 return mSearchResultsFragment.onQueryTextSubmit(query);
1252 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001253
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001254 @Override
1255 public boolean onQueryTextChange(String newText) {
1256 mSearchQuery = newText;
Fabrice Di Meglio7e4855e2014-05-23 16:03:43 -07001257 if (mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001258 return false;
1259 }
1260 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001261 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001262
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001263 @Override
1264 public boolean onClose() {
1265 return false;
1266 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001267
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001268 @Override
1269 public boolean onMenuItemActionExpand(MenuItem item) {
1270 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001271 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001272 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001273 return true;
1274 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001275
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001276 @Override
1277 public boolean onMenuItemActionCollapse(MenuItem item) {
1278 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001279 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001280 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001281 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001282 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001283 return true;
1284 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001285
Jason Monk4da79e02015-09-10 10:54:36 -04001286 @Override
Jason Monkd4f03ec2016-01-07 16:25:34 -05001287 protected void onTileClicked(Tile tile) {
Jason Monk4da79e02015-09-10 10:54:36 -04001288 if (mIsShowingDashboard) {
1289 // If on dashboard, don't finish so the back comes back to here.
1290 openTile(tile);
1291 } else {
1292 super.onTileClicked(tile);
1293 }
1294 }
1295
Jason Monkaf001092015-11-04 13:16:18 -05001296 @Override
1297 public void onProfileTileOpen() {
1298 if (!mIsShowingDashboard) {
1299 finish();
1300 }
1301 }
1302
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001303 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001304 if (mSearchResultsFragment != null) {
1305 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001306 }
Anna Galusza6b1e9db2016-03-30 17:25:36 -07001307 Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001308 if (current != null && current instanceof SearchResultsSummary) {
1309 mSearchResultsFragment = (SearchResultsSummary) current;
1310 } else {
Fan Zhang28691572016-03-23 15:31:08 -07001311 setContentHeaderView(null);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001312 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001313 SearchResultsSummary.class.getName(), null, false, true,
1314 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001315 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001316 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001317 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001318 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001319
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001320 public void needToRevertToInitialFragment() {
1321 mNeedToRevertToInitialFragment = true;
1322 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001323
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001324 private void revertToInitialFragment() {
1325 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001326 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001327 mSearchMenuItemExpanded = false;
1328 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1329 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001330 if (mSearchMenuItem != null) {
1331 mSearchMenuItem.collapseActionView();
1332 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001333 }
Jim Miller0698a212014-10-16 19:49:07 -07001334
1335 public Intent getResultIntentData() {
1336 return mResultIntentData;
1337 }
1338
1339 public void setResultIntentData(Intent resultIntentData) {
1340 mResultIntentData = resultIntentData;
1341 }
Jason Monkd4f03ec2016-01-07 16:25:34 -05001342
1343 public void startSuggestion(Intent intent) {
Matthew Fritze7ac78f22016-10-03 13:26:07 -07001344 if (intent == null || ActivityManager.isUserAMonkey()) {
Matthew Fritze703dc602016-09-30 12:36:27 -07001345 return;
1346 }
Matthew Fritzef265dbc2016-10-04 13:39:27 -07001347 mCurrentSuggestion = intent.getComponent();
Jason Monkd4f03ec2016-01-07 16:25:34 -05001348 startActivityForResult(intent, REQUEST_SUGGESTION);
1349 }
1350
1351 @Override
1352 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
1353 if (requestCode == REQUEST_SUGGESTION && mCurrentSuggestion != null
1354 && resultCode != RESULT_CANCELED) {
1355 getPackageManager().setComponentEnabledSetting(mCurrentSuggestion,
1356 PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
1357 }
1358 super.onActivityResult(requestCode, resultCode, data);
1359 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001360}