blob: 88cfc748d735c352d707980d0f6ef5f7c817a9a4 [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();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800777 }
778
779 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400780 protected void onPause() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800781 super.onPause();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800782 unregisterReceiver(mBatteryInfoReceiver);
Clara Bayarri8c9521f2016-01-12 14:10:45 +0000783 unregisterReceiver(mUserAddRemoveReceiver);
Svetoslav990159a2014-04-14 17:14:59 -0700784 mDynamicIndexableContentMonitor.unregister();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800785 }
786
787 @Override
788 public void onDestroy() {
789 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700790
791 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
792 mDevelopmentPreferencesListener);
793 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800794 }
795
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800796 protected boolean isValidFragment(String fragmentName) {
797 // Almost all fragments are wrapped in this,
798 // except for a few that have their own activities.
799 for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
800 if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
801 }
802 return false;
803 }
804
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800805 @Override
806 public Intent getIntent() {
807 Intent superIntent = super.getIntent();
808 String startingFragment = getStartingFragmentClass(superIntent);
809 // This is called from super.onCreate, isMultiPane() is not yet reliable
810 // Do not use onIsHidingHeaders either, which relies itself on this method
811 if (startingFragment != null) {
812 Intent modIntent = new Intent(superIntent);
813 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
814 Bundle args = superIntent.getExtras();
815 if (args != null) {
816 args = new Bundle(args);
817 } else {
818 args = new Bundle();
819 }
820 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100821 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800822 return modIntent;
823 }
824 return superIntent;
825 }
826
827 /**
828 * Checks if the component name in the intent is different from the Settings class and
829 * returns the class name to load as a fragment.
830 */
831 private String getStartingFragmentClass(Intent intent) {
832 if (mFragmentClass != null) return mFragmentClass;
833
834 String intentClass = intent.getComponent().getClassName();
835 if (intentClass.equals(getClass().getName())) return null;
836
837 if ("com.android.settings.ManageApplications".equals(intentClass)
838 || "com.android.settings.RunningServices".equals(intentClass)
839 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
840 // Old names of manage apps.
841 intentClass = com.android.settings.applications.ManageApplications.class.getName();
842 }
843
844 return intentClass;
845 }
846
847 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000848 * Start a new fragment containing a preference panel. If the preferences
849 * are being displayed in multi-pane mode, the given fragment class will
850 * be instantiated and placed in the appropriate pane. If running in
851 * single-pane mode, a new activity will be launched in which to show the
852 * fragment.
853 *
854 * @param fragmentClass Full name of the class implementing the fragment.
855 * @param args Any desired arguments to supply to the fragment.
856 * @param titleRes Optional resource identifier of the title of this
857 * fragment.
858 * @param titleText Optional text of the title of this fragment.
859 * @param resultTo Optional fragment that result data should be sent to.
860 * If non-null, resultTo.onActivityResult() will be called when this
861 * preference panel is done. The launched panel must use
862 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
863 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700864 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000865 */
866 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700867 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700868 String title = null;
869 if (titleRes < 0) {
870 if (titleText != null) {
871 title = titleText.toString();
872 } else {
873 // There not much we can do in that case
874 title = "";
875 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700876 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700877 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700878 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000879 }
880
881 /**
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100882 * Start a new fragment in a new activity containing a preference panel for a given user. If the
883 * preferences are being displayed in multi-pane mode, the given fragment class will be
884 * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
885 * activity will be launched in which to show the fragment.
886 *
887 * @param fragmentClass Full name of the class implementing the fragment.
888 * @param args Any desired arguments to supply to the fragment.
889 * @param titleRes Optional resource identifier of the title of this fragment.
890 * @param titleText Optional text of the title of this fragment.
891 * @param userHandle The user for which the panel has to be started.
892 */
893 public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
894 CharSequence titleText, UserHandle userHandle) {
Lifu Tangd0332852015-04-02 12:05:46 -0700895 // This is a workaround.
896 //
897 // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
898 // starting the fragment could cause a native stack corruption. See b/17523189. However,
899 // adding that flag and start the preference panel with the same UserHandler will make it
900 // impossible to use back button to return to the previous screen. See b/20042570.
901 //
902 // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
903 // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
904 // when we're calling it as the same user.
905 if (userHandle.getIdentifier() == UserHandle.myUserId()) {
906 startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0);
907 } else {
908 String title = null;
909 if (titleRes < 0) {
910 if (titleText != null) {
911 title = titleText.toString();
912 } else {
913 // There not much we can do in that case
914 title = "";
915 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100916 }
Lifu Tangd0332852015-04-02 12:05:46 -0700917 Utils.startWithFragmentAsUser(this, fragmentClass, args,
918 titleRes, title, mIsShortcut, userHandle);
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100919 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100920 }
921
922 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800923 * Called by a preference panel fragment to finish itself.
924 *
925 * @param caller The fragment that is asking to be finished.
926 * @param resultCode Optional result code to send back to the original
927 * launching fragment.
928 * @param resultData Optional result data to send back to the original
929 * launching fragment.
930 */
931 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
932 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700933 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800934 }
935
936 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000937 * Start a new fragment.
938 *
939 * @param fragment The fragment to start
940 * @param push If true, the current fragment will be pushed onto the back stack. If false,
941 * the current fragment will be replaced.
942 */
943 public void startPreferenceFragment(Fragment fragment, boolean push) {
944 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700945 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000946 if (push) {
947 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
948 transaction.addToBackStack(BACK_STACK_PREFS);
949 } else {
950 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
951 }
952 transaction.commitAllowingStateLoss();
953 }
954
955 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700956 * Switch to a specific Fragment with taking care of validation, Title and BackStack
957 */
958 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700959 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700960 if (validate && !isValidFragment(fragmentName)) {
961 throw new IllegalArgumentException("Invalid fragment for this activity: "
962 + fragmentName);
963 }
964 Fragment f = Fragment.instantiate(this, fragmentName, args);
965 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700966 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700967 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700968 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700969 }
970 if (addToBackStack) {
971 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
972 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700973 if (titleResId > 0) {
974 transaction.setBreadCrumbTitle(titleResId);
975 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700976 transaction.setBreadCrumbTitle(title);
977 }
978 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700979 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700980 return f;
981 }
982
Jason Monk4da79e02015-09-10 10:54:36 -0400983 private void updateTilesList() {
Jason Monkfd2c7222015-12-02 15:38:38 -0500984 // Generally the items that are will be changing from these updates will
985 // not be in the top list of tiles, so run it in the background and the
986 // SettingsDrawerActivity will pick up on the updates automatically.
987 AsyncTask.execute(new Runnable() {
988 @Override
989 public void run() {
990 doUpdateTilesList();
991 }
992 });
993 }
994
995 private void doUpdateTilesList() {
Jason Monk4da79e02015-09-10 10:54:36 -0400996 PackageManager pm = getPackageManager();
Xiaohui Chen44879a32015-07-22 13:53:22 -0700997 final UserManager um = UserManager.get(this);
998 final boolean isAdmin = um.isAdminUser();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700999
Jason Monk4da79e02015-09-10 10:54:36 -04001000 String packageName = getPackageName();
1001 setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()),
1002 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001003
Jason Monk4da79e02015-09-10 10:54:36 -04001004 setTileEnabled(new ComponentName(packageName,
1005 Settings.BluetoothSettingsActivity.class.getName()),
1006 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001007
Jason Monk4da79e02015-09-10 10:54:36 -04001008 setTileEnabled(new ComponentName(packageName,
1009 Settings.DataUsageSummaryActivity.class.getName()),
1010 Utils.isBandwidthControlEnabled(), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001011
Jason Monk4da79e02015-09-10 10:54:36 -04001012 setTileEnabled(new ComponentName(packageName,
1013 Settings.SimSettingsActivity.class.getName()),
1014 Utils.showSimCardTile(this), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001015
Jason Monk4da79e02015-09-10 10:54:36 -04001016 setTileEnabled(new ComponentName(packageName,
1017 Settings.PowerUsageSummaryActivity.class.getName()),
1018 mBatteryPresent, isAdmin, pm);
1019
1020 setTileEnabled(new ComponentName(packageName,
1021 Settings.HomeSettingsActivity.class.getName()),
1022 updateHomeSettingTiles(), isAdmin, pm);
1023
1024 setTileEnabled(new ComponentName(packageName,
1025 Settings.UserSettingsActivity.class.getName()),
1026 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
1027 && !Utils.isMonkeyRunning(), isAdmin, pm);
1028
1029 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
1030 setTileEnabled(new ComponentName(packageName,
1031 Settings.PaymentSettingsActivity.class.getName()),
1032 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
1033 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
1034 && adapter != null && adapter.isEnabled(), isAdmin, pm);
1035
1036 setTileEnabled(new ComponentName(packageName,
1037 Settings.PrintSettingsActivity.class.getName()),
1038 pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin, pm);
1039
1040 final boolean showDev = mDevelopmentPreferences.getBoolean(
1041 DevelopmentSettings.PREF_SHOW,
1042 android.os.Build.TYPE.equals("eng"));
1043 setTileEnabled(new ComponentName(packageName,
1044 Settings.DevelopmentSettingsActivity.class.getName()),
1045 showDev && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES),
1046 isAdmin, pm);
1047
1048 if (UserHandle.MU_ENABLED && !isAdmin) {
1049 // When on restricted users, disable all extra categories (but only the settings ones).
Jason Monkfd2c7222015-12-02 15:38:38 -05001050 List<DashboardCategory> categories = getDashboardCategories();
Jason Monk4da79e02015-09-10 10:54:36 -04001051 for (DashboardCategory category : categories) {
Jason Monkd4f03ec2016-01-07 16:25:34 -05001052 for (Tile tile : category.tiles) {
Jason Monk4da79e02015-09-10 10:54:36 -04001053 ComponentName component = tile.intent.getComponent();
1054 if (packageName.equals(component)&& !ArrayUtils.contains(
1055 SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1056 setTileEnabled(component, false, isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001057 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001058 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001059 }
1060 }
Jason Monk2ebc8a02015-02-13 15:23:19 -05001061 }
1062
Jason Monk4da79e02015-09-10 10:54:36 -04001063 private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin,
1064 PackageManager pm) {
1065 if (UserHandle.MU_ENABLED && !isAdmin
1066 && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1067 enabled = false;
1068 }
1069 int state = pm.getComponentEnabledSetting(component);
1070 boolean isEnabled = state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
1071 || state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
1072 if (isEnabled != enabled) {
1073 pm.setComponentEnabledSetting(component, enabled
1074 ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
1075 : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
1076 PackageManager.DONT_KILL_APP);
Jason Monk2ebc8a02015-02-13 15:23:19 -05001077 }
1078 }
1079
Jason Monk4da79e02015-09-10 10:54:36 -04001080 private boolean updateHomeSettingTiles() {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001081 // Once we decide to show Home settings, keep showing it forever
1082 SharedPreferences sp = getSharedPreferences(HomeSettings.HOME_PREFS, Context.MODE_PRIVATE);
1083 if (sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false)) {
1084 return true;
1085 }
1086
1087 try {
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -07001088 mHomeActivitiesCount = getHomeActivitiesCount();
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -07001089 if (mHomeActivitiesCount < 2) {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001090 return false;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001091 }
1092 } catch (Exception e) {
1093 // Can't look up the home activity; bail on configuring the icon
1094 Log.w(LOG_TAG, "Problem looking up home activity!", e);
1095 }
1096
1097 sp.edit().putBoolean(HomeSettings.HOME_PREFS_DO_SHOW, true).apply();
1098 return true;
1099 }
1100
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001101 private void getMetaData() {
1102 try {
1103 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1104 PackageManager.GET_META_DATA);
1105 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001106 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1107 } catch (NameNotFoundException nnfe) {
1108 // No recovery
1109 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1110 }
1111 }
1112
1113 // give subclasses access to the Next button
1114 public boolean hasNextButton() {
1115 return mNextButton != null;
1116 }
1117
1118 public Button getNextButton() {
1119 return mNextButton;
1120 }
1121
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001122 @Override
1123 public boolean shouldUpRecreateTask(Intent targetIntent) {
1124 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1125 }
1126
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001127 @Override
1128 public boolean onQueryTextSubmit(String query) {
1129 switchToSearchResultsFragmentIfNeeded();
1130 mSearchQuery = query;
1131 return mSearchResultsFragment.onQueryTextSubmit(query);
1132 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001133
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001134 @Override
1135 public boolean onQueryTextChange(String newText) {
1136 mSearchQuery = newText;
Fabrice Di Meglio7e4855e2014-05-23 16:03:43 -07001137 if (mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001138 return false;
1139 }
1140 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001141 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001142
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001143 @Override
1144 public boolean onClose() {
1145 return false;
1146 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001147
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001148 @Override
1149 public boolean onMenuItemActionExpand(MenuItem item) {
1150 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001151 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001152 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001153 return true;
1154 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001155
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001156 @Override
1157 public boolean onMenuItemActionCollapse(MenuItem item) {
1158 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001159 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001160 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001161 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001162 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001163 return true;
1164 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001165
Jason Monk4da79e02015-09-10 10:54:36 -04001166 @Override
Jason Monkd4f03ec2016-01-07 16:25:34 -05001167 protected void onTileClicked(Tile tile) {
Jason Monk4da79e02015-09-10 10:54:36 -04001168 if (mIsShowingDashboard) {
1169 // If on dashboard, don't finish so the back comes back to here.
1170 openTile(tile);
1171 } else {
1172 super.onTileClicked(tile);
1173 }
1174 }
1175
Jason Monkaf001092015-11-04 13:16:18 -05001176 @Override
1177 public void onProfileTileOpen() {
1178 if (!mIsShowingDashboard) {
1179 finish();
1180 }
1181 }
1182
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001183 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001184 if (mSearchResultsFragment != null) {
1185 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001186 }
Fabrice Di Megliod40dd452014-07-18 15:20:34 -07001187 Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001188 if (current != null && current instanceof SearchResultsSummary) {
1189 mSearchResultsFragment = (SearchResultsSummary) current;
1190 } else {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001191 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001192 SearchResultsSummary.class.getName(), null, false, true,
1193 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001194 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001195 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001196 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001197 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001198
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001199 public void needToRevertToInitialFragment() {
1200 mNeedToRevertToInitialFragment = true;
1201 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001202
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001203 private void revertToInitialFragment() {
1204 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001205 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001206 mSearchMenuItemExpanded = false;
1207 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1208 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001209 if (mSearchMenuItem != null) {
1210 mSearchMenuItem.collapseActionView();
1211 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001212 }
Jim Miller0698a212014-10-16 19:49:07 -07001213
1214 public Intent getResultIntentData() {
1215 return mResultIntentData;
1216 }
1217
1218 public void setResultIntentData(Intent resultIntentData) {
1219 mResultIntentData = resultIntentData;
1220 }
Jason Monkd4f03ec2016-01-07 16:25:34 -05001221
1222 public void startSuggestion(Intent intent) {
1223 mCurrentSuggestion = intent.getComponent();
1224 startActivityForResult(intent, REQUEST_SUGGESTION);
1225 }
1226
1227 @Override
1228 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
1229 if (requestCode == REQUEST_SUGGESTION && mCurrentSuggestion != null
1230 && resultCode != RESULT_CANCELED) {
1231 getPackageManager().setComponentEnabledSetting(mCurrentSuggestion,
1232 PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
1233 }
1234 super.onActivityResult(requestCode, resultCode, data);
1235 }
1236
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001237}