blob: d5e886f34041d3206e4b918fdf886444d133433f [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;
jackqdyulei6c355f52017-03-01 17:37:23 -080034import android.graphics.Bitmap;
35import android.graphics.BitmapFactory;
36import android.graphics.Canvas;
37import android.graphics.drawable.Drawable;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080038import android.nfc.NfcAdapter;
Jason Monkfd2c7222015-12-02 15:38:38 -050039import android.os.AsyncTask;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080040import android.os.Bundle;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080041import android.os.UserHandle;
42import android.os.UserManager;
Fan Zhanga3e8f5c2016-12-01 09:52:10 -080043import android.support.annotation.VisibleForTesting;
Jason Monk39b46742015-09-10 15:52:51 -040044import android.support.v14.preference.PreferenceFragment;
45import android.support.v7.preference.Preference;
46import android.support.v7.preference.PreferenceManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080047import android.text.TextUtils;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070048import android.transition.TransitionManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080049import android.util.Log;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070050import android.view.Menu;
51import android.view.MenuInflater;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080052import android.view.MenuItem;
53import android.view.View;
54import android.view.View.OnClickListener;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070055import android.view.ViewGroup;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080056import android.widget.Button;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070057import android.widget.SearchView;
Fan Zhang28691572016-03-23 15:31:08 -070058
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080059import com.android.internal.util.ArrayUtils;
Jason Monk4da79e02015-09-10 10:54:36 -040060import com.android.settings.Settings.WifiSettingsActivity;
Anton Philippovadfec552017-01-25 20:37:36 +000061import com.android.settings.backup.BackupSettingsActivity;
Fan Zhanga3e8f5c2016-12-01 09:52:10 -080062import com.android.settings.core.gateway.SettingsGateway;
Fan Zhangc6ca3142017-02-14 15:02:35 -080063import com.android.settings.core.instrumentation.MetricsFeatureProvider;
Fan Zhang5f79ae92016-08-18 16:04:19 -070064import com.android.settings.core.instrumentation.SharedPreferencesLogger;
Fan Zhanga96a2d82016-09-27 17:51:11 -070065import com.android.settings.dashboard.DashboardFeatureProvider;
66import com.android.settings.dashboard.DashboardSummary;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070067import com.android.settings.dashboard.SearchResultsSummary;
Fan Zhanga96a2d82016-09-27 17:51:11 -070068import com.android.settings.overlay.FeatureFactory;
Jason Monk2ebc8a02015-02-13 15:23:19 -050069import com.android.settings.search.DynamicIndexableContentMonitor;
Matthew Fritze0ed37c32016-10-24 10:12:49 -070070import com.android.settings.search2.SearchFeatureProvider;
Fabrice Di Meglio41937762014-05-13 19:51:59 -070071import com.android.settings.widget.SwitchBar;
Jason Monk4da79e02015-09-10 10:54:36 -040072import com.android.settingslib.drawer.DashboardCategory;
Jason Monk4da79e02015-09-10 10:54:36 -040073import com.android.settingslib.drawer.SettingsDrawerActivity;
Jason Monk7ea14c52016-01-22 14:28:02 -050074import com.android.settingslib.drawer.Tile;
Jason Monk2ebc8a02015-02-13 15:23:19 -050075
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080076import java.util.ArrayList;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080077import java.util.List;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -070078import java.util.Set;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080079
Jason Monk4da79e02015-09-10 10:54:36 -040080public class SettingsActivity extends SettingsDrawerActivity
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080081 implements PreferenceManager.OnPreferenceTreeClickListener,
82 PreferenceFragment.OnPreferenceStartFragmentCallback,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +010083 ButtonBarHandler, FragmentManager.OnBackStackChangedListener,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070084 SearchView.OnQueryTextListener, SearchView.OnCloseListener,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +010085 MenuItem.OnActionExpandListener {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080086
87 private static final String LOG_TAG = "Settings";
88
Philip P. Moltmannd9779db2016-02-24 12:11:05 -080089 private static final int LOADER_ID_INDEXABLE_CONTENT_MONITOR = 1;
90
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080091 // Constants for state save/restore
Fabrice Di Meglio769630c2014-04-24 14:48:48 -070092 private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070093 private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
94 private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
Fabrice Di Megliob731dd02014-04-03 18:40:38 -070095 private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -070096 private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080097
98 /**
99 * When starting this activity, the invoking Intent can contain this extra
100 * string to specify which fragment should be initially displayed.
101 * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
102 * will call isValidFragment() to confirm that the fragment class name is valid for this
103 * activity.
104 */
105 public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
106
107 /**
Fan Zhangc6ca3142017-02-14 15:02:35 -0800108 * The metrics category constant for logging source when a setting fragment is opened.
109 */
110 public static final String EXTRA_SOURCE_METRICS_CATEGORY = ":settings:source_metrics";
111
112 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800113 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
114 * this extra can also be specified to supply a Bundle of arguments to pass
115 * to that fragment when it is instantiated during the initial creation
116 * of the activity.
117 */
118 public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
119
120 /**
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700121 * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
122 */
123 public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
124
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800125 public static final String BACK_STACK_PREFS = ":settings:prefs";
126
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800127 // extras that allow any preference activity to be launched as part of a wizard
128
129 // show Back and Next buttons? takes boolean parameter
130 // Back will then return RESULT_CANCELED and Next RESULT_OK
131 protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
132
133 // add a Skip button?
134 private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
135
136 // specify custom text for the Back or Next buttons, or cause a button to not appear
137 // at all by setting it to null
138 protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
139 protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
140
141 /**
142 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700143 * 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 -0800144 * that fragment.
145 */
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700146 public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100147 /**
148 * The package name used to resolve the title resource id.
149 */
150 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
151 ":settings:show_fragment_title_res_package_name";
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700152 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
153 ":settings:show_fragment_title_resid";
154 public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
155 ":settings:show_fragment_as_shortcut";
156
157 public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
158 ":settings:show_fragment_as_subsetting";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800159
Fan Zhang78ab9f92017-02-27 16:10:05 -0800160 @Deprecated
Udam Saini92779ce2016-03-28 14:29:48 -0700161 public static final String EXTRA_HIDE_DRAWER = ":settings:hide_drawer";
162
Jason Monk30695812015-11-17 09:01:08 -0500163 public static final String META_DATA_KEY_FRAGMENT_CLASS =
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800164 "com.android.settings.FRAGMENT_CLASS";
165
166 private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
167
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700168 private static final String EMPTY_QUERY = "";
169
Jason Monkd4f03ec2016-01-07 16:25:34 -0500170 private static final int REQUEST_SUGGESTION = 42;
171
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800172 private String mFragmentClass;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800173
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800174 private CharSequence mInitialTitle;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700175 private int mInitialTitleResId;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800176
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700177 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
178 "android.settings.APPLICATION_DETAILS_SETTINGS"
179 };
180
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800181 private SharedPreferences mDevelopmentPreferences;
182 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
183
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800184 private boolean mBatteryPresent = true;
185 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800186 @Override
187 public void onReceive(Context context, Intent intent) {
188 String action = intent.getAction();
189 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
190 boolean batteryPresent = Utils.isBatteryPresent(intent);
191
192 if (mBatteryPresent != batteryPresent) {
193 mBatteryPresent = batteryPresent;
Jason Monk4da79e02015-09-10 10:54:36 -0400194 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800195 }
196 }
197 }
198 };
199
Clara Bayarri6934a042015-10-14 11:07:35 +0100200 private final BroadcastReceiver mUserAddRemoveReceiver = new BroadcastReceiver() {
201 @Override
202 public void onReceive(Context context, Intent intent) {
Matthew Fritze34c27602017-01-18 18:24:56 -0800203 if (mSearchFeatureProvider != null && !mSearchFeatureProvider.isEnabled(context)) {
204 String action = intent.getAction();
205 if (action.equals(Intent.ACTION_USER_ADDED)
206 || action.equals(Intent.ACTION_USER_REMOVED)) {
207 mSearchFeatureProvider.updateIndex(getApplicationContext());
208 }
Clara Bayarri6934a042015-10-14 11:07:35 +0100209 }
210 }
211 };
212
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800213 private DynamicIndexableContentMonitor mDynamicIndexableContentMonitor;
Svetoslav853e4712014-04-14 10:10:25 -0700214
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700215 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700216 private SwitchBar mSwitchBar;
217
218 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700219
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700220 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700221 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700222
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700223 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700224 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700225
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700226 private ViewGroup mContent;
227
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700228 private SearchView mSearchView;
229 private MenuItem mSearchMenuItem;
230 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700231 private SearchResultsSummary mSearchResultsFragment;
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700232 private SearchFeatureProvider mSearchFeatureProvider;
Fan Zhangc6ca3142017-02-14 15:02:35 -0800233 private MetricsFeatureProvider mMetricsFeatureProvider;
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700234
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700235 // Categories
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800236 private ArrayList<DashboardCategory> mCategories = new ArrayList<>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800237
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700238 private boolean mNeedToRevertToInitialFragment = false;
239
Fan Zhanga96a2d82016-09-27 17:51:11 -0700240 private DashboardFeatureProvider mDashboardFeatureProvider;
Jim Miller0698a212014-10-16 19:49:07 -0700241 private Intent mResultIntentData;
Jason Monkd4f03ec2016-01-07 16:25:34 -0500242 private ComponentName mCurrentSuggestion;
Jim Miller0698a212014-10-16 19:49:07 -0700243
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800244 @VisibleForTesting
245 String mSearchQuery;
246
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700247 public SwitchBar getSwitchBar() {
248 return mSwitchBar;
249 }
250
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800251 @Override
252 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
Fan Zhangc6ca3142017-02-14 15:02:35 -0800253 startPreferencePanel(caller, pref.getFragment(), pref.getExtras(), -1, pref.getTitle(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800254 null, 0);
255 return true;
256 }
257
258 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400259 public boolean onPreferenceTreeClick(Preference preference) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800260 return false;
261 }
262
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800263 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800264 public void onConfigurationChanged(Configuration newConfig) {
265 super.onConfigurationChanged(newConfig);
Matthew Fritze34c27602017-01-18 18:24:56 -0800266 if (!mSearchFeatureProvider.isEnabled(this)) {
267 mSearchFeatureProvider.updateIndex(getApplicationContext());
268 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800269 }
270
271 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700272 protected void onStart() {
273 super.onStart();
274
275 if (mNeedToRevertToInitialFragment) {
276 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800277 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800278 }
279
280 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700281 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700282 if (!mDisplaySearch) {
283 return false;
284 }
285
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700286 MenuInflater inflater = getMenuInflater();
Matthew Fritze9955db62016-12-20 09:37:21 -0800287 if (mSearchFeatureProvider.isEnabled(this)) {
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700288 mSearchFeatureProvider.setUpSearchMenu(menu, this);
289 return true;
290 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700291 inflater.inflate(R.menu.options_menu, menu);
292
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700293
294 // Cache the search query (can be overridden by the OnQueryTextListener)
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700295 final String query = mSearchQuery;
296
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700297 mSearchMenuItem = menu.findItem(R.id.search);
298 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700299
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700300 if (mSearchMenuItem == null || mSearchView == null) {
301 return false;
302 }
303
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700304 if (mSearchResultsFragment != null) {
305 mSearchResultsFragment.setSearchView(mSearchView);
306 }
307
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700308 mSearchMenuItem.setOnActionExpandListener(this);
Fan Zhangb9239182016-08-22 13:59:59 -0700309 mSearchView.setMaxWidth(Integer.MAX_VALUE);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700310 mSearchView.setOnQueryTextListener(this);
311 mSearchView.setOnCloseListener(this);
312
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700313 if (mSearchMenuItemExpanded) {
314 mSearchMenuItem.expandActionView();
315 }
316 mSearchView.setQuery(query, true /* submit */);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700317 return true;
318 }
319
Jason Monk31c7c322016-01-20 14:41:52 -0500320 @Override
321 public SharedPreferences getSharedPreferences(String name, int mode) {
322 if (name.equals(getPackageName() + "_preferences")) {
Jason Monke4ebcd12016-02-21 09:37:41 -0500323 return new SharedPreferencesLogger(this, getMetricsTag());
Jason Monk31c7c322016-01-20 14:41:52 -0500324 }
325 return super.getSharedPreferences(name, mode);
326 }
327
Jason Monke4ebcd12016-02-21 09:37:41 -0500328 private String getMetricsTag() {
329 String tag = getClass().getName();
330 if (getIntent() != null && getIntent().hasExtra(EXTRA_SHOW_FRAGMENT)) {
331 tag = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
332 }
333 if (tag.startsWith("com.android.settings.")) {
334 tag = tag.replace("com.android.settings.", "");
335 }
336 return tag;
337 }
338
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700339 private static boolean isShortCutIntent(final Intent intent) {
340 Set<String> categories = intent.getCategories();
341 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
342 }
343
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700344 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700345 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700346 if (action == null) {
347 return false;
348 }
349 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
350 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
351 }
352 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700353 }
354
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700355 @Override
356 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700357 super.onCreate(savedState);
Jason Monkfd2c7222015-12-02 15:38:38 -0500358 long startTime = System.currentTimeMillis();
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700359
360 final FeatureFactory factory = FeatureFactory.getFactory(this);
361
362 mDashboardFeatureProvider = factory.getDashboardFeatureProvider(this);
Matthew Fritze9955db62016-12-20 09:37:21 -0800363 mSearchFeatureProvider = factory.getSearchFeatureProvider();
Fan Zhangc6ca3142017-02-14 15:02:35 -0800364 mMetricsFeatureProvider = factory.getMetricsFeatureProvider();
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700365
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700366 // Should happen before any call to getIntent()
367 getMetaData();
368
369 final Intent intent = getIntent();
370 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
371 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800372 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800373
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800374 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
375 Context.MODE_PRIVATE);
376
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700377 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700378 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700379
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700380 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700381 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
382
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700383 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700384 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700385
Jason Monk4da79e02015-09-10 10:54:36 -0400386 mIsShowingDashboard = className.equals(Settings.class.getName())
387 || className.equals(Settings.WirelessSettings.class.getName())
388 || className.equals(Settings.DeviceSettings.class.getName())
389 || className.equals(Settings.PersonalSettings.class.getName())
390 || className.equals(Settings.WirelessSettings.class.getName());
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700391
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700392 // This is a "Sub Settings" when:
393 // - this is a real SubSettings
394 // - or :settings:show_fragment_as_subsetting is passed to the Intent
Jorim Jaggi4dfcb822015-04-29 17:21:32 -0700395 final boolean isSubSettings = this instanceof SubSettings ||
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700396 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
397
Fan Zhang92f1e942017-01-21 10:07:26 -0800398 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content
399 // insets
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700400 if (isSubSettings) {
Fan Zhang92f1e942017-01-21 10:07:26 -0800401 setTheme(R.style.Theme_SubSettings);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700402 }
403
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700404 setContentView(mIsShowingDashboard ?
405 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800406
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700407 mContent = (ViewGroup) findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700408
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800409 getFragmentManager().addOnBackStackChangedListener(this);
410
Matthew Fritze34c27602017-01-18 18:24:56 -0800411 if (mIsShowingDashboard && !mSearchFeatureProvider.isEnabled(this)) {
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800412 // Run the Index update only if we have some space
413 if (!Utils.isLowStorage(this)) {
Fan Zhanga8759242017-01-06 09:18:59 -0800414 mSearchFeatureProvider.updateIndex(getApplicationContext());
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800415 } else {
416 Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
417 }
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700418 }
419
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700420 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700421 // We are restarting from a previous saved state; used that to initialize, instead
422 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700423 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
424 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700425 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800426
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700427 ArrayList<DashboardCategory> categories =
428 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
429 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700430 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700431 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700432 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800433 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700434
435 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700436 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Salvador Martinez2368e542016-07-25 18:16:47 -0700437
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800438 } else {
Doris Lingcb69baf2017-02-23 17:50:03 -0800439 launchSettingFragment(initialFragmentName, isSubSettings, intent);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800440 }
441
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700442 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700443 if (mActionBar != null) {
444 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
445 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
446 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700447 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
Jason Monke4ebcd12016-02-21 09:37:41 -0500448 if (mSwitchBar != null) {
449 mSwitchBar.setMetricsTag(getMetricsTag());
450 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700451
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800452 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800453 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
454
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700455 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800456 if (buttonBar != null) {
457 buttonBar.setVisibility(View.VISIBLE);
458
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700459 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800460 backButton.setOnClickListener(new OnClickListener() {
461 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700462 setResult(RESULT_CANCELED, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800463 finish();
464 }
465 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700466 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800467 skipButton.setOnClickListener(new OnClickListener() {
468 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700469 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800470 finish();
471 }
472 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700473 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800474 mNextButton.setOnClickListener(new OnClickListener() {
475 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700476 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800477 finish();
478 }
479 });
480
481 // set our various button parameters
482 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
483 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
484 if (TextUtils.isEmpty(buttonText)) {
485 mNextButton.setVisibility(View.GONE);
486 }
487 else {
488 mNextButton.setText(buttonText);
489 }
490 }
491 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
492 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
493 if (TextUtils.isEmpty(buttonText)) {
494 backButton.setVisibility(View.GONE);
495 }
496 else {
497 backButton.setText(buttonText);
498 }
499 }
500 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
501 skipButton.setVisibility(View.VISIBLE);
502 }
503 }
504 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700505
Fan Zhangefba6b42017-02-07 17:40:59 -0800506 if (DEBUG_TIMING) {
507 Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime) + " ms");
508 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700509 }
510
Doris Lingcb69baf2017-02-23 17:50:03 -0800511 @VisibleForTesting
512 void launchSettingFragment(String initialFragmentName, boolean isSubSettings, Intent intent) {
513 if (!mIsShowingDashboard && initialFragmentName != null) {
514 mDisplaySearch = false;
515 // UP will be shown only if it is a sub settings
516 if (mIsShortcut) {
517 mDisplayHomeAsUpEnabled = isSubSettings;
518 } else if (isSubSettings) {
519 mDisplayHomeAsUpEnabled = true;
520 } else {
521 mDisplayHomeAsUpEnabled = false;
522 }
523 setTitleFromIntent(intent);
524
525 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
526 switchToFragment(initialFragmentName, initialArguments, true, false,
527 mInitialTitleResId, mInitialTitle, false);
528 } else {
529 // No UP affordance if we are displaying the main Dashboard
530 mDisplayHomeAsUpEnabled = false;
531 // Show Search affordance
532 mDisplaySearch = true;
533 mInitialTitleResId = R.string.dashboard_title;
534
535 switchToFragment(DashboardSummary.class.getName(), null /* args */, false, false,
536 mInitialTitleResId, mInitialTitle, false);
537 }
538 }
539
Fan Zhangece8ff62016-06-30 13:20:12 -0700540 public void setDisplaySearchMenu(boolean displaySearch) {
541 if (displaySearch != mDisplaySearch) {
542 mDisplaySearch = displaySearch;
543 invalidateOptionsMenu();
544 }
545 }
546
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700547 private void setTitleFromIntent(Intent intent) {
548 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
549 if (initialTitleResId > 0) {
550 mInitialTitle = null;
551 mInitialTitleResId = initialTitleResId;
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100552
553 final String initialTitleResPackageName = intent.getStringExtra(
554 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
555 if (initialTitleResPackageName != null) {
556 try {
557 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
558 0 /* flags */, new UserHandle(UserHandle.myUserId()));
559 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
560 setTitle(mInitialTitle);
561 mInitialTitleResId = -1;
562 return;
563 } catch (NameNotFoundException e) {
564 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
565 }
566 } else {
567 setTitle(mInitialTitleResId);
568 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700569 } else {
570 mInitialTitleResId = -1;
571 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
572 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
573 setTitle(mInitialTitle);
574 }
575 }
576
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800577 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800578 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700579 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800580 }
581
Fan Zhang28691572016-03-23 15:31:08 -0700582 private void setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800583 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700584
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800585 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700586 if (mInitialTitleResId > 0) {
587 setTitle(mInitialTitleResId);
588 } else {
589 setTitle(mInitialTitle);
590 }
Fan Zhang28691572016-03-23 15:31:08 -0700591 return;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800592 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700593
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800594 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
595 setTitleFromBackStackEntry(bse);
596 }
597
598 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
599 final CharSequence title;
600 final int titleRes = bse.getBreadCrumbTitleRes();
601 if (titleRes > 0) {
602 title = getText(titleRes);
603 } else {
604 title = bse.getBreadCrumbTitle();
605 }
606 if (title != null) {
607 setTitle(title);
608 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800609 }
610
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800611 @Override
612 protected void onSaveInstanceState(Bundle outState) {
613 super.onSaveInstanceState(outState);
614
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700615 if (mCategories.size() > 0) {
616 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800617 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700618
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700619 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700620 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700621
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700622 if (mDisplaySearch) {
623 // The option menus are created if the ActionBar is visible and they are also created
624 // asynchronously. If you launch Settings with an Intent action like
625 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
626 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
627 // menu item and search view are null.
628 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
629 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700630
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700631 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
632 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
633 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800634 }
635
636 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400637 protected void onResume() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800638 super.onResume();
639
640 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
641 @Override
642 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Jason Monk4da79e02015-09-10 10:54:36 -0400643 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800644 }
645 };
646 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
647 mDevelopmentPreferencesListener);
648
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800649 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Matthew Fritze34c27602017-01-18 18:24:56 -0800650 if (!mSearchFeatureProvider.isEnabled(this)) {
651 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_ADDED));
652 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_REMOVED));
653 }
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800654 if (mDynamicIndexableContentMonitor == null) {
655 mDynamicIndexableContentMonitor = new DynamicIndexableContentMonitor();
656 }
Philip P. Moltmannd9779db2016-02-24 12:11:05 -0800657 mDynamicIndexableContentMonitor.register(this, LOADER_ID_INDEXABLE_CONTENT_MONITOR);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700658
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700659 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700660 onQueryTextSubmit(mSearchQuery);
661 }
Jason Monk4da79e02015-09-10 10:54:36 -0400662 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800663 }
664
665 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400666 protected void onPause() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800667 super.onPause();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800668 unregisterReceiver(mBatteryInfoReceiver);
Matthew Fritze34c27602017-01-18 18:24:56 -0800669 if (!mSearchFeatureProvider.isEnabled(this)) {
670 unregisterReceiver(mUserAddRemoveReceiver);
671 }
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800672 if (mDynamicIndexableContentMonitor != null) {
Tadashi G. Takaokaa034fa52016-11-21 14:20:19 +0900673 mDynamicIndexableContentMonitor.unregister(this, LOADER_ID_INDEXABLE_CONTENT_MONITOR);
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800674 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800675 }
676
677 @Override
678 public void onDestroy() {
679 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700680
681 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
682 mDevelopmentPreferencesListener);
683 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800684 }
685
jackqdyulei6c355f52017-03-01 17:37:23 -0800686 @Override
687 public void setTaskDescription(ActivityManager.TaskDescription taskDescription) {
688 final Bitmap icon = getBitmapFromXmlResource(R.drawable.ic_launcher_settings);
689 taskDescription.setIcon(icon);
690 super.setTaskDescription(taskDescription);
691 }
692
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800693 protected boolean isValidFragment(String fragmentName) {
694 // Almost all fragments are wrapped in this,
695 // except for a few that have their own activities.
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800696 for (int i = 0; i < SettingsGateway.ENTRY_FRAGMENTS.length; i++) {
697 if (SettingsGateway.ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800698 }
699 return false;
700 }
701
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800702 @Override
703 public Intent getIntent() {
704 Intent superIntent = super.getIntent();
705 String startingFragment = getStartingFragmentClass(superIntent);
706 // This is called from super.onCreate, isMultiPane() is not yet reliable
707 // Do not use onIsHidingHeaders either, which relies itself on this method
708 if (startingFragment != null) {
709 Intent modIntent = new Intent(superIntent);
710 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
711 Bundle args = superIntent.getExtras();
712 if (args != null) {
713 args = new Bundle(args);
714 } else {
715 args = new Bundle();
716 }
717 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100718 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800719 return modIntent;
720 }
721 return superIntent;
722 }
723
724 /**
725 * Checks if the component name in the intent is different from the Settings class and
726 * returns the class name to load as a fragment.
727 */
728 private String getStartingFragmentClass(Intent intent) {
729 if (mFragmentClass != null) return mFragmentClass;
730
731 String intentClass = intent.getComponent().getClassName();
732 if (intentClass.equals(getClass().getName())) return null;
733
734 if ("com.android.settings.ManageApplications".equals(intentClass)
735 || "com.android.settings.RunningServices".equals(intentClass)
736 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
737 // Old names of manage apps.
738 intentClass = com.android.settings.applications.ManageApplications.class.getName();
739 }
740
741 return intentClass;
742 }
743
744 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000745 * Start a new fragment containing a preference panel. If the preferences
746 * are being displayed in multi-pane mode, the given fragment class will
747 * be instantiated and placed in the appropriate pane. If running in
748 * single-pane mode, a new activity will be launched in which to show the
749 * fragment.
750 *
751 * @param fragmentClass Full name of the class implementing the fragment.
752 * @param args Any desired arguments to supply to the fragment.
753 * @param titleRes Optional resource identifier of the title of this
754 * fragment.
755 * @param titleText Optional text of the title of this fragment.
756 * @param resultTo Optional fragment that result data should be sent to.
757 * If non-null, resultTo.onActivityResult() will be called when this
758 * preference panel is done. The launched panel must use
759 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
760 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700761 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000762 */
Fan Zhangc6ca3142017-02-14 15:02:35 -0800763 public void startPreferencePanel(Fragment caller, String fragmentClass, Bundle args,
764 int titleRes, CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700765 String title = null;
766 if (titleRes < 0) {
767 if (titleText != null) {
768 title = titleText.toString();
769 } else {
770 // There not much we can do in that case
771 title = "";
772 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700773 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700774 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fan Zhangc6ca3142017-02-14 15:02:35 -0800775 titleRes, title, mIsShortcut, mMetricsFeatureProvider.getMetricsCategory(caller));
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000776 }
777
778 /**
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100779 * Start a new fragment in a new activity containing a preference panel for a given user. If the
780 * preferences are being displayed in multi-pane mode, the given fragment class will be
781 * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
782 * activity will be launched in which to show the fragment.
783 *
784 * @param fragmentClass Full name of the class implementing the fragment.
785 * @param args Any desired arguments to supply to the fragment.
786 * @param titleRes Optional resource identifier of the title of this fragment.
787 * @param titleText Optional text of the title of this fragment.
788 * @param userHandle The user for which the panel has to be started.
789 */
Fan Zhangc6ca3142017-02-14 15:02:35 -0800790 public void startPreferencePanelAsUser(Fragment caller, String fragmentClass,
791 Bundle args, int titleRes, CharSequence titleText, UserHandle userHandle) {
Lifu Tangd0332852015-04-02 12:05:46 -0700792 // This is a workaround.
793 //
794 // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
795 // starting the fragment could cause a native stack corruption. See b/17523189. However,
796 // adding that flag and start the preference panel with the same UserHandler will make it
797 // impossible to use back button to return to the previous screen. See b/20042570.
798 //
799 // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
800 // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
801 // when we're calling it as the same user.
802 if (userHandle.getIdentifier() == UserHandle.myUserId()) {
Fan Zhangc6ca3142017-02-14 15:02:35 -0800803 startPreferencePanel(caller, fragmentClass, args, titleRes, titleText, null, 0);
Lifu Tangd0332852015-04-02 12:05:46 -0700804 } else {
805 String title = null;
806 if (titleRes < 0) {
807 if (titleText != null) {
808 title = titleText.toString();
809 } else {
810 // There not much we can do in that case
811 title = "";
812 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100813 }
Fan Zhangc6ca3142017-02-14 15:02:35 -0800814 Utils.startWithFragmentAsUser(this, fragmentClass, args, titleRes, title,
815 mIsShortcut, mMetricsFeatureProvider.getMetricsCategory(caller), userHandle);
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100816 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100817 }
818
819 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800820 * Called by a preference panel fragment to finish itself.
821 *
822 * @param caller The fragment that is asking to be finished.
823 * @param resultCode Optional result code to send back to the original
824 * launching fragment.
825 * @param resultData Optional result data to send back to the original
826 * launching fragment.
827 */
828 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
829 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700830 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800831 }
832
833 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000834 * Start a new fragment.
835 *
836 * @param fragment The fragment to start
837 * @param push If true, the current fragment will be pushed onto the back stack. If false,
838 * the current fragment will be replaced.
839 */
840 public void startPreferenceFragment(Fragment fragment, boolean push) {
841 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700842 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000843 if (push) {
844 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
845 transaction.addToBackStack(BACK_STACK_PREFS);
846 } else {
847 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
848 }
849 transaction.commitAllowingStateLoss();
850 }
851
852 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700853 * Switch to a specific Fragment with taking care of validation, Title and BackStack
854 */
855 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700856 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700857 if (validate && !isValidFragment(fragmentName)) {
858 throw new IllegalArgumentException("Invalid fragment for this activity: "
859 + fragmentName);
860 }
861 Fragment f = Fragment.instantiate(this, fragmentName, args);
862 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700863 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700864 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700865 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700866 }
867 if (addToBackStack) {
868 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
869 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700870 if (titleResId > 0) {
871 transaction.setBreadCrumbTitle(titleResId);
872 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700873 transaction.setBreadCrumbTitle(title);
874 }
875 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700876 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700877 return f;
878 }
879
Jason Monk4da79e02015-09-10 10:54:36 -0400880 private void updateTilesList() {
Jason Monkfd2c7222015-12-02 15:38:38 -0500881 // Generally the items that are will be changing from these updates will
882 // not be in the top list of tiles, so run it in the background and the
883 // SettingsDrawerActivity will pick up on the updates automatically.
884 AsyncTask.execute(new Runnable() {
885 @Override
886 public void run() {
887 doUpdateTilesList();
888 }
889 });
890 }
891
892 private void doUpdateTilesList() {
Jason Monk4da79e02015-09-10 10:54:36 -0400893 PackageManager pm = getPackageManager();
Xiaohui Chen44879a32015-07-22 13:53:22 -0700894 final UserManager um = UserManager.get(this);
895 final boolean isAdmin = um.isAdminUser();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700896
Jason Monk4da79e02015-09-10 10:54:36 -0400897 String packageName = getPackageName();
898 setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800899 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700900
Jason Monk4da79e02015-09-10 10:54:36 -0400901 setTileEnabled(new ComponentName(packageName,
902 Settings.BluetoothSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800903 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700904
Jason Monk4da79e02015-09-10 10:54:36 -0400905 setTileEnabled(new ComponentName(packageName,
906 Settings.DataUsageSummaryActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800907 Utils.isBandwidthControlEnabled(), isAdmin);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700908
Jason Monk4da79e02015-09-10 10:54:36 -0400909 setTileEnabled(new ComponentName(packageName,
910 Settings.SimSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800911 Utils.showSimCardTile(this), isAdmin);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700912
Jason Monk4da79e02015-09-10 10:54:36 -0400913 setTileEnabled(new ComponentName(packageName,
914 Settings.PowerUsageSummaryActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800915 mBatteryPresent, isAdmin);
Jason Monk4da79e02015-09-10 10:54:36 -0400916
917 setTileEnabled(new ComponentName(packageName,
Jason Monk4da79e02015-09-10 10:54:36 -0400918 Settings.UserSettingsActivity.class.getName()),
919 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
Fan Zhang224caad2017-01-06 11:42:48 -0800920 && !Utils.isMonkeyRunning(), isAdmin);
Jason Monk4da79e02015-09-10 10:54:36 -0400921
Fyodor Kupolovca060e32016-06-24 13:01:11 -0700922 setTileEnabled(new ComponentName(packageName,
Doris Ling26208222017-03-03 11:28:05 -0800923 Settings.NetworkDashboardActivity.class.getName()),
924 !UserManager.isDeviceInDemoMode(this), isAdmin);
925
926 setTileEnabled(new ComponentName(packageName,
927 Settings.ConnectedDeviceDashboardActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800928 !UserManager.isDeviceInDemoMode(this), isAdmin);
Fyodor Kupolovca060e32016-06-24 13:01:11 -0700929
930 setTileEnabled(new ComponentName(packageName,
931 Settings.DateTimeSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800932 !UserManager.isDeviceInDemoMode(this), isAdmin);
Jason Monk4da79e02015-09-10 10:54:36 -0400933 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
934 setTileEnabled(new ComponentName(packageName,
935 Settings.PaymentSettingsActivity.class.getName()),
936 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
937 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
Fan Zhang224caad2017-01-06 11:42:48 -0800938 && adapter != null && adapter.isEnabled(), isAdmin);
Fan Zhangffd328b2017-01-09 10:16:49 -0800939 setTileEnabled(new ComponentName(packageName,
940 "com.android.settings.PaymentSettingsDashboardAlias"),
941 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
942 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
943 && adapter != null && adapter.isEnabled(), isAdmin);
Jason Monk4da79e02015-09-10 10:54:36 -0400944
945 setTileEnabled(new ComponentName(packageName,
946 Settings.PrintSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800947 pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin);
Jason Monk4da79e02015-09-10 10:54:36 -0400948
949 final boolean showDev = mDevelopmentPreferences.getBoolean(
Dan Sandler12c4ba42016-03-28 11:13:40 -0400950 DevelopmentSettings.PREF_SHOW, android.os.Build.TYPE.equals("eng"))
951 && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES);
Jason Monk4da79e02015-09-10 10:54:36 -0400952 setTileEnabled(new ComponentName(packageName,
953 Settings.DevelopmentSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800954 showDev, isAdmin);
Dan Sandler12c4ba42016-03-28 11:13:40 -0400955
Jason Monk4da79e02015-09-10 10:54:36 -0400956 if (UserHandle.MU_ENABLED && !isAdmin) {
957 // When on restricted users, disable all extra categories (but only the settings ones).
Fan Zhang78ab9f92017-02-27 16:10:05 -0800958 final List<DashboardCategory> categories = mDashboardFeatureProvider.getAllCategories();
Fan Zhanga96a2d82016-09-27 17:51:11 -0700959
Jason Monk4da79e02015-09-10 10:54:36 -0400960 for (DashboardCategory category : categories) {
Jason Monkd4f03ec2016-01-07 16:25:34 -0500961 for (Tile tile : category.tiles) {
Jason Monk4da79e02015-09-10 10:54:36 -0400962 ComponentName component = tile.intent.getComponent();
Fan Zhang9ec45362017-01-10 11:55:45 -0800963 final String name = component.getClassName();
964 final boolean isEnabledForRestricted = ArrayUtils.contains(
965 SettingsGateway.SETTINGS_FOR_RESTRICTED, name);
966 if (packageName.equals(component.getPackageName()) && !isEnabledForRestricted) {
Fan Zhang224caad2017-01-06 11:42:48 -0800967 setTileEnabled(component, false, isAdmin);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700968 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700969 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700970 }
971 }
Doris Ling26bf0032016-06-15 18:16:09 -0700972
Anton Philippovadfec552017-01-25 20:37:36 +0000973 // Enable/disable backup settings depending on whether the user is admin.
Doris Ling26bf0032016-06-15 18:16:09 -0700974 setTileEnabled(new ComponentName(packageName,
Christine Franks14782222017-01-23 16:44:02 -0800975 BackupSettingsActivity.class.getName()), true,
976 isAdmin || Utils.isCarrierDemoUser(this));
Doris Ling26bf0032016-06-15 18:16:09 -0700977
Bartosz Fabianowski05061fc2016-11-14 12:04:49 +0100978 setTileEnabled(new ComponentName(packageName,
979 Settings.EnterprisePrivacySettingsActivity.class.getName()),
980 FeatureFactory.getFactory(this).getEnterprisePrivacyFeatureProvider(this)
Fan Zhang224caad2017-01-06 11:42:48 -0800981 .hasDeviceOwner(), isAdmin);
Fan Zhang224caad2017-01-06 11:42:48 -0800982 // Final step, refresh categories.
983 updateCategories();
Jason Monk2ebc8a02015-02-13 15:23:19 -0500984 }
985
Fan Zhang224caad2017-01-06 11:42:48 -0800986 private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin) {
Jason Monk5862c1e2016-06-07 14:02:33 -0400987 if (UserHandle.MU_ENABLED && !isAdmin && getPackageName().equals(component.getPackageName())
Fan Zhang9ec45362017-01-10 11:55:45 -0800988 && !ArrayUtils.contains(SettingsGateway.SETTINGS_FOR_RESTRICTED,
989 component.getClassName())) {
Jason Monk4da79e02015-09-10 10:54:36 -0400990 enabled = false;
991 }
Jason Monk5862c1e2016-06-07 14:02:33 -0400992 setTileEnabled(component, enabled);
Jason Monk2ebc8a02015-02-13 15:23:19 -0500993 }
994
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800995 private void getMetaData() {
996 try {
997 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
998 PackageManager.GET_META_DATA);
999 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001000 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1001 } catch (NameNotFoundException nnfe) {
1002 // No recovery
1003 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1004 }
1005 }
1006
1007 // give subclasses access to the Next button
1008 public boolean hasNextButton() {
1009 return mNextButton != null;
1010 }
1011
1012 public Button getNextButton() {
1013 return mNextButton;
1014 }
1015
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001016 @Override
1017 public boolean shouldUpRecreateTask(Intent targetIntent) {
1018 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1019 }
1020
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001021 @Deprecated
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001022 @Override
1023 public boolean onQueryTextSubmit(String query) {
Matthew Fritze9955db62016-12-20 09:37:21 -08001024 if (mSearchFeatureProvider.isEnabled(this)) {
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001025 return false;
1026 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001027 mSearchQuery = query;
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001028 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001029 return mSearchResultsFragment.onQueryTextSubmit(query);
1030 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001031
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001032 @Deprecated
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001033 @Override
1034 public boolean onQueryTextChange(String newText) {
Fan Zhanga3e8f5c2016-12-01 09:52:10 -08001035 mSearchQuery = newText;
Matthew Fritze9955db62016-12-20 09:37:21 -08001036 if (mSearchFeatureProvider.isEnabled(this) || mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001037 return false;
1038 }
1039 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001040 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001041
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001042 @Override
1043 public boolean onClose() {
1044 return false;
1045 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001046
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001047 @Override
1048 public boolean onMenuItemActionExpand(MenuItem item) {
1049 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001050 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001051 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001052 return true;
1053 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001054
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001055 @Override
1056 public boolean onMenuItemActionCollapse(MenuItem item) {
1057 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001058 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001059 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001060 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001061 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001062 return true;
1063 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001064
Jason Monk4da79e02015-09-10 10:54:36 -04001065 @Override
Jason Monkaf001092015-11-04 13:16:18 -05001066 public void onProfileTileOpen() {
1067 if (!mIsShowingDashboard) {
1068 finish();
1069 }
1070 }
1071
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001072 @Deprecated
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001073 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001074 if (mSearchResultsFragment != null) {
1075 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001076 }
Anna Galusza6b1e9db2016-03-30 17:25:36 -07001077 Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001078 if (current != null && current instanceof SearchResultsSummary) {
1079 mSearchResultsFragment = (SearchResultsSummary) current;
1080 } else {
Fan Zhang28691572016-03-23 15:31:08 -07001081 setContentHeaderView(null);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001082 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001083 SearchResultsSummary.class.getName(), null, false, true,
1084 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001085 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001086 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001087 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001088 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001089
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001090 @Deprecated
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001091 public void needToRevertToInitialFragment() {
1092 mNeedToRevertToInitialFragment = true;
1093 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001094
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001095 @Deprecated
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001096 private void revertToInitialFragment() {
1097 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001098 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001099 mSearchMenuItemExpanded = false;
1100 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1101 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001102 if (mSearchMenuItem != null) {
1103 mSearchMenuItem.collapseActionView();
1104 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001105 }
Jim Miller0698a212014-10-16 19:49:07 -07001106
1107 public Intent getResultIntentData() {
1108 return mResultIntentData;
1109 }
1110
1111 public void setResultIntentData(Intent resultIntentData) {
1112 mResultIntentData = resultIntentData;
1113 }
Jason Monkd4f03ec2016-01-07 16:25:34 -05001114
1115 public void startSuggestion(Intent intent) {
Matthew Fritze7ac78f22016-10-03 13:26:07 -07001116 if (intent == null || ActivityManager.isUserAMonkey()) {
Matthew Fritze703dc602016-09-30 12:36:27 -07001117 return;
1118 }
Matthew Fritzef265dbc2016-10-04 13:39:27 -07001119 mCurrentSuggestion = intent.getComponent();
Jason Monkd4f03ec2016-01-07 16:25:34 -05001120 startActivityForResult(intent, REQUEST_SUGGESTION);
1121 }
1122
1123 @Override
1124 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
1125 if (requestCode == REQUEST_SUGGESTION && mCurrentSuggestion != null
1126 && resultCode != RESULT_CANCELED) {
1127 getPackageManager().setComponentEnabledSetting(mCurrentSuggestion,
1128 PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
1129 }
1130 super.onActivityResult(requestCode, resultCode, data);
1131 }
jackqdyulei6c355f52017-03-01 17:37:23 -08001132
1133 @VisibleForTesting
1134 Bitmap getBitmapFromXmlResource(int drawableRes) {
1135 Drawable drawable = getResources().getDrawable(drawableRes, getTheme());
1136 Canvas canvas = new Canvas();
1137 Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
1138 drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
1139 canvas.setBitmap(bitmap);
1140 drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
1141 drawable.draw(canvas);
1142
1143 return bitmap;
1144 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001145}