blob: bcb1ce962113e9decd231ac0ca63f42ea625c5e5 [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;
32import android.content.pm.ResolveInfo;
33import android.content.res.Configuration;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080034import android.nfc.NfcAdapter;
Jason Monkfd2c7222015-12-02 15:38:38 -050035import android.os.AsyncTask;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080036import android.os.Bundle;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080037import android.os.UserHandle;
38import android.os.UserManager;
Jason Monk39b46742015-09-10 15:52:51 -040039import android.support.v14.preference.PreferenceFragment;
40import android.support.v7.preference.Preference;
41import android.support.v7.preference.PreferenceManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080042import android.text.TextUtils;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070043import android.transition.TransitionManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080044import android.util.Log;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070045import android.view.Menu;
46import android.view.MenuInflater;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080047import android.view.MenuItem;
48import android.view.View;
49import android.view.View.OnClickListener;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070050import android.view.ViewGroup;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080051import android.widget.Button;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070052import android.widget.SearchView;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080053import com.android.internal.util.ArrayUtils;
Jason Monk4da79e02015-09-10 10:54:36 -040054import com.android.settings.Settings.WifiSettingsActivity;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080055import com.android.settings.accessibility.AccessibilitySettings;
Anna Galuszab1795f52016-01-08 14:37:16 -080056import com.android.settings.accessibility.AccessibilitySettingsForSetupWizard;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080057import com.android.settings.accessibility.CaptionPropertiesFragment;
Alexandra Gherghina6d839872014-07-22 12:04:58 +000058import com.android.settings.accounts.AccountSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080059import com.android.settings.accounts.AccountSyncSettings;
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;
Julia Reynolds2e1e0b72015-12-14 08:32:46 -050064import com.android.settings.applications.ManageDefaultApps;
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;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080084import com.android.settings.inputmethod.SpellCheckersSettings;
85import com.android.settings.inputmethod.UserDictionaryList;
Mihai Nitad7d48fd2016-01-12 08:55:05 -080086import com.android.settings.localepicker.LocaleListEditor;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080087import com.android.settings.location.LocationSettings;
88import com.android.settings.nfc.AndroidBeam;
89import com.android.settings.nfc.PaymentSettings;
John Spurlock802ddf92014-07-18 11:51:13 -040090import com.android.settings.notification.AppNotificationSettings;
Julia Reynolds8c0a4232015-11-24 10:08:14 -050091import com.android.settings.notification.ConfigureNotificationSettings;
John Spurlock4a350512014-04-08 14:08:21 -040092import com.android.settings.notification.NotificationAccessSettings;
John Spurlock4a350512014-04-08 14:08:21 -040093import com.android.settings.notification.NotificationStation;
Jason Monk2ebc8a02015-02-13 15:23:19 -050094import com.android.settings.notification.OtherSoundSettings;
Jason Monkb37e2882016-01-11 14:27:20 -050095import com.android.settings.notification.SoundSettings;
John Spurlock08531a82015-05-07 17:45:43 -040096import com.android.settings.notification.ZenAccessSettings;
John Spurlock533a5662015-06-19 10:47:36 -040097import com.android.settings.notification.ZenModeAutomationSettings;
John Spurlockf57bad72015-04-30 09:26:15 -040098import com.android.settings.notification.ZenModeEventRuleSettings;
John Spurlockc1df2aa2015-04-13 20:57:06 -040099import com.android.settings.notification.ZenModePrioritySettings;
John Spurlock45fa1402015-04-09 12:50:04 -0400100import com.android.settings.notification.ZenModeScheduleRuleSettings;
Jason Monk39b46742015-09-10 15:52:51 -0400101import com.android.settings.notification.ZenModeSettings;
Julia Reynolds5555d262015-11-09 10:52:17 -0500102import com.android.settings.notification.ZenModeVisualInterruptionSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800103import com.android.settings.print.PrintJobSettingsFragment;
104import com.android.settings.print.PrintSettingsFragment;
Jason Monk2ebc8a02015-02-13 15:23:19 -0500105import com.android.settings.search.DynamicIndexableContentMonitor;
106import com.android.settings.search.Index;
PauloftheWest38155612014-06-30 10:02:36 -0700107import com.android.settings.sim.SimSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800108import com.android.settings.tts.TextToSpeechSettings;
109import com.android.settings.users.UserSettings;
110import com.android.settings.vpn2.VpnSettings;
111import com.android.settings.wfd.WifiDisplaySettings;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700112import com.android.settings.widget.SwitchBar;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800113import com.android.settings.wifi.AdvancedWifiSettings;
PauloftheWest7837b992014-06-24 07:42:27 -0700114import com.android.settings.wifi.SavedAccessPointsWifiSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800115import com.android.settings.wifi.WifiSettings;
116import com.android.settings.wifi.p2p.WifiP2pSettings;
Jason Monk4da79e02015-09-10 10:54:36 -0400117import com.android.settingslib.drawer.DashboardCategory;
Jason Monkd4f03ec2016-01-07 16:25:34 -0500118import com.android.settingslib.drawer.Tile;
Jason Monk4da79e02015-09-10 10:54:36 -0400119import com.android.settingslib.drawer.SettingsDrawerActivity;
Jason Monk2ebc8a02015-02-13 15:23:19 -0500120
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800121import java.util.ArrayList;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800122import java.util.List;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700123import java.util.Set;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800124
Jason Monk4da79e02015-09-10 10:54:36 -0400125public class SettingsActivity extends SettingsDrawerActivity
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800126 implements PreferenceManager.OnPreferenceTreeClickListener,
127 PreferenceFragment.OnPreferenceStartFragmentCallback,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100128 ButtonBarHandler, FragmentManager.OnBackStackChangedListener,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700129 SearchView.OnQueryTextListener, SearchView.OnCloseListener,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100130 MenuItem.OnActionExpandListener {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800131
132 private static final String LOG_TAG = "Settings";
133
134 // Constants for state save/restore
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700135 private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700136 private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
137 private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700138 private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700139 private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700140 private static final String SAVE_KEY_HOME_ACTIVITIES_COUNT = ":settings:home_activities_count";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800141
142 /**
143 * When starting this activity, the invoking Intent can contain this extra
144 * string to specify which fragment should be initially displayed.
145 * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
146 * will call isValidFragment() to confirm that the fragment class name is valid for this
147 * activity.
148 */
149 public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
150
151 /**
152 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
153 * this extra can also be specified to supply a Bundle of arguments to pass
154 * to that fragment when it is instantiated during the initial creation
155 * of the activity.
156 */
157 public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
158
159 /**
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700160 * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
161 */
162 public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
163
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800164 public static final String BACK_STACK_PREFS = ":settings:prefs";
165
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800166 // extras that allow any preference activity to be launched as part of a wizard
167
168 // show Back and Next buttons? takes boolean parameter
169 // Back will then return RESULT_CANCELED and Next RESULT_OK
170 protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
171
172 // add a Skip button?
173 private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
174
175 // specify custom text for the Back or Next buttons, or cause a button to not appear
176 // at all by setting it to null
177 protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
178 protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
179
180 /**
181 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700182 * 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 -0800183 * that fragment.
184 */
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700185 public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100186 /**
187 * The package name used to resolve the title resource id.
188 */
189 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
190 ":settings:show_fragment_title_res_package_name";
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700191 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
192 ":settings:show_fragment_title_resid";
193 public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
194 ":settings:show_fragment_as_shortcut";
195
196 public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
197 ":settings:show_fragment_as_subsetting";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800198
Jason Monk30695812015-11-17 09:01:08 -0500199 public static final String META_DATA_KEY_FRAGMENT_CLASS =
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800200 "com.android.settings.FRAGMENT_CLASS";
201
202 private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
203
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700204 private static final String EMPTY_QUERY = "";
205
Jason Monkd4f03ec2016-01-07 16:25:34 -0500206 private static final int REQUEST_SUGGESTION = 42;
207
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800208 private String mFragmentClass;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800209
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800210 private CharSequence mInitialTitle;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700211 private int mInitialTitleResId;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800212
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800213 // Show only these settings for restricted users
Jason Monk4da79e02015-09-10 10:54:36 -0400214 private String[] SETTINGS_FOR_RESTRICTED = {
215 //wireless_section
216 WifiSettingsActivity.class.getName(),
217 Settings.BluetoothSettingsActivity.class.getName(),
218 Settings.DataUsageSummaryActivity.class.getName(),
219 Settings.SimSettingsActivity.class.getName(),
220 Settings.WirelessSettingsActivity.class.getName(),
221 //device_section
222 Settings.HomeSettingsActivity.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500223 Settings.SoundSettingsActivity.class.getName(),
Jason Monk4da79e02015-09-10 10:54:36 -0400224 Settings.DisplaySettingsActivity.class.getName(),
225 Settings.StorageSettingsActivity.class.getName(),
226 Settings.ManageApplicationsActivity.class.getName(),
227 Settings.PowerUsageSummaryActivity.class.getName(),
228 //personal_section
229 Settings.LocationSettingsActivity.class.getName(),
230 Settings.SecuritySettingsActivity.class.getName(),
231 Settings.InputMethodAndLanguageSettingsActivity.class.getName(),
232 Settings.UserSettingsActivity.class.getName(),
233 Settings.AccountSettingsActivity.class.getName(),
234 //system_section
235 Settings.DateTimeSettingsActivity.class.getName(),
236 Settings.DeviceInfoSettingsActivity.class.getName(),
237 Settings.AccessibilitySettingsActivity.class.getName(),
238 Settings.PrintSettingsActivity.class.getName(),
239 Settings.PaymentSettingsActivity.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800240 };
241
242 private static final String[] ENTRY_FRAGMENTS = {
243 WirelessSettings.class.getName(),
244 WifiSettings.class.getName(),
245 AdvancedWifiSettings.class.getName(),
PauloftheWest7837b992014-06-24 07:42:27 -0700246 SavedAccessPointsWifiSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800247 BluetoothSettings.class.getName(),
PauloftheWest38155612014-06-30 10:02:36 -0700248 SimSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800249 TetherSettings.class.getName(),
250 WifiP2pSettings.class.getName(),
251 VpnSettings.class.getName(),
252 DateTimeSettings.class.getName(),
Mihai Nitad7d48fd2016-01-12 08:55:05 -0800253 LocaleListEditor.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800254 InputMethodAndLanguageSettings.class.getName(),
Abodunrinwa Toki976bb3f2016-01-20 18:43:20 +0000255 AvailableVirtualKeyboardFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800256 SpellCheckersSettings.class.getName(),
257 UserDictionaryList.class.getName(),
258 UserDictionarySettings.class.getName(),
Amith Yamasani3033ce02014-07-14 18:03:15 -0700259 HomeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800260 DisplaySettings.class.getName(),
261 DeviceInfoSettings.class.getName(),
262 ManageApplications.class.getName(),
Xiyuan Xia86a55402015-06-02 14:55:32 -0700263 ManageAssist.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800264 ProcessStatsUi.class.getName(),
265 NotificationStation.class.getName(),
266 LocationSettings.class.getName(),
267 SecuritySettings.class.getName(),
Jason Monkd8da51c2015-04-17 14:34:12 -0400268 UsageAccessDetails.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800269 PrivacySettings.class.getName(),
270 DeviceAdminSettings.class.getName(),
271 AccessibilitySettings.class.getName(),
Anna Galuszab1795f52016-01-08 14:37:16 -0800272 AccessibilitySettingsForSetupWizard.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800273 CaptionPropertiesFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800274 com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(),
275 TextToSpeechSettings.class.getName(),
Jeff Sharkey42833b22015-04-11 21:27:33 -0700276 StorageSettings.class.getName(),
Jeff Sharkeya16257d2015-04-28 13:41:01 -0700277 PrivateVolumeForget.class.getName(),
Jeff Sharkeye77f0682015-04-29 11:24:57 -0700278 PrivateVolumeSettings.class.getName(),
279 PublicVolumeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800280 DevelopmentSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800281 AndroidBeam.class.getName(),
282 WifiDisplaySettings.class.getName(),
283 PowerUsageSummary.class.getName(),
284 AccountSyncSettings.class.getName(),
Alexandra Gherghina6d839872014-07-22 12:04:58 +0000285 AccountSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800286 CryptKeeperSettings.class.getName(),
287 DataUsageSummary.class.getName(),
288 DreamSettings.class.getName(),
289 UserSettings.class.getName(),
290 NotificationAccessSettings.class.getName(),
John Spurlock08531a82015-05-07 17:45:43 -0400291 ZenAccessSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800292 PrintSettingsFragment.class.getName(),
293 PrintJobSettingsFragment.class.getName(),
294 TrustedCredentialsSettings.class.getName(),
295 PaymentSettings.class.getName(),
296 KeyboardLayoutPickerFragment.class.getName(),
Abodunrinwa Toki5f0b59b2016-01-25 23:02:23 +0000297 KeyboardLayoutPickerFragment2.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700298 ZenModeSettings.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500299 SoundSettings.class.getName(),
300 ConfigureNotificationSettings.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700301 ChooseLockPassword.ChooseLockPasswordFragment.class.getName(),
302 ChooseLockPattern.ChooseLockPatternFragment.class.getName(),
John Spurlockc7f8e8c2014-06-04 19:11:22 -0400303 InstalledAppDetails.class.getName(),
304 BatterySaverSettings.class.getName(),
Fabrice Di Megliodcf59dd2014-07-21 11:22:20 -0700305 AppNotificationSettings.class.getName(),
Fabrice Di Meglioe3ff4d82014-07-23 20:03:20 -0700306 OtherSoundSettings.class.getName(),
Narayan Kamath33acb152015-03-16 12:48:05 +0000307 ApnSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400308 WifiCallingSettings.class.getName(),
John Spurlockc1df2aa2015-04-13 20:57:06 -0400309 ZenModePrioritySettings.class.getName(),
John Spurlock533a5662015-06-19 10:47:36 -0400310 ZenModeAutomationSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400311 ZenModeScheduleRuleSettings.class.getName(),
John Spurlockf57bad72015-04-30 09:26:15 -0400312 ZenModeEventRuleSettings.class.getName(),
Julia Reynolds5555d262015-11-09 10:52:17 -0500313 ZenModeVisualInterruptionSettings.class.getName(),
Jason Monk2583fc12015-03-25 09:46:30 -0400314 ProcessStatsUi.class.getName(),
Jason Monk1eb54eb2015-04-29 12:46:42 -0400315 PowerUsageDetail.class.getName(),
Jason Monk2cdafc62015-06-12 12:32:50 -0400316 ProcessStatsSummary.class.getName(),
Billy Laufee78562015-07-27 12:57:07 +0100317 DrawOverlayDetails.class.getName(),
318 WriteSettingsDetails.class.getName(),
Julia Reynolds2e1e0b72015-12-14 08:32:46 -0500319 ManageDefaultApps.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800320 };
321
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700322
323 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
324 "android.settings.APPLICATION_DETAILS_SETTINGS"
325 };
326
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800327 private SharedPreferences mDevelopmentPreferences;
328 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
329
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800330 private boolean mBatteryPresent = true;
331 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800332 @Override
333 public void onReceive(Context context, Intent intent) {
334 String action = intent.getAction();
335 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
336 boolean batteryPresent = Utils.isBatteryPresent(intent);
337
338 if (mBatteryPresent != batteryPresent) {
339 mBatteryPresent = batteryPresent;
Jason Monk4da79e02015-09-10 10:54:36 -0400340 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800341 }
342 }
343 }
344 };
345
Clara Bayarri6934a042015-10-14 11:07:35 +0100346 private final BroadcastReceiver mUserAddRemoveReceiver = new BroadcastReceiver() {
347 @Override
348 public void onReceive(Context context, Intent intent) {
349 String action = intent.getAction();
350 if (action.equals(Intent.ACTION_USER_ADDED)
351 || action.equals(Intent.ACTION_USER_REMOVED)) {
352 Index.getInstance(getApplicationContext()).update();
353 }
354 }
355 };
356
Svetoslav990159a2014-04-14 17:14:59 -0700357 private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor =
358 new DynamicIndexableContentMonitor();
Svetoslav853e4712014-04-14 10:10:25 -0700359
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700360 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700361 private SwitchBar mSwitchBar;
362
363 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700364
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700365 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700366 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700367
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700368 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700369 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700370
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700371 private ViewGroup mContent;
372
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700373 private SearchView mSearchView;
374 private MenuItem mSearchMenuItem;
375 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700376 private SearchResultsSummary mSearchResultsFragment;
377 private String mSearchQuery;
378
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700379 // Categories
380 private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800381
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700382 private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800383
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700384 private boolean mNeedToRevertToInitialFragment = false;
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700385 private int mHomeActivitiesCount = 1;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700386
Jim Miller0698a212014-10-16 19:49:07 -0700387 private Intent mResultIntentData;
Jason Monkd4f03ec2016-01-07 16:25:34 -0500388 private ComponentName mCurrentSuggestion;
Jim Miller0698a212014-10-16 19:49:07 -0700389
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700390 public SwitchBar getSwitchBar() {
391 return mSwitchBar;
392 }
393
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800394 @Override
395 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
396 // Override the fragment title for Wallpaper settings
Jason Monk39b46742015-09-10 15:52:51 -0400397 CharSequence title = pref.getTitle();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800398 if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) {
Jason Monk39b46742015-09-10 15:52:51 -0400399 title = getString(R.string.wallpaper_settings_fragment_title);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800400 }
Jason Monkb1dd5c92015-12-16 16:13:54 -0500401 startPreferencePanel(pref.getFragment(), pref.getExtras(), -1, title,
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800402 null, 0);
403 return true;
404 }
405
406 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400407 public boolean onPreferenceTreeClick(Preference preference) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800408 return false;
409 }
410
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800411 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800412 public void onConfigurationChanged(Configuration newConfig) {
413 super.onConfigurationChanged(newConfig);
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800414 Index.getInstance(this).update();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800415 }
416
417 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700418 protected void onStart() {
419 super.onStart();
420
421 if (mNeedToRevertToInitialFragment) {
422 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800423 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800424 }
425
426 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700427 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700428 if (!mDisplaySearch) {
429 return false;
430 }
431
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700432 MenuInflater inflater = getMenuInflater();
433 inflater.inflate(R.menu.options_menu, menu);
434
435 // Cache the search query (can be overriden by the OnQueryTextListener)
436 final String query = mSearchQuery;
437
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700438 mSearchMenuItem = menu.findItem(R.id.search);
439 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700440
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700441 if (mSearchMenuItem == null || mSearchView == null) {
442 return false;
443 }
444
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700445 if (mSearchResultsFragment != null) {
446 mSearchResultsFragment.setSearchView(mSearchView);
447 }
448
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700449 mSearchMenuItem.setOnActionExpandListener(this);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700450 mSearchView.setOnQueryTextListener(this);
451 mSearchView.setOnCloseListener(this);
452
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700453 if (mSearchMenuItemExpanded) {
454 mSearchMenuItem.expandActionView();
455 }
456 mSearchView.setQuery(query, true /* submit */);
457
458 return true;
459 }
460
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700461 private static boolean isShortCutIntent(final Intent intent) {
462 Set<String> categories = intent.getCategories();
463 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
464 }
465
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700466 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700467 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700468 if (action == null) {
469 return false;
470 }
471 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
472 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
473 }
474 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700475 }
476
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700477 @Override
478 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700479 super.onCreate(savedState);
Jason Monkfd2c7222015-12-02 15:38:38 -0500480 long startTime = System.currentTimeMillis();
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700481
482 // Should happen before any call to getIntent()
483 getMetaData();
484
485 final Intent intent = getIntent();
486 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
487 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800488 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800489
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800490 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
491 Context.MODE_PRIVATE);
492
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700493 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700494 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700495
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700496 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700497 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
498
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700499 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700500 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700501
Jason Monk4da79e02015-09-10 10:54:36 -0400502 mIsShowingDashboard = className.equals(Settings.class.getName())
503 || className.equals(Settings.WirelessSettings.class.getName())
504 || className.equals(Settings.DeviceSettings.class.getName())
505 || className.equals(Settings.PersonalSettings.class.getName())
506 || className.equals(Settings.WirelessSettings.class.getName());
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700507
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700508 // This is a "Sub Settings" when:
509 // - this is a real SubSettings
510 // - or :settings:show_fragment_as_subsetting is passed to the Intent
Jorim Jaggi4dfcb822015-04-29 17:21:32 -0700511 final boolean isSubSettings = this instanceof SubSettings ||
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700512 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
513
514 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
515 if (isSubSettings) {
Fabrice Di Meglio712df6c2014-07-18 17:44:37 -0700516 // Check also that we are not a Theme Dialog as we don't want to override them
517 final int themeResId = getThemeResId();
518 if (themeResId != R.style.Theme_DialogWhenLarge &&
519 themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
520 setTheme(R.style.Theme_SubSettings);
521 }
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700522 }
523
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700524 setContentView(mIsShowingDashboard ?
525 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800526
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700527 mContent = (ViewGroup) findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700528
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800529 getFragmentManager().addOnBackStackChangedListener(this);
530
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700531 if (mIsShowingDashboard) {
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800532 // Run the Index update only if we have some space
533 if (!Utils.isLowStorage(this)) {
Jason Monkfd2c7222015-12-02 15:38:38 -0500534 long indexStartTime = System.currentTimeMillis();
535 AsyncTask.execute(new Runnable() {
536 @Override
537 public void run() {
538 Index.getInstance(getApplicationContext()).update();
539 }
540 });
541 if (DEBUG_TIMING) Log.d(LOG_TAG, "Index.update() took "
542 + (System.currentTimeMillis() - indexStartTime) + " ms");
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800543 } else {
544 Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
545 }
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700546 }
547
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700548 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700549 // We are restarting from a previous saved state; used that to initialize, instead
550 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700551 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
552 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800553
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700554 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800555
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700556 ArrayList<DashboardCategory> categories =
557 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
558 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700559 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700560 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700561 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800562 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700563
564 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700565 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700566 mHomeActivitiesCount = savedState.getInt(SAVE_KEY_HOME_ACTIVITIES_COUNT,
567 1 /* one home activity by default */);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800568 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700569 if (!mIsShowingDashboard) {
Jason Monkea8b1a72015-06-02 16:46:34 -0400570 mDisplaySearch = false;
571 // UP will be shown only if it is a sub settings
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700572 if (mIsShortcut) {
573 mDisplayHomeAsUpEnabled = isSubSettings;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700574 } else if (isSubSettings) {
575 mDisplayHomeAsUpEnabled = true;
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700576 } else {
577 mDisplayHomeAsUpEnabled = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700578 }
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700579 setTitleFromIntent(intent);
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700580
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700581 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700582 switchToFragment(initialFragmentName, initialArguments, true, false,
583 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000584 } else {
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700585 // No UP affordance if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700586 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700587 // Show Search affordance
588 mDisplaySearch = true;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700589 mInitialTitleResId = R.string.dashboard_title;
Fabrice Di Meglio42c4b0a2014-05-22 10:30:03 -0700590 switchToFragment(DashboardSummary.class.getName(), null, false, false,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700591 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800592 }
593 }
594
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700595 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700596 if (mActionBar != null) {
597 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
598 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
599 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700600 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
601
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800602 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800603 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
604
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700605 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800606 if (buttonBar != null) {
607 buttonBar.setVisibility(View.VISIBLE);
608
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700609 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800610 backButton.setOnClickListener(new OnClickListener() {
611 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700612 setResult(RESULT_CANCELED, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800613 finish();
614 }
615 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700616 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800617 skipButton.setOnClickListener(new OnClickListener() {
618 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700619 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800620 finish();
621 }
622 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700623 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800624 mNextButton.setOnClickListener(new OnClickListener() {
625 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700626 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800627 finish();
628 }
629 });
630
631 // set our various button parameters
632 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
633 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
634 if (TextUtils.isEmpty(buttonText)) {
635 mNextButton.setVisibility(View.GONE);
636 }
637 else {
638 mNextButton.setText(buttonText);
639 }
640 }
641 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
642 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
643 if (TextUtils.isEmpty(buttonText)) {
644 backButton.setVisibility(View.GONE);
645 }
646 else {
647 backButton.setText(buttonText);
648 }
649 }
650 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
651 skipButton.setVisibility(View.VISIBLE);
652 }
653 }
654 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700655
656 mHomeActivitiesCount = getHomeActivitiesCount();
Jason Monkfd2c7222015-12-02 15:38:38 -0500657 if (DEBUG_TIMING) Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
658 + " ms");
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700659 }
660
661 private int getHomeActivitiesCount() {
662 final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>();
663 getPackageManager().getHomeActivities(homeApps);
664 return homeApps.size();
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800665 }
666
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700667 private void setTitleFromIntent(Intent intent) {
668 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
669 if (initialTitleResId > 0) {
670 mInitialTitle = null;
671 mInitialTitleResId = initialTitleResId;
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100672
673 final String initialTitleResPackageName = intent.getStringExtra(
674 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
675 if (initialTitleResPackageName != null) {
676 try {
677 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
678 0 /* flags */, new UserHandle(UserHandle.myUserId()));
679 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
680 setTitle(mInitialTitle);
681 mInitialTitleResId = -1;
682 return;
683 } catch (NameNotFoundException e) {
684 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
685 }
686 } else {
687 setTitle(mInitialTitleResId);
688 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700689 } else {
690 mInitialTitleResId = -1;
691 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
692 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
693 setTitle(mInitialTitle);
694 }
695 }
696
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800697 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800698 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700699 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800700 }
701
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700702 private int setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800703 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700704
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800705 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700706 if (mInitialTitleResId > 0) {
707 setTitle(mInitialTitleResId);
708 } else {
709 setTitle(mInitialTitle);
710 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700711 return 0;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800712 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700713
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800714 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
715 setTitleFromBackStackEntry(bse);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700716
717 return count;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800718 }
719
720 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
721 final CharSequence title;
722 final int titleRes = bse.getBreadCrumbTitleRes();
723 if (titleRes > 0) {
724 title = getText(titleRes);
725 } else {
726 title = bse.getBreadCrumbTitle();
727 }
728 if (title != null) {
729 setTitle(title);
730 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800731 }
732
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800733 @Override
734 protected void onSaveInstanceState(Bundle outState) {
735 super.onSaveInstanceState(outState);
736
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700737 if (mCategories.size() > 0) {
738 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800739 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700740
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700741 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700742 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700743
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700744 if (mDisplaySearch) {
745 // The option menus are created if the ActionBar is visible and they are also created
746 // asynchronously. If you launch Settings with an Intent action like
747 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
748 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
749 // menu item and search view are null.
750 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
751 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700752
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700753 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
754 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
755 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700756
757 outState.putInt(SAVE_KEY_HOME_ACTIVITIES_COUNT, mHomeActivitiesCount);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800758 }
759
760 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400761 protected void onResume() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800762 super.onResume();
763
764 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
765 @Override
766 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Jason Monk4da79e02015-09-10 10:54:36 -0400767 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800768 }
769 };
770 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
771 mDevelopmentPreferencesListener);
772
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800773 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Clara Bayarri6934a042015-10-14 11:07:35 +0100774 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_ADDED));
775 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_REMOVED));
Svetoslav853e4712014-04-14 10:10:25 -0700776
Svetoslav990159a2014-04-14 17:14:59 -0700777 mDynamicIndexableContentMonitor.register(this);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700778
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700779 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700780 onQueryTextSubmit(mSearchQuery);
781 }
Jason Monk4da79e02015-09-10 10:54:36 -0400782 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800783 }
784
785 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400786 protected void onPause() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800787 super.onPause();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800788 unregisterReceiver(mBatteryInfoReceiver);
Clara Bayarri8c9521f2016-01-12 14:10:45 +0000789 unregisterReceiver(mUserAddRemoveReceiver);
Svetoslav990159a2014-04-14 17:14:59 -0700790 mDynamicIndexableContentMonitor.unregister();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800791 }
792
793 @Override
794 public void onDestroy() {
795 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700796
797 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
798 mDevelopmentPreferencesListener);
799 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800800 }
801
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800802 protected boolean isValidFragment(String fragmentName) {
803 // Almost all fragments are wrapped in this,
804 // except for a few that have their own activities.
805 for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
806 if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
807 }
808 return false;
809 }
810
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800811 @Override
812 public Intent getIntent() {
813 Intent superIntent = super.getIntent();
814 String startingFragment = getStartingFragmentClass(superIntent);
815 // This is called from super.onCreate, isMultiPane() is not yet reliable
816 // Do not use onIsHidingHeaders either, which relies itself on this method
817 if (startingFragment != null) {
818 Intent modIntent = new Intent(superIntent);
819 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
820 Bundle args = superIntent.getExtras();
821 if (args != null) {
822 args = new Bundle(args);
823 } else {
824 args = new Bundle();
825 }
826 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100827 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800828 return modIntent;
829 }
830 return superIntent;
831 }
832
833 /**
834 * Checks if the component name in the intent is different from the Settings class and
835 * returns the class name to load as a fragment.
836 */
837 private String getStartingFragmentClass(Intent intent) {
838 if (mFragmentClass != null) return mFragmentClass;
839
840 String intentClass = intent.getComponent().getClassName();
841 if (intentClass.equals(getClass().getName())) return null;
842
843 if ("com.android.settings.ManageApplications".equals(intentClass)
844 || "com.android.settings.RunningServices".equals(intentClass)
845 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
846 // Old names of manage apps.
847 intentClass = com.android.settings.applications.ManageApplications.class.getName();
848 }
849
850 return intentClass;
851 }
852
853 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000854 * Start a new fragment containing a preference panel. If the preferences
855 * are being displayed in multi-pane mode, the given fragment class will
856 * be instantiated and placed in the appropriate pane. If running in
857 * single-pane mode, a new activity will be launched in which to show the
858 * fragment.
859 *
860 * @param fragmentClass Full name of the class implementing the fragment.
861 * @param args Any desired arguments to supply to the fragment.
862 * @param titleRes Optional resource identifier of the title of this
863 * fragment.
864 * @param titleText Optional text of the title of this fragment.
865 * @param resultTo Optional fragment that result data should be sent to.
866 * If non-null, resultTo.onActivityResult() will be called when this
867 * preference panel is done. The launched panel must use
868 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
869 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700870 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000871 */
872 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700873 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700874 String title = null;
875 if (titleRes < 0) {
876 if (titleText != null) {
877 title = titleText.toString();
878 } else {
879 // There not much we can do in that case
880 title = "";
881 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700882 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700883 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700884 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000885 }
886
887 /**
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100888 * Start a new fragment in a new activity containing a preference panel for a given user. If the
889 * preferences are being displayed in multi-pane mode, the given fragment class will be
890 * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
891 * activity will be launched in which to show the fragment.
892 *
893 * @param fragmentClass Full name of the class implementing the fragment.
894 * @param args Any desired arguments to supply to the fragment.
895 * @param titleRes Optional resource identifier of the title of this fragment.
896 * @param titleText Optional text of the title of this fragment.
897 * @param userHandle The user for which the panel has to be started.
898 */
899 public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
900 CharSequence titleText, UserHandle userHandle) {
Lifu Tangd0332852015-04-02 12:05:46 -0700901 // This is a workaround.
902 //
903 // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
904 // starting the fragment could cause a native stack corruption. See b/17523189. However,
905 // adding that flag and start the preference panel with the same UserHandler will make it
906 // impossible to use back button to return to the previous screen. See b/20042570.
907 //
908 // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
909 // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
910 // when we're calling it as the same user.
911 if (userHandle.getIdentifier() == UserHandle.myUserId()) {
912 startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0);
913 } else {
914 String title = null;
915 if (titleRes < 0) {
916 if (titleText != null) {
917 title = titleText.toString();
918 } else {
919 // There not much we can do in that case
920 title = "";
921 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100922 }
Lifu Tangd0332852015-04-02 12:05:46 -0700923 Utils.startWithFragmentAsUser(this, fragmentClass, args,
924 titleRes, title, mIsShortcut, userHandle);
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100925 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100926 }
927
928 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800929 * Called by a preference panel fragment to finish itself.
930 *
931 * @param caller The fragment that is asking to be finished.
932 * @param resultCode Optional result code to send back to the original
933 * launching fragment.
934 * @param resultData Optional result data to send back to the original
935 * launching fragment.
936 */
937 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
938 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700939 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800940 }
941
942 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000943 * Start a new fragment.
944 *
945 * @param fragment The fragment to start
946 * @param push If true, the current fragment will be pushed onto the back stack. If false,
947 * the current fragment will be replaced.
948 */
949 public void startPreferenceFragment(Fragment fragment, boolean push) {
950 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700951 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000952 if (push) {
953 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
954 transaction.addToBackStack(BACK_STACK_PREFS);
955 } else {
956 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
957 }
958 transaction.commitAllowingStateLoss();
959 }
960
961 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700962 * Switch to a specific Fragment with taking care of validation, Title and BackStack
963 */
964 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700965 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700966 if (validate && !isValidFragment(fragmentName)) {
967 throw new IllegalArgumentException("Invalid fragment for this activity: "
968 + fragmentName);
969 }
970 Fragment f = Fragment.instantiate(this, fragmentName, args);
971 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700972 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700973 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700974 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700975 }
976 if (addToBackStack) {
977 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
978 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700979 if (titleResId > 0) {
980 transaction.setBreadCrumbTitle(titleResId);
981 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700982 transaction.setBreadCrumbTitle(title);
983 }
984 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700985 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700986 return f;
987 }
988
Jason Monk4da79e02015-09-10 10:54:36 -0400989 private void updateTilesList() {
Jason Monkfd2c7222015-12-02 15:38:38 -0500990 // Generally the items that are will be changing from these updates will
991 // not be in the top list of tiles, so run it in the background and the
992 // SettingsDrawerActivity will pick up on the updates automatically.
993 AsyncTask.execute(new Runnable() {
994 @Override
995 public void run() {
996 doUpdateTilesList();
997 }
998 });
999 }
1000
1001 private void doUpdateTilesList() {
Jason Monk4da79e02015-09-10 10:54:36 -04001002 PackageManager pm = getPackageManager();
Xiaohui Chen44879a32015-07-22 13:53:22 -07001003 final UserManager um = UserManager.get(this);
1004 final boolean isAdmin = um.isAdminUser();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001005
Jason Monk4da79e02015-09-10 10:54:36 -04001006 String packageName = getPackageName();
1007 setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()),
1008 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001009
Jason Monk4da79e02015-09-10 10:54:36 -04001010 setTileEnabled(new ComponentName(packageName,
1011 Settings.BluetoothSettingsActivity.class.getName()),
1012 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001013
Jason Monk4da79e02015-09-10 10:54:36 -04001014 setTileEnabled(new ComponentName(packageName,
1015 Settings.DataUsageSummaryActivity.class.getName()),
1016 Utils.isBandwidthControlEnabled(), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001017
Jason Monk4da79e02015-09-10 10:54:36 -04001018 setTileEnabled(new ComponentName(packageName,
1019 Settings.SimSettingsActivity.class.getName()),
1020 Utils.showSimCardTile(this), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001021
Jason Monk4da79e02015-09-10 10:54:36 -04001022 setTileEnabled(new ComponentName(packageName,
1023 Settings.PowerUsageSummaryActivity.class.getName()),
1024 mBatteryPresent, isAdmin, pm);
1025
1026 setTileEnabled(new ComponentName(packageName,
1027 Settings.HomeSettingsActivity.class.getName()),
1028 updateHomeSettingTiles(), isAdmin, pm);
1029
1030 setTileEnabled(new ComponentName(packageName,
1031 Settings.UserSettingsActivity.class.getName()),
1032 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
1033 && !Utils.isMonkeyRunning(), isAdmin, pm);
1034
1035 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
1036 setTileEnabled(new ComponentName(packageName,
1037 Settings.PaymentSettingsActivity.class.getName()),
1038 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
1039 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
1040 && adapter != null && adapter.isEnabled(), isAdmin, pm);
1041
1042 setTileEnabled(new ComponentName(packageName,
1043 Settings.PrintSettingsActivity.class.getName()),
1044 pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin, pm);
1045
1046 final boolean showDev = mDevelopmentPreferences.getBoolean(
1047 DevelopmentSettings.PREF_SHOW,
1048 android.os.Build.TYPE.equals("eng"));
1049 setTileEnabled(new ComponentName(packageName,
1050 Settings.DevelopmentSettingsActivity.class.getName()),
1051 showDev && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES),
1052 isAdmin, pm);
1053
1054 if (UserHandle.MU_ENABLED && !isAdmin) {
1055 // When on restricted users, disable all extra categories (but only the settings ones).
Jason Monkfd2c7222015-12-02 15:38:38 -05001056 List<DashboardCategory> categories = getDashboardCategories();
Jason Monk4da79e02015-09-10 10:54:36 -04001057 for (DashboardCategory category : categories) {
Jason Monkd4f03ec2016-01-07 16:25:34 -05001058 for (Tile tile : category.tiles) {
Jason Monk4da79e02015-09-10 10:54:36 -04001059 ComponentName component = tile.intent.getComponent();
1060 if (packageName.equals(component)&& !ArrayUtils.contains(
1061 SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1062 setTileEnabled(component, false, isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001063 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001064 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001065 }
1066 }
Jason Monk2ebc8a02015-02-13 15:23:19 -05001067 }
1068
Jason Monk4da79e02015-09-10 10:54:36 -04001069 private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin,
1070 PackageManager pm) {
1071 if (UserHandle.MU_ENABLED && !isAdmin
1072 && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1073 enabled = false;
1074 }
1075 int state = pm.getComponentEnabledSetting(component);
1076 boolean isEnabled = state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
1077 || state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
1078 if (isEnabled != enabled) {
1079 pm.setComponentEnabledSetting(component, enabled
1080 ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
1081 : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
1082 PackageManager.DONT_KILL_APP);
Jason Monk2ebc8a02015-02-13 15:23:19 -05001083 }
1084 }
1085
Jason Monk4da79e02015-09-10 10:54:36 -04001086 private boolean updateHomeSettingTiles() {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001087 // Once we decide to show Home settings, keep showing it forever
1088 SharedPreferences sp = getSharedPreferences(HomeSettings.HOME_PREFS, Context.MODE_PRIVATE);
1089 if (sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false)) {
1090 return true;
1091 }
1092
1093 try {
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -07001094 mHomeActivitiesCount = getHomeActivitiesCount();
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -07001095 if (mHomeActivitiesCount < 2) {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001096 return false;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001097 }
1098 } catch (Exception e) {
1099 // Can't look up the home activity; bail on configuring the icon
1100 Log.w(LOG_TAG, "Problem looking up home activity!", e);
1101 }
1102
1103 sp.edit().putBoolean(HomeSettings.HOME_PREFS_DO_SHOW, true).apply();
1104 return true;
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 }
Fabrice Di Megliod40dd452014-07-18 15:20:34 -07001193 Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
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}