blob: 9f86646fe64bb0d933d7cb21be86ba371cbbef58 [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
Philip P. Moltmannd9779db2016-02-24 12:11:05 -0800134 private static final int LOADER_ID_INDEXABLE_CONTENT_MONITOR = 1;
135
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800136 // Constants for state save/restore
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700137 private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700138 private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
139 private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700140 private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700141 private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700142 private static final String SAVE_KEY_HOME_ACTIVITIES_COUNT = ":settings:home_activities_count";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800143
144 /**
145 * When starting this activity, the invoking Intent can contain this extra
146 * string to specify which fragment should be initially displayed.
147 * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
148 * will call isValidFragment() to confirm that the fragment class name is valid for this
149 * activity.
150 */
151 public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
152
153 /**
154 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
155 * this extra can also be specified to supply a Bundle of arguments to pass
156 * to that fragment when it is instantiated during the initial creation
157 * of the activity.
158 */
159 public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
160
161 /**
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700162 * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
163 */
164 public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
165
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800166 public static final String BACK_STACK_PREFS = ":settings:prefs";
167
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800168 // extras that allow any preference activity to be launched as part of a wizard
169
170 // show Back and Next buttons? takes boolean parameter
171 // Back will then return RESULT_CANCELED and Next RESULT_OK
172 protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
173
174 // add a Skip button?
175 private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
176
177 // specify custom text for the Back or Next buttons, or cause a button to not appear
178 // at all by setting it to null
179 protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
180 protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
181
182 /**
183 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700184 * 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 -0800185 * that fragment.
186 */
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700187 public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100188 /**
189 * The package name used to resolve the title resource id.
190 */
191 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
192 ":settings:show_fragment_title_res_package_name";
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700193 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
194 ":settings:show_fragment_title_resid";
195 public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
196 ":settings:show_fragment_as_shortcut";
197
198 public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
199 ":settings:show_fragment_as_subsetting";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800200
Jason Monk30695812015-11-17 09:01:08 -0500201 public static final String META_DATA_KEY_FRAGMENT_CLASS =
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800202 "com.android.settings.FRAGMENT_CLASS";
203
204 private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
205
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700206 private static final String EMPTY_QUERY = "";
207
Jason Monkd4f03ec2016-01-07 16:25:34 -0500208 private static final int REQUEST_SUGGESTION = 42;
209
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800210 private String mFragmentClass;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800211
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800212 private CharSequence mInitialTitle;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700213 private int mInitialTitleResId;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800214
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800215 // Show only these settings for restricted users
Jason Monk4da79e02015-09-10 10:54:36 -0400216 private String[] SETTINGS_FOR_RESTRICTED = {
217 //wireless_section
218 WifiSettingsActivity.class.getName(),
219 Settings.BluetoothSettingsActivity.class.getName(),
220 Settings.DataUsageSummaryActivity.class.getName(),
221 Settings.SimSettingsActivity.class.getName(),
222 Settings.WirelessSettingsActivity.class.getName(),
223 //device_section
224 Settings.HomeSettingsActivity.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500225 Settings.SoundSettingsActivity.class.getName(),
Jason Monk4da79e02015-09-10 10:54:36 -0400226 Settings.DisplaySettingsActivity.class.getName(),
227 Settings.StorageSettingsActivity.class.getName(),
228 Settings.ManageApplicationsActivity.class.getName(),
229 Settings.PowerUsageSummaryActivity.class.getName(),
230 //personal_section
231 Settings.LocationSettingsActivity.class.getName(),
232 Settings.SecuritySettingsActivity.class.getName(),
233 Settings.InputMethodAndLanguageSettingsActivity.class.getName(),
234 Settings.UserSettingsActivity.class.getName(),
235 Settings.AccountSettingsActivity.class.getName(),
236 //system_section
237 Settings.DateTimeSettingsActivity.class.getName(),
238 Settings.DeviceInfoSettingsActivity.class.getName(),
239 Settings.AccessibilitySettingsActivity.class.getName(),
240 Settings.PrintSettingsActivity.class.getName(),
241 Settings.PaymentSettingsActivity.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800242 };
243
244 private static final String[] ENTRY_FRAGMENTS = {
245 WirelessSettings.class.getName(),
246 WifiSettings.class.getName(),
247 AdvancedWifiSettings.class.getName(),
PauloftheWest7837b992014-06-24 07:42:27 -0700248 SavedAccessPointsWifiSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800249 BluetoothSettings.class.getName(),
PauloftheWest38155612014-06-30 10:02:36 -0700250 SimSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800251 TetherSettings.class.getName(),
252 WifiP2pSettings.class.getName(),
253 VpnSettings.class.getName(),
254 DateTimeSettings.class.getName(),
Mihai Nitad7d48fd2016-01-12 08:55:05 -0800255 LocaleListEditor.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800256 InputMethodAndLanguageSettings.class.getName(),
Abodunrinwa Toki976bb3f2016-01-20 18:43:20 +0000257 AvailableVirtualKeyboardFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800258 SpellCheckersSettings.class.getName(),
259 UserDictionaryList.class.getName(),
260 UserDictionarySettings.class.getName(),
Amith Yamasani3033ce02014-07-14 18:03:15 -0700261 HomeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800262 DisplaySettings.class.getName(),
263 DeviceInfoSettings.class.getName(),
264 ManageApplications.class.getName(),
Jason Monka2d47fc2016-03-03 10:49:44 -0500265 NotificationApps.class.getName(),
Xiyuan Xia86a55402015-06-02 14:55:32 -0700266 ManageAssist.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800267 ProcessStatsUi.class.getName(),
268 NotificationStation.class.getName(),
269 LocationSettings.class.getName(),
270 SecuritySettings.class.getName(),
Jason Monkd8da51c2015-04-17 14:34:12 -0400271 UsageAccessDetails.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800272 PrivacySettings.class.getName(),
273 DeviceAdminSettings.class.getName(),
274 AccessibilitySettings.class.getName(),
Anna Galuszab1795f52016-01-08 14:37:16 -0800275 AccessibilitySettingsForSetupWizard.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800276 CaptionPropertiesFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800277 com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(),
278 TextToSpeechSettings.class.getName(),
Jeff Sharkey42833b22015-04-11 21:27:33 -0700279 StorageSettings.class.getName(),
Jeff Sharkeya16257d2015-04-28 13:41:01 -0700280 PrivateVolumeForget.class.getName(),
Jeff Sharkeye77f0682015-04-29 11:24:57 -0700281 PrivateVolumeSettings.class.getName(),
282 PublicVolumeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800283 DevelopmentSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800284 AndroidBeam.class.getName(),
285 WifiDisplaySettings.class.getName(),
286 PowerUsageSummary.class.getName(),
287 AccountSyncSettings.class.getName(),
Alexandra Gherghina6d839872014-07-22 12:04:58 +0000288 AccountSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800289 CryptKeeperSettings.class.getName(),
290 DataUsageSummary.class.getName(),
291 DreamSettings.class.getName(),
292 UserSettings.class.getName(),
293 NotificationAccessSettings.class.getName(),
John Spurlock08531a82015-05-07 17:45:43 -0400294 ZenAccessSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800295 PrintSettingsFragment.class.getName(),
296 PrintJobSettingsFragment.class.getName(),
297 TrustedCredentialsSettings.class.getName(),
298 PaymentSettings.class.getName(),
299 KeyboardLayoutPickerFragment.class.getName(),
Abodunrinwa Toki5f0b59b2016-01-25 23:02:23 +0000300 KeyboardLayoutPickerFragment2.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700301 ZenModeSettings.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500302 SoundSettings.class.getName(),
303 ConfigureNotificationSettings.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700304 ChooseLockPassword.ChooseLockPasswordFragment.class.getName(),
305 ChooseLockPattern.ChooseLockPatternFragment.class.getName(),
John Spurlockc7f8e8c2014-06-04 19:11:22 -0400306 InstalledAppDetails.class.getName(),
307 BatterySaverSettings.class.getName(),
Fabrice Di Megliodcf59dd2014-07-21 11:22:20 -0700308 AppNotificationSettings.class.getName(),
Fabrice Di Meglioe3ff4d82014-07-23 20:03:20 -0700309 OtherSoundSettings.class.getName(),
Narayan Kamath33acb152015-03-16 12:48:05 +0000310 ApnSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400311 WifiCallingSettings.class.getName(),
John Spurlockc1df2aa2015-04-13 20:57:06 -0400312 ZenModePrioritySettings.class.getName(),
John Spurlock533a5662015-06-19 10:47:36 -0400313 ZenModeAutomationSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400314 ZenModeScheduleRuleSettings.class.getName(),
John Spurlockf57bad72015-04-30 09:26:15 -0400315 ZenModeEventRuleSettings.class.getName(),
Julia Reynolds5555d262015-11-09 10:52:17 -0500316 ZenModeVisualInterruptionSettings.class.getName(),
Jason Monk2583fc12015-03-25 09:46:30 -0400317 ProcessStatsUi.class.getName(),
Jason Monk1eb54eb2015-04-29 12:46:42 -0400318 PowerUsageDetail.class.getName(),
Jason Monk2cdafc62015-06-12 12:32:50 -0400319 ProcessStatsSummary.class.getName(),
Billy Laufee78562015-07-27 12:57:07 +0100320 DrawOverlayDetails.class.getName(),
321 WriteSettingsDetails.class.getName(),
Jason Monk91e2f892016-02-23 15:31:09 -0500322 AdvancedAppSettings.class.getName(),
Jason Monkb9e5d232016-01-26 17:43:57 -0500323 WallpaperTypeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800324 };
325
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700326
327 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
328 "android.settings.APPLICATION_DETAILS_SETTINGS"
329 };
330
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800331 private SharedPreferences mDevelopmentPreferences;
332 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
333
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800334 private boolean mBatteryPresent = true;
335 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800336 @Override
337 public void onReceive(Context context, Intent intent) {
338 String action = intent.getAction();
339 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
340 boolean batteryPresent = Utils.isBatteryPresent(intent);
341
342 if (mBatteryPresent != batteryPresent) {
343 mBatteryPresent = batteryPresent;
Jason Monk4da79e02015-09-10 10:54:36 -0400344 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800345 }
346 }
347 }
348 };
349
Clara Bayarri6934a042015-10-14 11:07:35 +0100350 private final BroadcastReceiver mUserAddRemoveReceiver = new BroadcastReceiver() {
351 @Override
352 public void onReceive(Context context, Intent intent) {
353 String action = intent.getAction();
354 if (action.equals(Intent.ACTION_USER_ADDED)
355 || action.equals(Intent.ACTION_USER_REMOVED)) {
356 Index.getInstance(getApplicationContext()).update();
357 }
358 }
359 };
360
Svetoslav990159a2014-04-14 17:14:59 -0700361 private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor =
362 new DynamicIndexableContentMonitor();
Svetoslav853e4712014-04-14 10:10:25 -0700363
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700364 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700365 private SwitchBar mSwitchBar;
366
367 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700368
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700369 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700370 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700371
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700372 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700373 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700374
Anna Galusza2f1c1132016-03-04 18:41:35 -0800375 private int mMainContentId = R.id.main_content;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700376 private ViewGroup mContent;
377
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700378 private SearchView mSearchView;
379 private MenuItem mSearchMenuItem;
380 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700381 private SearchResultsSummary mSearchResultsFragment;
382 private String mSearchQuery;
383
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700384 // Categories
385 private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800386
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700387 private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800388
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700389 private boolean mNeedToRevertToInitialFragment = false;
390
Jim Miller0698a212014-10-16 19:49:07 -0700391 private Intent mResultIntentData;
Jason Monkd4f03ec2016-01-07 16:25:34 -0500392 private ComponentName mCurrentSuggestion;
Jim Miller0698a212014-10-16 19:49:07 -0700393
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700394 public SwitchBar getSwitchBar() {
395 return mSwitchBar;
396 }
397
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800398 @Override
399 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
400 // Override the fragment title for Wallpaper settings
Jason Monk39b46742015-09-10 15:52:51 -0400401 CharSequence title = pref.getTitle();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800402 if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) {
Jason Monk39b46742015-09-10 15:52:51 -0400403 title = getString(R.string.wallpaper_settings_fragment_title);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800404 }
Jason Monkb1dd5c92015-12-16 16:13:54 -0500405 startPreferencePanel(pref.getFragment(), pref.getExtras(), -1, title,
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800406 null, 0);
407 return true;
408 }
409
410 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400411 public boolean onPreferenceTreeClick(Preference preference) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800412 return false;
413 }
414
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800415 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800416 public void onConfigurationChanged(Configuration newConfig) {
417 super.onConfigurationChanged(newConfig);
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800418 Index.getInstance(this).update();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800419 }
420
421 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700422 protected void onStart() {
423 super.onStart();
424
425 if (mNeedToRevertToInitialFragment) {
426 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800427 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800428 }
429
430 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700431 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700432 if (!mDisplaySearch) {
433 return false;
434 }
435
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700436 MenuInflater inflater = getMenuInflater();
437 inflater.inflate(R.menu.options_menu, menu);
438
439 // Cache the search query (can be overriden by the OnQueryTextListener)
440 final String query = mSearchQuery;
441
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700442 mSearchMenuItem = menu.findItem(R.id.search);
443 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700444
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700445 if (mSearchMenuItem == null || mSearchView == null) {
446 return false;
447 }
448
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700449 if (mSearchResultsFragment != null) {
450 mSearchResultsFragment.setSearchView(mSearchView);
451 }
452
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700453 mSearchMenuItem.setOnActionExpandListener(this);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700454 mSearchView.setOnQueryTextListener(this);
455 mSearchView.setOnCloseListener(this);
456
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700457 if (mSearchMenuItemExpanded) {
458 mSearchMenuItem.expandActionView();
459 }
460 mSearchView.setQuery(query, true /* submit */);
461
462 return true;
463 }
464
Jason Monk31c7c322016-01-20 14:41:52 -0500465 @Override
466 public SharedPreferences getSharedPreferences(String name, int mode) {
467 if (name.equals(getPackageName() + "_preferences")) {
Jason Monke4ebcd12016-02-21 09:37:41 -0500468 return new SharedPreferencesLogger(this, getMetricsTag());
Jason Monk31c7c322016-01-20 14:41:52 -0500469 }
470 return super.getSharedPreferences(name, mode);
471 }
472
Jason Monke4ebcd12016-02-21 09:37:41 -0500473 private String getMetricsTag() {
474 String tag = getClass().getName();
475 if (getIntent() != null && getIntent().hasExtra(EXTRA_SHOW_FRAGMENT)) {
476 tag = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
477 }
478 if (tag.startsWith("com.android.settings.")) {
479 tag = tag.replace("com.android.settings.", "");
480 }
481 return tag;
482 }
483
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700484 private static boolean isShortCutIntent(final Intent intent) {
485 Set<String> categories = intent.getCategories();
486 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
487 }
488
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700489 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700490 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700491 if (action == null) {
492 return false;
493 }
494 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
495 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
496 }
497 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700498 }
499
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700500 @Override
501 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700502 super.onCreate(savedState);
Jason Monkfd2c7222015-12-02 15:38:38 -0500503 long startTime = System.currentTimeMillis();
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700504
505 // Should happen before any call to getIntent()
506 getMetaData();
507
508 final Intent intent = getIntent();
509 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
510 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800511 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800512
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800513 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
514 Context.MODE_PRIVATE);
515
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700516 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700517 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700518
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700519 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700520 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
521
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700522 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700523 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700524
Jason Monk4da79e02015-09-10 10:54:36 -0400525 mIsShowingDashboard = className.equals(Settings.class.getName())
526 || className.equals(Settings.WirelessSettings.class.getName())
527 || className.equals(Settings.DeviceSettings.class.getName())
528 || className.equals(Settings.PersonalSettings.class.getName())
529 || className.equals(Settings.WirelessSettings.class.getName());
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700530
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700531 // This is a "Sub Settings" when:
532 // - this is a real SubSettings
533 // - or :settings:show_fragment_as_subsetting is passed to the Intent
Jorim Jaggi4dfcb822015-04-29 17:21:32 -0700534 final boolean isSubSettings = this instanceof SubSettings ||
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700535 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
536
537 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
538 if (isSubSettings) {
Fabrice Di Meglio712df6c2014-07-18 17:44:37 -0700539 // Check also that we are not a Theme Dialog as we don't want to override them
540 final int themeResId = getThemeResId();
541 if (themeResId != R.style.Theme_DialogWhenLarge &&
542 themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
543 setTheme(R.style.Theme_SubSettings);
544 }
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700545 }
546
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700547 setContentView(mIsShowingDashboard ?
548 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800549
Anna Galusza2f1c1132016-03-04 18:41:35 -0800550 mContent = (ViewGroup) findViewById(mMainContentId);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700551
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800552 getFragmentManager().addOnBackStackChangedListener(this);
553
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700554 if (mIsShowingDashboard) {
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800555 // Run the Index update only if we have some space
556 if (!Utils.isLowStorage(this)) {
Jason Monkfd2c7222015-12-02 15:38:38 -0500557 long indexStartTime = System.currentTimeMillis();
558 AsyncTask.execute(new Runnable() {
559 @Override
560 public void run() {
561 Index.getInstance(getApplicationContext()).update();
562 }
563 });
564 if (DEBUG_TIMING) Log.d(LOG_TAG, "Index.update() took "
565 + (System.currentTimeMillis() - indexStartTime) + " ms");
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800566 } else {
567 Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
568 }
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700569 }
570
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700571 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700572 // We are restarting from a previous saved state; used that to initialize, instead
573 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700574 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
575 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800576
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700577 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800578
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700579 ArrayList<DashboardCategory> categories =
580 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
581 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700582 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700583 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700584 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800585 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700586
587 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700588 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800589 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700590 if (!mIsShowingDashboard) {
Jason Monkea8b1a72015-06-02 16:46:34 -0400591 mDisplaySearch = false;
592 // UP will be shown only if it is a sub settings
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700593 if (mIsShortcut) {
594 mDisplayHomeAsUpEnabled = isSubSettings;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700595 } else if (isSubSettings) {
596 mDisplayHomeAsUpEnabled = true;
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700597 } else {
598 mDisplayHomeAsUpEnabled = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700599 }
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700600 setTitleFromIntent(intent);
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700601
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700602 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700603 switchToFragment(initialFragmentName, initialArguments, true, false,
604 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000605 } else {
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700606 // No UP affordance if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700607 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700608 // Show Search affordance
609 mDisplaySearch = true;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700610 mInitialTitleResId = R.string.dashboard_title;
Fabrice Di Meglio42c4b0a2014-05-22 10:30:03 -0700611 switchToFragment(DashboardSummary.class.getName(), null, false, false,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700612 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800613 }
614 }
615
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700616 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700617 if (mActionBar != null) {
618 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
619 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
620 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700621 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
Jason Monke4ebcd12016-02-21 09:37:41 -0500622 if (mSwitchBar != null) {
623 mSwitchBar.setMetricsTag(getMetricsTag());
624 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700625
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800626 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800627 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
628
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700629 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800630 if (buttonBar != null) {
631 buttonBar.setVisibility(View.VISIBLE);
632
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700633 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800634 backButton.setOnClickListener(new OnClickListener() {
635 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700636 setResult(RESULT_CANCELED, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800637 finish();
638 }
639 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700640 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800641 skipButton.setOnClickListener(new OnClickListener() {
642 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700643 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800644 finish();
645 }
646 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700647 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800648 mNextButton.setOnClickListener(new OnClickListener() {
649 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700650 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800651 finish();
652 }
653 });
654
655 // set our various button parameters
656 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
657 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
658 if (TextUtils.isEmpty(buttonText)) {
659 mNextButton.setVisibility(View.GONE);
660 }
661 else {
662 mNextButton.setText(buttonText);
663 }
664 }
665 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
666 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
667 if (TextUtils.isEmpty(buttonText)) {
668 backButton.setVisibility(View.GONE);
669 }
670 else {
671 backButton.setText(buttonText);
672 }
673 }
674 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
675 skipButton.setVisibility(View.VISIBLE);
676 }
677 }
678 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700679
Jason Monkfd2c7222015-12-02 15:38:38 -0500680 if (DEBUG_TIMING) Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
681 + " ms");
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700682 }
683
Anna Galusza2f1c1132016-03-04 18:41:35 -0800684 /**
685 * Sets the id of the view continaing the main content. Should be called before calling super's
686 * onCreate.
687 */
688 protected void setMainContentId(int contentId) {
689 mMainContentId = contentId;
690 }
691
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700692 private void setTitleFromIntent(Intent intent) {
693 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
694 if (initialTitleResId > 0) {
695 mInitialTitle = null;
696 mInitialTitleResId = initialTitleResId;
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100697
698 final String initialTitleResPackageName = intent.getStringExtra(
699 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
700 if (initialTitleResPackageName != null) {
701 try {
702 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
703 0 /* flags */, new UserHandle(UserHandle.myUserId()));
704 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
705 setTitle(mInitialTitle);
706 mInitialTitleResId = -1;
707 return;
708 } catch (NameNotFoundException e) {
709 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
710 }
711 } else {
712 setTitle(mInitialTitleResId);
713 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700714 } else {
715 mInitialTitleResId = -1;
716 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
717 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
718 setTitle(mInitialTitle);
719 }
720 }
721
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800722 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800723 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700724 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800725 }
726
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700727 private int setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800728 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700729
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800730 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700731 if (mInitialTitleResId > 0) {
732 setTitle(mInitialTitleResId);
733 } else {
734 setTitle(mInitialTitle);
735 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700736 return 0;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800737 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700738
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800739 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
740 setTitleFromBackStackEntry(bse);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700741
742 return count;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800743 }
744
745 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
746 final CharSequence title;
747 final int titleRes = bse.getBreadCrumbTitleRes();
748 if (titleRes > 0) {
749 title = getText(titleRes);
750 } else {
751 title = bse.getBreadCrumbTitle();
752 }
753 if (title != null) {
754 setTitle(title);
755 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800756 }
757
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800758 @Override
759 protected void onSaveInstanceState(Bundle outState) {
760 super.onSaveInstanceState(outState);
761
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700762 if (mCategories.size() > 0) {
763 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800764 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700765
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700766 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700767 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700768
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700769 if (mDisplaySearch) {
770 // The option menus are created if the ActionBar is visible and they are also created
771 // asynchronously. If you launch Settings with an Intent action like
772 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
773 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
774 // menu item and search view are null.
775 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
776 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700777
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700778 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
779 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
780 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800781 }
782
783 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400784 protected void onResume() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800785 super.onResume();
786
787 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
788 @Override
789 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Jason Monk4da79e02015-09-10 10:54:36 -0400790 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800791 }
792 };
793 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
794 mDevelopmentPreferencesListener);
795
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800796 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Clara Bayarri6934a042015-10-14 11:07:35 +0100797 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_ADDED));
798 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_REMOVED));
Svetoslav853e4712014-04-14 10:10:25 -0700799
Philip P. Moltmannd9779db2016-02-24 12:11:05 -0800800 mDynamicIndexableContentMonitor.register(this, LOADER_ID_INDEXABLE_CONTENT_MONITOR);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700801
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700802 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700803 onQueryTextSubmit(mSearchQuery);
804 }
Jason Monk4da79e02015-09-10 10:54:36 -0400805 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800806 }
807
808 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400809 protected void onPause() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800810 super.onPause();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800811 unregisterReceiver(mBatteryInfoReceiver);
Clara Bayarri8c9521f2016-01-12 14:10:45 +0000812 unregisterReceiver(mUserAddRemoveReceiver);
Svetoslav990159a2014-04-14 17:14:59 -0700813 mDynamicIndexableContentMonitor.unregister();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800814 }
815
816 @Override
817 public void onDestroy() {
818 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700819
820 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
821 mDevelopmentPreferencesListener);
822 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800823 }
824
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800825 protected boolean isValidFragment(String fragmentName) {
826 // Almost all fragments are wrapped in this,
827 // except for a few that have their own activities.
828 for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
829 if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
830 }
831 return false;
832 }
833
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800834 @Override
835 public Intent getIntent() {
836 Intent superIntent = super.getIntent();
837 String startingFragment = getStartingFragmentClass(superIntent);
838 // This is called from super.onCreate, isMultiPane() is not yet reliable
839 // Do not use onIsHidingHeaders either, which relies itself on this method
840 if (startingFragment != null) {
841 Intent modIntent = new Intent(superIntent);
842 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
843 Bundle args = superIntent.getExtras();
844 if (args != null) {
845 args = new Bundle(args);
846 } else {
847 args = new Bundle();
848 }
849 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100850 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800851 return modIntent;
852 }
853 return superIntent;
854 }
855
856 /**
857 * Checks if the component name in the intent is different from the Settings class and
858 * returns the class name to load as a fragment.
859 */
860 private String getStartingFragmentClass(Intent intent) {
861 if (mFragmentClass != null) return mFragmentClass;
862
863 String intentClass = intent.getComponent().getClassName();
864 if (intentClass.equals(getClass().getName())) return null;
865
866 if ("com.android.settings.ManageApplications".equals(intentClass)
867 || "com.android.settings.RunningServices".equals(intentClass)
868 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
869 // Old names of manage apps.
870 intentClass = com.android.settings.applications.ManageApplications.class.getName();
871 }
872
873 return intentClass;
874 }
875
876 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000877 * Start a new fragment containing a preference panel. If the preferences
878 * are being displayed in multi-pane mode, the given fragment class will
879 * be instantiated and placed in the appropriate pane. If running in
880 * single-pane mode, a new activity will be launched in which to show the
881 * fragment.
882 *
883 * @param fragmentClass Full name of the class implementing the fragment.
884 * @param args Any desired arguments to supply to the fragment.
885 * @param titleRes Optional resource identifier of the title of this
886 * fragment.
887 * @param titleText Optional text of the title of this fragment.
888 * @param resultTo Optional fragment that result data should be sent to.
889 * If non-null, resultTo.onActivityResult() will be called when this
890 * preference panel is done. The launched panel must use
891 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
892 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700893 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000894 */
895 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700896 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700897 String title = null;
898 if (titleRes < 0) {
899 if (titleText != null) {
900 title = titleText.toString();
901 } else {
902 // There not much we can do in that case
903 title = "";
904 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700905 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700906 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700907 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000908 }
909
910 /**
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100911 * Start a new fragment in a new activity containing a preference panel for a given user. If the
912 * preferences are being displayed in multi-pane mode, the given fragment class will be
913 * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
914 * activity will be launched in which to show the fragment.
915 *
916 * @param fragmentClass Full name of the class implementing the fragment.
917 * @param args Any desired arguments to supply to the fragment.
918 * @param titleRes Optional resource identifier of the title of this fragment.
919 * @param titleText Optional text of the title of this fragment.
920 * @param userHandle The user for which the panel has to be started.
921 */
922 public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
923 CharSequence titleText, UserHandle userHandle) {
Lifu Tangd0332852015-04-02 12:05:46 -0700924 // This is a workaround.
925 //
926 // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
927 // starting the fragment could cause a native stack corruption. See b/17523189. However,
928 // adding that flag and start the preference panel with the same UserHandler will make it
929 // impossible to use back button to return to the previous screen. See b/20042570.
930 //
931 // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
932 // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
933 // when we're calling it as the same user.
934 if (userHandle.getIdentifier() == UserHandle.myUserId()) {
935 startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0);
936 } else {
937 String title = null;
938 if (titleRes < 0) {
939 if (titleText != null) {
940 title = titleText.toString();
941 } else {
942 // There not much we can do in that case
943 title = "";
944 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100945 }
Lifu Tangd0332852015-04-02 12:05:46 -0700946 Utils.startWithFragmentAsUser(this, fragmentClass, args,
947 titleRes, title, mIsShortcut, userHandle);
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100948 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100949 }
950
951 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800952 * Called by a preference panel fragment to finish itself.
953 *
954 * @param caller The fragment that is asking to be finished.
955 * @param resultCode Optional result code to send back to the original
956 * launching fragment.
957 * @param resultData Optional result data to send back to the original
958 * launching fragment.
959 */
960 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
961 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700962 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800963 }
964
965 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000966 * Start a new fragment.
967 *
968 * @param fragment The fragment to start
969 * @param push If true, the current fragment will be pushed onto the back stack. If false,
970 * the current fragment will be replaced.
971 */
972 public void startPreferenceFragment(Fragment fragment, boolean push) {
973 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Anna Galusza2f1c1132016-03-04 18:41:35 -0800974 transaction.replace(mMainContentId, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000975 if (push) {
976 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
977 transaction.addToBackStack(BACK_STACK_PREFS);
978 } else {
979 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
980 }
981 transaction.commitAllowingStateLoss();
982 }
983
984 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700985 * Switch to a specific Fragment with taking care of validation, Title and BackStack
986 */
987 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700988 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700989 if (validate && !isValidFragment(fragmentName)) {
990 throw new IllegalArgumentException("Invalid fragment for this activity: "
991 + fragmentName);
992 }
993 Fragment f = Fragment.instantiate(this, fragmentName, args);
994 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Anna Galusza2f1c1132016-03-04 18:41:35 -0800995 transaction.replace(mMainContentId, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700996 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700997 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700998 }
999 if (addToBackStack) {
1000 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
1001 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001002 if (titleResId > 0) {
1003 transaction.setBreadCrumbTitle(titleResId);
1004 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001005 transaction.setBreadCrumbTitle(title);
1006 }
1007 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -07001008 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001009 return f;
1010 }
1011
Jason Monk4da79e02015-09-10 10:54:36 -04001012 private void updateTilesList() {
Jason Monkfd2c7222015-12-02 15:38:38 -05001013 // Generally the items that are will be changing from these updates will
1014 // not be in the top list of tiles, so run it in the background and the
1015 // SettingsDrawerActivity will pick up on the updates automatically.
1016 AsyncTask.execute(new Runnable() {
1017 @Override
1018 public void run() {
1019 doUpdateTilesList();
1020 }
1021 });
1022 }
1023
1024 private void doUpdateTilesList() {
Jason Monk4da79e02015-09-10 10:54:36 -04001025 PackageManager pm = getPackageManager();
Xiaohui Chen44879a32015-07-22 13:53:22 -07001026 final UserManager um = UserManager.get(this);
1027 final boolean isAdmin = um.isAdminUser();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001028
Jason Monk4da79e02015-09-10 10:54:36 -04001029 String packageName = getPackageName();
1030 setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()),
1031 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001032
Jason Monk4da79e02015-09-10 10:54:36 -04001033 setTileEnabled(new ComponentName(packageName,
1034 Settings.BluetoothSettingsActivity.class.getName()),
1035 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001036
Jason Monk4da79e02015-09-10 10:54:36 -04001037 setTileEnabled(new ComponentName(packageName,
1038 Settings.DataUsageSummaryActivity.class.getName()),
1039 Utils.isBandwidthControlEnabled(), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001040
Jason Monk4da79e02015-09-10 10:54:36 -04001041 setTileEnabled(new ComponentName(packageName,
1042 Settings.SimSettingsActivity.class.getName()),
1043 Utils.showSimCardTile(this), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001044
Jason Monk4da79e02015-09-10 10:54:36 -04001045 setTileEnabled(new ComponentName(packageName,
1046 Settings.PowerUsageSummaryActivity.class.getName()),
1047 mBatteryPresent, isAdmin, pm);
1048
1049 setTileEnabled(new ComponentName(packageName,
Jason Monk4da79e02015-09-10 10:54:36 -04001050 Settings.UserSettingsActivity.class.getName()),
1051 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
1052 && !Utils.isMonkeyRunning(), isAdmin, pm);
1053
1054 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
1055 setTileEnabled(new ComponentName(packageName,
1056 Settings.PaymentSettingsActivity.class.getName()),
1057 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
1058 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
1059 && adapter != null && adapter.isEnabled(), isAdmin, pm);
1060
1061 setTileEnabled(new ComponentName(packageName,
1062 Settings.PrintSettingsActivity.class.getName()),
1063 pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin, pm);
1064
1065 final boolean showDev = mDevelopmentPreferences.getBoolean(
1066 DevelopmentSettings.PREF_SHOW,
1067 android.os.Build.TYPE.equals("eng"));
1068 setTileEnabled(new ComponentName(packageName,
1069 Settings.DevelopmentSettingsActivity.class.getName()),
1070 showDev && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES),
1071 isAdmin, pm);
1072
1073 if (UserHandle.MU_ENABLED && !isAdmin) {
1074 // When on restricted users, disable all extra categories (but only the settings ones).
Jason Monkfd2c7222015-12-02 15:38:38 -05001075 List<DashboardCategory> categories = getDashboardCategories();
Jason Monk4da79e02015-09-10 10:54:36 -04001076 for (DashboardCategory category : categories) {
Jason Monkd4f03ec2016-01-07 16:25:34 -05001077 for (Tile tile : category.tiles) {
Jason Monk4da79e02015-09-10 10:54:36 -04001078 ComponentName component = tile.intent.getComponent();
1079 if (packageName.equals(component)&& !ArrayUtils.contains(
1080 SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1081 setTileEnabled(component, false, isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001082 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001083 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001084 }
1085 }
Jason Monk2ebc8a02015-02-13 15:23:19 -05001086 }
1087
Jason Monk4da79e02015-09-10 10:54:36 -04001088 private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin,
1089 PackageManager pm) {
1090 if (UserHandle.MU_ENABLED && !isAdmin
1091 && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1092 enabled = false;
1093 }
1094 int state = pm.getComponentEnabledSetting(component);
1095 boolean isEnabled = state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
1096 || state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
1097 if (isEnabled != enabled) {
1098 pm.setComponentEnabledSetting(component, enabled
1099 ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
1100 : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
1101 PackageManager.DONT_KILL_APP);
Jason Monk2ebc8a02015-02-13 15:23:19 -05001102 }
1103 }
1104
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001105 private void getMetaData() {
1106 try {
1107 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1108 PackageManager.GET_META_DATA);
1109 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001110 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1111 } catch (NameNotFoundException nnfe) {
1112 // No recovery
1113 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1114 }
1115 }
1116
1117 // give subclasses access to the Next button
1118 public boolean hasNextButton() {
1119 return mNextButton != null;
1120 }
1121
1122 public Button getNextButton() {
1123 return mNextButton;
1124 }
1125
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001126 @Override
1127 public boolean shouldUpRecreateTask(Intent targetIntent) {
1128 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1129 }
1130
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001131 @Override
1132 public boolean onQueryTextSubmit(String query) {
1133 switchToSearchResultsFragmentIfNeeded();
1134 mSearchQuery = query;
1135 return mSearchResultsFragment.onQueryTextSubmit(query);
1136 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001137
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001138 @Override
1139 public boolean onQueryTextChange(String newText) {
1140 mSearchQuery = newText;
Fabrice Di Meglio7e4855e2014-05-23 16:03:43 -07001141 if (mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001142 return false;
1143 }
1144 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001145 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001146
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001147 @Override
1148 public boolean onClose() {
1149 return false;
1150 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001151
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001152 @Override
1153 public boolean onMenuItemActionExpand(MenuItem item) {
1154 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001155 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001156 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001157 return true;
1158 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001159
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001160 @Override
1161 public boolean onMenuItemActionCollapse(MenuItem item) {
1162 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001163 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001164 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001165 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001166 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001167 return true;
1168 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001169
Jason Monk4da79e02015-09-10 10:54:36 -04001170 @Override
Jason Monkd4f03ec2016-01-07 16:25:34 -05001171 protected void onTileClicked(Tile tile) {
Jason Monk4da79e02015-09-10 10:54:36 -04001172 if (mIsShowingDashboard) {
1173 // If on dashboard, don't finish so the back comes back to here.
1174 openTile(tile);
1175 } else {
1176 super.onTileClicked(tile);
1177 }
1178 }
1179
Jason Monkaf001092015-11-04 13:16:18 -05001180 @Override
1181 public void onProfileTileOpen() {
1182 if (!mIsShowingDashboard) {
1183 finish();
1184 }
1185 }
1186
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001187 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001188 if (mSearchResultsFragment != null) {
1189 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001190 }
Anna Galusza2f1c1132016-03-04 18:41:35 -08001191 Fragment current = getFragmentManager().findFragmentById(mMainContentId);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001192 if (current != null && current instanceof SearchResultsSummary) {
1193 mSearchResultsFragment = (SearchResultsSummary) current;
1194 } else {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001195 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001196 SearchResultsSummary.class.getName(), null, false, true,
1197 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001198 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001199 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001200 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001201 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001202
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001203 public void needToRevertToInitialFragment() {
1204 mNeedToRevertToInitialFragment = true;
1205 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001206
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001207 private void revertToInitialFragment() {
1208 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001209 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001210 mSearchMenuItemExpanded = false;
1211 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1212 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001213 if (mSearchMenuItem != null) {
1214 mSearchMenuItem.collapseActionView();
1215 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001216 }
Jim Miller0698a212014-10-16 19:49:07 -07001217
1218 public Intent getResultIntentData() {
1219 return mResultIntentData;
1220 }
1221
1222 public void setResultIntentData(Intent resultIntentData) {
1223 mResultIntentData = resultIntentData;
1224 }
Jason Monkd4f03ec2016-01-07 16:25:34 -05001225
1226 public void startSuggestion(Intent intent) {
1227 mCurrentSuggestion = intent.getComponent();
1228 startActivityForResult(intent, REQUEST_SUGGESTION);
1229 }
1230
1231 @Override
1232 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
1233 if (requestCode == REQUEST_SUGGESTION && mCurrentSuggestion != null
1234 && resultCode != RESULT_CANCELED) {
1235 getPackageManager().setComponentEnabledSetting(mCurrentSuggestion,
1236 PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
1237 }
1238 super.onActivityResult(requestCode, resultCode, data);
1239 }
1240
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001241}