blob: fe25a8f92653d71e572f9f2cdd1781a8bebcf269 [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
Fan Zhang60f01072016-10-13 16:53:41 -070019import android.app.ActionBar;
Matthew Fritze7ac78f22016-10-03 13:26:07 -070020import android.app.ActivityManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080021import android.app.Fragment;
22import android.app.FragmentManager;
23import android.app.FragmentTransaction;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080024import android.content.BroadcastReceiver;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070025import android.content.ComponentName;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080026import android.content.Context;
27import android.content.Intent;
28import android.content.IntentFilter;
29import android.content.SharedPreferences;
30import android.content.pm.ActivityInfo;
31import android.content.pm.PackageManager;
32import android.content.pm.PackageManager.NameNotFoundException;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080033import 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;
Fan Zhanga3e8f5c2016-12-01 09:52:10 -080039import android.support.annotation.VisibleForTesting;
Jason Monk39b46742015-09-10 15:52:51 -040040import android.support.v14.preference.PreferenceFragment;
41import android.support.v7.preference.Preference;
42import android.support.v7.preference.PreferenceManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080043import android.text.TextUtils;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070044import android.transition.TransitionManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080045import android.util.Log;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070046import android.view.Menu;
47import android.view.MenuInflater;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080048import android.view.MenuItem;
49import android.view.View;
50import android.view.View.OnClickListener;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070051import android.view.ViewGroup;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080052import android.widget.Button;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070053import android.widget.SearchView;
Fan Zhang28691572016-03-23 15:31:08 -070054
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080055import com.android.internal.util.ArrayUtils;
Jason Monk4da79e02015-09-10 10:54:36 -040056import com.android.settings.Settings.WifiSettingsActivity;
Fan Zhanga3e8f5c2016-12-01 09:52:10 -080057import com.android.settings.core.gateway.SettingsGateway;
Fan Zhang5f79ae92016-08-18 16:04:19 -070058import com.android.settings.core.instrumentation.SharedPreferencesLogger;
Fan Zhang28691572016-03-23 15:31:08 -070059import com.android.settings.dashboard.DashboardContainerFragment;
Fan Zhanga96a2d82016-09-27 17:51:11 -070060import com.android.settings.dashboard.DashboardFeatureProvider;
61import com.android.settings.dashboard.DashboardSummary;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070062import com.android.settings.dashboard.SearchResultsSummary;
Fan Zhanga96a2d82016-09-27 17:51:11 -070063import com.android.settings.overlay.FeatureFactory;
Dan Sandler12c4ba42016-03-28 11:13:40 -040064import com.android.settings.qstile.DevelopmentTiles;
Jason Monk2ebc8a02015-02-13 15:23:19 -050065import com.android.settings.search.DynamicIndexableContentMonitor;
66import com.android.settings.search.Index;
Matthew Fritze0ed37c32016-10-24 10:12:49 -070067import com.android.settings.search2.SearchFeatureProvider;
Fabrice Di Meglio41937762014-05-13 19:51:59 -070068import com.android.settings.widget.SwitchBar;
Jason Monk4da79e02015-09-10 10:54:36 -040069import com.android.settingslib.drawer.DashboardCategory;
Jason Monk4da79e02015-09-10 10:54:36 -040070import com.android.settingslib.drawer.SettingsDrawerActivity;
Jason Monk7ea14c52016-01-22 14:28:02 -050071import com.android.settingslib.drawer.Tile;
Jason Monk2ebc8a02015-02-13 15:23:19 -050072
Doris Ling26bf0032016-06-15 18:16:09 -070073import java.net.URISyntaxException;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080074import java.util.ArrayList;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080075import java.util.List;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -070076import java.util.Set;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080077
Jason Monk4da79e02015-09-10 10:54:36 -040078public class SettingsActivity extends SettingsDrawerActivity
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080079 implements PreferenceManager.OnPreferenceTreeClickListener,
80 PreferenceFragment.OnPreferenceStartFragmentCallback,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +010081 ButtonBarHandler, FragmentManager.OnBackStackChangedListener,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070082 SearchView.OnQueryTextListener, SearchView.OnCloseListener,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +010083 MenuItem.OnActionExpandListener {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080084
85 private static final String LOG_TAG = "Settings";
86
Philip P. Moltmannd9779db2016-02-24 12:11:05 -080087 private static final int LOADER_ID_INDEXABLE_CONTENT_MONITOR = 1;
88
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080089 // Constants for state save/restore
Fabrice Di Meglio769630c2014-04-24 14:48:48 -070090 private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070091 private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
92 private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
Fabrice Di Megliob731dd02014-04-03 18:40:38 -070093 private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -070094 private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080095
96 /**
97 * When starting this activity, the invoking Intent can contain this extra
98 * string to specify which fragment should be initially displayed.
99 * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
100 * will call isValidFragment() to confirm that the fragment class name is valid for this
101 * activity.
102 */
103 public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
104
105 /**
106 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
107 * this extra can also be specified to supply a Bundle of arguments to pass
108 * to that fragment when it is instantiated during the initial creation
109 * of the activity.
110 */
111 public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
112
113 /**
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700114 * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
115 */
116 public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
117
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800118 public static final String BACK_STACK_PREFS = ":settings:prefs";
119
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800120 // extras that allow any preference activity to be launched as part of a wizard
121
122 // show Back and Next buttons? takes boolean parameter
123 // Back will then return RESULT_CANCELED and Next RESULT_OK
124 protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
125
126 // add a Skip button?
127 private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
128
129 // specify custom text for the Back or Next buttons, or cause a button to not appear
130 // at all by setting it to null
131 protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
132 protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
133
134 /**
135 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700136 * 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 -0800137 * that fragment.
138 */
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700139 public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100140 /**
141 * The package name used to resolve the title resource id.
142 */
143 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
144 ":settings:show_fragment_title_res_package_name";
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700145 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
146 ":settings:show_fragment_title_resid";
147 public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
148 ":settings:show_fragment_as_shortcut";
149
150 public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
151 ":settings:show_fragment_as_subsetting";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800152
Udam Saini92779ce2016-03-28 14:29:48 -0700153 public static final String EXTRA_HIDE_DRAWER = ":settings:hide_drawer";
154
Jason Monk30695812015-11-17 09:01:08 -0500155 public static final String META_DATA_KEY_FRAGMENT_CLASS =
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800156 "com.android.settings.FRAGMENT_CLASS";
157
158 private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
159
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700160 private static final String EMPTY_QUERY = "";
161
Jason Monkd4f03ec2016-01-07 16:25:34 -0500162 private static final int REQUEST_SUGGESTION = 42;
163
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800164 private String mFragmentClass;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800165
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800166 private CharSequence mInitialTitle;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700167 private int mInitialTitleResId;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800168
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800169 // Show only these settings for restricted users
Jason Monk4da79e02015-09-10 10:54:36 -0400170 private String[] SETTINGS_FOR_RESTRICTED = {
171 //wireless_section
172 WifiSettingsActivity.class.getName(),
173 Settings.BluetoothSettingsActivity.class.getName(),
174 Settings.DataUsageSummaryActivity.class.getName(),
175 Settings.SimSettingsActivity.class.getName(),
176 Settings.WirelessSettingsActivity.class.getName(),
177 //device_section
178 Settings.HomeSettingsActivity.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500179 Settings.SoundSettingsActivity.class.getName(),
Jason Monk4da79e02015-09-10 10:54:36 -0400180 Settings.DisplaySettingsActivity.class.getName(),
181 Settings.StorageSettingsActivity.class.getName(),
182 Settings.ManageApplicationsActivity.class.getName(),
183 Settings.PowerUsageSummaryActivity.class.getName(),
Doris Ling91365232016-05-23 17:06:26 -0700184 Settings.GestureSettingsActivity.class.getName(),
Jason Monk4da79e02015-09-10 10:54:36 -0400185 //personal_section
186 Settings.LocationSettingsActivity.class.getName(),
187 Settings.SecuritySettingsActivity.class.getName(),
188 Settings.InputMethodAndLanguageSettingsActivity.class.getName(),
189 Settings.UserSettingsActivity.class.getName(),
190 Settings.AccountSettingsActivity.class.getName(),
191 //system_section
192 Settings.DateTimeSettingsActivity.class.getName(),
193 Settings.DeviceInfoSettingsActivity.class.getName(),
194 Settings.AccessibilitySettingsActivity.class.getName(),
195 Settings.PrintSettingsActivity.class.getName(),
196 Settings.PaymentSettingsActivity.class.getName(),
Bartosz Fabianowski05061fc2016-11-14 12:04:49 +0100197 Settings.EnterprisePrivacySettingsActivity.class.getName(),
Fan Zhangcc335d92016-09-29 14:37:14 -0700198
199 // New IA
200 // Home page
Fan Zhangbb93dc02016-10-11 16:27:45 -0700201 Settings.NetworkDashboardActivity.class.getName(),
Fan Zhangf37be6a2016-10-20 12:47:52 -0700202 Settings.ConnectedDeviceDashboardActivity.class.getName(),
203 Settings.AppAndNotificationDashboardActivity.class.getName(),
Fan Zhangcc335d92016-09-29 14:37:14 -0700204 "com.android.settings.Settings.BatteryDashboardAlias",
Fan Zhang66b573a2016-10-06 16:33:13 -0700205 "com.android.settings.Settings.DisplayDashboardAlias",
Doris Ling55578652016-10-18 13:08:29 -0700206 "com.android.settings.Settings.SoundDashboardAlias",
Fan Zhang8da6f882016-10-14 14:02:03 -0700207 "com.android.settings.Settings.SecurityDashboardAlias",
Doris Lingd7aae182016-10-21 11:33:54 -0700208 Settings.UserAndAccountDashboardActivity.class.getName(),
Fan Zhangcc335d92016-09-29 14:37:14 -0700209 Settings.SystemDashboardActivity.class.getName(),
210 Settings.SupportDashboardActivity.class.getName(),
Fan Zhangcdacd1d2016-10-20 17:15:50 -0700211 // Home page > Apps & Notifications
212 "com.android.settings.Settings.ManageApplicationsDashboardAlias",
Fan Zhang4136d902016-10-21 14:23:56 -0700213 "com.android.settings.Settings.PaymentSettingsDashboardAlias",
Fan Zhangbb93dc02016-10-11 16:27:45 -0700214 // Home page > Network & Internet
215 "com.android.settings.Settings.WifiDashboardAlias",
216 "com.android.settings.Settings.DataUsageDashboardAlias",
Fan Zhang301fe802016-10-26 10:44:45 -0700217 // Home page > Security
218 "com.android.settings.Settings.LocationDashboardAlias",
Fan Zhangcc335d92016-09-29 14:37:14 -0700219 // Home page > System
Fan Zhanga1d1d672016-11-07 15:12:52 -0800220 Settings.LanguageAndRegionSettingsActivity.class.getName(),
221 Settings.InputAndGestureSettingsActivity.class.getName(),
Fan Zhangcc335d92016-09-29 14:37:14 -0700222 "com.android.settings.Settings.DateTimeDashboardAlias",
223 "com.android.settings.Settings.AccessibilityDashboardAlias",
224 "com.android.settings.Settings.AboutDeviceDashboardAlias",
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800225 };
226
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700227 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
228 "android.settings.APPLICATION_DETAILS_SETTINGS"
229 };
230
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800231 private SharedPreferences mDevelopmentPreferences;
232 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
233
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800234 private boolean mBatteryPresent = true;
235 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800236 @Override
237 public void onReceive(Context context, Intent intent) {
238 String action = intent.getAction();
239 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
240 boolean batteryPresent = Utils.isBatteryPresent(intent);
241
242 if (mBatteryPresent != batteryPresent) {
243 mBatteryPresent = batteryPresent;
Jason Monk4da79e02015-09-10 10:54:36 -0400244 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800245 }
246 }
247 }
248 };
249
Clara Bayarri6934a042015-10-14 11:07:35 +0100250 private final BroadcastReceiver mUserAddRemoveReceiver = new BroadcastReceiver() {
251 @Override
252 public void onReceive(Context context, Intent intent) {
253 String action = intent.getAction();
254 if (action.equals(Intent.ACTION_USER_ADDED)
255 || action.equals(Intent.ACTION_USER_REMOVED)) {
256 Index.getInstance(getApplicationContext()).update();
257 }
258 }
259 };
260
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800261 private DynamicIndexableContentMonitor mDynamicIndexableContentMonitor;
Svetoslav853e4712014-04-14 10:10:25 -0700262
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700263 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700264 private SwitchBar mSwitchBar;
265
266 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700267
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700268 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700269 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700270
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700271 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700272 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700273
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700274 private ViewGroup mContent;
275
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700276 private SearchView mSearchView;
277 private MenuItem mSearchMenuItem;
278 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700279 private SearchResultsSummary mSearchResultsFragment;
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700280 private SearchFeatureProvider mSearchFeatureProvider;
281
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700282 // Categories
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800283 private ArrayList<DashboardCategory> mCategories = new ArrayList<>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800284
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700285 private boolean mNeedToRevertToInitialFragment = false;
286
Fan Zhanga96a2d82016-09-27 17:51:11 -0700287 private DashboardFeatureProvider mDashboardFeatureProvider;
Jim Miller0698a212014-10-16 19:49:07 -0700288 private Intent mResultIntentData;
Jason Monkd4f03ec2016-01-07 16:25:34 -0500289 private ComponentName mCurrentSuggestion;
Jim Miller0698a212014-10-16 19:49:07 -0700290
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800291 @VisibleForTesting
292 String mSearchQuery;
293
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700294 public SwitchBar getSwitchBar() {
295 return mSwitchBar;
296 }
297
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800298 @Override
299 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
Sunny Goyal21ef89f2016-05-25 12:41:16 -0700300 startPreferencePanel(pref.getFragment(), pref.getExtras(), -1, pref.getTitle(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800301 null, 0);
302 return true;
303 }
304
305 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400306 public boolean onPreferenceTreeClick(Preference preference) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800307 return false;
308 }
309
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800310 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800311 public void onConfigurationChanged(Configuration newConfig) {
312 super.onConfigurationChanged(newConfig);
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800313 Index.getInstance(this).update();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800314 }
315
316 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700317 protected void onStart() {
318 super.onStart();
319
320 if (mNeedToRevertToInitialFragment) {
321 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800322 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800323 }
324
325 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700326 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700327 if (!mDisplaySearch) {
328 return false;
329 }
330
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700331 MenuInflater inflater = getMenuInflater();
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700332 if (mSearchFeatureProvider.isEnabled()) {
333 mSearchFeatureProvider.setUpSearchMenu(menu, this);
334 return true;
335 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700336 inflater.inflate(R.menu.options_menu, menu);
337
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700338
339 // Cache the search query (can be overridden by the OnQueryTextListener)
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700340 final String query = mSearchQuery;
341
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700342 mSearchMenuItem = menu.findItem(R.id.search);
343 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700344
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700345 if (mSearchMenuItem == null || mSearchView == null) {
346 return false;
347 }
348
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700349 if (mSearchResultsFragment != null) {
350 mSearchResultsFragment.setSearchView(mSearchView);
351 }
352
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700353 mSearchMenuItem.setOnActionExpandListener(this);
Fan Zhangb9239182016-08-22 13:59:59 -0700354 mSearchView.setMaxWidth(Integer.MAX_VALUE);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700355 mSearchView.setOnQueryTextListener(this);
356 mSearchView.setOnCloseListener(this);
357
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700358 if (mSearchMenuItemExpanded) {
359 mSearchMenuItem.expandActionView();
360 }
361 mSearchView.setQuery(query, true /* submit */);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700362 return true;
363 }
364
Jason Monk31c7c322016-01-20 14:41:52 -0500365 @Override
366 public SharedPreferences getSharedPreferences(String name, int mode) {
367 if (name.equals(getPackageName() + "_preferences")) {
Jason Monke4ebcd12016-02-21 09:37:41 -0500368 return new SharedPreferencesLogger(this, getMetricsTag());
Jason Monk31c7c322016-01-20 14:41:52 -0500369 }
370 return super.getSharedPreferences(name, mode);
371 }
372
Jason Monke4ebcd12016-02-21 09:37:41 -0500373 private String getMetricsTag() {
374 String tag = getClass().getName();
375 if (getIntent() != null && getIntent().hasExtra(EXTRA_SHOW_FRAGMENT)) {
376 tag = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
377 }
378 if (tag.startsWith("com.android.settings.")) {
379 tag = tag.replace("com.android.settings.", "");
380 }
381 return tag;
382 }
383
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700384 private static boolean isShortCutIntent(final Intent intent) {
385 Set<String> categories = intent.getCategories();
386 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
387 }
388
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700389 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700390 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700391 if (action == null) {
392 return false;
393 }
394 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
395 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
396 }
397 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700398 }
399
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700400 @Override
401 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700402 super.onCreate(savedState);
Jason Monkfd2c7222015-12-02 15:38:38 -0500403 long startTime = System.currentTimeMillis();
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700404
405 final FeatureFactory factory = FeatureFactory.getFactory(this);
406
407 mDashboardFeatureProvider = factory.getDashboardFeatureProvider(this);
408 mSearchFeatureProvider = factory.getSearchFeatureProvider(this);
409
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700410 // Should happen before any call to getIntent()
411 getMetaData();
412
413 final Intent intent = getIntent();
414 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
415 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800416 }
Udam Saini92779ce2016-03-28 14:29:48 -0700417 if (intent.getBooleanExtra(EXTRA_HIDE_DRAWER, false)) {
418 setIsDrawerPresent(false);
419 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800420
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800421 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
422 Context.MODE_PRIVATE);
423
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700424 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700425 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700426
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700427 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700428 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
429
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700430 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700431 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700432
Jason Monk4da79e02015-09-10 10:54:36 -0400433 mIsShowingDashboard = className.equals(Settings.class.getName())
434 || className.equals(Settings.WirelessSettings.class.getName())
435 || className.equals(Settings.DeviceSettings.class.getName())
436 || className.equals(Settings.PersonalSettings.class.getName())
437 || className.equals(Settings.WirelessSettings.class.getName());
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700438
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700439 // This is a "Sub Settings" when:
440 // - this is a real SubSettings
441 // - or :settings:show_fragment_as_subsetting is passed to the Intent
Jorim Jaggi4dfcb822015-04-29 17:21:32 -0700442 final boolean isSubSettings = this instanceof SubSettings ||
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700443 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
444
445 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
446 if (isSubSettings) {
Fabrice Di Meglio712df6c2014-07-18 17:44:37 -0700447 // Check also that we are not a Theme Dialog as we don't want to override them
448 final int themeResId = getThemeResId();
449 if (themeResId != R.style.Theme_DialogWhenLarge &&
450 themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
451 setTheme(R.style.Theme_SubSettings);
452 }
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700453 }
454
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700455 setContentView(mIsShowingDashboard ?
456 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800457
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700458 mContent = (ViewGroup) findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700459
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800460 getFragmentManager().addOnBackStackChangedListener(this);
461
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700462 if (mIsShowingDashboard) {
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800463 // Run the Index update only if we have some space
464 if (!Utils.isLowStorage(this)) {
Jason Monkfd2c7222015-12-02 15:38:38 -0500465 long indexStartTime = System.currentTimeMillis();
Jason Monk6c9e8842016-04-14 14:34:16 -0400466 Index.getInstance(getApplicationContext()).update();
Jason Monkfd2c7222015-12-02 15:38:38 -0500467 if (DEBUG_TIMING) Log.d(LOG_TAG, "Index.update() took "
468 + (System.currentTimeMillis() - indexStartTime) + " ms");
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800469 } else {
470 Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
471 }
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700472 }
473
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700474 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700475 // We are restarting from a previous saved state; used that to initialize, instead
476 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700477 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
478 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700479 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800480
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700481 ArrayList<DashboardCategory> categories =
482 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
483 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700484 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700485 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700486 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800487 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700488
489 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700490 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Salvador Martinez2368e542016-07-25 18:16:47 -0700491
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800492 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700493 if (!mIsShowingDashboard) {
Jason Monkea8b1a72015-06-02 16:46:34 -0400494 mDisplaySearch = false;
495 // UP will be shown only if it is a sub settings
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700496 if (mIsShortcut) {
497 mDisplayHomeAsUpEnabled = isSubSettings;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700498 } else if (isSubSettings) {
499 mDisplayHomeAsUpEnabled = true;
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700500 } else {
501 mDisplayHomeAsUpEnabled = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700502 }
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700503 setTitleFromIntent(intent);
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700504
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700505 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700506 switchToFragment(initialFragmentName, initialArguments, true, false,
507 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000508 } else {
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700509 // No UP affordance if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700510 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700511 // Show Search affordance
512 mDisplaySearch = true;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700513 mInitialTitleResId = R.string.dashboard_title;
Salvador Martinez2368e542016-07-25 18:16:47 -0700514
515 // add argument to indicate which settings tab should be initially selected
516 final Bundle args = new Bundle();
517 final String extraName = DashboardContainerFragment.EXTRA_SELECT_SETTINGS_TAB;
518 args.putString(extraName, intent.getStringExtra(extraName));
Fan Zhanga96a2d82016-09-27 17:51:11 -0700519 if (isDashboardFeatureEnabled()) {
520 switchToFragment(DashboardSummary.class.getName(), args, false, false,
521 mInitialTitleResId, mInitialTitle, false);
522 } else {
523 switchToFragment(DashboardContainerFragment.class.getName(), args, false, false,
524 mInitialTitleResId, mInitialTitle, false);
525 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800526 }
527 }
528
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700529 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700530 if (mActionBar != null) {
531 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
532 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
533 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700534 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
Jason Monke4ebcd12016-02-21 09:37:41 -0500535 if (mSwitchBar != null) {
536 mSwitchBar.setMetricsTag(getMetricsTag());
537 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700538
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800539 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800540 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
541
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700542 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800543 if (buttonBar != null) {
544 buttonBar.setVisibility(View.VISIBLE);
545
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700546 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800547 backButton.setOnClickListener(new OnClickListener() {
548 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700549 setResult(RESULT_CANCELED, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800550 finish();
551 }
552 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700553 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800554 skipButton.setOnClickListener(new OnClickListener() {
555 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700556 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800557 finish();
558 }
559 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700560 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800561 mNextButton.setOnClickListener(new OnClickListener() {
562 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700563 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800564 finish();
565 }
566 });
567
568 // set our various button parameters
569 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
570 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
571 if (TextUtils.isEmpty(buttonText)) {
572 mNextButton.setVisibility(View.GONE);
573 }
574 else {
575 mNextButton.setText(buttonText);
576 }
577 }
578 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
579 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
580 if (TextUtils.isEmpty(buttonText)) {
581 backButton.setVisibility(View.GONE);
582 }
583 else {
584 backButton.setText(buttonText);
585 }
586 }
587 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
588 skipButton.setVisibility(View.VISIBLE);
589 }
590 }
591 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700592
Jason Monkfd2c7222015-12-02 15:38:38 -0500593 if (DEBUG_TIMING) Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
594 + " ms");
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700595 }
596
Fan Zhangece8ff62016-06-30 13:20:12 -0700597 public void setDisplaySearchMenu(boolean displaySearch) {
598 if (displaySearch != mDisplaySearch) {
599 mDisplaySearch = displaySearch;
600 invalidateOptionsMenu();
601 }
602 }
603
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700604 private void setTitleFromIntent(Intent intent) {
605 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
606 if (initialTitleResId > 0) {
607 mInitialTitle = null;
608 mInitialTitleResId = initialTitleResId;
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100609
610 final String initialTitleResPackageName = intent.getStringExtra(
611 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
612 if (initialTitleResPackageName != null) {
613 try {
614 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
615 0 /* flags */, new UserHandle(UserHandle.myUserId()));
616 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
617 setTitle(mInitialTitle);
618 mInitialTitleResId = -1;
619 return;
620 } catch (NameNotFoundException e) {
621 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
622 }
623 } else {
624 setTitle(mInitialTitleResId);
625 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700626 } else {
627 mInitialTitleResId = -1;
628 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
629 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
630 setTitle(mInitialTitle);
631 }
632 }
633
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800634 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800635 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700636 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800637 }
638
Fan Zhang28691572016-03-23 15:31:08 -0700639 private void setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800640 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700641
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800642 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700643 if (mInitialTitleResId > 0) {
644 setTitle(mInitialTitleResId);
645 } else {
646 setTitle(mInitialTitle);
647 }
Fan Zhang28691572016-03-23 15:31:08 -0700648 return;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800649 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700650
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800651 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
652 setTitleFromBackStackEntry(bse);
653 }
654
655 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
656 final CharSequence title;
657 final int titleRes = bse.getBreadCrumbTitleRes();
658 if (titleRes > 0) {
659 title = getText(titleRes);
660 } else {
661 title = bse.getBreadCrumbTitle();
662 }
663 if (title != null) {
664 setTitle(title);
665 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800666 }
667
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800668 @Override
669 protected void onSaveInstanceState(Bundle outState) {
670 super.onSaveInstanceState(outState);
671
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700672 if (mCategories.size() > 0) {
673 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800674 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700675
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700676 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700677 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700678
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700679 if (mDisplaySearch) {
680 // The option menus are created if the ActionBar is visible and they are also created
681 // asynchronously. If you launch Settings with an Intent action like
682 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
683 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
684 // menu item and search view are null.
685 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
686 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700687
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700688 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
689 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
690 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800691 }
692
693 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400694 protected void onResume() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800695 super.onResume();
696
697 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
698 @Override
699 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Jason Monk4da79e02015-09-10 10:54:36 -0400700 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800701 }
702 };
703 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
704 mDevelopmentPreferencesListener);
705
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800706 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Clara Bayarri6934a042015-10-14 11:07:35 +0100707 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_ADDED));
708 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_REMOVED));
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800709 if (mDynamicIndexableContentMonitor == null) {
710 mDynamicIndexableContentMonitor = new DynamicIndexableContentMonitor();
711 }
Philip P. Moltmannd9779db2016-02-24 12:11:05 -0800712 mDynamicIndexableContentMonitor.register(this, LOADER_ID_INDEXABLE_CONTENT_MONITOR);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700713
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700714 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700715 onQueryTextSubmit(mSearchQuery);
716 }
Jason Monk4da79e02015-09-10 10:54:36 -0400717 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800718 }
719
720 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400721 protected void onPause() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800722 super.onPause();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800723 unregisterReceiver(mBatteryInfoReceiver);
Clara Bayarri8c9521f2016-01-12 14:10:45 +0000724 unregisterReceiver(mUserAddRemoveReceiver);
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800725 if (mDynamicIndexableContentMonitor != null) {
726 mDynamicIndexableContentMonitor.unregister();
727 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800728 }
729
730 @Override
731 public void onDestroy() {
732 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700733
734 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
735 mDevelopmentPreferencesListener);
736 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800737 }
738
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800739 protected boolean isValidFragment(String fragmentName) {
740 // Almost all fragments are wrapped in this,
741 // except for a few that have their own activities.
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800742 for (int i = 0; i < SettingsGateway.ENTRY_FRAGMENTS.length; i++) {
743 if (SettingsGateway.ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800744 }
745 return false;
746 }
747
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800748 @Override
749 public Intent getIntent() {
750 Intent superIntent = super.getIntent();
751 String startingFragment = getStartingFragmentClass(superIntent);
752 // This is called from super.onCreate, isMultiPane() is not yet reliable
753 // Do not use onIsHidingHeaders either, which relies itself on this method
754 if (startingFragment != null) {
755 Intent modIntent = new Intent(superIntent);
756 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
757 Bundle args = superIntent.getExtras();
758 if (args != null) {
759 args = new Bundle(args);
760 } else {
761 args = new Bundle();
762 }
763 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100764 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800765 return modIntent;
766 }
767 return superIntent;
768 }
769
770 /**
771 * Checks if the component name in the intent is different from the Settings class and
772 * returns the class name to load as a fragment.
773 */
774 private String getStartingFragmentClass(Intent intent) {
775 if (mFragmentClass != null) return mFragmentClass;
776
777 String intentClass = intent.getComponent().getClassName();
778 if (intentClass.equals(getClass().getName())) return null;
779
780 if ("com.android.settings.ManageApplications".equals(intentClass)
781 || "com.android.settings.RunningServices".equals(intentClass)
782 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
783 // Old names of manage apps.
784 intentClass = com.android.settings.applications.ManageApplications.class.getName();
785 }
786
787 return intentClass;
788 }
789
790 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000791 * Start a new fragment containing a preference panel. If the preferences
792 * are being displayed in multi-pane mode, the given fragment class will
793 * be instantiated and placed in the appropriate pane. If running in
794 * single-pane mode, a new activity will be launched in which to show the
795 * fragment.
796 *
797 * @param fragmentClass Full name of the class implementing the fragment.
798 * @param args Any desired arguments to supply to the fragment.
799 * @param titleRes Optional resource identifier of the title of this
800 * fragment.
801 * @param titleText Optional text of the title of this fragment.
802 * @param resultTo Optional fragment that result data should be sent to.
803 * If non-null, resultTo.onActivityResult() will be called when this
804 * preference panel is done. The launched panel must use
805 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
806 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700807 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000808 */
809 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700810 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700811 String title = null;
812 if (titleRes < 0) {
813 if (titleText != null) {
814 title = titleText.toString();
815 } else {
816 // There not much we can do in that case
817 title = "";
818 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700819 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700820 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700821 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000822 }
823
824 /**
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100825 * Start a new fragment in a new activity containing a preference panel for a given user. If the
826 * preferences are being displayed in multi-pane mode, the given fragment class will be
827 * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
828 * activity will be launched in which to show the fragment.
829 *
830 * @param fragmentClass Full name of the class implementing the fragment.
831 * @param args Any desired arguments to supply to the fragment.
832 * @param titleRes Optional resource identifier of the title of this fragment.
833 * @param titleText Optional text of the title of this fragment.
834 * @param userHandle The user for which the panel has to be started.
835 */
836 public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
837 CharSequence titleText, UserHandle userHandle) {
Lifu Tangd0332852015-04-02 12:05:46 -0700838 // This is a workaround.
839 //
840 // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
841 // starting the fragment could cause a native stack corruption. See b/17523189. However,
842 // adding that flag and start the preference panel with the same UserHandler will make it
843 // impossible to use back button to return to the previous screen. See b/20042570.
844 //
845 // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
846 // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
847 // when we're calling it as the same user.
848 if (userHandle.getIdentifier() == UserHandle.myUserId()) {
849 startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0);
850 } else {
851 String title = null;
852 if (titleRes < 0) {
853 if (titleText != null) {
854 title = titleText.toString();
855 } else {
856 // There not much we can do in that case
857 title = "";
858 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100859 }
Lifu Tangd0332852015-04-02 12:05:46 -0700860 Utils.startWithFragmentAsUser(this, fragmentClass, args,
861 titleRes, title, mIsShortcut, userHandle);
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100862 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100863 }
864
865 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800866 * Called by a preference panel fragment to finish itself.
867 *
868 * @param caller The fragment that is asking to be finished.
869 * @param resultCode Optional result code to send back to the original
870 * launching fragment.
871 * @param resultData Optional result data to send back to the original
872 * launching fragment.
873 */
874 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
875 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700876 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800877 }
878
879 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000880 * Start a new fragment.
881 *
882 * @param fragment The fragment to start
883 * @param push If true, the current fragment will be pushed onto the back stack. If false,
884 * the current fragment will be replaced.
885 */
886 public void startPreferenceFragment(Fragment fragment, boolean push) {
887 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700888 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000889 if (push) {
890 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
891 transaction.addToBackStack(BACK_STACK_PREFS);
892 } else {
893 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
894 }
895 transaction.commitAllowingStateLoss();
896 }
897
898 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700899 * Switch to a specific Fragment with taking care of validation, Title and BackStack
900 */
901 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700902 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700903 if (validate && !isValidFragment(fragmentName)) {
904 throw new IllegalArgumentException("Invalid fragment for this activity: "
905 + fragmentName);
906 }
907 Fragment f = Fragment.instantiate(this, fragmentName, args);
908 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700909 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700910 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700911 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700912 }
913 if (addToBackStack) {
914 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
915 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700916 if (titleResId > 0) {
917 transaction.setBreadCrumbTitle(titleResId);
918 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700919 transaction.setBreadCrumbTitle(title);
920 }
921 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700922 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700923 return f;
924 }
925
Jason Monk4da79e02015-09-10 10:54:36 -0400926 private void updateTilesList() {
Jason Monkfd2c7222015-12-02 15:38:38 -0500927 // Generally the items that are will be changing from these updates will
928 // not be in the top list of tiles, so run it in the background and the
929 // SettingsDrawerActivity will pick up on the updates automatically.
930 AsyncTask.execute(new Runnable() {
931 @Override
932 public void run() {
933 doUpdateTilesList();
934 }
935 });
936 }
937
938 private void doUpdateTilesList() {
Jason Monk4da79e02015-09-10 10:54:36 -0400939 PackageManager pm = getPackageManager();
Xiaohui Chen44879a32015-07-22 13:53:22 -0700940 final UserManager um = UserManager.get(this);
941 final boolean isAdmin = um.isAdminUser();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700942
Jason Monk4da79e02015-09-10 10:54:36 -0400943 String packageName = getPackageName();
944 setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()),
945 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700946
Jason Monk4da79e02015-09-10 10:54:36 -0400947 setTileEnabled(new ComponentName(packageName,
948 Settings.BluetoothSettingsActivity.class.getName()),
949 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700950
Jason Monk4da79e02015-09-10 10:54:36 -0400951 setTileEnabled(new ComponentName(packageName,
952 Settings.DataUsageSummaryActivity.class.getName()),
953 Utils.isBandwidthControlEnabled(), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700954
Jason Monk4da79e02015-09-10 10:54:36 -0400955 setTileEnabled(new ComponentName(packageName,
956 Settings.SimSettingsActivity.class.getName()),
957 Utils.showSimCardTile(this), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700958
Jason Monk4da79e02015-09-10 10:54:36 -0400959 setTileEnabled(new ComponentName(packageName,
960 Settings.PowerUsageSummaryActivity.class.getName()),
961 mBatteryPresent, isAdmin, pm);
962
963 setTileEnabled(new ComponentName(packageName,
Jason Monk4da79e02015-09-10 10:54:36 -0400964 Settings.UserSettingsActivity.class.getName()),
965 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
966 && !Utils.isMonkeyRunning(), isAdmin, pm);
967
Fyodor Kupolovca060e32016-06-24 13:01:11 -0700968 setTileEnabled(new ComponentName(packageName,
969 Settings.WirelessSettingsActivity.class.getName()),
970 !UserManager.isDeviceInDemoMode(this), isAdmin, pm);
971
972 setTileEnabled(new ComponentName(packageName,
973 Settings.DateTimeSettingsActivity.class.getName()),
974 !UserManager.isDeviceInDemoMode(this), isAdmin, pm);
Jason Monk4da79e02015-09-10 10:54:36 -0400975 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
976 setTileEnabled(new ComponentName(packageName,
977 Settings.PaymentSettingsActivity.class.getName()),
978 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
979 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
980 && adapter != null && adapter.isEnabled(), isAdmin, pm);
981
982 setTileEnabled(new ComponentName(packageName,
983 Settings.PrintSettingsActivity.class.getName()),
984 pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin, pm);
985
986 final boolean showDev = mDevelopmentPreferences.getBoolean(
Dan Sandler12c4ba42016-03-28 11:13:40 -0400987 DevelopmentSettings.PREF_SHOW, android.os.Build.TYPE.equals("eng"))
988 && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES);
Jason Monk4da79e02015-09-10 10:54:36 -0400989 setTileEnabled(new ComponentName(packageName,
990 Settings.DevelopmentSettingsActivity.class.getName()),
Dan Sandler12c4ba42016-03-28 11:13:40 -0400991 showDev, isAdmin, pm);
Fan Zhangcc335d92016-09-29 14:37:14 -0700992 setTileEnabled(new ComponentName(packageName,
993 Settings.DevelopmentSettingsActivity.DASHBOARD_ALIAS),
994 showDev, isAdmin, pm);
Dan Sandler12c4ba42016-03-28 11:13:40 -0400995
996 // Reveal development-only quick settings tiles
997 DevelopmentTiles.setTilesEnabled(this, showDev);
Jason Monk4da79e02015-09-10 10:54:36 -0400998
999 if (UserHandle.MU_ENABLED && !isAdmin) {
1000 // When on restricted users, disable all extra categories (but only the settings ones).
Fan Zhanga96a2d82016-09-27 17:51:11 -07001001 List<DashboardCategory> categories;
1002 if (isDashboardFeatureEnabled()) {
1003 categories = mDashboardFeatureProvider.getAllCategories();
1004 } else {
1005 categories = getDashboardCategories();
1006 }
1007
Jason Monk4da79e02015-09-10 10:54:36 -04001008 for (DashboardCategory category : categories) {
Jason Monkd4f03ec2016-01-07 16:25:34 -05001009 for (Tile tile : category.tiles) {
Jason Monk4da79e02015-09-10 10:54:36 -04001010 ComponentName component = tile.intent.getComponent();
Jason Monk5862c1e2016-06-07 14:02:33 -04001011 if (packageName.equals(component.getPackageName()) && !ArrayUtils.contains(
Jason Monk4da79e02015-09-10 10:54:36 -04001012 SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1013 setTileEnabled(component, false, isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001014 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001015 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001016 }
1017 }
Doris Ling26bf0032016-06-15 18:16:09 -07001018
1019 String backupIntent = getResources().getString(R.string.config_backup_settings_intent);
1020 boolean useDefaultBackup = TextUtils.isEmpty(backupIntent);
1021 setTileEnabled(new ComponentName(packageName,
1022 Settings.PrivacySettingsActivity.class.getName()), useDefaultBackup, isAdmin, pm);
Fan Zhang0e8d0d12016-11-02 09:15:33 -07001023 setTileEnabled(new ComponentName(packageName,
1024 "com.android.settings.PrivacyDashboardAlias"),
1025 useDefaultBackup, isAdmin, pm);
1026
Doris Ling26bf0032016-06-15 18:16:09 -07001027 boolean hasBackupActivity = false;
1028 if (!useDefaultBackup) {
1029 try {
1030 Intent intent = Intent.parseUri(backupIntent, 0);
1031 hasBackupActivity = !getPackageManager().queryIntentActivities(intent, 0).isEmpty();
1032 } catch (URISyntaxException e) {
1033 Log.e(LOG_TAG, "Invalid backup intent URI!", e);
1034 }
1035 }
Fan Zhang10dd4652016-11-16 10:24:26 -08001036
1037 // Enable/disble BackupSettingsActivity and its alias.
Doris Ling26bf0032016-06-15 18:16:09 -07001038 setTileEnabled(new ComponentName(packageName,
1039 BackupSettingsActivity.class.getName()), hasBackupActivity, isAdmin, pm);
Fan Zhang10dd4652016-11-16 10:24:26 -08001040 setTileEnabled(new ComponentName(packageName,
1041 "com.android.settings.BackupResetDashboardAlias"), hasBackupActivity, isAdmin, pm);
Doris Ling26bf0032016-06-15 18:16:09 -07001042
Bartosz Fabianowski05061fc2016-11-14 12:04:49 +01001043 setTileEnabled(new ComponentName(packageName,
1044 Settings.EnterprisePrivacySettingsActivity.class.getName()),
1045 FeatureFactory.getFactory(this).getEnterprisePrivacyFeatureProvider(this)
1046 .hasDeviceOwner(), isAdmin, pm);
Fan Zhang10dd4652016-11-16 10:24:26 -08001047 setTileEnabled(new ComponentName(packageName,
1048 "com.android.settings.EnterprisePrivacyDashboardAlias"),
1049 FeatureFactory.getFactory(this).getEnterprisePrivacyFeatureProvider(this)
1050 .hasDeviceOwner(), isAdmin, pm);
Jason Monk2ebc8a02015-02-13 15:23:19 -05001051 }
1052
Jason Monk4da79e02015-09-10 10:54:36 -04001053 private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin,
Fan Zhang10dd4652016-11-16 10:24:26 -08001054 PackageManager pm) {
Jason Monk5862c1e2016-06-07 14:02:33 -04001055 if (UserHandle.MU_ENABLED && !isAdmin && getPackageName().equals(component.getPackageName())
Jason Monk4da79e02015-09-10 10:54:36 -04001056 && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1057 enabled = false;
1058 }
Jason Monk5862c1e2016-06-07 14:02:33 -04001059 setTileEnabled(component, enabled);
Jason Monk2ebc8a02015-02-13 15:23:19 -05001060 }
1061
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001062 private void getMetaData() {
1063 try {
1064 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1065 PackageManager.GET_META_DATA);
1066 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001067 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1068 } catch (NameNotFoundException nnfe) {
1069 // No recovery
1070 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1071 }
1072 }
1073
Fan Zhanga96a2d82016-09-27 17:51:11 -07001074 @Override
1075 protected boolean isDashboardFeatureEnabled() {
1076 if (mDashboardFeatureProvider == null) {
1077 mDashboardFeatureProvider =
1078 FeatureFactory.getFactory(this).getDashboardFeatureProvider(this);
1079 }
1080 return mDashboardFeatureProvider.isEnabled();
1081 }
1082
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001083 // give subclasses access to the Next button
1084 public boolean hasNextButton() {
1085 return mNextButton != null;
1086 }
1087
1088 public Button getNextButton() {
1089 return mNextButton;
1090 }
1091
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001092 @Override
1093 public boolean shouldUpRecreateTask(Intent targetIntent) {
1094 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1095 }
1096
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001097 @Deprecated
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001098 @Override
1099 public boolean onQueryTextSubmit(String query) {
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001100 if (mSearchFeatureProvider.isEnabled()) {
1101 return false;
1102 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001103 mSearchQuery = query;
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001104 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001105 return mSearchResultsFragment.onQueryTextSubmit(query);
1106 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001107
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001108 @Deprecated
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001109 @Override
1110 public boolean onQueryTextChange(String newText) {
Fan Zhanga3e8f5c2016-12-01 09:52:10 -08001111 mSearchQuery = newText;
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001112 if (mSearchFeatureProvider.isEnabled() || mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001113 return false;
1114 }
1115 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001116 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001117
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001118 @Override
1119 public boolean onClose() {
1120 return false;
1121 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001122
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001123 @Override
1124 public boolean onMenuItemActionExpand(MenuItem item) {
1125 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001126 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001127 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001128 return true;
1129 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001130
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001131 @Override
1132 public boolean onMenuItemActionCollapse(MenuItem item) {
1133 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001134 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001135 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001136 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001137 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001138 return true;
1139 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001140
Jason Monk4da79e02015-09-10 10:54:36 -04001141 @Override
Jason Monkd4f03ec2016-01-07 16:25:34 -05001142 protected void onTileClicked(Tile tile) {
Jason Monk4da79e02015-09-10 10:54:36 -04001143 if (mIsShowingDashboard) {
1144 // If on dashboard, don't finish so the back comes back to here.
1145 openTile(tile);
1146 } else {
1147 super.onTileClicked(tile);
1148 }
1149 }
1150
Jason Monkaf001092015-11-04 13:16:18 -05001151 @Override
1152 public void onProfileTileOpen() {
1153 if (!mIsShowingDashboard) {
1154 finish();
1155 }
1156 }
1157
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001158 @Deprecated
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001159 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001160 if (mSearchResultsFragment != null) {
1161 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001162 }
Anna Galusza6b1e9db2016-03-30 17:25:36 -07001163 Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001164 if (current != null && current instanceof SearchResultsSummary) {
1165 mSearchResultsFragment = (SearchResultsSummary) current;
1166 } else {
Fan Zhang28691572016-03-23 15:31:08 -07001167 setContentHeaderView(null);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001168 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001169 SearchResultsSummary.class.getName(), null, false, true,
1170 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001171 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001172 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001173 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001174 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001175
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001176 @Deprecated
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001177 public void needToRevertToInitialFragment() {
1178 mNeedToRevertToInitialFragment = true;
1179 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001180
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001181 @Deprecated
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001182 private void revertToInitialFragment() {
1183 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001184 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001185 mSearchMenuItemExpanded = false;
1186 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1187 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001188 if (mSearchMenuItem != null) {
1189 mSearchMenuItem.collapseActionView();
1190 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001191 }
Jim Miller0698a212014-10-16 19:49:07 -07001192
1193 public Intent getResultIntentData() {
1194 return mResultIntentData;
1195 }
1196
1197 public void setResultIntentData(Intent resultIntentData) {
1198 mResultIntentData = resultIntentData;
1199 }
Jason Monkd4f03ec2016-01-07 16:25:34 -05001200
1201 public void startSuggestion(Intent intent) {
Matthew Fritze7ac78f22016-10-03 13:26:07 -07001202 if (intent == null || ActivityManager.isUserAMonkey()) {
Matthew Fritze703dc602016-09-30 12:36:27 -07001203 return;
1204 }
Matthew Fritzef265dbc2016-10-04 13:39:27 -07001205 mCurrentSuggestion = intent.getComponent();
Jason Monkd4f03ec2016-01-07 16:25:34 -05001206 startActivityForResult(intent, REQUEST_SUGGESTION);
1207 }
1208
1209 @Override
1210 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
1211 if (requestCode == REQUEST_SUGGESTION && mCurrentSuggestion != null
1212 && resultCode != RESULT_CANCELED) {
1213 getPackageManager().setComponentEnabledSetting(mCurrentSuggestion,
1214 PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
1215 }
1216 super.onActivityResult(requestCode, resultCode, data);
1217 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001218}