blob: 4d9e2f0ae703b2053a25569d3e562e2b35548da0 [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;
Chris Wren8a963ba2015-03-20 10:29:14 -040053import com.android.internal.logging.MetricsLogger;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080054import com.android.internal.util.ArrayUtils;
Jason Monk4da79e02015-09-10 10:54:36 -040055import com.android.settings.Settings.WifiSettingsActivity;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080056import com.android.settings.accessibility.AccessibilitySettings;
57import 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;
Jeff Sharkeya16257d2015-04-28 13:41:01 -070072import com.android.settings.deviceinfo.PrivateVolumeForget;
Jeff Sharkeye77f0682015-04-29 11:24:57 -070073import com.android.settings.deviceinfo.PrivateVolumeSettings;
Jeff Sharkey42833b22015-04-11 21:27:33 -070074import com.android.settings.deviceinfo.PublicVolumeSettings;
75import com.android.settings.deviceinfo.StorageSettings;
John Spurlockc7f8e8c2014-06-04 19:11:22 -040076import com.android.settings.fuelgauge.BatterySaverSettings;
Jason Monk1eb54eb2015-04-29 12:46:42 -040077import com.android.settings.fuelgauge.PowerUsageDetail;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080078import com.android.settings.fuelgauge.PowerUsageSummary;
79import com.android.settings.inputmethod.InputMethodAndLanguageSettings;
80import com.android.settings.inputmethod.KeyboardLayoutPickerFragment;
81import com.android.settings.inputmethod.SpellCheckersSettings;
82import com.android.settings.inputmethod.UserDictionaryList;
83import com.android.settings.location.LocationSettings;
84import com.android.settings.nfc.AndroidBeam;
85import com.android.settings.nfc.PaymentSettings;
John Spurlock802ddf92014-07-18 11:51:13 -040086import com.android.settings.notification.AppNotificationSettings;
Julia Reynolds8c0a4232015-11-24 10:08:14 -050087import com.android.settings.notification.ConfigureNotificationSettings;
John Spurlock4a350512014-04-08 14:08:21 -040088import com.android.settings.notification.NotificationAccessSettings;
Julia Reynolds8c0a4232015-11-24 10:08:14 -050089import com.android.settings.notification.SoundSettings;
John Spurlock4a350512014-04-08 14:08:21 -040090import com.android.settings.notification.NotificationStation;
Jason Monk2ebc8a02015-02-13 15:23:19 -050091import com.android.settings.notification.OtherSoundSettings;
John Spurlock08531a82015-05-07 17:45:43 -040092import com.android.settings.notification.ZenAccessSettings;
John Spurlock533a5662015-06-19 10:47:36 -040093import com.android.settings.notification.ZenModeAutomationSettings;
John Spurlockf57bad72015-04-30 09:26:15 -040094import com.android.settings.notification.ZenModeEventRuleSettings;
John Spurlockc1df2aa2015-04-13 20:57:06 -040095import com.android.settings.notification.ZenModePrioritySettings;
John Spurlock45fa1402015-04-09 12:50:04 -040096import com.android.settings.notification.ZenModeScheduleRuleSettings;
Jason Monk39b46742015-09-10 15:52:51 -040097import com.android.settings.notification.ZenModeSettings;
Julia Reynolds5555d262015-11-09 10:52:17 -050098import com.android.settings.notification.ZenModeVisualInterruptionSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080099import com.android.settings.print.PrintJobSettingsFragment;
100import com.android.settings.print.PrintSettingsFragment;
Jason Monk2ebc8a02015-02-13 15:23:19 -0500101import com.android.settings.search.DynamicIndexableContentMonitor;
102import com.android.settings.search.Index;
PauloftheWest38155612014-06-30 10:02:36 -0700103import com.android.settings.sim.SimSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800104import com.android.settings.tts.TextToSpeechSettings;
105import com.android.settings.users.UserSettings;
106import com.android.settings.vpn2.VpnSettings;
107import com.android.settings.wfd.WifiDisplaySettings;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700108import com.android.settings.widget.SwitchBar;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800109import com.android.settings.wifi.AdvancedWifiSettings;
PauloftheWest7837b992014-06-24 07:42:27 -0700110import com.android.settings.wifi.SavedAccessPointsWifiSettings;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800111import com.android.settings.wifi.WifiSettings;
112import com.android.settings.wifi.p2p.WifiP2pSettings;
Jason Monk4da79e02015-09-10 10:54:36 -0400113import com.android.settingslib.drawer.DashboardCategory;
114import com.android.settingslib.drawer.DashboardTile;
115import com.android.settingslib.drawer.SettingsDrawerActivity;
Jason Monk2ebc8a02015-02-13 15:23:19 -0500116
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800117import java.util.ArrayList;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800118import java.util.List;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700119import java.util.Set;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800120
Jason Monk4da79e02015-09-10 10:54:36 -0400121public class SettingsActivity extends SettingsDrawerActivity
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800122 implements PreferenceManager.OnPreferenceTreeClickListener,
123 PreferenceFragment.OnPreferenceStartFragmentCallback,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100124 ButtonBarHandler, FragmentManager.OnBackStackChangedListener,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700125 SearchView.OnQueryTextListener, SearchView.OnCloseListener,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +0100126 MenuItem.OnActionExpandListener {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800127
128 private static final String LOG_TAG = "Settings";
129
130 // Constants for state save/restore
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700131 private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700132 private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
133 private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700134 private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700135 private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700136 private static final String SAVE_KEY_HOME_ACTIVITIES_COUNT = ":settings:home_activities_count";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800137
138 /**
139 * When starting this activity, the invoking Intent can contain this extra
140 * string to specify which fragment should be initially displayed.
141 * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
142 * will call isValidFragment() to confirm that the fragment class name is valid for this
143 * activity.
144 */
145 public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
146
147 /**
148 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
149 * this extra can also be specified to supply a Bundle of arguments to pass
150 * to that fragment when it is instantiated during the initial creation
151 * of the activity.
152 */
153 public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
154
155 /**
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700156 * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
157 */
158 public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
159
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800160 public static final String BACK_STACK_PREFS = ":settings:prefs";
161
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800162 // extras that allow any preference activity to be launched as part of a wizard
163
164 // show Back and Next buttons? takes boolean parameter
165 // Back will then return RESULT_CANCELED and Next RESULT_OK
166 protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
167
168 // add a Skip button?
169 private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
170
171 // specify custom text for the Back or Next buttons, or cause a button to not appear
172 // at all by setting it to null
173 protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
174 protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
175
176 /**
177 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700178 * 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 -0800179 * that fragment.
180 */
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700181 public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100182 /**
183 * The package name used to resolve the title resource id.
184 */
185 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
186 ":settings:show_fragment_title_res_package_name";
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700187 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
188 ":settings:show_fragment_title_resid";
189 public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
190 ":settings:show_fragment_as_shortcut";
191
192 public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
193 ":settings:show_fragment_as_subsetting";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800194
Jason Monk30695812015-11-17 09:01:08 -0500195 public static final String META_DATA_KEY_FRAGMENT_CLASS =
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800196 "com.android.settings.FRAGMENT_CLASS";
197
198 private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
199
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700200 private static final String EMPTY_QUERY = "";
201
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800202 private String mFragmentClass;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800203
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800204 private CharSequence mInitialTitle;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700205 private int mInitialTitleResId;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800206
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800207 // Show only these settings for restricted users
Jason Monk4da79e02015-09-10 10:54:36 -0400208 private String[] SETTINGS_FOR_RESTRICTED = {
209 //wireless_section
210 WifiSettingsActivity.class.getName(),
211 Settings.BluetoothSettingsActivity.class.getName(),
212 Settings.DataUsageSummaryActivity.class.getName(),
213 Settings.SimSettingsActivity.class.getName(),
214 Settings.WirelessSettingsActivity.class.getName(),
215 //device_section
216 Settings.HomeSettingsActivity.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500217 Settings.SoundSettingsActivity.class.getName(),
Jason Monk4da79e02015-09-10 10:54:36 -0400218 Settings.DisplaySettingsActivity.class.getName(),
219 Settings.StorageSettingsActivity.class.getName(),
220 Settings.ManageApplicationsActivity.class.getName(),
221 Settings.PowerUsageSummaryActivity.class.getName(),
222 //personal_section
223 Settings.LocationSettingsActivity.class.getName(),
224 Settings.SecuritySettingsActivity.class.getName(),
225 Settings.InputMethodAndLanguageSettingsActivity.class.getName(),
226 Settings.UserSettingsActivity.class.getName(),
227 Settings.AccountSettingsActivity.class.getName(),
228 //system_section
229 Settings.DateTimeSettingsActivity.class.getName(),
230 Settings.DeviceInfoSettingsActivity.class.getName(),
231 Settings.AccessibilitySettingsActivity.class.getName(),
232 Settings.PrintSettingsActivity.class.getName(),
233 Settings.PaymentSettingsActivity.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800234 };
235
236 private static final String[] ENTRY_FRAGMENTS = {
237 WirelessSettings.class.getName(),
238 WifiSettings.class.getName(),
239 AdvancedWifiSettings.class.getName(),
PauloftheWest7837b992014-06-24 07:42:27 -0700240 SavedAccessPointsWifiSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800241 BluetoothSettings.class.getName(),
PauloftheWest38155612014-06-30 10:02:36 -0700242 SimSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800243 TetherSettings.class.getName(),
244 WifiP2pSettings.class.getName(),
245 VpnSettings.class.getName(),
246 DateTimeSettings.class.getName(),
247 LocalePicker.class.getName(),
248 InputMethodAndLanguageSettings.class.getName(),
249 SpellCheckersSettings.class.getName(),
250 UserDictionaryList.class.getName(),
251 UserDictionarySettings.class.getName(),
Amith Yamasani3033ce02014-07-14 18:03:15 -0700252 HomeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800253 DisplaySettings.class.getName(),
254 DeviceInfoSettings.class.getName(),
255 ManageApplications.class.getName(),
Xiyuan Xia86a55402015-06-02 14:55:32 -0700256 ManageAssist.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800257 ProcessStatsUi.class.getName(),
258 NotificationStation.class.getName(),
259 LocationSettings.class.getName(),
260 SecuritySettings.class.getName(),
Jason Monkd8da51c2015-04-17 14:34:12 -0400261 UsageAccessDetails.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800262 PrivacySettings.class.getName(),
263 DeviceAdminSettings.class.getName(),
264 AccessibilitySettings.class.getName(),
265 CaptionPropertiesFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800266 com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(),
267 TextToSpeechSettings.class.getName(),
Jeff Sharkey42833b22015-04-11 21:27:33 -0700268 StorageSettings.class.getName(),
Jeff Sharkeya16257d2015-04-28 13:41:01 -0700269 PrivateVolumeForget.class.getName(),
Jeff Sharkeye77f0682015-04-29 11:24:57 -0700270 PrivateVolumeSettings.class.getName(),
271 PublicVolumeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800272 DevelopmentSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800273 AndroidBeam.class.getName(),
274 WifiDisplaySettings.class.getName(),
275 PowerUsageSummary.class.getName(),
276 AccountSyncSettings.class.getName(),
Alexandra Gherghina6d839872014-07-22 12:04:58 +0000277 AccountSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800278 CryptKeeperSettings.class.getName(),
279 DataUsageSummary.class.getName(),
280 DreamSettings.class.getName(),
281 UserSettings.class.getName(),
282 NotificationAccessSettings.class.getName(),
John Spurlock08531a82015-05-07 17:45:43 -0400283 ZenAccessSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800284 PrintSettingsFragment.class.getName(),
285 PrintJobSettingsFragment.class.getName(),
286 TrustedCredentialsSettings.class.getName(),
287 PaymentSettings.class.getName(),
288 KeyboardLayoutPickerFragment.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700289 ZenModeSettings.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500290 SoundSettings.class.getName(),
291 ConfigureNotificationSettings.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700292 ChooseLockPassword.ChooseLockPasswordFragment.class.getName(),
293 ChooseLockPattern.ChooseLockPatternFragment.class.getName(),
John Spurlockc7f8e8c2014-06-04 19:11:22 -0400294 InstalledAppDetails.class.getName(),
295 BatterySaverSettings.class.getName(),
Fabrice Di Megliodcf59dd2014-07-21 11:22:20 -0700296 AppNotificationSettings.class.getName(),
Fabrice Di Meglioe3ff4d82014-07-23 20:03:20 -0700297 OtherSoundSettings.class.getName(),
Narayan Kamath33acb152015-03-16 12:48:05 +0000298 ApnSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400299 WifiCallingSettings.class.getName(),
John Spurlockc1df2aa2015-04-13 20:57:06 -0400300 ZenModePrioritySettings.class.getName(),
John Spurlock533a5662015-06-19 10:47:36 -0400301 ZenModeAutomationSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400302 ZenModeScheduleRuleSettings.class.getName(),
John Spurlockf57bad72015-04-30 09:26:15 -0400303 ZenModeEventRuleSettings.class.getName(),
Julia Reynolds5555d262015-11-09 10:52:17 -0500304 ZenModeVisualInterruptionSettings.class.getName(),
Jason Monk2583fc12015-03-25 09:46:30 -0400305 ProcessStatsUi.class.getName(),
Jason Monk1eb54eb2015-04-29 12:46:42 -0400306 PowerUsageDetail.class.getName(),
Jason Monk2cdafc62015-06-12 12:32:50 -0400307 ProcessStatsSummary.class.getName(),
Billy Laufee78562015-07-27 12:57:07 +0100308 DrawOverlayDetails.class.getName(),
309 WriteSettingsDetails.class.getName(),
Julia Reynolds2e1e0b72015-12-14 08:32:46 -0500310 ManageDefaultApps.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800311 };
312
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700313
314 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
315 "android.settings.APPLICATION_DETAILS_SETTINGS"
316 };
317
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800318 private SharedPreferences mDevelopmentPreferences;
319 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
320
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800321 private boolean mBatteryPresent = true;
322 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800323 @Override
324 public void onReceive(Context context, Intent intent) {
325 String action = intent.getAction();
326 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
327 boolean batteryPresent = Utils.isBatteryPresent(intent);
328
329 if (mBatteryPresent != batteryPresent) {
330 mBatteryPresent = batteryPresent;
Jason Monk4da79e02015-09-10 10:54:36 -0400331 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800332 }
333 }
334 }
335 };
336
Svetoslav990159a2014-04-14 17:14:59 -0700337 private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor =
338 new DynamicIndexableContentMonitor();
Svetoslav853e4712014-04-14 10:10:25 -0700339
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700340 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700341 private SwitchBar mSwitchBar;
342
343 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700344
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700345 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700346 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700347
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700348 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700349 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700350
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700351 private ViewGroup mContent;
352
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700353 private SearchView mSearchView;
354 private MenuItem mSearchMenuItem;
355 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700356 private SearchResultsSummary mSearchResultsFragment;
357 private String mSearchQuery;
358
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700359 // Categories
360 private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800361
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700362 private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800363
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700364 private boolean mNeedToRevertToInitialFragment = false;
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700365 private int mHomeActivitiesCount = 1;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700366
Jim Miller0698a212014-10-16 19:49:07 -0700367 private Intent mResultIntentData;
368
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700369 public SwitchBar getSwitchBar() {
370 return mSwitchBar;
371 }
372
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800373 @Override
374 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
375 // Override the fragment title for Wallpaper settings
Jason Monk39b46742015-09-10 15:52:51 -0400376 CharSequence title = pref.getTitle();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800377 if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) {
Jason Monk39b46742015-09-10 15:52:51 -0400378 title = getString(R.string.wallpaper_settings_fragment_title);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800379 }
Jason Monkb1dd5c92015-12-16 16:13:54 -0500380 startPreferencePanel(pref.getFragment(), pref.getExtras(), -1, title,
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800381 null, 0);
382 return true;
383 }
384
385 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400386 public boolean onPreferenceTreeClick(Preference preference) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800387 return false;
388 }
389
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800390 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800391 public void onConfigurationChanged(Configuration newConfig) {
392 super.onConfigurationChanged(newConfig);
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800393 Index.getInstance(this).update();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800394 }
395
396 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700397 protected void onStart() {
398 super.onStart();
399
400 if (mNeedToRevertToInitialFragment) {
401 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800402 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800403 }
404
405 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700406 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700407 if (!mDisplaySearch) {
408 return false;
409 }
410
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700411 MenuInflater inflater = getMenuInflater();
412 inflater.inflate(R.menu.options_menu, menu);
413
414 // Cache the search query (can be overriden by the OnQueryTextListener)
415 final String query = mSearchQuery;
416
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700417 mSearchMenuItem = menu.findItem(R.id.search);
418 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700419
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700420 if (mSearchMenuItem == null || mSearchView == null) {
421 return false;
422 }
423
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700424 if (mSearchResultsFragment != null) {
425 mSearchResultsFragment.setSearchView(mSearchView);
426 }
427
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700428 mSearchMenuItem.setOnActionExpandListener(this);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700429 mSearchView.setOnQueryTextListener(this);
430 mSearchView.setOnCloseListener(this);
431
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700432 if (mSearchMenuItemExpanded) {
433 mSearchMenuItem.expandActionView();
434 }
435 mSearchView.setQuery(query, true /* submit */);
436
437 return true;
438 }
439
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700440 private static boolean isShortCutIntent(final Intent intent) {
441 Set<String> categories = intent.getCategories();
442 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
443 }
444
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700445 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700446 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700447 if (action == null) {
448 return false;
449 }
450 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
451 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
452 }
453 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700454 }
455
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700456 @Override
457 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700458 super.onCreate(savedState);
Jason Monkfd2c7222015-12-02 15:38:38 -0500459 long startTime = System.currentTimeMillis();
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700460
461 // Should happen before any call to getIntent()
462 getMetaData();
463
464 final Intent intent = getIntent();
465 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
466 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800467 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800468
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800469 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
470 Context.MODE_PRIVATE);
471
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700472 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700473 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700474
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700475 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700476 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
477
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700478 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700479 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700480
Jason Monk4da79e02015-09-10 10:54:36 -0400481 mIsShowingDashboard = className.equals(Settings.class.getName())
482 || className.equals(Settings.WirelessSettings.class.getName())
483 || className.equals(Settings.DeviceSettings.class.getName())
484 || className.equals(Settings.PersonalSettings.class.getName())
485 || className.equals(Settings.WirelessSettings.class.getName());
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700486
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700487 // This is a "Sub Settings" when:
488 // - this is a real SubSettings
489 // - or :settings:show_fragment_as_subsetting is passed to the Intent
Jorim Jaggi4dfcb822015-04-29 17:21:32 -0700490 final boolean isSubSettings = this instanceof SubSettings ||
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700491 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
492
493 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
494 if (isSubSettings) {
Fabrice Di Meglio712df6c2014-07-18 17:44:37 -0700495 // Check also that we are not a Theme Dialog as we don't want to override them
496 final int themeResId = getThemeResId();
497 if (themeResId != R.style.Theme_DialogWhenLarge &&
498 themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
499 setTheme(R.style.Theme_SubSettings);
500 }
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700501 }
502
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700503 setContentView(mIsShowingDashboard ?
504 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800505
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700506 mContent = (ViewGroup) findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700507
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800508 getFragmentManager().addOnBackStackChangedListener(this);
509
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700510 if (mIsShowingDashboard) {
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800511 // Run the Index update only if we have some space
512 if (!Utils.isLowStorage(this)) {
Jason Monkfd2c7222015-12-02 15:38:38 -0500513 long indexStartTime = System.currentTimeMillis();
514 AsyncTask.execute(new Runnable() {
515 @Override
516 public void run() {
517 Index.getInstance(getApplicationContext()).update();
518 }
519 });
520 if (DEBUG_TIMING) Log.d(LOG_TAG, "Index.update() took "
521 + (System.currentTimeMillis() - indexStartTime) + " ms");
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800522 } else {
523 Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
524 }
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700525 }
526
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700527 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700528 // We are restarting from a previous saved state; used that to initialize, instead
529 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700530 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
531 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800532
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700533 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800534
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700535 ArrayList<DashboardCategory> categories =
536 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
537 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700538 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700539 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700540 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800541 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700542
543 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700544 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700545 mHomeActivitiesCount = savedState.getInt(SAVE_KEY_HOME_ACTIVITIES_COUNT,
546 1 /* one home activity by default */);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800547 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700548 if (!mIsShowingDashboard) {
Jason Monkea8b1a72015-06-02 16:46:34 -0400549 mDisplaySearch = false;
550 // UP will be shown only if it is a sub settings
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700551 if (mIsShortcut) {
552 mDisplayHomeAsUpEnabled = isSubSettings;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700553 } else if (isSubSettings) {
554 mDisplayHomeAsUpEnabled = true;
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700555 } else {
556 mDisplayHomeAsUpEnabled = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700557 }
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700558 setTitleFromIntent(intent);
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700559
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700560 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700561 switchToFragment(initialFragmentName, initialArguments, true, false,
562 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000563 } else {
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700564 // No UP affordance if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700565 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700566 // Show Search affordance
567 mDisplaySearch = true;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700568 mInitialTitleResId = R.string.dashboard_title;
Fabrice Di Meglio42c4b0a2014-05-22 10:30:03 -0700569 switchToFragment(DashboardSummary.class.getName(), null, false, false,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700570 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800571 }
572 }
573
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700574 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700575 if (mActionBar != null) {
576 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
577 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
578 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700579 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
580
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800581 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800582 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
583
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700584 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800585 if (buttonBar != null) {
586 buttonBar.setVisibility(View.VISIBLE);
587
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700588 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800589 backButton.setOnClickListener(new OnClickListener() {
590 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700591 setResult(RESULT_CANCELED, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800592 finish();
593 }
594 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700595 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800596 skipButton.setOnClickListener(new OnClickListener() {
597 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700598 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800599 finish();
600 }
601 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700602 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800603 mNextButton.setOnClickListener(new OnClickListener() {
604 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700605 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800606 finish();
607 }
608 });
609
610 // set our various button parameters
611 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
612 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
613 if (TextUtils.isEmpty(buttonText)) {
614 mNextButton.setVisibility(View.GONE);
615 }
616 else {
617 mNextButton.setText(buttonText);
618 }
619 }
620 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
621 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
622 if (TextUtils.isEmpty(buttonText)) {
623 backButton.setVisibility(View.GONE);
624 }
625 else {
626 backButton.setText(buttonText);
627 }
628 }
629 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
630 skipButton.setVisibility(View.VISIBLE);
631 }
632 }
633 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700634
635 mHomeActivitiesCount = getHomeActivitiesCount();
Jason Monkfd2c7222015-12-02 15:38:38 -0500636 if (DEBUG_TIMING) Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
637 + " ms");
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700638 }
639
640 private int getHomeActivitiesCount() {
641 final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>();
642 getPackageManager().getHomeActivities(homeApps);
643 return homeApps.size();
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800644 }
645
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700646 private void setTitleFromIntent(Intent intent) {
647 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
648 if (initialTitleResId > 0) {
649 mInitialTitle = null;
650 mInitialTitleResId = initialTitleResId;
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100651
652 final String initialTitleResPackageName = intent.getStringExtra(
653 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
654 if (initialTitleResPackageName != null) {
655 try {
656 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
657 0 /* flags */, new UserHandle(UserHandle.myUserId()));
658 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
659 setTitle(mInitialTitle);
660 mInitialTitleResId = -1;
661 return;
662 } catch (NameNotFoundException e) {
663 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
664 }
665 } else {
666 setTitle(mInitialTitleResId);
667 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700668 } else {
669 mInitialTitleResId = -1;
670 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
671 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
672 setTitle(mInitialTitle);
673 }
674 }
675
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800676 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800677 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700678 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800679 }
680
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700681 private int setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800682 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700683
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800684 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700685 if (mInitialTitleResId > 0) {
686 setTitle(mInitialTitleResId);
687 } else {
688 setTitle(mInitialTitle);
689 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700690 return 0;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800691 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700692
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800693 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
694 setTitleFromBackStackEntry(bse);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700695
696 return count;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800697 }
698
699 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
700 final CharSequence title;
701 final int titleRes = bse.getBreadCrumbTitleRes();
702 if (titleRes > 0) {
703 title = getText(titleRes);
704 } else {
705 title = bse.getBreadCrumbTitle();
706 }
707 if (title != null) {
708 setTitle(title);
709 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800710 }
711
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800712 @Override
713 protected void onSaveInstanceState(Bundle outState) {
714 super.onSaveInstanceState(outState);
715
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700716 if (mCategories.size() > 0) {
717 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800718 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700719
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700720 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700721 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700722
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700723 if (mDisplaySearch) {
724 // The option menus are created if the ActionBar is visible and they are also created
725 // asynchronously. If you launch Settings with an Intent action like
726 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
727 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
728 // menu item and search view are null.
729 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
730 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700731
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700732 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
733 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
734 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700735
736 outState.putInt(SAVE_KEY_HOME_ACTIVITIES_COUNT, mHomeActivitiesCount);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800737 }
738
739 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400740 protected void onResume() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800741 super.onResume();
742
743 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
744 @Override
745 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Jason Monk4da79e02015-09-10 10:54:36 -0400746 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800747 }
748 };
749 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
750 mDevelopmentPreferencesListener);
751
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800752 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Svetoslav853e4712014-04-14 10:10:25 -0700753
Svetoslav990159a2014-04-14 17:14:59 -0700754 mDynamicIndexableContentMonitor.register(this);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700755
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700756 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700757 onQueryTextSubmit(mSearchQuery);
758 }
Jason Monk4da79e02015-09-10 10:54:36 -0400759 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800760 }
761
762 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400763 protected void onPause() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800764 super.onPause();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800765 unregisterReceiver(mBatteryInfoReceiver);
Svetoslav990159a2014-04-14 17:14:59 -0700766 mDynamicIndexableContentMonitor.unregister();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800767 }
768
769 @Override
770 public void onDestroy() {
771 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700772
773 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
774 mDevelopmentPreferencesListener);
775 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800776 }
777
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800778 protected boolean isValidFragment(String fragmentName) {
779 // Almost all fragments are wrapped in this,
780 // except for a few that have their own activities.
781 for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
782 if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
783 }
784 return false;
785 }
786
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800787 @Override
788 public Intent getIntent() {
789 Intent superIntent = super.getIntent();
790 String startingFragment = getStartingFragmentClass(superIntent);
791 // This is called from super.onCreate, isMultiPane() is not yet reliable
792 // Do not use onIsHidingHeaders either, which relies itself on this method
793 if (startingFragment != null) {
794 Intent modIntent = new Intent(superIntent);
795 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
796 Bundle args = superIntent.getExtras();
797 if (args != null) {
798 args = new Bundle(args);
799 } else {
800 args = new Bundle();
801 }
802 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100803 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800804 return modIntent;
805 }
806 return superIntent;
807 }
808
809 /**
810 * Checks if the component name in the intent is different from the Settings class and
811 * returns the class name to load as a fragment.
812 */
813 private String getStartingFragmentClass(Intent intent) {
814 if (mFragmentClass != null) return mFragmentClass;
815
816 String intentClass = intent.getComponent().getClassName();
817 if (intentClass.equals(getClass().getName())) return null;
818
819 if ("com.android.settings.ManageApplications".equals(intentClass)
820 || "com.android.settings.RunningServices".equals(intentClass)
821 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
822 // Old names of manage apps.
823 intentClass = com.android.settings.applications.ManageApplications.class.getName();
824 }
825
826 return intentClass;
827 }
828
829 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000830 * Start a new fragment containing a preference panel. If the preferences
831 * are being displayed in multi-pane mode, the given fragment class will
832 * be instantiated and placed in the appropriate pane. If running in
833 * single-pane mode, a new activity will be launched in which to show the
834 * fragment.
835 *
836 * @param fragmentClass Full name of the class implementing the fragment.
837 * @param args Any desired arguments to supply to the fragment.
838 * @param titleRes Optional resource identifier of the title of this
839 * fragment.
840 * @param titleText Optional text of the title of this fragment.
841 * @param resultTo Optional fragment that result data should be sent to.
842 * If non-null, resultTo.onActivityResult() will be called when this
843 * preference panel is done. The launched panel must use
844 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
845 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700846 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000847 */
848 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700849 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700850 String title = null;
851 if (titleRes < 0) {
852 if (titleText != null) {
853 title = titleText.toString();
854 } else {
855 // There not much we can do in that case
856 title = "";
857 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700858 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700859 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700860 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000861 }
862
863 /**
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100864 * Start a new fragment in a new activity containing a preference panel for a given user. If the
865 * preferences are being displayed in multi-pane mode, the given fragment class will be
866 * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
867 * activity will be launched in which to show the fragment.
868 *
869 * @param fragmentClass Full name of the class implementing the fragment.
870 * @param args Any desired arguments to supply to the fragment.
871 * @param titleRes Optional resource identifier of the title of this fragment.
872 * @param titleText Optional text of the title of this fragment.
873 * @param userHandle The user for which the panel has to be started.
874 */
875 public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
876 CharSequence titleText, UserHandle userHandle) {
Lifu Tangd0332852015-04-02 12:05:46 -0700877 // This is a workaround.
878 //
879 // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
880 // starting the fragment could cause a native stack corruption. See b/17523189. However,
881 // adding that flag and start the preference panel with the same UserHandler will make it
882 // impossible to use back button to return to the previous screen. See b/20042570.
883 //
884 // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
885 // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
886 // when we're calling it as the same user.
887 if (userHandle.getIdentifier() == UserHandle.myUserId()) {
888 startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0);
889 } else {
890 String title = null;
891 if (titleRes < 0) {
892 if (titleText != null) {
893 title = titleText.toString();
894 } else {
895 // There not much we can do in that case
896 title = "";
897 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100898 }
Lifu Tangd0332852015-04-02 12:05:46 -0700899 Utils.startWithFragmentAsUser(this, fragmentClass, args,
900 titleRes, title, mIsShortcut, userHandle);
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100901 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100902 }
903
904 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800905 * Called by a preference panel fragment to finish itself.
906 *
907 * @param caller The fragment that is asking to be finished.
908 * @param resultCode Optional result code to send back to the original
909 * launching fragment.
910 * @param resultData Optional result data to send back to the original
911 * launching fragment.
912 */
913 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
914 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700915 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800916 }
917
918 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000919 * Start a new fragment.
920 *
921 * @param fragment The fragment to start
922 * @param push If true, the current fragment will be pushed onto the back stack. If false,
923 * the current fragment will be replaced.
924 */
925 public void startPreferenceFragment(Fragment fragment, boolean push) {
926 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700927 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000928 if (push) {
929 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
930 transaction.addToBackStack(BACK_STACK_PREFS);
931 } else {
932 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
933 }
934 transaction.commitAllowingStateLoss();
935 }
936
937 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700938 * Switch to a specific Fragment with taking care of validation, Title and BackStack
939 */
940 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700941 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700942 if (validate && !isValidFragment(fragmentName)) {
943 throw new IllegalArgumentException("Invalid fragment for this activity: "
944 + fragmentName);
945 }
946 Fragment f = Fragment.instantiate(this, fragmentName, args);
947 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700948 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700949 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700950 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700951 }
952 if (addToBackStack) {
953 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
954 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700955 if (titleResId > 0) {
956 transaction.setBreadCrumbTitle(titleResId);
957 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700958 transaction.setBreadCrumbTitle(title);
959 }
960 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700961 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700962 return f;
963 }
964
Jason Monk4da79e02015-09-10 10:54:36 -0400965 private void updateTilesList() {
Jason Monkfd2c7222015-12-02 15:38:38 -0500966 // Generally the items that are will be changing from these updates will
967 // not be in the top list of tiles, so run it in the background and the
968 // SettingsDrawerActivity will pick up on the updates automatically.
969 AsyncTask.execute(new Runnable() {
970 @Override
971 public void run() {
972 doUpdateTilesList();
973 }
974 });
975 }
976
977 private void doUpdateTilesList() {
Jason Monk4da79e02015-09-10 10:54:36 -0400978 PackageManager pm = getPackageManager();
Xiaohui Chen44879a32015-07-22 13:53:22 -0700979 final UserManager um = UserManager.get(this);
980 final boolean isAdmin = um.isAdminUser();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700981
Jason Monk4da79e02015-09-10 10:54:36 -0400982 String packageName = getPackageName();
983 setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()),
984 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700985
Jason Monk4da79e02015-09-10 10:54:36 -0400986 setTileEnabled(new ComponentName(packageName,
987 Settings.BluetoothSettingsActivity.class.getName()),
988 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700989
Jason Monk4da79e02015-09-10 10:54:36 -0400990 setTileEnabled(new ComponentName(packageName,
991 Settings.DataUsageSummaryActivity.class.getName()),
992 Utils.isBandwidthControlEnabled(), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700993
Jason Monk4da79e02015-09-10 10:54:36 -0400994 setTileEnabled(new ComponentName(packageName,
995 Settings.SimSettingsActivity.class.getName()),
996 Utils.showSimCardTile(this), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700997
Jason Monk4da79e02015-09-10 10:54:36 -0400998 setTileEnabled(new ComponentName(packageName,
999 Settings.PowerUsageSummaryActivity.class.getName()),
1000 mBatteryPresent, isAdmin, pm);
1001
1002 setTileEnabled(new ComponentName(packageName,
1003 Settings.HomeSettingsActivity.class.getName()),
1004 updateHomeSettingTiles(), isAdmin, pm);
1005
1006 setTileEnabled(new ComponentName(packageName,
1007 Settings.UserSettingsActivity.class.getName()),
1008 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
1009 && !Utils.isMonkeyRunning(), isAdmin, pm);
1010
1011 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
1012 setTileEnabled(new ComponentName(packageName,
1013 Settings.PaymentSettingsActivity.class.getName()),
1014 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
1015 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
1016 && adapter != null && adapter.isEnabled(), isAdmin, pm);
1017
1018 setTileEnabled(new ComponentName(packageName,
1019 Settings.PrintSettingsActivity.class.getName()),
1020 pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin, pm);
1021
1022 final boolean showDev = mDevelopmentPreferences.getBoolean(
1023 DevelopmentSettings.PREF_SHOW,
1024 android.os.Build.TYPE.equals("eng"));
1025 setTileEnabled(new ComponentName(packageName,
1026 Settings.DevelopmentSettingsActivity.class.getName()),
1027 showDev && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES),
1028 isAdmin, pm);
1029
1030 if (UserHandle.MU_ENABLED && !isAdmin) {
1031 // When on restricted users, disable all extra categories (but only the settings ones).
Jason Monkfd2c7222015-12-02 15:38:38 -05001032 List<DashboardCategory> categories = getDashboardCategories();
Jason Monk4da79e02015-09-10 10:54:36 -04001033 for (DashboardCategory category : categories) {
1034 for (DashboardTile tile : category.tiles) {
1035 ComponentName component = tile.intent.getComponent();
1036 if (packageName.equals(component)&& !ArrayUtils.contains(
1037 SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1038 setTileEnabled(component, false, isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001039 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001040 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001041 }
1042 }
Jason Monk2ebc8a02015-02-13 15:23:19 -05001043 }
1044
Jason Monk4da79e02015-09-10 10:54:36 -04001045 private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin,
1046 PackageManager pm) {
1047 if (UserHandle.MU_ENABLED && !isAdmin
1048 && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1049 enabled = false;
1050 }
1051 int state = pm.getComponentEnabledSetting(component);
1052 boolean isEnabled = state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
1053 || state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
1054 if (isEnabled != enabled) {
1055 pm.setComponentEnabledSetting(component, enabled
1056 ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
1057 : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
1058 PackageManager.DONT_KILL_APP);
Jason Monk2ebc8a02015-02-13 15:23:19 -05001059 }
1060 }
1061
Jason Monk4da79e02015-09-10 10:54:36 -04001062 private boolean updateHomeSettingTiles() {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001063 // Once we decide to show Home settings, keep showing it forever
1064 SharedPreferences sp = getSharedPreferences(HomeSettings.HOME_PREFS, Context.MODE_PRIVATE);
1065 if (sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false)) {
1066 return true;
1067 }
1068
1069 try {
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -07001070 mHomeActivitiesCount = getHomeActivitiesCount();
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -07001071 if (mHomeActivitiesCount < 2) {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001072 return false;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001073 }
1074 } catch (Exception e) {
1075 // Can't look up the home activity; bail on configuring the icon
1076 Log.w(LOG_TAG, "Problem looking up home activity!", e);
1077 }
1078
1079 sp.edit().putBoolean(HomeSettings.HOME_PREFS_DO_SHOW, true).apply();
1080 return true;
1081 }
1082
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001083 private void getMetaData() {
1084 try {
1085 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1086 PackageManager.GET_META_DATA);
1087 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001088 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1089 } catch (NameNotFoundException nnfe) {
1090 // No recovery
1091 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1092 }
1093 }
1094
1095 // give subclasses access to the Next button
1096 public boolean hasNextButton() {
1097 return mNextButton != null;
1098 }
1099
1100 public Button getNextButton() {
1101 return mNextButton;
1102 }
1103
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001104 @Override
1105 public boolean shouldUpRecreateTask(Intent targetIntent) {
1106 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1107 }
1108
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001109 @Override
1110 public boolean onQueryTextSubmit(String query) {
1111 switchToSearchResultsFragmentIfNeeded();
1112 mSearchQuery = query;
1113 return mSearchResultsFragment.onQueryTextSubmit(query);
1114 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001115
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001116 @Override
1117 public boolean onQueryTextChange(String newText) {
1118 mSearchQuery = newText;
Fabrice Di Meglio7e4855e2014-05-23 16:03:43 -07001119 if (mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001120 return false;
1121 }
1122 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001123 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001124
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001125 @Override
1126 public boolean onClose() {
1127 return false;
1128 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001129
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001130 @Override
1131 public boolean onMenuItemActionExpand(MenuItem item) {
1132 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001133 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001134 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001135 return true;
1136 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001137
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001138 @Override
1139 public boolean onMenuItemActionCollapse(MenuItem item) {
1140 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001141 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001142 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001143 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001144 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001145 return true;
1146 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001147
Jason Monk4da79e02015-09-10 10:54:36 -04001148 @Override
1149 protected void onTileClicked(DashboardTile tile) {
1150 if (mIsShowingDashboard) {
1151 // If on dashboard, don't finish so the back comes back to here.
1152 openTile(tile);
1153 } else {
1154 super.onTileClicked(tile);
1155 }
1156 }
1157
Jason Monkaf001092015-11-04 13:16:18 -05001158 @Override
1159 public void onProfileTileOpen() {
1160 if (!mIsShowingDashboard) {
1161 finish();
1162 }
1163 }
1164
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001165 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001166 if (mSearchResultsFragment != null) {
1167 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001168 }
Fabrice Di Megliod40dd452014-07-18 15:20:34 -07001169 Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001170 if (current != null && current instanceof SearchResultsSummary) {
1171 mSearchResultsFragment = (SearchResultsSummary) current;
1172 } else {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001173 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001174 SearchResultsSummary.class.getName(), null, false, true,
1175 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001176 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001177 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001178 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001179 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001180
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001181 public void needToRevertToInitialFragment() {
1182 mNeedToRevertToInitialFragment = true;
1183 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001184
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001185 private void revertToInitialFragment() {
1186 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001187 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001188 mSearchMenuItemExpanded = false;
1189 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1190 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001191 if (mSearchMenuItem != null) {
1192 mSearchMenuItem.collapseActionView();
1193 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001194 }
Jim Miller0698a212014-10-16 19:49:07 -07001195
1196 public Intent getResultIntentData() {
1197 return mResultIntentData;
1198 }
1199
1200 public void setResultIntentData(Intent resultIntentData) {
1201 mResultIntentData = resultIntentData;
1202 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001203}