blob: c4585d1ca8ca8600b4f8c3b13502067a47590bde [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;
Jason Monk91e2f892016-02-23 15:31:09 -050059import com.android.settings.applications.AdvancedAppSettings;
Billy Laufee78562015-07-27 12:57:07 +010060import com.android.settings.applications.DrawOverlayDetails;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070061import com.android.settings.applications.InstalledAppDetails;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080062import com.android.settings.applications.ManageApplications;
Xiyuan Xia86a55402015-06-02 14:55:32 -070063import com.android.settings.applications.ManageAssist;
Jason Monka2d47fc2016-03-03 10:49:44 -050064import com.android.settings.applications.NotificationApps;
Jason Monk2cdafc62015-06-12 12:32:50 -040065import com.android.settings.applications.ProcessStatsSummary;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080066import com.android.settings.applications.ProcessStatsUi;
Jason Monkd8da51c2015-04-17 14:34:12 -040067import com.android.settings.applications.UsageAccessDetails;
Billy Laufee78562015-07-27 12:57:07 +010068import com.android.settings.applications.WriteSettingsDetails;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080069import com.android.settings.bluetooth.BluetoothSettings;
70import com.android.settings.dashboard.DashboardSummary;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070071import com.android.settings.dashboard.SearchResultsSummary;
Jason Monkb37e2882016-01-11 14:27:20 -050072import com.android.settings.datausage.DataUsageSummary;
Jeff Sharkeya16257d2015-04-28 13:41:01 -070073import com.android.settings.deviceinfo.PrivateVolumeForget;
Jeff Sharkeye77f0682015-04-29 11:24:57 -070074import com.android.settings.deviceinfo.PrivateVolumeSettings;
Jeff Sharkey42833b22015-04-11 21:27:33 -070075import com.android.settings.deviceinfo.PublicVolumeSettings;
76import com.android.settings.deviceinfo.StorageSettings;
John Spurlockc7f8e8c2014-06-04 19:11:22 -040077import com.android.settings.fuelgauge.BatterySaverSettings;
Jason Monk1eb54eb2015-04-29 12:46:42 -040078import com.android.settings.fuelgauge.PowerUsageDetail;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080079import com.android.settings.fuelgauge.PowerUsageSummary;
Abodunrinwa Toki976bb3f2016-01-20 18:43:20 +000080import com.android.settings.inputmethod.AvailableVirtualKeyboardFragment;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080081import com.android.settings.inputmethod.InputMethodAndLanguageSettings;
82import com.android.settings.inputmethod.KeyboardLayoutPickerFragment;
Abodunrinwa Toki5f0b59b2016-01-25 23:02:23 +000083import com.android.settings.inputmethod.KeyboardLayoutPickerFragment2;
Abodunrinwa Tokib28b2cc2016-03-22 16:29:38 +000084import com.android.settings.inputmethod.PhysicalKeyboardFragment;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080085import com.android.settings.inputmethod.SpellCheckersSettings;
86import com.android.settings.inputmethod.UserDictionaryList;
Mihai Nitad7d48fd2016-01-12 08:55:05 -080087import com.android.settings.localepicker.LocaleListEditor;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080088import com.android.settings.location.LocationSettings;
89import com.android.settings.nfc.AndroidBeam;
90import com.android.settings.nfc.PaymentSettings;
John Spurlock802ddf92014-07-18 11:51:13 -040091import com.android.settings.notification.AppNotificationSettings;
Julia Reynolds8c0a4232015-11-24 10:08:14 -050092import com.android.settings.notification.ConfigureNotificationSettings;
John Spurlock4a350512014-04-08 14:08:21 -040093import com.android.settings.notification.NotificationAccessSettings;
John Spurlock4a350512014-04-08 14:08:21 -040094import com.android.settings.notification.NotificationStation;
Jason Monk2ebc8a02015-02-13 15:23:19 -050095import com.android.settings.notification.OtherSoundSettings;
Jason Monkb37e2882016-01-11 14:27:20 -050096import com.android.settings.notification.SoundSettings;
John Spurlock08531a82015-05-07 17:45:43 -040097import com.android.settings.notification.ZenAccessSettings;
John Spurlock533a5662015-06-19 10:47:36 -040098import com.android.settings.notification.ZenModeAutomationSettings;
John Spurlockf57bad72015-04-30 09:26:15 -040099import com.android.settings.notification.ZenModeEventRuleSettings;
John Spurlockc1df2aa2015-04-13 20:57:06 -0400100import com.android.settings.notification.ZenModePrioritySettings;
John Spurlock45fa1402015-04-09 12:50:04 -0400101import com.android.settings.notification.ZenModeScheduleRuleSettings;
Jason Monk39b46742015-09-10 15:52:51 -0400102import com.android.settings.notification.ZenModeSettings;
Julia Reynolds5555d262015-11-09 10:52:17 -0500103import com.android.settings.notification.ZenModeVisualInterruptionSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800104import com.android.settings.print.PrintJobSettingsFragment;
105import com.android.settings.print.PrintSettingsFragment;
Jason Monk2ebc8a02015-02-13 15:23:19 -0500106import com.android.settings.search.DynamicIndexableContentMonitor;
107import com.android.settings.search.Index;
PauloftheWest38155612014-06-30 10:02:36 -0700108import com.android.settings.sim.SimSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800109import com.android.settings.tts.TextToSpeechSettings;
110import com.android.settings.users.UserSettings;
111import com.android.settings.vpn2.VpnSettings;
112import com.android.settings.wfd.WifiDisplaySettings;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700113import com.android.settings.widget.SwitchBar;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800114import com.android.settings.wifi.AdvancedWifiSettings;
PauloftheWest7837b992014-06-24 07:42:27 -0700115import com.android.settings.wifi.SavedAccessPointsWifiSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800116import com.android.settings.wifi.WifiSettings;
117import com.android.settings.wifi.p2p.WifiP2pSettings;
Jason Monk4da79e02015-09-10 10:54:36 -0400118import com.android.settingslib.drawer.DashboardCategory;
Jason Monk4da79e02015-09-10 10:54:36 -0400119import com.android.settingslib.drawer.SettingsDrawerActivity;
Jason Monk7ea14c52016-01-22 14:28:02 -0500120import com.android.settingslib.drawer.Tile;
Jason Monk2ebc8a02015-02-13 15:23:19 -0500121
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800122import java.util.ArrayList;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800123import java.util.List;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700124import java.util.Set;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800125
Jason Monk4da79e02015-09-10 10:54:36 -0400126public class SettingsActivity extends SettingsDrawerActivity
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800127 implements PreferenceManager.OnPreferenceTreeClickListener,
128 PreferenceFragment.OnPreferenceStartFragmentCallback,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100129 ButtonBarHandler, FragmentManager.OnBackStackChangedListener,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700130 SearchView.OnQueryTextListener, SearchView.OnCloseListener,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100131 MenuItem.OnActionExpandListener {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800132
133 private static final String LOG_TAG = "Settings";
134
Philip P. Moltmannd9779db2016-02-24 12:11:05 -0800135 private static final int LOADER_ID_INDEXABLE_CONTENT_MONITOR = 1;
136
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800137 // Constants for state save/restore
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700138 private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700139 private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
140 private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700141 private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700142 private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700143 private static final String SAVE_KEY_HOME_ACTIVITIES_COUNT = ":settings:home_activities_count";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800144
145 /**
146 * When starting this activity, the invoking Intent can contain this extra
147 * string to specify which fragment should be initially displayed.
148 * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
149 * will call isValidFragment() to confirm that the fragment class name is valid for this
150 * activity.
151 */
152 public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
153
154 /**
155 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
156 * this extra can also be specified to supply a Bundle of arguments to pass
157 * to that fragment when it is instantiated during the initial creation
158 * of the activity.
159 */
160 public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
161
162 /**
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700163 * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
164 */
165 public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
166
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800167 public static final String BACK_STACK_PREFS = ":settings:prefs";
168
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800169 // extras that allow any preference activity to be launched as part of a wizard
170
171 // show Back and Next buttons? takes boolean parameter
172 // Back will then return RESULT_CANCELED and Next RESULT_OK
173 protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
174
175 // add a Skip button?
176 private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
177
178 // specify custom text for the Back or Next buttons, or cause a button to not appear
179 // at all by setting it to null
180 protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
181 protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
182
183 /**
184 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700185 * 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 -0800186 * that fragment.
187 */
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700188 public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100189 /**
190 * The package name used to resolve the title resource id.
191 */
192 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
193 ":settings:show_fragment_title_res_package_name";
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700194 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
195 ":settings:show_fragment_title_resid";
196 public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
197 ":settings:show_fragment_as_shortcut";
198
199 public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
200 ":settings:show_fragment_as_subsetting";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800201
Jason Monk30695812015-11-17 09:01:08 -0500202 public static final String META_DATA_KEY_FRAGMENT_CLASS =
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800203 "com.android.settings.FRAGMENT_CLASS";
204
205 private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
206
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700207 private static final String EMPTY_QUERY = "";
208
Jason Monkd4f03ec2016-01-07 16:25:34 -0500209 private static final int REQUEST_SUGGESTION = 42;
210
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800211 private String mFragmentClass;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800212
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800213 private CharSequence mInitialTitle;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700214 private int mInitialTitleResId;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800215
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800216 // Show only these settings for restricted users
Jason Monk4da79e02015-09-10 10:54:36 -0400217 private String[] SETTINGS_FOR_RESTRICTED = {
218 //wireless_section
219 WifiSettingsActivity.class.getName(),
220 Settings.BluetoothSettingsActivity.class.getName(),
221 Settings.DataUsageSummaryActivity.class.getName(),
222 Settings.SimSettingsActivity.class.getName(),
223 Settings.WirelessSettingsActivity.class.getName(),
224 //device_section
225 Settings.HomeSettingsActivity.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500226 Settings.SoundSettingsActivity.class.getName(),
Jason Monk4da79e02015-09-10 10:54:36 -0400227 Settings.DisplaySettingsActivity.class.getName(),
228 Settings.StorageSettingsActivity.class.getName(),
229 Settings.ManageApplicationsActivity.class.getName(),
230 Settings.PowerUsageSummaryActivity.class.getName(),
231 //personal_section
232 Settings.LocationSettingsActivity.class.getName(),
233 Settings.SecuritySettingsActivity.class.getName(),
234 Settings.InputMethodAndLanguageSettingsActivity.class.getName(),
235 Settings.UserSettingsActivity.class.getName(),
236 Settings.AccountSettingsActivity.class.getName(),
237 //system_section
238 Settings.DateTimeSettingsActivity.class.getName(),
239 Settings.DeviceInfoSettingsActivity.class.getName(),
240 Settings.AccessibilitySettingsActivity.class.getName(),
241 Settings.PrintSettingsActivity.class.getName(),
242 Settings.PaymentSettingsActivity.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800243 };
244
245 private static final String[] ENTRY_FRAGMENTS = {
246 WirelessSettings.class.getName(),
247 WifiSettings.class.getName(),
248 AdvancedWifiSettings.class.getName(),
PauloftheWest7837b992014-06-24 07:42:27 -0700249 SavedAccessPointsWifiSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800250 BluetoothSettings.class.getName(),
PauloftheWest38155612014-06-30 10:02:36 -0700251 SimSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800252 TetherSettings.class.getName(),
253 WifiP2pSettings.class.getName(),
254 VpnSettings.class.getName(),
255 DateTimeSettings.class.getName(),
Mihai Nitad7d48fd2016-01-12 08:55:05 -0800256 LocaleListEditor.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800257 InputMethodAndLanguageSettings.class.getName(),
Abodunrinwa Toki976bb3f2016-01-20 18:43:20 +0000258 AvailableVirtualKeyboardFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800259 SpellCheckersSettings.class.getName(),
260 UserDictionaryList.class.getName(),
261 UserDictionarySettings.class.getName(),
Amith Yamasani3033ce02014-07-14 18:03:15 -0700262 HomeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800263 DisplaySettings.class.getName(),
264 DeviceInfoSettings.class.getName(),
265 ManageApplications.class.getName(),
Jason Monka2d47fc2016-03-03 10:49:44 -0500266 NotificationApps.class.getName(),
Xiyuan Xia86a55402015-06-02 14:55:32 -0700267 ManageAssist.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800268 ProcessStatsUi.class.getName(),
269 NotificationStation.class.getName(),
270 LocationSettings.class.getName(),
271 SecuritySettings.class.getName(),
Jason Monkd8da51c2015-04-17 14:34:12 -0400272 UsageAccessDetails.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800273 PrivacySettings.class.getName(),
274 DeviceAdminSettings.class.getName(),
275 AccessibilitySettings.class.getName(),
Anna Galuszab1795f52016-01-08 14:37:16 -0800276 AccessibilitySettingsForSetupWizard.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800277 CaptionPropertiesFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800278 com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(),
279 TextToSpeechSettings.class.getName(),
Jeff Sharkey42833b22015-04-11 21:27:33 -0700280 StorageSettings.class.getName(),
Jeff Sharkeya16257d2015-04-28 13:41:01 -0700281 PrivateVolumeForget.class.getName(),
Jeff Sharkeye77f0682015-04-29 11:24:57 -0700282 PrivateVolumeSettings.class.getName(),
283 PublicVolumeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800284 DevelopmentSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800285 AndroidBeam.class.getName(),
286 WifiDisplaySettings.class.getName(),
287 PowerUsageSummary.class.getName(),
288 AccountSyncSettings.class.getName(),
Alexandra Gherghina6d839872014-07-22 12:04:58 +0000289 AccountSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800290 CryptKeeperSettings.class.getName(),
291 DataUsageSummary.class.getName(),
292 DreamSettings.class.getName(),
293 UserSettings.class.getName(),
294 NotificationAccessSettings.class.getName(),
John Spurlock08531a82015-05-07 17:45:43 -0400295 ZenAccessSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800296 PrintSettingsFragment.class.getName(),
297 PrintJobSettingsFragment.class.getName(),
298 TrustedCredentialsSettings.class.getName(),
299 PaymentSettings.class.getName(),
300 KeyboardLayoutPickerFragment.class.getName(),
Abodunrinwa Toki5f0b59b2016-01-25 23:02:23 +0000301 KeyboardLayoutPickerFragment2.class.getName(),
Abodunrinwa Tokib28b2cc2016-03-22 16:29:38 +0000302 PhysicalKeyboardFragment.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700303 ZenModeSettings.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500304 SoundSettings.class.getName(),
305 ConfigureNotificationSettings.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700306 ChooseLockPassword.ChooseLockPasswordFragment.class.getName(),
307 ChooseLockPattern.ChooseLockPatternFragment.class.getName(),
John Spurlockc7f8e8c2014-06-04 19:11:22 -0400308 InstalledAppDetails.class.getName(),
309 BatterySaverSettings.class.getName(),
Fabrice Di Megliodcf59dd2014-07-21 11:22:20 -0700310 AppNotificationSettings.class.getName(),
Fabrice Di Meglioe3ff4d82014-07-23 20:03:20 -0700311 OtherSoundSettings.class.getName(),
Narayan Kamath33acb152015-03-16 12:48:05 +0000312 ApnSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400313 WifiCallingSettings.class.getName(),
John Spurlockc1df2aa2015-04-13 20:57:06 -0400314 ZenModePrioritySettings.class.getName(),
John Spurlock533a5662015-06-19 10:47:36 -0400315 ZenModeAutomationSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400316 ZenModeScheduleRuleSettings.class.getName(),
John Spurlockf57bad72015-04-30 09:26:15 -0400317 ZenModeEventRuleSettings.class.getName(),
Julia Reynolds5555d262015-11-09 10:52:17 -0500318 ZenModeVisualInterruptionSettings.class.getName(),
Jason Monk2583fc12015-03-25 09:46:30 -0400319 ProcessStatsUi.class.getName(),
Jason Monk1eb54eb2015-04-29 12:46:42 -0400320 PowerUsageDetail.class.getName(),
Jason Monk2cdafc62015-06-12 12:32:50 -0400321 ProcessStatsSummary.class.getName(),
Billy Laufee78562015-07-27 12:57:07 +0100322 DrawOverlayDetails.class.getName(),
323 WriteSettingsDetails.class.getName(),
Jason Monk91e2f892016-02-23 15:31:09 -0500324 AdvancedAppSettings.class.getName(),
Jason Monkb9e5d232016-01-26 17:43:57 -0500325 WallpaperTypeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800326 };
327
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700328
329 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
330 "android.settings.APPLICATION_DETAILS_SETTINGS"
331 };
332
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800333 private SharedPreferences mDevelopmentPreferences;
334 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
335
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800336 private boolean mBatteryPresent = true;
337 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800338 @Override
339 public void onReceive(Context context, Intent intent) {
340 String action = intent.getAction();
341 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
342 boolean batteryPresent = Utils.isBatteryPresent(intent);
343
344 if (mBatteryPresent != batteryPresent) {
345 mBatteryPresent = batteryPresent;
Jason Monk4da79e02015-09-10 10:54:36 -0400346 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800347 }
348 }
349 }
350 };
351
Clara Bayarri6934a042015-10-14 11:07:35 +0100352 private final BroadcastReceiver mUserAddRemoveReceiver = new BroadcastReceiver() {
353 @Override
354 public void onReceive(Context context, Intent intent) {
355 String action = intent.getAction();
356 if (action.equals(Intent.ACTION_USER_ADDED)
357 || action.equals(Intent.ACTION_USER_REMOVED)) {
358 Index.getInstance(getApplicationContext()).update();
359 }
360 }
361 };
362
Svetoslav990159a2014-04-14 17:14:59 -0700363 private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor =
364 new DynamicIndexableContentMonitor();
Svetoslav853e4712014-04-14 10:10:25 -0700365
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700366 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700367 private SwitchBar mSwitchBar;
368
369 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700370
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700371 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700372 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700373
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700374 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700375 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700376
Anna Galusza2f1c1132016-03-04 18:41:35 -0800377 private int mMainContentId = R.id.main_content;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700378 private ViewGroup mContent;
379
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700380 private SearchView mSearchView;
381 private MenuItem mSearchMenuItem;
382 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700383 private SearchResultsSummary mSearchResultsFragment;
384 private String mSearchQuery;
385
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700386 // Categories
387 private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800388
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700389 private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800390
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700391 private boolean mNeedToRevertToInitialFragment = false;
392
Jim Miller0698a212014-10-16 19:49:07 -0700393 private Intent mResultIntentData;
Jason Monkd4f03ec2016-01-07 16:25:34 -0500394 private ComponentName mCurrentSuggestion;
Jim Miller0698a212014-10-16 19:49:07 -0700395
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700396 public SwitchBar getSwitchBar() {
397 return mSwitchBar;
398 }
399
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800400 @Override
401 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
402 // Override the fragment title for Wallpaper settings
Jason Monk39b46742015-09-10 15:52:51 -0400403 CharSequence title = pref.getTitle();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800404 if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) {
Jason Monk39b46742015-09-10 15:52:51 -0400405 title = getString(R.string.wallpaper_settings_fragment_title);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800406 }
Jason Monkb1dd5c92015-12-16 16:13:54 -0500407 startPreferencePanel(pref.getFragment(), pref.getExtras(), -1, title,
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800408 null, 0);
409 return true;
410 }
411
412 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400413 public boolean onPreferenceTreeClick(Preference preference) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800414 return false;
415 }
416
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800417 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800418 public void onConfigurationChanged(Configuration newConfig) {
419 super.onConfigurationChanged(newConfig);
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800420 Index.getInstance(this).update();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800421 }
422
423 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700424 protected void onStart() {
425 super.onStart();
426
427 if (mNeedToRevertToInitialFragment) {
428 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800429 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800430 }
431
432 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700433 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700434 if (!mDisplaySearch) {
435 return false;
436 }
437
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700438 MenuInflater inflater = getMenuInflater();
439 inflater.inflate(R.menu.options_menu, menu);
440
441 // Cache the search query (can be overriden by the OnQueryTextListener)
442 final String query = mSearchQuery;
443
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700444 mSearchMenuItem = menu.findItem(R.id.search);
445 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700446
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700447 if (mSearchMenuItem == null || mSearchView == null) {
448 return false;
449 }
450
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700451 if (mSearchResultsFragment != null) {
452 mSearchResultsFragment.setSearchView(mSearchView);
453 }
454
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700455 mSearchMenuItem.setOnActionExpandListener(this);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700456 mSearchView.setOnQueryTextListener(this);
457 mSearchView.setOnCloseListener(this);
458
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700459 if (mSearchMenuItemExpanded) {
460 mSearchMenuItem.expandActionView();
461 }
462 mSearchView.setQuery(query, true /* submit */);
463
464 return true;
465 }
466
Jason Monk31c7c322016-01-20 14:41:52 -0500467 @Override
468 public SharedPreferences getSharedPreferences(String name, int mode) {
469 if (name.equals(getPackageName() + "_preferences")) {
Jason Monke4ebcd12016-02-21 09:37:41 -0500470 return new SharedPreferencesLogger(this, getMetricsTag());
Jason Monk31c7c322016-01-20 14:41:52 -0500471 }
472 return super.getSharedPreferences(name, mode);
473 }
474
Jason Monke4ebcd12016-02-21 09:37:41 -0500475 private String getMetricsTag() {
476 String tag = getClass().getName();
477 if (getIntent() != null && getIntent().hasExtra(EXTRA_SHOW_FRAGMENT)) {
478 tag = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
479 }
480 if (tag.startsWith("com.android.settings.")) {
481 tag = tag.replace("com.android.settings.", "");
482 }
483 return tag;
484 }
485
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700486 private static boolean isShortCutIntent(final Intent intent) {
487 Set<String> categories = intent.getCategories();
488 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
489 }
490
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700491 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700492 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700493 if (action == null) {
494 return false;
495 }
496 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
497 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
498 }
499 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700500 }
501
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700502 @Override
503 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700504 super.onCreate(savedState);
Jason Monkfd2c7222015-12-02 15:38:38 -0500505 long startTime = System.currentTimeMillis();
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700506
507 // Should happen before any call to getIntent()
508 getMetaData();
509
510 final Intent intent = getIntent();
511 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
512 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800513 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800514
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800515 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
516 Context.MODE_PRIVATE);
517
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700518 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700519 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700520
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700521 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700522 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
523
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700524 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700525 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700526
Jason Monk4da79e02015-09-10 10:54:36 -0400527 mIsShowingDashboard = className.equals(Settings.class.getName())
528 || className.equals(Settings.WirelessSettings.class.getName())
529 || className.equals(Settings.DeviceSettings.class.getName())
530 || className.equals(Settings.PersonalSettings.class.getName())
531 || className.equals(Settings.WirelessSettings.class.getName());
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700532
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700533 // This is a "Sub Settings" when:
534 // - this is a real SubSettings
535 // - or :settings:show_fragment_as_subsetting is passed to the Intent
Jorim Jaggi4dfcb822015-04-29 17:21:32 -0700536 final boolean isSubSettings = this instanceof SubSettings ||
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700537 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
538
539 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
540 if (isSubSettings) {
Fabrice Di Meglio712df6c2014-07-18 17:44:37 -0700541 // Check also that we are not a Theme Dialog as we don't want to override them
542 final int themeResId = getThemeResId();
543 if (themeResId != R.style.Theme_DialogWhenLarge &&
544 themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
545 setTheme(R.style.Theme_SubSettings);
546 }
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700547 }
548
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700549 setContentView(mIsShowingDashboard ?
550 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800551
Anna Galusza2f1c1132016-03-04 18:41:35 -0800552 mContent = (ViewGroup) findViewById(mMainContentId);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700553
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800554 getFragmentManager().addOnBackStackChangedListener(this);
555
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700556 if (mIsShowingDashboard) {
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800557 // Run the Index update only if we have some space
558 if (!Utils.isLowStorage(this)) {
Jason Monkfd2c7222015-12-02 15:38:38 -0500559 long indexStartTime = System.currentTimeMillis();
560 AsyncTask.execute(new Runnable() {
561 @Override
562 public void run() {
563 Index.getInstance(getApplicationContext()).update();
564 }
565 });
566 if (DEBUG_TIMING) Log.d(LOG_TAG, "Index.update() took "
567 + (System.currentTimeMillis() - indexStartTime) + " ms");
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800568 } else {
569 Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
570 }
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700571 }
572
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700573 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700574 // We are restarting from a previous saved state; used that to initialize, instead
575 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700576 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
577 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800578
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700579 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800580
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700581 ArrayList<DashboardCategory> categories =
582 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
583 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700584 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700585 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700586 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800587 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700588
589 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700590 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800591 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700592 if (!mIsShowingDashboard) {
Jason Monkea8b1a72015-06-02 16:46:34 -0400593 mDisplaySearch = false;
594 // UP will be shown only if it is a sub settings
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700595 if (mIsShortcut) {
596 mDisplayHomeAsUpEnabled = isSubSettings;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700597 } else if (isSubSettings) {
598 mDisplayHomeAsUpEnabled = true;
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700599 } else {
600 mDisplayHomeAsUpEnabled = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700601 }
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700602 setTitleFromIntent(intent);
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700603
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700604 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700605 switchToFragment(initialFragmentName, initialArguments, true, false,
606 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000607 } else {
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700608 // No UP affordance if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700609 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700610 // Show Search affordance
611 mDisplaySearch = true;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700612 mInitialTitleResId = R.string.dashboard_title;
Fabrice Di Meglio42c4b0a2014-05-22 10:30:03 -0700613 switchToFragment(DashboardSummary.class.getName(), null, false, false,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700614 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800615 }
616 }
617
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700618 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700619 if (mActionBar != null) {
620 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
621 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
622 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700623 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
Jason Monke4ebcd12016-02-21 09:37:41 -0500624 if (mSwitchBar != null) {
625 mSwitchBar.setMetricsTag(getMetricsTag());
626 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700627
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800628 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800629 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
630
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700631 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800632 if (buttonBar != null) {
633 buttonBar.setVisibility(View.VISIBLE);
634
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700635 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800636 backButton.setOnClickListener(new OnClickListener() {
637 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700638 setResult(RESULT_CANCELED, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800639 finish();
640 }
641 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700642 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800643 skipButton.setOnClickListener(new OnClickListener() {
644 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700645 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800646 finish();
647 }
648 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700649 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800650 mNextButton.setOnClickListener(new OnClickListener() {
651 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700652 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800653 finish();
654 }
655 });
656
657 // set our various button parameters
658 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
659 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
660 if (TextUtils.isEmpty(buttonText)) {
661 mNextButton.setVisibility(View.GONE);
662 }
663 else {
664 mNextButton.setText(buttonText);
665 }
666 }
667 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
668 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
669 if (TextUtils.isEmpty(buttonText)) {
670 backButton.setVisibility(View.GONE);
671 }
672 else {
673 backButton.setText(buttonText);
674 }
675 }
676 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
677 skipButton.setVisibility(View.VISIBLE);
678 }
679 }
680 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700681
Jason Monkfd2c7222015-12-02 15:38:38 -0500682 if (DEBUG_TIMING) Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
683 + " ms");
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700684 }
685
Anna Galusza2f1c1132016-03-04 18:41:35 -0800686 /**
687 * Sets the id of the view continaing the main content. Should be called before calling super's
688 * onCreate.
689 */
690 protected void setMainContentId(int contentId) {
691 mMainContentId = contentId;
692 }
693
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700694 private void setTitleFromIntent(Intent intent) {
695 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
696 if (initialTitleResId > 0) {
697 mInitialTitle = null;
698 mInitialTitleResId = initialTitleResId;
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100699
700 final String initialTitleResPackageName = intent.getStringExtra(
701 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
702 if (initialTitleResPackageName != null) {
703 try {
704 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
705 0 /* flags */, new UserHandle(UserHandle.myUserId()));
706 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
707 setTitle(mInitialTitle);
708 mInitialTitleResId = -1;
709 return;
710 } catch (NameNotFoundException e) {
711 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
712 }
713 } else {
714 setTitle(mInitialTitleResId);
715 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700716 } else {
717 mInitialTitleResId = -1;
718 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
719 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
720 setTitle(mInitialTitle);
721 }
722 }
723
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800724 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800725 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700726 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800727 }
728
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700729 private int setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800730 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700731
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800732 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700733 if (mInitialTitleResId > 0) {
734 setTitle(mInitialTitleResId);
735 } else {
736 setTitle(mInitialTitle);
737 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700738 return 0;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800739 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700740
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800741 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
742 setTitleFromBackStackEntry(bse);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700743
744 return count;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800745 }
746
747 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
748 final CharSequence title;
749 final int titleRes = bse.getBreadCrumbTitleRes();
750 if (titleRes > 0) {
751 title = getText(titleRes);
752 } else {
753 title = bse.getBreadCrumbTitle();
754 }
755 if (title != null) {
756 setTitle(title);
757 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800758 }
759
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800760 @Override
761 protected void onSaveInstanceState(Bundle outState) {
762 super.onSaveInstanceState(outState);
763
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700764 if (mCategories.size() > 0) {
765 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800766 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700767
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700768 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700769 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700770
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700771 if (mDisplaySearch) {
772 // The option menus are created if the ActionBar is visible and they are also created
773 // asynchronously. If you launch Settings with an Intent action like
774 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
775 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
776 // menu item and search view are null.
777 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
778 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700779
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700780 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
781 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
782 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800783 }
784
785 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400786 protected void onResume() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800787 super.onResume();
788
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 Monk39b46742015-09-10 15:52:51 -0400811 protected void onPause() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800812 super.onPause();
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(
1068 DevelopmentSettings.PREF_SHOW,
1069 android.os.Build.TYPE.equals("eng"));
1070 setTileEnabled(new ComponentName(packageName,
1071 Settings.DevelopmentSettingsActivity.class.getName()),
1072 showDev && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES),
1073 isAdmin, pm);
1074
1075 if (UserHandle.MU_ENABLED && !isAdmin) {
1076 // When on restricted users, disable all extra categories (but only the settings ones).
Jason Monkfd2c7222015-12-02 15:38:38 -05001077 List<DashboardCategory> categories = getDashboardCategories();
Jason Monk4da79e02015-09-10 10:54:36 -04001078 for (DashboardCategory category : categories) {
Jason Monkd4f03ec2016-01-07 16:25:34 -05001079 for (Tile tile : category.tiles) {
Jason Monk4da79e02015-09-10 10:54:36 -04001080 ComponentName component = tile.intent.getComponent();
1081 if (packageName.equals(component)&& !ArrayUtils.contains(
1082 SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1083 setTileEnabled(component, false, isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001084 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001085 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001086 }
1087 }
Jason Monk2ebc8a02015-02-13 15:23:19 -05001088 }
1089
Jason Monk4da79e02015-09-10 10:54:36 -04001090 private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin,
1091 PackageManager pm) {
1092 if (UserHandle.MU_ENABLED && !isAdmin
1093 && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1094 enabled = false;
1095 }
1096 int state = pm.getComponentEnabledSetting(component);
1097 boolean isEnabled = state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
1098 || state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
1099 if (isEnabled != enabled) {
1100 pm.setComponentEnabledSetting(component, enabled
1101 ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
1102 : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
1103 PackageManager.DONT_KILL_APP);
Jason Monk2ebc8a02015-02-13 15:23:19 -05001104 }
1105 }
1106
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001107 private void getMetaData() {
1108 try {
1109 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1110 PackageManager.GET_META_DATA);
1111 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001112 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1113 } catch (NameNotFoundException nnfe) {
1114 // No recovery
1115 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1116 }
1117 }
1118
1119 // give subclasses access to the Next button
1120 public boolean hasNextButton() {
1121 return mNextButton != null;
1122 }
1123
1124 public Button getNextButton() {
1125 return mNextButton;
1126 }
1127
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001128 @Override
1129 public boolean shouldUpRecreateTask(Intent targetIntent) {
1130 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1131 }
1132
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001133 @Override
1134 public boolean onQueryTextSubmit(String query) {
1135 switchToSearchResultsFragmentIfNeeded();
1136 mSearchQuery = query;
1137 return mSearchResultsFragment.onQueryTextSubmit(query);
1138 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001139
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001140 @Override
1141 public boolean onQueryTextChange(String newText) {
1142 mSearchQuery = newText;
Fabrice Di Meglio7e4855e2014-05-23 16:03:43 -07001143 if (mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001144 return false;
1145 }
1146 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001147 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001148
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001149 @Override
1150 public boolean onClose() {
1151 return false;
1152 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001153
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001154 @Override
1155 public boolean onMenuItemActionExpand(MenuItem item) {
1156 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001157 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001158 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001159 return true;
1160 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001161
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001162 @Override
1163 public boolean onMenuItemActionCollapse(MenuItem item) {
1164 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001165 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001166 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001167 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001168 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001169 return true;
1170 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001171
Jason Monk4da79e02015-09-10 10:54:36 -04001172 @Override
Jason Monkd4f03ec2016-01-07 16:25:34 -05001173 protected void onTileClicked(Tile tile) {
Jason Monk4da79e02015-09-10 10:54:36 -04001174 if (mIsShowingDashboard) {
1175 // If on dashboard, don't finish so the back comes back to here.
1176 openTile(tile);
1177 } else {
1178 super.onTileClicked(tile);
1179 }
1180 }
1181
Jason Monkaf001092015-11-04 13:16:18 -05001182 @Override
1183 public void onProfileTileOpen() {
1184 if (!mIsShowingDashboard) {
1185 finish();
1186 }
1187 }
1188
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001189 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001190 if (mSearchResultsFragment != null) {
1191 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001192 }
Anna Galusza2f1c1132016-03-04 18:41:35 -08001193 Fragment current = getFragmentManager().findFragmentById(mMainContentId);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001194 if (current != null && current instanceof SearchResultsSummary) {
1195 mSearchResultsFragment = (SearchResultsSummary) current;
1196 } else {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001197 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001198 SearchResultsSummary.class.getName(), null, false, true,
1199 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001200 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001201 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001202 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001203 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001204
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001205 public void needToRevertToInitialFragment() {
1206 mNeedToRevertToInitialFragment = true;
1207 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001208
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001209 private void revertToInitialFragment() {
1210 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001211 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001212 mSearchMenuItemExpanded = false;
1213 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1214 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001215 if (mSearchMenuItem != null) {
1216 mSearchMenuItem.collapseActionView();
1217 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001218 }
Jim Miller0698a212014-10-16 19:49:07 -07001219
1220 public Intent getResultIntentData() {
1221 return mResultIntentData;
1222 }
1223
1224 public void setResultIntentData(Intent resultIntentData) {
1225 mResultIntentData = resultIntentData;
1226 }
Jason Monkd4f03ec2016-01-07 16:25:34 -05001227
1228 public void startSuggestion(Intent intent) {
1229 mCurrentSuggestion = intent.getComponent();
1230 startActivityForResult(intent, REQUEST_SUGGESTION);
1231 }
1232
1233 @Override
1234 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
1235 if (requestCode == REQUEST_SUGGESTION && mCurrentSuggestion != null
1236 && resultCode != RESULT_CANCELED) {
1237 getPackageManager().setComponentEnabledSetting(mCurrentSuggestion,
1238 PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
1239 }
1240 super.onActivityResult(requestCode, resultCode, data);
1241 }
1242
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001243}