blob: 00a2c7d72d1a765434a655561a5653bb89c0f725 [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;
jackqdyulei6c355f52017-03-01 17:37:23 -080035import android.graphics.Canvas;
36import android.graphics.drawable.Drawable;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080037import android.nfc.NfcAdapter;
Jason Monkfd2c7222015-12-02 15:38:38 -050038import android.os.AsyncTask;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080039import android.os.Bundle;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080040import android.os.UserHandle;
41import android.os.UserManager;
Fan Zhanga3e8f5c2016-12-01 09:52:10 -080042import android.support.annotation.VisibleForTesting;
Jason Monk39b46742015-09-10 15:52:51 -040043import android.support.v14.preference.PreferenceFragment;
44import android.support.v7.preference.Preference;
45import android.support.v7.preference.PreferenceManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080046import android.text.TextUtils;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070047import android.transition.TransitionManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080048import android.util.Log;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070049import android.view.Menu;
50import android.view.MenuInflater;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080051import android.view.MenuItem;
52import android.view.View;
53import android.view.View.OnClickListener;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070054import android.view.ViewGroup;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080055import android.widget.Button;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070056import android.widget.SearchView;
Fan Zhang28691572016-03-23 15:31:08 -070057
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080058import com.android.internal.util.ArrayUtils;
Jason Monk4da79e02015-09-10 10:54:36 -040059import com.android.settings.Settings.WifiSettingsActivity;
Anton Philippovadfec552017-01-25 20:37:36 +000060import com.android.settings.backup.BackupSettingsActivity;
Fan Zhanga3e8f5c2016-12-01 09:52:10 -080061import com.android.settings.core.gateway.SettingsGateway;
Fan Zhangc6ca3142017-02-14 15:02:35 -080062import com.android.settings.core.instrumentation.MetricsFeatureProvider;
Fan Zhang5f79ae92016-08-18 16:04:19 -070063import com.android.settings.core.instrumentation.SharedPreferencesLogger;
Fan Zhanga96a2d82016-09-27 17:51:11 -070064import com.android.settings.dashboard.DashboardFeatureProvider;
65import com.android.settings.dashboard.DashboardSummary;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070066import com.android.settings.dashboard.SearchResultsSummary;
Fan Zhangcabc5092017-03-14 12:38:43 -070067import com.android.settings.enterprise.EnterprisePrivacySettings;
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;
Fan Zhang4fcd5ed2017-03-10 12:25:35 -080071import com.android.settings.wfd.WifiDisplaySettings;
Fabrice Di Meglio41937762014-05-13 19:51:59 -070072import com.android.settings.widget.SwitchBar;
Jason Monk4da79e02015-09-10 10:54:36 -040073import com.android.settingslib.drawer.DashboardCategory;
Jason Monk4da79e02015-09-10 10:54:36 -040074import com.android.settingslib.drawer.SettingsDrawerActivity;
Jason Monk7ea14c52016-01-22 14:28:02 -050075import com.android.settingslib.drawer.Tile;
Jason Monk2ebc8a02015-02-13 15:23:19 -050076
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080077import java.util.ArrayList;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080078import java.util.List;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -070079import java.util.Set;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080080
Jason Monk4da79e02015-09-10 10:54:36 -040081public class SettingsActivity extends SettingsDrawerActivity
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080082 implements PreferenceManager.OnPreferenceTreeClickListener,
83 PreferenceFragment.OnPreferenceStartFragmentCallback,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +010084 ButtonBarHandler, FragmentManager.OnBackStackChangedListener,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070085 SearchView.OnQueryTextListener, SearchView.OnCloseListener,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +010086 MenuItem.OnActionExpandListener {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080087
88 private static final String LOG_TAG = "Settings";
89
Philip P. Moltmannd9779db2016-02-24 12:11:05 -080090 private static final int LOADER_ID_INDEXABLE_CONTENT_MONITOR = 1;
91
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080092 // Constants for state save/restore
Fabrice Di Meglio769630c2014-04-24 14:48:48 -070093 private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070094 private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
95 private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
Fabrice Di Megliob731dd02014-04-03 18:40:38 -070096 private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -070097 private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080098
99 /**
100 * When starting this activity, the invoking Intent can contain this extra
101 * string to specify which fragment should be initially displayed.
102 * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
103 * will call isValidFragment() to confirm that the fragment class name is valid for this
104 * activity.
105 */
106 public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
107
108 /**
Fan Zhangc6ca3142017-02-14 15:02:35 -0800109 * The metrics category constant for logging source when a setting fragment is opened.
110 */
111 public static final String EXTRA_SOURCE_METRICS_CATEGORY = ":settings:source_metrics";
112
113 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800114 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
115 * this extra can also be specified to supply a Bundle of arguments to pass
116 * to that fragment when it is instantiated during the initial creation
117 * of the activity.
118 */
119 public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
120
121 /**
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700122 * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
123 */
124 public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
125
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800126 public static final String BACK_STACK_PREFS = ":settings:prefs";
127
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800128 // extras that allow any preference activity to be launched as part of a wizard
129
130 // show Back and Next buttons? takes boolean parameter
131 // Back will then return RESULT_CANCELED and Next RESULT_OK
132 protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
133
134 // add a Skip button?
135 private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
136
137 // specify custom text for the Back or Next buttons, or cause a button to not appear
138 // at all by setting it to null
139 protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
140 protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
141
142 /**
143 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700144 * 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 -0800145 * that fragment.
146 */
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700147 public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100148 /**
149 * The package name used to resolve the title resource id.
150 */
151 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
152 ":settings:show_fragment_title_res_package_name";
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700153 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
154 ":settings:show_fragment_title_resid";
155 public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
156 ":settings:show_fragment_as_shortcut";
157
158 public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
159 ":settings:show_fragment_as_subsetting";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800160
Fan Zhang78ab9f92017-02-27 16:10:05 -0800161 @Deprecated
Udam Saini92779ce2016-03-28 14:29:48 -0700162 public static final String EXTRA_HIDE_DRAWER = ":settings:hide_drawer";
163
Jason Monk30695812015-11-17 09:01:08 -0500164 public static final String META_DATA_KEY_FRAGMENT_CLASS =
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800165 "com.android.settings.FRAGMENT_CLASS";
166
167 private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
168
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700169 private static final String EMPTY_QUERY = "";
170
Jason Monkd4f03ec2016-01-07 16:25:34 -0500171 private static final int REQUEST_SUGGESTION = 42;
172
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800173 private String mFragmentClass;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800174
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800175 private CharSequence mInitialTitle;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700176 private int mInitialTitleResId;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800177
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700178 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
179 "android.settings.APPLICATION_DETAILS_SETTINGS"
180 };
181
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800182 private SharedPreferences mDevelopmentPreferences;
183 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
184
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800185 private boolean mBatteryPresent = true;
186 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800187 @Override
188 public void onReceive(Context context, Intent intent) {
189 String action = intent.getAction();
190 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
191 boolean batteryPresent = Utils.isBatteryPresent(intent);
192
193 if (mBatteryPresent != batteryPresent) {
194 mBatteryPresent = batteryPresent;
Jason Monk4da79e02015-09-10 10:54:36 -0400195 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800196 }
197 }
198 }
199 };
200
Clara Bayarri6934a042015-10-14 11:07:35 +0100201 private final BroadcastReceiver mUserAddRemoveReceiver = new BroadcastReceiver() {
202 @Override
203 public void onReceive(Context context, Intent intent) {
Matthew Fritze34c27602017-01-18 18:24:56 -0800204 if (mSearchFeatureProvider != null && !mSearchFeatureProvider.isEnabled(context)) {
205 String action = intent.getAction();
206 if (action.equals(Intent.ACTION_USER_ADDED)
207 || action.equals(Intent.ACTION_USER_REMOVED)) {
208 mSearchFeatureProvider.updateIndex(getApplicationContext());
209 }
Clara Bayarri6934a042015-10-14 11:07:35 +0100210 }
211 }
212 };
213
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800214 private DynamicIndexableContentMonitor mDynamicIndexableContentMonitor;
Svetoslav853e4712014-04-14 10:10:25 -0700215
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700216 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700217 private SwitchBar mSwitchBar;
218
219 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700220
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700221 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700222 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700223
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700224 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700225 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700226
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700227 private ViewGroup mContent;
228
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700229 private SearchView mSearchView;
230 private MenuItem mSearchMenuItem;
231 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700232 private SearchResultsSummary mSearchResultsFragment;
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700233 private SearchFeatureProvider mSearchFeatureProvider;
Fan Zhangc6ca3142017-02-14 15:02:35 -0800234 private MetricsFeatureProvider mMetricsFeatureProvider;
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700235
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700236 // Categories
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800237 private ArrayList<DashboardCategory> mCategories = new ArrayList<>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800238
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700239 private boolean mNeedToRevertToInitialFragment = false;
240
Fan Zhanga96a2d82016-09-27 17:51:11 -0700241 private DashboardFeatureProvider mDashboardFeatureProvider;
Jim Miller0698a212014-10-16 19:49:07 -0700242 private Intent mResultIntentData;
Jason Monkd4f03ec2016-01-07 16:25:34 -0500243 private ComponentName mCurrentSuggestion;
Jim Miller0698a212014-10-16 19:49:07 -0700244
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800245 @VisibleForTesting
246 String mSearchQuery;
247
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700248 public SwitchBar getSwitchBar() {
249 return mSwitchBar;
250 }
251
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800252 @Override
253 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
Fan Zhangc6ca3142017-02-14 15:02:35 -0800254 startPreferencePanel(caller, pref.getFragment(), pref.getExtras(), -1, pref.getTitle(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800255 null, 0);
256 return true;
257 }
258
259 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400260 public boolean onPreferenceTreeClick(Preference preference) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800261 return false;
262 }
263
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800264 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800265 public void onConfigurationChanged(Configuration newConfig) {
266 super.onConfigurationChanged(newConfig);
Matthew Fritze34c27602017-01-18 18:24:56 -0800267 if (!mSearchFeatureProvider.isEnabled(this)) {
268 mSearchFeatureProvider.updateIndex(getApplicationContext());
269 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800270 }
271
272 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700273 protected void onStart() {
274 super.onStart();
275
276 if (mNeedToRevertToInitialFragment) {
277 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800278 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800279 }
280
281 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700282 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700283 if (!mDisplaySearch) {
284 return false;
285 }
286
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700287 MenuInflater inflater = getMenuInflater();
Matthew Fritze9955db62016-12-20 09:37:21 -0800288 if (mSearchFeatureProvider.isEnabled(this)) {
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700289 mSearchFeatureProvider.setUpSearchMenu(menu, this);
290 return true;
291 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700292 inflater.inflate(R.menu.options_menu, menu);
293
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700294
295 // Cache the search query (can be overridden by the OnQueryTextListener)
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700296 final String query = mSearchQuery;
297
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700298 mSearchMenuItem = menu.findItem(R.id.search);
299 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700300
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700301 if (mSearchMenuItem == null || mSearchView == null) {
302 return false;
303 }
304
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700305 if (mSearchResultsFragment != null) {
306 mSearchResultsFragment.setSearchView(mSearchView);
307 }
308
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700309 mSearchMenuItem.setOnActionExpandListener(this);
Fan Zhangb9239182016-08-22 13:59:59 -0700310 mSearchView.setMaxWidth(Integer.MAX_VALUE);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700311 mSearchView.setOnQueryTextListener(this);
312 mSearchView.setOnCloseListener(this);
313
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700314 if (mSearchMenuItemExpanded) {
315 mSearchMenuItem.expandActionView();
316 }
317 mSearchView.setQuery(query, true /* submit */);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700318 return true;
319 }
320
Jason Monk31c7c322016-01-20 14:41:52 -0500321 @Override
322 public SharedPreferences getSharedPreferences(String name, int mode) {
323 if (name.equals(getPackageName() + "_preferences")) {
Jason Monke4ebcd12016-02-21 09:37:41 -0500324 return new SharedPreferencesLogger(this, getMetricsTag());
Jason Monk31c7c322016-01-20 14:41:52 -0500325 }
326 return super.getSharedPreferences(name, mode);
327 }
328
Jason Monke4ebcd12016-02-21 09:37:41 -0500329 private String getMetricsTag() {
330 String tag = getClass().getName();
331 if (getIntent() != null && getIntent().hasExtra(EXTRA_SHOW_FRAGMENT)) {
332 tag = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
333 }
334 if (tag.startsWith("com.android.settings.")) {
335 tag = tag.replace("com.android.settings.", "");
336 }
337 return tag;
338 }
339
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700340 private static boolean isShortCutIntent(final Intent intent) {
341 Set<String> categories = intent.getCategories();
342 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
343 }
344
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700345 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700346 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700347 if (action == null) {
348 return false;
349 }
350 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
351 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
352 }
353 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700354 }
355
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700356 @Override
357 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700358 super.onCreate(savedState);
Jason Monkfd2c7222015-12-02 15:38:38 -0500359 long startTime = System.currentTimeMillis();
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700360
361 final FeatureFactory factory = FeatureFactory.getFactory(this);
362
363 mDashboardFeatureProvider = factory.getDashboardFeatureProvider(this);
Matthew Fritze9955db62016-12-20 09:37:21 -0800364 mSearchFeatureProvider = factory.getSearchFeatureProvider();
Fan Zhangc6ca3142017-02-14 15:02:35 -0800365 mMetricsFeatureProvider = factory.getMetricsFeatureProvider();
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700366
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700367 // Should happen before any call to getIntent()
368 getMetaData();
369
370 final Intent intent = getIntent();
371 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
372 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800373 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800374
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800375 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
376 Context.MODE_PRIVATE);
377
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700378 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700379 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700380
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700381 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700382 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
383
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700384 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700385 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700386
Doris Ling1694d4b2017-03-03 14:21:37 -0800387 mIsShowingDashboard = className.equals(Settings.class.getName());
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700388
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700389 // This is a "Sub Settings" when:
390 // - this is a real SubSettings
391 // - or :settings:show_fragment_as_subsetting is passed to the Intent
Jorim Jaggi4dfcb822015-04-29 17:21:32 -0700392 final boolean isSubSettings = this instanceof SubSettings ||
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700393 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
394
Fan Zhang92f1e942017-01-21 10:07:26 -0800395 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content
396 // insets
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700397 if (isSubSettings) {
Fan Zhang92f1e942017-01-21 10:07:26 -0800398 setTheme(R.style.Theme_SubSettings);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700399 }
400
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700401 setContentView(mIsShowingDashboard ?
402 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800403
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700404 mContent = (ViewGroup) findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700405
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800406 getFragmentManager().addOnBackStackChangedListener(this);
407
Matthew Fritze34c27602017-01-18 18:24:56 -0800408 if (mIsShowingDashboard && !mSearchFeatureProvider.isEnabled(this)) {
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800409 // Run the Index update only if we have some space
410 if (!Utils.isLowStorage(this)) {
Fan Zhanga8759242017-01-06 09:18:59 -0800411 mSearchFeatureProvider.updateIndex(getApplicationContext());
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800412 } else {
413 Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
414 }
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700415 }
416
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700417 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700418 // We are restarting from a previous saved state; used that to initialize, instead
419 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700420 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
421 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700422 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800423
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700424 ArrayList<DashboardCategory> categories =
425 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
426 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700427 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700428 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700429 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800430 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700431
432 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700433 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Salvador Martinez2368e542016-07-25 18:16:47 -0700434
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800435 } else {
Doris Lingcb69baf2017-02-23 17:50:03 -0800436 launchSettingFragment(initialFragmentName, isSubSettings, intent);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800437 }
438
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700439 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700440 if (mActionBar != null) {
441 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
442 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
443 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700444 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
Jason Monke4ebcd12016-02-21 09:37:41 -0500445 if (mSwitchBar != null) {
446 mSwitchBar.setMetricsTag(getMetricsTag());
447 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700448
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800449 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800450 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
451
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700452 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800453 if (buttonBar != null) {
454 buttonBar.setVisibility(View.VISIBLE);
455
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700456 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800457 backButton.setOnClickListener(new OnClickListener() {
458 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700459 setResult(RESULT_CANCELED, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800460 finish();
461 }
462 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700463 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800464 skipButton.setOnClickListener(new OnClickListener() {
465 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700466 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800467 finish();
468 }
469 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700470 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800471 mNextButton.setOnClickListener(new OnClickListener() {
472 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700473 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800474 finish();
475 }
476 });
477
478 // set our various button parameters
479 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
480 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
481 if (TextUtils.isEmpty(buttonText)) {
482 mNextButton.setVisibility(View.GONE);
483 }
484 else {
485 mNextButton.setText(buttonText);
486 }
487 }
488 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
489 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
490 if (TextUtils.isEmpty(buttonText)) {
491 backButton.setVisibility(View.GONE);
492 }
493 else {
494 backButton.setText(buttonText);
495 }
496 }
497 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
498 skipButton.setVisibility(View.VISIBLE);
499 }
500 }
501 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700502
Fan Zhangefba6b42017-02-07 17:40:59 -0800503 if (DEBUG_TIMING) {
504 Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime) + " ms");
505 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700506 }
507
Doris Lingcb69baf2017-02-23 17:50:03 -0800508 @VisibleForTesting
509 void launchSettingFragment(String initialFragmentName, boolean isSubSettings, Intent intent) {
510 if (!mIsShowingDashboard && initialFragmentName != null) {
511 mDisplaySearch = false;
512 // UP will be shown only if it is a sub settings
513 if (mIsShortcut) {
514 mDisplayHomeAsUpEnabled = isSubSettings;
515 } else if (isSubSettings) {
516 mDisplayHomeAsUpEnabled = true;
517 } else {
518 mDisplayHomeAsUpEnabled = false;
519 }
520 setTitleFromIntent(intent);
521
522 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
523 switchToFragment(initialFragmentName, initialArguments, true, false,
524 mInitialTitleResId, mInitialTitle, false);
525 } else {
526 // No UP affordance if we are displaying the main Dashboard
527 mDisplayHomeAsUpEnabled = false;
528 // Show Search affordance
529 mDisplaySearch = true;
530 mInitialTitleResId = R.string.dashboard_title;
531
532 switchToFragment(DashboardSummary.class.getName(), null /* args */, false, false,
533 mInitialTitleResId, mInitialTitle, false);
534 }
535 }
536
Fan Zhangece8ff62016-06-30 13:20:12 -0700537 public void setDisplaySearchMenu(boolean displaySearch) {
538 if (displaySearch != mDisplaySearch) {
539 mDisplaySearch = displaySearch;
540 invalidateOptionsMenu();
541 }
542 }
543
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700544 private void setTitleFromIntent(Intent intent) {
545 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
546 if (initialTitleResId > 0) {
547 mInitialTitle = null;
548 mInitialTitleResId = initialTitleResId;
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100549
550 final String initialTitleResPackageName = intent.getStringExtra(
551 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
552 if (initialTitleResPackageName != null) {
553 try {
554 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
555 0 /* flags */, new UserHandle(UserHandle.myUserId()));
556 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
557 setTitle(mInitialTitle);
558 mInitialTitleResId = -1;
559 return;
560 } catch (NameNotFoundException e) {
561 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
562 }
563 } else {
564 setTitle(mInitialTitleResId);
565 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700566 } else {
567 mInitialTitleResId = -1;
568 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
569 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
570 setTitle(mInitialTitle);
571 }
572 }
573
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800574 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800575 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700576 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800577 }
578
Fan Zhang28691572016-03-23 15:31:08 -0700579 private void setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800580 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700581
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800582 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700583 if (mInitialTitleResId > 0) {
584 setTitle(mInitialTitleResId);
585 } else {
586 setTitle(mInitialTitle);
587 }
Fan Zhang28691572016-03-23 15:31:08 -0700588 return;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800589 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700590
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800591 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
592 setTitleFromBackStackEntry(bse);
593 }
594
595 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
596 final CharSequence title;
597 final int titleRes = bse.getBreadCrumbTitleRes();
598 if (titleRes > 0) {
599 title = getText(titleRes);
600 } else {
601 title = bse.getBreadCrumbTitle();
602 }
603 if (title != null) {
604 setTitle(title);
605 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800606 }
607
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800608 @Override
609 protected void onSaveInstanceState(Bundle outState) {
610 super.onSaveInstanceState(outState);
611
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700612 if (mCategories.size() > 0) {
613 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800614 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700615
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700616 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700617 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700618
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700619 if (mDisplaySearch) {
620 // The option menus are created if the ActionBar is visible and they are also created
621 // asynchronously. If you launch Settings with an Intent action like
622 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
623 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
624 // menu item and search view are null.
625 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
626 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700627
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700628 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
629 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
630 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800631 }
632
633 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400634 protected void onResume() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800635 super.onResume();
636
637 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
638 @Override
639 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Jason Monk4da79e02015-09-10 10:54:36 -0400640 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800641 }
642 };
643 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
644 mDevelopmentPreferencesListener);
645
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800646 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Matthew Fritze34c27602017-01-18 18:24:56 -0800647 if (!mSearchFeatureProvider.isEnabled(this)) {
648 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_ADDED));
649 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_REMOVED));
650 }
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800651 if (mDynamicIndexableContentMonitor == null) {
652 mDynamicIndexableContentMonitor = new DynamicIndexableContentMonitor();
653 }
Philip P. Moltmannd9779db2016-02-24 12:11:05 -0800654 mDynamicIndexableContentMonitor.register(this, LOADER_ID_INDEXABLE_CONTENT_MONITOR);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700655
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700656 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700657 onQueryTextSubmit(mSearchQuery);
658 }
Jason Monk4da79e02015-09-10 10:54:36 -0400659 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800660 }
661
662 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400663 protected void onPause() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800664 super.onPause();
Fan Zhanga6986e72017-03-08 09:24:45 -0800665 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
666 mDevelopmentPreferencesListener);
667 mDevelopmentPreferencesListener = null;
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
jackqdyulei6c355f52017-03-01 17:37:23 -0800678 public void setTaskDescription(ActivityManager.TaskDescription taskDescription) {
679 final Bitmap icon = getBitmapFromXmlResource(R.drawable.ic_launcher_settings);
680 taskDescription.setIcon(icon);
681 super.setTaskDescription(taskDescription);
682 }
683
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800684 protected boolean isValidFragment(String fragmentName) {
685 // Almost all fragments are wrapped in this,
686 // except for a few that have their own activities.
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800687 for (int i = 0; i < SettingsGateway.ENTRY_FRAGMENTS.length; i++) {
688 if (SettingsGateway.ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800689 }
690 return false;
691 }
692
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800693 @Override
694 public Intent getIntent() {
695 Intent superIntent = super.getIntent();
696 String startingFragment = getStartingFragmentClass(superIntent);
697 // This is called from super.onCreate, isMultiPane() is not yet reliable
698 // Do not use onIsHidingHeaders either, which relies itself on this method
699 if (startingFragment != null) {
700 Intent modIntent = new Intent(superIntent);
701 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
702 Bundle args = superIntent.getExtras();
703 if (args != null) {
704 args = new Bundle(args);
705 } else {
706 args = new Bundle();
707 }
708 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100709 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800710 return modIntent;
711 }
712 return superIntent;
713 }
714
715 /**
716 * Checks if the component name in the intent is different from the Settings class and
717 * returns the class name to load as a fragment.
718 */
719 private String getStartingFragmentClass(Intent intent) {
720 if (mFragmentClass != null) return mFragmentClass;
721
722 String intentClass = intent.getComponent().getClassName();
723 if (intentClass.equals(getClass().getName())) return null;
724
725 if ("com.android.settings.ManageApplications".equals(intentClass)
726 || "com.android.settings.RunningServices".equals(intentClass)
727 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
728 // Old names of manage apps.
729 intentClass = com.android.settings.applications.ManageApplications.class.getName();
730 }
731
732 return intentClass;
733 }
734
735 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000736 * Start a new fragment containing a preference panel. If the preferences
737 * are being displayed in multi-pane mode, the given fragment class will
738 * be instantiated and placed in the appropriate pane. If running in
739 * single-pane mode, a new activity will be launched in which to show the
740 * fragment.
741 *
742 * @param fragmentClass Full name of the class implementing the fragment.
743 * @param args Any desired arguments to supply to the fragment.
744 * @param titleRes Optional resource identifier of the title of this
745 * fragment.
746 * @param titleText Optional text of the title of this fragment.
747 * @param resultTo Optional fragment that result data should be sent to.
748 * If non-null, resultTo.onActivityResult() will be called when this
749 * preference panel is done. The launched panel must use
750 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
751 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700752 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000753 */
Fan Zhangc6ca3142017-02-14 15:02:35 -0800754 public void startPreferencePanel(Fragment caller, String fragmentClass, Bundle args,
755 int titleRes, CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700756 String title = null;
757 if (titleRes < 0) {
758 if (titleText != null) {
759 title = titleText.toString();
760 } else {
761 // There not much we can do in that case
762 title = "";
763 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700764 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700765 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fan Zhangc6ca3142017-02-14 15:02:35 -0800766 titleRes, title, mIsShortcut, mMetricsFeatureProvider.getMetricsCategory(caller));
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000767 }
768
769 /**
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100770 * Start a new fragment in a new activity containing a preference panel for a given user. If the
771 * preferences are being displayed in multi-pane mode, the given fragment class will be
772 * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
773 * activity will be launched in which to show the fragment.
774 *
775 * @param fragmentClass Full name of the class implementing the fragment.
776 * @param args Any desired arguments to supply to the fragment.
777 * @param titleRes Optional resource identifier of the title of this fragment.
778 * @param titleText Optional text of the title of this fragment.
779 * @param userHandle The user for which the panel has to be started.
780 */
Fan Zhangc6ca3142017-02-14 15:02:35 -0800781 public void startPreferencePanelAsUser(Fragment caller, String fragmentClass,
782 Bundle args, int titleRes, CharSequence titleText, UserHandle userHandle) {
Lifu Tangd0332852015-04-02 12:05:46 -0700783 // This is a workaround.
784 //
785 // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
786 // starting the fragment could cause a native stack corruption. See b/17523189. However,
787 // adding that flag and start the preference panel with the same UserHandler will make it
788 // impossible to use back button to return to the previous screen. See b/20042570.
789 //
790 // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
791 // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
792 // when we're calling it as the same user.
793 if (userHandle.getIdentifier() == UserHandle.myUserId()) {
Fan Zhangc6ca3142017-02-14 15:02:35 -0800794 startPreferencePanel(caller, fragmentClass, args, titleRes, titleText, null, 0);
Lifu Tangd0332852015-04-02 12:05:46 -0700795 } else {
796 String title = null;
797 if (titleRes < 0) {
798 if (titleText != null) {
799 title = titleText.toString();
800 } else {
801 // There not much we can do in that case
802 title = "";
803 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100804 }
Fan Zhangc6ca3142017-02-14 15:02:35 -0800805 Utils.startWithFragmentAsUser(this, fragmentClass, args, titleRes, title,
806 mIsShortcut, mMetricsFeatureProvider.getMetricsCategory(caller), userHandle);
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100807 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100808 }
809
810 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800811 * Called by a preference panel fragment to finish itself.
812 *
813 * @param caller The fragment that is asking to be finished.
814 * @param resultCode Optional result code to send back to the original
815 * launching fragment.
816 * @param resultData Optional result data to send back to the original
817 * launching fragment.
818 */
819 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
820 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700821 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800822 }
823
824 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000825 * Start a new fragment.
826 *
827 * @param fragment The fragment to start
828 * @param push If true, the current fragment will be pushed onto the back stack. If false,
829 * the current fragment will be replaced.
830 */
831 public void startPreferenceFragment(Fragment fragment, boolean push) {
832 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700833 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000834 if (push) {
835 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
836 transaction.addToBackStack(BACK_STACK_PREFS);
837 } else {
838 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
839 }
840 transaction.commitAllowingStateLoss();
841 }
842
843 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700844 * Switch to a specific Fragment with taking care of validation, Title and BackStack
845 */
846 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700847 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700848 if (validate && !isValidFragment(fragmentName)) {
849 throw new IllegalArgumentException("Invalid fragment for this activity: "
850 + fragmentName);
851 }
852 Fragment f = Fragment.instantiate(this, fragmentName, args);
853 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700854 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700855 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700856 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700857 }
858 if (addToBackStack) {
859 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
860 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700861 if (titleResId > 0) {
862 transaction.setBreadCrumbTitle(titleResId);
863 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700864 transaction.setBreadCrumbTitle(title);
865 }
866 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700867 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700868 return f;
869 }
870
Jason Monk4da79e02015-09-10 10:54:36 -0400871 private void updateTilesList() {
Jason Monkfd2c7222015-12-02 15:38:38 -0500872 // Generally the items that are will be changing from these updates will
873 // not be in the top list of tiles, so run it in the background and the
874 // SettingsDrawerActivity will pick up on the updates automatically.
875 AsyncTask.execute(new Runnable() {
876 @Override
877 public void run() {
878 doUpdateTilesList();
879 }
880 });
881 }
882
883 private void doUpdateTilesList() {
Jason Monk4da79e02015-09-10 10:54:36 -0400884 PackageManager pm = getPackageManager();
Xiaohui Chen44879a32015-07-22 13:53:22 -0700885 final UserManager um = UserManager.get(this);
886 final boolean isAdmin = um.isAdminUser();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700887
Jason Monk4da79e02015-09-10 10:54:36 -0400888 String packageName = getPackageName();
889 setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800890 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700891
Jason Monk4da79e02015-09-10 10:54:36 -0400892 setTileEnabled(new ComponentName(packageName,
Fan Zhanga6986e72017-03-08 09:24:45 -0800893 Settings.BluetoothSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800894 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700895
Jason Monk4da79e02015-09-10 10:54:36 -0400896 setTileEnabled(new ComponentName(packageName,
Fan Zhanga6986e72017-03-08 09:24:45 -0800897 Settings.DataUsageSummaryActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800898 Utils.isBandwidthControlEnabled(), isAdmin);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700899
Jason Monk4da79e02015-09-10 10:54:36 -0400900 setTileEnabled(new ComponentName(packageName,
Fan Zhanga6986e72017-03-08 09:24:45 -0800901 Settings.SimSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800902 Utils.showSimCardTile(this), isAdmin);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700903
Jason Monk4da79e02015-09-10 10:54:36 -0400904 setTileEnabled(new ComponentName(packageName,
Fan Zhanga6986e72017-03-08 09:24:45 -0800905 Settings.PowerUsageSummaryActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800906 mBatteryPresent, isAdmin);
Jason Monk4da79e02015-09-10 10:54:36 -0400907
908 setTileEnabled(new ComponentName(packageName,
Fan Zhanga6986e72017-03-08 09:24:45 -0800909 Settings.UserSettingsActivity.class.getName()),
Jason Monk4da79e02015-09-10 10:54:36 -0400910 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
Fan Zhanga6986e72017-03-08 09:24:45 -0800911 && !Utils.isMonkeyRunning(), isAdmin);
Jason Monk4da79e02015-09-10 10:54:36 -0400912
Fyodor Kupolovca060e32016-06-24 13:01:11 -0700913 setTileEnabled(new ComponentName(packageName,
Fan Zhanga6986e72017-03-08 09:24:45 -0800914 Settings.NetworkDashboardActivity.class.getName()),
Doris Ling26208222017-03-03 11:28:05 -0800915 !UserManager.isDeviceInDemoMode(this), isAdmin);
916
917 setTileEnabled(new ComponentName(packageName,
Fan Zhanga6986e72017-03-08 09:24:45 -0800918 Settings.ConnectedDeviceDashboardActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800919 !UserManager.isDeviceInDemoMode(this), isAdmin);
Fyodor Kupolovca060e32016-06-24 13:01:11 -0700920
921 setTileEnabled(new ComponentName(packageName,
922 Settings.DateTimeSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800923 !UserManager.isDeviceInDemoMode(this), isAdmin);
Jason Monk4da79e02015-09-10 10:54:36 -0400924 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
925 setTileEnabled(new ComponentName(packageName,
926 Settings.PaymentSettingsActivity.class.getName()),
927 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
928 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
Fan Zhang224caad2017-01-06 11:42:48 -0800929 && adapter != null && adapter.isEnabled(), isAdmin);
Jason Monk4da79e02015-09-10 10:54:36 -0400930
931 setTileEnabled(new ComponentName(packageName,
Fan Zhanga6986e72017-03-08 09:24:45 -0800932 Settings.PrintSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800933 pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin);
Jason Monk4da79e02015-09-10 10:54:36 -0400934
935 final boolean showDev = mDevelopmentPreferences.getBoolean(
Fan Zhanga6986e72017-03-08 09:24:45 -0800936 DevelopmentSettings.PREF_SHOW, android.os.Build.TYPE.equals("eng"))
Dan Sandler12c4ba42016-03-28 11:13:40 -0400937 && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES);
Jason Monk4da79e02015-09-10 10:54:36 -0400938 setTileEnabled(new ComponentName(packageName,
939 Settings.DevelopmentSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800940 showDev, isAdmin);
Dan Sandler12c4ba42016-03-28 11:13:40 -0400941
Fan Zhanga6986e72017-03-08 09:24:45 -0800942 // Enable/disable backup settings depending on whether the user is admin.
943 setTileEnabled(new ComponentName(packageName,
944 BackupSettingsActivity.class.getName()), true,
945 isAdmin || Utils.isCarrierDemoUser(this));
946
947 setTileEnabled(new ComponentName(packageName,
948 Settings.EnterprisePrivacySettingsActivity.class.getName()),
Fan Zhangcabc5092017-03-14 12:38:43 -0700949 EnterprisePrivacySettings.isPageEnabled(this), isAdmin);
Fan Zhanga6986e72017-03-08 09:24:45 -0800950
Fan Zhang4fcd5ed2017-03-10 12:25:35 -0800951 setTileEnabled(new ComponentName(packageName,
952 Settings.WifiDisplaySettingsActivity.class.getName()),
953 WifiDisplaySettings.isAvailable(this), isAdmin);
954
Jason Monk4da79e02015-09-10 10:54:36 -0400955 if (UserHandle.MU_ENABLED && !isAdmin) {
Fan Zhanga6986e72017-03-08 09:24:45 -0800956
Jason Monk4da79e02015-09-10 10:54:36 -0400957 // 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 Zhanga6986e72017-03-08 09:24:45 -0800959 synchronized (categories) {
960 for (DashboardCategory category : categories) {
961 for (Tile tile : category.tiles) {
962 ComponentName component = tile.intent.getComponent();
963 final String name = component.getClassName();
964 final boolean isEnabledForRestricted = ArrayUtils.contains(
965 SettingsGateway.SETTINGS_FOR_RESTRICTED, name);
966 if (packageName.equals(component.getPackageName())
967 && !isEnabledForRestricted) {
968 setTileEnabled(component, false, isAdmin);
969 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700970 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700971 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700972 }
973 }
Doris Ling26bf0032016-06-15 18:16:09 -0700974
Fan Zhang224caad2017-01-06 11:42:48 -0800975 // Final step, refresh categories.
976 updateCategories();
Jason Monk2ebc8a02015-02-13 15:23:19 -0500977 }
978
Fan Zhang224caad2017-01-06 11:42:48 -0800979 private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin) {
Jason Monk5862c1e2016-06-07 14:02:33 -0400980 if (UserHandle.MU_ENABLED && !isAdmin && getPackageName().equals(component.getPackageName())
Fan Zhang9ec45362017-01-10 11:55:45 -0800981 && !ArrayUtils.contains(SettingsGateway.SETTINGS_FOR_RESTRICTED,
982 component.getClassName())) {
Jason Monk4da79e02015-09-10 10:54:36 -0400983 enabled = false;
984 }
Jason Monk5862c1e2016-06-07 14:02:33 -0400985 setTileEnabled(component, enabled);
Jason Monk2ebc8a02015-02-13 15:23:19 -0500986 }
987
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800988 private void getMetaData() {
989 try {
990 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
991 PackageManager.GET_META_DATA);
992 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800993 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
994 } catch (NameNotFoundException nnfe) {
995 // No recovery
996 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
997 }
998 }
999
1000 // give subclasses access to the Next button
1001 public boolean hasNextButton() {
1002 return mNextButton != null;
1003 }
1004
1005 public Button getNextButton() {
1006 return mNextButton;
1007 }
1008
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001009 @Override
1010 public boolean shouldUpRecreateTask(Intent targetIntent) {
1011 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1012 }
1013
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001014 @Deprecated
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001015 @Override
1016 public boolean onQueryTextSubmit(String query) {
Matthew Fritze9955db62016-12-20 09:37:21 -08001017 if (mSearchFeatureProvider.isEnabled(this)) {
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001018 return false;
1019 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001020 mSearchQuery = query;
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001021 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001022 return mSearchResultsFragment.onQueryTextSubmit(query);
1023 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001024
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001025 @Deprecated
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001026 @Override
1027 public boolean onQueryTextChange(String newText) {
Fan Zhanga3e8f5c2016-12-01 09:52:10 -08001028 mSearchQuery = newText;
Matthew Fritze9955db62016-12-20 09:37:21 -08001029 if (mSearchFeatureProvider.isEnabled(this) || mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001030 return false;
1031 }
1032 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001033 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001034
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001035 @Override
1036 public boolean onClose() {
1037 return false;
1038 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001039
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001040 @Override
1041 public boolean onMenuItemActionExpand(MenuItem item) {
1042 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001043 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001044 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001045 return true;
1046 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001047
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001048 @Override
1049 public boolean onMenuItemActionCollapse(MenuItem item) {
1050 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001051 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001052 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001053 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001054 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001055 return true;
1056 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001057
Jason Monk4da79e02015-09-10 10:54:36 -04001058 @Override
Jason Monkaf001092015-11-04 13:16:18 -05001059 public void onProfileTileOpen() {
1060 if (!mIsShowingDashboard) {
1061 finish();
1062 }
1063 }
1064
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001065 @Deprecated
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001066 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001067 if (mSearchResultsFragment != null) {
1068 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001069 }
Anna Galusza6b1e9db2016-03-30 17:25:36 -07001070 Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001071 if (current != null && current instanceof SearchResultsSummary) {
1072 mSearchResultsFragment = (SearchResultsSummary) current;
1073 } else {
Fan Zhang28691572016-03-23 15:31:08 -07001074 setContentHeaderView(null);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001075 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001076 SearchResultsSummary.class.getName(), null, false, true,
1077 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001078 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001079 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001080 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001081 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001082
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001083 @Deprecated
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001084 public void needToRevertToInitialFragment() {
1085 mNeedToRevertToInitialFragment = true;
1086 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001087
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001088 @Deprecated
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001089 private void revertToInitialFragment() {
1090 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001091 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001092 mSearchMenuItemExpanded = false;
1093 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1094 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001095 if (mSearchMenuItem != null) {
1096 mSearchMenuItem.collapseActionView();
1097 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001098 }
Jim Miller0698a212014-10-16 19:49:07 -07001099
1100 public Intent getResultIntentData() {
1101 return mResultIntentData;
1102 }
1103
Jason Monkd4f03ec2016-01-07 16:25:34 -05001104 public void startSuggestion(Intent intent) {
Matthew Fritze7ac78f22016-10-03 13:26:07 -07001105 if (intent == null || ActivityManager.isUserAMonkey()) {
Matthew Fritze703dc602016-09-30 12:36:27 -07001106 return;
1107 }
Matthew Fritzef265dbc2016-10-04 13:39:27 -07001108 mCurrentSuggestion = intent.getComponent();
Jason Monkd4f03ec2016-01-07 16:25:34 -05001109 startActivityForResult(intent, REQUEST_SUGGESTION);
1110 }
1111
1112 @Override
1113 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
1114 if (requestCode == REQUEST_SUGGESTION && mCurrentSuggestion != null
1115 && resultCode != RESULT_CANCELED) {
1116 getPackageManager().setComponentEnabledSetting(mCurrentSuggestion,
1117 PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
1118 }
1119 super.onActivityResult(requestCode, resultCode, data);
1120 }
jackqdyulei6c355f52017-03-01 17:37:23 -08001121
1122 @VisibleForTesting
1123 Bitmap getBitmapFromXmlResource(int drawableRes) {
1124 Drawable drawable = getResources().getDrawable(drawableRes, getTheme());
1125 Canvas canvas = new Canvas();
1126 Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
1127 drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
1128 canvas.setBitmap(bitmap);
1129 drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
1130 drawable.draw(canvas);
1131
1132 return bitmap;
1133 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001134}