blob: 8dafd7472de42dedc8ba4a91075c444ebe984fb3 [file] [log] [blame]
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.settings;
18
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080019import android.app.ActionBar;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080020import android.app.Fragment;
21import android.app.FragmentManager;
22import android.app.FragmentTransaction;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080023import android.content.BroadcastReceiver;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070024import android.content.ComponentName;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080025import android.content.Context;
26import android.content.Intent;
27import android.content.IntentFilter;
28import android.content.SharedPreferences;
29import android.content.pm.ActivityInfo;
30import android.content.pm.PackageManager;
31import android.content.pm.PackageManager.NameNotFoundException;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080032import android.content.res.Configuration;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080033import android.nfc.NfcAdapter;
Jason Monkfd2c7222015-12-02 15:38:38 -050034import android.os.AsyncTask;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080035import android.os.Bundle;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080036import android.os.UserHandle;
37import android.os.UserManager;
Jason Monk39b46742015-09-10 15:52:51 -040038import android.support.v14.preference.PreferenceFragment;
39import android.support.v7.preference.Preference;
40import android.support.v7.preference.PreferenceManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080041import android.text.TextUtils;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070042import android.transition.TransitionManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080043import android.util.Log;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070044import android.view.Menu;
45import android.view.MenuInflater;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080046import android.view.MenuItem;
47import android.view.View;
48import android.view.View.OnClickListener;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070049import android.view.ViewGroup;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080050import android.widget.Button;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070051import android.widget.SearchView;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080052import com.android.internal.util.ArrayUtils;
Jason Monk4da79e02015-09-10 10:54:36 -040053import com.android.settings.Settings.WifiSettingsActivity;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080054import com.android.settings.accessibility.AccessibilitySettings;
Anna Galuszab1795f52016-01-08 14:37:16 -080055import com.android.settings.accessibility.AccessibilitySettingsForSetupWizard;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080056import com.android.settings.accessibility.CaptionPropertiesFragment;
Alexandra Gherghina6d839872014-07-22 12:04:58 +000057import com.android.settings.accounts.AccountSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080058import com.android.settings.accounts.AccountSyncSettings;
Jason Monk91e2f892016-02-23 15:31:09 -050059import com.android.settings.applications.AdvancedAppSettings;
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;
Jason Monka2d47fc2016-03-03 10:49:44 -050064import com.android.settings.applications.NotificationApps;
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;
Abodunrinwa Toki976bb3f2016-01-20 18:43:20 +000080import com.android.settings.inputmethod.AvailableVirtualKeyboardFragment;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080081import com.android.settings.inputmethod.InputMethodAndLanguageSettings;
82import com.android.settings.inputmethod.KeyboardLayoutPickerFragment;
Abodunrinwa Toki5f0b59b2016-01-25 23:02:23 +000083import com.android.settings.inputmethod.KeyboardLayoutPickerFragment2;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080084import com.android.settings.inputmethod.SpellCheckersSettings;
85import com.android.settings.inputmethod.UserDictionaryList;
Mihai Nitad7d48fd2016-01-12 08:55:05 -080086import com.android.settings.localepicker.LocaleListEditor;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080087import com.android.settings.location.LocationSettings;
88import com.android.settings.nfc.AndroidBeam;
89import com.android.settings.nfc.PaymentSettings;
John Spurlock802ddf92014-07-18 11:51:13 -040090import com.android.settings.notification.AppNotificationSettings;
Julia Reynolds8c0a4232015-11-24 10:08:14 -050091import com.android.settings.notification.ConfigureNotificationSettings;
John Spurlock4a350512014-04-08 14:08:21 -040092import com.android.settings.notification.NotificationAccessSettings;
John Spurlock4a350512014-04-08 14:08:21 -040093import com.android.settings.notification.NotificationStation;
Jason Monk2ebc8a02015-02-13 15:23:19 -050094import com.android.settings.notification.OtherSoundSettings;
Jason Monkb37e2882016-01-11 14:27:20 -050095import com.android.settings.notification.SoundSettings;
John Spurlock08531a82015-05-07 17:45:43 -040096import com.android.settings.notification.ZenAccessSettings;
John Spurlock533a5662015-06-19 10:47:36 -040097import com.android.settings.notification.ZenModeAutomationSettings;
John Spurlockf57bad72015-04-30 09:26:15 -040098import com.android.settings.notification.ZenModeEventRuleSettings;
John Spurlockc1df2aa2015-04-13 20:57:06 -040099import com.android.settings.notification.ZenModePrioritySettings;
John Spurlock45fa1402015-04-09 12:50:04 -0400100import com.android.settings.notification.ZenModeScheduleRuleSettings;
Jason Monk39b46742015-09-10 15:52:51 -0400101import com.android.settings.notification.ZenModeSettings;
Julia Reynolds5555d262015-11-09 10:52:17 -0500102import com.android.settings.notification.ZenModeVisualInterruptionSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800103import com.android.settings.print.PrintJobSettingsFragment;
104import com.android.settings.print.PrintSettingsFragment;
Jason Monk2ebc8a02015-02-13 15:23:19 -0500105import com.android.settings.search.DynamicIndexableContentMonitor;
106import com.android.settings.search.Index;
PauloftheWest38155612014-06-30 10:02:36 -0700107import com.android.settings.sim.SimSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800108import com.android.settings.tts.TextToSpeechSettings;
109import com.android.settings.users.UserSettings;
110import com.android.settings.vpn2.VpnSettings;
111import com.android.settings.wfd.WifiDisplaySettings;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700112import com.android.settings.widget.SwitchBar;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800113import com.android.settings.wifi.AdvancedWifiSettings;
PauloftheWest7837b992014-06-24 07:42:27 -0700114import com.android.settings.wifi.SavedAccessPointsWifiSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800115import com.android.settings.wifi.WifiSettings;
116import com.android.settings.wifi.p2p.WifiP2pSettings;
Jason Monk4da79e02015-09-10 10:54:36 -0400117import com.android.settingslib.drawer.DashboardCategory;
Jason Monk4da79e02015-09-10 10:54:36 -0400118import com.android.settingslib.drawer.SettingsDrawerActivity;
Jason Monk7ea14c52016-01-22 14:28:02 -0500119import com.android.settingslib.drawer.Tile;
Jason Monk2ebc8a02015-02-13 15:23:19 -0500120
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800121import java.util.ArrayList;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800122import java.util.List;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700123import java.util.Set;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800124
Jason Monk4da79e02015-09-10 10:54:36 -0400125public class SettingsActivity extends SettingsDrawerActivity
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800126 implements PreferenceManager.OnPreferenceTreeClickListener,
127 PreferenceFragment.OnPreferenceStartFragmentCallback,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100128 ButtonBarHandler, FragmentManager.OnBackStackChangedListener,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700129 SearchView.OnQueryTextListener, SearchView.OnCloseListener,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100130 MenuItem.OnActionExpandListener {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800131
132 private static final String LOG_TAG = "Settings";
133
134 // Constants for state save/restore
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700135 private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700136 private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
137 private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700138 private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700139 private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700140 private static final String SAVE_KEY_HOME_ACTIVITIES_COUNT = ":settings:home_activities_count";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800141
142 /**
143 * When starting this activity, the invoking Intent can contain this extra
144 * string to specify which fragment should be initially displayed.
145 * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
146 * will call isValidFragment() to confirm that the fragment class name is valid for this
147 * activity.
148 */
149 public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
150
151 /**
152 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
153 * this extra can also be specified to supply a Bundle of arguments to pass
154 * to that fragment when it is instantiated during the initial creation
155 * of the activity.
156 */
157 public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
158
159 /**
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700160 * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
161 */
162 public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
163
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800164 public static final String BACK_STACK_PREFS = ":settings:prefs";
165
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800166 // extras that allow any preference activity to be launched as part of a wizard
167
168 // show Back and Next buttons? takes boolean parameter
169 // Back will then return RESULT_CANCELED and Next RESULT_OK
170 protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
171
172 // add a Skip button?
173 private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
174
175 // specify custom text for the Back or Next buttons, or cause a button to not appear
176 // at all by setting it to null
177 protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
178 protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
179
180 /**
181 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700182 * 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 -0800183 * that fragment.
184 */
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700185 public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100186 /**
187 * The package name used to resolve the title resource id.
188 */
189 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
190 ":settings:show_fragment_title_res_package_name";
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700191 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
192 ":settings:show_fragment_title_resid";
193 public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
194 ":settings:show_fragment_as_shortcut";
195
196 public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
197 ":settings:show_fragment_as_subsetting";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800198
Jason Monk30695812015-11-17 09:01:08 -0500199 public static final String META_DATA_KEY_FRAGMENT_CLASS =
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800200 "com.android.settings.FRAGMENT_CLASS";
201
202 private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
203
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700204 private static final String EMPTY_QUERY = "";
205
Jason Monkd4f03ec2016-01-07 16:25:34 -0500206 private static final int REQUEST_SUGGESTION = 42;
207
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800208 private String mFragmentClass;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800209
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800210 private CharSequence mInitialTitle;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700211 private int mInitialTitleResId;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800212
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800213 // Show only these settings for restricted users
Jason Monk4da79e02015-09-10 10:54:36 -0400214 private String[] SETTINGS_FOR_RESTRICTED = {
215 //wireless_section
216 WifiSettingsActivity.class.getName(),
217 Settings.BluetoothSettingsActivity.class.getName(),
218 Settings.DataUsageSummaryActivity.class.getName(),
219 Settings.SimSettingsActivity.class.getName(),
220 Settings.WirelessSettingsActivity.class.getName(),
221 //device_section
222 Settings.HomeSettingsActivity.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500223 Settings.SoundSettingsActivity.class.getName(),
Jason Monk4da79e02015-09-10 10:54:36 -0400224 Settings.DisplaySettingsActivity.class.getName(),
225 Settings.StorageSettingsActivity.class.getName(),
226 Settings.ManageApplicationsActivity.class.getName(),
227 Settings.PowerUsageSummaryActivity.class.getName(),
228 //personal_section
229 Settings.LocationSettingsActivity.class.getName(),
230 Settings.SecuritySettingsActivity.class.getName(),
231 Settings.InputMethodAndLanguageSettingsActivity.class.getName(),
232 Settings.UserSettingsActivity.class.getName(),
233 Settings.AccountSettingsActivity.class.getName(),
234 //system_section
235 Settings.DateTimeSettingsActivity.class.getName(),
236 Settings.DeviceInfoSettingsActivity.class.getName(),
237 Settings.AccessibilitySettingsActivity.class.getName(),
238 Settings.PrintSettingsActivity.class.getName(),
239 Settings.PaymentSettingsActivity.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800240 };
241
242 private static final String[] ENTRY_FRAGMENTS = {
243 WirelessSettings.class.getName(),
244 WifiSettings.class.getName(),
245 AdvancedWifiSettings.class.getName(),
PauloftheWest7837b992014-06-24 07:42:27 -0700246 SavedAccessPointsWifiSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800247 BluetoothSettings.class.getName(),
PauloftheWest38155612014-06-30 10:02:36 -0700248 SimSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800249 TetherSettings.class.getName(),
250 WifiP2pSettings.class.getName(),
251 VpnSettings.class.getName(),
252 DateTimeSettings.class.getName(),
Mihai Nitad7d48fd2016-01-12 08:55:05 -0800253 LocaleListEditor.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800254 InputMethodAndLanguageSettings.class.getName(),
Abodunrinwa Toki976bb3f2016-01-20 18:43:20 +0000255 AvailableVirtualKeyboardFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800256 SpellCheckersSettings.class.getName(),
257 UserDictionaryList.class.getName(),
258 UserDictionarySettings.class.getName(),
Amith Yamasani3033ce02014-07-14 18:03:15 -0700259 HomeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800260 DisplaySettings.class.getName(),
261 DeviceInfoSettings.class.getName(),
262 ManageApplications.class.getName(),
Jason Monka2d47fc2016-03-03 10:49:44 -0500263 NotificationApps.class.getName(),
Xiyuan Xia86a55402015-06-02 14:55:32 -0700264 ManageAssist.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800265 ProcessStatsUi.class.getName(),
266 NotificationStation.class.getName(),
267 LocationSettings.class.getName(),
268 SecuritySettings.class.getName(),
Jason Monkd8da51c2015-04-17 14:34:12 -0400269 UsageAccessDetails.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800270 PrivacySettings.class.getName(),
271 DeviceAdminSettings.class.getName(),
272 AccessibilitySettings.class.getName(),
Anna Galuszab1795f52016-01-08 14:37:16 -0800273 AccessibilitySettingsForSetupWizard.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800274 CaptionPropertiesFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800275 com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(),
276 TextToSpeechSettings.class.getName(),
Jeff Sharkey42833b22015-04-11 21:27:33 -0700277 StorageSettings.class.getName(),
Jeff Sharkeya16257d2015-04-28 13:41:01 -0700278 PrivateVolumeForget.class.getName(),
Jeff Sharkeye77f0682015-04-29 11:24:57 -0700279 PrivateVolumeSettings.class.getName(),
280 PublicVolumeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800281 DevelopmentSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800282 AndroidBeam.class.getName(),
283 WifiDisplaySettings.class.getName(),
284 PowerUsageSummary.class.getName(),
285 AccountSyncSettings.class.getName(),
Alexandra Gherghina6d839872014-07-22 12:04:58 +0000286 AccountSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800287 CryptKeeperSettings.class.getName(),
288 DataUsageSummary.class.getName(),
289 DreamSettings.class.getName(),
290 UserSettings.class.getName(),
291 NotificationAccessSettings.class.getName(),
John Spurlock08531a82015-05-07 17:45:43 -0400292 ZenAccessSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800293 PrintSettingsFragment.class.getName(),
294 PrintJobSettingsFragment.class.getName(),
295 TrustedCredentialsSettings.class.getName(),
296 PaymentSettings.class.getName(),
297 KeyboardLayoutPickerFragment.class.getName(),
Abodunrinwa Toki5f0b59b2016-01-25 23:02:23 +0000298 KeyboardLayoutPickerFragment2.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700299 ZenModeSettings.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500300 SoundSettings.class.getName(),
301 ConfigureNotificationSettings.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700302 ChooseLockPassword.ChooseLockPasswordFragment.class.getName(),
303 ChooseLockPattern.ChooseLockPatternFragment.class.getName(),
John Spurlockc7f8e8c2014-06-04 19:11:22 -0400304 InstalledAppDetails.class.getName(),
305 BatterySaverSettings.class.getName(),
Fabrice Di Megliodcf59dd2014-07-21 11:22:20 -0700306 AppNotificationSettings.class.getName(),
Fabrice Di Meglioe3ff4d82014-07-23 20:03:20 -0700307 OtherSoundSettings.class.getName(),
Narayan Kamath33acb152015-03-16 12:48:05 +0000308 ApnSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400309 WifiCallingSettings.class.getName(),
John Spurlockc1df2aa2015-04-13 20:57:06 -0400310 ZenModePrioritySettings.class.getName(),
John Spurlock533a5662015-06-19 10:47:36 -0400311 ZenModeAutomationSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400312 ZenModeScheduleRuleSettings.class.getName(),
John Spurlockf57bad72015-04-30 09:26:15 -0400313 ZenModeEventRuleSettings.class.getName(),
Julia Reynolds5555d262015-11-09 10:52:17 -0500314 ZenModeVisualInterruptionSettings.class.getName(),
Jason Monk2583fc12015-03-25 09:46:30 -0400315 ProcessStatsUi.class.getName(),
Jason Monk1eb54eb2015-04-29 12:46:42 -0400316 PowerUsageDetail.class.getName(),
Jason Monk2cdafc62015-06-12 12:32:50 -0400317 ProcessStatsSummary.class.getName(),
Billy Laufee78562015-07-27 12:57:07 +0100318 DrawOverlayDetails.class.getName(),
319 WriteSettingsDetails.class.getName(),
Jason Monk91e2f892016-02-23 15:31:09 -0500320 AdvancedAppSettings.class.getName(),
Jason Monkb9e5d232016-01-26 17:43:57 -0500321 WallpaperTypeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800322 };
323
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700324
325 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
326 "android.settings.APPLICATION_DETAILS_SETTINGS"
327 };
328
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800329 private SharedPreferences mDevelopmentPreferences;
330 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
331
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800332 private boolean mBatteryPresent = true;
333 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800334 @Override
335 public void onReceive(Context context, Intent intent) {
336 String action = intent.getAction();
337 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
338 boolean batteryPresent = Utils.isBatteryPresent(intent);
339
340 if (mBatteryPresent != batteryPresent) {
341 mBatteryPresent = batteryPresent;
Jason Monk4da79e02015-09-10 10:54:36 -0400342 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800343 }
344 }
345 }
346 };
347
Clara Bayarri6934a042015-10-14 11:07:35 +0100348 private final BroadcastReceiver mUserAddRemoveReceiver = new BroadcastReceiver() {
349 @Override
350 public void onReceive(Context context, Intent intent) {
351 String action = intent.getAction();
352 if (action.equals(Intent.ACTION_USER_ADDED)
353 || action.equals(Intent.ACTION_USER_REMOVED)) {
354 Index.getInstance(getApplicationContext()).update();
355 }
356 }
357 };
358
Svetoslav990159a2014-04-14 17:14:59 -0700359 private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor =
360 new DynamicIndexableContentMonitor();
Svetoslav853e4712014-04-14 10:10:25 -0700361
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700362 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700363 private SwitchBar mSwitchBar;
364
365 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700366
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700367 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700368 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700369
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700370 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700371 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700372
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700373 private ViewGroup mContent;
374
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700375 private SearchView mSearchView;
376 private MenuItem mSearchMenuItem;
377 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700378 private SearchResultsSummary mSearchResultsFragment;
379 private String mSearchQuery;
380
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700381 // Categories
382 private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800383
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700384 private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800385
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700386 private boolean mNeedToRevertToInitialFragment = false;
387
Jim Miller0698a212014-10-16 19:49:07 -0700388 private Intent mResultIntentData;
Jason Monkd4f03ec2016-01-07 16:25:34 -0500389 private ComponentName mCurrentSuggestion;
Jim Miller0698a212014-10-16 19:49:07 -0700390
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700391 public SwitchBar getSwitchBar() {
392 return mSwitchBar;
393 }
394
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800395 @Override
396 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
397 // Override the fragment title for Wallpaper settings
Jason Monk39b46742015-09-10 15:52:51 -0400398 CharSequence title = pref.getTitle();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800399 if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) {
Jason Monk39b46742015-09-10 15:52:51 -0400400 title = getString(R.string.wallpaper_settings_fragment_title);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800401 }
Jason Monkb1dd5c92015-12-16 16:13:54 -0500402 startPreferencePanel(pref.getFragment(), pref.getExtras(), -1, title,
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800403 null, 0);
404 return true;
405 }
406
407 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400408 public boolean onPreferenceTreeClick(Preference preference) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800409 return false;
410 }
411
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800412 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800413 public void onConfigurationChanged(Configuration newConfig) {
414 super.onConfigurationChanged(newConfig);
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800415 Index.getInstance(this).update();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800416 }
417
418 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700419 protected void onStart() {
420 super.onStart();
421
422 if (mNeedToRevertToInitialFragment) {
423 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800424 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800425 }
426
427 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700428 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700429 if (!mDisplaySearch) {
430 return false;
431 }
432
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700433 MenuInflater inflater = getMenuInflater();
434 inflater.inflate(R.menu.options_menu, menu);
435
436 // Cache the search query (can be overriden by the OnQueryTextListener)
437 final String query = mSearchQuery;
438
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700439 mSearchMenuItem = menu.findItem(R.id.search);
440 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700441
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700442 if (mSearchMenuItem == null || mSearchView == null) {
443 return false;
444 }
445
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700446 if (mSearchResultsFragment != null) {
447 mSearchResultsFragment.setSearchView(mSearchView);
448 }
449
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700450 mSearchMenuItem.setOnActionExpandListener(this);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700451 mSearchView.setOnQueryTextListener(this);
452 mSearchView.setOnCloseListener(this);
453
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700454 if (mSearchMenuItemExpanded) {
455 mSearchMenuItem.expandActionView();
456 }
457 mSearchView.setQuery(query, true /* submit */);
458
459 return true;
460 }
461
Jason Monk31c7c322016-01-20 14:41:52 -0500462 @Override
463 public SharedPreferences getSharedPreferences(String name, int mode) {
464 if (name.equals(getPackageName() + "_preferences")) {
Jason Monke4ebcd12016-02-21 09:37:41 -0500465 return new SharedPreferencesLogger(this, getMetricsTag());
Jason Monk31c7c322016-01-20 14:41:52 -0500466 }
467 return super.getSharedPreferences(name, mode);
468 }
469
Jason Monke4ebcd12016-02-21 09:37:41 -0500470 private String getMetricsTag() {
471 String tag = getClass().getName();
472 if (getIntent() != null && getIntent().hasExtra(EXTRA_SHOW_FRAGMENT)) {
473 tag = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
474 }
475 if (tag.startsWith("com.android.settings.")) {
476 tag = tag.replace("com.android.settings.", "");
477 }
478 return tag;
479 }
480
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700481 private static boolean isShortCutIntent(final Intent intent) {
482 Set<String> categories = intent.getCategories();
483 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
484 }
485
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700486 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700487 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700488 if (action == null) {
489 return false;
490 }
491 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
492 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
493 }
494 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700495 }
496
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700497 @Override
498 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700499 super.onCreate(savedState);
Jason Monkfd2c7222015-12-02 15:38:38 -0500500 long startTime = System.currentTimeMillis();
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700501
502 // Should happen before any call to getIntent()
503 getMetaData();
504
505 final Intent intent = getIntent();
506 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
507 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800508 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800509
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800510 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
511 Context.MODE_PRIVATE);
512
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700513 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700514 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700515
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700516 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700517 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
518
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700519 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700520 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700521
Jason Monk4da79e02015-09-10 10:54:36 -0400522 mIsShowingDashboard = className.equals(Settings.class.getName())
523 || className.equals(Settings.WirelessSettings.class.getName())
524 || className.equals(Settings.DeviceSettings.class.getName())
525 || className.equals(Settings.PersonalSettings.class.getName())
526 || className.equals(Settings.WirelessSettings.class.getName());
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700527
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700528 // This is a "Sub Settings" when:
529 // - this is a real SubSettings
530 // - or :settings:show_fragment_as_subsetting is passed to the Intent
Jorim Jaggi4dfcb822015-04-29 17:21:32 -0700531 final boolean isSubSettings = this instanceof SubSettings ||
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700532 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
533
534 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
535 if (isSubSettings) {
Fabrice Di Meglio712df6c2014-07-18 17:44:37 -0700536 // Check also that we are not a Theme Dialog as we don't want to override them
537 final int themeResId = getThemeResId();
538 if (themeResId != R.style.Theme_DialogWhenLarge &&
539 themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
540 setTheme(R.style.Theme_SubSettings);
541 }
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700542 }
543
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700544 setContentView(mIsShowingDashboard ?
545 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800546
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700547 mContent = (ViewGroup) findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700548
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800549 getFragmentManager().addOnBackStackChangedListener(this);
550
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700551 if (mIsShowingDashboard) {
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800552 // Run the Index update only if we have some space
553 if (!Utils.isLowStorage(this)) {
Jason Monkfd2c7222015-12-02 15:38:38 -0500554 long indexStartTime = System.currentTimeMillis();
555 AsyncTask.execute(new Runnable() {
556 @Override
557 public void run() {
558 Index.getInstance(getApplicationContext()).update();
559 }
560 });
561 if (DEBUG_TIMING) Log.d(LOG_TAG, "Index.update() took "
562 + (System.currentTimeMillis() - indexStartTime) + " ms");
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800563 } else {
564 Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
565 }
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700566 }
567
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700568 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700569 // We are restarting from a previous saved state; used that to initialize, instead
570 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700571 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
572 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800573
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700574 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800575
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700576 ArrayList<DashboardCategory> categories =
577 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
578 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700579 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700580 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700581 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800582 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700583
584 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700585 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800586 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700587 if (!mIsShowingDashboard) {
Jason Monkea8b1a72015-06-02 16:46:34 -0400588 mDisplaySearch = false;
589 // UP will be shown only if it is a sub settings
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700590 if (mIsShortcut) {
591 mDisplayHomeAsUpEnabled = isSubSettings;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700592 } else if (isSubSettings) {
593 mDisplayHomeAsUpEnabled = true;
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700594 } else {
595 mDisplayHomeAsUpEnabled = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700596 }
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700597 setTitleFromIntent(intent);
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700598
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700599 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700600 switchToFragment(initialFragmentName, initialArguments, true, false,
601 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000602 } else {
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700603 // No UP affordance if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700604 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700605 // Show Search affordance
606 mDisplaySearch = true;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700607 mInitialTitleResId = R.string.dashboard_title;
Fabrice Di Meglio42c4b0a2014-05-22 10:30:03 -0700608 switchToFragment(DashboardSummary.class.getName(), null, false, false,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700609 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800610 }
611 }
612
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700613 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700614 if (mActionBar != null) {
615 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
616 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
617 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700618 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
Jason Monke4ebcd12016-02-21 09:37:41 -0500619 if (mSwitchBar != null) {
620 mSwitchBar.setMetricsTag(getMetricsTag());
621 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700622
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800623 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800624 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
625
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700626 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800627 if (buttonBar != null) {
628 buttonBar.setVisibility(View.VISIBLE);
629
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700630 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800631 backButton.setOnClickListener(new OnClickListener() {
632 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700633 setResult(RESULT_CANCELED, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800634 finish();
635 }
636 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700637 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800638 skipButton.setOnClickListener(new OnClickListener() {
639 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700640 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800641 finish();
642 }
643 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700644 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800645 mNextButton.setOnClickListener(new OnClickListener() {
646 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700647 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800648 finish();
649 }
650 });
651
652 // set our various button parameters
653 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
654 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
655 if (TextUtils.isEmpty(buttonText)) {
656 mNextButton.setVisibility(View.GONE);
657 }
658 else {
659 mNextButton.setText(buttonText);
660 }
661 }
662 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
663 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
664 if (TextUtils.isEmpty(buttonText)) {
665 backButton.setVisibility(View.GONE);
666 }
667 else {
668 backButton.setText(buttonText);
669 }
670 }
671 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
672 skipButton.setVisibility(View.VISIBLE);
673 }
674 }
675 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700676
Jason Monkfd2c7222015-12-02 15:38:38 -0500677 if (DEBUG_TIMING) Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
678 + " ms");
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700679 }
680
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700681 private void setTitleFromIntent(Intent intent) {
682 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
683 if (initialTitleResId > 0) {
684 mInitialTitle = null;
685 mInitialTitleResId = initialTitleResId;
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100686
687 final String initialTitleResPackageName = intent.getStringExtra(
688 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
689 if (initialTitleResPackageName != null) {
690 try {
691 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
692 0 /* flags */, new UserHandle(UserHandle.myUserId()));
693 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
694 setTitle(mInitialTitle);
695 mInitialTitleResId = -1;
696 return;
697 } catch (NameNotFoundException e) {
698 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
699 }
700 } else {
701 setTitle(mInitialTitleResId);
702 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700703 } else {
704 mInitialTitleResId = -1;
705 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
706 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
707 setTitle(mInitialTitle);
708 }
709 }
710
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800711 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800712 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700713 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800714 }
715
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700716 private int setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800717 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700718
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800719 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700720 if (mInitialTitleResId > 0) {
721 setTitle(mInitialTitleResId);
722 } else {
723 setTitle(mInitialTitle);
724 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700725 return 0;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800726 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700727
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800728 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
729 setTitleFromBackStackEntry(bse);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700730
731 return count;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800732 }
733
734 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
735 final CharSequence title;
736 final int titleRes = bse.getBreadCrumbTitleRes();
737 if (titleRes > 0) {
738 title = getText(titleRes);
739 } else {
740 title = bse.getBreadCrumbTitle();
741 }
742 if (title != null) {
743 setTitle(title);
744 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800745 }
746
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800747 @Override
748 protected void onSaveInstanceState(Bundle outState) {
749 super.onSaveInstanceState(outState);
750
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700751 if (mCategories.size() > 0) {
752 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800753 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700754
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700755 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700756 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700757
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700758 if (mDisplaySearch) {
759 // The option menus are created if the ActionBar is visible and they are also created
760 // asynchronously. If you launch Settings with an Intent action like
761 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
762 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
763 // menu item and search view are null.
764 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
765 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700766
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700767 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
768 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
769 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800770 }
771
772 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400773 protected void onResume() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800774 super.onResume();
775
776 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
777 @Override
778 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Jason Monk4da79e02015-09-10 10:54:36 -0400779 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800780 }
781 };
782 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
783 mDevelopmentPreferencesListener);
784
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800785 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Clara Bayarri6934a042015-10-14 11:07:35 +0100786 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_ADDED));
787 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_REMOVED));
Svetoslav853e4712014-04-14 10:10:25 -0700788
Svetoslav990159a2014-04-14 17:14:59 -0700789 mDynamicIndexableContentMonitor.register(this);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700790
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700791 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700792 onQueryTextSubmit(mSearchQuery);
793 }
Jason Monk4da79e02015-09-10 10:54:36 -0400794 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800795 }
796
797 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400798 protected void onPause() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800799 super.onPause();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800800 unregisterReceiver(mBatteryInfoReceiver);
Clara Bayarri8c9521f2016-01-12 14:10:45 +0000801 unregisterReceiver(mUserAddRemoveReceiver);
Svetoslav990159a2014-04-14 17:14:59 -0700802 mDynamicIndexableContentMonitor.unregister();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800803 }
804
805 @Override
806 public void onDestroy() {
807 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700808
809 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
810 mDevelopmentPreferencesListener);
811 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800812 }
813
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800814 protected boolean isValidFragment(String fragmentName) {
815 // Almost all fragments are wrapped in this,
816 // except for a few that have their own activities.
817 for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
818 if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
819 }
820 return false;
821 }
822
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800823 @Override
824 public Intent getIntent() {
825 Intent superIntent = super.getIntent();
826 String startingFragment = getStartingFragmentClass(superIntent);
827 // This is called from super.onCreate, isMultiPane() is not yet reliable
828 // Do not use onIsHidingHeaders either, which relies itself on this method
829 if (startingFragment != null) {
830 Intent modIntent = new Intent(superIntent);
831 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
832 Bundle args = superIntent.getExtras();
833 if (args != null) {
834 args = new Bundle(args);
835 } else {
836 args = new Bundle();
837 }
838 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100839 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800840 return modIntent;
841 }
842 return superIntent;
843 }
844
845 /**
846 * Checks if the component name in the intent is different from the Settings class and
847 * returns the class name to load as a fragment.
848 */
849 private String getStartingFragmentClass(Intent intent) {
850 if (mFragmentClass != null) return mFragmentClass;
851
852 String intentClass = intent.getComponent().getClassName();
853 if (intentClass.equals(getClass().getName())) return null;
854
855 if ("com.android.settings.ManageApplications".equals(intentClass)
856 || "com.android.settings.RunningServices".equals(intentClass)
857 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
858 // Old names of manage apps.
859 intentClass = com.android.settings.applications.ManageApplications.class.getName();
860 }
861
862 return intentClass;
863 }
864
865 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000866 * Start a new fragment containing a preference panel. If the preferences
867 * are being displayed in multi-pane mode, the given fragment class will
868 * be instantiated and placed in the appropriate pane. If running in
869 * single-pane mode, a new activity will be launched in which to show the
870 * fragment.
871 *
872 * @param fragmentClass Full name of the class implementing the fragment.
873 * @param args Any desired arguments to supply to the fragment.
874 * @param titleRes Optional resource identifier of the title of this
875 * fragment.
876 * @param titleText Optional text of the title of this fragment.
877 * @param resultTo Optional fragment that result data should be sent to.
878 * If non-null, resultTo.onActivityResult() will be called when this
879 * preference panel is done. The launched panel must use
880 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
881 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700882 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000883 */
884 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700885 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700886 String title = null;
887 if (titleRes < 0) {
888 if (titleText != null) {
889 title = titleText.toString();
890 } else {
891 // There not much we can do in that case
892 title = "";
893 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700894 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700895 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700896 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000897 }
898
899 /**
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100900 * Start a new fragment in a new activity containing a preference panel for a given user. If the
901 * preferences are being displayed in multi-pane mode, the given fragment class will be
902 * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
903 * activity will be launched in which to show the fragment.
904 *
905 * @param fragmentClass Full name of the class implementing the fragment.
906 * @param args Any desired arguments to supply to the fragment.
907 * @param titleRes Optional resource identifier of the title of this fragment.
908 * @param titleText Optional text of the title of this fragment.
909 * @param userHandle The user for which the panel has to be started.
910 */
911 public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
912 CharSequence titleText, UserHandle userHandle) {
Lifu Tangd0332852015-04-02 12:05:46 -0700913 // This is a workaround.
914 //
915 // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
916 // starting the fragment could cause a native stack corruption. See b/17523189. However,
917 // adding that flag and start the preference panel with the same UserHandler will make it
918 // impossible to use back button to return to the previous screen. See b/20042570.
919 //
920 // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
921 // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
922 // when we're calling it as the same user.
923 if (userHandle.getIdentifier() == UserHandle.myUserId()) {
924 startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0);
925 } else {
926 String title = null;
927 if (titleRes < 0) {
928 if (titleText != null) {
929 title = titleText.toString();
930 } else {
931 // There not much we can do in that case
932 title = "";
933 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100934 }
Lifu Tangd0332852015-04-02 12:05:46 -0700935 Utils.startWithFragmentAsUser(this, fragmentClass, args,
936 titleRes, title, mIsShortcut, userHandle);
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100937 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100938 }
939
940 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800941 * Called by a preference panel fragment to finish itself.
942 *
943 * @param caller The fragment that is asking to be finished.
944 * @param resultCode Optional result code to send back to the original
945 * launching fragment.
946 * @param resultData Optional result data to send back to the original
947 * launching fragment.
948 */
949 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
950 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700951 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800952 }
953
954 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000955 * Start a new fragment.
956 *
957 * @param fragment The fragment to start
958 * @param push If true, the current fragment will be pushed onto the back stack. If false,
959 * the current fragment will be replaced.
960 */
961 public void startPreferenceFragment(Fragment fragment, boolean push) {
962 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700963 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000964 if (push) {
965 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
966 transaction.addToBackStack(BACK_STACK_PREFS);
967 } else {
968 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
969 }
970 transaction.commitAllowingStateLoss();
971 }
972
973 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700974 * Switch to a specific Fragment with taking care of validation, Title and BackStack
975 */
976 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700977 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700978 if (validate && !isValidFragment(fragmentName)) {
979 throw new IllegalArgumentException("Invalid fragment for this activity: "
980 + fragmentName);
981 }
982 Fragment f = Fragment.instantiate(this, fragmentName, args);
983 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700984 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700985 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700986 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700987 }
988 if (addToBackStack) {
989 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
990 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700991 if (titleResId > 0) {
992 transaction.setBreadCrumbTitle(titleResId);
993 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700994 transaction.setBreadCrumbTitle(title);
995 }
996 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700997 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700998 return f;
999 }
1000
Jason Monk4da79e02015-09-10 10:54:36 -04001001 private void updateTilesList() {
Jason Monkfd2c7222015-12-02 15:38:38 -05001002 // Generally the items that are will be changing from these updates will
1003 // not be in the top list of tiles, so run it in the background and the
1004 // SettingsDrawerActivity will pick up on the updates automatically.
1005 AsyncTask.execute(new Runnable() {
1006 @Override
1007 public void run() {
1008 doUpdateTilesList();
1009 }
1010 });
1011 }
1012
1013 private void doUpdateTilesList() {
Jason Monk4da79e02015-09-10 10:54:36 -04001014 PackageManager pm = getPackageManager();
Xiaohui Chen44879a32015-07-22 13:53:22 -07001015 final UserManager um = UserManager.get(this);
1016 final boolean isAdmin = um.isAdminUser();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001017
Jason Monk4da79e02015-09-10 10:54:36 -04001018 String packageName = getPackageName();
1019 setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()),
1020 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001021
Jason Monk4da79e02015-09-10 10:54:36 -04001022 setTileEnabled(new ComponentName(packageName,
1023 Settings.BluetoothSettingsActivity.class.getName()),
1024 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001025
Jason Monk4da79e02015-09-10 10:54:36 -04001026 setTileEnabled(new ComponentName(packageName,
1027 Settings.DataUsageSummaryActivity.class.getName()),
1028 Utils.isBandwidthControlEnabled(), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001029
Jason Monk4da79e02015-09-10 10:54:36 -04001030 setTileEnabled(new ComponentName(packageName,
1031 Settings.SimSettingsActivity.class.getName()),
1032 Utils.showSimCardTile(this), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001033
Jason Monk4da79e02015-09-10 10:54:36 -04001034 setTileEnabled(new ComponentName(packageName,
1035 Settings.PowerUsageSummaryActivity.class.getName()),
1036 mBatteryPresent, isAdmin, pm);
1037
1038 setTileEnabled(new ComponentName(packageName,
Jason Monk4da79e02015-09-10 10:54:36 -04001039 Settings.UserSettingsActivity.class.getName()),
1040 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
1041 && !Utils.isMonkeyRunning(), isAdmin, pm);
1042
1043 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
1044 setTileEnabled(new ComponentName(packageName,
1045 Settings.PaymentSettingsActivity.class.getName()),
1046 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
1047 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
1048 && adapter != null && adapter.isEnabled(), isAdmin, pm);
1049
1050 setTileEnabled(new ComponentName(packageName,
1051 Settings.PrintSettingsActivity.class.getName()),
1052 pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin, pm);
1053
1054 final boolean showDev = mDevelopmentPreferences.getBoolean(
1055 DevelopmentSettings.PREF_SHOW,
1056 android.os.Build.TYPE.equals("eng"));
1057 setTileEnabled(new ComponentName(packageName,
1058 Settings.DevelopmentSettingsActivity.class.getName()),
1059 showDev && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES),
1060 isAdmin, pm);
1061
1062 if (UserHandle.MU_ENABLED && !isAdmin) {
1063 // When on restricted users, disable all extra categories (but only the settings ones).
Jason Monkfd2c7222015-12-02 15:38:38 -05001064 List<DashboardCategory> categories = getDashboardCategories();
Jason Monk4da79e02015-09-10 10:54:36 -04001065 for (DashboardCategory category : categories) {
Jason Monkd4f03ec2016-01-07 16:25:34 -05001066 for (Tile tile : category.tiles) {
Jason Monk4da79e02015-09-10 10:54:36 -04001067 ComponentName component = tile.intent.getComponent();
1068 if (packageName.equals(component)&& !ArrayUtils.contains(
1069 SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1070 setTileEnabled(component, false, isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001071 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001072 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001073 }
1074 }
Jason Monk2ebc8a02015-02-13 15:23:19 -05001075 }
1076
Jason Monk4da79e02015-09-10 10:54:36 -04001077 private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin,
1078 PackageManager pm) {
1079 if (UserHandle.MU_ENABLED && !isAdmin
1080 && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1081 enabled = false;
1082 }
1083 int state = pm.getComponentEnabledSetting(component);
1084 boolean isEnabled = state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
1085 || state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
1086 if (isEnabled != enabled) {
1087 pm.setComponentEnabledSetting(component, enabled
1088 ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
1089 : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
1090 PackageManager.DONT_KILL_APP);
Jason Monk2ebc8a02015-02-13 15:23:19 -05001091 }
1092 }
1093
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001094 private void getMetaData() {
1095 try {
1096 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1097 PackageManager.GET_META_DATA);
1098 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001099 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1100 } catch (NameNotFoundException nnfe) {
1101 // No recovery
1102 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1103 }
1104 }
1105
1106 // give subclasses access to the Next button
1107 public boolean hasNextButton() {
1108 return mNextButton != null;
1109 }
1110
1111 public Button getNextButton() {
1112 return mNextButton;
1113 }
1114
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001115 @Override
1116 public boolean shouldUpRecreateTask(Intent targetIntent) {
1117 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1118 }
1119
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001120 @Override
1121 public boolean onQueryTextSubmit(String query) {
1122 switchToSearchResultsFragmentIfNeeded();
1123 mSearchQuery = query;
1124 return mSearchResultsFragment.onQueryTextSubmit(query);
1125 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001126
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001127 @Override
1128 public boolean onQueryTextChange(String newText) {
1129 mSearchQuery = newText;
Fabrice Di Meglio7e4855e2014-05-23 16:03:43 -07001130 if (mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001131 return false;
1132 }
1133 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001134 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001135
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001136 @Override
1137 public boolean onClose() {
1138 return false;
1139 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001140
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001141 @Override
1142 public boolean onMenuItemActionExpand(MenuItem item) {
1143 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001144 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001145 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001146 return true;
1147 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001148
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001149 @Override
1150 public boolean onMenuItemActionCollapse(MenuItem item) {
1151 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001152 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001153 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001154 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001155 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001156 return true;
1157 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001158
Jason Monk4da79e02015-09-10 10:54:36 -04001159 @Override
Jason Monkd4f03ec2016-01-07 16:25:34 -05001160 protected void onTileClicked(Tile tile) {
Jason Monk4da79e02015-09-10 10:54:36 -04001161 if (mIsShowingDashboard) {
1162 // If on dashboard, don't finish so the back comes back to here.
1163 openTile(tile);
1164 } else {
1165 super.onTileClicked(tile);
1166 }
1167 }
1168
Jason Monkaf001092015-11-04 13:16:18 -05001169 @Override
1170 public void onProfileTileOpen() {
1171 if (!mIsShowingDashboard) {
1172 finish();
1173 }
1174 }
1175
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001176 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001177 if (mSearchResultsFragment != null) {
1178 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001179 }
Fabrice Di Megliod40dd452014-07-18 15:20:34 -07001180 Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001181 if (current != null && current instanceof SearchResultsSummary) {
1182 mSearchResultsFragment = (SearchResultsSummary) current;
1183 } else {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001184 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001185 SearchResultsSummary.class.getName(), null, false, true,
1186 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001187 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001188 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001189 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001190 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001191
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001192 public void needToRevertToInitialFragment() {
1193 mNeedToRevertToInitialFragment = true;
1194 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001195
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001196 private void revertToInitialFragment() {
1197 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001198 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001199 mSearchMenuItemExpanded = false;
1200 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1201 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001202 if (mSearchMenuItem != null) {
1203 mSearchMenuItem.collapseActionView();
1204 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001205 }
Jim Miller0698a212014-10-16 19:49:07 -07001206
1207 public Intent getResultIntentData() {
1208 return mResultIntentData;
1209 }
1210
1211 public void setResultIntentData(Intent resultIntentData) {
1212 mResultIntentData = resultIntentData;
1213 }
Jason Monkd4f03ec2016-01-07 16:25:34 -05001214
1215 public void startSuggestion(Intent intent) {
1216 mCurrentSuggestion = intent.getComponent();
1217 startActivityForResult(intent, REQUEST_SUGGESTION);
1218 }
1219
1220 @Override
1221 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
1222 if (requestCode == REQUEST_SUGGESTION && mCurrentSuggestion != null
1223 && resultCode != RESULT_CANCELED) {
1224 getPackageManager().setComponentEnabledSetting(mCurrentSuggestion,
1225 PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
1226 }
1227 super.onActivityResult(requestCode, resultCode, data);
1228 }
1229
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001230}