blob: dab2cb7607c8cb16c615cc6dd656aed48b7c05ac [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;
Jason Monkb37e2882016-01-11 14:27:20 -050071import com.android.settings.datausage.DataUsageSummary;
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;
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;
Jason Monkb37e2882016-01-11 14:27:20 -050091import com.android.settings.notification.SoundSettings;
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;
Jason Monkd4f03ec2016-01-07 16:25:34 -0500114import com.android.settingslib.drawer.Tile;
Jason Monk4da79e02015-09-10 10:54:36 -0400115import 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
Jason Monkd4f03ec2016-01-07 16:25:34 -0500202 private static final int REQUEST_SUGGESTION = 42;
203
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800204 private String mFragmentClass;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800205
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800206 private CharSequence mInitialTitle;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700207 private int mInitialTitleResId;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800208
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800209 // Show only these settings for restricted users
Jason Monk4da79e02015-09-10 10:54:36 -0400210 private String[] SETTINGS_FOR_RESTRICTED = {
211 //wireless_section
212 WifiSettingsActivity.class.getName(),
213 Settings.BluetoothSettingsActivity.class.getName(),
214 Settings.DataUsageSummaryActivity.class.getName(),
215 Settings.SimSettingsActivity.class.getName(),
216 Settings.WirelessSettingsActivity.class.getName(),
217 //device_section
218 Settings.HomeSettingsActivity.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500219 Settings.SoundSettingsActivity.class.getName(),
Jason Monk4da79e02015-09-10 10:54:36 -0400220 Settings.DisplaySettingsActivity.class.getName(),
221 Settings.StorageSettingsActivity.class.getName(),
222 Settings.ManageApplicationsActivity.class.getName(),
223 Settings.PowerUsageSummaryActivity.class.getName(),
224 //personal_section
225 Settings.LocationSettingsActivity.class.getName(),
226 Settings.SecuritySettingsActivity.class.getName(),
227 Settings.InputMethodAndLanguageSettingsActivity.class.getName(),
228 Settings.UserSettingsActivity.class.getName(),
229 Settings.AccountSettingsActivity.class.getName(),
230 //system_section
231 Settings.DateTimeSettingsActivity.class.getName(),
232 Settings.DeviceInfoSettingsActivity.class.getName(),
233 Settings.AccessibilitySettingsActivity.class.getName(),
234 Settings.PrintSettingsActivity.class.getName(),
235 Settings.PaymentSettingsActivity.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800236 };
237
238 private static final String[] ENTRY_FRAGMENTS = {
239 WirelessSettings.class.getName(),
240 WifiSettings.class.getName(),
241 AdvancedWifiSettings.class.getName(),
PauloftheWest7837b992014-06-24 07:42:27 -0700242 SavedAccessPointsWifiSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800243 BluetoothSettings.class.getName(),
PauloftheWest38155612014-06-30 10:02:36 -0700244 SimSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800245 TetherSettings.class.getName(),
246 WifiP2pSettings.class.getName(),
247 VpnSettings.class.getName(),
248 DateTimeSettings.class.getName(),
249 LocalePicker.class.getName(),
250 InputMethodAndLanguageSettings.class.getName(),
251 SpellCheckersSettings.class.getName(),
252 UserDictionaryList.class.getName(),
253 UserDictionarySettings.class.getName(),
Amith Yamasani3033ce02014-07-14 18:03:15 -0700254 HomeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800255 DisplaySettings.class.getName(),
256 DeviceInfoSettings.class.getName(),
257 ManageApplications.class.getName(),
Xiyuan Xia86a55402015-06-02 14:55:32 -0700258 ManageAssist.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800259 ProcessStatsUi.class.getName(),
260 NotificationStation.class.getName(),
261 LocationSettings.class.getName(),
262 SecuritySettings.class.getName(),
Jason Monkd8da51c2015-04-17 14:34:12 -0400263 UsageAccessDetails.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800264 PrivacySettings.class.getName(),
265 DeviceAdminSettings.class.getName(),
266 AccessibilitySettings.class.getName(),
267 CaptionPropertiesFragment.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800268 com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(),
269 TextToSpeechSettings.class.getName(),
Jeff Sharkey42833b22015-04-11 21:27:33 -0700270 StorageSettings.class.getName(),
Jeff Sharkeya16257d2015-04-28 13:41:01 -0700271 PrivateVolumeForget.class.getName(),
Jeff Sharkeye77f0682015-04-29 11:24:57 -0700272 PrivateVolumeSettings.class.getName(),
273 PublicVolumeSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800274 DevelopmentSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800275 AndroidBeam.class.getName(),
276 WifiDisplaySettings.class.getName(),
277 PowerUsageSummary.class.getName(),
278 AccountSyncSettings.class.getName(),
Alexandra Gherghina6d839872014-07-22 12:04:58 +0000279 AccountSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800280 CryptKeeperSettings.class.getName(),
281 DataUsageSummary.class.getName(),
282 DreamSettings.class.getName(),
283 UserSettings.class.getName(),
284 NotificationAccessSettings.class.getName(),
John Spurlock08531a82015-05-07 17:45:43 -0400285 ZenAccessSettings.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800286 PrintSettingsFragment.class.getName(),
287 PrintJobSettingsFragment.class.getName(),
288 TrustedCredentialsSettings.class.getName(),
289 PaymentSettings.class.getName(),
290 KeyboardLayoutPickerFragment.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700291 ZenModeSettings.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500292 SoundSettings.class.getName(),
293 ConfigureNotificationSettings.class.getName(),
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700294 ChooseLockPassword.ChooseLockPasswordFragment.class.getName(),
295 ChooseLockPattern.ChooseLockPatternFragment.class.getName(),
John Spurlockc7f8e8c2014-06-04 19:11:22 -0400296 InstalledAppDetails.class.getName(),
297 BatterySaverSettings.class.getName(),
Fabrice Di Megliodcf59dd2014-07-21 11:22:20 -0700298 AppNotificationSettings.class.getName(),
Fabrice Di Meglioe3ff4d82014-07-23 20:03:20 -0700299 OtherSoundSettings.class.getName(),
Narayan Kamath33acb152015-03-16 12:48:05 +0000300 ApnSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400301 WifiCallingSettings.class.getName(),
John Spurlockc1df2aa2015-04-13 20:57:06 -0400302 ZenModePrioritySettings.class.getName(),
John Spurlock533a5662015-06-19 10:47:36 -0400303 ZenModeAutomationSettings.class.getName(),
John Spurlock45fa1402015-04-09 12:50:04 -0400304 ZenModeScheduleRuleSettings.class.getName(),
John Spurlockf57bad72015-04-30 09:26:15 -0400305 ZenModeEventRuleSettings.class.getName(),
Julia Reynolds5555d262015-11-09 10:52:17 -0500306 ZenModeVisualInterruptionSettings.class.getName(),
Jason Monk2583fc12015-03-25 09:46:30 -0400307 ProcessStatsUi.class.getName(),
Jason Monk1eb54eb2015-04-29 12:46:42 -0400308 PowerUsageDetail.class.getName(),
Jason Monk2cdafc62015-06-12 12:32:50 -0400309 ProcessStatsSummary.class.getName(),
Billy Laufee78562015-07-27 12:57:07 +0100310 DrawOverlayDetails.class.getName(),
311 WriteSettingsDetails.class.getName(),
Julia Reynolds2e1e0b72015-12-14 08:32:46 -0500312 ManageDefaultApps.class.getName(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800313 };
314
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700315
316 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
317 "android.settings.APPLICATION_DETAILS_SETTINGS"
318 };
319
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800320 private SharedPreferences mDevelopmentPreferences;
321 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
322
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800323 private boolean mBatteryPresent = true;
324 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800325 @Override
326 public void onReceive(Context context, Intent intent) {
327 String action = intent.getAction();
328 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
329 boolean batteryPresent = Utils.isBatteryPresent(intent);
330
331 if (mBatteryPresent != batteryPresent) {
332 mBatteryPresent = batteryPresent;
Jason Monk4da79e02015-09-10 10:54:36 -0400333 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800334 }
335 }
336 }
337 };
338
Clara Bayarri6934a042015-10-14 11:07:35 +0100339 private final BroadcastReceiver mUserAddRemoveReceiver = new BroadcastReceiver() {
340 @Override
341 public void onReceive(Context context, Intent intent) {
342 String action = intent.getAction();
343 if (action.equals(Intent.ACTION_USER_ADDED)
344 || action.equals(Intent.ACTION_USER_REMOVED)) {
345 Index.getInstance(getApplicationContext()).update();
346 }
347 }
348 };
349
Svetoslav990159a2014-04-14 17:14:59 -0700350 private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor =
351 new DynamicIndexableContentMonitor();
Svetoslav853e4712014-04-14 10:10:25 -0700352
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700353 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700354 private SwitchBar mSwitchBar;
355
356 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700357
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700358 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700359 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700360
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700361 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700362 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700363
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700364 private ViewGroup mContent;
365
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700366 private SearchView mSearchView;
367 private MenuItem mSearchMenuItem;
368 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700369 private SearchResultsSummary mSearchResultsFragment;
370 private String mSearchQuery;
371
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700372 // Categories
373 private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800374
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -0700375 private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800376
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700377 private boolean mNeedToRevertToInitialFragment = false;
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700378 private int mHomeActivitiesCount = 1;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700379
Jim Miller0698a212014-10-16 19:49:07 -0700380 private Intent mResultIntentData;
Jason Monkd4f03ec2016-01-07 16:25:34 -0500381 private ComponentName mCurrentSuggestion;
Jim Miller0698a212014-10-16 19:49:07 -0700382
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700383 public SwitchBar getSwitchBar() {
384 return mSwitchBar;
385 }
386
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800387 @Override
388 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
389 // Override the fragment title for Wallpaper settings
Jason Monk39b46742015-09-10 15:52:51 -0400390 CharSequence title = pref.getTitle();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800391 if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) {
Jason Monk39b46742015-09-10 15:52:51 -0400392 title = getString(R.string.wallpaper_settings_fragment_title);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800393 }
Jason Monkb1dd5c92015-12-16 16:13:54 -0500394 startPreferencePanel(pref.getFragment(), pref.getExtras(), -1, title,
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800395 null, 0);
396 return true;
397 }
398
399 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400400 public boolean onPreferenceTreeClick(Preference preference) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800401 return false;
402 }
403
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800404 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800405 public void onConfigurationChanged(Configuration newConfig) {
406 super.onConfigurationChanged(newConfig);
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800407 Index.getInstance(this).update();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800408 }
409
410 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700411 protected void onStart() {
412 super.onStart();
413
414 if (mNeedToRevertToInitialFragment) {
415 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800416 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800417 }
418
419 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700420 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700421 if (!mDisplaySearch) {
422 return false;
423 }
424
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700425 MenuInflater inflater = getMenuInflater();
426 inflater.inflate(R.menu.options_menu, menu);
427
428 // Cache the search query (can be overriden by the OnQueryTextListener)
429 final String query = mSearchQuery;
430
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700431 mSearchMenuItem = menu.findItem(R.id.search);
432 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700433
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700434 if (mSearchMenuItem == null || mSearchView == null) {
435 return false;
436 }
437
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700438 if (mSearchResultsFragment != null) {
439 mSearchResultsFragment.setSearchView(mSearchView);
440 }
441
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700442 mSearchMenuItem.setOnActionExpandListener(this);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700443 mSearchView.setOnQueryTextListener(this);
444 mSearchView.setOnCloseListener(this);
445
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700446 if (mSearchMenuItemExpanded) {
447 mSearchMenuItem.expandActionView();
448 }
449 mSearchView.setQuery(query, true /* submit */);
450
451 return true;
452 }
453
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700454 private static boolean isShortCutIntent(final Intent intent) {
455 Set<String> categories = intent.getCategories();
456 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
457 }
458
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700459 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700460 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700461 if (action == null) {
462 return false;
463 }
464 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
465 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
466 }
467 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700468 }
469
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700470 @Override
471 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700472 super.onCreate(savedState);
Jason Monkfd2c7222015-12-02 15:38:38 -0500473 long startTime = System.currentTimeMillis();
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700474
475 // Should happen before any call to getIntent()
476 getMetaData();
477
478 final Intent intent = getIntent();
479 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
480 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800481 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800482
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800483 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
484 Context.MODE_PRIVATE);
485
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700486 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700487 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700488
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700489 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700490 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
491
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700492 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700493 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700494
Jason Monk4da79e02015-09-10 10:54:36 -0400495 mIsShowingDashboard = className.equals(Settings.class.getName())
496 || className.equals(Settings.WirelessSettings.class.getName())
497 || className.equals(Settings.DeviceSettings.class.getName())
498 || className.equals(Settings.PersonalSettings.class.getName())
499 || className.equals(Settings.WirelessSettings.class.getName());
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700500
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700501 // This is a "Sub Settings" when:
502 // - this is a real SubSettings
503 // - or :settings:show_fragment_as_subsetting is passed to the Intent
Jorim Jaggi4dfcb822015-04-29 17:21:32 -0700504 final boolean isSubSettings = this instanceof SubSettings ||
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700505 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
506
507 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
508 if (isSubSettings) {
Fabrice Di Meglio712df6c2014-07-18 17:44:37 -0700509 // Check also that we are not a Theme Dialog as we don't want to override them
510 final int themeResId = getThemeResId();
511 if (themeResId != R.style.Theme_DialogWhenLarge &&
512 themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
513 setTheme(R.style.Theme_SubSettings);
514 }
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700515 }
516
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700517 setContentView(mIsShowingDashboard ?
518 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800519
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700520 mContent = (ViewGroup) findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700521
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800522 getFragmentManager().addOnBackStackChangedListener(this);
523
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700524 if (mIsShowingDashboard) {
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800525 // Run the Index update only if we have some space
526 if (!Utils.isLowStorage(this)) {
Jason Monkfd2c7222015-12-02 15:38:38 -0500527 long indexStartTime = System.currentTimeMillis();
528 AsyncTask.execute(new Runnable() {
529 @Override
530 public void run() {
531 Index.getInstance(getApplicationContext()).update();
532 }
533 });
534 if (DEBUG_TIMING) Log.d(LOG_TAG, "Index.update() took "
535 + (System.currentTimeMillis() - indexStartTime) + " ms");
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800536 } else {
537 Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
538 }
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700539 }
540
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700541 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700542 // We are restarting from a previous saved state; used that to initialize, instead
543 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700544 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
545 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800546
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700547 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800548
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700549 ArrayList<DashboardCategory> categories =
550 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
551 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700552 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700553 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700554 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800555 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700556
557 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700558 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700559 mHomeActivitiesCount = savedState.getInt(SAVE_KEY_HOME_ACTIVITIES_COUNT,
560 1 /* one home activity by default */);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800561 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700562 if (!mIsShowingDashboard) {
Jason Monkea8b1a72015-06-02 16:46:34 -0400563 mDisplaySearch = false;
564 // UP will be shown only if it is a sub settings
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700565 if (mIsShortcut) {
566 mDisplayHomeAsUpEnabled = isSubSettings;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700567 } else if (isSubSettings) {
568 mDisplayHomeAsUpEnabled = true;
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700569 } else {
570 mDisplayHomeAsUpEnabled = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700571 }
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700572 setTitleFromIntent(intent);
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700573
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700574 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700575 switchToFragment(initialFragmentName, initialArguments, true, false,
576 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000577 } else {
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700578 // No UP affordance if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700579 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700580 // Show Search affordance
581 mDisplaySearch = true;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700582 mInitialTitleResId = R.string.dashboard_title;
Fabrice Di Meglio42c4b0a2014-05-22 10:30:03 -0700583 switchToFragment(DashboardSummary.class.getName(), null, false, false,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700584 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800585 }
586 }
587
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700588 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700589 if (mActionBar != null) {
590 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
591 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
592 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700593 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
594
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800595 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800596 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
597
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700598 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800599 if (buttonBar != null) {
600 buttonBar.setVisibility(View.VISIBLE);
601
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700602 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800603 backButton.setOnClickListener(new OnClickListener() {
604 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700605 setResult(RESULT_CANCELED, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800606 finish();
607 }
608 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700609 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800610 skipButton.setOnClickListener(new OnClickListener() {
611 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700612 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800613 finish();
614 }
615 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700616 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800617 mNextButton.setOnClickListener(new OnClickListener() {
618 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700619 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800620 finish();
621 }
622 });
623
624 // set our various button parameters
625 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
626 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
627 if (TextUtils.isEmpty(buttonText)) {
628 mNextButton.setVisibility(View.GONE);
629 }
630 else {
631 mNextButton.setText(buttonText);
632 }
633 }
634 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
635 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
636 if (TextUtils.isEmpty(buttonText)) {
637 backButton.setVisibility(View.GONE);
638 }
639 else {
640 backButton.setText(buttonText);
641 }
642 }
643 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
644 skipButton.setVisibility(View.VISIBLE);
645 }
646 }
647 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700648
649 mHomeActivitiesCount = getHomeActivitiesCount();
Jason Monkfd2c7222015-12-02 15:38:38 -0500650 if (DEBUG_TIMING) Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
651 + " ms");
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700652 }
653
654 private int getHomeActivitiesCount() {
655 final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>();
656 getPackageManager().getHomeActivities(homeApps);
657 return homeApps.size();
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800658 }
659
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700660 private void setTitleFromIntent(Intent intent) {
661 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
662 if (initialTitleResId > 0) {
663 mInitialTitle = null;
664 mInitialTitleResId = initialTitleResId;
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100665
666 final String initialTitleResPackageName = intent.getStringExtra(
667 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
668 if (initialTitleResPackageName != null) {
669 try {
670 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
671 0 /* flags */, new UserHandle(UserHandle.myUserId()));
672 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
673 setTitle(mInitialTitle);
674 mInitialTitleResId = -1;
675 return;
676 } catch (NameNotFoundException e) {
677 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
678 }
679 } else {
680 setTitle(mInitialTitleResId);
681 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700682 } else {
683 mInitialTitleResId = -1;
684 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
685 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
686 setTitle(mInitialTitle);
687 }
688 }
689
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800690 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800691 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700692 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800693 }
694
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700695 private int setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800696 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700697
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800698 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700699 if (mInitialTitleResId > 0) {
700 setTitle(mInitialTitleResId);
701 } else {
702 setTitle(mInitialTitle);
703 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700704 return 0;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800705 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700706
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800707 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
708 setTitleFromBackStackEntry(bse);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700709
710 return count;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800711 }
712
713 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
714 final CharSequence title;
715 final int titleRes = bse.getBreadCrumbTitleRes();
716 if (titleRes > 0) {
717 title = getText(titleRes);
718 } else {
719 title = bse.getBreadCrumbTitle();
720 }
721 if (title != null) {
722 setTitle(title);
723 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800724 }
725
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800726 @Override
727 protected void onSaveInstanceState(Bundle outState) {
728 super.onSaveInstanceState(outState);
729
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700730 if (mCategories.size() > 0) {
731 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800732 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700733
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700734 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700735 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700736
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700737 if (mDisplaySearch) {
738 // The option menus are created if the ActionBar is visible and they are also created
739 // asynchronously. If you launch Settings with an Intent action like
740 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
741 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
742 // menu item and search view are null.
743 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
744 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700745
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700746 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
747 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
748 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700749
750 outState.putInt(SAVE_KEY_HOME_ACTIVITIES_COUNT, mHomeActivitiesCount);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800751 }
752
753 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400754 protected void onResume() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800755 super.onResume();
756
757 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
758 @Override
759 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Jason Monk4da79e02015-09-10 10:54:36 -0400760 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800761 }
762 };
763 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
764 mDevelopmentPreferencesListener);
765
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800766 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Clara Bayarri6934a042015-10-14 11:07:35 +0100767 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_ADDED));
768 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_REMOVED));
Svetoslav853e4712014-04-14 10:10:25 -0700769
Svetoslav990159a2014-04-14 17:14:59 -0700770 mDynamicIndexableContentMonitor.register(this);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700771
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700772 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700773 onQueryTextSubmit(mSearchQuery);
774 }
Jason Monk4da79e02015-09-10 10:54:36 -0400775 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800776 }
777
778 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400779 protected void onPause() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800780 super.onPause();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800781 unregisterReceiver(mBatteryInfoReceiver);
Clara Bayarri8c9521f2016-01-12 14:10:45 +0000782 unregisterReceiver(mUserAddRemoveReceiver);
Svetoslav990159a2014-04-14 17:14:59 -0700783 mDynamicIndexableContentMonitor.unregister();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800784 }
785
786 @Override
787 public void onDestroy() {
788 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700789
790 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
791 mDevelopmentPreferencesListener);
792 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800793 }
794
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800795 protected boolean isValidFragment(String fragmentName) {
796 // Almost all fragments are wrapped in this,
797 // except for a few that have their own activities.
798 for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) {
799 if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
800 }
801 return false;
802 }
803
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800804 @Override
805 public Intent getIntent() {
806 Intent superIntent = super.getIntent();
807 String startingFragment = getStartingFragmentClass(superIntent);
808 // This is called from super.onCreate, isMultiPane() is not yet reliable
809 // Do not use onIsHidingHeaders either, which relies itself on this method
810 if (startingFragment != null) {
811 Intent modIntent = new Intent(superIntent);
812 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
813 Bundle args = superIntent.getExtras();
814 if (args != null) {
815 args = new Bundle(args);
816 } else {
817 args = new Bundle();
818 }
819 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100820 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800821 return modIntent;
822 }
823 return superIntent;
824 }
825
826 /**
827 * Checks if the component name in the intent is different from the Settings class and
828 * returns the class name to load as a fragment.
829 */
830 private String getStartingFragmentClass(Intent intent) {
831 if (mFragmentClass != null) return mFragmentClass;
832
833 String intentClass = intent.getComponent().getClassName();
834 if (intentClass.equals(getClass().getName())) return null;
835
836 if ("com.android.settings.ManageApplications".equals(intentClass)
837 || "com.android.settings.RunningServices".equals(intentClass)
838 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
839 // Old names of manage apps.
840 intentClass = com.android.settings.applications.ManageApplications.class.getName();
841 }
842
843 return intentClass;
844 }
845
846 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000847 * Start a new fragment containing a preference panel. If the preferences
848 * are being displayed in multi-pane mode, the given fragment class will
849 * be instantiated and placed in the appropriate pane. If running in
850 * single-pane mode, a new activity will be launched in which to show the
851 * fragment.
852 *
853 * @param fragmentClass Full name of the class implementing the fragment.
854 * @param args Any desired arguments to supply to the fragment.
855 * @param titleRes Optional resource identifier of the title of this
856 * fragment.
857 * @param titleText Optional text of the title of this fragment.
858 * @param resultTo Optional fragment that result data should be sent to.
859 * If non-null, resultTo.onActivityResult() will be called when this
860 * preference panel is done. The launched panel must use
861 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
862 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700863 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000864 */
865 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700866 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700867 String title = null;
868 if (titleRes < 0) {
869 if (titleText != null) {
870 title = titleText.toString();
871 } else {
872 // There not much we can do in that case
873 title = "";
874 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700875 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700876 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700877 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000878 }
879
880 /**
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100881 * Start a new fragment in a new activity containing a preference panel for a given user. If the
882 * preferences are being displayed in multi-pane mode, the given fragment class will be
883 * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
884 * activity will be launched in which to show the fragment.
885 *
886 * @param fragmentClass Full name of the class implementing the fragment.
887 * @param args Any desired arguments to supply to the fragment.
888 * @param titleRes Optional resource identifier of the title of this fragment.
889 * @param titleText Optional text of the title of this fragment.
890 * @param userHandle The user for which the panel has to be started.
891 */
892 public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
893 CharSequence titleText, UserHandle userHandle) {
Lifu Tangd0332852015-04-02 12:05:46 -0700894 // This is a workaround.
895 //
896 // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
897 // starting the fragment could cause a native stack corruption. See b/17523189. However,
898 // adding that flag and start the preference panel with the same UserHandler will make it
899 // impossible to use back button to return to the previous screen. See b/20042570.
900 //
901 // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
902 // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
903 // when we're calling it as the same user.
904 if (userHandle.getIdentifier() == UserHandle.myUserId()) {
905 startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0);
906 } else {
907 String title = null;
908 if (titleRes < 0) {
909 if (titleText != null) {
910 title = titleText.toString();
911 } else {
912 // There not much we can do in that case
913 title = "";
914 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100915 }
Lifu Tangd0332852015-04-02 12:05:46 -0700916 Utils.startWithFragmentAsUser(this, fragmentClass, args,
917 titleRes, title, mIsShortcut, userHandle);
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100918 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100919 }
920
921 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800922 * Called by a preference panel fragment to finish itself.
923 *
924 * @param caller The fragment that is asking to be finished.
925 * @param resultCode Optional result code to send back to the original
926 * launching fragment.
927 * @param resultData Optional result data to send back to the original
928 * launching fragment.
929 */
930 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
931 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700932 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800933 }
934
935 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000936 * Start a new fragment.
937 *
938 * @param fragment The fragment to start
939 * @param push If true, the current fragment will be pushed onto the back stack. If false,
940 * the current fragment will be replaced.
941 */
942 public void startPreferenceFragment(Fragment fragment, boolean push) {
943 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700944 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000945 if (push) {
946 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
947 transaction.addToBackStack(BACK_STACK_PREFS);
948 } else {
949 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
950 }
951 transaction.commitAllowingStateLoss();
952 }
953
954 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700955 * Switch to a specific Fragment with taking care of validation, Title and BackStack
956 */
957 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700958 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700959 if (validate && !isValidFragment(fragmentName)) {
960 throw new IllegalArgumentException("Invalid fragment for this activity: "
961 + fragmentName);
962 }
963 Fragment f = Fragment.instantiate(this, fragmentName, args);
964 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700965 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700966 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700967 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700968 }
969 if (addToBackStack) {
970 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
971 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700972 if (titleResId > 0) {
973 transaction.setBreadCrumbTitle(titleResId);
974 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700975 transaction.setBreadCrumbTitle(title);
976 }
977 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700978 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700979 return f;
980 }
981
Jason Monk4da79e02015-09-10 10:54:36 -0400982 private void updateTilesList() {
Jason Monkfd2c7222015-12-02 15:38:38 -0500983 // Generally the items that are will be changing from these updates will
984 // not be in the top list of tiles, so run it in the background and the
985 // SettingsDrawerActivity will pick up on the updates automatically.
986 AsyncTask.execute(new Runnable() {
987 @Override
988 public void run() {
989 doUpdateTilesList();
990 }
991 });
992 }
993
994 private void doUpdateTilesList() {
Jason Monk4da79e02015-09-10 10:54:36 -0400995 PackageManager pm = getPackageManager();
Xiaohui Chen44879a32015-07-22 13:53:22 -0700996 final UserManager um = UserManager.get(this);
997 final boolean isAdmin = um.isAdminUser();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700998
Jason Monk4da79e02015-09-10 10:54:36 -0400999 String packageName = getPackageName();
1000 setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()),
1001 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001002
Jason Monk4da79e02015-09-10 10:54:36 -04001003 setTileEnabled(new ComponentName(packageName,
1004 Settings.BluetoothSettingsActivity.class.getName()),
1005 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001006
Jason Monk4da79e02015-09-10 10:54:36 -04001007 setTileEnabled(new ComponentName(packageName,
1008 Settings.DataUsageSummaryActivity.class.getName()),
1009 Utils.isBandwidthControlEnabled(), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001010
Jason Monk4da79e02015-09-10 10:54:36 -04001011 setTileEnabled(new ComponentName(packageName,
1012 Settings.SimSettingsActivity.class.getName()),
1013 Utils.showSimCardTile(this), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001014
Jason Monk4da79e02015-09-10 10:54:36 -04001015 setTileEnabled(new ComponentName(packageName,
1016 Settings.PowerUsageSummaryActivity.class.getName()),
1017 mBatteryPresent, isAdmin, pm);
1018
1019 setTileEnabled(new ComponentName(packageName,
1020 Settings.HomeSettingsActivity.class.getName()),
1021 updateHomeSettingTiles(), isAdmin, pm);
1022
1023 setTileEnabled(new ComponentName(packageName,
1024 Settings.UserSettingsActivity.class.getName()),
1025 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
1026 && !Utils.isMonkeyRunning(), isAdmin, pm);
1027
1028 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
1029 setTileEnabled(new ComponentName(packageName,
1030 Settings.PaymentSettingsActivity.class.getName()),
1031 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
1032 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
1033 && adapter != null && adapter.isEnabled(), isAdmin, pm);
1034
1035 setTileEnabled(new ComponentName(packageName,
1036 Settings.PrintSettingsActivity.class.getName()),
1037 pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin, pm);
1038
1039 final boolean showDev = mDevelopmentPreferences.getBoolean(
1040 DevelopmentSettings.PREF_SHOW,
1041 android.os.Build.TYPE.equals("eng"));
1042 setTileEnabled(new ComponentName(packageName,
1043 Settings.DevelopmentSettingsActivity.class.getName()),
1044 showDev && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES),
1045 isAdmin, pm);
1046
1047 if (UserHandle.MU_ENABLED && !isAdmin) {
1048 // When on restricted users, disable all extra categories (but only the settings ones).
Jason Monkfd2c7222015-12-02 15:38:38 -05001049 List<DashboardCategory> categories = getDashboardCategories();
Jason Monk4da79e02015-09-10 10:54:36 -04001050 for (DashboardCategory category : categories) {
Jason Monkd4f03ec2016-01-07 16:25:34 -05001051 for (Tile tile : category.tiles) {
Jason Monk4da79e02015-09-10 10:54:36 -04001052 ComponentName component = tile.intent.getComponent();
1053 if (packageName.equals(component)&& !ArrayUtils.contains(
1054 SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1055 setTileEnabled(component, false, isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001056 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001057 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001058 }
1059 }
Jason Monk2ebc8a02015-02-13 15:23:19 -05001060 }
1061
Jason Monk4da79e02015-09-10 10:54:36 -04001062 private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin,
1063 PackageManager pm) {
1064 if (UserHandle.MU_ENABLED && !isAdmin
1065 && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1066 enabled = false;
1067 }
1068 int state = pm.getComponentEnabledSetting(component);
1069 boolean isEnabled = state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
1070 || state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
1071 if (isEnabled != enabled) {
1072 pm.setComponentEnabledSetting(component, enabled
1073 ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
1074 : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
1075 PackageManager.DONT_KILL_APP);
Jason Monk2ebc8a02015-02-13 15:23:19 -05001076 }
1077 }
1078
Jason Monk4da79e02015-09-10 10:54:36 -04001079 private boolean updateHomeSettingTiles() {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001080 // Once we decide to show Home settings, keep showing it forever
1081 SharedPreferences sp = getSharedPreferences(HomeSettings.HOME_PREFS, Context.MODE_PRIVATE);
1082 if (sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false)) {
1083 return true;
1084 }
1085
1086 try {
Fabrice Di Megliob0a464f2014-07-23 18:15:42 -07001087 mHomeActivitiesCount = getHomeActivitiesCount();
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -07001088 if (mHomeActivitiesCount < 2) {
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001089 return false;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001090 }
1091 } catch (Exception e) {
1092 // Can't look up the home activity; bail on configuring the icon
1093 Log.w(LOG_TAG, "Problem looking up home activity!", e);
1094 }
1095
1096 sp.edit().putBoolean(HomeSettings.HOME_PREFS_DO_SHOW, true).apply();
1097 return true;
1098 }
1099
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001100 private void getMetaData() {
1101 try {
1102 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1103 PackageManager.GET_META_DATA);
1104 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001105 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1106 } catch (NameNotFoundException nnfe) {
1107 // No recovery
1108 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1109 }
1110 }
1111
1112 // give subclasses access to the Next button
1113 public boolean hasNextButton() {
1114 return mNextButton != null;
1115 }
1116
1117 public Button getNextButton() {
1118 return mNextButton;
1119 }
1120
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001121 @Override
1122 public boolean shouldUpRecreateTask(Intent targetIntent) {
1123 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1124 }
1125
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001126 @Override
1127 public boolean onQueryTextSubmit(String query) {
1128 switchToSearchResultsFragmentIfNeeded();
1129 mSearchQuery = query;
1130 return mSearchResultsFragment.onQueryTextSubmit(query);
1131 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001132
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001133 @Override
1134 public boolean onQueryTextChange(String newText) {
1135 mSearchQuery = newText;
Fabrice Di Meglio7e4855e2014-05-23 16:03:43 -07001136 if (mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001137 return false;
1138 }
1139 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001140 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001141
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001142 @Override
1143 public boolean onClose() {
1144 return false;
1145 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001146
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001147 @Override
1148 public boolean onMenuItemActionExpand(MenuItem item) {
1149 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001150 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001151 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001152 return true;
1153 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001154
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001155 @Override
1156 public boolean onMenuItemActionCollapse(MenuItem item) {
1157 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001158 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001159 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001160 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001161 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001162 return true;
1163 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001164
Jason Monk4da79e02015-09-10 10:54:36 -04001165 @Override
Jason Monkd4f03ec2016-01-07 16:25:34 -05001166 protected void onTileClicked(Tile tile) {
Jason Monk4da79e02015-09-10 10:54:36 -04001167 if (mIsShowingDashboard) {
1168 // If on dashboard, don't finish so the back comes back to here.
1169 openTile(tile);
1170 } else {
1171 super.onTileClicked(tile);
1172 }
1173 }
1174
Jason Monkaf001092015-11-04 13:16:18 -05001175 @Override
1176 public void onProfileTileOpen() {
1177 if (!mIsShowingDashboard) {
1178 finish();
1179 }
1180 }
1181
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001182 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001183 if (mSearchResultsFragment != null) {
1184 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001185 }
Fabrice Di Megliod40dd452014-07-18 15:20:34 -07001186 Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001187 if (current != null && current instanceof SearchResultsSummary) {
1188 mSearchResultsFragment = (SearchResultsSummary) current;
1189 } else {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001190 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001191 SearchResultsSummary.class.getName(), null, false, true,
1192 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001193 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001194 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001195 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001196 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001197
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001198 public void needToRevertToInitialFragment() {
1199 mNeedToRevertToInitialFragment = true;
1200 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001201
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001202 private void revertToInitialFragment() {
1203 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001204 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001205 mSearchMenuItemExpanded = false;
1206 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1207 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001208 if (mSearchMenuItem != null) {
1209 mSearchMenuItem.collapseActionView();
1210 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001211 }
Jim Miller0698a212014-10-16 19:49:07 -07001212
1213 public Intent getResultIntentData() {
1214 return mResultIntentData;
1215 }
1216
1217 public void setResultIntentData(Intent resultIntentData) {
1218 mResultIntentData = resultIntentData;
1219 }
Jason Monkd4f03ec2016-01-07 16:25:34 -05001220
1221 public void startSuggestion(Intent intent) {
1222 mCurrentSuggestion = intent.getComponent();
1223 startActivityForResult(intent, REQUEST_SUGGESTION);
1224 }
1225
1226 @Override
1227 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
1228 if (requestCode == REQUEST_SUGGESTION && mCurrentSuggestion != null
1229 && resultCode != RESULT_CANCELED) {
1230 getPackageManager().setComponentEnabledSetting(mCurrentSuggestion,
1231 PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
1232 }
1233 super.onActivityResult(requestCode, resultCode, data);
1234 }
1235
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001236}