blob: 3014225c841648f21e5a32c81896d244ad15c8f4 [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;
56import 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;
Billy Laufee78562015-07-27 12:57:07 +010059import com.android.settings.applications.DrawOverlayDetails;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070060import com.android.settings.applications.InstalledAppDetails;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080061import com.android.settings.applications.ManageApplications;
Xiyuan Xia86a55402015-06-02 14:55:32 -070062import com.android.settings.applications.ManageAssist;
Julia Reynolds2e1e0b72015-12-14 08:32:46 -050063import com.android.settings.applications.ManageDefaultApps;
Jason Monk2cdafc62015-06-12 12:32:50 -040064import com.android.settings.applications.ProcessStatsSummary;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080065import com.android.settings.applications.ProcessStatsUi;
Jason Monkd8da51c2015-04-17 14:34:12 -040066import com.android.settings.applications.UsageAccessDetails;
Billy Laufee78562015-07-27 12:57:07 +010067import com.android.settings.applications.WriteSettingsDetails;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080068import com.android.settings.bluetooth.BluetoothSettings;
69import com.android.settings.dashboard.DashboardSummary;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070070import com.android.settings.dashboard.SearchResultsSummary;
Jeff Sharkeya16257d2015-04-28 13:41:01 -070071import com.android.settings.deviceinfo.PrivateVolumeForget;
Jeff Sharkeye77f0682015-04-29 11:24:57 -070072import com.android.settings.deviceinfo.PrivateVolumeSettings;
Jeff Sharkey42833b22015-04-11 21:27:33 -070073import com.android.settings.deviceinfo.PublicVolumeSettings;
74import com.android.settings.deviceinfo.StorageSettings;
John Spurlockc7f8e8c2014-06-04 19:11:22 -040075import com.android.settings.fuelgauge.BatterySaverSettings;
Jason Monk1eb54eb2015-04-29 12:46:42 -040076import com.android.settings.fuelgauge.PowerUsageDetail;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080077import com.android.settings.fuelgauge.PowerUsageSummary;
78import com.android.settings.inputmethod.InputMethodAndLanguageSettings;
79import com.android.settings.inputmethod.KeyboardLayoutPickerFragment;
80import com.android.settings.inputmethod.SpellCheckersSettings;
81import com.android.settings.inputmethod.UserDictionaryList;
82import com.android.settings.location.LocationSettings;
83import com.android.settings.nfc.AndroidBeam;
84import com.android.settings.nfc.PaymentSettings;
John Spurlock802ddf92014-07-18 11:51:13 -040085import com.android.settings.notification.AppNotificationSettings;
Julia Reynolds8c0a4232015-11-24 10:08:14 -050086import com.android.settings.notification.ConfigureNotificationSettings;
John Spurlock4a350512014-04-08 14:08:21 -040087import com.android.settings.notification.NotificationAccessSettings;
Julia Reynolds8c0a4232015-11-24 10:08:14 -050088import com.android.settings.notification.SoundSettings;
John Spurlock4a350512014-04-08 14:08:21 -040089import com.android.settings.notification.NotificationStation;
Jason Monk2ebc8a02015-02-13 15:23:19 -050090import com.android.settings.notification.OtherSoundSettings;
John Spurlock08531a82015-05-07 17:45:43 -040091import com.android.settings.notification.ZenAccessSettings;
John Spurlock533a5662015-06-19 10:47:36 -040092import com.android.settings.notification.ZenModeAutomationSettings;
John Spurlockf57bad72015-04-30 09:26:15 -040093import com.android.settings.notification.ZenModeEventRuleSettings;
John Spurlockc1df2aa2015-04-13 20:57:06 -040094import com.android.settings.notification.ZenModePrioritySettings;
John Spurlock45fa1402015-04-09 12:50:04 -040095import com.android.settings.notification.ZenModeScheduleRuleSettings;
Jason Monk39b46742015-09-10 15:52:51 -040096import com.android.settings.notification.ZenModeSettings;
Julia Reynolds5555d262015-11-09 10:52:17 -050097import com.android.settings.notification.ZenModeVisualInterruptionSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080098import com.android.settings.print.PrintJobSettingsFragment;
99import com.android.settings.print.PrintSettingsFragment;
Jason Monk2ebc8a02015-02-13 15:23:19 -0500100import com.android.settings.search.DynamicIndexableContentMonitor;
101import com.android.settings.search.Index;
PauloftheWest38155612014-06-30 10:02:36 -0700102import com.android.settings.sim.SimSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800103import com.android.settings.tts.TextToSpeechSettings;
104import com.android.settings.users.UserSettings;
105import com.android.settings.vpn2.VpnSettings;
106import com.android.settings.wfd.WifiDisplaySettings;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700107import com.android.settings.widget.SwitchBar;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800108import com.android.settings.wifi.AdvancedWifiSettings;
PauloftheWest7837b992014-06-24 07:42:27 -0700109import com.android.settings.wifi.SavedAccessPointsWifiSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800110import com.android.settings.wifi.WifiSettings;
111import com.android.settings.wifi.p2p.WifiP2pSettings;
Jason Monk4da79e02015-09-10 10:54:36 -0400112import com.android.settingslib.drawer.DashboardCategory;
Jason Monkd4f03ec2016-01-07 16:25:34 -0500113import com.android.settingslib.drawer.Tile;
Jason Monk4da79e02015-09-10 10:54:36 -0400114import com.android.settingslib.drawer.SettingsDrawerActivity;
Jason Monk2ebc8a02015-02-13 15:23:19 -0500115
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800116import java.util.ArrayList;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800117import java.util.List;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700118import java.util.Set;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800119
Jason Monk4da79e02015-09-10 10:54:36 -0400120public class SettingsActivity extends SettingsDrawerActivity
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800121 implements PreferenceManager.OnPreferenceTreeClickListener,
122 PreferenceFragment.OnPreferenceStartFragmentCallback,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100123 ButtonBarHandler, FragmentManager.OnBackStackChangedListener,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700124 SearchView.OnQueryTextListener, SearchView.OnCloseListener,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100125 MenuItem.OnActionExpandListener {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800126
127 private static final String LOG_TAG = "Settings";
128
129 // Constants for state save/restore
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700130 private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700131 private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
132 private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700133 private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700134 private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700135 private static final String SAVE_KEY_HOME_ACTIVITIES_COUNT = ":settings:home_activities_count";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800136
137 /**
138 * When starting this activity, the invoking Intent can contain this extra
139 * string to specify which fragment should be initially displayed.
140 * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
141 * will call isValidFragment() to confirm that the fragment class name is valid for this
142 * activity.
143 */
144 public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
145
146 /**
147 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
148 * this extra can also be specified to supply a Bundle of arguments to pass
149 * to that fragment when it is instantiated during the initial creation
150 * of the activity.
151 */
152 public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
153
154 /**
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700155 * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
156 */
157 public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
158
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800159 public static final String BACK_STACK_PREFS = ":settings:prefs";
160
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800161 // extras that allow any preference activity to be launched as part of a wizard
162
163 // show Back and Next buttons? takes boolean parameter
164 // Back will then return RESULT_CANCELED and Next RESULT_OK
165 protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
166
167 // add a Skip button?
168 private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
169
170 // specify custom text for the Back or Next buttons, or cause a button to not appear
171 // at all by setting it to null
172 protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
173 protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
174
175 /**
176 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700177 * 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 -0800178 * that fragment.
179 */
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700180 public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100181 /**
182 * The package name used to resolve the title resource id.
183 */
184 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
185 ":settings:show_fragment_title_res_package_name";
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700186 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
187 ":settings:show_fragment_title_resid";
188 public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
189 ":settings:show_fragment_as_shortcut";
190
191 public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
192 ":settings:show_fragment_as_subsetting";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800193
Jason Monk30695812015-11-17 09:01:08 -0500194 public static final String META_DATA_KEY_FRAGMENT_CLASS =
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800195 "com.android.settings.FRAGMENT_CLASS";
196
197 private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
198
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700199 private static final String EMPTY_QUERY = "";
200
Jason Monkd4f03ec2016-01-07 16:25:34 -0500201 private static final int REQUEST_SUGGESTION = 42;
202
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800203 private String mFragmentClass;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800204
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800205 private CharSequence mInitialTitle;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700206 private int mInitialTitleResId;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800207
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800208 // Show only these settings for restricted users
Jason Monk4da79e02015-09-10 10:54:36 -0400209 private String[] SETTINGS_FOR_RESTRICTED = {
210 //wireless_section
211 WifiSettingsActivity.class.getName(),
212 Settings.BluetoothSettingsActivity.class.getName(),
213 Settings.DataUsageSummaryActivity.class.getName(),
214 Settings.SimSettingsActivity.class.getName(),
215 Settings.WirelessSettingsActivity.class.getName(),
216 //device_section
217 Settings.HomeSettingsActivity.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500218 Settings.SoundSettingsActivity.class.getName(),
Jason Monk4da79e02015-09-10 10:54:36 -0400219 Settings.DisplaySettingsActivity.class.getName(),
220 Settings.StorageSettingsActivity.class.getName(),
221 Settings.ManageApplicationsActivity.class.getName(),
222 Settings.PowerUsageSummaryActivity.class.getName(),
223 //personal_section
224 Settings.LocationSettingsActivity.class.getName(),
225 Settings.SecuritySettingsActivity.class.getName(),
226 Settings.InputMethodAndLanguageSettingsActivity.class.getName(),
227 Settings.UserSettingsActivity.class.getName(),
228 Settings.AccountSettingsActivity.class.getName(),
229 //system_section
230 Settings.DateTimeSettingsActivity.class.getName(),
231 Settings.DeviceInfoSettingsActivity.class.getName(),
232 Settings.AccessibilitySettingsActivity.class.getName(),
233 Settings.PrintSettingsActivity.class.getName(),
234 Settings.PaymentSettingsActivity.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800235 };
236
237 private static final String[] ENTRY_FRAGMENTS = {
238 WirelessSettings.class.getName(),
239 WifiSettings.class.getName(),
240 AdvancedWifiSettings.class.getName(),
PauloftheWest7837b992014-06-24 07:42:27 -0700241 SavedAccessPointsWifiSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800242 BluetoothSettings.class.getName(),
PauloftheWest38155612014-06-30 10:02:36 -0700243 SimSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800244 TetherSettings.class.getName(),
245 WifiP2pSettings.class.getName(),
246 VpnSettings.class.getName(),
247 DateTimeSettings.class.getName(),
248 LocalePicker.class.getName(),
249 InputMethodAndLanguageSettings.class.getName(),
250 SpellCheckersSettings.class.getName(),
251 UserDictionaryList.class.getName(),
252 UserDictionarySettings.class.getName(),
Amith Yamasani3033ce02014-07-14 18:03:15 -0700253 HomeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800254 DisplaySettings.class.getName(),
255 DeviceInfoSettings.class.getName(),
256 ManageApplications.class.getName(),
Xiyuan Xia86a55402015-06-02 14:55:32 -0700257 ManageAssist.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800258 ProcessStatsUi.class.getName(),
259 NotificationStation.class.getName(),
260 LocationSettings.class.getName(),
261 SecuritySettings.class.getName(),
Jason Monkd8da51c2015-04-17 14:34:12 -0400262 UsageAccessDetails.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800263 PrivacySettings.class.getName(),
264 DeviceAdminSettings.class.getName(),
265 AccessibilitySettings.class.getName(),
266 CaptionPropertiesFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800267 com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(),
268 TextToSpeechSettings.class.getName(),
Jeff Sharkey42833b22015-04-11 21:27:33 -0700269 StorageSettings.class.getName(),
Jeff Sharkeya16257d2015-04-28 13:41:01 -0700270 PrivateVolumeForget.class.getName(),
Jeff Sharkeye77f0682015-04-29 11:24:57 -0700271 PrivateVolumeSettings.class.getName(),
272 PublicVolumeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800273 DevelopmentSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800274 AndroidBeam.class.getName(),
275 WifiDisplaySettings.class.getName(),
276 PowerUsageSummary.class.getName(),
277 AccountSyncSettings.class.getName(),
Alexandra Gherghina6d839872014-07-22 12:04:58 +0000278 AccountSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800279 CryptKeeperSettings.class.getName(),
280 DataUsageSummary.class.getName(),
281 DreamSettings.class.getName(),
282 UserSettings.class.getName(),
283 NotificationAccessSettings.class.getName(),
John Spurlock08531a82015-05-07 17:45:43 -0400284 ZenAccessSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800285 PrintSettingsFragment.class.getName(),
286 PrintJobSettingsFragment.class.getName(),
287 TrustedCredentialsSettings.class.getName(),
288 PaymentSettings.class.getName(),
289 KeyboardLayoutPickerFragment.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700290 ZenModeSettings.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500291 SoundSettings.class.getName(),
292 ConfigureNotificationSettings.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700293 ChooseLockPassword.ChooseLockPasswordFragment.class.getName(),
294 ChooseLockPattern.ChooseLockPatternFragment.class.getName(),
John Spurlockc7f8e8c2014-06-04 19:11:22 -0400295 InstalledAppDetails.class.getName(),
296 BatterySaverSettings.class.getName(),
Fabrice Di Megliodcf59dd2014-07-21 11:22:20 -0700297 AppNotificationSettings.class.getName(),
Fabrice Di Meglioe3ff4d82014-07-23 20:03:20 -0700298 OtherSoundSettings.class.getName(),
Narayan Kamath33acb152015-03-16 12:48:05 +0000299 ApnSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400300 WifiCallingSettings.class.getName(),
John Spurlockc1df2aa2015-04-13 20:57:06 -0400301 ZenModePrioritySettings.class.getName(),
John Spurlock533a5662015-06-19 10:47:36 -0400302 ZenModeAutomationSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400303 ZenModeScheduleRuleSettings.class.getName(),
John Spurlockf57bad72015-04-30 09:26:15 -0400304 ZenModeEventRuleSettings.class.getName(),
Julia Reynolds5555d262015-11-09 10:52:17 -0500305 ZenModeVisualInterruptionSettings.class.getName(),
Jason Monk2583fc12015-03-25 09:46:30 -0400306 ProcessStatsUi.class.getName(),
Jason Monk1eb54eb2015-04-29 12:46:42 -0400307 PowerUsageDetail.class.getName(),
Jason Monk2cdafc62015-06-12 12:32:50 -0400308 ProcessStatsSummary.class.getName(),
Billy Laufee78562015-07-27 12:57:07 +0100309 DrawOverlayDetails.class.getName(),
310 WriteSettingsDetails.class.getName(),
Julia Reynolds2e1e0b72015-12-14 08:32:46 -0500311 ManageDefaultApps.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800312 };
313
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700314
315 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
316 "android.settings.APPLICATION_DETAILS_SETTINGS"
317 };
318
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800319 private SharedPreferences mDevelopmentPreferences;
320 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
321
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800322 private boolean mBatteryPresent = true;
323 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800324 @Override
325 public void onReceive(Context context, Intent intent) {
326 String action = intent.getAction();
327 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
328 boolean batteryPresent = Utils.isBatteryPresent(intent);
329
330 if (mBatteryPresent != batteryPresent) {
331 mBatteryPresent = batteryPresent;
Jason Monk4da79e02015-09-10 10:54:36 -0400332 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800333 }
334 }
335 }
336 };
337
Clara Bayarri6934a042015-10-14 11:07:35 +0100338 private final BroadcastReceiver mUserAddRemoveReceiver = new BroadcastReceiver() {
339 @Override
340 public void onReceive(Context context, Intent intent) {
341 String action = intent.getAction();
342 if (action.equals(Intent.ACTION_USER_ADDED)
343 || action.equals(Intent.ACTION_USER_REMOVED)) {
344 Index.getInstance(getApplicationContext()).update();
345 }
346 }
347 };
348
Svetoslav990159a2014-04-14 17:14:59 -0700349 private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor =
350 new DynamicIndexableContentMonitor();
Svetoslav853e4712014-04-14 10:10:25 -0700351
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700352 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700353 private SwitchBar mSwitchBar;
354
355 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700356
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700357 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700358 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700359
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700360 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700361 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700362
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700363 private ViewGroup mContent;
364
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700365 private SearchView mSearchView;
366 private MenuItem mSearchMenuItem;
367 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700368 private SearchResultsSummary mSearchResultsFragment;
369 private String mSearchQuery;
370
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700371 // Categories
372 private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800373
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700374 private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800375
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700376 private boolean mNeedToRevertToInitialFragment = false;
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700377 private int mHomeActivitiesCount = 1;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700378
Jim Miller0698a212014-10-16 19:49:07 -0700379 private Intent mResultIntentData;
Jason Monkd4f03ec2016-01-07 16:25:34 -0500380 private ComponentName mCurrentSuggestion;
Jim Miller0698a212014-10-16 19:49:07 -0700381
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700382 public SwitchBar getSwitchBar() {
383 return mSwitchBar;
384 }
385
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800386 @Override
387 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
388 // Override the fragment title for Wallpaper settings
Jason Monk39b46742015-09-10 15:52:51 -0400389 CharSequence title = pref.getTitle();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800390 if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) {
Jason Monk39b46742015-09-10 15:52:51 -0400391 title = getString(R.string.wallpaper_settings_fragment_title);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800392 }
Jason Monkb1dd5c92015-12-16 16:13:54 -0500393 startPreferencePanel(pref.getFragment(), pref.getExtras(), -1, title,
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800394 null, 0);
395 return true;
396 }
397
398 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400399 public boolean onPreferenceTreeClick(Preference preference) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800400 return false;
401 }
402
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800403 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800404 public void onConfigurationChanged(Configuration newConfig) {
405 super.onConfigurationChanged(newConfig);
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800406 Index.getInstance(this).update();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800407 }
408
409 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700410 protected void onStart() {
411 super.onStart();
412
413 if (mNeedToRevertToInitialFragment) {
414 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800415 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800416 }
417
418 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700419 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700420 if (!mDisplaySearch) {
421 return false;
422 }
423
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700424 MenuInflater inflater = getMenuInflater();
425 inflater.inflate(R.menu.options_menu, menu);
426
427 // Cache the search query (can be overriden by the OnQueryTextListener)
428 final String query = mSearchQuery;
429
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700430 mSearchMenuItem = menu.findItem(R.id.search);
431 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700432
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700433 if (mSearchMenuItem == null || mSearchView == null) {
434 return false;
435 }
436
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700437 if (mSearchResultsFragment != null) {
438 mSearchResultsFragment.setSearchView(mSearchView);
439 }
440
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700441 mSearchMenuItem.setOnActionExpandListener(this);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700442 mSearchView.setOnQueryTextListener(this);
443 mSearchView.setOnCloseListener(this);
444
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700445 if (mSearchMenuItemExpanded) {
446 mSearchMenuItem.expandActionView();
447 }
448 mSearchView.setQuery(query, true /* submit */);
449
450 return true;
451 }
452
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700453 private static boolean isShortCutIntent(final Intent intent) {
454 Set<String> categories = intent.getCategories();
455 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
456 }
457
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700458 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700459 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700460 if (action == null) {
461 return false;
462 }
463 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
464 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
465 }
466 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700467 }
468
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700469 @Override
470 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700471 super.onCreate(savedState);
Jason Monkfd2c7222015-12-02 15:38:38 -0500472 long startTime = System.currentTimeMillis();
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700473
474 // Should happen before any call to getIntent()
475 getMetaData();
476
477 final Intent intent = getIntent();
478 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
479 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800480 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800481
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800482 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
483 Context.MODE_PRIVATE);
484
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700485 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700486 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700487
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700488 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700489 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
490
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700491 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700492 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700493
Jason Monk4da79e02015-09-10 10:54:36 -0400494 mIsShowingDashboard = className.equals(Settings.class.getName())
495 || className.equals(Settings.WirelessSettings.class.getName())
496 || className.equals(Settings.DeviceSettings.class.getName())
497 || className.equals(Settings.PersonalSettings.class.getName())
498 || className.equals(Settings.WirelessSettings.class.getName());
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700499
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700500 // This is a "Sub Settings" when:
501 // - this is a real SubSettings
502 // - or :settings:show_fragment_as_subsetting is passed to the Intent
Jorim Jaggi4dfcb822015-04-29 17:21:32 -0700503 final boolean isSubSettings = this instanceof SubSettings ||
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700504 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
505
506 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
507 if (isSubSettings) {
Fabrice Di Meglio712df6c2014-07-18 17:44:37 -0700508 // Check also that we are not a Theme Dialog as we don't want to override them
509 final int themeResId = getThemeResId();
510 if (themeResId != R.style.Theme_DialogWhenLarge &&
511 themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
512 setTheme(R.style.Theme_SubSettings);
513 }
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700514 }
515
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700516 setContentView(mIsShowingDashboard ?
517 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800518
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700519 mContent = (ViewGroup) findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700520
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800521 getFragmentManager().addOnBackStackChangedListener(this);
522
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700523 if (mIsShowingDashboard) {
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800524 // Run the Index update only if we have some space
525 if (!Utils.isLowStorage(this)) {
Jason Monkfd2c7222015-12-02 15:38:38 -0500526 long indexStartTime = System.currentTimeMillis();
527 AsyncTask.execute(new Runnable() {
528 @Override
529 public void run() {
530 Index.getInstance(getApplicationContext()).update();
531 }
532 });
533 if (DEBUG_TIMING) Log.d(LOG_TAG, "Index.update() took "
534 + (System.currentTimeMillis() - indexStartTime) + " ms");
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800535 } else {
536 Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
537 }
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700538 }
539
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700540 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700541 // We are restarting from a previous saved state; used that to initialize, instead
542 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700543 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
544 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800545
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700546 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800547
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700548 ArrayList<DashboardCategory> categories =
549 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
550 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700551 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700552 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700553 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800554 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700555
556 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700557 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700558 mHomeActivitiesCount = savedState.getInt(SAVE_KEY_HOME_ACTIVITIES_COUNT,
559 1 /* one home activity by default */);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800560 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700561 if (!mIsShowingDashboard) {
Jason Monkea8b1a72015-06-02 16:46:34 -0400562 mDisplaySearch = false;
563 // UP will be shown only if it is a sub settings
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700564 if (mIsShortcut) {
565 mDisplayHomeAsUpEnabled = isSubSettings;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700566 } else if (isSubSettings) {
567 mDisplayHomeAsUpEnabled = true;
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700568 } else {
569 mDisplayHomeAsUpEnabled = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700570 }
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700571 setTitleFromIntent(intent);
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700572
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700573 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700574 switchToFragment(initialFragmentName, initialArguments, true, false,
575 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000576 } else {
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700577 // No UP affordance if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700578 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700579 // Show Search affordance
580 mDisplaySearch = true;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700581 mInitialTitleResId = R.string.dashboard_title;
Fabrice Di Meglio42c4b0a2014-05-22 10:30:03 -0700582 switchToFragment(DashboardSummary.class.getName(), null, false, false,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700583 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800584 }
585 }
586
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700587 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700588 if (mActionBar != null) {
589 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
590 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
591 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700592 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
593
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800594 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800595 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
596
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700597 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800598 if (buttonBar != null) {
599 buttonBar.setVisibility(View.VISIBLE);
600
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700601 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800602 backButton.setOnClickListener(new OnClickListener() {
603 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700604 setResult(RESULT_CANCELED, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800605 finish();
606 }
607 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700608 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800609 skipButton.setOnClickListener(new OnClickListener() {
610 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700611 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800612 finish();
613 }
614 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700615 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800616 mNextButton.setOnClickListener(new OnClickListener() {
617 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700618 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800619 finish();
620 }
621 });
622
623 // set our various button parameters
624 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
625 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
626 if (TextUtils.isEmpty(buttonText)) {
627 mNextButton.setVisibility(View.GONE);
628 }
629 else {
630 mNextButton.setText(buttonText);
631 }
632 }
633 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
634 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
635 if (TextUtils.isEmpty(buttonText)) {
636 backButton.setVisibility(View.GONE);
637 }
638 else {
639 backButton.setText(buttonText);
640 }
641 }
642 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
643 skipButton.setVisibility(View.VISIBLE);
644 }
645 }
646 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700647
648 mHomeActivitiesCount = getHomeActivitiesCount();
Jason Monkfd2c7222015-12-02 15:38:38 -0500649 if (DEBUG_TIMING) Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
650 + " ms");
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700651 }
652
653 private int getHomeActivitiesCount() {
654 final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>();
655 getPackageManager().getHomeActivities(homeApps);
656 return homeApps.size();
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800657 }
658
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700659 private void setTitleFromIntent(Intent intent) {
660 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
661 if (initialTitleResId > 0) {
662 mInitialTitle = null;
663 mInitialTitleResId = initialTitleResId;
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100664
665 final String initialTitleResPackageName = intent.getStringExtra(
666 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
667 if (initialTitleResPackageName != null) {
668 try {
669 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
670 0 /* flags */, new UserHandle(UserHandle.myUserId()));
671 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
672 setTitle(mInitialTitle);
673 mInitialTitleResId = -1;
674 return;
675 } catch (NameNotFoundException e) {
676 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
677 }
678 } else {
679 setTitle(mInitialTitleResId);
680 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700681 } else {
682 mInitialTitleResId = -1;
683 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
684 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
685 setTitle(mInitialTitle);
686 }
687 }
688
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800689 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800690 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700691 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800692 }
693
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700694 private int setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800695 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700696
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800697 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700698 if (mInitialTitleResId > 0) {
699 setTitle(mInitialTitleResId);
700 } else {
701 setTitle(mInitialTitle);
702 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700703 return 0;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800704 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700705
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800706 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
707 setTitleFromBackStackEntry(bse);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700708
709 return count;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800710 }
711
712 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
713 final CharSequence title;
714 final int titleRes = bse.getBreadCrumbTitleRes();
715 if (titleRes > 0) {
716 title = getText(titleRes);
717 } else {
718 title = bse.getBreadCrumbTitle();
719 }
720 if (title != null) {
721 setTitle(title);
722 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800723 }
724
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800725 @Override
726 protected void onSaveInstanceState(Bundle outState) {
727 super.onSaveInstanceState(outState);
728
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700729 if (mCategories.size() > 0) {
730 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800731 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700732
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700733 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700734 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700735
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700736 if (mDisplaySearch) {
737 // The option menus are created if the ActionBar is visible and they are also created
738 // asynchronously. If you launch Settings with an Intent action like
739 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
740 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
741 // menu item and search view are null.
742 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
743 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700744
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700745 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
746 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
747 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700748
749 outState.putInt(SAVE_KEY_HOME_ACTIVITIES_COUNT, mHomeActivitiesCount);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800750 }
751
752 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400753 protected void onResume() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800754 super.onResume();
755
756 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
757 @Override
758 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Jason Monk4da79e02015-09-10 10:54:36 -0400759 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800760 }
761 };
762 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
763 mDevelopmentPreferencesListener);
764
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800765 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Clara Bayarri6934a042015-10-14 11:07:35 +0100766 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_ADDED));
767 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_REMOVED));
Svetoslav853e4712014-04-14 10:10:25 -0700768
Svetoslav990159a2014-04-14 17:14:59 -0700769 mDynamicIndexableContentMonitor.register(this);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700770
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700771 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700772 onQueryTextSubmit(mSearchQuery);
773 }
Jason Monk4da79e02015-09-10 10:54:36 -0400774 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800775 }
776
777 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400778 protected void onPause() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800779 super.onPause();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800780 unregisterReceiver(mBatteryInfoReceiver);
Svetoslav990159a2014-04-14 17:14:59 -0700781 mDynamicIndexableContentMonitor.unregister();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800782 }
783
784 @Override
785 public void onDestroy() {
786 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700787
788 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
789 mDevelopmentPreferencesListener);
790 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800791 }
792
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800793 protected boolean isValidFragment(String fragmentName) {
794 // Almost all fragments are wrapped in this,
795 // except for a few that have their own activities.
796 for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
797 if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
798 }
799 return false;
800 }
801
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800802 @Override
803 public Intent getIntent() {
804 Intent superIntent = super.getIntent();
805 String startingFragment = getStartingFragmentClass(superIntent);
806 // This is called from super.onCreate, isMultiPane() is not yet reliable
807 // Do not use onIsHidingHeaders either, which relies itself on this method
808 if (startingFragment != null) {
809 Intent modIntent = new Intent(superIntent);
810 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
811 Bundle args = superIntent.getExtras();
812 if (args != null) {
813 args = new Bundle(args);
814 } else {
815 args = new Bundle();
816 }
817 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100818 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800819 return modIntent;
820 }
821 return superIntent;
822 }
823
824 /**
825 * Checks if the component name in the intent is different from the Settings class and
826 * returns the class name to load as a fragment.
827 */
828 private String getStartingFragmentClass(Intent intent) {
829 if (mFragmentClass != null) return mFragmentClass;
830
831 String intentClass = intent.getComponent().getClassName();
832 if (intentClass.equals(getClass().getName())) return null;
833
834 if ("com.android.settings.ManageApplications".equals(intentClass)
835 || "com.android.settings.RunningServices".equals(intentClass)
836 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
837 // Old names of manage apps.
838 intentClass = com.android.settings.applications.ManageApplications.class.getName();
839 }
840
841 return intentClass;
842 }
843
844 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000845 * Start a new fragment containing a preference panel. If the preferences
846 * are being displayed in multi-pane mode, the given fragment class will
847 * be instantiated and placed in the appropriate pane. If running in
848 * single-pane mode, a new activity will be launched in which to show the
849 * fragment.
850 *
851 * @param fragmentClass Full name of the class implementing the fragment.
852 * @param args Any desired arguments to supply to the fragment.
853 * @param titleRes Optional resource identifier of the title of this
854 * fragment.
855 * @param titleText Optional text of the title of this fragment.
856 * @param resultTo Optional fragment that result data should be sent to.
857 * If non-null, resultTo.onActivityResult() will be called when this
858 * preference panel is done. The launched panel must use
859 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
860 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700861 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000862 */
863 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700864 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700865 String title = null;
866 if (titleRes < 0) {
867 if (titleText != null) {
868 title = titleText.toString();
869 } else {
870 // There not much we can do in that case
871 title = "";
872 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700873 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700874 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700875 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000876 }
877
878 /**
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100879 * Start a new fragment in a new activity containing a preference panel for a given user. If the
880 * preferences are being displayed in multi-pane mode, the given fragment class will be
881 * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
882 * activity will be launched in which to show the fragment.
883 *
884 * @param fragmentClass Full name of the class implementing the fragment.
885 * @param args Any desired arguments to supply to the fragment.
886 * @param titleRes Optional resource identifier of the title of this fragment.
887 * @param titleText Optional text of the title of this fragment.
888 * @param userHandle The user for which the panel has to be started.
889 */
890 public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
891 CharSequence titleText, UserHandle userHandle) {
Lifu Tangd0332852015-04-02 12:05:46 -0700892 // This is a workaround.
893 //
894 // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
895 // starting the fragment could cause a native stack corruption. See b/17523189. However,
896 // adding that flag and start the preference panel with the same UserHandler will make it
897 // impossible to use back button to return to the previous screen. See b/20042570.
898 //
899 // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
900 // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
901 // when we're calling it as the same user.
902 if (userHandle.getIdentifier() == UserHandle.myUserId()) {
903 startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0);
904 } else {
905 String title = null;
906 if (titleRes < 0) {
907 if (titleText != null) {
908 title = titleText.toString();
909 } else {
910 // There not much we can do in that case
911 title = "";
912 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100913 }
Lifu Tangd0332852015-04-02 12:05:46 -0700914 Utils.startWithFragmentAsUser(this, fragmentClass, args,
915 titleRes, title, mIsShortcut, userHandle);
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100916 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100917 }
918
919 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800920 * Called by a preference panel fragment to finish itself.
921 *
922 * @param caller The fragment that is asking to be finished.
923 * @param resultCode Optional result code to send back to the original
924 * launching fragment.
925 * @param resultData Optional result data to send back to the original
926 * launching fragment.
927 */
928 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
929 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700930 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800931 }
932
933 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000934 * Start a new fragment.
935 *
936 * @param fragment The fragment to start
937 * @param push If true, the current fragment will be pushed onto the back stack. If false,
938 * the current fragment will be replaced.
939 */
940 public void startPreferenceFragment(Fragment fragment, boolean push) {
941 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700942 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000943 if (push) {
944 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
945 transaction.addToBackStack(BACK_STACK_PREFS);
946 } else {
947 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
948 }
949 transaction.commitAllowingStateLoss();
950 }
951
952 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700953 * Switch to a specific Fragment with taking care of validation, Title and BackStack
954 */
955 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700956 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700957 if (validate && !isValidFragment(fragmentName)) {
958 throw new IllegalArgumentException("Invalid fragment for this activity: "
959 + fragmentName);
960 }
961 Fragment f = Fragment.instantiate(this, fragmentName, args);
962 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700963 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700964 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700965 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700966 }
967 if (addToBackStack) {
968 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
969 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700970 if (titleResId > 0) {
971 transaction.setBreadCrumbTitle(titleResId);
972 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700973 transaction.setBreadCrumbTitle(title);
974 }
975 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700976 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700977 return f;
978 }
979
Jason Monk4da79e02015-09-10 10:54:36 -0400980 private void updateTilesList() {
Jason Monkfd2c7222015-12-02 15:38:38 -0500981 // Generally the items that are will be changing from these updates will
982 // not be in the top list of tiles, so run it in the background and the
983 // SettingsDrawerActivity will pick up on the updates automatically.
984 AsyncTask.execute(new Runnable() {
985 @Override
986 public void run() {
987 doUpdateTilesList();
988 }
989 });
990 }
991
992 private void doUpdateTilesList() {
Jason Monk4da79e02015-09-10 10:54:36 -0400993 PackageManager pm = getPackageManager();
Xiaohui Chen44879a32015-07-22 13:53:22 -0700994 final UserManager um = UserManager.get(this);
995 final boolean isAdmin = um.isAdminUser();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700996
Jason Monk4da79e02015-09-10 10:54:36 -0400997 String packageName = getPackageName();
998 setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()),
999 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001000
Jason Monk4da79e02015-09-10 10:54:36 -04001001 setTileEnabled(new ComponentName(packageName,
1002 Settings.BluetoothSettingsActivity.class.getName()),
1003 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001004
Jason Monk4da79e02015-09-10 10:54:36 -04001005 setTileEnabled(new ComponentName(packageName,
1006 Settings.DataUsageSummaryActivity.class.getName()),
1007 Utils.isBandwidthControlEnabled(), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001008
Jason Monk4da79e02015-09-10 10:54:36 -04001009 setTileEnabled(new ComponentName(packageName,
1010 Settings.SimSettingsActivity.class.getName()),
1011 Utils.showSimCardTile(this), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001012
Jason Monk4da79e02015-09-10 10:54:36 -04001013 setTileEnabled(new ComponentName(packageName,
1014 Settings.PowerUsageSummaryActivity.class.getName()),
1015 mBatteryPresent, isAdmin, pm);
1016
1017 setTileEnabled(new ComponentName(packageName,
1018 Settings.HomeSettingsActivity.class.getName()),
1019 updateHomeSettingTiles(), isAdmin, pm);
1020
1021 setTileEnabled(new ComponentName(packageName,
1022 Settings.UserSettingsActivity.class.getName()),
1023 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
1024 && !Utils.isMonkeyRunning(), isAdmin, pm);
1025
1026 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
1027 setTileEnabled(new ComponentName(packageName,
1028 Settings.PaymentSettingsActivity.class.getName()),
1029 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
1030 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
1031 && adapter != null && adapter.isEnabled(), isAdmin, pm);
1032
1033 setTileEnabled(new ComponentName(packageName,
1034 Settings.PrintSettingsActivity.class.getName()),
1035 pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin, pm);
1036
1037 final boolean showDev = mDevelopmentPreferences.getBoolean(
1038 DevelopmentSettings.PREF_SHOW,
1039 android.os.Build.TYPE.equals("eng"));
1040 setTileEnabled(new ComponentName(packageName,
1041 Settings.DevelopmentSettingsActivity.class.getName()),
1042 showDev && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES),
1043 isAdmin, pm);
1044
1045 if (UserHandle.MU_ENABLED && !isAdmin) {
1046 // When on restricted users, disable all extra categories (but only the settings ones).
Jason Monkfd2c7222015-12-02 15:38:38 -05001047 List<DashboardCategory> categories = getDashboardCategories();
Jason Monk4da79e02015-09-10 10:54:36 -04001048 for (DashboardCategory category : categories) {
Jason Monkd4f03ec2016-01-07 16:25:34 -05001049 for (Tile tile : category.tiles) {
Jason Monk4da79e02015-09-10 10:54:36 -04001050 ComponentName component = tile.intent.getComponent();
1051 if (packageName.equals(component)&& !ArrayUtils.contains(
1052 SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1053 setTileEnabled(component, false, isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001054 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001055 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001056 }
1057 }
Jason Monk2ebc8a02015-02-13 15:23:19 -05001058 }
1059
Jason Monk4da79e02015-09-10 10:54:36 -04001060 private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin,
1061 PackageManager pm) {
1062 if (UserHandle.MU_ENABLED && !isAdmin
1063 && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1064 enabled = false;
1065 }
1066 int state = pm.getComponentEnabledSetting(component);
1067 boolean isEnabled = state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
1068 || state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
1069 if (isEnabled != enabled) {
1070 pm.setComponentEnabledSetting(component, enabled
1071 ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
1072 : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
1073 PackageManager.DONT_KILL_APP);
Jason Monk2ebc8a02015-02-13 15:23:19 -05001074 }
1075 }
1076
Jason Monk4da79e02015-09-10 10:54:36 -04001077 private boolean updateHomeSettingTiles() {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001078 // Once we decide to show Home settings, keep showing it forever
1079 SharedPreferences sp = getSharedPreferences(HomeSettings.HOME_PREFS, Context.MODE_PRIVATE);
1080 if (sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false)) {
1081 return true;
1082 }
1083
1084 try {
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -07001085 mHomeActivitiesCount = getHomeActivitiesCount();
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -07001086 if (mHomeActivitiesCount < 2) {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001087 return false;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001088 }
1089 } catch (Exception e) {
1090 // Can't look up the home activity; bail on configuring the icon
1091 Log.w(LOG_TAG, "Problem looking up home activity!", e);
1092 }
1093
1094 sp.edit().putBoolean(HomeSettings.HOME_PREFS_DO_SHOW, true).apply();
1095 return true;
1096 }
1097
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001098 private void getMetaData() {
1099 try {
1100 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1101 PackageManager.GET_META_DATA);
1102 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001103 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1104 } catch (NameNotFoundException nnfe) {
1105 // No recovery
1106 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1107 }
1108 }
1109
1110 // give subclasses access to the Next button
1111 public boolean hasNextButton() {
1112 return mNextButton != null;
1113 }
1114
1115 public Button getNextButton() {
1116 return mNextButton;
1117 }
1118
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001119 @Override
1120 public boolean shouldUpRecreateTask(Intent targetIntent) {
1121 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1122 }
1123
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001124 @Override
1125 public boolean onQueryTextSubmit(String query) {
1126 switchToSearchResultsFragmentIfNeeded();
1127 mSearchQuery = query;
1128 return mSearchResultsFragment.onQueryTextSubmit(query);
1129 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001130
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001131 @Override
1132 public boolean onQueryTextChange(String newText) {
1133 mSearchQuery = newText;
Fabrice Di Meglio7e4855e2014-05-23 16:03:43 -07001134 if (mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001135 return false;
1136 }
1137 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001138 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001139
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001140 @Override
1141 public boolean onClose() {
1142 return false;
1143 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001144
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001145 @Override
1146 public boolean onMenuItemActionExpand(MenuItem item) {
1147 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001148 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001149 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001150 return true;
1151 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001152
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001153 @Override
1154 public boolean onMenuItemActionCollapse(MenuItem item) {
1155 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001156 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001157 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001158 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001159 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001160 return true;
1161 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001162
Jason Monk4da79e02015-09-10 10:54:36 -04001163 @Override
Jason Monkd4f03ec2016-01-07 16:25:34 -05001164 protected void onTileClicked(Tile tile) {
Jason Monk4da79e02015-09-10 10:54:36 -04001165 if (mIsShowingDashboard) {
1166 // If on dashboard, don't finish so the back comes back to here.
1167 openTile(tile);
1168 } else {
1169 super.onTileClicked(tile);
1170 }
1171 }
1172
Jason Monkaf001092015-11-04 13:16:18 -05001173 @Override
1174 public void onProfileTileOpen() {
1175 if (!mIsShowingDashboard) {
1176 finish();
1177 }
1178 }
1179
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001180 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001181 if (mSearchResultsFragment != null) {
1182 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001183 }
Fabrice Di Megliod40dd452014-07-18 15:20:34 -07001184 Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001185 if (current != null && current instanceof SearchResultsSummary) {
1186 mSearchResultsFragment = (SearchResultsSummary) current;
1187 } else {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001188 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001189 SearchResultsSummary.class.getName(), null, false, true,
1190 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001191 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001192 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001193 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001194 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001195
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001196 public void needToRevertToInitialFragment() {
1197 mNeedToRevertToInitialFragment = true;
1198 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001199
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001200 private void revertToInitialFragment() {
1201 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001202 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001203 mSearchMenuItemExpanded = false;
1204 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1205 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001206 if (mSearchMenuItem != null) {
1207 mSearchMenuItem.collapseActionView();
1208 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001209 }
Jim Miller0698a212014-10-16 19:49:07 -07001210
1211 public Intent getResultIntentData() {
1212 return mResultIntentData;
1213 }
1214
1215 public void setResultIntentData(Intent resultIntentData) {
1216 mResultIntentData = resultIntentData;
1217 }
Jason Monkd4f03ec2016-01-07 16:25:34 -05001218
1219 public void startSuggestion(Intent intent) {
1220 mCurrentSuggestion = intent.getComponent();
1221 startActivityForResult(intent, REQUEST_SUGGESTION);
1222 }
1223
1224 @Override
1225 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
1226 if (requestCode == REQUEST_SUGGESTION && mCurrentSuggestion != null
1227 && resultCode != RESULT_CANCELED) {
1228 getPackageManager().setComponentEnabledSetting(mCurrentSuggestion,
1229 PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
1230 }
1231 super.onActivityResult(requestCode, resultCode, data);
1232 }
1233
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001234}