blob: 13bc0488d3b82f520f64008fe5570be732c9ef29 [file] [log] [blame]
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.settings;
18
Fan Zhang60f01072016-10-13 16:53:41 -070019import android.app.ActionBar;
Matthew Fritze7ac78f22016-10-03 13:26:07 -070020import android.app.ActivityManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080021import android.app.Fragment;
22import android.app.FragmentManager;
23import android.app.FragmentTransaction;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080024import android.content.BroadcastReceiver;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070025import android.content.ComponentName;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080026import android.content.Context;
27import android.content.Intent;
28import android.content.IntentFilter;
29import android.content.SharedPreferences;
30import android.content.pm.ActivityInfo;
31import android.content.pm.PackageManager;
32import android.content.pm.PackageManager.NameNotFoundException;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080033import android.content.res.Configuration;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080034import android.nfc.NfcAdapter;
Jason Monkfd2c7222015-12-02 15:38:38 -050035import android.os.AsyncTask;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080036import android.os.Bundle;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080037import android.os.UserHandle;
38import android.os.UserManager;
Fan Zhanga3e8f5c2016-12-01 09:52:10 -080039import android.support.annotation.VisibleForTesting;
Jason Monk39b46742015-09-10 15:52:51 -040040import android.support.v14.preference.PreferenceFragment;
41import android.support.v7.preference.Preference;
42import android.support.v7.preference.PreferenceManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080043import android.text.TextUtils;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070044import android.transition.TransitionManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080045import android.util.Log;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070046import android.view.Menu;
47import android.view.MenuInflater;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080048import android.view.MenuItem;
49import android.view.View;
50import android.view.View.OnClickListener;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070051import android.view.ViewGroup;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080052import android.widget.Button;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070053import android.widget.SearchView;
Fan Zhang28691572016-03-23 15:31:08 -070054
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080055import com.android.internal.util.ArrayUtils;
Jason Monk4da79e02015-09-10 10:54:36 -040056import com.android.settings.Settings.WifiSettingsActivity;
Fan Zhanga3e8f5c2016-12-01 09:52:10 -080057import com.android.settings.core.gateway.SettingsGateway;
Fan Zhang5f79ae92016-08-18 16:04:19 -070058import com.android.settings.core.instrumentation.SharedPreferencesLogger;
Fan Zhang28691572016-03-23 15:31:08 -070059import com.android.settings.dashboard.DashboardContainerFragment;
Fan Zhanga96a2d82016-09-27 17:51:11 -070060import com.android.settings.dashboard.DashboardFeatureProvider;
61import com.android.settings.dashboard.DashboardSummary;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070062import com.android.settings.dashboard.SearchResultsSummary;
Fan Zhanga96a2d82016-09-27 17:51:11 -070063import com.android.settings.overlay.FeatureFactory;
Sunny Goyalbf9f2d22016-11-02 11:20:17 -070064import com.android.settings.qstile.DevelopmentModeTile;
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
Doris Ling26bf0032016-06-15 18:16:09 -070072import java.net.URISyntaxException;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080073import java.util.ArrayList;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080074import java.util.List;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -070075import java.util.Set;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080076
Jason Monk4da79e02015-09-10 10:54:36 -040077public class SettingsActivity extends SettingsDrawerActivity
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080078 implements PreferenceManager.OnPreferenceTreeClickListener,
79 PreferenceFragment.OnPreferenceStartFragmentCallback,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +010080 ButtonBarHandler, FragmentManager.OnBackStackChangedListener,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070081 SearchView.OnQueryTextListener, SearchView.OnCloseListener,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +010082 MenuItem.OnActionExpandListener {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080083
84 private static final String LOG_TAG = "Settings";
85
Philip P. Moltmannd9779db2016-02-24 12:11:05 -080086 private static final int LOADER_ID_INDEXABLE_CONTENT_MONITOR = 1;
87
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080088 // Constants for state save/restore
Fabrice Di Meglio769630c2014-04-24 14:48:48 -070089 private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070090 private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
91 private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
Fabrice Di Megliob731dd02014-04-03 18:40:38 -070092 private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -070093 private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080094
95 /**
96 * When starting this activity, the invoking Intent can contain this extra
97 * string to specify which fragment should be initially displayed.
98 * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
99 * will call isValidFragment() to confirm that the fragment class name is valid for this
100 * activity.
101 */
102 public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
103
104 /**
105 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
106 * this extra can also be specified to supply a Bundle of arguments to pass
107 * to that fragment when it is instantiated during the initial creation
108 * of the activity.
109 */
110 public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
111
112 /**
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700113 * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
114 */
115 public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
116
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800117 public static final String BACK_STACK_PREFS = ":settings:prefs";
118
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800119 // extras that allow any preference activity to be launched as part of a wizard
120
121 // show Back and Next buttons? takes boolean parameter
122 // Back will then return RESULT_CANCELED and Next RESULT_OK
123 protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
124
125 // add a Skip button?
126 private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
127
128 // specify custom text for the Back or Next buttons, or cause a button to not appear
129 // at all by setting it to null
130 protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
131 protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
132
133 /**
134 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700135 * 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 -0800136 * that fragment.
137 */
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700138 public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100139 /**
140 * The package name used to resolve the title resource id.
141 */
142 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
143 ":settings:show_fragment_title_res_package_name";
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700144 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
145 ":settings:show_fragment_title_resid";
146 public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
147 ":settings:show_fragment_as_shortcut";
148
149 public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
150 ":settings:show_fragment_as_subsetting";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800151
Udam Saini92779ce2016-03-28 14:29:48 -0700152 public static final String EXTRA_HIDE_DRAWER = ":settings:hide_drawer";
153
Jason Monk30695812015-11-17 09:01:08 -0500154 public static final String META_DATA_KEY_FRAGMENT_CLASS =
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800155 "com.android.settings.FRAGMENT_CLASS";
156
157 private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
158
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700159 private static final String EMPTY_QUERY = "";
160
Jason Monkd4f03ec2016-01-07 16:25:34 -0500161 private static final int REQUEST_SUGGESTION = 42;
162
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800163 private String mFragmentClass;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800164
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800165 private CharSequence mInitialTitle;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700166 private int mInitialTitleResId;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800167
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700168 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
169 "android.settings.APPLICATION_DETAILS_SETTINGS"
170 };
171
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800172 private SharedPreferences mDevelopmentPreferences;
173 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
174
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800175 private boolean mBatteryPresent = true;
176 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800177 @Override
178 public void onReceive(Context context, Intent intent) {
179 String action = intent.getAction();
180 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
181 boolean batteryPresent = Utils.isBatteryPresent(intent);
182
183 if (mBatteryPresent != batteryPresent) {
184 mBatteryPresent = batteryPresent;
Jason Monk4da79e02015-09-10 10:54:36 -0400185 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800186 }
187 }
188 }
189 };
190
Clara Bayarri6934a042015-10-14 11:07:35 +0100191 private final BroadcastReceiver mUserAddRemoveReceiver = new BroadcastReceiver() {
192 @Override
193 public void onReceive(Context context, Intent intent) {
Matthew Fritze34c27602017-01-18 18:24:56 -0800194 if (mSearchFeatureProvider != null && !mSearchFeatureProvider.isEnabled(context)) {
195 String action = intent.getAction();
196 if (action.equals(Intent.ACTION_USER_ADDED)
197 || action.equals(Intent.ACTION_USER_REMOVED)) {
198 mSearchFeatureProvider.updateIndex(getApplicationContext());
199 }
Clara Bayarri6934a042015-10-14 11:07:35 +0100200 }
201 }
202 };
203
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800204 private DynamicIndexableContentMonitor mDynamicIndexableContentMonitor;
Svetoslav853e4712014-04-14 10:10:25 -0700205
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700206 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700207 private SwitchBar mSwitchBar;
208
209 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700210
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700211 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700212 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700213
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700214 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700215 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700216
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700217 private ViewGroup mContent;
218
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700219 private SearchView mSearchView;
220 private MenuItem mSearchMenuItem;
221 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700222 private SearchResultsSummary mSearchResultsFragment;
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700223 private SearchFeatureProvider mSearchFeatureProvider;
224
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700225 // Categories
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800226 private ArrayList<DashboardCategory> mCategories = new ArrayList<>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800227
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700228 private boolean mNeedToRevertToInitialFragment = false;
229
Fan Zhanga96a2d82016-09-27 17:51:11 -0700230 private DashboardFeatureProvider mDashboardFeatureProvider;
Jim Miller0698a212014-10-16 19:49:07 -0700231 private Intent mResultIntentData;
Jason Monkd4f03ec2016-01-07 16:25:34 -0500232 private ComponentName mCurrentSuggestion;
Jim Miller0698a212014-10-16 19:49:07 -0700233
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800234 @VisibleForTesting
235 String mSearchQuery;
236
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700237 public SwitchBar getSwitchBar() {
238 return mSwitchBar;
239 }
240
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800241 @Override
242 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
Sunny Goyal21ef89f2016-05-25 12:41:16 -0700243 startPreferencePanel(pref.getFragment(), pref.getExtras(), -1, pref.getTitle(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800244 null, 0);
245 return true;
246 }
247
248 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400249 public boolean onPreferenceTreeClick(Preference preference) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800250 return false;
251 }
252
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800253 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800254 public void onConfigurationChanged(Configuration newConfig) {
255 super.onConfigurationChanged(newConfig);
Matthew Fritze34c27602017-01-18 18:24:56 -0800256 if (!mSearchFeatureProvider.isEnabled(this)) {
257 mSearchFeatureProvider.updateIndex(getApplicationContext());
258 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800259 }
260
261 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700262 protected void onStart() {
263 super.onStart();
264
265 if (mNeedToRevertToInitialFragment) {
266 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800267 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800268 }
269
270 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700271 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700272 if (!mDisplaySearch) {
273 return false;
274 }
275
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700276 MenuInflater inflater = getMenuInflater();
Matthew Fritze9955db62016-12-20 09:37:21 -0800277 if (mSearchFeatureProvider.isEnabled(this)) {
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700278 mSearchFeatureProvider.setUpSearchMenu(menu, this);
279 return true;
280 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700281 inflater.inflate(R.menu.options_menu, menu);
282
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700283
284 // Cache the search query (can be overridden by the OnQueryTextListener)
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700285 final String query = mSearchQuery;
286
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700287 mSearchMenuItem = menu.findItem(R.id.search);
288 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700289
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700290 if (mSearchMenuItem == null || mSearchView == null) {
291 return false;
292 }
293
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700294 if (mSearchResultsFragment != null) {
295 mSearchResultsFragment.setSearchView(mSearchView);
296 }
297
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700298 mSearchMenuItem.setOnActionExpandListener(this);
Fan Zhangb9239182016-08-22 13:59:59 -0700299 mSearchView.setMaxWidth(Integer.MAX_VALUE);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700300 mSearchView.setOnQueryTextListener(this);
301 mSearchView.setOnCloseListener(this);
302
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700303 if (mSearchMenuItemExpanded) {
304 mSearchMenuItem.expandActionView();
305 }
306 mSearchView.setQuery(query, true /* submit */);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700307 return true;
308 }
309
Jason Monk31c7c322016-01-20 14:41:52 -0500310 @Override
311 public SharedPreferences getSharedPreferences(String name, int mode) {
312 if (name.equals(getPackageName() + "_preferences")) {
Jason Monke4ebcd12016-02-21 09:37:41 -0500313 return new SharedPreferencesLogger(this, getMetricsTag());
Jason Monk31c7c322016-01-20 14:41:52 -0500314 }
315 return super.getSharedPreferences(name, mode);
316 }
317
Jason Monke4ebcd12016-02-21 09:37:41 -0500318 private String getMetricsTag() {
319 String tag = getClass().getName();
320 if (getIntent() != null && getIntent().hasExtra(EXTRA_SHOW_FRAGMENT)) {
321 tag = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
322 }
323 if (tag.startsWith("com.android.settings.")) {
324 tag = tag.replace("com.android.settings.", "");
325 }
326 return tag;
327 }
328
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700329 private static boolean isShortCutIntent(final Intent intent) {
330 Set<String> categories = intent.getCategories();
331 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
332 }
333
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700334 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700335 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700336 if (action == null) {
337 return false;
338 }
339 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
340 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
341 }
342 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700343 }
344
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700345 @Override
346 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700347 super.onCreate(savedState);
Jason Monkfd2c7222015-12-02 15:38:38 -0500348 long startTime = System.currentTimeMillis();
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700349
350 final FeatureFactory factory = FeatureFactory.getFactory(this);
351
352 mDashboardFeatureProvider = factory.getDashboardFeatureProvider(this);
Matthew Fritze9955db62016-12-20 09:37:21 -0800353 mSearchFeatureProvider = factory.getSearchFeatureProvider();
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700354
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700355 // Should happen before any call to getIntent()
356 getMetaData();
357
358 final Intent intent = getIntent();
359 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
360 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800361 }
Udam Saini92779ce2016-03-28 14:29:48 -0700362 if (intent.getBooleanExtra(EXTRA_HIDE_DRAWER, false)) {
363 setIsDrawerPresent(false);
364 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800365
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800366 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
367 Context.MODE_PRIVATE);
368
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700369 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700370 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700371
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700372 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700373 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
374
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700375 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700376 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700377
Jason Monk4da79e02015-09-10 10:54:36 -0400378 mIsShowingDashboard = className.equals(Settings.class.getName())
379 || className.equals(Settings.WirelessSettings.class.getName())
380 || className.equals(Settings.DeviceSettings.class.getName())
381 || className.equals(Settings.PersonalSettings.class.getName())
382 || className.equals(Settings.WirelessSettings.class.getName());
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700383
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700384 // This is a "Sub Settings" when:
385 // - this is a real SubSettings
386 // - or :settings:show_fragment_as_subsetting is passed to the Intent
Jorim Jaggi4dfcb822015-04-29 17:21:32 -0700387 final boolean isSubSettings = this instanceof SubSettings ||
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700388 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
389
390 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
391 if (isSubSettings) {
Fabrice Di Meglio712df6c2014-07-18 17:44:37 -0700392 // Check also that we are not a Theme Dialog as we don't want to override them
393 final int themeResId = getThemeResId();
394 if (themeResId != R.style.Theme_DialogWhenLarge &&
395 themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
396 setTheme(R.style.Theme_SubSettings);
397 }
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700398 }
399
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700400 setContentView(mIsShowingDashboard ?
401 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800402
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700403 mContent = (ViewGroup) findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700404
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800405 getFragmentManager().addOnBackStackChangedListener(this);
406
Matthew Fritze34c27602017-01-18 18:24:56 -0800407 if (mIsShowingDashboard && !mSearchFeatureProvider.isEnabled(this)) {
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800408 // Run the Index update only if we have some space
409 if (!Utils.isLowStorage(this)) {
Fan Zhanga8759242017-01-06 09:18:59 -0800410 mSearchFeatureProvider.updateIndex(getApplicationContext());
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800411 } else {
412 Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
413 }
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700414 }
415
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700416 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700417 // We are restarting from a previous saved state; used that to initialize, instead
418 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700419 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
420 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700421 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800422
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700423 ArrayList<DashboardCategory> categories =
424 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
425 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700426 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700427 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700428 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800429 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700430
431 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700432 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Salvador Martinez2368e542016-07-25 18:16:47 -0700433
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800434 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700435 if (!mIsShowingDashboard) {
Jason Monkea8b1a72015-06-02 16:46:34 -0400436 mDisplaySearch = false;
437 // UP will be shown only if it is a sub settings
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700438 if (mIsShortcut) {
439 mDisplayHomeAsUpEnabled = isSubSettings;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700440 } else if (isSubSettings) {
441 mDisplayHomeAsUpEnabled = true;
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700442 } else {
443 mDisplayHomeAsUpEnabled = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700444 }
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700445 setTitleFromIntent(intent);
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700446
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700447 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700448 switchToFragment(initialFragmentName, initialArguments, true, false,
449 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000450 } else {
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700451 // No UP affordance if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700452 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700453 // Show Search affordance
454 mDisplaySearch = true;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700455 mInitialTitleResId = R.string.dashboard_title;
Salvador Martinez2368e542016-07-25 18:16:47 -0700456
457 // add argument to indicate which settings tab should be initially selected
458 final Bundle args = new Bundle();
459 final String extraName = DashboardContainerFragment.EXTRA_SELECT_SETTINGS_TAB;
460 args.putString(extraName, intent.getStringExtra(extraName));
Fan Zhanga96a2d82016-09-27 17:51:11 -0700461 if (isDashboardFeatureEnabled()) {
462 switchToFragment(DashboardSummary.class.getName(), args, false, false,
463 mInitialTitleResId, mInitialTitle, false);
464 } else {
465 switchToFragment(DashboardContainerFragment.class.getName(), args, false, false,
466 mInitialTitleResId, mInitialTitle, false);
467 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800468 }
469 }
470
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700471 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700472 if (mActionBar != null) {
473 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
474 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
475 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700476 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
Jason Monke4ebcd12016-02-21 09:37:41 -0500477 if (mSwitchBar != null) {
478 mSwitchBar.setMetricsTag(getMetricsTag());
479 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700480
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800481 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800482 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
483
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700484 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800485 if (buttonBar != null) {
486 buttonBar.setVisibility(View.VISIBLE);
487
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700488 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800489 backButton.setOnClickListener(new OnClickListener() {
490 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700491 setResult(RESULT_CANCELED, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800492 finish();
493 }
494 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700495 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800496 skipButton.setOnClickListener(new OnClickListener() {
497 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700498 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800499 finish();
500 }
501 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700502 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800503 mNextButton.setOnClickListener(new OnClickListener() {
504 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700505 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800506 finish();
507 }
508 });
509
510 // set our various button parameters
511 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
512 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
513 if (TextUtils.isEmpty(buttonText)) {
514 mNextButton.setVisibility(View.GONE);
515 }
516 else {
517 mNextButton.setText(buttonText);
518 }
519 }
520 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
521 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
522 if (TextUtils.isEmpty(buttonText)) {
523 backButton.setVisibility(View.GONE);
524 }
525 else {
526 backButton.setText(buttonText);
527 }
528 }
529 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
530 skipButton.setVisibility(View.VISIBLE);
531 }
532 }
533 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700534
Jason Monkfd2c7222015-12-02 15:38:38 -0500535 if (DEBUG_TIMING) Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
536 + " ms");
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700537 }
538
Fan Zhangece8ff62016-06-30 13:20:12 -0700539 public void setDisplaySearchMenu(boolean displaySearch) {
540 if (displaySearch != mDisplaySearch) {
541 mDisplaySearch = displaySearch;
542 invalidateOptionsMenu();
543 }
544 }
545
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700546 private void setTitleFromIntent(Intent intent) {
547 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
548 if (initialTitleResId > 0) {
549 mInitialTitle = null;
550 mInitialTitleResId = initialTitleResId;
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100551
552 final String initialTitleResPackageName = intent.getStringExtra(
553 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
554 if (initialTitleResPackageName != null) {
555 try {
556 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
557 0 /* flags */, new UserHandle(UserHandle.myUserId()));
558 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
559 setTitle(mInitialTitle);
560 mInitialTitleResId = -1;
561 return;
562 } catch (NameNotFoundException e) {
563 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
564 }
565 } else {
566 setTitle(mInitialTitleResId);
567 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700568 } else {
569 mInitialTitleResId = -1;
570 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
571 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
572 setTitle(mInitialTitle);
573 }
574 }
575
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800576 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800577 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700578 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800579 }
580
Fan Zhang28691572016-03-23 15:31:08 -0700581 private void setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800582 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700583
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800584 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700585 if (mInitialTitleResId > 0) {
586 setTitle(mInitialTitleResId);
587 } else {
588 setTitle(mInitialTitle);
589 }
Fan Zhang28691572016-03-23 15:31:08 -0700590 return;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800591 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700592
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800593 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
594 setTitleFromBackStackEntry(bse);
595 }
596
597 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
598 final CharSequence title;
599 final int titleRes = bse.getBreadCrumbTitleRes();
600 if (titleRes > 0) {
601 title = getText(titleRes);
602 } else {
603 title = bse.getBreadCrumbTitle();
604 }
605 if (title != null) {
606 setTitle(title);
607 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800608 }
609
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800610 @Override
611 protected void onSaveInstanceState(Bundle outState) {
612 super.onSaveInstanceState(outState);
613
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700614 if (mCategories.size() > 0) {
615 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800616 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700617
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700618 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700619 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700620
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700621 if (mDisplaySearch) {
622 // The option menus are created if the ActionBar is visible and they are also created
623 // asynchronously. If you launch Settings with an Intent action like
624 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
625 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
626 // menu item and search view are null.
627 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
628 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700629
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700630 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
631 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
632 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800633 }
634
635 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400636 protected void onResume() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800637 super.onResume();
638
639 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
640 @Override
641 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Jason Monk4da79e02015-09-10 10:54:36 -0400642 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800643 }
644 };
645 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
646 mDevelopmentPreferencesListener);
647
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800648 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Matthew Fritze34c27602017-01-18 18:24:56 -0800649 if (!mSearchFeatureProvider.isEnabled(this)) {
650 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_ADDED));
651 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_REMOVED));
652 }
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800653 if (mDynamicIndexableContentMonitor == null) {
654 mDynamicIndexableContentMonitor = new DynamicIndexableContentMonitor();
655 }
Philip P. Moltmannd9779db2016-02-24 12:11:05 -0800656 mDynamicIndexableContentMonitor.register(this, LOADER_ID_INDEXABLE_CONTENT_MONITOR);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700657
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700658 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700659 onQueryTextSubmit(mSearchQuery);
660 }
Jason Monk4da79e02015-09-10 10:54:36 -0400661 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800662 }
663
664 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400665 protected void onPause() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800666 super.onPause();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800667 unregisterReceiver(mBatteryInfoReceiver);
Matthew Fritze34c27602017-01-18 18:24:56 -0800668 if (!mSearchFeatureProvider.isEnabled(this)) {
669 unregisterReceiver(mUserAddRemoveReceiver);
670 }
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800671 if (mDynamicIndexableContentMonitor != null) {
Tadashi G. Takaokaa034fa52016-11-21 14:20:19 +0900672 mDynamicIndexableContentMonitor.unregister(this, LOADER_ID_INDEXABLE_CONTENT_MONITOR);
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800673 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800674 }
675
676 @Override
677 public void onDestroy() {
678 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700679
680 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
681 mDevelopmentPreferencesListener);
682 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800683 }
684
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800685 protected boolean isValidFragment(String fragmentName) {
686 // Almost all fragments are wrapped in this,
687 // except for a few that have their own activities.
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800688 for (int i = 0; i < SettingsGateway.ENTRY_FRAGMENTS.length; i++) {
689 if (SettingsGateway.ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800690 }
691 return false;
692 }
693
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800694 @Override
695 public Intent getIntent() {
696 Intent superIntent = super.getIntent();
697 String startingFragment = getStartingFragmentClass(superIntent);
698 // This is called from super.onCreate, isMultiPane() is not yet reliable
699 // Do not use onIsHidingHeaders either, which relies itself on this method
700 if (startingFragment != null) {
701 Intent modIntent = new Intent(superIntent);
702 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
703 Bundle args = superIntent.getExtras();
704 if (args != null) {
705 args = new Bundle(args);
706 } else {
707 args = new Bundle();
708 }
709 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100710 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800711 return modIntent;
712 }
713 return superIntent;
714 }
715
716 /**
717 * Checks if the component name in the intent is different from the Settings class and
718 * returns the class name to load as a fragment.
719 */
720 private String getStartingFragmentClass(Intent intent) {
721 if (mFragmentClass != null) return mFragmentClass;
722
723 String intentClass = intent.getComponent().getClassName();
724 if (intentClass.equals(getClass().getName())) return null;
725
726 if ("com.android.settings.ManageApplications".equals(intentClass)
727 || "com.android.settings.RunningServices".equals(intentClass)
728 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
729 // Old names of manage apps.
730 intentClass = com.android.settings.applications.ManageApplications.class.getName();
731 }
732
733 return intentClass;
734 }
735
736 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000737 * Start a new fragment containing a preference panel. If the preferences
738 * are being displayed in multi-pane mode, the given fragment class will
739 * be instantiated and placed in the appropriate pane. If running in
740 * single-pane mode, a new activity will be launched in which to show the
741 * fragment.
742 *
743 * @param fragmentClass Full name of the class implementing the fragment.
744 * @param args Any desired arguments to supply to the fragment.
745 * @param titleRes Optional resource identifier of the title of this
746 * fragment.
747 * @param titleText Optional text of the title of this fragment.
748 * @param resultTo Optional fragment that result data should be sent to.
749 * If non-null, resultTo.onActivityResult() will be called when this
750 * preference panel is done. The launched panel must use
751 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
752 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700753 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000754 */
755 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700756 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700757 String title = null;
758 if (titleRes < 0) {
759 if (titleText != null) {
760 title = titleText.toString();
761 } else {
762 // There not much we can do in that case
763 title = "";
764 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700765 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700766 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700767 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000768 }
769
770 /**
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100771 * Start a new fragment in a new activity containing a preference panel for a given user. If the
772 * preferences are being displayed in multi-pane mode, the given fragment class will be
773 * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
774 * activity will be launched in which to show the fragment.
775 *
776 * @param fragmentClass Full name of the class implementing the fragment.
777 * @param args Any desired arguments to supply to the fragment.
778 * @param titleRes Optional resource identifier of the title of this fragment.
779 * @param titleText Optional text of the title of this fragment.
780 * @param userHandle The user for which the panel has to be started.
781 */
782 public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
783 CharSequence titleText, UserHandle userHandle) {
Lifu Tangd0332852015-04-02 12:05:46 -0700784 // This is a workaround.
785 //
786 // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
787 // starting the fragment could cause a native stack corruption. See b/17523189. However,
788 // adding that flag and start the preference panel with the same UserHandler will make it
789 // impossible to use back button to return to the previous screen. See b/20042570.
790 //
791 // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
792 // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
793 // when we're calling it as the same user.
794 if (userHandle.getIdentifier() == UserHandle.myUserId()) {
795 startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0);
796 } else {
797 String title = null;
798 if (titleRes < 0) {
799 if (titleText != null) {
800 title = titleText.toString();
801 } else {
802 // There not much we can do in that case
803 title = "";
804 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100805 }
Lifu Tangd0332852015-04-02 12:05:46 -0700806 Utils.startWithFragmentAsUser(this, fragmentClass, args,
807 titleRes, title, mIsShortcut, userHandle);
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100808 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100809 }
810
811 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800812 * Called by a preference panel fragment to finish itself.
813 *
814 * @param caller The fragment that is asking to be finished.
815 * @param resultCode Optional result code to send back to the original
816 * launching fragment.
817 * @param resultData Optional result data to send back to the original
818 * launching fragment.
819 */
820 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
821 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700822 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800823 }
824
825 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000826 * Start a new fragment.
827 *
828 * @param fragment The fragment to start
829 * @param push If true, the current fragment will be pushed onto the back stack. If false,
830 * the current fragment will be replaced.
831 */
832 public void startPreferenceFragment(Fragment fragment, boolean push) {
833 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700834 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000835 if (push) {
836 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
837 transaction.addToBackStack(BACK_STACK_PREFS);
838 } else {
839 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
840 }
841 transaction.commitAllowingStateLoss();
842 }
843
844 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700845 * Switch to a specific Fragment with taking care of validation, Title and BackStack
846 */
847 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700848 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700849 if (validate && !isValidFragment(fragmentName)) {
850 throw new IllegalArgumentException("Invalid fragment for this activity: "
851 + fragmentName);
852 }
853 Fragment f = Fragment.instantiate(this, fragmentName, args);
854 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700855 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700856 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700857 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700858 }
859 if (addToBackStack) {
860 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
861 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700862 if (titleResId > 0) {
863 transaction.setBreadCrumbTitle(titleResId);
864 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700865 transaction.setBreadCrumbTitle(title);
866 }
867 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700868 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700869 return f;
870 }
871
Jason Monk4da79e02015-09-10 10:54:36 -0400872 private void updateTilesList() {
Jason Monkfd2c7222015-12-02 15:38:38 -0500873 // Generally the items that are will be changing from these updates will
874 // not be in the top list of tiles, so run it in the background and the
875 // SettingsDrawerActivity will pick up on the updates automatically.
876 AsyncTask.execute(new Runnable() {
877 @Override
878 public void run() {
879 doUpdateTilesList();
880 }
881 });
882 }
883
884 private void doUpdateTilesList() {
Jason Monk4da79e02015-09-10 10:54:36 -0400885 PackageManager pm = getPackageManager();
Xiaohui Chen44879a32015-07-22 13:53:22 -0700886 final UserManager um = UserManager.get(this);
887 final boolean isAdmin = um.isAdminUser();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700888
Jason Monk4da79e02015-09-10 10:54:36 -0400889 String packageName = getPackageName();
890 setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800891 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700892
Jason Monk4da79e02015-09-10 10:54:36 -0400893 setTileEnabled(new ComponentName(packageName,
894 Settings.BluetoothSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800895 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700896
Jason Monk4da79e02015-09-10 10:54:36 -0400897 setTileEnabled(new ComponentName(packageName,
898 Settings.DataUsageSummaryActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800899 Utils.isBandwidthControlEnabled(), isAdmin);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700900
Jason Monk4da79e02015-09-10 10:54:36 -0400901 setTileEnabled(new ComponentName(packageName,
902 Settings.SimSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800903 Utils.showSimCardTile(this), isAdmin);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700904
Jason Monk4da79e02015-09-10 10:54:36 -0400905 setTileEnabled(new ComponentName(packageName,
906 Settings.PowerUsageSummaryActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800907 mBatteryPresent, isAdmin);
Jason Monk4da79e02015-09-10 10:54:36 -0400908
909 setTileEnabled(new ComponentName(packageName,
Jason Monk4da79e02015-09-10 10:54:36 -0400910 Settings.UserSettingsActivity.class.getName()),
911 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
Fan Zhang224caad2017-01-06 11:42:48 -0800912 && !Utils.isMonkeyRunning(), isAdmin);
Jason Monk4da79e02015-09-10 10:54:36 -0400913
Fyodor Kupolovca060e32016-06-24 13:01:11 -0700914 setTileEnabled(new ComponentName(packageName,
915 Settings.WirelessSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800916 !UserManager.isDeviceInDemoMode(this), isAdmin);
Fyodor Kupolovca060e32016-06-24 13:01:11 -0700917
918 setTileEnabled(new ComponentName(packageName,
919 Settings.DateTimeSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800920 !UserManager.isDeviceInDemoMode(this), isAdmin);
Jason Monk4da79e02015-09-10 10:54:36 -0400921 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
922 setTileEnabled(new ComponentName(packageName,
923 Settings.PaymentSettingsActivity.class.getName()),
924 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
925 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
Fan Zhang224caad2017-01-06 11:42:48 -0800926 && adapter != null && adapter.isEnabled(), isAdmin);
Fan Zhangffd328b2017-01-09 10:16:49 -0800927 setTileEnabled(new ComponentName(packageName,
928 "com.android.settings.PaymentSettingsDashboardAlias"),
929 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
930 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
931 && adapter != null && adapter.isEnabled(), isAdmin);
Jason Monk4da79e02015-09-10 10:54:36 -0400932
933 setTileEnabled(new ComponentName(packageName,
934 Settings.PrintSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800935 pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin);
Jason Monk4da79e02015-09-10 10:54:36 -0400936
937 final boolean showDev = mDevelopmentPreferences.getBoolean(
Dan Sandler12c4ba42016-03-28 11:13:40 -0400938 DevelopmentSettings.PREF_SHOW, android.os.Build.TYPE.equals("eng"))
939 && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES);
Jason Monk4da79e02015-09-10 10:54:36 -0400940 setTileEnabled(new ComponentName(packageName,
941 Settings.DevelopmentSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800942 showDev, isAdmin);
Fan Zhangcc335d92016-09-29 14:37:14 -0700943 setTileEnabled(new ComponentName(packageName,
944 Settings.DevelopmentSettingsActivity.DASHBOARD_ALIAS),
Fan Zhang224caad2017-01-06 11:42:48 -0800945 showDev, isAdmin);
Dan Sandler12c4ba42016-03-28 11:13:40 -0400946
947 // Reveal development-only quick settings tiles
Sunny Goyalbf9f2d22016-11-02 11:20:17 -0700948 setTileEnabled(new ComponentName(this, DevelopmentModeTile.class), showDev);
Jason Monk4da79e02015-09-10 10:54:36 -0400949
950 if (UserHandle.MU_ENABLED && !isAdmin) {
951 // When on restricted users, disable all extra categories (but only the settings ones).
Fan Zhanga96a2d82016-09-27 17:51:11 -0700952 List<DashboardCategory> categories;
953 if (isDashboardFeatureEnabled()) {
954 categories = mDashboardFeatureProvider.getAllCategories();
955 } else {
956 categories = getDashboardCategories();
957 }
958
Jason Monk4da79e02015-09-10 10:54:36 -0400959 for (DashboardCategory category : categories) {
Jason Monkd4f03ec2016-01-07 16:25:34 -0500960 for (Tile tile : category.tiles) {
Jason Monk4da79e02015-09-10 10:54:36 -0400961 ComponentName component = tile.intent.getComponent();
Fan Zhang9ec45362017-01-10 11:55:45 -0800962 final String name = component.getClassName();
963 final boolean isEnabledForRestricted = ArrayUtils.contains(
964 SettingsGateway.SETTINGS_FOR_RESTRICTED, name);
965 if (packageName.equals(component.getPackageName()) && !isEnabledForRestricted) {
Fan Zhang224caad2017-01-06 11:42:48 -0800966 setTileEnabled(component, false, isAdmin);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700967 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700968 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700969 }
970 }
Doris Ling26bf0032016-06-15 18:16:09 -0700971
972 String backupIntent = getResources().getString(R.string.config_backup_settings_intent);
973 boolean useDefaultBackup = TextUtils.isEmpty(backupIntent);
974 setTileEnabled(new ComponentName(packageName,
Fan Zhang224caad2017-01-06 11:42:48 -0800975 Settings.PrivacySettingsActivity.class.getName()), useDefaultBackup, isAdmin);
Fan Zhang0e8d0d12016-11-02 09:15:33 -0700976 setTileEnabled(new ComponentName(packageName,
977 "com.android.settings.PrivacyDashboardAlias"),
Fan Zhang224caad2017-01-06 11:42:48 -0800978 useDefaultBackup, isAdmin);
Fan Zhang0e8d0d12016-11-02 09:15:33 -0700979
Doris Ling26bf0032016-06-15 18:16:09 -0700980 boolean hasBackupActivity = false;
981 if (!useDefaultBackup) {
982 try {
983 Intent intent = Intent.parseUri(backupIntent, 0);
984 hasBackupActivity = !getPackageManager().queryIntentActivities(intent, 0).isEmpty();
985 } catch (URISyntaxException e) {
986 Log.e(LOG_TAG, "Invalid backup intent URI!", e);
987 }
988 }
Fan Zhang10dd4652016-11-16 10:24:26 -0800989
Fan Zhang224caad2017-01-06 11:42:48 -0800990 // Enable/disable BackupSettingsActivity and its alias.
Doris Ling26bf0032016-06-15 18:16:09 -0700991 setTileEnabled(new ComponentName(packageName,
Fan Zhang224caad2017-01-06 11:42:48 -0800992 BackupSettingsActivity.class.getName()), hasBackupActivity, isAdmin);
Fan Zhang10dd4652016-11-16 10:24:26 -0800993 setTileEnabled(new ComponentName(packageName,
Fan Zhang224caad2017-01-06 11:42:48 -0800994 "com.android.settings.BackupResetDashboardAlias"), hasBackupActivity, 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}