blob: 51613c730a0ec0b0825bdee6baeb40c5329b936f [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;
Anton Philippovadfec552017-01-25 20:37:36 +000057import com.android.settings.backup.BackupSettingsActivity;
Fan Zhanga3e8f5c2016-12-01 09:52:10 -080058import com.android.settings.core.gateway.SettingsGateway;
Fan Zhang5f79ae92016-08-18 16:04:19 -070059import com.android.settings.core.instrumentation.SharedPreferencesLogger;
Fan Zhang28691572016-03-23 15:31:08 -070060import com.android.settings.dashboard.DashboardContainerFragment;
Fan Zhanga96a2d82016-09-27 17:51:11 -070061import com.android.settings.dashboard.DashboardFeatureProvider;
62import com.android.settings.dashboard.DashboardSummary;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070063import com.android.settings.dashboard.SearchResultsSummary;
Fan Zhanga96a2d82016-09-27 17:51:11 -070064import com.android.settings.overlay.FeatureFactory;
Jason Monk2ebc8a02015-02-13 15:23:19 -050065import com.android.settings.search.DynamicIndexableContentMonitor;
Matthew Fritze0ed37c32016-10-24 10:12:49 -070066import com.android.settings.search2.SearchFeatureProvider;
Fabrice Di Meglio41937762014-05-13 19:51:59 -070067import com.android.settings.widget.SwitchBar;
Jason Monk4da79e02015-09-10 10:54:36 -040068import com.android.settingslib.drawer.DashboardCategory;
Jason Monk4da79e02015-09-10 10:54:36 -040069import com.android.settingslib.drawer.SettingsDrawerActivity;
Jason Monk7ea14c52016-01-22 14:28:02 -050070import com.android.settingslib.drawer.Tile;
Jason Monk2ebc8a02015-02-13 15:23:19 -050071
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080072import java.util.ArrayList;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080073import java.util.List;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -070074import java.util.Set;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080075
Jason Monk4da79e02015-09-10 10:54:36 -040076public class SettingsActivity extends SettingsDrawerActivity
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080077 implements PreferenceManager.OnPreferenceTreeClickListener,
78 PreferenceFragment.OnPreferenceStartFragmentCallback,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +010079 ButtonBarHandler, FragmentManager.OnBackStackChangedListener,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070080 SearchView.OnQueryTextListener, SearchView.OnCloseListener,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +010081 MenuItem.OnActionExpandListener {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080082
83 private static final String LOG_TAG = "Settings";
84
Philip P. Moltmannd9779db2016-02-24 12:11:05 -080085 private static final int LOADER_ID_INDEXABLE_CONTENT_MONITOR = 1;
86
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080087 // Constants for state save/restore
Fabrice Di Meglio769630c2014-04-24 14:48:48 -070088 private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070089 private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
90 private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
Fabrice Di Megliob731dd02014-04-03 18:40:38 -070091 private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -070092 private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080093
94 /**
95 * When starting this activity, the invoking Intent can contain this extra
96 * string to specify which fragment should be initially displayed.
97 * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
98 * will call isValidFragment() to confirm that the fragment class name is valid for this
99 * activity.
100 */
101 public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
102
103 /**
104 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
105 * this extra can also be specified to supply a Bundle of arguments to pass
106 * to that fragment when it is instantiated during the initial creation
107 * of the activity.
108 */
109 public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
110
111 /**
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700112 * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
113 */
114 public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
115
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800116 public static final String BACK_STACK_PREFS = ":settings:prefs";
117
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800118 // extras that allow any preference activity to be launched as part of a wizard
119
120 // show Back and Next buttons? takes boolean parameter
121 // Back will then return RESULT_CANCELED and Next RESULT_OK
122 protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
123
124 // add a Skip button?
125 private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
126
127 // specify custom text for the Back or Next buttons, or cause a button to not appear
128 // at all by setting it to null
129 protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
130 protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
131
132 /**
133 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700134 * 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 -0800135 * that fragment.
136 */
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700137 public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100138 /**
139 * The package name used to resolve the title resource id.
140 */
141 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
142 ":settings:show_fragment_title_res_package_name";
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700143 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
144 ":settings:show_fragment_title_resid";
145 public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
146 ":settings:show_fragment_as_shortcut";
147
148 public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
149 ":settings:show_fragment_as_subsetting";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800150
Udam Saini92779ce2016-03-28 14:29:48 -0700151 public static final String EXTRA_HIDE_DRAWER = ":settings:hide_drawer";
152
Jason Monk30695812015-11-17 09:01:08 -0500153 public static final String META_DATA_KEY_FRAGMENT_CLASS =
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800154 "com.android.settings.FRAGMENT_CLASS";
155
156 private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
157
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700158 private static final String EMPTY_QUERY = "";
159
Jason Monkd4f03ec2016-01-07 16:25:34 -0500160 private static final int REQUEST_SUGGESTION = 42;
161
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800162 private String mFragmentClass;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800163
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800164 private CharSequence mInitialTitle;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700165 private int mInitialTitleResId;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800166
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700167 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
168 "android.settings.APPLICATION_DETAILS_SETTINGS"
169 };
170
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800171 private SharedPreferences mDevelopmentPreferences;
172 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
173
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800174 private boolean mBatteryPresent = true;
175 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800176 @Override
177 public void onReceive(Context context, Intent intent) {
178 String action = intent.getAction();
179 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
180 boolean batteryPresent = Utils.isBatteryPresent(intent);
181
182 if (mBatteryPresent != batteryPresent) {
183 mBatteryPresent = batteryPresent;
Jason Monk4da79e02015-09-10 10:54:36 -0400184 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800185 }
186 }
187 }
188 };
189
Clara Bayarri6934a042015-10-14 11:07:35 +0100190 private final BroadcastReceiver mUserAddRemoveReceiver = new BroadcastReceiver() {
191 @Override
192 public void onReceive(Context context, Intent intent) {
Matthew Fritze34c27602017-01-18 18:24:56 -0800193 if (mSearchFeatureProvider != null && !mSearchFeatureProvider.isEnabled(context)) {
194 String action = intent.getAction();
195 if (action.equals(Intent.ACTION_USER_ADDED)
196 || action.equals(Intent.ACTION_USER_REMOVED)) {
197 mSearchFeatureProvider.updateIndex(getApplicationContext());
198 }
Clara Bayarri6934a042015-10-14 11:07:35 +0100199 }
200 }
201 };
202
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800203 private DynamicIndexableContentMonitor mDynamicIndexableContentMonitor;
Svetoslav853e4712014-04-14 10:10:25 -0700204
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700205 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700206 private SwitchBar mSwitchBar;
207
208 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700209
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700210 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700211 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700212
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700213 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700214 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700215
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700216 private ViewGroup mContent;
217
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700218 private SearchView mSearchView;
219 private MenuItem mSearchMenuItem;
220 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700221 private SearchResultsSummary mSearchResultsFragment;
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700222 private SearchFeatureProvider mSearchFeatureProvider;
223
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700224 // Categories
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800225 private ArrayList<DashboardCategory> mCategories = new ArrayList<>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800226
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700227 private boolean mNeedToRevertToInitialFragment = false;
228
Fan Zhanga96a2d82016-09-27 17:51:11 -0700229 private DashboardFeatureProvider mDashboardFeatureProvider;
Jim Miller0698a212014-10-16 19:49:07 -0700230 private Intent mResultIntentData;
Jason Monkd4f03ec2016-01-07 16:25:34 -0500231 private ComponentName mCurrentSuggestion;
Jim Miller0698a212014-10-16 19:49:07 -0700232
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800233 @VisibleForTesting
234 String mSearchQuery;
235
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700236 public SwitchBar getSwitchBar() {
237 return mSwitchBar;
238 }
239
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800240 @Override
241 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
Sunny Goyal21ef89f2016-05-25 12:41:16 -0700242 startPreferencePanel(pref.getFragment(), pref.getExtras(), -1, pref.getTitle(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800243 null, 0);
244 return true;
245 }
246
247 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400248 public boolean onPreferenceTreeClick(Preference preference) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800249 return false;
250 }
251
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800252 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800253 public void onConfigurationChanged(Configuration newConfig) {
254 super.onConfigurationChanged(newConfig);
Matthew Fritze34c27602017-01-18 18:24:56 -0800255 if (!mSearchFeatureProvider.isEnabled(this)) {
256 mSearchFeatureProvider.updateIndex(getApplicationContext());
257 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800258 }
259
260 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700261 protected void onStart() {
262 super.onStart();
263
264 if (mNeedToRevertToInitialFragment) {
265 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800266 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800267 }
268
269 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700270 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700271 if (!mDisplaySearch) {
272 return false;
273 }
274
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700275 MenuInflater inflater = getMenuInflater();
Matthew Fritze9955db62016-12-20 09:37:21 -0800276 if (mSearchFeatureProvider.isEnabled(this)) {
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700277 mSearchFeatureProvider.setUpSearchMenu(menu, this);
278 return true;
279 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700280 inflater.inflate(R.menu.options_menu, menu);
281
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700282
283 // Cache the search query (can be overridden by the OnQueryTextListener)
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700284 final String query = mSearchQuery;
285
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700286 mSearchMenuItem = menu.findItem(R.id.search);
287 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700288
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700289 if (mSearchMenuItem == null || mSearchView == null) {
290 return false;
291 }
292
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700293 if (mSearchResultsFragment != null) {
294 mSearchResultsFragment.setSearchView(mSearchView);
295 }
296
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700297 mSearchMenuItem.setOnActionExpandListener(this);
Fan Zhangb9239182016-08-22 13:59:59 -0700298 mSearchView.setMaxWidth(Integer.MAX_VALUE);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700299 mSearchView.setOnQueryTextListener(this);
300 mSearchView.setOnCloseListener(this);
301
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700302 if (mSearchMenuItemExpanded) {
303 mSearchMenuItem.expandActionView();
304 }
305 mSearchView.setQuery(query, true /* submit */);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700306 return true;
307 }
308
Jason Monk31c7c322016-01-20 14:41:52 -0500309 @Override
310 public SharedPreferences getSharedPreferences(String name, int mode) {
311 if (name.equals(getPackageName() + "_preferences")) {
Jason Monke4ebcd12016-02-21 09:37:41 -0500312 return new SharedPreferencesLogger(this, getMetricsTag());
Jason Monk31c7c322016-01-20 14:41:52 -0500313 }
314 return super.getSharedPreferences(name, mode);
315 }
316
Jason Monke4ebcd12016-02-21 09:37:41 -0500317 private String getMetricsTag() {
318 String tag = getClass().getName();
319 if (getIntent() != null && getIntent().hasExtra(EXTRA_SHOW_FRAGMENT)) {
320 tag = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
321 }
322 if (tag.startsWith("com.android.settings.")) {
323 tag = tag.replace("com.android.settings.", "");
324 }
325 return tag;
326 }
327
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700328 private static boolean isShortCutIntent(final Intent intent) {
329 Set<String> categories = intent.getCategories();
330 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
331 }
332
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700333 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700334 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700335 if (action == null) {
336 return false;
337 }
338 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
339 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
340 }
341 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700342 }
343
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700344 @Override
345 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700346 super.onCreate(savedState);
Jason Monkfd2c7222015-12-02 15:38:38 -0500347 long startTime = System.currentTimeMillis();
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700348
349 final FeatureFactory factory = FeatureFactory.getFactory(this);
350
351 mDashboardFeatureProvider = factory.getDashboardFeatureProvider(this);
Matthew Fritze9955db62016-12-20 09:37:21 -0800352 mSearchFeatureProvider = factory.getSearchFeatureProvider();
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700353
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700354 // Should happen before any call to getIntent()
355 getMetaData();
356
357 final Intent intent = getIntent();
358 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
359 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800360 }
Udam Saini92779ce2016-03-28 14:29:48 -0700361 if (intent.getBooleanExtra(EXTRA_HIDE_DRAWER, false)) {
362 setIsDrawerPresent(false);
363 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800364
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800365 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
366 Context.MODE_PRIVATE);
367
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700368 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700369 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700370
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700371 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700372 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
373
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700374 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700375 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700376
Jason Monk4da79e02015-09-10 10:54:36 -0400377 mIsShowingDashboard = className.equals(Settings.class.getName())
378 || className.equals(Settings.WirelessSettings.class.getName())
379 || className.equals(Settings.DeviceSettings.class.getName())
380 || className.equals(Settings.PersonalSettings.class.getName())
381 || className.equals(Settings.WirelessSettings.class.getName());
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700382
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700383 // This is a "Sub Settings" when:
384 // - this is a real SubSettings
385 // - or :settings:show_fragment_as_subsetting is passed to the Intent
Jorim Jaggi4dfcb822015-04-29 17:21:32 -0700386 final boolean isSubSettings = this instanceof SubSettings ||
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700387 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
388
Fan Zhang92f1e942017-01-21 10:07:26 -0800389 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content
390 // insets
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700391 if (isSubSettings) {
Fan Zhang92f1e942017-01-21 10:07:26 -0800392 setTheme(R.style.Theme_SubSettings);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700393 }
394
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700395 setContentView(mIsShowingDashboard ?
396 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800397
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700398 mContent = (ViewGroup) findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700399
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800400 getFragmentManager().addOnBackStackChangedListener(this);
401
Matthew Fritze34c27602017-01-18 18:24:56 -0800402 if (mIsShowingDashboard && !mSearchFeatureProvider.isEnabled(this)) {
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800403 // Run the Index update only if we have some space
404 if (!Utils.isLowStorage(this)) {
Fan Zhanga8759242017-01-06 09:18:59 -0800405 mSearchFeatureProvider.updateIndex(getApplicationContext());
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800406 } else {
407 Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
408 }
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700409 }
410
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700411 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700412 // We are restarting from a previous saved state; used that to initialize, instead
413 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700414 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
415 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700416 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800417
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700418 ArrayList<DashboardCategory> categories =
419 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
420 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700421 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700422 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700423 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800424 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700425
426 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700427 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Salvador Martinez2368e542016-07-25 18:16:47 -0700428
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800429 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700430 if (!mIsShowingDashboard) {
Jason Monkea8b1a72015-06-02 16:46:34 -0400431 mDisplaySearch = false;
432 // UP will be shown only if it is a sub settings
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700433 if (mIsShortcut) {
434 mDisplayHomeAsUpEnabled = isSubSettings;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700435 } else if (isSubSettings) {
436 mDisplayHomeAsUpEnabled = true;
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700437 } else {
438 mDisplayHomeAsUpEnabled = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700439 }
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700440 setTitleFromIntent(intent);
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700441
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700442 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700443 switchToFragment(initialFragmentName, initialArguments, true, false,
444 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000445 } else {
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700446 // No UP affordance if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700447 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700448 // Show Search affordance
449 mDisplaySearch = true;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700450 mInitialTitleResId = R.string.dashboard_title;
Salvador Martinez2368e542016-07-25 18:16:47 -0700451
452 // add argument to indicate which settings tab should be initially selected
453 final Bundle args = new Bundle();
454 final String extraName = DashboardContainerFragment.EXTRA_SELECT_SETTINGS_TAB;
455 args.putString(extraName, intent.getStringExtra(extraName));
Fan Zhanga96a2d82016-09-27 17:51:11 -0700456 if (isDashboardFeatureEnabled()) {
457 switchToFragment(DashboardSummary.class.getName(), args, false, false,
458 mInitialTitleResId, mInitialTitle, false);
459 } else {
460 switchToFragment(DashboardContainerFragment.class.getName(), args, false, false,
461 mInitialTitleResId, mInitialTitle, false);
462 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800463 }
464 }
465
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700466 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700467 if (mActionBar != null) {
468 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
469 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
470 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700471 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
Jason Monke4ebcd12016-02-21 09:37:41 -0500472 if (mSwitchBar != null) {
473 mSwitchBar.setMetricsTag(getMetricsTag());
474 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700475
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800476 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800477 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
478
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700479 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800480 if (buttonBar != null) {
481 buttonBar.setVisibility(View.VISIBLE);
482
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700483 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800484 backButton.setOnClickListener(new OnClickListener() {
485 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700486 setResult(RESULT_CANCELED, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800487 finish();
488 }
489 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700490 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800491 skipButton.setOnClickListener(new OnClickListener() {
492 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700493 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800494 finish();
495 }
496 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700497 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800498 mNextButton.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 });
504
505 // set our various button parameters
506 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
507 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
508 if (TextUtils.isEmpty(buttonText)) {
509 mNextButton.setVisibility(View.GONE);
510 }
511 else {
512 mNextButton.setText(buttonText);
513 }
514 }
515 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
516 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
517 if (TextUtils.isEmpty(buttonText)) {
518 backButton.setVisibility(View.GONE);
519 }
520 else {
521 backButton.setText(buttonText);
522 }
523 }
524 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
525 skipButton.setVisibility(View.VISIBLE);
526 }
527 }
528 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700529
Jason Monkfd2c7222015-12-02 15:38:38 -0500530 if (DEBUG_TIMING) Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
531 + " ms");
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700532 }
533
Fan Zhangece8ff62016-06-30 13:20:12 -0700534 public void setDisplaySearchMenu(boolean displaySearch) {
535 if (displaySearch != mDisplaySearch) {
536 mDisplaySearch = displaySearch;
537 invalidateOptionsMenu();
538 }
539 }
540
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700541 private void setTitleFromIntent(Intent intent) {
542 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
543 if (initialTitleResId > 0) {
544 mInitialTitle = null;
545 mInitialTitleResId = initialTitleResId;
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100546
547 final String initialTitleResPackageName = intent.getStringExtra(
548 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
549 if (initialTitleResPackageName != null) {
550 try {
551 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
552 0 /* flags */, new UserHandle(UserHandle.myUserId()));
553 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
554 setTitle(mInitialTitle);
555 mInitialTitleResId = -1;
556 return;
557 } catch (NameNotFoundException e) {
558 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
559 }
560 } else {
561 setTitle(mInitialTitleResId);
562 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700563 } else {
564 mInitialTitleResId = -1;
565 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
566 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
567 setTitle(mInitialTitle);
568 }
569 }
570
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800571 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800572 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700573 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800574 }
575
Fan Zhang28691572016-03-23 15:31:08 -0700576 private void setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800577 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700578
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800579 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700580 if (mInitialTitleResId > 0) {
581 setTitle(mInitialTitleResId);
582 } else {
583 setTitle(mInitialTitle);
584 }
Fan Zhang28691572016-03-23 15:31:08 -0700585 return;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800586 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700587
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800588 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
589 setTitleFromBackStackEntry(bse);
590 }
591
592 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
593 final CharSequence title;
594 final int titleRes = bse.getBreadCrumbTitleRes();
595 if (titleRes > 0) {
596 title = getText(titleRes);
597 } else {
598 title = bse.getBreadCrumbTitle();
599 }
600 if (title != null) {
601 setTitle(title);
602 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800603 }
604
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800605 @Override
606 protected void onSaveInstanceState(Bundle outState) {
607 super.onSaveInstanceState(outState);
608
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700609 if (mCategories.size() > 0) {
610 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800611 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700612
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700613 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700614 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700615
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700616 if (mDisplaySearch) {
617 // The option menus are created if the ActionBar is visible and they are also created
618 // asynchronously. If you launch Settings with an Intent action like
619 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
620 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
621 // menu item and search view are null.
622 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
623 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700624
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700625 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
626 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
627 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800628 }
629
630 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400631 protected void onResume() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800632 super.onResume();
633
634 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
635 @Override
636 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Jason Monk4da79e02015-09-10 10:54:36 -0400637 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800638 }
639 };
640 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
641 mDevelopmentPreferencesListener);
642
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800643 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Matthew Fritze34c27602017-01-18 18:24:56 -0800644 if (!mSearchFeatureProvider.isEnabled(this)) {
645 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_ADDED));
646 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_REMOVED));
647 }
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800648 if (mDynamicIndexableContentMonitor == null) {
649 mDynamicIndexableContentMonitor = new DynamicIndexableContentMonitor();
650 }
Philip P. Moltmannd9779db2016-02-24 12:11:05 -0800651 mDynamicIndexableContentMonitor.register(this, LOADER_ID_INDEXABLE_CONTENT_MONITOR);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700652
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700653 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700654 onQueryTextSubmit(mSearchQuery);
655 }
Jason Monk4da79e02015-09-10 10:54:36 -0400656 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800657 }
658
659 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400660 protected void onPause() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800661 super.onPause();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800662 unregisterReceiver(mBatteryInfoReceiver);
Matthew Fritze34c27602017-01-18 18:24:56 -0800663 if (!mSearchFeatureProvider.isEnabled(this)) {
664 unregisterReceiver(mUserAddRemoveReceiver);
665 }
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800666 if (mDynamicIndexableContentMonitor != null) {
Tadashi G. Takaokaa034fa52016-11-21 14:20:19 +0900667 mDynamicIndexableContentMonitor.unregister(this, LOADER_ID_INDEXABLE_CONTENT_MONITOR);
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800668 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800669 }
670
671 @Override
672 public void onDestroy() {
673 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700674
675 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
676 mDevelopmentPreferencesListener);
677 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800678 }
679
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800680 protected boolean isValidFragment(String fragmentName) {
681 // Almost all fragments are wrapped in this,
682 // except for a few that have their own activities.
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800683 for (int i = 0; i < SettingsGateway.ENTRY_FRAGMENTS.length; i++) {
684 if (SettingsGateway.ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800685 }
686 return false;
687 }
688
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800689 @Override
690 public Intent getIntent() {
691 Intent superIntent = super.getIntent();
692 String startingFragment = getStartingFragmentClass(superIntent);
693 // This is called from super.onCreate, isMultiPane() is not yet reliable
694 // Do not use onIsHidingHeaders either, which relies itself on this method
695 if (startingFragment != null) {
696 Intent modIntent = new Intent(superIntent);
697 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
698 Bundle args = superIntent.getExtras();
699 if (args != null) {
700 args = new Bundle(args);
701 } else {
702 args = new Bundle();
703 }
704 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100705 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800706 return modIntent;
707 }
708 return superIntent;
709 }
710
711 /**
712 * Checks if the component name in the intent is different from the Settings class and
713 * returns the class name to load as a fragment.
714 */
715 private String getStartingFragmentClass(Intent intent) {
716 if (mFragmentClass != null) return mFragmentClass;
717
718 String intentClass = intent.getComponent().getClassName();
719 if (intentClass.equals(getClass().getName())) return null;
720
721 if ("com.android.settings.ManageApplications".equals(intentClass)
722 || "com.android.settings.RunningServices".equals(intentClass)
723 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
724 // Old names of manage apps.
725 intentClass = com.android.settings.applications.ManageApplications.class.getName();
726 }
727
728 return intentClass;
729 }
730
731 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000732 * Start a new fragment containing a preference panel. If the preferences
733 * are being displayed in multi-pane mode, the given fragment class will
734 * be instantiated and placed in the appropriate pane. If running in
735 * single-pane mode, a new activity will be launched in which to show the
736 * fragment.
737 *
738 * @param fragmentClass Full name of the class implementing the fragment.
739 * @param args Any desired arguments to supply to the fragment.
740 * @param titleRes Optional resource identifier of the title of this
741 * fragment.
742 * @param titleText Optional text of the title of this fragment.
743 * @param resultTo Optional fragment that result data should be sent to.
744 * If non-null, resultTo.onActivityResult() will be called when this
745 * preference panel is done. The launched panel must use
746 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
747 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700748 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000749 */
750 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700751 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700752 String title = null;
753 if (titleRes < 0) {
754 if (titleText != null) {
755 title = titleText.toString();
756 } else {
757 // There not much we can do in that case
758 title = "";
759 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700760 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700761 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700762 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000763 }
764
765 /**
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100766 * Start a new fragment in a new activity containing a preference panel for a given user. If the
767 * preferences are being displayed in multi-pane mode, the given fragment class will be
768 * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
769 * activity will be launched in which to show the fragment.
770 *
771 * @param fragmentClass Full name of the class implementing the fragment.
772 * @param args Any desired arguments to supply to the fragment.
773 * @param titleRes Optional resource identifier of the title of this fragment.
774 * @param titleText Optional text of the title of this fragment.
775 * @param userHandle The user for which the panel has to be started.
776 */
777 public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
778 CharSequence titleText, UserHandle userHandle) {
Lifu Tangd0332852015-04-02 12:05:46 -0700779 // This is a workaround.
780 //
781 // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
782 // starting the fragment could cause a native stack corruption. See b/17523189. However,
783 // adding that flag and start the preference panel with the same UserHandler will make it
784 // impossible to use back button to return to the previous screen. See b/20042570.
785 //
786 // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
787 // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
788 // when we're calling it as the same user.
789 if (userHandle.getIdentifier() == UserHandle.myUserId()) {
790 startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0);
791 } else {
792 String title = null;
793 if (titleRes < 0) {
794 if (titleText != null) {
795 title = titleText.toString();
796 } else {
797 // There not much we can do in that case
798 title = "";
799 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100800 }
Lifu Tangd0332852015-04-02 12:05:46 -0700801 Utils.startWithFragmentAsUser(this, fragmentClass, args,
802 titleRes, title, mIsShortcut, userHandle);
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100803 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100804 }
805
806 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800807 * Called by a preference panel fragment to finish itself.
808 *
809 * @param caller The fragment that is asking to be finished.
810 * @param resultCode Optional result code to send back to the original
811 * launching fragment.
812 * @param resultData Optional result data to send back to the original
813 * launching fragment.
814 */
815 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
816 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700817 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800818 }
819
820 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000821 * Start a new fragment.
822 *
823 * @param fragment The fragment to start
824 * @param push If true, the current fragment will be pushed onto the back stack. If false,
825 * the current fragment will be replaced.
826 */
827 public void startPreferenceFragment(Fragment fragment, boolean push) {
828 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700829 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000830 if (push) {
831 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
832 transaction.addToBackStack(BACK_STACK_PREFS);
833 } else {
834 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
835 }
836 transaction.commitAllowingStateLoss();
837 }
838
839 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700840 * Switch to a specific Fragment with taking care of validation, Title and BackStack
841 */
842 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700843 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700844 if (validate && !isValidFragment(fragmentName)) {
845 throw new IllegalArgumentException("Invalid fragment for this activity: "
846 + fragmentName);
847 }
848 Fragment f = Fragment.instantiate(this, fragmentName, args);
849 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700850 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700851 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700852 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700853 }
854 if (addToBackStack) {
855 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
856 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700857 if (titleResId > 0) {
858 transaction.setBreadCrumbTitle(titleResId);
859 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700860 transaction.setBreadCrumbTitle(title);
861 }
862 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700863 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700864 return f;
865 }
866
Jason Monk4da79e02015-09-10 10:54:36 -0400867 private void updateTilesList() {
Jason Monkfd2c7222015-12-02 15:38:38 -0500868 // Generally the items that are will be changing from these updates will
869 // not be in the top list of tiles, so run it in the background and the
870 // SettingsDrawerActivity will pick up on the updates automatically.
871 AsyncTask.execute(new Runnable() {
872 @Override
873 public void run() {
874 doUpdateTilesList();
875 }
876 });
877 }
878
879 private void doUpdateTilesList() {
Jason Monk4da79e02015-09-10 10:54:36 -0400880 PackageManager pm = getPackageManager();
Xiaohui Chen44879a32015-07-22 13:53:22 -0700881 final UserManager um = UserManager.get(this);
882 final boolean isAdmin = um.isAdminUser();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700883
Jason Monk4da79e02015-09-10 10:54:36 -0400884 String packageName = getPackageName();
885 setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800886 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700887
Jason Monk4da79e02015-09-10 10:54:36 -0400888 setTileEnabled(new ComponentName(packageName,
889 Settings.BluetoothSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800890 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700891
Jason Monk4da79e02015-09-10 10:54:36 -0400892 setTileEnabled(new ComponentName(packageName,
893 Settings.DataUsageSummaryActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800894 Utils.isBandwidthControlEnabled(), isAdmin);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700895
Jason Monk4da79e02015-09-10 10:54:36 -0400896 setTileEnabled(new ComponentName(packageName,
897 Settings.SimSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800898 Utils.showSimCardTile(this), isAdmin);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700899
Jason Monk4da79e02015-09-10 10:54:36 -0400900 setTileEnabled(new ComponentName(packageName,
901 Settings.PowerUsageSummaryActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800902 mBatteryPresent, isAdmin);
Jason Monk4da79e02015-09-10 10:54:36 -0400903
904 setTileEnabled(new ComponentName(packageName,
Jason Monk4da79e02015-09-10 10:54:36 -0400905 Settings.UserSettingsActivity.class.getName()),
906 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
Fan Zhang224caad2017-01-06 11:42:48 -0800907 && !Utils.isMonkeyRunning(), isAdmin);
Jason Monk4da79e02015-09-10 10:54:36 -0400908
Fyodor Kupolovca060e32016-06-24 13:01:11 -0700909 setTileEnabled(new ComponentName(packageName,
910 Settings.WirelessSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800911 !UserManager.isDeviceInDemoMode(this), isAdmin);
Fyodor Kupolovca060e32016-06-24 13:01:11 -0700912
913 setTileEnabled(new ComponentName(packageName,
914 Settings.DateTimeSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800915 !UserManager.isDeviceInDemoMode(this), isAdmin);
Jason Monk4da79e02015-09-10 10:54:36 -0400916 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
917 setTileEnabled(new ComponentName(packageName,
918 Settings.PaymentSettingsActivity.class.getName()),
919 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
920 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
Fan Zhang224caad2017-01-06 11:42:48 -0800921 && adapter != null && adapter.isEnabled(), isAdmin);
Fan Zhangffd328b2017-01-09 10:16:49 -0800922 setTileEnabled(new ComponentName(packageName,
923 "com.android.settings.PaymentSettingsDashboardAlias"),
924 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
925 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
926 && adapter != null && adapter.isEnabled(), isAdmin);
Jason Monk4da79e02015-09-10 10:54:36 -0400927
928 setTileEnabled(new ComponentName(packageName,
929 Settings.PrintSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800930 pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin);
Jason Monk4da79e02015-09-10 10:54:36 -0400931
932 final boolean showDev = mDevelopmentPreferences.getBoolean(
Dan Sandler12c4ba42016-03-28 11:13:40 -0400933 DevelopmentSettings.PREF_SHOW, android.os.Build.TYPE.equals("eng"))
934 && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES);
Jason Monk4da79e02015-09-10 10:54:36 -0400935 setTileEnabled(new ComponentName(packageName,
936 Settings.DevelopmentSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800937 showDev, isAdmin);
Fan Zhangcc335d92016-09-29 14:37:14 -0700938 setTileEnabled(new ComponentName(packageName,
939 Settings.DevelopmentSettingsActivity.DASHBOARD_ALIAS),
Fan Zhang224caad2017-01-06 11:42:48 -0800940 showDev, isAdmin);
Dan Sandler12c4ba42016-03-28 11:13:40 -0400941
Jason Monk4da79e02015-09-10 10:54:36 -0400942 if (UserHandle.MU_ENABLED && !isAdmin) {
943 // When on restricted users, disable all extra categories (but only the settings ones).
Fan Zhanga96a2d82016-09-27 17:51:11 -0700944 List<DashboardCategory> categories;
945 if (isDashboardFeatureEnabled()) {
946 categories = mDashboardFeatureProvider.getAllCategories();
947 } else {
948 categories = getDashboardCategories();
949 }
950
Jason Monk4da79e02015-09-10 10:54:36 -0400951 for (DashboardCategory category : categories) {
Jason Monkd4f03ec2016-01-07 16:25:34 -0500952 for (Tile tile : category.tiles) {
Jason Monk4da79e02015-09-10 10:54:36 -0400953 ComponentName component = tile.intent.getComponent();
Fan Zhang9ec45362017-01-10 11:55:45 -0800954 final String name = component.getClassName();
955 final boolean isEnabledForRestricted = ArrayUtils.contains(
956 SettingsGateway.SETTINGS_FOR_RESTRICTED, name);
957 if (packageName.equals(component.getPackageName()) && !isEnabledForRestricted) {
Fan Zhang224caad2017-01-06 11:42:48 -0800958 setTileEnabled(component, false, isAdmin);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700959 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700960 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700961 }
962 }
Doris Ling26bf0032016-06-15 18:16:09 -0700963
Anton Philippovadfec552017-01-25 20:37:36 +0000964 // Enable/disable backup settings depending on whether the user is admin.
Doris Ling26bf0032016-06-15 18:16:09 -0700965 setTileEnabled(new ComponentName(packageName,
Christine Franks14782222017-01-23 16:44:02 -0800966 BackupSettingsActivity.class.getName()), true,
967 isAdmin || Utils.isCarrierDemoUser(this));
Fan Zhang0e8d0d12016-11-02 09:15:33 -0700968 setTileEnabled(new ComponentName(packageName,
Anton Philippovadfec552017-01-25 20:37:36 +0000969 "com.android.settings.BackupResetDashboardAlias"), true, isAdmin);
Doris Ling26bf0032016-06-15 18:16:09 -0700970
Bartosz Fabianowski05061fc2016-11-14 12:04:49 +0100971 setTileEnabled(new ComponentName(packageName,
972 Settings.EnterprisePrivacySettingsActivity.class.getName()),
973 FeatureFactory.getFactory(this).getEnterprisePrivacyFeatureProvider(this)
Fan Zhang224caad2017-01-06 11:42:48 -0800974 .hasDeviceOwner(), isAdmin);
Fan Zhang10dd4652016-11-16 10:24:26 -0800975 setTileEnabled(new ComponentName(packageName,
976 "com.android.settings.EnterprisePrivacyDashboardAlias"),
977 FeatureFactory.getFactory(this).getEnterprisePrivacyFeatureProvider(this)
Fan Zhang224caad2017-01-06 11:42:48 -0800978 .hasDeviceOwner(), isAdmin);
979 // Final step, refresh categories.
980 updateCategories();
Jason Monk2ebc8a02015-02-13 15:23:19 -0500981 }
982
Fan Zhang224caad2017-01-06 11:42:48 -0800983 private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin) {
Jason Monk5862c1e2016-06-07 14:02:33 -0400984 if (UserHandle.MU_ENABLED && !isAdmin && getPackageName().equals(component.getPackageName())
Fan Zhang9ec45362017-01-10 11:55:45 -0800985 && !ArrayUtils.contains(SettingsGateway.SETTINGS_FOR_RESTRICTED,
986 component.getClassName())) {
Jason Monk4da79e02015-09-10 10:54:36 -0400987 enabled = false;
988 }
Jason Monk5862c1e2016-06-07 14:02:33 -0400989 setTileEnabled(component, enabled);
Jason Monk2ebc8a02015-02-13 15:23:19 -0500990 }
991
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800992 private void getMetaData() {
993 try {
994 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
995 PackageManager.GET_META_DATA);
996 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800997 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
998 } catch (NameNotFoundException nnfe) {
999 // No recovery
1000 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1001 }
1002 }
1003
Fan Zhanga96a2d82016-09-27 17:51:11 -07001004 @Override
1005 protected boolean isDashboardFeatureEnabled() {
1006 if (mDashboardFeatureProvider == null) {
1007 mDashboardFeatureProvider =
1008 FeatureFactory.getFactory(this).getDashboardFeatureProvider(this);
1009 }
1010 return mDashboardFeatureProvider.isEnabled();
1011 }
1012
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001013 // give subclasses access to the Next button
1014 public boolean hasNextButton() {
1015 return mNextButton != null;
1016 }
1017
1018 public Button getNextButton() {
1019 return mNextButton;
1020 }
1021
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001022 @Override
1023 public boolean shouldUpRecreateTask(Intent targetIntent) {
1024 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1025 }
1026
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001027 @Deprecated
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001028 @Override
1029 public boolean onQueryTextSubmit(String query) {
Matthew Fritze9955db62016-12-20 09:37:21 -08001030 if (mSearchFeatureProvider.isEnabled(this)) {
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001031 return false;
1032 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001033 mSearchQuery = query;
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001034 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001035 return mSearchResultsFragment.onQueryTextSubmit(query);
1036 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001037
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001038 @Deprecated
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001039 @Override
1040 public boolean onQueryTextChange(String newText) {
Fan Zhanga3e8f5c2016-12-01 09:52:10 -08001041 mSearchQuery = newText;
Matthew Fritze9955db62016-12-20 09:37:21 -08001042 if (mSearchFeatureProvider.isEnabled(this) || mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001043 return false;
1044 }
1045 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001046 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001047
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001048 @Override
1049 public boolean onClose() {
1050 return false;
1051 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001052
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001053 @Override
1054 public boolean onMenuItemActionExpand(MenuItem item) {
1055 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001056 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001057 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001058 return true;
1059 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001060
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001061 @Override
1062 public boolean onMenuItemActionCollapse(MenuItem item) {
1063 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001064 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001065 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001066 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001067 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001068 return true;
1069 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001070
Jason Monk4da79e02015-09-10 10:54:36 -04001071 @Override
Jason Monkd4f03ec2016-01-07 16:25:34 -05001072 protected void onTileClicked(Tile tile) {
Jason Monk4da79e02015-09-10 10:54:36 -04001073 if (mIsShowingDashboard) {
1074 // If on dashboard, don't finish so the back comes back to here.
1075 openTile(tile);
1076 } else {
1077 super.onTileClicked(tile);
1078 }
1079 }
1080
Jason Monkaf001092015-11-04 13:16:18 -05001081 @Override
1082 public void onProfileTileOpen() {
1083 if (!mIsShowingDashboard) {
1084 finish();
1085 }
1086 }
1087
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001088 @Deprecated
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001089 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001090 if (mSearchResultsFragment != null) {
1091 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001092 }
Anna Galusza6b1e9db2016-03-30 17:25:36 -07001093 Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001094 if (current != null && current instanceof SearchResultsSummary) {
1095 mSearchResultsFragment = (SearchResultsSummary) current;
1096 } else {
Fan Zhang28691572016-03-23 15:31:08 -07001097 setContentHeaderView(null);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001098 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001099 SearchResultsSummary.class.getName(), null, false, true,
1100 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001101 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001102 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001103 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001104 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001105
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001106 @Deprecated
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001107 public void needToRevertToInitialFragment() {
1108 mNeedToRevertToInitialFragment = true;
1109 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001110
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001111 @Deprecated
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001112 private void revertToInitialFragment() {
1113 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001114 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001115 mSearchMenuItemExpanded = false;
1116 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1117 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001118 if (mSearchMenuItem != null) {
1119 mSearchMenuItem.collapseActionView();
1120 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001121 }
Jim Miller0698a212014-10-16 19:49:07 -07001122
1123 public Intent getResultIntentData() {
1124 return mResultIntentData;
1125 }
1126
1127 public void setResultIntentData(Intent resultIntentData) {
1128 mResultIntentData = resultIntentData;
1129 }
Jason Monkd4f03ec2016-01-07 16:25:34 -05001130
1131 public void startSuggestion(Intent intent) {
Matthew Fritze7ac78f22016-10-03 13:26:07 -07001132 if (intent == null || ActivityManager.isUserAMonkey()) {
Matthew Fritze703dc602016-09-30 12:36:27 -07001133 return;
1134 }
Matthew Fritzef265dbc2016-10-04 13:39:27 -07001135 mCurrentSuggestion = intent.getComponent();
Jason Monkd4f03ec2016-01-07 16:25:34 -05001136 startActivityForResult(intent, REQUEST_SUGGESTION);
1137 }
1138
1139 @Override
1140 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
1141 if (requestCode == REQUEST_SUGGESTION && mCurrentSuggestion != null
1142 && resultCode != RESULT_CANCELED) {
1143 getPackageManager().setComponentEnabledSetting(mCurrentSuggestion,
1144 PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
1145 }
1146 super.onActivityResult(requestCode, resultCode, data);
1147 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001148}