blob: ba975a2c2e70e183c4ddab06a7964e383a7456d3 [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
Svetoslav990159a2014-04-14 17:14:59 -0700338 private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor =
339 new DynamicIndexableContentMonitor();
Svetoslav853e4712014-04-14 10:10:25 -0700340
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700341 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700342 private SwitchBar mSwitchBar;
343
344 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700345
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700346 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700347 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700348
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700349 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700350 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700351
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700352 private ViewGroup mContent;
353
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700354 private SearchView mSearchView;
355 private MenuItem mSearchMenuItem;
356 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700357 private SearchResultsSummary mSearchResultsFragment;
358 private String mSearchQuery;
359
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700360 // Categories
361 private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800362
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700363 private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800364
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700365 private boolean mNeedToRevertToInitialFragment = false;
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700366 private int mHomeActivitiesCount = 1;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700367
Jim Miller0698a212014-10-16 19:49:07 -0700368 private Intent mResultIntentData;
Jason Monkd4f03ec2016-01-07 16:25:34 -0500369 private ComponentName mCurrentSuggestion;
Jim Miller0698a212014-10-16 19:49:07 -0700370
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700371 public SwitchBar getSwitchBar() {
372 return mSwitchBar;
373 }
374
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800375 @Override
376 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
377 // Override the fragment title for Wallpaper settings
Jason Monk39b46742015-09-10 15:52:51 -0400378 CharSequence title = pref.getTitle();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800379 if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) {
Jason Monk39b46742015-09-10 15:52:51 -0400380 title = getString(R.string.wallpaper_settings_fragment_title);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800381 }
Jason Monkb1dd5c92015-12-16 16:13:54 -0500382 startPreferencePanel(pref.getFragment(), pref.getExtras(), -1, title,
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800383 null, 0);
384 return true;
385 }
386
387 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400388 public boolean onPreferenceTreeClick(Preference preference) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800389 return false;
390 }
391
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800392 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800393 public void onConfigurationChanged(Configuration newConfig) {
394 super.onConfigurationChanged(newConfig);
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800395 Index.getInstance(this).update();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800396 }
397
398 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700399 protected void onStart() {
400 super.onStart();
401
402 if (mNeedToRevertToInitialFragment) {
403 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800404 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800405 }
406
407 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700408 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700409 if (!mDisplaySearch) {
410 return false;
411 }
412
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700413 MenuInflater inflater = getMenuInflater();
414 inflater.inflate(R.menu.options_menu, menu);
415
416 // Cache the search query (can be overriden by the OnQueryTextListener)
417 final String query = mSearchQuery;
418
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700419 mSearchMenuItem = menu.findItem(R.id.search);
420 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700421
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700422 if (mSearchMenuItem == null || mSearchView == null) {
423 return false;
424 }
425
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700426 if (mSearchResultsFragment != null) {
427 mSearchResultsFragment.setSearchView(mSearchView);
428 }
429
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700430 mSearchMenuItem.setOnActionExpandListener(this);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700431 mSearchView.setOnQueryTextListener(this);
432 mSearchView.setOnCloseListener(this);
433
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700434 if (mSearchMenuItemExpanded) {
435 mSearchMenuItem.expandActionView();
436 }
437 mSearchView.setQuery(query, true /* submit */);
438
439 return true;
440 }
441
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700442 private static boolean isShortCutIntent(final Intent intent) {
443 Set<String> categories = intent.getCategories();
444 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
445 }
446
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700447 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700448 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700449 if (action == null) {
450 return false;
451 }
452 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
453 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
454 }
455 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700456 }
457
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700458 @Override
459 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700460 super.onCreate(savedState);
Jason Monkfd2c7222015-12-02 15:38:38 -0500461 long startTime = System.currentTimeMillis();
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700462
463 // Should happen before any call to getIntent()
464 getMetaData();
465
466 final Intent intent = getIntent();
467 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
468 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800469 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800470
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800471 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
472 Context.MODE_PRIVATE);
473
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700474 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700475 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700476
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700477 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700478 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
479
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700480 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700481 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700482
Jason Monk4da79e02015-09-10 10:54:36 -0400483 mIsShowingDashboard = className.equals(Settings.class.getName())
484 || className.equals(Settings.WirelessSettings.class.getName())
485 || className.equals(Settings.DeviceSettings.class.getName())
486 || className.equals(Settings.PersonalSettings.class.getName())
487 || className.equals(Settings.WirelessSettings.class.getName());
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700488
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700489 // This is a "Sub Settings" when:
490 // - this is a real SubSettings
491 // - or :settings:show_fragment_as_subsetting is passed to the Intent
Jorim Jaggi4dfcb822015-04-29 17:21:32 -0700492 final boolean isSubSettings = this instanceof SubSettings ||
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700493 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
494
495 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
496 if (isSubSettings) {
Fabrice Di Meglio712df6c2014-07-18 17:44:37 -0700497 // Check also that we are not a Theme Dialog as we don't want to override them
498 final int themeResId = getThemeResId();
499 if (themeResId != R.style.Theme_DialogWhenLarge &&
500 themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
501 setTheme(R.style.Theme_SubSettings);
502 }
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700503 }
504
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700505 setContentView(mIsShowingDashboard ?
506 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800507
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700508 mContent = (ViewGroup) findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700509
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800510 getFragmentManager().addOnBackStackChangedListener(this);
511
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700512 if (mIsShowingDashboard) {
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800513 // Run the Index update only if we have some space
514 if (!Utils.isLowStorage(this)) {
Jason Monkfd2c7222015-12-02 15:38:38 -0500515 long indexStartTime = System.currentTimeMillis();
516 AsyncTask.execute(new Runnable() {
517 @Override
518 public void run() {
519 Index.getInstance(getApplicationContext()).update();
520 }
521 });
522 if (DEBUG_TIMING) Log.d(LOG_TAG, "Index.update() took "
523 + (System.currentTimeMillis() - indexStartTime) + " ms");
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800524 } else {
525 Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
526 }
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700527 }
528
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700529 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700530 // We are restarting from a previous saved state; used that to initialize, instead
531 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700532 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
533 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800534
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700535 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800536
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700537 ArrayList<DashboardCategory> categories =
538 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
539 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700540 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700541 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700542 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800543 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700544
545 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700546 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700547 mHomeActivitiesCount = savedState.getInt(SAVE_KEY_HOME_ACTIVITIES_COUNT,
548 1 /* one home activity by default */);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800549 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700550 if (!mIsShowingDashboard) {
Jason Monkea8b1a72015-06-02 16:46:34 -0400551 mDisplaySearch = false;
552 // UP will be shown only if it is a sub settings
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700553 if (mIsShortcut) {
554 mDisplayHomeAsUpEnabled = isSubSettings;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700555 } else if (isSubSettings) {
556 mDisplayHomeAsUpEnabled = true;
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700557 } else {
558 mDisplayHomeAsUpEnabled = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700559 }
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700560 setTitleFromIntent(intent);
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700561
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700562 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700563 switchToFragment(initialFragmentName, initialArguments, true, false,
564 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000565 } else {
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700566 // No UP affordance if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700567 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700568 // Show Search affordance
569 mDisplaySearch = true;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700570 mInitialTitleResId = R.string.dashboard_title;
Fabrice Di Meglio42c4b0a2014-05-22 10:30:03 -0700571 switchToFragment(DashboardSummary.class.getName(), null, false, false,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700572 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800573 }
574 }
575
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700576 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700577 if (mActionBar != null) {
578 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
579 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
580 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700581 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
582
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800583 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800584 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
585
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700586 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800587 if (buttonBar != null) {
588 buttonBar.setVisibility(View.VISIBLE);
589
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700590 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800591 backButton.setOnClickListener(new OnClickListener() {
592 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700593 setResult(RESULT_CANCELED, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800594 finish();
595 }
596 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700597 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800598 skipButton.setOnClickListener(new OnClickListener() {
599 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700600 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800601 finish();
602 }
603 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700604 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800605 mNextButton.setOnClickListener(new OnClickListener() {
606 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700607 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800608 finish();
609 }
610 });
611
612 // set our various button parameters
613 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
614 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
615 if (TextUtils.isEmpty(buttonText)) {
616 mNextButton.setVisibility(View.GONE);
617 }
618 else {
619 mNextButton.setText(buttonText);
620 }
621 }
622 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
623 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
624 if (TextUtils.isEmpty(buttonText)) {
625 backButton.setVisibility(View.GONE);
626 }
627 else {
628 backButton.setText(buttonText);
629 }
630 }
631 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
632 skipButton.setVisibility(View.VISIBLE);
633 }
634 }
635 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700636
637 mHomeActivitiesCount = getHomeActivitiesCount();
Jason Monkfd2c7222015-12-02 15:38:38 -0500638 if (DEBUG_TIMING) Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
639 + " ms");
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700640 }
641
642 private int getHomeActivitiesCount() {
643 final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>();
644 getPackageManager().getHomeActivities(homeApps);
645 return homeApps.size();
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800646 }
647
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700648 private void setTitleFromIntent(Intent intent) {
649 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
650 if (initialTitleResId > 0) {
651 mInitialTitle = null;
652 mInitialTitleResId = initialTitleResId;
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100653
654 final String initialTitleResPackageName = intent.getStringExtra(
655 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
656 if (initialTitleResPackageName != null) {
657 try {
658 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
659 0 /* flags */, new UserHandle(UserHandle.myUserId()));
660 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
661 setTitle(mInitialTitle);
662 mInitialTitleResId = -1;
663 return;
664 } catch (NameNotFoundException e) {
665 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
666 }
667 } else {
668 setTitle(mInitialTitleResId);
669 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700670 } else {
671 mInitialTitleResId = -1;
672 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
673 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
674 setTitle(mInitialTitle);
675 }
676 }
677
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800678 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800679 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700680 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800681 }
682
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700683 private int setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800684 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700685
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800686 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700687 if (mInitialTitleResId > 0) {
688 setTitle(mInitialTitleResId);
689 } else {
690 setTitle(mInitialTitle);
691 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700692 return 0;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800693 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700694
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800695 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
696 setTitleFromBackStackEntry(bse);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700697
698 return count;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800699 }
700
701 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
702 final CharSequence title;
703 final int titleRes = bse.getBreadCrumbTitleRes();
704 if (titleRes > 0) {
705 title = getText(titleRes);
706 } else {
707 title = bse.getBreadCrumbTitle();
708 }
709 if (title != null) {
710 setTitle(title);
711 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800712 }
713
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800714 @Override
715 protected void onSaveInstanceState(Bundle outState) {
716 super.onSaveInstanceState(outState);
717
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700718 if (mCategories.size() > 0) {
719 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800720 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700721
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700722 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700723 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700724
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700725 if (mDisplaySearch) {
726 // The option menus are created if the ActionBar is visible and they are also created
727 // asynchronously. If you launch Settings with an Intent action like
728 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
729 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
730 // menu item and search view are null.
731 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
732 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700733
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700734 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
735 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
736 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700737
738 outState.putInt(SAVE_KEY_HOME_ACTIVITIES_COUNT, mHomeActivitiesCount);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800739 }
740
741 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400742 protected void onResume() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800743 super.onResume();
744
745 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
746 @Override
747 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Jason Monk4da79e02015-09-10 10:54:36 -0400748 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800749 }
750 };
751 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
752 mDevelopmentPreferencesListener);
753
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800754 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Svetoslav853e4712014-04-14 10:10:25 -0700755
Svetoslav990159a2014-04-14 17:14:59 -0700756 mDynamicIndexableContentMonitor.register(this);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700757
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700758 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700759 onQueryTextSubmit(mSearchQuery);
760 }
Jason Monk4da79e02015-09-10 10:54:36 -0400761 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800762 }
763
764 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400765 protected void onPause() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800766 super.onPause();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800767 unregisterReceiver(mBatteryInfoReceiver);
Svetoslav990159a2014-04-14 17:14:59 -0700768 mDynamicIndexableContentMonitor.unregister();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800769 }
770
771 @Override
772 public void onDestroy() {
773 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700774
775 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
776 mDevelopmentPreferencesListener);
777 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800778 }
779
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800780 protected boolean isValidFragment(String fragmentName) {
781 // Almost all fragments are wrapped in this,
782 // except for a few that have their own activities.
783 for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
784 if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
785 }
786 return false;
787 }
788
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800789 @Override
790 public Intent getIntent() {
791 Intent superIntent = super.getIntent();
792 String startingFragment = getStartingFragmentClass(superIntent);
793 // This is called from super.onCreate, isMultiPane() is not yet reliable
794 // Do not use onIsHidingHeaders either, which relies itself on this method
795 if (startingFragment != null) {
796 Intent modIntent = new Intent(superIntent);
797 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
798 Bundle args = superIntent.getExtras();
799 if (args != null) {
800 args = new Bundle(args);
801 } else {
802 args = new Bundle();
803 }
804 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100805 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800806 return modIntent;
807 }
808 return superIntent;
809 }
810
811 /**
812 * Checks if the component name in the intent is different from the Settings class and
813 * returns the class name to load as a fragment.
814 */
815 private String getStartingFragmentClass(Intent intent) {
816 if (mFragmentClass != null) return mFragmentClass;
817
818 String intentClass = intent.getComponent().getClassName();
819 if (intentClass.equals(getClass().getName())) return null;
820
821 if ("com.android.settings.ManageApplications".equals(intentClass)
822 || "com.android.settings.RunningServices".equals(intentClass)
823 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
824 // Old names of manage apps.
825 intentClass = com.android.settings.applications.ManageApplications.class.getName();
826 }
827
828 return intentClass;
829 }
830
831 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000832 * Start a new fragment containing a preference panel. If the preferences
833 * are being displayed in multi-pane mode, the given fragment class will
834 * be instantiated and placed in the appropriate pane. If running in
835 * single-pane mode, a new activity will be launched in which to show the
836 * fragment.
837 *
838 * @param fragmentClass Full name of the class implementing the fragment.
839 * @param args Any desired arguments to supply to the fragment.
840 * @param titleRes Optional resource identifier of the title of this
841 * fragment.
842 * @param titleText Optional text of the title of this fragment.
843 * @param resultTo Optional fragment that result data should be sent to.
844 * If non-null, resultTo.onActivityResult() will be called when this
845 * preference panel is done. The launched panel must use
846 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
847 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700848 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000849 */
850 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700851 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700852 String title = null;
853 if (titleRes < 0) {
854 if (titleText != null) {
855 title = titleText.toString();
856 } else {
857 // There not much we can do in that case
858 title = "";
859 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700860 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700861 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700862 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000863 }
864
865 /**
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100866 * Start a new fragment in a new activity containing a preference panel for a given user. If the
867 * preferences are being displayed in multi-pane mode, the given fragment class will be
868 * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
869 * activity will be launched in which to show the fragment.
870 *
871 * @param fragmentClass Full name of the class implementing the fragment.
872 * @param args Any desired arguments to supply to the fragment.
873 * @param titleRes Optional resource identifier of the title of this fragment.
874 * @param titleText Optional text of the title of this fragment.
875 * @param userHandle The user for which the panel has to be started.
876 */
877 public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
878 CharSequence titleText, UserHandle userHandle) {
Lifu Tangd0332852015-04-02 12:05:46 -0700879 // This is a workaround.
880 //
881 // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
882 // starting the fragment could cause a native stack corruption. See b/17523189. However,
883 // adding that flag and start the preference panel with the same UserHandler will make it
884 // impossible to use back button to return to the previous screen. See b/20042570.
885 //
886 // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
887 // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
888 // when we're calling it as the same user.
889 if (userHandle.getIdentifier() == UserHandle.myUserId()) {
890 startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0);
891 } else {
892 String title = null;
893 if (titleRes < 0) {
894 if (titleText != null) {
895 title = titleText.toString();
896 } else {
897 // There not much we can do in that case
898 title = "";
899 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100900 }
Lifu Tangd0332852015-04-02 12:05:46 -0700901 Utils.startWithFragmentAsUser(this, fragmentClass, args,
902 titleRes, title, mIsShortcut, userHandle);
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100903 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100904 }
905
906 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800907 * Called by a preference panel fragment to finish itself.
908 *
909 * @param caller The fragment that is asking to be finished.
910 * @param resultCode Optional result code to send back to the original
911 * launching fragment.
912 * @param resultData Optional result data to send back to the original
913 * launching fragment.
914 */
915 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
916 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700917 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800918 }
919
920 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000921 * Start a new fragment.
922 *
923 * @param fragment The fragment to start
924 * @param push If true, the current fragment will be pushed onto the back stack. If false,
925 * the current fragment will be replaced.
926 */
927 public void startPreferenceFragment(Fragment fragment, boolean push) {
928 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700929 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000930 if (push) {
931 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
932 transaction.addToBackStack(BACK_STACK_PREFS);
933 } else {
934 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
935 }
936 transaction.commitAllowingStateLoss();
937 }
938
939 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700940 * Switch to a specific Fragment with taking care of validation, Title and BackStack
941 */
942 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700943 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700944 if (validate && !isValidFragment(fragmentName)) {
945 throw new IllegalArgumentException("Invalid fragment for this activity: "
946 + fragmentName);
947 }
948 Fragment f = Fragment.instantiate(this, fragmentName, args);
949 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700950 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700951 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700952 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700953 }
954 if (addToBackStack) {
955 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
956 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700957 if (titleResId > 0) {
958 transaction.setBreadCrumbTitle(titleResId);
959 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700960 transaction.setBreadCrumbTitle(title);
961 }
962 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700963 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700964 return f;
965 }
966
Jason Monk4da79e02015-09-10 10:54:36 -0400967 private void updateTilesList() {
Jason Monkfd2c7222015-12-02 15:38:38 -0500968 // Generally the items that are will be changing from these updates will
969 // not be in the top list of tiles, so run it in the background and the
970 // SettingsDrawerActivity will pick up on the updates automatically.
971 AsyncTask.execute(new Runnable() {
972 @Override
973 public void run() {
974 doUpdateTilesList();
975 }
976 });
977 }
978
979 private void doUpdateTilesList() {
Jason Monk4da79e02015-09-10 10:54:36 -0400980 PackageManager pm = getPackageManager();
Xiaohui Chen44879a32015-07-22 13:53:22 -0700981 final UserManager um = UserManager.get(this);
982 final boolean isAdmin = um.isAdminUser();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700983
Jason Monk4da79e02015-09-10 10:54:36 -0400984 String packageName = getPackageName();
985 setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()),
986 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700987
Jason Monk4da79e02015-09-10 10:54:36 -0400988 setTileEnabled(new ComponentName(packageName,
989 Settings.BluetoothSettingsActivity.class.getName()),
990 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700991
Jason Monk4da79e02015-09-10 10:54:36 -0400992 setTileEnabled(new ComponentName(packageName,
993 Settings.DataUsageSummaryActivity.class.getName()),
994 Utils.isBandwidthControlEnabled(), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700995
Jason Monk4da79e02015-09-10 10:54:36 -0400996 setTileEnabled(new ComponentName(packageName,
997 Settings.SimSettingsActivity.class.getName()),
998 Utils.showSimCardTile(this), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700999
Jason Monk4da79e02015-09-10 10:54:36 -04001000 setTileEnabled(new ComponentName(packageName,
1001 Settings.PowerUsageSummaryActivity.class.getName()),
1002 mBatteryPresent, isAdmin, pm);
1003
1004 setTileEnabled(new ComponentName(packageName,
1005 Settings.HomeSettingsActivity.class.getName()),
1006 updateHomeSettingTiles(), isAdmin, pm);
1007
1008 setTileEnabled(new ComponentName(packageName,
1009 Settings.UserSettingsActivity.class.getName()),
1010 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
1011 && !Utils.isMonkeyRunning(), isAdmin, pm);
1012
1013 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
1014 setTileEnabled(new ComponentName(packageName,
1015 Settings.PaymentSettingsActivity.class.getName()),
1016 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
1017 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
1018 && adapter != null && adapter.isEnabled(), isAdmin, pm);
1019
1020 setTileEnabled(new ComponentName(packageName,
1021 Settings.PrintSettingsActivity.class.getName()),
1022 pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin, pm);
1023
1024 final boolean showDev = mDevelopmentPreferences.getBoolean(
1025 DevelopmentSettings.PREF_SHOW,
1026 android.os.Build.TYPE.equals("eng"));
1027 setTileEnabled(new ComponentName(packageName,
1028 Settings.DevelopmentSettingsActivity.class.getName()),
1029 showDev && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES),
1030 isAdmin, pm);
1031
1032 if (UserHandle.MU_ENABLED && !isAdmin) {
1033 // When on restricted users, disable all extra categories (but only the settings ones).
Jason Monkfd2c7222015-12-02 15:38:38 -05001034 List<DashboardCategory> categories = getDashboardCategories();
Jason Monk4da79e02015-09-10 10:54:36 -04001035 for (DashboardCategory category : categories) {
Jason Monkd4f03ec2016-01-07 16:25:34 -05001036 for (Tile tile : category.tiles) {
Jason Monk4da79e02015-09-10 10:54:36 -04001037 ComponentName component = tile.intent.getComponent();
1038 if (packageName.equals(component)&& !ArrayUtils.contains(
1039 SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1040 setTileEnabled(component, false, isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001041 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001042 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001043 }
1044 }
Jason Monk2ebc8a02015-02-13 15:23:19 -05001045 }
1046
Jason Monk4da79e02015-09-10 10:54:36 -04001047 private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin,
1048 PackageManager pm) {
1049 if (UserHandle.MU_ENABLED && !isAdmin
1050 && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1051 enabled = false;
1052 }
1053 int state = pm.getComponentEnabledSetting(component);
1054 boolean isEnabled = state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
1055 || state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
1056 if (isEnabled != enabled) {
1057 pm.setComponentEnabledSetting(component, enabled
1058 ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
1059 : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
1060 PackageManager.DONT_KILL_APP);
Jason Monk2ebc8a02015-02-13 15:23:19 -05001061 }
1062 }
1063
Jason Monk4da79e02015-09-10 10:54:36 -04001064 private boolean updateHomeSettingTiles() {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001065 // Once we decide to show Home settings, keep showing it forever
1066 SharedPreferences sp = getSharedPreferences(HomeSettings.HOME_PREFS, Context.MODE_PRIVATE);
1067 if (sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false)) {
1068 return true;
1069 }
1070
1071 try {
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -07001072 mHomeActivitiesCount = getHomeActivitiesCount();
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -07001073 if (mHomeActivitiesCount < 2) {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001074 return false;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001075 }
1076 } catch (Exception e) {
1077 // Can't look up the home activity; bail on configuring the icon
1078 Log.w(LOG_TAG, "Problem looking up home activity!", e);
1079 }
1080
1081 sp.edit().putBoolean(HomeSettings.HOME_PREFS_DO_SHOW, true).apply();
1082 return true;
1083 }
1084
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001085 private void getMetaData() {
1086 try {
1087 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1088 PackageManager.GET_META_DATA);
1089 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001090 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1091 } catch (NameNotFoundException nnfe) {
1092 // No recovery
1093 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1094 }
1095 }
1096
1097 // give subclasses access to the Next button
1098 public boolean hasNextButton() {
1099 return mNextButton != null;
1100 }
1101
1102 public Button getNextButton() {
1103 return mNextButton;
1104 }
1105
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001106 @Override
1107 public boolean shouldUpRecreateTask(Intent targetIntent) {
1108 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1109 }
1110
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001111 @Override
1112 public boolean onQueryTextSubmit(String query) {
1113 switchToSearchResultsFragmentIfNeeded();
1114 mSearchQuery = query;
1115 return mSearchResultsFragment.onQueryTextSubmit(query);
1116 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001117
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001118 @Override
1119 public boolean onQueryTextChange(String newText) {
1120 mSearchQuery = newText;
Fabrice Di Meglio7e4855e2014-05-23 16:03:43 -07001121 if (mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001122 return false;
1123 }
1124 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001125 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001126
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001127 @Override
1128 public boolean onClose() {
1129 return false;
1130 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001131
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001132 @Override
1133 public boolean onMenuItemActionExpand(MenuItem item) {
1134 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001135 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001136 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001137 return true;
1138 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001139
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001140 @Override
1141 public boolean onMenuItemActionCollapse(MenuItem item) {
1142 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001143 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001144 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001145 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001146 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001147 return true;
1148 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001149
Jason Monk4da79e02015-09-10 10:54:36 -04001150 @Override
Jason Monkd4f03ec2016-01-07 16:25:34 -05001151 protected void onTileClicked(Tile tile) {
Jason Monk4da79e02015-09-10 10:54:36 -04001152 if (mIsShowingDashboard) {
1153 // If on dashboard, don't finish so the back comes back to here.
1154 openTile(tile);
1155 } else {
1156 super.onTileClicked(tile);
1157 }
1158 }
1159
Jason Monkaf001092015-11-04 13:16:18 -05001160 @Override
1161 public void onProfileTileOpen() {
1162 if (!mIsShowingDashboard) {
1163 finish();
1164 }
1165 }
1166
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001167 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001168 if (mSearchResultsFragment != null) {
1169 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001170 }
Fabrice Di Megliod40dd452014-07-18 15:20:34 -07001171 Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001172 if (current != null && current instanceof SearchResultsSummary) {
1173 mSearchResultsFragment = (SearchResultsSummary) current;
1174 } else {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001175 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001176 SearchResultsSummary.class.getName(), null, false, true,
1177 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001178 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001179 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001180 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001181 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001182
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001183 public void needToRevertToInitialFragment() {
1184 mNeedToRevertToInitialFragment = true;
1185 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001186
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001187 private void revertToInitialFragment() {
1188 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001189 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001190 mSearchMenuItemExpanded = false;
1191 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1192 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001193 if (mSearchMenuItem != null) {
1194 mSearchMenuItem.collapseActionView();
1195 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001196 }
Jim Miller0698a212014-10-16 19:49:07 -07001197
1198 public Intent getResultIntentData() {
1199 return mResultIntentData;
1200 }
1201
1202 public void setResultIntentData(Intent resultIntentData) {
1203 mResultIntentData = resultIntentData;
1204 }
Jason Monkd4f03ec2016-01-07 16:25:34 -05001205
1206 public void startSuggestion(Intent intent) {
1207 mCurrentSuggestion = intent.getComponent();
1208 startActivityForResult(intent, REQUEST_SUGGESTION);
1209 }
1210
1211 @Override
1212 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
1213 if (requestCode == REQUEST_SUGGESTION && mCurrentSuggestion != null
1214 && resultCode != RESULT_CANCELED) {
1215 getPackageManager().setComponentEnabledSetting(mCurrentSuggestion,
1216 PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
1217 }
1218 super.onActivityResult(requestCode, resultCode, data);
1219 }
1220
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001221}