blob: 9a9dfee3f568e173b3d7f73c63c8f69ea03943b5 [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;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080052import com.android.internal.util.ArrayUtils;
Jason Monk4da79e02015-09-10 10:54:36 -040053import com.android.settings.Settings.WifiSettingsActivity;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080054import com.android.settings.accessibility.AccessibilitySettings;
Anna Galuszab1795f52016-01-08 14:37:16 -080055import com.android.settings.accessibility.AccessibilitySettingsForSetupWizard;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080056import com.android.settings.accessibility.CaptionPropertiesFragment;
Alexandra Gherghina6d839872014-07-22 12:04:58 +000057import com.android.settings.accounts.AccountSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080058import com.android.settings.accounts.AccountSyncSettings;
Tony Mak64f6d982016-05-03 18:55:41 +010059import com.android.settings.accounts.ManagedProfileSettings;
Jason Monk91e2f892016-02-23 15:31:09 -050060import com.android.settings.applications.AdvancedAppSettings;
Billy Laufee78562015-07-27 12:57:07 +010061import com.android.settings.applications.DrawOverlayDetails;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070062import com.android.settings.applications.InstalledAppDetails;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080063import com.android.settings.applications.ManageApplications;
Xiyuan Xia86a55402015-06-02 14:55:32 -070064import com.android.settings.applications.ManageAssist;
Jason Monka2d47fc2016-03-03 10:49:44 -050065import com.android.settings.applications.NotificationApps;
Jason Monk2cdafc62015-06-12 12:32:50 -040066import com.android.settings.applications.ProcessStatsSummary;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080067import com.android.settings.applications.ProcessStatsUi;
Jason Monkd8da51c2015-04-17 14:34:12 -040068import com.android.settings.applications.UsageAccessDetails;
Billy Laufee78562015-07-27 12:57:07 +010069import com.android.settings.applications.WriteSettingsDetails;
Ruben Brunkc461d5c2016-04-07 21:45:41 -070070import com.android.settings.applications.VrListenerSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080071import com.android.settings.bluetooth.BluetoothSettings;
72import com.android.settings.dashboard.DashboardSummary;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070073import com.android.settings.dashboard.SearchResultsSummary;
Jason Monkb37e2882016-01-11 14:27:20 -050074import com.android.settings.datausage.DataUsageSummary;
Jeff Sharkeya16257d2015-04-28 13:41:01 -070075import com.android.settings.deviceinfo.PrivateVolumeForget;
Jeff Sharkeye77f0682015-04-29 11:24:57 -070076import com.android.settings.deviceinfo.PrivateVolumeSettings;
Jeff Sharkey42833b22015-04-11 21:27:33 -070077import com.android.settings.deviceinfo.PublicVolumeSettings;
78import com.android.settings.deviceinfo.StorageSettings;
John Spurlockc7f8e8c2014-06-04 19:11:22 -040079import com.android.settings.fuelgauge.BatterySaverSettings;
Jason Monk1eb54eb2015-04-29 12:46:42 -040080import com.android.settings.fuelgauge.PowerUsageDetail;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080081import com.android.settings.fuelgauge.PowerUsageSummary;
Abodunrinwa Toki976bb3f2016-01-20 18:43:20 +000082import com.android.settings.inputmethod.AvailableVirtualKeyboardFragment;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080083import com.android.settings.inputmethod.InputMethodAndLanguageSettings;
84import com.android.settings.inputmethod.KeyboardLayoutPickerFragment;
Abodunrinwa Toki5f0b59b2016-01-25 23:02:23 +000085import com.android.settings.inputmethod.KeyboardLayoutPickerFragment2;
Abodunrinwa Tokib28b2cc2016-03-22 16:29:38 +000086import com.android.settings.inputmethod.PhysicalKeyboardFragment;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080087import com.android.settings.inputmethod.SpellCheckersSettings;
88import com.android.settings.inputmethod.UserDictionaryList;
Mihai Nitad7d48fd2016-01-12 08:55:05 -080089import com.android.settings.localepicker.LocaleListEditor;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080090import com.android.settings.location.LocationSettings;
91import com.android.settings.nfc.AndroidBeam;
92import com.android.settings.nfc.PaymentSettings;
John Spurlock802ddf92014-07-18 11:51:13 -040093import com.android.settings.notification.AppNotificationSettings;
Julia Reynolds8c0a4232015-11-24 10:08:14 -050094import com.android.settings.notification.ConfigureNotificationSettings;
John Spurlock4a350512014-04-08 14:08:21 -040095import com.android.settings.notification.NotificationAccessSettings;
John Spurlock4a350512014-04-08 14:08:21 -040096import com.android.settings.notification.NotificationStation;
Jason Monk2ebc8a02015-02-13 15:23:19 -050097import com.android.settings.notification.OtherSoundSettings;
Jason Monkb37e2882016-01-11 14:27:20 -050098import com.android.settings.notification.SoundSettings;
John Spurlock08531a82015-05-07 17:45:43 -040099import com.android.settings.notification.ZenAccessSettings;
John Spurlock533a5662015-06-19 10:47:36 -0400100import com.android.settings.notification.ZenModeAutomationSettings;
John Spurlockf57bad72015-04-30 09:26:15 -0400101import com.android.settings.notification.ZenModeEventRuleSettings;
John Spurlockc1df2aa2015-04-13 20:57:06 -0400102import com.android.settings.notification.ZenModePrioritySettings;
John Spurlock45fa1402015-04-09 12:50:04 -0400103import com.android.settings.notification.ZenModeScheduleRuleSettings;
Jason Monk39b46742015-09-10 15:52:51 -0400104import com.android.settings.notification.ZenModeSettings;
Julia Reynolds5555d262015-11-09 10:52:17 -0500105import com.android.settings.notification.ZenModeVisualInterruptionSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800106import com.android.settings.print.PrintJobSettingsFragment;
107import com.android.settings.print.PrintSettingsFragment;
Dan Sandler12c4ba42016-03-28 11:13:40 -0400108import com.android.settings.qstile.DevelopmentTiles;
Jason Monk2ebc8a02015-02-13 15:23:19 -0500109import com.android.settings.search.DynamicIndexableContentMonitor;
110import com.android.settings.search.Index;
PauloftheWest38155612014-06-30 10:02:36 -0700111import com.android.settings.sim.SimSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800112import com.android.settings.tts.TextToSpeechSettings;
113import com.android.settings.users.UserSettings;
114import com.android.settings.vpn2.VpnSettings;
115import com.android.settings.wfd.WifiDisplaySettings;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700116import com.android.settings.widget.SwitchBar;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800117import com.android.settings.wifi.AdvancedWifiSettings;
PauloftheWest7837b992014-06-24 07:42:27 -0700118import com.android.settings.wifi.SavedAccessPointsWifiSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800119import com.android.settings.wifi.WifiSettings;
120import com.android.settings.wifi.p2p.WifiP2pSettings;
Jason Monk4da79e02015-09-10 10:54:36 -0400121import com.android.settingslib.drawer.DashboardCategory;
Jason Monk4da79e02015-09-10 10:54:36 -0400122import com.android.settingslib.drawer.SettingsDrawerActivity;
Jason Monk7ea14c52016-01-22 14:28:02 -0500123import com.android.settingslib.drawer.Tile;
Jason Monk2ebc8a02015-02-13 15:23:19 -0500124
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800125import java.util.ArrayList;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800126import java.util.List;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700127import java.util.Set;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800128
Jason Monk4da79e02015-09-10 10:54:36 -0400129public class SettingsActivity extends SettingsDrawerActivity
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800130 implements PreferenceManager.OnPreferenceTreeClickListener,
131 PreferenceFragment.OnPreferenceStartFragmentCallback,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100132 ButtonBarHandler, FragmentManager.OnBackStackChangedListener,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700133 SearchView.OnQueryTextListener, SearchView.OnCloseListener,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100134 MenuItem.OnActionExpandListener {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800135
136 private static final String LOG_TAG = "Settings";
137
Philip P. Moltmannd9779db2016-02-24 12:11:05 -0800138 private static final int LOADER_ID_INDEXABLE_CONTENT_MONITOR = 1;
139
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800140 // Constants for state save/restore
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700141 private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700142 private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
143 private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700144 private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700145 private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700146 private static final String SAVE_KEY_HOME_ACTIVITIES_COUNT = ":settings:home_activities_count";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800147
148 /**
149 * When starting this activity, the invoking Intent can contain this extra
150 * string to specify which fragment should be initially displayed.
151 * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
152 * will call isValidFragment() to confirm that the fragment class name is valid for this
153 * activity.
154 */
155 public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
156
157 /**
158 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
159 * this extra can also be specified to supply a Bundle of arguments to pass
160 * to that fragment when it is instantiated during the initial creation
161 * of the activity.
162 */
163 public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
164
165 /**
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700166 * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
167 */
168 public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
169
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800170 public static final String BACK_STACK_PREFS = ":settings:prefs";
171
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800172 // extras that allow any preference activity to be launched as part of a wizard
173
174 // show Back and Next buttons? takes boolean parameter
175 // Back will then return RESULT_CANCELED and Next RESULT_OK
176 protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
177
178 // add a Skip button?
179 private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
180
181 // specify custom text for the Back or Next buttons, or cause a button to not appear
182 // at all by setting it to null
183 protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
184 protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
185
186 /**
187 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700188 * 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 -0800189 * that fragment.
190 */
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700191 public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100192 /**
193 * The package name used to resolve the title resource id.
194 */
195 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
196 ":settings:show_fragment_title_res_package_name";
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700197 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
198 ":settings:show_fragment_title_resid";
199 public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
200 ":settings:show_fragment_as_shortcut";
201
202 public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
203 ":settings:show_fragment_as_subsetting";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800204
Udam Saini92779ce2016-03-28 14:29:48 -0700205 public static final String EXTRA_HIDE_DRAWER = ":settings:hide_drawer";
206
Jason Monk30695812015-11-17 09:01:08 -0500207 public static final String META_DATA_KEY_FRAGMENT_CLASS =
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800208 "com.android.settings.FRAGMENT_CLASS";
209
210 private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
211
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700212 private static final String EMPTY_QUERY = "";
213
Jason Monkd4f03ec2016-01-07 16:25:34 -0500214 private static final int REQUEST_SUGGESTION = 42;
215
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800216 private String mFragmentClass;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800217
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800218 private CharSequence mInitialTitle;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700219 private int mInitialTitleResId;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800220
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800221 // Show only these settings for restricted users
Jason Monk4da79e02015-09-10 10:54:36 -0400222 private String[] SETTINGS_FOR_RESTRICTED = {
223 //wireless_section
224 WifiSettingsActivity.class.getName(),
225 Settings.BluetoothSettingsActivity.class.getName(),
226 Settings.DataUsageSummaryActivity.class.getName(),
227 Settings.SimSettingsActivity.class.getName(),
228 Settings.WirelessSettingsActivity.class.getName(),
229 //device_section
230 Settings.HomeSettingsActivity.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500231 Settings.SoundSettingsActivity.class.getName(),
Jason Monk4da79e02015-09-10 10:54:36 -0400232 Settings.DisplaySettingsActivity.class.getName(),
233 Settings.StorageSettingsActivity.class.getName(),
234 Settings.ManageApplicationsActivity.class.getName(),
235 Settings.PowerUsageSummaryActivity.class.getName(),
236 //personal_section
237 Settings.LocationSettingsActivity.class.getName(),
238 Settings.SecuritySettingsActivity.class.getName(),
239 Settings.InputMethodAndLanguageSettingsActivity.class.getName(),
240 Settings.UserSettingsActivity.class.getName(),
241 Settings.AccountSettingsActivity.class.getName(),
242 //system_section
243 Settings.DateTimeSettingsActivity.class.getName(),
244 Settings.DeviceInfoSettingsActivity.class.getName(),
245 Settings.AccessibilitySettingsActivity.class.getName(),
246 Settings.PrintSettingsActivity.class.getName(),
247 Settings.PaymentSettingsActivity.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800248 };
249
250 private static final String[] ENTRY_FRAGMENTS = {
251 WirelessSettings.class.getName(),
252 WifiSettings.class.getName(),
253 AdvancedWifiSettings.class.getName(),
PauloftheWest7837b992014-06-24 07:42:27 -0700254 SavedAccessPointsWifiSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800255 BluetoothSettings.class.getName(),
PauloftheWest38155612014-06-30 10:02:36 -0700256 SimSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800257 TetherSettings.class.getName(),
258 WifiP2pSettings.class.getName(),
259 VpnSettings.class.getName(),
260 DateTimeSettings.class.getName(),
Mihai Nitad7d48fd2016-01-12 08:55:05 -0800261 LocaleListEditor.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800262 InputMethodAndLanguageSettings.class.getName(),
Abodunrinwa Toki976bb3f2016-01-20 18:43:20 +0000263 AvailableVirtualKeyboardFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800264 SpellCheckersSettings.class.getName(),
265 UserDictionaryList.class.getName(),
266 UserDictionarySettings.class.getName(),
Amith Yamasani3033ce02014-07-14 18:03:15 -0700267 HomeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800268 DisplaySettings.class.getName(),
269 DeviceInfoSettings.class.getName(),
270 ManageApplications.class.getName(),
Jason Monka2d47fc2016-03-03 10:49:44 -0500271 NotificationApps.class.getName(),
Xiyuan Xia86a55402015-06-02 14:55:32 -0700272 ManageAssist.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800273 ProcessStatsUi.class.getName(),
274 NotificationStation.class.getName(),
275 LocationSettings.class.getName(),
276 SecuritySettings.class.getName(),
Jason Monkd8da51c2015-04-17 14:34:12 -0400277 UsageAccessDetails.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800278 PrivacySettings.class.getName(),
279 DeviceAdminSettings.class.getName(),
280 AccessibilitySettings.class.getName(),
Anna Galuszab1795f52016-01-08 14:37:16 -0800281 AccessibilitySettingsForSetupWizard.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800282 CaptionPropertiesFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800283 com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(),
284 TextToSpeechSettings.class.getName(),
Jeff Sharkey42833b22015-04-11 21:27:33 -0700285 StorageSettings.class.getName(),
Jeff Sharkeya16257d2015-04-28 13:41:01 -0700286 PrivateVolumeForget.class.getName(),
Jeff Sharkeye77f0682015-04-29 11:24:57 -0700287 PrivateVolumeSettings.class.getName(),
288 PublicVolumeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800289 DevelopmentSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800290 AndroidBeam.class.getName(),
291 WifiDisplaySettings.class.getName(),
292 PowerUsageSummary.class.getName(),
293 AccountSyncSettings.class.getName(),
Alexandra Gherghina6d839872014-07-22 12:04:58 +0000294 AccountSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800295 CryptKeeperSettings.class.getName(),
296 DataUsageSummary.class.getName(),
297 DreamSettings.class.getName(),
298 UserSettings.class.getName(),
299 NotificationAccessSettings.class.getName(),
John Spurlock08531a82015-05-07 17:45:43 -0400300 ZenAccessSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800301 PrintSettingsFragment.class.getName(),
302 PrintJobSettingsFragment.class.getName(),
303 TrustedCredentialsSettings.class.getName(),
304 PaymentSettings.class.getName(),
305 KeyboardLayoutPickerFragment.class.getName(),
Abodunrinwa Toki5f0b59b2016-01-25 23:02:23 +0000306 KeyboardLayoutPickerFragment2.class.getName(),
Abodunrinwa Tokib28b2cc2016-03-22 16:29:38 +0000307 PhysicalKeyboardFragment.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700308 ZenModeSettings.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500309 SoundSettings.class.getName(),
310 ConfigureNotificationSettings.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700311 ChooseLockPassword.ChooseLockPasswordFragment.class.getName(),
312 ChooseLockPattern.ChooseLockPatternFragment.class.getName(),
John Spurlockc7f8e8c2014-06-04 19:11:22 -0400313 InstalledAppDetails.class.getName(),
314 BatterySaverSettings.class.getName(),
Fabrice Di Megliodcf59dd2014-07-21 11:22:20 -0700315 AppNotificationSettings.class.getName(),
Fabrice Di Meglioe3ff4d82014-07-23 20:03:20 -0700316 OtherSoundSettings.class.getName(),
Narayan Kamath33acb152015-03-16 12:48:05 +0000317 ApnSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400318 WifiCallingSettings.class.getName(),
John Spurlockc1df2aa2015-04-13 20:57:06 -0400319 ZenModePrioritySettings.class.getName(),
John Spurlock533a5662015-06-19 10:47:36 -0400320 ZenModeAutomationSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400321 ZenModeScheduleRuleSettings.class.getName(),
John Spurlockf57bad72015-04-30 09:26:15 -0400322 ZenModeEventRuleSettings.class.getName(),
Julia Reynolds5555d262015-11-09 10:52:17 -0500323 ZenModeVisualInterruptionSettings.class.getName(),
Jason Monk2583fc12015-03-25 09:46:30 -0400324 ProcessStatsUi.class.getName(),
Jason Monk1eb54eb2015-04-29 12:46:42 -0400325 PowerUsageDetail.class.getName(),
Jason Monk2cdafc62015-06-12 12:32:50 -0400326 ProcessStatsSummary.class.getName(),
Billy Laufee78562015-07-27 12:57:07 +0100327 DrawOverlayDetails.class.getName(),
328 WriteSettingsDetails.class.getName(),
Jason Monk91e2f892016-02-23 15:31:09 -0500329 AdvancedAppSettings.class.getName(),
Jason Monkb9e5d232016-01-26 17:43:57 -0500330 WallpaperTypeSettings.class.getName(),
Ruben Brunkc461d5c2016-04-07 21:45:41 -0700331 VrListenerSettings.class.getName(),
Tony Mak64f6d982016-05-03 18:55:41 +0100332 ManagedProfileSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800333 };
334
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700335
336 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
337 "android.settings.APPLICATION_DETAILS_SETTINGS"
338 };
339
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800340 private SharedPreferences mDevelopmentPreferences;
341 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
342
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800343 private boolean mBatteryPresent = true;
344 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800345 @Override
346 public void onReceive(Context context, Intent intent) {
347 String action = intent.getAction();
348 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
349 boolean batteryPresent = Utils.isBatteryPresent(intent);
350
351 if (mBatteryPresent != batteryPresent) {
352 mBatteryPresent = batteryPresent;
Jason Monk4da79e02015-09-10 10:54:36 -0400353 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800354 }
355 }
356 }
357 };
358
Clara Bayarri6934a042015-10-14 11:07:35 +0100359 private final BroadcastReceiver mUserAddRemoveReceiver = new BroadcastReceiver() {
360 @Override
361 public void onReceive(Context context, Intent intent) {
362 String action = intent.getAction();
363 if (action.equals(Intent.ACTION_USER_ADDED)
364 || action.equals(Intent.ACTION_USER_REMOVED)) {
365 Index.getInstance(getApplicationContext()).update();
366 }
367 }
368 };
369
Svetoslav990159a2014-04-14 17:14:59 -0700370 private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor =
371 new DynamicIndexableContentMonitor();
Svetoslav853e4712014-04-14 10:10:25 -0700372
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700373 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700374 private SwitchBar mSwitchBar;
375
376 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700377
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700378 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700379 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700380
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700381 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700382 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700383
Anna Galusza2f1c1132016-03-04 18:41:35 -0800384 private int mMainContentId = R.id.main_content;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700385 private ViewGroup mContent;
386
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700387 private SearchView mSearchView;
388 private MenuItem mSearchMenuItem;
389 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700390 private SearchResultsSummary mSearchResultsFragment;
391 private String mSearchQuery;
392
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700393 // Categories
394 private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800395
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700396 private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800397
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700398 private boolean mNeedToRevertToInitialFragment = false;
399
Jim Miller0698a212014-10-16 19:49:07 -0700400 private Intent mResultIntentData;
Jason Monkd4f03ec2016-01-07 16:25:34 -0500401 private ComponentName mCurrentSuggestion;
Jim Miller0698a212014-10-16 19:49:07 -0700402
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700403 public SwitchBar getSwitchBar() {
404 return mSwitchBar;
405 }
406
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800407 @Override
408 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
409 // Override the fragment title for Wallpaper settings
Jason Monk39b46742015-09-10 15:52:51 -0400410 CharSequence title = pref.getTitle();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800411 if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) {
Jason Monk39b46742015-09-10 15:52:51 -0400412 title = getString(R.string.wallpaper_settings_fragment_title);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800413 }
Jason Monkb1dd5c92015-12-16 16:13:54 -0500414 startPreferencePanel(pref.getFragment(), pref.getExtras(), -1, title,
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800415 null, 0);
416 return true;
417 }
418
419 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400420 public boolean onPreferenceTreeClick(Preference preference) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800421 return false;
422 }
423
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800424 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800425 public void onConfigurationChanged(Configuration newConfig) {
426 super.onConfigurationChanged(newConfig);
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800427 Index.getInstance(this).update();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800428 }
429
430 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700431 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700432 if (!mDisplaySearch) {
433 return false;
434 }
435
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700436 MenuInflater inflater = getMenuInflater();
437 inflater.inflate(R.menu.options_menu, menu);
438
439 // Cache the search query (can be overriden by the OnQueryTextListener)
440 final String query = mSearchQuery;
441
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700442 mSearchMenuItem = menu.findItem(R.id.search);
443 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700444
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700445 if (mSearchMenuItem == null || mSearchView == null) {
446 return false;
447 }
448
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700449 if (mSearchResultsFragment != null) {
450 mSearchResultsFragment.setSearchView(mSearchView);
451 }
452
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700453 mSearchMenuItem.setOnActionExpandListener(this);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700454 mSearchView.setOnQueryTextListener(this);
455 mSearchView.setOnCloseListener(this);
456
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700457 if (mSearchMenuItemExpanded) {
458 mSearchMenuItem.expandActionView();
459 }
460 mSearchView.setQuery(query, true /* submit */);
461
462 return true;
463 }
464
Jason Monk31c7c322016-01-20 14:41:52 -0500465 @Override
466 public SharedPreferences getSharedPreferences(String name, int mode) {
467 if (name.equals(getPackageName() + "_preferences")) {
Jason Monke4ebcd12016-02-21 09:37:41 -0500468 return new SharedPreferencesLogger(this, getMetricsTag());
Jason Monk31c7c322016-01-20 14:41:52 -0500469 }
470 return super.getSharedPreferences(name, mode);
471 }
472
Jason Monke4ebcd12016-02-21 09:37:41 -0500473 private String getMetricsTag() {
474 String tag = getClass().getName();
475 if (getIntent() != null && getIntent().hasExtra(EXTRA_SHOW_FRAGMENT)) {
476 tag = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
477 }
478 if (tag.startsWith("com.android.settings.")) {
479 tag = tag.replace("com.android.settings.", "");
480 }
481 return tag;
482 }
483
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700484 private static boolean isShortCutIntent(final Intent intent) {
485 Set<String> categories = intent.getCategories();
486 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
487 }
488
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700489 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700490 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700491 if (action == null) {
492 return false;
493 }
494 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
495 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
496 }
497 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700498 }
499
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700500 @Override
501 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700502 super.onCreate(savedState);
Jason Monkfd2c7222015-12-02 15:38:38 -0500503 long startTime = System.currentTimeMillis();
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700504
505 // Should happen before any call to getIntent()
506 getMetaData();
507
508 final Intent intent = getIntent();
509 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
510 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800511 }
Udam Saini92779ce2016-03-28 14:29:48 -0700512 if (intent.getBooleanExtra(EXTRA_HIDE_DRAWER, false)) {
513 setIsDrawerPresent(false);
514 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800515
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800516 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
517 Context.MODE_PRIVATE);
518
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700519 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700520 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700521
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700522 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700523 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
524
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700525 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700526 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700527
Jason Monk4da79e02015-09-10 10:54:36 -0400528 mIsShowingDashboard = className.equals(Settings.class.getName())
529 || className.equals(Settings.WirelessSettings.class.getName())
530 || className.equals(Settings.DeviceSettings.class.getName())
531 || className.equals(Settings.PersonalSettings.class.getName())
532 || className.equals(Settings.WirelessSettings.class.getName());
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700533
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700534 // This is a "Sub Settings" when:
535 // - this is a real SubSettings
536 // - or :settings:show_fragment_as_subsetting is passed to the Intent
Jorim Jaggi4dfcb822015-04-29 17:21:32 -0700537 final boolean isSubSettings = this instanceof SubSettings ||
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700538 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
539
540 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
541 if (isSubSettings) {
Fabrice Di Meglio712df6c2014-07-18 17:44:37 -0700542 // Check also that we are not a Theme Dialog as we don't want to override them
543 final int themeResId = getThemeResId();
544 if (themeResId != R.style.Theme_DialogWhenLarge &&
545 themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
546 setTheme(R.style.Theme_SubSettings);
547 }
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700548 }
549
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700550 setContentView(mIsShowingDashboard ?
551 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800552
Anna Galusza2f1c1132016-03-04 18:41:35 -0800553 mContent = (ViewGroup) findViewById(mMainContentId);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700554
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800555 getFragmentManager().addOnBackStackChangedListener(this);
556
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700557 if (mIsShowingDashboard) {
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800558 // Run the Index update only if we have some space
559 if (!Utils.isLowStorage(this)) {
Jason Monkfd2c7222015-12-02 15:38:38 -0500560 long indexStartTime = System.currentTimeMillis();
Jason Monk6c9e8842016-04-14 14:34:16 -0400561 Index.getInstance(getApplicationContext()).update();
Jason Monkfd2c7222015-12-02 15:38:38 -0500562 if (DEBUG_TIMING) Log.d(LOG_TAG, "Index.update() took "
563 + (System.currentTimeMillis() - indexStartTime) + " ms");
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800564 } else {
565 Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
566 }
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700567 }
568
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700569 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700570 // We are restarting from a previous saved state; used that to initialize, instead
571 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700572 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
573 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800574
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700575 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800576
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700577 ArrayList<DashboardCategory> categories =
578 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
579 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700580 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700581 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700582 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800583 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700584
585 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700586 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800587 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700588 if (!mIsShowingDashboard) {
Jason Monkea8b1a72015-06-02 16:46:34 -0400589 mDisplaySearch = false;
590 // UP will be shown only if it is a sub settings
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700591 if (mIsShortcut) {
592 mDisplayHomeAsUpEnabled = isSubSettings;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700593 } else if (isSubSettings) {
594 mDisplayHomeAsUpEnabled = true;
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700595 } else {
596 mDisplayHomeAsUpEnabled = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700597 }
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700598 setTitleFromIntent(intent);
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700599
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700600 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700601 switchToFragment(initialFragmentName, initialArguments, true, false,
602 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000603 } else {
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700604 // No UP affordance if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700605 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700606 // Show Search affordance
607 mDisplaySearch = true;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700608 mInitialTitleResId = R.string.dashboard_title;
Fabrice Di Meglio42c4b0a2014-05-22 10:30:03 -0700609 switchToFragment(DashboardSummary.class.getName(), null, false, false,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700610 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800611 }
612 }
613
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700614 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700615 if (mActionBar != null) {
616 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
617 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
618 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700619 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
Jason Monke4ebcd12016-02-21 09:37:41 -0500620 if (mSwitchBar != null) {
621 mSwitchBar.setMetricsTag(getMetricsTag());
622 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700623
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800624 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800625 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
626
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700627 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800628 if (buttonBar != null) {
629 buttonBar.setVisibility(View.VISIBLE);
630
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700631 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800632 backButton.setOnClickListener(new OnClickListener() {
633 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700634 setResult(RESULT_CANCELED, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800635 finish();
636 }
637 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700638 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800639 skipButton.setOnClickListener(new OnClickListener() {
640 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700641 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800642 finish();
643 }
644 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700645 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800646 mNextButton.setOnClickListener(new OnClickListener() {
647 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700648 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800649 finish();
650 }
651 });
652
653 // set our various button parameters
654 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
655 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
656 if (TextUtils.isEmpty(buttonText)) {
657 mNextButton.setVisibility(View.GONE);
658 }
659 else {
660 mNextButton.setText(buttonText);
661 }
662 }
663 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
664 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
665 if (TextUtils.isEmpty(buttonText)) {
666 backButton.setVisibility(View.GONE);
667 }
668 else {
669 backButton.setText(buttonText);
670 }
671 }
672 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
673 skipButton.setVisibility(View.VISIBLE);
674 }
675 }
676 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700677
Jason Monkfd2c7222015-12-02 15:38:38 -0500678 if (DEBUG_TIMING) Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
679 + " ms");
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700680 }
681
Anna Galusza2f1c1132016-03-04 18:41:35 -0800682 /**
683 * Sets the id of the view continaing the main content. Should be called before calling super's
684 * onCreate.
685 */
686 protected void setMainContentId(int contentId) {
687 mMainContentId = contentId;
688 }
689
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700690 private void setTitleFromIntent(Intent intent) {
691 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
692 if (initialTitleResId > 0) {
693 mInitialTitle = null;
694 mInitialTitleResId = initialTitleResId;
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100695
696 final String initialTitleResPackageName = intent.getStringExtra(
697 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
698 if (initialTitleResPackageName != null) {
699 try {
700 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
701 0 /* flags */, new UserHandle(UserHandle.myUserId()));
702 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
703 setTitle(mInitialTitle);
704 mInitialTitleResId = -1;
705 return;
706 } catch (NameNotFoundException e) {
707 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
708 }
709 } else {
710 setTitle(mInitialTitleResId);
711 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700712 } else {
713 mInitialTitleResId = -1;
714 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
715 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
716 setTitle(mInitialTitle);
717 }
718 }
719
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800720 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800721 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700722 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800723 }
724
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700725 private int setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800726 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700727
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800728 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700729 if (mInitialTitleResId > 0) {
730 setTitle(mInitialTitleResId);
731 } else {
732 setTitle(mInitialTitle);
733 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700734 return 0;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800735 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700736
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800737 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
738 setTitleFromBackStackEntry(bse);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700739
740 return count;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800741 }
742
743 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
744 final CharSequence title;
745 final int titleRes = bse.getBreadCrumbTitleRes();
746 if (titleRes > 0) {
747 title = getText(titleRes);
748 } else {
749 title = bse.getBreadCrumbTitle();
750 }
751 if (title != null) {
752 setTitle(title);
753 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800754 }
755
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800756 @Override
757 protected void onSaveInstanceState(Bundle outState) {
758 super.onSaveInstanceState(outState);
759
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700760 if (mCategories.size() > 0) {
761 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800762 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700763
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700764 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700765 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700766
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700767 if (mDisplaySearch) {
768 // The option menus are created if the ActionBar is visible and they are also created
769 // asynchronously. If you launch Settings with an Intent action like
770 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
771 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
772 // menu item and search view are null.
773 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
774 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700775
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700776 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
777 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
778 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800779 }
780
781 @Override
Jason Monk350a9302016-06-01 13:45:25 -0400782 protected void onStart() {
783 super.onStart();
784
785 if (mNeedToRevertToInitialFragment) {
786 revertToInitialFragment();
787 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800788
789 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
790 @Override
791 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Jason Monk4da79e02015-09-10 10:54:36 -0400792 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800793 }
794 };
795 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
796 mDevelopmentPreferencesListener);
797
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800798 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Clara Bayarri6934a042015-10-14 11:07:35 +0100799 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_ADDED));
800 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_REMOVED));
Svetoslav853e4712014-04-14 10:10:25 -0700801
Philip P. Moltmannd9779db2016-02-24 12:11:05 -0800802 mDynamicIndexableContentMonitor.register(this, LOADER_ID_INDEXABLE_CONTENT_MONITOR);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700803
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700804 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700805 onQueryTextSubmit(mSearchQuery);
806 }
Jason Monk4da79e02015-09-10 10:54:36 -0400807 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800808 }
809
810 @Override
Jason Monk350a9302016-06-01 13:45:25 -0400811 protected void onStop() {
812 super.onStop();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800813 unregisterReceiver(mBatteryInfoReceiver);
Clara Bayarri8c9521f2016-01-12 14:10:45 +0000814 unregisterReceiver(mUserAddRemoveReceiver);
Svetoslav990159a2014-04-14 17:14:59 -0700815 mDynamicIndexableContentMonitor.unregister();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800816 }
817
818 @Override
819 public void onDestroy() {
820 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700821
822 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
823 mDevelopmentPreferencesListener);
824 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800825 }
826
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800827 protected boolean isValidFragment(String fragmentName) {
828 // Almost all fragments are wrapped in this,
829 // except for a few that have their own activities.
830 for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
831 if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
832 }
833 return false;
834 }
835
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800836 @Override
837 public Intent getIntent() {
838 Intent superIntent = super.getIntent();
839 String startingFragment = getStartingFragmentClass(superIntent);
840 // This is called from super.onCreate, isMultiPane() is not yet reliable
841 // Do not use onIsHidingHeaders either, which relies itself on this method
842 if (startingFragment != null) {
843 Intent modIntent = new Intent(superIntent);
844 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
845 Bundle args = superIntent.getExtras();
846 if (args != null) {
847 args = new Bundle(args);
848 } else {
849 args = new Bundle();
850 }
851 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100852 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800853 return modIntent;
854 }
855 return superIntent;
856 }
857
858 /**
859 * Checks if the component name in the intent is different from the Settings class and
860 * returns the class name to load as a fragment.
861 */
862 private String getStartingFragmentClass(Intent intent) {
863 if (mFragmentClass != null) return mFragmentClass;
864
865 String intentClass = intent.getComponent().getClassName();
866 if (intentClass.equals(getClass().getName())) return null;
867
868 if ("com.android.settings.ManageApplications".equals(intentClass)
869 || "com.android.settings.RunningServices".equals(intentClass)
870 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
871 // Old names of manage apps.
872 intentClass = com.android.settings.applications.ManageApplications.class.getName();
873 }
874
875 return intentClass;
876 }
877
878 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000879 * Start a new fragment containing a preference panel. If the preferences
880 * are being displayed in multi-pane mode, the given fragment class will
881 * be instantiated and placed in the appropriate pane. If running in
882 * single-pane mode, a new activity will be launched in which to show the
883 * fragment.
884 *
885 * @param fragmentClass Full name of the class implementing the fragment.
886 * @param args Any desired arguments to supply to the fragment.
887 * @param titleRes Optional resource identifier of the title of this
888 * fragment.
889 * @param titleText Optional text of the title of this fragment.
890 * @param resultTo Optional fragment that result data should be sent to.
891 * If non-null, resultTo.onActivityResult() will be called when this
892 * preference panel is done. The launched panel must use
893 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
894 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700895 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000896 */
897 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700898 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700899 String title = null;
900 if (titleRes < 0) {
901 if (titleText != null) {
902 title = titleText.toString();
903 } else {
904 // There not much we can do in that case
905 title = "";
906 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700907 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700908 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700909 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000910 }
911
912 /**
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100913 * Start a new fragment in a new activity containing a preference panel for a given user. If the
914 * preferences are being displayed in multi-pane mode, the given fragment class will be
915 * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
916 * activity will be launched in which to show the fragment.
917 *
918 * @param fragmentClass Full name of the class implementing the fragment.
919 * @param args Any desired arguments to supply to the fragment.
920 * @param titleRes Optional resource identifier of the title of this fragment.
921 * @param titleText Optional text of the title of this fragment.
922 * @param userHandle The user for which the panel has to be started.
923 */
924 public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
925 CharSequence titleText, UserHandle userHandle) {
Lifu Tangd0332852015-04-02 12:05:46 -0700926 // This is a workaround.
927 //
928 // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
929 // starting the fragment could cause a native stack corruption. See b/17523189. However,
930 // adding that flag and start the preference panel with the same UserHandler will make it
931 // impossible to use back button to return to the previous screen. See b/20042570.
932 //
933 // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
934 // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
935 // when we're calling it as the same user.
936 if (userHandle.getIdentifier() == UserHandle.myUserId()) {
937 startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0);
938 } else {
939 String title = null;
940 if (titleRes < 0) {
941 if (titleText != null) {
942 title = titleText.toString();
943 } else {
944 // There not much we can do in that case
945 title = "";
946 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100947 }
Lifu Tangd0332852015-04-02 12:05:46 -0700948 Utils.startWithFragmentAsUser(this, fragmentClass, args,
949 titleRes, title, mIsShortcut, userHandle);
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100950 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100951 }
952
953 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800954 * Called by a preference panel fragment to finish itself.
955 *
956 * @param caller The fragment that is asking to be finished.
957 * @param resultCode Optional result code to send back to the original
958 * launching fragment.
959 * @param resultData Optional result data to send back to the original
960 * launching fragment.
961 */
962 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
963 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700964 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800965 }
966
967 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000968 * Start a new fragment.
969 *
970 * @param fragment The fragment to start
971 * @param push If true, the current fragment will be pushed onto the back stack. If false,
972 * the current fragment will be replaced.
973 */
974 public void startPreferenceFragment(Fragment fragment, boolean push) {
975 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Anna Galusza2f1c1132016-03-04 18:41:35 -0800976 transaction.replace(mMainContentId, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000977 if (push) {
978 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
979 transaction.addToBackStack(BACK_STACK_PREFS);
980 } else {
981 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
982 }
983 transaction.commitAllowingStateLoss();
984 }
985
986 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700987 * Switch to a specific Fragment with taking care of validation, Title and BackStack
988 */
989 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700990 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700991 if (validate && !isValidFragment(fragmentName)) {
992 throw new IllegalArgumentException("Invalid fragment for this activity: "
993 + fragmentName);
994 }
995 Fragment f = Fragment.instantiate(this, fragmentName, args);
996 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Anna Galusza2f1c1132016-03-04 18:41:35 -0800997 transaction.replace(mMainContentId, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700998 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700999 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001000 }
1001 if (addToBackStack) {
1002 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
1003 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001004 if (titleResId > 0) {
1005 transaction.setBreadCrumbTitle(titleResId);
1006 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001007 transaction.setBreadCrumbTitle(title);
1008 }
1009 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -07001010 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001011 return f;
1012 }
1013
Jason Monk4da79e02015-09-10 10:54:36 -04001014 private void updateTilesList() {
Jason Monkfd2c7222015-12-02 15:38:38 -05001015 // Generally the items that are will be changing from these updates will
1016 // not be in the top list of tiles, so run it in the background and the
1017 // SettingsDrawerActivity will pick up on the updates automatically.
1018 AsyncTask.execute(new Runnable() {
1019 @Override
1020 public void run() {
1021 doUpdateTilesList();
1022 }
1023 });
1024 }
1025
1026 private void doUpdateTilesList() {
Jason Monk4da79e02015-09-10 10:54:36 -04001027 PackageManager pm = getPackageManager();
Xiaohui Chen44879a32015-07-22 13:53:22 -07001028 final UserManager um = UserManager.get(this);
1029 final boolean isAdmin = um.isAdminUser();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001030
Jason Monk4da79e02015-09-10 10:54:36 -04001031 String packageName = getPackageName();
1032 setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()),
1033 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001034
Jason Monk4da79e02015-09-10 10:54:36 -04001035 setTileEnabled(new ComponentName(packageName,
1036 Settings.BluetoothSettingsActivity.class.getName()),
1037 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001038
Jason Monk4da79e02015-09-10 10:54:36 -04001039 setTileEnabled(new ComponentName(packageName,
1040 Settings.DataUsageSummaryActivity.class.getName()),
1041 Utils.isBandwidthControlEnabled(), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001042
Jason Monk4da79e02015-09-10 10:54:36 -04001043 setTileEnabled(new ComponentName(packageName,
1044 Settings.SimSettingsActivity.class.getName()),
1045 Utils.showSimCardTile(this), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001046
Jason Monk4da79e02015-09-10 10:54:36 -04001047 setTileEnabled(new ComponentName(packageName,
1048 Settings.PowerUsageSummaryActivity.class.getName()),
1049 mBatteryPresent, isAdmin, pm);
1050
1051 setTileEnabled(new ComponentName(packageName,
Jason Monk4da79e02015-09-10 10:54:36 -04001052 Settings.UserSettingsActivity.class.getName()),
1053 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
1054 && !Utils.isMonkeyRunning(), isAdmin, pm);
1055
1056 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
1057 setTileEnabled(new ComponentName(packageName,
1058 Settings.PaymentSettingsActivity.class.getName()),
1059 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
1060 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
1061 && adapter != null && adapter.isEnabled(), isAdmin, pm);
1062
1063 setTileEnabled(new ComponentName(packageName,
1064 Settings.PrintSettingsActivity.class.getName()),
1065 pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin, pm);
1066
1067 final boolean showDev = mDevelopmentPreferences.getBoolean(
Dan Sandler12c4ba42016-03-28 11:13:40 -04001068 DevelopmentSettings.PREF_SHOW, android.os.Build.TYPE.equals("eng"))
1069 && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES);
Jason Monk4da79e02015-09-10 10:54:36 -04001070 setTileEnabled(new ComponentName(packageName,
1071 Settings.DevelopmentSettingsActivity.class.getName()),
Dan Sandler12c4ba42016-03-28 11:13:40 -04001072 showDev, isAdmin, pm);
1073
1074 // Reveal development-only quick settings tiles
1075 DevelopmentTiles.setTilesEnabled(this, showDev);
Jason Monk4da79e02015-09-10 10:54:36 -04001076
1077 if (UserHandle.MU_ENABLED && !isAdmin) {
1078 // When on restricted users, disable all extra categories (but only the settings ones).
Jason Monkfd2c7222015-12-02 15:38:38 -05001079 List<DashboardCategory> categories = getDashboardCategories();
Jason Monk4da79e02015-09-10 10:54:36 -04001080 for (DashboardCategory category : categories) {
Jason Monkd4f03ec2016-01-07 16:25:34 -05001081 for (Tile tile : category.tiles) {
Jason Monk4da79e02015-09-10 10:54:36 -04001082 ComponentName component = tile.intent.getComponent();
Jason Monk5862c1e2016-06-07 14:02:33 -04001083 if (packageName.equals(component.getPackageName()) && !ArrayUtils.contains(
Jason Monk4da79e02015-09-10 10:54:36 -04001084 SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1085 setTileEnabled(component, false, isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001086 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001087 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001088 }
1089 }
Jason Monk2ebc8a02015-02-13 15:23:19 -05001090 }
1091
Jason Monk4da79e02015-09-10 10:54:36 -04001092 private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin,
1093 PackageManager pm) {
Jason Monk5862c1e2016-06-07 14:02:33 -04001094 if (UserHandle.MU_ENABLED && !isAdmin && getPackageName().equals(component.getPackageName())
Jason Monk4da79e02015-09-10 10:54:36 -04001095 && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1096 enabled = false;
1097 }
Jason Monk5862c1e2016-06-07 14:02:33 -04001098 setTileEnabled(component, enabled);
Jason Monk2ebc8a02015-02-13 15:23:19 -05001099 }
1100
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001101 private void getMetaData() {
1102 try {
1103 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1104 PackageManager.GET_META_DATA);
1105 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001106 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1107 } catch (NameNotFoundException nnfe) {
1108 // No recovery
1109 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1110 }
1111 }
1112
1113 // give subclasses access to the Next button
1114 public boolean hasNextButton() {
1115 return mNextButton != null;
1116 }
1117
1118 public Button getNextButton() {
1119 return mNextButton;
1120 }
1121
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001122 @Override
1123 public boolean shouldUpRecreateTask(Intent targetIntent) {
1124 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1125 }
1126
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001127 @Override
1128 public boolean onQueryTextSubmit(String query) {
1129 switchToSearchResultsFragmentIfNeeded();
1130 mSearchQuery = query;
1131 return mSearchResultsFragment.onQueryTextSubmit(query);
1132 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001133
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001134 @Override
1135 public boolean onQueryTextChange(String newText) {
1136 mSearchQuery = newText;
Fabrice Di Meglio7e4855e2014-05-23 16:03:43 -07001137 if (mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001138 return false;
1139 }
1140 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001141 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001142
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001143 @Override
1144 public boolean onClose() {
1145 return false;
1146 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001147
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001148 @Override
1149 public boolean onMenuItemActionExpand(MenuItem item) {
1150 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001151 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001152 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001153 return true;
1154 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001155
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001156 @Override
1157 public boolean onMenuItemActionCollapse(MenuItem item) {
1158 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001159 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001160 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001161 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001162 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001163 return true;
1164 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001165
Jason Monk4da79e02015-09-10 10:54:36 -04001166 @Override
Jason Monkd4f03ec2016-01-07 16:25:34 -05001167 protected void onTileClicked(Tile tile) {
Jason Monk4da79e02015-09-10 10:54:36 -04001168 if (mIsShowingDashboard) {
1169 // If on dashboard, don't finish so the back comes back to here.
1170 openTile(tile);
1171 } else {
1172 super.onTileClicked(tile);
1173 }
1174 }
1175
Jason Monkaf001092015-11-04 13:16:18 -05001176 @Override
1177 public void onProfileTileOpen() {
1178 if (!mIsShowingDashboard) {
1179 finish();
1180 }
1181 }
1182
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001183 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001184 if (mSearchResultsFragment != null) {
1185 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001186 }
Anna Galusza2f1c1132016-03-04 18:41:35 -08001187 Fragment current = getFragmentManager().findFragmentById(mMainContentId);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001188 if (current != null && current instanceof SearchResultsSummary) {
1189 mSearchResultsFragment = (SearchResultsSummary) current;
1190 } else {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001191 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001192 SearchResultsSummary.class.getName(), null, false, true,
1193 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001194 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001195 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001196 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001197 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001198
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001199 public void needToRevertToInitialFragment() {
1200 mNeedToRevertToInitialFragment = true;
1201 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001202
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001203 private void revertToInitialFragment() {
1204 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001205 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001206 mSearchMenuItemExpanded = false;
1207 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1208 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001209 if (mSearchMenuItem != null) {
1210 mSearchMenuItem.collapseActionView();
1211 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001212 }
Jim Miller0698a212014-10-16 19:49:07 -07001213
1214 public Intent getResultIntentData() {
1215 return mResultIntentData;
1216 }
1217
1218 public void setResultIntentData(Intent resultIntentData) {
1219 mResultIntentData = resultIntentData;
1220 }
Jason Monkd4f03ec2016-01-07 16:25:34 -05001221
1222 public void startSuggestion(Intent intent) {
1223 mCurrentSuggestion = intent.getComponent();
1224 startActivityForResult(intent, REQUEST_SUGGESTION);
1225 }
1226
1227 @Override
1228 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
1229 if (requestCode == REQUEST_SUGGESTION && mCurrentSuggestion != null
1230 && resultCode != RESULT_CANCELED) {
1231 getPackageManager().setComponentEnabledSetting(mCurrentSuggestion,
1232 PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
1233 }
1234 super.onActivityResult(requestCode, resultCode, data);
1235 }
1236
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001237}