blob: a375cb150405f2c1d6ad0f1cc5a284a42bc906cc [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(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800317 };
318
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700319
320 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
321 "android.settings.APPLICATION_DETAILS_SETTINGS"
322 };
323
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800324 private SharedPreferences mDevelopmentPreferences;
325 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
326
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800327 private boolean mBatteryPresent = true;
328 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800329 @Override
330 public void onReceive(Context context, Intent intent) {
331 String action = intent.getAction();
332 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
333 boolean batteryPresent = Utils.isBatteryPresent(intent);
334
335 if (mBatteryPresent != batteryPresent) {
336 mBatteryPresent = batteryPresent;
Jason Monk4da79e02015-09-10 10:54:36 -0400337 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800338 }
339 }
340 }
341 };
342
Clara Bayarri6934a042015-10-14 11:07:35 +0100343 private final BroadcastReceiver mUserAddRemoveReceiver = new BroadcastReceiver() {
344 @Override
345 public void onReceive(Context context, Intent intent) {
346 String action = intent.getAction();
347 if (action.equals(Intent.ACTION_USER_ADDED)
348 || action.equals(Intent.ACTION_USER_REMOVED)) {
349 Index.getInstance(getApplicationContext()).update();
350 }
351 }
352 };
353
Svetoslav990159a2014-04-14 17:14:59 -0700354 private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor =
355 new DynamicIndexableContentMonitor();
Svetoslav853e4712014-04-14 10:10:25 -0700356
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700357 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700358 private SwitchBar mSwitchBar;
359
360 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700361
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700362 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700363 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700364
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700365 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700366 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700367
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700368 private ViewGroup mContent;
369
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700370 private SearchView mSearchView;
371 private MenuItem mSearchMenuItem;
372 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700373 private SearchResultsSummary mSearchResultsFragment;
374 private String mSearchQuery;
375
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700376 // Categories
377 private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800378
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700379 private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800380
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700381 private boolean mNeedToRevertToInitialFragment = false;
382
Jim Miller0698a212014-10-16 19:49:07 -0700383 private Intent mResultIntentData;
Jason Monkd4f03ec2016-01-07 16:25:34 -0500384 private ComponentName mCurrentSuggestion;
Jim Miller0698a212014-10-16 19:49:07 -0700385
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700386 public SwitchBar getSwitchBar() {
387 return mSwitchBar;
388 }
389
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800390 @Override
391 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
392 // Override the fragment title for Wallpaper settings
Jason Monk39b46742015-09-10 15:52:51 -0400393 CharSequence title = pref.getTitle();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800394 if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) {
Jason Monk39b46742015-09-10 15:52:51 -0400395 title = getString(R.string.wallpaper_settings_fragment_title);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800396 }
Jason Monkb1dd5c92015-12-16 16:13:54 -0500397 startPreferencePanel(pref.getFragment(), pref.getExtras(), -1, title,
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800398 null, 0);
399 return true;
400 }
401
402 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400403 public boolean onPreferenceTreeClick(Preference preference) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800404 return false;
405 }
406
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800407 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800408 public void onConfigurationChanged(Configuration newConfig) {
409 super.onConfigurationChanged(newConfig);
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800410 Index.getInstance(this).update();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800411 }
412
413 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700414 protected void onStart() {
415 super.onStart();
416
417 if (mNeedToRevertToInitialFragment) {
418 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800419 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800420 }
421
422 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700423 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700424 if (!mDisplaySearch) {
425 return false;
426 }
427
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700428 MenuInflater inflater = getMenuInflater();
429 inflater.inflate(R.menu.options_menu, menu);
430
431 // Cache the search query (can be overriden by the OnQueryTextListener)
432 final String query = mSearchQuery;
433
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700434 mSearchMenuItem = menu.findItem(R.id.search);
435 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700436
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700437 if (mSearchMenuItem == null || mSearchView == null) {
438 return false;
439 }
440
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700441 if (mSearchResultsFragment != null) {
442 mSearchResultsFragment.setSearchView(mSearchView);
443 }
444
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700445 mSearchMenuItem.setOnActionExpandListener(this);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700446 mSearchView.setOnQueryTextListener(this);
447 mSearchView.setOnCloseListener(this);
448
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700449 if (mSearchMenuItemExpanded) {
450 mSearchMenuItem.expandActionView();
451 }
452 mSearchView.setQuery(query, true /* submit */);
453
454 return true;
455 }
456
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700457 private static boolean isShortCutIntent(final Intent intent) {
458 Set<String> categories = intent.getCategories();
459 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
460 }
461
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700462 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700463 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700464 if (action == null) {
465 return false;
466 }
467 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
468 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
469 }
470 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700471 }
472
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700473 @Override
474 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700475 super.onCreate(savedState);
Jason Monkfd2c7222015-12-02 15:38:38 -0500476 long startTime = System.currentTimeMillis();
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700477
478 // Should happen before any call to getIntent()
479 getMetaData();
480
481 final Intent intent = getIntent();
482 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
483 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800484 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800485
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800486 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
487 Context.MODE_PRIVATE);
488
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700489 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700490 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700491
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700492 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700493 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
494
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700495 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700496 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700497
Jason Monk4da79e02015-09-10 10:54:36 -0400498 mIsShowingDashboard = className.equals(Settings.class.getName())
499 || className.equals(Settings.WirelessSettings.class.getName())
500 || className.equals(Settings.DeviceSettings.class.getName())
501 || className.equals(Settings.PersonalSettings.class.getName())
502 || className.equals(Settings.WirelessSettings.class.getName());
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700503
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700504 // This is a "Sub Settings" when:
505 // - this is a real SubSettings
506 // - or :settings:show_fragment_as_subsetting is passed to the Intent
Jorim Jaggi4dfcb822015-04-29 17:21:32 -0700507 final boolean isSubSettings = this instanceof SubSettings ||
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700508 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
509
510 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
511 if (isSubSettings) {
Fabrice Di Meglio712df6c2014-07-18 17:44:37 -0700512 // Check also that we are not a Theme Dialog as we don't want to override them
513 final int themeResId = getThemeResId();
514 if (themeResId != R.style.Theme_DialogWhenLarge &&
515 themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
516 setTheme(R.style.Theme_SubSettings);
517 }
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700518 }
519
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700520 setContentView(mIsShowingDashboard ?
521 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800522
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700523 mContent = (ViewGroup) findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700524
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800525 getFragmentManager().addOnBackStackChangedListener(this);
526
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700527 if (mIsShowingDashboard) {
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800528 // Run the Index update only if we have some space
529 if (!Utils.isLowStorage(this)) {
Jason Monkfd2c7222015-12-02 15:38:38 -0500530 long indexStartTime = System.currentTimeMillis();
531 AsyncTask.execute(new Runnable() {
532 @Override
533 public void run() {
534 Index.getInstance(getApplicationContext()).update();
535 }
536 });
537 if (DEBUG_TIMING) Log.d(LOG_TAG, "Index.update() took "
538 + (System.currentTimeMillis() - indexStartTime) + " ms");
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800539 } else {
540 Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
541 }
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700542 }
543
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700544 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700545 // We are restarting from a previous saved state; used that to initialize, instead
546 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700547 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
548 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800549
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700550 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800551
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700552 ArrayList<DashboardCategory> categories =
553 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
554 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700555 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700556 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700557 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800558 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700559
560 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700561 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
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
Jason Monkfd2c7222015-12-02 15:38:38 -0500650 if (DEBUG_TIMING) Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
651 + " ms");
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700652 }
653
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700654 private void setTitleFromIntent(Intent intent) {
655 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
656 if (initialTitleResId > 0) {
657 mInitialTitle = null;
658 mInitialTitleResId = initialTitleResId;
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100659
660 final String initialTitleResPackageName = intent.getStringExtra(
661 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
662 if (initialTitleResPackageName != null) {
663 try {
664 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
665 0 /* flags */, new UserHandle(UserHandle.myUserId()));
666 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
667 setTitle(mInitialTitle);
668 mInitialTitleResId = -1;
669 return;
670 } catch (NameNotFoundException e) {
671 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
672 }
673 } else {
674 setTitle(mInitialTitleResId);
675 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700676 } else {
677 mInitialTitleResId = -1;
678 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
679 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
680 setTitle(mInitialTitle);
681 }
682 }
683
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800684 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800685 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700686 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800687 }
688
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700689 private int setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800690 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700691
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800692 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700693 if (mInitialTitleResId > 0) {
694 setTitle(mInitialTitleResId);
695 } else {
696 setTitle(mInitialTitle);
697 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700698 return 0;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800699 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700700
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800701 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
702 setTitleFromBackStackEntry(bse);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700703
704 return count;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800705 }
706
707 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
708 final CharSequence title;
709 final int titleRes = bse.getBreadCrumbTitleRes();
710 if (titleRes > 0) {
711 title = getText(titleRes);
712 } else {
713 title = bse.getBreadCrumbTitle();
714 }
715 if (title != null) {
716 setTitle(title);
717 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800718 }
719
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800720 @Override
721 protected void onSaveInstanceState(Bundle outState) {
722 super.onSaveInstanceState(outState);
723
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700724 if (mCategories.size() > 0) {
725 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800726 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700727
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700728 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700729 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700730
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700731 if (mDisplaySearch) {
732 // The option menus are created if the ActionBar is visible and they are also created
733 // asynchronously. If you launch Settings with an Intent action like
734 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
735 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
736 // menu item and search view are null.
737 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
738 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700739
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700740 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
741 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
742 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800743 }
744
745 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400746 protected void onResume() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800747 super.onResume();
748
749 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
750 @Override
751 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Jason Monk4da79e02015-09-10 10:54:36 -0400752 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800753 }
754 };
755 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
756 mDevelopmentPreferencesListener);
757
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800758 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Clara Bayarri6934a042015-10-14 11:07:35 +0100759 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_ADDED));
760 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_REMOVED));
Svetoslav853e4712014-04-14 10:10:25 -0700761
Svetoslav990159a2014-04-14 17:14:59 -0700762 mDynamicIndexableContentMonitor.register(this);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700763
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700764 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700765 onQueryTextSubmit(mSearchQuery);
766 }
Jason Monk4da79e02015-09-10 10:54:36 -0400767 updateTilesList();
Jason Monk478c5922016-01-22 15:20:20 -0500768 if (mIsShowingDashboard) {
769 showMenuIcon();
770 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800771 }
772
773 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400774 protected void onPause() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800775 super.onPause();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800776 unregisterReceiver(mBatteryInfoReceiver);
Clara Bayarri8c9521f2016-01-12 14:10:45 +0000777 unregisterReceiver(mUserAddRemoveReceiver);
Svetoslav990159a2014-04-14 17:14:59 -0700778 mDynamicIndexableContentMonitor.unregister();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800779 }
780
781 @Override
782 public void onDestroy() {
783 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700784
785 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
786 mDevelopmentPreferencesListener);
787 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800788 }
789
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800790 protected boolean isValidFragment(String fragmentName) {
791 // Almost all fragments are wrapped in this,
792 // except for a few that have their own activities.
793 for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
794 if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
795 }
796 return false;
797 }
798
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800799 @Override
800 public Intent getIntent() {
801 Intent superIntent = super.getIntent();
802 String startingFragment = getStartingFragmentClass(superIntent);
803 // This is called from super.onCreate, isMultiPane() is not yet reliable
804 // Do not use onIsHidingHeaders either, which relies itself on this method
805 if (startingFragment != null) {
806 Intent modIntent = new Intent(superIntent);
807 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
808 Bundle args = superIntent.getExtras();
809 if (args != null) {
810 args = new Bundle(args);
811 } else {
812 args = new Bundle();
813 }
814 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100815 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800816 return modIntent;
817 }
818 return superIntent;
819 }
820
821 /**
822 * Checks if the component name in the intent is different from the Settings class and
823 * returns the class name to load as a fragment.
824 */
825 private String getStartingFragmentClass(Intent intent) {
826 if (mFragmentClass != null) return mFragmentClass;
827
828 String intentClass = intent.getComponent().getClassName();
829 if (intentClass.equals(getClass().getName())) return null;
830
831 if ("com.android.settings.ManageApplications".equals(intentClass)
832 || "com.android.settings.RunningServices".equals(intentClass)
833 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
834 // Old names of manage apps.
835 intentClass = com.android.settings.applications.ManageApplications.class.getName();
836 }
837
838 return intentClass;
839 }
840
841 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000842 * Start a new fragment containing a preference panel. If the preferences
843 * are being displayed in multi-pane mode, the given fragment class will
844 * be instantiated and placed in the appropriate pane. If running in
845 * single-pane mode, a new activity will be launched in which to show the
846 * fragment.
847 *
848 * @param fragmentClass Full name of the class implementing the fragment.
849 * @param args Any desired arguments to supply to the fragment.
850 * @param titleRes Optional resource identifier of the title of this
851 * fragment.
852 * @param titleText Optional text of the title of this fragment.
853 * @param resultTo Optional fragment that result data should be sent to.
854 * If non-null, resultTo.onActivityResult() will be called when this
855 * preference panel is done. The launched panel must use
856 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
857 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700858 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000859 */
860 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700861 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700862 String title = null;
863 if (titleRes < 0) {
864 if (titleText != null) {
865 title = titleText.toString();
866 } else {
867 // There not much we can do in that case
868 title = "";
869 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700870 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700871 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700872 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000873 }
874
875 /**
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100876 * Start a new fragment in a new activity containing a preference panel for a given user. If the
877 * preferences are being displayed in multi-pane mode, the given fragment class will be
878 * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
879 * activity will be launched in which to show the fragment.
880 *
881 * @param fragmentClass Full name of the class implementing the fragment.
882 * @param args Any desired arguments to supply to the fragment.
883 * @param titleRes Optional resource identifier of the title of this fragment.
884 * @param titleText Optional text of the title of this fragment.
885 * @param userHandle The user for which the panel has to be started.
886 */
887 public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
888 CharSequence titleText, UserHandle userHandle) {
Lifu Tangd0332852015-04-02 12:05:46 -0700889 // This is a workaround.
890 //
891 // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
892 // starting the fragment could cause a native stack corruption. See b/17523189. However,
893 // adding that flag and start the preference panel with the same UserHandler will make it
894 // impossible to use back button to return to the previous screen. See b/20042570.
895 //
896 // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
897 // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
898 // when we're calling it as the same user.
899 if (userHandle.getIdentifier() == UserHandle.myUserId()) {
900 startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0);
901 } else {
902 String title = null;
903 if (titleRes < 0) {
904 if (titleText != null) {
905 title = titleText.toString();
906 } else {
907 // There not much we can do in that case
908 title = "";
909 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100910 }
Lifu Tangd0332852015-04-02 12:05:46 -0700911 Utils.startWithFragmentAsUser(this, fragmentClass, args,
912 titleRes, title, mIsShortcut, userHandle);
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100913 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100914 }
915
916 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800917 * Called by a preference panel fragment to finish itself.
918 *
919 * @param caller The fragment that is asking to be finished.
920 * @param resultCode Optional result code to send back to the original
921 * launching fragment.
922 * @param resultData Optional result data to send back to the original
923 * launching fragment.
924 */
925 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
926 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700927 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800928 }
929
930 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000931 * Start a new fragment.
932 *
933 * @param fragment The fragment to start
934 * @param push If true, the current fragment will be pushed onto the back stack. If false,
935 * the current fragment will be replaced.
936 */
937 public void startPreferenceFragment(Fragment fragment, boolean push) {
938 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700939 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000940 if (push) {
941 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
942 transaction.addToBackStack(BACK_STACK_PREFS);
943 } else {
944 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
945 }
946 transaction.commitAllowingStateLoss();
947 }
948
949 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700950 * Switch to a specific Fragment with taking care of validation, Title and BackStack
951 */
952 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700953 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700954 if (validate && !isValidFragment(fragmentName)) {
955 throw new IllegalArgumentException("Invalid fragment for this activity: "
956 + fragmentName);
957 }
958 Fragment f = Fragment.instantiate(this, fragmentName, args);
959 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700960 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700961 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700962 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700963 }
964 if (addToBackStack) {
965 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
966 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700967 if (titleResId > 0) {
968 transaction.setBreadCrumbTitle(titleResId);
969 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700970 transaction.setBreadCrumbTitle(title);
971 }
972 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700973 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700974 return f;
975 }
976
Jason Monk4da79e02015-09-10 10:54:36 -0400977 private void updateTilesList() {
Jason Monkfd2c7222015-12-02 15:38:38 -0500978 // Generally the items that are will be changing from these updates will
979 // not be in the top list of tiles, so run it in the background and the
980 // SettingsDrawerActivity will pick up on the updates automatically.
981 AsyncTask.execute(new Runnable() {
982 @Override
983 public void run() {
984 doUpdateTilesList();
985 }
986 });
987 }
988
989 private void doUpdateTilesList() {
Jason Monk4da79e02015-09-10 10:54:36 -0400990 PackageManager pm = getPackageManager();
Xiaohui Chen44879a32015-07-22 13:53:22 -0700991 final UserManager um = UserManager.get(this);
992 final boolean isAdmin = um.isAdminUser();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700993
Jason Monk4da79e02015-09-10 10:54:36 -0400994 String packageName = getPackageName();
995 setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()),
996 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700997
Jason Monk4da79e02015-09-10 10:54:36 -0400998 setTileEnabled(new ComponentName(packageName,
999 Settings.BluetoothSettingsActivity.class.getName()),
1000 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001001
Jason Monk4da79e02015-09-10 10:54:36 -04001002 setTileEnabled(new ComponentName(packageName,
1003 Settings.DataUsageSummaryActivity.class.getName()),
1004 Utils.isBandwidthControlEnabled(), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001005
Jason Monk4da79e02015-09-10 10:54:36 -04001006 setTileEnabled(new ComponentName(packageName,
1007 Settings.SimSettingsActivity.class.getName()),
1008 Utils.showSimCardTile(this), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001009
Jason Monk4da79e02015-09-10 10:54:36 -04001010 setTileEnabled(new ComponentName(packageName,
1011 Settings.PowerUsageSummaryActivity.class.getName()),
1012 mBatteryPresent, isAdmin, pm);
1013
1014 setTileEnabled(new ComponentName(packageName,
Jason Monk4da79e02015-09-10 10:54:36 -04001015 Settings.UserSettingsActivity.class.getName()),
1016 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
1017 && !Utils.isMonkeyRunning(), isAdmin, pm);
1018
1019 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
1020 setTileEnabled(new ComponentName(packageName,
1021 Settings.PaymentSettingsActivity.class.getName()),
1022 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
1023 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
1024 && adapter != null && adapter.isEnabled(), isAdmin, pm);
1025
1026 setTileEnabled(new ComponentName(packageName,
1027 Settings.PrintSettingsActivity.class.getName()),
1028 pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin, pm);
1029
1030 final boolean showDev = mDevelopmentPreferences.getBoolean(
1031 DevelopmentSettings.PREF_SHOW,
1032 android.os.Build.TYPE.equals("eng"));
1033 setTileEnabled(new ComponentName(packageName,
1034 Settings.DevelopmentSettingsActivity.class.getName()),
1035 showDev && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES),
1036 isAdmin, pm);
1037
1038 if (UserHandle.MU_ENABLED && !isAdmin) {
1039 // When on restricted users, disable all extra categories (but only the settings ones).
Jason Monkfd2c7222015-12-02 15:38:38 -05001040 List<DashboardCategory> categories = getDashboardCategories();
Jason Monk4da79e02015-09-10 10:54:36 -04001041 for (DashboardCategory category : categories) {
Jason Monkd4f03ec2016-01-07 16:25:34 -05001042 for (Tile tile : category.tiles) {
Jason Monk4da79e02015-09-10 10:54:36 -04001043 ComponentName component = tile.intent.getComponent();
1044 if (packageName.equals(component)&& !ArrayUtils.contains(
1045 SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1046 setTileEnabled(component, false, isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001047 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001048 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001049 }
1050 }
Jason Monk2ebc8a02015-02-13 15:23:19 -05001051 }
1052
Jason Monk4da79e02015-09-10 10:54:36 -04001053 private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin,
1054 PackageManager pm) {
1055 if (UserHandle.MU_ENABLED && !isAdmin
1056 && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1057 enabled = false;
1058 }
1059 int state = pm.getComponentEnabledSetting(component);
1060 boolean isEnabled = state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
1061 || state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
1062 if (isEnabled != enabled) {
1063 pm.setComponentEnabledSetting(component, enabled
1064 ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
1065 : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
1066 PackageManager.DONT_KILL_APP);
Jason Monk2ebc8a02015-02-13 15:23:19 -05001067 }
1068 }
1069
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001070 private void getMetaData() {
1071 try {
1072 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1073 PackageManager.GET_META_DATA);
1074 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001075 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1076 } catch (NameNotFoundException nnfe) {
1077 // No recovery
1078 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1079 }
1080 }
1081
1082 // give subclasses access to the Next button
1083 public boolean hasNextButton() {
1084 return mNextButton != null;
1085 }
1086
1087 public Button getNextButton() {
1088 return mNextButton;
1089 }
1090
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001091 @Override
1092 public boolean shouldUpRecreateTask(Intent targetIntent) {
1093 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1094 }
1095
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001096 @Override
1097 public boolean onQueryTextSubmit(String query) {
1098 switchToSearchResultsFragmentIfNeeded();
1099 mSearchQuery = query;
1100 return mSearchResultsFragment.onQueryTextSubmit(query);
1101 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001102
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001103 @Override
1104 public boolean onQueryTextChange(String newText) {
1105 mSearchQuery = newText;
Fabrice Di Meglio7e4855e2014-05-23 16:03:43 -07001106 if (mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001107 return false;
1108 }
1109 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001110 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001111
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001112 @Override
1113 public boolean onClose() {
1114 return false;
1115 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001116
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001117 @Override
1118 public boolean onMenuItemActionExpand(MenuItem item) {
1119 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001120 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001121 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001122 return true;
1123 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001124
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001125 @Override
1126 public boolean onMenuItemActionCollapse(MenuItem item) {
1127 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001128 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001129 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001130 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001131 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001132 return true;
1133 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001134
Jason Monk4da79e02015-09-10 10:54:36 -04001135 @Override
Jason Monkd4f03ec2016-01-07 16:25:34 -05001136 protected void onTileClicked(Tile tile) {
Jason Monk4da79e02015-09-10 10:54:36 -04001137 if (mIsShowingDashboard) {
1138 // If on dashboard, don't finish so the back comes back to here.
1139 openTile(tile);
1140 } else {
1141 super.onTileClicked(tile);
1142 }
1143 }
1144
Jason Monkaf001092015-11-04 13:16:18 -05001145 @Override
1146 public void onProfileTileOpen() {
1147 if (!mIsShowingDashboard) {
1148 finish();
1149 }
1150 }
1151
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001152 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001153 if (mSearchResultsFragment != null) {
1154 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001155 }
Fabrice Di Megliod40dd452014-07-18 15:20:34 -07001156 Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001157 if (current != null && current instanceof SearchResultsSummary) {
1158 mSearchResultsFragment = (SearchResultsSummary) current;
1159 } else {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001160 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001161 SearchResultsSummary.class.getName(), null, false, true,
1162 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001163 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001164 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001165 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001166 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001167
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001168 public void needToRevertToInitialFragment() {
1169 mNeedToRevertToInitialFragment = true;
1170 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001171
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001172 private void revertToInitialFragment() {
1173 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001174 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001175 mSearchMenuItemExpanded = false;
1176 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1177 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001178 if (mSearchMenuItem != null) {
1179 mSearchMenuItem.collapseActionView();
1180 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001181 }
Jim Miller0698a212014-10-16 19:49:07 -07001182
1183 public Intent getResultIntentData() {
1184 return mResultIntentData;
1185 }
1186
1187 public void setResultIntentData(Intent resultIntentData) {
1188 mResultIntentData = resultIntentData;
1189 }
Jason Monkd4f03ec2016-01-07 16:25:34 -05001190
1191 public void startSuggestion(Intent intent) {
1192 mCurrentSuggestion = intent.getComponent();
1193 startActivityForResult(intent, REQUEST_SUGGESTION);
1194 }
1195
1196 @Override
1197 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
1198 if (requestCode == REQUEST_SUGGESTION && mCurrentSuggestion != null
1199 && resultCode != RESULT_CANCELED) {
1200 getPackageManager().setComponentEnabledSetting(mCurrentSuggestion,
1201 PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
1202 }
1203 super.onActivityResult(requestCode, resultCode, data);
1204 }
1205
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001206}