blob: 7fe116762b37377ab52311b3bea221edc678f58d [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;
Anton Philippov970a66c2017-01-19 18:17:44 +000036import android.os.Build;
37import android.os.Build.VERSION;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080038import android.os.Bundle;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080039import android.os.UserHandle;
40import android.os.UserManager;
Fan Zhanga3e8f5c2016-12-01 09:52:10 -080041import android.support.annotation.VisibleForTesting;
Jason Monk39b46742015-09-10 15:52:51 -040042import android.support.v14.preference.PreferenceFragment;
43import android.support.v7.preference.Preference;
44import android.support.v7.preference.PreferenceManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080045import android.text.TextUtils;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070046import android.transition.TransitionManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080047import android.util.Log;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070048import android.view.Menu;
49import android.view.MenuInflater;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080050import android.view.MenuItem;
51import android.view.View;
52import android.view.View.OnClickListener;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070053import android.view.ViewGroup;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080054import android.widget.Button;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070055import android.widget.SearchView;
Fan Zhang28691572016-03-23 15:31:08 -070056
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080057import com.android.internal.util.ArrayUtils;
Jason Monk4da79e02015-09-10 10:54:36 -040058import com.android.settings.Settings.WifiSettingsActivity;
Fan Zhanga3e8f5c2016-12-01 09:52:10 -080059import com.android.settings.core.gateway.SettingsGateway;
Fan Zhang5f79ae92016-08-18 16:04:19 -070060import com.android.settings.core.instrumentation.SharedPreferencesLogger;
Fan Zhang28691572016-03-23 15:31:08 -070061import com.android.settings.dashboard.DashboardContainerFragment;
Fan Zhanga96a2d82016-09-27 17:51:11 -070062import com.android.settings.dashboard.DashboardFeatureProvider;
63import com.android.settings.dashboard.DashboardSummary;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070064import com.android.settings.dashboard.SearchResultsSummary;
Fan Zhanga96a2d82016-09-27 17:51:11 -070065import com.android.settings.overlay.FeatureFactory;
Sunny Goyalbf9f2d22016-11-02 11:20:17 -070066import com.android.settings.qstile.DevelopmentModeTile;
Jason Monk2ebc8a02015-02-13 15:23:19 -050067import com.android.settings.search.DynamicIndexableContentMonitor;
Matthew Fritze0ed37c32016-10-24 10:12:49 -070068import com.android.settings.search2.SearchFeatureProvider;
Fabrice Di Meglio41937762014-05-13 19:51:59 -070069import com.android.settings.widget.SwitchBar;
Jason Monk4da79e02015-09-10 10:54:36 -040070import com.android.settingslib.drawer.DashboardCategory;
Jason Monk4da79e02015-09-10 10:54:36 -040071import com.android.settingslib.drawer.SettingsDrawerActivity;
Jason Monk7ea14c52016-01-22 14:28:02 -050072import com.android.settingslib.drawer.Tile;
Jason Monk2ebc8a02015-02-13 15:23:19 -050073
Doris Ling26bf0032016-06-15 18:16:09 -070074import java.net.URISyntaxException;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080075import java.util.ArrayList;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080076import java.util.List;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -070077import java.util.Set;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080078
Jason Monk4da79e02015-09-10 10:54:36 -040079public class SettingsActivity extends SettingsDrawerActivity
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080080 implements PreferenceManager.OnPreferenceTreeClickListener,
81 PreferenceFragment.OnPreferenceStartFragmentCallback,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +010082 ButtonBarHandler, FragmentManager.OnBackStackChangedListener,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070083 SearchView.OnQueryTextListener, SearchView.OnCloseListener,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +010084 MenuItem.OnActionExpandListener {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080085
86 private static final String LOG_TAG = "Settings";
87
Philip P. Moltmannd9779db2016-02-24 12:11:05 -080088 private static final int LOADER_ID_INDEXABLE_CONTENT_MONITOR = 1;
89
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080090 // Constants for state save/restore
Fabrice Di Meglio769630c2014-04-24 14:48:48 -070091 private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070092 private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
93 private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
Fabrice Di Megliob731dd02014-04-03 18:40:38 -070094 private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -070095 private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080096
97 /**
98 * When starting this activity, the invoking Intent can contain this extra
99 * string to specify which fragment should be initially displayed.
100 * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
101 * will call isValidFragment() to confirm that the fragment class name is valid for this
102 * activity.
103 */
104 public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
105
106 /**
107 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
108 * this extra can also be specified to supply a Bundle of arguments to pass
109 * to that fragment when it is instantiated during the initial creation
110 * of the activity.
111 */
112 public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
113
114 /**
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700115 * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
116 */
117 public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
118
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800119 public static final String BACK_STACK_PREFS = ":settings:prefs";
120
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800121 // extras that allow any preference activity to be launched as part of a wizard
122
123 // show Back and Next buttons? takes boolean parameter
124 // Back will then return RESULT_CANCELED and Next RESULT_OK
125 protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
126
127 // add a Skip button?
128 private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
129
130 // specify custom text for the Back or Next buttons, or cause a button to not appear
131 // at all by setting it to null
132 protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
133 protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
134
135 /**
136 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700137 * 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 -0800138 * that fragment.
139 */
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700140 public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100141 /**
142 * The package name used to resolve the title resource id.
143 */
144 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
145 ":settings:show_fragment_title_res_package_name";
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700146 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
147 ":settings:show_fragment_title_resid";
148 public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
149 ":settings:show_fragment_as_shortcut";
150
151 public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
152 ":settings:show_fragment_as_subsetting";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800153
Udam Saini92779ce2016-03-28 14:29:48 -0700154 public static final String EXTRA_HIDE_DRAWER = ":settings:hide_drawer";
155
Jason Monk30695812015-11-17 09:01:08 -0500156 public static final String META_DATA_KEY_FRAGMENT_CLASS =
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800157 "com.android.settings.FRAGMENT_CLASS";
158
159 private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
160
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700161 private static final String EMPTY_QUERY = "";
162
Jason Monkd4f03ec2016-01-07 16:25:34 -0500163 private static final int REQUEST_SUGGESTION = 42;
164
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800165 private String mFragmentClass;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800166
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800167 private CharSequence mInitialTitle;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700168 private int mInitialTitleResId;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800169
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700170 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
171 "android.settings.APPLICATION_DETAILS_SETTINGS"
172 };
173
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800174 private SharedPreferences mDevelopmentPreferences;
175 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
176
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800177 private boolean mBatteryPresent = true;
178 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800179 @Override
180 public void onReceive(Context context, Intent intent) {
181 String action = intent.getAction();
182 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
183 boolean batteryPresent = Utils.isBatteryPresent(intent);
184
185 if (mBatteryPresent != batteryPresent) {
186 mBatteryPresent = batteryPresent;
Jason Monk4da79e02015-09-10 10:54:36 -0400187 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800188 }
189 }
190 }
191 };
192
Clara Bayarri6934a042015-10-14 11:07:35 +0100193 private final BroadcastReceiver mUserAddRemoveReceiver = new BroadcastReceiver() {
194 @Override
195 public void onReceive(Context context, Intent intent) {
Matthew Fritze34c27602017-01-18 18:24:56 -0800196 if (mSearchFeatureProvider != null && !mSearchFeatureProvider.isEnabled(context)) {
197 String action = intent.getAction();
198 if (action.equals(Intent.ACTION_USER_ADDED)
199 || action.equals(Intent.ACTION_USER_REMOVED)) {
200 mSearchFeatureProvider.updateIndex(getApplicationContext());
201 }
Clara Bayarri6934a042015-10-14 11:07:35 +0100202 }
203 }
204 };
205
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800206 private DynamicIndexableContentMonitor mDynamicIndexableContentMonitor;
Svetoslav853e4712014-04-14 10:10:25 -0700207
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700208 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700209 private SwitchBar mSwitchBar;
210
211 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700212
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700213 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700214 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700215
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700216 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700217 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700218
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700219 private ViewGroup mContent;
220
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700221 private SearchView mSearchView;
222 private MenuItem mSearchMenuItem;
223 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700224 private SearchResultsSummary mSearchResultsFragment;
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700225 private SearchFeatureProvider mSearchFeatureProvider;
226
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700227 // Categories
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800228 private ArrayList<DashboardCategory> mCategories = new ArrayList<>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800229
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700230 private boolean mNeedToRevertToInitialFragment = false;
231
Fan Zhanga96a2d82016-09-27 17:51:11 -0700232 private DashboardFeatureProvider mDashboardFeatureProvider;
Jim Miller0698a212014-10-16 19:49:07 -0700233 private Intent mResultIntentData;
Jason Monkd4f03ec2016-01-07 16:25:34 -0500234 private ComponentName mCurrentSuggestion;
Jim Miller0698a212014-10-16 19:49:07 -0700235
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800236 @VisibleForTesting
237 String mSearchQuery;
238
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700239 public SwitchBar getSwitchBar() {
240 return mSwitchBar;
241 }
242
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800243 @Override
244 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
Sunny Goyal21ef89f2016-05-25 12:41:16 -0700245 startPreferencePanel(pref.getFragment(), pref.getExtras(), -1, pref.getTitle(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800246 null, 0);
247 return true;
248 }
249
250 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400251 public boolean onPreferenceTreeClick(Preference preference) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800252 return false;
253 }
254
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800255 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800256 public void onConfigurationChanged(Configuration newConfig) {
257 super.onConfigurationChanged(newConfig);
Matthew Fritze34c27602017-01-18 18:24:56 -0800258 if (!mSearchFeatureProvider.isEnabled(this)) {
259 mSearchFeatureProvider.updateIndex(getApplicationContext());
260 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800261 }
262
263 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700264 protected void onStart() {
265 super.onStart();
266
267 if (mNeedToRevertToInitialFragment) {
268 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800269 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800270 }
271
272 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700273 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700274 if (!mDisplaySearch) {
275 return false;
276 }
277
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700278 MenuInflater inflater = getMenuInflater();
Matthew Fritze9955db62016-12-20 09:37:21 -0800279 if (mSearchFeatureProvider.isEnabled(this)) {
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700280 mSearchFeatureProvider.setUpSearchMenu(menu, this);
281 return true;
282 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700283 inflater.inflate(R.menu.options_menu, menu);
284
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700285
286 // Cache the search query (can be overridden by the OnQueryTextListener)
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700287 final String query = mSearchQuery;
288
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700289 mSearchMenuItem = menu.findItem(R.id.search);
290 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700291
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700292 if (mSearchMenuItem == null || mSearchView == null) {
293 return false;
294 }
295
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700296 if (mSearchResultsFragment != null) {
297 mSearchResultsFragment.setSearchView(mSearchView);
298 }
299
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700300 mSearchMenuItem.setOnActionExpandListener(this);
Fan Zhangb9239182016-08-22 13:59:59 -0700301 mSearchView.setMaxWidth(Integer.MAX_VALUE);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700302 mSearchView.setOnQueryTextListener(this);
303 mSearchView.setOnCloseListener(this);
304
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700305 if (mSearchMenuItemExpanded) {
306 mSearchMenuItem.expandActionView();
307 }
308 mSearchView.setQuery(query, true /* submit */);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700309 return true;
310 }
311
Jason Monk31c7c322016-01-20 14:41:52 -0500312 @Override
313 public SharedPreferences getSharedPreferences(String name, int mode) {
314 if (name.equals(getPackageName() + "_preferences")) {
Jason Monke4ebcd12016-02-21 09:37:41 -0500315 return new SharedPreferencesLogger(this, getMetricsTag());
Jason Monk31c7c322016-01-20 14:41:52 -0500316 }
317 return super.getSharedPreferences(name, mode);
318 }
319
Jason Monke4ebcd12016-02-21 09:37:41 -0500320 private String getMetricsTag() {
321 String tag = getClass().getName();
322 if (getIntent() != null && getIntent().hasExtra(EXTRA_SHOW_FRAGMENT)) {
323 tag = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
324 }
325 if (tag.startsWith("com.android.settings.")) {
326 tag = tag.replace("com.android.settings.", "");
327 }
328 return tag;
329 }
330
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700331 private static boolean isShortCutIntent(final Intent intent) {
332 Set<String> categories = intent.getCategories();
333 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
334 }
335
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700336 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700337 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700338 if (action == null) {
339 return false;
340 }
341 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
342 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
343 }
344 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700345 }
346
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700347 @Override
348 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700349 super.onCreate(savedState);
Jason Monkfd2c7222015-12-02 15:38:38 -0500350 long startTime = System.currentTimeMillis();
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700351
352 final FeatureFactory factory = FeatureFactory.getFactory(this);
353
354 mDashboardFeatureProvider = factory.getDashboardFeatureProvider(this);
Matthew Fritze9955db62016-12-20 09:37:21 -0800355 mSearchFeatureProvider = factory.getSearchFeatureProvider();
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700356
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700357 // Should happen before any call to getIntent()
358 getMetaData();
359
360 final Intent intent = getIntent();
361 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
362 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800363 }
Udam Saini92779ce2016-03-28 14:29:48 -0700364 if (intent.getBooleanExtra(EXTRA_HIDE_DRAWER, false)) {
365 setIsDrawerPresent(false);
366 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800367
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800368 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
369 Context.MODE_PRIVATE);
370
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700371 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700372 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700373
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700374 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700375 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
376
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700377 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700378 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700379
Jason Monk4da79e02015-09-10 10:54:36 -0400380 mIsShowingDashboard = className.equals(Settings.class.getName())
381 || className.equals(Settings.WirelessSettings.class.getName())
382 || className.equals(Settings.DeviceSettings.class.getName())
383 || className.equals(Settings.PersonalSettings.class.getName())
384 || className.equals(Settings.WirelessSettings.class.getName());
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700385
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700386 // This is a "Sub Settings" when:
387 // - this is a real SubSettings
388 // - or :settings:show_fragment_as_subsetting is passed to the Intent
Jorim Jaggi4dfcb822015-04-29 17:21:32 -0700389 final boolean isSubSettings = this instanceof SubSettings ||
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700390 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
391
392 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
393 if (isSubSettings) {
Fabrice Di Meglio712df6c2014-07-18 17:44:37 -0700394 // Check also that we are not a Theme Dialog as we don't want to override them
395 final int themeResId = getThemeResId();
396 if (themeResId != R.style.Theme_DialogWhenLarge &&
397 themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
398 setTheme(R.style.Theme_SubSettings);
399 }
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700400 }
401
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700402 setContentView(mIsShowingDashboard ?
403 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800404
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700405 mContent = (ViewGroup) findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700406
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800407 getFragmentManager().addOnBackStackChangedListener(this);
408
Matthew Fritze34c27602017-01-18 18:24:56 -0800409 if (mIsShowingDashboard && !mSearchFeatureProvider.isEnabled(this)) {
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800410 // Run the Index update only if we have some space
411 if (!Utils.isLowStorage(this)) {
Fan Zhanga8759242017-01-06 09:18:59 -0800412 mSearchFeatureProvider.updateIndex(getApplicationContext());
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800413 } else {
414 Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
415 }
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700416 }
417
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700418 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700419 // We are restarting from a previous saved state; used that to initialize, instead
420 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700421 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
422 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700423 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800424
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700425 ArrayList<DashboardCategory> categories =
426 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
427 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700428 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700429 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700430 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800431 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700432
433 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700434 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Salvador Martinez2368e542016-07-25 18:16:47 -0700435
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800436 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700437 if (!mIsShowingDashboard) {
Jason Monkea8b1a72015-06-02 16:46:34 -0400438 mDisplaySearch = false;
439 // UP will be shown only if it is a sub settings
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700440 if (mIsShortcut) {
441 mDisplayHomeAsUpEnabled = isSubSettings;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700442 } else if (isSubSettings) {
443 mDisplayHomeAsUpEnabled = true;
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700444 } else {
445 mDisplayHomeAsUpEnabled = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700446 }
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700447 setTitleFromIntent(intent);
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700448
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700449 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700450 switchToFragment(initialFragmentName, initialArguments, true, false,
451 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000452 } else {
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700453 // No UP affordance if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700454 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700455 // Show Search affordance
456 mDisplaySearch = true;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700457 mInitialTitleResId = R.string.dashboard_title;
Salvador Martinez2368e542016-07-25 18:16:47 -0700458
459 // add argument to indicate which settings tab should be initially selected
460 final Bundle args = new Bundle();
461 final String extraName = DashboardContainerFragment.EXTRA_SELECT_SETTINGS_TAB;
462 args.putString(extraName, intent.getStringExtra(extraName));
Fan Zhanga96a2d82016-09-27 17:51:11 -0700463 if (isDashboardFeatureEnabled()) {
464 switchToFragment(DashboardSummary.class.getName(), args, false, false,
465 mInitialTitleResId, mInitialTitle, false);
466 } else {
467 switchToFragment(DashboardContainerFragment.class.getName(), args, false, false,
468 mInitialTitleResId, mInitialTitle, false);
469 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800470 }
471 }
472
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700473 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700474 if (mActionBar != null) {
475 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
476 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
477 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700478 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
Jason Monke4ebcd12016-02-21 09:37:41 -0500479 if (mSwitchBar != null) {
480 mSwitchBar.setMetricsTag(getMetricsTag());
481 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700482
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800483 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800484 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
485
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700486 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800487 if (buttonBar != null) {
488 buttonBar.setVisibility(View.VISIBLE);
489
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700490 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800491 backButton.setOnClickListener(new OnClickListener() {
492 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700493 setResult(RESULT_CANCELED, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800494 finish();
495 }
496 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700497 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800498 skipButton.setOnClickListener(new OnClickListener() {
499 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700500 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800501 finish();
502 }
503 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700504 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800505 mNextButton.setOnClickListener(new OnClickListener() {
506 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700507 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800508 finish();
509 }
510 });
511
512 // set our various button parameters
513 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
514 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
515 if (TextUtils.isEmpty(buttonText)) {
516 mNextButton.setVisibility(View.GONE);
517 }
518 else {
519 mNextButton.setText(buttonText);
520 }
521 }
522 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
523 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
524 if (TextUtils.isEmpty(buttonText)) {
525 backButton.setVisibility(View.GONE);
526 }
527 else {
528 backButton.setText(buttonText);
529 }
530 }
531 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
532 skipButton.setVisibility(View.VISIBLE);
533 }
534 }
535 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700536
Jason Monkfd2c7222015-12-02 15:38:38 -0500537 if (DEBUG_TIMING) Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
538 + " ms");
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700539 }
540
Fan Zhangece8ff62016-06-30 13:20:12 -0700541 public void setDisplaySearchMenu(boolean displaySearch) {
542 if (displaySearch != mDisplaySearch) {
543 mDisplaySearch = displaySearch;
544 invalidateOptionsMenu();
545 }
546 }
547
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700548 private void setTitleFromIntent(Intent intent) {
549 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
550 if (initialTitleResId > 0) {
551 mInitialTitle = null;
552 mInitialTitleResId = initialTitleResId;
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100553
554 final String initialTitleResPackageName = intent.getStringExtra(
555 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
556 if (initialTitleResPackageName != null) {
557 try {
558 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
559 0 /* flags */, new UserHandle(UserHandle.myUserId()));
560 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
561 setTitle(mInitialTitle);
562 mInitialTitleResId = -1;
563 return;
564 } catch (NameNotFoundException e) {
565 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
566 }
567 } else {
568 setTitle(mInitialTitleResId);
569 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700570 } else {
571 mInitialTitleResId = -1;
572 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
573 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
574 setTitle(mInitialTitle);
575 }
576 }
577
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800578 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800579 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700580 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800581 }
582
Fan Zhang28691572016-03-23 15:31:08 -0700583 private void setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800584 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700585
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800586 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700587 if (mInitialTitleResId > 0) {
588 setTitle(mInitialTitleResId);
589 } else {
590 setTitle(mInitialTitle);
591 }
Fan Zhang28691572016-03-23 15:31:08 -0700592 return;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800593 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700594
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800595 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
596 setTitleFromBackStackEntry(bse);
597 }
598
599 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
600 final CharSequence title;
601 final int titleRes = bse.getBreadCrumbTitleRes();
602 if (titleRes > 0) {
603 title = getText(titleRes);
604 } else {
605 title = bse.getBreadCrumbTitle();
606 }
607 if (title != null) {
608 setTitle(title);
609 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800610 }
611
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800612 @Override
613 protected void onSaveInstanceState(Bundle outState) {
614 super.onSaveInstanceState(outState);
615
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700616 if (mCategories.size() > 0) {
617 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800618 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700619
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700620 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700621 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700622
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700623 if (mDisplaySearch) {
624 // The option menus are created if the ActionBar is visible and they are also created
625 // asynchronously. If you launch Settings with an Intent action like
626 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
627 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
628 // menu item and search view are null.
629 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
630 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700631
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700632 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
633 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
634 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800635 }
636
637 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400638 protected void onResume() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800639 super.onResume();
640
641 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
642 @Override
643 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Jason Monk4da79e02015-09-10 10:54:36 -0400644 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800645 }
646 };
647 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
648 mDevelopmentPreferencesListener);
649
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800650 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Matthew Fritze34c27602017-01-18 18:24:56 -0800651 if (!mSearchFeatureProvider.isEnabled(this)) {
652 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_ADDED));
653 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_REMOVED));
654 }
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800655 if (mDynamicIndexableContentMonitor == null) {
656 mDynamicIndexableContentMonitor = new DynamicIndexableContentMonitor();
657 }
Philip P. Moltmannd9779db2016-02-24 12:11:05 -0800658 mDynamicIndexableContentMonitor.register(this, LOADER_ID_INDEXABLE_CONTENT_MONITOR);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700659
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700660 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700661 onQueryTextSubmit(mSearchQuery);
662 }
Jason Monk4da79e02015-09-10 10:54:36 -0400663 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800664 }
665
666 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400667 protected void onPause() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800668 super.onPause();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800669 unregisterReceiver(mBatteryInfoReceiver);
Matthew Fritze34c27602017-01-18 18:24:56 -0800670 if (!mSearchFeatureProvider.isEnabled(this)) {
671 unregisterReceiver(mUserAddRemoveReceiver);
672 }
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800673 if (mDynamicIndexableContentMonitor != null) {
Tadashi G. Takaokaa034fa52016-11-21 14:20:19 +0900674 mDynamicIndexableContentMonitor.unregister(this, LOADER_ID_INDEXABLE_CONTENT_MONITOR);
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800675 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800676 }
677
678 @Override
679 public void onDestroy() {
680 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700681
682 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
683 mDevelopmentPreferencesListener);
684 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800685 }
686
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800687 protected boolean isValidFragment(String fragmentName) {
688 // Almost all fragments are wrapped in this,
689 // except for a few that have their own activities.
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800690 for (int i = 0; i < SettingsGateway.ENTRY_FRAGMENTS.length; i++) {
691 if (SettingsGateway.ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800692 }
693 return false;
694 }
695
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800696 @Override
697 public Intent getIntent() {
698 Intent superIntent = super.getIntent();
699 String startingFragment = getStartingFragmentClass(superIntent);
700 // This is called from super.onCreate, isMultiPane() is not yet reliable
701 // Do not use onIsHidingHeaders either, which relies itself on this method
702 if (startingFragment != null) {
703 Intent modIntent = new Intent(superIntent);
704 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
705 Bundle args = superIntent.getExtras();
706 if (args != null) {
707 args = new Bundle(args);
708 } else {
709 args = new Bundle();
710 }
711 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100712 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800713 return modIntent;
714 }
715 return superIntent;
716 }
717
718 /**
719 * Checks if the component name in the intent is different from the Settings class and
720 * returns the class name to load as a fragment.
721 */
722 private String getStartingFragmentClass(Intent intent) {
723 if (mFragmentClass != null) return mFragmentClass;
724
725 String intentClass = intent.getComponent().getClassName();
726 if (intentClass.equals(getClass().getName())) return null;
727
728 if ("com.android.settings.ManageApplications".equals(intentClass)
729 || "com.android.settings.RunningServices".equals(intentClass)
730 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
731 // Old names of manage apps.
732 intentClass = com.android.settings.applications.ManageApplications.class.getName();
733 }
734
735 return intentClass;
736 }
737
738 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000739 * Start a new fragment containing a preference panel. If the preferences
740 * are being displayed in multi-pane mode, the given fragment class will
741 * be instantiated and placed in the appropriate pane. If running in
742 * single-pane mode, a new activity will be launched in which to show the
743 * fragment.
744 *
745 * @param fragmentClass Full name of the class implementing the fragment.
746 * @param args Any desired arguments to supply to the fragment.
747 * @param titleRes Optional resource identifier of the title of this
748 * fragment.
749 * @param titleText Optional text of the title of this fragment.
750 * @param resultTo Optional fragment that result data should be sent to.
751 * If non-null, resultTo.onActivityResult() will be called when this
752 * preference panel is done. The launched panel must use
753 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
754 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700755 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000756 */
757 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700758 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700759 String title = null;
760 if (titleRes < 0) {
761 if (titleText != null) {
762 title = titleText.toString();
763 } else {
764 // There not much we can do in that case
765 title = "";
766 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700767 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700768 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700769 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000770 }
771
772 /**
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100773 * Start a new fragment in a new activity containing a preference panel for a given user. If the
774 * preferences are being displayed in multi-pane mode, the given fragment class will be
775 * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
776 * activity will be launched in which to show the fragment.
777 *
778 * @param fragmentClass Full name of the class implementing the fragment.
779 * @param args Any desired arguments to supply to the fragment.
780 * @param titleRes Optional resource identifier of the title of this fragment.
781 * @param titleText Optional text of the title of this fragment.
782 * @param userHandle The user for which the panel has to be started.
783 */
784 public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
785 CharSequence titleText, UserHandle userHandle) {
Lifu Tangd0332852015-04-02 12:05:46 -0700786 // This is a workaround.
787 //
788 // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
789 // starting the fragment could cause a native stack corruption. See b/17523189. However,
790 // adding that flag and start the preference panel with the same UserHandler will make it
791 // impossible to use back button to return to the previous screen. See b/20042570.
792 //
793 // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
794 // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
795 // when we're calling it as the same user.
796 if (userHandle.getIdentifier() == UserHandle.myUserId()) {
797 startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0);
798 } else {
799 String title = null;
800 if (titleRes < 0) {
801 if (titleText != null) {
802 title = titleText.toString();
803 } else {
804 // There not much we can do in that case
805 title = "";
806 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100807 }
Lifu Tangd0332852015-04-02 12:05:46 -0700808 Utils.startWithFragmentAsUser(this, fragmentClass, args,
809 titleRes, title, mIsShortcut, userHandle);
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100810 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100811 }
812
813 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800814 * Called by a preference panel fragment to finish itself.
815 *
816 * @param caller The fragment that is asking to be finished.
817 * @param resultCode Optional result code to send back to the original
818 * launching fragment.
819 * @param resultData Optional result data to send back to the original
820 * launching fragment.
821 */
822 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
823 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700824 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800825 }
826
827 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000828 * Start a new fragment.
829 *
830 * @param fragment The fragment to start
831 * @param push If true, the current fragment will be pushed onto the back stack. If false,
832 * the current fragment will be replaced.
833 */
834 public void startPreferenceFragment(Fragment fragment, boolean push) {
835 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700836 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000837 if (push) {
838 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
839 transaction.addToBackStack(BACK_STACK_PREFS);
840 } else {
841 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
842 }
843 transaction.commitAllowingStateLoss();
844 }
845
846 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700847 * Switch to a specific Fragment with taking care of validation, Title and BackStack
848 */
849 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700850 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700851 if (validate && !isValidFragment(fragmentName)) {
852 throw new IllegalArgumentException("Invalid fragment for this activity: "
853 + fragmentName);
854 }
855 Fragment f = Fragment.instantiate(this, fragmentName, args);
856 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700857 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700858 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700859 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700860 }
861 if (addToBackStack) {
862 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
863 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700864 if (titleResId > 0) {
865 transaction.setBreadCrumbTitle(titleResId);
866 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700867 transaction.setBreadCrumbTitle(title);
868 }
869 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700870 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700871 return f;
872 }
873
Jason Monk4da79e02015-09-10 10:54:36 -0400874 private void updateTilesList() {
Jason Monkfd2c7222015-12-02 15:38:38 -0500875 // Generally the items that are will be changing from these updates will
876 // not be in the top list of tiles, so run it in the background and the
877 // SettingsDrawerActivity will pick up on the updates automatically.
878 AsyncTask.execute(new Runnable() {
879 @Override
880 public void run() {
881 doUpdateTilesList();
882 }
883 });
884 }
885
886 private void doUpdateTilesList() {
Jason Monk4da79e02015-09-10 10:54:36 -0400887 PackageManager pm = getPackageManager();
Xiaohui Chen44879a32015-07-22 13:53:22 -0700888 final UserManager um = UserManager.get(this);
889 final boolean isAdmin = um.isAdminUser();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700890
Jason Monk4da79e02015-09-10 10:54:36 -0400891 String packageName = getPackageName();
892 setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800893 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700894
Jason Monk4da79e02015-09-10 10:54:36 -0400895 setTileEnabled(new ComponentName(packageName,
896 Settings.BluetoothSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800897 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700898
Jason Monk4da79e02015-09-10 10:54:36 -0400899 setTileEnabled(new ComponentName(packageName,
900 Settings.DataUsageSummaryActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800901 Utils.isBandwidthControlEnabled(), isAdmin);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700902
Jason Monk4da79e02015-09-10 10:54:36 -0400903 setTileEnabled(new ComponentName(packageName,
904 Settings.SimSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800905 Utils.showSimCardTile(this), isAdmin);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700906
Jason Monk4da79e02015-09-10 10:54:36 -0400907 setTileEnabled(new ComponentName(packageName,
908 Settings.PowerUsageSummaryActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800909 mBatteryPresent, isAdmin);
Jason Monk4da79e02015-09-10 10:54:36 -0400910
911 setTileEnabled(new ComponentName(packageName,
Jason Monk4da79e02015-09-10 10:54:36 -0400912 Settings.UserSettingsActivity.class.getName()),
913 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
Fan Zhang224caad2017-01-06 11:42:48 -0800914 && !Utils.isMonkeyRunning(), isAdmin);
Jason Monk4da79e02015-09-10 10:54:36 -0400915
Fyodor Kupolovca060e32016-06-24 13:01:11 -0700916 setTileEnabled(new ComponentName(packageName,
917 Settings.WirelessSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800918 !UserManager.isDeviceInDemoMode(this), isAdmin);
Fyodor Kupolovca060e32016-06-24 13:01:11 -0700919
920 setTileEnabled(new ComponentName(packageName,
921 Settings.DateTimeSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800922 !UserManager.isDeviceInDemoMode(this), isAdmin);
Jason Monk4da79e02015-09-10 10:54:36 -0400923 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
924 setTileEnabled(new ComponentName(packageName,
925 Settings.PaymentSettingsActivity.class.getName()),
926 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
927 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
Fan Zhang224caad2017-01-06 11:42:48 -0800928 && adapter != null && adapter.isEnabled(), isAdmin);
Fan Zhangffd328b2017-01-09 10:16:49 -0800929 setTileEnabled(new ComponentName(packageName,
930 "com.android.settings.PaymentSettingsDashboardAlias"),
931 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
932 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
933 && adapter != null && adapter.isEnabled(), isAdmin);
Jason Monk4da79e02015-09-10 10:54:36 -0400934
935 setTileEnabled(new ComponentName(packageName,
936 Settings.PrintSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800937 pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin);
Jason Monk4da79e02015-09-10 10:54:36 -0400938
939 final boolean showDev = mDevelopmentPreferences.getBoolean(
Dan Sandler12c4ba42016-03-28 11:13:40 -0400940 DevelopmentSettings.PREF_SHOW, android.os.Build.TYPE.equals("eng"))
941 && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES);
Jason Monk4da79e02015-09-10 10:54:36 -0400942 setTileEnabled(new ComponentName(packageName,
943 Settings.DevelopmentSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800944 showDev, isAdmin);
Fan Zhangcc335d92016-09-29 14:37:14 -0700945 setTileEnabled(new ComponentName(packageName,
946 Settings.DevelopmentSettingsActivity.DASHBOARD_ALIAS),
Fan Zhang224caad2017-01-06 11:42:48 -0800947 showDev, isAdmin);
Dan Sandler12c4ba42016-03-28 11:13:40 -0400948
949 // Reveal development-only quick settings tiles
Sunny Goyalbf9f2d22016-11-02 11:20:17 -0700950 setTileEnabled(new ComponentName(this, DevelopmentModeTile.class), showDev);
Jason Monk4da79e02015-09-10 10:54:36 -0400951
952 if (UserHandle.MU_ENABLED && !isAdmin) {
953 // When on restricted users, disable all extra categories (but only the settings ones).
Fan Zhanga96a2d82016-09-27 17:51:11 -0700954 List<DashboardCategory> categories;
955 if (isDashboardFeatureEnabled()) {
956 categories = mDashboardFeatureProvider.getAllCategories();
957 } else {
958 categories = getDashboardCategories();
959 }
960
Jason Monk4da79e02015-09-10 10:54:36 -0400961 for (DashboardCategory category : categories) {
Jason Monkd4f03ec2016-01-07 16:25:34 -0500962 for (Tile tile : category.tiles) {
Jason Monk4da79e02015-09-10 10:54:36 -0400963 ComponentName component = tile.intent.getComponent();
Fan Zhang9ec45362017-01-10 11:55:45 -0800964 final String name = component.getClassName();
965 final boolean isEnabledForRestricted = ArrayUtils.contains(
966 SettingsGateway.SETTINGS_FOR_RESTRICTED, name);
967 if (packageName.equals(component.getPackageName()) && !isEnabledForRestricted) {
Fan Zhang224caad2017-01-06 11:42:48 -0800968 setTileEnabled(component, false, isAdmin);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700969 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700970 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700971 }
972 }
Doris Ling26bf0032016-06-15 18:16:09 -0700973
Anton Philippov970a66c2017-01-19 18:17:44 +0000974 // Check if the backup transport has provided an intent to launch the backup settings.
975 BackupSettingsHelper backupHelper = new BackupSettingsHelper();
976 boolean useDefaultBackup = !backupHelper.isIntentProvidedByTransport(getPackageManager());
977 if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) {
978 Log.v(LOG_TAG, "Enabling default backup settings page: " + useDefaultBackup);
979 }
980
Doris Ling26bf0032016-06-15 18:16:09 -0700981 setTileEnabled(new ComponentName(packageName,
Fan Zhang224caad2017-01-06 11:42:48 -0800982 Settings.PrivacySettingsActivity.class.getName()), useDefaultBackup, isAdmin);
Fan Zhang0e8d0d12016-11-02 09:15:33 -0700983 setTileEnabled(new ComponentName(packageName,
984 "com.android.settings.PrivacyDashboardAlias"),
Fan Zhang224caad2017-01-06 11:42:48 -0800985 useDefaultBackup, isAdmin);
Fan Zhang0e8d0d12016-11-02 09:15:33 -0700986
Fan Zhang224caad2017-01-06 11:42:48 -0800987 // Enable/disable BackupSettingsActivity and its alias.
Anton Philippov970a66c2017-01-19 18:17:44 +0000988 if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) {
989 Log.v(LOG_TAG, "Enabling transport provided backup settings: " + !useDefaultBackup);
990 }
Doris Ling26bf0032016-06-15 18:16:09 -0700991 setTileEnabled(new ComponentName(packageName,
Anton Philippov970a66c2017-01-19 18:17:44 +0000992 BackupSettingsActivity.class.getName()), !useDefaultBackup, isAdmin);
Fan Zhang10dd4652016-11-16 10:24:26 -0800993 setTileEnabled(new ComponentName(packageName,
Anton Philippov970a66c2017-01-19 18:17:44 +0000994 "com.android.settings.BackupResetDashboardAlias"), !useDefaultBackup, isAdmin);
Doris Ling26bf0032016-06-15 18:16:09 -0700995
Bartosz Fabianowski05061fc2016-11-14 12:04:49 +0100996 setTileEnabled(new ComponentName(packageName,
997 Settings.EnterprisePrivacySettingsActivity.class.getName()),
998 FeatureFactory.getFactory(this).getEnterprisePrivacyFeatureProvider(this)
Fan Zhang224caad2017-01-06 11:42:48 -0800999 .hasDeviceOwner(), isAdmin);
Fan Zhang10dd4652016-11-16 10:24:26 -08001000 setTileEnabled(new ComponentName(packageName,
1001 "com.android.settings.EnterprisePrivacyDashboardAlias"),
1002 FeatureFactory.getFactory(this).getEnterprisePrivacyFeatureProvider(this)
Fan Zhang224caad2017-01-06 11:42:48 -08001003 .hasDeviceOwner(), isAdmin);
1004 // Final step, refresh categories.
1005 updateCategories();
Jason Monk2ebc8a02015-02-13 15:23:19 -05001006 }
1007
Fan Zhang224caad2017-01-06 11:42:48 -08001008 private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin) {
Jason Monk5862c1e2016-06-07 14:02:33 -04001009 if (UserHandle.MU_ENABLED && !isAdmin && getPackageName().equals(component.getPackageName())
Fan Zhang9ec45362017-01-10 11:55:45 -08001010 && !ArrayUtils.contains(SettingsGateway.SETTINGS_FOR_RESTRICTED,
1011 component.getClassName())) {
Jason Monk4da79e02015-09-10 10:54:36 -04001012 enabled = false;
1013 }
Jason Monk5862c1e2016-06-07 14:02:33 -04001014 setTileEnabled(component, enabled);
Jason Monk2ebc8a02015-02-13 15:23:19 -05001015 }
1016
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001017 private void getMetaData() {
1018 try {
1019 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1020 PackageManager.GET_META_DATA);
1021 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001022 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1023 } catch (NameNotFoundException nnfe) {
1024 // No recovery
1025 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1026 }
1027 }
1028
Fan Zhanga96a2d82016-09-27 17:51:11 -07001029 @Override
1030 protected boolean isDashboardFeatureEnabled() {
1031 if (mDashboardFeatureProvider == null) {
1032 mDashboardFeatureProvider =
1033 FeatureFactory.getFactory(this).getDashboardFeatureProvider(this);
1034 }
1035 return mDashboardFeatureProvider.isEnabled();
1036 }
1037
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001038 // give subclasses access to the Next button
1039 public boolean hasNextButton() {
1040 return mNextButton != null;
1041 }
1042
1043 public Button getNextButton() {
1044 return mNextButton;
1045 }
1046
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001047 @Override
1048 public boolean shouldUpRecreateTask(Intent targetIntent) {
1049 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1050 }
1051
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001052 @Deprecated
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001053 @Override
1054 public boolean onQueryTextSubmit(String query) {
Matthew Fritze9955db62016-12-20 09:37:21 -08001055 if (mSearchFeatureProvider.isEnabled(this)) {
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001056 return false;
1057 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001058 mSearchQuery = query;
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001059 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001060 return mSearchResultsFragment.onQueryTextSubmit(query);
1061 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001062
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001063 @Deprecated
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001064 @Override
1065 public boolean onQueryTextChange(String newText) {
Fan Zhanga3e8f5c2016-12-01 09:52:10 -08001066 mSearchQuery = newText;
Matthew Fritze9955db62016-12-20 09:37:21 -08001067 if (mSearchFeatureProvider.isEnabled(this) || mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001068 return false;
1069 }
1070 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001071 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001072
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001073 @Override
1074 public boolean onClose() {
1075 return false;
1076 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001077
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001078 @Override
1079 public boolean onMenuItemActionExpand(MenuItem item) {
1080 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001081 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001082 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001083 return true;
1084 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001085
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001086 @Override
1087 public boolean onMenuItemActionCollapse(MenuItem item) {
1088 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001089 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001090 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001091 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001092 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001093 return true;
1094 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001095
Jason Monk4da79e02015-09-10 10:54:36 -04001096 @Override
Jason Monkd4f03ec2016-01-07 16:25:34 -05001097 protected void onTileClicked(Tile tile) {
Jason Monk4da79e02015-09-10 10:54:36 -04001098 if (mIsShowingDashboard) {
1099 // If on dashboard, don't finish so the back comes back to here.
1100 openTile(tile);
1101 } else {
1102 super.onTileClicked(tile);
1103 }
1104 }
1105
Jason Monkaf001092015-11-04 13:16:18 -05001106 @Override
1107 public void onProfileTileOpen() {
1108 if (!mIsShowingDashboard) {
1109 finish();
1110 }
1111 }
1112
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001113 @Deprecated
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001114 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001115 if (mSearchResultsFragment != null) {
1116 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001117 }
Anna Galusza6b1e9db2016-03-30 17:25:36 -07001118 Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001119 if (current != null && current instanceof SearchResultsSummary) {
1120 mSearchResultsFragment = (SearchResultsSummary) current;
1121 } else {
Fan Zhang28691572016-03-23 15:31:08 -07001122 setContentHeaderView(null);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001123 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001124 SearchResultsSummary.class.getName(), null, false, true,
1125 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001126 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001127 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001128 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001129 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001130
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001131 @Deprecated
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001132 public void needToRevertToInitialFragment() {
1133 mNeedToRevertToInitialFragment = true;
1134 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001135
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001136 @Deprecated
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001137 private void revertToInitialFragment() {
1138 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001139 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001140 mSearchMenuItemExpanded = false;
1141 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1142 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001143 if (mSearchMenuItem != null) {
1144 mSearchMenuItem.collapseActionView();
1145 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001146 }
Jim Miller0698a212014-10-16 19:49:07 -07001147
1148 public Intent getResultIntentData() {
1149 return mResultIntentData;
1150 }
1151
1152 public void setResultIntentData(Intent resultIntentData) {
1153 mResultIntentData = resultIntentData;
1154 }
Jason Monkd4f03ec2016-01-07 16:25:34 -05001155
1156 public void startSuggestion(Intent intent) {
Matthew Fritze7ac78f22016-10-03 13:26:07 -07001157 if (intent == null || ActivityManager.isUserAMonkey()) {
Matthew Fritze703dc602016-09-30 12:36:27 -07001158 return;
1159 }
Matthew Fritzef265dbc2016-10-04 13:39:27 -07001160 mCurrentSuggestion = intent.getComponent();
Jason Monkd4f03ec2016-01-07 16:25:34 -05001161 startActivityForResult(intent, REQUEST_SUGGESTION);
1162 }
1163
1164 @Override
1165 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
1166 if (requestCode == REQUEST_SUGGESTION && mCurrentSuggestion != null
1167 && resultCode != RESULT_CANCELED) {
1168 getPackageManager().setComponentEnabledSetting(mCurrentSuggestion,
1169 PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
1170 }
1171 super.onActivityResult(requestCode, resultCode, data);
1172 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001173}