blob: 32888601856d664759aec379bc4382020e3277cc [file] [log] [blame]
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.settings;
18
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080019import android.app.ActionBar;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080020import android.app.Fragment;
21import android.app.FragmentManager;
22import android.app.FragmentTransaction;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080023import android.content.BroadcastReceiver;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070024import android.content.ComponentName;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080025import android.content.Context;
26import android.content.Intent;
27import android.content.IntentFilter;
28import android.content.SharedPreferences;
29import android.content.pm.ActivityInfo;
30import android.content.pm.PackageManager;
31import android.content.pm.PackageManager.NameNotFoundException;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080032import android.content.res.Configuration;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080033import android.nfc.NfcAdapter;
Jason Monkfd2c7222015-12-02 15:38:38 -050034import android.os.AsyncTask;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080035import android.os.Bundle;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080036import android.os.UserHandle;
37import android.os.UserManager;
Jason Monk39b46742015-09-10 15:52:51 -040038import android.support.v14.preference.PreferenceFragment;
39import android.support.v7.preference.Preference;
40import android.support.v7.preference.PreferenceManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080041import android.text.TextUtils;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070042import android.transition.TransitionManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080043import android.util.Log;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070044import android.view.Menu;
45import android.view.MenuInflater;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080046import android.view.MenuItem;
47import android.view.View;
48import android.view.View.OnClickListener;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070049import android.view.ViewGroup;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080050import android.widget.Button;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070051import android.widget.SearchView;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080052import com.android.internal.util.ArrayUtils;
Jason Monk4da79e02015-09-10 10:54:36 -040053import com.android.settings.Settings.WifiSettingsActivity;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080054import com.android.settings.accessibility.AccessibilitySettings;
Anna Galuszab1795f52016-01-08 14:37:16 -080055import com.android.settings.accessibility.AccessibilitySettingsForSetupWizard;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080056import com.android.settings.accessibility.CaptionPropertiesFragment;
Alexandra Gherghina6d839872014-07-22 12:04:58 +000057import com.android.settings.accounts.AccountSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080058import com.android.settings.accounts.AccountSyncSettings;
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;
Abodunrinwa Toki976bb3f2016-01-20 18:43:20 +000079import com.android.settings.inputmethod.AvailableVirtualKeyboardFragment;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080080import com.android.settings.inputmethod.InputMethodAndLanguageSettings;
81import com.android.settings.inputmethod.KeyboardLayoutPickerFragment;
82import com.android.settings.inputmethod.SpellCheckersSettings;
83import com.android.settings.inputmethod.UserDictionaryList;
Mihai Nitad7d48fd2016-01-12 08:55:05 -080084import com.android.settings.localepicker.LocaleListEditor;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080085import com.android.settings.location.LocationSettings;
86import com.android.settings.nfc.AndroidBeam;
87import com.android.settings.nfc.PaymentSettings;
John Spurlock802ddf92014-07-18 11:51:13 -040088import com.android.settings.notification.AppNotificationSettings;
Julia Reynolds8c0a4232015-11-24 10:08:14 -050089import com.android.settings.notification.ConfigureNotificationSettings;
John Spurlock4a350512014-04-08 14:08:21 -040090import com.android.settings.notification.NotificationAccessSettings;
John Spurlock4a350512014-04-08 14:08:21 -040091import com.android.settings.notification.NotificationStation;
Jason Monk2ebc8a02015-02-13 15:23:19 -050092import com.android.settings.notification.OtherSoundSettings;
Jason Monkb37e2882016-01-11 14:27:20 -050093import com.android.settings.notification.SoundSettings;
John Spurlock08531a82015-05-07 17:45:43 -040094import com.android.settings.notification.ZenAccessSettings;
John Spurlock533a5662015-06-19 10:47:36 -040095import com.android.settings.notification.ZenModeAutomationSettings;
John Spurlockf57bad72015-04-30 09:26:15 -040096import com.android.settings.notification.ZenModeEventRuleSettings;
John Spurlockc1df2aa2015-04-13 20:57:06 -040097import com.android.settings.notification.ZenModePrioritySettings;
John Spurlock45fa1402015-04-09 12:50:04 -040098import com.android.settings.notification.ZenModeScheduleRuleSettings;
Jason Monk39b46742015-09-10 15:52:51 -040099import com.android.settings.notification.ZenModeSettings;
Julia Reynolds5555d262015-11-09 10:52:17 -0500100import com.android.settings.notification.ZenModeVisualInterruptionSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800101import com.android.settings.print.PrintJobSettingsFragment;
102import com.android.settings.print.PrintSettingsFragment;
Jason Monk2ebc8a02015-02-13 15:23:19 -0500103import com.android.settings.search.DynamicIndexableContentMonitor;
104import com.android.settings.search.Index;
PauloftheWest38155612014-06-30 10:02:36 -0700105import com.android.settings.sim.SimSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800106import com.android.settings.tts.TextToSpeechSettings;
107import com.android.settings.users.UserSettings;
108import com.android.settings.vpn2.VpnSettings;
109import com.android.settings.wfd.WifiDisplaySettings;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700110import com.android.settings.widget.SwitchBar;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800111import com.android.settings.wifi.AdvancedWifiSettings;
PauloftheWest7837b992014-06-24 07:42:27 -0700112import com.android.settings.wifi.SavedAccessPointsWifiSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800113import com.android.settings.wifi.WifiSettings;
114import com.android.settings.wifi.p2p.WifiP2pSettings;
Jason Monk4da79e02015-09-10 10:54:36 -0400115import com.android.settingslib.drawer.DashboardCategory;
Jason Monk4da79e02015-09-10 10:54:36 -0400116import com.android.settingslib.drawer.SettingsDrawerActivity;
Jason Monk7ea14c52016-01-22 14:28:02 -0500117import com.android.settingslib.drawer.Tile;
Jason Monk2ebc8a02015-02-13 15:23:19 -0500118
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800119import java.util.ArrayList;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800120import java.util.List;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700121import java.util.Set;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800122
Jason Monk4da79e02015-09-10 10:54:36 -0400123public class SettingsActivity extends SettingsDrawerActivity
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800124 implements PreferenceManager.OnPreferenceTreeClickListener,
125 PreferenceFragment.OnPreferenceStartFragmentCallback,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100126 ButtonBarHandler, FragmentManager.OnBackStackChangedListener,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700127 SearchView.OnQueryTextListener, SearchView.OnCloseListener,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100128 MenuItem.OnActionExpandListener {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800129
130 private static final String LOG_TAG = "Settings";
131
132 // Constants for state save/restore
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700133 private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700134 private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
135 private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700136 private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700137 private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700138 private static final String SAVE_KEY_HOME_ACTIVITIES_COUNT = ":settings:home_activities_count";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800139
140 /**
141 * When starting this activity, the invoking Intent can contain this extra
142 * string to specify which fragment should be initially displayed.
143 * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
144 * will call isValidFragment() to confirm that the fragment class name is valid for this
145 * activity.
146 */
147 public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
148
149 /**
150 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
151 * this extra can also be specified to supply a Bundle of arguments to pass
152 * to that fragment when it is instantiated during the initial creation
153 * of the activity.
154 */
155 public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
156
157 /**
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700158 * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
159 */
160 public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
161
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800162 public static final String BACK_STACK_PREFS = ":settings:prefs";
163
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800164 // extras that allow any preference activity to be launched as part of a wizard
165
166 // show Back and Next buttons? takes boolean parameter
167 // Back will then return RESULT_CANCELED and Next RESULT_OK
168 protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
169
170 // add a Skip button?
171 private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
172
173 // specify custom text for the Back or Next buttons, or cause a button to not appear
174 // at all by setting it to null
175 protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
176 protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
177
178 /**
179 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700180 * 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 -0800181 * that fragment.
182 */
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700183 public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100184 /**
185 * The package name used to resolve the title resource id.
186 */
187 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
188 ":settings:show_fragment_title_res_package_name";
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700189 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
190 ":settings:show_fragment_title_resid";
191 public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
192 ":settings:show_fragment_as_shortcut";
193
194 public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
195 ":settings:show_fragment_as_subsetting";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800196
Jason Monk30695812015-11-17 09:01:08 -0500197 public static final String META_DATA_KEY_FRAGMENT_CLASS =
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800198 "com.android.settings.FRAGMENT_CLASS";
199
200 private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
201
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700202 private static final String EMPTY_QUERY = "";
203
Jason Monkd4f03ec2016-01-07 16:25:34 -0500204 private static final int REQUEST_SUGGESTION = 42;
205
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800206 private String mFragmentClass;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800207
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800208 private CharSequence mInitialTitle;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700209 private int mInitialTitleResId;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800210
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800211 // Show only these settings for restricted users
Jason Monk4da79e02015-09-10 10:54:36 -0400212 private String[] SETTINGS_FOR_RESTRICTED = {
213 //wireless_section
214 WifiSettingsActivity.class.getName(),
215 Settings.BluetoothSettingsActivity.class.getName(),
216 Settings.DataUsageSummaryActivity.class.getName(),
217 Settings.SimSettingsActivity.class.getName(),
218 Settings.WirelessSettingsActivity.class.getName(),
219 //device_section
220 Settings.HomeSettingsActivity.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500221 Settings.SoundSettingsActivity.class.getName(),
Jason Monk4da79e02015-09-10 10:54:36 -0400222 Settings.DisplaySettingsActivity.class.getName(),
223 Settings.StorageSettingsActivity.class.getName(),
224 Settings.ManageApplicationsActivity.class.getName(),
225 Settings.PowerUsageSummaryActivity.class.getName(),
226 //personal_section
227 Settings.LocationSettingsActivity.class.getName(),
228 Settings.SecuritySettingsActivity.class.getName(),
229 Settings.InputMethodAndLanguageSettingsActivity.class.getName(),
230 Settings.UserSettingsActivity.class.getName(),
231 Settings.AccountSettingsActivity.class.getName(),
232 //system_section
233 Settings.DateTimeSettingsActivity.class.getName(),
234 Settings.DeviceInfoSettingsActivity.class.getName(),
235 Settings.AccessibilitySettingsActivity.class.getName(),
236 Settings.PrintSettingsActivity.class.getName(),
237 Settings.PaymentSettingsActivity.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800238 };
239
240 private static final String[] ENTRY_FRAGMENTS = {
241 WirelessSettings.class.getName(),
242 WifiSettings.class.getName(),
243 AdvancedWifiSettings.class.getName(),
PauloftheWest7837b992014-06-24 07:42:27 -0700244 SavedAccessPointsWifiSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800245 BluetoothSettings.class.getName(),
PauloftheWest38155612014-06-30 10:02:36 -0700246 SimSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800247 TetherSettings.class.getName(),
248 WifiP2pSettings.class.getName(),
249 VpnSettings.class.getName(),
250 DateTimeSettings.class.getName(),
Mihai Nitad7d48fd2016-01-12 08:55:05 -0800251 LocaleListEditor.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800252 InputMethodAndLanguageSettings.class.getName(),
Abodunrinwa Toki976bb3f2016-01-20 18:43:20 +0000253 AvailableVirtualKeyboardFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800254 SpellCheckersSettings.class.getName(),
255 UserDictionaryList.class.getName(),
256 UserDictionarySettings.class.getName(),
Amith Yamasani3033ce02014-07-14 18:03:15 -0700257 HomeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800258 DisplaySettings.class.getName(),
259 DeviceInfoSettings.class.getName(),
260 ManageApplications.class.getName(),
Xiyuan Xia86a55402015-06-02 14:55:32 -0700261 ManageAssist.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800262 ProcessStatsUi.class.getName(),
263 NotificationStation.class.getName(),
264 LocationSettings.class.getName(),
265 SecuritySettings.class.getName(),
Jason Monkd8da51c2015-04-17 14:34:12 -0400266 UsageAccessDetails.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800267 PrivacySettings.class.getName(),
268 DeviceAdminSettings.class.getName(),
269 AccessibilitySettings.class.getName(),
Anna Galuszab1795f52016-01-08 14:37:16 -0800270 AccessibilitySettingsForSetupWizard.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800271 CaptionPropertiesFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800272 com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(),
273 TextToSpeechSettings.class.getName(),
Jeff Sharkey42833b22015-04-11 21:27:33 -0700274 StorageSettings.class.getName(),
Jeff Sharkeya16257d2015-04-28 13:41:01 -0700275 PrivateVolumeForget.class.getName(),
Jeff Sharkeye77f0682015-04-29 11:24:57 -0700276 PrivateVolumeSettings.class.getName(),
277 PublicVolumeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800278 DevelopmentSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800279 AndroidBeam.class.getName(),
280 WifiDisplaySettings.class.getName(),
281 PowerUsageSummary.class.getName(),
282 AccountSyncSettings.class.getName(),
Alexandra Gherghina6d839872014-07-22 12:04:58 +0000283 AccountSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800284 CryptKeeperSettings.class.getName(),
285 DataUsageSummary.class.getName(),
286 DreamSettings.class.getName(),
287 UserSettings.class.getName(),
288 NotificationAccessSettings.class.getName(),
John Spurlock08531a82015-05-07 17:45:43 -0400289 ZenAccessSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800290 PrintSettingsFragment.class.getName(),
291 PrintJobSettingsFragment.class.getName(),
292 TrustedCredentialsSettings.class.getName(),
293 PaymentSettings.class.getName(),
294 KeyboardLayoutPickerFragment.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700295 ZenModeSettings.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500296 SoundSettings.class.getName(),
297 ConfigureNotificationSettings.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700298 ChooseLockPassword.ChooseLockPasswordFragment.class.getName(),
299 ChooseLockPattern.ChooseLockPatternFragment.class.getName(),
John Spurlockc7f8e8c2014-06-04 19:11:22 -0400300 InstalledAppDetails.class.getName(),
301 BatterySaverSettings.class.getName(),
Fabrice Di Megliodcf59dd2014-07-21 11:22:20 -0700302 AppNotificationSettings.class.getName(),
Fabrice Di Meglioe3ff4d82014-07-23 20:03:20 -0700303 OtherSoundSettings.class.getName(),
Narayan Kamath33acb152015-03-16 12:48:05 +0000304 ApnSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400305 WifiCallingSettings.class.getName(),
John Spurlockc1df2aa2015-04-13 20:57:06 -0400306 ZenModePrioritySettings.class.getName(),
John Spurlock533a5662015-06-19 10:47:36 -0400307 ZenModeAutomationSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400308 ZenModeScheduleRuleSettings.class.getName(),
John Spurlockf57bad72015-04-30 09:26:15 -0400309 ZenModeEventRuleSettings.class.getName(),
Julia Reynolds5555d262015-11-09 10:52:17 -0500310 ZenModeVisualInterruptionSettings.class.getName(),
Jason Monk2583fc12015-03-25 09:46:30 -0400311 ProcessStatsUi.class.getName(),
Jason Monk1eb54eb2015-04-29 12:46:42 -0400312 PowerUsageDetail.class.getName(),
Jason Monk2cdafc62015-06-12 12:32:50 -0400313 ProcessStatsSummary.class.getName(),
Billy Laufee78562015-07-27 12:57:07 +0100314 DrawOverlayDetails.class.getName(),
315 WriteSettingsDetails.class.getName(),
Julia Reynolds2e1e0b72015-12-14 08:32:46 -0500316 ManageDefaultApps.class.getName(),
Jason Monkb9e5d232016-01-26 17:43:57 -0500317 WallpaperTypeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800318 };
319
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700320
321 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
322 "android.settings.APPLICATION_DETAILS_SETTINGS"
323 };
324
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800325 private SharedPreferences mDevelopmentPreferences;
326 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
327
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800328 private boolean mBatteryPresent = true;
329 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800330 @Override
331 public void onReceive(Context context, Intent intent) {
332 String action = intent.getAction();
333 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
334 boolean batteryPresent = Utils.isBatteryPresent(intent);
335
336 if (mBatteryPresent != batteryPresent) {
337 mBatteryPresent = batteryPresent;
Jason Monk4da79e02015-09-10 10:54:36 -0400338 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800339 }
340 }
341 }
342 };
343
Clara Bayarri6934a042015-10-14 11:07:35 +0100344 private final BroadcastReceiver mUserAddRemoveReceiver = new BroadcastReceiver() {
345 @Override
346 public void onReceive(Context context, Intent intent) {
347 String action = intent.getAction();
348 if (action.equals(Intent.ACTION_USER_ADDED)
349 || action.equals(Intent.ACTION_USER_REMOVED)) {
350 Index.getInstance(getApplicationContext()).update();
351 }
352 }
353 };
354
Svetoslav990159a2014-04-14 17:14:59 -0700355 private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor =
356 new DynamicIndexableContentMonitor();
Svetoslav853e4712014-04-14 10:10:25 -0700357
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700358 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700359 private SwitchBar mSwitchBar;
360
361 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700362
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700363 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700364 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700365
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700366 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700367 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700368
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700369 private ViewGroup mContent;
370
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700371 private SearchView mSearchView;
372 private MenuItem mSearchMenuItem;
373 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700374 private SearchResultsSummary mSearchResultsFragment;
375 private String mSearchQuery;
376
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700377 // Categories
378 private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800379
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700380 private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800381
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700382 private boolean mNeedToRevertToInitialFragment = false;
383
Jim Miller0698a212014-10-16 19:49:07 -0700384 private Intent mResultIntentData;
Jason Monkd4f03ec2016-01-07 16:25:34 -0500385 private ComponentName mCurrentSuggestion;
Jim Miller0698a212014-10-16 19:49:07 -0700386
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700387 public SwitchBar getSwitchBar() {
388 return mSwitchBar;
389 }
390
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800391 @Override
392 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
393 // Override the fragment title for Wallpaper settings
Jason Monk39b46742015-09-10 15:52:51 -0400394 CharSequence title = pref.getTitle();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800395 if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) {
Jason Monk39b46742015-09-10 15:52:51 -0400396 title = getString(R.string.wallpaper_settings_fragment_title);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800397 }
Jason Monkb1dd5c92015-12-16 16:13:54 -0500398 startPreferencePanel(pref.getFragment(), pref.getExtras(), -1, title,
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800399 null, 0);
400 return true;
401 }
402
403 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400404 public boolean onPreferenceTreeClick(Preference preference) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800405 return false;
406 }
407
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800408 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800409 public void onConfigurationChanged(Configuration newConfig) {
410 super.onConfigurationChanged(newConfig);
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800411 Index.getInstance(this).update();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800412 }
413
414 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700415 protected void onStart() {
416 super.onStart();
417
418 if (mNeedToRevertToInitialFragment) {
419 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800420 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800421 }
422
423 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700424 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700425 if (!mDisplaySearch) {
426 return false;
427 }
428
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700429 MenuInflater inflater = getMenuInflater();
430 inflater.inflate(R.menu.options_menu, menu);
431
432 // Cache the search query (can be overriden by the OnQueryTextListener)
433 final String query = mSearchQuery;
434
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700435 mSearchMenuItem = menu.findItem(R.id.search);
436 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700437
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700438 if (mSearchMenuItem == null || mSearchView == null) {
439 return false;
440 }
441
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700442 if (mSearchResultsFragment != null) {
443 mSearchResultsFragment.setSearchView(mSearchView);
444 }
445
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700446 mSearchMenuItem.setOnActionExpandListener(this);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700447 mSearchView.setOnQueryTextListener(this);
448 mSearchView.setOnCloseListener(this);
449
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700450 if (mSearchMenuItemExpanded) {
451 mSearchMenuItem.expandActionView();
452 }
453 mSearchView.setQuery(query, true /* submit */);
454
455 return true;
456 }
457
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700458 private static boolean isShortCutIntent(final Intent intent) {
459 Set<String> categories = intent.getCategories();
460 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
461 }
462
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700463 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700464 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700465 if (action == null) {
466 return false;
467 }
468 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
469 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
470 }
471 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700472 }
473
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700474 @Override
475 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700476 super.onCreate(savedState);
Jason Monkfd2c7222015-12-02 15:38:38 -0500477 long startTime = System.currentTimeMillis();
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700478
479 // Should happen before any call to getIntent()
480 getMetaData();
481
482 final Intent intent = getIntent();
483 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
484 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800485 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800486
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800487 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
488 Context.MODE_PRIVATE);
489
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700490 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700491 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700492
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700493 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700494 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
495
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700496 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700497 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700498
Jason Monk4da79e02015-09-10 10:54:36 -0400499 mIsShowingDashboard = className.equals(Settings.class.getName())
500 || className.equals(Settings.WirelessSettings.class.getName())
501 || className.equals(Settings.DeviceSettings.class.getName())
502 || className.equals(Settings.PersonalSettings.class.getName())
503 || className.equals(Settings.WirelessSettings.class.getName());
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700504
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700505 // This is a "Sub Settings" when:
506 // - this is a real SubSettings
507 // - or :settings:show_fragment_as_subsetting is passed to the Intent
Jorim Jaggi4dfcb822015-04-29 17:21:32 -0700508 final boolean isSubSettings = this instanceof SubSettings ||
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700509 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
510
511 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
512 if (isSubSettings) {
Fabrice Di Meglio712df6c2014-07-18 17:44:37 -0700513 // Check also that we are not a Theme Dialog as we don't want to override them
514 final int themeResId = getThemeResId();
515 if (themeResId != R.style.Theme_DialogWhenLarge &&
516 themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
517 setTheme(R.style.Theme_SubSettings);
518 }
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700519 }
520
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700521 setContentView(mIsShowingDashboard ?
522 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800523
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700524 mContent = (ViewGroup) findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700525
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800526 getFragmentManager().addOnBackStackChangedListener(this);
527
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700528 if (mIsShowingDashboard) {
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800529 // Run the Index update only if we have some space
530 if (!Utils.isLowStorage(this)) {
Jason Monkfd2c7222015-12-02 15:38:38 -0500531 long indexStartTime = System.currentTimeMillis();
532 AsyncTask.execute(new Runnable() {
533 @Override
534 public void run() {
535 Index.getInstance(getApplicationContext()).update();
536 }
537 });
538 if (DEBUG_TIMING) Log.d(LOG_TAG, "Index.update() took "
539 + (System.currentTimeMillis() - indexStartTime) + " ms");
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800540 } else {
541 Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
542 }
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700543 }
544
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700545 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700546 // We are restarting from a previous saved state; used that to initialize, instead
547 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700548 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
549 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800550
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700551 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800552
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700553 ArrayList<DashboardCategory> categories =
554 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
555 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700556 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700557 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700558 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800559 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700560
561 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700562 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800563 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700564 if (!mIsShowingDashboard) {
Jason Monkea8b1a72015-06-02 16:46:34 -0400565 mDisplaySearch = false;
566 // UP will be shown only if it is a sub settings
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700567 if (mIsShortcut) {
568 mDisplayHomeAsUpEnabled = isSubSettings;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700569 } else if (isSubSettings) {
570 mDisplayHomeAsUpEnabled = true;
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700571 } else {
572 mDisplayHomeAsUpEnabled = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700573 }
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700574 setTitleFromIntent(intent);
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700575
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700576 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700577 switchToFragment(initialFragmentName, initialArguments, true, false,
578 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000579 } else {
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700580 // No UP affordance if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700581 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700582 // Show Search affordance
583 mDisplaySearch = true;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700584 mInitialTitleResId = R.string.dashboard_title;
Fabrice Di Meglio42c4b0a2014-05-22 10:30:03 -0700585 switchToFragment(DashboardSummary.class.getName(), null, false, false,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700586 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800587 }
588 }
589
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700590 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700591 if (mActionBar != null) {
592 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
593 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
594 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700595 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
596
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800597 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800598 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
599
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700600 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800601 if (buttonBar != null) {
602 buttonBar.setVisibility(View.VISIBLE);
603
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700604 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800605 backButton.setOnClickListener(new OnClickListener() {
606 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700607 setResult(RESULT_CANCELED, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800608 finish();
609 }
610 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700611 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800612 skipButton.setOnClickListener(new OnClickListener() {
613 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700614 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800615 finish();
616 }
617 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700618 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800619 mNextButton.setOnClickListener(new OnClickListener() {
620 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700621 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800622 finish();
623 }
624 });
625
626 // set our various button parameters
627 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
628 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
629 if (TextUtils.isEmpty(buttonText)) {
630 mNextButton.setVisibility(View.GONE);
631 }
632 else {
633 mNextButton.setText(buttonText);
634 }
635 }
636 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
637 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
638 if (TextUtils.isEmpty(buttonText)) {
639 backButton.setVisibility(View.GONE);
640 }
641 else {
642 backButton.setText(buttonText);
643 }
644 }
645 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
646 skipButton.setVisibility(View.VISIBLE);
647 }
648 }
649 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700650
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
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700655 private void setTitleFromIntent(Intent intent) {
656 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
657 if (initialTitleResId > 0) {
658 mInitialTitle = null;
659 mInitialTitleResId = initialTitleResId;
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100660
661 final String initialTitleResPackageName = intent.getStringExtra(
662 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
663 if (initialTitleResPackageName != null) {
664 try {
665 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
666 0 /* flags */, new UserHandle(UserHandle.myUserId()));
667 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
668 setTitle(mInitialTitle);
669 mInitialTitleResId = -1;
670 return;
671 } catch (NameNotFoundException e) {
672 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
673 }
674 } else {
675 setTitle(mInitialTitleResId);
676 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700677 } else {
678 mInitialTitleResId = -1;
679 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
680 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
681 setTitle(mInitialTitle);
682 }
683 }
684
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800685 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800686 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700687 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800688 }
689
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700690 private int setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800691 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700692
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800693 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700694 if (mInitialTitleResId > 0) {
695 setTitle(mInitialTitleResId);
696 } else {
697 setTitle(mInitialTitle);
698 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700699 return 0;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800700 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700701
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800702 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
703 setTitleFromBackStackEntry(bse);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700704
705 return count;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800706 }
707
708 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
709 final CharSequence title;
710 final int titleRes = bse.getBreadCrumbTitleRes();
711 if (titleRes > 0) {
712 title = getText(titleRes);
713 } else {
714 title = bse.getBreadCrumbTitle();
715 }
716 if (title != null) {
717 setTitle(title);
718 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800719 }
720
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800721 @Override
722 protected void onSaveInstanceState(Bundle outState) {
723 super.onSaveInstanceState(outState);
724
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700725 if (mCategories.size() > 0) {
726 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800727 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700728
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700729 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700730 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700731
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700732 if (mDisplaySearch) {
733 // The option menus are created if the ActionBar is visible and they are also created
734 // asynchronously. If you launch Settings with an Intent action like
735 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
736 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
737 // menu item and search view are null.
738 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
739 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700740
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700741 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
742 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
743 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800744 }
745
746 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400747 protected void onResume() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800748 super.onResume();
749
750 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
751 @Override
752 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Jason Monk4da79e02015-09-10 10:54:36 -0400753 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800754 }
755 };
756 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
757 mDevelopmentPreferencesListener);
758
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800759 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Clara Bayarri6934a042015-10-14 11:07:35 +0100760 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_ADDED));
761 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_REMOVED));
Svetoslav853e4712014-04-14 10:10:25 -0700762
Svetoslav990159a2014-04-14 17:14:59 -0700763 mDynamicIndexableContentMonitor.register(this);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700764
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700765 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700766 onQueryTextSubmit(mSearchQuery);
767 }
Jason Monk4da79e02015-09-10 10:54:36 -0400768 updateTilesList();
Jason Monk478c5922016-01-22 15:20:20 -0500769 if (mIsShowingDashboard) {
770 showMenuIcon();
771 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800772 }
773
774 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400775 protected void onPause() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800776 super.onPause();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800777 unregisterReceiver(mBatteryInfoReceiver);
Clara Bayarri8c9521f2016-01-12 14:10:45 +0000778 unregisterReceiver(mUserAddRemoveReceiver);
Svetoslav990159a2014-04-14 17:14:59 -0700779 mDynamicIndexableContentMonitor.unregister();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800780 }
781
782 @Override
783 public void onDestroy() {
784 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700785
786 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
787 mDevelopmentPreferencesListener);
788 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800789 }
790
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800791 protected boolean isValidFragment(String fragmentName) {
792 // Almost all fragments are wrapped in this,
793 // except for a few that have their own activities.
794 for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
795 if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
796 }
797 return false;
798 }
799
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800800 @Override
801 public Intent getIntent() {
802 Intent superIntent = super.getIntent();
803 String startingFragment = getStartingFragmentClass(superIntent);
804 // This is called from super.onCreate, isMultiPane() is not yet reliable
805 // Do not use onIsHidingHeaders either, which relies itself on this method
806 if (startingFragment != null) {
807 Intent modIntent = new Intent(superIntent);
808 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
809 Bundle args = superIntent.getExtras();
810 if (args != null) {
811 args = new Bundle(args);
812 } else {
813 args = new Bundle();
814 }
815 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100816 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800817 return modIntent;
818 }
819 return superIntent;
820 }
821
822 /**
823 * Checks if the component name in the intent is different from the Settings class and
824 * returns the class name to load as a fragment.
825 */
826 private String getStartingFragmentClass(Intent intent) {
827 if (mFragmentClass != null) return mFragmentClass;
828
829 String intentClass = intent.getComponent().getClassName();
830 if (intentClass.equals(getClass().getName())) return null;
831
832 if ("com.android.settings.ManageApplications".equals(intentClass)
833 || "com.android.settings.RunningServices".equals(intentClass)
834 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
835 // Old names of manage apps.
836 intentClass = com.android.settings.applications.ManageApplications.class.getName();
837 }
838
839 return intentClass;
840 }
841
842 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000843 * Start a new fragment containing a preference panel. If the preferences
844 * are being displayed in multi-pane mode, the given fragment class will
845 * be instantiated and placed in the appropriate pane. If running in
846 * single-pane mode, a new activity will be launched in which to show the
847 * fragment.
848 *
849 * @param fragmentClass Full name of the class implementing the fragment.
850 * @param args Any desired arguments to supply to the fragment.
851 * @param titleRes Optional resource identifier of the title of this
852 * fragment.
853 * @param titleText Optional text of the title of this fragment.
854 * @param resultTo Optional fragment that result data should be sent to.
855 * If non-null, resultTo.onActivityResult() will be called when this
856 * preference panel is done. The launched panel must use
857 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
858 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700859 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000860 */
861 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700862 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700863 String title = null;
864 if (titleRes < 0) {
865 if (titleText != null) {
866 title = titleText.toString();
867 } else {
868 // There not much we can do in that case
869 title = "";
870 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700871 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700872 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700873 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000874 }
875
876 /**
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100877 * Start a new fragment in a new activity containing a preference panel for a given user. If the
878 * preferences are being displayed in multi-pane mode, the given fragment class will be
879 * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
880 * activity will be launched in which to show the fragment.
881 *
882 * @param fragmentClass Full name of the class implementing the fragment.
883 * @param args Any desired arguments to supply to the fragment.
884 * @param titleRes Optional resource identifier of the title of this fragment.
885 * @param titleText Optional text of the title of this fragment.
886 * @param userHandle The user for which the panel has to be started.
887 */
888 public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
889 CharSequence titleText, UserHandle userHandle) {
Lifu Tangd0332852015-04-02 12:05:46 -0700890 // This is a workaround.
891 //
892 // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
893 // starting the fragment could cause a native stack corruption. See b/17523189. However,
894 // adding that flag and start the preference panel with the same UserHandler will make it
895 // impossible to use back button to return to the previous screen. See b/20042570.
896 //
897 // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
898 // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
899 // when we're calling it as the same user.
900 if (userHandle.getIdentifier() == UserHandle.myUserId()) {
901 startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0);
902 } else {
903 String title = null;
904 if (titleRes < 0) {
905 if (titleText != null) {
906 title = titleText.toString();
907 } else {
908 // There not much we can do in that case
909 title = "";
910 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100911 }
Lifu Tangd0332852015-04-02 12:05:46 -0700912 Utils.startWithFragmentAsUser(this, fragmentClass, args,
913 titleRes, title, mIsShortcut, userHandle);
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100914 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100915 }
916
917 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800918 * Called by a preference panel fragment to finish itself.
919 *
920 * @param caller The fragment that is asking to be finished.
921 * @param resultCode Optional result code to send back to the original
922 * launching fragment.
923 * @param resultData Optional result data to send back to the original
924 * launching fragment.
925 */
926 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
927 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700928 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800929 }
930
931 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000932 * Start a new fragment.
933 *
934 * @param fragment The fragment to start
935 * @param push If true, the current fragment will be pushed onto the back stack. If false,
936 * the current fragment will be replaced.
937 */
938 public void startPreferenceFragment(Fragment fragment, boolean push) {
939 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700940 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000941 if (push) {
942 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
943 transaction.addToBackStack(BACK_STACK_PREFS);
944 } else {
945 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
946 }
947 transaction.commitAllowingStateLoss();
948 }
949
950 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700951 * Switch to a specific Fragment with taking care of validation, Title and BackStack
952 */
953 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700954 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700955 if (validate && !isValidFragment(fragmentName)) {
956 throw new IllegalArgumentException("Invalid fragment for this activity: "
957 + fragmentName);
958 }
959 Fragment f = Fragment.instantiate(this, fragmentName, args);
960 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700961 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700962 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700963 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700964 }
965 if (addToBackStack) {
966 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
967 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700968 if (titleResId > 0) {
969 transaction.setBreadCrumbTitle(titleResId);
970 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700971 transaction.setBreadCrumbTitle(title);
972 }
973 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700974 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700975 return f;
976 }
977
Jason Monk4da79e02015-09-10 10:54:36 -0400978 private void updateTilesList() {
Jason Monkfd2c7222015-12-02 15:38:38 -0500979 // Generally the items that are will be changing from these updates will
980 // not be in the top list of tiles, so run it in the background and the
981 // SettingsDrawerActivity will pick up on the updates automatically.
982 AsyncTask.execute(new Runnable() {
983 @Override
984 public void run() {
985 doUpdateTilesList();
986 }
987 });
988 }
989
990 private void doUpdateTilesList() {
Jason Monk4da79e02015-09-10 10:54:36 -0400991 PackageManager pm = getPackageManager();
Xiaohui Chen44879a32015-07-22 13:53:22 -0700992 final UserManager um = UserManager.get(this);
993 final boolean isAdmin = um.isAdminUser();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700994
Jason Monk4da79e02015-09-10 10:54:36 -0400995 String packageName = getPackageName();
996 setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()),
997 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700998
Jason Monk4da79e02015-09-10 10:54:36 -0400999 setTileEnabled(new ComponentName(packageName,
1000 Settings.BluetoothSettingsActivity.class.getName()),
1001 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001002
Jason Monk4da79e02015-09-10 10:54:36 -04001003 setTileEnabled(new ComponentName(packageName,
1004 Settings.DataUsageSummaryActivity.class.getName()),
1005 Utils.isBandwidthControlEnabled(), 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.SimSettingsActivity.class.getName()),
1009 Utils.showSimCardTile(this), 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.PowerUsageSummaryActivity.class.getName()),
1013 mBatteryPresent, isAdmin, pm);
1014
1015 setTileEnabled(new ComponentName(packageName,
Jason Monk4da79e02015-09-10 10:54:36 -04001016 Settings.UserSettingsActivity.class.getName()),
1017 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
1018 && !Utils.isMonkeyRunning(), isAdmin, pm);
1019
1020 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
1021 setTileEnabled(new ComponentName(packageName,
1022 Settings.PaymentSettingsActivity.class.getName()),
1023 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
1024 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
1025 && adapter != null && adapter.isEnabled(), isAdmin, pm);
1026
1027 setTileEnabled(new ComponentName(packageName,
1028 Settings.PrintSettingsActivity.class.getName()),
1029 pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin, pm);
1030
1031 final boolean showDev = mDevelopmentPreferences.getBoolean(
1032 DevelopmentSettings.PREF_SHOW,
1033 android.os.Build.TYPE.equals("eng"));
1034 setTileEnabled(new ComponentName(packageName,
1035 Settings.DevelopmentSettingsActivity.class.getName()),
1036 showDev && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES),
1037 isAdmin, pm);
1038
1039 if (UserHandle.MU_ENABLED && !isAdmin) {
1040 // When on restricted users, disable all extra categories (but only the settings ones).
Jason Monkfd2c7222015-12-02 15:38:38 -05001041 List<DashboardCategory> categories = getDashboardCategories();
Jason Monk4da79e02015-09-10 10:54:36 -04001042 for (DashboardCategory category : categories) {
Jason Monkd4f03ec2016-01-07 16:25:34 -05001043 for (Tile tile : category.tiles) {
Jason Monk4da79e02015-09-10 10:54:36 -04001044 ComponentName component = tile.intent.getComponent();
1045 if (packageName.equals(component)&& !ArrayUtils.contains(
1046 SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1047 setTileEnabled(component, false, isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001048 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001049 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001050 }
1051 }
Jason Monk2ebc8a02015-02-13 15:23:19 -05001052 }
1053
Jason Monk4da79e02015-09-10 10:54:36 -04001054 private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin,
1055 PackageManager pm) {
1056 if (UserHandle.MU_ENABLED && !isAdmin
1057 && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1058 enabled = false;
1059 }
1060 int state = pm.getComponentEnabledSetting(component);
1061 boolean isEnabled = state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
1062 || state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
1063 if (isEnabled != enabled) {
1064 pm.setComponentEnabledSetting(component, enabled
1065 ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
1066 : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
1067 PackageManager.DONT_KILL_APP);
Jason Monk2ebc8a02015-02-13 15:23:19 -05001068 }
1069 }
1070
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001071 private void getMetaData() {
1072 try {
1073 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1074 PackageManager.GET_META_DATA);
1075 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001076 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1077 } catch (NameNotFoundException nnfe) {
1078 // No recovery
1079 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1080 }
1081 }
1082
1083 // give subclasses access to the Next button
1084 public boolean hasNextButton() {
1085 return mNextButton != null;
1086 }
1087
1088 public Button getNextButton() {
1089 return mNextButton;
1090 }
1091
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001092 @Override
1093 public boolean shouldUpRecreateTask(Intent targetIntent) {
1094 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1095 }
1096
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001097 @Override
1098 public boolean onQueryTextSubmit(String query) {
1099 switchToSearchResultsFragmentIfNeeded();
1100 mSearchQuery = query;
1101 return mSearchResultsFragment.onQueryTextSubmit(query);
1102 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001103
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001104 @Override
1105 public boolean onQueryTextChange(String newText) {
1106 mSearchQuery = newText;
Fabrice Di Meglio7e4855e2014-05-23 16:03:43 -07001107 if (mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001108 return false;
1109 }
1110 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001111 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001112
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001113 @Override
1114 public boolean onClose() {
1115 return false;
1116 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001117
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001118 @Override
1119 public boolean onMenuItemActionExpand(MenuItem item) {
1120 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001121 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001122 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001123 return true;
1124 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001125
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001126 @Override
1127 public boolean onMenuItemActionCollapse(MenuItem item) {
1128 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001129 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001130 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001131 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001132 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001133 return true;
1134 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001135
Jason Monk4da79e02015-09-10 10:54:36 -04001136 @Override
Jason Monkd4f03ec2016-01-07 16:25:34 -05001137 protected void onTileClicked(Tile tile) {
Jason Monk4da79e02015-09-10 10:54:36 -04001138 if (mIsShowingDashboard) {
1139 // If on dashboard, don't finish so the back comes back to here.
1140 openTile(tile);
1141 } else {
1142 super.onTileClicked(tile);
1143 }
1144 }
1145
Jason Monkaf001092015-11-04 13:16:18 -05001146 @Override
1147 public void onProfileTileOpen() {
1148 if (!mIsShowingDashboard) {
1149 finish();
1150 }
1151 }
1152
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001153 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001154 if (mSearchResultsFragment != null) {
1155 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001156 }
Fabrice Di Megliod40dd452014-07-18 15:20:34 -07001157 Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001158 if (current != null && current instanceof SearchResultsSummary) {
1159 mSearchResultsFragment = (SearchResultsSummary) current;
1160 } else {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001161 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001162 SearchResultsSummary.class.getName(), null, false, true,
1163 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001164 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001165 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001166 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001167 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001168
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001169 public void needToRevertToInitialFragment() {
1170 mNeedToRevertToInitialFragment = true;
1171 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001172
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001173 private void revertToInitialFragment() {
1174 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001175 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001176 mSearchMenuItemExpanded = false;
1177 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1178 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001179 if (mSearchMenuItem != null) {
1180 mSearchMenuItem.collapseActionView();
1181 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001182 }
Jim Miller0698a212014-10-16 19:49:07 -07001183
1184 public Intent getResultIntentData() {
1185 return mResultIntentData;
1186 }
1187
1188 public void setResultIntentData(Intent resultIntentData) {
1189 mResultIntentData = resultIntentData;
1190 }
Jason Monkd4f03ec2016-01-07 16:25:34 -05001191
1192 public void startSuggestion(Intent intent) {
1193 mCurrentSuggestion = intent.getComponent();
1194 startActivityForResult(intent, REQUEST_SUGGESTION);
1195 }
1196
1197 @Override
1198 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
1199 if (requestCode == REQUEST_SUGGESTION && mCurrentSuggestion != null
1200 && resultCode != RESULT_CANCELED) {
1201 getPackageManager().setComponentEnabledSetting(mCurrentSuggestion,
1202 PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
1203 }
1204 super.onActivityResult(requestCode, resultCode, data);
1205 }
1206
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001207}