blob: 62cd2f0e1ca4b822ee9471b06b9253c373139da7 [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;
56import 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;
Billy Laufee78562015-07-27 12:57:07 +010059import com.android.settings.applications.DrawOverlayDetails;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070060import com.android.settings.applications.InstalledAppDetails;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080061import com.android.settings.applications.ManageApplications;
Xiyuan Xia86a55402015-06-02 14:55:32 -070062import com.android.settings.applications.ManageAssist;
Julia Reynolds2e1e0b72015-12-14 08:32:46 -050063import com.android.settings.applications.ManageDefaultApps;
Jason Monk2cdafc62015-06-12 12:32:50 -040064import com.android.settings.applications.ProcessStatsSummary;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080065import com.android.settings.applications.ProcessStatsUi;
Jason Monkd8da51c2015-04-17 14:34:12 -040066import com.android.settings.applications.UsageAccessDetails;
Billy Laufee78562015-07-27 12:57:07 +010067import com.android.settings.applications.WriteSettingsDetails;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080068import com.android.settings.bluetooth.BluetoothSettings;
69import com.android.settings.dashboard.DashboardSummary;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070070import com.android.settings.dashboard.SearchResultsSummary;
Jason Monkb37e2882016-01-11 14:27:20 -050071import com.android.settings.datausage.DataUsageSummary;
Jeff Sharkeya16257d2015-04-28 13:41:01 -070072import com.android.settings.deviceinfo.PrivateVolumeForget;
Jeff Sharkeye77f0682015-04-29 11:24:57 -070073import com.android.settings.deviceinfo.PrivateVolumeSettings;
Jeff Sharkey42833b22015-04-11 21:27:33 -070074import com.android.settings.deviceinfo.PublicVolumeSettings;
75import com.android.settings.deviceinfo.StorageSettings;
John Spurlockc7f8e8c2014-06-04 19:11:22 -040076import com.android.settings.fuelgauge.BatterySaverSettings;
Jason Monk1eb54eb2015-04-29 12:46:42 -040077import com.android.settings.fuelgauge.PowerUsageDetail;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080078import com.android.settings.fuelgauge.PowerUsageSummary;
79import com.android.settings.inputmethod.InputMethodAndLanguageSettings;
80import com.android.settings.inputmethod.KeyboardLayoutPickerFragment;
81import com.android.settings.inputmethod.SpellCheckersSettings;
82import com.android.settings.inputmethod.UserDictionaryList;
Mihai Nitad7d48fd2016-01-12 08:55:05 -080083import com.android.settings.localepicker.LocaleListEditor;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080084import com.android.settings.location.LocationSettings;
85import com.android.settings.nfc.AndroidBeam;
86import com.android.settings.nfc.PaymentSettings;
John Spurlock802ddf92014-07-18 11:51:13 -040087import com.android.settings.notification.AppNotificationSettings;
Julia Reynolds8c0a4232015-11-24 10:08:14 -050088import com.android.settings.notification.ConfigureNotificationSettings;
John Spurlock4a350512014-04-08 14:08:21 -040089import com.android.settings.notification.NotificationAccessSettings;
John Spurlock4a350512014-04-08 14:08:21 -040090import com.android.settings.notification.NotificationStation;
Jason Monk2ebc8a02015-02-13 15:23:19 -050091import com.android.settings.notification.OtherSoundSettings;
Jason Monkb37e2882016-01-11 14:27:20 -050092import com.android.settings.notification.SoundSettings;
John Spurlock08531a82015-05-07 17:45:43 -040093import com.android.settings.notification.ZenAccessSettings;
John Spurlock533a5662015-06-19 10:47:36 -040094import com.android.settings.notification.ZenModeAutomationSettings;
John Spurlockf57bad72015-04-30 09:26:15 -040095import com.android.settings.notification.ZenModeEventRuleSettings;
John Spurlockc1df2aa2015-04-13 20:57:06 -040096import com.android.settings.notification.ZenModePrioritySettings;
John Spurlock45fa1402015-04-09 12:50:04 -040097import com.android.settings.notification.ZenModeScheduleRuleSettings;
Jason Monk39b46742015-09-10 15:52:51 -040098import com.android.settings.notification.ZenModeSettings;
Julia Reynolds5555d262015-11-09 10:52:17 -050099import com.android.settings.notification.ZenModeVisualInterruptionSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800100import com.android.settings.print.PrintJobSettingsFragment;
101import com.android.settings.print.PrintSettingsFragment;
Jason Monk2ebc8a02015-02-13 15:23:19 -0500102import com.android.settings.search.DynamicIndexableContentMonitor;
103import com.android.settings.search.Index;
PauloftheWest38155612014-06-30 10:02:36 -0700104import com.android.settings.sim.SimSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800105import com.android.settings.tts.TextToSpeechSettings;
106import com.android.settings.users.UserSettings;
107import com.android.settings.vpn2.VpnSettings;
108import com.android.settings.wfd.WifiDisplaySettings;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700109import com.android.settings.widget.SwitchBar;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800110import com.android.settings.wifi.AdvancedWifiSettings;
PauloftheWest7837b992014-06-24 07:42:27 -0700111import com.android.settings.wifi.SavedAccessPointsWifiSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800112import com.android.settings.wifi.WifiSettings;
113import com.android.settings.wifi.p2p.WifiP2pSettings;
Jason Monk4da79e02015-09-10 10:54:36 -0400114import com.android.settingslib.drawer.DashboardCategory;
Jason Monkd4f03ec2016-01-07 16:25:34 -0500115import com.android.settingslib.drawer.Tile;
Jason Monk4da79e02015-09-10 10:54:36 -0400116import com.android.settingslib.drawer.SettingsDrawerActivity;
Jason Monk2ebc8a02015-02-13 15:23:19 -0500117
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800118import java.util.ArrayList;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800119import java.util.List;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700120import java.util.Set;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800121
Jason Monk4da79e02015-09-10 10:54:36 -0400122public class SettingsActivity extends SettingsDrawerActivity
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800123 implements PreferenceManager.OnPreferenceTreeClickListener,
124 PreferenceFragment.OnPreferenceStartFragmentCallback,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100125 ButtonBarHandler, FragmentManager.OnBackStackChangedListener,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700126 SearchView.OnQueryTextListener, SearchView.OnCloseListener,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100127 MenuItem.OnActionExpandListener {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800128
129 private static final String LOG_TAG = "Settings";
130
131 // Constants for state save/restore
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700132 private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700133 private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
134 private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700135 private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700136 private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700137 private static final String SAVE_KEY_HOME_ACTIVITIES_COUNT = ":settings:home_activities_count";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800138
139 /**
140 * When starting this activity, the invoking Intent can contain this extra
141 * string to specify which fragment should be initially displayed.
142 * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
143 * will call isValidFragment() to confirm that the fragment class name is valid for this
144 * activity.
145 */
146 public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
147
148 /**
149 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
150 * this extra can also be specified to supply a Bundle of arguments to pass
151 * to that fragment when it is instantiated during the initial creation
152 * of the activity.
153 */
154 public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
155
156 /**
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700157 * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
158 */
159 public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
160
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800161 public static final String BACK_STACK_PREFS = ":settings:prefs";
162
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800163 // extras that allow any preference activity to be launched as part of a wizard
164
165 // show Back and Next buttons? takes boolean parameter
166 // Back will then return RESULT_CANCELED and Next RESULT_OK
167 protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
168
169 // add a Skip button?
170 private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
171
172 // specify custom text for the Back or Next buttons, or cause a button to not appear
173 // at all by setting it to null
174 protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
175 protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
176
177 /**
178 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700179 * 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 -0800180 * that fragment.
181 */
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700182 public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100183 /**
184 * The package name used to resolve the title resource id.
185 */
186 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
187 ":settings:show_fragment_title_res_package_name";
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700188 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
189 ":settings:show_fragment_title_resid";
190 public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
191 ":settings:show_fragment_as_shortcut";
192
193 public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
194 ":settings:show_fragment_as_subsetting";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800195
Jason Monk30695812015-11-17 09:01:08 -0500196 public static final String META_DATA_KEY_FRAGMENT_CLASS =
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800197 "com.android.settings.FRAGMENT_CLASS";
198
199 private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
200
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700201 private static final String EMPTY_QUERY = "";
202
Jason Monkd4f03ec2016-01-07 16:25:34 -0500203 private static final int REQUEST_SUGGESTION = 42;
204
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800205 private String mFragmentClass;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800206
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800207 private CharSequence mInitialTitle;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700208 private int mInitialTitleResId;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800209
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800210 // Show only these settings for restricted users
Jason Monk4da79e02015-09-10 10:54:36 -0400211 private String[] SETTINGS_FOR_RESTRICTED = {
212 //wireless_section
213 WifiSettingsActivity.class.getName(),
214 Settings.BluetoothSettingsActivity.class.getName(),
215 Settings.DataUsageSummaryActivity.class.getName(),
216 Settings.SimSettingsActivity.class.getName(),
217 Settings.WirelessSettingsActivity.class.getName(),
218 //device_section
219 Settings.HomeSettingsActivity.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500220 Settings.SoundSettingsActivity.class.getName(),
Jason Monk4da79e02015-09-10 10:54:36 -0400221 Settings.DisplaySettingsActivity.class.getName(),
222 Settings.StorageSettingsActivity.class.getName(),
223 Settings.ManageApplicationsActivity.class.getName(),
224 Settings.PowerUsageSummaryActivity.class.getName(),
225 //personal_section
226 Settings.LocationSettingsActivity.class.getName(),
227 Settings.SecuritySettingsActivity.class.getName(),
228 Settings.InputMethodAndLanguageSettingsActivity.class.getName(),
229 Settings.UserSettingsActivity.class.getName(),
230 Settings.AccountSettingsActivity.class.getName(),
231 //system_section
232 Settings.DateTimeSettingsActivity.class.getName(),
233 Settings.DeviceInfoSettingsActivity.class.getName(),
234 Settings.AccessibilitySettingsActivity.class.getName(),
235 Settings.PrintSettingsActivity.class.getName(),
236 Settings.PaymentSettingsActivity.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800237 };
238
239 private static final String[] ENTRY_FRAGMENTS = {
240 WirelessSettings.class.getName(),
241 WifiSettings.class.getName(),
242 AdvancedWifiSettings.class.getName(),
PauloftheWest7837b992014-06-24 07:42:27 -0700243 SavedAccessPointsWifiSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800244 BluetoothSettings.class.getName(),
PauloftheWest38155612014-06-30 10:02:36 -0700245 SimSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800246 TetherSettings.class.getName(),
247 WifiP2pSettings.class.getName(),
248 VpnSettings.class.getName(),
249 DateTimeSettings.class.getName(),
Mihai Nitad7d48fd2016-01-12 08:55:05 -0800250 LocaleListEditor.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800251 InputMethodAndLanguageSettings.class.getName(),
252 SpellCheckersSettings.class.getName(),
253 UserDictionaryList.class.getName(),
254 UserDictionarySettings.class.getName(),
Amith Yamasani3033ce02014-07-14 18:03:15 -0700255 HomeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800256 DisplaySettings.class.getName(),
257 DeviceInfoSettings.class.getName(),
258 ManageApplications.class.getName(),
Xiyuan Xia86a55402015-06-02 14:55:32 -0700259 ManageAssist.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800260 ProcessStatsUi.class.getName(),
261 NotificationStation.class.getName(),
262 LocationSettings.class.getName(),
263 SecuritySettings.class.getName(),
Jason Monkd8da51c2015-04-17 14:34:12 -0400264 UsageAccessDetails.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800265 PrivacySettings.class.getName(),
266 DeviceAdminSettings.class.getName(),
267 AccessibilitySettings.class.getName(),
268 CaptionPropertiesFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800269 com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(),
270 TextToSpeechSettings.class.getName(),
Jeff Sharkey42833b22015-04-11 21:27:33 -0700271 StorageSettings.class.getName(),
Jeff Sharkeya16257d2015-04-28 13:41:01 -0700272 PrivateVolumeForget.class.getName(),
Jeff Sharkeye77f0682015-04-29 11:24:57 -0700273 PrivateVolumeSettings.class.getName(),
274 PublicVolumeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800275 DevelopmentSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800276 AndroidBeam.class.getName(),
277 WifiDisplaySettings.class.getName(),
278 PowerUsageSummary.class.getName(),
279 AccountSyncSettings.class.getName(),
Alexandra Gherghina6d839872014-07-22 12:04:58 +0000280 AccountSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800281 CryptKeeperSettings.class.getName(),
282 DataUsageSummary.class.getName(),
283 DreamSettings.class.getName(),
284 UserSettings.class.getName(),
285 NotificationAccessSettings.class.getName(),
John Spurlock08531a82015-05-07 17:45:43 -0400286 ZenAccessSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800287 PrintSettingsFragment.class.getName(),
288 PrintJobSettingsFragment.class.getName(),
289 TrustedCredentialsSettings.class.getName(),
290 PaymentSettings.class.getName(),
291 KeyboardLayoutPickerFragment.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700292 ZenModeSettings.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500293 SoundSettings.class.getName(),
294 ConfigureNotificationSettings.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700295 ChooseLockPassword.ChooseLockPasswordFragment.class.getName(),
296 ChooseLockPattern.ChooseLockPatternFragment.class.getName(),
John Spurlockc7f8e8c2014-06-04 19:11:22 -0400297 InstalledAppDetails.class.getName(),
298 BatterySaverSettings.class.getName(),
Fabrice Di Megliodcf59dd2014-07-21 11:22:20 -0700299 AppNotificationSettings.class.getName(),
Fabrice Di Meglioe3ff4d82014-07-23 20:03:20 -0700300 OtherSoundSettings.class.getName(),
Narayan Kamath33acb152015-03-16 12:48:05 +0000301 ApnSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400302 WifiCallingSettings.class.getName(),
John Spurlockc1df2aa2015-04-13 20:57:06 -0400303 ZenModePrioritySettings.class.getName(),
John Spurlock533a5662015-06-19 10:47:36 -0400304 ZenModeAutomationSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400305 ZenModeScheduleRuleSettings.class.getName(),
John Spurlockf57bad72015-04-30 09:26:15 -0400306 ZenModeEventRuleSettings.class.getName(),
Julia Reynolds5555d262015-11-09 10:52:17 -0500307 ZenModeVisualInterruptionSettings.class.getName(),
Jason Monk2583fc12015-03-25 09:46:30 -0400308 ProcessStatsUi.class.getName(),
Jason Monk1eb54eb2015-04-29 12:46:42 -0400309 PowerUsageDetail.class.getName(),
Jason Monk2cdafc62015-06-12 12:32:50 -0400310 ProcessStatsSummary.class.getName(),
Billy Laufee78562015-07-27 12:57:07 +0100311 DrawOverlayDetails.class.getName(),
312 WriteSettingsDetails.class.getName(),
Julia Reynolds2e1e0b72015-12-14 08:32:46 -0500313 ManageDefaultApps.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800314 };
315
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700316
317 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
318 "android.settings.APPLICATION_DETAILS_SETTINGS"
319 };
320
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800321 private SharedPreferences mDevelopmentPreferences;
322 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
323
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800324 private boolean mBatteryPresent = true;
325 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800326 @Override
327 public void onReceive(Context context, Intent intent) {
328 String action = intent.getAction();
329 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
330 boolean batteryPresent = Utils.isBatteryPresent(intent);
331
332 if (mBatteryPresent != batteryPresent) {
333 mBatteryPresent = batteryPresent;
Jason Monk4da79e02015-09-10 10:54:36 -0400334 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800335 }
336 }
337 }
338 };
339
Clara Bayarri6934a042015-10-14 11:07:35 +0100340 private final BroadcastReceiver mUserAddRemoveReceiver = new BroadcastReceiver() {
341 @Override
342 public void onReceive(Context context, Intent intent) {
343 String action = intent.getAction();
344 if (action.equals(Intent.ACTION_USER_ADDED)
345 || action.equals(Intent.ACTION_USER_REMOVED)) {
346 Index.getInstance(getApplicationContext()).update();
347 }
348 }
349 };
350
Svetoslav990159a2014-04-14 17:14:59 -0700351 private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor =
352 new DynamicIndexableContentMonitor();
Svetoslav853e4712014-04-14 10:10:25 -0700353
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700354 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700355 private SwitchBar mSwitchBar;
356
357 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700358
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700359 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700360 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700361
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700362 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700363 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700364
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700365 private ViewGroup mContent;
366
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700367 private SearchView mSearchView;
368 private MenuItem mSearchMenuItem;
369 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700370 private SearchResultsSummary mSearchResultsFragment;
371 private String mSearchQuery;
372
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700373 // Categories
374 private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800375
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700376 private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800377
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700378 private boolean mNeedToRevertToInitialFragment = false;
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700379 private int mHomeActivitiesCount = 1;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700380
Jim Miller0698a212014-10-16 19:49:07 -0700381 private Intent mResultIntentData;
Jason Monkd4f03ec2016-01-07 16:25:34 -0500382 private ComponentName mCurrentSuggestion;
Jim Miller0698a212014-10-16 19:49:07 -0700383
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700384 public SwitchBar getSwitchBar() {
385 return mSwitchBar;
386 }
387
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800388 @Override
389 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
390 // Override the fragment title for Wallpaper settings
Jason Monk39b46742015-09-10 15:52:51 -0400391 CharSequence title = pref.getTitle();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800392 if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) {
Jason Monk39b46742015-09-10 15:52:51 -0400393 title = getString(R.string.wallpaper_settings_fragment_title);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800394 }
Jason Monkb1dd5c92015-12-16 16:13:54 -0500395 startPreferencePanel(pref.getFragment(), pref.getExtras(), -1, title,
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800396 null, 0);
397 return true;
398 }
399
400 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400401 public boolean onPreferenceTreeClick(Preference preference) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800402 return false;
403 }
404
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800405 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800406 public void onConfigurationChanged(Configuration newConfig) {
407 super.onConfigurationChanged(newConfig);
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800408 Index.getInstance(this).update();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800409 }
410
411 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700412 protected void onStart() {
413 super.onStart();
414
415 if (mNeedToRevertToInitialFragment) {
416 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800417 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800418 }
419
420 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700421 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700422 if (!mDisplaySearch) {
423 return false;
424 }
425
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700426 MenuInflater inflater = getMenuInflater();
427 inflater.inflate(R.menu.options_menu, menu);
428
429 // Cache the search query (can be overriden by the OnQueryTextListener)
430 final String query = mSearchQuery;
431
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700432 mSearchMenuItem = menu.findItem(R.id.search);
433 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700434
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700435 if (mSearchMenuItem == null || mSearchView == null) {
436 return false;
437 }
438
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700439 if (mSearchResultsFragment != null) {
440 mSearchResultsFragment.setSearchView(mSearchView);
441 }
442
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700443 mSearchMenuItem.setOnActionExpandListener(this);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700444 mSearchView.setOnQueryTextListener(this);
445 mSearchView.setOnCloseListener(this);
446
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700447 if (mSearchMenuItemExpanded) {
448 mSearchMenuItem.expandActionView();
449 }
450 mSearchView.setQuery(query, true /* submit */);
451
452 return true;
453 }
454
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700455 private static boolean isShortCutIntent(final Intent intent) {
456 Set<String> categories = intent.getCategories();
457 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
458 }
459
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700460 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700461 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700462 if (action == null) {
463 return false;
464 }
465 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
466 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
467 }
468 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700469 }
470
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700471 @Override
472 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700473 super.onCreate(savedState);
Jason Monkfd2c7222015-12-02 15:38:38 -0500474 long startTime = System.currentTimeMillis();
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700475
476 // Should happen before any call to getIntent()
477 getMetaData();
478
479 final Intent intent = getIntent();
480 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
481 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800482 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800483
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800484 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
485 Context.MODE_PRIVATE);
486
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700487 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700488 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700489
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700490 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700491 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
492
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700493 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700494 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700495
Jason Monk4da79e02015-09-10 10:54:36 -0400496 mIsShowingDashboard = className.equals(Settings.class.getName())
497 || className.equals(Settings.WirelessSettings.class.getName())
498 || className.equals(Settings.DeviceSettings.class.getName())
499 || className.equals(Settings.PersonalSettings.class.getName())
500 || className.equals(Settings.WirelessSettings.class.getName());
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700501
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700502 // This is a "Sub Settings" when:
503 // - this is a real SubSettings
504 // - or :settings:show_fragment_as_subsetting is passed to the Intent
Jorim Jaggi4dfcb822015-04-29 17:21:32 -0700505 final boolean isSubSettings = this instanceof SubSettings ||
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700506 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
507
508 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
509 if (isSubSettings) {
Fabrice Di Meglio712df6c2014-07-18 17:44:37 -0700510 // Check also that we are not a Theme Dialog as we don't want to override them
511 final int themeResId = getThemeResId();
512 if (themeResId != R.style.Theme_DialogWhenLarge &&
513 themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
514 setTheme(R.style.Theme_SubSettings);
515 }
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700516 }
517
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700518 setContentView(mIsShowingDashboard ?
519 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800520
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700521 mContent = (ViewGroup) findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700522
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800523 getFragmentManager().addOnBackStackChangedListener(this);
524
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700525 if (mIsShowingDashboard) {
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800526 // Run the Index update only if we have some space
527 if (!Utils.isLowStorage(this)) {
Jason Monkfd2c7222015-12-02 15:38:38 -0500528 long indexStartTime = System.currentTimeMillis();
529 AsyncTask.execute(new Runnable() {
530 @Override
531 public void run() {
532 Index.getInstance(getApplicationContext()).update();
533 }
534 });
535 if (DEBUG_TIMING) Log.d(LOG_TAG, "Index.update() took "
536 + (System.currentTimeMillis() - indexStartTime) + " ms");
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800537 } else {
538 Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
539 }
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700540 }
541
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700542 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700543 // We are restarting from a previous saved state; used that to initialize, instead
544 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700545 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
546 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800547
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700548 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800549
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700550 ArrayList<DashboardCategory> categories =
551 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
552 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700553 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700554 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700555 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800556 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700557
558 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700559 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700560 mHomeActivitiesCount = savedState.getInt(SAVE_KEY_HOME_ACTIVITIES_COUNT,
561 1 /* one home activity by default */);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800562 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700563 if (!mIsShowingDashboard) {
Jason Monkea8b1a72015-06-02 16:46:34 -0400564 mDisplaySearch = false;
565 // UP will be shown only if it is a sub settings
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700566 if (mIsShortcut) {
567 mDisplayHomeAsUpEnabled = isSubSettings;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700568 } else if (isSubSettings) {
569 mDisplayHomeAsUpEnabled = true;
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700570 } else {
571 mDisplayHomeAsUpEnabled = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700572 }
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700573 setTitleFromIntent(intent);
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700574
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700575 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700576 switchToFragment(initialFragmentName, initialArguments, true, false,
577 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000578 } else {
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700579 // No UP affordance if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700580 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700581 // Show Search affordance
582 mDisplaySearch = true;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700583 mInitialTitleResId = R.string.dashboard_title;
Fabrice Di Meglio42c4b0a2014-05-22 10:30:03 -0700584 switchToFragment(DashboardSummary.class.getName(), null, false, false,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700585 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800586 }
587 }
588
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700589 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700590 if (mActionBar != null) {
591 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
592 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
593 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700594 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
595
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800596 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800597 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
598
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700599 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800600 if (buttonBar != null) {
601 buttonBar.setVisibility(View.VISIBLE);
602
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700603 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800604 backButton.setOnClickListener(new OnClickListener() {
605 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700606 setResult(RESULT_CANCELED, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800607 finish();
608 }
609 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700610 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800611 skipButton.setOnClickListener(new OnClickListener() {
612 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700613 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800614 finish();
615 }
616 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700617 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800618 mNextButton.setOnClickListener(new OnClickListener() {
619 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700620 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800621 finish();
622 }
623 });
624
625 // set our various button parameters
626 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
627 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
628 if (TextUtils.isEmpty(buttonText)) {
629 mNextButton.setVisibility(View.GONE);
630 }
631 else {
632 mNextButton.setText(buttonText);
633 }
634 }
635 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
636 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
637 if (TextUtils.isEmpty(buttonText)) {
638 backButton.setVisibility(View.GONE);
639 }
640 else {
641 backButton.setText(buttonText);
642 }
643 }
644 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
645 skipButton.setVisibility(View.VISIBLE);
646 }
647 }
648 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700649
650 mHomeActivitiesCount = getHomeActivitiesCount();
Jason Monkfd2c7222015-12-02 15:38:38 -0500651 if (DEBUG_TIMING) Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
652 + " ms");
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700653 }
654
655 private int getHomeActivitiesCount() {
656 final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>();
657 getPackageManager().getHomeActivities(homeApps);
658 return homeApps.size();
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800659 }
660
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700661 private void setTitleFromIntent(Intent intent) {
662 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
663 if (initialTitleResId > 0) {
664 mInitialTitle = null;
665 mInitialTitleResId = initialTitleResId;
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100666
667 final String initialTitleResPackageName = intent.getStringExtra(
668 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
669 if (initialTitleResPackageName != null) {
670 try {
671 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
672 0 /* flags */, new UserHandle(UserHandle.myUserId()));
673 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
674 setTitle(mInitialTitle);
675 mInitialTitleResId = -1;
676 return;
677 } catch (NameNotFoundException e) {
678 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
679 }
680 } else {
681 setTitle(mInitialTitleResId);
682 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700683 } else {
684 mInitialTitleResId = -1;
685 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
686 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
687 setTitle(mInitialTitle);
688 }
689 }
690
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800691 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800692 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700693 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800694 }
695
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700696 private int setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800697 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700698
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800699 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700700 if (mInitialTitleResId > 0) {
701 setTitle(mInitialTitleResId);
702 } else {
703 setTitle(mInitialTitle);
704 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700705 return 0;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800706 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700707
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800708 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
709 setTitleFromBackStackEntry(bse);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700710
711 return count;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800712 }
713
714 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
715 final CharSequence title;
716 final int titleRes = bse.getBreadCrumbTitleRes();
717 if (titleRes > 0) {
718 title = getText(titleRes);
719 } else {
720 title = bse.getBreadCrumbTitle();
721 }
722 if (title != null) {
723 setTitle(title);
724 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800725 }
726
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800727 @Override
728 protected void onSaveInstanceState(Bundle outState) {
729 super.onSaveInstanceState(outState);
730
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700731 if (mCategories.size() > 0) {
732 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800733 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700734
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700735 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700736 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700737
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700738 if (mDisplaySearch) {
739 // The option menus are created if the ActionBar is visible and they are also created
740 // asynchronously. If you launch Settings with an Intent action like
741 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
742 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
743 // menu item and search view are null.
744 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
745 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700746
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700747 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
748 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
749 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700750
751 outState.putInt(SAVE_KEY_HOME_ACTIVITIES_COUNT, mHomeActivitiesCount);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800752 }
753
754 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400755 protected void onResume() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800756 super.onResume();
757
758 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
759 @Override
760 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Jason Monk4da79e02015-09-10 10:54:36 -0400761 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800762 }
763 };
764 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
765 mDevelopmentPreferencesListener);
766
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800767 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Clara Bayarri6934a042015-10-14 11:07:35 +0100768 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_ADDED));
769 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_REMOVED));
Svetoslav853e4712014-04-14 10:10:25 -0700770
Svetoslav990159a2014-04-14 17:14:59 -0700771 mDynamicIndexableContentMonitor.register(this);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700772
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700773 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700774 onQueryTextSubmit(mSearchQuery);
775 }
Jason Monk4da79e02015-09-10 10:54:36 -0400776 updateTilesList();
Jason Monk478c5922016-01-22 15:20:20 -0500777 if (mIsShowingDashboard) {
778 showMenuIcon();
779 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800780 }
781
782 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400783 protected void onPause() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800784 super.onPause();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800785 unregisterReceiver(mBatteryInfoReceiver);
Clara Bayarri8c9521f2016-01-12 14:10:45 +0000786 unregisterReceiver(mUserAddRemoveReceiver);
Svetoslav990159a2014-04-14 17:14:59 -0700787 mDynamicIndexableContentMonitor.unregister();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800788 }
789
790 @Override
791 public void onDestroy() {
792 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700793
794 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
795 mDevelopmentPreferencesListener);
796 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800797 }
798
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800799 protected boolean isValidFragment(String fragmentName) {
800 // Almost all fragments are wrapped in this,
801 // except for a few that have their own activities.
802 for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
803 if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
804 }
805 return false;
806 }
807
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800808 @Override
809 public Intent getIntent() {
810 Intent superIntent = super.getIntent();
811 String startingFragment = getStartingFragmentClass(superIntent);
812 // This is called from super.onCreate, isMultiPane() is not yet reliable
813 // Do not use onIsHidingHeaders either, which relies itself on this method
814 if (startingFragment != null) {
815 Intent modIntent = new Intent(superIntent);
816 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
817 Bundle args = superIntent.getExtras();
818 if (args != null) {
819 args = new Bundle(args);
820 } else {
821 args = new Bundle();
822 }
823 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100824 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800825 return modIntent;
826 }
827 return superIntent;
828 }
829
830 /**
831 * Checks if the component name in the intent is different from the Settings class and
832 * returns the class name to load as a fragment.
833 */
834 private String getStartingFragmentClass(Intent intent) {
835 if (mFragmentClass != null) return mFragmentClass;
836
837 String intentClass = intent.getComponent().getClassName();
838 if (intentClass.equals(getClass().getName())) return null;
839
840 if ("com.android.settings.ManageApplications".equals(intentClass)
841 || "com.android.settings.RunningServices".equals(intentClass)
842 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
843 // Old names of manage apps.
844 intentClass = com.android.settings.applications.ManageApplications.class.getName();
845 }
846
847 return intentClass;
848 }
849
850 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000851 * Start a new fragment containing a preference panel. If the preferences
852 * are being displayed in multi-pane mode, the given fragment class will
853 * be instantiated and placed in the appropriate pane. If running in
854 * single-pane mode, a new activity will be launched in which to show the
855 * fragment.
856 *
857 * @param fragmentClass Full name of the class implementing the fragment.
858 * @param args Any desired arguments to supply to the fragment.
859 * @param titleRes Optional resource identifier of the title of this
860 * fragment.
861 * @param titleText Optional text of the title of this fragment.
862 * @param resultTo Optional fragment that result data should be sent to.
863 * If non-null, resultTo.onActivityResult() will be called when this
864 * preference panel is done. The launched panel must use
865 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
866 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700867 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000868 */
869 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700870 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700871 String title = null;
872 if (titleRes < 0) {
873 if (titleText != null) {
874 title = titleText.toString();
875 } else {
876 // There not much we can do in that case
877 title = "";
878 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700879 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700880 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700881 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000882 }
883
884 /**
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100885 * Start a new fragment in a new activity containing a preference panel for a given user. If the
886 * preferences are being displayed in multi-pane mode, the given fragment class will be
887 * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
888 * activity will be launched in which to show the fragment.
889 *
890 * @param fragmentClass Full name of the class implementing the fragment.
891 * @param args Any desired arguments to supply to the fragment.
892 * @param titleRes Optional resource identifier of the title of this fragment.
893 * @param titleText Optional text of the title of this fragment.
894 * @param userHandle The user for which the panel has to be started.
895 */
896 public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
897 CharSequence titleText, UserHandle userHandle) {
Lifu Tangd0332852015-04-02 12:05:46 -0700898 // This is a workaround.
899 //
900 // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
901 // starting the fragment could cause a native stack corruption. See b/17523189. However,
902 // adding that flag and start the preference panel with the same UserHandler will make it
903 // impossible to use back button to return to the previous screen. See b/20042570.
904 //
905 // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
906 // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
907 // when we're calling it as the same user.
908 if (userHandle.getIdentifier() == UserHandle.myUserId()) {
909 startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0);
910 } else {
911 String title = null;
912 if (titleRes < 0) {
913 if (titleText != null) {
914 title = titleText.toString();
915 } else {
916 // There not much we can do in that case
917 title = "";
918 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100919 }
Lifu Tangd0332852015-04-02 12:05:46 -0700920 Utils.startWithFragmentAsUser(this, fragmentClass, args,
921 titleRes, title, mIsShortcut, userHandle);
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100922 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100923 }
924
925 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800926 * Called by a preference panel fragment to finish itself.
927 *
928 * @param caller The fragment that is asking to be finished.
929 * @param resultCode Optional result code to send back to the original
930 * launching fragment.
931 * @param resultData Optional result data to send back to the original
932 * launching fragment.
933 */
934 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
935 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700936 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800937 }
938
939 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000940 * Start a new fragment.
941 *
942 * @param fragment The fragment to start
943 * @param push If true, the current fragment will be pushed onto the back stack. If false,
944 * the current fragment will be replaced.
945 */
946 public void startPreferenceFragment(Fragment fragment, boolean push) {
947 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700948 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000949 if (push) {
950 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
951 transaction.addToBackStack(BACK_STACK_PREFS);
952 } else {
953 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
954 }
955 transaction.commitAllowingStateLoss();
956 }
957
958 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700959 * Switch to a specific Fragment with taking care of validation, Title and BackStack
960 */
961 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700962 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700963 if (validate && !isValidFragment(fragmentName)) {
964 throw new IllegalArgumentException("Invalid fragment for this activity: "
965 + fragmentName);
966 }
967 Fragment f = Fragment.instantiate(this, fragmentName, args);
968 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700969 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700970 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700971 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700972 }
973 if (addToBackStack) {
974 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
975 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700976 if (titleResId > 0) {
977 transaction.setBreadCrumbTitle(titleResId);
978 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700979 transaction.setBreadCrumbTitle(title);
980 }
981 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700982 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700983 return f;
984 }
985
Jason Monk4da79e02015-09-10 10:54:36 -0400986 private void updateTilesList() {
Jason Monkfd2c7222015-12-02 15:38:38 -0500987 // Generally the items that are will be changing from these updates will
988 // not be in the top list of tiles, so run it in the background and the
989 // SettingsDrawerActivity will pick up on the updates automatically.
990 AsyncTask.execute(new Runnable() {
991 @Override
992 public void run() {
993 doUpdateTilesList();
994 }
995 });
996 }
997
998 private void doUpdateTilesList() {
Jason Monk4da79e02015-09-10 10:54:36 -0400999 PackageManager pm = getPackageManager();
Xiaohui Chen44879a32015-07-22 13:53:22 -07001000 final UserManager um = UserManager.get(this);
1001 final boolean isAdmin = um.isAdminUser();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001002
Jason Monk4da79e02015-09-10 10:54:36 -04001003 String packageName = getPackageName();
1004 setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()),
1005 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001006
Jason Monk4da79e02015-09-10 10:54:36 -04001007 setTileEnabled(new ComponentName(packageName,
1008 Settings.BluetoothSettingsActivity.class.getName()),
1009 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001010
Jason Monk4da79e02015-09-10 10:54:36 -04001011 setTileEnabled(new ComponentName(packageName,
1012 Settings.DataUsageSummaryActivity.class.getName()),
1013 Utils.isBandwidthControlEnabled(), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001014
Jason Monk4da79e02015-09-10 10:54:36 -04001015 setTileEnabled(new ComponentName(packageName,
1016 Settings.SimSettingsActivity.class.getName()),
1017 Utils.showSimCardTile(this), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001018
Jason Monk4da79e02015-09-10 10:54:36 -04001019 setTileEnabled(new ComponentName(packageName,
1020 Settings.PowerUsageSummaryActivity.class.getName()),
1021 mBatteryPresent, isAdmin, pm);
1022
1023 setTileEnabled(new ComponentName(packageName,
1024 Settings.HomeSettingsActivity.class.getName()),
1025 updateHomeSettingTiles(), isAdmin, pm);
1026
1027 setTileEnabled(new ComponentName(packageName,
1028 Settings.UserSettingsActivity.class.getName()),
1029 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
1030 && !Utils.isMonkeyRunning(), isAdmin, pm);
1031
1032 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
1033 setTileEnabled(new ComponentName(packageName,
1034 Settings.PaymentSettingsActivity.class.getName()),
1035 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
1036 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
1037 && adapter != null && adapter.isEnabled(), isAdmin, pm);
1038
1039 setTileEnabled(new ComponentName(packageName,
1040 Settings.PrintSettingsActivity.class.getName()),
1041 pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin, pm);
1042
1043 final boolean showDev = mDevelopmentPreferences.getBoolean(
1044 DevelopmentSettings.PREF_SHOW,
1045 android.os.Build.TYPE.equals("eng"));
1046 setTileEnabled(new ComponentName(packageName,
1047 Settings.DevelopmentSettingsActivity.class.getName()),
1048 showDev && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES),
1049 isAdmin, pm);
1050
1051 if (UserHandle.MU_ENABLED && !isAdmin) {
1052 // When on restricted users, disable all extra categories (but only the settings ones).
Jason Monkfd2c7222015-12-02 15:38:38 -05001053 List<DashboardCategory> categories = getDashboardCategories();
Jason Monk4da79e02015-09-10 10:54:36 -04001054 for (DashboardCategory category : categories) {
Jason Monkd4f03ec2016-01-07 16:25:34 -05001055 for (Tile tile : category.tiles) {
Jason Monk4da79e02015-09-10 10:54:36 -04001056 ComponentName component = tile.intent.getComponent();
1057 if (packageName.equals(component)&& !ArrayUtils.contains(
1058 SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1059 setTileEnabled(component, false, isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001060 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001061 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001062 }
1063 }
Jason Monk2ebc8a02015-02-13 15:23:19 -05001064 }
1065
Jason Monk4da79e02015-09-10 10:54:36 -04001066 private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin,
1067 PackageManager pm) {
1068 if (UserHandle.MU_ENABLED && !isAdmin
1069 && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1070 enabled = false;
1071 }
1072 int state = pm.getComponentEnabledSetting(component);
1073 boolean isEnabled = state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
1074 || state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
1075 if (isEnabled != enabled) {
1076 pm.setComponentEnabledSetting(component, enabled
1077 ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
1078 : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
1079 PackageManager.DONT_KILL_APP);
Jason Monk2ebc8a02015-02-13 15:23:19 -05001080 }
1081 }
1082
Jason Monk4da79e02015-09-10 10:54:36 -04001083 private boolean updateHomeSettingTiles() {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001084 // Once we decide to show Home settings, keep showing it forever
1085 SharedPreferences sp = getSharedPreferences(HomeSettings.HOME_PREFS, Context.MODE_PRIVATE);
1086 if (sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false)) {
1087 return true;
1088 }
1089
1090 try {
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -07001091 mHomeActivitiesCount = getHomeActivitiesCount();
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -07001092 if (mHomeActivitiesCount < 2) {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001093 return false;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001094 }
1095 } catch (Exception e) {
1096 // Can't look up the home activity; bail on configuring the icon
1097 Log.w(LOG_TAG, "Problem looking up home activity!", e);
1098 }
1099
1100 sp.edit().putBoolean(HomeSettings.HOME_PREFS_DO_SHOW, true).apply();
1101 return true;
1102 }
1103
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001104 private void getMetaData() {
1105 try {
1106 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1107 PackageManager.GET_META_DATA);
1108 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001109 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1110 } catch (NameNotFoundException nnfe) {
1111 // No recovery
1112 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1113 }
1114 }
1115
1116 // give subclasses access to the Next button
1117 public boolean hasNextButton() {
1118 return mNextButton != null;
1119 }
1120
1121 public Button getNextButton() {
1122 return mNextButton;
1123 }
1124
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001125 @Override
1126 public boolean shouldUpRecreateTask(Intent targetIntent) {
1127 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1128 }
1129
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001130 @Override
1131 public boolean onQueryTextSubmit(String query) {
1132 switchToSearchResultsFragmentIfNeeded();
1133 mSearchQuery = query;
1134 return mSearchResultsFragment.onQueryTextSubmit(query);
1135 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001136
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001137 @Override
1138 public boolean onQueryTextChange(String newText) {
1139 mSearchQuery = newText;
Fabrice Di Meglio7e4855e2014-05-23 16:03:43 -07001140 if (mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001141 return false;
1142 }
1143 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001144 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001145
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001146 @Override
1147 public boolean onClose() {
1148 return false;
1149 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001150
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001151 @Override
1152 public boolean onMenuItemActionExpand(MenuItem item) {
1153 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001154 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001155 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001156 return true;
1157 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001158
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001159 @Override
1160 public boolean onMenuItemActionCollapse(MenuItem item) {
1161 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001162 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001163 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001164 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001165 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001166 return true;
1167 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001168
Jason Monk4da79e02015-09-10 10:54:36 -04001169 @Override
Jason Monkd4f03ec2016-01-07 16:25:34 -05001170 protected void onTileClicked(Tile tile) {
Jason Monk4da79e02015-09-10 10:54:36 -04001171 if (mIsShowingDashboard) {
1172 // If on dashboard, don't finish so the back comes back to here.
1173 openTile(tile);
1174 } else {
1175 super.onTileClicked(tile);
1176 }
1177 }
1178
Jason Monkaf001092015-11-04 13:16:18 -05001179 @Override
1180 public void onProfileTileOpen() {
1181 if (!mIsShowingDashboard) {
1182 finish();
1183 }
1184 }
1185
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001186 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001187 if (mSearchResultsFragment != null) {
1188 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001189 }
Fabrice Di Megliod40dd452014-07-18 15:20:34 -07001190 Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001191 if (current != null && current instanceof SearchResultsSummary) {
1192 mSearchResultsFragment = (SearchResultsSummary) current;
1193 } else {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001194 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001195 SearchResultsSummary.class.getName(), null, false, true,
1196 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001197 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001198 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001199 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001200 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001201
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001202 public void needToRevertToInitialFragment() {
1203 mNeedToRevertToInitialFragment = true;
1204 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001205
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001206 private void revertToInitialFragment() {
1207 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001208 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001209 mSearchMenuItemExpanded = false;
1210 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1211 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001212 if (mSearchMenuItem != null) {
1213 mSearchMenuItem.collapseActionView();
1214 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001215 }
Jim Miller0698a212014-10-16 19:49:07 -07001216
1217 public Intent getResultIntentData() {
1218 return mResultIntentData;
1219 }
1220
1221 public void setResultIntentData(Intent resultIntentData) {
1222 mResultIntentData = resultIntentData;
1223 }
Jason Monkd4f03ec2016-01-07 16:25:34 -05001224
1225 public void startSuggestion(Intent intent) {
1226 mCurrentSuggestion = intent.getComponent();
1227 startActivityForResult(intent, REQUEST_SUGGESTION);
1228 }
1229
1230 @Override
1231 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
1232 if (requestCode == REQUEST_SUGGESTION && mCurrentSuggestion != null
1233 && resultCode != RESULT_CANCELED) {
1234 getPackageManager().setComponentEnabledSetting(mCurrentSuggestion,
1235 PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
1236 }
1237 super.onActivityResult(requestCode, resultCode, data);
1238 }
1239
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001240}