blob: bad8af892a0fee50eab4b15b3020787cdc889f8c [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;
84import com.android.settings.location.LocationSettings;
85import com.android.settings.nfc.AndroidBeam;
86import com.android.settings.nfc.PaymentSettings;
John Spurlock802ddf92014-07-18 11:51:13 -040087import com.android.settings.notification.AppNotificationSettings;
Julia Reynolds8c0a4232015-11-24 10:08:14 -050088import com.android.settings.notification.ConfigureNotificationSettings;
John Spurlock4a350512014-04-08 14:08:21 -040089import com.android.settings.notification.NotificationAccessSettings;
John Spurlock4a350512014-04-08 14:08:21 -040090import com.android.settings.notification.NotificationStation;
Jason Monk2ebc8a02015-02-13 15:23:19 -050091import com.android.settings.notification.OtherSoundSettings;
Jason Monkb37e2882016-01-11 14:27:20 -050092import com.android.settings.notification.SoundSettings;
John Spurlock08531a82015-05-07 17:45:43 -040093import com.android.settings.notification.ZenAccessSettings;
John Spurlock533a5662015-06-19 10:47:36 -040094import com.android.settings.notification.ZenModeAutomationSettings;
John Spurlockf57bad72015-04-30 09:26:15 -040095import com.android.settings.notification.ZenModeEventRuleSettings;
John Spurlockc1df2aa2015-04-13 20:57:06 -040096import com.android.settings.notification.ZenModePrioritySettings;
John Spurlock45fa1402015-04-09 12:50:04 -040097import com.android.settings.notification.ZenModeScheduleRuleSettings;
Jason Monk39b46742015-09-10 15:52:51 -040098import com.android.settings.notification.ZenModeSettings;
Julia Reynolds5555d262015-11-09 10:52:17 -050099import com.android.settings.notification.ZenModeVisualInterruptionSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800100import com.android.settings.print.PrintJobSettingsFragment;
101import com.android.settings.print.PrintSettingsFragment;
Jason Monk2ebc8a02015-02-13 15:23:19 -0500102import com.android.settings.search.DynamicIndexableContentMonitor;
103import com.android.settings.search.Index;
PauloftheWest38155612014-06-30 10:02:36 -0700104import com.android.settings.sim.SimSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800105import com.android.settings.tts.TextToSpeechSettings;
106import com.android.settings.users.UserSettings;
107import com.android.settings.vpn2.VpnSettings;
108import com.android.settings.wfd.WifiDisplaySettings;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700109import com.android.settings.widget.SwitchBar;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800110import com.android.settings.wifi.AdvancedWifiSettings;
PauloftheWest7837b992014-06-24 07:42:27 -0700111import com.android.settings.wifi.SavedAccessPointsWifiSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800112import com.android.settings.wifi.WifiSettings;
113import com.android.settings.wifi.p2p.WifiP2pSettings;
Jason Monk4da79e02015-09-10 10:54:36 -0400114import com.android.settingslib.drawer.DashboardCategory;
Jason Monkd4f03ec2016-01-07 16:25:34 -0500115import com.android.settingslib.drawer.Tile;
Jason Monk4da79e02015-09-10 10:54:36 -0400116import com.android.settingslib.drawer.SettingsDrawerActivity;
Jason Monk2ebc8a02015-02-13 15:23:19 -0500117
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800118import java.util.ArrayList;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800119import java.util.List;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700120import java.util.Set;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800121
Jason Monk4da79e02015-09-10 10:54:36 -0400122public class SettingsActivity extends SettingsDrawerActivity
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800123 implements PreferenceManager.OnPreferenceTreeClickListener,
124 PreferenceFragment.OnPreferenceStartFragmentCallback,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100125 ButtonBarHandler, FragmentManager.OnBackStackChangedListener,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700126 SearchView.OnQueryTextListener, SearchView.OnCloseListener,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100127 MenuItem.OnActionExpandListener {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800128
129 private static final String LOG_TAG = "Settings";
130
131 // Constants for state save/restore
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700132 private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700133 private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
134 private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700135 private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700136 private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700137 private static final String SAVE_KEY_HOME_ACTIVITIES_COUNT = ":settings:home_activities_count";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800138
139 /**
140 * When starting this activity, the invoking Intent can contain this extra
141 * string to specify which fragment should be initially displayed.
142 * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
143 * will call isValidFragment() to confirm that the fragment class name is valid for this
144 * activity.
145 */
146 public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
147
148 /**
149 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
150 * this extra can also be specified to supply a Bundle of arguments to pass
151 * to that fragment when it is instantiated during the initial creation
152 * of the activity.
153 */
154 public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
155
156 /**
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700157 * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
158 */
159 public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
160
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800161 public static final String BACK_STACK_PREFS = ":settings:prefs";
162
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800163 // extras that allow any preference activity to be launched as part of a wizard
164
165 // show Back and Next buttons? takes boolean parameter
166 // Back will then return RESULT_CANCELED and Next RESULT_OK
167 protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
168
169 // add a Skip button?
170 private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
171
172 // specify custom text for the Back or Next buttons, or cause a button to not appear
173 // at all by setting it to null
174 protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
175 protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
176
177 /**
178 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700179 * those extra can also be specify to supply the title or title res id to be shown for
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800180 * that fragment.
181 */
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700182 public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100183 /**
184 * The package name used to resolve the title resource id.
185 */
186 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
187 ":settings:show_fragment_title_res_package_name";
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700188 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
189 ":settings:show_fragment_title_resid";
190 public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
191 ":settings:show_fragment_as_shortcut";
192
193 public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
194 ":settings:show_fragment_as_subsetting";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800195
Jason Monk30695812015-11-17 09:01:08 -0500196 public static final String META_DATA_KEY_FRAGMENT_CLASS =
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800197 "com.android.settings.FRAGMENT_CLASS";
198
199 private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
200
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700201 private static final String EMPTY_QUERY = "";
202
Jason Monkd4f03ec2016-01-07 16:25:34 -0500203 private static final int REQUEST_SUGGESTION = 42;
204
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800205 private String mFragmentClass;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800206
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800207 private CharSequence mInitialTitle;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700208 private int mInitialTitleResId;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800209
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800210 // Show only these settings for restricted users
Jason Monk4da79e02015-09-10 10:54:36 -0400211 private String[] SETTINGS_FOR_RESTRICTED = {
212 //wireless_section
213 WifiSettingsActivity.class.getName(),
214 Settings.BluetoothSettingsActivity.class.getName(),
215 Settings.DataUsageSummaryActivity.class.getName(),
216 Settings.SimSettingsActivity.class.getName(),
217 Settings.WirelessSettingsActivity.class.getName(),
218 //device_section
219 Settings.HomeSettingsActivity.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500220 Settings.SoundSettingsActivity.class.getName(),
Jason Monk4da79e02015-09-10 10:54:36 -0400221 Settings.DisplaySettingsActivity.class.getName(),
222 Settings.StorageSettingsActivity.class.getName(),
223 Settings.ManageApplicationsActivity.class.getName(),
224 Settings.PowerUsageSummaryActivity.class.getName(),
225 //personal_section
226 Settings.LocationSettingsActivity.class.getName(),
227 Settings.SecuritySettingsActivity.class.getName(),
228 Settings.InputMethodAndLanguageSettingsActivity.class.getName(),
229 Settings.UserSettingsActivity.class.getName(),
230 Settings.AccountSettingsActivity.class.getName(),
231 //system_section
232 Settings.DateTimeSettingsActivity.class.getName(),
233 Settings.DeviceInfoSettingsActivity.class.getName(),
234 Settings.AccessibilitySettingsActivity.class.getName(),
235 Settings.PrintSettingsActivity.class.getName(),
236 Settings.PaymentSettingsActivity.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800237 };
238
239 private static final String[] ENTRY_FRAGMENTS = {
240 WirelessSettings.class.getName(),
241 WifiSettings.class.getName(),
242 AdvancedWifiSettings.class.getName(),
PauloftheWest7837b992014-06-24 07:42:27 -0700243 SavedAccessPointsWifiSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800244 BluetoothSettings.class.getName(),
PauloftheWest38155612014-06-30 10:02:36 -0700245 SimSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800246 TetherSettings.class.getName(),
247 WifiP2pSettings.class.getName(),
248 VpnSettings.class.getName(),
249 DateTimeSettings.class.getName(),
250 LocalePicker.class.getName(),
251 InputMethodAndLanguageSettings.class.getName(),
252 SpellCheckersSettings.class.getName(),
253 UserDictionaryList.class.getName(),
254 UserDictionarySettings.class.getName(),
Amith Yamasani3033ce02014-07-14 18:03:15 -0700255 HomeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800256 DisplaySettings.class.getName(),
257 DeviceInfoSettings.class.getName(),
258 ManageApplications.class.getName(),
Xiyuan Xia86a55402015-06-02 14:55:32 -0700259 ManageAssist.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800260 ProcessStatsUi.class.getName(),
261 NotificationStation.class.getName(),
262 LocationSettings.class.getName(),
263 SecuritySettings.class.getName(),
Jason Monkd8da51c2015-04-17 14:34:12 -0400264 UsageAccessDetails.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800265 PrivacySettings.class.getName(),
266 DeviceAdminSettings.class.getName(),
267 AccessibilitySettings.class.getName(),
Anna Galuszab1795f52016-01-08 14:37:16 -0800268 AccessibilitySettingsForSetupWizard.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800269 CaptionPropertiesFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800270 com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(),
271 TextToSpeechSettings.class.getName(),
Jeff Sharkey42833b22015-04-11 21:27:33 -0700272 StorageSettings.class.getName(),
Jeff Sharkeya16257d2015-04-28 13:41:01 -0700273 PrivateVolumeForget.class.getName(),
Jeff Sharkeye77f0682015-04-29 11:24:57 -0700274 PrivateVolumeSettings.class.getName(),
275 PublicVolumeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800276 DevelopmentSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800277 AndroidBeam.class.getName(),
278 WifiDisplaySettings.class.getName(),
279 PowerUsageSummary.class.getName(),
280 AccountSyncSettings.class.getName(),
Alexandra Gherghina6d839872014-07-22 12:04:58 +0000281 AccountSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800282 CryptKeeperSettings.class.getName(),
283 DataUsageSummary.class.getName(),
284 DreamSettings.class.getName(),
285 UserSettings.class.getName(),
286 NotificationAccessSettings.class.getName(),
John Spurlock08531a82015-05-07 17:45:43 -0400287 ZenAccessSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800288 PrintSettingsFragment.class.getName(),
289 PrintJobSettingsFragment.class.getName(),
290 TrustedCredentialsSettings.class.getName(),
291 PaymentSettings.class.getName(),
292 KeyboardLayoutPickerFragment.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700293 ZenModeSettings.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500294 SoundSettings.class.getName(),
295 ConfigureNotificationSettings.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700296 ChooseLockPassword.ChooseLockPasswordFragment.class.getName(),
297 ChooseLockPattern.ChooseLockPatternFragment.class.getName(),
John Spurlockc7f8e8c2014-06-04 19:11:22 -0400298 InstalledAppDetails.class.getName(),
299 BatterySaverSettings.class.getName(),
Fabrice Di Megliodcf59dd2014-07-21 11:22:20 -0700300 AppNotificationSettings.class.getName(),
Fabrice Di Meglioe3ff4d82014-07-23 20:03:20 -0700301 OtherSoundSettings.class.getName(),
Narayan Kamath33acb152015-03-16 12:48:05 +0000302 ApnSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400303 WifiCallingSettings.class.getName(),
John Spurlockc1df2aa2015-04-13 20:57:06 -0400304 ZenModePrioritySettings.class.getName(),
John Spurlock533a5662015-06-19 10:47:36 -0400305 ZenModeAutomationSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400306 ZenModeScheduleRuleSettings.class.getName(),
John Spurlockf57bad72015-04-30 09:26:15 -0400307 ZenModeEventRuleSettings.class.getName(),
Julia Reynolds5555d262015-11-09 10:52:17 -0500308 ZenModeVisualInterruptionSettings.class.getName(),
Jason Monk2583fc12015-03-25 09:46:30 -0400309 ProcessStatsUi.class.getName(),
Jason Monk1eb54eb2015-04-29 12:46:42 -0400310 PowerUsageDetail.class.getName(),
Jason Monk2cdafc62015-06-12 12:32:50 -0400311 ProcessStatsSummary.class.getName(),
Billy Laufee78562015-07-27 12:57:07 +0100312 DrawOverlayDetails.class.getName(),
313 WriteSettingsDetails.class.getName(),
Julia Reynolds2e1e0b72015-12-14 08:32:46 -0500314 ManageDefaultApps.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800315 };
316
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700317
318 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
319 "android.settings.APPLICATION_DETAILS_SETTINGS"
320 };
321
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800322 private SharedPreferences mDevelopmentPreferences;
323 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
324
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800325 private boolean mBatteryPresent = true;
326 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800327 @Override
328 public void onReceive(Context context, Intent intent) {
329 String action = intent.getAction();
330 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
331 boolean batteryPresent = Utils.isBatteryPresent(intent);
332
333 if (mBatteryPresent != batteryPresent) {
334 mBatteryPresent = batteryPresent;
Jason Monk4da79e02015-09-10 10:54:36 -0400335 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800336 }
337 }
338 }
339 };
340
Clara Bayarri6934a042015-10-14 11:07:35 +0100341 private final BroadcastReceiver mUserAddRemoveReceiver = new BroadcastReceiver() {
342 @Override
343 public void onReceive(Context context, Intent intent) {
344 String action = intent.getAction();
345 if (action.equals(Intent.ACTION_USER_ADDED)
346 || action.equals(Intent.ACTION_USER_REMOVED)) {
347 Index.getInstance(getApplicationContext()).update();
348 }
349 }
350 };
351
Svetoslav990159a2014-04-14 17:14:59 -0700352 private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor =
353 new DynamicIndexableContentMonitor();
Svetoslav853e4712014-04-14 10:10:25 -0700354
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700355 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700356 private SwitchBar mSwitchBar;
357
358 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700359
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700360 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700361 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700362
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700363 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700364 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700365
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700366 private ViewGroup mContent;
367
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700368 private SearchView mSearchView;
369 private MenuItem mSearchMenuItem;
370 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700371 private SearchResultsSummary mSearchResultsFragment;
372 private String mSearchQuery;
373
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700374 // Categories
375 private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800376
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700377 private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800378
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700379 private boolean mNeedToRevertToInitialFragment = false;
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700380 private int mHomeActivitiesCount = 1;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700381
Jim Miller0698a212014-10-16 19:49:07 -0700382 private Intent mResultIntentData;
Jason Monkd4f03ec2016-01-07 16:25:34 -0500383 private ComponentName mCurrentSuggestion;
Jim Miller0698a212014-10-16 19:49:07 -0700384
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700385 public SwitchBar getSwitchBar() {
386 return mSwitchBar;
387 }
388
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800389 @Override
390 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
391 // Override the fragment title for Wallpaper settings
Jason Monk39b46742015-09-10 15:52:51 -0400392 CharSequence title = pref.getTitle();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800393 if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) {
Jason Monk39b46742015-09-10 15:52:51 -0400394 title = getString(R.string.wallpaper_settings_fragment_title);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800395 }
Jason Monkb1dd5c92015-12-16 16:13:54 -0500396 startPreferencePanel(pref.getFragment(), pref.getExtras(), -1, title,
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800397 null, 0);
398 return true;
399 }
400
401 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400402 public boolean onPreferenceTreeClick(Preference preference) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800403 return false;
404 }
405
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800406 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800407 public void onConfigurationChanged(Configuration newConfig) {
408 super.onConfigurationChanged(newConfig);
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800409 Index.getInstance(this).update();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800410 }
411
412 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700413 protected void onStart() {
414 super.onStart();
415
416 if (mNeedToRevertToInitialFragment) {
417 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800418 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800419 }
420
421 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700422 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700423 if (!mDisplaySearch) {
424 return false;
425 }
426
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700427 MenuInflater inflater = getMenuInflater();
428 inflater.inflate(R.menu.options_menu, menu);
429
430 // Cache the search query (can be overriden by the OnQueryTextListener)
431 final String query = mSearchQuery;
432
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700433 mSearchMenuItem = menu.findItem(R.id.search);
434 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700435
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700436 if (mSearchMenuItem == null || mSearchView == null) {
437 return false;
438 }
439
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700440 if (mSearchResultsFragment != null) {
441 mSearchResultsFragment.setSearchView(mSearchView);
442 }
443
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700444 mSearchMenuItem.setOnActionExpandListener(this);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700445 mSearchView.setOnQueryTextListener(this);
446 mSearchView.setOnCloseListener(this);
447
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700448 if (mSearchMenuItemExpanded) {
449 mSearchMenuItem.expandActionView();
450 }
451 mSearchView.setQuery(query, true /* submit */);
452
453 return true;
454 }
455
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700456 private static boolean isShortCutIntent(final Intent intent) {
457 Set<String> categories = intent.getCategories();
458 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
459 }
460
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700461 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700462 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700463 if (action == null) {
464 return false;
465 }
466 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
467 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
468 }
469 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700470 }
471
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700472 @Override
473 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700474 super.onCreate(savedState);
Jason Monkfd2c7222015-12-02 15:38:38 -0500475 long startTime = System.currentTimeMillis();
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700476
477 // Should happen before any call to getIntent()
478 getMetaData();
479
480 final Intent intent = getIntent();
481 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
482 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800483 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800484
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800485 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
486 Context.MODE_PRIVATE);
487
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700488 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700489 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700490
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700491 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700492 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
493
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700494 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700495 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700496
Jason Monk4da79e02015-09-10 10:54:36 -0400497 mIsShowingDashboard = className.equals(Settings.class.getName())
498 || className.equals(Settings.WirelessSettings.class.getName())
499 || className.equals(Settings.DeviceSettings.class.getName())
500 || className.equals(Settings.PersonalSettings.class.getName())
501 || className.equals(Settings.WirelessSettings.class.getName());
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700502
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700503 // This is a "Sub Settings" when:
504 // - this is a real SubSettings
505 // - or :settings:show_fragment_as_subsetting is passed to the Intent
Jorim Jaggi4dfcb822015-04-29 17:21:32 -0700506 final boolean isSubSettings = this instanceof SubSettings ||
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700507 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
508
509 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
510 if (isSubSettings) {
Fabrice Di Meglio712df6c2014-07-18 17:44:37 -0700511 // Check also that we are not a Theme Dialog as we don't want to override them
512 final int themeResId = getThemeResId();
513 if (themeResId != R.style.Theme_DialogWhenLarge &&
514 themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
515 setTheme(R.style.Theme_SubSettings);
516 }
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700517 }
518
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700519 setContentView(mIsShowingDashboard ?
520 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800521
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700522 mContent = (ViewGroup) findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700523
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800524 getFragmentManager().addOnBackStackChangedListener(this);
525
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700526 if (mIsShowingDashboard) {
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800527 // Run the Index update only if we have some space
528 if (!Utils.isLowStorage(this)) {
Jason Monkfd2c7222015-12-02 15:38:38 -0500529 long indexStartTime = System.currentTimeMillis();
530 AsyncTask.execute(new Runnable() {
531 @Override
532 public void run() {
533 Index.getInstance(getApplicationContext()).update();
534 }
535 });
536 if (DEBUG_TIMING) Log.d(LOG_TAG, "Index.update() took "
537 + (System.currentTimeMillis() - indexStartTime) + " ms");
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800538 } else {
539 Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
540 }
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700541 }
542
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700543 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700544 // We are restarting from a previous saved state; used that to initialize, instead
545 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700546 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
547 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800548
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700549 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800550
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700551 ArrayList<DashboardCategory> categories =
552 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
553 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700554 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700555 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700556 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800557 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700558
559 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700560 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700561 mHomeActivitiesCount = savedState.getInt(SAVE_KEY_HOME_ACTIVITIES_COUNT,
562 1 /* one home activity by default */);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800563 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700564 if (!mIsShowingDashboard) {
Jason Monkea8b1a72015-06-02 16:46:34 -0400565 mDisplaySearch = false;
566 // UP will be shown only if it is a sub settings
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700567 if (mIsShortcut) {
568 mDisplayHomeAsUpEnabled = isSubSettings;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700569 } else if (isSubSettings) {
570 mDisplayHomeAsUpEnabled = true;
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700571 } else {
572 mDisplayHomeAsUpEnabled = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700573 }
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700574 setTitleFromIntent(intent);
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700575
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700576 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700577 switchToFragment(initialFragmentName, initialArguments, true, false,
578 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000579 } else {
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700580 // No UP affordance if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700581 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700582 // Show Search affordance
583 mDisplaySearch = true;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700584 mInitialTitleResId = R.string.dashboard_title;
Fabrice Di Meglio42c4b0a2014-05-22 10:30:03 -0700585 switchToFragment(DashboardSummary.class.getName(), null, false, false,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700586 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800587 }
588 }
589
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700590 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700591 if (mActionBar != null) {
592 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
593 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
594 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700595 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
596
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800597 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800598 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
599
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700600 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800601 if (buttonBar != null) {
602 buttonBar.setVisibility(View.VISIBLE);
603
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700604 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800605 backButton.setOnClickListener(new OnClickListener() {
606 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700607 setResult(RESULT_CANCELED, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800608 finish();
609 }
610 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700611 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800612 skipButton.setOnClickListener(new OnClickListener() {
613 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700614 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800615 finish();
616 }
617 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700618 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800619 mNextButton.setOnClickListener(new OnClickListener() {
620 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700621 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800622 finish();
623 }
624 });
625
626 // set our various button parameters
627 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
628 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
629 if (TextUtils.isEmpty(buttonText)) {
630 mNextButton.setVisibility(View.GONE);
631 }
632 else {
633 mNextButton.setText(buttonText);
634 }
635 }
636 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
637 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
638 if (TextUtils.isEmpty(buttonText)) {
639 backButton.setVisibility(View.GONE);
640 }
641 else {
642 backButton.setText(buttonText);
643 }
644 }
645 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
646 skipButton.setVisibility(View.VISIBLE);
647 }
648 }
649 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700650
651 mHomeActivitiesCount = getHomeActivitiesCount();
Jason Monkfd2c7222015-12-02 15:38:38 -0500652 if (DEBUG_TIMING) Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
653 + " ms");
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700654 }
655
656 private int getHomeActivitiesCount() {
657 final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>();
658 getPackageManager().getHomeActivities(homeApps);
659 return homeApps.size();
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800660 }
661
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700662 private void setTitleFromIntent(Intent intent) {
663 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
664 if (initialTitleResId > 0) {
665 mInitialTitle = null;
666 mInitialTitleResId = initialTitleResId;
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100667
668 final String initialTitleResPackageName = intent.getStringExtra(
669 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
670 if (initialTitleResPackageName != null) {
671 try {
672 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
673 0 /* flags */, new UserHandle(UserHandle.myUserId()));
674 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
675 setTitle(mInitialTitle);
676 mInitialTitleResId = -1;
677 return;
678 } catch (NameNotFoundException e) {
679 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
680 }
681 } else {
682 setTitle(mInitialTitleResId);
683 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700684 } else {
685 mInitialTitleResId = -1;
686 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
687 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
688 setTitle(mInitialTitle);
689 }
690 }
691
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800692 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800693 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700694 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800695 }
696
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700697 private int setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800698 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700699
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800700 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700701 if (mInitialTitleResId > 0) {
702 setTitle(mInitialTitleResId);
703 } else {
704 setTitle(mInitialTitle);
705 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700706 return 0;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800707 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700708
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800709 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
710 setTitleFromBackStackEntry(bse);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700711
712 return count;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800713 }
714
715 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
716 final CharSequence title;
717 final int titleRes = bse.getBreadCrumbTitleRes();
718 if (titleRes > 0) {
719 title = getText(titleRes);
720 } else {
721 title = bse.getBreadCrumbTitle();
722 }
723 if (title != null) {
724 setTitle(title);
725 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800726 }
727
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800728 @Override
729 protected void onSaveInstanceState(Bundle outState) {
730 super.onSaveInstanceState(outState);
731
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700732 if (mCategories.size() > 0) {
733 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800734 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700735
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700736 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700737 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700738
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700739 if (mDisplaySearch) {
740 // The option menus are created if the ActionBar is visible and they are also created
741 // asynchronously. If you launch Settings with an Intent action like
742 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
743 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
744 // menu item and search view are null.
745 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
746 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700747
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700748 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
749 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
750 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700751
752 outState.putInt(SAVE_KEY_HOME_ACTIVITIES_COUNT, mHomeActivitiesCount);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800753 }
754
755 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400756 protected void onResume() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800757 super.onResume();
758
759 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
760 @Override
761 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Jason Monk4da79e02015-09-10 10:54:36 -0400762 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800763 }
764 };
765 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
766 mDevelopmentPreferencesListener);
767
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800768 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Clara Bayarri6934a042015-10-14 11:07:35 +0100769 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_ADDED));
770 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_REMOVED));
Svetoslav853e4712014-04-14 10:10:25 -0700771
Svetoslav990159a2014-04-14 17:14:59 -0700772 mDynamicIndexableContentMonitor.register(this);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700773
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700774 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700775 onQueryTextSubmit(mSearchQuery);
776 }
Jason Monk4da79e02015-09-10 10:54:36 -0400777 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800778 }
779
780 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400781 protected void onPause() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800782 super.onPause();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800783 unregisterReceiver(mBatteryInfoReceiver);
Clara Bayarri8c9521f2016-01-12 14:10:45 +0000784 unregisterReceiver(mUserAddRemoveReceiver);
Svetoslav990159a2014-04-14 17:14:59 -0700785 mDynamicIndexableContentMonitor.unregister();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800786 }
787
788 @Override
789 public void onDestroy() {
790 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700791
792 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
793 mDevelopmentPreferencesListener);
794 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800795 }
796
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800797 protected boolean isValidFragment(String fragmentName) {
798 // Almost all fragments are wrapped in this,
799 // except for a few that have their own activities.
800 for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
801 if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
802 }
803 return false;
804 }
805
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800806 @Override
807 public Intent getIntent() {
808 Intent superIntent = super.getIntent();
809 String startingFragment = getStartingFragmentClass(superIntent);
810 // This is called from super.onCreate, isMultiPane() is not yet reliable
811 // Do not use onIsHidingHeaders either, which relies itself on this method
812 if (startingFragment != null) {
813 Intent modIntent = new Intent(superIntent);
814 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
815 Bundle args = superIntent.getExtras();
816 if (args != null) {
817 args = new Bundle(args);
818 } else {
819 args = new Bundle();
820 }
821 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100822 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800823 return modIntent;
824 }
825 return superIntent;
826 }
827
828 /**
829 * Checks if the component name in the intent is different from the Settings class and
830 * returns the class name to load as a fragment.
831 */
832 private String getStartingFragmentClass(Intent intent) {
833 if (mFragmentClass != null) return mFragmentClass;
834
835 String intentClass = intent.getComponent().getClassName();
836 if (intentClass.equals(getClass().getName())) return null;
837
838 if ("com.android.settings.ManageApplications".equals(intentClass)
839 || "com.android.settings.RunningServices".equals(intentClass)
840 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
841 // Old names of manage apps.
842 intentClass = com.android.settings.applications.ManageApplications.class.getName();
843 }
844
845 return intentClass;
846 }
847
848 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000849 * Start a new fragment containing a preference panel. If the preferences
850 * are being displayed in multi-pane mode, the given fragment class will
851 * be instantiated and placed in the appropriate pane. If running in
852 * single-pane mode, a new activity will be launched in which to show the
853 * fragment.
854 *
855 * @param fragmentClass Full name of the class implementing the fragment.
856 * @param args Any desired arguments to supply to the fragment.
857 * @param titleRes Optional resource identifier of the title of this
858 * fragment.
859 * @param titleText Optional text of the title of this fragment.
860 * @param resultTo Optional fragment that result data should be sent to.
861 * If non-null, resultTo.onActivityResult() will be called when this
862 * preference panel is done. The launched panel must use
863 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
864 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700865 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000866 */
867 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700868 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700869 String title = null;
870 if (titleRes < 0) {
871 if (titleText != null) {
872 title = titleText.toString();
873 } else {
874 // There not much we can do in that case
875 title = "";
876 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700877 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700878 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700879 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000880 }
881
882 /**
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100883 * Start a new fragment in a new activity containing a preference panel for a given user. If the
884 * preferences are being displayed in multi-pane mode, the given fragment class will be
885 * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
886 * activity will be launched in which to show the fragment.
887 *
888 * @param fragmentClass Full name of the class implementing the fragment.
889 * @param args Any desired arguments to supply to the fragment.
890 * @param titleRes Optional resource identifier of the title of this fragment.
891 * @param titleText Optional text of the title of this fragment.
892 * @param userHandle The user for which the panel has to be started.
893 */
894 public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
895 CharSequence titleText, UserHandle userHandle) {
Lifu Tangd0332852015-04-02 12:05:46 -0700896 // This is a workaround.
897 //
898 // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
899 // starting the fragment could cause a native stack corruption. See b/17523189. However,
900 // adding that flag and start the preference panel with the same UserHandler will make it
901 // impossible to use back button to return to the previous screen. See b/20042570.
902 //
903 // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
904 // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
905 // when we're calling it as the same user.
906 if (userHandle.getIdentifier() == UserHandle.myUserId()) {
907 startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0);
908 } else {
909 String title = null;
910 if (titleRes < 0) {
911 if (titleText != null) {
912 title = titleText.toString();
913 } else {
914 // There not much we can do in that case
915 title = "";
916 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100917 }
Lifu Tangd0332852015-04-02 12:05:46 -0700918 Utils.startWithFragmentAsUser(this, fragmentClass, args,
919 titleRes, title, mIsShortcut, userHandle);
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100920 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100921 }
922
923 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800924 * Called by a preference panel fragment to finish itself.
925 *
926 * @param caller The fragment that is asking to be finished.
927 * @param resultCode Optional result code to send back to the original
928 * launching fragment.
929 * @param resultData Optional result data to send back to the original
930 * launching fragment.
931 */
932 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
933 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700934 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800935 }
936
937 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000938 * Start a new fragment.
939 *
940 * @param fragment The fragment to start
941 * @param push If true, the current fragment will be pushed onto the back stack. If false,
942 * the current fragment will be replaced.
943 */
944 public void startPreferenceFragment(Fragment fragment, boolean push) {
945 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700946 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000947 if (push) {
948 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
949 transaction.addToBackStack(BACK_STACK_PREFS);
950 } else {
951 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
952 }
953 transaction.commitAllowingStateLoss();
954 }
955
956 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700957 * Switch to a specific Fragment with taking care of validation, Title and BackStack
958 */
959 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700960 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700961 if (validate && !isValidFragment(fragmentName)) {
962 throw new IllegalArgumentException("Invalid fragment for this activity: "
963 + fragmentName);
964 }
965 Fragment f = Fragment.instantiate(this, fragmentName, args);
966 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700967 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700968 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700969 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700970 }
971 if (addToBackStack) {
972 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
973 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700974 if (titleResId > 0) {
975 transaction.setBreadCrumbTitle(titleResId);
976 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700977 transaction.setBreadCrumbTitle(title);
978 }
979 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700980 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700981 return f;
982 }
983
Jason Monk4da79e02015-09-10 10:54:36 -0400984 private void updateTilesList() {
Jason Monkfd2c7222015-12-02 15:38:38 -0500985 // Generally the items that are will be changing from these updates will
986 // not be in the top list of tiles, so run it in the background and the
987 // SettingsDrawerActivity will pick up on the updates automatically.
988 AsyncTask.execute(new Runnable() {
989 @Override
990 public void run() {
991 doUpdateTilesList();
992 }
993 });
994 }
995
996 private void doUpdateTilesList() {
Jason Monk4da79e02015-09-10 10:54:36 -0400997 PackageManager pm = getPackageManager();
Xiaohui Chen44879a32015-07-22 13:53:22 -0700998 final UserManager um = UserManager.get(this);
999 final boolean isAdmin = um.isAdminUser();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001000
Jason Monk4da79e02015-09-10 10:54:36 -04001001 String packageName = getPackageName();
1002 setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()),
1003 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001004
Jason Monk4da79e02015-09-10 10:54:36 -04001005 setTileEnabled(new ComponentName(packageName,
1006 Settings.BluetoothSettingsActivity.class.getName()),
1007 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001008
Jason Monk4da79e02015-09-10 10:54:36 -04001009 setTileEnabled(new ComponentName(packageName,
1010 Settings.DataUsageSummaryActivity.class.getName()),
1011 Utils.isBandwidthControlEnabled(), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001012
Jason Monk4da79e02015-09-10 10:54:36 -04001013 setTileEnabled(new ComponentName(packageName,
1014 Settings.SimSettingsActivity.class.getName()),
1015 Utils.showSimCardTile(this), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001016
Jason Monk4da79e02015-09-10 10:54:36 -04001017 setTileEnabled(new ComponentName(packageName,
1018 Settings.PowerUsageSummaryActivity.class.getName()),
1019 mBatteryPresent, isAdmin, pm);
1020
1021 setTileEnabled(new ComponentName(packageName,
1022 Settings.HomeSettingsActivity.class.getName()),
1023 updateHomeSettingTiles(), isAdmin, pm);
1024
1025 setTileEnabled(new ComponentName(packageName,
1026 Settings.UserSettingsActivity.class.getName()),
1027 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
1028 && !Utils.isMonkeyRunning(), isAdmin, pm);
1029
1030 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
1031 setTileEnabled(new ComponentName(packageName,
1032 Settings.PaymentSettingsActivity.class.getName()),
1033 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
1034 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
1035 && adapter != null && adapter.isEnabled(), isAdmin, pm);
1036
1037 setTileEnabled(new ComponentName(packageName,
1038 Settings.PrintSettingsActivity.class.getName()),
1039 pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin, pm);
1040
1041 final boolean showDev = mDevelopmentPreferences.getBoolean(
1042 DevelopmentSettings.PREF_SHOW,
1043 android.os.Build.TYPE.equals("eng"));
1044 setTileEnabled(new ComponentName(packageName,
1045 Settings.DevelopmentSettingsActivity.class.getName()),
1046 showDev && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES),
1047 isAdmin, pm);
1048
1049 if (UserHandle.MU_ENABLED && !isAdmin) {
1050 // When on restricted users, disable all extra categories (but only the settings ones).
Jason Monkfd2c7222015-12-02 15:38:38 -05001051 List<DashboardCategory> categories = getDashboardCategories();
Jason Monk4da79e02015-09-10 10:54:36 -04001052 for (DashboardCategory category : categories) {
Jason Monkd4f03ec2016-01-07 16:25:34 -05001053 for (Tile tile : category.tiles) {
Jason Monk4da79e02015-09-10 10:54:36 -04001054 ComponentName component = tile.intent.getComponent();
1055 if (packageName.equals(component)&& !ArrayUtils.contains(
1056 SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1057 setTileEnabled(component, false, isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001058 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001059 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001060 }
1061 }
Jason Monk2ebc8a02015-02-13 15:23:19 -05001062 }
1063
Jason Monk4da79e02015-09-10 10:54:36 -04001064 private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin,
1065 PackageManager pm) {
1066 if (UserHandle.MU_ENABLED && !isAdmin
1067 && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1068 enabled = false;
1069 }
1070 int state = pm.getComponentEnabledSetting(component);
1071 boolean isEnabled = state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
1072 || state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
1073 if (isEnabled != enabled) {
1074 pm.setComponentEnabledSetting(component, enabled
1075 ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
1076 : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
1077 PackageManager.DONT_KILL_APP);
Jason Monk2ebc8a02015-02-13 15:23:19 -05001078 }
1079 }
1080
Jason Monk4da79e02015-09-10 10:54:36 -04001081 private boolean updateHomeSettingTiles() {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001082 // Once we decide to show Home settings, keep showing it forever
1083 SharedPreferences sp = getSharedPreferences(HomeSettings.HOME_PREFS, Context.MODE_PRIVATE);
1084 if (sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false)) {
1085 return true;
1086 }
1087
1088 try {
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -07001089 mHomeActivitiesCount = getHomeActivitiesCount();
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -07001090 if (mHomeActivitiesCount < 2) {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001091 return false;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001092 }
1093 } catch (Exception e) {
1094 // Can't look up the home activity; bail on configuring the icon
1095 Log.w(LOG_TAG, "Problem looking up home activity!", e);
1096 }
1097
1098 sp.edit().putBoolean(HomeSettings.HOME_PREFS_DO_SHOW, true).apply();
1099 return true;
1100 }
1101
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001102 private void getMetaData() {
1103 try {
1104 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1105 PackageManager.GET_META_DATA);
1106 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001107 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1108 } catch (NameNotFoundException nnfe) {
1109 // No recovery
1110 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1111 }
1112 }
1113
1114 // give subclasses access to the Next button
1115 public boolean hasNextButton() {
1116 return mNextButton != null;
1117 }
1118
1119 public Button getNextButton() {
1120 return mNextButton;
1121 }
1122
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001123 @Override
1124 public boolean shouldUpRecreateTask(Intent targetIntent) {
1125 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1126 }
1127
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001128 @Override
1129 public boolean onQueryTextSubmit(String query) {
1130 switchToSearchResultsFragmentIfNeeded();
1131 mSearchQuery = query;
1132 return mSearchResultsFragment.onQueryTextSubmit(query);
1133 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001134
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001135 @Override
1136 public boolean onQueryTextChange(String newText) {
1137 mSearchQuery = newText;
Fabrice Di Meglio7e4855e2014-05-23 16:03:43 -07001138 if (mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001139 return false;
1140 }
1141 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001142 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001143
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001144 @Override
1145 public boolean onClose() {
1146 return false;
1147 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001148
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001149 @Override
1150 public boolean onMenuItemActionExpand(MenuItem item) {
1151 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001152 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001153 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001154 return true;
1155 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001156
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001157 @Override
1158 public boolean onMenuItemActionCollapse(MenuItem item) {
1159 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001160 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001161 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001162 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001163 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001164 return true;
1165 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001166
Jason Monk4da79e02015-09-10 10:54:36 -04001167 @Override
Jason Monkd4f03ec2016-01-07 16:25:34 -05001168 protected void onTileClicked(Tile tile) {
Jason Monk4da79e02015-09-10 10:54:36 -04001169 if (mIsShowingDashboard) {
1170 // If on dashboard, don't finish so the back comes back to here.
1171 openTile(tile);
1172 } else {
1173 super.onTileClicked(tile);
1174 }
1175 }
1176
Jason Monkaf001092015-11-04 13:16:18 -05001177 @Override
1178 public void onProfileTileOpen() {
1179 if (!mIsShowingDashboard) {
1180 finish();
1181 }
1182 }
1183
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001184 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001185 if (mSearchResultsFragment != null) {
1186 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001187 }
Fabrice Di Megliod40dd452014-07-18 15:20:34 -07001188 Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001189 if (current != null && current instanceof SearchResultsSummary) {
1190 mSearchResultsFragment = (SearchResultsSummary) current;
1191 } else {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001192 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001193 SearchResultsSummary.class.getName(), null, false, true,
1194 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001195 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001196 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001197 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001198 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001199
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001200 public void needToRevertToInitialFragment() {
1201 mNeedToRevertToInitialFragment = true;
1202 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001203
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001204 private void revertToInitialFragment() {
1205 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001206 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001207 mSearchMenuItemExpanded = false;
1208 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1209 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001210 if (mSearchMenuItem != null) {
1211 mSearchMenuItem.collapseActionView();
1212 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001213 }
Jim Miller0698a212014-10-16 19:49:07 -07001214
1215 public Intent getResultIntentData() {
1216 return mResultIntentData;
1217 }
1218
1219 public void setResultIntentData(Intent resultIntentData) {
1220 mResultIntentData = resultIntentData;
1221 }
Jason Monkd4f03ec2016-01-07 16:25:34 -05001222
1223 public void startSuggestion(Intent intent) {
1224 mCurrentSuggestion = intent.getComponent();
1225 startActivityForResult(intent, REQUEST_SUGGESTION);
1226 }
1227
1228 @Override
1229 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
1230 if (requestCode == REQUEST_SUGGESTION && mCurrentSuggestion != null
1231 && resultCode != RESULT_CANCELED) {
1232 getPackageManager().setComponentEnabledSetting(mCurrentSuggestion,
1233 PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
1234 }
1235 super.onActivityResult(requestCode, resultCode, data);
1236 }
1237
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001238}