blob: 403e760fa48773440ea1168a76d2a9c5d2bbead7 [file] [log] [blame]
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.settings;
18
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080019import android.app.ActionBar;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080020import android.app.Fragment;
21import android.app.FragmentManager;
22import android.app.FragmentTransaction;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080023import android.content.BroadcastReceiver;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070024import android.content.ComponentName;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080025import android.content.Context;
26import android.content.Intent;
27import android.content.IntentFilter;
28import android.content.SharedPreferences;
29import android.content.pm.ActivityInfo;
30import android.content.pm.PackageManager;
31import android.content.pm.PackageManager.NameNotFoundException;
32import android.content.pm.ResolveInfo;
33import android.content.res.Configuration;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080034import android.nfc.NfcAdapter;
Jason Monkfd2c7222015-12-02 15:38:38 -050035import android.os.AsyncTask;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080036import android.os.Bundle;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080037import android.os.UserHandle;
38import android.os.UserManager;
Jason Monk39b46742015-09-10 15:52:51 -040039import android.support.v14.preference.PreferenceFragment;
40import android.support.v7.preference.Preference;
41import android.support.v7.preference.PreferenceManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080042import android.text.TextUtils;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070043import android.transition.TransitionManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080044import android.util.Log;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070045import android.view.Menu;
46import android.view.MenuInflater;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080047import android.view.MenuItem;
48import android.view.View;
49import android.view.View.OnClickListener;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070050import android.view.ViewGroup;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080051import android.widget.Button;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070052import android.widget.SearchView;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080053import com.android.internal.util.ArrayUtils;
Jason Monk4da79e02015-09-10 10:54:36 -040054import com.android.settings.Settings.WifiSettingsActivity;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080055import com.android.settings.accessibility.AccessibilitySettings;
Anna Galuszab1795f52016-01-08 14:37:16 -080056import com.android.settings.accessibility.AccessibilitySettingsForSetupWizard;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080057import com.android.settings.accessibility.CaptionPropertiesFragment;
Alexandra Gherghina6d839872014-07-22 12:04:58 +000058import com.android.settings.accounts.AccountSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080059import com.android.settings.accounts.AccountSyncSettings;
Billy Laufee78562015-07-27 12:57:07 +010060import com.android.settings.applications.DrawOverlayDetails;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070061import com.android.settings.applications.InstalledAppDetails;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080062import com.android.settings.applications.ManageApplications;
Xiyuan Xia86a55402015-06-02 14:55:32 -070063import com.android.settings.applications.ManageAssist;
Julia Reynolds2e1e0b72015-12-14 08:32:46 -050064import com.android.settings.applications.ManageDefaultApps;
Jason Monk2cdafc62015-06-12 12:32:50 -040065import com.android.settings.applications.ProcessStatsSummary;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080066import com.android.settings.applications.ProcessStatsUi;
Jason Monkd8da51c2015-04-17 14:34:12 -040067import com.android.settings.applications.UsageAccessDetails;
Billy Laufee78562015-07-27 12:57:07 +010068import com.android.settings.applications.WriteSettingsDetails;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080069import com.android.settings.bluetooth.BluetoothSettings;
70import com.android.settings.dashboard.DashboardSummary;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070071import com.android.settings.dashboard.SearchResultsSummary;
Jason Monkb37e2882016-01-11 14:27:20 -050072import com.android.settings.datausage.DataUsageSummary;
Jeff Sharkeya16257d2015-04-28 13:41:01 -070073import com.android.settings.deviceinfo.PrivateVolumeForget;
Jeff Sharkeye77f0682015-04-29 11:24:57 -070074import com.android.settings.deviceinfo.PrivateVolumeSettings;
Jeff Sharkey42833b22015-04-11 21:27:33 -070075import com.android.settings.deviceinfo.PublicVolumeSettings;
76import com.android.settings.deviceinfo.StorageSettings;
John Spurlockc7f8e8c2014-06-04 19:11:22 -040077import com.android.settings.fuelgauge.BatterySaverSettings;
Jason Monk1eb54eb2015-04-29 12:46:42 -040078import com.android.settings.fuelgauge.PowerUsageDetail;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080079import com.android.settings.fuelgauge.PowerUsageSummary;
80import 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 Monkd4f03ec2016-01-07 16:25:34 -0500116import com.android.settingslib.drawer.Tile;
Jason Monk4da79e02015-09-10 10:54:36 -0400117import com.android.settingslib.drawer.SettingsDrawerActivity;
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(),
253 SpellCheckersSettings.class.getName(),
254 UserDictionaryList.class.getName(),
255 UserDictionarySettings.class.getName(),
Amith Yamasani3033ce02014-07-14 18:03:15 -0700256 HomeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800257 DisplaySettings.class.getName(),
258 DeviceInfoSettings.class.getName(),
259 ManageApplications.class.getName(),
Xiyuan Xia86a55402015-06-02 14:55:32 -0700260 ManageAssist.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800261 ProcessStatsUi.class.getName(),
262 NotificationStation.class.getName(),
263 LocationSettings.class.getName(),
264 SecuritySettings.class.getName(),
Jason Monkd8da51c2015-04-17 14:34:12 -0400265 UsageAccessDetails.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800266 PrivacySettings.class.getName(),
267 DeviceAdminSettings.class.getName(),
268 AccessibilitySettings.class.getName(),
Anna Galuszab1795f52016-01-08 14:37:16 -0800269 AccessibilitySettingsForSetupWizard.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800270 CaptionPropertiesFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800271 com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(),
272 TextToSpeechSettings.class.getName(),
Jeff Sharkey42833b22015-04-11 21:27:33 -0700273 StorageSettings.class.getName(),
Jeff Sharkeya16257d2015-04-28 13:41:01 -0700274 PrivateVolumeForget.class.getName(),
Jeff Sharkeye77f0682015-04-29 11:24:57 -0700275 PrivateVolumeSettings.class.getName(),
276 PublicVolumeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800277 DevelopmentSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800278 AndroidBeam.class.getName(),
279 WifiDisplaySettings.class.getName(),
280 PowerUsageSummary.class.getName(),
281 AccountSyncSettings.class.getName(),
Alexandra Gherghina6d839872014-07-22 12:04:58 +0000282 AccountSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800283 CryptKeeperSettings.class.getName(),
284 DataUsageSummary.class.getName(),
285 DreamSettings.class.getName(),
286 UserSettings.class.getName(),
287 NotificationAccessSettings.class.getName(),
John Spurlock08531a82015-05-07 17:45:43 -0400288 ZenAccessSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800289 PrintSettingsFragment.class.getName(),
290 PrintJobSettingsFragment.class.getName(),
291 TrustedCredentialsSettings.class.getName(),
292 PaymentSettings.class.getName(),
293 KeyboardLayoutPickerFragment.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700294 ZenModeSettings.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500295 SoundSettings.class.getName(),
296 ConfigureNotificationSettings.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700297 ChooseLockPassword.ChooseLockPasswordFragment.class.getName(),
298 ChooseLockPattern.ChooseLockPatternFragment.class.getName(),
John Spurlockc7f8e8c2014-06-04 19:11:22 -0400299 InstalledAppDetails.class.getName(),
300 BatterySaverSettings.class.getName(),
Fabrice Di Megliodcf59dd2014-07-21 11:22:20 -0700301 AppNotificationSettings.class.getName(),
Fabrice Di Meglioe3ff4d82014-07-23 20:03:20 -0700302 OtherSoundSettings.class.getName(),
Narayan Kamath33acb152015-03-16 12:48:05 +0000303 ApnSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400304 WifiCallingSettings.class.getName(),
John Spurlockc1df2aa2015-04-13 20:57:06 -0400305 ZenModePrioritySettings.class.getName(),
John Spurlock533a5662015-06-19 10:47:36 -0400306 ZenModeAutomationSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400307 ZenModeScheduleRuleSettings.class.getName(),
John Spurlockf57bad72015-04-30 09:26:15 -0400308 ZenModeEventRuleSettings.class.getName(),
Julia Reynolds5555d262015-11-09 10:52:17 -0500309 ZenModeVisualInterruptionSettings.class.getName(),
Jason Monk2583fc12015-03-25 09:46:30 -0400310 ProcessStatsUi.class.getName(),
Jason Monk1eb54eb2015-04-29 12:46:42 -0400311 PowerUsageDetail.class.getName(),
Jason Monk2cdafc62015-06-12 12:32:50 -0400312 ProcessStatsSummary.class.getName(),
Billy Laufee78562015-07-27 12:57:07 +0100313 DrawOverlayDetails.class.getName(),
314 WriteSettingsDetails.class.getName(),
Julia Reynolds2e1e0b72015-12-14 08:32:46 -0500315 ManageDefaultApps.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800316 };
317
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700318
319 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
320 "android.settings.APPLICATION_DETAILS_SETTINGS"
321 };
322
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800323 private SharedPreferences mDevelopmentPreferences;
324 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
325
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800326 private boolean mBatteryPresent = true;
327 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800328 @Override
329 public void onReceive(Context context, Intent intent) {
330 String action = intent.getAction();
331 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
332 boolean batteryPresent = Utils.isBatteryPresent(intent);
333
334 if (mBatteryPresent != batteryPresent) {
335 mBatteryPresent = batteryPresent;
Jason Monk4da79e02015-09-10 10:54:36 -0400336 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800337 }
338 }
339 }
340 };
341
Clara Bayarri6934a042015-10-14 11:07:35 +0100342 private final BroadcastReceiver mUserAddRemoveReceiver = new BroadcastReceiver() {
343 @Override
344 public void onReceive(Context context, Intent intent) {
345 String action = intent.getAction();
346 if (action.equals(Intent.ACTION_USER_ADDED)
347 || action.equals(Intent.ACTION_USER_REMOVED)) {
348 Index.getInstance(getApplicationContext()).update();
349 }
350 }
351 };
352
Svetoslav990159a2014-04-14 17:14:59 -0700353 private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor =
354 new DynamicIndexableContentMonitor();
Svetoslav853e4712014-04-14 10:10:25 -0700355
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700356 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700357 private SwitchBar mSwitchBar;
358
359 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700360
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700361 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700362 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700363
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700364 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700365 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700366
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700367 private ViewGroup mContent;
368
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700369 private SearchView mSearchView;
370 private MenuItem mSearchMenuItem;
371 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700372 private SearchResultsSummary mSearchResultsFragment;
373 private String mSearchQuery;
374
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700375 // Categories
376 private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800377
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700378 private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800379
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700380 private boolean mNeedToRevertToInitialFragment = false;
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700381 private int mHomeActivitiesCount = 1;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700382
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 Meglioceb335f2014-07-23 16:25:30 -0700562 mHomeActivitiesCount = savedState.getInt(SAVE_KEY_HOME_ACTIVITIES_COUNT,
563 1 /* one home activity by default */);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800564 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700565 if (!mIsShowingDashboard) {
Jason Monkea8b1a72015-06-02 16:46:34 -0400566 mDisplaySearch = false;
567 // UP will be shown only if it is a sub settings
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700568 if (mIsShortcut) {
569 mDisplayHomeAsUpEnabled = isSubSettings;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700570 } else if (isSubSettings) {
571 mDisplayHomeAsUpEnabled = true;
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700572 } else {
573 mDisplayHomeAsUpEnabled = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700574 }
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700575 setTitleFromIntent(intent);
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700576
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700577 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700578 switchToFragment(initialFragmentName, initialArguments, true, false,
579 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000580 } else {
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700581 // No UP affordance if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700582 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700583 // Show Search affordance
584 mDisplaySearch = true;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700585 mInitialTitleResId = R.string.dashboard_title;
Fabrice Di Meglio42c4b0a2014-05-22 10:30:03 -0700586 switchToFragment(DashboardSummary.class.getName(), null, false, false,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700587 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800588 }
589 }
590
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700591 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700592 if (mActionBar != null) {
593 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
594 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
595 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700596 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
597
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800598 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800599 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
600
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700601 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800602 if (buttonBar != null) {
603 buttonBar.setVisibility(View.VISIBLE);
604
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700605 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800606 backButton.setOnClickListener(new OnClickListener() {
607 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700608 setResult(RESULT_CANCELED, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800609 finish();
610 }
611 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700612 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800613 skipButton.setOnClickListener(new OnClickListener() {
614 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700615 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800616 finish();
617 }
618 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700619 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800620 mNextButton.setOnClickListener(new OnClickListener() {
621 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700622 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800623 finish();
624 }
625 });
626
627 // set our various button parameters
628 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
629 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
630 if (TextUtils.isEmpty(buttonText)) {
631 mNextButton.setVisibility(View.GONE);
632 }
633 else {
634 mNextButton.setText(buttonText);
635 }
636 }
637 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
638 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
639 if (TextUtils.isEmpty(buttonText)) {
640 backButton.setVisibility(View.GONE);
641 }
642 else {
643 backButton.setText(buttonText);
644 }
645 }
646 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
647 skipButton.setVisibility(View.VISIBLE);
648 }
649 }
650 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700651
652 mHomeActivitiesCount = getHomeActivitiesCount();
Jason Monkfd2c7222015-12-02 15:38:38 -0500653 if (DEBUG_TIMING) Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
654 + " ms");
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700655 }
656
657 private int getHomeActivitiesCount() {
658 final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>();
659 getPackageManager().getHomeActivities(homeApps);
660 return homeApps.size();
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800661 }
662
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700663 private void setTitleFromIntent(Intent intent) {
664 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
665 if (initialTitleResId > 0) {
666 mInitialTitle = null;
667 mInitialTitleResId = initialTitleResId;
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100668
669 final String initialTitleResPackageName = intent.getStringExtra(
670 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
671 if (initialTitleResPackageName != null) {
672 try {
673 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
674 0 /* flags */, new UserHandle(UserHandle.myUserId()));
675 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
676 setTitle(mInitialTitle);
677 mInitialTitleResId = -1;
678 return;
679 } catch (NameNotFoundException e) {
680 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
681 }
682 } else {
683 setTitle(mInitialTitleResId);
684 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700685 } else {
686 mInitialTitleResId = -1;
687 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
688 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
689 setTitle(mInitialTitle);
690 }
691 }
692
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800693 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800694 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700695 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800696 }
697
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700698 private int setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800699 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700700
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800701 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700702 if (mInitialTitleResId > 0) {
703 setTitle(mInitialTitleResId);
704 } else {
705 setTitle(mInitialTitle);
706 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700707 return 0;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800708 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700709
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800710 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
711 setTitleFromBackStackEntry(bse);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700712
713 return count;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800714 }
715
716 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
717 final CharSequence title;
718 final int titleRes = bse.getBreadCrumbTitleRes();
719 if (titleRes > 0) {
720 title = getText(titleRes);
721 } else {
722 title = bse.getBreadCrumbTitle();
723 }
724 if (title != null) {
725 setTitle(title);
726 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800727 }
728
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800729 @Override
730 protected void onSaveInstanceState(Bundle outState) {
731 super.onSaveInstanceState(outState);
732
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700733 if (mCategories.size() > 0) {
734 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800735 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700736
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700737 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700738 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700739
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700740 if (mDisplaySearch) {
741 // The option menus are created if the ActionBar is visible and they are also created
742 // asynchronously. If you launch Settings with an Intent action like
743 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
744 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
745 // menu item and search view are null.
746 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
747 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700748
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700749 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
750 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
751 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700752
753 outState.putInt(SAVE_KEY_HOME_ACTIVITIES_COUNT, mHomeActivitiesCount);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800754 }
755
756 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400757 protected void onResume() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800758 super.onResume();
759
760 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
761 @Override
762 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Jason Monk4da79e02015-09-10 10:54:36 -0400763 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800764 }
765 };
766 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
767 mDevelopmentPreferencesListener);
768
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800769 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Clara Bayarri6934a042015-10-14 11:07:35 +0100770 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_ADDED));
771 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_REMOVED));
Svetoslav853e4712014-04-14 10:10:25 -0700772
Svetoslav990159a2014-04-14 17:14:59 -0700773 mDynamicIndexableContentMonitor.register(this);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700774
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700775 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700776 onQueryTextSubmit(mSearchQuery);
777 }
Jason Monk4da79e02015-09-10 10:54:36 -0400778 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800779 }
780
781 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400782 protected void onPause() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800783 super.onPause();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800784 unregisterReceiver(mBatteryInfoReceiver);
Clara Bayarri8c9521f2016-01-12 14:10:45 +0000785 unregisterReceiver(mUserAddRemoveReceiver);
Svetoslav990159a2014-04-14 17:14:59 -0700786 mDynamicIndexableContentMonitor.unregister();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800787 }
788
789 @Override
790 public void onDestroy() {
791 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700792
793 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
794 mDevelopmentPreferencesListener);
795 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800796 }
797
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800798 protected boolean isValidFragment(String fragmentName) {
799 // Almost all fragments are wrapped in this,
800 // except for a few that have their own activities.
801 for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
802 if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
803 }
804 return false;
805 }
806
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800807 @Override
808 public Intent getIntent() {
809 Intent superIntent = super.getIntent();
810 String startingFragment = getStartingFragmentClass(superIntent);
811 // This is called from super.onCreate, isMultiPane() is not yet reliable
812 // Do not use onIsHidingHeaders either, which relies itself on this method
813 if (startingFragment != null) {
814 Intent modIntent = new Intent(superIntent);
815 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
816 Bundle args = superIntent.getExtras();
817 if (args != null) {
818 args = new Bundle(args);
819 } else {
820 args = new Bundle();
821 }
822 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100823 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800824 return modIntent;
825 }
826 return superIntent;
827 }
828
829 /**
830 * Checks if the component name in the intent is different from the Settings class and
831 * returns the class name to load as a fragment.
832 */
833 private String getStartingFragmentClass(Intent intent) {
834 if (mFragmentClass != null) return mFragmentClass;
835
836 String intentClass = intent.getComponent().getClassName();
837 if (intentClass.equals(getClass().getName())) return null;
838
839 if ("com.android.settings.ManageApplications".equals(intentClass)
840 || "com.android.settings.RunningServices".equals(intentClass)
841 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
842 // Old names of manage apps.
843 intentClass = com.android.settings.applications.ManageApplications.class.getName();
844 }
845
846 return intentClass;
847 }
848
849 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000850 * Start a new fragment containing a preference panel. If the preferences
851 * are being displayed in multi-pane mode, the given fragment class will
852 * be instantiated and placed in the appropriate pane. If running in
853 * single-pane mode, a new activity will be launched in which to show the
854 * fragment.
855 *
856 * @param fragmentClass Full name of the class implementing the fragment.
857 * @param args Any desired arguments to supply to the fragment.
858 * @param titleRes Optional resource identifier of the title of this
859 * fragment.
860 * @param titleText Optional text of the title of this fragment.
861 * @param resultTo Optional fragment that result data should be sent to.
862 * If non-null, resultTo.onActivityResult() will be called when this
863 * preference panel is done. The launched panel must use
864 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
865 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700866 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000867 */
868 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700869 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700870 String title = null;
871 if (titleRes < 0) {
872 if (titleText != null) {
873 title = titleText.toString();
874 } else {
875 // There not much we can do in that case
876 title = "";
877 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700878 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700879 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700880 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000881 }
882
883 /**
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100884 * Start a new fragment in a new activity containing a preference panel for a given user. If the
885 * preferences are being displayed in multi-pane mode, the given fragment class will be
886 * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
887 * activity will be launched in which to show the fragment.
888 *
889 * @param fragmentClass Full name of the class implementing the fragment.
890 * @param args Any desired arguments to supply to the fragment.
891 * @param titleRes Optional resource identifier of the title of this fragment.
892 * @param titleText Optional text of the title of this fragment.
893 * @param userHandle The user for which the panel has to be started.
894 */
895 public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
896 CharSequence titleText, UserHandle userHandle) {
Lifu Tangd0332852015-04-02 12:05:46 -0700897 // This is a workaround.
898 //
899 // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
900 // starting the fragment could cause a native stack corruption. See b/17523189. However,
901 // adding that flag and start the preference panel with the same UserHandler will make it
902 // impossible to use back button to return to the previous screen. See b/20042570.
903 //
904 // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
905 // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
906 // when we're calling it as the same user.
907 if (userHandle.getIdentifier() == UserHandle.myUserId()) {
908 startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0);
909 } else {
910 String title = null;
911 if (titleRes < 0) {
912 if (titleText != null) {
913 title = titleText.toString();
914 } else {
915 // There not much we can do in that case
916 title = "";
917 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100918 }
Lifu Tangd0332852015-04-02 12:05:46 -0700919 Utils.startWithFragmentAsUser(this, fragmentClass, args,
920 titleRes, title, mIsShortcut, userHandle);
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100921 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100922 }
923
924 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800925 * Called by a preference panel fragment to finish itself.
926 *
927 * @param caller The fragment that is asking to be finished.
928 * @param resultCode Optional result code to send back to the original
929 * launching fragment.
930 * @param resultData Optional result data to send back to the original
931 * launching fragment.
932 */
933 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
934 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700935 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800936 }
937
938 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000939 * Start a new fragment.
940 *
941 * @param fragment The fragment to start
942 * @param push If true, the current fragment will be pushed onto the back stack. If false,
943 * the current fragment will be replaced.
944 */
945 public void startPreferenceFragment(Fragment fragment, boolean push) {
946 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700947 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000948 if (push) {
949 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
950 transaction.addToBackStack(BACK_STACK_PREFS);
951 } else {
952 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
953 }
954 transaction.commitAllowingStateLoss();
955 }
956
957 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700958 * Switch to a specific Fragment with taking care of validation, Title and BackStack
959 */
960 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700961 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700962 if (validate && !isValidFragment(fragmentName)) {
963 throw new IllegalArgumentException("Invalid fragment for this activity: "
964 + fragmentName);
965 }
966 Fragment f = Fragment.instantiate(this, fragmentName, args);
967 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700968 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700969 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700970 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700971 }
972 if (addToBackStack) {
973 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
974 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700975 if (titleResId > 0) {
976 transaction.setBreadCrumbTitle(titleResId);
977 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700978 transaction.setBreadCrumbTitle(title);
979 }
980 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700981 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700982 return f;
983 }
984
Jason Monk4da79e02015-09-10 10:54:36 -0400985 private void updateTilesList() {
Jason Monkfd2c7222015-12-02 15:38:38 -0500986 // Generally the items that are will be changing from these updates will
987 // not be in the top list of tiles, so run it in the background and the
988 // SettingsDrawerActivity will pick up on the updates automatically.
989 AsyncTask.execute(new Runnable() {
990 @Override
991 public void run() {
992 doUpdateTilesList();
993 }
994 });
995 }
996
997 private void doUpdateTilesList() {
Jason Monk4da79e02015-09-10 10:54:36 -0400998 PackageManager pm = getPackageManager();
Xiaohui Chen44879a32015-07-22 13:53:22 -0700999 final UserManager um = UserManager.get(this);
1000 final boolean isAdmin = um.isAdminUser();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001001
Jason Monk4da79e02015-09-10 10:54:36 -04001002 String packageName = getPackageName();
1003 setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()),
1004 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), 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.BluetoothSettingsActivity.class.getName()),
1008 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), 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.DataUsageSummaryActivity.class.getName()),
1012 Utils.isBandwidthControlEnabled(), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001013
Jason Monk4da79e02015-09-10 10:54:36 -04001014 setTileEnabled(new ComponentName(packageName,
1015 Settings.SimSettingsActivity.class.getName()),
1016 Utils.showSimCardTile(this), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001017
Jason Monk4da79e02015-09-10 10:54:36 -04001018 setTileEnabled(new ComponentName(packageName,
1019 Settings.PowerUsageSummaryActivity.class.getName()),
1020 mBatteryPresent, isAdmin, pm);
1021
1022 setTileEnabled(new ComponentName(packageName,
1023 Settings.HomeSettingsActivity.class.getName()),
1024 updateHomeSettingTiles(), isAdmin, pm);
1025
1026 setTileEnabled(new ComponentName(packageName,
1027 Settings.UserSettingsActivity.class.getName()),
1028 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
1029 && !Utils.isMonkeyRunning(), isAdmin, pm);
1030
1031 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
1032 setTileEnabled(new ComponentName(packageName,
1033 Settings.PaymentSettingsActivity.class.getName()),
1034 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
1035 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
1036 && adapter != null && adapter.isEnabled(), isAdmin, pm);
1037
1038 setTileEnabled(new ComponentName(packageName,
1039 Settings.PrintSettingsActivity.class.getName()),
1040 pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin, pm);
1041
1042 final boolean showDev = mDevelopmentPreferences.getBoolean(
1043 DevelopmentSettings.PREF_SHOW,
1044 android.os.Build.TYPE.equals("eng"));
1045 setTileEnabled(new ComponentName(packageName,
1046 Settings.DevelopmentSettingsActivity.class.getName()),
1047 showDev && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES),
1048 isAdmin, pm);
1049
1050 if (UserHandle.MU_ENABLED && !isAdmin) {
1051 // When on restricted users, disable all extra categories (but only the settings ones).
Jason Monkfd2c7222015-12-02 15:38:38 -05001052 List<DashboardCategory> categories = getDashboardCategories();
Jason Monk4da79e02015-09-10 10:54:36 -04001053 for (DashboardCategory category : categories) {
Jason Monkd4f03ec2016-01-07 16:25:34 -05001054 for (Tile tile : category.tiles) {
Jason Monk4da79e02015-09-10 10:54:36 -04001055 ComponentName component = tile.intent.getComponent();
1056 if (packageName.equals(component)&& !ArrayUtils.contains(
1057 SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1058 setTileEnabled(component, false, isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001059 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001060 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001061 }
1062 }
Jason Monk2ebc8a02015-02-13 15:23:19 -05001063 }
1064
Jason Monk4da79e02015-09-10 10:54:36 -04001065 private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin,
1066 PackageManager pm) {
1067 if (UserHandle.MU_ENABLED && !isAdmin
1068 && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1069 enabled = false;
1070 }
1071 int state = pm.getComponentEnabledSetting(component);
1072 boolean isEnabled = state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
1073 || state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
1074 if (isEnabled != enabled) {
1075 pm.setComponentEnabledSetting(component, enabled
1076 ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
1077 : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
1078 PackageManager.DONT_KILL_APP);
Jason Monk2ebc8a02015-02-13 15:23:19 -05001079 }
1080 }
1081
Jason Monk4da79e02015-09-10 10:54:36 -04001082 private boolean updateHomeSettingTiles() {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001083 // Once we decide to show Home settings, keep showing it forever
1084 SharedPreferences sp = getSharedPreferences(HomeSettings.HOME_PREFS, Context.MODE_PRIVATE);
1085 if (sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false)) {
1086 return true;
1087 }
1088
1089 try {
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -07001090 mHomeActivitiesCount = getHomeActivitiesCount();
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -07001091 if (mHomeActivitiesCount < 2) {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001092 return false;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001093 }
1094 } catch (Exception e) {
1095 // Can't look up the home activity; bail on configuring the icon
1096 Log.w(LOG_TAG, "Problem looking up home activity!", e);
1097 }
1098
1099 sp.edit().putBoolean(HomeSettings.HOME_PREFS_DO_SHOW, true).apply();
1100 return true;
1101 }
1102
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001103 private void getMetaData() {
1104 try {
1105 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1106 PackageManager.GET_META_DATA);
1107 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001108 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1109 } catch (NameNotFoundException nnfe) {
1110 // No recovery
1111 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1112 }
1113 }
1114
1115 // give subclasses access to the Next button
1116 public boolean hasNextButton() {
1117 return mNextButton != null;
1118 }
1119
1120 public Button getNextButton() {
1121 return mNextButton;
1122 }
1123
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001124 @Override
1125 public boolean shouldUpRecreateTask(Intent targetIntent) {
1126 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1127 }
1128
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001129 @Override
1130 public boolean onQueryTextSubmit(String query) {
1131 switchToSearchResultsFragmentIfNeeded();
1132 mSearchQuery = query;
1133 return mSearchResultsFragment.onQueryTextSubmit(query);
1134 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001135
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001136 @Override
1137 public boolean onQueryTextChange(String newText) {
1138 mSearchQuery = newText;
Fabrice Di Meglio7e4855e2014-05-23 16:03:43 -07001139 if (mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001140 return false;
1141 }
1142 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001143 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001144
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001145 @Override
1146 public boolean onClose() {
1147 return false;
1148 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001149
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001150 @Override
1151 public boolean onMenuItemActionExpand(MenuItem item) {
1152 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001153 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001154 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001155 return true;
1156 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001157
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001158 @Override
1159 public boolean onMenuItemActionCollapse(MenuItem item) {
1160 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001161 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001162 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001163 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001164 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001165 return true;
1166 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001167
Jason Monk4da79e02015-09-10 10:54:36 -04001168 @Override
Jason Monkd4f03ec2016-01-07 16:25:34 -05001169 protected void onTileClicked(Tile tile) {
Jason Monk4da79e02015-09-10 10:54:36 -04001170 if (mIsShowingDashboard) {
1171 // If on dashboard, don't finish so the back comes back to here.
1172 openTile(tile);
1173 } else {
1174 super.onTileClicked(tile);
1175 }
1176 }
1177
Jason Monkaf001092015-11-04 13:16:18 -05001178 @Override
1179 public void onProfileTileOpen() {
1180 if (!mIsShowingDashboard) {
1181 finish();
1182 }
1183 }
1184
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001185 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001186 if (mSearchResultsFragment != null) {
1187 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001188 }
Fabrice Di Megliod40dd452014-07-18 15:20:34 -07001189 Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001190 if (current != null && current instanceof SearchResultsSummary) {
1191 mSearchResultsFragment = (SearchResultsSummary) current;
1192 } else {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001193 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001194 SearchResultsSummary.class.getName(), null, false, true,
1195 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001196 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001197 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001198 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001199 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001200
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001201 public void needToRevertToInitialFragment() {
1202 mNeedToRevertToInitialFragment = true;
1203 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001204
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001205 private void revertToInitialFragment() {
1206 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001207 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001208 mSearchMenuItemExpanded = false;
1209 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1210 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001211 if (mSearchMenuItem != null) {
1212 mSearchMenuItem.collapseActionView();
1213 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001214 }
Jim Miller0698a212014-10-16 19:49:07 -07001215
1216 public Intent getResultIntentData() {
1217 return mResultIntentData;
1218 }
1219
1220 public void setResultIntentData(Intent resultIntentData) {
1221 mResultIntentData = resultIntentData;
1222 }
Jason Monkd4f03ec2016-01-07 16:25:34 -05001223
1224 public void startSuggestion(Intent intent) {
1225 mCurrentSuggestion = intent.getComponent();
1226 startActivityForResult(intent, REQUEST_SUGGESTION);
1227 }
1228
1229 @Override
1230 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
1231 if (requestCode == REQUEST_SUGGESTION && mCurrentSuggestion != null
1232 && resultCode != RESULT_CANCELED) {
1233 getPackageManager().setComponentEnabledSetting(mCurrentSuggestion,
1234 PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
1235 }
1236 super.onActivityResult(requestCode, resultCode, data);
1237 }
1238
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001239}