blob: dc134ff4a32b09a327b51f3b969517fc4c545a33 [file] [log] [blame]
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.settings;
18
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080019import android.app.ActionBar;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080020import android.app.Fragment;
21import android.app.FragmentManager;
22import android.app.FragmentTransaction;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080023import android.content.BroadcastReceiver;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070024import android.content.ComponentName;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080025import android.content.Context;
26import android.content.Intent;
27import android.content.IntentFilter;
28import android.content.SharedPreferences;
29import android.content.pm.ActivityInfo;
30import android.content.pm.PackageManager;
31import android.content.pm.PackageManager.NameNotFoundException;
32import android.content.pm.ResolveInfo;
33import android.content.res.Configuration;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080034import android.nfc.NfcAdapter;
Jason Monkfd2c7222015-12-02 15:38:38 -050035import android.os.AsyncTask;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080036import android.os.Bundle;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080037import android.os.UserHandle;
38import android.os.UserManager;
Jason Monk39b46742015-09-10 15:52:51 -040039import android.support.v14.preference.PreferenceFragment;
40import android.support.v7.preference.Preference;
41import android.support.v7.preference.PreferenceManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080042import android.text.TextUtils;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070043import android.transition.TransitionManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080044import android.util.Log;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070045import android.view.Menu;
46import android.view.MenuInflater;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080047import android.view.MenuItem;
48import android.view.View;
49import android.view.View.OnClickListener;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070050import android.view.ViewGroup;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080051import android.widget.Button;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070052import android.widget.SearchView;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080053import com.android.internal.util.ArrayUtils;
Jason Monk4da79e02015-09-10 10:54:36 -040054import com.android.settings.Settings.WifiSettingsActivity;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080055import com.android.settings.accessibility.AccessibilitySettings;
Anna Galuszab1795f52016-01-08 14:37:16 -080056import com.android.settings.accessibility.AccessibilitySettingsForSetupWizard;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080057import com.android.settings.accessibility.CaptionPropertiesFragment;
Alexandra Gherghina6d839872014-07-22 12:04:58 +000058import com.android.settings.accounts.AccountSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080059import com.android.settings.accounts.AccountSyncSettings;
Billy Laufee78562015-07-27 12:57:07 +010060import com.android.settings.applications.DrawOverlayDetails;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070061import com.android.settings.applications.InstalledAppDetails;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080062import com.android.settings.applications.ManageApplications;
Xiyuan Xia86a55402015-06-02 14:55:32 -070063import com.android.settings.applications.ManageAssist;
Julia Reynolds2e1e0b72015-12-14 08:32:46 -050064import com.android.settings.applications.ManageDefaultApps;
Jason Monk2cdafc62015-06-12 12:32:50 -040065import com.android.settings.applications.ProcessStatsSummary;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080066import com.android.settings.applications.ProcessStatsUi;
Jason Monkd8da51c2015-04-17 14:34:12 -040067import com.android.settings.applications.UsageAccessDetails;
Billy Laufee78562015-07-27 12:57:07 +010068import com.android.settings.applications.WriteSettingsDetails;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080069import com.android.settings.bluetooth.BluetoothSettings;
70import com.android.settings.dashboard.DashboardSummary;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070071import com.android.settings.dashboard.SearchResultsSummary;
Jason Monkb37e2882016-01-11 14:27:20 -050072import com.android.settings.datausage.DataUsageSummary;
Jeff Sharkeya16257d2015-04-28 13:41:01 -070073import com.android.settings.deviceinfo.PrivateVolumeForget;
Jeff Sharkeye77f0682015-04-29 11:24:57 -070074import com.android.settings.deviceinfo.PrivateVolumeSettings;
Jeff Sharkey42833b22015-04-11 21:27:33 -070075import com.android.settings.deviceinfo.PublicVolumeSettings;
76import com.android.settings.deviceinfo.StorageSettings;
John Spurlockc7f8e8c2014-06-04 19:11:22 -040077import com.android.settings.fuelgauge.BatterySaverSettings;
Jason Monk1eb54eb2015-04-29 12:46:42 -040078import com.android.settings.fuelgauge.PowerUsageDetail;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080079import com.android.settings.fuelgauge.PowerUsageSummary;
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;
83import com.android.settings.inputmethod.SpellCheckersSettings;
84import com.android.settings.inputmethod.UserDictionaryList;
Mihai Nitad7d48fd2016-01-12 08:55:05 -080085import com.android.settings.localepicker.LocaleListEditor;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080086import com.android.settings.location.LocationSettings;
87import com.android.settings.nfc.AndroidBeam;
88import com.android.settings.nfc.PaymentSettings;
John Spurlock802ddf92014-07-18 11:51:13 -040089import com.android.settings.notification.AppNotificationSettings;
Julia Reynolds8c0a4232015-11-24 10:08:14 -050090import com.android.settings.notification.ConfigureNotificationSettings;
John Spurlock4a350512014-04-08 14:08:21 -040091import com.android.settings.notification.NotificationAccessSettings;
John Spurlock4a350512014-04-08 14:08:21 -040092import com.android.settings.notification.NotificationStation;
Jason Monk2ebc8a02015-02-13 15:23:19 -050093import com.android.settings.notification.OtherSoundSettings;
Jason Monkb37e2882016-01-11 14:27:20 -050094import com.android.settings.notification.SoundSettings;
John Spurlock08531a82015-05-07 17:45:43 -040095import com.android.settings.notification.ZenAccessSettings;
John Spurlock533a5662015-06-19 10:47:36 -040096import com.android.settings.notification.ZenModeAutomationSettings;
John Spurlockf57bad72015-04-30 09:26:15 -040097import com.android.settings.notification.ZenModeEventRuleSettings;
John Spurlockc1df2aa2015-04-13 20:57:06 -040098import com.android.settings.notification.ZenModePrioritySettings;
John Spurlock45fa1402015-04-09 12:50:04 -040099import com.android.settings.notification.ZenModeScheduleRuleSettings;
Jason Monk39b46742015-09-10 15:52:51 -0400100import com.android.settings.notification.ZenModeSettings;
Julia Reynolds5555d262015-11-09 10:52:17 -0500101import com.android.settings.notification.ZenModeVisualInterruptionSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800102import com.android.settings.print.PrintJobSettingsFragment;
103import com.android.settings.print.PrintSettingsFragment;
Jason Monk2ebc8a02015-02-13 15:23:19 -0500104import com.android.settings.search.DynamicIndexableContentMonitor;
105import com.android.settings.search.Index;
PauloftheWest38155612014-06-30 10:02:36 -0700106import com.android.settings.sim.SimSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800107import com.android.settings.tts.TextToSpeechSettings;
108import com.android.settings.users.UserSettings;
109import com.android.settings.vpn2.VpnSettings;
110import com.android.settings.wfd.WifiDisplaySettings;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700111import com.android.settings.widget.SwitchBar;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800112import com.android.settings.wifi.AdvancedWifiSettings;
PauloftheWest7837b992014-06-24 07:42:27 -0700113import com.android.settings.wifi.SavedAccessPointsWifiSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800114import com.android.settings.wifi.WifiSettings;
115import com.android.settings.wifi.p2p.WifiP2pSettings;
Jason Monk4da79e02015-09-10 10:54:36 -0400116import com.android.settingslib.drawer.DashboardCategory;
Jason Monkd4f03ec2016-01-07 16:25:34 -0500117import com.android.settingslib.drawer.Tile;
Jason Monk4da79e02015-09-10 10:54:36 -0400118import com.android.settingslib.drawer.SettingsDrawerActivity;
Jason Monk2ebc8a02015-02-13 15:23:19 -0500119
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800120import java.util.ArrayList;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800121import java.util.List;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700122import java.util.Set;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800123
Jason Monk4da79e02015-09-10 10:54:36 -0400124public class SettingsActivity extends SettingsDrawerActivity
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800125 implements PreferenceManager.OnPreferenceTreeClickListener,
126 PreferenceFragment.OnPreferenceStartFragmentCallback,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100127 ButtonBarHandler, FragmentManager.OnBackStackChangedListener,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700128 SearchView.OnQueryTextListener, SearchView.OnCloseListener,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100129 MenuItem.OnActionExpandListener {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800130
131 private static final String LOG_TAG = "Settings";
132
133 // Constants for state save/restore
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700134 private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700135 private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
136 private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700137 private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700138 private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700139 private static final String SAVE_KEY_HOME_ACTIVITIES_COUNT = ":settings:home_activities_count";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800140
141 /**
142 * When starting this activity, the invoking Intent can contain this extra
143 * string to specify which fragment should be initially displayed.
144 * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
145 * will call isValidFragment() to confirm that the fragment class name is valid for this
146 * activity.
147 */
148 public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
149
150 /**
151 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
152 * this extra can also be specified to supply a Bundle of arguments to pass
153 * to that fragment when it is instantiated during the initial creation
154 * of the activity.
155 */
156 public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
157
158 /**
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700159 * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
160 */
161 public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
162
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800163 public static final String BACK_STACK_PREFS = ":settings:prefs";
164
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800165 // extras that allow any preference activity to be launched as part of a wizard
166
167 // show Back and Next buttons? takes boolean parameter
168 // Back will then return RESULT_CANCELED and Next RESULT_OK
169 protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
170
171 // add a Skip button?
172 private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
173
174 // specify custom text for the Back or Next buttons, or cause a button to not appear
175 // at all by setting it to null
176 protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
177 protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
178
179 /**
180 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700181 * 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 -0800182 * that fragment.
183 */
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700184 public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100185 /**
186 * The package name used to resolve the title resource id.
187 */
188 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
189 ":settings:show_fragment_title_res_package_name";
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700190 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
191 ":settings:show_fragment_title_resid";
192 public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
193 ":settings:show_fragment_as_shortcut";
194
195 public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
196 ":settings:show_fragment_as_subsetting";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800197
Jason Monk30695812015-11-17 09:01:08 -0500198 public static final String META_DATA_KEY_FRAGMENT_CLASS =
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800199 "com.android.settings.FRAGMENT_CLASS";
200
201 private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
202
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700203 private static final String EMPTY_QUERY = "";
204
Jason Monkd4f03ec2016-01-07 16:25:34 -0500205 private static final int REQUEST_SUGGESTION = 42;
206
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800207 private String mFragmentClass;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800208
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800209 private CharSequence mInitialTitle;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700210 private int mInitialTitleResId;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800211
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800212 // Show only these settings for restricted users
Jason Monk4da79e02015-09-10 10:54:36 -0400213 private String[] SETTINGS_FOR_RESTRICTED = {
214 //wireless_section
215 WifiSettingsActivity.class.getName(),
216 Settings.BluetoothSettingsActivity.class.getName(),
217 Settings.DataUsageSummaryActivity.class.getName(),
218 Settings.SimSettingsActivity.class.getName(),
219 Settings.WirelessSettingsActivity.class.getName(),
220 //device_section
221 Settings.HomeSettingsActivity.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500222 Settings.SoundSettingsActivity.class.getName(),
Jason Monk4da79e02015-09-10 10:54:36 -0400223 Settings.DisplaySettingsActivity.class.getName(),
224 Settings.StorageSettingsActivity.class.getName(),
225 Settings.ManageApplicationsActivity.class.getName(),
226 Settings.PowerUsageSummaryActivity.class.getName(),
227 //personal_section
228 Settings.LocationSettingsActivity.class.getName(),
229 Settings.SecuritySettingsActivity.class.getName(),
230 Settings.InputMethodAndLanguageSettingsActivity.class.getName(),
231 Settings.UserSettingsActivity.class.getName(),
232 Settings.AccountSettingsActivity.class.getName(),
233 //system_section
234 Settings.DateTimeSettingsActivity.class.getName(),
235 Settings.DeviceInfoSettingsActivity.class.getName(),
236 Settings.AccessibilitySettingsActivity.class.getName(),
237 Settings.PrintSettingsActivity.class.getName(),
238 Settings.PaymentSettingsActivity.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800239 };
240
241 private static final String[] ENTRY_FRAGMENTS = {
242 WirelessSettings.class.getName(),
243 WifiSettings.class.getName(),
244 AdvancedWifiSettings.class.getName(),
PauloftheWest7837b992014-06-24 07:42:27 -0700245 SavedAccessPointsWifiSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800246 BluetoothSettings.class.getName(),
PauloftheWest38155612014-06-30 10:02:36 -0700247 SimSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800248 TetherSettings.class.getName(),
249 WifiP2pSettings.class.getName(),
250 VpnSettings.class.getName(),
251 DateTimeSettings.class.getName(),
Mihai Nitad7d48fd2016-01-12 08:55:05 -0800252 LocaleListEditor.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800253 InputMethodAndLanguageSettings.class.getName(),
Abodunrinwa Toki976bb3f2016-01-20 18:43:20 +0000254 AvailableVirtualKeyboardFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800255 SpellCheckersSettings.class.getName(),
256 UserDictionaryList.class.getName(),
257 UserDictionarySettings.class.getName(),
Amith Yamasani3033ce02014-07-14 18:03:15 -0700258 HomeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800259 DisplaySettings.class.getName(),
260 DeviceInfoSettings.class.getName(),
261 ManageApplications.class.getName(),
Xiyuan Xia86a55402015-06-02 14:55:32 -0700262 ManageAssist.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800263 ProcessStatsUi.class.getName(),
264 NotificationStation.class.getName(),
265 LocationSettings.class.getName(),
266 SecuritySettings.class.getName(),
Jason Monkd8da51c2015-04-17 14:34:12 -0400267 UsageAccessDetails.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800268 PrivacySettings.class.getName(),
269 DeviceAdminSettings.class.getName(),
270 AccessibilitySettings.class.getName(),
Anna Galuszab1795f52016-01-08 14:37:16 -0800271 AccessibilitySettingsForSetupWizard.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800272 CaptionPropertiesFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800273 com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(),
274 TextToSpeechSettings.class.getName(),
Jeff Sharkey42833b22015-04-11 21:27:33 -0700275 StorageSettings.class.getName(),
Jeff Sharkeya16257d2015-04-28 13:41:01 -0700276 PrivateVolumeForget.class.getName(),
Jeff Sharkeye77f0682015-04-29 11:24:57 -0700277 PrivateVolumeSettings.class.getName(),
278 PublicVolumeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800279 DevelopmentSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800280 AndroidBeam.class.getName(),
281 WifiDisplaySettings.class.getName(),
282 PowerUsageSummary.class.getName(),
283 AccountSyncSettings.class.getName(),
Alexandra Gherghina6d839872014-07-22 12:04:58 +0000284 AccountSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800285 CryptKeeperSettings.class.getName(),
286 DataUsageSummary.class.getName(),
287 DreamSettings.class.getName(),
288 UserSettings.class.getName(),
289 NotificationAccessSettings.class.getName(),
John Spurlock08531a82015-05-07 17:45:43 -0400290 ZenAccessSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800291 PrintSettingsFragment.class.getName(),
292 PrintJobSettingsFragment.class.getName(),
293 TrustedCredentialsSettings.class.getName(),
294 PaymentSettings.class.getName(),
295 KeyboardLayoutPickerFragment.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700296 ZenModeSettings.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500297 SoundSettings.class.getName(),
298 ConfigureNotificationSettings.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700299 ChooseLockPassword.ChooseLockPasswordFragment.class.getName(),
300 ChooseLockPattern.ChooseLockPatternFragment.class.getName(),
John Spurlockc7f8e8c2014-06-04 19:11:22 -0400301 InstalledAppDetails.class.getName(),
302 BatterySaverSettings.class.getName(),
Fabrice Di Megliodcf59dd2014-07-21 11:22:20 -0700303 AppNotificationSettings.class.getName(),
Fabrice Di Meglioe3ff4d82014-07-23 20:03:20 -0700304 OtherSoundSettings.class.getName(),
Narayan Kamath33acb152015-03-16 12:48:05 +0000305 ApnSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400306 WifiCallingSettings.class.getName(),
John Spurlockc1df2aa2015-04-13 20:57:06 -0400307 ZenModePrioritySettings.class.getName(),
John Spurlock533a5662015-06-19 10:47:36 -0400308 ZenModeAutomationSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400309 ZenModeScheduleRuleSettings.class.getName(),
John Spurlockf57bad72015-04-30 09:26:15 -0400310 ZenModeEventRuleSettings.class.getName(),
Julia Reynolds5555d262015-11-09 10:52:17 -0500311 ZenModeVisualInterruptionSettings.class.getName(),
Jason Monk2583fc12015-03-25 09:46:30 -0400312 ProcessStatsUi.class.getName(),
Jason Monk1eb54eb2015-04-29 12:46:42 -0400313 PowerUsageDetail.class.getName(),
Jason Monk2cdafc62015-06-12 12:32:50 -0400314 ProcessStatsSummary.class.getName(),
Billy Laufee78562015-07-27 12:57:07 +0100315 DrawOverlayDetails.class.getName(),
316 WriteSettingsDetails.class.getName(),
Julia Reynolds2e1e0b72015-12-14 08:32:46 -0500317 ManageDefaultApps.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800318 };
319
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700320
321 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
322 "android.settings.APPLICATION_DETAILS_SETTINGS"
323 };
324
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800325 private SharedPreferences mDevelopmentPreferences;
326 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
327
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800328 private boolean mBatteryPresent = true;
329 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800330 @Override
331 public void onReceive(Context context, Intent intent) {
332 String action = intent.getAction();
333 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
334 boolean batteryPresent = Utils.isBatteryPresent(intent);
335
336 if (mBatteryPresent != batteryPresent) {
337 mBatteryPresent = batteryPresent;
Jason Monk4da79e02015-09-10 10:54:36 -0400338 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800339 }
340 }
341 }
342 };
343
Clara Bayarri6934a042015-10-14 11:07:35 +0100344 private final BroadcastReceiver mUserAddRemoveReceiver = new BroadcastReceiver() {
345 @Override
346 public void onReceive(Context context, Intent intent) {
347 String action = intent.getAction();
348 if (action.equals(Intent.ACTION_USER_ADDED)
349 || action.equals(Intent.ACTION_USER_REMOVED)) {
350 Index.getInstance(getApplicationContext()).update();
351 }
352 }
353 };
354
Svetoslav990159a2014-04-14 17:14:59 -0700355 private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor =
356 new DynamicIndexableContentMonitor();
Svetoslav853e4712014-04-14 10:10:25 -0700357
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700358 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700359 private SwitchBar mSwitchBar;
360
361 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700362
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700363 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700364 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700365
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700366 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700367 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700368
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700369 private ViewGroup mContent;
370
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700371 private SearchView mSearchView;
372 private MenuItem mSearchMenuItem;
373 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700374 private SearchResultsSummary mSearchResultsFragment;
375 private String mSearchQuery;
376
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700377 // Categories
378 private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800379
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700380 private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800381
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700382 private boolean mNeedToRevertToInitialFragment = false;
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700383 private int mHomeActivitiesCount = 1;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700384
Jim Miller0698a212014-10-16 19:49:07 -0700385 private Intent mResultIntentData;
Jason Monkd4f03ec2016-01-07 16:25:34 -0500386 private ComponentName mCurrentSuggestion;
Jim Miller0698a212014-10-16 19:49:07 -0700387
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700388 public SwitchBar getSwitchBar() {
389 return mSwitchBar;
390 }
391
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800392 @Override
393 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
394 // Override the fragment title for Wallpaper settings
Jason Monk39b46742015-09-10 15:52:51 -0400395 CharSequence title = pref.getTitle();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800396 if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) {
Jason Monk39b46742015-09-10 15:52:51 -0400397 title = getString(R.string.wallpaper_settings_fragment_title);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800398 }
Jason Monkb1dd5c92015-12-16 16:13:54 -0500399 startPreferencePanel(pref.getFragment(), pref.getExtras(), -1, title,
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800400 null, 0);
401 return true;
402 }
403
404 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400405 public boolean onPreferenceTreeClick(Preference preference) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800406 return false;
407 }
408
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800409 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800410 public void onConfigurationChanged(Configuration newConfig) {
411 super.onConfigurationChanged(newConfig);
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800412 Index.getInstance(this).update();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800413 }
414
415 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700416 protected void onStart() {
417 super.onStart();
418
419 if (mNeedToRevertToInitialFragment) {
420 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800421 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800422 }
423
424 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700425 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700426 if (!mDisplaySearch) {
427 return false;
428 }
429
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700430 MenuInflater inflater = getMenuInflater();
431 inflater.inflate(R.menu.options_menu, menu);
432
433 // Cache the search query (can be overriden by the OnQueryTextListener)
434 final String query = mSearchQuery;
435
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700436 mSearchMenuItem = menu.findItem(R.id.search);
437 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700438
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700439 if (mSearchMenuItem == null || mSearchView == null) {
440 return false;
441 }
442
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700443 if (mSearchResultsFragment != null) {
444 mSearchResultsFragment.setSearchView(mSearchView);
445 }
446
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700447 mSearchMenuItem.setOnActionExpandListener(this);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700448 mSearchView.setOnQueryTextListener(this);
449 mSearchView.setOnCloseListener(this);
450
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700451 if (mSearchMenuItemExpanded) {
452 mSearchMenuItem.expandActionView();
453 }
454 mSearchView.setQuery(query, true /* submit */);
455
456 return true;
457 }
458
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700459 private static boolean isShortCutIntent(final Intent intent) {
460 Set<String> categories = intent.getCategories();
461 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
462 }
463
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700464 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700465 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700466 if (action == null) {
467 return false;
468 }
469 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
470 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
471 }
472 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700473 }
474
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700475 @Override
476 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700477 super.onCreate(savedState);
Jason Monkfd2c7222015-12-02 15:38:38 -0500478 long startTime = System.currentTimeMillis();
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700479
480 // Should happen before any call to getIntent()
481 getMetaData();
482
483 final Intent intent = getIntent();
484 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
485 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800486 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800487
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800488 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
489 Context.MODE_PRIVATE);
490
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700491 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700492 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700493
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700494 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700495 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
496
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700497 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700498 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700499
Jason Monk4da79e02015-09-10 10:54:36 -0400500 mIsShowingDashboard = className.equals(Settings.class.getName())
501 || className.equals(Settings.WirelessSettings.class.getName())
502 || className.equals(Settings.DeviceSettings.class.getName())
503 || className.equals(Settings.PersonalSettings.class.getName())
504 || className.equals(Settings.WirelessSettings.class.getName());
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700505
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700506 // This is a "Sub Settings" when:
507 // - this is a real SubSettings
508 // - or :settings:show_fragment_as_subsetting is passed to the Intent
Jorim Jaggi4dfcb822015-04-29 17:21:32 -0700509 final boolean isSubSettings = this instanceof SubSettings ||
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700510 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
511
512 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
513 if (isSubSettings) {
Fabrice Di Meglio712df6c2014-07-18 17:44:37 -0700514 // Check also that we are not a Theme Dialog as we don't want to override them
515 final int themeResId = getThemeResId();
516 if (themeResId != R.style.Theme_DialogWhenLarge &&
517 themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
518 setTheme(R.style.Theme_SubSettings);
519 }
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700520 }
521
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700522 setContentView(mIsShowingDashboard ?
523 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800524
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700525 mContent = (ViewGroup) findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700526
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800527 getFragmentManager().addOnBackStackChangedListener(this);
528
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700529 if (mIsShowingDashboard) {
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800530 // Run the Index update only if we have some space
531 if (!Utils.isLowStorage(this)) {
Jason Monkfd2c7222015-12-02 15:38:38 -0500532 long indexStartTime = System.currentTimeMillis();
533 AsyncTask.execute(new Runnable() {
534 @Override
535 public void run() {
536 Index.getInstance(getApplicationContext()).update();
537 }
538 });
539 if (DEBUG_TIMING) Log.d(LOG_TAG, "Index.update() took "
540 + (System.currentTimeMillis() - indexStartTime) + " ms");
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800541 } else {
542 Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
543 }
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700544 }
545
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700546 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700547 // We are restarting from a previous saved state; used that to initialize, instead
548 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700549 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
550 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800551
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700552 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800553
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700554 ArrayList<DashboardCategory> categories =
555 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
556 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700557 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700558 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700559 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800560 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700561
562 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700563 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700564 mHomeActivitiesCount = savedState.getInt(SAVE_KEY_HOME_ACTIVITIES_COUNT,
565 1 /* one home activity by default */);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800566 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700567 if (!mIsShowingDashboard) {
Jason Monkea8b1a72015-06-02 16:46:34 -0400568 mDisplaySearch = false;
569 // UP will be shown only if it is a sub settings
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700570 if (mIsShortcut) {
571 mDisplayHomeAsUpEnabled = isSubSettings;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700572 } else if (isSubSettings) {
573 mDisplayHomeAsUpEnabled = true;
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700574 } else {
575 mDisplayHomeAsUpEnabled = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700576 }
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700577 setTitleFromIntent(intent);
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700578
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700579 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700580 switchToFragment(initialFragmentName, initialArguments, true, false,
581 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000582 } else {
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700583 // No UP affordance if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700584 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700585 // Show Search affordance
586 mDisplaySearch = true;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700587 mInitialTitleResId = R.string.dashboard_title;
Fabrice Di Meglio42c4b0a2014-05-22 10:30:03 -0700588 switchToFragment(DashboardSummary.class.getName(), null, false, false,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700589 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800590 }
591 }
592
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700593 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700594 if (mActionBar != null) {
595 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
596 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
597 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700598 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
599
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800600 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800601 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
602
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700603 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800604 if (buttonBar != null) {
605 buttonBar.setVisibility(View.VISIBLE);
606
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700607 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800608 backButton.setOnClickListener(new OnClickListener() {
609 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700610 setResult(RESULT_CANCELED, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800611 finish();
612 }
613 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700614 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800615 skipButton.setOnClickListener(new OnClickListener() {
616 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700617 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800618 finish();
619 }
620 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700621 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800622 mNextButton.setOnClickListener(new OnClickListener() {
623 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700624 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800625 finish();
626 }
627 });
628
629 // set our various button parameters
630 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
631 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
632 if (TextUtils.isEmpty(buttonText)) {
633 mNextButton.setVisibility(View.GONE);
634 }
635 else {
636 mNextButton.setText(buttonText);
637 }
638 }
639 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
640 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
641 if (TextUtils.isEmpty(buttonText)) {
642 backButton.setVisibility(View.GONE);
643 }
644 else {
645 backButton.setText(buttonText);
646 }
647 }
648 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
649 skipButton.setVisibility(View.VISIBLE);
650 }
651 }
652 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700653
654 mHomeActivitiesCount = getHomeActivitiesCount();
Jason Monkfd2c7222015-12-02 15:38:38 -0500655 if (DEBUG_TIMING) Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
656 + " ms");
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700657 }
658
659 private int getHomeActivitiesCount() {
660 final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>();
661 getPackageManager().getHomeActivities(homeApps);
662 return homeApps.size();
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800663 }
664
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700665 private void setTitleFromIntent(Intent intent) {
666 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
667 if (initialTitleResId > 0) {
668 mInitialTitle = null;
669 mInitialTitleResId = initialTitleResId;
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100670
671 final String initialTitleResPackageName = intent.getStringExtra(
672 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
673 if (initialTitleResPackageName != null) {
674 try {
675 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
676 0 /* flags */, new UserHandle(UserHandle.myUserId()));
677 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
678 setTitle(mInitialTitle);
679 mInitialTitleResId = -1;
680 return;
681 } catch (NameNotFoundException e) {
682 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
683 }
684 } else {
685 setTitle(mInitialTitleResId);
686 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700687 } else {
688 mInitialTitleResId = -1;
689 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
690 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
691 setTitle(mInitialTitle);
692 }
693 }
694
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800695 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800696 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700697 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800698 }
699
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700700 private int setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800701 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700702
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800703 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700704 if (mInitialTitleResId > 0) {
705 setTitle(mInitialTitleResId);
706 } else {
707 setTitle(mInitialTitle);
708 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700709 return 0;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800710 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700711
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800712 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
713 setTitleFromBackStackEntry(bse);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700714
715 return count;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800716 }
717
718 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
719 final CharSequence title;
720 final int titleRes = bse.getBreadCrumbTitleRes();
721 if (titleRes > 0) {
722 title = getText(titleRes);
723 } else {
724 title = bse.getBreadCrumbTitle();
725 }
726 if (title != null) {
727 setTitle(title);
728 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800729 }
730
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800731 @Override
732 protected void onSaveInstanceState(Bundle outState) {
733 super.onSaveInstanceState(outState);
734
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700735 if (mCategories.size() > 0) {
736 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800737 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700738
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700739 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700740 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700741
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700742 if (mDisplaySearch) {
743 // The option menus are created if the ActionBar is visible and they are also created
744 // asynchronously. If you launch Settings with an Intent action like
745 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
746 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
747 // menu item and search view are null.
748 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
749 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700750
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700751 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
752 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
753 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700754
755 outState.putInt(SAVE_KEY_HOME_ACTIVITIES_COUNT, mHomeActivitiesCount);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800756 }
757
758 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400759 protected void onResume() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800760 super.onResume();
761
762 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
763 @Override
764 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Jason Monk4da79e02015-09-10 10:54:36 -0400765 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800766 }
767 };
768 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
769 mDevelopmentPreferencesListener);
770
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800771 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Clara Bayarri6934a042015-10-14 11:07:35 +0100772 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_ADDED));
773 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_REMOVED));
Svetoslav853e4712014-04-14 10:10:25 -0700774
Svetoslav990159a2014-04-14 17:14:59 -0700775 mDynamicIndexableContentMonitor.register(this);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700776
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700777 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700778 onQueryTextSubmit(mSearchQuery);
779 }
Jason Monk4da79e02015-09-10 10:54:36 -0400780 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800781 }
782
783 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400784 protected void onPause() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800785 super.onPause();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800786 unregisterReceiver(mBatteryInfoReceiver);
Clara Bayarri8c9521f2016-01-12 14:10:45 +0000787 unregisterReceiver(mUserAddRemoveReceiver);
Svetoslav990159a2014-04-14 17:14:59 -0700788 mDynamicIndexableContentMonitor.unregister();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800789 }
790
791 @Override
792 public void onDestroy() {
793 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700794
795 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
796 mDevelopmentPreferencesListener);
797 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800798 }
799
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800800 protected boolean isValidFragment(String fragmentName) {
801 // Almost all fragments are wrapped in this,
802 // except for a few that have their own activities.
803 for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
804 if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
805 }
806 return false;
807 }
808
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800809 @Override
810 public Intent getIntent() {
811 Intent superIntent = super.getIntent();
812 String startingFragment = getStartingFragmentClass(superIntent);
813 // This is called from super.onCreate, isMultiPane() is not yet reliable
814 // Do not use onIsHidingHeaders either, which relies itself on this method
815 if (startingFragment != null) {
816 Intent modIntent = new Intent(superIntent);
817 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
818 Bundle args = superIntent.getExtras();
819 if (args != null) {
820 args = new Bundle(args);
821 } else {
822 args = new Bundle();
823 }
824 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100825 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800826 return modIntent;
827 }
828 return superIntent;
829 }
830
831 /**
832 * Checks if the component name in the intent is different from the Settings class and
833 * returns the class name to load as a fragment.
834 */
835 private String getStartingFragmentClass(Intent intent) {
836 if (mFragmentClass != null) return mFragmentClass;
837
838 String intentClass = intent.getComponent().getClassName();
839 if (intentClass.equals(getClass().getName())) return null;
840
841 if ("com.android.settings.ManageApplications".equals(intentClass)
842 || "com.android.settings.RunningServices".equals(intentClass)
843 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
844 // Old names of manage apps.
845 intentClass = com.android.settings.applications.ManageApplications.class.getName();
846 }
847
848 return intentClass;
849 }
850
851 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000852 * Start a new fragment containing a preference panel. If the preferences
853 * are being displayed in multi-pane mode, the given fragment class will
854 * be instantiated and placed in the appropriate pane. If running in
855 * single-pane mode, a new activity will be launched in which to show the
856 * fragment.
857 *
858 * @param fragmentClass Full name of the class implementing the fragment.
859 * @param args Any desired arguments to supply to the fragment.
860 * @param titleRes Optional resource identifier of the title of this
861 * fragment.
862 * @param titleText Optional text of the title of this fragment.
863 * @param resultTo Optional fragment that result data should be sent to.
864 * If non-null, resultTo.onActivityResult() will be called when this
865 * preference panel is done. The launched panel must use
866 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
867 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700868 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000869 */
870 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700871 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700872 String title = null;
873 if (titleRes < 0) {
874 if (titleText != null) {
875 title = titleText.toString();
876 } else {
877 // There not much we can do in that case
878 title = "";
879 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700880 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700881 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700882 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000883 }
884
885 /**
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100886 * Start a new fragment in a new activity containing a preference panel for a given user. If the
887 * preferences are being displayed in multi-pane mode, the given fragment class will be
888 * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
889 * activity will be launched in which to show the fragment.
890 *
891 * @param fragmentClass Full name of the class implementing the fragment.
892 * @param args Any desired arguments to supply to the fragment.
893 * @param titleRes Optional resource identifier of the title of this fragment.
894 * @param titleText Optional text of the title of this fragment.
895 * @param userHandle The user for which the panel has to be started.
896 */
897 public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
898 CharSequence titleText, UserHandle userHandle) {
Lifu Tangd0332852015-04-02 12:05:46 -0700899 // This is a workaround.
900 //
901 // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
902 // starting the fragment could cause a native stack corruption. See b/17523189. However,
903 // adding that flag and start the preference panel with the same UserHandler will make it
904 // impossible to use back button to return to the previous screen. See b/20042570.
905 //
906 // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
907 // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
908 // when we're calling it as the same user.
909 if (userHandle.getIdentifier() == UserHandle.myUserId()) {
910 startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0);
911 } else {
912 String title = null;
913 if (titleRes < 0) {
914 if (titleText != null) {
915 title = titleText.toString();
916 } else {
917 // There not much we can do in that case
918 title = "";
919 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100920 }
Lifu Tangd0332852015-04-02 12:05:46 -0700921 Utils.startWithFragmentAsUser(this, fragmentClass, args,
922 titleRes, title, mIsShortcut, userHandle);
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100923 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100924 }
925
926 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800927 * Called by a preference panel fragment to finish itself.
928 *
929 * @param caller The fragment that is asking to be finished.
930 * @param resultCode Optional result code to send back to the original
931 * launching fragment.
932 * @param resultData Optional result data to send back to the original
933 * launching fragment.
934 */
935 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
936 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700937 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800938 }
939
940 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000941 * Start a new fragment.
942 *
943 * @param fragment The fragment to start
944 * @param push If true, the current fragment will be pushed onto the back stack. If false,
945 * the current fragment will be replaced.
946 */
947 public void startPreferenceFragment(Fragment fragment, boolean push) {
948 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700949 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000950 if (push) {
951 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
952 transaction.addToBackStack(BACK_STACK_PREFS);
953 } else {
954 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
955 }
956 transaction.commitAllowingStateLoss();
957 }
958
959 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700960 * Switch to a specific Fragment with taking care of validation, Title and BackStack
961 */
962 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700963 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700964 if (validate && !isValidFragment(fragmentName)) {
965 throw new IllegalArgumentException("Invalid fragment for this activity: "
966 + fragmentName);
967 }
968 Fragment f = Fragment.instantiate(this, fragmentName, args);
969 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700970 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700971 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700972 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700973 }
974 if (addToBackStack) {
975 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
976 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700977 if (titleResId > 0) {
978 transaction.setBreadCrumbTitle(titleResId);
979 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700980 transaction.setBreadCrumbTitle(title);
981 }
982 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700983 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700984 return f;
985 }
986
Jason Monk4da79e02015-09-10 10:54:36 -0400987 private void updateTilesList() {
Jason Monkfd2c7222015-12-02 15:38:38 -0500988 // Generally the items that are will be changing from these updates will
989 // not be in the top list of tiles, so run it in the background and the
990 // SettingsDrawerActivity will pick up on the updates automatically.
991 AsyncTask.execute(new Runnable() {
992 @Override
993 public void run() {
994 doUpdateTilesList();
995 }
996 });
997 }
998
999 private void doUpdateTilesList() {
Jason Monk4da79e02015-09-10 10:54:36 -04001000 PackageManager pm = getPackageManager();
Xiaohui Chen44879a32015-07-22 13:53:22 -07001001 final UserManager um = UserManager.get(this);
1002 final boolean isAdmin = um.isAdminUser();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001003
Jason Monk4da79e02015-09-10 10:54:36 -04001004 String packageName = getPackageName();
1005 setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()),
1006 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001007
Jason Monk4da79e02015-09-10 10:54:36 -04001008 setTileEnabled(new ComponentName(packageName,
1009 Settings.BluetoothSettingsActivity.class.getName()),
1010 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001011
Jason Monk4da79e02015-09-10 10:54:36 -04001012 setTileEnabled(new ComponentName(packageName,
1013 Settings.DataUsageSummaryActivity.class.getName()),
1014 Utils.isBandwidthControlEnabled(), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001015
Jason Monk4da79e02015-09-10 10:54:36 -04001016 setTileEnabled(new ComponentName(packageName,
1017 Settings.SimSettingsActivity.class.getName()),
1018 Utils.showSimCardTile(this), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001019
Jason Monk4da79e02015-09-10 10:54:36 -04001020 setTileEnabled(new ComponentName(packageName,
1021 Settings.PowerUsageSummaryActivity.class.getName()),
1022 mBatteryPresent, isAdmin, pm);
1023
1024 setTileEnabled(new ComponentName(packageName,
1025 Settings.HomeSettingsActivity.class.getName()),
1026 updateHomeSettingTiles(), isAdmin, pm);
1027
1028 setTileEnabled(new ComponentName(packageName,
1029 Settings.UserSettingsActivity.class.getName()),
1030 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
1031 && !Utils.isMonkeyRunning(), isAdmin, pm);
1032
1033 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
1034 setTileEnabled(new ComponentName(packageName,
1035 Settings.PaymentSettingsActivity.class.getName()),
1036 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
1037 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
1038 && adapter != null && adapter.isEnabled(), isAdmin, pm);
1039
1040 setTileEnabled(new ComponentName(packageName,
1041 Settings.PrintSettingsActivity.class.getName()),
1042 pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin, pm);
1043
1044 final boolean showDev = mDevelopmentPreferences.getBoolean(
1045 DevelopmentSettings.PREF_SHOW,
1046 android.os.Build.TYPE.equals("eng"));
1047 setTileEnabled(new ComponentName(packageName,
1048 Settings.DevelopmentSettingsActivity.class.getName()),
1049 showDev && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES),
1050 isAdmin, pm);
1051
1052 if (UserHandle.MU_ENABLED && !isAdmin) {
1053 // When on restricted users, disable all extra categories (but only the settings ones).
Jason Monkfd2c7222015-12-02 15:38:38 -05001054 List<DashboardCategory> categories = getDashboardCategories();
Jason Monk4da79e02015-09-10 10:54:36 -04001055 for (DashboardCategory category : categories) {
Jason Monkd4f03ec2016-01-07 16:25:34 -05001056 for (Tile tile : category.tiles) {
Jason Monk4da79e02015-09-10 10:54:36 -04001057 ComponentName component = tile.intent.getComponent();
1058 if (packageName.equals(component)&& !ArrayUtils.contains(
1059 SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1060 setTileEnabled(component, false, isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001061 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001062 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001063 }
1064 }
Jason Monk2ebc8a02015-02-13 15:23:19 -05001065 }
1066
Jason Monk4da79e02015-09-10 10:54:36 -04001067 private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin,
1068 PackageManager pm) {
1069 if (UserHandle.MU_ENABLED && !isAdmin
1070 && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1071 enabled = false;
1072 }
1073 int state = pm.getComponentEnabledSetting(component);
1074 boolean isEnabled = state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
1075 || state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
1076 if (isEnabled != enabled) {
1077 pm.setComponentEnabledSetting(component, enabled
1078 ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
1079 : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
1080 PackageManager.DONT_KILL_APP);
Jason Monk2ebc8a02015-02-13 15:23:19 -05001081 }
1082 }
1083
Jason Monk4da79e02015-09-10 10:54:36 -04001084 private boolean updateHomeSettingTiles() {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001085 // Once we decide to show Home settings, keep showing it forever
1086 SharedPreferences sp = getSharedPreferences(HomeSettings.HOME_PREFS, Context.MODE_PRIVATE);
1087 if (sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false)) {
1088 return true;
1089 }
1090
1091 try {
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -07001092 mHomeActivitiesCount = getHomeActivitiesCount();
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -07001093 if (mHomeActivitiesCount < 2) {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001094 return false;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001095 }
1096 } catch (Exception e) {
1097 // Can't look up the home activity; bail on configuring the icon
1098 Log.w(LOG_TAG, "Problem looking up home activity!", e);
1099 }
1100
1101 sp.edit().putBoolean(HomeSettings.HOME_PREFS_DO_SHOW, true).apply();
1102 return true;
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 }
Fabrice Di Megliod40dd452014-07-18 15:20:34 -07001191 Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
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}